Index: trunk/pswarp/src/pswarpLoop.c
===================================================================
--- trunk/pswarp/src/pswarpLoop.c	(revision 13705)
+++ trunk/pswarp/src/pswarpLoop.c	(revision 13904)
@@ -50,7 +50,39 @@
     }
 
-    // de-activate PSWARP.SKYCELL and PSWARP.OUTPUT
+    // Read the input astrometry
+    {
+        pmFPAfileActivate(config->files, false, "PSWARP.INPUT");
+        pmFPAfileActivate(config->files, false, "PSWARP.MASK");
+        pmFPAfileActivate(config->files, false, "PSWARP.WEIGHT");
+        pmFPAfileActivate(config->files, true, "PSWARP.ASTROM");
+        pmFPAfileActivate(config->files, false, "PSWARP.OUTPUT");
+        pmFPAfileActivate(config->files, false, "PSWARP.OUTPUT.MASK");
+        pmFPAfileActivate(config->files, false, "PSWARP.OUTPUT.WEIGHT");
+        pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+        pmChip *chip;
+        pmFPAview *view = pmFPAviewAlloc(0);
+        while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
+            psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+            if (!chip->process || !chip->file_exists) { continue; }
+            pmFPAfileIOChecks(config, view, PM_FPA_BEFORE);
+            pmCell *cell;
+            while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
+                psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+                if (!cell->process || !cell->file_exists) { continue; }
+                pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+            }
+        }
+        psFree(view);
+
+        pmFPAfileActivate(config->files, true, "PSWARP.INPUT");
+        pmFPAfileActivate(config->files, true, "PSWARP.MASK");
+        pmFPAfileActivate(config->files, true, "PSWARP.WEIGHT");
+        pmFPAfileActivate(config->files, false, "PSWARP.ASTROM");
+        pmFPAfileActivate(config->files, true, "PSWARP.OUTPUT");
+        pmFPAfileActivate(config->files, true, "PSWARP.OUTPUT.MASK");
+        pmFPAfileActivate(config->files, true, "PSWARP.OUTPUT.WEIGHT");
+    }
+
     pmFPAfileActivate(config->files, false, "PSWARP.SKYCELL");
-
     view = pmFPAviewAlloc(0);
 
@@ -72,4 +104,6 @@
         }
     }
+
+    psList *cells = psListAlloc(NULL);  // List of cells, for concepts averaging
 
     // files associated with the science image
@@ -107,4 +141,6 @@
             pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
 
+            psListAdd(cells, PS_LIST_TAIL, cell);
+
             // process each of the readouts
             pmReadout *readout;
@@ -128,6 +164,13 @@
     pmFPA *outFPA = outChip->parent;    // Output FPA
 
-    if (!pmFPACopyConcepts(output->parent->parent->parent, input->fpa)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from input to output.");
+    if (!pmConceptsAverageCells(outCell, cells, NULL, NULL, false)) {
+        psError(PS_ERR_UNKNOWN, false, "Unable to average cell concepts.");
+        psFree(stats);
+        psFree(view);
+        return false;
+    }
+
+    if (!psMetadataCopy(outFPA->concepts, input->fpa->concepts)) {
+        psError(PS_ERR_UNKNOWN, false, "Unable to copy FPA concepts from input to output.");
         psFree(stats);
         psFree(view);
@@ -139,5 +182,10 @@
     outChip->data_exists = true;
 
-
+#if 0
+    float gain = 0.0, readnoise = 0.0, saturation = INFINITY, exposure = 0.0, darktime = 0.0;
+    double mjd = 0.0;
+#endif
+
+#if 0
     // XXX Hack so that INSTRUME header keyword and the like are not updated properly
     // If INSTRUME (etc) is updated, then the FITS file with the warped image will be often
@@ -158,10 +206,12 @@
         item->data.V = NULL;
     }
-
+#endif
 
 
     // Perform statistics on the output image
     if (stats) {
-        ppStats(stats, output->parent->parent->parent, view, maskBad | maskPoor, config);
+        if (!ppStats(stats, output->parent->parent->parent, view, maskBad | maskPoor, config)) {
+            psWarning("Unable to perform statistics on warped image.");
+        }
     }
 
@@ -190,5 +240,5 @@
     if (stats) {
         const char *statsMDC = psMetadataConfigFormat(stats);
-        if (!statsMDC || strlen(statsMDC) == 0) {
+        if (!statsMDC) {
             psError(PS_ERR_IO, false, "Unable to get statistics MDC file.\n");
             psFree(stats);
