Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/Makefile
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/Makefile	(revision 33895)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/Makefile	(revision 33896)
@@ -78,4 +78,5 @@
 $(SRC)/resort_threaded.$(ARCH).o \
 $(SRC)/resort_unthreaded.$(ARCH).o \
+$(SRC)/resort_unthreaded_catalogs.$(ARCH).o \
 $(SRC)/StarOps.$(ARCH).o \
 $(SRC)/ReadStarsFITS.$(ARCH).o \
@@ -89,4 +90,18 @@
 $(SRC)/update_coords.$(ARCH).o \
 $(SRC)/psps_ids.$(ARCH).o
+
+# this is the client for parallel operations
+ADDSTAR_CLIENT = \
+$(SRC)/ConfigInit.$(ARCH).o \
+$(SRC)/SetSignals.$(ARCH).o \
+$(SRC)/Shutdown.$(ARCH).o \
+$(SRC)/SkyListForStars.$(ARCH).o \
+$(SRC)/SkyRegionUtils.$(ARCH).o \
+$(SRC)/addstar_client.$(ARCH).o \
+$(SRC)/args_parallel_client.$(ARCH).o \
+$(SRC)/resort_catalog.$(ARCH).o \
+$(SRC)/resort_threaded.$(ARCH).o \
+$(SRC)/resort_unthreaded.$(ARCH).o \
+$(SRC)/resort_unthreaded_catalogs.$(ARCH).o
 
 ADDSTARD = \
@@ -168,4 +183,5 @@
 $(SRC)/psps_ids.$(ARCH).o
 
+# this is the client for server / client addstar operations
 ADDSTARC = \
 $(SRC)/addstarc.$(ARCH).o \
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/include/addstar.h
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/include/addstar.h	(revision 33895)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/include/addstar.h	(revision 33896)
@@ -59,5 +59,5 @@
 typedef struct sockaddr_in SockAddress;
 
-enum {M_IMAGE, M_REFLIST, M_REFCAT, M_FAKEIMAGE, M_RESORT};
+enum {ADDSTAR_MODE_NONE, ADDSTAR_MODE_IMAGE, ADDSTAR_MODE_REFLIST, ADDSTAR_MODE_REFCAT, ADDSTAR_MODE_FAKEIMAGE, ADDSTAR_MODE_RESORT};
 enum {NONE, SIMPLE_CMP, SIMPLE_CMF, SIMPLE_MEF, MOSAIC_CMP, MOSAIC_CMF, MOSAIC_MEF, MOSAIC_PHU, SDSS_OBJ};
 /* note: MEF implies CMF */
@@ -132,4 +132,10 @@
 int     OLD_RESORT;
 
+int    PARALLEL;
+int    PARALLEL_MANUAL;
+int    PARALLEL_SERIAL;
+int    HOST_ID;
+char  *HOSTDIR;
+
 // carries the mosaic into gstars
 
@@ -216,5 +222,6 @@
 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        resort_unthreaded      PROTO((AddstarClientOptions *options, SkyTable *sky, int hostID, char *hostpath));
+int        resort_unthreaded_catalogs PROTO((AddstarClientOptions *options, SkyList *skylist, int hostID, char *hostpath));
 void       resort_catalog         PROTO((Catalog *catalog));
 void       resort_catalog_old     PROTO((Catalog *catalog));
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/addstar.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/addstar.c	(revision 33895)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/addstar.c	(revision 33896)
@@ -34,7 +34,7 @@
   SkyTableSetFilenames (sky, CATDIR, "cpt");
   
-  if (options.mode == M_RESORT) {
+  if (options.mode == ADDSTAR_MODE_RESORT) {
     if (NTHREADS == 0) {
-      resort_unthreaded (&options, sky);
+      resort_unthreaded (&options, sky, 0, NULL);
     } else {
       resort_threaded (&options, sky);
@@ -47,5 +47,5 @@
   /*** load in the new data (images, stars) ***/
   switch (options.mode) {
-    case M_IMAGE:
+    case ADDSTAR_MODE_IMAGE:
       stars = LoadStars (argv[1], &Nstars, &images, &Nimages, &options);
 
@@ -62,13 +62,13 @@
       ImageOptions (&options, images, Nimages);
       break;
-    case M_REFLIST:
+    case ADDSTAR_MODE_REFLIST:
       stars = grefstars (argv[1], options.photcode, &Nstars);
       skylist = SkyListForStars (sky, -1, stars, Nstars);
       break;
-    case M_RESORT:
-    case M_REFCAT:
+    case ADDSTAR_MODE_RESORT:
+    case ADDSTAR_MODE_REFCAT:
       skylist = SkyListByPatch (sky, -1, &UserPatch);
       break;
-    case M_FAKEIMAGE:
+    case ADDSTAR_MODE_FAKEIMAGE:
       images = fakeimage (argv[1], &Nimages, options.photcode);
       ALLOCATE (skylist, SkyList, 1);
@@ -137,5 +137,5 @@
 
     switch (options.mode) {
-      case M_IMAGE:
+      case ADDSTAR_MODE_IMAGE:
 	Nsubset = Nstars;
 	if (options.closest) {
@@ -145,7 +145,7 @@
 	}
 	break;
-      case M_REFCAT:
+      case ADDSTAR_MODE_REFCAT:
 	stars = greference (argv[1], skylist[0].regions[i], options.photcode, &Nstars);
-      case M_REFLIST:
+      case ADDSTAR_MODE_REFLIST:
 	subset = find_subset (skylist[0].regions[i], stars, Nstars, &Nsubset);
 	if (options.closest) {
@@ -156,5 +156,5 @@
 	if (Nsubset) free (subset);
 	break;
-      case M_RESORT:
+      case ADDSTAR_MODE_RESORT:
 	if (options.nosort == 3) catalog.sorted = FALSE;
 
@@ -192,5 +192,5 @@
     dvo_catalog_free (&catalog);
 
-    if (options.mode == M_REFCAT) free (stars);
+    if (options.mode == ADDSTAR_MODE_REFCAT) free (stars);
   }
 
@@ -216,5 +216,5 @@
 
   /* add the new images and save */
-  if (options.mode == M_IMAGE) {
+  if (options.mode == ADDSTAR_MODE_IMAGE) {
     dvo_image_addrows (&db, images, Nimages);
     SetProtect (TRUE);
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/addstar_client.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/addstar_client.c	(revision 33896)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/addstar_client.c	(revision 33896)
@@ -0,0 +1,33 @@
+# include "addstar.h"
+
+// addstar_client is run on a remote host and is responsible for updating the catalogs
+// owned by that host.  
+
+// there is one mode:
+
+// addstar_client -resort : update the table indicies
+
+int main (int argc, char **argv) {
+
+  AddstarClientOptions options;
+
+  // get configuration info, args, lockfile (set CATDIR, HOST_ID, HOSTDIR, etc) 
+  options = ConfigInit (&argc, argv);
+  options = args_parallel_client (argc, argv, options);
+
+  // load the current sky table (layout of all SkyRegions) 
+  SkyTable *sky = SkyTableLoadOptimal (CATDIR, NULL, NULL, TRUE, -1, VERBOSE);
+  if (!sky) {
+      fprintf (stderr, "ERROR running loading sky table from %s\n", CATDIR);
+      exit (2);
+  }
+  SkyTableSetFilenames (sky, CATDIR, "cpt");
+
+  if (options.mode == M_RESORT) {
+    resort_unthreaded (&options, sky, HOST_ID, HOSTDIR);
+    exit (0);
+  }
+
+  fprintf (stderr, "unknown mode for addstar_client\n");
+  exit (1);
+}
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/addstarc.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/addstarc.c	(revision 33895)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/addstarc.c	(revision 33896)
@@ -20,5 +20,5 @@
   /* send new data to server */
   switch (options.mode) {
-    case M_IMAGE:
+    case ADDSTAR_MODE_IMAGE:
       /* load data */
       stars = LoadStars (argv[1], &Nstars, &images, &Nimages, &options);
@@ -40,5 +40,5 @@
       break;
 
-    case M_REFLIST:
+    case ADDSTAR_MODE_REFLIST:
       /* load data */
       stars = grefstars (argv[1], options.photcode, &Nstars);
@@ -50,5 +50,5 @@
       break;
 
-    case M_REFCAT:
+    case ADDSTAR_MODE_REFCAT:
       /* send data to server */
       SendCommand (BindSocket, 5, "REFCT");
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/addstart.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/addstart.c	(revision 33895)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/addstart.c	(revision 33896)
@@ -31,13 +31,13 @@
 
     switch (dataset[0].options[0].mode) {
-      case M_IMAGE:
+      case ADDSTAR_MODE_IMAGE:
 	UpdateDatabase_Image (dataset[0].options, dataset[0].images, dataset[0].Nimages, dataset[0].mosaic, dataset[0].stars, dataset[0].Nstars);
 	continue;
 
-      case M_REFLIST:
+      case ADDSTAR_MODE_REFLIST:
 	UpdateDatabase_Reflist (dataset[0].options, dataset[0].stars, dataset[0].Nstars);
 	continue;
 
-      case M_REFCAT:
+      case ADDSTAR_MODE_REFCAT:
 	UpdateDatabase_Refcat (dataset[0].options, dataset[0].patch, dataset[0].refcat);
 	continue;
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args.c	(revision 33895)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args.c	(revision 33896)
@@ -21,20 +21,20 @@
 
   /* basic mode: image, list, refcat */
-  options.mode = M_IMAGE;
+  options.mode = ADDSTAR_MODE_IMAGE;
   if ((N = get_argument (argc, argv, "-ref"))) {
-    options.mode = M_REFLIST;
+    options.mode = ADDSTAR_MODE_REFLIST;
     remove_argument (N, &argc, argv);
   }
   if ((N = get_argument (argc, argv, "-cat"))) {
-    options.mode = M_REFCAT;
+    options.mode = ADDSTAR_MODE_REFCAT;
     remove_argument (N, &argc, argv);
   }
   if ((N = get_argument (argc, argv, "-resort"))) {
-    options.mode = M_RESORT;
+    options.mode = ADDSTAR_MODE_RESORT;
     remove_argument (N, &argc, argv);
   }
 
   if ((N = get_argument (argc, argv, "-fakeimage"))) {
-    options.mode = M_FAKEIMAGE;
+    options.mode = ADDSTAR_MODE_FAKEIMAGE;
     remove_argument (N, &argc, argv);
     FAKE_RA = atof (argv[N]);
@@ -98,11 +98,11 @@
     remove_argument (N, &argc, argv);
   } else {
-      if (options.mode == M_IMAGE) goto allow;
-      if (options.mode == M_FAKEIMAGE) goto allow;
-      if (options.mode == M_REFLIST) goto allow;
-      if (options.mode == M_REFCAT) {
+      if (options.mode == ADDSTAR_MODE_IMAGE) goto allow;
+      if (options.mode == ADDSTAR_MODE_FAKEIMAGE) goto allow;
+      if (options.mode == ADDSTAR_MODE_REFLIST) goto allow;
+      if (options.mode == ADDSTAR_MODE_REFCAT) {
 	  fprintf (stderr, "you have requested uploading from a catalog to the entire sky in one pass\n");
       }
-      if (options.mode == M_RESORT) {
+      if (options.mode == ADDSTAR_MODE_RESORT) {
 	  fprintf (stderr, "you have requested resorting the entire sky in one pass\n");
       }
@@ -330,8 +330,42 @@
   }
 
-  if ((options.mode == M_RESORT) && (argc == 1)) return (options);
+  // XXX for the moment, make this selection manual.  it needs to be automatic 
+  // based on the state of the SkyTable
+  PARALLEL = FALSE;
+  if ((N = get_argument (argc, argv, "-parallel"))) {
+    PARALLEL = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  // this is a test mode : rather than launching the remote jobs and waiting for completion,
+  // relphot will simply list the remote command and wait for the user to signal completion
+  PARALLEL_MANUAL = FALSE;
+  if ((N = get_argument (argc, argv, "-parallel-manual"))) {
+    PARALLEL = TRUE; // -parallel-manual implies -parallel
+    PARALLEL_MANUAL = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  // this is a test mode : rather than launching the relphot_client jobs remotely, they are 
+  // run in serial via 'system'
+  PARALLEL_SERIAL = FALSE;
+  if ((N = get_argument (argc, argv, "-parallel-serial"))) {
+    if (PARALLEL_MANUAL) {
+      fprintf (stderr, "ERROR: cannot mix -parallel-manual and -parallel-serial\n");
+      exit (1);
+    }
+    PARALLEL = TRUE; // -parallel-serial implies -parallel
+    PARALLEL_SERIAL = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  if (PARALLEL) {
+    if (options.mode != ADDSTAR_MODE_RESORT) {
+      fprintf (stderr, "parallel mode is only valid for -resort mode\n");
+      exit (2);
+    }
+  }
+
+  if ((options.mode == ADDSTAR_MODE_RESORT) && (argc == 1)) return (options);
   if (argc == 2) return (options);
 
-  if ((options.mode == M_REFLIST) && (options.photcode == 0)) {
+  if ((options.mode == ADDSTAR_MODE_REFLIST) && (options.photcode == 0)) {
     fprintf (stderr, "photcode must be specified for -ref\n");
     exit (2);
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_client.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_client.c	(revision 33895)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_client.c	(revision 33896)
@@ -18,11 +18,11 @@
 
   /* basic mode: image, list, refcat */
-  options.mode = M_IMAGE;
+  options.mode = ADDSTAR_MODE_IMAGE;
   if ((N = get_argument (argc, argv, "-ref"))) {
-    options.mode = M_REFLIST;
+    options.mode = ADDSTAR_MODE_REFLIST;
     remove_argument (N, &argc, argv);
   }
   if ((N = get_argument (argc, argv, "-cat"))) {
-    options.mode = M_REFCAT;
+    options.mode = ADDSTAR_MODE_REFCAT;
     remove_argument (N, &argc, argv);
   }
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_load2mass.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_load2mass.c	(revision 33895)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_load2mass.c	(revision 33896)
@@ -18,5 +18,5 @@
 
   /* basic mode: image, list, refcat */
-  options.mode = M_REFCAT;
+  options.mode = ADDSTAR_MODE_REFCAT;
 
   /*** provide additional data ***/ 
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_loadsupercos.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_loadsupercos.c	(revision 33895)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_loadsupercos.c	(revision 33896)
@@ -18,5 +18,5 @@
 
   /* basic mode: image, list, refcat */
-  options.mode = M_REFCAT;
+  options.mode = ADDSTAR_MODE_REFCAT;
 
   /* we do not allow a subset to be extracted -- all or nothing, babe */
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_loadwise.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_loadwise.c	(revision 33895)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_loadwise.c	(revision 33896)
@@ -19,5 +19,5 @@
 
   /* basic mode: image, list, refcat */
-  options.mode = M_REFCAT;
+  options.mode = ADDSTAR_MODE_REFCAT;
 
   /* we do not allow a subset to be extracted -- all or nothing, babe */
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_parallel_client.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_parallel_client.c	(revision 33896)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_parallel_client.c	(revision 33896)
@@ -0,0 +1,130 @@
+# include "addstar.h"
+
+static void help (void);
+
+// options actually respected by addstar_client
+//   options.mode
+//   options.existing_regions
+//   options.nosort
+
+AddstarClientOptions args (int argc, char **argv, AddstarClientOptions options) {
+  
+  int i, N;
+  int QUALITY_AIRMASS;
+
+  NREFSTAR_GROUP = 1; // not used by -resort
+  NSTAR_GROUP = 1; // not used by -resort
+  NTHREADS = 0; // for now, addstar_client is not threaded
+
+  /* check for help request */
+  if (get_argument (argc, argv, "-help") ||
+      get_argument (argc, argv, "-h")) {
+    help ();
+  }
+
+  /* basic mode: image, list, refcat */
+  options.mode = ADDSTAR_MODE_NONE;
+  if ((N = get_argument (argc, argv, "-resort"))) {
+    options.mode = ADDSTAR_MODE_RESORT;
+    remove_argument (N, &argc, argv);
+  }
+  if (options.mode == ADDSTAR_MODE_NONE) {
+      fprintf (stderr, "error: no valid addstar_client mode is defined\n");
+      exit (2);
+  }
+
+  /* restrict to a portion of the sky? (REFCAT only) */
+  UserPatch.Rmin = 0;
+  UserPatch.Rmax = 360;
+  UserPatch.Dmin = -90;
+  UserPatch.Dmax = +90;
+  if ((N = get_argument (argc, argv, "-region"))) {
+    remove_argument (N, &argc, argv);
+    UserPatch.Rmin = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    UserPatch.Rmax = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    UserPatch.Dmin = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    UserPatch.Dmax = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  // by definition, the client is not parallel 
+  PARALLEL = FALSE;
+  PARALLEL_MANUAL = FALSE;
+  PARALLEL_SERIAL = FALSE;
+
+  HOST_ID = 0;
+  if ((N = get_argument (argc, argv, "-hostID"))) {
+    remove_argument (N, &argc, argv);
+    HOST_ID = atoi (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  if (!HOST_ID) help();
+
+  HOSTDIR = NULL;
+  if ((N = get_argument (argc, argv, "-hostdir"))) {
+    remove_argument (N, &argc, argv);
+    HOSTDIR = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  if (!HOSTDIR) help();
+
+  /*** modify behavior ***/
+  /* only add to existing objects */
+  options.existing_regions = FALSE;
+  if ((N = get_argument (argc, argv, "-existing-regions"))) {
+    options.existing_regions = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  /* don't re-sort the measure sequence */
+  options.nosort = FALSE;
+  if ((N = get_argument (argc, argv, "-nosort"))) {
+    options.nosort = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  /* only add new rows (-update) or re-write complete measure table (forces -nosort) */
+  options.update = FALSE;
+  if ((N = get_argument (argc, argv, "-update"))) {
+    options.update = TRUE;
+    options.nosort = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  if ((N = get_argument (argc, argv, "-force-sort"))) {
+    options.nosort = 3;  // temporary mode to mean 'force-sort'
+    remove_argument (N, &argc, argv);
+  }
+
+  /* extra error messages */
+  VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    VERBOSE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  if ((options.mode == ADDSTAR_MODE_RESORT) && (argc == 1)) return (options);
+
+  fprintf (stderr, "USAGE: addstar_client -resort (SkyRegion)\n");
+  exit (2);
+}
+
+static void help () {
+
+  fprintf (stderr, "USAGE\n");
+  fprintf (stderr, "  addstar_client -resort (SkyRegion) -hostID (id) -hostdir (dir)");
+  fprintf (stderr, "     perform measure sorting for the specified catalog\n\n");
+
+  fprintf (stderr, "  optional flags:\n");
+  fprintf (stderr, "  -region ra ra dec dec 	  : only add data in specified region (-ref mode only)\n");
+  fprintf (stderr, "  -existing-regions           : only add measurements to existing catalog files\n");
+  fprintf (stderr, "  -nosort             	  : don't re-sort the measure entries (improves speed)\n");
+  fprintf (stderr, "  -update             	  : only update the new rows (forces -nosort)\n");
+  fprintf (stderr, "  -force-sort             	  : \n");
+  fprintf (stderr, "  -v                    	  : verbose mode\n");
+  fprintf (stderr, "  -help                 	  : this list\n");
+  fprintf (stderr, "  -h                    	  : this list\n\n");
+
+  exit (2);
+}
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_sedstar.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_sedstar.c	(revision 33895)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/args_sedstar.c	(revision 33896)
@@ -18,5 +18,5 @@
 
   /* basic mode: image, list, refcat */
-  options.mode = M_REFCAT;
+  options.mode = ADDSTAR_MODE_REFCAT;
 
   /*** provide additional data ***/ 
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/resort_unthreaded.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/resort_unthreaded.c	(revision 33895)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/resort_unthreaded.c	(revision 33896)
@@ -1,17 +1,5 @@
 # include "addstar.h"
 
-/* upgrade to parallel mode:
-   
-   setup up skylist and call resort_unthreaded_catalogs ()
-   
-   resort_unthreaded_catalogs has a parallel and serial version, etc.
-
- */
-
-int resort_unthreaded (AddstarClientOptions *options, SkyTable *sky) {
-
-  off_t i;
-  off_t Naverage, Nmeasure;
-  Catalog catalog;
+int resort_unthreaded (AddstarClientOptions *options, SkyTable *sky, int hostID, char *hostpath) {
 
   double dtime;
@@ -52,5 +40,5 @@
   }
 
-  resort_unthreaded_catalogs ()
+  resort_unthreaded_catalogs (options, 0, NULL)
 
   gettimeofday (&stop, NULL);
Index: /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/resort_unthreaded_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/resort_unthreaded_catalogs.c	(revision 33895)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/addstar/src/resort_unthreaded_catalogs.c	(revision 33896)
@@ -1,8 +1,13 @@
 # include "addstar.h"
 
-int resort_unthreaded_catalogs (int hostID, char *hostpath) {
+// 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 ();
+    resort_unthreaded_parallel (options, skylist);
     return TRUE;
   }
@@ -15,13 +20,10 @@
     if (!HostTableTestHost(skylist[0].regions[i], hostID)) continue;
 
-    // XXX BLOCK here for an empty thread
-
-    // set the parameters which guide catalog open/load/create
-    catalog.filename  = skylist[0].filename[i];
-
+    // 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
@@ -45,6 +47,4 @@
     if (options->nosort == 3) catalog.sorted = FALSE;
 
-    // XXX send these to a free thread
-
     if (OLD_RESORT) { 
       resort_catalog_old (&catalog);
@@ -53,7 +53,5 @@
     }
 
-    // XXX wait for completed threads
-
-    /* report total updated values */
+    // report total updated values 
     Naverage += catalog.Naverage;
     Nmeasure += catalog.Nmeasure;
@@ -66,11 +64,10 @@
     dvo_catalog_free (&catalog);
   }
+  return TRUE;
 }
 
 // CATDIR is supplied globally
 # define DEBUG 1
-int resort_unthreaded_parallel (SkyList *sky) {
-
-  // launch the setphot_client jobs to the parallel hosts
+int resort_unthreaded_parallel (AddstarClientOptions *options, SkyList *sky) {
 
   // load the list of hosts
@@ -89,26 +86,12 @@
     table->hosts[i].pathname = tmppath;
 
-    // options / arguments that can affect relphot_client -update-objects:
-    // VERBOSE, VERBOSE2
-    // KEEP_UBERCAL
-    // RESET (-reset)
-    // TimeSelect -time
-    // DophotSelect
-    // (note that psfQual is applied rigidly at 0.85, as is the galaxy test)
-    // MAG_LIM
-    // SIGMA_LIM
-    // ImagSelect, ImagMin, ImagMax
-    // MaxDensityUse, MaxDensityValue
-
     char command[1024];
-    snprintf (command, 1024, "relphot_client -update-objects -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -D CAMERA %s -D STAR_TOOFEW %d -minerror %f", 
-	      table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, CAMERA, STAR_TOOFEW, MIN_ERROR);
+    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 (VERBOSE2)      { snprintf (tmpline, 1024, "%s -vv",             command); 		     strcpy (command, tmpline); }
-    if (RESET)         { snprintf (tmpline, 1024, "%s -reset",          command); 		     strcpy (command, tmpline); }
-    if (UPDATE)        { snprintf (tmpline, 1024, "%s -update",         command); 		     strcpy (command, tmpline); }
-    if (!KEEP_UBERCAL) { snprintf (tmpline, 1024, "%s -reset-ubercal",  command); 		     strcpy (command, tmpline); }
 
     fprintf (stderr, "command: %s\n", command);
@@ -119,5 +102,5 @@
       int status = system (command);
       if (status) {
-	fprintf (stderr, "ERROR running relphot_client\n");
+	fprintf (stderr, "ERROR running addstar_client\n");
 	exit (2);
       }
@@ -135,5 +118,5 @@
 
   if (PARALLEL_MANUAL) {
-    fprintf (stderr, "run the relphot_client commands above.  when these are done, hit return\n");
+    fprintf (stderr, "run the addstar_client commands above.  when these are done, hit return\n");
     getchar();
   }
