# include "photdbc.h"

Catalog *load_catalogs (GSCRegion *region, int Nregion) {

  int i, Nstar;
  Catalog *catalog;

  if (VERBOSE) fprintf (stderr, "loading catalog data\n");

  ALLOCATE (catalog, Catalog, Nregion);

  /* load data from each region file */
  for (i = 0; i < Nregion; i++) {
    catalog[i].filename = region[i].filename;  /* don't free region before catalog! */
    switch (lock_catalog (&catalog[i], LCK_SOFT)) {
    case 0:
      fprintf (stderr, "ERROR: can't lock file %s\n", catalog[i].filename);
      exit (1);
    case 1:
      gcatalog (&catalog[i]); /* load from disk */
      break;
    case 2:
      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog[i].filename);
      catalog[i].Naverage = 0;
      catalog[i].Nmeasure = 0;
      break;
    default:
      fprintf (stderr, "weird lock_catalog exit state\n");
      exit (1);
    }
  }
  return (catalog);
}
