function dop=dopSessionReset(dop)
% dopOSCCI Mark II: dopSessionReset ~ 20-11-2010 (last edit)
%
% reset session variable for next run
% - sets balancing saving coordindation
% - individual session details
% - clears particular variables
fprintf('%s\n',['Running ',mfilename]);
try
    %% balancing info
    % during save of regular data and graph data, the balanced screend (3rd
    % column the dop.scrn.(ev) matrix is only available for the combined
    % session summary (session = dop.ses.nSes+1).
    % When this is not the case, we don't want it to be saved...as it's not
    % there to be saved...
    if ~dop.ses.ind % setup (see dopSessionSet)
        fprintf('\t%s\n','First run during setup');
        dop.ses.bal=[0 0];
        if dop.def.saveEpochSelection(end) % 6 = bal
            dop.ses.bal(1)=1;
%             dop.scrn.saveData(end+1)=dop.def.saveEpochSelection(end);
%             dop.def.saveEpochSelection(5)=0;
            % this can only run during summary session save summary
            % see dopSessionCollect
        end
        if dop.def.saveEpochSelectionGraph(end)
            dop.ses.bal(2)=1;
%             dop.scrn.saveGraphData(end+1)=dop.def.saveEpochSelectionGraph(end);
%             dop.def.saveGraphData(5)=0;
            % this can only be run for combined session summary
        end
    else % resets & subsequent individuals
        fprintf('\t%s\n','run as reset');
        % epoch selection for regular data save (see dopSaveSum)
        % dop.ses.bal 1=save data, 2 = save graph data
        if sum(dop.ses.bal) && strcmp(dop.scrn.labels{end},'bal') %length(dop.def.saveEpochSelection)==5;
            dop.scrn.labels(end)=[];
%             dop.def.saveEpochSelection(5)=0;
        end
        % epoch selection for graph data save (see dopSaveGraphData)
%         if dop.ses.bal(2) && strcmp(dop.scrn.labels{end},'bal')
%             dop.def.saveGraphData(5)=0;
%         end
        % reset the screen labels...might not need the above resetting
        % anymore...
%         if strcmp(dop.scrn.labels{end},'bal')
%             dop.scrn.tmp=[];
%             for i=1:length(dop.scrn.labels)-1
%                 dop.scrn.tmp{end+1}=dop.scrn.labels{i};
%             end
%         end

    end
    %% some individual variables
    dop.ses.ind=dop.ses.ind+1; % individual number
    dop.ses.session=1; % session number
    dop.ses.combinedName=[]; % combined name used for combined summary session
    
    %% clear the session variables
    % if they exist
    if isfield(dop.ses,'vars')
        for i=1:length(dop.ses.vars);
            dop.tmp.var=dop.ses.vars{i};
            if isfield(dop.ses,dop.tmp.var)
                dop.ses=rmfield(dop.ses,dop.tmp.var);
            end
        end
    end
    if isfield(dop,'tmp');
        dop=rmfield(dop,'tmp');
    end
    fprintf('%s\n','Done');
catch err
    %% catch dopOSCCI error
    % 
save(dopOSCCIdebug(mfilename));throw(err); 
%     dopOSCCIcrash(err,dop,mfilename);
end

