Index: /trunk/pswarp/src/pswarpDefine.c
===================================================================
--- /trunk/pswarp/src/pswarpDefine.c	(revision 13704)
+++ /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);
Index: /trunk/pswarp/src/pswarpLoop.c
===================================================================
--- /trunk/pswarp/src/pswarpLoop.c	(revision 13704)
+++ /trunk/pswarp/src/pswarpLoop.c	(revision 13705)
@@ -135,4 +135,8 @@
     }
 
+    output->data_exists = true;
+    outCell->data_exists = true;
+    outChip->data_exists = true;
+
 
     // XXX Hack so that INSTRUME header keyword and the like are not updated properly
@@ -163,4 +167,7 @@
 
     pmHDU *hdu = output->parent->parent->parent->hdu; // HDU for the output warped image
+    if (!hdu->header) {
+        hdu->header = psMetadataAlloc();
+    }
 
     // Add MD5 information for readout
Index: /trunk/pswarp/src/pswarpParseCamera.c
===================================================================
--- /trunk/pswarp/src/pswarpParseCamera.c	(revision 13704)
+++ /trunk/pswarp/src/pswarpParseCamera.c	(revision 13705)
@@ -9,5 +9,5 @@
     // the input image(s) are required arguments; they define the camera
     status = false;
-    pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PSWARP.INPUT", "INPUT");
+    pmFPAfile *input = pmFPAfileDefineFromArgs(&status, config, "PSWARP.INPUT", "INPUT");
     if (!input || !status) {
         psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.INPUT");
@@ -17,5 +17,5 @@
     // the input image(s) are required arguments; they define the camera
     status = false;
-    pmFPAfile *astrom = pmFPAfileDefineFromArgs (&status, config, "PSWARP.ASTROM", "ASTROM");
+    pmFPAfile *astrom = pmFPAfileBindFromArgs(&status, input, config, "PSWARP.ASTROM", "ASTROM");
     if (!status) {
         psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
@@ -49,28 +49,27 @@
     // the input skycell is a required argument: it defines the output image
     // XXX we may need a different skycell structure here
-    status = pswarpDefineSkycell (&skycell, &skyConfig, config, "PSWARP.SKYCELL", "SKYCELL");
+    status = pswarpDefineSkycell(&skycell, &skyConfig, config, "PSWARP.SKYCELL", "SKYCELL");
     if (!status) {
         psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.SKYCELL");
         return false;
     }
+    psFree(skyConfig);
 
-    // these calls bind the I/O handle to the specified fpa
-    // NOTE: output file could be binned relative to sky cell...
-    // if (!pmFPAfileDefineFromFPA (skyConfig, skycell->fpa, 1, 1, "PSWARP.OUTPUT")) {
-    if (!pmFPAfileDefineOutput (skyConfig, skycell->fpa, "PSWARP.OUTPUT")) {
+    // The output skycell
+    pmFPAfile *output = pmFPAfileDefineSkycell(config, NULL, "PSWARP.OUTPUT");
+    if (!output) {
         psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT");
         return false;
     }
-    if (!pmFPAfileDefineOutput (skyConfig, skycell->fpa, "PSWARP.OUTPUT.MASK")) {
+    if (!pmFPAfileDefineSkycell(config, output->fpa, "PSWARP.OUTPUT.MASK")) {
         psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT.MASK");
         return false;
     }
     if (inWeight) {
-        if (!pmFPAfileDefineOutput (skyConfig, skycell->fpa, "PSWARP.OUTPUT.WEIGHT")) {
+        if (!pmFPAfileDefineSkycell(config, output->fpa, "PSWARP.OUTPUT.WEIGHT")) {
             psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT.WEIGHT");
             return false;
         }
     }
-    psFree (skyConfig);
 
     // Chip selection: turn on only the chips specified
