Index: trunk/psModules/src/camera/pmFPACopy.c
===================================================================
--- trunk/psModules/src/camera/pmFPACopy.c	(revision 12696)
+++ trunk/psModules/src/camera/pmFPACopy.c	(revision 12791)
@@ -51,10 +51,10 @@
 
     if (*target) {
-	psFree(*target);
+        psFree(*target);
     }
     if (pixels) {
-	*target = psImageFlip(NULL, source, xFlip, yFlip);
-	return;
-    } 
+        *target = psImageFlip(NULL, source, xFlip, yFlip);
+        return;
+    }
 
     // I have the fine image size, I know the binning factor, determine the ruff image size
@@ -108,24 +108,34 @@
     int xParitySource = psMetadataLookupS32(&mdokS, source->concepts, "CELL.XPARITY"); // Source parity
     int xParityTarget = psMetadataLookupS32(&mdokT, target->concepts, "CELL.XPARITY"); // Target x parity
-    assert (mdokS && mdokT);
-    assert (abs(xParitySource) == 1);
-    assert (abs(xParityTarget) == 1);
+    assert(mdokS && mdokT);
+    if (abs(xParitySource) != 1 || abs(xParityTarget) != 1) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "CELL.XPARITY is not set for both source (%d) and target (%d)",
+                xParitySource, xParityTarget);
+        psFree(binning);
+        return false;
+    }
     if (xParityTarget != xParitySource) {
-	xFlip = true;
+        xFlip = true;
     } else {
-	// Use the source parity
-	COPY_CONCEPT(target->concepts, source->concepts, "CELL.XPARITY", S32);
+        // Use the source parity
+        COPY_CONCEPT(target->concepts, source->concepts, "CELL.XPARITY", S32);
     }
 
     int yParityTarget = psMetadataLookupS32(&mdokT, target->concepts, "CELL.YPARITY"); // Target y parity
     int yParitySource = psMetadataLookupS32(&mdokS, source->concepts, "CELL.YPARITY"); // Source parity
-    assert (mdokS && mdokT);
-    assert (abs(yParitySource) == 1);
-    assert (abs(yParityTarget) == 1);
+    assert(mdokS && mdokT);
+    if (abs(yParitySource) != 1 || abs(yParityTarget) != 1) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "CELL.YPARITY is not set for both source (%d) and target (%d)",
+                yParitySource, yParityTarget);
+        psFree(binning);
+        return false;
+    }
     if (yParityTarget != yParitySource) {
-	yFlip = true;
+        yFlip = true;
     } else {
-	// Use the source parity
-	COPY_CONCEPT(target->concepts, source->concepts, "CELL.YPARITY", S32);
+        // Use the source parity
+        COPY_CONCEPT(target->concepts, source->concepts, "CELL.YPARITY", S32);
     }
     psTrace("psModules.camera", 3, "xFlip: %d; yFlip: %d\n", xFlip, yFlip);
@@ -140,5 +150,5 @@
 
         // Copy attributes
-	// XXX is this correct under binning?
+        // XXX is this correct under binning?
         targetReadout->col0 = sourceReadout->col0;
         targetReadout->row0 = sourceReadout->row0;
@@ -148,7 +158,7 @@
 
         // Copy all three image components (image, mask, weight)
-	readoutCopyComponent (&targetReadout->image,  sourceReadout->image,  binning, xFlip, yFlip, pixels);
-	readoutCopyComponent (&targetReadout->mask,   sourceReadout->mask,   binning, xFlip, yFlip, pixels);
-	readoutCopyComponent (&targetReadout->weight, sourceReadout->weight, binning, xFlip, yFlip, pixels);
+        readoutCopyComponent (&targetReadout->image,  sourceReadout->image,  binning, xFlip, yFlip, pixels);
+        readoutCopyComponent (&targetReadout->mask,   sourceReadout->mask,   binning, xFlip, yFlip, pixels);
+        readoutCopyComponent (&targetReadout->weight, sourceReadout->weight, binning, xFlip, yFlip, pixels);
 
         // Copy bias
@@ -162,5 +172,5 @@
         while ((bias = psListGetAndIncrement(biasIter))) {
             psImage *biasCopy = NULL;          // Copy of the bias
-	    readoutCopyComponent (&biasCopy, bias, binning, xFlip, yFlip, pixels);
+            readoutCopyComponent (&biasCopy, bias, binning, xFlip, yFlip, pixels);
             psListAdd(targetReadout->bias, PS_LIST_TAIL, biasCopy);
             psFree(biasCopy);           // Drop reference
@@ -181,13 +191,13 @@
         psString name = conceptItem->name; // Name of concept
         if (!strcmp(name, "CELL.TRIMSEC")) continue;
-	if (!strcmp(name, "CELL.BIASSEC")) continue;
-	if (!strcmp(name, "CELL.XPARITY")) continue;
-	if (!strcmp(name, "CELL.YPARITY")) continue;
-	if (!strcmp(name, "CELL.X0")) continue;
-	if (!strcmp(name, "CELL.Y0")) continue;
-
-	psMetadataItem *copy = psMetadataItemCopy(conceptItem); // Copy of the concept
-	psMetadataAddItem(target->concepts, copy, PS_LIST_TAIL, PS_META_REPLACE);
-	psFree(copy);               // Drop reference
+        if (!strcmp(name, "CELL.BIASSEC")) continue;
+        if (!strcmp(name, "CELL.XPARITY")) continue;
+        if (!strcmp(name, "CELL.YPARITY")) continue;
+        if (!strcmp(name, "CELL.X0")) continue;
+        if (!strcmp(name, "CELL.Y0")) continue;
+
+        psMetadataItem *copy = psMetadataItemCopy(conceptItem); // Copy of the concept
+        psMetadataAddItem(target->concepts, copy, PS_LIST_TAIL, PS_META_REPLACE);
+        psFree(copy);               // Drop reference
     }
     psFree(conceptsIter);
@@ -196,5 +206,5 @@
     // XXX this code seems to be very similar to pmConceptsUpdate
     if ((binning->nXbin != 1) || (binning->nYbin != 1)) {
-	bool mdok = false;
+        bool mdok = false;
         psRegion *trimsec = psMetadataLookupPtr(&mdok, target->concepts, "CELL.TRIMSEC"); // The trim section
         if (mdok && trimsec && !psRegionIsNaN(*trimsec)) {
@@ -227,5 +237,5 @@
         }
 
-	// XXX make sure this is consistent with the psImageBinning
+        // XXX make sure this is consistent with the psImageBinning
         psTrace("psModules.camera", 3, "CELL.X0: Before: %d After: %d\n", xZero, xZero + (xSize - 1) * xParity * sourceBin);
         psTrace("psModules.camera", 9, "(xParity: %d xBin: %d numCols: %d)\n", xParity, sourceBin, xSize);
@@ -284,5 +294,5 @@
     pmHDU *targetPHU = findBlankPHU(target); // The target PHU
     if (targetPHU && targetPHU != targetHDU) {
-	// pmHDU *sourcePHU = pmHDUGetHighest(source->parent->parent, source->parent, source); // A source HDU
+        // pmHDU *sourcePHU = pmHDUGetHighest(source->parent->parent, source->parent, source); // A source HDU
         pmHDU *sourcePHU = findBlankPHU(source); // The target PHU
         if (sourcePHU && sourcePHU->header) {
