#include "AutoCal.h"
#include <fstream>
#include <math.h> // function "pow()"

using std::ofstream;

IHAC_AutoCal::IHAC_AutoCal()
{
	_InitCP();
	
	NLP = new T_NonLinear_Parms[CP.ncombi];
	_Set_PreCalibration1_Parms(CP, NLP);
}

IHAC_AutoCal::~IHAC_AutoCal()
{
	delete[] NLP;
}

T_NonLinear_Parms *IHAC_AutoCal::_Set_PreCalibration1_Parms(T_Cal CP, T_NonLinear_Parms *nlp)
{
	int		i, j, k;
	double	parm1, parm2, parm3;
	double	step1 = (CP.ub1 - CP.lb1) / CP.nsteps1;
	double	step2 = (CP.ub2 - CP.lb2) / CP.nsteps2;
	double	step3 = (CP.ub3 - CP.lb3) / CP.nsteps3;
	int		counter = 0;
	
	for (i = 0; i < CP.nsteps1+1; i++)
	{
		parm1 = CP.lb1 + i * step1;
		for (j = 0; j < CP.nsteps2+1; j++)
		{
			parm2 = CP.lb2 + j * step2;
			for (k = 0; k < CP.nsteps3+1; k++)
			{
				parm3 = CP.lb3 + k * step3;

				// Assign non-linear parameter settings
				nlp[counter].Tw = parm1;
				nlp[counter].c	= parm2;
				nlp[counter].f	= parm3;
				counter++;
			} // end for(k...)

		} // end for(j...)

	} // end for(i...)

	return(nlp);
}

void IHAC_AutoCal::_InitCP()
{
	CP.nsteps1 = 10;
	CP.nsteps2 = 10;
	CP.nsteps3 = 10;
	CP.ncombi = (CP.nsteps1 + 1) * (CP.nsteps2 + 1) * (CP.nsteps3 + 1);

	CP.lb1 = 0;
	CP.ub1 = 10;

	CP.lb2 = 0;
	CP.ub2 = 22;

	CP.lb3 = 0.00178;
	CP.ub3 = 0.00469;
}