Index: trunk/psLib/src/fits/psFits.c
===================================================================
--- trunk/psLib/src/fits/psFits.c	(revision 6354)
+++ trunk/psLib/src/fits/psFits.c	(revision 6767)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.52 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-02-08 01:03:34 $
+ *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-04 19:52:42 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -166,4 +166,5 @@
             psFits* fits = psAlloc(sizeof(psFits));
         fits->fd = fptr;
+        fits->writable = (iomode == READWRITE);
         psMemSetDeallocator(fits,(psFreeFunc)fitsFree);
 
@@ -252,6 +253,10 @@
             return false;
         }
-
-        return psFitsMoveExtNum(fits,psFitsGetSize(fits),false);
+        int size = psFitsGetSize(fits);
+        if (size == 0) { // empty file -- no action needed
+            return true;
+        } else {
+            return psFitsMoveExtNum(fits,size-1,false);
+        }
     }
 
@@ -329,4 +334,10 @@
         }
 
+        if (! fits->writable) {
+            psError(PS_ERR_IO, true,
+                    PS_ERRORTEXT_psFits_NOT_WRITABLE);
+            return false;
+        }
+
         // move to the specified HDU
         if (! psFitsMoveExtNum(fits,extnum,relative) ) {
@@ -361,4 +372,10 @@
         }
 
+        if (! fits->writable) {
+            psError(PS_ERR_IO, true,
+                    PS_ERRORTEXT_psFits_NOT_WRITABLE);
+            return false;
+        }
+
         // move to the specified HDU
         if (! psFitsMoveExtName(fits,extname) ) {
@@ -442,4 +459,10 @@
             psError(PS_ERR_BAD_PARAMETER_NULL, true,
                     PS_ERRORTEXT_psFits_NULL);
+            return PS_FITS_TYPE_NONE;
+        }
+
+        if (! fits->writable) {
+            psError(PS_ERR_IO, true,
+                    PS_ERRORTEXT_psFits_NOT_WRITABLE);
             return PS_FITS_TYPE_NONE;
         }
