# include "imregister.h"
# include "spreg.h"

int define_table (Header *header, Matrix *matrix, Header *theader, FTable *table) {

  /* create primary header */
  fits_init_header (header);    
  header[0].extend = TRUE;
  fits_create_header (header);
  fits_create_matrix (header, matrix);
  fits_print (header, "NEXTEND", "%d", 1, 1);
    
  /* define bintable header  layout */
  fits_create_table_header (theader, "BINTABLE", "SPECTRUM_DATABASE");

  fits_define_bintable_column (theader, "32A",  "FILENAME",   "filename in db",        "",                              1.0, 0.0);
  fits_define_bintable_column (theader, "64A",  "PATHNAME",   "fullpath in db",        "",                              1.0, 0.0);
  fits_define_bintable_column (theader, "16A",  "INSTRUMENT", "instrument",            "",                              1.0, 0.0);
  fits_define_bintable_column (theader, "16A",  "TELESCOPE",  "telescope",             "",                              1.0, 0.0);
  fits_define_bintable_column (theader, "16A",  "OBJNAME",    "object name",           "",                              1.0, 0.0);
  fits_define_bintable_column (theader, "16A",  "EXTNAME",    "extname in file",       "",                              1.0, 0.0);

  fits_define_bintable_column (theader, "E",    "RA",         "ra",                    "degrees",                       1.0, 0.0); 
  fits_define_bintable_column (theader, "E",    "DEC",        "dec",                   "degrees",                       1.0, 0.0); 
  fits_define_bintable_column (theader, "E",    "EXPTIME",    "exposure time",         "seconds",                       1.0, 0.0); 
  fits_define_bintable_column (theader, "E",    "AIRMASS",    "airmass",               "",                              1.0, 0.0); 
  fits_define_bintable_column (theader, "E",    "Ws",         "spectral range start",  "Angstrom",                 	1.0, 0.0); 
  fits_define_bintable_column (theader, "E",    "We",         "spectral range end",    "Angstrom",                 	1.0, 0.0); 
  fits_define_bintable_column (theader, "E",    "dW",         "spectral resolution",   "Angstrom / pix",                1.0, 0.0); 

  fits_define_bintable_column (theader, "J",    "NSPECTRA",   "number of spectra",     "",                              1.0, 0.0); 
  fits_define_bintable_column (theader, "J",    "OBS_TIME",   "time of measurement",   "seconds since Jan 1, 1970 UT",  1.0, 0.0);
  fits_define_bintable_column (theader, "J",    "REG_TIME",   "time of registration",  "seconds since Jan 1, 1970 UT",  1.0, 0.0);

  fits_define_bintable_column (theader, "A",    "MODE",       "phu/mef/ext",           "",                              1.0, 0.0);
  fits_define_bintable_column (theader, "A",    "STATE",      "raw/wav/flx/etc",       "",                              1.0, 0.0);
  fits_define_bintable_column (theader, "A",    "FLAG",       "status flags",          "",                              1.0, 0.0);
  fits_define_bintable_column (theader, "13A",  "EXTRA",      "room for expansion",    "",                              1.0, 0.0);

  /* create table, add data values */
  fits_create_table (theader, table);

  return (TRUE);
}
