Home > vbmeg > external > mne > fiff_open.m

fiff_open

PURPOSE ^

SYNOPSIS ^

function [fid, tree, dir] = fiff_open(fname)

DESCRIPTION ^

 [fid, tree, dir] = fiff_open(fname)

 Open a fif file and provide the directory of tags

 fid     the opened file id
 tree    tag directory organized into a tree
 dir     the sequential tag directory

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [fid, tree, dir] = fiff_open(fname)
0002 %
0003 % [fid, tree, dir] = fiff_open(fname)
0004 %
0005 % Open a fif file and provide the directory of tags
0006 %
0007 % fid     the opened file id
0008 % tree    tag directory organized into a tree
0009 % dir     the sequential tag directory
0010 %
0011 
0012 %
0013 %   Author : Matti Hamalainen, MGH Martinos Center
0014 %   License : BSD 3-clause
0015 %
0016 %   Revision 1.7  2009/03/30 11:37:37  msh
0017 %   Added copying of measurement info blocks from the original like in mne_browse_raw
0018 %
0019 %   Revision 1.6  2008/11/16 21:31:23  msh
0020 %   Added mne_transform_coordinates and new coordinate frame definitions
0021 %
0022 %   Revision 1.5  2006/05/03 19:03:19  msh
0023 %   Eliminated the use of cast function for Matlab 6.5 compatibility
0024 %
0025 %   Revision 1.4  2006/04/23 15:29:40  msh
0026 %   Added MGH to the copyright
0027 %
0028 %   Revision 1.3  2006/04/18 20:44:46  msh
0029 %   Added reading of forward solution.
0030 %   Use length instead of size when appropriate
0031 %
0032 %   Revision 1.2  2006/04/17 15:01:34  msh
0033 %   More small improvements.
0034 %
0035 %   Revision 1.1  2006/04/10 23:26:54  msh
0036 %   Added fiff reading routines
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 %   Check that this looks like a fif file
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 %   Read or create the directory tree
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 %   Create the directory tree structure
0098 %
0099 tree = fiff_make_dir_tree(fid,dir);
0100 if verbose
0101     fprintf(1,'[done]\n');
0102 end
0103 %
0104 %   Back to the beginning
0105 %
0106 fseek(fid,0,'bof');
0107 return;

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005