Index: trunk/psphot/src/psphotForcedImageLoop.c
===================================================================
--- trunk/psphot/src/psphotForcedImageLoop.c	(revision 29936)
+++ trunk/psphot/src/psphotForcedImageLoop.c	(revision 31154)
@@ -1,9 +1,9 @@
 # include "psphotStandAlone.h"
 
-# define ESCAPE(MESSAGE) { \
-  psError(PSPHOT_ERR_DATA, false, MESSAGE); \
-  psFree (view); \
-  return false; \
-}
+# define ESCAPE(MESSAGE) {				\
+	psError(PSPHOT_ERR_DATA, false, MESSAGE);	\
+	psFree (view);					\
+	return false;					\
+    }
 
 bool psphotForcedImageLoop (pmConfig *config) {
@@ -31,4 +31,10 @@
     if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot.");
 
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
+    psImageMaskType maskTest = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
+
     // for psphot, we force data to be read at the chip level
     while ((chip = pmFPAviewNextChip (view, load->fpa, 1)) != NULL) {
@@ -45,4 +51,21 @@
         // mosaic the cells of a chip into a single contiguous (trimmed) chip
         if (!psphotMosaicChip(config, view, "PSPHOT.INPUT", "PSPHOT.LOAD")) ESCAPE ("Unable to mosaic chip.");
+
+        // Read WCS if easy.
+        // XXX Since we're mosaicking cells, we ignore the case where the WCS is defined for a cell.
+        {
+            pmChip *inChip = pmFPAviewThisChip(view, input->fpa); // Mosaicked chip
+            pmHDU *hduLow = pmHDUGetLowest(input->fpa, inChip, NULL);
+            if (hduLow && !pmAstromReadWCS(input->fpa, inChip, hduLow->header, 1.0)) {
+                psWarning("Unable to read WCS astrometry from header.");
+                psErrorClear();
+                pmHDU *hduHigh = pmHDUGetHighest(input->fpa, inChip, NULL);
+                if (hduHigh && hduHigh != hduLow &&
+                    !pmAstromReadWCS(input->fpa, chip, hduHigh->header, 1.0)) {
+                    psWarning("Unable to read WCS astrometry from primary header.");
+                    psErrorClear();
+                }
+            }
+        }
 
         // try to load other supporting data (PSF, SRC, etc).
@@ -76,5 +99,5 @@
 		if (readout->mask) {
 		    psImageMaskType maskSat = pmConfigMaskGet("SAT", config); // Mask value for saturated pixels
-		    if (!pmReadoutMaskNonfinite(readout, maskSat)) {
+                    if (!pmReadoutMaskInvalid(readout, maskTest, maskSat)) {
 			psError(psErrorCodeLast(), false, "Unable to mask non-finite pixels.");
 			psFree(view);
@@ -91,4 +114,5 @@
             }
 
+            // drop all versions of the internal files
             status = true;
             status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL");
