Index: /trunk/Ohana/src/libfits/include/gfitsio.h
===================================================================
--- /trunk/Ohana/src/libfits/include/gfitsio.h	(revision 39459)
+++ /trunk/Ohana/src/libfits/include/gfitsio.h	(revision 39460)
@@ -247,4 +247,5 @@
 int     gfits_fwrite_vtable            PROTO((FILE *f, VTable *table));
 int     gfits_fwrite_ftable_range      PROTO((FILE *f, FTable *table, off_t start, off_t Nrows, off_t Ndisk, off_t Ntotal));
+int     gfits_byteswap_bintable_column PROTO((FTable *ftable, int column));
 int     gfits_get_bintable_column      PROTO((Header *header, FTable *table, char *label, void **data));
 int     gfits_get_bintable_column_raw  PROTO((Header *header, FTable *table, char *label, void **data, char nativeOrder));
Index: /trunk/Ohana/src/libfits/table/F_get_column.c
===================================================================
--- /trunk/Ohana/src/libfits/table/F_get_column.c	(revision 39459)
+++ /trunk/Ohana/src/libfits/table/F_get_column.c	(revision 39460)
@@ -139,4 +139,96 @@
   *Nrow = Ny;
   return (array);
+}
+
+// do a column byteswap in-situ (needed because uncompress returns an unswapped binary table
+int gfits_byteswap_bintable_column (FTable *ftable, int column) {
+
+  off_t Nx, Ny;
+  int i, Nval, Nbytes, Nv, Nb;
+  char field[256], format[256], tmpline[64], type[64];
+  char *Pin, *Pout, *array;
+
+  Header *header = ftable->header;
+
+  /* interpret format */
+  snprintf (field, 256, "TFORM%d", column);
+  if (!gfits_scan (header, field, "%s", 1, format)) return FALSE;
+
+  if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return FALSE;
+  
+  /* convert data in-situ with correct type, byte swap and Bzero/Bscale */
+  if (!strcmp (type, "char")) return TRUE;
+  if (!strcmp (type, "byte")) return TRUE;
+
+  /* check existing table dimensions */
+  gfits_scan (header, "NAXIS1",  OFF_T_FMT, 1,  &Nx);
+  gfits_scan (header, "NAXIS2",  OFF_T_FMT, 1,  &Ny);
+
+  /* scan prior columns to find insert point */
+  int Nstart = 0;
+  for (i = 1; i < column; i++) {
+    snprintf (field, 256, "TFORM%d", i);
+    gfits_scan (header, field, "%s", 1, format);
+    gfits_bintable_format (format, tmpline, &Nv, &Nb);
+    Nstart += Nv*Nb;
+  }
+
+  /* extract bytes from table into array */
+  ALLOCATE (array, char, Nbytes*Nval*Ny);
+  Pin  = ftable[0].buffer + Nstart;
+  Pout = array;
+  for (i = 0; i < Ny; i++, Pin += Nx, Pout += Nval*Nbytes) {
+    memcpy (Pout, Pin, Nval*Nbytes);
+  }
+
+  // NOTE: we have already copied the data to 'array', so the blocks below
+  // only need to swap if this is a direct copy
+  Pin  = array;
+  Pout = array;
+
+  if (!strcmp (type, "short")) {
+    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
+# ifdef BYTE_SWAP
+      SWAP_BYTE;
+# endif
+    }  
+  }
+  if (!strcmp (type, "int")) {
+    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
+# ifdef BYTE_SWAP
+      SWAP_WORD;
+# endif
+    }
+  }
+  if (!strcmp (type, "int64_t")) {
+    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
+# ifdef BYTE_SWAP
+      SWAP_DBLE;
+# endif
+    }
+  }
+  if (!strcmp (type, "float")) {
+    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
+# ifdef BYTE_SWAP
+      SWAP_WORD;
+# endif
+    }
+  }
+  if (!strcmp (type, "double")) {
+    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
+# ifdef BYTE_SWAP
+      SWAP_DBLE;
+# endif
+    }
+  }
+
+  // save the bytes back into the table buffer
+  Pout = ftable[0].buffer + Nstart;
+  Pin  = array;
+  for (i = 0; i < Ny; i++, Pout += Nx, Pin += Nval*Nbytes) {
+    memcpy (Pout, Pin, Nval*Nbytes);
+  }
+
+  return TRUE;
 }
 
