0001 function vb_remake_megfile_by_bexp(bexp, new_file, org_file, ext_info)
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 if ~exist('bexp', 'var'), bexp = []; end
0039 if ~exist('new_file', 'var'), new_file = ''; end
0040 if ~exist('org_file', 'var'), org_file = ''; end
0041 if ~exist('ext_info', 'var'), ext_info = []; end
0042 [bexp, new_file, org_file, ext_info] = ...
0043 inner_check_arguments(bexp, new_file, org_file, ext_info);
0044
0045
0046
0047
0048 MEGinfo.Nchannel = size(bexp,1);
0049 MEGinfo.Nsample = size(bexp,2);
0050 MEGinfo.Nrepeat = size(bexp,3);
0051
0052 for i_tr = 1:MEGinfo.Nrepeat
0053 MEGinfo.Trial(i_tr).number = i_tr;
0054 MEGinfo.Trial(i_tr).sample = 1:MEGinfo.Nsample;
0055 MEGinfo.Trial(i_tr).Active = 1;
0056 end
0057
0058 MEGinfo.MEGch_id = (1:MEGinfo.Nchannel)';
0059 MEGinfo.MEGch_name = cell(MEGinfo.Nchannel,1);
0060 for i_ch = 1:MEGinfo.Nchannel
0061 MEGinfo.MEGch_name{i_ch} = num2str(MEGinfo.MEGch_id(i_ch));
0062 end
0063
0064 MEGinfo.ActiveChannel = ones(MEGinfo.Nchannel,1);
0065 MEGinfo.ActiveTrial = ones(MEGinfo.Nrepeat,1);
0066
0067
0068 MEGinfo.Measurement = 'MEG';
0069 MEGinfo.device = 'YOKOGAWA';
0070 MEGinfo.Pretrigger = [];
0071 MEGinfo.SampleFreq = [];
0072 MEGinfo.sensor_weight = [];
0073 MEGinfo.MEG_ID = [];
0074 MEGinfo.MRI_ID = [];
0075 MEGinfo.Vcenter = [];
0076 MEGinfo.Vradius = [];
0077
0078 MEGinfo.ChannelInfo.ID = MEGinfo.MEGch_id;
0079 MEGinfo.ChannelInfo.Name = MEGinfo.MEGch_name;
0080 MEGinfo.ChannelInfo.Active = MEGinfo.ActiveChannel;
0081 MEGinfo.ChannelInfo.Type = [];
0082 MEGinfo.ExtraChannelInfo = [];
0083
0084 MEGinfo.saveman = [];
0085
0086 MEGinfo = vb_info_set_transinfo(MEGinfo, []);
0087 MEGinfo = vb_meginfo_set_acqinfo(MEGinfo, []);
0088 MEGinfo = vb_meginfo_set_acqtype(MEGinfo, '');
0089
0090
0091 CoordType = '';
0092 Measurement = '';
0093 pick = [];
0094 Qpick = [];
0095
0096
0097 if ~isempty(org_file)
0098 org_MEGinfo = vb_load_measurement_info(org_file);
0099
0100 if isfield(org_MEGinfo, 'Measurement')
0101 MEGinfo.Measurement = org_MEGinfo.Measurement;
0102 end
0103 if isfield(org_MEGinfo, 'device')
0104 MEGinfo.device = org_MEGinfo.device;
0105 end
0106 if isfield(org_MEGinfo, 'Pretrigger')
0107 MEGinfo.Pretrigger = org_MEGinfo.Pretrigger;
0108 end
0109 if isfield(org_MEGinfo, 'SampleFreq')
0110 MEGinfo.SampleFreq = org_MEGinfo.SampleFreq;
0111 end
0112 if isfield(org_MEGinfo, 'Vcenter')
0113 MEGinfo.Vcenter = org_MEGinfo.Vcenter;
0114 end
0115 if isfield(org_MEGinfo, 'Vradius')
0116 MEGinfo.Vradius = org_MEGinfo.Vradius;
0117 end
0118 if isfield(org_MEGinfo, 'MEG_ID')
0119 MEGinfo.MEG_ID = org_MEGinfo.MEG_ID;
0120 end
0121 if isfield(org_MEGinfo, 'MRI_ID')
0122 MEGinfo.MRI_ID = org_MEGinfo.MRI_ID;
0123 end
0124 if isfield(org_MEGinfo, 'saveman')
0125 MEGinfo.saveman = org_MEGinfo.saveman;
0126 end
0127
0128
0129
0130 MEGinfo = ...
0131 vb_info_set_transinfo(MEGinfo, vb_info_get_transinfo(org_MEGinfo));
0132
0133 MEGinfo = ...
0134 vb_meginfo_set_acqinfo(MEGinfo, vb_meginfo_get_acqinfo(org_MEGinfo));
0135
0136 acqinfo = vb_meginfo_get_acqinfo(MEGinfo);
0137 if isfield(acqinfo, 'condition') && isfield(acqinfo.condition, 'type')
0138 MEGinfo = vb_meginfo_set_acqtype(MEGinfo, acqinfo.condition.type);
0139 end
0140
0141
0142 load(org_file, 'CoordType', 'Measurement');
0143 end
0144
0145
0146 if ~isempty(ext_info)
0147
0148 if isfield(ext_info, 'Pretrigger')
0149 MEGinfo.Pretrigger = ext_info.Pretrigger;
0150 end
0151
0152
0153 if isfield(ext_info, 'AcqTypeCode')
0154 switch ext_info.AcqTypeCode
0155 case 1
0156 MEGinfo = vb_meginfo_set_acqtype(MEGinfo, 'Evoked_Raw');
0157 case 2
0158 MEGinfo = vb_meginfo_set_acqtype(MEGinfo, 'Evoked_Ave');
0159 case 3
0160 MEGinfo = vb_meginfo_set_acqtype(MEGinfo, 'Continuous_Raw');
0161 otherwise
0162 fprintf('(%s)unknown ext_info.AcqTypeCode : %d\n', ...
0163 mfilename, ext_info.AcqType);
0164
0165 end
0166 end
0167
0168
0169 if isfield(ext_info, 'sampling_freq')
0170 MEGinfo.SampleFreq = ext_info.sampling_freq;
0171 end
0172
0173 end
0174
0175 if isempty(CoordType)
0176 CoordType = 'SPM_Right_m';
0177 end
0178
0179 if isempty(Measurement)
0180 Measurement = 'MEG';
0181 end
0182
0183
0184 vb_fsave(new_file, 'pick', 'Qpick', ...
0185 'CoordType', 'Measurement', 'bexp', 'MEGinfo');
0186 return;
0187
0188
0189
0190
0191
0192
0193
0194 function [bexp, new_file, org_file, ext_info] = ...
0195 inner_check_arguments(bexp, new_file, org_file, ext_info)
0196 func_ = mfilename;
0197 if isempty(bexp)
0198 error('(%s)bexp is a required parameter', func_);
0199 end
0200
0201 if isempty(new_file)
0202 error('(%s)new_file is a required parameter', func_);
0203 end
0204
0205 if ~isempty(org_file) && exist(org_file, 'file') ~= 2
0206 error('(%s) cannot find org_file : %s', func_, org_file);
0207 end
0208 return;
0209
0210
0211
0212
0213
0214