//
// Simple implementation of the Sherpa beta1D model as a user model
//
// Unlike the "ascfit" usermodel version we just need to provide a
// routine that will evaluate the model. The user_model.cc file
// contains routines that handle the S-Lang interface.
//
// Both *.cc files need editing if you want to add your own model(s).
//
// Although written in C++, the code does not make use of the
// features provided by the language.

#include <math.h>

// prototype
void evaluate_beta1d(double r0,
		     double beta,
		     double xpos,
		     double ampl,
		     double *x,
		     double *y,
		     int nelem);

// This routine evaluates the model and fills in the output array
//
void evaluate_beta1d(double r0,
		     double beta,
		     double xpos,
		     double ampl,
		     double *x,
		     double *y,
		     int nelem)
{
  // Evaluate:
  //   f(x) = A (1+[(x-xpos)/r_o]^2)^(-3*beta+1/2)
  //
  double powterm = 0.5 - 3.0 * beta;
  double r02 = r0 * r0;

  int i;
  for(i = 0; i < nelem; i++)
  {
    y[i] =
      ampl * pow (1.0 + (x[i] - xpos)*(x[i] - xpos)/r02, powterm);
  }
}

// End
