Index: trunk/psModules/src/camera/pmFPAMaskWeight.c
===================================================================
--- trunk/psModules/src/camera/pmFPAMaskWeight.c	(revision 17692)
+++ trunk/psModules/src/camera/pmFPAMaskWeight.c	(revision 17730)
@@ -404,2 +404,29 @@
     return true;
 }
+
+
+
+bool pmSubtractionMaskApply(pmReadout *readout, psMaskType maskVal)
+{
+    PM_ASSERT_READOUT_NON_NULL(readout, false);
+    PM_ASSERT_READOUT_IMAGE(readout, false);
+    PM_ASSERT_READOUT_MASK(readout, false);
+
+    int numCols = image->numCols, numRows = image->numRows; // Size of image
+    psMaskType **maskData = mask->data.PS_TYPE_MASK_DATA; // Dereference mask
+    psF32 **imageData = image->data.F32;// Dereference image
+    psF32 **weightData = weight->data.F32; // Dereference weight map
+
+    for (int y = 0; y < numRows; y++) {
+        for (int x = 0; x < numCols; x++) {
+            if (maskData[y][x] & maskVal) {
+                imageData[y][x] = NAN;
+                if (weight) {
+                    weightData[y][x] = NAN;
+                }
+            }
+        }
+    }
+
+    return true;
+}
Index: trunk/psModules/src/camera/pmFPAMaskWeight.h
===================================================================
--- trunk/psModules/src/camera/pmFPAMaskWeight.h	(revision 17692)
+++ trunk/psModules/src/camera/pmFPAMaskWeight.h	(revision 17730)
@@ -5,6 +5,6 @@
  * @author Eugene Magnier, IfA
  *
- * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-05-15 03:25:10 $
+ * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2008-05-17 02:38:46 $
  * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
  */
@@ -115,4 +115,14 @@
     );
 
+/// Apply a mask to the image and weight map
+///
+/// Unfortunately, image subtraction may result in a bi-modal image in masked areas, which can upset image
+/// statistics (very important for quantising images so that a product can be written out!).  This function
+/// sets masked areas to NAN in the image and weight.
+bool pmSubtractionMaskApply(pmReadout *readout, ///< Readout to mask
+                            psMaskType maskVal ///< Mask value for which to apply mask
+    );
+
+
 /// @}
 #endif
