0001 function channel_info = vb_megfile_make_channel_info(megfile, ...
0002 meg_labels, ext_labels, ref_labels)
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 if ~exist('megfile', 'var'), megfile = ''; end
0036 if ~exist('meg_labels', 'var'), meg_labels = []; end
0037 if ~exist('ext_labels', 'var'), ext_labels = []; end
0038 if ~exist('ref_labels', 'var'), ref_labels = []; end
0039 [megfile, meg_labels, ext_labels, ref_labels] = ...
0040 inner_check_arguments(megfile, meg_labels, ext_labels, ref_labels);
0041
0042
0043
0044 channel_info.Active = [];
0045 channel_info.Name = [];
0046 channel_info.Type = [];
0047 channel_info.ID = [];
0048
0049 meginfo = vb_megfile_load_meginfo(megfile);
0050 org_meg_ch_info = vb_info_get_channel_info(meginfo);
0051 if isempty(org_meg_ch_info)
0052 warning('(%s) cannot get channel information\n', mfilename);
0053 return;
0054 end
0055
0056 org_ext_label = vb_meginfo_get_channel_label_extra(meginfo, false, true);
0057
0058 if ~isempty(org_ext_label) && ~isempty(ext_labels)
0059 [tmp_ext_idx] = vb_util_get_index(org_ext_label, ext_labels);
0060 else
0061 tmp_ext_idx = [];
0062 end
0063
0064 if ~isempty(org_ext_label) && ~isempty(ref_labels)
0065 [tmp_ref_idx] = vb_util_get_index(org_ext_label, ref_labels);
0066 else
0067 tmp_ref_idx = [];
0068 end
0069
0070
0071 if ~isempty(tmp_ext_idx) || ~isempty(tmp_ref_idx)
0072 if ~isfield(meginfo, 'ExtraChannelInfo') && isempty(meginfo.ExtraChannelInfo)
0073 warning('(%s)cannot get extra channel information\n', mfilename);
0074 return;
0075 else
0076
0077 extra_info = meginfo.ExtraChannelInfo;
0078
0079
0080 ext_active = extra_info.Channel_active(tmp_ext_idx);
0081 ref_active = extra_info.Channel_active(tmp_ref_idx);
0082
0083
0084 ext_type = extra_info.Channel_type(tmp_ext_idx);
0085 ref_type = extra_info.Channel_type(tmp_ref_idx);
0086
0087
0088 ext_idx = extra_info.Channel_id(tmp_ext_idx);
0089 ref_idx = extra_info.Channel_id(tmp_ref_idx);
0090 end
0091 else
0092 ext_active = [];
0093 ref_active = [];
0094 ext_type = [];
0095 ref_type = [];
0096 ext_idx = [];
0097 ref_idx = [];
0098 end
0099
0100
0101 org_meg_label = vb_meginfo_get_channel_label_meg(meginfo, false);
0102 if ~isempty(org_meg_label) && ~isempty(meg_labels)
0103 [tmp_meg_idx] = vb_util_get_index(org_meg_label, meg_labels);
0104 else
0105 tmp_meg_idx = [];
0106 end
0107
0108
0109 org_meg_active = org_meg_ch_info.Active;
0110 meg_active = org_meg_active(tmp_meg_idx);
0111 channel_info.Active = [meg_active;ext_active;ref_active];
0112
0113
0114 org_meg_labels = org_meg_ch_info.Name;
0115 meg_labels = org_meg_labels(tmp_meg_idx);
0116 channel_info.Name = [meg_labels;ext_labels;ref_labels];
0117
0118
0119 org_meg_type = org_meg_ch_info.Type;
0120 meg_type = org_meg_type(tmp_meg_idx);
0121 channel_info.Type = [meg_type;ext_type;ref_type];
0122
0123
0124 org_meg_idx = org_meg_ch_info.ID;
0125 meg_idx = org_meg_idx(tmp_meg_idx);
0126 channel_info.ID = [meg_idx;ext_idx;ref_idx];
0127
0128 return;
0129
0130
0131
0132
0133
0134
0135
0136 function [megfile, meg_labels, ext_labels, ref_labels] = ...
0137 inner_check_arguments(megfile, meg_labels, ext_labels, ref_labels)
0138 func_ = mfilename;
0139 if isempty(megfile)
0140 error('(%s)megfile is a required parameter', func_);
0141 end
0142
0143 if exist(megfile, 'file') ~= 2
0144 error('(%s)cannot find megfile : %s', func_, megfile);
0145 end
0146 return;
0147
0148
0149
0150
0151
0152