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

vb_saver_meg_copy_info

PURPOSE ^

(utility to save data) make new MEG-MAT file by copying information from old

SYNOPSIS ^

function vb_saver_meg_copy_info(old_file, new_file, new_info)

DESCRIPTION ^

 (utility to save data) make new MEG-MAT file by copying information from old
 [usage]
   [new_file] = vb_saver_meg_copy_info(old_file, new_file, new_info)

 [input]
   old_file : <required> <<file>> MEG-MAT file as a base
   new_file : <required> MEG-MAT filename with path which will be created
   new_info : <optional> <<struct>> changing information from old
            :  if this or following fields are not specified or is empty, 
            :  value of a parameter will be copied as it is in old_file,
            :  except for bin_dir field.
            :  .n_sample      
            :  .sampling_freq (Hz)
            :  .pretrigger
            :  .bin_dir
            :  -if this is empty or is not specified, saveman will be deleted.

 [output]
   none

 [note]

 [history]
   2013-02-08 (Sako) initial version

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function vb_saver_meg_copy_info(old_file, new_file, new_info)
0002 % (utility to save data) make new MEG-MAT file by copying information from old
0003 % [usage]
0004 %   [new_file] = vb_saver_meg_copy_info(old_file, new_file, new_info)
0005 %
0006 % [input]
0007 %   old_file : <required> <<file>> MEG-MAT file as a base
0008 %   new_file : <required> MEG-MAT filename with path which will be created
0009 %   new_info : <optional> <<struct>> changing information from old
0010 %            :  if this or following fields are not specified or is empty,
0011 %            :  value of a parameter will be copied as it is in old_file,
0012 %            :  except for bin_dir field.
0013 %            :  .n_sample
0014 %            :  .sampling_freq (Hz)
0015 %            :  .pretrigger
0016 %            :  .bin_dir
0017 %            :  -if this is empty or is not specified, saveman will be deleted.
0018 %
0019 % [output]
0020 %   none
0021 %
0022 % [note]
0023 %
0024 % [history]
0025 %   2013-02-08 (Sako) initial version
0026 
0027 % --- CHECK ARGUMENTS --- %
0028 if ~exist('old_file', 'var'), old_file = ''; end
0029 if ~exist('new_file', 'var'), new_file = ''; end
0030 if ~exist('new_info', 'var'), new_info = []; end
0031 [old_file, new_file, new_info] = ...
0032   inner_check_arguments(old_file, new_file, new_info);
0033 
0034 % --- MAIN PROCEDURE --------------------------------------------------------- %
0035 %
0036 
0037 cur_meg = load(old_file);
0038 new_meginfo = cur_meg.MEGinfo;
0039 
0040 % --- update fields
0041 if isempty(new_info)
0042   if isfield(new_meginfo, 'saveman') 
0043     new_meginfo = rmfield(new_meginfo, 'saveman');
0044   end
0045   new_info.n_sample      = vb_meginfo_get_sample_number(new_meginfo);
0046   new_info.sampling_freq = vb_meginfo_get_sampling_frequency(new_meginfo);
0047   new_info.pretrigger    = vb_meginfo_get_pre_trigger(new_meginfo);
0048 
0049 else
0050   
0051   if isempty(new_info.bin_dir)
0052     if isfield(new_meginfo, 'saveman') 
0053       new_meginfo = rmfield(new_meginfo, 'saveman');
0054     end
0055   else
0056     new_meginfo.saveman.data_dir = new_info.bin_dir;
0057   end
0058 
0059   if isempty(new_info.n_sample)
0060     new_info.n_sample = vb_meginfo_get_sample_number(new_meginfo);
0061   end
0062 
0063   if isempty(new_info.sampling_freq)
0064     new_info.sampling_freq = vb_meginfo_get_sampling_frequency(new_meginfo);
0065   end
0066 
0067   if isempty(new_info.pretrigger)
0068     new_info.pretrigger = vb_meginfo_get_pre_trigger(new_meginfo);
0069   end
0070 end
0071 
0072 new_meginfo.Nsample    = new_info.n_sample;
0073 new_meginfo.SampleFreq = new_info.sampling_freq;
0074 new_meginfo.Pretrigger = new_info.pretrigger;
0075     
0076 % MEGinfo = new_meginfo;
0077 cur_meg.MEGinfo = new_meginfo;
0078 
0079 cur_meg.bexp         = [];
0080 cur_meg.bexp_ext     = [];
0081 cur_meg.refmg        = [];
0082 
0083 vb_save_struct(new_file, cur_meg);
0084 
0085 return
0086 end
0087 %
0088 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0089 
0090 % --- INNER FUNCTIONS -------------------------------------------------------- %
0091 %
0092 % --- inner_check_arguments()
0093 %
0094 function [old_file, new_file, new_info] = ...
0095   inner_check_arguments(old_file, new_file, new_info)
0096 func_ = mfilename;
0097 
0098 % --- old_file
0099 if isempty(old_file)
0100   error('(%s) old_file is a required parameter', func_);
0101 end
0102 
0103 if exist(old_file, 'file') ~= 2
0104   error('(%s) cannot find old_file : %s', func_, old_file);
0105 end
0106 
0107 % --- new_file
0108 if isempty(new_file)
0109   error('(%s) new_file is a required parameter', func_);
0110 end
0111 
0112 % --- new_info
0113 if isempty(new_info)
0114   % do nothing
0115 end
0116 
0117 % ----- new_info.bin_dir
0118 if ~isfield(new_info, 'bin_dir')
0119   new_info.bin_dir = '';
0120 end
0121 
0122 % ----- new_info.n_sample
0123 if ~isfield(new_info, 'n_sample')
0124   new_info.n_sample = [];
0125 end
0126 
0127 % ----- new_info.sampling_freq
0128 if ~isfield(new_info, 'sampling_freq')
0129   new_info.sampling_freq = [];
0130 end
0131 
0132 % ----- new_info.pretrigger
0133 if ~isfield(new_info, 'pretrigger')
0134   new_info.pretrigger = [];
0135 end
0136 
0137 return
0138 end
0139 %
0140 % --- end of inner_check_arguments()
0141 %
0142 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0143 
0144 % --- END OF FILE --- %

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