


store new data
[usage]
result = vb_msrmnt_store_data(msrmnt_file, new_data, new_history, new_file)
[input]
msrmnt_file : <required> <<file>> base file (MEG-MAT or EEG-MAT)
new_data : <optional> <<struct>>
: data group which will be stored []
: all the data size are [Nchannel x Nsample x Ntrial]
: (MEG)
: .bexp
: .bexp_ext
: .refmg
: (EEG)
: .eeg_data
new_file : <optional> new file in which the new data will be stored
: [<msrmnt_file>]
: if this is empty, data will be stored to base file
new_history : <optional> history data which will be added to
: MEG(EEG)info.History
[output]
result : <<integer>> error code
: 0) success
: 1) bad msrmnt_file
: 2) bad Measurement
[note]
[history]
2008-05-07 (Sako) initial version
2011-06-01 (Sako) converted return values of vb_load_device to upper case
Copyright (C) 2011, ATR All Rights Reserved.
License : New BSD License(see VBMEG_LICENSE.txt)


0001 function result = vb_msrmnt_store_data( ... 0002 msrmnt_file, new_data, new_history, new_file) 0003 % store new data 0004 % [usage] 0005 % result = vb_msrmnt_store_data(msrmnt_file, new_data, new_history, new_file) 0006 % [input] 0007 % msrmnt_file : <required> <<file>> base file (MEG-MAT or EEG-MAT) 0008 % new_data : <optional> <<struct>> 0009 % : data group which will be stored [] 0010 % : all the data size are [Nchannel x Nsample x Ntrial] 0011 % : (MEG) 0012 % : .bexp 0013 % : .bexp_ext 0014 % : .refmg 0015 % : (EEG) 0016 % : .eeg_data 0017 % new_file : <optional> new file in which the new data will be stored 0018 % : [<msrmnt_file>] 0019 % : if this is empty, data will be stored to base file 0020 % new_history : <optional> history data which will be added to 0021 % : MEG(EEG)info.History 0022 % [output] 0023 % result : <<integer>> error code 0024 % : 0) success 0025 % : 1) bad msrmnt_file 0026 % : 2) bad Measurement 0027 % [note] 0028 % 0029 % [history] 0030 % 2008-05-07 (Sako) initial version 0031 % 2011-06-01 (Sako) converted return values of vb_load_device to upper case 0032 % 0033 % Copyright (C) 2011, ATR All Rights Reserved. 0034 % License : New BSD License(see VBMEG_LICENSE.txt) 0035 0036 % --- CHECK ARGUMENTS --- % 0037 if ~exist('msrmnt_file', 'var'), msrmnt_file = ''; end 0038 if ~exist('new_data', 'var'), new_data = []; end 0039 if ~exist('new_history', 'var'), new_history = []; end 0040 if ~exist('new_file', 'var'), new_file = ''; end 0041 [msrmnt_file, new_data, new_history, new_file, result] = ... 0042 inner_check_arguments(msrmnt_file, new_data, new_history, new_file); 0043 0044 % --- MAIN PROCEDURE --------------------------------------------------------- % 0045 % 0046 if result ~= 0 0047 return; 0048 end 0049 0050 [measurement] = vb_load_device(msrmnt_file); 0051 Measurement = upper(measurement); 0052 0053 old_data = load(msrmnt_file); 0054 0055 info = []; 0056 0057 if ~isempty(new_history) 0058 info = vb_load_measurement_info(msrmnt_file); 0059 info = vb_info_add_preprocess_parm(info, new_history); 0060 end 0061 0062 switch Measurement 0063 case 'MEG' 0064 % ----- set MEGInfo.History 0065 if ~isempty(info) 0066 old_data.MEGinfo = info; 0067 end 0068 0069 if isfield(new_data, 'bexp') && ~isempty(new_data.bexp) 0070 old_data.bexp = new_data.bexp; 0071 end 0072 if isfield(new_data, 'bexp_ext') && ~isempty(new_data.bexp_ext) 0073 old_data.bexp_ext = new_data.bexp_ext; 0074 end 0075 if isfield(new_data, 'refmg') && ~isempty(new_data.refmg) 0076 old_data.refmg = new_data.refmg; 0077 end 0078 0079 case 'EEG' 0080 % ----- set EEGInfo.History 0081 if ~isempty(info) 0082 old_data.EEGinfo = info; 0083 end 0084 0085 if isfield(new_data, 'eeg_data') && ~isempty(new_data.eeg_data) 0086 old_data.eeg_data = new_data.eeg_data; 0087 end 0088 0089 otherwise 0090 fprintf('(%s) unknown MEASUREMENT : %s\n', mfilename, MEASURE); 0091 result = 2; 0092 return; 0093 end 0094 0095 % ----- save new file 0096 vb_util_save_struct_fields(new_file, old_data); 0097 return; 0098 % 0099 % --- END OF MAIN PROCEDURE -------------------------------------------------- % 0100 0101 0102 % --- INNER FUNCTIONS -------------------------------------------------------- % 0103 % 0104 % --- inner_check_arguments() 0105 % 0106 function [msrmnt_file, new_data, new_history, new_file, result] = ... 0107 inner_check_arguments(msrmnt_file, new_data, new_history, new_file) 0108 func_ = mfilename; 0109 result = 0; % success 0110 0111 if isempty(msrmnt_file) 0112 fprintf('(%s)msrmnt_file is a required parameter\n', func_); 0113 result = 1; 0114 return; 0115 end 0116 0117 if exist(msrmnt_file, 'file') ~= 2 0118 fprintf('(%s)cannot find msrmnt_file : %s\n', func_, msrmnt_file); 0119 result = 1; 0120 return; 0121 end 0122 0123 if isempty(new_file) 0124 new_file = msrmnt_file; 0125 end 0126 return; 0127 % 0128 % --- end of inner_check_arguments() 0129 % 0130 % --- END OF INNER FUNCTIONS ------------------------------------------------- % 0131 0132 % --- END OF FILE --- %