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

enum {DOPHOT, CHAD, SEXTRACT};

int    MODE;
int    VERBOSE;
int    RESET;
int    FORCE_RUN;
int    PROVIDE_ASTROM;
int    NEWPHOTCODE;

/* global variables set in parameter file */
char   *PHOTCODE;
char   PhotCodeFile[256];
char   AstromFile[256];

double DEFAULT_ERROR;
double RADIUS;
double TRAIL_WIDTH;
int    NBINS;
int    NPTSINLINE;
double MIN_DENSITY;
double NSIGMA;

double RA, DEC, ZERO_POINT, MIN_SN_FSTAT;
int CHAR_LINE, TYPE_FIELD, AP_FIELD, PSF_FIELD, HEADER_COORDS;

int FIX_KEYWORD;
char **KEYWORD, **KEYVALU, **KEYFMT;

typedef struct {
  double X;
  double Y;
  double M, dM;
  char   dophot;
  double sky;
  double fx, fy, df;
  double Mgal, Map;
} Stars;

Stars *LoadStars ();
Stars *LoadStarsChad ();
Stars *LoadStarsSex ();

Stars *LoadStarsDophot (char *filename, int *nstars, Header *header);
Stars *LoadStarsChad (char *filename, int *nstars, Header *header);
Stars *LoadStarsSex (char *filename, int *nstars, Header *header);

void ConfigInit (int *argc, char **argv);
void AdjustHeader (Header *header);
void sort_stars (Stars *X, int N);
void find_trails (Stars *stars, int Nstars);
int find_group (Stars *stars, char *mark, int Npts, int i, double *ANGLE);
void wstars (char *filename, Stars *stars, int Nstars, Header *header);

void fix_total (Stars *stars, int Nstars, Header *header);
int find_line (Stars *stars, char *mark, int Npts, int i, double *M, double *B, double Angle);
void find_better_line (Stars *stars, char *mark, int Npts, int i, double *M, double *B, int axis);

void help ();
void args (int argc, char **argv);
