#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 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 GRBIGNSIGERRORCUT;

  float MINDETECT;

  float MAXDETECT;

  float MAXMINDETECTMAG;

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

  float UGMAXFAINT2;

  float GRMAXFAINT;
  
  float CHILDERROR;

  float BADAMPERROR;

  float	UGRHIZUGMIN;

  float UGRHIZUMIN;

  float UGRHIZGRMAX;

  float UGRHIZRIMAX;

  float UGRHIZSLOPE;

  float UGRHIZOFFSET;

  float UGRHIZIZMIN;

  float GRIHIZUGMIN;

  float GRIHIZUMIN;

  float GRIHIZGRMIN1;

  float GRIHIZGRMIN2;

  float GRIHIZSLOPE;

  float GRIHIZOFFSET;

  float GRIHIZIZMAX;

  float GRIHIZIZMIN;

  float RIZHIZUMIN;
  
  float RIZHIZGMIN;
  
  float RIZHIZRIMIN;

  float RIZHIZSLOPE;

  float RIZHIZOFFSET;

  float RIZHIZIZMIN;
  
  float UVXUGMAX;

  int DIAGREJECT;

  int DIAGACCEPT;

} TA_QUASARS_PARAMS;  /* pragma SCHEMA */

/* Prototypes */
int taQuasarsTargetSelect(TA_CALIB_OBJ *obj, const TA_QUASARS_PARAMS *params);
int taQuasarsSouthernTargetSelect(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, int badamp, const TA_QUASARS_PARAMS *params);
int cutWMregion(float *mag, float *err, const TA_QUASARS_PARAMS *params);
int ugrHizCut(float *mag, float *err, const TA_QUASARS_PARAMS *params);
int griHizCut(float *mag, float *err, const TA_QUASARS_PARAMS *params);
int rizHizCut(float *mag, float *err, const TA_QUASARS_PARAMS *params);
int lowzColorCut(float *mag, float *err, int *det, const TA_QUASARS_PARAMS *params);

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

#ifdef __cplusplus
}
#endif

#endif
