2 % OPENIFF is an auxillary
function to SOPEN
for
5 % Use SOPEN instead of OPENIFF
7 % See also: fopen, SOPEN
11 % This program is free software; you can redistribute it and/or
12 % modify it under the terms of the GNU General Public License
13 % as published by the Free Software Foundation; either version 3
14 % of the License, or (at your option) any later version.
16 % $Id:
openiff.m 2205 2009-10-27 12:18:15Z schloegl $
17 % Copyright (C) 2004,2005,2007 by Alois Schloegl <a.schloegl@ieee.org>
18 % This is part of the BIOSIG-toolbox http:
35 [tmp,c] = fread(fid,[1,4],
'uint8');
36 while ((LEN>0) | isnan(LEN)) & (c>0),
38 tagsize = fread(fid,1,
'uint32'); % which size
39 tagsize0= tagsize + rem(tagsize,2);
43 % fprintf(1,
'tag: %6s\tpos: %8i\tsize: %8i\n',tag,filepos,tagsize);
47 elseif strcmp(tag,
'FORM')
48 [tmp,c] = fread(fid,[1,4],
'uint8');tag,
49 VAL = setfield([],
char(tmp),
openiff(fid,tagsize-4));
50 elseif 0,strcmp(tag,
'RIFF')
52 elseif strcmp(tag,'RIFF')
53 [tmp,c] = fread(fid,[1,4],'uint8');
54 %val = fread(fid,tagsize-4,'uint8');
56 VAL = setfield([],
char(tmp),val);
57 elseif strcmp(tag,'MThd')
58 VAL.MThd = fread(fid,tagsize,'uchar');
63 elseif strcmp(tag,'LIST'); % CNT_RIFF (EEP 3.1)
64 [tmp,c] = fread(fid,[1,4],'uint8');
65 VAL = setfield([],
char(tmp),
openiff(fid,tagsize-4));
67 elseif strcmp(tag,'chan') % CNT_RIFF (EEP 3.1)
68 VAL = fread(fid,[1,tagsize/2],'uint16');
69 elseif strcmp(tag,'info') % CNT_RIFF (EEP 3.1)
70 VAL = fread(fid,[1,tagsize],'*
char');
71 elseif strcmp(tag,'eeph') % CNT_RIFF (EEP 3.1)
72 VAL = fread(fid,[1,tagsize],'*
char');
73 elseif strncmp(tag,'ep ',4), % CNT_RIFF (EEP 3.1)
74 VAL = fread(fid,[1,tagsize/4],'uint32');
75 elseif strcmp(tag,'hdrl')
76 [tmp,c] = fread(fid,[1,4],'uint8');
77 VAL = setfield([],
char(tmp),
openiff(fid,tagsize-4));
79 elseif strcmp(tag,'CAT ')
82 elseif strcmp(tag,'data')
83 % LEN = fread(fid,1,'uint32');
84 VAL = fread(fid,[1,LEN],'*uint8');
85 %[tmp,c] = fread(fid,[1,4],'*
char');
86 %LEN = fread(fid,1,'int32');
87 %VAL.data = fread(fid,LEN,'uint8');
89 elseif strncmp(tag,'(c)',3)
91 VAL =
char(fread(fid,tagsize,'uchar')');
92 %VAL.CopyRight =
char(VAL);
95 VAL = fread(fid,tagsize,'uchar');
98 VAL.handle = ftell(fid);
100 status = fseek(fid,tagsize,'cof');
101 if status, return; end;
105 if strcmp(tag(3:4),'dc')
107 ix = (tag(1:2)-48)*[16;1]+1;
109 elseif strcmp(tag(3:4),
'wb')
111 ix = (tag(1:2)-48)*[16;1]+1;
115 IFF = setfield(IFF,deblank(tag),VAL);
119 status = fseek(fid,filepos+tagsize0,
'bof');
120 LEN = LEN - tagsize0;
121 [tmp,c] = fread(fid,[1,4],
'uint8');
124 if ~isfield(IFF,
'MThd'), %
do not check MIDI files
126 fprintf(2,
'Warning OPENIFF: LEN=%i %i %i %i %s %i\n',LEN,filepos,tagsize0,ftell(fid),
char(tmp),c);