Index: /trunk/pswarp/src/pswarpDefine.c
===================================================================
--- /trunk/pswarp/src/pswarpDefine.c	(revision 12825)
+++ /trunk/pswarp/src/pswarpDefine.c	(revision 12826)
@@ -7,6 +7,6 @@
     psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);
     if (!recipe) {
-	psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n");
-	return false;
+        psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n");
+        return false;
     }
 
@@ -14,15 +14,41 @@
     pmFPAfile *skycell = psMetadataLookupPtr (NULL, config->files, "PSWARP.SKYCELL");
     if (!skycell) {
-	psError(PSWARP_ERR_CONFIG, true, "Can't find skycell data!\n");
-	return false;
+        psError(PSWARP_ERR_CONFIG, true, "Can't find skycell data!\n");
+        return false;
     }
 
     // open the full skycell file; no need to defer different depths. only load the header data
-    // XXX force fileLevel and view to be chip. is this right?
-    // skycell->type = PM_FPA_FILE_HEADER;
-    // skycell->fileLevel = PM_FPA_LEVEL_CHIP;
     pmFPAview *view = pmFPAviewAlloc (0);
     pmFPAfileOpen (skycell, view, config);
-    pmFPAfileRead (skycell, view, config);
+
+    // Read header and create target
+    {
+        pmFPAReadHeaderSet(skycell->fpa, skycell->fits, config->database);
+        view->chip = 0;
+        view->cell = 0;
+        view->readout = 0;
+        pmCell *source = pmFPAfileThisCell(config->files, view, "PSWARP.SKYCELL"); // Source cell
+        pmHDU *hdu = pmHDUFromCell(source); // HDU for source
+        if (!hdu || !hdu->header) {
+            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find header for sky cell.");
+            return false;
+        }
+        int numCols = psMetadataLookupS32(NULL, hdu->header, "NAXIS1"); // Number of columns
+        int numRows = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); // Number of rows
+
+        pmCell *target = pmFPAfileThisCell(config->files, view, "PSWARP.OUTPUT"); // Target cell
+        pmReadout *readout = pmReadoutAlloc(target); // Target readout
+        readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
+        psFree(readout);                // Drop reference
+
+        psMetadataItemSupplement(target->concepts, source->concepts, "CELL.XBIN");
+        psMetadataItemSupplement(target->concepts, source->concepts, "CELL.YBIN");
+        psMetadataItemSupplement(target->concepts, source->concepts, "CELL.XSIZE");
+        psMetadataItemSupplement(target->concepts, source->concepts, "CELL.YSIZE");
+        psMetadataItemSupplement(target->concepts, source->concepts, "CELL.XPARITY");
+        psMetadataItemSupplement(target->concepts, source->concepts, "CELL.YPARITY");
+        psMetadataItemSupplement(target->concepts, source->concepts, "CELL.X0");
+        psMetadataItemSupplement(target->concepts, source->concepts, "CELL.Y0");
+    }
 
     // XXX this is not a sufficient test
@@ -33,15 +59,15 @@
     bool bilevelAstrometry = false;
     if (phu) {
-	char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1");
-	if (ctype) {
-	    bilevelAstrometry = !strcmp (&ctype[4], "-DIS");
-	}
+        char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1");
+        if (ctype) {
+            bilevelAstrometry = !strcmp (&ctype[4], "-DIS");
+        }
     }
     if (bilevelAstrometry) {
-	pmAstromReadBilevelMosaic (skycell->fpa, phu->header);
-	pmAstromReadBilevelChip (chip, hdu->header); 
+        pmAstromReadBilevelMosaic (skycell->fpa, phu->header);
+        pmAstromReadBilevelChip (chip, hdu->header);
     } else {
-	// we use a default FPA pixel scale of 1.0
-	pmAstromReadWCS (skycell->fpa, chip, hdu->header, 1.0);
+        // we use a default FPA pixel scale of 1.0
+        pmAstromReadWCS (skycell->fpa, chip, hdu->header, 1.0);
     }
 
@@ -49,40 +75,7 @@
     pmFPAfile *output = psMetadataLookupPtr (NULL, config->files, "PSWARP.OUTPUT");
     if (!output) {
-	psError(PSWARP_ERR_CONFIG, true, "Can't find output data!\n");
-	return false;
+        psError(PSWARP_ERR_CONFIG, true, "Can't find output data!\n");
+        return false;
     }
-    // output->fileLevel = PM_FPA_LEVEL_CHIP;
-
-    pmFPAfileCreate(output, view, config);
-
-# if 0
-    // XXX This function should only load the skycell headers and create the output based
-    // on that file.  I'm going to ask paul to look into this
-    pmFPACopyStructure (output->fpa, skycell->fpa, 1, 1);
-
-    // XXX can I just create the needed readout?
-    // create the needed readouts
-    for (int i = 0; i < output->fpa->chips->n; i++) {
-	pmChip *chip = output->fpa->chips->data[i];
-	for (int j = 0; j < chip->cells->n; j++) {
-	    pmCell *cell = chip->cells->data[j];
-	    pmReadout *readout;
-	    if (cell->readouts->n == 0) {
-		readout = pmReadoutAlloc (cell);
-	    }
-	    bool mdok1 = false;
-	    bool mdok2 = false;
-	    pmHDU *hdu = pmHDUGetLowest (output->fpa, chip, cell);
-	    int Nx = psMetadataLookupS32(&mdok1, hdu->header, "NAXIS1"); // Trim section
-	    int Ny = psMetadataLookupS32(&mdok2, hdu->header, "NAXIS2"); // Trim section
-	    if (!mdok1 || !mdok2) {
-		psError(PS_ERR_IO, true, "NAXIS1 or NAXIS2 not set --- unable to create output image.\n");
-		return false;
-	    }
-	    readout->image = psImageAlloc (Nx, Ny, PS_TYPE_F32);
-	    psFree (readout);
-	}
-    }
-# endif
 
     psFree (view);
