Index: trunk/ppImage/src/ppImageLoop.c
===================================================================
--- trunk/ppImage/src/ppImageLoop.c	(revision 13970)
+++ trunk/ppImage/src/ppImageLoop.c	(revision 14000)
@@ -4,6 +4,4 @@
 
 #include "ppImage.h"
-#include "ppImageDetrendFringe.h"
-#include "ppImageVersion.h"
 
 bool ppImageLoop (pmConfig *config, ppImageOptions *options) {
@@ -88,5 +86,5 @@
 	
 	// measure various statistics for this image
-	if (!ppImageStats (config, chip, view, options)) {
+	if (!ppImagePixelStats (config, options, view)) {
 	    psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to measures stats for image");
 	    psFree (view);
@@ -119,5 +117,5 @@
         }
 
-        // Close cells
+        // Close cells (XXX shouldn't pmFPAfileClose iterate down as needed?)
         view->cell = -1;
         while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) {
@@ -139,11 +137,4 @@
     }
 
-    // Write out summary statistics
-    if (!ppImageStatsOutput (config, input->fpa, options)) {
-	psError(PS_ERR_UNKNOWN, false, "Unable to write statistics file.\n");
-	psFree (view);
-	return false;
-    }
-
     // XXX an optional full-scale FPA mosaic could happen here
     // it would require us to NOT free PPIMAGE.CHIP until here
@@ -161,4 +152,21 @@
     }
 
+    ppImageFileCheck (config);
+
+    // Write out summary statistics
+    if (!ppImageMetadataStats (config, options)) {
+	psError(PS_ERR_UNKNOWN, false, "Unable to write statistics file.\n");
+	psFree (view);
+	return false;
+    }
+
+
+    // Write out summary statistics
+    if (!ppImageStatsOutput (config, options)) {
+	psError(PS_ERR_UNKNOWN, false, "Unable to write statistics file.\n");
+	psFree (view);
+	return false;
+    }
+
     // Close FPA
     if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
