# include "addstar.h"

int resort_unthreaded (AddstarClientOptions *options, SkyTable *sky, int hostID, char *hostpath) {

  double dtime;
  struct timeval start, stop;

  gettimeofday (&start, NULL);

  SkyList *skylist = SkyListByPatch (sky, -1, &UserPatch);
  
  // in these cases, limit the sky catalogs to an existing subset
  if (options->existing_regions) {
    SkyList *tmp;
    tmp = SkyListExistingSubset (skylist, CATDIR);
    SkyListFree (skylist);
    skylist = tmp;
  }
  if (VERBOSE) fprintf (stderr, "writing to "OFF_T_FMT" regions\n",  skylist[0].Nregions);

  if (options->only_images) {
    fprintf (stderr, "-image (only images) makes no sense with -resort\n");
    exit (2);
  }
  if (options->only_match) {
    fprintf (stderr, "-only-match makes no sense with -resort\n");
    exit (2);
  }
  if (options->nosort == 1) {
    fprintf (stderr, "-nosort makes no sense with -resort\n");
    exit (2);
  }
  if (options->update) {
    fprintf (stderr, "-update makes no sense with -resort\n");
    exit (2);
  }
  if (options->calibrate) {
    fprintf (stderr, "-cal (calibrate) makes no sense with -resort\n");
    exit (2);
  }

  resort_unthreaded_catalogs (options, skylist, 0, NULL);

  gettimeofday (&stop, NULL);
  dtime = DTIME (stop, start);
  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec\n", dtime);

  return TRUE;
}

