Home > 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'
 [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

 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 % [output]
0020 %   none
0021 % [note]
0022 %   Following parameters are not be able to be decided automatically.
0023 %     pick
0024 %     Qpick
0025 %     MEGinfo.sensor_weight
0026 %     MEGinfo.ChannelInfo.Type
0027 %
0028 % [history]
0029 %   2008-05-09 (Sako) initial version
0030 %   2011-06-02 (Sako) modified according to the new data format
0031 %
0032 % Copyright (C) 2011, ATR All Rights Reserved.
0033 % License : New BSD License(see VBMEG_LICENSE.txt)
0034 
0035 % --- CHECK ARGUMENTS --- %
0036 if ~exist('bexp', 'var'), bexp = []; end
0037 if ~exist('new_file', 'var'), new_file = ''; end
0038 if ~exist('org_file', 'var'), org_file = ''; end
0039 if ~exist('ext_info', 'var'), ext_info = []; end
0040 [bexp, new_file, org_file, ext_info] = ...
0041   inner_check_arguments(bexp, new_file, org_file, ext_info);
0042 
0043 % --- MAIN PROCEDURE --------------------------------------------------------- %
0044 %
0045 % ----- from bexp
0046 MEGinfo.Nchannel = size(bexp,1);
0047 MEGinfo.Nsample  = size(bexp,2);
0048 MEGinfo.Nrepeat  = size(bexp,3);
0049 
0050 for i_tr = 1:MEGinfo.Nrepeat
0051   MEGinfo.Trial(i_tr).number = i_tr;
0052   MEGinfo.Trial(i_tr).sample = 1:MEGinfo.Nsample;
0053   MEGinfo.Trial(i_tr).Active = 1;
0054 end
0055 
0056 MEGinfo.MEGch_id = (1:MEGinfo.Nchannel)';
0057 MEGinfo.MEGch_name = cell(MEGinfo.Nchannel,1);
0058 for i_ch = 1:MEGinfo.Nchannel
0059   MEGinfo.MEGch_name{i_ch} = num2str(MEGinfo.MEGch_id(i_ch));
0060 end
0061 
0062 MEGinfo.ActiveChannel = ones(MEGinfo.Nchannel,1);
0063 MEGinfo.ActiveTrial   = ones(MEGinfo.Nrepeat,1);
0064 
0065 % ----- else
0066 MEGinfo.Measurement = 'MEG';
0067 MEGinfo.device = 'YOKOGAWA';
0068 MEGinfo.Pretrigger = [];
0069 MEGinfo.SampleFreq = [];
0070 MEGinfo.sensor_weight = [];
0071 MEGinfo.MEG_ID = [];
0072 MEGinfo.MRI_ID = [];
0073 MEGinfo.Vcenter = [];
0074 MEGinfo.Vradius = [];
0075 
0076 MEGinfo.ChannelInfo.ID = MEGinfo.MEGch_id;
0077 MEGinfo.ChannelInfo.Name = MEGinfo.MEGch_name;
0078 MEGinfo.ChannelInfo.Active = MEGinfo.ActiveChannel;
0079 MEGinfo.ChannelInfo.Type = [];
0080 MEGinfo.ExtraChannelInfo = [];
0081 
0082 MEGinfo.saveman = [];
0083 
0084 MEGinfo = vb_info_set_transinfo(MEGinfo, []);
0085 MEGinfo = vb_meginfo_set_acqinfo(MEGinfo, []);
0086 MEGinfo = vb_meginfo_set_acqtype(MEGinfo, '');
0087 
0088 % ----- top fields
0089 CoordType = '';
0090 Measurement = '';
0091 pick = [];
0092 Qpick = [];
0093 
0094 % ----- from original file
0095 if ~isempty(org_file)
0096   org_MEGinfo = vb_load_measurement_info(org_file);
0097   
0098   if isfield(org_MEGinfo, 'Measurement')
0099     MEGinfo.Measurement = org_MEGinfo.Measurement;
0100   end
0101   if isfield(org_MEGinfo, 'device')
0102     MEGinfo.device = org_MEGinfo.device;
0103   end
0104   if isfield(org_MEGinfo, 'Pretrigger')
0105     MEGinfo.Pretrigger = org_MEGinfo.Pretrigger;
0106   end
0107   if isfield(org_MEGinfo, 'SampleFreq')
0108     MEGinfo.SampleFreq = org_MEGinfo.SampleFreq;
0109   end
0110   if isfield(org_MEGinfo, 'Vcenter')
0111     MEGinfo.Vcenter = org_MEGinfo.Vcenter;
0112   end
0113   if isfield(org_MEGinfo, 'Vradius')
0114     MEGinfo.Vradius = org_MEGinfo.Vradius;
0115   end
0116   if isfield(org_MEGinfo, 'MEG_ID')
0117     MEGinfo.MEG_ID = org_MEGinfo.MEG_ID;
0118   end
0119   if isfield(org_MEGinfo, 'MRI_ID')
0120     MEGinfo.MRI_ID = org_MEGinfo.MRI_ID;
0121   end
0122   if isfield(org_MEGinfo, 'saveman')
0123     MEGinfo.saveman = org_MEGinfo.saveman;
0124   end
0125 
0126   % --- device dependent fields
0127   % ----- device_info.TransInfo
0128   MEGinfo = ...
0129     vb_info_set_transinfo(MEGinfo, vb_info_get_transinfo(org_MEGinfo));
0130   % ----- device_info.acq_info
0131   MEGinfo = ...
0132     vb_meginfo_set_acqinfo(MEGinfo, vb_meginfo_get_acqinfo(org_MEGinfo));
0133   % ----- device_info.acq_type
0134   acqinfo = vb_meginfo_get_acqinfo(MEGinfo);
0135   if isfield(acqinfo, 'condition') && isfield(acqinfo.condition, 'type')
0136     MEGinfo = vb_meginfo_set_acqtype(MEGinfo, acqinfo.condition.type);
0137   end
0138   
0139   % --- coordinate type
0140   load(org_file, 'CoordType', 'Measurement');
0141 end % if ~isempty(org_file)
0142 
0143 % ----- from extension
0144 if ~isempty(ext_info)
0145   % --- pre-trigger
0146   if isfield(ext_info, 'Pretrigger')
0147     MEGinfo.Pretrigger = ext_info.Pretrigger;
0148   end
0149   
0150   % --- data type
0151   if isfield(ext_info, 'AcqTypeCode')
0152     switch ext_info.AcqTypeCode
0153       case 1
0154         MEGinfo = vb_meginfo_set_acqtype(MEGinfo, 'Evoked_Raw');
0155       case 2
0156         MEGinfo = vb_meginfo_set_acqtype(MEGinfo, 'Evoked_Ave');
0157       case 3
0158         MEGinfo = vb_meginfo_set_acqtype(MEGinfo, 'Continuous_Raw');
0159       otherwise
0160         fprintf('(%s)unknown ext_info.AcqTypeCode : %d\n', ...
0161           mfilename, ext_info.AcqType);
0162         % do nothing
0163     end
0164   end
0165 end
0166 
0167 if isempty(CoordType)
0168   CoordType = 'SPM_Right_m';
0169 end
0170 
0171 if isempty(Measurement)
0172   Measurement = 'MEG';
0173 end
0174 
0175 % ----- save
0176 vb_fsave(new_file, 'pick', 'Qpick', ...
0177   'CoordType', 'Measurement', 'bexp', 'MEGinfo');
0178 return;
0179 %
0180 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0181 
0182 % --- INNER FUNCTIONS -------------------------------------------------------- %
0183 %
0184 % --- inner_check_arguments()
0185 %
0186 function [bexp, new_file, org_file, ext_info] = ...
0187   inner_check_arguments(bexp, new_file, org_file, ext_info)
0188 func_ = mfilename;
0189 if isempty(bexp)
0190   error('(%s)bexp is a required parameter', func_);
0191 end
0192 
0193 if isempty(new_file)
0194   error('(%s)new_file is a required parameter', func_);
0195 end
0196 
0197 if ~isempty(org_file) && exist(org_file, 'file') ~= 2
0198   error('(%s) cannot find org_file : %s', func_, org_file);
0199 end
0200 return;
0201 %
0202 % --- end of inner_check_arguments()
0203 %
0204 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0205 
0206 % --- END OF FILE --- %

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005