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
8// <-- CLI SHELL MODE -->
9
10// test of fscanfMat and fprintfMat
11// --------------------------------
12n=50;
13a=rand(n,n,'u');
14// now the data
15fd=mopen(TMPDIR+'/Mat','w');
16texte=['Some text ';'Some more text'];
17for t=texte
18  mfprintf(fd,'%s\n',t);
19end
20for i=1:n ,
21  for j=1:n, mfprintf(fd,'%5.2f ',a(i,j));end;
22  mfprintf(fd,'\n');
23end
24mclose(fd);
25a1=fscanfMat(TMPDIR+'/Mat');
26if max(a1-a) > 1.e-1 then pause,end
27
28[a1,txt]=fscanfMat(TMPDIR+'/Mat');
29if ~and(txt==texte) then pause,end
30if max(a1-a) > 1.e-1 then pause,end
31
32// ---- test with fprintfMat
33n=50;
34a=rand(n,n,'u');
35fprintfMat(TMPDIR+'/Mat',a,'%5.2f');
36a1=fscanfMat(TMPDIR+'/Mat');
37if max(a1-a) > 1.e-1 then pause,end
38
39// ---- test with fprintfMat
40n=50;
41a=rand(n,n,'u');
42fprintfMat(TMPDIR+'/Mat',a,'%5.2f',txt);
43[a1,txt1]=fscanfMat(TMPDIR+'/Mat');
44if max(a1-a) > 1.e-1 then pause,end
45if ~and(txt==txt1) then pause,end
46
47n=100;
48a=rand(n,n,'u');
49fprintfMat(TMPDIR+'/Mat',a)
50[a1]=fscanfMat(TMPDIR+'/Mat');
51if max(a1-a) > 1.e-1 then pause,end
52[a1,S]=fscanfMat(TMPDIR+'/Mat');
53if S<>emptystr() then pause,end
54
55[a1,txt1]=fscanfMat('SCI/modules/fileio/tests/unit_tests/fscanfMatUTF8BOM.mat');
56if size(a1, "r") <> 50 then pause, end
57if size(a1, "c") <> 50 then pause, end
58if size(txt1,"r") <> 12 then pause, end
59if size(txt1,"c") <> 1 then pause, end
60if 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 pause, end
61