Index: branches/eam_branches/ipp-20130509/Ohana/src/delstar/include/delstar.h
===================================================================
--- branches/eam_branches/ipp-20130509/Ohana/src/delstar/include/delstar.h	(revision 35712)
+++ branches/eam_branches/ipp-20130509/Ohana/src/delstar/include/delstar.h	(revision 35713)
@@ -48,4 +48,5 @@
 char  *IMAGENAME;
 char  *IMAGES;
+char  *IMSTATS_FILE;
 
 double NSIGMA;
@@ -161,2 +162,9 @@
 
 void sort_fullIDs (uint64_t *I, int *S, off_t N);
+
+int ImageValidSave(char *filename);
+int ImageValidLoad(char *filename);
+void SummaryImageStats (ImageSubset *image, off_t Nimage_comp);
+void BumpInvalidImage (int Seq);
+void BumpValidImage (int Seq);
+
Index: branches/eam_branches/ipp-20130509/Ohana/src/delstar/src/ImageOpsFixLAP.c
===================================================================
--- branches/eam_branches/ipp-20130509/Ohana/src/delstar/src/ImageOpsFixLAP.c	(revision 35712)
+++ branches/eam_branches/ipp-20130509/Ohana/src/delstar/src/ImageOpsFixLAP.c	(revision 35713)
@@ -16,6 +16,6 @@
 int *imageIndex = NULL;
 
-// XX int *Nimage_valid = NULL;
-// XX int *Nimage_invalid = NULL;
+int *Nimage_valid = NULL;
+int *Nimage_invalid = NULL;
 
 void sort_image_externID (unsigned int *E, short *C, unsigned int *I, unsigned int *Q, off_t N);
@@ -38,4 +38,9 @@
   ALLOCATE (imageID_stk, unsigned int, Nimage);
   ALLOCATE (imageSeq_stk, unsigned int, Nimage);
+
+  ALLOCATE (Nimage_valid, int, Nimage);
+  ALLOCATE (Nimage_invalid, int, Nimage);
+  memset (Nimage_valid, 0, sizeof(int)*Nimage);
+  memset (Nimage_invalid, 0, sizeof(int)*Nimage);
 
   int maxID = 0;
@@ -207,5 +212,4 @@
 }
 
-# if (0)
 // increment the count of valid detections for this image
 void BumpValidImage (int Seq) {
@@ -249,10 +253,12 @@
 
   int Nfixed = 0;
+  int Nskip  = 0;
   int Nbad_1 = 0;
   int Nbad_2 = 0;
 
   for (i = 0; i < Nimage_comp; i++) {
-    if (Nimage_valid[i] + Nimage_invalid[i] == 0) continue;     // XXX for now, skip (optionally?) images with no matched detections
     if (image[i].photcode == 0) continue; // skip images with 0 photcode (eg, PHU)
+
+    if (Nimage_valid[i] + Nimage_invalid[i] == 0) Nskip ++;
 
     if (Nimage_invalid[i] > 0) Nfixed ++;
@@ -264,5 +270,5 @@
   }
 
-  fprintf (stderr, "Nfixed: %d, Ndrop (>1%%) %d, Ndrop (>5%%) %d\n", Nfixed, Nbad_1, Nbad_2);
+  fprintf (stderr, "Nfixed: %d, Nskip %d, Ndrop (>1%%) %d, Ndrop (>5%%) %d\n", Nfixed, Nskip, Nbad_1, Nbad_2);
 }
 
@@ -383,3 +389,2 @@
   return TRUE;
 }
-# endif
Index: branches/eam_branches/ipp-20130509/Ohana/src/delstar/src/args.c
===================================================================
--- branches/eam_branches/ipp-20130509/Ohana/src/delstar/src/args.c	(revision 35712)
+++ branches/eam_branches/ipp-20130509/Ohana/src/delstar/src/args.c	(revision 35713)
@@ -220,4 +220,9 @@
   }
 
+  IMSTATS_FILE = NULL;
+  if ((MODE == MODE_FIX_LAP) && (!PARALLEL)) {
+    IMSTATS_FILE = strcreate ("delstar.fixLAP.stats.fits");
+  }
+
 goodtime:
 
@@ -381,4 +386,16 @@
   }
 
+  IMSTATS_FILE = NULL;
+  if (MODE == MODE_FIX_LAP) {
+    N = get_argument (argc, argv, "-imstats");
+    if (N == 0) {
+      fprintf (stderr, "delstar_client -fix-LAP needs -imstats (FILE)\n");
+      exit (2);
+    }
+    remove_argument (N, &argc, argv);
+    IMSTATS_FILE = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
   if (MODE == MODE_NONE) delstar_client_usage ();
   return (TRUE);
Index: branches/eam_branches/ipp-20130509/Ohana/src/delstar/src/delete_fix_LAP.c
===================================================================
--- branches/eam_branches/ipp-20130509/Ohana/src/delstar/src/delete_fix_LAP.c	(revision 35712)
+++ branches/eam_branches/ipp-20130509/Ohana/src/delstar/src/delete_fix_LAP.c	(revision 35713)
@@ -70,4 +70,7 @@
     dvo_catalog_free (&catalog);
   }
+
+  ImageValidSave (IMSTATS_FILE);
+
   return TRUE;
 }
@@ -122,7 +125,10 @@
     table->hosts[i].pathname = tmppath;
 
+    ALLOCATE (table->hosts[i].results, char, 1024);
+    snprintf (table->hosts[i].results, 1024, "%s/delstar.fixLAP.imstats.%s.dat", table->hosts[i].pathname, uniquer);
+
     char command[1024];
-    snprintf (command, 1024, "delstar_client -hostID %d -D CATDIR %s -hostdir %s -images %s -region %f %f %f %f -fix-LAP", 
-	      table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, imageFile,
+    snprintf (command, 1024, "delstar_client -hostID %d -D CATDIR %s -hostdir %s -images %s -imstats %s -region %f %f %f %f -fix-LAP", 
+	      table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, imageFile, table->hosts[i].results,
 	      UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
 
@@ -163,8 +169,17 @@
   }
 
+  for (i = 0; i < table->Nhosts; i++) {
+    while (!ImageValidLoad (table->hosts[i].results)) {
+      fprintf (stderr, "failed to read data from %s\n", table->hosts[i].hostname);
+    }
+  }
+
   return TRUE;
 }
 
 int UnpackPSPSStackDetectionID(int *sourceID, int *imageID, int *detID, uint64_t pspsStackID);
+
+int Nvalid = 0;
+int Ninvalid = 0;
 
 int delete_fix_LAP_catalog (Catalog *catalog, ImageSubset *image, off_t Nimage) {
@@ -188,4 +203,6 @@
   SecFilt *secfilt = catalog[0].secfilt;
   
+  Nvalid = 0;
+  Ninvalid = 0;
   if (VERBOSE) fprintf (stderr, "starting with Nave, Nmeas: "OFF_T_FMT" "OFF_T_FMT"\n",  catalog[0].Naverage,  catalog[0].Nmeasure);
 
@@ -360,5 +377,5 @@
   off_t NdelMeas = Nmeasure - catalog[0].Nmeasure;
   if (NdelAves || NdelMeas) {
-    fprintf (stderr, "deleting "OFF_T_FMT" measures and "OFF_T_FMT" averages : %s\n",  NdelMeas, NdelAves, catalog[0].filename);
+    fprintf (stderr, "deleting "OFF_T_FMT" measures and "OFF_T_FMT" averages (%d valid, %d invalid): %s\n",  NdelMeas, NdelAves, Nvalid, Ninvalid, catalog[0].filename);
   }
 
@@ -392,5 +409,5 @@
 
   Measure *measure = catalog[0].measure;
-  Average *average = catalog[0].average;
+  // Average *average = catalog[0].average;
   
   uint64_t *fullID;
@@ -440,6 +457,6 @@
     if (!keep) {
       measureDrop[j] = TRUE;
-      off_t N = measure[j].averef;
-      fprintf (stderr, "0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode);
+      // off_t N = measure[j].averef;
+      // fprintf (stderr, "0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode);
     }
   }
@@ -454,6 +471,5 @@
     // for gpc1 exposures, 10000 < photcode < 10600
     if ((10000 < measure[j].photcode) && (measure[j].photcode < 10600)) {
-      // int resetID = FALSE;
-      int resetID = TRUE;
+      int resetID = FALSE;
       off_t imageID = measure[j].imageID;
       if (imageID == 0) {
@@ -478,10 +494,13 @@
 	// off_t N = measure[j].averef;
 	// fprintf (stderr, "no repair 0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode);
+	BumpValidImage (imageN);
+	Nvalid ++;
+	  continue;
       }	
 
     resetID_exp:
       if (resetID) {
-	off_t N = measure[j].averef;
-	fprintf (stderr, "repair 0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode);
+	// off_t N = measure[j].averef;
+	// fprintf (stderr, "repair 0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode);
 	// update the image ID
 	short photcode = measure[j].photcode;
@@ -498,4 +517,7 @@
 	}
 	measure[j].imageID = imageID;
+	BumpInvalidImage (imageN);
+	Ninvalid ++;
+	continue;
       }
     }
@@ -503,6 +525,5 @@
     // for gpc1 exposures, 10000 < photcode < 10600
     if ((11000 <= measure[j].photcode) && (measure[j].photcode < 11600)) {
-      // int resetID = FALSE;
-      int resetID = TRUE;
+      int resetID = FALSE;
       off_t imageID = measure[j].imageID;
       if (imageID == 0) {
@@ -527,8 +548,16 @@
       }
 
+      if (!resetID) {
+	// off_t N = measure[j].averef;
+	// fprintf (stderr, "no repair 0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode);
+	BumpValidImage (imageN);
+	Nvalid ++;
+	continue;
+      }	
+
     resetID_stk:
       if (resetID) {
-	off_t N = measure[j].averef;
-	fprintf (stderr, "repair 0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode);
+	// off_t N = measure[j].averef;
+	// fprintf (stderr, "repair 0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode);
 	// update the image ID
 	off_t imageID, Seq;
@@ -539,4 +568,7 @@
 	}
 	measure[j].imageID = imageID;
+	BumpInvalidImage (imageN);
+	Ninvalid ++;
+	continue;
       }
     }
Index: branches/eam_branches/ipp-20130509/Ohana/src/delstar/src/delstar.c
===================================================================
--- branches/eam_branches/ipp-20130509/Ohana/src/delstar/src/delstar.c	(revision 35712)
+++ branches/eam_branches/ipp-20130509/Ohana/src/delstar/src/delstar.c	(revision 35713)
@@ -41,4 +41,6 @@
 
 	if (!delete_fix_LAP (subset, Nimage)) exit (1);
+	SummaryImageStats (subset, Nimage);
+
 	exit (0);
 	break;
