Index: /trunk/ppImage/src/ppImageDetrendFringe.c
===================================================================
--- /trunk/ppImage/src/ppImageDetrendFringe.c	(revision 24909)
+++ /trunk/ppImage/src/ppImageDetrendFringe.c	(revision 24910)
@@ -192,4 +192,6 @@
     }
     assert(fringes->readouts->n == solution->nFringeFrames);
+
+    psImageMaskType maskVal = options->flatMask;
 
     bool mdok;                          // Status of MD lookup
@@ -257,9 +259,19 @@
         }
 
+	// subtract fringe and update mask if fringe value is NAN
+	for (int iy = 0; iy < readout->image->numRows; iy++) {
+	    for (int ix = 0; ix < readout->image->numCols; ix++) {
+		readout->mask->data.F32[iy][ix] -= sumFringe->data.F32[iy][ix];
+		if (!isfinite(sumFringe->data.F32[iy][ix]) && readout->mask) {
+		    readout->mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= maskVal;
+		} 
+	    }
+	}
+
         // XXX: Make generic, so subregions may be subtracted as well
-        if (!psBinaryOp(readout->image, readout->image, "-", sumFringe)) {
-            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to subtract fringe.\n");
-            return false;
-        }
+        // if (!psBinaryOp(readout->image, readout->image, "-", sumFringe)) {
+        //     psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to subtract fringe.\n");
+        //     return false;
+        // }
 
 	// measure residual fringe amplitude. results go to FRINGE.RESIDUALS
