#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>


//put additional include files here

//put your own support static functions here



void quantiles(const vector& ix, double& min, double& q1, double& median, double& q3, double& max, double& iqr)
{
	
	QuantileOptions opt;
	QuantileResults res;
	int nRet;
	
	//Set all value to be true,test all option
	opt.Min = true;
	opt.iMin = true;
	opt.Q1 = true;
	opt.Median = true;
	opt.Q3 = true;
	opt.Max = true;
	opt.iMax = true;
	opt.IQR = true;
	opt.Range = true;
	//opt.Interpolate = INTERPOLATE_EDF;	// use default interpolation method
	opt.Interpolate = 0;	// Max 6/19/08 0 is default interpolation method ans same as Stat on Cols tool
	
	nRet = ocmath_quantiles( ix, ix.GetSize(), &opt, &res);	
	if (nRet != STATS_NO_ERROR)
	{
		XF_THROW_EX(CER_UNKNOWN_ERROR_EX, nRet);
	}
	
	if (min!=NULL)	min = res.Min;
	if (q1!=NULL)	q1 = res.Q1;
	if (median!=NULL)	median = res.Median;
	if (q3!=NULL)	q3 = res.Q3;
	if (max!=NULL)	max = res.Max;	
	if (iqr!=NULL)	iqr = res.IQR;
	
}

//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int quantiles_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return quantiles_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	return false;

}

int quantiles_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	return false;
}
//nGetNDialog = 0,1,2, corresponding to the XF GetN dropdown, 0 = dialog is not used
//you can change nRet to be one of XFEVT_PROCEED (defualt), XFEVT_ABORT, XFEVT_PROCEED_NO_DLG or XFEVT_PROCEED_WITH_DLG(when nGetNDialog = 0)
//nGetNDialog = -1 when Ok on GetN dialog to allow handler to preocess <auto> etc variables
//dwCntrl is combination of bits
//LTXF_FROM_GUI_MENU, LTXF_FROM_GUI_PROMPT, LTXF_FROM_AUTO_UPDATE, LTXF_FROM_FUNCTION, LTXF_THEME_USED, LTXF_CHANGE_PARAM
void quantiles_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{

}
//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int quantiles_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
