# include "relastro.h"

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

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

  SkyTable *sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
  SkyTableSetFilenames (sky, CATDIR, "cpt");
  SkyList *skylist = SkyListByPatch (sky, -1, &UserPatch);

  switch (FIT_TARGET) {
    case TARGET_UPDATE_OBJECTS:
      /* the object analysis is a separate process iterating over catalogs */
      relastro_objects (skylist, 0, NULL);
      exit (0);

    case TARGET_HIGH_SPEED:
      /* high-speed is a 2pt cross-correlation process for linking moving objects (high PM) */
      high_speed_catalogs (sky, skylist, 0, NULL);
      exit (0);

    case TARGET_MERGE_SOURCE:
      /* a special method to manually merge unlinked detections of sources togther (not parallel) */
      relastro_merge_source (sky);
      exit (0);

    case TARGET_SIMPLE:
    case TARGET_CHIPS:
    case TARGET_MOSAICS:
      relastro_images (skylist);
      exit (0);

    case TARGET_UPDATE_OFFSETS:
      // iterate over catalogs to make detection coordinates consistant
      UpdateObjectOffsets (skylist, 0, NULL);

    default:
      fprintf (stderr, "impossible!\n");
      abort();
  }
  exit (1);
}
