Index: trunk/psModules/src/camera/pmHDU.c
===================================================================
--- trunk/psModules/src/camera/pmHDU.c	(revision 9609)
+++ trunk/psModules/src/camera/pmHDU.c	(revision 9983)
@@ -124,19 +124,16 @@
 }
 
-// XXX: Add a region specifier?
-bool pmHDUWrite(pmHDU *hdu, psFits *fits)
+// Write an HDU to a FITS file
+bool hduWrite(pmHDU *hdu,               // HDU to write
+              psArray *images,          // Images to write
+              psFits *fits              // FITS file to which to write
+             )
 {
-    PS_ASSERT_PTR_NON_NULL(hdu, false);
-    PS_ASSERT_PTR_NON_NULL(fits, false);
+    assert(hdu);
+    assert(fits);
 
     psTrace("psModules.camera", 7, "Writing HDU %s\n", hdu->extname);
 
-    if (hdu->images && !hdu->header) {
-        psError(PS_ERR_IO, true, "Both image and table data provided in HDU, but no header --- "
-                "don't know which to write!\n");
-        return false;
-    }
-
-    if (!hdu->images && !hdu->header) {
+    if (!images && !hdu->header) {
         psLogMsg(__func__, PS_LOG_WARN, "Nothing to write for HDU %s\n", hdu->extname);
         return false;
@@ -154,11 +151,11 @@
 
     // Only a header
-    if (!hdu->images && !psFitsWriteBlank(fits, hdu->header, extname)) {
+    if (!images && !psFitsWriteBlank(fits, hdu->header, extname)) {
         psError(PS_ERR_IO, false, "Unable to write header for extension %s\n", extname);
     }
 
-    if (hdu->images) {
+    if (images) {
         psTrace("psModules.camera", 9, "Writing pixels for %s\n", hdu->extname);
-        if (!psFitsWriteImageCube(fits, hdu->header, hdu->images, extname)) {
+        if (!psFitsWriteImageCube(fits, hdu->header, images, extname)) {
             psError(PS_ERR_IO, false, "Unable to write image to extension %s\n", hdu->extname);
             return false;
@@ -168,2 +165,19 @@
 }
 
+// XXX: Add a region specifier?
+bool pmHDUWrite(pmHDU *hdu, psFits *fits)
+{
+    PS_ASSERT_PTR_NON_NULL(hdu, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
+    return hduWrite(hdu, hdu->images, fits);
+}
+
+bool pmHDUWriteMask(pmHDU *hdu, psFits *fits)
+{
+    PS_ASSERT_PTR_NON_NULL(hdu, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
+    return hduWrite(hdu, hdu->masks, fits);
+}
+
