Index: /trunk/psLib/src/fits/psFitsImage.c
===================================================================
--- /trunk/psLib/src/fits/psFitsImage.c	(revision 21534)
+++ /trunk/psLib/src/fits/psFitsImage.c	(revision 21535)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-01-27 06:39:37 $
+ *  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-19 03:15:40 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -266,5 +266,23 @@
     *floatType = PS_FITS_FLOAT_NONE;
 
-    psFitsOptions *options = fits->options;
+    psFitsOptions *options = fits->options; // Options for FITS writing
+
+    // Can't PLIO compress U16,U32,U64 directly, so convert them
+    if (psFitsCompressionGetType(fits) == PS_FITS_COMPRESS_PLIO && (!options || options->bitpix == 0)) {
+        switch (image->type.type) {
+          case PS_TYPE_U16:
+            return psImageCopy(NULL, image, PS_TYPE_S32);
+          case PS_TYPE_U32:
+            return psImageCopy(NULL, image, PS_TYPE_S64);
+          case PS_TYPE_U64:
+            // Conversion would result in numerical overflow
+            psError(PS_ERR_IO, true, "Unable to compress U64 images");
+            return NULL;
+          default:
+            // No action
+            ;
+        }
+    }
+
     if (!options) {
         return psMemIncrRefCounter((psImage*)image); // Casting away const
