Home > vbmeg > functions > common > utility > vb_remake_megfile_by_bexp.m

vb_remake_megfile_by_bexp

PURPOSE ^

remake MEG-MAT file in accordance with current bexp data

SYNOPSIS ^

function vb_remake_megfile_by_bexp(bexp, new_file, org_file, ext_info)

DESCRIPTION ^

 remake MEG-MAT file in accordance with current bexp data
 [usage]
   vb_remake_megfile_by_bexp(bexp, new_file, org_file, ext_info)
 [input]
       bexp : <required> [Nchannel x Nsample x Ntrial]
   new_file : <required> <<file>> file name which will be remade
   org_file : <optional> <<file>> original MEG-MAT file
            :  if this is not empty, some data will be obtained from this file
   ext_info : <optional> <<struct>>  extension information
            :  if fields of this struct are specified, they will be overwritten
            :  to the appropriate fields of MEG-MAT file
            :  fow now, valid fields are as follows:
            :   .Pretrigger
            :   .AcqTypeCode [1|2|3]
            :     1) 'Evoked_Raw'
            :     2) 'Evoked_Ave'
            :     3) 'Continuous_Raw'
            :   .sampling_freq
 [output]
   none
 [note]
   Following parameters are not be able to be decided automatically.
     pick
     Qpick
     MEGinfo.sensor_weight
     MEGinfo.ChannelInfo.Type

 [history]
   2008-05-09 (Sako) initial version
   2011-06-02 (Sako) modified according to the new data format
   2013-02-08 (Sako) added sampling_freq field to ext_info

 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 vb_remake_megfile_by_bexp(bexp, new_file, org_file, ext_info)
0002 % remake MEG-MAT file in accordance with current bexp data
0003 % [usage]
0004 %   vb_remake_megfile_by_bexp(bexp, new_file, org_file, ext_info)
0005 % [input]
0006 %       bexp : <required> [Nchannel x Nsample x Ntrial]
0007 %   new_file : <required> <<file>> file name which will be remade
0008 %   org_file : <optional> <<file>> original MEG-MAT file
0009 %            :  if this is not empty, some data will be obtained from this file
0010 %   ext_info : <optional> <<struct>>  extension information
0011 %            :  if fields of this struct are specified, they will be overwritten
0012 %            :  to the appropriate fields of MEG-MAT file
0013 %            :  fow now, valid fields are as follows:
0014 %            :   .Pretrigger
0015 %            :   .AcqTypeCode [1|2|3]
0016 %            :     1) 'Evoked_Raw'
0017 %            :     2) 'Evoked_Ave'
0018 %            :     3) 'Continuous_Raw'
0019 %            :   .sampling_freq
0020 % [output]
0021 %   none
0022 % [note]
0023 %   Following parameters are not be able to be decided automatically.
0024 %     pick
0025 %     Qpick
0026 %     MEGinfo.sensor_weight
0027 %     MEGinfo.ChannelInfo.Type
0028 %
0029 % [history]
0030 %   2008-05-09 (Sako) initial version
0031 %   2011-06-02 (Sako) modified according to the new data format
0032 %   2013-02-08 (Sako) added sampling_freq field to ext_info
0033 %
0034 % Copyright (C) 2011, ATR All Rights Reserved.
0035 % License : New BSD License(see VBMEG_LICENSE.txt)
0036 
0037 % --- CHECK ARGUMENTS --- %
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 % --- MAIN PROCEDURE --------------------------------------------------------- %
0046 %
0047 % ----- from bexp
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 % ----- else
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 % ----- top fields
0091 CoordType = '';
0092 Measurement = '';
0093 pick = [];
0094 Qpick = [];
0095 
0096 % ----- from original file
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   % --- device dependent fields
0129   % ----- device_info.TransInfo
0130   MEGinfo = ...
0131     vb_info_set_transinfo(MEGinfo, vb_info_get_transinfo(org_MEGinfo));
0132   % ----- device_info.acq_info
0133   MEGinfo = ...
0134     vb_meginfo_set_acqinfo(MEGinfo, vb_meginfo_get_acqinfo(org_MEGinfo));
0135   % ----- device_info.acq_type
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   % --- coordinate type
0142   load(org_file, 'CoordType', 'Measurement');
0143 end % if ~isempty(org_file)
0144 
0145 % ----- from extension
0146 if ~isempty(ext_info)
0147   % --- pre-trigger
0148   if isfield(ext_info, 'Pretrigger')
0149     MEGinfo.Pretrigger = ext_info.Pretrigger;
0150   end
0151   
0152   % --- data type
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         % do nothing
0165     end
0166   end
0167   
0168   % --- sampling frequency
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 % ----- save
0184 vb_fsave(new_file, 'pick', 'Qpick', ...
0185   'CoordType', 'Measurement', 'bexp', 'MEGinfo');
0186 return;
0187 %
0188 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0189 
0190 % --- INNER FUNCTIONS -------------------------------------------------------- %
0191 %
0192 % --- inner_check_arguments()
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 % --- end of inner_check_arguments()
0211 %
0212 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0213 
0214 % --- END OF FILE --- %

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005