Index: trunk/psModules/src/objects/pmSourceIO_CMP.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_CMP.c	(revision 7306)
+++ trunk/psModules/src/objects/pmSourceIO_CMP.c	(revision 7311)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-03 00:40:46 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-03 01:02:08 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -69,11 +69,29 @@
 
     psFits *fits = psFitsOpen (filename, "w");
-    psFitsWriteBlank(fits, header);
-    psFitsClose (fits);
+    if (fits == NULL) {
+        psError(PS_ERR_IO, false, "can't open output file for write %s\n", filename);
+        return false;
+    }
+    if (!psFitsWriteBlank(fits, header)) {
+        psError(PS_ERR_IO, false, "Writing header to %s\n", filename);
+        (void)psFitsClose(fits);
+        return false;
+    }
+    if (!psFitsClose(fits)) {
+        const psErrorCode code = psErrorCodeLast();
+
+        if (code == PS_ERR_BAD_FITS) {
+            psErrorClear();
+        } else {
+            psError(PS_ERR_IO, false, "Closing %s\n", filename);
+            return false;
+        }
+    }
 
     // re-open, add data to end of file
     FILE *f = fopen (filename, "a+");
     if (f == NULL) {
-        psLogMsg ("WriteSourceOBJ", 3, "can't open output file for output %s\n", filename);
+        psLogMsg ("WriteSourceOBJ", 3, "can't reopen output file for append %s\n", filename);
+        psError(PS_ERR_IO, false, "can't open output file for output %s\n", filename);
         return false;
     }
