0001 function [ch_info] = vb_load_channel_info(datafile, ch_class, ch_user)
0002
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 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
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
0055 ch_info = vb_info_get_channel_info(info, 0);
0056 return;
0057 end
0058
0059
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
0068
0069
0070
0071
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
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
0098
0099
0100
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
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
0174
0175
0176
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
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
0198
0199
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
0213
0214
0215
0216