Index: trunk/psModules/src/camera/pmFPAfileFitsIO.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfileFitsIO.c	(revision 7712)
+++ trunk/psModules/src/camera/pmFPAfileFitsIO.c	(revision 7726)
@@ -73,5 +73,9 @@
 
 // given an already-opened fits file, write the components corresponding
-// to the specified view
+// to the specified view. when the file was opened, pmFPA/Chip/CellWrite was
+// called on it with blank=true to write the (possible) blank PHU
+// do NOT call the functions below with blank=true or they will write
+// out data in an inconsistent fashion
+// the calls below should recurse down the element to write out all components.
 bool pmFPAviewWriteFitsImage (const pmFPAview *view, pmFPAfile *file)
 {
@@ -84,5 +88,5 @@
     // pmFPAWrite takes care of all PHUs as needed
     if (view->chip == -1) {
-        pmFPAWrite(fpa, fits, NULL, true, true);
+        pmFPAWrite(fpa, fits, NULL, false, true);
         return true;
     }
@@ -94,10 +98,46 @@
     pmChip *chip = fpa->chips->data[view->chip];
 
-
+    if (view->cell == -1) {
+        pmChipWrite (chip, fits, NULL, false, true);
+        return true;
+    }
+
+    if (view->cell >= chip->cells->n) {
+        psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %d", view->cell, chip->cells->n);
+        return false;
+    }
+    pmCell *cell = chip->cells->data[view->cell];
+
+    if (view->readout == -1) {
+        return pmCellWrite (cell, fits, NULL, false);
+    }
+    psError(PS_ERR_UNKNOWN, true, "Returning false");
+    return false;
+
+    // XXX disable readout write for now
     #if 0
-    // XXX This no longer required since we write the PHU at open.
-
-    // do we need to write out a PHU for this entry?
-    if (file->phu == NULL) {
+
+    if (view->readout >= cell->readouts->n) {
+        psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouts->n == %d",
+                view->readout, cell->readouts->n);
+        return false;
+    }
+    pmReadout *readout = cell->readouts->data[view->readout];
+
+    if (view->nRows == 0) {
+        pmReadoutWrite (readout, fits, NULL, NULL);
+    } else {
+        pmReadoutWriteSegment (readout, fits, view->nRows, view->iRows, NULL, NULL);
+    }
+    return true;
+    #endif
+}
+
+// this old code was used to write the blank by hand.
+// pmFPAWrite now takes care of this choice.
+# if 0
+// do we need to write out a PHU for this entry?
+if (file->phu == NULL)
+    {
         pmHDU *hdu = pmFPAviewThisHDU (view, file->fpa);
         pmHDU *phu = pmFPAviewThisPHU (view, file->fpa);
@@ -119,41 +159,5 @@
         }
     }
-    #endif
-
-    if (view->cell == -1) {
-        pmChipWrite (chip, fits, NULL, true, true);
-        return true;
-    }
-
-    if (view->cell >= chip->cells->n) {
-        psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %d", view->cell, chip->cells->n);
-        return false;
-    }
-    pmCell *cell = chip->cells->data[view->cell];
-
-    if (view->readout == -1) {
-        return pmCellWrite (cell, fits, NULL, true);
-    }
-    psError(PS_ERR_UNKNOWN, true, "Returning false");
-    return false;
-
-    // XXX disable readout write for now
-    #if 0
-
-    if (view->readout >= cell->readouts->n) {
-        psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouts->n == %d",
-                view->readout, cell->readouts->n);
-        return false;
-    }
-    pmReadout *readout = cell->readouts->data[view->readout];
-
-    if (view->nRows == 0) {
-        pmReadoutWrite (readout, fits, NULL, NULL);
-    } else {
-        pmReadoutWriteSegment (readout, fits, view->nRows, view->iRows, NULL, NULL);
-    }
-    return true;
-    #endif
-}
+# endif
 
 // given an already-opened fits file, read the components corresponding
