# include "addstar.h"
# include <time.h>

void mkcatalog (GSCRegion *region, Catalog *catalog) {
  
  char filename[64], line[64];
  struct tm *local;
  struct timeval now;

  if (VERBOSE) fprintf (stderr, "new catalog file: %s\n", region[0].filename);
  if (!fits_read_header (CatTemplate, &catalog[0].header)) {
    fprintf (stderr, "ERROR: can't find template header %s\n", CatTemplate);
    exit (1);
  }
  
  /* assign header values for RA, DEC, DATE, etc */
  fits_modify (&catalog[0].header, "RA0", "%lf", 1, region[0].RA[0]);
  fits_modify (&catalog[0].header, "DEC0", "%lf", 1, region[0].DEC[0]);
  fits_modify (&catalog[0].header, "RA1", "%lf", 1, region[0].RA[1]);
  fits_modify (&catalog[0].header, "DEC1", "%lf", 1, region[0].DEC[1]);
  gettimeofday (&now, NULL);
  local = localtime (&now.tv_sec);
  sprintf (line, "%02d/%02d/%02d", local[0].tm_year, local[0].tm_mon + 1, local[0].tm_mday); 
  fits_modify (&catalog[0].header, "DATE", "%s", 1, line);
  strcpy (filename, CatTemplate);
  ALLOCATE (catalog[0].average, Average, 1);
  ALLOCATE (catalog[0].measure, Measure, 1);
  ALLOCATE (catalog[0].missing, Missing, 1);
  catalog[0].Naverage = catalog[0].Nmeasure = catalog[0].Nmissing = 0;

  /* setup secondary filters to match photcodes */
  ALLOCATE (catalog[0].secfilt, SecFilt, 1);
  catalog[0].Nsecfilt = GetPhotcodeNsecfilt ();

  /* Nsecfilt is number of filters.  Number of entries in array is
     Nsecfilt * Naverage.  At this point, N entries == 0 */

}
