Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/include/relastro.h
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/include/relastro.h	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/include/relastro.h	(revision 35671)
@@ -161,4 +161,5 @@
 
 int    RESET;
+int    RESET_BAD_IMAGES;
 int    NLOOP;
 int    NTHREADS;
@@ -278,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: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/ImageOps.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/ImageOps.c	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/ImageOps.c	(revision 35671)
@@ -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) {
@@ -517,5 +539,5 @@
       NoffDECori ++;
       if (VERBOSE2) {
-	fprintf (stderr, "measurement moves far from original location (D): %f %f (%f %f)\n", average[0].R, average[0].D, dR, measure[0].dD, dD);
+	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();
@@ -535,4 +557,6 @@
   }
 
+  NcatTotal += nPos;
+
   int Noff = NoffRAave + NoffDECave + NoffRAori + NoffDECori;
   if (VERBOSE && (Noff > 0)) fprintf (stderr, "Noff ave RA %d, Noff ave DEC %d, Noff ori RA %d, Noff ori DEC %d\n", NoffRAave, NoffDECave, NoffRAori, NoffDECori);
@@ -540,4 +564,8 @@
 
   return;
+}
+
+void printNcatTotal () {
+  fprintf (stderr, "NcatTotal: %d\n", NcatTotal);
 }
 
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateMeasures.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateMeasures.c	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateMeasures.c	(revision 35671)
@@ -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: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateObjectOffsets.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateObjectOffsets.c	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateObjectOffsets.c	(revision 35671)
@@ -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); }
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateObjects.c	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateObjects.c	(revision 35671)
@@ -356,4 +356,7 @@
       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;
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/args.c	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/args.c	(revision 35671)
@@ -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"))) {
@@ -640,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;
   }
 
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/high_speed_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/high_speed_catalogs.c	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/high_speed_catalogs.c	(revision 35671)
@@ -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
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/hpm_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/hpm_catalogs.c	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/hpm_catalogs.c	(revision 35671)
@@ -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
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/load_images.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/load_images.c	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/load_images.c	(revision 35671)
@@ -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: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro.c	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro.c	(revision 35671)
@@ -39,4 +39,5 @@
       // iterate over catalogs to make detection coordinates consistant
       UpdateObjectOffsets (skylist, 0, NULL);
+      exit (0);
 
     default:
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro_client.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro_client.c	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro_client.c	(revision 35671)
@@ -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: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro_images.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro_images.c	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro_images.c	(revision 35671)
@@ -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: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro_objects.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro_objects.c	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro_objects.c	(revision 35671)
@@ -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
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/select_images.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/select_images.c	(revision 35670)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/select_images.c	(revision 35671)
@@ -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;
