Home > vbmeg > functions > device > eeg > vb_eegfile_update_data.m

vb_eegfile_update_data

PURPOSE ^

Replace data and update EEG-MAT file.

SYNOPSIS ^

function vb_eegfile_update_data(inst_spec)

DESCRIPTION ^

 Replace data and update EEG-MAT file.

 This function is used to create/update EEG-MAT file with arbitrary
 signal preprocessing function not supported by VBMEG. 

 [syntax]
   vb_eegfile_update_data(inst_spec)

 [input]
   inst_spec : <<required>> <struct> instruction spec
         :  fields are as follows:
         :   .org_file     : <<required>> EEG-MAT file which will be updated
         :   .new_data     : <<required>> [n_channel x n_sample]
         :   .channel_type : <<optional>> ['EEG'] | 'EXTRA'
         :   .new_file     : <<optional>> if you want to make new file.
         :                 :  ['org_file']
         :                 :  Empty means overwriting '.org_file'.
         :   .bin_data_dir : <<optional>> data stored directory.
         :                 : This parameter is valid only when 
         :                 : '.new_file' field is set.
         :                 : [(body of 'new_file')_bin]
         :                 : e.g. './new_0123.eeg.mat' --> './new_0123_bin'

 [output]
   void
 [note]
 
 [history]
   2011-02-08 (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 vb_eegfile_update_data(inst_spec)
0002 % Replace data and update EEG-MAT file.
0003 %
0004 % This function is used to create/update EEG-MAT file with arbitrary
0005 % signal preprocessing function not supported by VBMEG.
0006 %
0007 % [syntax]
0008 %   vb_eegfile_update_data(inst_spec)
0009 %
0010 % [input]
0011 %   inst_spec : <<required>> <struct> instruction spec
0012 %         :  fields are as follows:
0013 %         :   .org_file     : <<required>> EEG-MAT file which will be updated
0014 %         :   .new_data     : <<required>> [n_channel x n_sample]
0015 %         :   .channel_type : <<optional>> ['EEG'] | 'EXTRA'
0016 %         :   .new_file     : <<optional>> if you want to make new file.
0017 %         :                 :  ['org_file']
0018 %         :                 :  Empty means overwriting '.org_file'.
0019 %         :   .bin_data_dir : <<optional>> data stored directory.
0020 %         :                 : This parameter is valid only when
0021 %         :                 : '.new_file' field is set.
0022 %         :                 : [(body of 'new_file')_bin]
0023 %         :                 : e.g. './new_0123.eeg.mat' --> './new_0123_bin'
0024 %
0025 % [output]
0026 %   void
0027 % [note]
0028 %
0029 % [history]
0030 %   2011-02-08 (Sako) initial version
0031 %
0032 % Copyright (C) 2011, ATR All Rights Reserved.
0033 % License : New BSD License(see VBMEG_LICENSE.txt)
0034 
0035 % --- CHECK ARGUMENTS --- %
0036 if ~exist('inst_spec', 'var'), inst_spec = []; end
0037 [inst_spec] = inner_check_arguments(inst_spec);
0038 
0039 % --- MAIN PROCEDURE --------------------------------------------------------- %
0040 %
0041 org_file = inst_spec.org_file;
0042 [ch_info] = vb_load_channel_info(org_file, inst_spec.channel_type);
0043 
0044 
0045 if ~isempty(inst_spec.new_file)
0046   % --- copy org_file - by using vb_load_meg_data()
0047 
0048   load_spec.ChannelType = 'ALL';
0049   load_spec.bin_data_dir = inst_spec.bin_data_dir;
0050   vb_load_meg_data(org_file, load_spec, inst_spec.new_file);
0051 
0052 
0053 else
0054   % --- overwrite original file
0055   inst_spec.new_file = org_file;
0056 end
0057 
0058 
0059 % ------------------- %
0060 % --- UPDATE DATA --- %
0061 % ------------------- %
0062 eeg_info = vb_load_measurement_info(inst_spec.new_file);
0063 tmp_dir = vb_eeginfo_get_datadir(eeg_info);
0064 eeg_root = vb_get_file_parts(inst_spec.new_file);
0065 
0066 data_dir = [eeg_root '/' tmp_dir];
0067 
0068 PRECISION = vb_eeginfo_get_datatype(eeg_info);
0069 % --- PRECISION [N x 1]
0070 
0071 vb_define_device;
0072 
0073 n_channel = size(ch_info.Name, 1);
0074 for i_ch = 1:n_channel
0075   ch_name = ch_info.Name{i_ch};
0076   cur_ch_file = sprintf('%s/%s.%s', ...
0077     data_dir, ch_name, FILE_EXT_BIN_CH_EEG);
0078 
0079   cur_fid = fopen(cur_ch_file, 'wb');
0080   if cur_fid == -1
0081     error('(%s)cannot open file (%s)', mfilename, cur_ch_file);
0082   end
0083 
0084   fwrite(cur_fid, inst_spec.new_data(i_ch, :), PRECISION{i_ch});
0085   fclose(cur_fid);
0086 %   fprintf('--- UPDATED %s\n', cur_ch_file);
0087 end
0088 
0089 return;
0090 %
0091 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0092 
0093 % --- INNER FUNCTIONS -------------------------------------------------------- %
0094 %
0095 % --- inner_check_arguments()
0096 %
0097 function [inst_spec] = inner_check_arguments(inst_spec)
0098 if isempty(inst_spec)
0099   error('(%s) inst_spec is a required parameter', mfilename);
0100 end
0101 
0102 if ~isfield(inst_spec, 'org_file') || isempty(inst_spec.org_file)
0103   error('(%s) inst_spec.org_file is a required field', mfilename);
0104 end
0105 
0106 if exist(inst_spec.org_file, 'file') ~= 2
0107   error('(%s) cannot find inst_spec.org_file : %s', ...
0108     mfilename, inst_spec.org_file);
0109 end
0110 
0111 if ~isfield(inst_spec, 'new_data') || isempty(inst_spec.new_data)
0112   error('(%s) inst_spec.new_data is a required field', mfilename);
0113 end
0114 
0115 if ~isfield(inst_spec, 'channel_type') || isempty(inst_spec.channel_type)
0116   inst_spec.channel_type = 'EEG';
0117 end
0118 
0119 if ~isfield(inst_spec, 'new_file')
0120   inst_spec.new_file = '';
0121 
0122 elseif ~isfield(inst_spec, 'bin_data_dir')
0123   inst_spec.bin_data_dir = '';
0124 end
0125 %
0126 % --- end of inner_check_arguments()
0127 %
0128 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0129 
0130 % --- END OF FILE --- %

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