# include "markstar.h"

wcatalog (char *catname, Catalog *catalog) {
  
  int status;
  char filename[256];

  fits_modify (&catalog[0].header, "MARKSTAR", "%t", 1, TRUE);

  sprintf (filename, "%s/%s\0", CATDIR, catname);
  status = save_catalog (filename, catalog, VERBOSE);

  if (catalog[0].Naverage) {
    free (catalog[0].average); 
    catalog[0].Naverage = 0;
  }
  if (catalog[0].Nmeasure) {
    free (catalog[0].measure); 
    catalog[0].Nmeasure = 0;
  }
  if (catalog[0].Nmissing) {
    free (catalog[0].missing); 
    catalog[0].Nmissing = 0;
  }
  if (catalog[0].Nsecfilt) {
    free (catalog[0].secfilt); 
    catalog[0].Nsecfilt = 0;
  }

  switch (status) {
  case 0:
    exit (0);
  case 1:
  case 2:
    return (status);
  default:
    fprintf (stderr, "unknown exit status for save_catalog\n");
    return (FALSE);
  }
}

