#ifndef TA_CATALOGS_H
#define TA_CATALOGS_H

#ifdef __cplusplus
extern "C" {
#endif

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

/* FIRST catalog entry --- just the fields which we copy to the tsObj files */
typedef struct taFirst
{
  int id;
  double lambda;  /* survey longitude (degrees) */
  double eta;     /* survey latitude (degrees) */
  int wflag;      /* 1=may be a sidelobe of nearby bright source, 0=not */
  float fpeak;    /* peak flux density (mJy) */
  float fint;     /* integrated flux density (mJy) */
  float rms;      /* local noise estimate at source position (mJy) */
  float maj;      /* major axis (FWHM, arcsec) from elliptical gaussian model*/
  float min;      /* major axis (FWHM, arcsec) from elliptical gaussian model*/
  float pa;       /* position angle (degrees east of north) from ell gau model*/
} TA_FIRST; /* pragma SCHEMA */

/* FIRST catalog */
typedef struct taFirstCatalog
{
  char *version;      /* Version */
  int nObj;           /* number of objects */
  int newSearch;      /* 1=initiate new search, 0=search from last position */
  double matchRadius; /* match radius for simple catalog objects (degrees) */
  double matchRadiusDouble; /* match radius for complex catalog objects (deg)*/
  double doubleSize; /* maximum radio size of doubles (arcsecs) */
  TA_FIRST *obj;      /* array of objects */
} TA_FIRST_CATALOG; /* pragma SCHEMA */

/* ROSAT catalog entry --- just the fields which we copy to the tsObj files */
typedef struct taRosat
{
  int id;           /* Unique ID */
  double lambda;    /* survey longitude (degrees) */
  double eta;       /* survey latitude (degrees) */
  float posErr;     /* Error in position (arcsecs) */
  TA_FLOAT_ERR cps; /* source countrate in broad energy band
		     * (PHA range 11 - 235), vignetted corrected(counts/sec) */
  TA_FLOAT_ERR hr1; /* hardness ratio 1 = (B - A) / (B + A) where
		     *   A = countrate in PHA range 11 - 41
		     *   B = countrate in PHA range 52 - 201 */
  TA_FLOAT_ERR hr2; /* hardness ratio 2 = (D - C) / (D + C) where
		     *   C = countrate in PHA range 52 - 90
		     *   D = countrate in PHA range 91 - 201 */
  float ext;        /* Extent parameter (arcsecs) */
  float extLike;    /* Likelihood of extent parameter */
  float detectLike; /* Likelihood of detection */
  float exposure;   /* Exposure time (seconds) */
} TA_ROSAT; /* pragma SCHEMA */

/* ROSAT catalog */
typedef struct taRosatCatalog
{
  char *version;      /* Version */
  int nObj;           /* number of objects */
  int newSearch;      /* 1=initiate new search, 0=search from last position */
  double matchRadius; /* match radius when searching catalog (degrees) */
  TA_ROSAT *obj;      /* array of objects */
} TA_ROSAT_CATALOG; /* pragma SCHEMA */

/* USNO catalog entry --- just the fields which we copy to the tsObj files */
typedef struct taUSNO
{
  int ra;           /* Right ascension (integer 100ths of arcsecs) */
  int spd;          /* South polar distance (integer 100ths of arcsecs) */
  int mags;         /* Bit-mapped mag field, modified from that in USNOA2.0
		     * to accomodate unique field number over both north and
		     * south --- FFFFBBBRRR
		     *   FFFF = field on which object was detected --- south
		     *          fields have 1000 added to distinguish from
		     *          north fields
		     *   BBB  = 10 times the blue magnitude
		     *   RRR  = 10 times the red magnitude */
  int lambda;       /* Survey "longitude" (integer 100ths of arcsecs) */
} TA_USNO; /* pragma SCHEMA */

/* USNO catalog */
typedef struct taUSNOCatalog
{
  char *version;      /* Version */
  int nObj;           /* number of objects */
  int newSearch;      /* 1=initiate new search, 0=search from last position */
  double matchRadius; /* match radius when searching catalog (degrees) */
  double epoch[2000]; /* Epoch for each USNO field (years, south fields have
		       * 1000 added to them to distinguish from north fields)*/
  TA_USNO *obj;      /* array of objects */
} TA_USNO_CATALOG; /* pragma SCHEMA */

/* Forward declarations */

void
taObjMatchAgainstFirst(TA_CALIB_OBJ *obj, TA_FIRST_CATALOG *catalog);
void
taObjMatchAgainstRosat(TA_CALIB_OBJ *obj, TA_ROSAT_CATALOG *catalog);
void
taObjMatchAgainstUSNO(TA_CALIB_OBJ *obj, TA_USNO_CATALOG *catalog);
RET_CODE
taUSNORead(double node, double incl, double equinox, double minMu,
	   double maxMu, const char *catDir, TA_USNO **array, int *nObj);
RET_CODE
taUSNOZoneRead(double node, double incl, double minMu,
	       double maxMu, const char *catDir, int zone, TA_USNO **array,
	       int *arraySize, int *nObj);

#ifdef __cplusplus
}
#endif

#endif
