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

vb_saver_eeg_copy_info

PURPOSE ^

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

SYNOPSIS ^

function vb_saver_eeg_copy_info(old_file, new_file, new_info)

DESCRIPTION ^

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

 [input]
   old_file : <required> <<file>> EEG-MAT file as a base
   new_file : <required> EEG-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, File 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_eeg_copy_info(old_file, new_file, new_info)
0002 % (utility to save data) make new EEG-MAT file by copying information from old
0003 % [usage]
0004 %   [new_file] = vb_saver_eeg_copy_info(old_file, new_file, new_info)
0005 %
0006 % [input]
0007 %   old_file : <required> <<file>> EEG-MAT file as a base
0008 %   new_file : <required> EEG-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, File 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 cur_eeg = load(old_file);
0037 new_eeginfo = cur_eeg.EEGinfo;
0038 
0039 % --- update fields
0040 if isempty(new_info)
0041   if isfield(new_eeginfo, 'File') && isfield(new_eeginfo.File, 'DataDir')
0042     new_eeginfo.File = rmfield(new_eeginfo.File, 'DataDir');
0043   end
0044   
0045   new_info.n_sample      = vb_eeginfo_get_sample_number(new_eeginfo);
0046   new_info.sampling_freq = vb_eeginfo_get_sampling_frequency(new_eeginfo);
0047   new_info.pretrigger    = vb_eeginfo_get_pre_trigger(new_eeginfo);
0048 
0049 else
0050   
0051   if isempty(new_info.bin_dir)
0052     if isfield(new_eeginfo, 'File') && isfield(new_eeginfo.File, 'DataDir')
0053       new_eeginfo.File = rmfield(new_eeginfo.File, 'DataDir');
0054     end
0055   else
0056     new_eeginfo.File.DataDir = new_info.bin_dir;
0057   end
0058 
0059   if isempty(new_info.n_sample)
0060     new_info.n_sample = vb_eeginfo_get_sample_number(new_eeginfo);
0061   end
0062 
0063   if isempty(new_info.sampling_freq)
0064     new_info.sampling_freq = vb_eeginfo_get_sampling_frequency(new_eeginfo);
0065   end
0066 
0067   if isempty(new_info.pretrigger)
0068     new_info.pretrigger = vb_eeginfo_get_pre_trigger(new_eeginfo);
0069   end
0070 end
0071 
0072 % channel info is not changed
0073 new_eeginfo.Nsample         = new_info.n_sample;
0074 new_eeginfo.SampleFrequency = new_info.sampling_freq;
0075 new_eeginfo.Pretrigger      = new_info.pretrigger;
0076     
0077 cur_eeg.EEGinfo = new_eeginfo;
0078 cur_eeg.eeg_data     = [];
0079 
0080 vb_save_struct(new_file, cur_eeg);
0081 
0082 return
0083 end
0084 %
0085 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0086 
0087 % --- INNER FUNCTIONS -------------------------------------------------------- %
0088 %
0089 % --- inner_check_arguments()
0090 %
0091 function [old_file, new_file, new_info] = ...
0092   inner_check_arguments(old_file, new_file, new_info)
0093 func_ = mfilename;
0094 
0095 % --- old_file
0096 if isempty(old_file)
0097   error('(%s) old_file is a required parameter', func_);
0098 end
0099 
0100 if exist(old_file, 'file') ~= 2
0101   error('(%s) cannot find old_file : %s', func_, old_file);
0102 end
0103 
0104 % --- new_file
0105 if isempty(new_file)
0106   error('(%s) new_file is a required parameter', func_);
0107 end
0108 
0109 % --- new_info
0110 if isempty(new_info)
0111   % do nothing
0112 end
0113 
0114 % ----- new_info.bin_dir
0115 if ~isfield(new_info, 'bin_dir')
0116   new_info.bin_dir = '';
0117 end
0118 
0119 % ----- new_info.n_sample
0120 if ~isfield(new_info, 'n_sample')
0121   new_info.n_sample = [];
0122 end
0123 
0124 % ----- new_info.sampling_freq
0125 if ~isfield(new_info, 'sampling_freq')
0126   new_info.sampling_freq = [];
0127 end
0128 
0129 % ----- new_info.pretrigger
0130 if ~isfield(new_info, 'pretrigger')
0131   new_info.pretrigger = [];
0132 end
0133 
0134 return
0135 end
0136 %
0137 % --- end of inner_check_arguments()
0138 %
0139 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0140 
0141 % --- END OF FILE --- %

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