# include "addstar.h"
# include "loadstarpar.h"

int loadstarpar_catalog (StarPar_Stars *stars, int Nstars, SkyRegion *region, char *filename, AddstarClientOptions *options) {

  Catalog catalog;

  // now we have all of the loaded stars in this catalog
  catalog.filename = filename;
  catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
  catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
  catalog.catflags = LOAD_AVES | LOAD_SECF | LOAD_STARPAR;
  catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    
  // an error exit status here is a significant error
  if (!dvo_catalog_open (&catalog, region, VERBOSE, "w")) {
    fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
    exit (2);
  }

  find_matches_starpar (region, stars, Nstars, &catalog, options);
    
  dvo_catalog_save (&catalog, VERBOSE);
  dvo_catalog_unlock (&catalog);
  dvo_catalog_free (&catalog);

  return (TRUE);
}
