0001 function [fid, tree, dir] = fiff_open(fname)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 global FIFF;
0040 if isempty(FIFF)
0041 FIFF = fiff_define_constants();
0042 end
0043
0044 me='MNE:fiff_open';
0045 verbose=false;
0046 fid = fopen(fname,'rb','ieee-be');
0047
0048 if (fid < 0)
0049 error(me,'Cannot open file %s', fname);
0050 end;
0051
0052
0053
0054 tag = fiff_read_tag_info(fid);
0055 if tag.kind ~= FIFF.FIFF_FILE_ID
0056 error(me,'file does not start with a file id tag');
0057 end
0058 if tag.type ~= FIFF.FIFFT_ID_STRUCT
0059 error(me,'file does not start with a file id tag');
0060 end
0061 if tag.size ~= 20
0062 error(me,'file does not start with a file id tag');
0063 end
0064 tag = fiff_read_tag(fid);
0065 if tag.kind ~= FIFF.FIFF_DIR_POINTER
0066 error(me,'file does have a directory pointer');
0067 end
0068 if nargout == 1
0069 fseek(fid,0,'bof');
0070 return;
0071 end
0072
0073
0074
0075 if verbose
0076 fprintf(1,'\tCreating tag directory for %s...',fname);
0077 end
0078 dirpos = double(tag.data);
0079 if dirpos > 0
0080 tag = fiff_read_tag(fid,dirpos);
0081 dir = tag.data;
0082 else
0083 k = 0;
0084 fseek(fid,0,'bof');
0085 dir = struct('kind',{},'type',{},'size',{},'pos',{});
0086 while tag.next >= 0
0087 pos = ftell(fid);
0088 tag = fiff_read_tag_info(fid);
0089 k = k + 1;
0090 dir(k).kind = tag.kind;
0091 dir(k).type = tag.type;
0092 dir(k).size = tag.size;
0093 dir(k).pos = pos;
0094 end
0095 end
0096
0097
0098
0099 tree = fiff_make_dir_tree(fid,dir);
0100 if verbose
0101 fprintf(1,'[done]\n');
0102 end
0103
0104
0105
0106 fseek(fid,0,'bof');
0107 return;