Index: /trunk/psphot/src/Makefile.am
===================================================================
--- /trunk/psphot/src/Makefile.am	(revision 37940)
+++ /trunk/psphot/src/Makefile.am	(revision 37941)
@@ -230,4 +230,5 @@
 	psphotLoadSRCTEXT.c            \
 	psphotReadoutCleanup.c	       \
+	psphotStatsFile.c	       \
 	psphotSourcePlots.c	       \
 	psphotRadialPlot.c	       \
Index: /trunk/psphot/src/psphotCleanup.c
===================================================================
--- /trunk/psphot/src/psphotCleanup.c	(revision 37940)
+++ /trunk/psphot/src/psphotCleanup.c	(revision 37941)
@@ -10,4 +10,10 @@
 	(void)pmConfigRecipesCull(config,NULL);
         pmConfigDump(config, dump_file);
+    }
+
+    // if the program has stats write it out
+    psphotStatsFile *statsFile = psphotStatsFileGet();
+    if (statsFile) {
+        psphotStatsFileSave(config, statsFile);
     }
 
Index: /trunk/psphot/src/psphotFullForce.c
===================================================================
--- /trunk/psphot/src/psphotFullForce.c	(revision 37940)
+++ /trunk/psphot/src/psphotFullForce.c	(revision 37941)
@@ -10,4 +10,9 @@
     pmConfig *config = psphotFullForceArguments (argc, argv);
     assert(config);
+
+    if (!psphotStatsFileOpen(config)) {
+        psErrorStackPrint(stderr, "Error creating statsFile\n");
+        exit (psphotGetExitStatus());
+    }
 
     psphotVersionPrint();
@@ -25,5 +30,5 @@
     }
 
-    psLogMsg ("psphot", 3, "complete psphot run: %f sec\n", psTimerMark ("complete"));
+    psLogMsg ("psphot", 3, "complete psphotFullForce run: %f sec\n", psTimerMark ("complete"));
 
     psErrorCode exit_status = psphotGetExitStatus();
Index: /trunk/psphot/src/psphotFullForceArguments.c
===================================================================
--- /trunk/psphot/src/psphotFullForceArguments.c	(revision 37940)
+++ /trunk/psphot/src/psphotFullForceArguments.c	(revision 37941)
@@ -65,4 +65,11 @@
         psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTIONS", PS_DATA_STRING, "", argv[N]);
         psArgumentRemove (N, &argc, argv);
+    }
+
+    if ((N = psArgumentGet(argc, argv, "-stats"))) {
+        psArgumentRemove(N, &argc, argv);
+        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "STATS", PS_DATA_STRING,
+                         "Filename for statistics of output file", argv[N]);
+        psArgumentRemove(N, &argc, argv);
     }
 
Index: /trunk/psphot/src/psphotInternal.h
===================================================================
--- /trunk/psphot/src/psphotInternal.h	(revision 37940)
+++ /trunk/psphot/src/psphotInternal.h	(revision 37941)
@@ -14,4 +14,5 @@
 #include <psmodules.h>
 #include "psphot.h"
+#include "psphotStatsFile.h"
 
 #endif
Index: /trunk/psphot/src/psphotReadoutCleanup.c
===================================================================
--- /trunk/psphot/src/psphotReadoutCleanup.c	(revision 37940)
+++ /trunk/psphot/src/psphotReadoutCleanup.c	(revision 37941)
@@ -54,4 +54,10 @@
     psArray      *sources    = detections ? detections->allSources : NULL;
     // XXX where do we free these, in here (psMetadataRemove?)
+
+    int quality = psMetadataLookupS32 (&status, readout->analysis, "PSPHOT_QUALITY");
+    if (quality) {
+        // if there is no stats file this will be a no-op
+        psphotStatsFileSetQuality(quality);
+    }
 
     // use the psf-model to measure FWHM stats
Index: /trunk/psphot/src/psphotStandAlone.h
===================================================================
--- /trunk/psphot/src/psphotStandAlone.h	(revision 37940)
+++ /trunk/psphot/src/psphotStandAlone.h	(revision 37941)
@@ -10,4 +10,5 @@
 #include <psmodules.h>
 #include "psphot.h"
+#include "psphotStatsFile.h"
 
 // Top level functions
