# include "delstar.h"

int delete_photcodes_single (char *cptname) {

  Catalog catalog;

  int Nphotcodes = 0;
  PhotCode **photcodes = ParsePhotcodeList (PHOTCODE_LIST, &Nphotcodes, FALSE);

  catalog.filename  = cptname;
  catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
  catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;

  if (VERBOSE) fprintf (stderr, "deleting from %s\n", catalog.filename);

  // an error exit status here is a significant error
  if (!dvo_catalog_open (&catalog, NULL, VERBOSE2, "a")) {
    fprintf (stderr, "ERROR: failure to open catalog file %s\n", catalog.filename);
    return FALSE;
  }
  if (!catalog.Naves_disk) {
    if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    dvo_catalog_unlock (&catalog);
    dvo_catalog_free (&catalog);
    return FALSE;
  }

  delete_photcodes_catalog (&catalog, photcodes, Nphotcodes);
  dvo_catalog_save_complete (&catalog, VERBOSE2);
  dvo_catalog_unlock (&catalog);
  dvo_catalog_free (&catalog);
  return TRUE;
}
