#ifndef TA_QUASARS_PARAM_H
#define TA_QUASARS_PARAM_H

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Quasars Working Group target selection interface
 */

#include <dervish.h>
#include "taCalibObj.h"

/* Maximum number of locus points */
#define TA_MAX_LOCUS_POINTS 50


/* Quasars Working Group target selection parameters */

typedef struct taQuasarLocus
{
  float lk[TA_MAX_LOCUS_POINTS]; 	/* Stellar locus arrays k values */
  int ln[TA_MAX_LOCUS_POINTS]; 		/* Stellar locus arrays npts values (not used)*/
  double lxl[TA_MAX_LOCUS_POINTS]; 	/* Stellar locus arrays xlocus */
  double lyl[TA_MAX_LOCUS_POINTS]; 	/* Stellar locus arrays ylocus */
  double lzl[TA_MAX_LOCUS_POINTS]; 	/* Stellar locus arrays zlocus */
  double lkhatx[TA_MAX_LOCUS_POINTS]; 	/* Stellar locus arrays kx */
  double lkhaty[TA_MAX_LOCUS_POINTS]; 	/* Stellar locus arrays ky */
  double lkhatz[TA_MAX_LOCUS_POINTS]; 	/* Stellar locus arrays kz */
  double la[TA_MAX_LOCUS_POINTS]; 	/* Stellar locus arrays a */
  double lb[TA_MAX_LOCUS_POINTS]; 	/* Stellar locus arrays b */
  double theta[TA_MAX_LOCUS_POINTS]; 	/* Stellar locus arrays theta */
  int   npts; 			        /* number of points in locus array */
  double mink;				/* first point in locus;  blue end */
  double minkdist;			/* radius from first point in locus;  blue end */
  double maxk;				/* last point in locus;  red end */
  double maxkdist;			/* radius from last point in locus;  red end */
  double nsigmaerrors;			/* radius multiplier for error Gaussian */
  double galaxyklimit;			/* k limit to consider extended sources with l>0 galaxies */
  char  LOCUSID[256];			/* id string for locus, i.e. CAP-LOCUS or SKIRT-LOCUS-1a */
} TA_QUASARS_LOCUS;  /* pragma SCHEMA */

typedef struct taQuasarsParams

{

  /* This will have to be modified if we use different loci for different
	l,b in the skirt */
  /* Variables that are currently in use have ** beginning the comment */

  TA_QUASARS_LOCUS stellarlocus; /** this must be allocated when the files
					are read in */
  TA_QUASARS_LOCUS hizlocus; /** this must be allocated when the files
					are read in */
  char  LOCUSFILEDIR[256];	/** directory of locus point array param (need to expand for many loci)*/

  float magnitudeFuzz;		/** Maximum fuzz on magnitude limits */
  float drMin;			/* deVauc radius params */
  float drMax;			/* deVauc radius params look for fuzzies */
  float firstDelta;		/** first matching radius tolerance (arcsec) */

  float HIZULIMIT;		/* limiting magnitude to check error
				 * reasonableness in u' (luptitudes) */
  float HIZUERROR;		/* limiting error that is reasonable in u'
				 * (luptitudes) */
  float HIZGLIMIT;		/* limiting magnitude to check error
				 * reasonableness in g' (luptitudes) */
  float HIZGERROR;		/* limiting error that is reasonable in g'
				 * (luptitudes) */
  float HIZRLIMIT;		/* limiting magnitude to check error
				 * reasonableness in r' (luptitudes) */
  float HIZRERROR;		/* limiting error that is reasonable in r'
				 * (luptitudes) */
  float HIZILIMIT;		/* limiting magnitude to check error
				 * reasonableness in i' (luptitudes) */
  float HIZIERROR;		/* limiting error that is reasonable in i'
				 * (luptitudes) */
  float HIZZLIMIT;		/* limiting magnitude to check error
				 * reasonableness in z' (luptitudes) */
  float HIZZERROR;		/* limiting error that is reasonable in z'
				 * (luptitudes) */

  float LOWZULIMIT ;		/** limiting magnitude to check error
				 ** reasonableness in u' (luptitudes) */
  float LOWZUERROR;		/* limiting error that is reasonable in u'
				 * (luptitudes) */
  float LOWZGLIMIT ;		/** limiting magnitude to check error
				 ** reasonableness in g' (luptitudes) */
  float LOWZGERROR;		/* limiting error that is reasonable in g'
				 * (luptitudes) */
  float LOWZRLIMIT ;		/** limiting magnitude to check error
				 ** reasonableness in r' (luptitudes) */
  float LOWZRERROR;		/* limiting error that is reasonable in r'
				 * (luptitudes) */
  float LOWZILIMIT ;		/** limiting magnitude to check error
				 ** reasonableness in i' (luptitudes) */
  float LOWZIERROR;		/* limiting error that is reasonable in i'
				 * (luptitudes) */
  float LOWZZLIMIT ;		/** limiting magnitude to check error
				 ** reasonableness in z' (luptitudes) */
  float LOWZZERROR;		/* limiting error that is reasonable in z'
				 * (luptitudes) */
  float SYSUERR;                /* systematic error in u' (luptitudes) */
  float SYSGERR;                /* systematic error in u' (luptitudes) */
  float SYSRERR;                /* systematic error in u' (luptitudes) */
  float SYSIERR;                /* systematic error in u' (luptitudes) */
  float SYSZERR;                /* systematic error in u' (luptitudes) */



  float SPECGLIMIT;		/* limiting magnitude of spectrograph in g'
				 * (luptitudes) */
  float SPECRLIMIT;		/* limiting magnitude of spectrograph in r'
				 * (luptitudes) */
  float SPECILIMIT;		/* limiting magnitude of spectrograph in i'
				 * (luptitudes) */
  float IPSFLIMIT;		/* limiting magnitude to check for stellarness
				 * in i' (luptitudes) */
  float ZPSFLIMIT;		/* limiting magnitude to check for stellarness
				 * in z' (luptitudes) */
  float LIKELIHOOD;		/* limit on acceptable fit to PSF (0.8) */
  float PSFFRACTION;		/* fraction of light that must be contributed
				 * by the central point source (fuzzy QSO
				 * detector) */

  float CAPSTARS;		/** sets the limit on the boundary of the cap
				 ** region based on the stellar density from
				 ** the Bahcall-Soneira model (1500/sq degree
				 ** for M<20) */
  float CAPGLIMIT;		/* limiting magnitude for spectroscopy in g',
				 * corrected for reddening (luptitudes) */
  float CAPRLIMIT;		/* limiting magnitude for spectroscopy in r',
				 * corrected for reddening (luptitudes) */
  float CAPILIMIT;		/** limiting magnitude for spectroscopy in i',
				 ** corrected for reddening (luptitudes) */

  float HIZUILIMIT;		/* limiting U-I color for hi-z quasars
				* (luptitudes) */
  float HIZUZLIMIT;		/* limiting U-Z color for hi-z quasars
				 * (luptitudes) */
  float HIZGILIMIT;		/* limiting G-I color for hi-z quasars
				 * (luptitudes) */
  float HIZGZLIMIT;		/* limiting G-Z color for hi-z quasars
				 * (luptitudes) */

  float SKIRTGLIMIT;		/* limiting magnitude for spectroscopy in g',
				 * corrected for reddening (luptitudes) */
  float SKIRTRLIMIT;		/* limiting magnitude for spectroscopy in r',
				 * corrected for reddening (luptitudes) */
  float SKIRTILIMIT;		/** limiting magnitude for spectroscopy in i',
				 ** corrected for reddening (luptitudes) */

  float SKIRTFIRSTGLIMIT;	/* limiting magnitude for FIRST source skirt
				 * spectroscopy in g' (luptitudes) */
  float SKIRTFIRSTRLIMIT;	/* limiting magnitude for FIRST source skirt
				 * spectroscopy in r' (luptitudes) */
  float SKIRTFIRSTILIMIT;	/* limiting magnitude for FIRST source skirt
				 * spectroscopy in i' (luptitudes) */

  float FIRSTERRORBOX;		/* matching radius for FIRST source with
				 * optical source (arcsecs) */

  float MAXQSOSPERFIELD;	/* if more than N candidates found per
				 * 0.17x0.2 sq degree field, then something
				 * may be wrong */

  float MAXQSOSPERTARGETAREA;	/* if more than NN candidates found per
				 * 3x3 sq degree target area something may
				 * be wrong */

  float GALMAX;                 /* Max and min bounds on the galaxy plane 
                                 * cut. */
  float GALMIN;

  float GALXCOEFF;              /* compontents of the normal to the 
                                 * fundamental plane of galaxies*/
  float GALYCOEFF;

  float GALZCOEFF;

  int CUTBOXES;                /* This flag sets whether the Astar, WD and W+M 
                                  regions will be targeted or not. 1 cuts these
				  regions from targetting; 0 targets objects in
				  these regions. */  
  int CUTASTARS;               /*This sets A star cut. 1 cuts; 0 targets A star box objects*/ 
  int TARGETMIDZ;              /*This sets if midZ objects will be automatically targeted */
  int CUTWD;                   /*This sets White Dwarf cut, same as CUTASTARS */
  int CUTWM;                   /*This sets W + M cut, same as CUTASTARS*/
  float UGMAXASTAR;            /*These parameters set the mins and maxes of the Astar cut.*/

  float UGMINASTAR;

  float GRMAXASTAR;

  float GRMINASTAR;

  float UGMINMIDZ;             /*These parameters set the constraints to the Midz cut which replaces
                                 portion of the Astar cut*/
  float UGMAXMIDZ;

  float GRMINMIDZ;

  float GRMAXMIDZ;

  float UGMINMIDZ2;            /*A second possible Midz cut, currently the usage of these cuts is mixed*/

  float UGMAXMIDZ2;

  float GRMINMIDZ2;

  float GRMAXMIDZ2;

  float MINMIDZDIST;


  float GRMINWD;               /* This set of parameters defines the constrints on the WhiteDwarf cut*/

  float GRMAXWD;

  float RIMINWD;

  float RIMAXWD;

  float IZMINWD;

  float IZMAXWD;


  float GRMINWM;               /* These parameters define the constraints on the W + Mstar cut.*/

  float GRMAXWM;

  float RIMINWM;

  float RIMAXWM;

  float RERRMAXWM;


} TA_QUASARS_PARAMS;  /* pragma SCHEMA */

/* Prototypes */
int taQuasarsTargetSelect(TA_CALIB_OBJ *obj, const TA_QUASARS_PARAMS *params);
int cutAstars( float *mag, float limit, float deltamag, const TA_QUASARS_PARAMS *params);
int midZbox(  float *mag, float limit, float deltamag, const TA_QUASARS_PARAMS *params);
int cutWDregion( float *mag, float limit, float deltamag, const TA_QUASARS_PARAMS *params);
int cutWMregion( float *mag, float limit, float deltamag, float *err, const TA_QUASARS_PARAMS *params);
int galaxyCut( const TA_CALIB_OBJ *obj, const TA_QUASARS_PARAMS *params, float *mag);
#ifdef __cplusplus
}
#endif

#endif
