# include "photdbc.h"

int main (int argc, char **argv) {

  int Nregion;
  char filename[1024];
  Catalog *catalog;
  GSCRegion *region;

  /* get configuration info, args, lockfile */
  initialize (argc, argv);

  /* load region and images overlapping region */
  region = load_images (argv[1], &Nregion);

  /* load catalog data corresponding to region file */
  catalog = load_catalogs (region, Nregion);

  /* limit number of measures based on selections */
  catalog = subcatalog (catalog);

  /* limit number of measures based on selections */
  join_stars (catalog);

  unique_measures (catalog);

  flag_measures (catalog);

  get_mags (catalog);

  unlock_catalog (catalog);

  sprintf (filename, "newdir/%s", argv[1]);
  catalog[0].filename = filename;

  check_directory (catalog[0].filename);
  if (!lock_catalog (catalog, LCK_XCLD)) { 
    fprintf (stderr, "can't lock new catalog file %s\n", catalog[0].filename);
    exit (1);
  }
  wcatalog (catalog);
}


/** this program is somewhat rough: minimal error checking
    -
    only one catalog is loaded, corresponding to region file
    



 */
