# 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 (RELASTRO_OP) {
    case OP_UPDATE_OBJECTS:
      /* the object analysis is a separate process iterating over catalogs */
      relastro_objects (skylist, 0, NULL);
      exit (0);

    case OP_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 OP_HPM:
      hpm_catalogs (sky, skylist, 0, NULL);
      exit (0);

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

    case OP_IMAGES:
      relastro_images (skylist);
      exit (0);

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

    case OP_PARALLEL_REGIONS:
      // run image updates in parallel across multiple remote machines
      relastro_parallel_regions ();
      exit (0);

    case OP_PARALLEL_IMAGES:
      // operation on the remote machines in the PARALLEL_REGION mode
      relastro_parallel_images ();
      exit (0);

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