Index: /trunk/psLib/src/fits/psFitsHeader.c
===================================================================
--- /trunk/psLib/src/fits/psFitsHeader.c	(revision 7294)
+++ /trunk/psLib/src/fits/psFitsHeader.c	(revision 7295)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-02 03:27:46 $
+ *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-02 19:50:48 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -254,23 +254,30 @@
     psMetadataItem* item;               // Item from iteration
     int status = 0;                     // Status of cfitsio calls
+    bool simple = true;                 // If SIMPLE is T, then the file should conform to the FITS standard
     while ((item = psListGetAndIncrement(iter))) {
+        // We allow the user to write SIMPLE, but it must be boolean
+        if (strcmp(item->name, "SIMPLE") == 0) {
+            if (item->type != PS_DATA_BOOL) {
+                psError(PS_ERR_BAD_PARAMETER_TYPE, true, "SIMPLE in a FITS header must be of boolean type: "
+                        "not %x --- assuming FALSE.\n", item->type);
+                int value = false;      // Temporary
+                fits_update_key(fits->fd, TLOGICAL, "SIMPLE", &value,
+                                "File does not conform to FITS standard", &status);
+                simple = false;
+                continue;
+            } else if (! item->data.B) {
+                simple = false;
+            }
+        }
+
         // Check to see if the item should be ignored
-        // We ignore particular (required) keywords, because these are written by CFITSIO
-        // Furthermore, users tend to supply FITS headers that are wrong (e.g., after binning down the
-        // image, the NAXISn haven't been changed; or after converting to F32, the BITPIX hasn't been changed)
-        // so we'll take care of that for them.
-        bool writeKey = true;           // Should we write this keyword?
-        for (int i = 0; noWriteFitsKeys[i] && writeKey; i++) {
-            if (strcmp(item->name, noWriteFitsKeys[i]) == 0) {
-                writeKey = false;
-            }
-        }
-        if (keyStarts) {
-            // Also block out TTYPEn, NAXISn, etc --- keywords that start with a certain sequence.
-            // We want to do this when writing an image or table, since it guarantees that the NAXISn etc
-            // that go in are correct.  However, when we're writing a "blank" HDU (header only), we want to
-            // preserve NAXISn etc for reference, so we don't do this.
-            for (int i = 0; noWriteFitsKeyStarts[i] && writeKey; i++) {
-                if (strncmp(item->name, noWriteFitsKeyStarts[i], strlen(noWriteFitsKeyStarts[i])) == 0) {
+        if (simple) {
+            // We ignore particular (required) keywords, because these are written by CFITSIO
+            // Furthermore, users tend to supply FITS headers that are wrong (e.g., after binning down the
+            // image, the NAXISn haven't been changed; or after converting to F32, the BITPIX hasn't been
+            // changed) so we'll take care of that for them.
+            bool writeKey = true;           // Should we write this keyword?
+            for (int i = 0; noWriteFitsKeys[i] && writeKey; i++) {
+                if (strcmp(item->name, noWriteFitsKeys[i]) == 0) {
                     writeKey = false;
                 }
@@ -280,11 +287,19 @@
                 continue;
             }
-        }
-
-        // We allow the user to write SIMPLE, but it must be boolean
-        if (strcmp(item->name, "SIMPLE") == 0 && item->type != PS_DATA_BOOL) {
-            psError(PS_ERR_BAD_PARAMETER_TYPE, true, "SIMPLE in a FITS header must be of boolean type: not "
-                    "%x --- ignored.\n", item->type);
-            continue;
+            if (keyStarts) {
+                // Also block out TTYPEn, NAXISn, etc --- keywords that start with a certain sequence.
+                // We want to do this when writing an image or table, since it guarantees that the NAXISn etc
+                // that go in are correct.  However, when we're writing a "blank" HDU (header only), we want
+                // to preserve NAXISn etc for reference, so we don't do this.
+                for (int i = 0; noWriteFitsKeyStarts[i] && writeKey; i++) {
+                    if (strncmp(item->name, noWriteFitsKeyStarts[i], strlen(noWriteFitsKeyStarts[i])) == 0) {
+                        writeKey = false;
+                    }
+                }
+                if (!writeKey) {
+                    // Don't write it; skip to the next key
+                    continue;
+                }
+            }
         }
 
@@ -349,4 +364,6 @@
             break;
         default:  // all other META types are ignored
+            psLogMsg(__func__, PS_LOG_WARN, "Attempt to write metadata type %x to FITS header ignored.\n",
+                     item->type);
             break;
         }
