Index: /branches/eam_branches/ipp-20140206/Ohana/src/libfits/table/F_get_column.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/libfits/table/F_get_column.c	(revision 36567)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/libfits/table/F_get_column.c	(revision 36568)
@@ -174,118 +174,13 @@
 int gfits_get_bintable_column (Header *header, FTable *table, char *label, void **data) {
 
-  off_t Nx, Ny;
-  int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
-  char tlabel[80], field[80], format[80], type[16], tmpline[16];
-  char *Pin, *Pout, *array;
-  double Bscale, Bzero;
-
-  if (label == (char *) NULL) return (FALSE);
-  if (label[0] == 0) return (FALSE);
-
-  /* find label in header */
-  tlabel[0] = 0;
-  gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
-  for (i = 1; strcasecmp (label, tlabel) && (i < Nfields + 1); i++) {
-    sprintf (field, "TTYPE%d", i);
-    gfits_scan (header, field, "%s", 1, tlabel);
-  }
-  if (strcasecmp (label, tlabel)) return (FALSE);
-  N = i - 1;
-
-  Bscale = 1; 
-  Bzero  = 0;
-
-  /* interpret format */
-  sprintf (field, "TSCAL%d", N);
-  gfits_scan (header, field, "%lf", 1, &Bscale);
-  sprintf (field, "TZERO%d", N);
-  gfits_scan (header, field, "%lf", 1, &Bzero);
-  sprintf (field, "TFORM%d", N);
-  gfits_scan (header, field, "%s", 1, format);
-
-  if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE);
-  
-  /* check existing table dimensions */
-  gfits_scan (header, "NAXIS1",  OFF_T_FMT, 1,  &Nx);
-  gfits_scan (header, "NAXIS2",  OFF_T_FMT, 1,  &Ny);
-
-  /* scan columns to find insert point */
-  Nstart = 0;
-  for (i = 1; i < N; i++) {
-    sprintf (field, "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 temporary array */
-  ALLOCATE (array, char, Nbytes*Nval*Ny);
-  Pin  = table[0].buffer + Nstart;
-  Pout = array;
-  for (i = 0; i < Ny; i++, Pin += Nx, Pout += Nval*Nbytes) {
-    memcpy (Pout, Pin, Nval*Nbytes);
-  }
-
-  /* convert data in-situ with correct type, byte swap and Bzero/Bscale */
-  Pin  = array;
-  Pout = array;
-  if (!strcmp (type, "char")) {
-    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
-      *(char *)Pout = *(char *)Pin*Bscale + Bzero;
-    }
-  }
-  if (!strcmp (type, "short")) {
-    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
-# ifdef BYTE_SWAP
-      SWAP_BYTE;
-# endif
-      *(short *)Pout = *(short *)Pin*Bscale + Bzero;
-    }  
-  }
-  if (!strcmp (type, "int")) {
-    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
-# ifdef BYTE_SWAP
-      SWAP_WORD;
-# endif
-      *(int *)Pout = *(int *)Pin*Bscale + Bzero;
-    }
-  }
-  if (!strcmp (type, "int64_t")) {
-    // XXX 64 bit int operations with Bzero & Bscale are inaccurate even with doubles
-    if ((Bzero == 0.0) && (Bscale == 1.0)) {
-      for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
-# ifdef BYTE_SWAP
-	SWAP_DBLE;
-# endif
-	*(int64_t *)Pout = *(int64_t *)Pin;
-      }
-    } else {
-      for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
-# ifdef BYTE_SWAP
-	SWAP_DBLE;
-# endif
-	*(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero;
-      }
-    }
-  }
-  if (!strcmp (type, "float")) {
-    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
-# ifdef BYTE_SWAP
-      SWAP_WORD;
-# endif
-      *(float *)Pout = *(float *)Pin*Bscale + Bzero;
-    }
-  }
-  if (!strcmp (type, "double")) {
-    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
-# ifdef BYTE_SWAP
-      SWAP_DBLE;
-# endif
-      *(double *)Pout = *(double *)Pin*Bscale + Bzero;
-    }
-  }
+  char type[16];
+  off_t Nrow;
+  int Ncol;
+
+  char *array = gfits_get_bintable_column_data (header, table, label, type, &Nrow, &Ncol);
+  if (array == NULL) return (FALSE);
 
   *data = array;
-  return (TRUE);
+  return TRUE;
 }
 
