0001 function [err_code, Basis_mode, pick, Qpick, Wsensor, V0, V, xx] = ...
0002 vb_basisparm_check(basis_parm, proj_root, abort_swt)
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
0041
0042
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
0051
0052
0053
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
0062
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
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
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
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
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
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
0154 [pick, Qpick, Wsensor, V0] = vb_load_sensor(meg_file);
0155
0156
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
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
0178 [V ,xx] = vb_load_cortex_area(brain_file,area_file,area_key,normal_mode);
0179 end
0180
0181
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
0198
0199
0200
0201
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
0224
0225
0226
0227 function result = inner_validate_coordtype(coordtype)
0228 APPROPRIATE_COORD_TYPE = {'SPM_RIGHT_M'};
0229 coordtype = upper(coordtype);
0230
0231
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
0249
0250
0251
0252