Index: trunk/ippconfig/recipes/ppImage.config
===================================================================
--- trunk/ippconfig/recipes/ppImage.config	(revision 41381)
+++ trunk/ippconfig/recipes/ppImage.config	(revision 41382)
@@ -20,4 +20,5 @@
 AUX.VIDEO.MASK     STR     NULL            # name of aditional masking for video cells
 APPLY.BURNTOOL     BOOL    FALSE           # apply burntool coorection
+APPLY.PIXELZERO    BOOL    TRUE            # apply zero'ing of pixels underneath masks
 VARIANCE.BUILD     BOOL    FALSE           # Build internal variance image
 ADDNOISE           BOOL    FALSE           # Add noise to degrade an MD image to a 3pi image?
Index: trunk/ippconfig/recipes/ppSub.config
===================================================================
--- trunk/ippconfig/recipes/ppSub.config	(revision 41381)
+++ trunk/ippconfig/recipes/ppSub.config	(revision 41382)
@@ -17,4 +17,5 @@
 NORM.FRAC	F32	0.02		# Fraction of window for normalisation window
 COVAR.FRAC	F32	0.01		# Fraction of kernel to truncate before calculating covariance
+APPLY.PIXELNAN	BOOL	TRUE		# Apply NAN'ing of pixels underneath masks
 
 MASK.VAL	STR	MASK.VALUE,CONV.BAD	# Mask value for input
Index: trunk/ippconfig/recipes/pswarp.config
===================================================================
--- trunk/ippconfig/recipes/pswarp.config	(revision 41381)
+++ trunk/ippconfig/recipes/pswarp.config	(revision 41382)
@@ -12,4 +12,5 @@
 PSF			BOOL	TRUE		# Measure PSF for warped image?
 SOURCES			BOOL	TRUE		# Write source list for warped image?
+APPLY.PIXELNAN		BOOL	TRUE		# Apply NAN'ing of pixels underneath masks
 
 NO.COMPRESS             BOOL    FALSE           # turn off image compression (if enabled)
Index: trunk/ppImage/src/ppImage.h
===================================================================
--- trunk/ppImage/src/ppImage.h	(revision 41381)
+++ trunk/ppImage/src/ppImage.h	(revision 41382)
@@ -28,4 +28,5 @@
     bool doVarianceBuild;               // Build internal variance map
     bool doApplyBurntool;               // apply burntool correction
+    bool doApplyPixelZero;              // put to zero pixels underneath mask
     bool doMaskBurntool;                // mask potential burntool trails
     bool doMaskSat;                     // mask saturated pixels
Index: trunk/ppImage/src/ppImageOptions.c
===================================================================
--- trunk/ppImage/src/ppImageOptions.c	(revision 41381)
+++ trunk/ppImage/src/ppImageOptions.c	(revision 41382)
@@ -53,4 +53,6 @@
     options->useVideoDark    = false;   // Use video dark if we can?
     options->useVideoMask    = false;   // Use video mask if we can?
+    options->doApplyPixelZero  = true;   // option for zero'ing pixels under masks
+
     // output files requested
     options->BaseFITS        = false;   // create output image
@@ -234,4 +236,6 @@
     options->doMaskBurntool  = psMetadataLookupBool(NULL, recipe, "MASK.BURNTOOL");
     options->doApplyBurntool = psMetadataLookupBool(NULL, recipe, "APPLY.BURNTOOL");
+    //TdB: read in switch for zero'ing pixels under masks
+    options->doApplyPixelZero = psMetadataLookupBool(NULL, recipe, "APPLY.PIXELZERO");
     options->doVarianceBuild = psMetadataLookupBool(NULL, recipe, "VARIANCE.BUILD");
     options->doAuxMask       = psMetadataLookupBool(NULL, recipe, "MASK.AUXMASK");
@@ -245,4 +249,5 @@
         }
     }
+
 
     // Mask recipe options (note that mask bit values are set in ppImageSetMaskBits.c)
Index: trunk/ppImage/src/ppImageReplaceBackground.c
===================================================================
--- trunk/ppImage/src/ppImageReplaceBackground.c	(revision 41381)
+++ trunk/ppImage/src/ppImageReplaceBackground.c	(revision 41382)
@@ -144,6 +144,16 @@
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
-            if (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
-                image->data.F32[y][x] = 0.0;
+            if(options->doApplyPixelZero) {
+              if (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
+                  image->data.F32[y][x] = 0.0;
+              } else {
+		float value = backData[y][x];
+		if (!isfinite(value)) {
+		    image->data.F32[y][x] = NAN;
+		    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= options->lowMask;
+		} else {
+		    image->data.F32[y][x] -= value;
+		}
+  	      }
             } else {
 		float value = backData[y][x];
@@ -154,5 +164,5 @@
 		    image->data.F32[y][x] -= value;
 		}
-	    }
+            }
         }
     }
@@ -162,6 +172,16 @@
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
-            if (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
-                image->data.F32[y][x] = 0.0;
+            if(options->doApplyPixelZero) {
+              if (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
+                  image->data.F32[y][x] = 0.0;
+              } else {
+                float value = psImageUnbinPixel(x + 0.5, y + 0.5, modelRO->image, binning); // Background value
+                if (!isfinite(value)) {
+                    image->data.F32[y][x] = NAN;
+                    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= options->lowMask;
+                } else {
+                    image->data.F32[y][x] -= value;
+                }
+              }
             } else {
                 float value = psImageUnbinPixel(x + 0.5, y + 0.5, modelRO->image, binning); // Background value
Index: trunk/ppSub/src/ppSub.h
===================================================================
--- trunk/ppSub/src/ppSub.h	(revision 41381)
+++ trunk/ppSub/src/ppSub.h	(revision 41382)
@@ -190,4 +190,17 @@
 void ppSubSetThreads (void);
 
+// ppSubMaskSetInMetadata examines named mask values and set the bits for maskValue and
+// markValue.  Ensures that the below-named mask values are set, and calculates the mask value
+// to catch all of the mask values marked as 'bad'.  Supplies the fallback name if the primary
+// name is not found, or the default values if the fallback name is not found.
+bool ppSubMaskSetInMetadata(psImageMaskType *outMaskValue, // Value of MASK.VALUE, returned
+                               psImageMaskType *outMarkValue, // Value of MARK.VALUE, returned
+                               psMetadata *source  // Source of mask bits
+  );
+
+// lookup an image mask value by name from a psMetadata, without requiring the entry to
+// be of type psImageMaskType, but verifying that it will fit in psImageMaskType
+psImageMaskType psMetadataLookupImageMaskFromGeneric (bool *status, const psMetadata *md, const char *name);
+
 ///@}
 #endif
Index: trunk/ppSub/src/ppSubBackground.c
===================================================================
--- trunk/ppSub/src/ppSubBackground.c	(revision 41381)
+++ trunk/ppSub/src/ppSubBackground.c	(revision 41382)
@@ -33,4 +33,6 @@
     psAssert(psphotRecipe, "Need PSPHOT recipe for binning");
 
+    bool doApplyMaskNaN = psMetadataLookupBool(&mdok, ppSubRecipe, "APPLY.PIXELNAN"); // NaN the pixels underneath masks
+
     psImageMaskType maskBad = pmConfigMaskGet("BLANK", config); // Bits to mask
 
@@ -64,9 +66,11 @@
         for (int x = 0; x < numCols; x++) {
 	    // special case 1: NAN the masked pixels
-            if (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskBad) {
+            if(doApplyMaskNaN) {
+              if (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskBad) {
                 image->data.F32[y][x] = NAN;
 		continue;
-            } 
-	    // special case 1: NAN & mask pixels without a valid background model
+              } 
+            }
+	    // special case 2: NAN & mask pixels without a valid background model
 	    float value = psImageUnbinPixel(x + 0.5, y + 0.5, modelImage, binning); // Background value
 	    if (!isfinite(value)) {
Index: trunk/ppSub/src/ppSubReadoutSubtract.c
===================================================================
--- trunk/ppSub/src/ppSubReadoutSubtract.c	(revision 41381)
+++ trunk/ppSub/src/ppSubReadoutSubtract.c	(revision 41382)
@@ -33,4 +33,5 @@
     bool noConvolve = psMetadataLookupBool(&mdok, recipe, "NOCONVOLVE"); // Do not use convolved images.
     bool addPair = psMetadataLookupBool(&mdok, recipe, "ADD.NOT.SUBTRACT"); // add instead of subtracting
+    bool doApplyMaskNaN = psMetadataLookupBool(&mdok, recipe, "APPLY.PIXELNAN"); // NaN the pixels underneath masks
 
     pmFPAview *view = ppSubViewReadout(); // View to readout
@@ -73,9 +74,11 @@
     // NAN the masked pixels in the diff image (pixels masked in A are not yet NAN'ed in B)
     psImageMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config) | pmConfigMaskGet("BLANK", config); // Bits to mask in inputs
-    for (int iy = 0; iy < outRO->image->numRows; iy++) {
+    if(doApplyMaskNaN) {
+      for (int iy = 0; iy < outRO->image->numRows; iy++) {
 	for (int ix = 0; ix < outRO->image->numCols; ix++) {
 	    if ((outRO->mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) == 0) continue;
 	    outRO->image->data.F32[iy][ix] = NAN;
 	}
+      }
     }
 
Index: trunk/ppSub/src/ppSubSetMasks.c
===================================================================
--- trunk/ppSub/src/ppSubSetMasks.c	(revision 41381)
+++ trunk/ppSub/src/ppSubSetMasks.c	(revision 41382)
@@ -22,20 +22,65 @@
 #include "ppSub.h"
 
+// Structure to hold the properties of a mask value
+typedef struct {
+    char *badMaskName;                  // name for "bad" (i.e., mask me please) pixels
+    char *fallbackName;                 // Fallback name in case a bad mask name is not defined
+    psImageMaskType defaultMaskValue;   // Default value in case a bad mask name and its fallback are not defined
+    bool isBad; // include this value as part of the MASK.VALUE entry (generically bad)
+} pmConfigMaskInfo;
+
+static pmConfigMaskInfo skycellmasks[] = {
+    // Features of the detector
+    { "DETECTOR",  NULL,       0x01, false }, // Something is wrong with the detector
+    { "FLAT",      "DETECTOR", 0x01, false }, // Pixel doesn't flat-field properly
+    { "DARK",      "DETECTOR", 0x01, false }, // Pixel doesn't dark-subtract properly
+    { "BLANK",     "DETECTOR", 0x01, true }, // Pixel doesn't contain valid data
+    { "CTE",       "DETECTOR", 0x01, false }, // Pixel has poor CTE
+    { "BURNTOOL",  NULL,       0x04, false }, // Pixel has been touched by burntool
+    // Invalid signal ranges
+    { "SAT",       NULL,       0x02, true  }, // Pixel is saturated or non-linear
+    { "LOW",       "SAT",      0x02, true  }, // Pixel is low
+    { "SUSPECT",   NULL,       0x04, false }, // Pixel is suspected of being bad
+    // Non-astronomical structures
+    { "CR",        NULL,       0x08, true  }, // Pixel contains a cosmic ray
+    { "SPIKE",     NULL,       0x08, false  }, // Pixel contains a diffraction spike
+    { "GHOST",     NULL,       0x08, false  }, // Pixel contains an optical ghost
+    { "STREAK",    NULL,       0x08, false  }, // Pixel contains streak data
+    { "STARCORE",  NULL,       0x08, false  }, // Pixel contains a bright star core
+    // Effects of convolution and interpolation
+    { "CONV.BAD",  NULL,       0x02, true  }, // Pixel is bad after convolution with a bad pixel
+    { "CONV.POOR", NULL,       0x04, false }, // Pixel is poor after convolution with a bad pixel
+};
+
 bool ppSubSetMasks(pmConfig *config)
 {
     psAssert(config, "Require configuration");
 
-    psImageMaskType maskValue, markValue; // Mask values
-    if (!pmConfigMaskSetBits(&maskValue, &markValue, config)) {
-        psError(PPSUB_ERR_CONFIG, false, "Unable to determine mask value.");
-        return false;
-    }
-
-    // Set the mask bits needed by psphot (in psphot recipe)
-    psphotSetMaskRecipe(config, maskValue, markValue);
-
     // Look up recipe values
     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
     psAssert(recipe, "We checked this earlier, so it should be here.");
+    bool doApplyMaskNaN = psMetadataLookupBool(NULL, recipe, "APPLY.PIXELNAN"); // NaN the pixels underneath masks
+
+    psImageMaskType maskValue, markValue; // Mask values
+    if(doApplyMaskNaN) {
+      if (!pmConfigMaskSetBits(&maskValue, &markValue, config)) {
+          psError(PPSUB_ERR_CONFIG, false, "Unable to determine mask value.");
+          return false;
+      }
+    } else {
+      psMetadata *maskrecipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
+      if (!maskrecipe) {
+          psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
+          return false;
+      }
+      if (!ppSubMaskSetInMetadata(&maskValue, &markValue, maskrecipe)) {
+          psError(PPSUB_ERR_CONFIG, false, "Unable to determine mask value.");
+          return false;
+      }
+    }
+
+    // Set the mask bits needed by psphot (in psphot recipe)
+    psphotSetMaskRecipe(config, maskValue, markValue);
+
 
     psImageMaskType satValue = pmConfigMaskGet("SAT", config);
@@ -121,2 +166,69 @@
     return true;
 }
+
+bool ppSubMaskSetInMetadata(psImageMaskType *outMaskValue, // Value of MASK.VALUE, returned
+                               psImageMaskType *outMarkValue, // Value of MARK.VALUE, returned
+                               psMetadata *source  // Source of mask bits
+    )
+{
+    PS_ASSERT_METADATA_NON_NULL(source, false);
+
+    // Ensure all the bad mask names exist, and set the value to catch all bad pixels
+    psImageMaskType maskValue = 0;           // Value to mask to catch all the bad pixels
+    psImageMaskType allMasks = 0;            // Value to mask to catch all masked bits (to set MARK)
+
+    int nMasks = sizeof (skycellmasks) / sizeof (pmConfigMaskInfo);
+
+    for (int i = 0; i < nMasks; i++) {
+        bool mdok;                      // Status of MD lookup
+        psImageMaskType value = psMetadataLookupImageMaskFromGeneric(&mdok, source, skycellmasks[i].badMaskName); // Value of mask
+        if (!mdok) {
+            psWarning ("problem with mask value %s\n", skycellmasks[i].badMaskName);
+        }
+
+        if (!value) {
+            if (skycellmasks[i].fallbackName) {
+                value = psMetadataLookupImageMaskFromGeneric(&mdok, source, skycellmasks[i].fallbackName);
+            }
+            if (!value) {
+                value = skycellmasks[i].defaultMaskValue;
+            }
+            psMetadataAddImageMask(source, PS_LIST_TAIL, skycellmasks[i].badMaskName, PS_META_REPLACE, NULL, value);
+        }
+        if (skycellmasks[i].isBad) {
+            maskValue |= value;
+        }
+        allMasks |= value;
+    }
+
+    // search for an unset bit to use for MARK:
+    psImageMaskType markValue = 0x00;
+    psImageMaskType markTrial = 0x01;
+
+    int nBits = sizeof(psImageMaskType) * 8;
+    for (int i = 0; !markValue && (i < nBits); i++) {
+        if (allMasks & markTrial) {
+            markTrial <<= 1;
+        } else {
+            markValue = markTrial;
+        }
+    }
+    if (!markValue) {
+        psError (PS_ERR_UNKNOWN, true, "Unable to define the MARK bit mask: all bits taken!");
+        return false;
+    }
+
+    // update the list with the results
+    psMetadataAddImageMask(source, PS_LIST_TAIL, "MASK.VALUE", PS_META_REPLACE, NULL, maskValue);
+    psMetadataAddImageMask(source, PS_LIST_TAIL, "MARK.VALUE", PS_META_REPLACE, NULL, markValue);
+
+    if (outMaskValue) {
+        *outMaskValue = maskValue;
+    }
+    if (outMarkValue) {
+        *outMarkValue = markValue;
+    }
+
+    return true;
+}
+
Index: trunk/psModules/src/objects/pmSourceIO.h
===================================================================
--- trunk/psModules/src/objects/pmSourceIO.h	(revision 41381)
+++ trunk/psModules/src/objects/pmSourceIO.h	(revision 41382)
@@ -91,5 +91,5 @@
 bool pmSourceIO_ReadMatchedRefs (psFits *fits, pmFPA *fpa, const pmConfig *config);
 
-bool psastroZeroPointFromRecipeGlint (float *zeropt, float *exptime, float *ghostMaxMag, double *glintMaxMag, pmFPA *fpa, psMetadata *recipe);
+bool pmSourceZeroPointFromRecipeGlint (float *zeropt, float *exptime, float *ghostMaxMag, double *glintMaxMag, pmFPA *fpa, psMetadata *recipe);
 bool pmSourceIO_WriteGlints (psFits *fits, pmFPA *fpa, pmConfig *config);
 bool pmSourceIO_WriteGhosts (psFits *fits, pmFPA *fpa, pmConfig *config);
Index: trunk/psModules/src/objects/pmSourceIO_Ghosts.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_Ghosts.c	(revision 41381)
+++ trunk/psModules/src/objects/pmSourceIO_Ghosts.c	(revision 41382)
@@ -55,5 +55,5 @@
 #include "pmAstrometryWCS.h"
 
-# include "psastroInternal.h"
+# include "pmSourceInternal.h"
 static psVector *chipXmin = NULL;
 static psVector *chipXmax = NULL;
@@ -68,10 +68,10 @@
     md = psMetadataLookupMetadata (&status, ghostModel, NAME); \
     if (!md) { \
-	psError(PSASTRO_ERR_CONFIG, true, "Missing %s in model file %s", NAME, ghostFile); \
+	psError(PM_ERR_CONFIG, true, "Missing %s in model file %s", NAME, ghostFile); \
 	goto escape; \
     } \
     OUT = psPolynomial2DfromMetadata(md); \
     if (!OUT) { \
-	psError(PSASTRO_ERR_CONFIG, true, "Trouble interpretting %s in model file %s", NAME, ghostFile); \
+	psError(PM_ERR_CONFIG, true, "Trouble interpretting %s in model file %s", NAME, ghostFile); \
 	goto escape; \
     }
@@ -80,10 +80,10 @@
     md = psMetadataLookupMetadata (&status, ghostModel, NAME); \
     if (!md) { \
-	psError(PSASTRO_ERR_CONFIG, true, "Missing %s in model file %s", NAME, ghostFile); \
+	psError(PM_ERR_CONFIG, true, "Missing %s in model file %s", NAME, ghostFile); \
 	goto escape; \
     } \
     OUT = psPolynomial1DfromMetadata(md);	\
     if (!OUT) { \
-	psError(PSASTRO_ERR_CONFIG, true, "Trouble interpretting %s in model file %s", NAME, ghostFile); \
+	psError(PM_ERR_CONFIG, true, "Trouble interpretting %s in model file %s", NAME, ghostFile); \
 	goto escape; \
     }
@@ -116,5 +116,5 @@
     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);
     if (!recipe) {
-        psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe");
+        psError(PM_ERR_CONFIG, true, "Can't find PSASTRO recipe");
         return false;
     }
@@ -129,5 +129,5 @@
 
     if (!pmConfigFileRead (&ghostModel, ghostFile, "GHOST MODEL")) {
-	psError(PSASTRO_ERR_CONFIG, true, "Trouble loading ghost model");
+	psError(PM_ERR_CONFIG, true, "Trouble loading ghost model");
         return false;
     }
@@ -156,5 +156,5 @@
     pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     if (!astrom) {
-        psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
+        psError(PM_ERR_CONFIG, true, "Can't find input data");
 	goto escape;
     }
@@ -162,5 +162,5 @@
 
     // really error-out here?  or just skip?
-    if (!psastroZeroPointFromRecipeGlint (&zeropt, &exptime, &MAX_MAG,NULL, fpa_ast, recipe)) {
+    if (!pmSourceZeroPointFromRecipeGlint (&zeropt, &exptime, &MAX_MAG,NULL, fpa_ast, recipe)) {
         psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
 	goto escape;
@@ -202,5 +202,5 @@
  			if (ref->Mag > MAX_MAG) continue;
 
- 			psastroGhost *ghost = psastroGhostAlloc ();
+ 			pmSourceGhost *ghost = pmSourceGhostAlloc ();
  			ghost->srcFP->x = ref->FP->x; 
  			ghost->srcFP->y = ref->FP->y;
@@ -239,6 +239,6 @@
  			// XXX this code yields a single chip: we need to provide results for any chips
  			// which encompass the full size of the ghost
- 			pmChip *ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, -ghost->srcFP->x, -ghost->srcFP->y);
- 			ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, ghost->FP->x, ghost->FP->y);
+ 			pmChip *ghostChip = pmSourceFindChip (&ghost->chip->x, &ghost->chip->y, fpa, -ghost->srcFP->x, -ghost->srcFP->y);
+ 			ghostChip = pmSourceFindChip (&ghost->chip->x, &ghost->chip->y, fpa, ghost->FP->x, ghost->FP->y);
 
                         //do a rudimentary check of whether the ghost is on the pixel FPA
@@ -331,5 +331,5 @@
 }
 
-static void psastroGhostFree (psastroGhost *ghost) {
+static void pmSourceGhostFree (pmSourceGhost *ghost) {
 
     if (ghost == NULL) return;
@@ -342,8 +342,8 @@
 }
 
-psastroGhost *psastroGhostAlloc (void) {
-
-    psastroGhost *ghost = (psastroGhost *) psAlloc(sizeof(psastroGhost));
-    psMemSetDeallocator(ghost, (psFreeFunc) psastroGhostFree);
+pmSourceGhost *pmSourceGhostAlloc (void) {
+
+    pmSourceGhost *ghost = (pmSourceGhost *) psAlloc(sizeof(pmSourceGhost));
+    psMemSetDeallocator(ghost, (psFreeFunc) pmSourceGhostFree);
 
     ghost->srcFP = psPlaneAlloc();
@@ -365,5 +365,5 @@
 
 
-bool psastroChipBounds (pmFPA *fpa) {
+bool pmSourceChipBounds (pmFPA *fpa) {
 
     chipXmin = psVectorAlloc (fpa->chips->n, PS_TYPE_F32);
@@ -416,5 +416,5 @@
 }
 
-pmChip *psastroFindChip (double *xChip, double *yChip, pmFPA *fpa, double xFPA, double yFPA) {
+pmChip *pmSourceFindChip (double *xChip, double *yChip, pmFPA *fpa, double xFPA, double yFPA) {
 
     *xChip = NAN;
@@ -422,5 +422,5 @@
 
     if (!chipXmin) {
-	psastroChipBounds (fpa);
+	pmSourceChipBounds (fpa);
     }
 
@@ -458,5 +458,5 @@
 
 // identify chips which land on this column (FP coords)
-bool psastroFindChipInXrange (pmFPA *fpa, int nChip, double xFPA, double yFPA) {
+bool pmSourceFindChipInXrange (pmFPA *fpa, int nChip, double xFPA, double yFPA) {
 
     if (!chipXmin || !chipXmax) {
@@ -470,5 +470,5 @@
 
 // identify chips which land on this row (FP coords)
-bool psastroFindChipInYrange (pmFPA *fpa, int nChip, double xFPA, double yFPA) {
+bool pmSourceFindChipInYrange (pmFPA *fpa, int nChip, double xFPA, double yFPA) {
 
     if (!chipYmin || !chipYmax) {
@@ -482,5 +482,5 @@
 
 // return the FPA coordinates of the Y edges of the chip
-bool psastroFindChipYedges (double *yFPAs, double *yFPAe, pmFPA *fpa, int nChip) {
+bool pmSourceFindChipYedges (double *yFPAs, double *yFPAe, pmFPA *fpa, int nChip) {
 
     *yFPAs = chipYmin->data.F32[nChip];
@@ -490,5 +490,5 @@
 
 // return the FPA coordinates of the X edges of the chip
-bool psastroFindChipXedges (double *yFPAs, double *yFPAe, pmFPA *fpa, int nChip) {
+bool pmSourceFindChipXedges (double *yFPAs, double *yFPAe, pmFPA *fpa, int nChip) {
 
     *yFPAs = chipXmin->data.F32[nChip];
@@ -498,5 +498,5 @@
 
 // convert FPA to Chip coordinates
-bool psastroFPAtoChip (double *xChip, double *yChip, pmFPA *fpa, int nChip, double xFPA, double yFPA) {
+bool pmSourceFPAtoChip (double *xChip, double *yChip, pmFPA *fpa, int nChip, double xFPA, double yFPA) {
 
     pmChip *chip = fpa->chips->data[nChip];
@@ -512,5 +512,5 @@
 }
 
-bool psastroExtractFreeChipBounds () {
+bool pmSourceExtractFreeChipBounds () {
   
   psFree (chipXmin);
Index: trunk/psModules/src/objects/pmSourceIO_Glints.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_Glints.c	(revision 41381)
+++ trunk/psModules/src/objects/pmSourceIO_Glints.c	(revision 41382)
@@ -55,5 +55,5 @@
 #include "pmAstrometryWCS.h"
 
-# include "psastroInternal.h"
+# include "pmSourceInternal.h"
 
 # define ESCAPE(MSG) { \
@@ -71,5 +71,5 @@
     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);
     if (!recipe) {
-        psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe");
+        psError(PM_ERR_CONFIG, true, "Can't find PSASTRO recipe");
         return false;
     }
@@ -110,5 +110,5 @@
     pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     if (!astrom) {
-        psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
+        psError(PM_ERR_CONFIG, true, "Can't find input data");
         return false;
     }
@@ -117,5 +117,5 @@
     // use the zero point and exposure time to convert to apparent mags: M_ap = M_inst + C_0 + 2.5*log(exptime)
     pmFPA *fpa_ast = astrom->fpa;
-    if (!psastroZeroPointFromRecipeGlint (&zeropt, &exptime, NULL,&GLINT_MAX_MAG, fpa_ast, recipe)) {
+    if (!pmSourceZeroPointFromRecipeGlint (&zeropt, &exptime, NULL,&GLINT_MAX_MAG, fpa_ast, recipe)) {
         psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
         return false;
@@ -237,5 +237,5 @@
 }
 
-bool psastroZeroPointFromRecipeGlint (float *zeropt, float *exptime, float *ghostMaxMag, double *glintMaxMag, pmFPA *fpa, psMetadata *recipe) {
+bool pmSourceZeroPointFromRecipeGlint (float *zeropt, float *exptime, float *ghostMaxMag, double *glintMaxMag, pmFPA *fpa, psMetadata *recipe) {
 
     bool status;
Index: trunk/pswarp/src/pswarpTransformReadout.c
===================================================================
--- trunk/pswarp/src/pswarpTransformReadout.c	(revision 41381)
+++ trunk/pswarp/src/pswarpTransformReadout.c	(revision 41382)
@@ -27,4 +27,6 @@
     int nGridX = psMetadataLookupS32(NULL, config->arguments, "GRID.NX"); ///< Number of grid points in x
     int nGridY = psMetadataLookupS32(NULL, config->arguments, "GRID.NY"); ///< Number of grid points in y
+    bool doApplyMaskNaN = psMetadataLookupBool(NULL, config->arguments, "APPLY.PIXELNAN"); ///NaN the pixels underneath masks
+
     psImageInterpolateMode interpolationMode = psMetadataLookupS32(NULL, config->arguments,
                                                                    "INTERPOLATION.MODE"); ///< Mode for interp
@@ -37,5 +39,9 @@
 
     // output mask bits
-    psImageMaskType maskIn   = psMetadataLookupImageMask(&mdok, recipe, "MASK.INPUT");
+    psImageMaskType maskIn   = 0 ;
+    if(doApplyMaskNaN) {
+      maskIn   = psMetadataLookupImageMask(&mdok, recipe, "MASK.INPUT");
+      psAssert(mdok, "MASK.INPUT was not defined");
+    } 
     psImageMaskType maskPoor = pmConfigMaskGet("CONV.POOR", config);
     if (!maskPoor) {
@@ -46,5 +52,4 @@
         maskBad  = pmConfigMaskGet("BAD.WARP", config);
     }
-    psAssert(mdok, "MASK.INPUT was not defined");
 
     if (!input->covariance) {
