Index: /branches/eam_branches/ipp-20111122/Ohana/src/relastro/include/relastro.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relastro/include/relastro.h	(revision 33536)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relastro/include/relastro.h	(revision 33537)
@@ -142,4 +142,6 @@
 int    PARALLEL_MANUAL;
 int    PARALLEL_SERIAL;
+
+int    PARALLEL_OUTPUT;
 
 int    VERBOSE;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/UpdateObjectOffsets.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/UpdateObjectOffsets.c	(revision 33536)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/UpdateObjectOffsets.c	(revision 33537)
@@ -15,5 +15,5 @@
 
   // XXX need to decide how to determine PARALLEL mode...
-  if (PARALLEL & !hostID) {
+  if (PARALLEL && !hostID) {
     UpdateObjectOffsets_parallel (skylist);
     return TRUE;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/UpdateObjects.c	(revision 33536)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/UpdateObjects.c	(revision 33537)
@@ -98,9 +98,7 @@
       // when we update the output measure values, we need to do it here
 
-      Tmin = Tmax = (measure[0].t - T2000) / (86400*365.25);
       mode = FIT_MODE;
 
       // find the basic properties of the detections for this object (Tmin, Tmax, Tmean)
-      Tmean = 0;
       for (k = 0; k < catalog[i].average[j].Nmeasure; k++) {
 
@@ -129,11 +127,12 @@
 	T[N] = (measure[k].t - T2000) / (86400*365.25) ; // time relative to J2000 in years
 
-	Tmin = MIN(Tmin, T[N]);
-	Tmax = MAX(Tmax, T[N]);
-	Tmean += T[N];
-
 	// dX, dY : error in arcsec -- 
 	dX[N] = GetAstromErrorTiny (&measure[k], ERROR_MODE_RA);
 	dY[N] = GetAstromErrorTiny (&measure[k], ERROR_MODE_DEC);
+
+	// XXX this is a bit hackish -- allow a given photcode or measurement to be
+	// ignored by ignoring excessively bad errors
+	if (dX[N] > 10.0) continue;
+	if (dY[N] > 10.0) continue;
 
 	// add systematic error in quadrature, if desired
@@ -166,8 +165,22 @@
       catalog[i].average[j].flags &= ~ID_STAR_FEW;
 
+      // find Tmin & Tmax from the list of accepted measurements
+      Tmean = 0;
+      Tmin = Tmax = T[0];
+      for (k = 0; k < N; k++) {
+	Tmin = MIN(Tmin, T[N]);
+	Tmax = MAX(Tmax, T[N]);
+	Tmean += T[N];
+      }
       // XXX add the parallax factor range as a criterion as well
       Trange = Tmax - Tmin;
       if (Trange < PM_DT_MIN) mode = FIT_AVERAGE;
       if ((mode == FIT_PM_ONLY) && (N < PM_TOOFEW)) mode = FIT_AVERAGE;
+
+      if (FIT_TARGET == TARGET_HIGH_SPEED) {
+	  Tmean = 0.5*(Tmax - Tmin);
+      } else {
+	  Tmean /= (float) N;
+      }
 
       // too few measurements for average position (require 2 values)
@@ -186,10 +199,4 @@
       coords.crval2 = D[0];
 
-      if (FIT_TARGET == TARGET_HIGH_SPEED) {
-	  Tmean = 0.5*(Tmax - Tmin);
-      } else {
-	  Tmean /= (float) N;
-      }
-      
       // XVERB |= (catalog[i].averge[j].objID == 0xc90) && (catalog[i].average[j].catID == 0x2a1e);
       XVERB |= (catalog[i].average[j].objID == OBJ_ID_SRC) && (catalog[i].average[j].catID == CAT_ID_SRC);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/args.c	(revision 33536)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/args.c	(revision 33537)
@@ -95,4 +95,14 @@
     HIGH_SPEED_DIR = abspath(argv[N], MAX_PATH_LENGTH);
     remove_argument (N, &argc, argv);
+  }
+
+  PARALLEL_OUTPUT = FALSE;
+  if ((N = get_argument (argc, argv, "-parallel-output"))) {
+    remove_argument (N, &argc, argv);
+    PARALLEL_OUTPUT = TRUE;
+    if (FIT_TARGET != TARGET_HIGH_SPEED) {
+      fprintf (stderr, "-parallel-output only valid for -high-speed mode\n");
+      exit (1);
+    }
   }
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/high_speed_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/high_speed_catalogs.c	(revision 33536)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/high_speed_catalogs.c	(revision 33537)
@@ -14,5 +14,5 @@
 
   // XXX need to decide how to determine PARALLEL mode...
-  if (PARALLEL & !hostID) {
+  if (PARALLEL && !hostID) {
     high_speed_catalogs_parallel (skylist);
     goto finish;
@@ -87,4 +87,22 @@
   }    
 
+  // If we want to parallelize the output, the remote client needs to load the HostTable
+  // for the output catdir.  Require the output HostTable to match the input (ie, same
+  // hostIDs must exist).  Preferred, but not required, that they match in the host
+  // location.
+  HostTable *tableOut = NULL;
+  if (PARALLEL_OUTPUT) {
+    // load the list of hosts
+    tableOut = HostTableLoad (HIGH_SPEED_DIR, skylist->hosts);
+    if (!tableOut) {
+      fprintf (stderr, "ERROR: failure reading Host Table %s for output database %s\n", skylist->hosts, HIGH_SPEED_DIR);
+      exit (1);
+    }    
+    if (table->Nhosts != tableOut->Nhosts) {
+      fprintf (stderr, "ERROR: output HostTable must have matching hosts (%d in, %d out)\n", table->Nhosts, tableOut->Nhosts);
+      exit (1);
+    }
+  }
+
   int i;
   for (i = 0; i < table->Nhosts; i++) {
@@ -95,10 +113,26 @@
     table->hosts[i].pathname = tmppath;
 
-    // options / arguments that can affect relastro_client -high-speed
+    // use this directory to save the output catalogs (distributed if parallel)
+    char *outputDir = strcreate(HIGH_SPEED_DIR);
+    if (PARALLEL_OUTPUT) {
+      // find the matching host entry in the output HostTable (match by ID, not index)
+      int hostID = table->hosts[i].hostID;
+      int index = table->index[hostID];
+      if (index == -1) {
+	fprintf (stderr, "ERROR: output HostTable must have matching hosts (host ID %d not found)\n", hostID);
+	exit (1);
+      }
+
+      free (outputDir);
+      outputDir = abspath (tableOut->hosts[index].pathname, MAX_PATH_LENGTH);
+    }
 
     char command[1024];
     snprintf (command, 1024, "relastro_client -high-speed %s %s %f %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f", 
-	      PHOTCODE_A_LIST, PHOTCODE_B_LIST, RADIUS, HIGH_SPEED_DIR, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
-
+	      PHOTCODE_A_LIST, PHOTCODE_B_LIST, RADIUS, outputDir, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
+
+    free (outputDir);
+
+    // options / arguments that can affect relastro_client -high-speed
     char tmpline[1024];
     if (FIT_MODE == FIT_PM_ONLY)  	 { snprintf (tmpline, 1024, "%s -pm",    command);           	strcpy (command, tmpline); }
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/high_speed_objects.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/high_speed_objects.c	(revision 33536)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/high_speed_objects.c	(revision 33537)
@@ -18,4 +18,5 @@
   int Nsecfilt;
   char filename[1024];
+
   snprintf (filename, 1024, "%s/%s.cpt", HIGH_SPEED_DIR, region[0].name);
   fprintf (stderr, "%s\n",filename);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/load_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/load_catalogs.c	(revision 33536)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/load_catalogs.c	(revision 33537)
@@ -9,5 +9,5 @@
 
   // XXX need to decide how to determine PARALLEL mode...
-  if (PARALLEL & !hostID) {
+  if (PARALLEL && !hostID) {
     catalog = load_catalogs_parallel (skylist, Ncatalog);
     return catalog;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/relastro_objects.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/relastro_objects.c	(revision 33536)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/relastro_objects.c	(revision 33537)
@@ -26,5 +26,5 @@
 
   // XXX need to decide how to determine PARALLEL mode...
-  if (PARALLEL & !hostID) {
+  if (PARALLEL && !hostID) {
     relastro_objects_parallel (skylist);
     return TRUE;
