0001 function result = vb_eegfile_trial_ch_data(proc_spec)
0002
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
0034 if ~exist('proc_spec', 'var'), proc_spec = []; end
0035 [proc_spec, trig_file, data_file] = inner_check_arguments(proc_spec);
0036
0037
0038
0039 result = [];
0040
0041 trig = load(trig_file);
0042
0043
0044 if ~isempty(proc_spec.proc_parm)
0045 if isfield(proc_spec.proc_parm, 'Pretrigger_ms') ...
0046 && ~isempty(proc_spec.proc_parm.Pretrigger_ms)
0047 pretrigger_ms = proc_spec.proc_parm.Pretrigger_ms;
0048 else
0049 pretrigger_ms = trig.parm.Pretrigger_ms;
0050 end
0051
0052 if isfield(proc_spec.proc_parm, 'Posttrigger_ms') ...
0053 && ~isempty(proc_spec.proc_parm.Posttrigger_ms)
0054 posttrigger_ms = proc_spec.proc_parm.Posttrigger_ms;
0055 else
0056 posttrigger_ms = trig.parm.Posttrigger_ms;
0057 end
0058 else
0059 pretrigger_ms = trig.parm.Pretrigger_ms;
0060 posttrigger_ms = trig.parm.Posttrigger_ms;
0061 end
0062
0063 load_spec.Trigger = trig.trig;
0064
0065
0066 load_spec.Pretrigger = ceil(pretrigger_ms *(fsamp/1000));
0067 load_spec.Posttrigger = ceil(posttrigger_ms *(fsamp/1000));
0068
0069 load_spec.ChannelType = 'ALL';
0070 new_file = proc_spec.new_file;
0071
0072 [eeg_data, ch_info] = vb_load_meg_data(data_file, load_spec, new_file);
0073 return;
0074
0075
0076
0077
0078
0079
0080
0081 function [proc_spec, trig_file, data_file] = inner_check_arguments(proc_spec)
0082 func_ = mfilename;
0083
0084 if isempty(proc_spec)
0085 error('(%s) proc_spec is a required parameter', func_);
0086 end
0087
0088
0089
0090
0091
0092
0093 if ~isfield(proc_spec, 'root_dir') || isempty(proc_spec.root_dir)
0094 proc_spec.root_dir = '.';
0095 end
0096
0097 if ~isfield(proc_spec, 'proc_parm')
0098 proc_spec.proc_parm = [];
0099 end
0100
0101
0102 if ~isfield(proc_spec, 'trig_file') || isempty(proc_spec.trig_file)
0103 error('(%s) trig_file is a required field of proc_spec', func_);
0104 end
0105
0106 trig_file = [proc_spec.root_dir '/' proc_spec.trig_file];
0107
0108 if exist(trig_file, 'file') ~= 2
0109 error('(%s) cannot find proc_spec.trig_file : %s', ...
0110 func_, trig_file);
0111 end
0112
0113 trig = load(trig_file);
0114 if ~isfield(trig, 'trig') || isempty(trig.trig)
0115 error('(%s) trig_file must have trig field', func_);
0116 end
0117
0118 if isfield(trig, 'parm') && ~isempty(trig.parm)
0119 if isfield(trig.parm, 'data_file') && ~isempty(trig.parm.data_file)
0120 data_file = [proc_spec.root_dir '/' trig.parm.data_file];
0121 else
0122 error('(%s) trig_file.parm must have data_file field', func_);
0123 end
0124 else
0125 error('(%s) trig_file must have parm field', func_);
0126 end
0127
0128 if exist(data_file, 'file') ~= 2
0129 error('(%s) cannot find data_file : %s', func_, data_file);
0130 end
0131
0132
0133 if ~isfield(proc_spec, 'new_file') || isempty(proc_spec.new_file)
0134 [fpath, fname] = vb_get_file_parts(data_file);
0135 proc_spec.new_file = ...
0136 sprintf('%s_epoch_%s.eeg.mat', fname, datestr(now, 'yymmdd-HHMMSS'));
0137 end
0138 return;
0139
0140
0141
0142
0143
0144