#pragma numlittype(push, TRUE)
#include <origin.h>

// Add your special include files here.
// For example, if you want to use functions from the NAG library, 
// add the header file for the NAG functions here.

// Add code here for other Origin C functions that you want to define in this file,
// and access in your parameter initialization.

// You can access C functions defined in other files, if those files are loaded and compiled 
// in your workspace, and the functions have been prototyped in a header file that you have 
// included above. 
	
// You can access NLSF object methods and properties directly in your function code.
// You should follow C-language syntax in defining your function. 
// For instance, if your parameter name is P1, you cannot use p1 in your function code. 
// When using fractions, remember that integer division such as 1/2 is equal to 0, and not 0.5
// Use 0.5 or 1/2.0 to get the correct value.

// For more information and examples, please refer to the "User-Defined Fitting Function" 
// section of the Origin Help file.


//----------------------------------------------------------
// 
void _nlsfParamExpGrow2(
// Fit Parameter(s):
double& y0, double& x0, double& A1, double& t1, double& A2, double& t2,
// Independent Dataset(s):
vector& x_data,
// Dependent Dataset(s):
vector& y_data,
// Curve(s):
Curve x_y_curve,
// Auxilary error code: 
int& nErr)
{
	// Beginning of editable part
	x0 = min(x_data);
	int sign;
	t1 = get_exponent_cuv(x_y_curve, &y0, &A1, &sign);
	if (t1 < 0)
	{
			int nSize = x_data.GetSize();
			y0 = y_data[0] + y_data[nSize-1] - y0;
			A1 = A2 = -0.5 * sign * exp(A1+t1*(x_data[0]+x_data[nSize-1])-x0*t1);
			t1 = t2 = -1 / t1;
	}
	else
	{
			t1 = t2 = 1 / t1;
			A1 = A2 = 0.5 * sign * exp(A1+x0/t1);
	}
	t1 = t1 * 0.9;
	t2 = t2 * 1.1;
	// End of editable part
}