#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) */
  REGION *covermap; /* image of coverage of FIRST catalog (north or south) */
   double crval1;  /* coverage translate from (xpix,ypix) --> (RA,DEC) */
   double crval2;
   double crpix1;
   double crpix2;
   double cdelt1;
   double cdelt2;
   int nrow;	/* size of coverage map */
   int ncol;
  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 at epoch (integer 100ths of arcsecs) */
  int spd;          /* South polar distance at epoch (integer 100ths of asec)*/
  int ra2000;       /* J2000 Right ascension (integer 100ths of arcsecs) */
  int spd2000;      /* J2000 South polar distance (integer 100ths of arcsecs)*/
  int plateRa[5];   /* Right ascension (integer 100ths of arcsecs) on each
		     * plate, in same order as mag array. */
  int plateSpd[5];  /* South polar distance (integer 100ths of arcsecs)
                     * on each plate, in same order as mag array. */
  int mag[5];       /* 100 * magnitude (order first epoch blue, red;
		     * second epoch blue, red, N) */
  int field[5];     /* field on which object was detected, in same order
		     * as mag array */
  int pmRa;         /* Proper motion in ra (mas/yr, cos(dec) term included) */
  int pmDec;        /* Proper motion in dec (mas/yr) */
  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[10000]; /* Epoch for each USNO field (years).  1000*survey
			* number is added to distinguish between surveys. */
  double catEpoch;    /* Positions have been converted to this epoch (years) */
  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);
TA_USNO_CATALOG*
taUSNORead(double node, double incl, double equinox, double minMu,
	   double maxMu, double minNu, double maxNu, const char *catDir,
	   double epoch, int maxObjects, TA_USNO_CATALOG *catalog);
RET_CODE
taUSNOZoneRead(double node, double incl, double minMu, double maxMu,
	       double minNu, double maxNu, const char *catDir, double epoch,
	       int zone, TA_USNO_CATALOG *catalog, int *arraySize);
void
taUSNOToEpoch(TA_USNO_CATALOG *catalog, double epoch);

#ifdef __cplusplus
}
#endif

#endif
