Index: /branches/pap_branch_20090128/psModules/src/camera/pmFPARead.c
===================================================================
--- /branches/pap_branch_20090128/psModules/src/camera/pmFPARead.c	(revision 21271)
+++ /branches/pap_branch_20090128/psModules/src/camera/pmFPARead.c	(revision 21272)
@@ -195,4 +195,25 @@
 
     return naxis3;
+}
+
+// Determine whether a FITS file contains covariance matrices
+static bool hduCovariance(pmHDU *hdu,   // Header data unit
+                          psFits *fits  // FITS file
+    )
+{
+    if (!psFitsMoveExtName(fits, hdu->extname)) {
+        psError(PS_ERR_IO, false, "Unable to move to extension %s", hdu->extname);
+        return false;
+    }
+    // Need to explicitly read the header, since the HDU may not contain the variance header
+    psMetadata *header = psFitsReadHeader(NULL, fits); // Header
+    if (!header) {
+        psError(PS_ERR_IO, false, "Unable to read variance header.");
+        return false;
+    }
+    bool mdok;                          // Status of MD lookup
+    bool covar = psMetadataLookupBool(&mdok, header, PM_HDU_COVARIANCE_KEYWORD); // Got covariance?
+    psFree(header);
+    return covar;
 }
 
@@ -521,9 +542,16 @@
     switch (type) {
       case FPA_READ_TYPE_MASK: {
-          pmHDU *phu = pmHDUGetHighest(cell->parent->parent, cell->parent, cell); // Primary header
-          if (!pmConfigMaskReadHeader(config, phu->header)) {
-              psError(PS_ERR_IO, false, "Unable to determine mask bits");
+          // Need to explicitly read the header, since what's in the pmHDU may not correspond to the mask
+          psMetadata *header = psFitsReadHeader(NULL, fits);
+          if (!header) {
+              psError(PS_ERR_IO, false, "Unable to read mask header.");
               return false;
           }
+          if (!pmConfigMaskReadHeader(config, header)) {
+              psError(PS_ERR_IO, false, "Unable to determine mask bits");
+              psFree(header);
+              return false;
+          }
+          psFree(header);
           bad = pmConfigMaskGet("BAD", config);
           break;
@@ -1142,5 +1170,9 @@
         return false;
     }
-    return pmCellReadCovariance(cell, fits);
+    pmHDU *hdu = pmHDUFromCell(cell);   // Header data unit
+    if (hduCovariance(hdu, fits)) {
+        return pmCellReadCovariance(cell, fits);
+    }
+    return true;
 }
 
@@ -1153,5 +1185,9 @@
         return false;
     }
-    return pmChipReadCovariance(chip, fits);
+    pmHDU *hdu = pmHDUFromChip(chip);   // Header data unit
+    if (hduCovariance(hdu, fits)) {
+        return pmChipReadCovariance(chip, fits);
+    }
+    return true;
 }
 
@@ -1164,5 +1200,9 @@
         return false;
     }
-    return pmFPAReadCovariance(fpa, fits);
+    pmHDU *hdu = pmHDUFromFPA(fpa);     // Header data unit
+    if (hduCovariance(hdu, fits)) {
+        return pmFPAReadCovariance(fpa, fits);
+    }
+    return true;
 }
 
