# include "external.h"
# include "shell.h"
# include "dvomath.h"
# include "convert.h"
# include "display.h"
# include "data.h"

# ifndef DVO_H
# define DVO_H

/* magnitude types */
enum {MAG_NONE, MAG_INST, MAG_CAT, MAG_SYS, MAG_REL, MAG_CAL, MAG_AVE, MAG_REF};

/* measure params */
enum {MEAS_ZERO, MEAS_RA, MEAS_DEC, MEAS_MAG, MEAS_dMAG, MEAS_MINST, MEAS_MCAT, 
      MEAS_MSYS, MEAS_MREL, MEAS_MCAL, MEAS_PHOTCODE, MEAS_TIME, MEAS_dR, MEAS_dD, 
      MEAS_FWHM, MEAS_DOPHOT, MEAS_XCCD, MEAS_YCCD, MEAS_XMOSAIC, MEAS_YMOSAIC, MEAS_FLAGS, MEAS_EXPTIME, MEAS_AIRMASS};

/* average params */
enum {AVE_ZERO, AVE_RA, AVE_DEC, AVE_MAG, AVE_REF, AVE_dMAG, AVE_Xm, AVE_Xp, AVE_NMEAS, 
      AVE_NMISS, AVE_TYPE, AVE_NPHOT, AVE_NCODE, AVE_NCRIT, AVE_FLAG};

typedef struct {
  char name[64];
  double RA0, RA1, DEC0, DEC1;
} RegionFile;

/* aregion, region_list, match_image, LoadImages */
RegionFile   *find_regions	    PROTO((double Ra, double Dec, double radius, int *Nregions));
GSCRegion    *get_regions	    PROTO((Image *image, int *Nregions));
void	      aregion		    PROTO((GSCRegion *region, FILE *f, double ra, double dec, char *path));
RegionFile   *region_list	    PROTO((char *filename, int *Nregions));
int	      match_image	    PROTO((Image *image, int Nimage, unsigned int T, short int S));
Image  	     *LoadImages	    PROTO((int *Nimage));
void	      image_subset	    PROTO((Image *image, int Nimage, int **Subset, int *Nsubset, Graphdata *graph, int RegionSelect, unsigned long int tzero, double trange, int TimeSelect));
void	      sort_images	    PROTO((Image *image, int N));
void	      sortave		    PROTO((Average *ave, int N));
void	      cprecess		    PROTO((Average *average, int Naverage, double in_epoch, double out_epoch));
void	      compare		    PROTO((Catalog *catlog1, Catalog *catlog2, Vector *rvec,  Vector *dvec,  Vector *mvec, Vector *drvec, Vector *ddvec, Vector *dmvec, double radius));

/*** photometry functions ***/
int           SetPhotSelections     PROTO((int *argc, char **argv));
int           SetImageSelection     PROTO((int mode, Graphdata *graphsky, int state));
void          FreeImageSelection    PROTO(());

int           InitPhotcodes         PROTO(());
int           GetPhotcodeInfo       PROTO((char *string, PhotCode **Code, int *Mode));

int           GetAverageParam       PROTO((char *parname));
int           GetMeasureParam       PROTO((char *parname));
int           GetMagMode            PROTO((char *string));
int           SelectMags            PROTO((int Nphot, int Tphot, int Ns, Average *average, Measure *measure, SecFilt *secfilt, int UL));
void          print_value           PROTO((FILE *f, double value, short int ival));
int           GetMeasureTypeCode    PROTO((Measure *measure));
int           DetermineTypeCode     PROTO((Average *average, Measure *measure, int Nphot));
double        ExtractAverages       PROTO((PhotCode *code, int mode, Average *ave, SecFilt *sec, Measure *meas, int param));
double       *ExtractMagnitudes     PROTO((PhotCode *code, int mode, Average *ave, SecFilt *sec, Measure *meas, int *n));
double       *ExtractMeasures       PROTO((PhotCode *code, int mode, Average *ave, SecFilt *sec, Measure *meas, int *nlist, int param));
double       *ExtractDMag           PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist));
double       *ExtractMeasuresDMag   PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist));
double       *ExtractMeasuresByDMag PROTO((PhotCode **code, int *mode, int use_first, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param));

# endif
