#include <math.h>

/* prototypes for OS-X */
double ascfituserstatfunction_(double* real, 
			       double* error, 
			       double* pred, 
			       double* weight);
double ascfituserstaterror_(double* data);

/*
 * In this example we the standard Gaussian error calculation,
 * including a weight. This should be replaced by your
 * own definition.
 */
double ascfituserstatfunction_(double* real, 
			       double* error, 
			       double* pred, 
			       double* weight)
{
  return (*real - *pred)*(*real - *pred)* *weight/(*error * *error);
}

/*
 * The following routine calculates an error for the given data point.
 * In the example below we use the Gaussian approximation (so we
 * return the square root of the absolute value of the data point)
 * unless the data value is small.
 *
 * This routine is only called if an error array has not been added
 * to the dataset (e.g. by 'READ ERRORS' or 'set_errors()').
 */
double ascfituserstaterror_(double* data)
{
  double f = fabs(*data);  
  return (f > 1e-10? sqrt(f):1e-10);
}
