Index: /trunk/psphot/src/psphotReadoutCleanup.c
===================================================================
--- /trunk/psphot/src/psphotReadoutCleanup.c	(revision 11184)
+++ /trunk/psphot/src/psphotReadoutCleanup.c	(revision 11184)
@@ -0,0 +1,38 @@
+# include "psphot.h"
+
+bool psphotReadoutCleanup (pmConfig *config, pmReadout *readout, psMetadata *recipe, pmPSF *psf, psArray *sources) {
+
+    // use the psf-model to measure FWHM stats
+    if (psf) {
+        if (!psphotPSFstats (readout, recipe, psf)) {
+            psError(PS_ERR_IO, true, "Failed to measure PSF shape parameters");
+            return false;
+        }
+    } else if (sources) {
+        if (!psphotMomentsStats (readout, recipe, sources)) {
+            psError(PS_ERR_IO, true, "Failed to measure Moment shape parameters");
+            return false;
+        }
+    }
+
+    // create an output header with stats results
+    psMetadata *header = psphotDefineHeader (recipe);
+
+    // save the results of the analysis
+    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY,    "psphot sources", sources);
+    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.HEADER",  PS_DATA_METADATA, "header stats", header);
+    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF",     PS_DATA_UNKNOWN,  "psphot psf", psf);
+
+    // remove internal pmFPAfiles, if created
+    pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL");
+    pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND");
+
+    // XXX move this to top of loop
+    pmKapaClose ();
+
+    psFree (psf);
+    psFree (header);
+    psFree (sources);
+
+    return true;
+}
