Index: trunk/psLib/src/fits/psFitsHeader.c
===================================================================
--- trunk/psLib/src/fits/psFitsHeader.c	(revision 7226)
+++ trunk/psLib/src/fits/psFitsHeader.c	(revision 7227)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-05-26 02:48:47 $
+ *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-05-26 03:24:49 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -218,8 +218,11 @@
 }
 
-bool psFitsWriteHeader(psMetadata* output,
-                       psFits* fits)
-{
-
+
+// Do the work of writing out the header.
+// Doesn't check to see if a new HDU needs to be created
+bool p_psFitsWriteHeader(psMetadata *output, // Metadata that is to be output into the FITS file
+                         psFits *fits   // The FITS file handle
+                        )
+{
     if (!fits) {
         psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_NULL);
@@ -230,19 +233,4 @@
         psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_METADATA_NULL);
         return false;
-    }
-
-    int status = 0;                     // Status of cfitsio calls
-
-    // Check to see if there are any extant HDUs
-    int hdus = psFitsGetSize(fits);     // Number of HDUs
-    if (hdus == 0) {
-        // Need to create a dummy image HDU for the primary HDU
-        fits_create_img(fits->fd, 16, 0, NULL, &status);
-        if (status) {
-            char fitsErr[MAX_STRING_LENGTH];
-            (void)fits_get_errstatus(status, fitsErr);
-            psError(PS_ERR_IO, true, "Unable to create primary header.\n%s\n", fitsErr);
-            return false;
-        }
     }
 
@@ -250,4 +238,5 @@
     psListIterator* iter = psListIteratorAlloc(output->list, PS_LIST_HEAD, true); // Iterator
     psMetadataItem* item;               // Item from iteration
+    int status = 0;                     // Status of cfitsio calls
     while ((item = psListGetAndIncrement(iter))) {
         // Check to see if the item should be ignored
@@ -325,4 +314,34 @@
 }
 
+bool psFitsWriteHeader(psMetadata* output,
+                       psFits* fits)
+{
+    if (!fits) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_NULL);
+        return false;
+    }
+
+    if (!output) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_METADATA_NULL);
+        return false;
+    }
+
+    // Check to see if there are any extant HDUs
+    int hdus = psFitsGetSize(fits);     // Number of HDUs
+    if (hdus == 0) {
+        // Need to create a dummy image HDU for the primary HDU
+        int status = 0;                 // Status of cfitsio
+        fits_create_img(fits->fd, 16, 0, NULL, &status);
+        if (status) {
+            char fitsErr[MAX_STRING_LENGTH];
+            (void)fits_get_errstatus(status, fitsErr);
+            psError(PS_ERR_IO, true, "Unable to create primary header.\n%s\n", fitsErr);
+            return false;
+        }
+    }
+
+    return p_psFitsWriteHeader(output, fits);
+}
+
 bool psFitsHeaderValidate(psMetadata *header)
 {
