Home > vbmeg > 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 = fullfile(proj_root, 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 if ~isempty(basis_parm.area_file)
0122     area_file = fullfile(proj_root, basis_parm.area_file);
0123 else
0124     area_file = '';
0125 end
0126 
0127 if ~isempty(basis_parm.area_key) && isempty(basis_parm.area_file)
0128   if ABORT
0129     error('area_file is a required if area_key is specified');
0130   end
0131   err_code = bitor(err_code, EC_AREA);
0132 end
0133 
0134 if ~isempty(basis_parm.area_file) && exist(area_file, 'file') ~= 2
0135   if ABORT
0136     error('cannot read area_file : ''%s''', area_file);
0137   end
0138   err_code = bitor(err_code, EC_AREA);
0139   area_file = '';
0140 end
0141 
0142 pick = [];
0143 Qpick = [];
0144 Wsensor = [];
0145 V0 = [];
0146 V = [];
0147 xx = [];
0148 
0149 % ----- MEG_FILE
0150 if ~isempty(basis_parm.meg_file)
0151   meg_file   = fullfile(proj_root, basis_parm.meg_file);
0152   if exist(meg_file, 'file') ~= 2
0153     if ABORT
0154       error('cannot read meg_file : ''%s''', meg_file);
0155     end
0156     err_code = bitor(err_code, EC_MEGFILE);
0157   else
0158     % Load sensor info
0159     [pick, Qpick, Wsensor, V0] = vb_load_sensor(meg_file);
0160 
0161     % ----- coordinate type of meg_file
0162     coordtype = vb_msrmnt_load_coordtype(meg_file);
0163     if ~inner_validate_coordtype(coordtype)
0164       if ABORT
0165         error('invalid coordtype');
0166       end
0167       err_code = bitor(err_code, EC_COORDTYPE);
0168     end
0169   end
0170 end
0171 
0172 % basis_parm.Vcenter has priority over Vcenter of megfile
0173 if isfield(basis_parm, 'Vcenter') && ~isempty(basis_parm.Vcenter)
0174   V0 = basis_parm.Vcenter;
0175 end
0176 
0177 Basis_mode  = basis_parm.Basis_mode;
0178 area_key    = basis_parm.area_key;
0179 normal_mode = basis_parm.normal_mode;
0180 
0181 if ~isempty(brain_file)
0182   % Load cortical vertex coordinate and normal vector
0183   [V, xx] = vb_load_cortex_area(brain_file,area_file,area_key,normal_mode,'subj');
0184 end
0185 
0186 % Select channel (2008-11-27 Taku Yoshioka)
0187 if ~isfield(basis_parm,'sensortype'), 
0188   basis_parm.sensortype = [];
0189 end
0190 sensortype = basis_parm.sensortype;
0191 if ~isempty(sensortype), 
0192   MEGinfo = vb_load_measurement_info(meg_file);
0193   ix_sensor = find(MEGinfo.ChannelInfo.Type==sensortype);
0194   ix_sensor2 = [ix_sensor; ix_sensor+length(ix_sensor)];
0195   pick = pick(ix_sensor2,:);
0196   Qpick = Qpick(ix_sensor2,:);
0197   Wsensor = Wsensor(ix_sensor,ix_sensor2);
0198 end
0199 
0200 return;
0201 %
0202 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0203 
0204 % --- INNER FUNCTIONS -------------------------------------------------------- %
0205 %
0206 % --- inner_check_arguments()
0207 %
0208 function [err_code, basis_parm, proj_root, abort_swt] = ...
0209   inner_check_arguments(err_code, basis_parm, proj_root, abort_swt)
0210 
0211 if isempty(abort_swt), abort_swt = false; end
0212 
0213 if abort_swt
0214   func_ = mfilename;
0215   if isempty(basis_parm)
0216     error('(%s)basis_parm is a required parameter', func_);
0217   end
0218 
0219 else
0220   if isempty(basis_parm),  err_code = bitor(err_code, 1); end
0221 end
0222 return;
0223 %
0224 % --- end of inner_check_arguments()
0225 
0226 % --- inner_validate_coordtype()
0227 %
0228 function result = inner_validate_coordtype(coordtype)
0229 APPROPRIATE_COORD_TYPE = {'SPM_RIGHT_M'}; % ignore the case
0230 coordtype = upper(coordtype);
0231 %
0232 % --- empty means O.K.
0233 %
0234 if isempty(coordtype)
0235   result = true;
0236   return;
0237 end
0238 
0239 type_len = length(APPROPRIATE_COORD_TYPE);
0240 for i_type = 1:type_len
0241   if strcmp(APPROPRIATE_COORD_TYPE(i_type), coordtype)
0242     result = true;
0243     return;
0244   end
0245 end
0246 result = false;
0247 return;
0248 %
0249 % --- end of inner_validate_coordtype()
0250 %
0251 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0252 
0253 %%% END OF FILE %%%

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