Home > functions > gui > preAnalysis > 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.root_dir  = base_path;
0042 proc_spec.proc_parm.sample_freq   = sample_freq;
0043 proc_spec.proc_parm.data_file     = [base_file, base_extension];
0044 
0045 
0046 % If downsampling is specified
0047 if ~isfield(data, 'output_sample_freq')
0048     data.output_sample_freq = sample_freq;
0049 end
0050 
0051 if data.output_sample_freq ~= sample_freq
0052     % Create down sampling file
0053     dsfile = [base_file, '_', num2str(data.output_sample_freq), 'Hz', base_extension];
0054     vb_disp(sprintf('Now creating downsampling file : %s\n', [base_path, filesep, dsfile]));
0055     if isfield(data, 'batch_mode') && data.batch_mode
0056         h = -1;
0057     else
0058         h = msgbox('Now creating downsampling file...', 'Please wait');
0059         bh = findall(h, 'Style', 'pushbutton');
0060         set(bh, 'Visible', 'off'); drawnow; pause(0.1);
0061     end
0062     if ishandle(h), delete(h), end
0063     err = inner_make_down_sample_file(org_file, dsfile, data.output_sample_freq);
0064     if ~err
0065         % Create success
0066         proc_spec.proc_parm.sample_freq = data.output_sample_freq;
0067         proc_spec.proc_parm.data_file   = dsfile;
0068     else
0069         % Create failure
0070         errmsg = sprintf('Unable to make down sampling file : %s\n', dsfile);
0071         if isfield(data, 'batch_mode') && data.batch_mode
0072             error(errmsg);
0073         else
0074             errordlg(errmsg, 'Output downsampling file');
0075             return;
0076         end
0077     end
0078 end
0079 
0080 for k=1:Nputfile
0081     % vb_msrmnt_make_trial_data
0082     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0083     % Output TRIAL INFO
0084     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0085     proc_spec.proc_parm.Pretrigger_ms  = data.trial_setting.pretrigger_ms;
0086     proc_spec.proc_parm.Posttrigger_ms = data.trial_setting.posttrigger_ms;
0087 
0088     % tag
0089     tag_obj = vb_tag_util_find_tag(data.label_list, data.output_file{k}.label_name);
0090     trial_ix = vb_tag_get_trial_index(tag_obj);
0091 
0092     % get onset sample list
0093     proc_spec.proc_parm.trigger = sort([data.trial_list(trial_ix).onset]);
0094     % Round trigger point
0095     proc_spec.proc_parm.trigger = round(...
0096                                       proc_spec.proc_parm.trigger * ...
0097                                      (data.output_sample_freq/sample_freq));
0098 
0099     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0100     % OUTPUT FILENAME
0101     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0102     proc_spec.new_file = data.output_file{k}.output_file;
0103 
0104     tmp = proc_spec.new_file;
0105     try
0106         vb_save(tmp, 'tmp');
0107         delete(tmp);
0108     catch
0109         errordlg(['Unable to make file : ', tmp, ...
0110                   sprintf('\nCheck directory permission.'), ...
0111                  ], 'Output MEG(EEG) file');
0112         return;
0113     end
0114     
0115     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0116     % Start creating file
0117     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0118     if isfield(data, 'batch_mode') && data.batch_mode
0119         h = -1;
0120         vb_disp('Now putting file(s). Please wait');
0121     else
0122         h = msgbox('Now putting file(s) ...', 'Please wait');
0123         bh = findall(h, 'Style', 'pushbutton');
0124         set(bh, 'Visible', 'off'); drawnow; pause(0.1);
0125     end
0126 
0127     vb_disp_nonl(sprintf('Label: %s -> %s ... ',...
0128                     vb_tag_get_tag_name(tag_obj), ...
0129                     proc_spec.new_file));
0130 
0131     vb_msrmnt_make_trial_data(proc_spec);
0132     vb_disp('done.');
0133     if ishandle(h), delete(h); end
0134 end
0135 
0136 
0137 function [err] = inner_make_down_sample_file(org_file, new_file, freq)
0138 err = false;
0139 
0140 try
0141 MEGinfo = vb_load_measurement_info(org_file);
0142 measurement = vb_info_get_measurement(MEGinfo);
0143 
0144 switch(upper(measurement))
0145     case 'MEG'
0146         fieldname = 'new_meg';
0147         func_name = 'vb_megfile_filter_ch_data';
0148     case 'EEG'
0149         fieldname = 'new_eeg';
0150         func_name = 'vb_eegfile_filter_ch_data';
0151     otherwise
0152         err = true;
0153         error('Unknown measurement device was specified.');
0154 end
0155 
0156 proc_spec.(fieldname) = new_file;
0157 proc_spec.parm.fsamp = freq;
0158 feval(func_name, org_file, proc_spec);
0159 
0160 catch
0161     err = true;
0162 end

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