Index: /trunk/Ohana/src/libfits/table/F_get_column.c
===================================================================
--- /trunk/Ohana/src/libfits/table/F_get_column.c	(revision 41675)
+++ /trunk/Ohana/src/libfits/table/F_get_column.c	(revision 41676)
@@ -310,5 +310,5 @@
    C - complex float
    M - complex double
-   P - var lenght array descrpt (64 bit)
+   P - var length array descrpt (64 bit)
    
    all can be preceeded by integer N which specified number
@@ -341,5 +341,4 @@
 
   if (!gfits_table_format (format, type, Nval, &Nbytes)) return (FALSE);
-  *Nval = 1;
 
   return (TRUE);
@@ -379,16 +378,25 @@
   gfits_scan (header, "NAXIS2",  OFF_T_FMT, 1,  &Ny);
 
-  /* scan columns to find insert point */
-  Nstart = 0;
-  for (i = 1; i < N; i++) {
-    snprintf (field, 256, "TFORM%d", i);
-    gfits_scan (header, field, "%s", 1, format);
-    gfits_table_format (format, tmp, &Nv, &Nb);
-    Nstart += Nv*Nb;
+  // find the starting byte for this column
+  // FITS ASCII table is supposed to have TBCOLn to specify the starting point
+  // but if it is missing, we can try to find by counting
+  snprintf (field, 256, "TBCOL%d", N);
+  int status = gfits_scan (header, field, "%d", 1, &Nstart);
+  if (!status) {
+    /* scan columns to find insert point */
+    Nstart = 0;
+    for (i = 1; i < N; i++) {
+      snprintf (field, 256, "TFORM%d", i);
+      gfits_scan (header, field, "%s", 1, format);
+      gfits_table_format (format, tmp, &Nv, &Nb);
+      Nstart += Nv*Nb;
+    }
+  } else {
+    Nstart --;
   }
 
   /* allocate temporary line, init pointers */
-  ALLOCATE (line, char, Nval+1);
-  bzero (line, Nval+1);
+  ALLOCATE (line, char, Nval*Nbytes+1);
+  bzero (line, Nval*Nbytes+1);
   Pin  = table[0].buffer + Nstart;
 
Index: /trunk/Ohana/src/libfits/table/F_set_column.c
===================================================================
--- /trunk/Ohana/src/libfits/table/F_set_column.c	(revision 41675)
+++ /trunk/Ohana/src/libfits/table/F_set_column.c	(revision 41676)
@@ -478,22 +478,22 @@
   /* print line with appropriate formatting */
   ALLOCATE (array, char, Nbytes*Nval*Nrow);
-  ALLOCATE (line, char, Nval+1);
+  ALLOCATE (line, char, Nbytes+1);
   Pin = data;
   Pout = array;
   if (!strcmp (type, "char")) {
-    for (i = 0; i < Nval*Nrow; i++, Pin++, Pout++) {
+    for (i = 0; i < Nbytes*Nval*Nrow; i++, Pin++, Pout++) {
       *Pout = *Pin;
     }
   }
   if (!strcmp (type, "int")) {
-    for (i = 0; i < Nrow; i++, Pin+=4, Pout+=Nval) {
-      snprintf (line, Nval + 1, cformat, *(int *)Pin);
-      memcpy (Pout, line, Nval);
+    for (i = 0; i < Nrow; i++, Pin+=4, Pout+=Nbytes) {
+      snprintf (line, Nbytes + 1, cformat, *(int *)Pin);
+      memcpy (Pout, line, Nbytes);
     }
   }
   if (!strcmp (type, "float")) {
-    for (i = 0; i < Nrow; i++, Pin+=4, Pout+=Nval) {
-      snprintf (line, Nval + 1, cformat, *(float *)Pin);
-      memcpy (Pout, line, Nval);
+    for (i = 0; i < Nrow; i++, Pin+=4, Pout+=Nbytes) {
+      snprintf (line, Nbytes + 1, cformat, *(float *)Pin);
+      memcpy (Pout, line, Nbytes);
     }
   }
Index: /trunk/Ohana/src/libfits/table/F_table_format.c
===================================================================
--- /trunk/Ohana/src/libfits/table/F_table_format.c	(revision 41675)
+++ /trunk/Ohana/src/libfits/table/F_table_format.c	(revision 41676)
@@ -5,5 +5,5 @@
 // get the format of a table column
 // Nval : number of joined columns
-// Nbytes : width of column
+// Nbytes : width of column, determined by the type (e.g., float = 4 bytes)
 int gfits_bintable_format (char *format, char *type, int *Nval, int *Nbytes) {
 
@@ -90,4 +90,7 @@
 
 /***********************/
+// get the format of a table column
+// Nval : number of fields (1 for all types except string)
+// Nbytes : width of FITS table column, ie number of bytes in ASCII table
 int gfits_table_format (char *format, char *type, int *Nval, int *Nbytes) {
 
@@ -109,9 +112,9 @@
   int isLong = FALSE;
   char Type = 'x';
-  if (Fchar == 'D') { *Nbytes = 1;  strcpy (type, "double"); Type = 'e'; *Nval = Nv; isLong = TRUE; }
-  if (Fchar == 'E') { *Nbytes = 1;  strcpy (type, "float");  Type = 'e'; *Nval = Nv; }
-  if (Fchar == 'F') { *Nbytes = 1;  strcpy (type, "float");  Type = 'f'; *Nval = Nv; }
-  if (Fchar == 'I') { *Nbytes = 1;  strcpy (type, "int");    Type = 'd'; *Nval = Nv; }
-  if (Fchar == 'A') { *Nbytes = 1;  strcpy (type, "char");   Type = 's'; *Nval = Nv; }
+  if (Fchar == 'D') { *Nbytes = Nv;  strcpy (type, "double"); Type = 'e'; *Nval =  1; isLong = TRUE; }
+  if (Fchar == 'E') { *Nbytes = Nv;  strcpy (type, "float");  Type = 'e'; *Nval =  1; }
+  if (Fchar == 'F') { *Nbytes = Nv;  strcpy (type, "float");  Type = 'f'; *Nval =  1; }
+  if (Fchar == 'I') { *Nbytes = Nv;  strcpy (type, "int");    Type = 'd'; *Nval =  1; }
+  if (Fchar == 'A') { *Nbytes =  1;  strcpy (type, "char");   Type = 's'; *Nval = Nv; }
   if (!*Nbytes) { return (FALSE); }
   
@@ -133,6 +136,6 @@
 /*
   valid TABLE column formats:
-  FN.N  - floating point
-  INN   - integer
+  FN.N  - floating point taking NN characters in the table
+  INN   - integer taking NN characters in the table
   ANN   - NN char string
   
