Index: trunk/psModules/src/camera/pmFPAfileIO.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfileIO.c	(revision 18554)
+++ trunk/psModules/src/camera/pmFPAfileIO.c	(revision 18601)
@@ -405,64 +405,7 @@
     }
 
-    // check if the file is a FITS file (or uses the fits header)
-    bool fitsType = false;
-    fitsType |= (file->type == PM_FPA_FILE_IMAGE);
-    fitsType |= (file->type == PM_FPA_FILE_MASK);
-    fitsType |= (file->type == PM_FPA_FILE_WEIGHT);
-    fitsType |= (file->type == PM_FPA_FILE_HEADER);
-    fitsType |= (file->type == PM_FPA_FILE_FRINGE);
-    fitsType |= (file->type == PM_FPA_FILE_DARK);
-    fitsType |= (file->type == PM_FPA_FILE_CMP);
-    fitsType |= (file->type == PM_FPA_FILE_CMF);
-    fitsType |= (file->type == PM_FPA_FILE_PSF);
-    fitsType |= (file->type == PM_FPA_FILE_ASTROM_MODEL);
-    fitsType |= (file->type == PM_FPA_FILE_ASTROM_REFSTARS);
-
-    // Ensure headers and all are updated
-    // This is here so that the individual write functions (e.g., images, PSFs, sources, etc) don't have to
-    // take care of all this themselves (because they generally don't).
-    if (fitsType) {
-        pmHDU *hdu = pmFPAviewThisHDU(view, file->fpa);
-        if (hdu) {
-            if (!hdu->header) {
-                hdu->header = psMetadataAlloc();
-            }
-            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;
-		}
-	    }
-        }
-
-        pmFPA *fpa = file->fpa;         // FPA of interest
-        pmChip *chip = pmFPAviewThisChip(view, file->fpa); // Chip of interest, or NULL
-        pmCell *cell = pmFPAviewThisCell(view, file->fpa); // Cell of interest, or NULL
-        if (!pmFPAUpdateNames(fpa, chip, cell)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to update names in header.");
-            return false;
-        }
-
-        pmConceptSource sources = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS |
-            PM_CONCEPT_SOURCE_DEFAULTS | PM_CONCEPT_SOURCE_DATABASE; // Concept sources to write
-        if (cell) {
-            if (!pmConceptsWriteCell(cell, sources, true, config)) {
-                psError(PS_ERR_IO, false, "Unable to write concepts for cell.\n");
-                return false;
-            }
-        } else if (chip) {
-            if (!pmConceptsWriteChip(chip, sources, true, true, config)) {
-                psError(PS_ERR_IO, false, "Unable to write concepts for chip.\n");
-                return false;
-            }
-        } else if (!pmConceptsWriteFPA(fpa, sources, true, config)) {
-            psError(PS_ERR_IO, false, "Unable to write concepts for FPA.\n");
-            return false;
-        }
-    }
+    // IMPORTANT: If adding a FITS-based file, make sure your write function uses an FPA produced by
+    // pmFPAfileSuitableFPA.  This ensures the HDUs are at the correct level for your output format, and sets
+    // the headers correctly.
 
     // select a writing method
@@ -487,5 +430,5 @@
         status = pmFPAviewWriteFitsImage (view, file, config);
         if (status) {
-            if (!pmFPAviewWriteFitsTable(view, file, "FRINGE")) {
+            if (!pmFPAviewWriteFitsTable(view, file, "FRINGE", config)) {
                 psError(PS_ERR_UNKNOWN, false, "Unable to write fringe data from %s.\n", file->filename);
                 return false;
@@ -802,12 +745,12 @@
           }
 
-	  // 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;
-	    }
-	  }
+          // 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
