1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) ????-2008 - ENPC
4//
5//  This file is distributed under the same license as the Scilab package.
6// =============================================================================
7// <-- CLI SHELL MODE -->
8// test of fscanfMat and fprintfMat
9// --------------------------------
10n=50;
11a=rand(n,n,'u');
12// now the data
13fd=mopen(TMPDIR+'/Mat','w');
14texte=['Some text ';'Some more text'];
15for t=texte
16  mfprintf(fd,'%s\n',t);
17end
18for i=1:n ,
19  for j=1:n, mfprintf(fd,'%5.2f ',a(i,j));end;
20  mfprintf(fd,'\n');
21end
22mclose(fd);
23a1=fscanfMat(TMPDIR+'/Mat');
24if max(a1-a) > 1.e-1 then bugmes();quit;end
25[a1,txt]=fscanfMat(TMPDIR+'/Mat');
26if ~and(txt==texte) then bugmes();quit;end
27if max(a1-a) > 1.e-1 then bugmes();quit;end
28// ---- test with fprintfMat
29n=50;
30a=rand(n,n,'u');
31fprintfMat(TMPDIR+'/Mat',a,'%5.2f');
32a1=fscanfMat(TMPDIR+'/Mat');
33if max(a1-a) > 1.e-1 then bugmes();quit;end
34// ---- test with fprintfMat
35n=50;
36a=rand(n,n,'u');
37fprintfMat(TMPDIR+'/Mat',a,'%5.2f',txt);
38[a1,txt1]=fscanfMat(TMPDIR+'/Mat');
39if max(a1-a) > 1.e-1 then bugmes();quit;end
40if ~and(txt==txt1) then bugmes();quit;end
41n=100;
42a=rand(n,n,'u');
43fprintfMat(TMPDIR+'/Mat',a)
44[a1]=fscanfMat(TMPDIR+'/Mat');
45if max(a1-a) > 1.e-1 then bugmes();quit;end
46[a1,S]=fscanfMat(TMPDIR+'/Mat');
47if S<>emptystr() then bugmes();quit;end
48[a1,txt1]=fscanfMat('SCI/modules/fileio/tests/unit_tests/fscanfMatUTF8BOM.mat');
49if size(a1, "r") <> 50 then bugmes();quit;end
50if size(a1, "c") <> 50 then bugmes();quit;end
51if size(txt1,"r") <> 12 then bugmes();quit;end
52if size(txt1,"c") <> 1 then bugmes();quit;end
53if txt1 <> "It is a high level programming language in that most of its functionality is based around the ability to specify many computations with few lines of code. It does this primarily by abstracting primitive data types to functionally equivalent matrices." then bugmes();quit;end
54