function classify(varargin)

global CROSSVAL_METHOD_DEF;

switch nargin
    case 1
        paramModel = varargin{1};
        %PROJECT_BASE_PATH = 'D:\Analyze\Stimolos';
        PROJECT_BASE_PATH = 'D:\Analyze\Choice\24pilot';
        PROJECT_RESULT_PATH = 'results\SPM.mat';
    otherwise
        error('spmtoolbox:SVMCrossVal:arginError','Please Specify action and parameter model');
end

        % timeline params (claculate and plot)
        timelineParams = struct;
        
        timelineParams.frameShiftStart = getDouble(paramModel.txtFrameShiftStart);  % -20;
        timelineParams.frameShiftEnd   = getDouble(paramModel.txtFrameShiftEnd); %15;
        timelineParams.decodeDuration  = getDouble(paramModel.txtFrameShiftDur);
        timelineParams.psthStart       = getDouble(paramModel.txtPSTHStart); % -25;
        timelineParams.psthEnd         = getDouble(paramModel.txtPSTHEnd); % 20;
        timelineParams.baselineStart   = getDouble(paramModel.txtBaselineStart); % -22;
        timelineParams.baselineEnd     = getDouble(paramModel.txtBaselineEnd); % -20;       
       
        % common params
        calculateParams  = struct;
        
%         calculateParams.CROSSVAL_METHOD_DEF = CROSSVAL_METHOD_DEF;
        calculateParams.CROSSVAL_METHOD     = CROSSVAL_METHOD_DEF.svmcrossval;
        calculateParams.PROJECT_BASE_PATH   = PROJECT_BASE_PATH;
        calculateParams.PROJECT_RESULT_PATH = PROJECT_RESULT_PATH;
        
        calculateParams.RANDOMIZE       = 0;
        
        calculateParams.smoothed        = getChkValue(paramModel.chkSmoothed);

        calculateParams.svmargs         = get(paramModel.txtSVMopts,'String');
        calculateParams.sessionList     = 1:3;

        classStruct = parseClassDef(paramModel);
        
        
        calculateParams.labelMap        = LabelMap(classStruct.labelCells , classStruct.conditionCells, 'auto'); % LabelMap({'<','>','<+<','>+>','<+>','>+<'},{-2,-1,1,2,3,4}); 0 is autolabel
        calculateParams.classList       = getClasses(calculateParams.labelMap);
        calculateParams.eventList       = classStruct.eventMatrix; %[9,11,13; 10,12,14];
%         calculateParams.eventList       = getPSTEventMatrix(calculateParams.labelMap);
        
        subjectSelection = getSubjectIDString(paramModel);
        calculateParams.subjectSelection = subjectSelection;
        
        decode = claculateMultiSubjectDecodePerformance(timelineParams,calculateParams);

        display('Finished calculations.');
        display('Plotting...');

        plotParams                   = struct;
        
%         plotParams.CROSSVAL_METHOD_DEF = CROSSVAL_METHOD_DEF;
        plotParams.CROSSVAL_METHOD     = calculateParams.CROSSVAL_METHOD;
        
        plotParams.nClasses          = length(calculateParams.classList);

        plotParams.decodePerformance = decode.decodePerformance;
        plotParams.rawTimeCourse     = decode.rawTimeCourse;
        plotParams.SubjectID         = subjectSelection;
        plotParams.smoothed          = boolToYesNoString(calculateParams.smoothed);

        assignin('base','plotParams',plotParams);
%         plotDecodePerformance(params.psthStart,params.psthEnd,params.nClasses,decode.decodeTable,params.frameShiftStart,params.frameShiftEnd,decode.rawTimeCourse);
        plotDecodePerformance(timelineParams,plotParams);
            
        display('all done.');
end
    

%% subject loop
function decode = claculateMultiSubjectDecodePerformance(timelineParams,calculateParams)
decode = struct;
decode.decodePerformance = [];
decode.rawTimeCourse     = [];

for subjectCell = subjectSelection
    SubjectID = cell2mat(subjectCell);
    namehelper = strcat('s',SubjectID); %Vars can not start with numbers.

    display('loading SPM.mat ...');
    spm = load(fullfile(calculateParams.PROJECT_BASE_PATH,SubjectID,calculateParams.PROJECT_RESULT_PATH));
    display('... done.');

    % calculate
    calculateParams.(namehelper).des             = spm.SPM;
    calculateParams.(namehelper).voxelList       = parseVoxelList(paramModel,SubjectID);
    assignin('base','calculateParams',calculateParams);

    display(sprintf('calculating cross-validation performance time-shift for Subject %s. Please Wait. ...',SubjectID));
    display('switching off all warnings');
    warning_state               = warning('off','all');
    display('calculating ...');
    decode.(namehelper)         = calculateDecodePerformance(timelineParams,calculateParams,SubjectID);

    display('... done');
    display('restoring warnings');
    warning(warning_state);

    decode.decodePerformance    = [decode.decodePerformance decode.(namehelper).decodePerformance];
    decode.rawTimeCourse        = [decode.rawTimeCourse decode.(namehelper).rawTimeCourse];

    assignin('base','decode',decode);
end

end