Index: trunk/ppMerge/src/ppMergeLoop.c
===================================================================
--- trunk/ppMerge/src/ppMergeLoop.c	(revision 23463)
+++ trunk/ppMerge/src/ppMergeLoop.c	(revision 23609)
@@ -164,4 +164,7 @@
                 pmHDU *hdu = pmHDUGetHighest(outFPA, outChip, outCell); // HDU for file
                 if (hdu && hdu != lastHDU) {
+                    if (!hdu->header) {
+                        hdu->header = psMetadataAlloc();
+                    }
                     ppMergeVersionHeader(hdu->header);
                     lastHDU = hdu;
@@ -411,26 +414,26 @@
             }
 
-	    // calculate CTEMASK after stats so stats reflect median image
+            // calculate CTEMASK after stats so stats reflect median image
             if (type == PPMERGE_TYPE_CTEMASK && outRO) {
-		// need to apply range cuts on the output image
-		psAssert (outRO->mask, "mask is not defined");
-		psAssert (outRO->mask->numCols == outRO->image->numCols, "mismatch between image and mask");
-		psAssert (outRO->mask->numRows == outRO->image->numRows, "mismatch between image and mask");
-
-		// CTEMASK parameters
-		float cteMin = psMetadataLookupF32(NULL, arguments, "CTE.MIN"); // Number of fringe points
-
-		char *cteMaskName = psMetadataLookupStr (&mdok, config->arguments, "MASK.SET.VALUE");
-		psImageMaskType cteMaskValue = pmConfigMaskGet(cteMaskName, config);
-
-		psF32 **outputImage = outRO->image->data.F32; 
-		psImageMaskType **outputMask = outRO->mask->data.PS_TYPE_IMAGE_MASK_DATA; 
-		for (int iy = 0; iy < outRO->image->numRows; iy++) {
-		    for (int ix = 0; ix < outRO->image->numCols; ix++) {
-			if (outputImage[iy][ix] < cteMin) {
-			    outputMask[iy][ix] |= cteMaskValue;
-			}
-		    }
-		}
+                // need to apply range cuts on the output image
+                psAssert (outRO->mask, "mask is not defined");
+                psAssert (outRO->mask->numCols == outRO->image->numCols, "mismatch between image and mask");
+                psAssert (outRO->mask->numRows == outRO->image->numRows, "mismatch between image and mask");
+
+                // CTEMASK parameters
+                float cteMin = psMetadataLookupF32(NULL, arguments, "CTE.MIN"); // Number of fringe points
+
+                char *cteMaskName = psMetadataLookupStr (&mdok, config->arguments, "MASK.SET.VALUE");
+                psImageMaskType cteMaskValue = pmConfigMaskGet(cteMaskName, config);
+
+                psF32 **outputImage = outRO->image->data.F32;
+                psImageMaskType **outputMask = outRO->mask->data.PS_TYPE_IMAGE_MASK_DATA;
+                for (int iy = 0; iy < outRO->image->numRows; iy++) {
+                    for (int ix = 0; ix < outRO->image->numCols; ix++) {
+                        if (outputImage[iy][ix] < cteMin) {
+                            outputMask[iy][ix] |= cteMaskValue;
+                        }
+                    }
+                }
             }
 
