Home > functions > leadfield > vb_basisparm_check.m

vb_basisparm_check

PURPOSE ^

check and read data from basis_parm

SYNOPSIS ^

function [err_code, Basis_mode, pick, Qpick, Wsensor, V0, V, xx] =vb_basisparm_check(basis_parm, proj_root, abort_swt)

DESCRIPTION ^

 check and read data from basis_parm
 [usage]
   [err_code, Basis_mode, pick, Qpick, Wsensor, V0, V, xx] = ...
     vb_basisparm_check(basis_parm, proj_root, abort_swt)
 [input]
   basis_parm : <required> <<struct>> 
    proj_root : <required> <<string>> path of read data file
    abort_swt : <optional> <<boolean>>
              :   true : if error occur, abort with error message
              : [false]: if error occur, return error code
 [output]
     err_code : error code
              : each bit means as follows
              :  0x00) no error
              :  0x01) basis_parm is empty
              :  0x02) proj_root is empty
              :  0x04) basis_parm.brain_file is invalid
              :  0x08) basis_parm.meg_file is invalid
              :  0x10) basis_parm.normal_mode is invalid
              :  0x20) basis_parm.Basis_mode is invalid
              :  0x40) basis_parm.area_key or area_file is invalid
              :  0x80) coordinate type of basis_parm.meg_file is improper
   Basis_mode : leadfield calculation mode
         pick : [Nch x 3] sensor coordinates
        Qpick : [Nch x 3] vector of each sensor coordinates
      Wsensor : on-off for double sensor of YOKOGAWA
           V0 : center of spherical model
            V : brain model
           xx : vector of brain model
 [note]
   if error occur, this program doesnot make abort, and return error code
 [history]
   2008-04-01 (Sako) initial version
   2008-10-15 Taku Yoshioka Support '.sensortype' parameter
   2010-01-29 (Sako) replaced vb_load_meg_info with vb_load_measurement_info

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [err_code, Basis_mode, pick, Qpick, Wsensor, V0, V, xx] = ...
0002   vb_basisparm_check(basis_parm, proj_root, abort_swt)
0003 % check and read data from basis_parm
0004 % [usage]
0005 %   [err_code, Basis_mode, pick, Qpick, Wsensor, V0, V, xx] = ...
0006 %     vb_basisparm_check(basis_parm, proj_root, abort_swt)
0007 % [input]
0008 %   basis_parm : <required> <<struct>>
0009 %    proj_root : <required> <<string>> path of read data file
0010 %    abort_swt : <optional> <<boolean>>
0011 %              :   true : if error occur, abort with error message
0012 %              : [false]: if error occur, return error code
0013 % [output]
0014 %     err_code : error code
0015 %              : each bit means as follows
0016 %              :  0x00) no error
0017 %              :  0x01) basis_parm is empty
0018 %              :  0x02) proj_root is empty
0019 %              :  0x04) basis_parm.brain_file is invalid
0020 %              :  0x08) basis_parm.meg_file is invalid
0021 %              :  0x10) basis_parm.normal_mode is invalid
0022 %              :  0x20) basis_parm.Basis_mode is invalid
0023 %              :  0x40) basis_parm.area_key or area_file is invalid
0024 %              :  0x80) coordinate type of basis_parm.meg_file is improper
0025 %   Basis_mode : leadfield calculation mode
0026 %         pick : [Nch x 3] sensor coordinates
0027 %        Qpick : [Nch x 3] vector of each sensor coordinates
0028 %      Wsensor : on-off for double sensor of YOKOGAWA
0029 %           V0 : center of spherical model
0030 %            V : brain model
0031 %           xx : vector of brain model
0032 % [note]
0033 %   if error occur, this program doesnot make abort, and return error code
0034 % [history]
0035 %   2008-04-01 (Sako) initial version
0036 %   2008-10-15 Taku Yoshioka Support '.sensortype' parameter
0037 %   2010-01-29 (Sako) replaced vb_load_meg_info with vb_load_measurement_info
0038 %
0039 % Copyright (C) 2011, ATR All Rights Reserved.
0040 % License : New BSD License(see VBMEG_LICENSE.txt)
0041 
0042 % --- CHECK ARGUMENTS --- %
0043 if ~exist('basis_parm', 'var'), basis_parm = []; end
0044 if ~exist('proj_root', 'var'), proj_root = ''; end
0045 if ~exist('abort_swt', 'var'), abort_swt = []; end
0046 err_code = 0;
0047 [err_code, basis_parm, proj_root, ABORT] = ...
0048   inner_check_arguments(err_code, basis_parm, proj_root, abort_swt);
0049 
0050 % --- MAIN PROCEDURE --------------------------------------------------------- %
0051 %
0052 
0053 % ----- CONSTANTS
0054 EC_BRAINFILE  = 4;
0055 EC_MEGFILE    = 8;
0056 EC_NORMALMODE = 16;
0057 EC_BASISMODE  = 32;
0058 EC_AREA       = 64;
0059 EC_COORDTYPE  = 128;
0060 
0061 % ----- required fields of basis_parm
0062 % ----- brain_file
0063 if ~isfield(basis_parm, 'brain_file')
0064   if ABORT
0065     error('brain_file is a required field of basis_parm');
0066   end;
0067   basis_parm.brain_file = '';
0068   err_code = bitor(err_code, EC_BRAINFILE);
0069 end
0070 
0071 % ----- meg_file
0072 if ~isfield(basis_parm, 'meg_file')
0073   if ABORT
0074     error('meg_file is a required field of basis_parm');
0075   end
0076   basis_parm.meg_file = '';
0077   err_code = bitor(err_code, EC_MEGFILE);
0078 end
0079 
0080 % ----- normal_mode
0081 if ~isfield(basis_parm, 'normal_mode')
0082   if ABORT
0083     error('normal_mode is a required field of basis_parm');
0084   end
0085   basis_parm.normal_mode = [];
0086   err_code = bitor(err_code, EC_NORMALMODE);
0087 end
0088 
0089 if ~isfield(basis_parm, 'Basis_mode')
0090   if ABORT
0091     error('Basis_mode is a required field of basis_parm');
0092   end
0093   basis_parm.Basis_mode = [];
0094   err_code = bitor(err_code, EC_BASISMODE);
0095 end
0096 
0097 % ----- optional fields of basis_parm
0098 if ~isfield(basis_parm, 'area_file')
0099     basis_parm.area_file = '';
0100 end;
0101 
0102 if ~isfield(basis_parm, 'area_key')
0103     basis_parm.area_key = '';
0104 end
0105 
0106 % ----- check as file
0107 if ~isempty(basis_parm.brain_file)
0108   brain_file = [proj_root filesep basis_parm.brain_file];
0109 
0110   if exist(brain_file, 'file') ~= 2
0111     if ABORT
0112       error('cannot read brain_file : ''%s''', brain_file)
0113     end
0114     err_code = bitor(err_code, EC_BRAINFILE);
0115     brain_file = '';
0116   end
0117 else
0118   brain_file = '';
0119 end
0120 
0121 area_file  = [proj_root filesep basis_parm.area_file ];
0122 if ~isempty(basis_parm.area_key) && isempty(basis_parm.area_file)
0123   if ABORT
0124     error('area_file is a required if area_key is specified');
0125   end
0126   err_code = bitor(err_code, EC_AREA);
0127 end
0128 
0129 if ~isempty(basis_parm.area_file) && exist(area_file, 'file') ~= 2
0130   if ABORT
0131     error('cannot read area_file : ''%s''', area_file);
0132   end
0133   err_code = bitor(err_code, EC_AREA);
0134   area_file = '';
0135 end
0136 
0137 pick = [];
0138 Qpick = [];
0139 Wsensor = [];
0140 V0 = [];
0141 V = [];
0142 xx = [];
0143 
0144 % ----- MEG_FILE
0145 if ~isempty(basis_parm.meg_file)
0146   meg_file   = [proj_root filesep basis_parm.meg_file];
0147   if exist(meg_file, 'file') ~= 2
0148     if ABORT
0149       error('cannot read meg_file : ''%s''', meg_file);
0150     end
0151     err_code = bitor(err_code, EC_MEGFILE);
0152   else
0153     % Load sensor info
0154     [pick, Qpick, Wsensor, V0] = vb_load_sensor(meg_file);
0155 
0156     % ----- coordinate type of meg_file
0157     coordtype = vb_msrmnt_load_coordtype(meg_file);
0158     if ~inner_validate_coordtype(coordtype)
0159       if ABORT
0160         error('invalid coordtype');
0161       end
0162       err_code = bitor(err_code, EC_COORDTYPE);
0163     end
0164   end
0165 end
0166 
0167 % basis_parm.Vcenter has priority over Vcenter of megfile
0168 if isfield(basis_parm, 'Vcenter') && ~isempty(basis_parm.Vcenter)
0169   V0 = basis_parm.Vcenter;
0170 end
0171 
0172 Basis_mode  = basis_parm.Basis_mode;
0173 area_key    = basis_parm.area_key;
0174 normal_mode = basis_parm.normal_mode;
0175 
0176 if ~isempty(brain_file) && ~isempty(area_file)
0177   % Load cortical vertex coordinate and normal vector
0178   [V ,xx] = vb_load_cortex_area(brain_file,area_file,area_key,normal_mode);
0179 end
0180 
0181 % Select channel (2008-11-27 Taku Yoshioka)
0182 if ~isfield(basis_parm,'sensortype'), 
0183   basis_parm.sensortype = [];
0184 end
0185 sensortype = basis_parm.sensortype;
0186 if ~isempty(sensortype), 
0187   MEGinfo = vb_load_measurement_info(meg_file);
0188   ix_sensor = find(MEGinfo.ChannelInfo.Type==sensortype);
0189   ix_sensor2 = [ix_sensor; ix_sensor+length(ix_sensor)];
0190   pick = pick(ix_sensor2,:);
0191   Qpick = Qpick(ix_sensor2,:);
0192   Wsensor = Wsensor(ix_sensor,ix_sensor2);
0193 end
0194 
0195 return;
0196 %
0197 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0198 
0199 % --- INNER FUNCTIONS -------------------------------------------------------- %
0200 %
0201 % --- inner_check_arguments()
0202 %
0203 function [err_code, basis_parm, proj_root, abort_swt] = ...
0204   inner_check_arguments(err_code, basis_parm, proj_root, abort_swt)
0205 
0206 if isempty(abort_swt), abort_swt = false; end
0207 
0208 if abort_swt
0209   func_ = mfilename;
0210   if isempty(basis_parm)
0211     error('(%s)basis_parm is a required parameter', func_);
0212   end
0213 
0214   if isempty(proj_root)
0215     error('(%s)proj_root is a required parameter', func_);
0216   end
0217 else
0218   if isempty(basis_parm),  err_code = bitor(err_code, 1); end
0219   if isempty(proj_root),   err_code = bitor(err_code, 2); end
0220 end
0221 return;
0222 %
0223 % --- end of inner_check_arguments()
0224 
0225 % --- inner_validate_coordtype()
0226 %
0227 function result = inner_validate_coordtype(coordtype)
0228 APPROPRIATE_COORD_TYPE = {'SPM_RIGHT_M'}; % ignore the case
0229 coordtype = upper(coordtype);
0230 %
0231 % --- empty means O.K.
0232 %
0233 if isempty(coordtype)
0234   result = true;
0235   return;
0236 end
0237 
0238 type_len = length(APPROPRIATE_COORD_TYPE);
0239 for i_type = 1:type_len
0240   if strcmp(APPROPRIATE_COORD_TYPE(i_type), coordtype)
0241     result = true;
0242     return;
0243   end
0244 end
0245 result = false;
0246 return;
0247 %
0248 % --- end of inner_validate_coordtype()
0249 %
0250 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0251 
0252 %%% END OF FILE %%%

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005