Index: trunk/ppStats/src/ppStatsLoop.c
===================================================================
--- trunk/ppStats/src/ppStatsLoop.c	(revision 10165)
+++ trunk/ppStats/src/ppStatsLoop.c	(revision 13607)
@@ -109,5 +109,5 @@
     }
 
-    if (!data->doStats) {
+    if (!data->doStats && psListLength(data->summary)) {
         // Nothing further to do --- don't want to waste our time reading the data
         if (psListLength(cellResults->list) > 0) {
@@ -143,10 +143,10 @@
     }
 
-    // Do the statistics
+    // Measure basic image statistics (means, stdevs, etc).  
     if (data->sample <= 0.0) {
         if (!psImageStats(data->stats, readout->image, readout->mask, data->maskVal)) {
             psLogMsg(__func__, PS_LOG_WARN, "Unable to perform statistics on cell %s --- "
                      "ignored.\n", cellName);
-            goto cellDone;
+            goto statsDone;
         }
     } else {
@@ -175,5 +175,5 @@
             psFree(sampleValues);
             psFree(sampleMask);
-            goto cellDone;
+            goto statsDone;
         }
         psFree(sampleValues);
@@ -201,4 +201,40 @@
     WRITE_STAT(PS_STAT_CLIPPED_STDEV,   "CLIPPED_STDEV", clippedStdev);
 
+    // measure other types of statistics tests
+    
+statsDone:
+    // count saturated pixels
+    if (psListLength(data->summary) > 0)     { 
+	bool get_nSatPixels = false;
+	bool get_fSatPixels = false;
+
+        psListIterator *iterator = psListIteratorAlloc(data->summary, PS_LIST_HEAD, false);
+        psString choice; 
+        while ((choice = psListGetAndIncrement(iterator))) {
+	    if (!strcasecmp (choice, "SAT_PIXEL_NUM"))  get_nSatPixels = true;
+	    if (!strcasecmp (choice, "SAT_PIXEL_FRAC")) get_fSatPixels = true;
+        }
+
+	if (!get_nSatPixels && !get_fSatPixels) goto cellDone;
+
+	// Get the "concepts" of interest
+	float saturation = psMetadataLookupF32(&mdok, cell->concepts, "CELL.SATURATION"); // Saturation level
+	if (!mdok || isnan(saturation)) {
+	    psLogMsg(__func__, PS_LOG_WARN, "CELL.SATURATION is not set --- unable to measure N_SAT_PIXELS.\n");
+	    goto cellDone;
+	}
+
+	int nSatPixels = 0;
+	for (int j = 0; j < readout->image->numRows; j++) {
+	    for (int i = 0; i < readout->image->numCols; i++) {
+		if (readout->image->data.F32[j][i] >= saturation) {
+		    nSatPixels ++;
+		}
+	    }
+	}
+	if (get_nSatPixels) psMetadataAddS32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_NUM", 0, NULL, nSatPixels);
+	if (get_fSatPixels) psMetadataAddF32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_FRAC", 0, NULL, nSatPixels / (double)(readout->image->numRows * readout->image->numCols));
+    }
+
 cellDone:
     // Add the cell results to the chip
