# include "external.h"
# include "shell.h"
# include "dvomath.h"
# include "convert.h"
# include "display.h"

# ifndef DATA_H
# define DATA_H

/*** typedef structs used by math functions ***/
typedef struct {
  int   NLINES;
  int   Nlines;
  char **lines;
  char  *name;
} Queue;

typedef struct {
  char *name;
  int NWORDS;
  int Nwords;
  char **words;
  char **value;
} Page;

typedef struct {
  char *name;
  int NPAGES;
  int Npages;
  Page **pages;
  // int *index; (why did I define this?  is it not used?)
  char **pageIDs;
} Book;

void InitData ();

/* in book.c */
void InitBooks ();
void InitBook (Book *book, char *name);
void FreeBook (Book *book);
Book *FindBook (char *name);
Book *GetBook (int where);
Book *CreateBook (char *name);
int DeleteBook (Book *book);
void ListBooks ();

/* in page.c */
void InitPage (Page *page, char *name);
void FreePage (Page *page);
Page *FindPage (Book *book, char *name);
Page *GetPage (Book *book, int where);
Page *GetPageRestricted (Book *book, int where, char *keyName, char *keyValue);
Page *CreatePage (Book *book, char *name);
int ShufflePages (Book *book);
int DeletePage (Book *book, Page *page);
void ListPages (Book *book);
void ListWords (Page *page);
int BookSetWord (Page *page, char *word, char *value);
char *BookGetWord (Page *page, char *word);

/* in queues.c */
void InitQueues ();
void ListQueues ();
Queue *FindQueue (char *name);
Queue *CreateQueue (char *name);
void PushQueue (Queue *queue, char *line);
void PushNamedQueue (char *name, char *line);
char *PopQueue (Queue *queue);
char *PopQueueMatch (Queue *queue, char *Key, char *value);
void PushQueueUnique (Queue *queue, char *line, char *Key);
void PushQueueReplace (Queue *queue, char *line, char *Key);
int InitQueue (Queue *queue);
int DeleteQueue (Queue *queue);
int PrintQueue (Queue *queue);

/* in fft.c */
void fft1D (float *dataRe, float *dataIm, int N, int Nbit, int forward);
int fftND (float *dataRe, float *dataIm, int Ndim, int *Nsize, int forward);
int IsBinary (int N, int *Nbit);

/* in spline.c */
void spline_construct (float *x, float *y, int N, float *y2);
float spline_apply (float *x, float *y, float *y2, int N, float X);

/* in svdcmp.c */
int svdcmp (float *a, float *w, float *v, int Nx, int Ny);

/* mrqmin.c */
float mrqcof (float *x, float *y, float *dy, int Npts, 
	      float *par, int Npar, float **ta, float **tb, 
	      float (funcs)(float, float *, int, float *));

float mrqmin (float *x, float *y, float *dy, int Npts, 
	      float *par, int Npar, 
	      float (funcs)(float, float *, int, float *), int VERBOSE);

float mrqinit (float *x, float *y, float *dy, int Npts, 
	       float *par, int Npar, 
	       float (funcs)(float, float *, int, float *), int VERBOSE);

float **mrqcovar (int Npar);

void mrqfree (int Npar);

/* mrq2dmin.c */
float mrq2dcof (float *x, float *t, float *y, float *dy, int Npts, 
		float *par, int Npar, float **ta, float **tb, 
		float (funcs)(float, float, float *, int, float *));

float mrq2dmin (float *x, float *t, float *y, float *dy, int Npts, 
		float *par, int Npar, 
		float (funcs)(float, float, float *, int, float *), int VERBOSE);

float mrq2dinit (float *x, float *t, float *y, float *dy, int Npts, 
		 float *par, int Npar, 
		 float (funcs)(float, float, float *, int, float *), int VERBOSE);

float mrq2dchi (float *x, float *t, float *y, float *dy, int Npts, 
		float *par, int Npar, 
		float (funcs)(float, float, float *, int, float *));

int mrq2dlimits (float *pmin, float *pmax, int Npar);

float **mrq2dcovar (int Npar);

void mrq2dfree (int Npar);

/* gaussian.c */
double gaussian (double x, double mean, double sigma);
void gauss_init (int Nbin);
double rnd_gauss (double mean, double sigma);

/* starfuncs.c */
double get_aperture_stats (Matrix *matrix, int X, int Y, int Npix, int Nborder, double max);
int set_rough_radii (double Ra, double Ri, double Ro);
int get_rough_star (float *data, int Nx, int Ny, int x, int y, float *xc, float *yc, float *sx, float *sy, float *sxy, float *zs, float *zp, float *sk);

/* precess.c */
double BtoJ (double in_epoch);
double get_epoch (char *in_epoch, char mode);

/* graphtools.c */
void          SetLimits             PROTO((Vector *xvec, Vector *yvec, Graphdata *graphmode));
void          SetLimitsRaw          PROTO((float *xvec, float *yvec, int Npts, Graphdata *graphmode));
void          ApplyLimits           PROTO((int Xgraph, Graphdata *graphmode, int apply));
int           style_args            PROTO((Graphdata *graphmode, int *argc, char **argv, int *kapa));

int read_table_vectors (int argc, char **argv, char *extname);

void *db_getConnection ();

int bracket (double *list, int Nlist, int mode, double value);
int ibracket (int *list, int Nlist, int mode, double value);

# endif

