Index: /branches/rel10_ifa/psModules/src/astrom/pmFPACopy.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPACopy.c	(revision 6837)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPACopy.c	(revision 6838)
@@ -366,4 +366,41 @@
 }
 
+
+static pmHDU *findPHU(const pmCell *cell// The cell for which to find the PHU
+                     )
+{
+    if (cell->hdu && cell->hdu->phu) {
+        return cell->hdu;
+    }
+    pmChip *chip = cell->parent;        // The parent chip
+    if (chip->hdu && chip->hdu->phu) {
+        return chip->hdu;
+    }
+    pmFPA *fpa = chip->parent;  // The parent FPA
+    if (fpa->hdu && fpa->hdu->phu) {
+        return fpa->hdu;
+    }
+
+    psError(PS_ERR_IO, true, "Unable to find PHU for target cell.\n");
+    return NULL;
+}
+
+
+static bool copyPHU(pmCell *targetCell, // The target cell
+                    pmCell *sourceCell  // The source cell
+                   )
+{
+    // Find the respective PHUs
+    pmHDU *targetPHU = findPHU(targetCell); // The target PHU
+    if (targetPHU->header) {
+        return false;                   // No work required
+    }
+    // Copy the header over
+    pmHDU *sourcePHU = findPHU(sourceCell); // The source PHU
+    targetPHU->header = psMetadataCopy(NULL, sourcePHU->header);
+    return true;
+}
+
+
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // File-static engine functions --- these do all the work.  Actually, cellCopy does all the work; the others
@@ -371,8 +408,8 @@
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-static int cellCopy(pmCell *target,          // The target cell
-                    pmCell *source,           // The source cell, to be copied
-                    bool pixels,             // Copy the pixels?
-                    int xBin, int yBin       // (Relative) binning factors in x and y
+static int cellCopy(pmCell *target,     // The target cell
+                    pmCell *source,     // The source cell, to be copied
+                    bool pixels,        // Copy the pixels?
+                    int xBin, int yBin  // (Relative) binning factors in x and y
                    )
 {
@@ -396,4 +433,6 @@
         hdu->header = psMetadataAlloc();
     }
+    // Copy the PHU over as well, if required
+    copyPHU(target, source);
 
     // Need to check/change CELL.XPARITY and CELL.YPARITY
@@ -485,8 +524,10 @@
         int xZero = psMetadataLookupS32(NULL, source->concepts, "CELL.X0"); // CELL.X0 from source
         int xParity = psMetadataLookupS32(NULL, target->concepts, "CELL.XPARITY"); // Parity in x
-        pmReadout *readout = target->readouts->data[0]; // A representative readout
+        int xBin = psMetadataLookupS32(NULL, source->concepts, "CELL.XBIN"); // CELL.XBIN from source
+        pmReadout *readout = source->readouts->data[0]; // A representative readout
         psTrace(__func__, 3, "CELL.X0: Before: %d After: %d\n", xZero,
-                xZero - (readout->image->numCols - 1) * xParity);
-        xZero -= (readout->image->numCols - 1) * xParity; // Change the parity on the X0 position
+                xZero - (readout->image->numCols - 1) * xParity * xBin);
+        psTrace(__func__, 9, "(xParity: %d xBin: %d numCols: %d)\n", xParity, xBin, readout->image->numCols);
+        xZero -= (readout->image->numCols - 1) * xParity * xBin; // Change the parity on the X0 position
         psMetadataItem *newItem = psMetadataLookup(target->concepts, "CELL.X0"); // CELL.X0 from target
         newItem->data.S32 = xZero;
@@ -495,8 +536,10 @@
         int yZero = psMetadataLookupS32(NULL, source->concepts, "CELL.Y0"); // CELL.Y0 from source
         int yParity = psMetadataLookupS32(NULL, target->concepts, "CELL.YPARITY"); // Parity in y
-        pmReadout *readout = target->readouts->data[0]; // A representative readout
+        int yBin = psMetadataLookupS32(NULL, source->concepts, "CELL.YBIN"); // Parity in y
+        pmReadout *readout = source->readouts->data[0]; // A representative readout
         psTrace(__func__, 3, "CELL.Y0: Before: %d After: %d\n", yZero,
-                yZero - (readout->image->numCols - 1) * yParity);
-        yZero -= (readout->image->numCols - 1) * yParity; // Change the parity on the Y0 position
+                yZero - (readout->image->numRows - 1) * yParity * yBin);
+        psTrace(__func__, 9, "(yParity: %d yBin: %d numRows: %d)\n", yParity, yBin, readout->image->numRows);
+        yZero -= (readout->image->numRows - 1) * yParity * yBin; // Change the parity on the Y0 position
         psMetadataItem *newItem = psMetadataLookup(target->concepts, "CELL.Y0"); // CELL.Y0 from target
         newItem->data.S32 = yZero;
