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 = 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
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
0159 [pick, Qpick, Wsensor, V0] = vb_load_sensor(meg_file);
0160
0161
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
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
0183 [V, xx] = vb_load_cortex_area(brain_file,area_file,area_key,normal_mode,'subj');
0184 end
0185
0186
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
0203
0204
0205
0206
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
0225
0226
0227
0228 function result = inner_validate_coordtype(coordtype)
0229 APPROPRIATE_COORD_TYPE = {'SPM_RIGHT_M'};
0230 coordtype = upper(coordtype);
0231
0232
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
0250
0251
0252
0253