# 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((off_t *nimage));
int        SetImages              PROTO((Image *new, off_t Nnew));
void       SetProtect             PROTO((int mode));
int        SetSignals             PROTO((void));
int        Shutdown               PROTO((char *format, ...)) OHANA_FORMAT(printf, 1, 2);
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));
off_t     *find_images_data       PROTO((FITS_DB *db, Image *timage, off_t *nlist));
off_t     *find_images_name       PROTO((FITS_DB *db, char *filename, off_t *nlist));
off_t     *find_images_time       PROTO((FITS_DB *db, e_time start, e_time end, PhotCode *code, off_t *nlist));
void       find_matches           PROTO((Catalog *catalog, int photcode, e_time start, e_time end));
int        gcatalog               PROTO((Catalog *catalog));
Image     *gimages                PROTO((char *filename));
Image     *gtimes                 PROTO((off_t *NIMAGE));
void       help                   PROTO((void));
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, off_t Nimage));
double     opening_angle          PROTO((double x1, double y1, double x2, double y2, double x3, double y3));
e_time     parse_time             PROTO((Header *header));
int        save_image_db          PROTO((void));
void       sort_lists             PROTO((float *X, float *Y, int *S, int N));
void       unlock_image_db        PROTO((FITS_DB *db));
void       usage                  PROTO((void));
int        wcatalog               PROTO((Catalog *catalog));

void set_db (FITS_DB *in);
