Index: trunk/psModules/src/camera/pmHDU.c
===================================================================
--- trunk/psModules/src/camera/pmHDU.c	(revision 9983)
+++ trunk/psModules/src/camera/pmHDU.c	(revision 10081)
@@ -85,5 +85,5 @@
     if (!hdu->header) {
         psTrace("psModules.camera", 5, "Reading the header...\n");
-        hdu->header = psFitsReadHeader(NULL, fits);
+        hdu->header = psFitsReadHeader(hdu->header, fits);
         if (! hdu->header) {
             psError(PS_ERR_IO, false, "Unable to read header for extension %s\n", hdu->extname);
@@ -95,9 +95,14 @@
 }
 
+// Read an HDU from a FITS file
 // XXX: Add a region specifier?
-bool pmHDURead(pmHDU *hdu, psFits *fits)
-{
-    PS_ASSERT_PTR_NON_NULL(hdu, false);
-    PS_ASSERT_PTR_NON_NULL(fits, false);
+bool hduRead(pmHDU *hdu,                // HDU to write
+             psArray **images,          // Images into which to read
+             psFits *fits               // FITS file to read
+            )
+{
+    assert(hdu);
+    assert(images);
+    assert(fits);
 
     // Read the header; includes the move
@@ -111,11 +116,11 @@
     }
 
-    if (hdu->images) {
+    if (*images) {
         psLogMsg(__func__, PS_LOG_WARN, "HDU %s has already been read --- overwriting.\n", hdu->extname);
-        psFree(hdu->images);        // Blow away anything existing
+        psFree(*images);                // Blow away anything existing
     }
     psTrace("psModules.camera", 5, "Reading the pixels...\n");
-    hdu->images = psFitsReadImageCube(fits, psRegionSet(0,0,0,0));
-    if (! hdu->images) {
+    *images = psFitsReadImageCube(fits, psRegionSet(0,0,0,0));
+    if (!*images) {
         psError(PS_ERR_IO, false, "Unable to read pixels for extension %s\n", hdu->extname);
         return false;
@@ -124,9 +129,33 @@
 }
 
+bool pmHDURead(pmHDU *hdu, psFits *fits)
+{
+    PS_ASSERT_PTR_NON_NULL(hdu, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
+    return hduRead(hdu, &hdu->images, fits);
+}
+
+bool pmHDUReadMask(pmHDU *hdu, psFits *fits)
+{
+    PS_ASSERT_PTR_NON_NULL(hdu, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
+    return hduRead(hdu, &hdu->masks, fits);
+}
+
+bool pmHDUReadWeight(pmHDU *hdu, psFits *fits)
+{
+    PS_ASSERT_PTR_NON_NULL(hdu, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
+    return hduRead(hdu, &hdu->weights, 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
-             )
+static bool hduWrite(pmHDU *hdu,        // HDU to write
+                     psArray *images,   // Images to write
+                     psFits *fits       // FITS file to which to write
+                    )
 {
     assert(hdu);
@@ -182,2 +211,9 @@
 }
 
+bool pmHDUWriteWeight(pmHDU *hdu, psFits *fits)
+{
+    PS_ASSERT_PTR_NON_NULL(hdu, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
+    return hduWrite(hdu, hdu->weights, fits);
+}
