Index: /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/ImageOps.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/ImageOps.c	(revision 28694)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/ImageOps.c	(revision 28695)
@@ -372,4 +372,5 @@
 
     // complain if the new location is far from the average location
+    // XXX warning or error here??
     if (fabs(dR) > 2.0) {
       fprintf (stderr, "!");
@@ -414,4 +415,6 @@
 
   saveOffsets (dPos, nPos, im);
+
+  // XXX this function should probably update the average positions as well.
 
   return;
Index: /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/StarMaps.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/StarMaps.c	(revision 28694)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/StarMaps.c	(revision 28695)
@@ -1,3 +1,19 @@
 # include "relastro.h"
+
+// XXX mark the image grid based on the loaded detections
+// XXX modify tcatalog to exclude any photcode or other choices that
+// only affect image selection?
+
+// XXX this stuff is only going to work for SIMPLE and CHIP; need to
+// use parentID to get from imageID to the mosaic pseudo-image
+
+typedef struct {
+  double L;
+  double M;
+  double X;
+  double Y;
+  double dL;
+  double dM;
+} StarMapPoint;
 
 typedef struct {
@@ -5,4 +21,6 @@
   int  Ny;
   int *stars;
+  StarMapPoint *points;
+  int Npoints;
 } StarMap;
 
@@ -58,2 +76,64 @@
   return (TRUE);
 }
+
+int createStarMapPoints() {
+
+  Image *images;
+  off_t i, Nimages;
+
+  images = getimages(&Nimages);
+
+  for (i = 0; i < Nimages; i++) {
+    
+    ALLOCATE (starmap[i].points, StarMapPoint, NX_MAP*NY_MAP);
+    starmap[i].Npoints = 0;
+
+    for (ix = 0; ix < NX_MAP; ix++) {
+      for (iy = 0; iy < NY_MAP; iy++) {
+	if (starmap[i].stars[iybin*NX_BAP + ixbin] < 1) continue;
+	StarMapPoint *point = &starmap[i].points[starmap[i].Npoints];
+	starmap[i].Npoints++;
+
+	// set the pixel coordinates
+	point[0].X = ixbin * NX_MAP; // XXX fix 0.5 pixel offset
+	point[0].Y = iybin * NY_MAP; // XXX fix 0.5 pixel offset
+
+	// set the transformed coordinates
+	XY_to_LM (&point[0].L, &point[0].M, point[0].X, point[0].Y, &image[i].coords);
+
+	point[0].dL = 0.0;
+	point[0].dM = 0.0;
+      }
+    }
+  }
+
+  return (TRUE);
+}
+
+int checkStarMap(int N) {
+
+  Image *images;
+  off_t i, Nimages;
+  double L, M, dLmax, dMmax;
+
+  images = getimages(&Nimages);
+
+  dLmax = dMmax = 0.0;
+
+  for (i = 0; i < starmap[N].Npoints; i++) {
+
+    // set the transformed coordinates
+    XY_to_LM (&L, &M, starmap[N].point[i].X, starmap[N].point[i].Y, &image[N].coords);
+
+    starmap[N].point[i].dL = starmap[N].point[i].L - L;
+    starmap[N].point[i].dM = starmap[N].point[i].M - M;
+
+    dLmax = MAX(starmap[N].point[i].dL, dLmax);
+    dMmax = MAX(starmap[N].point[i].dM, dMmax);
+  }
+
+  if (dLmax > XXX) return (FALSE);
+  if (dMmax > XXX) return (FALSE);
+  return (TRUE);
+}
+
Index: /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/UpdateChips.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/UpdateChips.c	(revision 28694)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/UpdateChips.c	(revision 28695)
@@ -35,4 +35,15 @@
       oldCoords = getCoords (i);
       memcpy (&image[i].coords, oldCoords, sizeof(Coords));
+      // XXX need to set some flag to note failure here
+      free (raw);
+      free (ref);
+      continue;
+    }
+
+    if (!checkStarMap (i)) {
+      fprintf (stderr, "fit diverges too much for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name,  i,  Nraw);
+      oldCoords = getCoords (i);
+      memcpy (&image[i].coords, oldCoords, sizeof(Coords));
+      // XXX need to set some flag to note failure here
     }
 
Index: /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/UpdateMeasures.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/UpdateMeasures.c	(revision 28694)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/UpdateMeasures.c	(revision 28695)
@@ -13,4 +13,6 @@
     if (!strcmp(&image[i].coords.ctype[4], "-DIS")) continue;
 
+    // skip images that have failed solutions (divergent or otherwise)
+
     /* convert measure coordinates to raw entries */
     fixImageRaw (catalog, Ncatalog, i);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/load_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/load_catalogs.c	(revision 28694)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/load_catalogs.c	(revision 28695)
@@ -37,6 +37,4 @@
     }
 
-    // XXX mark the image grid based on the loaded detections
-    // XXX modify tcatalog to exclude any photcode or other choices that only affect image selection?
     updateStarMaps (&tcatalog);
 
Index: /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/relastro.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/relastro.c	(revision 28694)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/relastro.c	(revision 28695)
@@ -66,4 +66,7 @@
   }
 
+  // set test points based on the starmap
+  createStarMapPoints();
+
   /* major modes */
   switch (FIT_TARGET) {
@@ -104,5 +107,5 @@
 
   // iterate over catalogs to make detection coordinates consistant
-  FixProblemImages (skylist);
+  // FixProblemImages (skylist);
 
   // save the updated image parameters
