Index: /branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_utils.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_utils.c	(revision 38414)
+++ /branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_utils.c	(revision 38415)
@@ -173,5 +173,6 @@
 int gfits_cmptype_valid (char *cmptype) {
 
-  if (!strcasecmp(cmptype, "NONE")) return TRUE;
+  if (!strcasecmp(cmptype, "NONE"))   return TRUE;
+  if (!strcasecmp(cmptype, "NONE_1")) return TRUE; // do not compress, but shuffle a la GZIP_1
   if (!strcasecmp(cmptype, "NONE_2")) return TRUE; // do not compress, but shuffle a la GZIP_2
   if (!strcasecmp(cmptype, "GZIP_1")) return TRUE;
@@ -192,4 +193,5 @@
       !strcasecmp(cmptype, "GZIP_2") || 
       !strcasecmp(cmptype, "NONE_2") || 
+      !strcasecmp(cmptype, "NONE_1") || 
       !strcasecmp(cmptype, "NONE")) {
     if (out_bitpix ==   8) return (1);
@@ -235,5 +237,5 @@
 
   // NONE should be swapped to mimic swapping types
-  if (!strcasecmp(cmptype, "NONE")) {
+  if (!strcasecmp(cmptype, "NONE") || !strcasecmp(cmptype, "NONE_1")) {
     if (out_bitpix ==   8) return (1);
     if (out_bitpix ==  16) return (2);
@@ -292,4 +294,5 @@
   if (!strcasecmp(cmptype, "GZIP_1") || 
       !strcasecmp(cmptype, "GZIP_2") || 
+      !strcasecmp(cmptype, "NONE_1") || 
       !strcasecmp(cmptype, "NONE_2") || 
       !strcasecmp(cmptype, "NONE")) {
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 38414)
+++ /branches/eam_branches/ohana.20150429/src/libfits/table/F_compress_T.c	(revision 38415)
@@ -39,10 +39,15 @@
   if (!ztilelen) ztilelen = srcheader->Naxis[1];
 
-  if (srcheader->Naxis[1] % ztilelen) {
-    Ntile = srcheader->Naxis[1] / ztilelen + 1;
-    ztilelast = srcheader->Naxis[1] % ztilelen;
+  if (!srcheader->Naxis[1]) {
+    Ntile = 0;
+    ztilelast = 0;
   } else {
-    Ntile = srcheader->Naxis[1] / ztilelen;
+    if (srcheader->Naxis[1] % ztilelen) {
+      Ntile = srcheader->Naxis[1] / ztilelen + 1;
+      ztilelast = srcheader->Naxis[1] % ztilelen;
+    } else {
+      Ntile = srcheader->Naxis[1] / ztilelen;
     ztilelast = ztilelen;
+    }
   }
 
@@ -237,6 +242,5 @@
       }
 
-      if (strcasecmp(fields[j].zctype, "NONE") &&
-	  strcasecmp(fields[j].zctype, "NONE_2") &&
+      if (strcasecmp(fields[j].zctype, "NONE_2") && // NONE and NONE_1 not swapped?
 	  strcasecmp(fields[j].zctype, "GZIP_1") &&
 	  strcasecmp(fields[j].zctype, "GZIP_2") && 
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 38414)
+++ /branches/eam_branches/ohana.20150429/src/libfits/table/F_uncompress_T.c	(revision 38415)
@@ -47,4 +47,19 @@
 }
 
+static float timeSum1 = 0.0;
+static float timeSum2 = 0.0;
+static float timeSum2a = 0.0;
+static float timeSum2b = 0.0;
+static float timeSum2c = 0.0;
+static float timeSum2d = 0.0;
+static float timeSum2e = 0.0;
+static float timeSum2f = 0.0;
+static float timeSum3 = 0.0;
+
+void gfits_uncompress_timing () {
+  fprintf (stderr, "times: %f %f %f\n", timeSum1, timeSum2, timeSum3);
+  fprintf (stderr, "times: %f %f %f %f %f %f\n", timeSum2a, timeSum2b, timeSum2c, timeSum2d, timeSum2e, timeSum2f);
+}
+
 int gfits_uncompress_table (FTable *srctable, FTable *tgttable) {
 
@@ -58,4 +73,9 @@
   Header *srcheader = srctable->header;
   Header *tgtheader = tgttable->header;
+
+  // XXX EAM:
+  struct timeval startTimer, stopTimer;
+  float dtime;
+  gettimeofday (&startTimer, (void *) NULL);
 
   int ztilelen;
@@ -126,4 +146,10 @@
   myAssert (Nx == tgtheader->Naxis[0], "table definition error?");
 
+  // XXX TIMER 1
+  gettimeofday (&stopTimer, (void *) NULL); 
+  dtime = DTIME (stopTimer, startTimer);
+  timeSum1 += dtime;
+  gettimeofday (&startTimer, (void *) NULL);
+
   // this allocates the pointer data array for the full set of tiles (NOT the heap)
   char *tmpbuffer = NULL;
@@ -135,5 +161,10 @@
     
   int Ntile = srcheader->Naxis[1];
-  int ztilelast = (tgtheader->Naxis[1] % ztilelen) ? tgtheader->Naxis[1] % ztilelen : ztilelen;
+  int ztilelast;
+  if (Ntile == 0) {
+    ztilelast = 0;
+  } else {
+    ztilelast = (tgtheader->Naxis[1] % ztilelen) ? tgtheader->Naxis[1] % ztilelen : ztilelen;
+  }
 
   // allocate the intermediate storage buffers
@@ -147,4 +178,10 @@
   gfits_dump_cmp_table (srctable, "unc");
 
+  // XXX TIMER 2
+  gettimeofday (&stopTimer, (void *) NULL); 
+  dtime = DTIME (stopTimer, startTimer);
+  timeSum2 += dtime;
+  gettimeofday (&startTimer, (void *) NULL);
+
   off_t row;
   for (row = 0; row < srcheader->Naxis[1]; row++) {
@@ -157,4 +194,6 @@
       // XXX note that this function currently byteswaps.  I should redo the code to make
       // byteswap of the varlength data segment a separate function
+
+      gettimeofday (&startTimer, (void *) NULL);
 
       off_t Nzdata;
@@ -173,6 +212,11 @@
       }
 
-      if (strcasecmp(fields[i].zctype, "NONE") && 
-	  strcasecmp(fields[i].zctype, "NONE_2") && 
+      // XXX TIMER 2a
+      gettimeofday (&stopTimer, (void *) NULL); 
+      dtime = DTIME (stopTimer, startTimer);
+      timeSum2a += dtime;
+      gettimeofday (&startTimer, (void *) NULL);
+  
+      if (strcasecmp(fields[i].zctype, "NONE_2") && 
 	  strcasecmp(fields[i].zctype, "GZIP_1") && 
 	  strcasecmp(fields[i].zctype, "GZIP_2") && 
@@ -183,4 +227,10 @@
       }
 
+      // XXX TIMER 2b
+      gettimeofday (&stopTimer, (void *) NULL); 
+      dtime = DTIME (stopTimer, startTimer);
+      timeSum2b += dtime;
+      gettimeofday (&startTimer, (void *) NULL);
+  
       if (VERBOSE_DUMP) {
 	int k;
@@ -194,4 +244,10 @@
       }
 
+      // XXX TIMER 2c
+      gettimeofday (&stopTimer, (void *) NULL); 
+      dtime = DTIME (stopTimer, startTimer);
+      timeSum2c += dtime;
+      gettimeofday (&startTimer, (void *) NULL);
+  
       int Nrows = (row == Ntile - 1) ? ztilelast : ztilelen;
       int Nraw = Nrows*fields[i].Nvalues*fields[i].pixsize; // expected number of bytes
@@ -209,4 +265,10 @@
       }
 
+      // XXX TIMER 2d
+      gettimeofday (&stopTimer, (void *) NULL); 
+      dtime = DTIME (stopTimer, startTimer);
+      timeSum2d += dtime;
+      gettimeofday (&startTimer, (void *) NULL);
+  
       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");
@@ -214,4 +276,10 @@
       }
 
+      // XXX TIMER 2e
+      gettimeofday (&stopTimer, (void *) NULL); 
+      dtime = DTIME (stopTimer, startTimer);
+      timeSum2e += dtime;
+      gettimeofday (&startTimer, (void *) NULL);
+  
       if (VERBOSE_DUMP) {
 	int k;
@@ -237,6 +305,18 @@
 	if (!gfits_distribute_table_data (tgttable, &fields[i], raw, row_start, Nrows)) ESCAPE;
       }      
+
+      // XXX TIMER 2f
+      gettimeofday (&stopTimer, (void *) NULL); 
+      dtime = DTIME (stopTimer, startTimer);
+      timeSum2f += dtime;
+      gettimeofday (&startTimer, (void *) NULL);
     }
   }
+
+  // XXX TIMER 3
+  gettimeofday (&stopTimer, (void *) NULL); 
+  dtime = DTIME (stopTimer, startTimer);
+  timeSum3 += dtime;
+  gettimeofday (&startTimer, (void *) NULL);
 
   gfits_dump_raw_table (tgttable, "unc");
@@ -264,8 +344,10 @@
   off_t Nx = table->header->Naxis[0];
 
+  char *tblbuffer = &table->buffer[Nx*row_start + field->offset];
+
   if (VERBOSE) fprintf (stderr, "distribute: ");
-  for (i = 0; i < Nrows; i++) {
-    int row = row_start + i;
-    memcpy (&table->buffer[Nx*row + field->offset], &raw[i*field->rowsize], field->rowsize);
+  for (i = 0; i < Nrows; i++, tblbuffer += Nx) {
+    // int row = row_start + i;
+    memcpy (tblbuffer, &raw[i*field->rowsize], field->rowsize);
 # if (VERBOSE)
     int j; for (j = 0; j < field->rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + field->offset + j]);
@@ -284,10 +366,39 @@
 
   off_t Nx = table->header->Naxis[0];
-
+  int Nvalues = field->Nvalues;
+  int pixsize = field->pixsize;
+  int offset = field->offset;
+
+  char *rawptr = raw;
+
+  for (k = 0; k < field->pixsize; k++) {
+# ifdef BYTE_SWAP      
+    char *tblptr_start = &table->buffer[Nx*row_start + offset + (pixsize - k - 1)];
+# else
+    char *tblptr_start = &table->buffer[Nx*row_start + offset + k];
+# endif
+    for (i = 0; i < Nrows; i++, tblptr_start += Nx) {
+      char *tblptr = tblptr_start;
+      for (j = 0; j < Nvalues; j++, tblptr += pixsize, rawptr++) {
+	*tblptr = *rawptr;
+      }
+    }
+  }
+  return (TRUE);
+}
+
+int gfits_distribute_table_gzp2_alt (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 *rawptr = &raw[i*field->Nvalues + k*Nrows*field->Nvalues];
-# ifdef BYTE_SWAP      
+# ifdef BYTE_SWAP     
       char *tblptr = &table->buffer[Nx*row + field->offset + (field->pixsize - k - 1)];
 # else
Index: /branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c	(revision 38414)
+++ /branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c	(revision 38415)
@@ -4,4 +4,5 @@
 
 int test_compress (char *zcmptype);
+int test_compress_empty (char *zcmptype);
 int test_compress_fullrange (char *zcmptype);
 int test_compress_single_full (char *zcmptype);
@@ -15,8 +16,7 @@
   diag ("libfits tablecomp.c tests");
 
-  // test_compress ("RICE_1");
-  // test_compress_fullrange ("RICE_1");
-
-# if (1)
+  // test_compress_empty ("GZIP_1");
+  // exit (0);
+
   test_compress (NULL);
   test_compress_fullrange (NULL);
@@ -26,21 +26,7 @@
     test_compress (cmptype[i]);
     test_compress_fullrange (cmptype[i]);
-  }
-# endif
-
-  // test_compress_single_full ("GZIP_1");
-  // test_compress_single_full ("RICE_1");
-
-  // test_compress (NULL);
-  // test_compress ("NONE");
-  // test_compress ("NONE_2");
-  // test_compress ("GZIP_1");
-  // test_compress ("GZIP_2");
-  // test_compress ("RICE_1");
-  // test_compress ("RICE_ONE");
-  // test_compress ("AUTO");
-
-  // test_compress_fullrange (NULL);
-  // test_compress_fullrange ("NONE");
+    test_compress_empty (cmptype[i]);
+    ok (ohana_memcheck_func (TRUE), "no memory corruption");
+  }
 
   return exit_status();
@@ -349,2 +335,119 @@
 }
 
+int test_compress_empty (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"
+
+  Header header;
+  FTable ftable;
+
+  diag ("--- starting test_compress with zcmptype %s ---", zcmptype);
+  ok (gfits_init_header (&header), "inited the header");
+  ok (gfits_init_table (&ftable), "inited the table");
+
+  ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header");
+
+  ok (gfits_define_bintable_column (&header, "B", "VAL_B", "byte",   "none", 1.0, 0.0), "defined byte column");
+  ok (gfits_define_bintable_column (&header, "I", "VAL_I", "short",  "none", 1.0, 0.0), "defined short column");
+  ok (gfits_define_bintable_column (&header, "J", "VAL_J", "int",    "none", 1.0, 0.0),  "defined int column");
+  ok (gfits_define_bintable_column (&header, "K", "VAL_K", "long",   "none", 1.0, 0.0),  "defined long column");
+  ok (gfits_define_bintable_column (&header, "E", "VAL_E", "float",  "degree", 1.0, 0.0),   "defined float column");
+  ok (gfits_define_bintable_column (&header, "D", "VAL_D", "double", "degree", 1.0, 0.0),   "defined double column");
+  
+  // generate the output array that carries the data
+  ok (gfits_create_table (&header, &ftable), "created the basic table");
+
+  int Nval = 0;
+  char    *VAL_B;  ALLOCATE (VAL_B, char,    Nval);
+  short   *VAL_I;  ALLOCATE (VAL_I, short,   Nval);
+  int     *VAL_J;  ALLOCATE (VAL_J, int,     Nval);
+  int64_t *VAL_K;  ALLOCATE (VAL_K, int64_t, Nval);
+  float   *VAL_E;  ALLOCATE (VAL_E, float,   Nval);
+  double  *VAL_D;  ALLOCATE (VAL_D, double,  Nval);
+  
+  int i;
+  for (i = 0; i < Nval; i++) {
+    VAL_B[i] = (i % 255) - 128;
+    VAL_I[i] = i;
+    VAL_J[i] = 10000*i + 100*i;
+    VAL_K[i] = 10000*i + 330*i;
+    VAL_E[i] = 0.1*i;
+    VAL_D[i] = 1.001*i;
+  }     
+
+  // add the columns to the output array
+  ok (gfits_set_bintable_column (&header, &ftable, "VAL_B", VAL_B, Nval), "set byte   table column");
+  ok (gfits_set_bintable_column (&header, &ftable, "VAL_I", VAL_I, Nval), "set short  table column");
+  ok (gfits_set_bintable_column (&header, &ftable, "VAL_J", VAL_J, Nval), "set int    table column");
+  ok (gfits_set_bintable_column (&header, &ftable, "VAL_K", VAL_K, Nval), "set long   table column");
+  ok (gfits_set_bintable_column (&header, &ftable, "VAL_E", VAL_E, Nval), "set float  table column");
+  ok (gfits_set_bintable_column (&header, &ftable, "VAL_D", VAL_D, Nval), "set double table column");
+
+  Header *outheader = &header;
+  FTable *outtable = &ftable;
+
+  if (zcmptype) {
+    Header cmpheader;
+    FTable cmptable;
+    cmptable.header = &cmpheader;
+    ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table");
+
+    Header rawheader;
+    FTable rawtable;
+    rawtable.header = &rawheader;
+    ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table");
+    
+    gfits_free_header (&cmpheader);
+    gfits_free_table (&cmptable);
+
+    outheader = &rawheader;
+    outtable  = &rawtable;
+  }
+
+  char type[16];
+  int Ncol;
+  off_t Nrow;
+
+  char    *VAL_B_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_B", type, &Nrow, &Ncol); ok (!strcmp (type, "byte"),    "read byte    table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
+  short   *VAL_I_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_I", type, &Nrow, &Ncol); ok (!strcmp (type, "short"),   "read short   table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
+  int     *VAL_J_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_J", type, &Nrow, &Ncol); ok (!strcmp (type, "int"),     "read int     table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
+  int64_t *VAL_K_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_K", type, &Nrow, &Ncol); ok (!strcmp (type, "int64_t"), "read int64_t table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
+  float   *VAL_E_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_E", type, &Nrow, &Ncol); ok (!strcmp (type, "float"),   "read float   table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
+  double  *VAL_D_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_D", type, &Nrow, &Ncol); ok (!strcmp (type, "double"),  "read double  table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
+
+  // count mismatched values
+  int NVAL_B_bad = 0;
+  int NVAL_I_bad = 0;
+  int NVAL_J_bad = 0;
+  int NVAL_K_bad = 0;
+  int NVAL_E_bad = 0;
+  int NVAL_D_bad = 0;
+
+  // for (i = 0; i < Nval; i++) {
+  //   fprintf (stderr, "%0llx : %0llx\n", (long long) VAL_K[i], (long long) VAL_K_t[i]);
+  // }
+
+  for (i = 0; i < Nval; i++) {
+    if (VAL_B[i] != VAL_B_t[i]) NVAL_B_bad++;
+    if (VAL_I[i] != VAL_I_t[i]) NVAL_I_bad++;
+    if (VAL_J[i] != VAL_J_t[i]) NVAL_J_bad++;
+    if (VAL_K[i] != VAL_K_t[i]) NVAL_K_bad++;
+    if (VAL_E[i] != VAL_E_t[i]) NVAL_E_bad++;
+    if (VAL_D[i] != VAL_D_t[i]) NVAL_D_bad++;
+  }
+
+  ok (!NVAL_B_bad, "byte    values match (input vs output)");
+  ok (!NVAL_I_bad, "short   values match (input vs output)");
+  ok (!NVAL_J_bad, "int     values match (input vs output)");
+  ok (!NVAL_K_bad, "int64_t values match (input vs output)");
+  ok (!NVAL_E_bad, "float   values match (input vs output)");
+  ok (!NVAL_D_bad, "double  values match (input vs output)");
+
+  gfits_free_header (&header);
+  gfits_free_table (&ftable);
+  if (zcmptype) {
+    gfits_free_header (outheader);
+    gfits_free_table (outtable);
+  }
+  return TRUE;
+}
+
+
