1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2008 - INRIA - Vincent Couvert <vincent.couvert@inria.fr>
5 // This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7 // <-- CLI SHELL MODE -->
8 // This Scilab script loads MAT-files to test the MATIO module
11 // Loads all MAT-files
13 binFormats = ["-v4";"-v6";"-v7"];
14 for formatIndex = 1:size(binFormats, "*")
15 matFiles = gsort(listfiles("SCI/modules/matio/tests/unit_tests/*" + binFormats(formatIndex) + ".mat"), "r", "i");
16 for fileIndex=1:size(matFiles, "*")
17 disp(fileparts(matFiles(fileIndex), "fname") + fileparts(matFiles(fileIndex), "extension"));
18 loadmatfile(matFiles(fileIndex));
21 // TESTS FOR CELL ARRAYS
23 if binFormats(formatIndex) <> "-v4" then // Cell arrays can not be stored in Matlab 4 binary files
24 assert_checkequal(emptycell , cell());
25 assert_checkequal(scalarcell , makecell([1 1], 1.23));
26 assert_checkequal(rowcell , makecell([1 3], "abc", [1.23+7.89*%i 4.56-1.23*%i 7.89+4.56*%i], 1.23));
27 assert_checkequal(colcell , makecell([3 1], [1.23+7.89*%i 4.56-1.23*%i 7.89+4.56*%i], "abc", 1.23));
28 assert_checkequal(arraycell , makecell([2 3], "a", [1.23+7.89*%i 4.56-1.23*%i 7.89+4.56*%i], int8(1), "abc", 1.23, eye(100,100)));
29 assert_checkequal(stringcell , makecell([2 3], "abc", "def", "ghi", "jkl", "mno", "pqr"));
30 clear emptycell scalarcell rowcell colcell arraycell stringcell
33 // TESTS FOR STRUCTURE ARRAYS
35 if binFormats(formatIndex) <> "-v4" then // Struct arrays can not be stored in Matlab 4 binary files
36 sciemptystruct = struct();
37 assert_checkequal(emptystruct , sciemptystruct);
38 sciscalarstruct = struct("f1", 10, "ftwo", "Hello", "field3", int8(12));
39 assert_checkequal(scalarstruct , sciscalarstruct);
40 scirowstruct = struct("field1", 10, "field2", "Hello", "field3", int8(12));
41 scirowstruct(1,2).field1 = "test";
42 scirowstruct(1,2).field2 = eye(10, 10);
43 scirowstruct(1,3).field2 = "a field contents";
44 scirowstruct(1,3).field3 = 1.23+4.56*%i;
45 assert_checkequal(rowstruct , scirowstruct);
46 scicolstruct = struct("name", 10, "phone", "Hello", "address", int8(12));
47 scicolstruct(2,1).name = "test";
48 scicolstruct(2,1).phone = eye(10, 10);
49 scicolstruct(3,1).phone = "a field contents";
50 scicolstruct(3,1).address = 1.23+4.56*%i;
51 assert_checkequal(colstruct , scicolstruct);
52 sciarraystruct = struct("field1", 10, "field2", "Hello", "field3", int8(12));
53 sciarraystruct(1,2).field1 = "test";
54 sciarraystruct(1,2).field2 = eye(10, 10);
55 sciarraystruct(1,3).field2 = "a field contents";
56 sciarraystruct(1,3).field3 = 1.23+4.56*%i;
57 sciarraystruct(2,1).name = "test";
58 sciarraystruct(2,1).phone = eye(10, 10);
59 sciarraystruct(3,1).phone = "a field contents";
60 sciarraystruct(3,1).address = 1.23+4.56*%i;
61 assert_checkequal(arraystruct , sciarraystruct);
63 // TESTS FOR STRUCTURE ARRAYS SPARSE
65 if binFormats(formatIndex) == "-v7" then
66 assert_checkequal(structure.test,sparse([1 0; 2 0; 0 3]));
69 clear emptystruct scalarstruct rowstruct colstruct arraystruct
70 clear sciemptystruct sciscalarstruct scirowstruct scicolstruct sciarraystruct
77 // TESTS FOR CHARACTER ARRAYS
79 assert_checkequal(emptystringmatrix , "");
80 assert_checkequal(stringscalar , "a");
81 assert_checkequal(stringrowvector , ["abc"]);
82 assert_checkequal(stringcolvector , ["a";"b";"c"]);
83 assert_checkequal(stringmatrix , ["abc";"def"]);
84 clear emptystringmatrix stringscalar stringrowvector stringcolvector stringmatrix
86 // TESTS FOR DOUBLE PRECISION ARRAYS
88 assert_checkequal(emptydoublematrix , []);
89 assert_checkequal(realdoublescalar , 1.23);
90 assert_checkequal(cplxdoublescalar , 1.23 + 4.56*%i);
91 assert_checkequal(realdoublerowvector , [1.23 -4.56 7.89]);
92 assert_checkequal(cplxdoublerowvector , [1.23+7.89*%i 4.56-1.23*%i 7.89+4.56*%i]);
93 assert_checkequal(realdoublecolvector , [1.23;-4.56;7.89]);
94 assert_checkequal(cplxdoublecolvector , [1.23+7.89*%i;4.56-1.23*%i;7.89+4.56*%i]);
95 assert_checkequal(realdoublematrix , [1.23 -4.56 7.89;9.87 6.54 -3.21]);
96 assert_checkequal(cplxdoublematrix , [1.23+7.89*%i 4.56-1.23*%i 7.89+4.56*%i;9.87+3.21*%i 6.54+9.87*%i 3.21-6.54*%i]);
97 clear emptydoublematrix realdoublescalar cplxdoublescalar realdoublerowvector cplxdoublerowvector realdoublecolvector cplxdoublecolvector realdoublematrix cplxdoublematrix
99 // TESTS FOR SINGLE PRECISION ARRAYS
103 // TESTS FOR SPARSE MATRICES
105 if binFormats(formatIndex) <> "-v4" then // Integers can not be stored in Matlab 4 binary files
106 assert_checkequal(emptysparse , []);
107 assert_checkequal(realscalarsparse , sparse(1.23));
108 //assert_checkequal(cplxscalarsparse , sparse(1.23 + 4.56i));
109 assert_checkequal(realrowvectorsparse , sparse([1.23 0 7.89]));
110 //assert_checkequal(cplxrowvectorsparse , sparse([1.23+7.89i 0 7.89+4.56i]));
111 assert_checkequal(realcolvectorsparse , sparse([1.23;0;7.89]));
112 //assert_checkequal(cplxcolvectorsparse , sparse([1.23+7.89i;;7.89+4.56i]));
113 assert_checkequal(realmatrixsparse , sparse([1.23 0 7.89;0 6.54 -3.21]));
114 //assert_checkequal(cplxmatrixsparse , sparse([1.23+7.89i 0 7.89+4.56i;0 6.54+9.87i 3.21-6.54i]));
116 if binFormats(formatIndex) <> "-v4" then // Integers can not be stored in Matlab 4 binary files
118 // TESTS FOR 8-BITS SIGNED INTEGERS
120 assert_checkequal(emptyint8matrix , int8([]));
121 assert_checkequal(int8scalar , int8(1));
122 assert_checkequal(int8rowvector , int8([1 -4 7]));
123 assert_checkequal(int8colvector , int8([1;-4;7]));
124 assert_checkequal(int8matrix , int8([1 -4 7;-9 6 -3]));
125 clear emptyint8matrix int8scalar int8rowvector int8colvector int8matrix
127 // TESTS FOR 16-BITS SIGNED INTEGERS
129 assert_checkequal(emptyint16matrix , int16([]));
130 assert_checkequal(int16scalar , int16(1));
131 assert_checkequal(int16rowvector , int16([1 -4 7]));
132 assert_checkequal(int16colvector , int16([1;-4;7]));
133 assert_checkequal(int16matrix , int16([1 -4 7;-9 6 -3]));
134 clear emptyint16matrix int16scalar int16rowvector int16colvector int16matrix
136 // TESTS FOR 32-BITS SIGNED INTEGERS
138 assert_checkequal(emptyint32matrix , int32([]));
139 assert_checkequal(int32scalar , int32(1));
140 assert_checkequal(int32rowvector , int32([1 -4 7]));
141 assert_checkequal(int32colvector , int32([1;-4;7]));
142 assert_checkequal(int32matrix , int32([1 -4 7;-9 6 -3]));
143 clear emptyint32matrix int32scalar int32rowvector int32colvector int32matrix
144 // TODO: int64 tests ?
146 // TESTS FOR 8-BITS UNSIGNED INTEGERS
148 assert_checkequal(emptyuint8matrix , uint8([]));
149 assert_checkequal(uint8scalar , uint8(1));
150 //assert_checkequal(uint8rowvector , uint8([1 -4 7]));
151 assert_checkequal(uint8rowvector , uint8([1 0 7]));
152 //assert_checkequal(uint8colvector , uint8([1;-4;7]));
153 assert_checkequal(uint8colvector , uint8([1;0;7]));
154 //assert_checkequal(uint8matrix , uint8([1 -4 7;-9 6 -3]));
155 assert_checkequal(uint8matrix , uint8([1 0 7;0 6 0]));
156 clear emptyuint8matrix uint8scalar uint8rowvector uint8colvector uint8matrix
158 // TESTS FOR 16-BITS UNSIGNED INTEGERS
160 assert_checkequal(emptyuint16matrix , uint16([]));
161 assert_checkequal(uint16scalar , uint16(1));
162 //assert_checkequal(uint16rowvector , uint16([1 -4 7]));
163 assert_checkequal(uint16rowvector , uint16([1 0 7]));
164 //assert_checkequal(uint16colvector , uint16([1;-4;7]));
165 assert_checkequal(uint16colvector , uint16([1;0;7]));
166 //assert_checkequal(uint16matrix , uint16([1 -4 7;-9 6 -3]));
167 assert_checkequal(uint16matrix , uint16([1 0 7;0 6 0]));
168 clear emptyuint16matrix uint16scalar uint16rowvector uint16colvector uint16matrix
170 // TESTS FOR 32-BITS UNSIGNED INTEGERS
172 assert_checkequal(emptyuint32matrix , uint32([]));
173 assert_checkequal(uint32scalar , uint32(1));
174 //assert_checkequal(uint32rowvector , uint32([1 -4 7]));
175 assert_checkequal(uint32rowvector , uint32([1 0 7]));
176 //assert_checkequal(uint32colvector , uint32([1;-4;7]));
177 assert_checkequal(uint32colvector , uint32([1;0;7]));
178 //assert_checkequal(uint32matrix , uint32([1 -4 7;-9 6 -3]));
179 assert_checkequal(uint32matrix , uint32([1 0 7;0 6 0]));
180 clear emptyuint32matrix uint32scalar uint32rowvector uint32colvector uint32matrix
181 // TODO: uint64 tests ?
183 // TESTS FOR ND-ARRAYS
185 assert_checkequal(emptyNDarray , []);
186 assert_checkequal(realdoubleNDarray , matrix(1:24, 2, 3, 4));
187 assert_checkequal(complexdoubleNDarray , matrix((1:24) + (1:24)*%i, 2, 3, 4));
188 clear emptyNDarray realdoubleNDarray complexdoubleNDarray
193 assert_checkequal(eye100x100 , eye(100,100));
195 cplxdoublecolvector-v4.mat
196 cplxdoublematrix-v4.mat
197 cplxdoublerowvector-v4.mat
198 cplxdoublescalar-v4.mat
199 emptydoublematrix-v4.mat
200 emptystringmatrix-v4.mat
202 realdoublecolvector-v4.mat
203 realdoublematrix-v4.mat
204 realdoublerowvector-v4.mat
205 realdoublescalar-v4.mat
206 stringcolvector-v4.mat
208 stringrowvector-v4.mat
214 complexdoubleNDarray-v6.mat
215 cplxdoublecolvector-v6.mat
216 cplxdoublematrix-v6.mat
217 cplxdoublerowvector-v6.mat
218 cplxdoublescalar-v6.mat
221 emptydoublematrix-v6.mat
222 emptyint16matrix-v6.mat
223 emptyint32matrix-v6.mat
224 emptyint64matrix-v6.mat
225 emptyint8matrix-v6.mat
227 emptystringmatrix-v6.mat
229 emptyuint16matrix-v6.mat
230 emptyuint32matrix-v6.mat
231 emptyuint64matrix-v6.mat
232 emptyuint8matrix-v6.mat
234 int16colvector-v6.mat
236 int16rowvector-v6.mat
238 int32colvector-v6.mat
240 int32rowvector-v6.mat
242 int64colvector-v6.mat
244 int64rowvector-v6.mat
250 realcolvectorsparse-v6.mat
251 realdoubleNDarray-v6.mat
252 realdoublecolvector-v6.mat
253 realdoublematrix-v6.mat
254 realdoublerowvector-v6.mat
255 realdoublescalar-v6.mat
256 realmatrixsparse-v6.mat
257 realrowvectorsparse-v6.mat
258 realscalarsparse-v6.mat
264 stringcolvector-v6.mat
266 stringrowvector-v6.mat
268 uint16colvector-v6.mat
270 uint16rowvector-v6.mat
272 uint32colvector-v6.mat
274 uint32rowvector-v6.mat
276 uint64colvector-v6.mat
278 uint64rowvector-v6.mat
280 uint8colvector-v6.mat
282 uint8rowvector-v6.mat
288 complexdoubleNDarray-v7.mat
289 cplxdoublecolvector-v7.mat
290 cplxdoublematrix-v7.mat
291 cplxdoublerowvector-v7.mat
292 cplxdoublescalar-v7.mat
295 emptydoublematrix-v7.mat
296 emptyint16matrix-v7.mat
297 emptyint32matrix-v7.mat
298 emptyint64matrix-v7.mat
299 emptyint8matrix-v7.mat
301 emptystringmatrix-v7.mat
303 emptyuint16matrix-v7.mat
304 emptyuint32matrix-v7.mat
305 emptyuint64matrix-v7.mat
306 emptyuint8matrix-v7.mat
308 int16colvector-v7.mat
310 int16rowvector-v7.mat
312 int32colvector-v7.mat
314 int32rowvector-v7.mat
316 int64colvector-v7.mat
318 int64rowvector-v7.mat
324 realcolvectorsparse-v7.mat
325 realdoubleNDarray-v7.mat
326 realdoublecolvector-v7.mat
327 realdoublematrix-v7.mat
328 realdoublerowvector-v7.mat
329 realdoublescalar-v7.mat
330 realmatrixsparse-v7.mat
331 realrowvectorsparse-v7.mat
332 realscalarsparse-v7.mat
338 stringcolvector-v7.mat
340 stringrowvector-v7.mat
343 uint16colvector-v7.mat
345 uint16rowvector-v7.mat
347 uint32colvector-v7.mat
349 uint32rowvector-v7.mat
351 uint64colvector-v7.mat
353 uint64rowvector-v7.mat
355 uint8colvector-v7.mat
357 uint8rowvector-v7.mat
359 // TODO: read all variables from a single file ?