function classify(varargin)

PROJECT_BASE_PATH = 'D:\Analyze\Choice\24pilot';
PROJECT_RESULT_PATH = 'results\SPM.mat';

switch nargin
    case 1
        action = 'decode';
        paramModel = varargin{1};
    otherwise
        error('spmtoolbox:SVMCrossVal:arginError','Please Specify action and parameter model');
end

    

    switch(action)
    case 'clear'
        evalin('base','clear map lm SPM classList dataTimeLine decodeTable labelTimeLine svmopts trialProtocol voxelList xTimeEnd xTimeStart xTimeWindow');
      
    case 'decode'
        
        
        % common params
        calculateParams  = struct;
        calculateParams.smoothed        = getDouble(paramModel.txtSmoothed);

        calculateParams.frameShiftStart = getDouble(paramModel.txtFrameShiftStart);  % -20;
        calculateParams.frameShiftEnd   = getDouble(paramModel.txtFrameShiftEnd); %15;
        calculateParams.decodeDuration  = getDouble(paramModel.txtFrameShiftDur);
        calculateParams.psthStart       = getDouble(paramModel.txtPSTHStart); % -25;
        calculateParams.psthEnd         = getDouble(paramModel.txtPSTHEnd); % 20;
        calculateParams.baselineStart   = getDouble(paramModel.txtBaselineStart); % -22;
        calculateParams.baselineEnd     = getDouble(paramModel.txtBaselineEnd); % -20;

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

        classStruct = parseClassDef(paramModel);
        
        calculateParams.classList       = classStruct.label; %{'<','>'};
        calculateParams.labelMap        = LabelMap(classStruct.label , classStruct.value); % LabelMap({'<','>','<+<','>+>','<+>','>+<'},{-2,-1,1,2,3,4});
        calculateParams.eventList       = classStruct.event; %[9,11,13; 10,12,14];

        params = struct;
        params.nClasses = 2;
        
        
        subjectSelection = getSubjectIDString(paramModel);
        decode = struct;
        decode.decodePerformance = [];
        decode.rawTimeCourse     = [];
        
        for subjectCell = subjectSelection
            SubjectID = cell2mat(subjectCell);

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

            %% calculate
            display(sprintf('calculating cross-validation performance time-shift for Subject %s',SubjectID));

            calculateParams.(SubjectID).des             = spm.SPM;
            calculateParams.(SubjectID).voxelList       = parseVoxelList(paramModel,SubjectID);
            
            assignin('base','calculateParams',calculateParams);
            
    %         [decodeTable rawTimeCourse] = calculateDecodePerformance(spm,params.frameShiftStart,params.frameShiftEnd,params.xTimeWindow,params.svmopts,1:4,params.sessionList,params.voxelList,params.classList,params.labelMap,params.normalize);
            display('switching off all warnings');
            warning_state = warning('off','all');
            
            decode.(SubjectID) = calculateDecodePerformance(calculateParams,SubjectID);
            display('restoring warnings');
            warning(warning_state);
            
            decode.decodePerformance = [decode.decodePerformance decode.(SubjectID).decodePerformance];
            decode.rawTimeCourse = [decode.rawTimeCourse decode.(SubjectID).rawTimeCourse];
  
            
%             display(sprintf('Min CrossVal Accuracy: %g%% \t Max CrossVal Accuracy: %g%%',decode.minPerformance,decode.maxPerformance));

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

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

        plotParams = struct;
        plotParams.psthStart = calculateParams.psthStart;
        plotParams.psthEnd   = calculateParams.psthEnd;
        plotParams.nClasses  = length(calculateParams.classList);
        
        plotParams.frameShiftStart   = calculateParams.frameShiftStart;
        plotParams.frameShiftEnd     = calculateParams.frameShiftEnd;
        plotParams.decodePerformance = decode.decodePerformance;
        plotParams.rawTimeCourse     = decode.rawTimeCourse;
        
        if numel(subjectSelection) == 1
          plotParams.SubjectID         = SubjectID;
        else
          plotParams.SubjectID         = 'Multiple';
        end

        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(plotParams);
            
        display('done.');

    otherwise
        display('give action command: clear, decode');
    end
    end