Index: trunk/psphot/src/psphotImageLoop.c
===================================================================
--- trunk/psphot/src/psphotImageLoop.c	(revision 23957)
+++ trunk/psphot/src/psphotImageLoop.c	(revision 25755)
@@ -67,18 +67,19 @@
 
                 // Update the header
-                {
-                    pmHDU *hdu = pmHDUGetHighest(input->fpa, chip, cell);
-                    if (hdu && hdu != lastHDU) {
-                        psphotVersionHeaderFull(hdu->header);
-                        lastHDU = hdu;
-                    }
+		pmHDU *hdu = pmHDUGetHighest(input->fpa, chip, cell);
+		if (hdu && hdu != lastHDU) {
+		    psphotVersionHeaderFull(hdu->header);
+		    lastHDU = hdu;
                 }
 
-                psImageMaskType maskSat = pmConfigMaskGet("SAT", config); // Mask value for saturated pixels
-                if (!pmReadoutMaskNonfinite(readout, maskSat)) {
-                    psError(psErrorCodeLast(), false, "Unable to mask non-finite pixels.");
-                    psFree(view);
-                    return false;
-                }
+		// if an external mask is supplied, ensure that NAN pixels are also masked
+		if (readout->mask) {
+		    psImageMaskType maskSat = pmConfigMaskGet("SAT", config); // Mask value for saturated pixels
+		    if (!pmReadoutMaskNonfinite(readout, maskSat)) {
+			psError(psErrorCodeLast(), false, "Unable to mask non-finite pixels.");
+			psFree(view);
+			return false;
+		    }
+		}
 
                 // run the actual photometry analysis on this chip/cell/readout
