00001 % =============================================================================
00002 % Scilab ( http:
00003 % Copyright (C) 2008 - INRIA - Vincent Couvert <vincent.couvert@inria.fr>
00004 %
00005 % This file is distributed under the same license as the Scilab package.
00006 % =============================================================================
00007
00008 % This Matlab script generates MAT-files to test the MATIO module
00009
00010 clear all
00011
00012 %
00013 % TESTS FOR CELL ARRAYS
00014 %
00015 emptycell = {};
00016 scalarcell = {1.23};
00017 rowcell = {'abc', [1.23+7.89i 4.56-1.23i 7.89+4.56i], 1.23};
00018 colcell = {[1.23+7.89i 4.56-1.23i 7.89+4.56i]; 'abc'; 1.23};
00019 arraycell = {'a', [1.23+7.89i 4.56-1.23i 7.89+4.56i], int8(1); 'abc', 1.23, eye(100,100)};
00020 stringcell = {'abc', 'def', 'ghi';'jkl', 'mno', 'pqr'};
00021
00022 %
00023 % TESTS FOR STRUCTURE ARRAYS
00024 %
00025 emptystruct = struct();
00026 scalarstruct = struct('f1', 10, 'ftwo', 'Hello', 'field3', int8(12));
00027 rowstruct = struct('field1', 10, 'field2', 'Hello', 'field3', int8(12));
00028 rowstruct(1,2).field1 = 'test';
00029 rowstruct(1,2).field2 = eye(10, 10);
00030 rowstruct(1,3).field2 = 'a field contents';
00031 rowstruct(1,3).field3 = 1.23+4.56i;
00032 colstruct = struct('name', 10, 'phone', 'Hello', 'address', int8(12));
00033 colstruct(2,1).name = 'test';
00034 colstruct(2,1).phone = eye(10, 10);
00035 colstruct(3,1).phone = 'a field contents';
00036 colstruct(3,1).address = 1.23+4.56i;
00037 arraystruct = struct('field1', 10, 'field2', 'Hello', 'field3', int8(12));
00038 arraystruct(1,2).field1 = 'test';
00039 arraystruct(1,2).field2 = eye(10, 10);
00040 arraystruct(1,3).field2 = 'a field contents';
00041 arraystruct(1,3).field3 = 1.23+4.56i;
00042 arraystruct(2,1).name = 'test';
00043 arraystruct(2,1).phone = eye(10, 10);
00044 arraystruct(3,1).phone = 'a field contents';
00045 arraystruct(3,1).address = 1.23+4.56i;
00046
00047 %
00048 % TESTS FOR OBJECTS
00049 %
00050
00051 % TODO
00052
00053 %
00054 % TESTS FOR CHARACTER ARRAYS
00055 %
00056
00057 emptystringmatrix = '';
00058 stringscalar = 'a';
00059 stringrowvector = ;
00060 stringcolvector = ;
00061 stringmatrix = ;
00062
00063 %
00064 % TESTS FOR DOUBLE PRECISION ARRAYS
00065 %
00066
00067 emptydoublematrix = ;
00068
00069 realdoublescalar = 1.23;
00070 cplxdoublescalar = 1.23 + 4.56i;
00071
00072 realdoublerowvector = ;
00073 cplxdoublerowvector = [1.23+7.89i 4.56-1.23i 7.89+4.56i];
00074
00075 realdoublecolvector = ;
00076 cplxdoublecolvector = [1.23+7.89i;4.56-1.23i;7.89+4.56i];
00077
00078 realdoublematrix = ;
00079 cplxdoublematrix = [1.23+7.89i 4.56-1.23i 7.89+4.56i;9.87+3.21i 6.54+9.87i 3.21-6.54i];
00080
00081 %
00082 % TESTS FOR SINGLE PRECISION ARRAYS
00083 %
00084
00085 % TODO
00086
00087 %
00088 % TESTS FOR SPARSE MATRICES
00089 %
00090 % Tests for complex matrices are not done because of a bug in MATIO
00091
00092 emptysparse = sparse([]);
00093
00094 realscalarsparse = sparse(1.23);
00095 %cplxscalarsparse = sparse(1.23 + 4.56i);
00096
00097 realrowvectorsparse = sparse([1.23 0 7.89]);
00098 %cplxrowvectorsparse = sparse([1.23+7.89i 0 7.89+4.56i]);
00099
00100 realcolvectorsparse = sparse([1.23;0;7.89]);
00101 %cplxcolvectorsparse = sparse([1.23+7.89i;0;7.89+4.56i]);
00102
00103 realmatrixsparse = sparse([1.23 0 7.89;0 6.54 -3.21]);
00104 %cplxmatrixsparse = sparse([1.23+7.89i 0 7.89+4.56i;0 6.54+9.87i 3.21-6.54i]);
00105
00106 %
00107 % TESTS FOR 8-BITS SIGNED INTEGERS
00108 %
00109
00110 emptyint8matrix = int8([]);
00111 int8scalar = int8(1);
00112 int8rowvector = int8([1 -4 7]);
00113 int8colvector = int8([1;-4;7]);
00114 int8matrix = int8([1 -4 7;-9 6 -3]);
00115
00116 %
00117 % TESTS FOR 16-BITS SIGNED INTEGERS
00118 %
00119
00120 emptyint16matrix = int16([]);
00121 int16scalar = int16(1);
00122 int16rowvector = int16([1 -4 7]);
00123 int16colvector = int16([1;-4;7]);
00124 int16matrix = int16([1 -4 7;-9 6 -3]);
00125
00126 %
00127 % TESTS FOR 32-BITS SIGNED INTEGERS
00128 %
00129
00130 emptyint32matrix = int32([]);
00131 int32scalar = int32(1);
00132 int32rowvector = int32([1 -4 7]);
00133 int32colvector = int32([1;-4;7]);
00134 int32matrix = int32([1 -4 7;-9 6 -3]);
00135
00136 % TODO: int64 tests ?
00137
00138 %
00139 % TESTS FOR 8-BITS UNSIGNED INTEGERS
00140 %
00141
00142 emptyuint8matrix = uint8([]);
00143 uint8scalar = uint8(1);
00144 uint8rowvector = uint8([1 -4 7]);
00145 uint8colvector = uint8([1;-4;7]);
00146 uint8matrix = uint8([1 -4 7;-9 6 -3]);
00147
00148 %
00149 % TESTS FOR 16-BITS UNSIGNED INTEGERS
00150 %
00151
00152 emptyuint16matrix = uint16([]);
00153 uint16scalar = uint16(1);
00154 uint16rowvector = uint16([1 -4 7]);
00155 uint16colvector = uint16([1;-4;7]);
00156 uint16matrix = uint16([1 -4 7;-9 6 -3]);
00157
00158 %
00159 % TESTS FOR 32-BITS UNSIGNED INTEGERS
00160 %
00161
00162 emptyuint32matrix = uint32([]);
00163 uint32scalar = uint32(1);
00164 uint32rowvector = uint32([1 -4 7]);
00165 uint32colvector = uint32([1;-4;7]);
00166 uint32matrix = uint32([1 -4 7;-9 6 -3]);
00167
00168 % TODO: uint64 tests ?
00169
00170 %
00171 % TESTS FOR ND-ARRAYS
00172 %
00173 emptyNDarray = reshape([], 0, 0, 0);
00174 realdoubleNDarray = reshape(1:24, 2, 3, 4);
00175 complexdoubleNDarray = reshape((1:24) + (1:24)*i, 2, 3, 4);
00176
00177 %
00178 % MISC
00179 %
00180 eye100x100 = eye(100,100);
00181
00182 %
00183 % Create files
00184 %
00185 varNames = who();
00186 binFormats = {'-v4';'-v6';'-v7'};
00187 for varIndex=1:length(varNames)
00188 for formatIndex=1:length(binFormats)
00189 % Integers and NDarrays not saved in -v4 format
00190 if formatIndex>1 | ...
00191 (formatIndex==1 & isempty(strfind(varNames{varIndex}, 'int')) ...
00192 & isempty(strfind(varNames{varIndex}, 'NDarray')) & isempty(strfind(varNames{varIndex}, 'cell')) & isempty(strfind(varNames{varIndex}, 'struct')) & isempty(strfind(varNames{varIndex}, 'sparse')))
00193 if exist([pwd filesep varNames{varIndex} binFormats{formatIndex} ...
00194 '.mat']) ~= 2 % If file does not already exist it is created
00195 saveCmd = ['save ' pwd filesep varNames{varIndex} binFormats{formatIndex} '.mat ' varNames{varIndex} ' ' binFormats{formatIndex}];
00196 eval(saveCmd);
00197 else
00198 %disp([pwd filesep varNames{varIndex} binFormats{formatIndex} '.mat already exists.'])
00199 end
00200 end
00201 end
00202 end
00203
00204 % TODO: save all variables in a single file ?