0001 function A = slreadarray(filename)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 value_types = { ...
0020 'double', ...
0021 'single', ...
0022 'logical', ...
0023 'char', ...
0024 'int8', ...
0025 'uint8', ...
0026 'int16', ...
0027 'uint16', ...
0028 'int32', ...
0029 'uint32', ...
0030 'int64', ...
0031 'uint64'};
0032
0033
0034 fid = fopen(filename, 'r');
0035 if fid <= 0
0036 error('sltoolbox:filefail', ...
0037 'Fail to open file %s', filename);
0038 end
0039
0040
0041
0042
0043
0044 tag = fread(fid, 4, '*char')';
0045 if ~isequal(tag, ['arr', 0])
0046 error('sltoolbox:parseerror', ...
0047 'The file tag is invalid');
0048 end
0049
0050
0051 typeidx = fread(fid, 1, 'uint8');
0052 valtype = value_types{typeidx};
0053
0054
0055 d = fread(fid, 1, 'uint8');
0056
0057
0058
0059 fseek(fid, 8, -1);
0060 siz = fread(fid, d, 'uint32')';
0061
0062
0063
0064 A = fread(fid, prod(siz), ['*', valtype]);
0065 if length(siz) == 1
0066 siz = [siz, 1];
0067 end
0068 A = reshape(A, siz);
0069
0070
0071
0072 fclose(fid);
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083