Index: trunk/Ohana/src/delstar/include/delstar.h
===================================================================
--- trunk/Ohana/src/delstar/include/delstar.h	(revision 39306)
+++ trunk/Ohana/src/delstar/include/delstar.h	(revision 39307)
@@ -66,4 +66,5 @@
 int    VERBOSE2;
 int    UPDATE;
+int    SKIP_DIFF_PAIRS;
 int    IMAGE_DETAILS;
 int    IMAGE_DUPLICATES_BY_OBSTIME;
Index: trunk/Ohana/src/delstar/src/args.c
===================================================================
--- trunk/Ohana/src/delstar/src/args.c	(revision 39306)
+++ trunk/Ohana/src/delstar/src/args.c	(revision 39307)
@@ -79,4 +79,10 @@
   }
 
+  SKIP_DIFF_PAIRS = FALSE;
+  if ((N = get_argument (argc, argv, "-skip-diff-pairs"))) {
+    SKIP_DIFF_PAIRS = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
   // We should generally not delete the images before the measures (or we won't know what
   // to delete). -image-only is for testing, -image-only-force -update WILL delete the images 
Index: trunk/Ohana/src/delstar/src/delete_duplicate_images.c
===================================================================
--- trunk/Ohana/src/delstar/src/delete_duplicate_images.c	(revision 39306)
+++ trunk/Ohana/src/delstar/src/delete_duplicate_images.c	(revision 39307)
@@ -466,4 +466,74 @@
   off_t Ndup = 0;
 
+  if (SKIP_DIFF_PAIRS) {
+    int *pair1 = NULL;
+    int *pair2 = NULL;
+
+    // in this case, I need to generate a set of pair maps:
+    ALLOCATE (pair1, int, extID->range); // first image for the extID
+    ALLOCATE (pair2, int, extID->range); // second image for the extID
+    for (i = 0; i < extID->range; i++) { 
+      pair1[i] = -1;
+      pair2[i] = -1;
+    }
+    for (i = 0; i < Nimage; i++) {
+      if (image[i].externID == 0) continue;
+      off_t Nx = image[i].externID - extID->minID;
+      myAssert (Nx >= 0, "oops");
+      myAssert (Nx < extID->range, "oops");
+
+      // only map the pairs
+      if (extID->value[Nx] != 2) continue;
+
+      if (pair1[Nx] == -1) {
+	pair1[Nx] = i;
+	continue;
+      }
+      if (pair2[Nx] == -1) {
+	pair2[Nx] = i;
+	continue;
+      }
+    }
+
+    for (i = 0; i < extID->range; i++) {
+      // we have only 2 valid cases: 
+      // 1) pair1 == pair2 == -1, 
+      // 2) pair1 > -1, pair2 > -1
+
+      // this extID does not correspond to a pair, skip it:
+      if ((pair1[i] == -1) && (pair2[i] == -1)) continue;
+
+      myAssert (extID->value[i] == 2, "oops");
+
+      int valid = ((pair1[i]  > -1) && (pair2[i]  > -1));
+      myAssert (valid, "oops");
+      
+      // we think we have a pair, check the names:
+      int length1 = strlen(image[pair1[i]].name);
+      int length2 = strlen(image[pair2[i]].name);
+
+      // names should be of the form: foo.cmf, foo.inv.cmf
+      valid = (length1 == length2 + 4) || (length1 == length2 - 4);
+      if (!valid) continue;
+
+      int baselength = MIN(length1, length2) - 4;
+      valid = !strncmp (image[pair1[i]].name, image[pair2[i]].name, baselength);
+      if (!valid) continue;
+
+      valid = TRUE;
+      if (length1 > length2) {
+	valid = valid && !strcmp (&image[pair1[i]].name[baselength], ".inv.cmf");
+	valid = valid && !strcmp (&image[pair2[i]].name[baselength], ".cmf");
+      } else {
+	valid = valid && !strcmp (&image[pair1[i]].name[baselength], ".cmf");
+	valid = valid && !strcmp (&image[pair2[i]].name[baselength], ".inv.cmf");
+      }
+      if (!valid) continue;
+
+      // this pair is a valid diff image pair, do not delete:
+      extID->value[i] = 1;
+    }
+  }
+
   // set imageID->value to TRUE for images we want to delete
   for (i = 0; i < Nimage; i++) {
@@ -472,5 +542,9 @@
     myAssert (Nx >= 0, "oops");
     myAssert (Nx < extID->range, "oops");
+
+    // do not delete any extID with only a single image
     if (extID->value[Nx] < 2) continue;
+
+    // do not delete the last image
     if (Ndelete[Nx] == extID->value[Nx] - 1) continue;
 
