Home > functions > device > vb_msrmnt_make_preprocessed_file.m

vb_msrmnt_make_preprocessed_file

PURPOSE ^

make new MEG-MAT or EEG-MAT file which have preprocessed data

SYNOPSIS ^

function [result] = vb_msrmnt_make_preprocessed_file(org_file, update_spec, new_file)

DESCRIPTION ^

 make new MEG-MAT or EEG-MAT file which have preprocessed data

 [usage]
   [result] = vb_msrmnt_make_preprocessed_file( ...
                org_file, update_spec, new_file)

 [input]
      org_file : <required> <<file>> base MEG-MAT or EEG-MAT file
   update_spec : <required> <<struct>> update information
               :   .preprocess_parm : <required> parameters to preprocess
               :                    :  this will be saved as a history
               :   .active_channel  : <optional> active channel list
               :   .active_trial    : <optional> active trial list
      new_file : <optional> new MEG-MAT or EEG-MAT file
               :  if this is empty, org_file will be overwritten

 [output]
        result :     0) success
               : not 0) failure
               :
 [note]
   this function does not check validity of update_spec

 [history]
   2008-04-11 (Sako) initial version

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [result] = vb_msrmnt_make_preprocessed_file( ...
0002   org_file, update_spec, new_file)
0003 % make new MEG-MAT or EEG-MAT file which have preprocessed data
0004 %
0005 % [usage]
0006 %   [result] = vb_msrmnt_make_preprocessed_file( ...
0007 %                org_file, update_spec, new_file)
0008 %
0009 % [input]
0010 %      org_file : <required> <<file>> base MEG-MAT or EEG-MAT file
0011 %   update_spec : <required> <<struct>> update information
0012 %               :   .preprocess_parm : <required> parameters to preprocess
0013 %               :                    :  this will be saved as a history
0014 %               :   .active_channel  : <optional> active channel list
0015 %               :   .active_trial    : <optional> active trial list
0016 %      new_file : <optional> new MEG-MAT or EEG-MAT file
0017 %               :  if this is empty, org_file will be overwritten
0018 %
0019 % [output]
0020 %        result :     0) success
0021 %               : not 0) failure
0022 %               :
0023 % [note]
0024 %   this function does not check validity of update_spec
0025 %
0026 % [history]
0027 %   2008-04-11 (Sako) initial version
0028 %
0029 % Copyright (C) 2011, ATR All Rights Reserved.
0030 % License : New BSD License(see VBMEG_LICENSE.txt)
0031 
0032 % --- CHECK ARGUMENTS --- %
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 % --- MAIN PROCEDURE --------------------------------------------------------- %
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 % --- save new EEG-MAT file
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   % ignore
0075 end
0076 vb_util_save_struct_fields(new_file, org_msrmnt);
0077 return;
0078 %
0079 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0080 
0081 % --- INNER FUNCTIONS -------------------------------------------------------- %
0082 %
0083 % --- inner_check_arguments()
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   % not be necessary to continue
0111   return;
0112 end
0113 
0114 if isempty(new_file)
0115   new_file = org_file;
0116 end
0117 return;
0118 %
0119 % --- end of inner_check_arguments()
0120 %
0121 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0122 
0123 % --- END OF FILE --- %

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005