Index: trunk/pswarp/src/pswarpDefine.c
===================================================================
--- trunk/pswarp/src/pswarpDefine.c	(revision 13109)
+++ trunk/pswarp/src/pswarpDefine.c	(revision 13705)
@@ -14,5 +14,15 @@
     pmFPAfile *skycell = psMetadataLookupPtr (NULL, config->files, "PSWARP.SKYCELL");
     if (!skycell) {
-        psError(PSWARP_ERR_CONFIG, true, "Can't find skycell data!\n");
+        psError(PSWARP_ERR_CONFIG, false, "Can't find skycell data!\n");
+        return false;
+    }
+    pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PSWARP.OUTPUT");
+    if (!output) {
+        psError(PSWARP_ERR_CONFIG, false, "Can't find output data!\n");
+        return false;
+    }
+    pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PSWARP.INPUT");
+    if (!input) {
+        psError(PSWARP_ERR_CONFIG, false, "Can't find input data!\n");
         return false;
     }
@@ -24,5 +34,9 @@
     // Read header and create target
     {
-        pmFPAReadHeaderSet(skycell->fpa, skycell->fits, config->database);
+        if (!pmFPAReadHeaderSet(skycell->fpa, skycell->fits, config->database)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to read headers for skycell.");
+            psFree(view);
+            return false;
+        }
         view->chip = 0;
         view->cell = 0;
@@ -32,4 +46,5 @@
         if (!hdu || !hdu->header) {
             psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find header for sky cell.");
+            psFree(view);
             return false;
         }
@@ -37,5 +52,5 @@
         int numRows = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); // Number of rows
 
-        pmCell *target = pmFPAfileThisCell(config->files, view, "PSWARP.OUTPUT"); // Target cell
+        pmCell *target = pmFPAviewThisCell(view, output->fpa); // Target cell
         pmReadout *readout = pmReadoutAlloc(target); // Target readout
         readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
@@ -54,21 +69,25 @@
     // XXX this is not a sufficient test
     view->chip = 0;
-    pmChip *chip = pmFPAviewThisChip (view, skycell->fpa);
-    pmHDU *phu = pmFPAviewThisPHU (view, skycell->fpa);
-    pmHDU *hdu = pmFPAviewThisHDU (view, skycell->fpa);
+    view->cell = 0;
+    view->readout = -1;
+    pmHDU *phu = pmFPAviewThisPHU(view, skycell->fpa); // Skycell PHU
+    pmHDU *hdu = pmFPAviewThisHDU(view, skycell->fpa); // Skycell header
     bool bilevelAstrometry = false;
     if (phu) {
-        char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1");
+        char *ctype = psMetadataLookupStr(NULL, phu->header, "CTYPE1");
         if (ctype) {
-            bilevelAstrometry = !strcmp (&ctype[4], "-DIS");
+            bilevelAstrometry = !strcmp(&ctype[4], "-DIS");
         }
     }
+
+    // We read from the skycell into the output.  i.e., the output receives the desired astrometry.
+    pmChip *outputChip = pmFPAviewThisChip(view, output->fpa); // Chip in the output
     if (bilevelAstrometry) {
-        if (!pmAstromReadBilevelMosaic (skycell->fpa, phu->header)) {
+        if (!pmAstromReadBilevelMosaic(output->fpa, phu->header)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for skycell.");
             psFree(view);
             return false;
         }
-        if (!pmAstromReadBilevelChip (chip, hdu->header)) {
+        if (!pmAstromReadBilevelChip(outputChip, hdu->header)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel chip astrometry for skycell.");
             psFree(view);
@@ -77,5 +96,5 @@
     } else {
         // we use a default FPA pixel scale of 1.0
-        if (!pmAstromReadWCS (skycell->fpa, chip, hdu->header, 1.0)) {
+        if (!pmAstromReadWCS(output->fpa, outputChip, hdu->header, 1.0)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry for skycell.");
             psFree(view);
@@ -84,10 +103,7 @@
     }
 
-    // construct the output fpa here
-    pmFPAfile *output = psMetadataLookupPtr (NULL, config->files, "PSWARP.OUTPUT");
-    if (!output) {
-        psError(PSWARP_ERR_CONFIG, true, "Can't find output data!\n");
-        return false;
-    }
+    const char *name = psMetadataLookupStr(NULL, input->fpa->concepts, "FPA.NAME"); // Name of FPA
+    view->chip = view->cell = view->readout = -1;
+    pmFPAAddSourceFromView(output->fpa, name, view, output->format);
 
     psFree (view);
