Home > functions > common > loadfunc > 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'|'AXIAL'|'PLANAR'|'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

 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'|'AXIAL'|'PLANAR'|'USER'
0012 %            :  2) <<numeric>> channel types defined by device
0013 %    ch_user : <conditionally required> channel list you want, Name or ID.
0014 %            :  {n_channel x 1}(Name) or [n_channel x 1](ID)
0015 %            :  If ch_class is 'USER', this is required.
0016 %            :  If ch_class is not 'USER', this is ignored.
0017 %            :  is numerical list ------> ID list
0018 %            :  is not numerical list --> Name list
0019 % [output]
0020 %    ch_info : <<struct>> the fields are as follows:
0021 %            :  .Active : list of active flag   [Nchannel x 1 boolean]
0022 %            :  .Name   : list of channel label {Nchannel x 1}
0023 %            :  .ID     : list of channel index [Nchannel x 1]
0024 %            :  .Type   : list of channel type  [Nchannel x 1]
0025 %
0026 % [note]
0027 %   @see vb_info_make_channel_info.m
0028 % [history]
0029 %   2009-07-27 (Sako) initial version
0030 %   2009-08-19 (Sako) modified to make data without ChannelInfo field
0031 %   2009-10-13 (Sako) modified help
0032 %   2009-10-14 (Sako) added 'USER' type
0033 %   2011-06-01 (Sako) converted return values of vb_load_device to upper case
0034 %
0035 % Copyright (C) 2011, ATR All Rights Reserved.
0036 % License : New BSD License(see VBMEG_LICENSE.txt)
0037 
0038 % --- CHECK ARGUMENTS --- %
0039 if ~exist('datafile', 'var'), datafile = ''; end
0040 if ~exist('ch_class', 'var'), ch_class = []; end
0041 if ~exist('ch_user', 'var'), ch_user = []; end
0042 [datafile, ch_class, ch_user] = ...
0043   inner_check_arguments(datafile, ch_class, ch_user);
0044 
0045 % --- MAIN PROCEDURE --------------------------------------------------------- %
0046 %
0047 info = vb_load_measurement_info(datafile);
0048 if ~isfield(info, 'ChannelInfo')
0049   measurement = vb_load_device(datafile);
0050   info.ChannelInfo = vb_info_make_channel_info(info, measurement);
0051 end
0052 
0053 if isempty(ch_class)
0054   % only info of ChannelInfo
0055   ch_info = vb_info_get_channel_info(info, 0);
0056   return;
0057 end
0058 
0059 % --- with extracting conditions
0060 measurement = vb_load_device(datafile);
0061 if ischar(ch_class)
0062   ch_info = inner_extract_channel_by_name(info, measurement, ch_class, ch_user);
0063 else
0064   ch_info = inner_extract_channel_by_type(info, measurement, ch_class);
0065 end
0066 %
0067 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0068 
0069 % --- INNER FUNCTIONS -------------------------------------------------------- %
0070 %
0071 % --- inner_check_arguments()
0072 %
0073 function [datafile, ch_class, ch_user] = ...
0074   inner_check_arguments(datafile, ch_class, ch_user)
0075 func_ = mfilename;
0076 
0077 if isempty(datafile)
0078   error('(%s) datafile is a required parameter', func_);
0079 end
0080 
0081 if exist(datafile, 'file') ~= 2
0082   error('(%s) cannot find datafile : %s', func_, datafile);
0083 end
0084 
0085 measurement = vb_load_device(datafile);
0086 const = vb_define_const(measurement);
0087 if isempty(ch_class)
0088   % require no action
0089 elseif strcmp(ch_class, const.DATA_TYPE_USER)
0090   if isempty(ch_user)
0091     error('(%s) ch_user is a required parameter when ch_type is ''%s''', ...
0092       func_, const.DATA_TYPE_USER);
0093   end
0094 end
0095 return;
0096 %
0097 % --- end of inner_check_arguments()
0098 
0099 
0100 % --- inner_extract_channel_by_name()
0101 %
0102 function ch_info = ...
0103   inner_extract_channel_by_name(info, measurement, ch_class, ch_user)
0104 const = vb_define_const(measurement);
0105 
0106 Measurement = upper(measurement);
0107 
0108 if strcmp(Measurement, 'MEG')
0109   switch ch_class
0110     case const.DATA_TYPE_ALL
0111       target_ch = vb_meginfo_get_channel_label_whole(info);
0112 
0113     case const.DATA_TYPE_MAIN
0114       target_ch = vb_meginfo_get_channel_label_meg(info);
0115 
0116     case const.DATA_TYPE_EXTRA
0117       target_ch = vb_meginfo_get_channel_label_extra(info);
0118 
0119     case const.DATA_TYPE_REFERENCE
0120       target_ch = vb_meginfo_get_channel_label_refmg(info);
0121     
0122     case const.DATA_TYPE_AXIAL
0123       target_ch = vb_info_get_channel_label_by_type(info, 2);
0124     
0125     case const.DATA_TYPE_PLANAR
0126       target_ch = vb_info_get_channel_label_by_type(info, 3);
0127     
0128     case const.DATA_TYPE_USER
0129       target_ch = inner_get_channel_label_user(info, ch_user);
0130       
0131     otherwise
0132       warning('(%s) unknown ch_class : %s\n', mfilename, ch_class);
0133       ch_info = [];
0134       return;
0135   end
0136   
0137 elseif strcmp(Measurement, 'EEG')
0138   switch ch_class
0139     case const.DATA_TYPE_ALL
0140       target_ch = [vb_eeginfo_get_channel_label(info); ...
0141         vb_eeginfo_get_channel_label_extra(info)];
0142 
0143     case const.DATA_TYPE_MAIN
0144       target_ch = vb_eeginfo_get_channel_label(info);
0145 
0146     case const.DATA_TYPE_EXTRA
0147       target_ch = vb_eeginfo_get_channel_label_extra(info);
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 else
0158   warning('(%s) unknown measurement : %s\n', mfilename, measurement);
0159   ch_info = [];
0160   return;
0161 end
0162 
0163 % --- get all channels info
0164 org_ch_info = vb_info_get_channel_info(info, 2);
0165 [idx] = vb_util_get_index(org_ch_info.Name, target_ch);
0166 
0167 ch_info.Active = org_ch_info.Active(idx,:);
0168 ch_info.Name   = org_ch_info.Name(idx,:);
0169 ch_info.ID     = org_ch_info.ID(idx,:);
0170 ch_info.Type   = org_ch_info.Type(idx,:);
0171 return;
0172 %
0173 % --- end of inner_extract_channel_by_name()
0174 
0175 
0176 % --- inner_extract_channel_by_type()
0177 %
0178 function ch_info = inner_extract_channel_by_type(info, measurement, ch_class)
0179 target_ch = vb_info_get_channel_label_by_type(info, ch_class);
0180 
0181 if isempty(target_ch)
0182   warning('(%s) cannot find channels of type : %d\n', mfilename, ch_class);
0183   ch_info = [];
0184   return;
0185 end
0186 
0187 % --- get all channels info
0188 org_ch_info = vb_info_get_channel_info(info, 2);
0189 [idx] = vb_util_get_index(org_ch_info.Name, target_ch);
0190 
0191 ch_info.Active = org_ch_info.Active(idx,:);
0192 ch_info.Name   = org_ch_info.Name(idx,:);
0193 ch_info.ID     = org_ch_info.ID(idx,:);
0194 ch_info.Type   = org_ch_info.Type(idx,:);
0195 return;
0196 %
0197 % --- end of inner_extract_channel_by_type()
0198 
0199 % --- inner_get_channel_label_user()
0200 %
0201 function target_ch = inner_get_channel_label_user(info, ch_user)
0202 ch_info = vb_info_get_channel_info(info, 2);
0203 
0204 if isnumeric(ch_user)
0205   [idx_ch] = vb_util_get_index(ch_info.ID, ch_user);
0206 else
0207   [idx_ch] = vb_util_get_index(ch_info.Name, ch_user);
0208 end
0209 target_ch = ch_info.Name(idx_ch, :);
0210 return;
0211 %
0212 % --- end of inner_get_channel_label_user()
0213 %
0214 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0215 
0216 % --- END OF FILE --- %

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005