function varargout=dopEventDifference(eventData)
% dopOSCCI Mark II: dopEventDifference ~ 2-12-2010 (last edit)
%
% calculate event data difference channel = left - right
%
% 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 Difference (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);
    
    ed.translation='event difference';
    ed.structAbbreviations='ed';
    ed.data=eventData; clear eventData
    
    if isstruct(ed.data) % most likely a stack of data from dopEventStack
        ed.fns=ed.data.evNames; % prior 29-10-10 fieldnames(ed.data); % field names
        for i=1:length(ed.fns)
            ed.fn=ed.fns{i};
            ed.out.(ed.fn)=diff(flipdim(ed.data.(ed.fn),3),1,3);
        end
    else % but just in case it's just a 3 dimensional array...
        ed.out.(ed.fn)=diff(ed.data,1,3)*-1;
    end
    
    %% set ouputs
    varargout{1}=ed.out;
    fprintf('\t%s\n','Done');
catch err
    %% catch dopOSCCI error
    % 
    save(dopOSCCIdebug(mfilename));rethrow(err); 
%     dopOSCCIcrash(err,ed,mfilename);
end

clear ed inputs

