Index: trunk/Ohana/src/dvolens/include/dvolens.h
===================================================================
--- trunk/Ohana/src/dvolens/include/dvolens.h	(revision 39548)
+++ trunk/Ohana/src/dvolens/include/dvolens.h	(revision 39550)
@@ -52,4 +52,5 @@
 
 int    REPAIR_LENSING_IDS;
+int    REPAIR_LENSING_IDS_FROM_WARPS;
 
 DvoLensMode MODE;
Index: trunk/Ohana/src/dvolens/src/args.c
===================================================================
--- trunk/Ohana/src/dvolens/src/args.c	(revision 39548)
+++ trunk/Ohana/src/dvolens/src/args.c	(revision 39550)
@@ -43,4 +43,10 @@
   if ((N = get_argument (argc, argv, "-repair-lensing-ids"))) {
     REPAIR_LENSING_IDS = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  REPAIR_LENSING_IDS_FROM_WARPS = FALSE;
+  if ((N = get_argument (argc, argv, "-repair-lensing-ids-from-warps"))) {
+    REPAIR_LENSING_IDS_FROM_WARPS = TRUE;
     remove_argument (N, &argc, argv);
   }
@@ -182,4 +188,10 @@
   }
 
+  REPAIR_LENSING_IDS_FROM_WARPS = FALSE;
+  if ((N = get_argument (argc, argv, "-repair-lensing-ids-from-warps"))) {
+    REPAIR_LENSING_IDS_FROM_WARPS = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
   UPDATE = FALSE;
   if ((N = get_argument (argc, argv, "-update"))) {
Index: trunk/Ohana/src/dvolens/src/update_objects_catalog.c
===================================================================
--- trunk/Ohana/src/dvolens/src/update_objects_catalog.c	(revision 39548)
+++ trunk/Ohana/src/dvolens/src/update_objects_catalog.c	(revision 39550)
@@ -45,4 +45,7 @@
   double time3 = 0.0;
   double time4 = 0.0;
+
+  int NmissLensing = 0;
+  int NmissWarps   = 0;
 
   for (i = 0; i < catalog->Naverage; i++) {
@@ -67,4 +70,29 @@
     off_t Loff = average->lensingOffset;
     off_t Moff = average->measureOffset;
+
+    // repair lensing imageID values by asserting the warp measurements and lensing measurements are in the same order
+    if (REPAIR_LENSING_IDS_FROM_WARPS) {
+      int Nmatch = 0;
+      for (Mj = 0, Lj = 0; (Mj < average->Nmeasure) && (Lj < average->Nlensing); Mj++) {
+	Measure *measure = &catalog->measure[Moff + Mj];
+	if (!isGPC1warp(measure->photcode)) continue;
+	
+	Lensing *lensing = &catalog->lensing[Loff + Lj];
+	if (lensing->detID == measure->detID) {
+	  lensing->oldImID = lensing->imageID;
+	  lensing->imageID = measure->imageID;
+	  Nmatch ++;
+	}
+	Lj ++;
+      }
+      if (Nmatch != Lj) { NmissLensing ++; }
+      
+      while (Mj < average->Nmeasure) {
+	Measure *measure = &catalog->measure[Moff + Mj];
+	Mj ++;
+	if (!isGPC1warp(measure->photcode)) continue;
+	NmissWarps ++;
+      }
+    }      
 
     // I have Nmeasure entries for this object.  I need to match measure to lensing (by imageID)
@@ -327,5 +355,7 @@
   fprintf (stderr, "done with %d aves (%f %f %f %f)\n", (int) catalog->Naverage, time1, time2, time3, time4);
 
-  fprintf (stderr, "corrected %d lensing IDs, failed on %d lensing IDs\n", Nfixed, Nfailed);
+  if (REPAIR_LENSING_IDS) fprintf (stderr, "corrected %d lensing IDs, failed on %d lensing IDs\n", Nfixed, Nfailed);
+
+  if (REPAIR_LENSING_IDS_FROM_WARPS) fprintf (stderr, "missed %d lensing IDs, %d warps\n", NmissLensing, NmissWarps);
 
   catalog->Nlensobj = Nlensobj;
