# include <ohana.h>
# include <dvo.h>
# include <signal.h>
# include <sys/time.h>
# include <time.h>
# include <zlib.h>

/* solaris requires both of these instead of ip.h:
   # include <sys/socket.h>
   # include <netinet/in.h>
*/

/* linux is happy with this, not solaris */
# include <netinet/ip.h>
# include <netdb.h>
# include <arpa/inet.h>
# include <glob.h>

int    VERBOSE;
char   CATDIR[256];
char   GSCFILE[256];
char   CATMODE[16];    /* raw, mef, split, mysql */
char   CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
float  RADIUS;
int    SKY_DEPTH;

SkyRegion UserPatch;  // used by MODE CAT

int        main                   PROTO((int argc, char **argv));

int        ConfigInit             PROTO((int *argc, char **argv));
void       GetConfig              PROTO((char *config, char *field, char *format, int N, void *ptr));

int        SetSignals             PROTO((void));
void       SetProtect             PROTO((int mode));
void       TrapSignal             PROTO((int sig));
int        Shutdown               PROTO((char *format, ...));

void       usage                  PROTO((void));
int        SkyTablePopulatedRange PROTO((int *ns, int *ne, SkyTable *sky, int Nstart));

SkyList   *SkyTablePopulatedList  PROTO((SkyTable *sky));
SkyList   *SkyTablePopulatedList_old  PROTO((SkyTable *sky, int Ns, int Ne));

int        LoadCatalog            PROTO((Catalog *catalog, SkyRegion *region, char *filename, char *mode));

int        merge_catalogs_new     PROTO((SkyRegion *region, Catalog *output, Catalog *input));
int        merge_catalogs_old     PROTO((SkyRegion *region, Catalog *output, Catalog *input, double RADIUS));

int 	  *init_measure_links     PROTO((Average *average, int Naverage, Measure *measure, int Nmeasure));
int 	  *init_missing_links     PROTO((Average *average, int Naverage, Missing *missing, int Nmissing));
int 	  *build_measure_links    PROTO((Average *average, int Naverage, Measure *measure, int Nmeasure));
int 	   add_meas_link     	  PROTO((Average *average, int *next, int Nmeasure, int NMEASURE));
int 	   add_miss_link     	  PROTO((Average *average, int *next, int Nmissing));
Measure   *sort_measure     	  PROTO((Average *average, int Naverage, Measure *measure, int Nmeasure, int *next));
Missing   *sort_missing     	  PROTO((Average *average, int Naverage, Missing *missing, int Nmissing, int *next_miss));
