Index: /branches/eam_branches/ipp-20140717/Ohana/src/addstar/Makefile
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/addstar/Makefile	(revision 37088)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/addstar/Makefile	(revision 37089)
@@ -78,8 +78,8 @@
 $(SRC)/parse_time.$(ARCH).o \
 $(SRC)/replace_match.$(ARCH).o \
-$(SRC)/resort_catalog.$(ARCH).o \
+$(SRC)/resort_catalogs.$(ARCH).o \
 $(SRC)/resort_threaded.$(ARCH).o \
 $(SRC)/resort_unthreaded.$(ARCH).o \
-$(SRC)/resort_unthreaded_catalogs.$(ARCH).o \
+$(SRC)/resort_catalog.$(ARCH).o \
 $(SRC)/StarOps.$(ARCH).o \
 $(SRC)/ReadStarsFITS.$(ARCH).o \
@@ -105,8 +105,8 @@
 $(SRC)/addstar_client.$(ARCH).o \
 $(SRC)/args_parallel_client.$(ARCH).o \
-$(SRC)/resort_catalog.$(ARCH).o \
+$(SRC)/resort_catalogs.$(ARCH).o \
 $(SRC)/resort_threaded.$(ARCH).o \
 $(SRC)/resort_unthreaded.$(ARCH).o \
-$(SRC)/resort_unthreaded_catalogs.$(ARCH).o
+$(SRC)/resort_catalog.$(ARCH).o
 
 ADDSTARD = \
Index: /branches/eam_branches/ipp-20140717/Ohana/src/addstar/include/addstar.h
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/addstar/include/addstar.h	(revision 37088)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/addstar/include/addstar.h	(revision 37089)
@@ -237,9 +237,11 @@
 Stars     *rd_gsc                 PROTO((char *filename, unsigned int *nstars));
 int        replace_match          PROTO((Average *average, Measure *measure, Stars *star));
-int        resort_threaded        PROTO((AddstarClientOptions *options, SkyTable *sky));
-int        resort_unthreaded      PROTO((AddstarClientOptions *options, SkyTable *sky, int hostID, char *hostpath));
-int        resort_unthreaded_catalogs PROTO((AddstarClientOptions *options, SkyList *skylist, int hostID, char *hostpath));
+int        resort_catalogs        PROTO((AddstarClientOptions *options, SkyTable *sky));
+int        resort_catalogs_parallel PROTO((AddstarClientOptions *options, SkyList *sky));
+int        resort_threaded        PROTO((SkyList *skylist, int ForceSort));
+int        resort_unthreaded      PROTO((SkyList *skylist, int ForceSort));
 void       resort_catalog         PROTO((Catalog *catalog));
 void       resort_catalog_old     PROTO((Catalog *catalog));
+
 Stars     *ReadStarsFITS          PROTO((FILE *f, Header *header, Header *in_theader, unsigned int *nstars));
 Stars     *ReadStarsTEXT          PROTO((FILE *f, unsigned int *nstars));
@@ -316,4 +318,5 @@
 void *memrchr(const void *s, int c, size_t n);
 int addstar_create_ID ();
+int strextend (char *input, char *format,...);
 
 /** 
Index: /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/addstar.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/addstar.c	(revision 37088)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/addstar.c	(revision 37089)
@@ -40,9 +40,5 @@
   
   if (options.mode == ADDSTAR_MODE_RESORT) {
-    if (NTHREADS == 0) {
-      resort_unthreaded (&options, sky, 0, NULL);
-    } else {
-      resort_threaded (&options, sky);
-    }
+    resort_catalogs (&options, sky);
     exit (0);
   }
@@ -71,5 +67,4 @@
       skylist = SkyListForStars (sky, -1, stars, Nstars);
       break;
-    case ADDSTAR_MODE_RESORT:
     case ADDSTAR_MODE_REFCAT:
       skylist = SkyListByPatch (sky, -1, &UserPatch);
@@ -161,21 +156,4 @@
 	if (Nsubset) free (subset);
 	break;
-      case ADDSTAR_MODE_RESORT:
-	if (options.nosort == 3) catalog.sorted = FALSE;
-
-	// no need to resort empty catalogs
-	if (catalog.Naves_disk == 0) {
-	  dvo_catalog_unlock (&catalog);
-	  dvo_catalog_free (&catalog);
-	  continue;
-	}
-
-	if (OLD_RESORT) { 
-	  resort_catalog_old (&catalog);
-	} else {
-	  resort_catalog (&catalog);
-	}
-	Nsubset = 1;
-	break;
     }
     /* report total updated values */
Index: /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/addstar_client.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/addstar_client.c	(revision 37088)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/addstar_client.c	(revision 37089)
@@ -25,5 +25,5 @@
 
   if (options.mode == ADDSTAR_MODE_RESORT) {
-    resort_unthreaded (&options, sky, HOST_ID, HOSTDIR);
+    resort_catalogs (&options, sky);
     exit (0);
   }
Index: /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/args.c	(revision 37088)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/args.c	(revision 37089)
@@ -34,4 +34,10 @@
     remove_argument (N, &argc, argv);
   }
+  OLD_RESORT = FALSE;
+  if ((N = get_argument (argc, argv, "-old-resort"))) {
+    remove_argument (N, &argc, argv);
+    OLD_RESORT = TRUE;
+  }
+
   if ((N = get_argument (argc, argv, "-create-id"))) {
     options.mode = ADDSTAR_MODE_CREATE_ID;
@@ -350,4 +356,6 @@
   // XXX for the moment, make this selection manual.  it needs to be automatic 
   // based on the state of the SkyTable
+  HOST_ID = 0;
+  HOSTDIR = NULL;
   PARALLEL = FALSE;
   if ((N = get_argument (argc, argv, "-parallel"))) {
@@ -466,4 +474,17 @@
 }
 
+int strextend (char *input, char *format,...) {
+
+  char tmpextra[1024], tmpline[1024];
+  va_list argp;
+
+  va_start (argp, format);
+  vsnprintf (tmpextra, 1024, format, argp);
+  snprintf (tmpline, 1024, "%s %s", input, tmpextra);
+  strcpy (input, tmpline);
+
+  return TRUE;
+}
+
 /** addstar modes:
  
Index: /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/args_parallel_client.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/args_parallel_client.c	(revision 37088)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/args_parallel_client.c	(revision 37089)
@@ -87,4 +87,10 @@
   }
 
+  OLD_RESORT = FALSE;
+  if ((N = get_argument (argc, argv, "-old-resort"))) {
+    remove_argument (N, &argc, argv);
+    OLD_RESORT = TRUE;
+  }
+
   /* extra error messages */
   VERBOSE = FALSE;
@@ -118,2 +124,16 @@
   exit (2);
 }
+
+int strextend (char *input, char *format,...) {
+
+  char tmpextra[1024], tmpline[1024];
+  va_list argp;
+
+  va_start (argp, format);
+  vsnprintf (tmpextra, 1024, format, argp);
+  snprintf (tmpline, 1024, "%s %s", input, tmpextra);
+  strcpy (input, tmpline);
+
+  return TRUE;
+}
+
Index: /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_catalog.c	(revision 37088)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_catalog.c	(revision 37089)
@@ -7,6 +7,6 @@
 void resort_catalog_old (Catalog *catalog) {
 
-  off_t *next_meas;
-  off_t Naves, Nmeas;
+  off_t *next_meas, *next_lens;
+  off_t Naves, Nmeas, Nlens;
 
   if (catalog[0].sorted == TRUE) return;
@@ -16,11 +16,14 @@
   /* internal counters */
   Nmeas = catalog[0].Nmeasure;
+  Nlens = catalog[0].Nlensing;
   Naves = catalog[0].Naverage;
   
   /* set up pointers for linked list of measure, missing */
   next_meas = build_measure_links (catalog[0].average, Naves, catalog[0].measure, Nmeas);
+  next_lens = build_lensing_links (catalog[0].average, Naves, catalog[0].lensing, Nlens);
 
   catalog[0].sorted = TRUE;
   catalog[0].measure = sort_measure (catalog[0].average, Naves, catalog[0].measure, Nmeas, next_meas);
+  catalog[0].lensing = sort_lensing (catalog[0].average, Naves, catalog[0].lensing, Nlens, next_lens);
 
   MARKTIME ("  match time %9.4f sec for %7lld measures, %6lld average\n", dtime, (long long) Nmeas, (long long) Naves);
Index: /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_catalogs.c	(revision 37089)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_catalogs.c	(revision 37089)
@@ -0,0 +1,120 @@
+# include "addstar.h"
+
+// pass in options and skylist?
+int resort_catalogs (AddstarClientOptions *options, SkyTable *sky) {
+
+  INITTIME;
+
+  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);
+  }
+
+  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 (PARALLEL && !HOST_ID) {
+    resort_catalogs_parallel (options, skylist);
+    return TRUE;
+  }
+
+  int ForceSort = (options->nosort == 3);
+
+  if (NTHREADS == 0) {
+    resort_unthreaded (skylist, ForceSort);
+  } else {
+    resort_threaded (skylist, ForceSort);
+  }
+
+  MARKTIME ("SUCCESS: elapsed time %9.4f sec\n", dtime);
+  return TRUE;
+}
+
+// CATDIR is supplied globally
+# define DEBUG 1
+int resort_catalogs_parallel (AddstarClientOptions *options, SkyList *sky) {
+
+  // load the list of hosts
+  HostTable *table = HostTableLoad (CATDIR, sky->hosts);
+  if (!table) {
+    fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);
+    exit (1);
+  }    
+
+  int i;
+  for (i = 0; i < table->Nhosts; i++) {
+
+    // ensure that the paths are absolute path names
+    char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH);
+    free (table->hosts[i].pathname);
+    table->hosts[i].pathname = tmppath;
+
+    char command[1024];
+    snprintf (command, 1024, "addstar_client -resort");
+    strextend (command, "-D CATDIR %s", CATDIR);
+    strextend (command, "-hostID %d", table->hosts[i].hostID);
+    strextend (command, "-hostdir %s", table->hosts[i].pathname);
+    strextend (command, "-region %f %f %f %f", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
+
+    if (VERBOSE)                   strextend (command, "%s -v");
+    if (NTHREADS)                  strextend (command, "%s -threads %d", NTHREADS);
+    if (OLD_RESORT)                strextend (command, "%s -old-resort");
+    if (options->nosort == 3)      strextend (command, "%s -force-sort");
+    if (options->existing_regions) strextend (command, "%s -existing-regions");
+
+    fprintf (stderr, "command: %s\n", command);
+
+    if (PARALLEL_MANUAL) continue;
+
+    if (PARALLEL_SERIAL) {
+      int status = system (command);
+      if (status) {
+	fprintf (stderr, "ERROR running addstar_client\n");
+	exit (2);
+      }
+    } else {
+      // launch the job on the remote machine (no handshake)
+      int errorInfo = 0;
+      int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE);
+      if (!pid) {
+	if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo);
+	exit (1);
+      }
+      table->hosts[i].pid = pid; // save for future reference
+    }
+  }
+
+  if (PARALLEL_MANUAL) {
+    fprintf (stderr, "run the addstar_client commands above.  when these are done, hit return\n");
+    getchar();
+  }
+  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
+    HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE);
+  }
+
+  return TRUE;
+}      
Index: /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_threaded.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_threaded.c	(revision 37088)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_threaded.c	(revision 37089)
@@ -13,5 +13,5 @@
   int iThread;
   int state;
-  int nosort;
+  int forcesort;
   char *filename;
   SkyRegion *region;
@@ -37,6 +37,10 @@
     }
 
+    // chose the catalog file (local or remote?)
+    char hostfile[1024];
+    snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, threadData->region->name);
+    catalog.filename  = HOST_ID ? hostfile : threadData->filename;
+
     // set the parameters which guide catalog open/load/create
-    catalog.filename  = threadData->filename;
     catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
     catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
@@ -64,5 +68,5 @@
 
     // this is an overloaded value to mean 'force sort'
-    if (threadData->nosort == 3) catalog.sorted = FALSE;
+    if (threadData->forcesort) catalog.sorted = FALSE;
 
     if (OLD_RESORT) { 
@@ -88,5 +92,5 @@
 }
 
-int resort_threaded (AddstarClientOptions *options, SkyTable *sky) {
+int resort_threaded (SkyList *skylist, int ForceSort) {
 
   int j, launched, done, Nwait, Nrun;
@@ -97,40 +101,4 @@
   ThreadData *threadData;
   pthread_t *threads;
-
-  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);
-  }
 
   ALLOCATE(threads, pthread_t, NTHREADS);
@@ -148,4 +116,7 @@
   Naverage = Nmeasure = 0;
   for (i = 0; i < skylist[0].Nregions; i++) {
+
+    // does this host ID match the desired location for the table?
+    if (!HostTableTestHost(skylist[0].regions[i], HOST_ID)) continue;
 
     launched = FALSE;
@@ -166,5 +137,5 @@
 	if (threadData[j].state == TS_FAIL) goto failure;
 	if (threadData[j].state != TS_WAIT) continue;
-	threadData[j].nosort = options->nosort;
+	threadData[j].forcesort = ForceSort;
 	threadData[j].filename = skylist[0].filename[i];
 	threadData[j].region = skylist[0].regions[i];
@@ -203,8 +174,4 @@
   }
 
-  gettimeofday (&stop, NULL);
-  dtime = DTIME (stop, start);
-  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec for, "OFF_T_FMT" average, "OFF_T_FMT" measure\n", dtime, Naverage, Nmeasure);
-
   // for (i = 0; i < NTHREADS; i++) {
   //   pthread_cancel(threads[i]);
Index: /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_unthreaded.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_unthreaded.c	(revision 37088)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_unthreaded.c	(revision 37089)
@@ -1,50 +1,64 @@
 # include "addstar.h"
 
-int resort_unthreaded (AddstarClientOptions *options, SkyTable *sky, int hostID, char *hostpath) {
+// pass in options and skylist?
+int resort_unthreaded (SkyList *skylist, int ForceSort) {
 
-  double dtime;
-  struct timeval start, stop;
+  off_t i;
+  off_t Naverage, Nmeasure;
+  Catalog catalog;
 
-  gettimeofday (&start, NULL);
+  /* match stars to existing catalog data (or otherwise manipulate catalog data) */
+  Naverage = Nmeasure = 0;
+  for (i = 0; i < skylist[0].Nregions; i++) {
 
-  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;
+    // does this host ID match the desired location for the table?
+    if (!HostTableTestHost(skylist[0].regions[i], HOST_ID)) continue;
+
+    // chose the catalog file (local or remote?)
+    char hostfile[1024];
+    snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
+    catalog.filename  = HOST_ID ? hostfile : skylist[0].filename[i];
+
+    // set the parameters which guide catalog open/load/create
+    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
+    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
+    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_LENSING;
+    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+
+    // an error exit status here is a significant error (disk I/O or file access)
+    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
+      fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
+      exit (2);
+    }
+
+    // Naves_disk == 0 implies an empty catalog file, skip empty catalogs
+    if (catalog.Naves_disk == 0) {
+      dvo_catalog_unlock (&catalog);
+      dvo_catalog_free (&catalog);
+      continue;
+    }
+
+    // this is an overloaded value to mean 'force sort'
+    if (ForceSort) catalog.sorted = FALSE;
+
+    if (OLD_RESORT) { 
+      resort_catalog_old (&catalog);
+    } else {
+      resort_catalog (&catalog);
+    }
+
+    // report total updated values 
+    Naverage += catalog.Naverage;
+    Nmeasure += catalog.Nmeasure;
+
+    // write out catalog, if appropriate
+    SetProtect (TRUE);
+    dvo_catalog_save (&catalog, VERBOSE);
+    SetProtect (FALSE);
+    dvo_catalog_unlock (&catalog);
+    dvo_catalog_free (&catalog);
   }
-  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, hostID, hostpath);
-
-  gettimeofday (&stop, NULL);
-  dtime = DTIME (stop, start);
-  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec\n", dtime);
-
   return TRUE;
 }
 
+
Index: anches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_unthreaded_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/addstar/src/resort_unthreaded_catalogs.c	(revision 37088)
+++ 	(revision )
@@ -1,132 +1,0 @@
-# include "addstar.h"
-
-int resort_unthreaded_parallel (AddstarClientOptions *options, SkyList *sky);
-
-// pass in options and skylist?
-int resort_unthreaded_catalogs (AddstarClientOptions *options, SkyList *skylist, int hostID, char *hostpath) {
-
-  off_t i;
-  off_t Naverage, Nmeasure;
-  Catalog catalog;
-
-  if (PARALLEL && !hostID) {
-    resort_unthreaded_parallel (options, skylist);
-    return TRUE;
-  }
-
-  /* match stars to existing catalog data (or otherwise manipulate catalog data) */
-  Naverage = Nmeasure = 0;
-  for (i = 0; i < skylist[0].Nregions; i++) {
-
-    // does this host ID match the desired location for the table?
-    if (!HostTableTestHost(skylist[0].regions[i], hostID)) continue;
-
-    // chose the catalog file (local or remote?)
-    char hostfile[1024];
-    snprintf (hostfile, 1024, "%s/%s.cpt", hostpath, skylist[0].regions[i]->name);
-    catalog.filename  = hostID ? hostfile : skylist[0].filename[i];
-
-    // set the parameters which guide catalog open/load/create
-    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
-    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
-    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_LENSING;
-    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
-
-    // an error exit status here is a significant error (disk I/O or file access)
-    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
-      fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
-      exit (2);
-    }
-
-    // Naves_disk == 0 implies an empty catalog file, skip empty catalogs
-    if (catalog.Naves_disk == 0) {
-      dvo_catalog_unlock (&catalog);
-      dvo_catalog_free (&catalog);
-      continue;
-    }
-
-    // this is an overloaded value to mean 'force sort'
-    if (options->nosort == 3) catalog.sorted = FALSE;
-
-    if (OLD_RESORT) { 
-      resort_catalog_old (&catalog);
-    } else {
-      resort_catalog (&catalog);
-    }
-
-    // report total updated values 
-    Naverage += catalog.Naverage;
-    Nmeasure += catalog.Nmeasure;
-
-    // write out catalog, if appropriate
-    SetProtect (TRUE);
-    dvo_catalog_save (&catalog, VERBOSE);
-    SetProtect (FALSE);
-    dvo_catalog_unlock (&catalog);
-    dvo_catalog_free (&catalog);
-  }
-  return TRUE;
-}
-
-// CATDIR is supplied globally
-# define DEBUG 1
-int resort_unthreaded_parallel (AddstarClientOptions *options, SkyList *sky) {
-
-  // load the list of hosts
-  HostTable *table = HostTableLoad (CATDIR, sky->hosts);
-  if (!table) {
-    fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);
-    exit (1);
-  }    
-
-  int i;
-  for (i = 0; i < table->Nhosts; i++) {
-
-    // ensure that the paths are absolute path names
-    char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH);
-    free (table->hosts[i].pathname);
-    table->hosts[i].pathname = tmppath;
-
-    char command[1024];
-    snprintf (command, 1024, "addstar_client -resort -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f", 
-	      table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, 
-	      UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
-
-    char tmpline[1024];
-    if (VERBOSE)                   { snprintf (tmpline, 1024, "%s -v",                command); strcpy (command, tmpline); }
-    if (options->nosort == 3)      { snprintf (tmpline, 1024, "%s -force-sort",       command); strcpy (command, tmpline); }
-    if (options->existing_regions) { snprintf (tmpline, 1024, "%s -existing-regions", command); strcpy (command, tmpline); }
-
-    fprintf (stderr, "command: %s\n", command);
-
-    if (PARALLEL_MANUAL) continue;
-
-    if (PARALLEL_SERIAL) {
-      int status = system (command);
-      if (status) {
-	fprintf (stderr, "ERROR running addstar_client\n");
-	exit (2);
-      }
-    } else {
-      // launch the job on the remote machine (no handshake)
-      int errorInfo = 0;
-      int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE);
-      if (!pid) {
-	if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo);
-	exit (1);
-      }
-      table->hosts[i].pid = pid; // save for future reference
-    }
-  }
-
-  if (PARALLEL_MANUAL) {
-    fprintf (stderr, "run the addstar_client commands above.  when these are done, hit return\n");
-    getchar();
-  }
-  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
-    HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE);
-  }
-
-  return TRUE;
-}      
-
