# include "data.h"
# include "basic.h"
# include "astro.h"

# ifndef DVOSHELL_H
# define DVOSHELL_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_RA_ERR, AVE_DEC_ERR, AVE_U_RA, AVE_U_DEC, 
      AVE_U_RA_ERR, AVE_U_DEC_ERR, AVE_PAR, AVE_PAR_ERR, AVE_MAG, AVE_REF, AVE_dMAG, 
      AVE_Xm, AVE_Xp, AVE_NMEAS, AVE_NMISS, AVE_TYPE, AVE_NPHOT, AVE_NCODE, AVE_NCRIT, 
      AVE_FLAG, AVE_TYPEFRAC};

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

typedef struct {
  double X;
  double Y;
  double R;
  double D;
  double M, dM;
  char   dophot;
  double sky;
  double fx, fy, df;
  double Mgal, Map;
  int found;
  short int code;
  e_time t;
} CMPstars;

/*** dvo prototypes ***/
int           DetermineTypeCode     PROTO((Average *average, Measure *measure, int code));
double        DetermineTypefrac     PROTO((Average *average, Measure *measure, PhotCode *code));
double        ExtractAverages       PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int param));
double       *ExtractByDMag         PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param));
double       *ExtractDMag           PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist));
double       *ExtractMagnitudes     PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int *n));
double       *ExtractMeasures       PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param));
double       *ExtractMeasuresByDMag PROTO((PhotCode **code, int *mode, int use_first, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param));
double       *ExtractMeasuresDMag   PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist));
void          FreeImageSelection    PROTO(());
void          FreeImageSelection    PROTO(());
int           GetAverageParam       PROTO((char *parname));
void          GetAverageParamHelp   PROTO(());
int           GetMagMode            PROTO((char *string));
double        GetMeasure            PROTO((int param, Average *average, Measure *measure, double mag));
int           GetMeasureParam       PROTO((char *parname));
int           GetMeasureTypeCode    PROTO((Measure *measure));
int           GetPhotcodeInfo       PROTO((char *string, PhotCode **Code, int *Mode));
int           GetSelectionParam     PROTO(());
int           GetTimeSelection      PROTO((time_t *tz, time_t *te));
void          InitDVO               PROTO(());
int           InitPhotcodes         PROTO(());
Image        *LoadImages            PROTO((int *Nimage));
Image        *MatchImage            PROTO((unsigned int time, short int source));
Image        *MatchImage            PROTO((unsigned int time, short int source));
Coords       *MatchMosaic           PROTO((unsigned int time, short int source));
int           Quality               PROTO((Measure *measure, int IsDophot));
int           SelectMags            PROTO((int Nphot, int Tphot, int Ns, Average *average, Measure *measure, SecFilt *secfilt, int UL));

SkyList      *SelectRegions         PROTO((char *RegionName, char *RegionList));
SkyList      *SkyListLoadFile       PROTO((char *filename));
int           SetCATDIR             PROTO((char *path, int verbose));
char *        GetCATDIR             PROTO(());
SkyTable     *GetSkyTable           PROTO(());
SkyList      *SkyListFromFile       PROTO((char *filename));
int           SetRegionSelection    PROTO((int *argc, char **argv, char **RegionName, char **RegionList));

int           SetImageSelection     PROTO((int mode, int RegionSelect));
int           SetPhotSelections     PROTO((int *argc, char **argv, int Nparams));
int           SetSelectionParam     PROTO((int param));
int           TestAverage           PROTO((PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure));
int           TestPhotSelections    PROTO((PhotCode **code, int *mode, int param));
void          compare               PROTO((Catalog *catlog1, Catalog *catlog2, Vector *rvec,  Vector *dvec,  Vector *mvec, Vector *drvec, Vector *ddvec, Vector *dmvec, double radius));
void          cprecess              PROTO((Average *average, int Naverage, double in_epoch, double out_epoch));
void          image_subset          PROTO((Image *image, int Nimage, int **Subset, int *Nsubset, Graphdata *graph, int RegionSelect, unsigned long int tzero, double trange, int TimeSelect));
int           match_image           PROTO((Image *image, int Nimage, unsigned int T, short int S));
int           match_image_subset    PROTO((Image *image, int *subset, int Nsubset, unsigned int T, short int S));
void          print_value           PROTO((double value, short int ival));
void          sort_image_subset     PROTO((Image *image, int *subset, int N));
void          sort_images           PROTO((Image *image, int N));
void          sortave               PROTO((Average *ave, int N));
CMPstars     *cmpReadFits           PROTO((FILE *f, int *nstars));
CMPstars     *cmpReadText           PROTO((FILE *f, int *nstars));
int           RD_to_XYpic           PROTO((double *x, double *y, double r, double d, Coords *coords, double Rmin, double Rmax, double Rmid, int *leftside));

# endif
