Index: /trunk/ppMerge/src/ppMerge.c
===================================================================
--- /trunk/ppMerge/src/ppMerge.c	(revision 8719)
+++ /trunk/ppMerge/src/ppMerge.c	(revision 8720)
@@ -2,5 +2,4 @@
 #include <pslib.h>
 #include <psmodules.h>
-#include <ppStats.h>
 
 #include "ppMerge.h"
@@ -50,10 +49,9 @@
     ppMergeCombine(scale, zero, data, options, config);
 
+    // Output the statistics
     if (data->statsFile) {
-        psMetadata *stats = ppStats(NULL, data->out, NULL, config); // Statistics for output FPA
-        psString statsOut = psMetadataConfigFormat(stats); // String to write out
+        psString statsOut = psMetadataConfigFormat(data->stats); // String to write out
         fprintf(data->statsFile, "%s", statsOut);
         psFree(statsOut);
-        psFree(stats);
     }
 
Index: /trunk/ppMerge/src/ppMergeCombine.c
===================================================================
--- /trunk/ppMerge/src/ppMergeCombine.c	(revision 8719)
+++ /trunk/ppMerge/src/ppMergeCombine.c	(revision 8720)
@@ -4,4 +4,5 @@
 #include <pslib.h>
 #include <psmodules.h>
+#include <ppStats.h>
 
 #include "ppMerge.h"
@@ -94,19 +95,13 @@
 
     // Iterate over the FPA
-    int cellNum = -1;                   // Cell number
+    pmFPA *fpa = data->out;             // Output FPA
+    pmFPAview *view = pmFPAviewAlloc(0);// View of FPA, for iteration
+    int cellNum = -1;                   // Cell number in the whole FPA
     pmFPAWrite(data->out, data->outFile, config->database, true, false); // Write header only
-    psArray *chips = data->out->chips;  // Array of output chips
-    for (int i = 0; i < chips->n; i++) {
-        pmChip *chip = chips->data[i];  // Output chip of interest
-        if (!chip) {
-            continue;
-        }
+    pmChip *chip;                       // Chip of interest
+    while ((chip = pmFPAviewNextChip(view, fpa, 1))) {
         pmChipWrite(chip, data->outFile, config->database, true, false); // Write header only
-        psArray *cells = chip->cells;   // Array of output cells
-        for (int j = 0; j < cells->n; j++) {
-            pmCell *cell = cells->data[j]; // Output cell of interest
-            if (!cell) {
-                continue;
-            }
+        pmCell *cell;                   // Cell of interest
+        while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
             cellNum++;
             pmCellWrite(cell, data->outFile, config->database, true); // Write header only
@@ -130,27 +125,27 @@
             do {
                 numRead = 0;
-                for (int k = 0; k < filenames->n; k++) {
-                    if (! filenames->data[k] || strlen(filenames->data[k]) == 0) {
+                for (int i = 0; i < filenames->n; i++) {
+                    if (! filenames->data[i] || strlen(filenames->data[i]) == 0) {
                         continue;
                     }
-                    psFits *fits = data->files->data[k]; // FITS file handle
+                    psFits *fits = data->files->data[i]; // FITS file handle
                     if (!fits) {
                         psError(PS_ERR_IO, false, "Unable to open input file %s --- ignored.\n",
-                                (char *)filenames->data[k]);
+                                (char*)filenames->data[i]);
                         continue;
                     }
 
-                    if (!stack->data[k]) {
-                        pmFPA *fpaIn = data->in->data[k]; // Input FPA
-                        pmChip *chipIn = fpaIn->chips->data[i]; // Input chip
-                        pmCell *cellIn = chipIn->cells->data[j]; // Input cell
-                        stack->data[k] = pmReadoutAlloc(cellIn); // Input readout
+                    if (!stack->data[i]) {
+                        pmFPA *fpaIn = data->in->data[i]; // Input FPA
+                        pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip
+                        pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell
+                        stack->data[i] = pmReadoutAlloc(cellIn); // Input readout
                     }
 
                     // Only reading and writing the first readout in each cell (plane 0)
-                    if (pmReadoutReadNext(stack->data[k], fits, 0, options->rows)) {
+                    if (pmReadoutReadNext(stack->data[i], fits, 0, options->rows)) {
                         // For anything except BIAS and DARK, we want a mask
                         if (options->scale || options->zero) {
-                            pmReadoutSetMask(stack->data[k]);
+                            pmReadoutSetMask(stack->data[i]);
                         }
                         numRead++;
@@ -160,5 +155,5 @@
                 if (numRead > 0) {
                     pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine);
-                    psTrace(__func__, 5, "Chip %d, cell %d, scan %d\n", i, j, numScan);
+                    psTrace(__func__, 5, "Chip %d, cell %d, scan %d\n", view->chip, view->cell, numScan);
                 }
                 numScan++;
@@ -169,19 +164,19 @@
             // Read whole cells at a time
 
-            printf("Chip %d, cell %d\n", i, j);
+            printf("Chip %d, cell %d\n", view->chip, view->cell);
             int numRead = 0;  // Number of inputs read
-            for (int k = 0; k < filenames->n; k++) {
-                if (! filenames->data[k] || strlen(filenames->data[k]) == 0) {
-                    continue;
-                }
-                psFits *fits = data->files->data[k]; // FITS file handle
+            for (int i = 0; i < filenames->n; i++) {
+                if (! filenames->data[i] || strlen(filenames->data[i]) == 0) {
+                    continue;
+                }
+                psFits *fits = data->files->data[i]; // FITS file handle
                 if (!fits) {
                     psError(PS_ERR_IO, false, "Unable to open input file %s --- ignored.\n",
-                            filenames->data[k]);
-                    continue;
-                }
-                pmFPA *fpaIn = data->in->data[k]; // Input FPA
-                pmChip *chipIn = fpaIn->chips->data[i]; // Input chip
-                pmCell *cellIn = chipIn->cells->data[j]; // Input cell
+                            filenames->data[i]);
+                    continue;
+                }
+                pmFPA *fpaIn = data->in->data[i]; // Input FPA
+                pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip
+                pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell
                 if (!cellIn->file_exists || !cellIn->data_exists) {
                     continue;
@@ -190,10 +185,10 @@
                     continue;
                 }
-                stack->data[k] = cellIn->readouts->data[0];
+                stack->data[i] = cellIn->readouts->data[0];
                 numRead++;
             }
             if (numRead > 0) {
                 pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine);
-                psTrace(__func__, 5, "Chip %d, cell %d\n", i, j);
+                psTrace(__func__, 5, "Chip %d, cell %d\n", view->chip, view->cell);
             }
 
@@ -204,9 +199,14 @@
             psFree(stack);
 
+            // Statistics on the merged cell
+            if (data->statsFile) {
+                data->stats = ppStats(data->stats, data->out, view, config); // Statistics for output FPA
+            }
+
             // Blow away the cell data
-            for (int k = 0; k < filenames->n; k++) {
-                pmFPA *fpaIn = data->in->data[k]; // Input FPA
-                pmChip *chipIn = fpaIn->chips->data[i]; // Input chip
-                pmCell *cellIn = chipIn->cells->data[j]; // Input cell
+            for (int i = 0; i < filenames->n; i++) {
+                pmFPA *fpaIn = data->in->data[i]; // Input FPA
+                pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip
+                pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell
                 pmCellFreeData(cellIn);
             }
@@ -221,7 +221,7 @@
 
         // Blow away the chip data
-        for (int k = 0; k < filenames->n; k++) {
-            pmFPA *fpaIn = data->in->data[k]; // Input FPA
-            pmChip *chipIn = fpaIn->chips->data[i]; // Input chip
+        for (int i = 0; i < filenames->n; i++) {
+            pmFPA *fpaIn = data->in->data[i]; // Input FPA
+            pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip
             pmChipFreeData(chipIn);
         }
@@ -242,6 +242,6 @@
 
     // Blow away the FPA data
-    for (int k = 0; k < filenames->n; k++) {
-        pmFPA *fpaIn = data->in->data[k]; // Input FPA
+    for (int i = 0; i < filenames->n; i++) {
+        pmFPA *fpaIn = data->in->data[i]; // Input FPA
         pmFPAFreeData(fpaIn);
     }
Index: /trunk/ppMerge/src/ppMergeData.c
===================================================================
--- /trunk/ppMerge/src/ppMergeData.c	(revision 8719)
+++ /trunk/ppMerge/src/ppMergeData.c	(revision 8720)
@@ -26,4 +26,5 @@
         data->statsFile = NULL;
     }
+    psFree(data->stats);
 }
 
@@ -39,4 +40,5 @@
     data->out = NULL;
     data->outFile = NULL;
+    data->stats = NULL;
     data->statsFile = NULL;
 
Index: /trunk/ppMerge/src/ppMergeData.h
===================================================================
--- /trunk/ppMerge/src/ppMergeData.h	(revision 8719)
+++ /trunk/ppMerge/src/ppMergeData.h	(revision 8720)
@@ -12,4 +12,5 @@
     pmFPA *out;                         // Output FPA structure
     psFits *outFile;                    // FITS file handle for output
+    psMetadata *stats;                  // Statistics on the combined image
     FILE *statsFile;                    // File stream for statistics output
 } ppMergeData;
