#if !defined(PHOTOM_MATCH_H)
#define PHOTOM_MATCH_H

   /* 
    * this value denotes a "bad" magnitude measurement -- do not
    * include it in any computations.
    */
#define BAD_MAG        99.0

   /* there can be at most this many passbands defined in each file */
#define MAX_PASSBANDS  4

   /* filter names have at most this many characters */
#define FILTER_LENGTH  2

   /* we allow this many input files with detected star lists */
#define MAX_DETECTED_FILES    300

   /* each file name may be this long */
#define MAX_FILENAME_LEN      255

   /* default radius for two stars to match is 10 arcseconds */
#define MATCH_RADIUS   10.0

   /* our photometric solution contains this many unknown coefficients */
#define PHOTOM_COEFFS   2

   /* 
    * This controls how we calculate uncertainty in calibrated magnitudes.
    * 
    * IGNORE_SYSTEMATICS  0    will include uncertainties in all the 
    *                             photometric coefficients.  This choice
    *                             will end up giving bright and faint stars
    *                             very similar overall uncertainties, 
    *                             which are dominated by the uncertainty
    *                             in zero-point (usually)
    *
    * IGNORE_SYSTEMATICS  1    will ignore uncertainties in the zero-point
    *                             and extinction coefficients.  This choice
    *                             will yield uncertainties which are 
    *                             dominated by the uncerts in raw, instrumental
    *                             magnitudes.  Thus, bright stars will be
    *                             given small uncertainties, and faint stars
    *                             large uncertainties.
    *
    */
#define IGNORE_SYSTEMATICS 1


   /* 
    * We calculate weights for each star in the photometric solution
    * based on the estimated uncertainty in their instrumental mags.
    * These are some limits on those uncertainties and weights,
    * to keep the solution from blowing up.
    */
#define PHOTOM_MIN_UNCERT   0.002   /* if uncert in instr. mag < this, */
                                    /*    then pretend it was this */
#define PHOTOM_MAX_UNCERT   0.100   /* if uncert in instr. mag > this, */
                                    /*    then assign PHOTOM_TINY_WEIGHT */
#define PHOTOM_TINY_WEIGHT  1.0e-10 /* this weight is so small that a star */
                                    /*    will not affect solution */

   /* 
    * the 'flag' field of S_DET structures holds information for each star
    * which is placed into the output calibrated magnitude file. 
    * We use logical OR to hold a variety of values in this field.
    * However, the photom program just passes values through without
    * altering them in any way ... so it doesn't need to know the
    * flag meanings.  Look for the meanings elsewhere.
    */


   /* file extensions, given to output file names */
#define COEFFS_EXT       ".coeff"   /* holds brief list of coeff values */
#define COMPARE_EXT      ".comp"    /* holds comparison of known and */
                                    /*    measured mags for standard stars */
#define CALIBRATED_EXT   ".cal"     /* holds output, calibrated star list */

   /* multiply by this to convert degrees to radians */
#ifndef PI
#define PI 3.14159265359
#endif
#define DEGTORAD  (PI/180.0)

   /* this structure contains information on DETECTED stars */
typedef struct s_detected {
   int id;              /* used for internal debugging only */
   double ra;           /* Right Ascension of star, J2000 */
   double dec;          /* Declination of star, J2000 */
   double jd;           /* Julian Date of measurement */
   double airmass;      /* airmass at time of measurement */
   char filter[MAX_PASSBANDS][FILTER_LENGTH+1];   /* name of filter */
   double mag[MAX_PASSBANDS];          /* instrumental magnitude of star */
   double magerr[MAX_PASSBANDS];       /* estimated uncertainty in instrumental magnitude */
   int cat_match_id;    /* index of matching catalog star */
                        /*     -1 means no match, >= 0 means match */
   int include;         /* 1 = include in solution, 0 = don't include */

   double calib_mag[MAX_PASSBANDS];    /* calibrate magnitude for star */
   double calib_magerr[MAX_PASSBANDS]; /* uncertainty in calib mag */
   int flag[MAX_PASSBANDS];    /* holds information placed in output file */
                               /*    see FLAG_* definitions above */
} S_DET;

   /* this structure contains information on CATALOG stars */
typedef struct s_catalog {
   int id;              /* used for internal debugging only */
   double ra;           /* Right Ascension of star, J2000 */
   double dec;          /* Declination of star, J2000 */
   char filter[MAX_PASSBANDS][FILTER_LENGTH+1];
   double mag[MAX_PASSBANDS];      /* known magnitude in each passband */
   int include;         /* 1 = include in solution, 0 = don't include */
} S_CAT;


   /* this structure holds information on a photometric solution */
typedef struct s_solution {
   int num_obs;        /* number of observations of stars used in solution */
	int num_zeropts;    /* number of independent zero-point values */
	                    /*   choices are:  1   combine all images together */
	                    /*                 N   if indiv. value for N images */
   double *a, *asig;   /* zero-point(s) of magnitude, and uncertainty */
   double b, bsig;     /* first-order color term, and its uncertainty */
   double k, ksig;     /* first-order extinction coeff, plus uncertainty */
   double rms;         /* RMS residual from the fit, in magnitudes */
} S_SOLUTION;



   /*
    * this struct is used to keep track of which passband indices 
    * are used with which other ones.
    */
typedef struct s_passbands {
   int pri_index[MAX_PASSBANDS];
   int sec_index[MAX_PASSBANDS];
   int cat_index[MAX_PASSBANDS];
   char pri_passband[MAX_PASSBANDS][FILTER_LENGTH+1];
   char sec_passband[MAX_PASSBANDS][FILTER_LENGTH+1];
   char cat_passband[MAX_PASSBANDS][FILTER_LENGTH+1];
} S_PASSBANDS;


   /*
    * create/delete detected star (S_DET) structures
    */

void
sdetFill(S_DET *star, double ra, double dec, double jd, 
         double airmass, unsigned int quality, 
	 int num_filt, char *filt_name[], double *mag_array, 
         double *magerr_array);
void
sdetPrint(S_DET *star);



   /*
    * create/delete catalog  star (S_CAT) structures
    */

void
scatFill(S_CAT *star, double ra, double dec, int num_filt,
         char *filt_array[], double *mag_array);
void 
scatPrint(S_CAT *star);


#endif   /* PHOTOM_MATCH_H */
