Home > vbmeg > functions > device > vb_loadspec_check.m

vb_loadspec_check

PURPOSE ^

check LoadSpec data

SYNOPSIS ^

function [loadspec, result] = vb_loadspec_check(loadspec, msrmntfile)

DESCRIPTION ^

 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)
            :               :  'MAG_X'     : Magnetometer OPM channel data toward X-axis (only QZFM device)
            :               :  'MAG_Y'     : Magnetometer OPM channel data toward Y-axis (only QZFM device)
            :               :  'MAG_Z'     : Magnetometer OPM channel data toward Z-axis (only QZFM device)
            :               :  '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
   2022-06-03 (k_suzuki) added OPM format

 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 [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 %            :               :  'MAG_X'     : Magnetometer OPM channel data toward X-axis (only QZFM device)
0022 %            :               :  'MAG_Y'     : Magnetometer OPM channel data toward Y-axis (only QZFM device)
0023 %            :               :  'MAG_Z'     : Magnetometer OPM channel data toward Z-axis (only QZFM device)
0024 %            :               :  'ALL'       : all the channels
0025 %            :               :  - case insensitive
0026 %            :  .Trigger : [Ntrigger x1 double] trigger list [1]
0027 %            :  .Pretrigger : [x1 double] number of sample before trigger [0]
0028 %            :  .Posttrigger : [x1 double] number of sample after trigger
0029 %            :    [(lenght of sample)-1]
0030 %            :  .TrialNumber : [x1 double] trial index list [all trial]
0031 %            :  .ActiveChannel : <<boolean>> active channel filter switch
0032 %            :                 :  if active channel is valid [true]
0033 %            :                 :  if active channel is invalid [false]
0034 %            :  .ActiveTrial   : <<boolean>> active trial filter switch
0035 %            :                 :  if active trial is valid [true]
0036 %            :                 :  if active trial is invalid [false]
0037 % msrmntfile : <required> <<file>> MEG-MAT or EEG-MAT file
0038 %
0039 % [output]
0040 %   loadspec : LoadSpec struct after check
0041 %     result : <<integer>> error code
0042 %            :  0) success
0043 %            :  1) error - bad msrmntfile
0044 %
0045 % [note]
0046 %   this function does not abort but return error code as 'result'
0047 %
0048 % [history]
0049 %   2008-02-29 (Sako) initial version
0050 %   2008-04-16 (Sako) added ActiveChannel field
0051 %   2008-04-28 (Sako) added loadtype
0052 %   2008-06-04 (Sako) changed default values of .ActiveChannel and .ActiveTrial
0053 %   2008-06-05 (Sako) added ChannelType field
0054 %   2009-07-14 (Sako) modified default value of .TrialNumber
0055 %   2009-07-24 (Sako) changed the default value of .ChannelType to 'ALL'
0056 %   2009-07-27 (Sako) modified ChannelType by using new vb_define_const
0057 %   2011-05-31 (Sako) modified to convert device character to be upper case
0058 %   2022-06-03 (k_suzuki) added OPM format
0059 %
0060 % Copyright (C) 2011, ATR All Rights Reserved.
0061 % License : New BSD License(see VBMEG_LICENSE.txt)
0062 
0063 % --- CHECK ARGUMENTS --- %
0064 if ~exist('loadspec', 'var'), loadspec = []; end
0065 if ~exist('msrmntfile', 'var'), msrmntfile = ''; end
0066 [loadspec, msrmntfile] = inner_check_arguments(loadspec, msrmntfile);
0067 
0068 % --- MAIN PROCEDURE --------------------------------------------------------- %
0069 %
0070 [measurement, device] = vb_load_device(msrmntfile);
0071 Measurement = upper(measurement);
0072 
0073 const = vb_define_const(Measurement);
0074 
0075 if isempty(loadspec.ChannelType)
0076     loadspec.ChannelType = const.DATA_TYPE_MAIN;
0077 end
0078 
0079 channel_name = [];
0080 
0081 % --- obtain basic information
0082 switch Measurement
0083     case 'MEG'
0084         switch device
0085             % SQUID-devices
0086             case {'YOKOGAWA', 'NEUROMAG'}
0087                 switch loadspec.ChannelType
0088                     case const.DATA_TYPE_MAIN
0089                         channel_name = vb_megfile_get_channel_label_meg(msrmntfile);
0090                     case const.DATA_TYPE_EXTRA
0091                         channel_name = vb_megfile_get_channel_label_extra(msrmntfile);
0092                     case const.DATA_TYPE_REFERENCE
0093                         channel_name = vb_megfile_get_channel_label_refmg(msrmntfile);
0094                     case const.DATA_TYPE_AXIAL
0095                         channel_name = vb_megfile_get_channel_label_axial(msrmntfile);
0096                     case const.DATA_TYPE_PLANAR
0097                         channel_name = vb_megfile_get_channel_label_planar(msrmntfile);
0098                     case const.DATA_TYPE_ALL
0099                         channel_name = vb_megfile_get_channel_label_whole(msrmntfile);
0100                 end
0101                 
0102             % OPM-device
0103             case 'QZFM'
0104                 switch loadspec.ChannelType
0105                     case const.DATA_TYPE_MAIN
0106                         channel_name = vb_megfile_get_channel_label_meg(msrmntfile);
0107                     case const.DATA_TYPE_EXTRA
0108                         channel_name = vb_megfile_get_channel_label_extra(msrmntfile);
0109                     case const.DATA_TYPE_REFERENCE
0110                         channel_name = vb_megfile_get_channel_label_refmg(msrmntfile);
0111                     case const.DATA_TYPE_MAG_X
0112                         channel_name = vb_megfile_get_channel_label_magx(msrmntfile);
0113                     case const.DATA_TYPE_MAG_Y
0114                         channel_name = vb_megfile_get_channel_label_magy(msrmntfile);
0115                     case const.DATA_TYPE_MAG_Z
0116                         channel_name = vb_megfile_get_channel_label_magz(msrmntfile);
0117                     case const.DATA_TYPE_ALL
0118                         channel_name = vb_megfile_get_channel_label_whole(msrmntfile);
0119                 end
0120         end
0121         
0122         % Common procedure for MEG
0123         meginfo = vb_megfile_load_meginfo(msrmntfile);
0124         trial_idx = vb_info_get_trial_data(meginfo, [], 'number');
0125         n_trial = vb_info_get_Nrepeat(meginfo);
0126         
0127     case 'EEG'
0128         eeginfo = vb_eegfile_load_eeginfo(msrmntfile);
0129         
0130         switch loadspec.ChannelType
0131             case const.DATA_TYPE_MAIN
0132                 channel_name = vb_eeginfo_get_channel_label(eeginfo);
0133             case const.DATA_TYPE_EXTRA
0134                 channel_name = vb_eeginfo_get_channel_label_extra(eeginfo);
0135             case const.DATA_TYPE_ALL
0136                 ch_name_eeg = vb_eeginfo_get_channel_label(eeginfo);
0137                 ch_name_ext = vb_eeginfo_get_channel_label_extra(eeginfo);
0138                 channel_name = [ch_name_eeg;ch_name_ext];
0139         end
0140         
0141         trial_idx = vb_info_get_trial_data(eeginfo, [], 'number');
0142         n_trial = vb_info_get_Nrepeat(eeginfo);
0143         
0144     otherwise
0145         error('(%s)unknown Measurement: %s', func_, Measurement);
0146 end
0147 % ----- ChannelType has been discarded
0148 
0149 % ----- (MEG/EEG) common procedure
0150 if ~isfield(loadspec, 'ChannelName') || isempty(loadspec.ChannelName)
0151     loadspec.ChannelName = channel_name;
0152 end
0153 
0154 if ~isfield(loadspec, 'ChannelSwitch') || isempty(loadspec.ChannelSwitch)
0155     loadspec.ChannelSwitch = true;
0156 end
0157 
0158 if n_trial > 1
0159     if ~isfield(loadspec, 'TrialNumber') || isempty(loadspec.TrialNumber)
0160         % --- all trials
0161         loadspec.TrialNumber = trial_idx;
0162     end
0163     
0164 elseif n_trial == 1
0165     loadspec.TrialNumber = [];
0166 end
0167 
0168 if ~isfield(loadspec, 'Trigger')
0169     loadspec.Trigger = [];
0170 end
0171 
0172 if ~isfield(loadspec, 'Pretrigger')
0173     loadspec.Pretrigger = [];
0174 end
0175 
0176 if ~isfield(loadspec, 'Posttrigger')
0177     loadspec.Posttrigger = [];
0178 end
0179 
0180 if ~isfield(loadspec, 'ActiveChannel') || isempty(loadspec.ActiveChannel)
0181     if vb_msrmnt_active_channel_is_valid(msrmntfile)
0182         loadspec.ActiveChannel = true;
0183     else
0184         loadspec.ActiveChannel = false;
0185     end
0186 end
0187 
0188 if ~isfield(loadspec, 'ActiveTrial') || isempty(loadspec.ActiveTrial)
0189     if vb_msrmnt_active_trial_is_valid(msrmntfile)
0190         loadspec.ActiveTrial = true;
0191     else
0192         loadspec.ActiveTrial = false;
0193     end
0194 end
0195 return;
0196 %
0197 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0198 
0199 
0200 % --- INNER FUNCTIONS -------------------------------------------------------- %
0201 %
0202 % --- inner_check_arguments()
0203 %
0204 function [loadspec, msrmntfile] = inner_check_arguments(loadspec, msrmntfile)
0205 func_ = mfilename;
0206 
0207 if isempty(msrmntfile)
0208     error('(%s)msrmntfile is a required parameter', func_);
0209 end
0210 
0211 if exist(msrmntfile, 'file') ~= 2
0212     error('(%s)cannot find msrmntfile: %s', func_, msrmntfile);
0213 end
0214 
0215 if isempty(loadspec) ...
0216         || ~isfield(loadspec, 'ChannelType')
0217     loadspec.ChannelType = '';
0218 end
0219 
0220 % --- for case insensitive
0221 if ~isempty(loadspec.ChannelType)
0222     loadspec.ChannelType = upper(loadspec.ChannelType);
0223 end
0224 return;
0225 %
0226 % --- end of inner_check_arguments()
0227 %
0228 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0229 
0230 % --- END OF FILE --- %

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