# include <signal.h>

enum {
  SPMODE_UKN,				/* unknown mode */
  SPMODE_PHU,				/* one spectrum, primary header unit */
  SPMODE_MEF,				/* spectrum group, extensions */
  SPMODE_EXT,				/* one of a spectrum group, extension */
  SPMODE_N
};

enum {
  SPSTATE_UKN,				/* unknown state */
  SPSTATE_RAW,				/* raw image counts */
  SPSTATE_FLT,				/* flattened image counts */
  SPSTATE_CLN,				/* clean extraction */
  SPSTATE_WAV,				/* wavelength calibrated */
  SPSTATE_FLX,				/* flux calibrated (implies WAV) */
  SPSTATE_N
};

struct {
  int Ntimes;           unsigned long *tstart, *tstop;
  int ModeSelect;       int Mode;
  int StateSelect;      int State;
  int ExptimeSelect;    float Exptime;
  int FilenameSelect;   char *Filename;
  int ObjectSelect;     char *Object;
  int TelescopeSelect;  char *Telescope;
  int InstrumentSelect; char *Instrument;
  int MatchNumber;
} criteria;

struct {
  int delete;
  int modify;

  int unique;
  int modify_path;
  char *oldpath, *newpath;

  int modify_mode, mode;
  int modify_state, state;

  int HST;
  int verbose;
  char *table;
  char *bintable;
} output;

typedef struct {
  int *ccd;
  int Nccd;
  char name[64];
} MosaicRegion;

typedef struct {
  MosaicRegion center;
  MosaicRegion outer;
  MosaicRegion top;
  MosaicRegion bottom;
  MosaicRegion left;
  MosaicRegion right;
} MosaicLayout;

enum {UNLOCK, LOCK, IGNORE};

int SingleIsSplit;
int NeedType;
int NoReg;
int IMSORT;
int CLIENT;
char *PIDFILE;
int LOOP_DELAY;
int DUMP;

char SpectrumDB[64];
char ObjectKeyword[64];
char TelescopeKeyword[64];


int args (int argc, char **argv);
int *match_criteria (Spectrum *spectrum, int Nspectrum, int *Nmatch);
int *unique_entries (Spectrum *spectrum, int Nspectrum, int *subset, int *Nmatch);

void ModifySubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch);
void DeleteSubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch);
void OutputSubset (Spectrum *spectrum, int Nspectrum, int *match, int Nmatch);

void SetOutputMode (char *mode);
void DumpFitsBintable (char *filename, Spectrum *spectrum, int *match, int Nmatch);
void DumpFitsTable (char *filename, Spectrum *spectrum, int *match, int Nmatch);
int PrintSubset (Spectrum *spectrum, int *match, int Nmatch);
int dump_data (Spectrum *spectrum, int Nspectrum);

Spectrum *spinfo (char *filename);
int *match_spectrums (Spectrum *subset, int Nsubset, int *Nmatch);
int SubmitSpectrums (Spectrum *spectrum);
void set_timezone (double dt);

void showinfo (Spectrum *spec);
int escape (int mode, char *message);
int set_spectra (Spectrum *new, int Nnew);
Spectrum *get_spectra (int *N);

void ConfigInitSpec (int *argc, char **argv);
