0001 function [result] = vb_msrmnt_make_preprocessed_file( ...
0002 org_file, update_spec, 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 if ~exist('org_file', 'var'), org_file = ''; end
0034 if ~exist('update_spec', 'var'), update_spec = []; end
0035 if ~exist('new_file', 'var'), new_file = ''; end
0036 [org_file, update_spec, new_file, result] = ...
0037 inner_check_arguments(org_file, update_spec, new_file);
0038 if result ~= 0, return; end
0039
0040
0041
0042
0043 [info, info_type] = vb_load_measurement_info(org_file);
0044
0045 if isfield(update_spec, 'active_channel')
0046 [info, result] = vb_info_set_active_channel(info, ...
0047 update_spec.active_channel);
0048 if result ~= 0
0049 fprintf('(%s, error code:%d)fail to info_set_active_channel\n', ...
0050 mfilename, result);
0051 return;
0052 end
0053 end
0054
0055 if isfield(update_spec, 'active_trial')
0056 [info, result] = vb_info_set_active_trial(info, ...
0057 update_spec.active_trial);
0058 if result ~= 0
0059 fprintf('(%s, error code:%d)fail to info_set_active_trial\n', ...
0060 mfilename, result);
0061 return;
0062 end
0063 end
0064
0065 info = vb_info_add_preprocess_parm(info, update_spec.preprocess_parm);
0066
0067
0068 org_msrmnt = load(org_file);
0069 if strcmp(info_type, 'MEGINFO')
0070 org_msrmnt.MEGinfo = info;
0071 elseif strcmp(info_type, 'EEGINFO')
0072 org_msrmnt.EEGinfo = info;
0073 else
0074
0075 end
0076 vb_util_save_struct_fields(new_file, org_msrmnt);
0077 return;
0078
0079
0080
0081
0082
0083
0084
0085 function [org_file, update_spec, new_file, err_code] = ...
0086 inner_check_arguments(org_file, update_spec, new_file)
0087 func_ = mfilename;
0088 err_code = 0;
0089 if isempty(org_file)
0090 fprintf('(%s)org_file is a required parameter', func_);
0091 err_code = bitor(err_code, 1);
0092 end
0093
0094 if isempty(update_spec)
0095 fprintf('(%s)update_spec is a required parameter', func_);
0096 err_code = bitor(err_code, 2);
0097 end
0098
0099 if ~isempty(org_file) && exist(org_file, 'file') ~= 2
0100 fprintf('(%s)cannot find org_file: %s\n', func_, org_file);
0101 err_code = bitor(err_code, 4);
0102 end
0103
0104 if ~isempty(update_spec) && ~isfield(update_spec, 'preprocess_parm')
0105 fprintf('(%s)preprocess_parm is a required field of update_spec\n', func_);
0106 err_code = bitor(err_code, 8);
0107 end
0108
0109 if err_code ~= 0
0110
0111 return;
0112 end
0113
0114 if isempty(new_file)
0115 new_file = org_file;
0116 end
0117 return;
0118
0119
0120
0121
0122
0123