Index: /trunk/Ohana/src/relastro/include/relastro.h
===================================================================
--- /trunk/Ohana/src/relastro/include/relastro.h	(revision 35762)
+++ /trunk/Ohana/src/relastro/include/relastro.h	(revision 35763)
@@ -161,4 +161,5 @@
 
 int    RESET;
+int    RESET_BAD_IMAGES;
 int    NLOOP;
 int    NTHREADS;
@@ -194,4 +195,7 @@
 
 int PhotFlagSelect, PhotFlagPoor, PhotFlagBad;
+
+float MinBadQF;
+float MaxMeanOffset;
 
 int TimeSelect;
@@ -275,6 +279,6 @@
 int           liststats_pos       PROTO((double *value, double *dvalue, int N, StatType *stats, int XVERB));
 Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath));
-int           load_images         PROTO((FITS_DB *db, SkyList *skylist));
-Image        *select_images       PROTO((SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage));
+int           load_images         PROTO((FITS_DB *db, SkyList *skylist, int UseFullOverlap));
+Image        *select_images       PROTO((SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage, int UseFullOverlap));
 
 void check_permissions (char *basefile);
Index: /trunk/Ohana/src/relastro/src/ImageOps.c
===================================================================
--- /trunk/Ohana/src/relastro/src/ImageOps.c	(revision 35762)
+++ /trunk/Ohana/src/relastro/src/ImageOps.c	(revision 35763)
@@ -222,4 +222,15 @@
 
   ID = measure[0].imageID;
+
+  if (catalog[cat].measure) {
+    Measure *measureBig = &catalog[cat].measure[meas];
+    int TESTPT = FALSE;
+    TESTPT |= (measureBig->imageID == CAT_ID_SRC) && (measureBig->detID == OBJ_ID_SRC);
+    TESTPT |= (measureBig->imageID == CAT_ID_DST) && (measureBig->detID == OBJ_ID_DST);
+    if (TESTPT) {
+      fprintf (stderr, "got test det\n");
+    }
+  }
+
   idx = getImageByID (ID);
   if (idx == -1) {
@@ -379,4 +390,6 @@
 }
 
+static int NcatTotal = 0;
+
 // return StarData values for detections in the specified image, converting coordinates from the
 // chip positions: X,Y -> L,M -> P,Q -> R,D
@@ -445,4 +458,13 @@
 
     Measure *measure = &catalog[c].measure[m];
+    MeasureTiny *measureT = &catalog[c].measureT[m];
+
+    int TESTPT = FALSE;
+
+    TESTPT |= (measure->imageID == CAT_ID_SRC) && (measure->detID == OBJ_ID_SRC);
+    TESTPT |= (measure->imageID == CAT_ID_DST) && (measure->detID == OBJ_ID_DST);
+    if (TESTPT) {
+      fprintf (stderr, "got test det\n");
+    }
 
     if (USE_FIXED_PIXCOORDS) {
@@ -454,4 +476,5 @@
     }
     n = measure[0].averef;
+    Average *average = &catalog[c].average[n];
 
     if (moscoords == NULL) {
@@ -467,14 +490,29 @@
 
     // new dR, dD : test
-    dR = 3600.0*(catalog[c].average[n].R - R);
-    dD = 3600.0*(catalog[c].average[n].D - D);
+    dR = 3600.0*(average[0].R - R);
+    dD = 3600.0*(average[0].D - D);
+
+    // make sure detection is on the same side of the 0,360 boundary as the average
+    // this will give some funny results withing ~1 arcsec of the pol
+    if (dR > +180.0*3600.0) {
+      // average on high end of boundary, move star up
+      R += 360.0;
+      dR = 3600.0*(average[0].R - R);
+    }
+    if (dR < -180.0*3600.0) {
+      // average on low end of boundary, move star down
+      R -= 360.0;
+      dR = 3600.0*(average[0].R - R);
+    }
+
+    float csdec = cos(average[0].D * RAD_DEG);
 
     // complain if the new location is far from the average location
     // NOTE: This should never happen, or our StarMap tests are not working
-    if (fabs(dR) > 3.0*ADDSTAR_RADIUS) {
+    if (fabs(dR*csdec) > 3.0*ADDSTAR_RADIUS) {
       NoffRAave ++;
       if (VERBOSE2) {
-	fprintf (stderr, "measurement is far from average location (R): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD);
-	dump_measures (&catalog[c].average[n], catalog[c].measure);
+	fprintf (stderr, "measurement is far from average location (R): %f %f (%f %f %f)\n", average[0].R, average[0].D, dR, dR*csdec, dD);
+	dump_measures (&average[0], catalog[c].measure);
       }
       // abort ();
@@ -483,6 +521,6 @@
       NoffDECave ++;
       if (VERBOSE2) {
-	fprintf (stderr, "measurement is far from average location (D): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD);
-	dump_measures (&catalog[c].average[n], catalog[c].measure);
+	fprintf (stderr, "measurement is far from average location (D): %f %f (%f %f)\n", average[0].R, average[0].D, dR, dD);
+	dump_measures (&average[0], catalog[c].measure);
       }
       // abort ();
@@ -490,9 +528,9 @@
 
     // complain if the new location is far from the old location
-    if (fabs(catalog[c].measureT[m].dR - dR) > DPOS_MAX_ASEC) {
+    if (fabs(csdec*(measure[0].dR - dR)) > DPOS_MAX_ASEC) {
       NoffRAori ++;
       if (VERBOSE2) {
-	fprintf (stderr, "measurement is far from original location (R): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD);
-	dump_measures (&catalog[c].average[n], catalog[c].measure);
+	fprintf (stderr, "measurement moves far from original location (R): %f %f (%f %f %f %f)\n", average[0].R, average[0].D, measure[0].dR, dR, csdec*(measure[0].dR - dR), dD);
+	dump_measures (&average[0], catalog[c].measure);
       }
       // abort();
@@ -501,6 +539,6 @@
       NoffDECori ++;
       if (VERBOSE2) {
-	fprintf (stderr, "measurement is far from original location (D): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD);
-	dump_measures (&catalog[c].average[n], catalog[c].measure);
+	fprintf (stderr, "measurement moves far from original location (D): %f %f (%f %f %f)\n", average[0].R, average[0].D, dR, measure[0].dD, dD);
+	dump_measures (&average[0], catalog[c].measure);
       }      // abort();
     }
@@ -511,19 +549,13 @@
     measure[0].dR = dR;
     measure[0].dD = dD;
+    measureT[0].dR = dR;
+    measureT[0].dD = dD;
     
-    if (measure[0].dR > +180.0*3600.0) {
-      // average on high end of boundary, move star up
-      R += 360.0;
-      measure[0].dR = 3600.0*(catalog[c].average[n].R - R);
-    }
-    if (measure[0].dR < -180.0*3600.0) {
-      // average on low end of boundary, move star down
-      R -= 360.0;
-      measure[0].dR = 3600.0*(catalog[c].average[n].R - R);
-    }
-
     // set the systematic error for this image:
     measure[0].dRsys = ToShortPixels(dPosSys);
-  }
+    measureT[0].dRsys = ToShortPixels(dPosSys);
+  }
+
+  NcatTotal += nPos;
 
   int Noff = NoffRAave + NoffDECave + NoffRAori + NoffDECori;
@@ -531,7 +563,9 @@
   saveOffsets (dPos, nPos, im);
 
-  // XXX this function should probably update the average positions as well.
-
   return;
+}
+
+void printNcatTotal () {
+  fprintf (stderr, "NcatTotal: %d\n", NcatTotal);
 }
 
@@ -1013,4 +1047,8 @@
   }  
   
+  // if (MinBadQF > 0.0) {
+  //   if (measure[0].psfQF < MinBadQF) return FALSE;
+  // }
+
   /* select measurements by time */
   if (TimeSelect) {
@@ -1075,4 +1113,8 @@
   }  
   
+  if (MinBadQF > 0.0) {
+    if (measure[0].psfQF < MinBadQF) return FALSE;
+  }
+
   /* select measurements by time */
   if (TimeSelect) {
Index: /trunk/Ohana/src/relastro/src/UpdateMeasures.c
===================================================================
--- /trunk/Ohana/src/relastro/src/UpdateMeasures.c	(revision 35762)
+++ /trunk/Ohana/src/relastro/src/UpdateMeasures.c	(revision 35763)
@@ -1,3 +1,5 @@
 # include "relastro.h"
+
+void printNcatTotal ();
 
 // this function operates on Measure, not MeasureTiny
@@ -13,4 +15,6 @@
     ID_IMAGE_ASTROM_SKIP | 
     ID_IMAGE_ASTROM_FEW;
+
+  if (RESET_BAD_IMAGES) badImage = 0;
 
   image = getimages (&Nimage, NULL);
@@ -28,4 +32,6 @@
   }
 
+  printNcatTotal ();
+
   return (TRUE);
 }
Index: /trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c
===================================================================
--- /trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c	(revision 35762)
+++ /trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c	(revision 35763)
@@ -65,4 +65,10 @@
     freeImageBins (1);
 
+    if (!UPDATE) {
+      dvo_catalog_unlock (&catalog);
+      dvo_catalog_free (&catalog);
+      continue;
+    }
+    
     // write the updated detections to disk
     save_catalogs (&catalog, 1);
@@ -85,6 +91,21 @@
   }    
 
-  int i;
+  int i, j;
   for (i = 0; i < table->Nhosts; i++) {
+
+    if (sky->Nregions < table->Nhosts) {
+      // do any of the regions want this host?
+      int wantThisHost = FALSE;
+      for (j = 0; j < sky->Nregions; j++) {
+	if (HostTableTestHost (sky->regions[j], table->hosts[i].hostID)) {
+	  wantThisHost = TRUE;
+	  break;
+	}
+      }
+      if (!wantThisHost) {
+	// fprintf (stderr, "skip host %s\n", table->hosts[i].hostname);
+	continue;
+      }
+    }
 
     // ensure that the paths are absolute path names
@@ -113,4 +134,8 @@
     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 (RESET_BAD_IMAGES) { snprintf (tmpline, 1024, "%s -reset-bad-images", command); 		     strcpy (command, tmpline); }
+
     if (ImagSelect)    { snprintf (tmpline, 1024, "%s -instmag %f %f",  command, ImagMin, ImagMax);  strcpy (command, tmpline); }
     if (MaxDensityUse) { snprintf (tmpline, 1024, "%s -max-density %f", command, MaxDensityValue);   strcpy (command, tmpline); }
@@ -127,4 +152,7 @@
     if (PhotFlagPoor)      { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor);   strcpy (command, tmpline); }
     // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
+
+    if (MinBadQF > 0.0)    { snprintf (tmpline, 1024, "%s -min-bad-psfqf %f",        command, MinBadQF);      strcpy (command, tmpline); }
+    if (MaxMeanOffset != 10.0) { snprintf (tmpline, 1024, "%s -max-mean-offset  %f", command, MaxMeanOffset); strcpy (command, tmpline); }
 
     if (TimeSelect) { 
Index: /trunk/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- /trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 35762)
+++ /trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 35763)
@@ -48,6 +48,6 @@
   PMFit fitAve, fitPM, fitPAR, fit;
   time_t T2000;
-  off_t Nave, Npm, Npar, Nskip;
-  off_t NaveSum, NpmSum, NparSum, NskipSum;
+  off_t Nave, Npm, Npar, Nskip, Noffset;
+  off_t NaveSum, NpmSum, NparSum, NskipSum, NoffSum;
   double Tmin, Tmax, Tmean, Trange;
 
@@ -80,14 +80,17 @@
   }
 
-  NaveSum = NparSum = NpmSum = NskipSum = 0;
+  NaveSum = NparSum = NpmSum = NoffSum = NskipSum = 0;
   for (i = 0; i < Ncatalog; i++) {
 
     if (VERBOSE2) fprintf (stderr, "astrometrize catalog %d : "OFF_T_FMT" ave, "OFF_T_FMT" meas\n", i,  catalog[i].Naverage,  catalog[i].Nmeasure);
 
-    Nave = Npar = Npm = Nskip = 0;
+    Nave = Npar = Npm = Nskip = Noffset = 0;
     for (j = 0; j < catalog[i].Naverage; j++) {
       /* calculate the average value of R,D for a single star */
 
       XVERB = FALSE;
+      fitAve.chisq = NAN;
+      fitPM.chisq = NAN;
+      fitPAR.chisq = NAN;
 
       if (catalog[i].average[j].Nmeasure == 0) {
@@ -118,5 +121,7 @@
 
 	// does the measurement pass the supplied filtering constraints?
-	if (!MeasFilterTestTiny(&measure[k], FALSE)) {
+	// MeasFilterTestTiny does not test psfQF
+	int keepMeasure = measureBig ? MeasFilterTest(&measureBig[k], FALSE) : MeasFilterTestTiny(&measure[k], FALSE);
+	if (!keepMeasure) {
 	  measure[k].dbFlags &= ~ID_MEAS_USED_OBJ;
 	  if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; }
@@ -198,5 +203,5 @@
       Trange = Tmax - Tmin;
       if (Trange < PM_DT_MIN) mode = FIT_AVERAGE;
-      if ((mode == FIT_PM_ONLY) && (N < PM_TOOFEW)) mode = FIT_AVERAGE;
+      if (((mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) && (N <= PM_TOOFEW)) mode = FIT_AVERAGE;
 
       if (FIT_TARGET == TARGET_HIGH_SPEED) {
@@ -265,6 +270,9 @@
 	float parRange = hypot (dXRange, dYRange);
 	
-	if (parRange >= PAR_FACTOR_MIN) {
+# define PAR_TOOFEW 5
+	if ((parRange >= PAR_FACTOR_MIN) && (N > PAR_TOOFEW)) {
 	  FitPMandPar (&fitPAR, X, dX, Y, dY, T, pX, pY, N, XVERB);
+	  if (XVERB) fprintf (stderr, "fitted PM+PAR:  %f - %f : %f %f : %f %f : %f %f : %f vs %f vs %f\n", Tmin, Tmax, fitPAR.Ro, fitPAR.Do, fitPAR.uR, fitPAR.uD, fitPAR.p, fitPAR.dp, fitPAR.chisq, fitPM.chisq, fitAve.chisq);
+
 	  XY_to_RD (&fitPAR.Ro, &fitPAR.Do, fitPAR.Ro, fitPAR.Do, &coords);
 	  catalog[i].average[j].flags |= ID_STAR_FIT_PAR;
@@ -315,5 +323,5 @@
 	break;
       }
-      if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f) pm=(%f %f)\n",
+      if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f) pm=(%f %f) plx=(%f +/- %f)\n",
 			  catalog[i].average[j].R, 
 			  catalog[i].average[j].D, 
@@ -321,6 +329,5 @@
 			  3600*(catalog[i].average[j].R - fit.Ro), 
 			  3600*(catalog[i].average[j].D - fit.Do),
-			  fit.uR,
-			  fit.uD);
+			  fit.uR, fit.uD, fit.p, fit.dp);
 
       // make sure that the fit succeeded
@@ -340,4 +347,20 @@
 	continue;
       }
+
+      // what is the offset relative to the mean fit position?
+      coords.crval1 = catalog[i].average[j].R;
+      coords.crval2 = catalog[i].average[j].D;
+
+      double dXoff, dYoff;
+      RD_to_XY (&dXoff, &dYoff, fit.Ro, fit.Do, &coords);
+      float dPos = hypot (dXoff, dYoff);
+      if (dPos > MaxMeanOffset) {
+	if (Noffset < 100) {
+	  fprintf (stderr, "(%f,%f) -> (%f,%f) (%f,%f)\n", coords.crval1, coords.crval2, fit.Ro, fit.Do, dXoff, dYoff);
+	}
+	Noffset ++;
+	continue;
+      }
+
 
       // the measure fields must be updated before the average fields
@@ -385,8 +408,9 @@
     NparSum += Npar;
     NskipSum += Nskip;
-    if (VERBOSE) fprintf (stderr, "catalog %d : "OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par : Nskip "OFF_T_FMT"\n",  i,  Nave,  Npm,  Npar,  Nskip);
+    NoffSum += Noffset;
+    if (VERBOSE) fprintf (stderr, "catalog %d : "OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par : Nskip "OFF_T_FMT", Noffset "OFF_T_FMT"\n",  i,  Nave,  Npm,  Npar,  Nskip, Noffset);
   }
 
-  if (VERBOSE) fprintf (stderr, "fitted "OFF_T_FMT" objects ("OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par), skipped "OFF_T_FMT"\n",  (NaveSum + NpmSum + NparSum),  NaveSum,  NpmSum,  NparSum,  NskipSum);
+  if (VERBOSE) fprintf (stderr, "fitted "OFF_T_FMT" objects ("OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par), skipped "OFF_T_FMT", "OFF_T_FMT" have too large an offset\n",  (NaveSum + NpmSum + NparSum),  NaveSum,  NpmSum,  NparSum,  NskipSum, NoffSum);
   return (TRUE);
 }
Index: /trunk/Ohana/src/relastro/src/args.c
===================================================================
--- /trunk/Ohana/src/relastro/src/args.c	(revision 35762)
+++ /trunk/Ohana/src/relastro/src/args.c	(revision 35763)
@@ -315,4 +315,10 @@
   }
 
+  RESET_BAD_IMAGES = FALSE;
+  if ((N = get_argument (argc, argv, "-reset-bad-images"))) {
+    remove_argument (N, &argc, argv);
+    RESET_BAD_IMAGES = TRUE;
+  }
+
   UPDATE = FALSE;
   if ((N = get_argument (argc, argv, "-update"))) {
@@ -379,4 +385,18 @@
     remove_argument (N, &argc, argv);
     PhotFlagPoor = atoi (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  MinBadQF = 0.0;
+  if ((N = get_argument (argc, argv, "-min-bad-psfqf"))) {
+    remove_argument (N, &argc, argv);
+    MinBadQF = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  MaxMeanOffset = 10.0;
+  if ((N = get_argument (argc, argv, "-max-mean-offset"))) {
+    remove_argument (N, &argc, argv);
+    MaxMeanOffset = atof (argv[N]);
     remove_argument (N, &argc, argv);
   }
@@ -626,13 +646,14 @@
   }
 
+  RESET_BAD_IMAGES = FALSE;
+  if ((N = get_argument (argc, argv, "-reset-bad-images"))) {
+    remove_argument (N, &argc, argv);
+    RESET_BAD_IMAGES = TRUE;
+  }
+
   UPDATE = FALSE;
   if ((N = get_argument (argc, argv, "-update"))) {
     remove_argument (N, &argc, argv);
     UPDATE = TRUE;
-  }
-
-  // do not hold the lock on the Image table for relastro_client -update-offsets
-  if (FIT_TARGET == TARGET_UPDATE_OFFSETS) {
-    UPDATE = FALSE;
   }
 
@@ -675,4 +696,18 @@
     remove_argument (N, &argc, argv);
     PhotFlagPoor = atoi (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  MinBadQF = 0.0;
+  if ((N = get_argument (argc, argv, "-min-bad-psfqf"))) {
+    remove_argument (N, &argc, argv);
+    MinBadQF = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  MaxMeanOffset = 10.0;
+  if ((N = get_argument (argc, argv, "-max-mean-offset"))) {
+    remove_argument (N, &argc, argv);
+    MaxMeanOffset = atof (argv[N]);
     remove_argument (N, &argc, argv);
   }
Index: /trunk/Ohana/src/relastro/src/high_speed_catalogs.c
===================================================================
--- /trunk/Ohana/src/relastro/src/high_speed_catalogs.c	(revision 35762)
+++ /trunk/Ohana/src/relastro/src/high_speed_catalogs.c	(revision 35763)
@@ -80,12 +80,12 @@
 // CATDIR is supplied globally
 # define DEBUG 1
-int high_speed_catalogs_parallel (SkyList *skylist) {
+int high_speed_catalogs_parallel (SkyList *sky) {
 
   // launch the setphot_client jobs to the parallel hosts
 
   // load the list of hosts
-  HostTable *table = HostTableLoad (CATDIR, skylist->hosts);
+  HostTable *table = HostTableLoad (CATDIR, sky->hosts);
   if (!table) {
-    fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", skylist->hosts, CATDIR);
+    fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);
     exit (1);
   }    
@@ -98,7 +98,7 @@
   if (PARALLEL_OUTPUT) {
     // load the list of hosts
-    tableOut = HostTableLoad (HIGH_SPEED_DIR, skylist->hosts);
+    tableOut = HostTableLoad (HIGH_SPEED_DIR, sky->hosts);
     if (!tableOut) {
-      fprintf (stderr, "ERROR: failure reading Host Table %s for output database %s\n", skylist->hosts, HIGH_SPEED_DIR);
+      fprintf (stderr, "ERROR: failure reading Host Table %s for output database %s\n", sky->hosts, HIGH_SPEED_DIR);
       exit (1);
     }    
@@ -109,6 +109,21 @@
   }
 
-  int i;
+  int i, j;
   for (i = 0; i < table->Nhosts; i++) {
+
+    if (sky->Nregions < table->Nhosts) {
+      // do any of the regions want this host?
+      int wantThisHost = FALSE;
+      for (j = 0; j < sky->Nregions; j++) {
+	if (HostTableTestHost (sky->regions[j], table->hosts[i].hostID)) {
+	  wantThisHost = TRUE;
+	  break;
+	}
+      }
+      if (!wantThisHost) {
+	// fprintf (stderr, "skip host %s\n", table->hosts[i].hostname);
+	continue;
+      }
+    }
 
     // ensure that the paths are absolute path names
@@ -163,4 +178,7 @@
     // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
 
+    if (MinBadQF > 0.0)    { snprintf (tmpline, 1024, "%s -min-bad-psfqf %f",        command, MinBadQF);      strcpy (command, tmpline); }
+    if (MaxMeanOffset != 10.0) { snprintf (tmpline, 1024, "%s -max-mean-offset  %f", command, MaxMeanOffset); strcpy (command, tmpline); }
+
     if (WHERE_A[0]) { snprintf (tmpline, 1024, "%s -D WHERE_A \"%s\"", command, WHERE_A);               strcpy (command, tmpline); }
     if (WHERE_B[0]) { snprintf (tmpline, 1024, "%s -D WHERE_B \"%s\"", command, WHERE_B);               strcpy (command, tmpline); }
Index: /trunk/Ohana/src/relastro/src/hpm_catalogs.c
===================================================================
--- /trunk/Ohana/src/relastro/src/hpm_catalogs.c	(revision 35762)
+++ /trunk/Ohana/src/relastro/src/hpm_catalogs.c	(revision 35763)
@@ -78,12 +78,12 @@
 // CATDIR is supplied globally
 # define DEBUG 1
-int hpm_catalogs_parallel (SkyList *skylist) {
+int hpm_catalogs_parallel (SkyList *sky) {
 
   // launch the setphot_client jobs to the parallel hosts
 
   // load the list of hosts
-  HostTable *table = HostTableLoad (CATDIR, skylist->hosts);
+  HostTable *table = HostTableLoad (CATDIR, sky->hosts);
   if (!table) {
-    fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", skylist->hosts, CATDIR);
+    fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);
     exit (1);
   }    
@@ -96,7 +96,7 @@
   if (PARALLEL_OUTPUT) {
     // load the list of hosts
-    tableOut = HostTableLoad (HIGH_SPEED_DIR, skylist->hosts);
+    tableOut = HostTableLoad (HIGH_SPEED_DIR, sky->hosts);
     if (!tableOut) {
-      fprintf (stderr, "ERROR: failure reading Host Table %s for output database %s\n", skylist->hosts, HIGH_SPEED_DIR);
+      fprintf (stderr, "ERROR: failure reading Host Table %s for output database %s\n", sky->hosts, HIGH_SPEED_DIR);
       exit (1);
     }    
@@ -107,6 +107,21 @@
   }
 
-  int i;
+  int i, j;
   for (i = 0; i < table->Nhosts; i++) {
+
+    if (sky->Nregions < table->Nhosts) {
+      // do any of the regions want this host?
+      int wantThisHost = FALSE;
+      for (j = 0; j < sky->Nregions; j++) {
+	if (HostTableTestHost (sky->regions[j], table->hosts[i].hostID)) {
+	  wantThisHost = TRUE;
+	  break;
+	}
+      }
+      if (!wantThisHost) {
+	// fprintf (stderr, "skip host %s\n", table->hosts[i].hostname);
+	continue;
+      }
+    }
 
     // ensure that the paths are absolute path names
@@ -161,4 +176,7 @@
     // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
 
+    if (MinBadQF > 0.0)    { snprintf (tmpline, 1024, "%s -min-bad-psfqf %f",        command, MinBadQF);      strcpy (command, tmpline); }
+    if (MaxMeanOffset != 10.0) { snprintf (tmpline, 1024, "%s -max-mean-offset  %f", command, MaxMeanOffset); strcpy (command, tmpline); }
+
     if (TimeSelect) { 
       char *tstart = ohana_sec_to_date (TSTART);
Index: /trunk/Ohana/src/relastro/src/load_images.c
===================================================================
--- /trunk/Ohana/src/relastro/src/load_images.c	(revision 35762)
+++ /trunk/Ohana/src/relastro/src/load_images.c	(revision 35763)
@@ -7,5 +7,5 @@
   fprintf (stderr, MSG, __VA_ARGS__); }
 
-int load_images (FITS_DB *db, SkyList *skylist) {
+int load_images (FITS_DB *db, SkyList *skylist, int UseFullOverlap) {
 
   Image     *image, *subset;
@@ -25,5 +25,5 @@
 
   // select the images which overlap the selected sky regions
-  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset);
+  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset, UseFullOverlap);
   MARKTIME("  select images: %f sec\n", dtime);
 
@@ -35,5 +35,6 @@
   
   /* unlock, if we can (else, unlocked below) */
-  if (!UPDATE) dvo_image_unlock (db); 
+  int unlockImages = !UPDATE || (FIT_TARGET == TARGET_UPDATE_OFFSETS);
+  if (unlockImages) dvo_image_unlock (db); 
 
   return TRUE;
Index: /trunk/Ohana/src/relastro/src/relastro.c
===================================================================
--- /trunk/Ohana/src/relastro/src/relastro.c	(revision 35762)
+++ /trunk/Ohana/src/relastro/src/relastro.c	(revision 35763)
@@ -39,4 +39,5 @@
       // iterate over catalogs to make detection coordinates consistant
       UpdateObjectOffsets (skylist, 0, NULL);
+      exit (0);
 
     default:
Index: /trunk/Ohana/src/relastro/src/relastro_client.c
===================================================================
--- /trunk/Ohana/src/relastro/src/relastro_client.c	(revision 35762)
+++ /trunk/Ohana/src/relastro/src/relastro_client.c	(revision 35763)
@@ -77,5 +77,5 @@
 
       /* load regions and images based on specified sky patch (default depth) */
-      load_images (&db, skylist);
+      load_images (&db, skylist, FALSE);
       
       // // load the image subset table from the specified location
Index: /trunk/Ohana/src/relastro/src/relastro_images.c
===================================================================
--- /trunk/Ohana/src/relastro/src/relastro_images.c	(revision 35762)
+++ /trunk/Ohana/src/relastro/src/relastro_images.c	(revision 35763)
@@ -20,6 +20,6 @@
   MARKTIME("load image data: %f sec\n", dtime);
 
-  /* load regions and images based on specified sky patch (default depth) */
-  load_images (&db, skylist);
+  /* load regions and images based on specified sky patch (default depth) (require full overlap) */
+  load_images (&db, skylist, TRUE);
   MARKTIME("load images: %f sec\n", dtime);
 
Index: /trunk/Ohana/src/relastro/src/relastro_objects.c
===================================================================
--- /trunk/Ohana/src/relastro/src/relastro_objects.c	(revision 35762)
+++ /trunk/Ohana/src/relastro/src/relastro_objects.c	(revision 35763)
@@ -110,6 +110,21 @@
   }    
 
-  int i;
+  int i, j;
   for (i = 0; i < table->Nhosts; i++) {
+
+    if (sky->Nregions < table->Nhosts) {
+      // do any of the regions want this host?
+      int wantThisHost = FALSE;
+      for (j = 0; j < sky->Nregions; j++) {
+	if (HostTableTestHost (sky->regions[j], table->hosts[i].hostID)) {
+	  wantThisHost = TRUE;
+	  break;
+	}
+      }
+      if (!wantThisHost) {
+	// fprintf (stderr, "skip host %s\n", table->hosts[i].hostname);
+	continue;
+      }
+    }
 
     // ensure that the paths are absolute path names
@@ -154,8 +169,11 @@
     if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, 1024, "%s +photcode %s", command, PHOTCODE_KEEP_LIST); strcpy (command, tmpline); }
     if (PHOTCODE_SKIP_LIST) { snprintf (tmpline, 1024, "%s -photcode %s", command, PHOTCODE_SKIP_LIST); strcpy (command, tmpline); }
-    if (PhotFlagSelect)    { snprintf (tmpline, 1024, "%s +photflags",   command);                     strcpy (command, tmpline); }
-    if (PhotFlagBad)       { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad);     strcpy (command, tmpline); }
-    if (PhotFlagPoor)      { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor);   strcpy (command, tmpline); }
+    if (PhotFlagSelect)    { snprintf (tmpline, 1024, "%s +photflags",   command);                     	strcpy (command, tmpline); }
+    if (PhotFlagBad)       { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad);     	strcpy (command, tmpline); }
+    if (PhotFlagPoor)      { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor);   	strcpy (command, tmpline); }
     // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
+
+    if (MinBadQF > 0.0)    { snprintf (tmpline, 1024, "%s -min-bad-psfqf %f",        command, MinBadQF);      strcpy (command, tmpline); }
+    if (MaxMeanOffset != 10.0) { snprintf (tmpline, 1024, "%s -max-mean-offset  %f", command, MaxMeanOffset); strcpy (command, tmpline); }
 
     if (TimeSelect) { 
Index: /trunk/Ohana/src/relastro/src/select_images.c
===================================================================
--- /trunk/Ohana/src/relastro/src/select_images.c	(revision 35762)
+++ /trunk/Ohana/src/relastro/src/select_images.c	(revision 35763)
@@ -22,5 +22,5 @@
   fprintf (stderr, MSG, __VA_ARGS__); }
 
-Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage) {
+Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage, int UseFullOverlap) {
   
   Image *image;
@@ -122,7 +122,15 @@
   for (i = 0; i < Ntimage; i++) {
       
+    if (FALSE && !strncmp(timage[i].name, "o5479g0238o", 10)) {
+      fprintf (stderr, "test image 1\n");
+    }
+    if (FALSE && !strncmp(timage[i].name, "o6227g0311o", 10)) {
+      fprintf (stderr, "test image 2\n");
+    }
+
     /* select images by photcode, or equiv photcode, if specified */
     if (NphotcodesKeep > 0) {
       found = FALSE;
+      // XXX this bit of code excludes DIS mosaics and should be fixed
       for (k = 0; (k < NphotcodesKeep) && !found; k++) {
 	if (photcodesKeep[k][0].code == timage[i].photcode) found = TRUE;
@@ -196,5 +204,5 @@
     if (RmaxImage < RminSkyRegion) continue;
 
-    if (!strncmp(timage[i].name, "o5903g0638o", 10) && (timage[i].photcode == 10355)) {
+    if (FALSE && !strncmp(timage[i].name, "o5903g0638o", 10) && (timage[i].photcode == 10355)) {
       fprintf (stderr, "test image\n");
     }
@@ -203,6 +211,5 @@
     // images) XXX : if we calibrate the mosaic, require that the full mosaic be inside
     // the region and all of its chips..
-# define FULL_OVERLAP 1
-    if (FULL_OVERLAP && strcmp(&timage[i].coords.ctype[4], "-DIS")) {
+    if (UseFullOverlap && strcmp(&timage[i].coords.ctype[4], "-DIS")) {
       if (RmaxImage > UserPatch.Rmax) continue;
       if (RminImage < UserPatch.Rmin) continue;
