# include <ohana.h>
# include <loneos.h>

typedef struct {
  double median;
  double mean;
  double sigma;
  double error;
  double chisq;
  double min;
  double max;
  double total;
  int    Nmeas;
} StatType;

typedef struct {
  void *tgroup;
  void *sgroup;
} ImageLink;

typedef struct {
  char label[64];
  short int M;
  short int dM;
  short int dMsub;
  double v1, v2;
  Image **image;
  ImageLink **imlink;
  int Nimage, Ngood;
} Group;

/* global variables set in parameter file */
char         ImageCat[256];
char         CATDIR[256];
char         STATMODE[64];
int          VERBOSE;
int          NLOOP;
int          TimeSelect;
int          VERBOSE;
int          UPDATE;
int          IMAGE_BAD;
double       RADIUS;
double       TRANGE;
unsigned int TSTART;
unsigned int TSTOP;
PhotCode    *photcode;

enum {black, white, red, orange, yellow, green, blue, indigo, violet};

/***** prototypes ****/
Group *find_image_tgroups (Image *image, ImageLink *imlink, int Nimage, int *Ntgroup);
Group *find_image_sgroups (Image *image, ImageLink *imlink, int Nimage, int *Nsgroup);
Image *load_images (int *nimage);
char *sec_to_date (unsigned long second);
double sec_to_jd (unsigned long second);
int main (int argc, char **argv);
int args (int argc, char **argv);
int liststats (double *value, double *dvalue, int N, StatType *stats);
int dms_to_ddd (double *Value, char *string);
int str_to_radec (double *ra, double *dec, char *str1, char *str2);
int chk_time (char *line);
int str_to_time (char *line, unsigned int *second);
int str_to_dtime (char *line, double *second);
int Fseek (FILE *f, long offset, int whence);
unsigned long int jd_to_sec (double jd);
unsigned long date_to_sec (char *date);
void initialize (int argc, char **argv);
void ConfigInit (int *argc, char **argv);
void fit_tgroup (Group *tgroup, int Ntgroup);
void fit_sgroup (Group *sgroup, int Nsgroup);
void initstats (char *mode);
void sort (unsigned int *X, int N);
void sortB (double *X, double *Y, int N);
void sortD (double *X, double *Y, double *Z, int N);
