Index: /branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_M.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_M.c	(revision 38362)
+++ /branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_M.c	(revision 38363)
@@ -173,6 +173,8 @@
 
   // size of a pixel in the image tile -- this is probably not needed
-  // int tile_pixsize = abs(header[0].bitpix) / 8;
-  // fprintf (stderr, "raw_pixsize: %d, cmp_pixsize: %d, tile_pixsize: %d, raw_bitpix: %d\n", raw_pixsize, cmp_pixsize, tile_pixsize, raw_bitpix);
+# if VERBOSE_DUMP
+  int tile_pixsize = abs(header[0].bitpix) / 8;
+  fprintf (stderr, "raw_pixsize: %d, cmp_pixsize: %d, tile_pixsize: %d, raw_bitpix: %d\n", raw_pixsize, cmp_pixsize, tile_pixsize, raw_bitpix);
+# endif
 
   // allocate the buffer for compression work
@@ -210,6 +212,6 @@
 
     // gzip compresses bytes which are in BIG-ENDIAN order
+    // Nraw is number of pixels
     if (!strcasecmp(zcmptype, "GZIP_1")) {
-      // Nraw is number of pixels
       if (!gfits_byteswap_zdata (raw, Nraw * raw_pixsize, raw_pixsize)) ESCAPE;
     }
@@ -238,5 +240,5 @@
     // compression modes require swapping after compression (compresssion & decompression
     // operate on native ENDIAN)
-    if (strcasecmp(zcmptype, "GZIP_1") && strcasecmp(zcmptype, "GZIP_2")) {
+    if (strcasecmp(zcmptype, "GZIP_1") && strcasecmp(zcmptype, "GZIP_2") && strcasecmp(zcmptype, "RICE_1")) {
       // Nzdata is number of bytes
       if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
Index: /branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_M.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_M.c	(revision 38362)
+++ /branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_M.c	(revision 38363)
@@ -284,5 +284,5 @@
     }
 
-    if (strcasecmp(cmptype, "GZIP_1")) {
+    if (strcasecmp(cmptype, "GZIP_1") && strcasecmp(cmptype, "GZIP_2") && strcasecmp(cmptype, "RICE_1")) {
       // Nzdata is number of bytes
       if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
Index: /branches/eam_branches/ohana.20150429/src/libfits/table/F_compress_T.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/libfits/table/F_compress_T.c	(revision 38362)
+++ /branches/eam_branches/ohana.20150429/src/libfits/table/F_compress_T.c	(revision 38363)
@@ -18,7 +18,8 @@
 // we do not try to support compression of an image with an associated table (not valid)
 
-# define ESCAPE(A) { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; }
-
-int gfits_collect_table_data (FTable *table, char *raw, int col, int row_start, int Nrows, int rowsize);
+# define ESCAPE { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; }
+
+int gfits_collect_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows);
+int gfits_collect_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows);
 
 int gfits_compress_table (FTable *srctable, FTable *tgttable, int ztilelen, char *zcmptype) {
@@ -50,8 +51,8 @@
 
   // creates an empty (Naxes = 2, Naxis[i] = 0) table header with XTENSION = BINTABLE, EXTNAME = COMPRESSED_TABLE
-  if (!gfits_create_table_header (tgtheader, "BINTABLE", extname)) ESCAPE(A);
+  if (!gfits_create_table_header (tgtheader, "BINTABLE", extname)) ESCAPE;
 
   int Nfields;
-  if (!gfits_scan (srcheader, "TFIELDS", "%d", 1, &Nfields)) ESCAPE(A);
+  if (!gfits_scan (srcheader, "TFIELDS", "%d", 1, &Nfields)) ESCAPE;
 
   TableField *fields = NULL;
@@ -59,6 +60,6 @@
   for (i = 0; i < Nfields; i++) {
     snprintf (keyword, 80, "TTYPE%d", i+1);
-    if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE(A);
-    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].ttype_cmt)) ESCAPE(A);
+    if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE;
+    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].ttype_cmt)) ESCAPE;
 
     // TUNIT is not mandatory
@@ -67,10 +68,10 @@
       fields[i].tunit[0] = 0;
     } else {
-      if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tunit_cmt)) ESCAPE(A);
+      if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tunit_cmt)) ESCAPE;
     }
     
     snprintf (keyword, 80, "TFORM%d", i+1);
-    if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE(A);
-    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE(A);
+    if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE;
+    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE;
 
     // XXX this should depend on the field type, but for now just use a single type (GZIP_1)
@@ -78,12 +79,12 @@
 
     // by using "P" format, we are limited to 32bit pointers (2GB heap)
-    if (!gfits_define_bintable_column (tgtheader, "1QB(0)", fields[i].ttype, fields[i].ttype_cmt, fields[i].tunit, 1.0, 0.0)) ESCAPE (A);
+    if (!gfits_define_bintable_column (tgtheader, "1QB(0)", fields[i].ttype, fields[i].ttype_cmt, fields[i].tunit, 1.0, 0.0)) ESCAPE;
   }    
 
   // allocates the default data array (tgttable->buffer)
-  if (!gfits_create_table (tgtheader, tgttable)) ESCAPE (A);
+  if (!gfits_create_table (tgtheader, tgttable)) ESCAPE;
 
   // copy original header to output header (XXX this needs to be finished)
-  if (!gfits_copy_keywords_compress (srcheader, tgtheader)) ESCAPE (A);
+  if (!gfits_copy_keywords_compress (srcheader, tgtheader)) ESCAPE;
   
   // this allocates the pointer data array for the full set of tiles (NOT the heap)
@@ -91,24 +92,24 @@
   ALLOCATE_ZERO (tmpbuffer, char, 16*Ntile); // need space for Ntile entries, each of width 16 bytes (2 long)
   for (i = 0; i < Nfields; i++) {
-    if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, tmpbuffer, Ntile)) ESCAPE (A);
+    if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, tmpbuffer, Ntile)) ESCAPE;
   }
   free (tmpbuffer);
     
   // add ZIMAGE from output header
-  if (!gfits_modify_alt (tgtheader, "ZTABLE", "%t", 1, TRUE)) ESCAPE (A);
+  if (!gfits_modify_alt (tgtheader, "ZTABLE", "%t", 1, TRUE)) ESCAPE;
 
   // define compression-specific keywords, update header as needed.
-  if (!gfits_modify (tgtheader, "ZTILELEN", "%d", 1, ztilelen)) ESCAPE(A);
-
-  if (!gfits_modify (tgtheader, "ZNAXIS1", OFF_T_FMT, 1, srcheader->Naxis[0])) ESCAPE (A);
-  if (!gfits_modify (tgtheader, "ZNAXIS2", OFF_T_FMT, 1, srcheader->Naxis[1])) ESCAPE (A);
+  if (!gfits_modify (tgtheader, "ZTILELEN", "%d", 1, ztilelen)) ESCAPE;
+
+  if (!gfits_modify (tgtheader, "ZNAXIS1", OFF_T_FMT, 1, srcheader->Naxis[0])) ESCAPE;
+  if (!gfits_modify (tgtheader, "ZNAXIS2", OFF_T_FMT, 1, srcheader->Naxis[1])) ESCAPE;
 
   off_t pcount;
-  if (!gfits_scan (srcheader, "PCOUNT", OFF_T_FMT, 1, &pcount)) ESCAPE (A);
-  if (!gfits_modify (tgtheader, "ZPCOUNT", OFF_T_FMT, 1, pcount)) ESCAPE (A);
+  if (!gfits_scan (srcheader, "PCOUNT", OFF_T_FMT, 1, &pcount)) ESCAPE;
+  if (!gfits_modify (tgtheader, "ZPCOUNT", OFF_T_FMT, 1, pcount)) ESCAPE;
 
   off_t theap;
   if (gfits_scan (srcheader, "THEAP", OFF_T_FMT, 1, &theap)) {
-    if (!gfits_modify (tgtheader, "ZTHEAP", OFF_T_FMT, 1, theap)) ESCAPE (A);
+    if (!gfits_modify (tgtheader, "ZTHEAP", OFF_T_FMT, 1, theap)) ESCAPE;
   }
   
@@ -118,7 +119,7 @@
   for (i = 0; i < Nfields; i++) {
     snprintf (keyword, 81, "ZFORM%d", i+1);
-    if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE (A);
-    if (!gfits_varlength_column_define (tgttable, &fields[i].zdef, i+1)) ESCAPE(A);
-    if (!gfits_bintable_format (fields[i].tformat, fields[i].datatype, &fields[i].Nvalues, &fields[i].pixsize)) ESCAPE(A); // 
+    if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE;
+    if (!gfits_varlength_column_define (tgttable, &fields[i].zdef, i+1)) ESCAPE;
+    if (!gfits_bintable_format (fields[i].tformat, fields[i].datatype, &fields[i].Nvalues, &fields[i].pixsize)) ESCAPE; // 
     fields[i].rowsize = fields[i].Nvalues*fields[i].pixsize;
     max_width = MAX(max_width, fields[i].rowsize);
@@ -126,5 +127,5 @@
     // compression type per column (XXX for now we are just using zcmptype, as set above)
     snprintf (keyword, 81, "ZCTYP%d", i+1);
-    if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[i].zctype)) ESCAPE (A);
+    if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[i].zctype)) ESCAPE;
 
     fields[i].offset = offset;
@@ -151,5 +152,9 @@
 
       // copy the raw pixels from their native matrix locations to the temporary output buffer
-      if (!gfits_collect_table_data (srctable, raw, fields[j].offset, row_start, Nrows, fields[j].rowsize)) ESCAPE(A);
+      if (!strcasecmp(fields[i].zctype, "GZIP_2")) {
+	if (!gfits_collect_table_gzp2 (srctable, &fields[j], raw, row_start, Nrows)) ESCAPE;
+      } else {
+	if (!gfits_collect_table_data (srctable, &fields[j], raw, row_start, Nrows)) ESCAPE;
+      }
       
       // optname, optvalue = NULL, Noptions = 0
@@ -157,19 +162,20 @@
       int Nraw = Nrows*fields[j].Nvalues; // number of pixels
       if (!strcmp(fields[j].zctype, "GZIP_1")) {
-	if (!gfits_byteswap_zdata (raw, Nraw * fields[j].pixsize, fields[j].pixsize)) ESCAPE(A);
+	if (!gfits_byteswap_zdata (raw, Nraw * fields[j].pixsize, fields[j].pixsize)) ESCAPE;
       }
 
       int Nzdata = Nzdata_alloc; // available space, replaced with actual output size on compression
-      if (!gfits_compress_data (zdata, &Nzdata, fields[j].zctype, NULL, NULL, 0, raw, Nraw, fields[j].pixsize, 0, 0)) ESCAPE(A);
+      if (!gfits_compress_data (zdata, &Nzdata, fields[j].zctype, NULL, NULL, 0, raw, Nraw, fields[j].pixsize, 0, 0)) ESCAPE;
       
-      if (!gfits_varlength_column_add_data (tgttable, zdata, Nzdata, i, &fields[j].zdef)) ESCAPE(A);
-      
-      // XXX need to activate
-      // if (FALSE) gfits_byteswap_zdata (zdata, Nzdata, zdata_pixsize) ESCAPE(A);
+      if (strcasecmp(fields[j].zctype, "GZIP_1") && strcasecmp(fields[j].zctype, "GZIP_2") && strcasecmp(fields[j].zctype, "RICE_1")) {
+	if (!gfits_byteswap_zdata (zdata, Nzdata, fields[j].pixsize)) ESCAPE;
+      }
+
+      if (!gfits_varlength_column_add_data (tgttable, zdata, Nzdata, i, &fields[j].zdef)) ESCAPE;
     }
   }
 
   for (i = 0; i < Nfields; i++) {
-    if (!gfits_varlength_column_finish (tgttable, &fields[i].zdef)) ESCAPE(A);
+    if (!gfits_varlength_column_finish (tgttable, &fields[i].zdef)) ESCAPE;
   }
 
@@ -190,5 +196,5 @@
 // raw_pixsize is the bytes / pixel for the input matrix
 // place the raw image bytes for the current tile into the tile buffer
-int gfits_collect_table_data (FTable *table, char *raw, int col, int row_start, int Nrows, int rowsize) {
+int gfits_collect_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows) {
 
   off_t i;
@@ -201,7 +207,7 @@
   for (i = 0; i < Nrows; i++) {
     int row = row_start + i;
-    memcpy (&raw[i*rowsize], &table->buffer[Nx*row + col], rowsize);
+    memcpy (&raw[i*field->rowsize], &table->buffer[Nx*row + field->offset], field->rowsize);
 # if (VERBOSE)
-    int j; for (j = 0; j < rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + col + j]);
+    int j; for (j = 0; j < field->rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + field->offset + j]);
 # endif
   }
@@ -210,2 +216,24 @@
   return (TRUE);
 }
+
+int gfits_collect_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows) {
+
+  off_t i, j, k;
+
+  // we are copying NN rows into the column which starts at XX and has MM bytes per row
+
+  off_t Nx = table->header->Naxis[0];
+
+  for (k = 0; k < field->pixsize; k++) {
+    for (i = 0; i < Nrows; i++) {
+      int row = row_start + i;
+      char *tgt = &raw[i*field->rowsize + k*Nrows*field->Nvalues];
+      char *src = &table->buffer[Nx*row + field->offset + k];
+      for (j = 0; j < field->Nvalues; j++, tgt+=field->pixsize, src++) {
+	*tgt = *src;
+	myAssert (src - raw < field->
+      }
+    }
+  }
+  return (TRUE);
+}
Index: /branches/eam_branches/ohana.20150429/src/libfits/table/F_uncompress_T.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/libfits/table/F_uncompress_T.c	(revision 38362)
+++ /branches/eam_branches/ohana.20150429/src/libfits/table/F_uncompress_T.c	(revision 38363)
@@ -3,7 +3,8 @@
 # include <zlib.h>
 
-# define ESCAPE(A) { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; }
-
-int gfits_distribute_table_data (FTable *table, char *raw, int col, int row_start, int Nrows, int rowsize);
+# define ESCAPE { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; }
+
+int gfits_distribute_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows);
+int gfits_distribute_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows);
 
 # define VERBOSE_DUMP 0
@@ -53,5 +54,5 @@
 
   int ztilelen;
-  if (!gfits_scan (srcheader, "ZTILELEN", "%d", 1, &ztilelen)) ESCAPE(A);
+  if (!gfits_scan (srcheader, "ZTILELEN", "%d", 1, &ztilelen)) ESCAPE;
   // XXX if ZTILELEN is missing, it should have the value of ZNAXIS2
 
@@ -63,8 +64,8 @@
 
   // creates an empty (Naxes = 2, Naxis[i] = 0) table header with XTENSION = BINTABLE, EXTNAME = COMPRESSED_TABLE
-  if (!gfits_create_table_header (tgtheader, "BINTABLE", extname)) ESCAPE(A);
+  if (!gfits_create_table_header (tgtheader, "BINTABLE", extname)) ESCAPE;
 
   int Nfields;
-  if (!gfits_scan (srcheader, "TFIELDS", "%d", 1, &Nfields)) ESCAPE(A);
+  if (!gfits_scan (srcheader, "TFIELDS", "%d", 1, &Nfields)) ESCAPE;
 
   // below we generate a fake table with tmpbuffers.  allocated it to the max needed size
@@ -76,6 +77,6 @@
   for (i = 0; i < Nfields; i++) {
     snprintf (keyword, 80, "TTYPE%d", i+1);
-    if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE(A);
-    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].ttype_cmt)) ESCAPE(A);
+    if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE;
+    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].ttype_cmt)) ESCAPE;
 
     // TUNIT is not mandatory
@@ -84,10 +85,10 @@
       fields[i].tunit[0] = 0;
     } else {
-      if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tunit_cmt)) ESCAPE(A);
+      if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tunit_cmt)) ESCAPE;
     }
     
     snprintf (keyword, 80, "ZFORM%d", i+1);
-    if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE(A);
-    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE(A);
+    if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE;
+    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE;
 
     snprintf (keyword, 80, "ZCTYP%d", i+1);
@@ -96,5 +97,5 @@
     }
 
-    if (!gfits_bintable_format (fields[i].tformat, fields[i].datatype, &fields[i].Nvalues, &fields[i].pixsize)) ESCAPE(A);
+    if (!gfits_bintable_format (fields[i].tformat, fields[i].datatype, &fields[i].Nvalues, &fields[i].pixsize)) ESCAPE;
     fields[i].rowsize = fields[i].Nvalues*fields[i].pixsize;
     max_width = MAX(max_width, fields[i].rowsize);
@@ -103,18 +104,18 @@
     offset += fields[i].rowsize;
 
-    if (!gfits_varlength_column_define (srctable, &fields[i].zdef, i + 1)) ESCAPE(A);
-
-    if (!gfits_define_bintable_column (tgtheader, fields[i].tformat, fields[i].ttype, fields[i].ttype_cmt, fields[i].tunit, 1.0, 0.0)) ESCAPE (A);
+    if (!gfits_varlength_column_define (srctable, &fields[i].zdef, i + 1)) ESCAPE;
+
+    if (!gfits_define_bintable_column (tgtheader, fields[i].tformat, fields[i].ttype, fields[i].ttype_cmt, fields[i].tunit, 1.0, 0.0)) ESCAPE;
   }    
 
   // allocates the default data array (tgttable->buffer)
-  if (!gfits_create_table (tgtheader, tgttable)) ESCAPE (A);
+  if (!gfits_create_table (tgtheader, tgttable)) ESCAPE;
 
   // copy original header to output header (XXX this needs to be finished)
-  if (!gfits_copy_keywords_compress (srcheader, tgtheader)) ESCAPE (A);
+  if (!gfits_copy_keywords_compress (srcheader, tgtheader)) ESCAPE;
   
   off_t Nx, Ny;
-  if (!gfits_scan (srcheader, "ZNAXIS1", OFF_T_FMT, 1, &Nx)) ESCAPE (A);
-  if (!gfits_scan (srcheader, "ZNAXIS2", OFF_T_FMT, 1, &Ny)) ESCAPE (A);
+  if (!gfits_scan (srcheader, "ZNAXIS1", OFF_T_FMT, 1, &Nx)) ESCAPE;
+  if (!gfits_scan (srcheader, "ZNAXIS2", OFF_T_FMT, 1, &Ny)) ESCAPE;
   myAssert (Nx == tgtheader->Naxis[0], "table definition error?");
 
@@ -123,5 +124,5 @@
   ALLOCATE_ZERO (tmpbuffer, char, max_width*Ny);
   for (i = 0; i < Nfields; i++) {
-    if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, tmpbuffer, Ny)) ESCAPE (A);
+    if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, tmpbuffer, Ny)) ESCAPE;
   }
   free (tmpbuffer);
@@ -153,13 +154,18 @@
       off_t Nzdata;
       char *zdata = gfits_varlength_column_pointer (srctable, &fields[i].zdef, row, &Nzdata);
-      if (!zdata) ESCAPE(A);
+      if (!zdata) ESCAPE;
     
+      if (strcasecmp(fields[i].zctype, "GZIP_1") && strcasecmp(fields[i].zctype, "GZIP_2") && strcasecmp(fields[i].zctype, "RICE_1")) {
+	// Nzdata is number of bytes
+	if (!gfits_byteswap_zdata (zdata, Nzdata, fields[i].pixsize)) ESCAPE;
+      }
+
       int Nrows = (row == Ntile - 1) ? ztilelast : ztilelen;
       int Nraw = Nraw_alloc; // expected number of pixel: Nrows*fields[i].Nvalues
-      if (!gfits_uncompress_data (zdata, Nzdata, fields[i].zctype, NULL, NULL, 0, raw, &Nraw, fields[i].pixsize)) ESCAPE(A);
+      if (!gfits_uncompress_data (zdata, Nzdata, fields[i].zctype, NULL, NULL, 0, raw, &Nraw, fields[i].pixsize)) ESCAPE;
 
       if (!strcasecmp(fields[i].zctype, "GZIP_1")) {
 	myAssert ((fields[i].zdef.format != 'C') && (fields[i].zdef.format != 'M'), "swap is probably wrong for C or M columns");
-	if (!gfits_byteswap_zdata (raw, Nraw * fields[i].pixsize, fields[i].pixsize)) ESCAPE(A);
+	if (!gfits_byteswap_zdata (raw, Nraw * fields[i].pixsize, fields[i].pixsize)) ESCAPE;
       }
 
@@ -171,8 +177,9 @@
 
       // copy the raw pixels from their native matrix locations to the temporary output buffer
-      if (!gfits_distribute_table_data (tgttable, raw, fields[i].offset, row_start, Nrows, fields[i].rowsize)) ESCAPE(A);
-      
-      // XXX need to activate
-      // if (FALSE) gfits_byteswap_zdata (zdata, Nzdata, zdata_pixsize) ESCAPE(A);
+      if (!strcasecmp(fields[i].zctype, "GZIP_2")) {
+	if (!gfits_distribute_table_gzp2 (tgttable, &fields[i], raw, row_start, Nrows)) ESCAPE;
+      } else {
+	if (!gfits_distribute_table_data (tgttable, &fields[i], raw, row_start, Nrows)) ESCAPE;
+      }      
     }
   }
@@ -194,5 +201,5 @@
 // raw_pixsize is the bytes / pixel for the input matrix
 // place the raw image bytes for the current tile into the tile buffer
-int gfits_distribute_table_data (FTable *table, char *raw, int col, int row_start, int Nrows, int rowsize) {
+int gfits_distribute_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows) {
 
   off_t i;
@@ -202,10 +209,10 @@
   off_t Nx = table->header->Naxis[0];
 
-  if (VERBOSE) fprintf (stderr, "collect: ");
+  if (VERBOSE) fprintf (stderr, "distribute: ");
   for (i = 0; i < Nrows; i++) {
     int row = row_start + i;
-    memcpy (&table->buffer[Nx*row + col], &raw[i*rowsize], rowsize);
+    memcpy (&table->buffer[Nx*row + field->offset], &raw[i*field->rowsize], field->rowsize);
 # if (VERBOSE)
-    int j; for (j = 0; j < rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + col + j]);
+    int j; for (j = 0; j < field->rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + field->offset + j]);
 # endif
   }
@@ -214,2 +221,23 @@
   return (TRUE);
 }
+
+int gfits_distribute_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows) {
+
+  off_t i, j, k;
+
+  // we are copying NN rows into the column which starts at XX and has MM bytes per row
+
+  off_t Nx = table->header->Naxis[0];
+
+  for (k = 0; k < field->pixsize; k++) {
+    for (i = 0; i < Nrows; i++) {
+      int row = row_start + i;
+      char *src = &raw[i*field->rowsize + k*Nrows*field->Nvalues];
+      char *tgt = &table->buffer[Nx*row + field->offset + k];
+      for (j = 0; j < field->Nvalues; j++, tgt+=field->pixsize, src++) {
+	*tgt = *src;
+      }
+    }
+  }
+  return (TRUE);
+}
Index: /branches/eam_branches/ohana.20150429/src/libfits/test/compress.sh
===================================================================
--- /branches/eam_branches/ohana.20150429/src/libfits/test/compress.sh	(revision 38362)
+++ /branches/eam_branches/ohana.20150429/src/libfits/test/compress.sh	(revision 38363)
@@ -1,15 +1,21 @@
+input tap.dvo
 
 macro test_image_all 
 
-  # foreach mode NONE GZIP_1 RICE_1
+  tapPLAN 88
+
+  foreach mode NONE GZIP_1 GZIP_2 RICE_1
   # foreach mode GZIP_1
-  foreach mode GZIP_2
+  # foreach mode GZIP_2
   # foreach mode RICE_1
     foreach bitpix 8 16 32 -32 -64
     # foreach bitpix 32
-      echo ===== bitpix = $bitpix =====
+      if (($mode == RICE_1) && ($bitpix < 0)) continue ; # RICE_1 is for int only
+      tapDIAG 2 "===== bitpix = $bitpix, mode = $mode ====="
       test_image_single $bitpix $mode
     end
   end
+
+  tapDONE
 end
 
@@ -30,5 +36,7 @@
  rd b test.cmp.fits -x 0
  set d = x - b
- stat d
+ stat -q d
+ tapOK {abs($MEAN)  < 0.001} "read our cmp $cmpmode $bitpix (MEAN  = $MEAN)"
+ tapOK {$SIGMA      < 0.001} "read our cmp $cmpmode $bitpix (SIGMA = $SIGMA)"
 
  if ($cmpmode == NONE) return
@@ -43,8 +51,10 @@
    exec fpack -r -S test.raw.fits > test.fpk.fits
  end
- echo "load fpack version"
+ # echo "load fpack version"
  rd c test.fpk.fits -x 0
  set d = x - c
- stat d
+ stat -q d
+ tapOK {abs($MEAN)  < 0.001} "read fpack $cmpmode $bitpix (MEAN  = $MEAN)"
+ tapOK {$SIGMA      < 0.001} "read fpack $cmpmode $bitpix (SIGMA = $SIGMA)"
 
  if ($cmpmode == RICE_1_0) 
@@ -53,9 +63,11 @@
  end
 
- echo "run funpack on our version"
+ # echo "run funpack on our version"
  exec funpack -S test.cmp.fits > test.fun.fits
  rd e test.fun.fits
  set d = x - e
- stat d
+ stat -q d
+ tapOK {abs($MEAN)  < 0.001} "funpack our cmp $cmpmode $bitpix (MEAN  = $MEAN)"
+ tapOK {$SIGMA      < 0.001} "funpack our cmp $cmpmode $bitpix (SIGMA = $SIGMA)"
 end
 
Index: /branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c	(revision 38362)
+++ /branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c	(revision 38363)
@@ -14,4 +14,6 @@
   test_compress ("NONE");
   test_compress ("GZIP_1");
+  test_compress ("GZIP_2");
+  // test_compress ("GZIP_1");
 
   exit (0);
Index: /branches/eam_branches/ohana.20150429/src/opihi/cmd.data/rd.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/opihi/cmd.data/rd.c	(revision 38362)
+++ /branches/eam_branches/ohana.20150429/src/opihi/cmd.data/rd.c	(revision 38363)
@@ -8,4 +8,10 @@
   char region[512];
   Buffer *buf;
+
+  int VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    remove_argument (N, &argc, argv);
+    VERBOSE = TRUE;
+  }
 
   int JustHead = FALSE;
@@ -193,7 +199,7 @@
     gfits_copy_header (&buf[0].header, ftable.header);
 
-    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { fprintf (stderr, "problem reading compressed image table data\n"); fclose (f); return FALSE; }
-    if (!gfits_byteswap_varlength_column (&ftable, 1)) { fprintf (stderr, "problem doing byteswap on compressed image metadata column\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }
-    if (!gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable)) { fprintf (stderr, "problem uncompressing the image data\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }
+    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { gprint (GP_ERR, "problem reading compressed image table data\n"); fclose (f); return FALSE; }
+    if (!gfits_byteswap_varlength_column (&ftable, 1)) { gprint (GP_ERR, "problem doing byteswap on compressed image metadata column\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }
+    if (!gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable)) { gprint (GP_ERR, "problem uncompressing the image data\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }
 
     // uncompressing the image leaves the format as an extension
@@ -238,6 +244,5 @@
   buf[0].unsign = buf[0].header.unsign;
 
-  gprint (GP_LOG, "read "OFF_T_FMT" bytes from %s into buffer %s\n", 
-	   buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]);
+  if (VERBOSE) gprint (GP_LOG, "read "OFF_T_FMT" bytes from %s into buffer %s\n", buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]);
 
   blank = 0xffff;
