Index: trunk/Ohana/src/relastro/src/UpdateMeasures.c
===================================================================
--- trunk/Ohana/src/relastro/src/UpdateMeasures.c	(revision 39384)
+++ trunk/Ohana/src/relastro/src/UpdateMeasures.c	(revision 39385)
@@ -9,21 +9,19 @@
   double DPOS_MAX_ASEC;
 
-  int badImage = 
-    ID_IMAGE_ASTROM_NOCAL | 
-    ID_IMAGE_ASTROM_POOR | 
-    ID_IMAGE_ASTROM_FAIL | 
-    ID_IMAGE_ASTROM_SKIP | 
-    ID_IMAGE_ASTROM_FEW;
-
-  if (RESET_BAD_IMAGES) badImage = 0;
-
   image = getimages (&Nimage, NULL);
 
   // track measurements which are far from their original position (poor at pole)
-  int NoffRAave = 0;  int NoffRAori = 0; 
-  int NoffDECave = 0; int NoffDECori = 0;
+  int NoffRAori = 0; 
+  int NoffDECori = 0;
 
   for (i = 0; i < Ncatalog; i++) {
     myAssert (!catalog[i].Nmeasure || catalog[i].measureT, "programming error");
+    for (j = 0; j < catalog[i].Naverage; j++) {
+      // normalize R,D to 0,360 & -90,90
+      Average *average = &catalog[i].average[j];
+      average[0].R = ohana_normalize_angle_to_midpoint(average[0].R, 180.0);
+      average[0].D = ohana_normalize_angle_to_midpoint(average[0].D,   0.0);
+    }
+
     for (j = 0; j < catalog[i].Nmeasure; j++) {
       MeasureTiny *measureT = &catalog[i].measureT[j];
@@ -38,8 +36,4 @@
       myAssert (measureT->t <= image[im].tzero + image[im].NX*image[im].trate/5000.0, "image time mismatch (2)");
       // I'm allowing the trate*NX to be a factor of 2x too small
-
-      // skip measurements on images that have failed solutions (divergent or otherwise)
-      // XXX apply this or not??
-      if (FALSE && (image[im].flags & badImage)) continue;
 
       Coords *moscoords = image[im].coords.mosaic;
@@ -68,55 +62,26 @@
       XY_to_RD (&R, &D, X, Y, imcoords);
 
-      int n = measureT[0].averef;
-      Average *average = &catalog[i].average[n];
+      R = ohana_normalize_angle_to_midpoint(R, 180.0);
+      D = ohana_normalize_angle_to_midpoint(D,   0.0);
 
-      double dR = 3600.0*(average[0].R - R);
-      double dD = 3600.0*(average[0].D - D);
+      double oldR = ohana_normalize_angle_to_midpoint(measureT[0].R, 180.0);
+      double oldD = ohana_normalize_angle_to_midpoint(measureT[0].D,   0.0);
 
-      // 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(oldD * RAD_DEG);
 
-      float csdec = cos(average[0].D * RAD_DEG);
+      double dR = 3600.0*fabs(csdec*(oldR - R));
+      double dD = 3600.0*fabs(oldD - R);
 
-      // 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*csdec) > 3.0*ADDSTAR_RADIUS) {
-	NoffRAave ++;
+      // complain if the new location is far from the old location
+      if (dR > DPOS_MAX_ASEC) {
+	NoffRAori ++;
 	if (VERBOSE2 && catalog[i].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[i].measure);
+	  fprintf (stderr, "measurement moves far from original location (R): %f %f : %f %f (%f)\n", oldR, oldD, R, D, dR);
 	}
       }
-      if (fabs(dD) > 3.0*ADDSTAR_RADIUS) {
-	NoffDECave ++;
-	if (VERBOSE2 && catalog[i].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[i].measure);
-	}
-      }
-
-      // complain if the new location is far from the old location
-      if (fabs(csdec*(measureT[0].R - R)) > DPOS_MAX_ASEC) {
-	NoffRAori ++;
-	if (VERBOSE2 && catalog[i].measure) {
-	  fprintf (stderr, "measurement moves far from original location (R): %f %f (%f %f %f %f)\n", average[0].R, average[0].D, measureT[0].R, dR, csdec*(measureT[0].R - R), dD);
-	  dump_measures (&average[0], catalog[i].measure);
-	}
-      }
-      if (fabs(measureT[0].D - D) > DPOS_MAX_ASEC) {
+      if (dD > DPOS_MAX_ASEC) {
 	NoffDECori ++;
 	if (VERBOSE2 && catalog[i].measure) {
-	  fprintf (stderr, "measurement moves far from original location (D): %f %f (%f %f %f)\n", average[0].R, average[0].D, dR, measureT[0].D, dD);
-	  dump_measures (&average[0], catalog[i].measure);
+	  fprintf (stderr, "measurement moves far from original location (D): %f %f : %f %f (%f)\n", oldR, oldD, R, D, dD);
 	}
       }
@@ -131,6 +96,6 @@
   // printNcatTotal ();
 
-  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);
+  int Noff = NoffRAori + NoffDECori;
+  if (VERBOSE && (Noff > 0)) fprintf (stderr, "Noff ori RA %d, Noff ori DEC %d\n", NoffRAori, NoffDECori);
 
   return (TRUE);
