Home > vbmeg > functions > gui > preAnalysis > meeg_processor > trial_extractor > vb_trial_extractor_output_file.m

vb_trial_extractor_output_file

PURPOSE ^

Create trial MEG/EEG-MAT file.

SYNOPSIS ^

function [data] = vb_trial_extractor_output_file(data)

DESCRIPTION ^

 Create trial MEG/EEG-MAT file.
 [USAGE]
    [data] = vb_trial_extractor_output_file(data);
 [IN]
    data : vb_trial_extractor object.
 [OUT]
    data : vb_trial_extractor object.
 [see also]
    vb_msrmnt_make_trial_data

 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 [data] = vb_trial_extractor_output_file(data)
0002 % Create trial MEG/EEG-MAT file.
0003 % [USAGE]
0004 %    [data] = vb_trial_extractor_output_file(data);
0005 % [IN]
0006 %    data : vb_trial_extractor object.
0007 % [OUT]
0008 %    data : vb_trial_extractor object.
0009 % [see also]
0010 %    vb_msrmnt_make_trial_data
0011 %
0012 % Copyright (C) 2011, ATR All Rights Reserved.
0013 % License : New BSD License(see VBMEG_LICENSE.txt)
0014 
0015 %
0016 % --- Previous check
0017 %
0018 if ~exist('data', 'var')
0019     error('data is a required parameter.');
0020 end
0021 
0022 %
0023 % --- Main Procedure
0024 %
0025 
0026 % Basename definition
0027 org_file = vb_continuous_file_get_filename(data.continuous_file);
0028 base_extension         = org_file(end-8+1:end);
0029 [base_path, base_file] = vb_get_file_parts(org_file(1:end-8));
0030 
0031 sample_freq = vb_continuous_file_get_sample_freq(data.continuous_file);
0032 
0033 Nputfile = length(data.output_file);
0034 
0035 proc_spec = struct;
0036 
0037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0038 % ORIGINAL FILE INFO
0039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0040 proc_spec.proc_parm = struct;
0041 proc_spec.proc_parm.sample_freq   = sample_freq;
0042 data_file = org_file;
0043 
0044 % If downsampling is specified
0045 if ~isfield(data, 'output_sample_freq')
0046     data.output_sample_freq = sample_freq;
0047 end
0048 
0049 if data.output_sample_freq ~= sample_freq
0050     % Create down sampling file
0051     dsfile = fullfile(base_path, [base_file, '_', num2str(data.output_sample_freq), 'Hz', base_extension]);
0052     vb_disp(sprintf('Now creating downsampling file : %s\n', ds_file));
0053     if isfield(data, 'batch_mode') && data.batch_mode
0054         h = -1;
0055     else
0056         h = msgbox('Now creating downsampling file...', 'Please wait');
0057         bh = findall(h, 'Style', 'pushbutton');
0058         set(bh, 'Visible', 'off'); drawnow; pause(0.1);
0059     end
0060     if ishandle(h), delete(h), end
0061     err = inner_make_down_sample_file(org_file, dsfile, data.output_sample_freq);
0062     if ~err
0063         % Create success
0064         proc_spec.proc_parm.sample_freq = data.output_sample_freq;
0065         data_file   = dsfile;
0066     else
0067         % Create failure
0068         errmsg = sprintf('Unable to make down sampling file : %s\n', dsfile);
0069         if isfield(data, 'batch_mode') && data.batch_mode
0070             error(errmsg);
0071         else
0072             errordlg(errmsg, 'Output downsampling file');
0073             return;
0074         end
0075     end
0076 end
0077 
0078 for k=1:Nputfile
0079     % vb_msrmnt_make_trial_data
0080     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0081     % Output TRIAL INFO
0082     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0083     proc_spec.proc_parm.Pretrigger_ms  = data.trial_setting.pretrigger_ms;
0084     proc_spec.proc_parm.Posttrigger_ms = data.trial_setting.posttrigger_ms;
0085 
0086     % tag
0087     tag_obj = vb_tag_util_find_tag(data.label_list, data.output_file{k}.label_name);
0088     trial_ix = vb_tag_get_trial_index(tag_obj);
0089 
0090     % get onset sample list
0091     proc_spec.proc_parm.trigger = sort([data.trial_list(trial_ix).onset]);
0092     % Round trigger point
0093     proc_spec.proc_parm.trigger = round(...
0094                                       proc_spec.proc_parm.trigger * ...
0095                                      (data.output_sample_freq/sample_freq));
0096 
0097     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0098     % OUTPUT FILENAME
0099     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0100     new_file = data.output_file{k}.output_file;
0101 
0102     tmp = new_file;
0103     try
0104         vb_save(tmp, 'tmp');
0105         delete(tmp);
0106     catch
0107         errordlg(['Unable to make file : ', tmp, ...
0108                   sprintf('\nCheck directory permission.'), ...
0109                  ], 'Output MEG(EEG) file');
0110         return;
0111     end
0112     
0113     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0114     % Start creating file
0115     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0116     if isfield(data, 'batch_mode') && data.batch_mode
0117         h = -1;
0118         vb_disp('Now putting file(s). Please wait');
0119     else
0120         h = msgbox('Now putting file(s) ...', 'Please wait');
0121         bh = findall(h, 'Style', 'pushbutton');
0122         set(bh, 'Visible', 'off'); drawnow; pause(0.1);
0123     end
0124 
0125     vb_disp_nonl(sprintf('Label: %s -> %s ... \n',...
0126                     vb_tag_get_tag_name(tag_obj), ...
0127                     new_file));
0128 
0129     vb_msrmnt_make_trial_data(data_file, proc_spec, new_file);
0130     vb_disp('done.');
0131     if ishandle(h), delete(h); end
0132 end
0133 
0134 
0135 function [err] = inner_make_down_sample_file(org_file, new_file, freq)
0136 err = false;
0137 
0138 try
0139 MEGinfo = vb_load_measurement_info(org_file);
0140 measurement = vb_info_get_measurement(MEGinfo);
0141 
0142 switch(upper(measurement))
0143     case 'MEG'
0144         func_name = 'vb_megfile_filter_ch_data';
0145     case 'EEG'
0146         func_name = 'vb_eegfile_filter_ch_data';
0147     otherwise
0148         err = true;
0149         error('Unknown measurement device was specified.');
0150 end
0151 
0152 proc_spec.parm.fsamp = freq;
0153 feval(func_name, org_file, proc_spec, new_file);
0154 
0155 catch
0156     err = true;
0157 end

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