void
JPlotLinearFit::JPlotLinearFitX
	(
	J2DPlotWidget* plot,
	JPlotDataBase* fitData,
	const JBoolean xlog,
	const JBoolean ylog
	)
{
	SetHasParameterErrors(kJTrue);
	SetParameterCount(2);
	SetHasGoodnessOfFit(kJTrue);
	itsXIsLog = xlog;
	itsYIsLog = ylog;
	if (!xlog && !ylog)
		{
		itsFunctionName = jnew JString("y = a+bx");
		}
	else if (!xlog && ylog)
		{
		itsFunctionName = jnew JString("y = a Exp(bx)");
		}
	itsRealCount = 0;
	GenerateFit();
	GenerateDiffData();
	if (itsYIsLog && !itsXIsLog)
		{
		AdjustDiffData();
		}
}
void
JPlotFitExp::JPlotFitExpX
	(
	J2DPlotWidget* plot, 
	JPlotDataBase* fitData
	)
{
	itsAParm	= 0;
	itsBParm	= 0;
	itsAErr	= 0;
	itsBErr	= 0;
	SetFunctionString("a*e^(b*x)");
	SetParameterCount(2);
	SetHasGoodnessOfFit(kJTrue);
}
void
JPlotFitQuad2::JPlotFitQuad2X
	(
	J2DPlotWidget* plot, 
	JPlotDataBase* fitData
	)
{
	SetParameterCount(3);
	SetHasGoodnessOfFit(kJTrue);
	itsFunctionName = "y = a + bx + cx^2";
	CalculateFirstPass();
	JVector p(3);
	p.SetElement(1, itsAParameter);
	p.SetElement(2, itsBParameter);
	p.SetElement(3, itsCParameter);
	GenerateFit(p, itsChi2Start);
}
JPlotFitProxy::JPlotFitProxy
	(
	J2DPlotWidget* 		plot, 
	JPlotDataBase* 		fitData,
	istream& 			is
	)
	:
	JPlotFitFunction(plot, fitData, 0, 0),
	itsErrors(NULL)
{
	is >> itsHasGOF;
	if (itsHasGOF)
		{
		is >> itsGOFName;
		is >> itsGOF;
		}

	itsParms	= new GVarList();
	assert(itsParms != NULL);
	itsParms->AddVariable("x", 0);

	JSize count;
	is >> count;
	for (JIndex i = 1; i <= count; i++)
		{
		JString name;
		is >> name;
		JFloat value;
		is >> value;
		itsParms->AddVariable(name, value);
		}

	SetParameterCount(count);
		
	JBoolean hasParameterErrors;
	is >> hasParameterErrors;
	
	if (hasParameterErrors)
		{
		SetHasParameterErrors(kJTrue);
		itsErrors	= new JArray<JFloat>;
		assert(itsErrors != NULL);
		for (JIndex i = 1; i <= count; i++)
			{
			JFloat value;
			is >> value;
			itsErrors->AppendElement(value);
			}
		}
	
	JFloat xMin;
	JFloat xMax;

	is >> xMin;
	is >> xMax;

	SetXRange(xMin, xMax);

	is >> itsFnString;
	
	itsFn	= NULL;
	JParseFunction(itsFnString, itsParms, &itsFn);
	SetHasGoodnessOfFit(itsHasGOF);

	GenerateDiffData();
}
JPlotFitProxy::JPlotFitProxy
	(
	JPlotFitFunction*	fit,
	J2DPlotWidget* 		plot, 
	JPlotDataBase* 		fitData
	)
	:
	JPlotFitFunction(plot, fitData, 0, 0),
	itsErrors(NULL),
	itsHasGOF(fit->HasParameterErrors()),
	itsGOFName(fit->HasGoodnessOfFit()),
	itsFnString(fit->GetFitFunctionString())
{
	if (itsHasGOF)
		{
		fit->GetGoodnessOfFitName(&itsGOFName);
		fit->GetGoodnessOfFit(&itsGOF);
		}
	itsParms	= new GVarList();
	assert(itsParms != NULL);
	itsParms->AddVariable("x", 0);
	const JSize count	= fit->GetParameterCount();
	SetParameterCount(count);
	for (JIndex i = 1; i <= count; i++)
		{
		JString name;
		JBoolean ok	= fit->GetParameterName(i, &name);
		assert(ok);
		JFloat value;
		ok	= fit->GetParameter(i, &value);
		assert(ok);
		itsParms->AddVariable(name, value);
		}

	if (fit->HasParameterErrors())
		{
		SetHasParameterErrors(kJTrue);
		itsErrors	= new JArray<JFloat>;
		assert(itsErrors != NULL);
		for (JIndex i = 1; i <= count; i++)
			{
			JFloat value;
			JBoolean ok	= fit->GetParameterError(i, &value);
			assert(ok);
			itsErrors->AppendElement(value);
			}
		}

	J2DPlotData* diff	= fit->GetDiffData();
	J2DPlotData* data;
	if (J2DPlotData::Create(&data, diff->GetXData(), diff->GetYData(), kJFalse))
		{
		const JArray<JFloat>* xerrors;
		if (diff->GetXPErrorData(&xerrors))
			{
			data->SetXErrors(*xerrors);
			}
		const JArray<JFloat>* yerrors;
		if (diff->GetYPErrorData(&yerrors))
			{
			data->SetYErrors(*yerrors);
			}
		SetDiffData(data);
		}
	JFloat xMin;
	JFloat xMax;
	fit->GetXRange(&xMin, &xMax);
	SetXRange(xMin, xMax);
	itsFn	= NULL;
	JParseFunction(itsFnString, itsParms, &itsFn);
	SetHasGoodnessOfFit(itsHasGOF);
}