Home > vbmeg > external > mne > fiff_read_ctf_comp.m

fiff_read_ctf_comp

PURPOSE ^

SYNOPSIS ^

function [ compdata ] = fiff_read_ctf_comp(fid,node,chs)

DESCRIPTION ^

 [ compdata ] = fiff_read_ctf_comp(fid,node,chs)

 Read the CTF software compensation data from the given node

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ compdata ] = fiff_read_ctf_comp(fid,node,chs)
0002 
0003 %
0004 % [ compdata ] = fiff_read_ctf_comp(fid,node,chs)
0005 %
0006 % Read the CTF software compensation data from the given node
0007 %
0008 
0009 
0010 %
0011 %   Author : Matti Hamalainen, MGH Martinos Center
0012 %   License : BSD 3-clause
0013 %
0014 %
0015 %   Revision 1.8  2007/11/13 10:55:32  msh
0016 %   Specify the second argument to all calls to the exist function
0017 %
0018 %   Revision 1.7  2006/09/25 19:48:16  msh
0019 %   Added projection item kinds to fiff_define_constants
0020 %   Changed some fields to int32 in surface structures
0021 %
0022 %   Revision 1.6  2006/08/09 15:22:51  msh
0023 %   Removed debug printout.
0024 %
0025 %   Revision 1.5  2006/06/22 21:22:46  msh
0026 %   Take into account the possibility of calibrated compensation matrices
0027 %
0028 %   Revision 1.4  2006/04/23 15:29:40  msh
0029 %   Added MGH to the copyright
0030 %
0031 %   Revision 1.3  2006/04/18 20:44:46  msh
0032 %   Added reading of forward solution.
0033 %   Use length instead of size when appropriate
0034 %
0035 %   Revision 1.2  2006/04/12 10:29:02  msh
0036 %   Made evoked data writing compatible with the structures returned in reading.
0037 %
0038 %   Revision 1.1  2006/04/10 23:26:54  msh
0039 %   Added fiff reading routines
0040 %
0041 %
0042 
0043 global FIFF;
0044 if isempty(FIFF)
0045     FIFF = fiff_define_constants();
0046 end
0047 
0048 me='MNE:fiff_read_ctf_comp';
0049 
0050 if nargin ~= 3
0051     error(me,'Incorrect number of arguments');
0052 end
0053 
0054 compdata = struct('ctfkind',{},'kind',{},'save_calibrated',{},'rowcals',{},'colcals',{},'data',{});
0055 comps = fiff_dir_tree_find(node,FIFF.FIFFB_MNE_CTF_COMP_DATA);
0056 
0057 for k = 1:length(comps)
0058     node = comps(k);
0059     %
0060     %   Read the data we need
0061     %
0062     mat  = fiff_read_named_matrix(fid,node,FIFF.FIFF_MNE_CTF_COMP_DATA);
0063     for p = 1:node.nent
0064         kind = node.dir(p).kind;
0065         pos  = node.dir(p).pos;
0066         if kind == FIFF.FIFF_MNE_CTF_COMP_KIND
0067             tag = fiff_read_tag(fid,pos);
0068             break;
0069         end
0070     end
0071     if ~exist('tag','var')
0072         error(me,'Compensation type not found');
0073     end
0074     %
0075     %   Get the compensation kind and map it to a simple number
0076     %
0077     one.ctfkind = tag.data;
0078     clear('tag');
0079     one.kind    = int32(-1);
0080     if one.ctfkind     == hex2dec('47314252')
0081         one.kind = int32(1);
0082     elseif one.ctfkind == hex2dec('47324252')
0083         one.kind = int32(2);
0084     elseif one.ctfkind == hex2dec('47334252')
0085         one.kind = int32(3);
0086     else
0087         one.kind = one.ctfkind;
0088     end
0089     for p = 1:node.nent
0090         kind = node.dir(p).kind;
0091         pos  = node.dir(p).pos;
0092         if kind == FIFF.FIFF_MNE_CTF_COMP_CALIBRATED
0093             tag = fiff_read_tag(fid,pos);
0094             break;
0095         end
0096     end
0097     if ~exist('tag','var')
0098         calibrated = false;
0099     else
0100         calibrated = tag.data;
0101     end
0102     one.save_calibrated = calibrated;
0103     one.rowcals = ones(1,size(mat.data,1));
0104     one.colcals = ones(1,size(mat.data,2));
0105     if ~calibrated
0106         %
0107         %   Calibrate...
0108         %
0109         %
0110         %   Do the columns first
0111         %
0112         for p  = 1:length(chs)
0113             ch_names{p} = chs(p).ch_name;
0114         end
0115         for col = 1:size(mat.data,2)
0116             p = strmatch(mat.col_names{col},ch_names,'exact');
0117             if isempty(p)
0118                 error(me,'Channel %s is not available in data',mat.col_names{col});
0119             elseif length(p) > 1
0120                 error(me,'Ambiguous channel %s',mat.col_names{col});
0121             end
0122             col_cals(col) = 1.0/(chs(p).range*chs(p).cal);
0123         end
0124         %
0125         %    Then the rows
0126         %
0127         for row = 1:size(mat.data,1)
0128             p = strmatch(mat.row_names{row},ch_names,'exact');
0129             if isempty(p)
0130                 error(me,'Channel %s is not available in data',mat.row_names{row});
0131             elseif length(p) > 1
0132                 error(me,'Ambiguous channel %s',mat.row_names{row});
0133             end
0134             row_cals(row) = chs(p).range*chs(p).cal;
0135         end
0136         mat.data            = diag(row_cals)*mat.data*diag(col_cals);
0137         one.rowcals         = row_cals;
0138         one.colcals         = col_cals;
0139     end
0140     one.data       = mat;
0141     compdata(k)    = one;
0142     clear('row_cals');
0143     clear('col_cals');
0144 end
0145 
0146 if length(compdata) > 0
0147     fprintf(1,'\tRead %d compensation matrices\n',length(compdata));
0148 end
0149 
0150 return;
0151 
0152 end
0153

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