# include "relphot.h"

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

  // get configuration info, args
  RelphotMode mode = initialize (argc, argv);
  if (!mode) exit (2);

  switch (mode) {
    case UPDATE_IMAGES:
      // IF CALLED WITH NLOOP == 0, DOES NOT LOAD bcatalog, just loads image table and generates ImageSubset.dat
      relphot_images ();
      exit (0);

    case UPDATE_AVERAGES:
      // take the current set of detections and set the mean magnitudes
      // DOES NOT LOAD THE IMAGE TABLE
      relphot_objects (0, NULL);
      exit (0);

    case SYNTH_PHOT:
      // set the mean magnitudes ONLY for SYNPHOT objects
      relphot_synthphot (0, NULL);
      exit (0);

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

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

    case APPLY_OFFSETS:
      // re-run this step from a previous attempt (assumes an existing Images.subset.dat file)
      if (!PARALLEL) {
	fprintf (stderr, "-apply-offsets only makes sense in an parallel context\n");
	exit (2);
      }
      reload_catalogs (NULL, NULL, 0, NULL);
      exit (0);

    default:
      fprintf (stderr, "ERROR: no valid relphot mode chosen\n");
      exit (2);
  }
  fprintf (stderr, "IMPOSSIBLE: skipped out of switch?\n");
  exit (1);
}

/***

    I would like to merge the functionality of relphot_images (Nloop == 0), relphot_objects, and apply_offsets
    
***/
