Index: /trunk/Ohana/src/libfits/include/gfitsio.h
===================================================================
--- /trunk/Ohana/src/libfits/include/gfitsio.h	(revision 15655)
+++ /trunk/Ohana/src/libfits/include/gfitsio.h	(revision 15656)
@@ -158,5 +158,5 @@
 int     gfits_extension_is_compressed  PROTO((Header *header));
 int     gfits_tile_size                PROTO((Matrix *matrix, int *otile, int *ztile));
-int     gfits_uncompressed_data_pixsize PROTO((char *cmptype));
+int     gfits_uncompressed_data_pixsize PROTO((char *cmptype, int out_bitpix));
 int     gfits_vartable_heap_pixsize    PROTO((char format));
 
Index: /trunk/Ohana/src/libfits/matrix/F_compress_M.c
===================================================================
--- /trunk/Ohana/src/libfits/matrix/F_compress_M.c	(revision 15655)
+++ /trunk/Ohana/src/libfits/matrix/F_compress_M.c	(revision 15656)
@@ -30,5 +30,5 @@
 int gfits_uncompress_image (Header *header, Matrix *matrix, FTable *ftable) {
 
-  int i, j, status, zimage, zcol, Nzrows, Nout, Nzdata, max_tile_size, bytes_per_pixel;
+  int i, j, status, zimage, zcol, Nzrows, Nout, Nzdata, max_tile_size;
   char cmptype[80];
   char zaxis[10], naxis[10], key[10], word[81], exttype[81], checksum[81], datasum[81];
@@ -183,5 +183,5 @@
 
   // size of a pixel in the output from the decompression routine
-  odata_pixsize = gfits_uncompressed_data_pixsize (cmptype);
+  odata_pixsize = gfits_uncompressed_data_pixsize (cmptype, header[0].bitpix);
   ALLOCATE (out, char, odata_pixsize*max_tile_size);
 
@@ -201,5 +201,5 @@
 
     // gfits_uncompress_data uncompresses from zdata to the temporary output buffer which must be allocated
-    if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, bytes_per_pixel)) return (FALSE);
+    if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, odata_pixsize)) return (FALSE);
 
     // copy the uncompressed pixels into their correct locations 	    
@@ -346,5 +346,5 @@
     // determine the offset of the next line relative to the start position
     offset = counter[matrix->Naxes - 1];
-    for (j = 1; j < matrix->Naxes; j++) {
+    for (j = matrix->Naxes - 2; j >= 0; j--) {
       offset = offset*matrix->Naxis[j] + counter[j];
     }      
@@ -436,17 +436,19 @@
 }
 
-int gfits_uncompressed_data_pixsize (char *cmptype) {
-
-  if (!strcasecmp(cmptype, "GZIP")) {
-    return (0);
-  }
-  if (!strcasecmp(cmptype, "RICE") || !strcasecmp(cmptype, "RICE_1")) {
+int gfits_uncompressed_data_pixsize (char *cmptype, int out_bitpix) {
+
+  if (!strcasecmp(cmptype, "GZIP_1")) {
     return (4);
   }
-  if (!strcasecmp(cmptype, "PLIO")) {
+  if (!strcasecmp(cmptype, "RICE_1")) {
+    return (4);
+  }
+  if (!strcasecmp(cmptype, "PLIO_1")) {
     return (1);
   }
-  if (!strcasecmp(cmptype, "HCOMPRESS")) {
-    return (4);
+  if (!strcasecmp(cmptype, "HCOMPRESS_1")) {
+    if (out_bitpix == 8)  return (4);
+    if (out_bitpix == 16) return (4);
+    return (8);
   }
   return (0);
Index: /trunk/Ohana/src/libfits/matrix/F_uncompress_data.c
===================================================================
--- /trunk/Ohana/src/libfits/matrix/F_uncompress_data.c	(revision 15655)
+++ /trunk/Ohana/src/libfits/matrix/F_uncompress_data.c	(revision 15656)
@@ -26,6 +26,6 @@
   static int Noutsum = 0;
 
-  if (!strcasecmp(cmptype, "GZIP")) {
-    unsigned long tNout = *Nout;
+  if (!strcasecmp(cmptype, "GZIP_1")) {
+    unsigned long tNout = *Nout * out_pixsize;
     // uncompress does not require us to know the expected number of pixel; it tells us the number
     status = uncompress ((Bytef *) outdata, &tNout, (Bytef *) zdata, Nzdata);
@@ -38,5 +38,5 @@
   }
 
-  if (!strcasecmp(cmptype, "RICE") || !strcasecmp(cmptype, "RICE_1")) {
+  if (!strcasecmp(cmptype, "RICE_1")) {
     int i, blocksize;
     // look for the BLOCKSIZE
@@ -69,7 +69,7 @@
   }
   
-  if (!strcasecmp(cmptype, "PLIO")) {
+  if (!strcasecmp(cmptype, "PLIO_1")) {
     int Npix;
-    Npix = pl_l2pi ((short *) zdata, 0, (int *) outdata, *Nout);
+    Npix = pl_l2pi ((short *) zdata, 1, (int *) outdata, *Nout);
     if (Npix != *Nout) {
       fprintf (stderr, "error in plio decompression\n");
@@ -79,5 +79,5 @@
   }
 
-  if (!strcasecmp(cmptype, "HCOMPRESS")) {
+  if (!strcasecmp(cmptype, "HCOMPRESS_1")) {
     int Nx, Ny, scale;
     status = 0;
