# include "dvosplit.h"

Catalog *open_output_catalogs (SkyList *outlist) {

  int i;
  Catalog *outcatalogs;

  ALLOCATE (outcatalogs, Catalog, outlist[0].Nregions);

  // an error exit status here is a significant error
  for (i = 0; i < outlist[0].Nregions; i++) {
    
    // set the parameters which guide catalog open/load/create
    outcatalogs[i].filename  = outlist[0].filename[i];
    outcatalogs[i].Nsecfilt  = GetPhotcodeNsecfilt ();
    outcatalogs[i].catflags  = LOAD_NONE;
    outcatalogs[i].catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    outcatalogs[i].catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data

    if (!dvo_catalog_open (&outcatalogs[i], outlist[0].regions[i], VERBOSE, "w")) {
      fprintf (stderr, "ERROR: failure to open catalog file %s\n", outcatalogs[i].filename);
      exit (2);
    }
  }
  
  return (outcatalogs);
}
