// Pierre MARECHAL - Scilab Project
// Copyright INRIA
// 12/02/2008
-mat_ref = [0..
+mat_ref = [ ..
0.15 0.19 0.96 ;
0.55 0.81 0.57 ;
0.28 0.33 0.43 ];
// new_1 already exists.
// status =
// 0.
-//0...
+// ...
// Copyright INRIA
// Scilab Project - Pierre MARECHAL
// Copyright INRIA 2005
// sys.math.scilab/browse_thread/thread/3e2f8a72af0148fd/e0f7866780de7fbf
//
// Since the Windows command interpreter accepts this (cd \ changes
-//0...
+// ...
// Copyright INRIA
// Scilab Project - Pierre MARECHAL
// Copyright INRIA 2005
L1 = msscanf(str1,"%d %d %d %d %d %d %d %d %d %d");
if or(L1<>[1:10]) then bugmes();quit;end
str2 = '..
-1 2 3 4 5 6 7 8 9 100..
-11 12 13 14 15 16 17 18 19 200..
-21 22 23 24 25 26 27 28 29 300..
-31 32 33 34 35 36 37 38 39 400..
+1 2 3 4 5 6 7 8 9 10 ..
+11 12 13 14 15 16 17 18 19 20 ..
+21 22 23 24 25 26 27 28 29 30 ..
+31 32 33 34 35 36 37 38 39 40 ..
41 42 43 44 45 46 47 48 49 50';
L2 = msscanf(str2,"..
-%d %d %d %d %d %d %d %d %d %d0..
-%d %d %d %d %d %d %d %d %d %d0..
-%d %d %d %d %d %d %d %d %d %d0..
-%d %d %d %d %d %d %d %d %d %d0..
+%d %d %d %d %d %d %d %d %d %d ..
+%d %d %d %d %d %d %d %d %d %d ..
+%d %d %d %d %d %d %d %d %d %d ..
+%d %d %d %d %d %d %d %d %d %d ..
%d %d %d %d %d %d %d %d %d %d");
if or(L2<>[1:50]) then bugmes();quit;end
str3 = '..
-1 2 3 4 5 6 7 8 9 100..
-11 12 13 14 15 16 17 18 19 200..
-21 22 23 24 25 26 27 28 29 300..
-31 32 33 34 35 36 37 38 39 400..
-41 42 43 44 45 46 47 48 49 500..
+1 2 3 4 5 6 7 8 9 10 ..
+11 12 13 14 15 16 17 18 19 20 ..
+21 22 23 24 25 26 27 28 29 30 ..
+31 32 33 34 35 36 37 38 39 40 ..
+41 42 43 44 45 46 47 48 49 50 ..
51 52 53 54 55 56 57 58 59 60..
';
StrExec="..
L3 = msscanf(str3,""..
-%d %d %d %d %d %d %d %d %d %d0..
-%d %d %d %d %d %d %d %d %d %d0..
-%d %d %d %d %d %d %d %d %d %d0..
-%d %d %d %d %d %d %d %d %d %d0..
-%d %d %d %d %d %d %d %d %d %d0..
+%d %d %d %d %d %d %d %d %d %d ..
+%d %d %d %d %d %d %d %d %d %d ..
+%d %d %d %d %d %d %d %d %d %d ..
+%d %d %d %d %d %d %d %d %d %d ..
+%d %d %d %d %d %d %d %d %d %d ..
%d %d %d %d %d %d %d %d %d %d..
"");";
errmsg=execstr(StrExec,'errcatch');
// Pierre MARECHAL - Scilab Project
// Copyright INRIA
// 12/02/2008
-mat_ref = [0..
- 72. 21. 26. 77. 11. ;0..
- 19. 31. 63. 21. 19. ;0..
- 54. 36. 40. 11. 56. ;0..
- 23. 29. 91. 68. 58. ;0..
- 23. 56. 4. 15. 68. ;0..
- 21. 48. 48. 69. 89. ;0..
- 88. 33. 26. 84. 50. ;0..
- 65. 59. 41. 40. 34. ;0..
- 30. 50. 28. 40. 38. ;0..
+mat_ref = [ ..
+ 72. 21. 26. 77. 11. ; ..
+ 19. 31. 63. 21. 19. ; ..
+ 54. 36. 40. 11. 56. ; ..
+ 23. 29. 91. 68. 58. ; ..
+ 23. 56. 4. 15. 68. ; ..
+ 21. 48. 48. 69. 89. ; ..
+ 88. 33. 26. 84. 50. ; ..
+ 65. 59. 41. 40. 34. ; ..
+ 30. 50. 28. 40. 38. ; ..
93. 43. 12. 87. 92. ];
mat = fscanfMat("SCI/modules/fileio/tests/nonreg_tests/bug_2555.mat")
mat =
// Copyright INRIA
// 10/02/2008
// test 1 : not enough input arguments
-if execstr("msprintf(""string = %s , number = %d0.\n"",""Hello world"")","errcatch") == 0 then bugmes();quit;end
+if execstr("msprintf(""string = %s , number = %d .\n"",""Hello world"")","errcatch") == 0 then bugmes();quit;end
// test2 : too many input arguments
-if execstr("msprintf(""string = %s , number = %d0.\n"",""Hello world"",2,3)","errcatch") == 0 then bugmes();quit;end
+if execstr("msprintf(""string = %s , number = %d .\n"",""Hello world"",2,3)","errcatch") == 0 then bugmes();quit;end
-
// Copyright ENPC
-
// test of fscanfMat and fprintfMat
-
// --------------------------------
-
n=50;
-
a=rand(n,n,'u');
-
// now the data
-
fd=mopen(TMPDIR+'/Mat','w');
-
texte=['Some text ';'Some more text'];
-
for t=texte
mfprintf(fd,'%s\n',t);
end
-
for i=1:n ,
for j=1:n, mfprintf(fd,'%5.2f ',a(i,j));end;
mfprintf(fd,'\n');
end
-
mclose(fd);
-
a1=fscanfMat(TMPDIR+'/Mat');
-
if maxi(a1-a) > 1.e-1 then bugmes();quit;end
-
-
[a1,txt]=fscanfMat(TMPDIR+'/Mat');
-
if ~and(txt==texte) then bugmes();quit;end
-
if maxi(a1-a) > 1.e-1 then bugmes();quit;end
-
-
// ---- test with fprintfMat
-
n=50;
-
a=rand(n,n,'u');
-
fprintfMat(TMPDIR+'/Mat',a,'%5.2f');
-
a1=fscanfMat(TMPDIR+'/Mat');
-
if maxi(a1-a) > 1.e-1 then bugmes();quit;end
-
-
// ---- test with fprintfMat
-
n=50;
-
a=rand(n,n,'u');
-
fprintfMat(TMPDIR+'/Mat',a,'%5.2f',txt);
-
[a1,txt1]=fscanfMat(TMPDIR+'/Mat');
-
if maxi(a1-a) > 1.e-1 then bugmes();quit;end
-
if ~and(txt==txt1) then bugmes();quit;end
-
-
n=100;
-
a=rand(n,n,'u');
-
fprintfMat(TMPDIR+'/Mat',a)
-
[a1]=fscanfMat(TMPDIR+'/Mat');
-
if maxi(a1-a) > 1.e-1 then bugmes();quit;end
-
[a1,S]=fscanfMat(TMPDIR+'/Mat');
-
if S<>emptystr() then bugmes();quit;end
-
-
-
-
-
-
// =============================================================================
if bugnum(Fprintf("%f",-35),"-35.000000" ) then bugmes();quit;end
if bugnum(Fprintf("%f",35.55),"35.550000" ) then bugmes();quit;end
-if bugnum(Fprintf("%f",0.00433),"0.004330" , "0.004330" ) then bugmes();quit;end
-if bugnum(Fprintf("%f",0.0000000345456),"0.000000" , "0.000000" ) then bugmes();quit;end
+if bugnum(Fprintf("%f",0.00433),"0.004330" , " .004330" ) then bugmes();quit;end
+if bugnum(Fprintf("%f",0.0000000345456),"0.000000" , " .000000" ) then bugmes();quit;end
if bugnum(Fprintf("%f",1112423453),"1112423453.000000" ) then bugmes();quit;end
if bugnum(Fprintf("%15f",-35)," -35.000000" ) then bugmes();quit;end
-if bugnum(Fprintf("%15f",0.00433)," 0.004330"," 0.004330" ) then bugmes();quit;end
-if bugnum(Fprintf("%15f",0.0000000345456)," 0.000000" ," 0.000000" ) then bugmes();quit;end
+if bugnum(Fprintf("%15f",0.00433)," 0.004330"," .004330" ) then bugmes();quit;end
+if bugnum(Fprintf("%15f",0.0000000345456)," 0.000000" ," .000000" ) then bugmes();quit;end
if bugnum(Fprintf("%15f",1112423453),"1112423453.000000" ) then bugmes();quit;end
if bugnum(Fprintf("%.1f",-35),"-35.0" ) then bugmes();quit;end
if bugnum(Fprintf("%.0f",-35),"-35" ) then bugmes();quit;end
if bugnum(Fprintf("%#.0f",-35),"-35." ) then bugmes();quit;end
-if bugnum(Fprintf("%.1f",0.00433),"0.0","0.0") then bugmes();quit;end
-if bugnum(Fprintf("%.15f",0.0000000345456),"0.000000034545600" ,"0.000000034545600" ) then bugmes();quit;end
+if bugnum(Fprintf("%.1f",0.00433),"0.0"," .0") then bugmes();quit;end
+if bugnum(Fprintf("%.15f",0.0000000345456),"0.000000034545600" ," .000000034545600" ) then bugmes();quit;end
if bugnum(Fprintf("%.1f",11124234534545),"11124234534545.0" ) then bugmes();quit;end
// test format "%g"
// =============================================================================
if bugnum(Fprintf("%g",35.55),"35.55" ) then bugmes();quit;end
if bugnum(Fprintf("%g",35.551234567890),"35.5512" ) then bugmes();quit;end
if bugnum(Fprintf("%+g",35.551234567890),"+35.5512" ) then bugmes();quit;end
-if bugnum(Fprintf("%g",0.00433),"0.00433" ,"0.00433" ) then bugmes();quit;end
+if bugnum(Fprintf("%g",0.00433),"0.00433" ," .00433" ) then bugmes();quit;end
if bugnum(Fprintf("%g",0.0000000345456),"3.45456e-08","3.45456e-008" ) then bugmes();quit;end
if bugnum(Fprintf("%g",11124234534545),"1.11242e+13","1.11242e+013" ) then bugmes();quit;end
if bugnum(Fprintf("%15g",-35)," -35" ) then bugmes();quit;end
-if bugnum(Fprintf("%15g",0.00433)," 0.00433"," 0.00433" ) then bugmes();quit;end
+if bugnum(Fprintf("%15g",0.00433)," 0.00433"," .00433" ) then bugmes();quit;end
if bugnum(Fprintf("%15g",0.0000000345456)," 3.45456e-08"," 3.45456e-008" ) then bugmes();quit;end
if bugnum(Fprintf("%15g",11124234534545)," 1.11242e+13"," 1.11242e+013" ) then bugmes();quit;end
if bugnum(Fprintf("%.1g",-35.1),"-4e+01","-4e+001" ) then bugmes();quit;end
if bugnum(Fprintf("%.0g",-35.1),"-4e+01","-4e+001" ) then bugmes();quit;end
if bugnum(Fprintf("%#.0g",-35.1),"-4.e+01","-4.e+001" ) then bugmes();quit;end
-if bugnum(Fprintf("%#.0G",-35.1),"-4.D+01","-4.D+001" ) then bugmes();quit;end
-if bugnum(Fprintf("%.1g",0.00433),"0.004" ,"0.004" ) then bugmes();quit;end
+if bugnum(Fprintf("%#.0G",-35.1),"-4.E+01","-4.E+001" ) then bugmes();quit;end
+if bugnum(Fprintf("%.1g",0.00433),"0.004" ," .004" ) then bugmes();quit;end
if bugnum(Fprintf("%.15g",0.0000000345456),"3.45456e-08","3.45456e-008" ) then bugmes();quit;end
if bugnum(Fprintf("%.1g",11124234534545),"1e+13","1e+013" ) then bugmes();quit;end
// test format "%e"
if bugnum(Fprintf("%e",0.00433),"4.330000e-03","4.330000e-003" ) then bugmes();quit;end
if bugnum(Fprintf("%e",0.0000000345456),"3.454560e-08","3.454560e-008" ) then bugmes();quit;end
if bugnum(Fprintf("%e",11124234534545),"1.112423e+13","1.112423e+013" ) then bugmes();quit;end
-if bugnum(Fprintf("%E",11124234534545),"1.112423D+13","1.112423D+013" ) then bugmes();quit;end
+if bugnum(Fprintf("%E",11124234534545),"1.112423E+13","1.112423E+013" ) then bugmes();quit;end
if bugnum(Fprintf("%15e",-35)," -3.500000e+01"," -3.500000e+001" ) then bugmes();quit;end
if bugnum(Fprintf("%15e",0.00433)," 4.330000e-03"," 4.330000e-003" ) then bugmes();quit;end
if bugnum(Fprintf("%15e",0.0000000345456)," 3.454560e-08"," 3.454560e-008" ) then bugmes();quit;end
-
// Copyright ENPC/INRIA
-
-
-
deff('[n,a,b,c,d,e]=Fscanf(str,f)',['fd=mopen(TMPDIR+''/fscanf.rep'',''w'');';
'mputstr(str,fd);mclose(fd);';
'fd=mopen(TMPDIR+''/fscanf.rep'',''r'');';
'[n,a,b,c,d,e]=mfscanf(fd,f);mclose(fd);']);
-
-
-
//--------------test format %i
-
[n,a]=Fscanf('123','%i');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf(' 123','%i');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf('123','%2i');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=Fscanf('123','%5i');
-
//--------------test format %li
-
[n,a]=Fscanf('123','%li');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf(' 123','%li');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf('123','%2li');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=Fscanf('123','%5li');
-
//--------------test format %hi
-
[n,a]=Fscanf('123','%hi');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf(' 123','%hi');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf('123','%2hi');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=Fscanf('123','%5hi');
-
//--------------test format %d
-
[n,a]=Fscanf('123','%d');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf(' 123','%d');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf('123','%2d');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=Fscanf('123','%5d');
-
//--------------test format %ld
-
[n,a]=Fscanf('123','%ld');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf(' 123','%ld');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf('123','%2ld');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=Fscanf('123','%5ld');
-
//--------------test format %hd
-
[n,a]=Fscanf('123','%hd');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf(' 123','%hd');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf('123','%2hd');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=Fscanf('123','%5hd');
-
-
//------------- test format %n
-
// Note that %n returned values are not counted in n
-
s1='123 45.67 pipo';s2=' foo';
-
[n,a,b,c,d,e]=Fscanf(s1+s2,'%d%lf%s%n%s');
-
if n<>4|a<>123|b<>45.67|c<>'pipo'|d<>length(s1)|e<>'foo' then bugmes();quit;end
-
-
//------------- test format %u
-
[n,a]=Fscanf('+123','%u');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf(' 123','%2u');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=Fscanf('+123','%5u');
-
if n<>1|a<>123 then bugmes();quit;end
-
//------------- test format %lu
-
[n,a]=Fscanf('+123','%lu');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf(' 123','%2lu');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=Fscanf('+123','%5lu');
-
if n<>1|a<>123 then bugmes();quit;end
-
//------------- test format %hu
-
[n,a]=Fscanf('+123','%hu');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=Fscanf(' 123','%2hu');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=Fscanf('+123','%5hu');
-
if n<>1|a<>123 then bugmes();quit;end
-
-
//------------- test format %o
-
[n,a]=Fscanf('123','%o');
-
if n<>1|a<>83 then bugmes();quit;end
-
[n,a]=Fscanf(' 123','%o');
-
if n<>1|a<>83 then bugmes();quit;end
-
[n,a]=Fscanf('123','%2o');
-
if n<>1|a<>10 then bugmes();quit;end
-
[n,a]=Fscanf('123','%5o');
-
if n<>1|a<>83 then bugmes();quit;end
-
-
//------------- test format %x
-
rep=10*16^2+11*16+12;
-
[n,a]=Fscanf('0xabc','%x');
-
if n<>1|a<>rep then bugmes();quit;end
-
[n,a]=Fscanf(' 0xabc','%x');
-
if n<>1|a<>rep then bugmes();quit;end
-
[n,a]=Fscanf('abc','%2x');
-
if n<>1|a<>10*16+11 then bugmes();quit;end
-
[n,a]=Fscanf('0xabc','%5x');
-
if n<>1|a<>rep then bugmes();quit;end
-
-
//------------- test format %e
-
[n,a]=Fscanf('123.45','%e');
-
if n<>1|norm(a-123.45)>1.e-2 then bugmes();quit;end
-
[n,a]=Fscanf(' 123.45','%e');
-
if n<>1|norm(a-123.45)>1.e-2 then bugmes();quit;end
-
[n,a]=Fscanf('123.45','%2e');
-
if n<>1| norm(a-12)>0.1 then bugmes();quit;end
-
[n,a]=Fscanf('123.45','%5e');
-
if n<>1|norm(a-123.4)>1.e-1 then bugmes();quit;end
-
-
//------------- test format %le
-
[n,a]=Fscanf('123.45','%le');
-
if n<>1|a<>123.45 then bugmes();quit;end
-
[n,a]=Fscanf(' 123.45','%le');
-
if n<>1|a<>123.45 then bugmes();quit;end
-
[n,a]=Fscanf('123.45','%2le');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=Fscanf('123.45','%5le');
-
if n<>1|a<>123.4 then bugmes();quit;end
-
-
//------------- test format %f
-
[n,a]=Fscanf('123.45','%f');
-
if n<>1|norm(a-123.45)>1.e-2 then bugmes();quit;end
-
[n,a]=Fscanf(' 123.45','%f');
-
if n<>1|norm(a-123.45)>1.e-2 then bugmes();quit;end
-
[n,a]=Fscanf('123.45','%2f');
-
if n<>1| norm(a-12)>0.1 then bugmes();quit;end
-
[n,a]=Fscanf('123.45','%5f');
-
if n<>1|norm(a-123.4)>1.e-1 then bugmes();quit;end
-
-
//------------- test format %lf
-
[n,a]=Fscanf('123.45','%lf');
-
if n<>1|a<>123.45 then bugmes();quit;end
-
[n,a]=Fscanf(' 123.45','%lf');
-
if n<>1|a<>123.45 then bugmes();quit;end
-
[n,a]=Fscanf('123.45','%2lf');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=Fscanf('123.45','%5lf');
-
if n<>1|a<>123.4 then bugmes();quit;end
-
-
//------------- test format %s
-
[n,a]=Fscanf('123','%s');
-
if n<>1|a<>'123' then bugmes();quit;end
-
[n,a]=Fscanf(' 123','%s');
-
if n<>1|a<>'123' then bugmes();quit;end
-
[n,a]=Fscanf('123','%2s');
-
if n<>1|a<>'12' then bugmes();quit;end
-
[n,a]=Fscanf('123','%5s');
-
if n<>1|a<>'123' then bugmes();quit;end
-
-
//------------- test format %c
-
-//XXXX : attention a finir0.... il faut ? scaner \n comme
-
+//XXXX : attention a finir .... il faut ? scaner \n comme
//un seul caractere
-
[n,a,b,c,d]=Fscanf(' 12\n','%c%c%c%c');
-
if n<>4|a<>' '|b<>'1'|c<>'2' then bugmes();quit;end
-
-
//------------- test format [
-
[n,a,b]=Fscanf('012345abczoo','%[0-9abc]%s');
-
if n<>2|a<>'012345abc'|b<>'zoo' then bugmes();quit;end
-
-
//------------- test format [
-
[n,a,b]=Fscanf('012345abczoo','%[^c]c%s');
-
if n<>2|a<>'012345ab'|b<>'zoo' then bugmes();quit;end
-
-
//------------- test ignoring arguments
-
[n,a,b]=Fscanf('123 4 pipo poo','%*s%s%*s%s');
-
if n<>2|a<>'4'|b<>'poo' then bugmes();quit;end
-
-
//------------- test [ * ^
-
[n,a]=Fscanf('123 4 pipo poo','%[^\n]\n');
-
if n<>1|a<>'123 4 pipo poo' then bugmes();quit;end
-
-
[n,a]=Fscanf('123 4 pipo Xpoo','%*[^X]X%s');
-
if n<>1|a<>'poo' then bugmes();quit;end
-
-
-
//------------- test composed directives
-
[n,a]=Fscanf('123 4','123%le');
-
if n<>1|a<>4 then bugmes();quit;end
-
[n,a,b,c]=Fscanf('xxxxx 4 test 23.45','xxxxx%d%s%le');
-
if n<>3|a<>4|b<>'test'|c<>23.45 then bugmes();quit;end
-
[n,a,b]=Fscanf('123 456','%le%le');
-
if n<>2|a<>123|b<>456 then bugmes();quit;end
-
-
//------------- test mismatch
-
[n,a]=Fscanf('123 poo','123%le');
-
if n<>0 then bugmes();quit;end
-
-
//------------- test end-of-file
-
[n,a]=Fscanf('123','123%le');
-
if n<>-1 then bugmes();quit;end
-
-
//------------- test with matrix scan
-
-
n=5
n =
5.
-
A=int(10*rand(n,n));
-
A1=strcat(string(A),' ','c');
-
-tmpf=TMPDIR+'/fscanf.rep';
-
-mputl(A1,tmpf);
-
-
-F='%d';F=strcat(F(ones(1,n)),' ');
-
-// all lines read as int we scan a 5x5 matrix
-
-fd=mopen(tmpf,'r');A2=mfscanf(-1,fd,F);mclose(fd);
-
-if norm(A2-A) > %eps then pause;end
-
-// read just 2 lines
-
-fd=mopen(tmpf,'r');A2=mfscanf(2,fd,F);mclose(fd);
-
-if norm(A2-A(1:2,:)) > %eps then pause;end
-
-// explicit columns we scan five columns
-
-fd=mopen(tmpf,'r');[n,a,b,c,d,e]=mfscanf(-1,fd,F);mclose(fd);
-
-if n<>5 then pause;end
-
-if norm([a,b,c,d,e]-A) > %eps then pause;end
-
-// all lines read as int but we scan only 2 columns using %*[^\n] to ignore the rest
-
-fd=mopen(tmpf,'r');A2=mfscanf(-1,fd,'%d%d%*[^\n]\n');mclose(fd);
-
-if norm(A2-A(:,1:2)) > %eps then pause;end
-
-
-// all lines read as string
-
-F='%s';F=strcat(F(ones(1,n)),' ');
-
-fd=mopen(tmpf,'r');A2=mfscanf(-1,fd,F);mclose(fd);
-
-if A2<>string(A) then pause;end
-
-// read just 2 lines
-
-fd=mopen(tmpf,'r');A2=mfscanf(2,fd,F);mclose(fd);
-
-if A2<>string(A(1:2,:)) then pause;end
-
-
-// mixed types read column 1 and 2 as string and others as int
-
-Fs='%s';Fs=strcat(Fs(ones(1,2)),' ');
-
-Fd='%d';Fd=strcat(Fd(ones(1,n-2)),' ');
-
-fd=mopen(tmpf,'r');[n,a,b,c,d,e]=mfscanf(-1,fd,Fs+' '+Fd);mclose(fd);
-
-if n<>5 then pause;end
-
-if norm([eval(a),eval(b),c,d,e]-A) > %eps then pause;end
-
-
-// same example but returned values are compacted in L
-
-fd=mopen(tmpf,'r');L=mfscanf(-1,fd,Fs+' '+Fd);mclose(fd);
-
-if length(L)<>3 then pause;end
-
-if norm(getfield(3,L)-A(:,3:n)) > %eps then pause;end
-
-if getfield(2,L)<>string(A(:,1:2)) then pause;end
-
-
==>-4e+01<==mprintf("==>%.0g<==",-35.1);
==>-4e+01<==mprintf("==>%#.0g<==",-35.1);
==>-4.e+01<==mprintf("==>%#.0G<==",-35.1);
-==>-4.D+01<==mprintf("==>%.1g<==",0.00433);
+==>-4.E+01<==mprintf("==>%.1g<==",0.00433);
==>0.004<==mprintf("==>%.15g<==",0.0000000345456);
==>3.45456e-08<==mprintf("==>%.1g<==",11124234534545);
==>1e+13<==// format '%e'
==>4.330000e-03<==mprintf("==>%e<==",0.0000000345456);
==>3.454560e-08<==mprintf("==>%e<==",11124234534545);
==>1.112423e+13<==mprintf("==>%E<==",11124234534545);
-==>1.112423D+13<==mprintf("==>%15e<==",-35);
+==>1.112423E+13<==mprintf("==>%15e<==",-35);
==> -3.500000e+01<==mprintf("==>%15e<==",0.00433);
==> 4.330000e-03<==mprintf("==>%15e<==",0.0000000345456);
==> 3.454560e-08<==mprintf("==>%+15e<==",0.0000000345456);
// =============================================================================
// test 1
A = "row "+string(1:10)';
-B = [0..
- 50.153416 28.06498 40.948255 ;0..
- 43.685876 12.800585 87.841258 ;0..
- 26.931248 77.831286 11.383597 ;0..
- 63.257449 21.190304 19.983377 ;0..
- 40.51954 11.213547 56.186607 ;0..
- 91.847078 68.56896 58.961773 ;0..
- 4.3733433 15.312167 68.539797 ;0..
- 48.185089 69.708506 89.062247 ;0..
- 26.39556 84.155184 50.422128 ;0..
+B = [ ..
+ 50.153416 28.06498 40.948255 ; ..
+ 43.685876 12.800585 87.841258 ; ..
+ 26.931248 77.831286 11.383597 ; ..
+ 63.257449 21.190304 19.983377 ; ..
+ 40.51954 11.213547 56.186607 ; ..
+ 91.847078 68.56896 58.961773 ; ..
+ 4.3733433 15.312167 68.539797 ; ..
+ 48.185089 69.708506 89.062247 ; ..
+ 26.39556 84.155184 50.422128 ; ..
41.481037 40.620248 34.936154 ];
mprintf("==>%10s : %08.4f %08.4f %08.4f<==\n",A,B);
==> row 1 : 050.1534 028.0650 040.9483<==
==> row 9 : 026.3956 084.1552 050.4221<==
==> row 10 : 041.4810 040.6202 034.9362<==
// test 2
-C = [0..
- 50.153416 28.06498 ;0..
- 43.685876 12.800585 ;0..
- 26.931248 77.831286 ;0..
- 63.257449 21.190304 ;0..
- 40.51954 11.213547 ;0..
- 91.847078 68.56896 ;0..
- 4.3733433 15.312167 ;0..
- 48.185089 69.708506 ;0..
- 26.39556 84.155184 ;0..
+C = [ ..
+ 50.153416 28.06498 ; ..
+ 43.685876 12.800585 ; ..
+ 26.931248 77.831286 ; ..
+ 63.257449 21.190304 ; ..
+ 40.51954 11.213547 ; ..
+ 91.847078 68.56896 ; ..
+ 4.3733433 15.312167 ; ..
+ 48.185089 69.708506 ; ..
+ 26.39556 84.155184 ; ..
41.481037 40.620248 ];
-D = [0..
- 40.948255 ;0..
- 87.841258 ;0..
- 11.383597 ;0..
- 19.983377 ;0..
- 56.186607 ;0..
- 58.961773 ;0..
- 68.539797 ;0..
- 89.062247 ;0..
- 50.422128 ;0..
+D = [ ..
+ 40.948255 ; ..
+ 87.841258 ; ..
+ 11.383597 ; ..
+ 19.983377 ; ..
+ 56.186607 ; ..
+ 58.961773 ; ..
+ 68.539797 ; ..
+ 89.062247 ; ..
+ 50.422128 ; ..
34.936154 ];
mprintf("==>%10s : %08.4f %08.4f %08.4f<==\n",A,C,D);
==> row 1 : 050.1534 028.0650 040.9483<==
cd TMPDIR;
// Deleting an existing file... Just in case...
mdelete("dummyFile.dummy")
-TXT = [ 'I am a dummy String';0..
- 'Multi lines ';0..
- 'to check that';0..
- ' mputl is okay';0..
- ' on linux and windows0... '];
+TXT = [ 'I am a dummy String'; ..
+ 'Multi lines '; ..
+ 'to check that'; ..
+ ' mputl is okay'; ..
+ ' on linux and windows ... '];
mputl(TXT, 'dummyFile.dummy')
TXT2 = mgetl('dummyFile.dummy');
if TXT2 <> TXT then bugmes();quit;end
if msprintf("%.1g",-35.1) <> "-4e+01" then bugmes();quit;end
if msprintf("%.0g",-35.1) <> "-4e+01" then bugmes();quit;end
if msprintf("%#.0g",-35.1) <> "-4.e+01" then bugmes();quit;end
-if msprintf("%#.0G",-35.1) <> "-4.D+01" then bugmes();quit;end
+if msprintf("%#.0G",-35.1) <> "-4.E+01" then bugmes();quit;end
if msprintf("%.1g",0.00433) <> "0.004" then bugmes();quit;end
if msprintf("%.15g",0.0000000345456) <> "3.45456e-08" then bugmes();quit;end
if msprintf("%.1g",11124234534545) <> "1e+13","1e+013" then bugmes();quit;end
if msprintf("%e",0.00433) <> "4.330000e-03" then bugmes();quit;end
if msprintf("%e",0.0000000345456) <> "3.454560e-08" then bugmes();quit;end
if msprintf("%e",11124234534545) <> "1.112423e+13" then bugmes();quit;end
-if msprintf("%E",11124234534545) <> "1.112423D+13" then bugmes();quit;end
+if msprintf("%E",11124234534545) <> "1.112423E+13" then bugmes();quit;end
if msprintf("%15e",-35) <> " -3.500000e+01" then bugmes();quit;end
if msprintf("%15e",0.00433) <> " 4.330000e-03" then bugmes();quit;end
if msprintf("%15e",0.0000000345456) <> " 3.454560e-08" then bugmes();quit;end
-
// Copyright ENPC/INRIA
-
//--------------test format %i
-
[n,a]=msscanf('123','%i');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf(' 123','%i');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf('123','%2i');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=msscanf('123','%5i');
-
//--------------test format %li
-
[n,a]=msscanf('123','%li');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf(' 123','%li');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf('123','%2li');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=msscanf('123','%5li');
-
//--------------test format %hi
-
[n,a]=msscanf('123','%hi');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf(' 123','%hi');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf('123','%2hi');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=msscanf('123','%5hi');
-
//--------------test format %d
-
[n,a]=msscanf('123','%d');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf(' 123','%d');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf('123','%2d');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=msscanf('123','%5d');
-
//--------------test format %ld
-
[n,a]=msscanf('123','%ld');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf(' 123','%ld');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf('123','%2ld');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=msscanf('123','%5ld');
-
//--------------test format %hd
-
[n,a]=msscanf('123','%hd');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf(' 123','%hd');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf('123','%2hd');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=msscanf('123','%5hd');
-
-
//------------- test format %n
-
// Note that %n returned values are not counted in n
-
s1='123 45.67 pipo';s2=' foo';
-
[n,a,b,c,d,e]=msscanf(s1+s2,'%d%lf%s%n%s');
-
if n<>4|a<>123|b<>45.67|c<>'pipo'|d<>length(s1)|e<>'foo' then bugmes();quit;end
-
-
//------------- test format %u
-
[n,a]=msscanf('+123','%u');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf(' 123','%2u');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=msscanf('+123','%5u');
-
if n<>1|a<>123 then bugmes();quit;end
-
//------------- test format %lu
-
[n,a]=msscanf('+123','%lu');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf(' 123','%2lu');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=msscanf('+123','%5lu');
-
if n<>1|a<>123 then bugmes();quit;end
-
//------------- test format %hu
-
[n,a]=msscanf('+123','%hu');
-
if n<>1|a<>123 then bugmes();quit;end
-
[n,a]=msscanf(' 123','%2hu');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=msscanf('+123','%5hu');
-
if n<>1|a<>123 then bugmes();quit;end
-
-
-
//------------- test format %o
-
[n,a]=msscanf('123','%o');
-
if n<>1|a<>83 then bugmes();quit;end
-
[n,a]=msscanf(' 123','%o');
-
if n<>1|a<>83 then bugmes();quit;end
-
[n,a]=msscanf('123','%2o');
-
if n<>1|a<>10 then bugmes();quit;end
-
[n,a]=msscanf('123','%5o');
-
if n<>1|a<>83 then bugmes();quit;end
-
-
//------------- test format %x
-
rep=10*16^2+11*16+12;
-
[n,a]=msscanf('0xabc','%x');
-
if n<>1|a<>rep then bugmes();quit;end
-
[n,a]=msscanf(' 0xabc','%x');
-
if n<>1|a<>rep then bugmes();quit;end
-
[n,a]=msscanf('abc','%2x');
-
if n<>1|a<>10*16+11 then bugmes();quit;end
-
[n,a]=msscanf('0xabc','%5x');
-
if n<>1|a<>rep then bugmes();quit;end
-
-
//------------- test format %e
-
[n,a]=msscanf('123.45','%e');
-
if n<>1|norm(a-123.45)>1.e-2 then bugmes();quit;end
-
[n,a]=msscanf(' 123.45','%e');
-
if n<>1|norm(a-123.45)>1.e-2 then bugmes();quit;end
-
[n,a]=msscanf('123.45','%2e');
-
if n<>1| norm(a-12)>0.1 then bugmes();quit;end
-
[n,a]=msscanf('123.45','%5e');
-
if n<>1|norm(a-123.4)>1.e-1 then bugmes();quit;end
-
-
//------------- test format %le
-
[n,a]=msscanf('123.45','%le');
-
if n<>1|a<>123.45 then bugmes();quit;end
-
[n,a]=msscanf(' 123.45','%le');
-
if n<>1|a<>123.45 then bugmes();quit;end
-
[n,a]=msscanf('123.45','%2le');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=msscanf('123.45','%5le');
-
if n<>1|a<>123.4 then bugmes();quit;end
-
-
//------------- test format %f
-
[n,a]=msscanf('123.45','%f');
-
if n<>1|norm(a-123.45)>1.e-2 then bugmes();quit;end
-
[n,a]=msscanf(' 123.45','%f');
-
if n<>1|norm(a-123.45)>1.e-2 then bugmes();quit;end
-
[n,a]=msscanf('123.45','%2f');
-
if n<>1| norm(a-12)>0.1 then bugmes();quit;end
-
[n,a]=msscanf('123.45','%5f');
-
if n<>1|norm(a-123.4)>1.e-1 then bugmes();quit;end
-
-
//------------- test format %lf
-
[n,a]=msscanf('123.45','%lf');
-
if n<>1|a<>123.45 then bugmes();quit;end
-
[n,a]=msscanf(' 123.45','%lf');
-
if n<>1|a<>123.45 then bugmes();quit;end
-
[n,a]=msscanf('123.45','%2lf');
-
if n<>1|a<>12 then bugmes();quit;end
-
[n,a]=msscanf('123.45','%5lf');
-
if n<>1|a<>123.4 then bugmes();quit;end
-
-
//------------- test format %s
-
[n,a]=msscanf('123','%s');
-
if n<>1|a<>'123' then bugmes();quit;end
-
[n,a]=msscanf(' 123','%s');
-
if n<>1|a<>'123' then bugmes();quit;end
-
[n,a]=msscanf('123','%2s');
-
if n<>1|a<>'12' then bugmes();quit;end
-
[n,a]=msscanf('123','%5s');
-
if n<>1|a<>'123' then bugmes();quit;end
-
-
//------------- test format %c
-
//note that \n is scaned into \ and n
-
[n,a,b,c,d]=msscanf(' 12\n','%c%c%c%c');
-
if n<>4|a<>' '|b<>'1'|c<>'2'|d<>'\' then bugmes();quit;end
-
//------------- test format [
-
[n,a,b]=msscanf('012345abczoo','%[0-9abc]%s');
-
if n<>2|a<>'012345abc'|b<>'zoo' then bugmes();quit;end
-
-
//------------- test format [
-
[n,a,b]=msscanf('012345abczoo','%[^c]c%s');
-
if n<>2|a<>'012345ab'|b<>'zoo' then bugmes();quit;end
-
-
//------------- test ignoring arguments
-
[n,a,b]=msscanf('123 4 pipo poo','%*s%s%*s%s');
-
if n<>2|a<>'4'|b<>'poo' then bugmes();quit;end
-
-
//------------- test [ * ^
-
-
[n,a]=msscanf('123 4 pipo Xpoo','%*[^X]X%s');
-
if n<>1|a<>'poo' then bugmes();quit;end
-
-
//------------- test ignoring arguments
-
[n,a,b]=msscanf('123 4 pipo poo','%*s%s%*s%s');
-
//if n<>2|a<>'4'|b<>'poo' then bugmes();quit;end
-
//------------- test composed directives
-
[n,a]=msscanf('123 4','123%le');
-
if n<>1|a<>4 then bugmes();quit;end
-
[n,a,b,c]=msscanf('xxxxx 4 test 23.45','xxxxx%d%s%le');
-
if n<>3|a<>4|b<>'test'|c<>23.45 then bugmes();quit;end
-
[n,a,b]=msscanf('123 456','%le%le');
-
if n<>2|a<>123|b<>456 then bugmes();quit;end
-
-
//------------- test mismatch
-
[n,a]=msscanf('123 poo','123%le');
-
if n<>0 then bugmes();quit;end
-
-
//------------- test end-of-file
-
[n,a]=msscanf('123','123%le');
-
if n<>-1 then bugmes();quit;end
-
-
//------------- test with matrix scan
-
-
n=5
n =
5.
-
A=int(10*rand(n,n));
-
A1=strcat(string(A),' ','c');
-
-F='%d';F=strcat(F(ones(1,n)),' ');
-
-// all lines read as int we scan a 5x5 matrix
-
-A2=msscanf(-1,A1,F);
-
-if norm(A2-A) > %eps then pause;end
-
-// read just 2 lines
-
-A2=msscanf(2,A1,F);
-
-if norm(A2-A(1:2,:)) > %eps then pause;end
-
-// explicit columns we scan five columns
-
-[n,a,b,c,d,e]=msscanf(-1,A1,F);
-
-if n<>5 then pause;end
-
-if norm([a,b,c,d,e]-A) > %eps then pause;end
-
-// all lines read as int but we scan only 2 columns
-
-A2=msscanf(-1,A1,'%d%d');
-
-if norm(A2-A(:,1:2)) > %eps then pause;end
-
-
-// all lines read as string
-
-F='%s';F=strcat(F(ones(1,n)),' ');
-
-A2=msscanf(-1,A1,F);
-
-if A2<>string(A) then pause;end
-
-// read just 2 lines
-
-A2=msscanf(2,A1,F);
-
-if A2<>string(A(1:2,:)) then pause;end
-
-
-// mixed types read column 1 and 2 as string and others as int
-
-Fs='%s';Fs=strcat(Fs(ones(1,2)),' ');
-
-Fd='%d';Fd=strcat(Fd(ones(1,n-2)),' ');
-
-[n,a,b,c,d,e]=msscanf(-1,A1,Fs+' '+Fd);
-
-if n<>5 then pause;end
-
-if norm([eval(a),eval(b),c,d,e]-A) > %eps then pause;end
-
-
-// same example but returned values are compacted in L
-
-L=msscanf(-1,A1,Fs+' '+Fd);
-
-if length(L)<>3 then pause;end
-
-if norm(getfield(3,L)-A(:,3:n)) > %eps then pause;end
-
-if getfield(2,L)<>string(A(:,1:2)) then pause;end
-