Index: trunk/psModules/src/camera/pmFPAfileIO.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfileIO.c	(revision 18330)
+++ trunk/psModules/src/camera/pmFPAfileIO.c	(revision 18554)
@@ -9,4 +9,5 @@
 
 #include "pmConfig.h"
+#include "pmConfigMask.h"
 #include "pmDetrendDB.h"
 
@@ -428,4 +429,13 @@
             }
             pmConfigConformHeader(hdu->header, file->format);
+
+	    // whenever we write out a mask image, we should define the bits which represent mask concepts
+	    if (file->type == PM_FPA_FILE_MASK) {
+		assert (hdu->header);
+		if (!pmConfigMaskWriteHeader (config, hdu->header)) {
+		    psError(PS_ERR_UNKNOWN, false, "failed to set the bitmask names in the PHU header for Image %s (%s)\n", file->filename, file->name);
+		    return false;
+		}
+	    }
         }
 
@@ -792,4 +802,13 @@
           }
 
+	  // XXX if we have a mask file, then we need to read the mask bit names
+	  // defined for this file
+	  if (file->type == PM_FPA_FILE_MASK) {
+	    if (!pmConfigMaskReadHeader (config, phu)) {
+		psError(PS_ERR_IO, false, "error in mask bits");
+		return false;
+	    }
+	  }
+
           // determine the current format from the header
           // determine camera if not specified already
