function classify(varargin)

switch nargin
    case 0
        action = 'decode';
        SubjectID = 'JZ006';
    case 1
        action = 'decode';
        paramModel = varargin{1};
        SubjectID = getSubjectIDString(paramModel);
    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'
        
        display('loading SPM.mat');
%         SubjectID = 'JZ006';
%         SubjectID = 'AI020';
%         SubjectID = 'HG027';
        spm = load(fullfile('D:\Analyze\Choice\24pilot',SubjectID,'results\SPM.mat'));

        display('done.');
        
        params = struct;
        params.nClasses = 2;

        assignin('base','params',params);
        %% calculate
        display('calculating cross-validation performance time-shift');
        calculateParams  = struct;
        
        calculateParams.des             = spm.SPM;
        
        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.voxelList       = parseVoxelList(paramModel);

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

        classStruct = parseClassDef(paramModel);
        assignin('base','classStruct',classStruct);
        
        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];
        
        
        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);
        decode = calculateDecodePerformance(calculateParams);
        display(sprintf('Min CrossVal Accuracy: %g%% \t Max CrossVal Accuracy: %g%%',decode.minPerformance,decode.maxPerformance));
        
        assignin('base','decode',decode);

        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;
        plotParams.SubjectID         = SubjectID;
        
        assignin('base','plotParams',plotParams);
%         plotDecodePerformance(params.psthStart,params.psthEnd,params.nClasses,decode.decodeTable,params.frameShiftStart,params.frameShiftEnd,decode.rawTimeCourse);
        plotDecodePerformance(plotParams);

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