Index: /trunk/ppMerge/src/ppMergeCombine.c
===================================================================
--- /trunk/ppMerge/src/ppMergeCombine.c	(revision 9831)
+++ /trunk/ppMerge/src/ppMergeCombine.c	(revision 9832)
@@ -214,10 +214,13 @@
                             }
                             numRead++;
+                        } else {
+                            psTrace("ppMerge", 3, "Unable to read from file %d for chip %d, "
+                                    "cell %d, scan %d\n", i, view->chip, view->cell, numScan);
                         }
                     }
 
+                    psTrace("ppMerge", 5, "Chip %d, cell %d, scan %d\n", view->chip, view->cell, numScan);
                     if (numRead > 0) {
                         pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine);
-                        psTrace("ppMerge", 5, "Chip %d, cell %d, scan %d\n", view->chip, view->cell, numScan);
                     }
                     numScan++;
@@ -259,5 +262,4 @@
             }
 
-            psFree(readout);            // Drop reference
             psFree(stack);
 
@@ -270,4 +272,37 @@
             }
 
+            // Measure the fringes for this cell
+            //
+            // XXX Need to deal with multiple components: we will do this by building up the components
+            // Read the existing fringe measurements
+            // Use existing regions to measure fringe statistics
+            // Add the new fringe measurements to the existing fringe measurements.
+            // Write the appended fringe measurements.
+            // Read in the "output" file to get the existing components.
+            // Put the new readout into the cell after the existing readouts.
+            if (options->fringe && readout->image) {
+                pmFringeRegions *regions = pmFringeRegionsAlloc(options->fringeNum, options->fringeSize,
+                                                                options->fringeSize, options->fringeSmoothX,
+                                                                options->fringeSmoothY); // Fringe regions
+                pmFringeStats *fringe = pmFringeStatsMeasure(regions, readout, options->combine->maskVal);
+                psFree(regions);
+
+                psArray *fringes = psArrayAlloc(1); // Array of fringes
+                fringes->data[0] = fringe;
+
+                const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); // Name of chip
+                const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); // Name of cell
+                psString extname = NULL;
+                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);
+                }
+
+                psFree(fringes);
+                psFree(extname);
+            }
+
+            psFree(readout);            // Drop reference
 
             // Statistics on the merged cell
Index: /trunk/ppMerge/src/ppMergeOptions.c
===================================================================
--- /trunk/ppMerge/src/ppMergeOptions.c	(revision 9831)
+++ /trunk/ppMerge/src/ppMergeOptions.c	(revision 9832)
@@ -35,8 +35,13 @@
     options->scale = false;
     options->darktime = false;
+    options->fringe = false;
     options->shutter = false;
     options->sample = 1;
     options->mean = PS_STAT_SAMPLE_MEDIAN;
     options->stdev = PS_STAT_SAMPLE_STDEV;
+    options->fringeNum = 100;
+    options->fringeSize = 10;
+    options->fringeSmoothX = 5;
+    options->fringeSmoothY = 5;
     options->shutterSize = 10;
     options->shutterIter = 2;
@@ -122,16 +127,20 @@
 
     // First, deal with the recipe.  These are parameters that will typically be constant for a camera.
-    OPTION_PARSE(options->rows,              recipe, "ROWS",      U16 );
-    OPTION_PARSE(options->minElectrons,      recipe, "ELECTRONS", F32 );
-    OPTION_PARSE(options->sample,            recipe, "SAMPLE",    S32 );
-    OPTION_PARSE(options->combine->rej,      recipe, "REJ",       F32 );
-    OPTION_PARSE(options->combine->iter,     recipe, "ITER",      S32 );
-    OPTION_PARSE(options->combine->fracHigh, recipe, "FRACHIGH",  F32 );
-    OPTION_PARSE(options->combine->fracLow,  recipe, "FRACLOW",   F32 );
-    OPTION_PARSE(options->combine->nKeep,    recipe, "NKEEP",     S32 );
-    OPTION_PARSE(options->combine->maskVal,  recipe, "MASKVAL",   S32 );
-    OPTION_PARSE(options->shutterSize,       recipe, "SHUTTER.SIZE", S32 );
-    OPTION_PARSE(options->shutterIter,       recipe, "SHUTTER.ITER", S32 );
-    OPTION_PARSE(options->shutterRej,        recipe, "SHUTTER.REJECT", F32 );
+    OPTION_PARSE(options->rows,              recipe, "ROWS",           U16);
+    OPTION_PARSE(options->minElectrons,      recipe, "ELECTRONS",      F32);
+    OPTION_PARSE(options->sample,            recipe, "SAMPLE",         S32);
+    OPTION_PARSE(options->combine->rej,      recipe, "REJ",            F32);
+    OPTION_PARSE(options->combine->iter,     recipe, "ITER",           S32);
+    OPTION_PARSE(options->combine->fracHigh, recipe, "FRACHIGH",       F32);
+    OPTION_PARSE(options->combine->fracLow,  recipe, "FRACLOW",        F32);
+    OPTION_PARSE(options->combine->nKeep,    recipe, "NKEEP",          S32);
+    OPTION_PARSE(options->combine->maskVal,  recipe, "MASKVAL",        S32);
+    OPTION_PARSE(options->fringeNum,         recipe, "FRINGE.NUM",     S32);
+    OPTION_PARSE(options->fringeSize,        recipe, "FRINGE.SIZE",    S32);
+    OPTION_PARSE(options->fringeSmoothX,     recipe, "FRINGE.XSMOOTH", S32);
+    OPTION_PARSE(options->fringeSmoothY,     recipe, "FRINGE.YSMOOTH", S32);
+    OPTION_PARSE(options->shutterSize,       recipe, "SHUTTER.SIZE",   S32);
+    OPTION_PARSE(options->shutterIter,       recipe, "SHUTTER.ITER",   S32);
+    OPTION_PARSE(options->shutterRej,        recipe, "SHUTTER.REJECT", F32);
 
     options->combine->combine = parseStat(recipe, "COMBINE");
@@ -148,4 +157,5 @@
             options->scale = false;
             options->darktime = false;
+            options->fringe = false;
             options->shutter = false;
         } else if (strcasecmp(type, "DARK") == 0) {
@@ -153,4 +163,5 @@
             options->scale = false;
             options->darktime = true;
+            options->fringe = false;
             options->shutter = false;
         } else if (strcasecmp(type, "FLAT") == 0) {
@@ -158,4 +169,5 @@
             options->scale = true;
             options->darktime = false;
+            options->fringe = false;
             options->shutter = false;
         } else if (strcasecmp(type, "FRINGE") == 0) {
@@ -163,4 +175,5 @@
             options->scale = true;
             options->darktime = false;
+            options->fringe = true;
             options->shutter = false;
         } else if (strcasecmp(type, "SHUTTER") == 0) {
@@ -168,4 +181,5 @@
             options->scale = false;
             options->darktime = false;
+            options->fringe = false;
             options->shutter = true;
         } else {
@@ -174,4 +188,5 @@
             options->scale = false;
             options->darktime = false;
+            options->fringe = false;
             options->shutter = false;
         }
@@ -181,4 +196,6 @@
         options->scale = false;
         options->darktime = false;
+        options->fringe = false;
+        options->shutter = false;
     }
 
Index: /trunk/ppMerge/src/ppMergeOptions.h
===================================================================
--- /trunk/ppMerge/src/ppMergeOptions.h	(revision 9831)
+++ /trunk/ppMerge/src/ppMergeOptions.h	(revision 9832)
@@ -22,8 +22,13 @@
     bool scale;                         // Scale by the background before combining?
     bool darktime;                      // Normalise by the dark time (time since flush)?
+    bool fringe;                        // Make fringe measurements?
     bool shutter;                       // Generate shutter correction?
     unsigned int sample;                // Sampling factor for measuring the background
     psStatsOptions mean;                // Statistic to use to measure the mean
     psStatsOptions stdev;               // Statistic to use to measure the stdev
+    int fringeNum;                      // Number of fringe regions per cell
+    int fringeSize;                     // Size of fringe regions
+    int fringeSmoothX;                  // Number of smoothing regions per cell, in x
+    int fringeSmoothY;                  // Number of smoothing regions per cell, in y
     int shutterSize;                    // Size for shutter measurement regions
     int shutterIter;                    // Number of iterations for shutter measurement
