Index: trunk/ppImage/src/ppImageMetadataStats.c
===================================================================
--- trunk/ppImage/src/ppImageMetadataStats.c	(revision 18556)
+++ trunk/ppImage/src/ppImageMetadataStats.c	(revision 19928)
@@ -6,10 +6,10 @@
 
 // calculate stats from headers and concepts
-bool ppImageMetadataStats (pmConfig *config, const ppImageOptions *options) {
+bool ppImageMetadataStats(pmConfig *config, psMetadata *stats, const ppImageOptions *options)
+{
+    bool mdok;              // Status of MD lookup
 
-    bool mdok;              // Status of MD lookup
-    
     if (!options->doStats) {
-	return true;
+        return true;
     }
 
@@ -20,6 +20,7 @@
 
     if (!outImage && !outPhotom && !outAstrom) {
-	psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find any output file (PPIMAGE.OUTPUT, PSPHOT.OUTPUT, PSASTRO.OUTPUT).");
-	return false;
+        psError(PS_ERR_UNEXPECTED_NULL, true,
+                "Unable to find any output file (PPIMAGE.OUTPUT, PSPHOT.OUTPUT, PSASTRO.OUTPUT).");
+        return false;
     }
 
@@ -27,34 +28,19 @@
     pmFPAfile *output = outAstrom;
     if (!output) {
-	output = outPhotom;
+        output = outPhotom;
     }
     if (!output) {
-	output = outImage;
+        output = outImage;
     }
 
-    // select or create the fpa-level analysis stats metadata for PPIMAGE.OUTPUT:
-    psMetadata *stats = psMetadataLookupPtr (&mdok, outImage->fpa->analysis, "PPIMAGE.STATS");
-    psMemIncrRefCounter (stats);
-    if (!stats) {
-	stats = psMetadataAlloc ();
-	if (!psMetadataAdd (outImage->fpa->analysis, PS_LIST_TAIL, "PPIMAGE.STATS", PS_DATA_METADATA, "stats container", stats)) {
-	    psError(PS_ERR_UNKNOWN, false, "Unable to push stats on fpa.analysis.");
-	    psFree (stats);
-	    return false;
-	}
-    }
-
-    // extract stats for the complete fpa 
+    // extract stats for the complete fpa
     pmFPAview *view = pmFPAviewAlloc(0);
-
     if (!ppStatsMetadata(stats, output->fpa, view, options->maskValue, config)) {
-	psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate stats for image.");
-	psFree(view);
-	psFree(stats);
-	return false;
+        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate stats for image.");
+        psFree(view);
+        return false;
     }
 
     psFree(view);
-    psFree(stats);
     return true;
 }
