check LoadSpec data [usage] [loadspec, result] = vb_loadspec_check(loadspec, msrmntfile) [input] loadspec : <optional> <<struct>> LoadSpec : .ChannelName : {Nch x 1 cell} channel name list : [all channels] : .ChannelSwitch : <<boolean>> ChannelName role : [true] ) to read : false ) to omit : .ChannelType : <optional> <<string>> channel type ['MEG(EEG)'] : : 'MEG' : MEG channel data : : 'EEG' : MEG channel data : : 'EXTRA' : extra channel data : : 'REFERENCE' : reference channel data (only MEG) : : 'AXIAL' : AxialGradioMeter (only MEG) : : 'PLANAR' : PlanarGradioMeter (only MEG) : : 'ALL' : all the channels : : - case insensitive : .Trigger : [Ntrigger x1 double] trigger list [1] : .Pretrigger : [x1 double] number of sample before trigger [0] : .Posttrigger : [x1 double] number of sample after trigger : [(lenght of sample)-1] : .TrialNumber : [x1 double] trial index list [all trial] : .ActiveChannel : <<boolean>> active channel filter switch : : if active channel is valid [true] : : if active channel is invalid [false] : .ActiveTrial : <<boolean>> active trial filter switch : : if active trial is valid [true] : : if active trial is invalid [false] msrmntfile : <required> <<file>> MEG-MAT or EEG-MAT file [output] loadspec : LoadSpec struct after check result : <<integer>> error code : 0) success : 1) error - bad msrmntfile [note] this function does not abort but return error code as 'result' [history] 2008-02-29 (Sako) initial version 2008-04-16 (Sako) added ActiveChannel field 2008-04-28 (Sako) added loadtype 2008-06-04 (Sako) changed default values of .ActiveChannel and .ActiveTrial 2008-06-05 (Sako) added ChannelType field 2009-07-14 (Sako) modified default value of .TrialNumber 2009-07-24 (Sako) changed the default value of .ChannelType to 'ALL' 2009-07-27 (Sako) modified ChannelType by using new vb_define_const 2011-05-31 (Sako) modified to convert device character to be upper case Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [loadspec, result] = vb_loadspec_check(loadspec, msrmntfile) 0002 % check LoadSpec data 0003 % 0004 % [usage] 0005 % [loadspec, result] = vb_loadspec_check(loadspec, msrmntfile) 0006 % 0007 % [input] 0008 % loadspec : <optional> <<struct>> LoadSpec 0009 % : .ChannelName : {Nch x 1 cell} channel name list 0010 % : [all channels] 0011 % : .ChannelSwitch : <<boolean>> ChannelName role 0012 % : [true] ) to read 0013 % : false ) to omit 0014 % : .ChannelType : <optional> <<string>> channel type ['MEG(EEG)'] 0015 % : : 'MEG' : MEG channel data 0016 % : : 'EEG' : MEG channel data 0017 % : : 'EXTRA' : extra channel data 0018 % : : 'REFERENCE' : reference channel data (only MEG) 0019 % : : 'AXIAL' : AxialGradioMeter (only MEG) 0020 % : : 'PLANAR' : PlanarGradioMeter (only MEG) 0021 % : : 'ALL' : all the channels 0022 % : : - case insensitive 0023 % : .Trigger : [Ntrigger x1 double] trigger list [1] 0024 % : .Pretrigger : [x1 double] number of sample before trigger [0] 0025 % : .Posttrigger : [x1 double] number of sample after trigger 0026 % : [(lenght of sample)-1] 0027 % : .TrialNumber : [x1 double] trial index list [all trial] 0028 % : .ActiveChannel : <<boolean>> active channel filter switch 0029 % : : if active channel is valid [true] 0030 % : : if active channel is invalid [false] 0031 % : .ActiveTrial : <<boolean>> active trial filter switch 0032 % : : if active trial is valid [true] 0033 % : : if active trial is invalid [false] 0034 % msrmntfile : <required> <<file>> MEG-MAT or EEG-MAT file 0035 % 0036 % [output] 0037 % loadspec : LoadSpec struct after check 0038 % result : <<integer>> error code 0039 % : 0) success 0040 % : 1) error - bad msrmntfile 0041 % 0042 % [note] 0043 % this function does not abort but return error code as 'result' 0044 % 0045 % [history] 0046 % 2008-02-29 (Sako) initial version 0047 % 2008-04-16 (Sako) added ActiveChannel field 0048 % 2008-04-28 (Sako) added loadtype 0049 % 2008-06-04 (Sako) changed default values of .ActiveChannel and .ActiveTrial 0050 % 2008-06-05 (Sako) added ChannelType field 0051 % 2009-07-14 (Sako) modified default value of .TrialNumber 0052 % 2009-07-24 (Sako) changed the default value of .ChannelType to 'ALL' 0053 % 2009-07-27 (Sako) modified ChannelType by using new vb_define_const 0054 % 2011-05-31 (Sako) modified to convert device character to be upper case 0055 % 0056 % Copyright (C) 2011, ATR All Rights Reserved. 0057 % License : New BSD License(see VBMEG_LICENSE.txt) 0058 0059 % --- CHECK ARGUMENTS --- % 0060 if ~exist('loadspec', 'var'), loadspec = []; end 0061 if ~exist('msrmntfile', 'var'), msrmntfile = ''; end 0062 [loadspec, msrmntfile] = inner_check_arguments(loadspec, msrmntfile); 0063 0064 % --- MAIN PROCEDURE --------------------------------------------------------- % 0065 % 0066 [measurement] = vb_load_device(msrmntfile); 0067 Measurement = upper(measurement); 0068 0069 const = vb_define_const(Measurement); 0070 0071 if isempty(loadspec.ChannelType) 0072 loadspec.ChannelType = const.DATA_TYPE_MAIN; 0073 end 0074 0075 channel_name = []; 0076 0077 % --- obtain basic information 0078 switch Measurement 0079 case 'MEG' 0080 0081 switch loadspec.ChannelType 0082 case const.DATA_TYPE_MAIN 0083 channel_name = vb_megfile_get_channel_label_meg(msrmntfile); 0084 case const.DATA_TYPE_EXTRA 0085 channel_name = vb_megfile_get_channel_label_extra(msrmntfile); 0086 case const.DATA_TYPE_REFERENCE 0087 channel_name = vb_megfile_get_channel_label_refmg(msrmntfile); 0088 case const.DATA_TYPE_ALL 0089 channel_name = vb_megfile_get_channel_label_whole(msrmntfile); 0090 end 0091 0092 meginfo = vb_megfile_load_meginfo(msrmntfile); 0093 trial_idx = vb_info_get_trial_data(meginfo, [], 'number'); 0094 n_trial = vb_info_get_Nrepeat(meginfo); 0095 0096 case 'EEG' 0097 eeginfo = vb_eegfile_load_eeginfo(msrmntfile); 0098 0099 switch loadspec.ChannelType 0100 case const.DATA_TYPE_MAIN 0101 channel_name = vb_eeginfo_get_channel_label(eeginfo); 0102 case const.DATA_TYPE_EXTRA 0103 channel_name = vb_eeginfo_get_channel_label_extra(eeginfo); 0104 case const.DATA_TYPE_ALL 0105 ch_name_eeg = vb_eeginfo_get_channel_label(eeginfo); 0106 ch_name_ext = vb_eeginfo_get_channel_label_extra(eeginfo); 0107 channel_name = [ch_name_eeg;ch_name_ext]; 0108 end 0109 0110 trial_idx = vb_info_get_trial_data(eeginfo, [], 'number'); 0111 n_trial = vb_info_get_Nrepeat(eeginfo); 0112 0113 otherwise 0114 error('(%s)unknown Measurement: %s', func_, Measurement); 0115 end 0116 % ----- ChannelType has been discarded 0117 0118 % ----- (MEG/EEG) common procedure 0119 if ~isfield(loadspec, 'ChannelName') || isempty(loadspec.ChannelName) 0120 loadspec.ChannelName = channel_name; 0121 end 0122 0123 if ~isfield(loadspec, 'ChannelSwitch') || isempty(loadspec.ChannelSwitch) 0124 loadspec.ChannelSwitch = true; 0125 end 0126 0127 if n_trial > 1 0128 if ~isfield(loadspec, 'TrialNumber') || isempty(loadspec.TrialNumber) 0129 % --- all trials 0130 loadspec.TrialNumber = trial_idx; 0131 end 0132 0133 elseif n_trial == 1 0134 loadspec.TrialNumber = []; 0135 end 0136 0137 if ~isfield(loadspec, 'Trigger') 0138 loadspec.Trigger = []; 0139 end 0140 0141 if ~isfield(loadspec, 'Pretrigger') 0142 loadspec.Pretrigger = []; 0143 end 0144 0145 if ~isfield(loadspec, 'Posttrigger') 0146 loadspec.Posttrigger = []; 0147 end 0148 0149 if ~isfield(loadspec, 'ActiveChannel') || isempty(loadspec.ActiveChannel) 0150 if vb_msrmnt_active_channel_is_valid(msrmntfile) 0151 loadspec.ActiveChannel = true; 0152 else 0153 loadspec.ActiveChannel = false; 0154 end 0155 end 0156 0157 if ~isfield(loadspec, 'ActiveTrial') || isempty(loadspec.ActiveTrial) 0158 if vb_msrmnt_active_trial_is_valid(msrmntfile) 0159 loadspec.ActiveTrial = true; 0160 else 0161 loadspec.ActiveTrial = false; 0162 end 0163 end 0164 return; 0165 % 0166 % --- END OF MAIN PROCEDURE -------------------------------------------------- % 0167 0168 0169 % --- INNER FUNCTIONS -------------------------------------------------------- % 0170 % 0171 % --- inner_check_arguments() 0172 % 0173 function [loadspec, msrmntfile] = inner_check_arguments(loadspec, msrmntfile) 0174 func_ = mfilename; 0175 0176 if isempty(msrmntfile) 0177 error('(%s)msrmntfile is a required parameter', func_); 0178 end 0179 0180 if exist(msrmntfile, 'file') ~= 2 0181 error('(%s)cannot find msrmntfile: %s', func_, msrmntfile); 0182 end 0183 0184 if isempty(loadspec) ... 0185 || ~isfield(loadspec, 'ChannelType') 0186 loadspec.ChannelType = ''; 0187 end 0188 0189 % --- for case insensitive 0190 if ~isempty(loadspec.ChannelType) 0191 loadspec.ChannelType = upper(loadspec.ChannelType); 0192 end 0193 return; 0194 % 0195 % --- end of inner_check_arguments() 0196 % 0197 % --- END OF INNER FUNCTIONS ------------------------------------------------- % 0198 0199 % --- END OF FILE --- %