0001 function [ projdata ] = fiff_read_proj(fid,node)
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
0040 global FIFF;
0041 if isempty(FIFF)
0042 FIFF = fiff_define_constants();
0043 end
0044
0045 me='MNE:fiff_read_proj';
0046
0047 if nargin ~= 2
0048 error(me,'Incorrect number of arguments');
0049 end
0050
0051 projdata = struct('kind',{},'active',{},'desc',{},'data',{});
0052
0053
0054
0055 nodes = fiff_dir_tree_find(node,FIFF.FIFFB_PROJ);
0056 if length(nodes) == 0
0057 return;
0058 end
0059 tag = find_tag(nodes(1),FIFF.FIFF_NCHAN);
0060 if ~isempty(tag)
0061 global_nchan = tag.data;
0062 end
0063 items = fiff_dir_tree_find(nodes(1),FIFF.FIFFB_PROJ_ITEM);
0064 for i = 1:length(items)
0065
0066
0067
0068 item = items(i);
0069 tag = find_tag(item,FIFF.FIFF_NCHAN);
0070 if ~isempty(tag)
0071 nchan = tag.data;
0072 else
0073 nchan = global_nchan;
0074 end
0075 tag = find_tag(item,FIFF.FIFF_DESCRIPTION);
0076 if ~isempty(tag)
0077 desc = tag.data;
0078 else
0079 tag = find_tag(item,FIFF.FIFF_NAME);
0080 if ~isempty(tag)
0081 desc = tag.data;
0082 else
0083 error(me,'Projection item description missing');
0084 end
0085 end
0086 tag = find_tag(item,FIFF.FIFF_PROJ_ITEM_CH_NAME_LIST);
0087 if ~isempty(tag)
0088 namelist = tag.data;
0089 else
0090 error(me,'Projection item channel list missing');
0091 end
0092 tag = find_tag(item,FIFF.FIFF_PROJ_ITEM_KIND);
0093 if ~isempty(tag)
0094 kind = tag.data;
0095 else
0096 error(me,'Projection item kind missing');
0097 end
0098 tag = find_tag(item,FIFF.FIFF_PROJ_ITEM_NVEC);
0099 if ~isempty(tag)
0100 nvec = tag.data;
0101 else
0102 error(me,'Number of projection vectors not specified');
0103 end
0104 tag = find_tag(item,FIFF.FIFF_PROJ_ITEM_CH_NAME_LIST);
0105 if ~isempty(tag)
0106 names = fiff_split_name_list(tag.data);
0107 else
0108 error(me,'Projection item channel list missing');
0109 end
0110 tag = find_tag(item,FIFF.FIFF_PROJ_ITEM_VECTORS);
0111 if ~isempty(tag)
0112 data = tag.data;
0113 else
0114 error(me,'Projection item data missing');
0115 end
0116 tag = find_tag(item,FIFF.FIFF_MNE_PROJ_ITEM_ACTIVE);
0117 if ~isempty(tag)
0118 active = tag.data;
0119 else
0120 active = false;
0121 end
0122 if size(data,2) ~= length(names)
0123 error(me,'Number of channel names does not match the size of data matrix');
0124 end
0125 one.kind = kind;
0126 one.active = active;
0127 one.desc = desc;
0128
0129
0130
0131 one.data.nrow = nvec;
0132 one.data.ncol = nchan;
0133 one.data.row_names = [];
0134 one.data.col_names = names;
0135 one.data.data = data;
0136
0137 projdata(i) = one;
0138 end
0139
0140 if length(projdata) > 0
0141 fprintf(1,'\tRead a total of %d projection items:\n', ...
0142 length(projdata));
0143 for k = 1:length(projdata)
0144 fprintf(1,'\t\t%s (%d x %d)',projdata(k).desc, ...
0145 projdata(k).data.nrow,projdata(k).data.ncol);
0146 if projdata(k).active
0147 fprintf(1,' active\n');
0148 else
0149 fprintf(1,' idle\n');
0150 end
0151 end
0152 end
0153
0154
0155 return;
0156
0157 function [tag] = find_tag(node,findkind)
0158
0159 for p = 1:node.nent
0160 if node.dir(p).kind == findkind
0161 tag = fiff_read_tag(fid,node.dir(p).pos);
0162 return;
0163 end
0164 end
0165 tag = [];
0166 end
0167
0168
0169 end