Home > vbmeg > external > mne > fiff_read_proj.m

fiff_read_proj

PURPOSE ^

SYNOPSIS ^

function [ projdata ] = fiff_read_proj(fid,node)

DESCRIPTION ^

 [ projdata ] = fiff_read_proj(fid,node)

 Read the SSP data under a given directory node

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ projdata ] = fiff_read_proj(fid,node)
0002 
0003 %
0004 % [ projdata ] = fiff_read_proj(fid,node)
0005 %
0006 % Read the SSP data under a given directory node
0007 %
0008 
0009 %
0010 %   Author : Matti Hamalainen, MGH Martinos Center
0011 %   License : BSD 3-clause
0012 %
0013 %
0014 %   Revision 1.7  2006/05/16 00:39:32  msh
0015 %   Fixed error in mne_ex_read_raw: All projection items were not activated.
0016 %   List the initial states of projection items when they are loaded.
0017 %
0018 %   Revision 1.6  2006/04/23 15:29:40  msh
0019 %   Added MGH to the copyright
0020 %
0021 %   Revision 1.5  2006/04/21 15:06:03  msh
0022 %   Do not list projection item status because it might be confusing.
0023 %
0024 %   Revision 1.4  2006/04/21 14:43:59  msh
0025 %   Report projection operators.
0026 %   Some more checks in raw data reading.
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/12 10:29:02  msh
0033 %   Made evoked data writing compatible with the structures returned in reading.
0034 %
0035 %   Revision 1.1  2006/04/10 23:26:54  msh
0036 %   Added fiff reading routines
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 %   Locate the projection data
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     %   Find all desired tags in one item
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     %   Use exactly the same fields in data as in a named matrix
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

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