Home > vbmeg > external > mne > fiff_read_events.m

fiff_read_events

PURPOSE ^

SYNOPSIS ^

function [events, mappings] = fiff_read_events(source, tree)

DESCRIPTION ^

 [events, mappings] = fiff_read_events(source, tree)

 Read the events

 If tree is specified, source is assumed to be an open file id,
 otherwise a the name of the file to read. If tree is missing, the
 meas output argument should not be specified.


   Author : Martin Luessi, MGH Martinos Center
   License : BSD 3-clause

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [events, mappings] = fiff_read_events(source, tree)
0002 %
0003 % [events, mappings] = fiff_read_events(source, tree)
0004 %
0005 % Read the events
0006 %
0007 % If tree is specified, source is assumed to be an open file id,
0008 % otherwise a the name of the file to read. If tree is missing, the
0009 % meas output argument should not be specified.
0010 %
0011 %
0012 %   Author : Martin Luessi, MGH Martinos Center
0013 %   License : BSD 3-clause
0014 
0015 
0016 global FIFF;
0017 if isempty(FIFF)
0018     FIFF = fiff_define_constants();
0019 end
0020 
0021 me='MNE:fiff_read_events';
0022 
0023 if nargin ~= 2 & nargin ~= 1
0024     error(me,'Incorrect number of arguments');
0025 end
0026 
0027 if nargin == 1
0028     [ fid, tree ] = fiff_open(source);
0029     open_here = true;
0030 else
0031     fid = source;
0032     open_here = false;
0033 end
0034 
0035 %
0036 %   Find the desired blocks
0037 %
0038 data = fiff_dir_tree_find(tree, FIFF.FIFFB_MNE_EVENTS);
0039 if length(data) == 0
0040     if open_here
0041         fclose(fid);
0042     end
0043     error(me,'Could not find events');
0044 end
0045 
0046 %
0047 %   Read the events
0048 %
0049 for k = 1:data.nent
0050     kind = data.dir(k).kind;
0051     pos  = data.dir(k).pos;
0052     if kind == FIFF.FIFF_MNE_EVENT_LIST
0053         tag = fiff_read_tag(fid, pos);
0054         events = tag.data;
0055         break
0056     end
0057 end
0058 
0059 if ~exist('events','var')
0060     if open_here
0061         fclose(fid);
0062     end
0063     error(me,'Events not found');
0064 end
0065 
0066 events = reshape(events, 3, length(events) / 3)';
0067 
0068 %
0069 % Read the event mappings
0070 %
0071 mappings = '';
0072 data = fiff_dir_tree_find(tree, FIFF.FIFFB_MNE_EVENTS);
0073 
0074 for k = 1:data.nent
0075     kind = data.dir(k).kind;
0076     pos  = data.dir(k).pos;
0077     if kind == FIFF.FIFF_DESCRIPTION
0078         tag = fiff_read_tag(fid, pos);
0079         mappings = tag.data;
0080         break
0081     end
0082 end
0083 
0084 if open_here
0085     fclose(fid);
0086 end
0087 
0088 return;
0089 
0090 
0091

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