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
0040
0041
0042
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
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
0059 ch_info = vb_info_get_channel_info(info, 0);
0060 return;
0061 end
0062
0063
0064 measurement = vb_load_device(datafile);
0065
0066
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
0079
0080
0081
0082
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
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
0109
0110
0111
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
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
0195
0196
0197
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
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
0219
0220
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
0234
0235
0236
0237