Index: /trunk/ppMerge/src/ppMergeCombine.c
===================================================================
--- /trunk/ppMerge/src/ppMergeCombine.c	(revision 9906)
+++ /trunk/ppMerge/src/ppMergeCombine.c	(revision 9907)
@@ -78,4 +78,31 @@
 #endif
 
+// Write fringe extensions
+static void writeFringes(psMetadata *fringes, // Table of extensions with fringe statistics to write
+                         psFits *fits   // FITS file to which to write
+                         )
+{
+    assert(fringes);
+
+    // Write the fringe extensions
+    psMetadataIterator *fringesIter = psMetadataIteratorAlloc(fringes, PS_LIST_HEAD, false); // Iterator
+    psMetadataItem *fringeItem;         // Item from iteration
+    while ((fringeItem = psMetadataGetAndIncrement(fringesIter))) {
+        const char *extname = fringeItem->name; // Extension name
+        psArray *fringe = fringeItem->data.V; // Fringe data (array of fringe components)
+        if (!pmFringesWriteFits(fits, NULL, fringe, extname)) {
+            psWarning("Unable to write fringe data to extension %s\n", extname);
+        }
+    }
+
+    // Clear the list
+    while (psListLength(fringes->list) > 0) {
+        psMetadataRemoveIndex(fringes, PS_LIST_TAIL);
+    }
+
+    return;
+}
+
+
 // Combine the inputs
 bool ppMergeCombine(psImage *scales,    // Scales for each cell of each integration, or NULL
@@ -101,4 +128,5 @@
     // Iterate over the FPA
     pmFPA *fpa = data->out;             // Output FPA
+    psMetadata *fringeExtns = psMetadataAlloc(); // List of fringe extensions to write
     pmFPAview *view = pmFPAviewAlloc(0);// View of FPA, for iteration
     int cellNum = -1;                   // Cell number in the whole FPA
@@ -296,8 +324,6 @@
                 psStringAppend(&extname, "FRINGE_%s_%s", chipName, cellName);
 
-                if (!pmFringesWriteFits(data->outFile, NULL, fringes, extname)) {
-                    psWarning("Unable to write fringe data to extension %s\n", extname);
-                }
-
+                psMetadataAdd(fringeExtns, PS_LIST_TAIL, extname, PS_DATA_UNKNOWN,
+                              "Fringe data to write", fringes);
                 psFree(fringes);
                 psFree(extname);
@@ -329,4 +355,8 @@
                 pmCellWrite(cell, data->outFile, config->database, false);
                 pmCellFreeData(cell);
+
+                if (options->fringe) {
+                    writeFringes(fringeExtns, data->outFile);
+                }
             }
         }
@@ -344,4 +374,8 @@
             pmChipWrite(chip, data->outFile, config->database, false, false);
             pmChipFreeData(chip);
+
+            if (options->fringe) {
+                writeFringes(fringeExtns, data->outFile);
+            }
         }
     }
@@ -357,4 +391,8 @@
         pmFPA *fpaIn = data->in->data[i]; // Input FPA
         pmFPAFreeData(fpaIn);
+
+        if (options->fringe) {
+            writeFringes(fringeExtns, data->outFile);
+        }
     }
     pmFPAFreeData(data->out);
Index: /trunk/ppMerge/src/ppMergeScaleZero.c
===================================================================
--- /trunk/ppMerge/src/ppMergeScaleZero.c	(revision 9906)
+++ /trunk/ppMerge/src/ppMergeScaleZero.c	(revision 9907)
@@ -11,27 +11,4 @@
 #include "ppMerge.h"
 #include "ppMergeScaleZero.h"
-
-// Extract a particular statistic from the stats
-static inline double getStat(const psStats *stats, // Statistics structure
-                             psStatsOptions option // Statistic option to return
-    )
-{
-    switch (option) {
-      case PS_STAT_SAMPLE_MEAN:
-        return stats->sampleMean;
-      case PS_STAT_SAMPLE_MEDIAN:
-        return stats->sampleMedian;
-      case PS_STAT_ROBUST_MEDIAN:
-        return stats->robustMedian;
-      case PS_STAT_FITTED_MEAN:
-        return stats->fittedMean;
-      case PS_STAT_CLIPPED_MEAN:
-        return stats->clippedMean;
-      default:
-        psAbort(__func__, "Invalid statistics option: %x\n", option);
-    }
-    return NAN;                         // Token return
-}
-
 
 // Get the scale and zero for each chip of each input
@@ -262,5 +239,5 @@
                     psFree(sample);
                     psFree(sampleMask);
-                    background->data.F32[i][cellNum] = getStat(bgStats, options->mean);
+                    background->data.F32[i][cellNum] = psStatsGetValue(bgStats, options->mean);
                     psTrace("ppMerge", 3, "Background for %s, cell %d is %f\n", name, cellNum,
                             background->data.F32[i][cellNum]);
