Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/Makefile
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/Makefile	(revision 33327)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/Makefile	(revision 33328)
@@ -71,4 +71,5 @@
 $(SRC)/load_catalogs.$(ARCH).o	 \
 $(SRC)/reload_catalogs.$(ARCH).o \
+$(SRC)/relphot_objects.$(ARCH).o	 \
 $(SRC)/relphot_client.$(ARCH).o	 \
 $(SRC)/setExclusions.$(ARCH).o 	 \
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/include/relphot.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/include/relphot.h	(revision 33327)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/include/relphot.h	(revision 33328)
@@ -12,4 +12,5 @@
     MODE_LOAD   = 1,
     MODE_UPDATE = 2,
+    MODE_UPDATE_OBJECTS = 3,
 } ModeType;
 
@@ -286,5 +287,5 @@
 void          wimages             PROTO((void));
 void          write_coords        PROTO((Header *header, Coords *coords));
-int relphot_objects (void);
+int relphot_objects (int hostID, char *hostpath);
 
 void relphot_usage (void);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/StarOps.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/StarOps.c	(revision 33327)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/StarOps.c	(revision 33328)
@@ -239,4 +239,6 @@
 // NOTE: this function operates on the real Measure & Average structures, not the
 // MeasureTiny & AverageTiny structures
+// NOTE: this function is called on the remote machine -- make sure any (global) options 
+// are passed to the relphot_client program
 int setMave (Catalog *catalog, int Ncatalog) {
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/args.c	(revision 33327)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/args.c	(revision 33328)
@@ -352,4 +352,12 @@
     remove_argument (N, &argc, argv);
   }
+  if ((N = get_argument (argc, argv, "-update-objects"))) {
+    if (MODE) {
+      fprintf (stderr, "ERROR: cannot mix modes (-load, -update, -update-objects)\n");
+      relphot_client_usage();
+    }
+    MODE = MODE_UPDATE_OBJECTS;
+    remove_argument (N, &argc, argv);
+  }
   if (!MODE) relphot_client_usage();
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/help.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/help.c	(revision 33327)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/help.c	(revision 33328)
@@ -47,4 +47,5 @@
   fprintf (stderr, "ERROR: USAGE: relphot (photcodes) -load (filename) -hostID (hostID) -hostdir (hostdir) [options]\n");
   fprintf (stderr, "       or:    relphot -update (filename) -hostID (hostID) -hostdir (hostdir) [options]\n");
+  fprintf (stderr, "       or:    relphot -update-objects -hostID (hostID) -hostdir (hostdir) [options]\n");
   fprintf (stderr, "  use -h for more usage information\n");
   exit (2);
@@ -65,7 +66,9 @@
   fprintf (stderr, "       relphot_client -update (images) : apply calculated zero points to the client's tables\n\n");
   fprintf (stderr, "                              (images) : location of the table with the image zero points\n");
+  fprintf (stderr, "       relphot_client -update-objects  : determine average magnitudes for objects\n\n");
   fprintf (stderr, "       db info : -hostID (hostID) -hostdir (hostdir) -catdir (catdir)\n");
   fprintf (stderr, "other options:\n");
-  fprintf (stderr, "  -v : verbose output\n");
+  fprintf (stderr, "  -v  : verbose output\n");
+  fprintf (stderr, "  -vv : extra verbose output\n");
   fprintf (stderr, "  \n");
   exit (2);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot.c	(revision 33327)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot.c	(revision 33328)
@@ -22,5 +22,5 @@
   /* the object analysis is a separate process iterating over catalogs */
   if (UpdateAverages) {
-    relphot_objects ();
+    relphot_objects (0, NULL);
     exit (0);
   }
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot_client.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot_client.c	(revision 33327)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot_client.c	(revision 33328)
@@ -71,4 +71,9 @@
     }
 
+    case MODE_UPDATE_OBJECTS: {
+      relphot_objects (HOST_ID, HOSTDIR);
+      break;
+    }
+
     default:
       fprintf (stderr, "impossible!");
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot_objects.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot_objects.c	(revision 33327)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot_objects.c	(revision 33328)
@@ -6,5 +6,7 @@
 // has been correctly propagated to the measurement, the average will respect that value.
 
-int relphot_objects () {
+int relphot_objects_parallel (SkyList *sky);
+
+int relphot_objects (int hostID, char *hostpath) {
 
   off_t i, j, k;
@@ -22,9 +24,20 @@
   skylist = SkyListByPatch (sky, -1, &UserPatch);
 
+  // XXX need to decide how to determine PARALLEL mode...
+  if (PARALLEL & !hostID) {
+    relphot_objects_parallel (skylist);
+    return TRUE;
+  }
+
   // load data from each region file, only use bright stars
   for (i = 0; i < skylist[0].Nregions; i++) {
 
+    if (hostID && (skylist[0].regions[i]->hostID != hostID)) continue;
+
     // set up the basic catalog info
-    catalog.filename  = skylist[0].filename[i];
+    // set up the basic catalog info
+    char hostfile[1024];
+    snprintf (hostfile, 1024, "%s/%s.cpt", hostpath, skylist[0].regions[i]->name);
+    catalog.filename  = hostID ? hostfile : skylist[0].filename[i];
     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
@@ -43,4 +56,5 @@
     }
 
+    // XXX need to respect UBERCAL measurements (and not reset them?)
     // reset 
     if (RESET) {
@@ -81,2 +95,81 @@
   return (TRUE);
 }
+
+// CATDIR is supplied globally
+# define DEBUG 1
+int relphot_objects_parallel (SkyList *sky) {
+
+  // launch the setphot_client jobs to the parallel hosts
+
+  // 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, MAX_PATH_LENGTH);
+    free (table->hosts[i].pathname);
+    table->hosts[i].pathname = tmppath;
+
+    char catalogFile[512];
+    snprintf (catalogFile, 512, "%s/relphot.catalog.subset.dat", table->hosts[i].pathname);
+
+    // 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", 
+	      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 (KEEP_UBERCAL)  { snprintf (tmpline, 1024, "%s -keep-ubercal",   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 relphot_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 relphot_client commands above.  when these are done, hit return\n");
+    getchar();
+  }
+  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
+    HostTableWaitJobs (table, __FILE__, __LINE__);
+  }
+
+  return TRUE;
+}      
