0001 function [events, mappings] = fiff_read_events(source, tree)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
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
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
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
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