# include <ohana.h>
# include <dvo.h>
# include <signal.h>

typedef struct {
  Coords coords;
  float *X, *Y;
  int *N;
  double RA[2], DEC[2];
  double Area, density, spacing;
} CatStats;

/* global variables set in parameter file */
char   ImageCat[256];
char   ImageTemplate[256];
char   CatTemplate[256];
char   GSCFILE[256];
char   CATDIR[256];
char   CATMODE[16];    /* raw, mef, split, mysql */
char   CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
double NSIGMA;
double ALPHA;
int    VERBOSE;
int    ORPHAN;
int    MISSED;
char   SKY_TABLE[256];
int    SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */

time_t    START;
time_t    END;
PhotCode *PHOTCODE;

int    MODE;
enum {MODE_IMAGENAME, MODE_IMAGEFILE, MODE_TIME, MODE_ORPHAN, MODE_MISSED};

char DateKeyword[64], DateMode[64], UTKeyword[64], MJDKeyword[64], JDKeyword[64];

/*** delstar prototypes ***/
void       ConfigInit             PROTO((int *argc, char **argv));
int        FindDecBand            PROTO((double dec, double *DEC0, double *DEC1));
FILE      *GetDB                  PROTO((int *state));
Image     *GetImages              PROTO((int *nimage));
int        SetImages              PROTO((Image *new, int Nnew));
void       SetProtect             PROTO((int mode));
int        SetSignals             PROTO(());
int        Shutdown               PROTO((char *format, ...));
void       TrapSignal             PROTO((int sig));
int        args                   PROTO((int *argc, char **argv));
void       check_permissions      PROTO((char *basefile));
void       delete_imagefile       PROTO((FITS_DB *db, char *filename));
void       delete_imagename       PROTO((FITS_DB *db, char *name));
void       delete_times           PROTO((FITS_DB *db));
int        edge_check             PROTO((double *x1, double *y1, double *x2, double *y2));
int       *find_images_data       PROTO((FITS_DB *db, Image *timage, int *nlist));
int       *find_images_name       PROTO((FITS_DB *db, char *filename, int *nlist));
int       *find_images_time       PROTO((FITS_DB *db, time_t start, time_t end, PhotCode *code, int *nlist));
void       find_matches           PROTO((Catalog *catalog, int photcode, int start, int end));
int        gcatalog               PROTO((Catalog *catalog));
Image     *gimages                PROTO((char *filename));
Image     *gtimes                 PROTO((int *NIMAGE));
void       help                   PROTO(());
int        load_image_db          PROTO((FITS_DB *db));
void       lock_image_db          PROTO((FITS_DB *db, char *filename));
void       match_images           PROTO((Catalog *catalog, Image *image, int Nimage));
double     opening_angle          PROTO((double x1, double y1, double x2, double y2, double x3, double y3));
int        parse_time             PROTO((Header *header));
int        save_image_db          PROTO(());
void       sort_lists             PROTO((float *X, float *Y, int *S, int N));
void       unlock_image_db        PROTO((FITS_DB *db));
void       usage                  PROTO(());
int        wcatalog               PROTO((Catalog *catalog));

void set_db (FITS_DB *in);
