Index: trunk/Ohana/src/relastro/src/RepairWarpMeasures.c
===================================================================
--- trunk/Ohana/src/relastro/src/RepairWarpMeasures.c	(revision 39470)
+++ trunk/Ohana/src/relastro/src/RepairWarpMeasures.c	(revision 39470)
@@ -0,0 +1,82 @@
+# include "relastro.h"
+
+// XXX need to load_images first and generate some lookup tables
+int RepairWarpMeasures (Catalog *catalog, int Ncatalog) {
+
+  off_t i, j, Nimage;
+  Image *image;
+  double DPOS_MAX_ASEC;
+
+  image = getimages (&Nimage, NULL);
+
+  for (i = 0; i < Ncatalog; i++) {
+    myAssert (!catalog[i].Nmeasure || catalog[i].measureT, "programming error");
+
+    for (j = 0; j < catalog[i].Nmeasure; j++) {
+      Measure *measure = &catalog[i].measure[j];
+
+      // we are only going to repair warp detections
+      if (!isGPC1warp(measure->photcode)) 
+	// XXX fix extID
+	continue;
+    }
+
+      // get the associated average value:
+      int averef = measure->averef;
+      Average *average = &catalog[i].average[averef];
+
+      // double-check for consistency
+      myAssert (average->objID == measure->objID, "mismatch");
+
+      // check if this detection is far from it correct location
+      double Rwrp = measure->R;
+      double Dwrp = measure->D;
+
+      double Rave = average->R;
+      double Dave = average->D;
+      
+      float csdec = cos(Dave * RAD_DEG);
+
+      // find the ra,dec displacement in arcsec:
+      double dR = 3600.0*(Rwrp - Rave)*csdec;
+      double dD = 3600.0*(Dwrp - Dave);
+
+      // skip detections which are within a small distance of the expected location
+      double dPos = hypot(dR,dD);
+      if (dPos < 2.0) continue;
+
+      // find the corrected warp ID:
+      int warpID = getWarpGroup (measure->t, measure->photcode, Rstk, Dstk);
+
+      // assert on coords being TAN?
+      Coords *imcoords = &image[warpID].coords;
+
+      double X = measure->Xccd;
+      double Y = measure->Yccd;
+
+      double Rnew, Dnew;
+      XY_to_RD (&Rnew, &Dnew, X, Y, imcoords);
+
+      Rnew = ohana_normalize_angle_to_midpoint(Rnew, 180.0);
+      Dnew = ohana_normalize_angle_to_midpoint(Dnew,   0.0);
+
+      // find the ra,dec displacement in arcsec:
+      double dRnew = 3600.0*(Rnew - Rave)*csdec;
+      double dDnew = 3600.0*(Dnew - Dave);
+
+      // skip detections which are within a small distance of the expected location
+      double dPos = hypot(dRnew,dDnew);
+      if (dPos > 2.0) {
+	// complain. abort?
+	fprintf (stderr, "measurement still far from average location\n");
+	abort();
+      }
+
+      measure->R = Rnew;
+      measure->D = Dnew;
+    }
+  }
+  return (TRUE);
+}
+
+
Index: trunk/Ohana/src/relastro/src/WarpImageMaps.c
===================================================================
--- trunk/Ohana/src/relastro/src/WarpImageMaps.c	(revision 39470)
+++ trunk/Ohana/src/relastro/src/WarpImageMaps.c	(revision 39470)
@@ -0,0 +1,4 @@
+
+int GetWarpID () {
+
+}
