0001 function result = vb_msrmnt_store_data( ...
0002 msrmnt_file, new_data, new_history, new_file)
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
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
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
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
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
0096 vb_util_save_struct_fields(new_file, old_data);
0097 return;
0098
0099
0100
0101
0102
0103
0104
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;
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
0129
0130
0131
0132