#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 */
  /* This isn't quite true anymore (GTR, 08/29/00) */

  TA_QUASARS_LOCUS lowzlocus; /** this must be allocated when the files
					are read in */
  TA_QUASARS_LOCUS midzlocus; /** 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 HIZMAGLIMIT;		/** limiting magnitude in i' for high-z
				 ** corrected for reddening */

  float CAPILIMIT;		/** limiting magnitude for spectroscopy in i',
				 ** corrected for reddening (luptitudes) */

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

  float LOWZULIMIT ;		/** limiting magnitude to check error
				 ** reasonableness in u' (luptitudes) */
  float LOWZGLIMIT ;		/** limiting magnitude to check error
				 ** reasonableness in g' (luptitudes) */
  float LOWZRLIMIT ;		/** limiting magnitude to check error
				 ** reasonableness in r' (luptitudes) */
  float LOWZILIMIT ;		/** limiting magnitude to check error
				 ** reasonableness in i' (luptitudes) */
  float LOWZZLIMIT ;		/** limiting magnitude to check error
				 ** reasonableness 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 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 BIGNSIGERRORS;

  float MINDETECT;

  float MAXDETECT;

  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 GALCUTBYPLANE;

  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 CUTWD;                   /*This sets White Dwarf cut, same as CUTASTARS */
  int CUTWM;                   /*This sets W + M cut, same as CUTASTARS*/

  int TARGETMIDZ;              /*This sets if midZ objects will be automatically targeted */

  int TARGETMIDZSOUTH;

  float UGMINASTAR;            /*These parameters set the mins and maxes of the Astar cut.*/

  float UGMAXASTAR;

  float GRMINASTAR;

  float GRMAXASTAR;

  float RIMINASTAR;

  float RIMAXASTAR;

  float IZMINASTAR;

  float IZMAXASTAR;

  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 RIMINMIDZ;

  float RIMAXMIDZ;

  float IZMINMIDZ;

  float IZMAXMIDZ;

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

  float UGMAXWD;

  float GRMINWD;

  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 IZMINWM;

  float IZMAXWM;

  float GERRMAXWM;

  float ERRINTERPCENTER;
  
  float IBRIGHT;

  float IBRIGHTINTERP;

  float MAXV;
  
  float MAXVSIG;

  float UGMINGALAXY;

  float UGMINHIGHZ;

  float UGMAXFAINT;

  float GRMAXFAINT;
  
  float CHILDERROR;

  float GRMINGAL;

  float GRMAXGAL;

  float RIMINGAL;
  
  float RIMAXGAL;

  float MINGALSIG;

  int DIAGREJECT;

  int DIAGACCEPT;

} TA_QUASARS_PARAMS;  /* pragma SCHEMA */

/* Prototypes */
int taQuasarsTargetSelect(TA_CALIB_OBJ *obj, const TA_QUASARS_PARAMS *params);
int cutAstars(float *mag, const TA_QUASARS_PARAMS *params);
int midZbox(float *mag, const TA_QUASARS_PARAMS *params);
int cutWDregion(float *mag, const TA_QUASARS_PARAMS *params);
int cutWMregion(float *mag, float *err, const TA_QUASARS_PARAMS *params);
int galaxyCut( const TA_CALIB_OBJ *obj, const TA_QUASARS_PARAMS *params, float *mag, double *galdist, int *inGalaxylocus);

void taQuasarsLog (FILE *fp, TA_CALIB_OBJ *obj, double val1, double val2, double val3, int reason);

#ifdef __cplusplus
}
#endif

#endif
