function varargout=dopEventAverage(eventData)
% dopOSCCI Mark II: dopEventAverage ~ 9-9-2010 (last edit)
%
% calculate event data average channel = mean(left, right) - use this to
% examine peak activation if desired.
%
% expects the inputted eventData to be an X (epoch) by Y (samples) by Z = 2
% (doppler channels - left right) array.
%
% copes with it being within a structure for multiple events:
% dop.stack.evenName1: [10x501x2 double], dop.stack.evenName2: [10x501x2
% double], etc.
% OR can just be the data itself, not in a structure.
%

fprintf('\n%s\n\t%s',['Running ',mfilename],...
    'Calculating Event Average = mean(left,right):');
try
%     inputs.varargin=varargin;
%     inputs.defaults=struct('epoch',[-10 10],... % epoch around event marker in seconds
%         'sample',25,... % sample rate of input (to figure out timing)
%         'eventLabels','mark1',...); % names of event channels
%         'evChs',0,... % doppler external channel numbers
%         'fillMethod','mirror'); % method to fill empty data with
%     
%     ed=setGetInputsStruct(inputs);
    
    ea.translation='event average';
    ea.structAbbreviations='ea';
    ea.data=eventData; clear eventData
    
    if isstruct(ea.data) % most likely a stack of data from dopEventStack
        ea.fns=ea.data.evNames; % prior 29-10-10 fieldnames(ea.data); % field names
        for i=1:length(ea.fns)
            ea.fn=ea.fns{i};
            ea.out.(ea.fn)=mean(ea.data.(ea.fn),3);
        end
    else % but just in case it's just a 3 dimensional array...
        ea.out.(ea.fn)=mean(ea.data,3);
    end
    
    %% set ouputs
    varargout{1}=ea.out;
    fprintf('\t%s\n','Done');
catch err
    %% remove the bc field
% type of temporary data storage
% 	dop=rmfield(dop,'bc');
save(dopOSCCIdebug(mfilename));rethrow(err); 
%     dopOSCCIcrash(err,ea,mfilename);
end

clear ea inputs

