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

// the interpolating spline information: this is based on the spline used by opihi/cmd.data/spline.c
typedef struct {
  int Nknots;
  double *xk;
  double *yk;
  double *y2;
} Spline;

/* global variables set in parameter file */
# define DVO_MAX_PATH 1024
char         ImageCat[DVO_MAX_PATH];
char        *CATDIR;
int          HOST_ID;
char        *HOSTDIR;
int          VERBOSE;
int          UPDATE;
int          PARALLEL;
int          PARALLEL_MANUAL;
int          PARALLEL_SERIAL;
char        *UPDATE_CATFORMAT;
char        *SINGLE_CPT;

char        *KH_FILE;
char        *DCR_FILE;

int          KH_RESET;
int          DCR_RESET;

SkyRegion    UserPatch;

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

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

void          usage_setastrom                 PROTO(());
void          initialize_setastrom            PROTO((int argc, char **argv));
int           args_setastrom                  PROTO((int argc, char **argv));

void          usage_setastrom_client          PROTO(());
void          initialize_setastrom_client     PROTO((int argc, char **argv));
int           args_setastrom_client           PROTO((int argc, char **argv));

// int           Shutdown                        PROTO((char *format, ...) OHANA_FORMAT(printf, 1, 2) );
// void          TrapSignal                      PROTO((int sig));
// void          SetProtect                      PROTO((int mode));
// int           SetSignals                      PROTO((void));

int           update_dvo_setastrom            PROTO(());
int           update_dvo_setastrom_parallel   PROTO((SkyTable *sky));

int           update_catalog_setastrom        PROTO((Catalog *catalog));

// spline correction functions
double spline_apply_dbl (double *x, double *y, double *y2, int N, double X);

int load_kh_correction (char *filename);
int get_kh_correction (int sub, int chip, double *dX, double *dY, float Minst);

int load_dcr_correction (char *filename);
int get_dcr_correction (int filter, double *dX, double *dY, float Color);
