Index: trunk/pswarp/src/pswarpSetMaskBits.c
===================================================================
--- trunk/pswarp/src/pswarpSetMaskBits.c	(revision 27096)
+++ trunk/pswarp/src/pswarpSetMaskBits.c	(revision 42293)
@@ -20,4 +20,5 @@
  * updated in the config metadata.
  */
+ 
 bool pswarpSetMaskBits (pmConfig *config)
 {
@@ -26,10 +27,27 @@
     psImageMaskType maskOut = 0x00;                     // mask for the output image
 
+    // Look up recipe values
+    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PSWARP_RECIPE); // Recipe for ppSim
+    psAssert(recipe, "We checked this earlier, so it should be here.");
+    bool doDetectCTE = psMetadataLookupBool(NULL, recipe, "DETECT.CTE"); // Do detections on pixels underneath CTE masks
+
     // this function sets the required single-image mask bits
-    if (!pmConfigMaskSetBits (&maskIn, &markIn, config)) {
-        psError (psErrorCodeLast(), false, "Unable to define the mask bit values");
-        return false;
+    if(!doDetectCTE) {
+      if (!pmConfigMaskSetBits (&maskIn, &markIn, config)) {
+          psError (psErrorCodeLast(), false, "Unable to define the mask bit values");
+          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 (!pswarpMaskSetInMetadata(&maskIn, &markIn, maskrecipe)) {
+          psError (psErrorCodeLast(), false, "Unable to determine the mask value");
+          return false;
+      }
     }
-
+    
     // mask for non-linear flat regions (default to DETECTOR if not defined)
     psImageMaskType badMask = pmConfigMaskGet("CONV.BAD", config);
