Home > vbmeg > functions > common > loadfunc > subdirectory > vb_load_channel_info.m

vb_load_channel_info

PURPOSE ^

return channel information

SYNOPSIS ^

function [ch_info] = vb_load_channel_info(datafile, ch_class, ch_user)

DESCRIPTION ^

 return channel information
 [usage]
   [ch_info] = vb_load_channel_info(datafile, ch_class, ch_user)
 [input]
   datafile : <required> <<file>> meg.mat or eeg.mat file
   ch_class : <optional> channel class to load ['MEG(EEG)']
            :  *** Except for YOKOGAWA, this parameter is invalid. ***
            :  You can demand "channel class" by two ways.
            :  1) <<string>> the defined key words
            :     'MEG'|'EEG'|'EXTRA'|'REFERENCE'|'ALL'|'MAG'|'AXIAL'|'PLANAR'|
                  'MAG_X'|'MAG_Y'|'MAG_Z'|'USER'
            :  2) <<numeric>> channel types defined by device
    ch_user : <conditionally required> channel list you want, Name or ID.
            :  {n_channel x 1}(Name) or [n_channel x 1](ID)
            :  If ch_class is 'USER', this is required.
            :  If ch_class is not 'USER', this is ignored.
            :  is numerical list ------> ID list
            :  is not numerical list --> Name list
 [output]
    ch_info : <<struct>> the fields are as follows:
            :  .Active : list of active flag   [Nchannel x 1 boolean]
            :  .Name   : list of channel label {Nchannel x 1}
            :  .ID     : list of channel index [Nchannel x 1]
            :  .Type   : list of channel type  [Nchannel x 1]

 [note]
   @see vb_info_make_channel_info.m
 [history]
   2009-07-27 (Sako) initial version
   2009-08-19 (Sako) modified to make data without ChannelInfo field
   2009-10-13 (Sako) modified help
   2009-10-14 (Sako) added 'USER' type
   2011-06-01 (Sako) converted return values of vb_load_device to upper case
   2018-08-28 (rhayashi) ch_class 'MAG' is supported.
   2022-06-03 (k_suzuki) ch_class 'MAG_X', 'MAG_Y', 'MAG_Z' are supported
   2022-06-20 (k_suzuki) corrected a bug when measurement of datafile is '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 [ch_info] = vb_load_channel_info(datafile, ch_class, ch_user)
0002 % return channel information
0003 % [usage]
0004 %   [ch_info] = vb_load_channel_info(datafile, ch_class, ch_user)
0005 % [input]
0006 %   datafile : <required> <<file>> meg.mat or eeg.mat file
0007 %   ch_class : <optional> channel class to load ['MEG(EEG)']
0008 %            :  *** Except for YOKOGAWA, this parameter is invalid. ***
0009 %            :  You can demand "channel class" by two ways.
0010 %            :  1) <<string>> the defined key words
0011 %            :     'MEG'|'EEG'|'EXTRA'|'REFERENCE'|'ALL'|'MAG'|'AXIAL'|'PLANAR'|
0012 %                  'MAG_X'|'MAG_Y'|'MAG_Z'|'USER'
0013 %            :  2) <<numeric>> channel types defined by device
0014 %    ch_user : <conditionally required> channel list you want, Name or ID.
0015 %            :  {n_channel x 1}(Name) or [n_channel x 1](ID)
0016 %            :  If ch_class is 'USER', this is required.
0017 %            :  If ch_class is not 'USER', this is ignored.
0018 %            :  is numerical list ------> ID list
0019 %            :  is not numerical list --> Name list
0020 % [output]
0021 %    ch_info : <<struct>> the fields are as follows:
0022 %            :  .Active : list of active flag   [Nchannel x 1 boolean]
0023 %            :  .Name   : list of channel label {Nchannel x 1}
0024 %            :  .ID     : list of channel index [Nchannel x 1]
0025 %            :  .Type   : list of channel type  [Nchannel x 1]
0026 %
0027 % [note]
0028 %   @see vb_info_make_channel_info.m
0029 % [history]
0030 %   2009-07-27 (Sako) initial version
0031 %   2009-08-19 (Sako) modified to make data without ChannelInfo field
0032 %   2009-10-13 (Sako) modified help
0033 %   2009-10-14 (Sako) added 'USER' type
0034 %   2011-06-01 (Sako) converted return values of vb_load_device to upper case
0035 %   2018-08-28 (rhayashi) ch_class 'MAG' is supported.
0036 %   2022-06-03 (k_suzuki) ch_class 'MAG_X', 'MAG_Y', 'MAG_Z' are supported
0037 %   2022-06-20 (k_suzuki) corrected a bug when measurement of datafile is '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('datafile', 'var'), datafile = ''; end
0044 if ~exist('ch_class', 'var'), ch_class = []; end
0045 if ~exist('ch_user', 'var'), ch_user = []; end
0046 [datafile, ch_class, ch_user] = ...
0047   inner_check_arguments(datafile, ch_class, ch_user);
0048 
0049 % --- MAIN PROCEDURE --------------------------------------------------------- %
0050 %
0051 info = vb_load_measurement_info(datafile);
0052 if ~isfield(info, 'ChannelInfo')
0053   measurement = vb_load_device(datafile);
0054   info.ChannelInfo = vb_info_make_channel_info(info, measurement);
0055 end
0056 
0057 if isempty(ch_class)
0058   % only info of ChannelInfo
0059   ch_info = vb_info_get_channel_info(info, 0);
0060   return;
0061 end
0062 
0063 % --- with extracting conditions
0064 measurement = vb_load_device(datafile);
0065 
0066 % If Measurement of datafile is 'INFO', then use Measurement of 1st file in INFO file
0067 if strcmp(measurement, 'INFO')
0068     M = load(datafile, 'fileinfo');
0069     measurement = vb_load_device(M.fileinfo.filename{1});
0070 end
0071 
0072 if ischar(ch_class)
0073   ch_info = inner_extract_channel_by_name(info, measurement, ch_class, ch_user);
0074 else
0075   ch_info = inner_extract_channel_by_type(info, measurement, ch_class);
0076 end
0077 %
0078 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0079 
0080 % --- INNER FUNCTIONS -------------------------------------------------------- %
0081 %
0082 % --- inner_check_arguments()
0083 %
0084 function [datafile, ch_class, ch_user] = ...
0085   inner_check_arguments(datafile, ch_class, ch_user)
0086 func_ = mfilename;
0087 
0088 if isempty(datafile)
0089   error('(%s) datafile is a required parameter', func_);
0090 end
0091 
0092 if exist(datafile, 'file') ~= 2
0093   error('(%s) cannot find datafile : %s', func_, datafile);
0094 end
0095 
0096 measurement = vb_load_device(datafile);
0097 const = vb_define_const(measurement);
0098 if isempty(ch_class)
0099   % require no action
0100 elseif strcmp(ch_class, const.DATA_TYPE_USER)
0101   if isempty(ch_user)
0102     error('(%s) ch_user is a required parameter when ch_type is ''%s''', ...
0103       func_, const.DATA_TYPE_USER);
0104   end
0105 end
0106 return;
0107 %
0108 % --- end of inner_check_arguments()
0109 
0110 
0111 % --- inner_extract_channel_by_name()
0112 %
0113 function ch_info = ...
0114   inner_extract_channel_by_name(info, measurement, ch_class, ch_user)
0115 const = vb_define_const(measurement);
0116 
0117 Measurement = upper(measurement);
0118 
0119 if strcmp(Measurement, 'MEG')
0120   switch ch_class
0121     case const.DATA_TYPE_ALL
0122       target_ch = vb_meginfo_get_channel_label_whole(info);
0123 
0124     case const.DATA_TYPE_MAIN
0125       target_ch = vb_meginfo_get_channel_label_meg(info);
0126 
0127     case const.DATA_TYPE_EXTRA
0128       target_ch = vb_meginfo_get_channel_label_extra(info);
0129 
0130     case const.DATA_TYPE_REFERENCE
0131       target_ch = vb_meginfo_get_channel_label_refmg(info);
0132 
0133     case const.DATA_TYPE_MAG
0134       target_ch = vb_info_get_channel_label_by_type(info, 1);
0135     
0136     case const.DATA_TYPE_AXIAL
0137       target_ch = vb_info_get_channel_label_by_type(info, 2);
0138     
0139     case const.DATA_TYPE_PLANAR
0140       target_ch = vb_info_get_channel_label_by_type(info, 3);
0141       
0142     case const.DATA_TYPE_MAG_X
0143       target_ch = vb_info_get_channel_label_by_type(info, 4);
0144     case const.DATA_TYPE_MAG_Y
0145       target_ch = vb_info_get_channel_label_by_type(info, 5);
0146     case const.DATA_TYPE_MAG_Z
0147       target_ch = vb_info_get_channel_label_by_type(info, 6);
0148     
0149     case const.DATA_TYPE_USER
0150       target_ch = inner_get_channel_label_user(info, ch_user);
0151       
0152     otherwise
0153       warning('(%s) unknown ch_class : %s\n', mfilename, ch_class);
0154       ch_info = [];
0155       return;
0156   end
0157   
0158 elseif strcmp(Measurement, 'EEG')
0159   switch ch_class
0160     case const.DATA_TYPE_ALL
0161       target_ch = [vb_eeginfo_get_channel_label(info); ...
0162         vb_eeginfo_get_channel_label_extra(info)];
0163 
0164     case const.DATA_TYPE_MAIN
0165       target_ch = vb_eeginfo_get_channel_label(info);
0166 
0167     case const.DATA_TYPE_EXTRA
0168       target_ch = vb_eeginfo_get_channel_label_extra(info);
0169 
0170     case const.DATA_TYPE_USER
0171       target_ch = inner_get_channel_label_user(info, ch_user);
0172       
0173     otherwise
0174       warning('(%s) unknown ch_class : %s\n', mfilename, ch_class);
0175       ch_info = [];
0176       return;
0177   end
0178 else
0179   warning('(%s) unknown measurement : %s\n', mfilename, measurement);
0180   ch_info = [];
0181   return;
0182 end
0183 
0184 % --- get all channels info
0185 org_ch_info = vb_info_get_channel_info(info, 2);
0186 [idx] = vb_util_get_index(org_ch_info.Name, target_ch);
0187 
0188 ch_info.Active = org_ch_info.Active(idx,:);
0189 ch_info.Name   = org_ch_info.Name(idx,:);
0190 ch_info.ID     = org_ch_info.ID(idx,:);
0191 ch_info.Type   = org_ch_info.Type(idx,:);
0192 return;
0193 %
0194 % --- end of inner_extract_channel_by_name()
0195 
0196 
0197 % --- inner_extract_channel_by_type()
0198 %
0199 function ch_info = inner_extract_channel_by_type(info, measurement, ch_class)
0200 target_ch = vb_info_get_channel_label_by_type(info, ch_class);
0201 
0202 if isempty(target_ch)
0203   warning('(%s) cannot find channels of type : %d\n', mfilename, ch_class);
0204   ch_info = [];
0205   return;
0206 end
0207 
0208 % --- get all channels info
0209 org_ch_info = vb_info_get_channel_info(info, 2);
0210 [idx] = vb_util_get_index(org_ch_info.Name, target_ch);
0211 
0212 ch_info.Active = org_ch_info.Active(idx,:);
0213 ch_info.Name   = org_ch_info.Name(idx,:);
0214 ch_info.ID     = org_ch_info.ID(idx,:);
0215 ch_info.Type   = org_ch_info.Type(idx,:);
0216 return;
0217 %
0218 % --- end of inner_extract_channel_by_type()
0219 
0220 % --- inner_get_channel_label_user()
0221 %
0222 function target_ch = inner_get_channel_label_user(info, ch_user)
0223 ch_info = vb_info_get_channel_info(info, 2);
0224 
0225 if isnumeric(ch_user)
0226   [idx_ch] = vb_util_get_index(ch_info.ID, ch_user);
0227 else
0228   [idx_ch] = vb_util_get_index(ch_info.Name, ch_user);
0229 end
0230 target_ch = ch_info.Name(idx_ch, :);
0231 return;
0232 %
0233 % --- end of inner_get_channel_label_user()
0234 %
0235 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0236 
0237 % --- END OF FILE --- %

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