Index: trunk/Ohana/src/libfits/header/F_H_field.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_H_field.c	(revision 26384)
+++ trunk/Ohana/src/libfits/header/F_H_field.c	(revision 27435)
@@ -6,6 +6,9 @@
 
   char *buf;
-  int i, Nwant, Nfound;
+  off_t i;
+  int Nwant, Nfound;
   char keyword[10];
+
+  if (header[0].buffer == NULL) return NULL;
 
   /* create a blank-padded keyword with exactly 8 characters */
@@ -19,5 +22,5 @@
     /* find the Nth entry */
     Nfound = 0;
-    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
+    for (i = 0; i < header[0].datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
       if (!strncmp (keyword, buf, 8)) {
 	Nfound ++;
@@ -30,5 +33,5 @@
     /* count the entries */
     Nfound = 0;
-    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
+    for (i = 0; i < header[0].datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
       if (!strncmp (keyword, buf, 8)) {
 	Nfound ++;
@@ -41,5 +44,5 @@
     /* find the Nwant entry */
     Nfound = 0;
-    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
+    for (i = 0; i < header[0].datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
       if (!strncmp (keyword, buf, 8)) {
 	Nfound ++;
@@ -50,5 +53,5 @@
   }
 
-  return ((char *) NULL);
+  return NULL;
 
 /* 
@@ -66,5 +69,8 @@
 
   char *buf, *ptr;
-  int i, Nwant, Nfound, Nfield;
+  off_t i;
+  int Nwant, Nfound, Nfield;
+
+  if (header[0].buffer == NULL) return NULL;
 
   Nfield = strlen (field);
@@ -76,5 +82,5 @@
   if (N > 0) {
     Nfound = 0;
-    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
+    for (i = 0; i < header[0].datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
       // have we found a HIERARCH entry?
       if (strncmp ("HIERARCH", buf, 8)) continue;
@@ -90,5 +96,5 @@
     /* count the entries */
     Nfound = 0;
-    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
+    for (i = 0; i < header[0].datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
       if (strncmp ("HIERARCH", buf, 8)) continue;
       ptr = buf + 9; // start of following keyword
@@ -102,5 +108,5 @@
     /* find the Nwant entry */
     Nfound = 0;
-    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
+    for (i = 0; i < header[0].datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
       if (strncmp ("HIERARCH", buf, 8)) continue;
       ptr = buf + 9; // start of following keyword
@@ -111,5 +117,5 @@
   }
 
-  return ((char *) NULL);
+  return NULL;
 
 /* 
@@ -122,9 +128,9 @@
 
 /*********************** fits header field ****************************/
-char *gfits_header_lineno (Header *header, int N) {
+char *gfits_header_lineno (Header *header, off_t N) {
 
   char *buf;
 
-  if (N*80 >= header[0].size) return NULL;
+  if (N*80 >= header[0].datasize) return NULL;
 
   buf = &header[0].buffer[N*80];
Index: trunk/Ohana/src/libfits/header/F_copy_H.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_copy_H.c	(revision 26384)
+++ trunk/Ohana/src/libfits/header/F_copy_H.c	(revision 27435)
@@ -16,5 +16,5 @@
     out[0].Naxis[i] = in[0].Naxis[i];
 
-  out[0].size   = in[0].size;
+  out[0].datasize = in[0].datasize;
 
   out[0].pcount = in[0].pcount;
@@ -24,7 +24,7 @@
 
   if (out[0].buffer != NULL) free (out[0].buffer);
-  ALLOCATE (out[0].buffer, char, out[0].size);
+  ALLOCATE (out[0].buffer, char, out[0].datasize);
   
-  strncpy (out[0].buffer, in[0].buffer, out[0].size);
+  memcpy (out[0].buffer, in[0].buffer, out[0].datasize);
 
   return (TRUE);
Index: trunk/Ohana/src/libfits/header/F_create_H.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_create_H.c	(revision 26384)
+++ trunk/Ohana/src/libfits/header/F_create_H.c	(revision 27435)
@@ -9,5 +9,5 @@
   char axis[10];
   
-  header[0].size = NBYTES;
+  header[0].datasize = NBYTES;
 
   ALLOCATE (header[0].buffer, char, NBYTES);
@@ -17,5 +17,5 @@
   strncpy (header[0].buffer, "END", 3);
 
-  gfits_modify (header, "SIMPLE", "%t", 1, header[0].simple);
+  gfits_modify_alt (header, "SIMPLE", "%t", 1, header[0].simple);
   gfits_modify (header, "BITPIX", "%d", 1, header[0].bitpix);
   gfits_modify (header, "NAXIS",  "%d", 1, header[0].Naxes);
@@ -23,5 +23,5 @@
   for (i = 0; i < header[0].Naxes; i++) {
     snprintf (axis, 10, "NAXIS%d", i + 1);
-    gfits_modify (header,  axis, "%d", 1, header[0].Naxis[i]);
+    gfits_modify (header,  axis, "%lld", 1, (long long) header[0].Naxis[i]);
   }
 
@@ -30,5 +30,5 @@
   gfits_modify (header, "BSCALE", "%lf", 1, header[0].bscale);
   gfits_modify (header, "BZERO",  "%lf", 1, header[0].bzero);
-  gfits_modify (header, "EXTEND", "%t",  1, header[0].extend);
+  gfits_modify_alt (header, "EXTEND", "%t",  1, header[0].extend);
   return (TRUE);
 
Index: trunk/Ohana/src/libfits/header/F_delete.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_delete.c	(revision 26384)
+++ trunk/Ohana/src/libfits/header/F_delete.c	(revision 27435)
@@ -5,5 +5,6 @@
 int gfits_delete (Header *header, char *field, int N) {
   
-  int i, Nbytes;
+  int i;
+  off_t Nbytes;
   char *p1, *p2;
   
@@ -22,7 +23,7 @@
 
   p2 = gfits_header_field (header, "END", 1);
-  if (header[0].size - (p2 - header[0].buffer + FT_LINE_LENGTH) > FT_RECORD_SIZE) {
-    header[0].size -= FT_RECORD_SIZE;
-    REALLOCATE (header[0].buffer, char, header[0].size);
+  if (header[0].datasize - (p2 - header[0].buffer + FT_LINE_LENGTH) > FT_RECORD_SIZE) {
+    header[0].datasize -= FT_RECORD_SIZE;
+    REALLOCATE (header[0].buffer, char, header[0].datasize);
   }
   return (TRUE);
Index: trunk/Ohana/src/libfits/header/F_modify.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_modify.c	(revision 26384)
+++ trunk/Ohana/src/libfits/header/F_modify.c	(revision 27435)
@@ -2,4 +2,5 @@
 # include <gfitsio.h>
 
+// this is only valid for the regular and non-boolean fields
 int gfits_modify (Header *header, char *field, char *mode, int N,...) {
   
@@ -8,5 +9,5 @@
 
   char comment[82], string[82], data[82];
-  char *p, *qs, *qe;
+  char *p, *qe;
   va_list argp;
   
@@ -29,7 +30,7 @@
     
     /* is there enough space for 1 more line? */
-    if (header[0].size - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
-      header[0].size += FT_RECORD_SIZE;
-      REALLOCATE (header[0].buffer, char, header[0].size);
+    if (header[0].datasize - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
+      header[0].datasize += FT_RECORD_SIZE;
+      REALLOCATE (header[0].buffer, char, header[0].datasize);
       p = gfits_header_field (header, "END", 1);
       if (p == NULL) return (FALSE); 
@@ -50,14 +51,79 @@
 
   /* write the numeric modes */
-  if (!strcmp (mode, "%d"))  snprintf (string, 81, "%-8s= %20d / %-s ",     field, va_arg (argp, int),      comment);
-  if (!strcmp (mode, "%u"))  snprintf (string, 81, "%-8s= %20d / %-s ",     field, va_arg (argp, unsigned), comment);
-  if (!strcmp (mode, "%ld")) snprintf (string, 81, "%-8s= %20ld / %-s ",    field, va_arg (argp, long),     comment);
-  if (!strcmp (mode, "%hd")) snprintf (string, 81, "%-8s= %20d / %-s ",     field, va_arg (argp, int),      comment);
-  if (!strcmp (mode, "%f"))  snprintf (string, 81, "%-8s= %20.10f / %-s ",  field, va_arg (argp, double),   comment); 
-  if (!strcmp (mode, "%lf")) snprintf (string, 81, "%-8s= %20.10f / %-s ",  field, va_arg (argp, double),   comment); 
-  if (!strcmp (mode, "%e"))  snprintf (string, 81, "%-8s= %20.10E / %-s ",  field, va_arg (argp, double),   comment); 
-  if (!strcmp (mode, "%le")) snprintf (string, 81, "%-8s= %20.10E / %-s ",  field, va_arg (argp, double),   comment); 
-  if (!strcmp (mode, "%g"))  snprintf (string, 81, "%-8s= %20.10G / %-s ",  field, va_arg (argp, double),   comment); 
-  if (!strcmp (mode, "%lg")) snprintf (string, 81, "%-8s= %20.10G / %-s ",  field, va_arg (argp, double),   comment); 
+  if (!strcmp (mode, "%d"))   snprintf (string, 81, "%-8s= %20d / %-s ",    field, va_arg (argp, int),       	      comment);
+  if (!strcmp (mode, "%ld"))  snprintf (string, 81, "%-8s= %20ld / %-s ",   field, va_arg (argp, long),      	      comment);
+  if (!strcmp (mode, "%lld")) snprintf (string, 81, "%-8s= %20lld / %-s ",  field, va_arg (argp, long long), 	      comment);
+  if (!strcmp (mode, "%Ld"))  snprintf (string, 81, "%-8s= %20lld / %-s ",  field, va_arg (argp, long long), 	      comment);
+  if (!strcmp (mode, "%u"))   snprintf (string, 81, "%-8s= %20u / %-s ",    field, va_arg (argp, unsigned),  	      comment);
+  if (!strcmp (mode, "%lu"))  snprintf (string, 81, "%-8s= %20lu / %-s ",   field, va_arg (argp, unsigned long),      comment);
+  if (!strcmp (mode, "%llu")) snprintf (string, 81, "%-8s= %20llu / %-s ",  field, va_arg (argp, unsigned long long), comment);
+  if (!strcmp (mode, "%Lu"))  snprintf (string, 81, "%-8s= %20llu / %-s ",  field, va_arg (argp, unsigned long long), comment);
+  if (!strcmp (mode, "%hd"))  snprintf (string, 81, "%-8s= %20d / %-s ",    field, va_arg (argp, int),      	      comment); 
+  if (!strcmp (mode, "%f"))   snprintf (string, 81, "%-8s= %20.10f / %-s ", field, va_arg (argp, double),   	      comment); 
+  if (!strcmp (mode, "%lf"))  snprintf (string, 81, "%-8s= %20.10f / %-s ", field, va_arg (argp, double),   	      comment); 
+  if (!strcmp (mode, "%e"))   snprintf (string, 81, "%-8s= %20.10E / %-s ", field, va_arg (argp, double),   	      comment); 
+  if (!strcmp (mode, "%le"))  snprintf (string, 81, "%-8s= %20.10E / %-s ", field, va_arg (argp, double),   	      comment); 
+  if (!strcmp (mode, "%g"))   snprintf (string, 81, "%-8s= %20.10G / %-s ", field, va_arg (argp, double),   	      comment); 
+  if (!strcmp (mode, "%lg"))  snprintf (string, 81, "%-8s= %20.10G / %-s ", field, va_arg (argp, double),   	      comment); 
+
+  /* string value.  Quotes must be at least 18 chars apart */
+  if (!strcmp (mode, "%s")) {
+    strncpy (data, va_arg (argp, char *), 68);
+    snprintf (string, 81, "%-8s= '%-18s' / %-s ", field, data, comment);
+  }
+
+  strncpy (p, string, 80);
+  va_end (argp);
+  return (TRUE);
+
+}
+
+// alternate version for the special types (boolean, comments, COMMENT)
+int gfits_modify_alt (Header *header, char *field, char *mode, int N,...) {
+  
+  /* this function expects one more argument, the value to be written */
+  /* this function is extremely similar to gfits_print, except it allows for changing an existing field. */
+
+  char comment[82], string[82], data[82];
+  char *p, *qs, *qe;
+  va_list argp;
+  
+  va_start (argp, N);
+  bzero (data, 82);
+  bzero (string, 82);
+  bzero (comment, 82);
+
+  if (mode[0] != '%') {
+    fprintf (stderr, "gfits_print: weird mode:  %s\n", mode);
+    return (FALSE);
+  }
+
+  /* find location of desired entry */
+  p = gfits_header_field (header, field, N);
+  if (p == NULL)  {
+    /* new entry, find the END of the header */
+    p = gfits_header_field (header, "END", 1);
+    if (p == NULL) return (FALSE); 
+    
+    /* is there enough space for 1 more line? */
+    if (header[0].datasize - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
+      header[0].datasize += FT_RECORD_SIZE;
+      REALLOCATE (header[0].buffer, char, header[0].datasize);
+      p = gfits_header_field (header, "END", 1);
+      if (p == NULL) return (FALSE); 
+      memset (p + FT_LINE_LENGTH, ' ', FT_RECORD_SIZE);
+    }
+    
+    /* push END line back 1 */
+    memmove ((p + FT_LINE_LENGTH), p, FT_LINE_LENGTH);
+    memset (p, ' ', FT_LINE_LENGTH);
+  } else {
+    /* old entry, save the comment region (is this skipping a character for non-strings?) */
+    qe = gfits_keyword_end (p);
+    qe += 3;
+    qe = MIN (p + 80, qe);
+    strncpy (comment, qe, p + 80 - qe);
+  }
+  gfits_pad_ending (comment, ' ', 82);  /* comment must contain spaces to the end */
 
   /* write the boolean mode */
@@ -67,10 +133,4 @@
     else
       snprintf (string, 81, "%-8s= %18s F / %-s ", field, " ", comment);
-  }
-
-  /* string value.  Quotes must be at least 18 chars apart */
-  if (!strcmp (mode, "%s")) {
-    strncpy (data, va_arg (argp, char *), 68);
-    snprintf (string, 81, "%-8s= '%-18s' / %-s ", field, data, comment);
   }
 
Index: trunk/Ohana/src/libfits/header/F_print.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_print.c	(revision 26384)
+++ trunk/Ohana/src/libfits/header/F_print.c	(revision 27435)
@@ -2,5 +2,80 @@
 # include <gfitsio.h>
 
+// this only prints the regular and non-boolean fields
 int gfits_print (Header *header, char *field, char *mode, int N,...) {
+  
+  /* this function expects one more argument, the value to be written */
+
+  static char blank[] = " ";
+  char string[82], line[80];
+  char *p;
+  va_list argp;  
+
+  va_start (argp, N);
+  
+  if (mode[0] != '%') {
+    fprintf (stderr, "gfits_print: weird mode:  %s\n", mode);
+    return (FALSE);
+  }
+
+  /* this is supposed to create a new field, not modify an old one.  */
+  p = gfits_header_field (header, field, N);
+  if (p != NULL) return (FALSE);
+
+  /* find the END of the header */
+  p = gfits_header_field (header, "END", 1);
+  if (p == NULL) return (FALSE); 
+
+  /* is there enough space for 1 more line? */
+  if (header[0].datasize - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
+    header[0].datasize += FT_RECORD_SIZE;
+    REALLOCATE (header[0].buffer, char, header[0].datasize);
+    /* re-find the "END" marker, in case new memory block is used */
+    p = gfits_header_field (header, "END", 1);
+    if (p == NULL) return (FALSE); 
+    memset (p + FT_LINE_LENGTH, ' ', FT_RECORD_SIZE);
+  }
+
+  /* push END line back 1 */
+  memmove ((p + FT_LINE_LENGTH), p, FT_LINE_LENGTH);
+  memset (p, ' ', FT_LINE_LENGTH);
+
+  /* write the new FITS card, setting the comment to be blank */
+  /* in these lines, the value field will expand as needed, forcing out the comment
+     the total line is limited by snprintf to only 80 chars + EOL */
+
+  /* write the numeric modes */
+  if (!strcmp (mode, "%d"))  { snprintf (string, 81, "%-8s= %20d / %46s ",    field, va_arg (argp, int),                blank); }
+  if (!strcmp (mode, "%ld")) { snprintf (string, 81, "%-8s= %20ld / %46s ",   field, va_arg (argp, long),               blank); }
+  if (!strcmp (mode, "%lld")){ snprintf (string, 81, "%-8s= %20lld / %46s ",  field, va_arg (argp, long long),          blank); }
+  if (!strcmp (mode, "%Ld")) { snprintf (string, 81, "%-8s= %20lld / %46s ",  field, va_arg (argp, long long),          blank); }
+  if (!strcmp (mode, "%u"))  { snprintf (string, 81, "%-8s= %20u / %46s ",    field, va_arg (argp, unsigned),           blank); }
+  if (!strcmp (mode, "%lu")) { snprintf (string, 81, "%-8s= %20lu / %46s ",   field, va_arg (argp, unsigned long),      blank); }
+  if (!strcmp (mode, "%llu")){ snprintf (string, 81, "%-8s= %20llu / %46s ",  field, va_arg (argp, unsigned long long), blank); }
+  if (!strcmp (mode, "%Lu")) { snprintf (string, 81, "%-8s= %20llu / %46s ",  field, va_arg (argp, unsigned long long), blank); }
+  if (!strcmp (mode, "%hd")) { snprintf (string, 81, "%-8s= %20d / %46s ",    field, va_arg (argp, int),                blank); }
+  if (!strcmp (mode, "%f"))  { snprintf (string, 81, "%-8s= %20.10f / %46s ", field, va_arg (argp, double),             blank); }
+  if (!strcmp (mode, "%lf")) { snprintf (string, 81, "%-8s= %20.10f / %46s ", field, va_arg (argp, double),             blank); }
+  if (!strcmp (mode, "%e"))  { snprintf (string, 81, "%-8s= %20.10E / %46s ", field, va_arg (argp, double),             blank); }
+  if (!strcmp (mode, "%le")) { snprintf (string, 81, "%-8s= %20.10E / %46s ", field, va_arg (argp, double),             blank); }
+  if (!strcmp (mode, "%g"))  { snprintf (string, 81, "%-8s= %20.10G / %46s ", field, va_arg (argp, double),             blank); }
+  if (!strcmp (mode, "%lg")) { snprintf (string, 81, "%-8s= %20.10G / %46s ", field, va_arg (argp, double),             blank); }
+
+  /* string value.  Quotes must be at least 18 chars apart.  Longer lines will this should be fixed to allow arbitrary string lengths, up to 69 chars */
+  if (!strcmp (mode, "%s")) {
+    strcpy (line, va_arg (argp, char *));
+    line[68] = 0;
+    snprintf (string, 81, "%-8s= '%-18s' / %46s ", field, line, blank);
+  }
+
+  strncpy (p, string, 80);
+  
+  va_end (argp);
+  return (TRUE);
+
+}
+
+// alternate version for the special types (boolean, comments, COMMENT)
+int gfits_print_alt (Header *header, char *field, char *mode, int N,...) {
   
   /* this function expects one more argument, the value to be written */
@@ -27,7 +102,7 @@
 
   /* is there enough space for 1 more line? */
-  if (header[0].size - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
-    header[0].size += FT_RECORD_SIZE;
-    REALLOCATE (header[0].buffer, char, header[0].size);
+  if (header[0].datasize - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
+    header[0].datasize += FT_RECORD_SIZE;
+    REALLOCATE (header[0].buffer, char, header[0].datasize);
     /* re-find the "END" marker, in case new memory block is used */
     p = gfits_header_field (header, "END", 1);
@@ -40,20 +115,4 @@
   memset (p, ' ', FT_LINE_LENGTH);
 
-  /* write the new FITS card, setting the comment to be blank */
-  /* in these lines, the value field will expand as needed, forcing out the comment
-     the total line is limited by snprintf to only 80 chars + EOL */
-
-  /* write the numeric modes */
-  if (!strcmp (mode, "%d"))  { snprintf (string, 81, "%-8s= %20d / %46s ",    field, va_arg (argp, int),      blank); }
-  if (!strcmp (mode, "%u"))  { snprintf (string, 81, "%-8s= %20d / %46s ",    field, va_arg (argp, unsigned), blank); }
-  if (!strcmp (mode, "%ld")) { snprintf (string, 81, "%-8s= %20ld / %46s ",   field, va_arg (argp, long),     blank); }
-  if (!strcmp (mode, "%hd")) { snprintf (string, 81, "%-8s= %20d / %46s ",    field, va_arg (argp, int),      blank); }
-  if (!strcmp (mode, "%f"))  { snprintf (string, 81, "%-8s= %20.10f / %46s ", field, va_arg (argp, double),   blank); }
-  if (!strcmp (mode, "%lf")) { snprintf (string, 81, "%-8s= %20.10f / %46s ", field, va_arg (argp, double),   blank); }
-  if (!strcmp (mode, "%e"))  { snprintf (string, 81, "%-8s= %20.10E / %46s ", field, va_arg (argp, double),   blank); }
-  if (!strcmp (mode, "%le")) { snprintf (string, 81, "%-8s= %20.10E / %46s ", field, va_arg (argp, double),   blank); }
-  if (!strcmp (mode, "%g"))  { snprintf (string, 81, "%-8s= %20.10G / %46s ", field, va_arg (argp, double),   blank); }
-  if (!strcmp (mode, "%lg")) { snprintf (string, 81, "%-8s= %20.10G / %46s ", field, va_arg (argp, double),   blank); }
-
   /* write the boolean mode */
   if (!strcmp (mode, "%t")) {
@@ -63,11 +122,4 @@
     else
       snprintf (string, 81, "%-8s= %18s F / %46s ", field, blank, blank);
-  }
-
-  /* string value.  Quotes must be at least 18 chars apart.  Longer lines will this should be fixed to allow arbitrary string lengths, up to 69 chars */
-  if (!strcmp (mode, "%s")) {
-    strcpy (line, va_arg (argp, char *));
-    line[68] = 0;
-    snprintf (string, 81, "%-8s= '%-18s' / %46s ", field, line, blank);
   }
 
Index: trunk/Ohana/src/libfits/header/F_read_H.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_read_H.c	(revision 26384)
+++ trunk/Ohana/src/libfits/header/F_read_H.c	(revision 27435)
@@ -23,8 +23,9 @@
 int gfits_load_header (FILE *f, Header *header) {
 
-  int i, done, Nbytes, t1, t2;
+  off_t i, Nbytes;
+  int done, t1, t2;
   char *p;
 
-  header[0].size = 0;
+  header[0].datasize = 0;
   done = FALSE;
   ALLOCATE (header[0].buffer, char, 1);
@@ -32,6 +33,5 @@
   for (i = 0; !done; i++) {
     REALLOCATE (header[0].buffer, char, (i + 1)*FT_RECORD_SIZE);
-    Nbytes = fread (&header[0].buffer[i*FT_RECORD_SIZE], 
-		    sizeof(char), FT_RECORD_SIZE, f);
+    Nbytes = fread (&header[0].buffer[i*FT_RECORD_SIZE], sizeof(char), FT_RECORD_SIZE, f);
     if (Nbytes != FT_RECORD_SIZE) {
       if (feof(f)) return (FALSE);
@@ -40,5 +40,5 @@
     }
     
-    header[0].size += Nbytes;
+    header[0].datasize += Nbytes;
 
     if (i == 0) { 
@@ -60,23 +60,23 @@
     header[0].Naxis[i] = 0;
 
-  gfits_scan (header,  "SIMPLE", "%t",   1, &header[0].simple);
+  gfits_scan_alt (header,  "SIMPLE", "%t",   1, &header[0].simple);
   gfits_scan (header,  "BITPIX", "%d",   1, &header[0].bitpix);
   gfits_scan (header,  "NAXIS",  "%d",   1, &header[0].Naxes);
 				                           
-  gfits_scan (header,  "EXTEND", "%t",   1, &header[0].extend);
-  gfits_scan (header,  "UNSIGN", "%t",   1, &header[0].unsign);
+  gfits_scan_alt (header,  "EXTEND", "%t",   1, &header[0].extend);
+  gfits_scan_alt (header,  "UNSIGN", "%t",   1, &header[0].unsign);
   gfits_scan (header,  "BSCALE", "%lf",  1, &header[0].bscale);
   gfits_scan (header,  "BZERO",  "%lf",  1, &header[0].bzero);
 				       
-  gfits_scan (header,  "NAXIS1", "%d", 1, &header[0].Naxis[0]);
-  gfits_scan (header,  "NAXIS2", "%d", 1, &header[0].Naxis[1]);
-  gfits_scan (header,  "NAXIS3", "%d", 1, &header[0].Naxis[2]);
-  gfits_scan (header,  "NAXIS4", "%d", 1, &header[0].Naxis[3]);
-  gfits_scan (header,  "NAXIS5", "%d", 1, &header[0].Naxis[4]);
-  gfits_scan (header,  "NAXIS6", "%d", 1, &header[0].Naxis[5]);
-  gfits_scan (header,  "NAXIS7", "%d", 1, &header[0].Naxis[6]);
-  gfits_scan (header,  "NAXIS8", "%d", 1, &header[0].Naxis[7]);
-  gfits_scan (header,  "NAXIS9", "%d", 1, &header[0].Naxis[8]);
-  gfits_scan (header, "NAXIS10", "%d", 1, &header[0].Naxis[9]);
+  gfits_scan (header,  "NAXIS1", "%lld", 1, (long long *) &header[0].Naxis[0]);
+  gfits_scan (header,  "NAXIS2", "%lld", 1, (long long *) &header[0].Naxis[1]);
+  gfits_scan (header,  "NAXIS3", "%lld", 1, (long long *) &header[0].Naxis[2]);
+  gfits_scan (header,  "NAXIS4", "%lld", 1, (long long *) &header[0].Naxis[3]);
+  gfits_scan (header,  "NAXIS5", "%lld", 1, (long long *) &header[0].Naxis[4]);
+  gfits_scan (header,  "NAXIS6", "%lld", 1, (long long *) &header[0].Naxis[5]);
+  gfits_scan (header,  "NAXIS7", "%lld", 1, (long long *) &header[0].Naxis[6]);
+  gfits_scan (header,  "NAXIS8", "%lld", 1, (long long *) &header[0].Naxis[7]);
+  gfits_scan (header,  "NAXIS9", "%lld", 1, (long long *) &header[0].Naxis[8]);
+  gfits_scan (header, "NAXIS10", "%lld", 1, (long long *) &header[0].Naxis[9]);
 
   if (!gfits_scan (header, "PCOUNT",  "%d", 1, &header[0].pcount)) {
Index: trunk/Ohana/src/libfits/header/F_read_XH.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_read_XH.c	(revision 26384)
+++ trunk/Ohana/src/libfits/header/F_read_XH.c	(revision 27435)
@@ -31,9 +31,10 @@
   /* read header for extension number N */
 
-  int j, Nmatrix, Nskip;
+  int j;
+  off_t Nmatrix, Nskip;
   Header theader;
   
   /* set f to beginning of file */
-  fseek (f, 0, SEEK_SET);
+  fseeko (f, 0, SEEK_SET);
 
   Nskip = 0;
@@ -47,6 +48,6 @@
 
     /* skip to next header */
-    fseek (f, Nmatrix, SEEK_CUR);
-    Nskip += (Nmatrix + theader.size);
+    fseeko (f, Nmatrix, SEEK_CUR);
+    Nskip += (Nmatrix + theader.datasize);
     gfits_free_header (&theader);
   }
@@ -55,5 +56,5 @@
     return (FALSE);
   }
-  Nskip += header[0].size;
+  Nskip += header[0].datasize;
   return (Nskip);
 }	
Index: trunk/Ohana/src/libfits/header/F_scan.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_scan.c	(revision 26384)
+++ trunk/Ohana/src/libfits/header/F_scan.c	(revision 27435)
@@ -2,4 +2,5 @@
 # include <gfitsio.h>
 
+// this only scans the regular and non-boolean fields
 int gfits_scan (Header *header, char *field, char *mode, int N,...) {
 
@@ -13,9 +14,23 @@
 }
   
+// alternate version for the special types (boolean, comments, COMMENT)
+int gfits_scan_alt (Header *header, char *field, char *mode, int N,...) {
+
+  int status;
+  va_list argp;
+  
+  va_start (argp, N);
+  status = gfits_vscan_alt (header, field, mode, N, argp);
+  va_end (argp);
+  return (status);
+}
+  
+// this only scans the regular and non-boolean fields
 int gfits_vscan (Header *header, char *field, char *mode, int N, va_list argp) {
 
   char *p, *q, *s, tmp[81];
   int Nchar, status;
-  double value;
+  long long value;
+  double fvalue;
   
   /* find the correct line with field */
@@ -26,4 +41,64 @@
   }
 
+  /* all others require '=' in column 8 */
+  if (p[8] != '=') return (FALSE);
+
+  /* extract data into char array (exclude containing ' chars) */
+  if (!strcmp (mode, "%s")) {
+    s = gfits_keyword_start (p); /* points at first char (not ') */
+    q = gfits_keyword_end (p); /* points at following space or ' */
+
+    Nchar = MAX (0, (q - s));
+    bzero (tmp, 81);
+    memcpy (tmp, s, Nchar);
+    stripwhite (tmp);
+    strcpy (va_arg (argp, char *), tmp);
+    return (TRUE);
+  }
+  
+  /* remaining options are numerical data */
+  /* need to interpret 1.0d5 as 1.0e5 */
+  s = gfits_keyword_start (p); /* points at first char (not ') */
+  q = gfits_keyword_end (p); /* points at following space or ' */
+
+  if (!strcmp (mode, "%f") || !strcmp (mode, "%lf")) {
+    fvalue = strtod (s, &q);
+    if ((*q == 'd') || (*q == 'D')) 
+      fvalue *= pow (10.0, atof (q + 1));
+
+    if (!strcmp (mode, "%f"))   { *va_arg (argp, float *)  = fvalue; return (TRUE); }
+    if (!strcmp (mode, "%lf"))  { *va_arg (argp, double *) = fvalue; return (TRUE); }
+  }
+
+  value = strtoll (s, &q, 0);
+  if ((*q == 'd') || (*q == 'D')) value *= pow (10.0, atof (q + 1));
+
+  if (!strcmp (mode, "%d"))   { *va_arg (argp, int *)       	     = value; return (TRUE); }
+  if (!strcmp (mode, "%ld"))  { *va_arg (argp, long *)      	     = value; return (TRUE); }
+  if (!strcmp (mode, "%lld")) { *va_arg (argp, long long *) 	     = value; return (TRUE); }
+  if (!strcmp (mode, "%Ld"))  { *va_arg (argp, long long *) 	     = value; return (TRUE); }
+  if (!strcmp (mode, "%u"))   { *va_arg (argp, unsigned *)  	     = value; return (TRUE); }
+  if (!strcmp (mode, "%lu"))  { *va_arg (argp, unsigned long *)      = value; return (TRUE); }
+  if (!strcmp (mode, "%llu")) { *va_arg (argp, unsigned long long *) = value; return (TRUE); }
+  if (!strcmp (mode, "%Lu"))  { *va_arg (argp, unsigned long long *) = value; return (TRUE); }
+  if (!strcmp (mode, "%hd"))  { *va_arg (argp, short *)     	     = value; return (TRUE); }
+
+  /* no valid mode found */
+  return (FALSE);
+}
+
+// alternate version for the special types (boolean, comments, COMMENT)
+int gfits_vscan_alt (Header *header, char *field, char *mode, int N, va_list argp) {
+
+  char *p, *q, *s, tmp[81];
+  int Nchar, status;
+
+  /* find the correct line with field */
+  p = gfits_header_field (header, field, N);
+  if (p == NULL) {
+    status = gfits_vscan_hierarch (header, field, mode, N, argp);
+    return (status);
+  }
+
   /* non-data entry (COMMENT, HISTORY) */
   if (!strcmp (mode, "%S")) {
@@ -47,17 +122,4 @@
   }
 
-  /* extract data into char array (exclude containing ' chars) */
-  if (!strcmp (mode, "%s")) {
-    s = gfits_keyword_start (p); /* points at first char (not ') */
-    q = gfits_keyword_end (p); /* points at following space or ' */
-
-    Nchar = MAX (0, (q - s));
-    bzero (tmp, 81);
-    memcpy (tmp, s, Nchar);
-    stripwhite (tmp);
-    strcpy (va_arg (argp, char *), tmp);
-    return (TRUE);
-  }
-  
   /* boolean data, requires int target */
   if (!strcmp (mode, "%t")) {
@@ -73,19 +135,4 @@
   }
 
-  /* remaining options are numerical data */
-  /* need to interpret 1.0d5 as 1.0e5 */
-  s = gfits_keyword_start (p); /* points at first char (not ') */
-  q = gfits_keyword_end (p); /* points at following space or ' */
-  value = strtod (s, &q);
-  if ((*q == 'd') || (*q == 'D')) 
-    value *= pow (10.0, atof (q + 1));
-
-  if (!strcmp (mode, "%d"))  { *va_arg (argp, int *)       = value; return (TRUE); }
-  if (!strcmp (mode, "%u"))  { *va_arg (argp, unsigned *)  = value; return (TRUE); }
-  if (!strcmp (mode, "%ld")) { *va_arg (argp, long *)      = value; return (TRUE); }
-  if (!strcmp (mode, "%hd")) { *va_arg (argp, short *)     = value; return (TRUE); }
-  if (!strcmp (mode, "%f"))  { *va_arg (argp, float *)     = value; return (TRUE); }
-  if (!strcmp (mode, "%lf")) { *va_arg (argp, double *)    = value; return (TRUE); }
-
   /* no valid mode found */
   return (FALSE);
@@ -97,5 +144,6 @@
   char *p, *q, *s, tmp[81];
   int Nchar, Nfield;
-  double value;
+  long long value;
+  double fvalue;
   
   /* find the correct line with field */
@@ -156,14 +204,26 @@
   s = gfits_hierarch_keyword_start (p, field); /* points at first char (not ') */
   q = gfits_hierarch_keyword_end (p, field); /* points at following space or ' */
-  value = strtod (s, &q);
-  if ((*q == 'd') || (*q == 'D')) 
-    value *= pow (10.0, atof (q + 1));
-
-  if (!strcmp (mode, "%d"))  { *va_arg (argp, int *)       = value; return (TRUE); }
-  if (!strcmp (mode, "%u"))  { *va_arg (argp, unsigned *)  = value; return (TRUE); }
-  if (!strcmp (mode, "%ld")) { *va_arg (argp, long *)      = value; return (TRUE); }
-  if (!strcmp (mode, "%hd")) { *va_arg (argp, short *)     = value; return (TRUE); }
-  if (!strcmp (mode, "%f"))  { *va_arg (argp, float *)     = value; return (TRUE); }
-  if (!strcmp (mode, "%lf")) { *va_arg (argp, double *)    = value; return (TRUE); }
+
+  if (!strcmp (mode, "%f") || !strcmp (mode, "%lf")) {
+    fvalue = strtod (s, &q);
+    if ((*q == 'd') || (*q == 'D')) 
+      fvalue *= pow (10.0, atof (q + 1));
+
+    if (!strcmp (mode, "%f"))   { *va_arg (argp, float *)  = fvalue; return (TRUE); }
+    if (!strcmp (mode, "%lf"))  { *va_arg (argp, double *) = fvalue; return (TRUE); }
+  }
+
+  value = strtoll (s, &q, 0);
+  if ((*q == 'd') || (*q == 'D')) value *= pow (10.0, atof (q + 1));
+
+  if (!strcmp (mode, "%d"))   { *va_arg (argp, int *)       	     = value; return (TRUE); }
+  if (!strcmp (mode, "%ld"))  { *va_arg (argp, long *)      	     = value; return (TRUE); }
+  if (!strcmp (mode, "%lld")) { *va_arg (argp, long long *) 	     = value; return (TRUE); }
+  if (!strcmp (mode, "%Ld"))  { *va_arg (argp, long long *) 	     = value; return (TRUE); }
+  if (!strcmp (mode, "%u"))   { *va_arg (argp, unsigned *)  	     = value; return (TRUE); }
+  if (!strcmp (mode, "%lu"))  { *va_arg (argp, unsigned long *)      = value; return (TRUE); }
+  if (!strcmp (mode, "%llu")) { *va_arg (argp, unsigned long long *) = value; return (TRUE); }
+  if (!strcmp (mode, "%Lu"))  { *va_arg (argp, unsigned long long *) = value; return (TRUE); }
+  if (!strcmp (mode, "%hd"))  { *va_arg (argp, short *)     	     = value; return (TRUE); }
 
   /* no valid mode found */
Index: trunk/Ohana/src/libfits/header/F_write_H.c
===================================================================
--- trunk/Ohana/src/libfits/header/F_write_H.c	(revision 26384)
+++ trunk/Ohana/src/libfits/header/F_write_H.c	(revision 27435)
@@ -6,5 +6,6 @@
 
   FILE *f;
-  int Nbytes, status;
+  off_t Nbytes;
+  int status;
   
   status = TRUE;
@@ -13,7 +14,7 @@
   if (f == (FILE *) NULL) return (FALSE);
 
-  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].size, f);
+  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].datasize, f);
 
-  if (Nbytes != header[0].size) {
+  if (Nbytes != header[0].datasize) {
     status = FALSE;
   }
@@ -27,11 +28,12 @@
 int gfits_save_header (FILE *f, Header *header) {
 
-  int Nbytes, status;
+  off_t Nbytes; 
+  int status;
   
   status = TRUE;
 
-  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].size, f);
+  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].datasize, f);
 
-  if (Nbytes != header[0].size) {
+  if (Nbytes != header[0].datasize) {
     status = FALSE;
   }
Index: trunk/Ohana/src/libfits/include/gfitsio.h
===================================================================
--- trunk/Ohana/src/libfits/include/gfitsio.h	(revision 26384)
+++ trunk/Ohana/src/libfits/include/gfitsio.h	(revision 27435)
@@ -44,11 +44,11 @@
 
 typedef struct {
-  int                     simple;
-  int                     unsign;
-  int                     extend;
-  int                     bitpix;
-  int                     Naxes;
-  int                     Naxis[FT_MAX_NAXES];
-  int                     size;
+  int                     simple; // T or F
+  int                     unsign; // T or F
+  int                     extend; // T or F
+  int                     bitpix; // 8, 16, 32, 64, or -32, -64
+  int                     Naxes;  // < FT_MAX_NAXES (10)
+  off_t                   Naxis[FT_MAX_NAXES];
+  off_t                   datasize;
   int                     pcount;
   int                     gcount;
@@ -65,6 +65,6 @@
   int                     bitpix;
   int                     Naxes;
-  int                     Naxis[FT_MAX_NAXES];
-  int                     size;
+  off_t                   Naxis[FT_MAX_NAXES];
+  off_t                   datasize;
   double                  bzero;
   double                  bscale;
@@ -76,5 +76,5 @@
   Header                 *header;
   char                   *buffer;
-  int                     size;
+  off_t                   datasize;
 } FTable;
 
@@ -83,16 +83,17 @@
   Header                 *header;
   char                  **buffer;
-  int                     Nrow;
-  int                    *row;
-  int                     size;  /* total buffer size */
-  int                     pad;   /* bytes of padding at the end */
+  off_t                   Nrow;
+  off_t                  *row;
+  off_t                   datasize;  /* total buffer size */
+  off_t                   pad;   /* bytes of padding at the end */
 } VTable;
 
 typedef struct {
-  int  maxlen; 		      // max size of all table rows
-  int  nbytes;		      // number of bytes per column element
-  int  Nstart;		      // byte offset of this column
-  int  heap_start;	      // byte offset to start of HEAP
-  char format;		      // data format character (one of: XLABIJEDCM)
+  int   maxlen; 	      // max size of all table rows
+  int   nbytes;		      // number of bytes per column element
+  int   Nstart;		      // byte offset of this column relative to first column
+  off_t heap_start;	      // byte offset to start of HEAP
+  char  format;		      // data format character (one of: XLABIJEDCM)
+  char  mode;		      // access data pointer type (one of P or Q)
 } VarLengthColumn;
 
@@ -106,5 +107,5 @@
 
 char   *gfits_header_field             PROTO((Header *header, char *field, int N)); 
-char   *gfits_header_lineno            PROTO((Header *header, int N)); 
+char   *gfits_header_lineno            PROTO((Header *header, off_t N)); 
 char   *gfits_keyword_end              PROTO((char *line));
 int     gfits_copy_header              PROTO((Header *in, Header *out)); 
@@ -118,16 +119,20 @@
 int     gfits_init_header              PROTO((Header *header));
 int     gfits_load_header              PROTO((FILE *f, Header *header));
-int     gfits_modify                   PROTO((Header *header, char *field, char *mode, int N,...)); 
-int     gfits_print                    PROTO((Header *header, char *field, char *mode, int N,...)); 
+int     gfits_modify                   PROTO((Header *header, char *field, char *mode, int N,...)) OHANA_FORMAT(printf, 3, 5); 
+int     gfits_print                    PROTO((Header *header, char *field, char *mode, int N,...)) OHANA_FORMAT(printf, 3, 5); 
+int     gfits_modify_alt               PROTO((Header *header, char *field, char *mode, int N,...)); 
+int     gfits_print_alt                PROTO((Header *header, char *field, char *mode, int N,...)); 
 int     gfits_read_Xheader             PROTO((char *filename, Header *header, int N));
 int     gfits_read_header              PROTO((char *filename, Header *header));
 int     gfits_save_header              PROTO((FILE *f, Header *header));
-int     gfits_scan                     PROTO((Header *header, char *field, char *mode, int N,...));
+int     gfits_scan                     PROTO((Header *header, char *field, char *mode, int N,...)) OHANA_FORMAT(scanf, 3, 5);
+int     gfits_scan_alt                 PROTO((Header *header, char *field, char *mode, int N,...));
 int     gfits_set_unsign_mode          PROTO((int mode));
 int     gfits_stripwhite               PROTO((char *string));
 int     gfits_vscan                    PROTO((Header *header, char *field, char *mode, int N, va_list argp));
+int     gfits_vscan_alt                PROTO((Header *header, char *field, char *mode, int N, va_list argp));
 int     gfits_write_header             PROTO((char *filename, Header *header)); 
-int     gfits_data_size                PROTO((Header *header));
-int     gfits_data_min_size            PROTO((Header *header));
+off_t   gfits_data_size                PROTO((Header *header));
+off_t   gfits_data_min_size            PROTO((Header *header));
 int 	gfits_extended_to_primary      PROTO((Header *header, int simple, char *comment));
 int 	gfits_primary_to_extended      PROTO((Header *header, char *exttype, char *comment));
@@ -143,5 +148,5 @@
 /******************************* Matrix functions *************/
 
-void   	gfits_add_matrix_value         PROTO((Matrix *matrix, int x, int y, double value)); 
+void   	gfits_add_matrix_value         PROTO((Matrix *matrix, off_t x, off_t y, double value)); 
 int    	gfits_convert_format           PROTO((Header *header, Matrix *matrix, int outBitpix, double outScale, double outZero, int inBlank, int outUnsign));
 int     gfits_copy_matrix              PROTO((Matrix *in, Matrix *out)); 
@@ -152,12 +157,12 @@
 void    gfits_free_matrix              PROTO((Matrix *matrix)); 
 int     gfits_fwrite_matrix            PROTO((FILE *f, Matrix *matrix));      
-double  gfits_get_matrix_value         PROTO((Matrix *matrix, int x, int y)); 
-void   	gfits_insert_array             PROTO((Matrix *matrix, Matrix *array, int x, int y)); 
+double  gfits_get_matrix_value         PROTO((Matrix *matrix, off_t x, off_t y)); 
+void   	gfits_insert_matrix            PROTO((Matrix *matrix, Matrix *array, off_t x, off_t y)); 
 int    	gfits_load_matrix              PROTO((FILE *f, Matrix *matrix, Header *header));
 int    	gfits_multiply_matrix          PROTO((Matrix *M1, Matrix *M2, Matrix *M3)); 
 int     gfits_read_matrix              PROTO((char *filename, Matrix *matrix));      
 int    	gfits_read_matrix_segment      PROTO((char *filename, Matrix *matrix, char *region));
-int     gfits_read_portion             PROTO((char *filename, Matrix *matrix, int Nskip, int Npix));
-void   	gfits_set_matrix_value         PROTO((Matrix *matrix, int x, int y, double value)); 
+int     gfits_read_portion             PROTO((char *filename, Matrix *matrix, off_t Nskip, off_t Npix));
+void   	gfits_set_matrix_value         PROTO((Matrix *matrix, off_t x, off_t y, double value)); 
 int     gfits_write_matrix             PROTO((char *filename, Matrix *matrix)); 
 int     gfits_uncompress_image 	       PROTO((Header *header, Matrix *matrix, FTable *ftable));
@@ -166,5 +171,5 @@
 int     gfits_byteswap_zdata   	       PROTO((char *zdata, int Nzdata, int bitpix));
 int     gfits_extension_is_compressed  PROTO((Header *header));
-int     gfits_tile_size                PROTO((Matrix *matrix, int *otile, int *ztile));
+off_t   gfits_tile_size                PROTO((Matrix *matrix, int *otile, int *ztile));
 int     gfits_uncompressed_data_pixsize PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions));
 int     gfits_vartable_heap_pixsize    PROTO((char format));
@@ -173,5 +178,5 @@
 
 char   *gfits_table_print              PROTO((FTable *ftable,...));
-int     gfits_add_rows                 PROTO((FTable *ftable, char *data, int Nrow, int Nbytes));
+int     gfits_add_rows                 PROTO((FTable *ftable, char *data, off_t Nrow, off_t Nbytes));
 int     gfits_bintable_format          PROTO((char *format, char *type, int *Nval, int *Nbytes));
 int     gfits_create_table             PROTO((Header *header, FTable *ftable));
@@ -181,28 +186,28 @@
 int   	gfits_fread_ftable             PROTO((FILE *f, FTable *ftable, char *extname)); 
 int   	gfits_fread_ftable_data        PROTO((FILE *f, FTable *ftable));
-int   	gfits_fread_ftable_range       PROTO((FILE *f, FTable *ftable, int start, int Nrows));
-int   	gfits_fread_vtable             PROTO((FILE *f, VTable *vtable, char *extname, int Nrow, int *row));
-int   	gfits_fread_vtable_range       PROTO((FILE *f, VTable *vtable, int start, int Nrows));
+int   	gfits_fread_ftable_range       PROTO((FILE *f, FTable *ftable, off_t start, off_t Nrows));
+int   	gfits_fread_vtable             PROTO((FILE *f, VTable *vtable, char *extname, off_t Nrow, off_t *row));
+int   	gfits_fread_vtable_range       PROTO((FILE *f, VTable *vtable, off_t start, off_t Nrows));
 int     gfits_free_table               PROTO((FTable *ftable));
 int     gfits_free_vtable              PROTO((VTable *vtable));
 int     gfits_fwrite_table             PROTO((FILE *f, FTable *table));
 int     gfits_fwrite_vtable            PROTO((FILE *f, VTable *table));
-int     gfits_fwrite_ftable_range      PROTO((FILE *f, FTable *table, int start, int Nrows, int Ndisk, int Ntotal));
+int     gfits_fwrite_ftable_range      PROTO((FILE *f, FTable *table, off_t start, off_t Nrows, off_t Ndisk, off_t Ntotal));
 int     gfits_get_bintable_column      PROTO((Header *header, FTable *table, char *label, void **data));
 int     gfits_get_bintable_column_type PROTO((Header *header, char *label, char *type, int *Nval));
-void   *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, int *Nrow, int *Ncol));
+void   *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol));
 int     gfits_get_table_column         PROTO((Header *header, FTable *table, char *label, void **data));
 int     gfits_get_table_column_type    PROTO((Header *header, char *label, char *type));
 int     gfits_read_ftable              PROTO((char *filename, FTable *table, char *extname));
 int     gfits_read_table               PROTO((char *filename, FTable *ftable)); 
-int     gfits_set_bintable_column      PROTO((Header *header, FTable *table, char *label, void *data, int Nrow));
-int     gfits_set_table_column         PROTO((Header *header, FTable *table, char *label, void *data, int Nrow));
-int     gfits_table_column             PROTO((FTable *ftable, char *field, char *mode,...));
+int     gfits_set_bintable_column      PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
+int     gfits_set_table_column         PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
+int     gfits_table_column             PROTO((FTable *ftable, char *field, char *mode,...)) OHANA_FORMAT(printf, 3, 4);
 int     gfits_table_format             PROTO((char *format, char *type, int *Nval, int *Nbytes));
 int     gfits_table_scale_data         PROTO((FTable *ftable));
 int     gfits_table_scale_storage      PROTO((FTable *ftable));
-int     gfits_table_to_vtable          PROTO((FTable *ftable, VTable *vtable, int start, int Nkeep));
-int     gfits_vadd_rows                PROTO((VTable *vtable, char *data, int Nrow, int Nbytes));
-int     gfits_vtable_from_ftable       PROTO((FTable *ftable, VTable *vtable, int *row, int Nrow));
+int     gfits_table_to_vtable          PROTO((FTable *ftable, VTable *vtable, off_t start, off_t Nkeep));
+int     gfits_vadd_rows                PROTO((VTable *vtable, char *data, off_t Nrow, off_t Nbytes));
+int     gfits_vtable_from_ftable       PROTO((FTable *ftable, VTable *vtable, off_t *row, off_t Nrow));
 int     gfits_write_table              PROTO((char *filename, FTable *ftable)); 
 
@@ -215,5 +220,5 @@
 
 int     gfits_varlength_column_define  PROTO((FTable *ftable, VarLengthColumn *def, int column));
-void   *gfits_varlength_column_pointer PROTO((FTable *ftable, VarLengthColumn *column, int row, int *length));
+void   *gfits_varlength_column_pointer PROTO((FTable *ftable, VarLengthColumn *column, off_t row, off_t *length));
 
 #endif /* FITSIO */
Index: trunk/Ohana/src/libfits/matrix/F_add_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_add_M.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_add_M.c	(revision 27435)
@@ -3,7 +3,5 @@
 
 /*********************** fits insert array ***********************************/
-void gfits_add_matrix (matrix, array, x, y) 
-Matrix *matrix, *array; 
-int x, y;
+void gfits_add_matrix (Matrix *matrix, Matrix *array, off_t x, off_t y) 
 {
 
@@ -15,7 +13,11 @@
   if ((x + array[0].Naxis[0] > matrix[0].Naxis[0]) ||
       (y + array[0].Naxis[1] > matrix[0].Naxis[1])) {
-    fprintf (stderr, "can't add array here: (%d,%d) - (%d,%d) vs (%d,%d)\n",
-	     x, y, x + array[0].Naxis[0], y + array[0].Naxis[1],
-	     matrix[0].Naxis[0], matrix[0].Naxis[1]);
+    fprintf (stderr, "can't add array here: (%lld,%lld) - (%lld,%lld) vs (%lld,%lld)\n",
+	     (long long) x, 
+	     (long long) y, 
+	     (long long) x + array[0].Naxis[0], 
+	     (long long) y + array[0].Naxis[1],
+	     (long long) matrix[0].Naxis[0], 
+	     (long long) matrix[0].Naxis[1]);
     return;
   }
Index: trunk/Ohana/src/libfits/matrix/F_add_M_value.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_add_M_value.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_add_M_value.c	(revision 27435)
@@ -3,8 +3,5 @@
 
 /***************** fits add matrix value ***********************************/
-void gfits_add_matrix_value (matrix, x, y, Value) 
-Matrix *matrix; 
-int x, y; 
-double Value;
+void gfits_add_matrix_value (Matrix *matrix, off_t x, off_t y, double Value) 
 {
 
Index: trunk/Ohana/src/libfits/matrix/F_compress_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_compress_M.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_compress_M.c	(revision 27435)
@@ -24,4 +24,10 @@
     gfits_delete (header, ZNAME, 1); }
 
+# define MOD_KEYWORD_ALT(ZNAME,NAME,TYPE,IN,OUT) { \
+    if (gfits_scan_alt (header, ZNAME, TYPE, 1, IN)) { \
+      gfits_modify_alt (header, NAME, TYPE, 1, OUT); \
+    } \
+    gfits_delete (header, ZNAME, 1); }
+
 # define MOD_KEYWORD_REQUIRED(ZNAME,NAME,TYPE,IN,OUT) { \
   if (!gfits_scan (header, ZNAME, TYPE, 1, IN)) ESCAPE; \
@@ -31,5 +37,6 @@
 int gfits_uncompress_image (Header *header, Matrix *matrix, FTable *ftable) {
 
-  int i, j, status, zimage, zcol, Nzrows, Nout, Nzdata, max_tile_size;
+  off_t Nzdata, Nzrows, zcol;
+  int i, j, status, zimage, Nout, max_tile_size;
   char cmptype[80];
   char zaxis[10], naxis[10], key[10], word[81], exttype[81], checksum[81], datasum[81];
@@ -51,5 +58,5 @@
 
   // is ZIMAGE present?
-  status = gfits_scan (ftable->header, "ZIMAGE", "%t", 1, &zimage);
+  status = gfits_scan_alt (ftable->header, "ZIMAGE", "%t", 1, &zimage);
   if (!status || !zimage) ESCAPE;
 
@@ -70,5 +77,5 @@
     snprintf (zaxis, 10, "ZNAXIS%d", i + 1);
     snprintf (naxis, 10, "NAXIS%d", i + 1);
-    MOD_KEYWORD_REQUIRED (zaxis,  naxis,  "%d", &header->Naxis[i],  header->Naxis[i]);
+    MOD_KEYWORD_REQUIRED (zaxis,  naxis,  "%lld", (long long *) &header->Naxis[i], (long long) header->Naxis[i]);
   }    
 
@@ -118,5 +125,5 @@
   int have_ztension;
 
-  have_zsimple  = gfits_scan (header, "ZSIMPLE", "%t", 1, &zsimple);
+  have_zsimple  = gfits_scan_alt (header, "ZSIMPLE", "%t", 1, &zsimple);
   have_ztension = gfits_scan (header, "ZTENSION", "%s", 1, exttype);
 
@@ -130,6 +137,6 @@
     gfits_extended_to_primary (header, header->simple, "Image data");
 
-    MOD_KEYWORD ("ZEXTEND",  "EXTEND",   "%t", &header->extend, header->extend);
-    MOD_KEYWORD ("ZBLOCKED", "BLOCKED",  "%t", &header->extend, header->extend);
+    MOD_KEYWORD_ALT ("ZEXTEND",  "EXTEND",   "%t", &header->extend, header->extend);
+    MOD_KEYWORD_ALT ("ZBLOCKED", "BLOCKED",  "%t", &header->extend, header->extend);
   }
 
@@ -140,6 +147,6 @@
     gfits_extended_to_primary (header, header->simple, "Image data");
 
-    MOD_KEYWORD ("ZEXTEND",  "EXTEND",   "%t", &header->extend, header->extend);
-    MOD_KEYWORD ("ZBLOCKED", "BLOCKED",  "%t", &header->extend, header->extend);
+    MOD_KEYWORD_ALT ("ZEXTEND",  "EXTEND",   "%t", &header->extend, header->extend);
+    MOD_KEYWORD_ALT ("ZBLOCKED", "BLOCKED",  "%t", &header->extend, header->extend);
   } 
 
@@ -175,5 +182,5 @@
 
   zscale = 1;
-  gfits_scan (header, "ZSCALE", "%lf", 1, &zscale);
+  gfits_scan (header, "ZSCALE", "%f", 1, &zscale);
 
   zblank = 32767;
@@ -184,5 +191,5 @@
 
   zzero = 0;
-  gfits_scan (header, "ZZERO", "%lf", 1, &zzero);
+  gfits_scan (header, "ZZERO", "%f", 1, &zzero);
 
   // find the COMPRESSED_DATA column (format should be 1PB, 1PI, 1PJ)
@@ -196,7 +203,7 @@
   if (!gfits_varlength_column_define (ftable, &zdef, zcol)) ESCAPE;
   gfits_delete (header, "TFIELDS", 1);
-  snprintf (key, 10, "TTYPE%d", zcol);
+  snprintf (key, 10, "TTYPE%lld", (long long) zcol);
   gfits_delete (header, key, 1);
-  snprintf (key, 10, "TFORM%d", zcol);
+  snprintf (key, 10, "TFORM%lld", (long long) zcol);
   gfits_delete (header, key, 1);
 
@@ -236,12 +243,14 @@
   ALLOCATE (out, char, odata_pixsize*max_tile_size);
 
+  off_t row;
+
   // uncompress the data
   Nzrows = ftable->header->Naxis[1];
-  for (i = 0; i < Nzrows; i++) {
+  for (row = 0; row < Nzrows; row++) {
 
     // expected output size for this tile
     Nout = gfits_tile_size (matrix, otile, ztile);
 
-    zdata = gfits_varlength_column_pointer (ftable, &zdef, i, &Nzdata);
+    zdata = gfits_varlength_column_pointer (ftable, &zdef, row, &Nzdata);
     if (!zdata) return (FALSE);
 
@@ -254,4 +263,5 @@
 
     // gfits_uncompress_data uncompresses from zdata to the temporary output buffer which must be allocated
+    // XXX the tile must not be > 2GB
     if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, odata_pixsize)) return (FALSE);
 
@@ -284,7 +294,7 @@
 
 // true sizes of this tile (in pixels)
-int gfits_tile_size (Matrix *matrix, int *otile, int *ztile) {
-
-  int i, Npixels, Ndimen;
+off_t gfits_tile_size (Matrix *matrix, int *otile, int *ztile) {
+
+  off_t i, Npixels, Ndimen;
 
   Npixels = 1;
@@ -470,5 +480,5 @@
     has_extension = gfits_scan (header, "XTENSION", "%s", 1, extension);
     has_extname = gfits_scan (header, "EXTNAME", "%s", 1, extname);
-    has_zimage  = gfits_scan (header, "ZIMAGE", "%t", 1, &zimage);
+    has_zimage  = gfits_scan_alt (header, "ZIMAGE", "%t", 1, &zimage);
 
     if (has_extension && !strcmp (extension, "IMAGE")) return (FALSE);
@@ -486,6 +496,6 @@
     int ztension, zimage;
 
-    has_zimage   = gfits_scan (header, "ZIMAGE",   "%t", 1, &zimage);
-    has_ztension = gfits_scan (header, "ZTENSION", "%t", 1, &ztension);
+    has_zimage   = gfits_scan_alt (header, "ZIMAGE",   "%t", 1, &zimage);
+    has_ztension = gfits_scan_alt (header, "ZTENSION", "%t", 1, &ztension);
 
     if (has_zimage && zimage) return (TRUE);
Index: trunk/Ohana/src/libfits/matrix/F_convert_format.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_convert_format.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_convert_format.c	(revision 27435)
@@ -24,5 +24,5 @@
       *out = *in*A + B;					\
     }							\
-  REALLOCATE (matrix[0].buffer, char, matrix[0].size); 
+  REALLOCATE (matrix[0].buffer, char, matrix[0].datasize); 
 
 # define CONVERTSAME(MY_NAN)			\
@@ -41,5 +41,5 @@
   inMode  *in;						\
   outMode *out;						\
-  REALLOCATE (matrix[0].buffer, char, matrix[0].size);	\
+  REALLOCATE (matrix[0].buffer, char, matrix[0].datasize);	\
   out = (outMode *)matrix[0].buffer + Npixels - 1;	\
   in  = (inMode  *)matrix[0].buffer + Npixels - 1;	\
@@ -62,5 +62,5 @@
       *out = *in*A + B;					\
     }							\
-  REALLOCATE (matrix[0].buffer, char, matrix[0].size); 
+  REALLOCATE (matrix[0].buffer, char, matrix[0].datasize); 
 
 # define CONVERTSAME_FF(MY_NAN)			\
@@ -79,5 +79,5 @@
   inMode  *in;						\
   outMode *out;						\
-  REALLOCATE (matrix[0].buffer, char, matrix[0].size);	\
+  REALLOCATE (matrix[0].buffer, char, matrix[0].datasize);	\
   out = (outMode *)matrix[0].buffer + Npixels - 1;	\
   in  = (inMode  *)matrix[0].buffer + Npixels - 1;	\
@@ -106,13 +106,13 @@
     return (TRUE);
 
-  matrix[0].bitpix = header[0].bitpix = outBitpix;
-  matrix[0].bscale = header[0].bscale = outScale;
-  matrix[0].bzero  = header[0].bzero  = outZero;
-  matrix[0].unsign = header[0].unsign = outUnsign;
-  matrix[0].size   = gfits_data_size (header);
+  matrix[0].bitpix   = header[0].bitpix = outBitpix;
+  matrix[0].bscale   = header[0].bscale = outScale;
+  matrix[0].bzero    = header[0].bzero  = outZero;
+  matrix[0].unsign   = header[0].unsign = outUnsign;
+  matrix[0].datasize = gfits_data_size (header);
   gfits_modify (header, "BITPIX", "%d", 1, outBitpix);
   gfits_modify (header, "BSCALE", "%lf", 1, outScale);
   gfits_modify (header, "BZERO",  "%lf", 1, outZero);
-  gfits_modify (header, "UNSIGN", "%t", 1, outUnsign);
+  gfits_modify_alt (header, "UNSIGN", "%t", 1, outUnsign);
 
   Npixels          = header[0].Naxis[0]*header[0].Naxis[1];
@@ -426,8 +426,8 @@
   {
     char *out;
-    int Nextra;
+    off_t Nextra;
     
     out = (char *)matrix[0].buffer;
-    Nextra = matrix[0].size - nbytes;
+    Nextra = matrix[0].datasize - nbytes;
     bzero (&out[nbytes], Nextra);
   }
Index: trunk/Ohana/src/libfits/matrix/F_copy_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_copy_M.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_copy_M.c	(revision 27435)
@@ -7,17 +7,17 @@
   int i;
 
-  matrix2[0].unsign = matrix1[0].unsign;
-  matrix2[0].bitpix = matrix1[0].bitpix;
-  matrix2[0].size   = matrix1[0].size;
-  matrix2[0].bzero  = matrix1[0].bzero;
-  matrix2[0].bscale = matrix1[0].bscale;
-  matrix2[0].Naxes  = matrix1[0].Naxes;
+  matrix2[0].unsign   = matrix1[0].unsign;
+  matrix2[0].bitpix   = matrix1[0].bitpix;
+  matrix2[0].datasize = matrix1[0].datasize;
+  matrix2[0].bzero    = matrix1[0].bzero;
+  matrix2[0].bscale   = matrix1[0].bscale;
+  matrix2[0].Naxes    = matrix1[0].Naxes;
   for (i = 0; i < FT_MAX_NAXES; i++) 
     matrix2[0].Naxis[i] = matrix1[0].Naxis[i];
 
   if (matrix2[0].buffer != NULL) free (matrix2[0].buffer);
-  ALLOCATE (matrix2[0].buffer, char, matrix2[0].size);
+  ALLOCATE (matrix2[0].buffer, char, matrix2[0].datasize);
   
-  memcpy (matrix2[0].buffer, matrix1[0].buffer, matrix2[0].size);
+  memcpy (matrix2[0].buffer, matrix1[0].buffer, matrix2[0].datasize);
 
   return (TRUE);
Index: trunk/Ohana/src/libfits/matrix/F_create_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_create_M.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_create_M.c	(revision 27435)
@@ -3,10 +3,8 @@
 
 /*********************** fits create matrix *******************************/
-int gfits_create_matrix (header, matrix) 
-Header *header;
-Matrix *matrix;
-{
+int gfits_create_matrix (Header *header, Matrix *matrix) {
 
-  int i, Nbytes;
+  int i;
+  off_t Nbytes;
 
   matrix[0].bitpix = header[0].bitpix;
@@ -20,7 +18,7 @@
   Nbytes = gfits_data_size (header);
   ALLOCATE (matrix[0].buffer, char, MAX (Nbytes, 1));
-  bzero (matrix[0].buffer, Nbytes);
+  memset (matrix[0].buffer, 0, Nbytes);
   
-  matrix[0].size = Nbytes;
+  matrix[0].datasize = Nbytes;
   return (TRUE);
 
Index: trunk/Ohana/src/libfits/matrix/F_get_M_value.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_get_M_value.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_get_M_value.c	(revision 27435)
@@ -3,5 +3,5 @@
 
 /***************** fits get matrix value ***********************************/
-double gfits_get_matrix_value (Matrix *matrix, int x, int y) {
+double gfits_get_matrix_value (Matrix *matrix, off_t x, off_t y) {
 
   double value;
@@ -11,5 +11,5 @@
     return (0.0);
   pixel = matrix[0].Naxis[0]*y + x;
-  value = HUGE_VAL;
+  value = NAN;
 
   if (matrix[0].unsign) {
Index: trunk/Ohana/src/libfits/matrix/F_insert_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_insert_M.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_insert_M.c	(revision 27435)
@@ -3,15 +3,20 @@
 
 /*********************** fits insert array ***********************************/
-void gfits_insert_matrix (Matrix *matrix, Matrix *array, int x, int y) {
+void gfits_insert_matrix (Matrix *matrix, Matrix *array, off_t x, off_t y) {
 
   /* there is no check here to match BITPIX, BZERO, or BSCALE */
 
-  int i, start_m, Nbytes_m, Nbytes;
+  int i;
+  off_t start_m, Nbytes_m, Nbytes;
 
   if ((x + array[0].Naxis[0] > matrix[0].Naxis[0]) ||
       (y + array[0].Naxis[1] > matrix[0].Naxis[1])) {
-    fprintf (stderr, "can't insert array here: (%d,%d) - (%d,%d) vs (%d,%d)\n",
-	     x, y, x + array[0].Naxis[0], y + array[0].Naxis[1],
-	     matrix[0].Naxis[0], matrix[0].Naxis[1]);
+    fprintf (stderr, "can't insert array here: (%lld,%lld) - (%lld,%lld) vs (%lld,%lld)\n",
+	     (long long) x, 
+	     (long long) y, 
+	     (long long) x + array[0].Naxis[0], 
+	     (long long) y + array[0].Naxis[1],
+	     (long long) matrix[0].Naxis[0], 
+	     (long long) matrix[0].Naxis[1]);
     return;
   }
Index: trunk/Ohana/src/libfits/matrix/F_load_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_load_M.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_load_M.c	(revision 27435)
@@ -13,5 +13,6 @@
 int gfits_load_matrix (FILE *f, Matrix *matrix, Header *header) {
 
-  int i, nbytes, Nbytes;
+  
+  off_t i, nbytes, Nbytes;
 
   matrix[0].bitpix = header[0].bitpix;
@@ -25,5 +26,5 @@
   Nbytes = gfits_data_size (header);
   ALLOCATE (matrix[0].buffer, char, Nbytes);
-  matrix[0].size = Nbytes;
+  matrix[0].datasize = Nbytes;
 
   nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
@@ -94,5 +95,5 @@
   }
   if (nbytes != Nbytes) {  /* this is a FITS error, but often the image is OK */
-    fprintf (stderr, "incomplete block in FITS file: (%d, %d)\n", nbytes, Nbytes);
+    fprintf (stderr, "incomplete block in FITS file: (%lld, %lld)\n", (long long) nbytes, (long long) Nbytes);
     return (TRUE); 
   }
Index: trunk/Ohana/src/libfits/matrix/F_matrix.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_matrix.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_matrix.c	(revision 27435)
@@ -2,7 +2,8 @@
 # include <gfitsio.h>
 
-int gfits_data_size (Header *header) {
+off_t gfits_data_size (Header *header) {
   
-  int i, Nrec, size;
+  int i;
+  off_t Nrec, size;
 
   if (header[0].Naxes == 0) return (0);
@@ -25,7 +26,8 @@
 }
 
-int gfits_data_min_size (Header *header) {
+off_t gfits_data_min_size (Header *header) {
   
-  int i, size;
+  int i;
+  off_t size;
 
   if (header[0].Naxes == 0) return (0);
Index: trunk/Ohana/src/libfits/matrix/F_read_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_read_M.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_read_M.c	(revision 27435)
@@ -18,5 +18,5 @@
   if (f == NULL) return (FALSE);
 
-  fseek (f, header.size, 0);
+  fseeko (f, header.datasize, 0);
   
   status = gfits_load_matrix (f, matrix, &header);
Index: trunk/Ohana/src/libfits/matrix/F_read_portion.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_read_portion.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_read_portion.c	(revision 27435)
@@ -9,9 +9,10 @@
 /*********************** fits read matrix ***********************************/
 /** the result of this function is a matrix with dimension Npix * 1 **/
-int gfits_read_portion (char *filename, Matrix *matrix, int Nskip, int Npix) {
+int gfits_read_portion (char *filename, Matrix *matrix, off_t Nskip, off_t Npix) {
 
   FILE *f;
   Header header;
-  int status, nbytes, Nbytes, Nrec;
+  int status;
+  off_t nbytes, Nbytes, Nrec;
 
   status = gfits_read_header (filename, &header);
@@ -37,5 +38,5 @@
     Nbytes = FT_RECORD_SIZE * Nrec;
   }
-  matrix[0].size = Nbytes;
+  matrix[0].datasize = Nbytes;
   ALLOCATE (matrix[0].buffer, char, Nbytes);
 
@@ -43,5 +44,5 @@
   f = fopen (filename, "r");
   if (f == NULL) return (FALSE);
-  fseek (f, header.size + Nskip, SEEK_SET);
+  fseeko (f, header.datasize + Nskip, SEEK_SET);
   nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
   if (nbytes != Nbytes) {
@@ -52,53 +53,54 @@
 
 # ifdef BYTE_SWAP  
- {
-  int i, perpix;
-  unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, ctmp;
+  {
+    off_t i;
+    int perpix;
+    unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, ctmp;
 
-  perpix = abs(header.bitpix) / 8;
-  if (perpix > 1) {
-    byte0 = (unsigned char *) matrix[0].buffer;
-    byte1 = (unsigned char *) matrix[0].buffer + 1;
-    byte2 = (unsigned char *) matrix[0].buffer + 2;
-    byte3 = (unsigned char *) matrix[0].buffer + 3;
-    byte4 = (unsigned char *) matrix[0].buffer + 4;
-    byte5 = (unsigned char *) matrix[0].buffer + 5;
-    byte6 = (unsigned char *) matrix[0].buffer + 6;
-    byte7 = (unsigned char *) matrix[0].buffer + 7;
-    if (perpix == 2) {
-      for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) {
-	ctmp = *byte0;
-	*byte0 = *byte1;
-	*byte1 = ctmp;
+    perpix = abs(header.bitpix) / 8;
+    if (perpix > 1) {
+      byte0 = (unsigned char *) matrix[0].buffer;
+      byte1 = (unsigned char *) matrix[0].buffer + 1;
+      byte2 = (unsigned char *) matrix[0].buffer + 2;
+      byte3 = (unsigned char *) matrix[0].buffer + 3;
+      byte4 = (unsigned char *) matrix[0].buffer + 4;
+      byte5 = (unsigned char *) matrix[0].buffer + 5;
+      byte6 = (unsigned char *) matrix[0].buffer + 6;
+      byte7 = (unsigned char *) matrix[0].buffer + 7;
+      if (perpix == 2) {
+	for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) {
+	  ctmp = *byte0;
+	  *byte0 = *byte1;
+	  *byte1 = ctmp;
+	}
       }
-    }
-    if (perpix == 4) {
-      for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) {
-	ctmp = *byte0;
-	*byte0 = *byte3;
-	*byte3 = ctmp;
-	ctmp = *byte1;
-	*byte1 = *byte2;
-	*byte2 = ctmp;
+      if (perpix == 4) {
+	for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) {
+	  ctmp = *byte0;
+	  *byte0 = *byte3;
+	  *byte3 = ctmp;
+	  ctmp = *byte1;
+	  *byte1 = *byte2;
+	  *byte2 = ctmp;
+	}
       }
-    }
-    if (perpix == 8) {
-      for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) {
-	ctmp = *byte0;
-	*byte0 = *byte7;
-	*byte7 = ctmp;
-	ctmp = *byte1;
-	*byte1 = *byte6;
-	*byte6 = ctmp;
-	ctmp = *byte1;
-	*byte2 = *byte5;
-	*byte5 = ctmp;
-	ctmp = *byte1;
-	*byte3 = *byte4;
-	*byte4 = ctmp;
+      if (perpix == 8) {
+	for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) {
+	  ctmp = *byte0;
+	  *byte0 = *byte7;
+	  *byte7 = ctmp;
+	  ctmp = *byte1;
+	  *byte1 = *byte6;
+	  *byte6 = ctmp;
+	  ctmp = *byte1;
+	  *byte2 = *byte5;
+	  *byte5 = ctmp;
+	  ctmp = *byte1;
+	  *byte3 = *byte4;
+	  *byte4 = ctmp;
+	}
       }
     }
   }
- }
 # endif
 
@@ -106,9 +108,9 @@
 
   if (nbytes < Nbytes - 2880) {  /* this is a bad FITS error: image is not OK */
-    fprintf (stderr, "error reading in matrix data from FITS file %s (%d < %d - 2880)\n", filename, nbytes, Nbytes);
+    fprintf (stderr, "error reading in matrix data from FITS file %s (%lld < %lld - 2880)\n", filename, (long long) nbytes, (long long) Nbytes);
     return (FALSE);
   }
   if (nbytes != Nbytes) {  /* this is a FITS error, but often the image is OK */
-    fprintf (stderr, "incomplete block in %s: (%d, %d)\n", filename, nbytes, Nbytes);
+    fprintf (stderr, "incomplete block in %s: (%lld, %lld)\n", filename, (long long) nbytes, (long long) Nbytes);
     return (TRUE); 
   }
Index: trunk/Ohana/src/libfits/matrix/F_read_segment.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_read_segment.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_read_segment.c	(revision 27435)
@@ -36,5 +36,6 @@
 int gfits_fread_matrix_segment (FILE *f, Matrix *matrix, Header *header, char *region) {
 
-  int status, i, nbytes, Nbytes, Nskip, NbytesData;
+  int status;
+  off_t i, nbytes, Nbytes, Nskip, NbytesData;
   int wantaxis[FT_MAX_NAXES][2];
   double tmp;
@@ -65,15 +66,15 @@
     matrix[0].Naxis[i] = wantaxis[i][1] - wantaxis[i][0];
 
-  matrix[0].size = abs (matrix[0].bitpix) / 8;
+  matrix[0].datasize = abs (matrix[0].bitpix) / 8;
   for (i = 0; i < matrix[0].Naxes; i++)
-    matrix[0].size *= matrix[0].Naxis[i];
+    matrix[0].datasize *= matrix[0].Naxis[i];
 
   Nskip = wantaxis[2][0]*matrix[0].Naxis[0]*matrix[0].Naxis[1]*abs(matrix[0].bitpix)/8;
-  NbytesData = Nskip + matrix[0].size;
+  NbytesData = Nskip + matrix[0].datasize;
 
   if (NbytesData % FT_RECORD_SIZE) 
-    Nbytes = FT_RECORD_SIZE * ((int) (NbytesData / FT_RECORD_SIZE) + 1) - Nskip;
+    Nbytes = FT_RECORD_SIZE * ((off_t) (NbytesData / FT_RECORD_SIZE) + 1) - Nskip;
   else 
-    Nbytes = FT_RECORD_SIZE * ((int) (NbytesData / FT_RECORD_SIZE)) - Nskip;
+    Nbytes = FT_RECORD_SIZE * ((off_t) (NbytesData / FT_RECORD_SIZE)) - Nskip;
 
   ALLOCATE (matrix[0].buffer, char, MAX (Nbytes, 1));
@@ -86,5 +87,5 @@
 
   /* currently only good for reading in full planes in 3-D */
-  fseek (f, Nskip, SEEK_CUR);
+  fseeko (f, Nskip, SEEK_CUR);
   nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
   if (nbytes != Nbytes) {
@@ -92,5 +93,5 @@
   }
 
-  matrix[0].size = Nbytes;
+  matrix[0].datasize = Nbytes;
 
 # ifdef BYTE_SWAP  
@@ -147,9 +148,9 @@
 
   if (nbytes < Nbytes - 2880) {  /* this is a bad FITS error: image is not OK */
-    fprintf (stderr, "error reading in matrix data from FITS file (%d < %d - 2880)\n", nbytes, Nbytes);
+    fprintf (stderr, "error reading in matrix data from FITS file (%lld < %lld - 2880)\n", (long long) nbytes, (long long) Nbytes);
     return (FALSE);
   }
   if (nbytes != Nbytes) {  /* this is a FITS error, but often the image is OK */
-    fprintf (stderr, "incomplete block in FITS file: (%d, %d)\n", nbytes, Nbytes);
+    fprintf (stderr, "incomplete block in FITS file: (%lld, %lld)\n", (long long) nbytes, (long long) Nbytes);
     return (TRUE); 
   }
Index: trunk/Ohana/src/libfits/matrix/F_set_M_value.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_set_M_value.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_set_M_value.c	(revision 27435)
@@ -3,7 +3,7 @@
 
 /****************** fits set matrix value ***********************************/
-void gfits_set_matrix_value (Matrix *matrix, int x, int y, double Value) {
+void gfits_set_matrix_value (Matrix *matrix, off_t x, off_t y, double Value) {
 
-  int pixel;
+  off_t pixel;
   double value;
 
Index: trunk/Ohana/src/libfits/matrix/F_write_M.c
===================================================================
--- trunk/Ohana/src/libfits/matrix/F_write_M.c	(revision 26384)
+++ trunk/Ohana/src/libfits/matrix/F_write_M.c	(revision 27435)
@@ -11,5 +11,5 @@
   if (f == NULL) return (FALSE);
   
-  fseek (f, 0, SEEK_END);  /* write matrix to end of file! */
+  fseeko (f, 0LL, SEEK_END);  /* write matrix to end of file! */
 
   status = gfits_fwrite_matrix (f, matrix);
@@ -21,5 +21,6 @@
 int gfits_fwrite_matrix (FILE *f, Matrix *matrix) {
 
-  int status, nbytes, Nbytes;
+  int status;
+  off_t nbytes, Nbytes;
 
   status = TRUE;
@@ -27,16 +28,16 @@
   /* this is a bit dangerous: we are not realloc'ing the matrix.
      if the size is wrong, it probably should simply pad the fwrite statement.
-     better policy should be defined (ie, matrix.size always correct blocking?)
+     better policy should be defined (ie, matrix.datasize always correct blocking?)
   */
 
-  if (matrix[0].size % FT_RECORD_SIZE) 
-    nbytes = FT_RECORD_SIZE * ((int) (matrix[0].size / FT_RECORD_SIZE) + 1);
+  if (matrix[0].datasize % FT_RECORD_SIZE) 
+    nbytes = FT_RECORD_SIZE * ((off_t) (matrix[0].datasize / FT_RECORD_SIZE) + 1);
   else 
-    nbytes = FT_RECORD_SIZE * ((int) (matrix[0].size / FT_RECORD_SIZE));
+    nbytes = FT_RECORD_SIZE * ((off_t) (matrix[0].datasize / FT_RECORD_SIZE));
 
   /* this is a bit cumbersome: swap all words, write out file, then swap back... */
 # ifdef BYTE_SWAP  
   { 
-    int i;
+    off_t i;
     unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, tmp;
     int perpix;
@@ -96,5 +97,5 @@
 # ifdef BYTE_SWAP 
   {
-    int i;
+    off_t i;
     unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, tmp;
     int perpix;
Index: trunk/Ohana/src/libfits/table/F_create_T.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_create_T.c	(revision 26384)
+++ trunk/Ohana/src/libfits/table/F_create_T.c	(revision 27435)
@@ -5,5 +5,5 @@
 int gfits_create_table (Header *header, FTable *table) {
 
-  int Nbytes;
+  off_t Nbytes;
   char type[80];
 
@@ -19,5 +19,5 @@
     memset (table[0].buffer, 0, Nbytes);
   }
-  table[0].size = Nbytes;
+  table[0].datasize = Nbytes;
   return (TRUE);
 
@@ -29,5 +29,5 @@
 int gfits_create_vtable (Header *header, VTable *table, int Nrow) {
 
-  int i, Nx, Ny;
+  off_t i, Nx, Ny;
   char type[80];
 
@@ -37,10 +37,10 @@
   Nx = table[0].header[0].Naxis[0];
   Ny = table[0].header[0].Naxis[0];
-  table[0].size = gfits_data_size (header);
-  table[0].pad = table[0].size - Nx*Ny;
+  table[0].datasize = gfits_data_size (header);
+  table[0].pad = table[0].datasize - Nx*Ny;
  
   table[0].Nrow = Nrow;
   ALLOCATE (table[0].buffer, char *, MAX (Nrow, 1));
-  ALLOCATE (table[0].row, int, MAX (Nrow, 1));
+  ALLOCATE (table[0].row, off_t, MAX (Nrow, 1));
   for (i = 0; i < Nrow; i++) {
     ALLOCATE (table[0].buffer[i], char, Nx);
Index: trunk/Ohana/src/libfits/table/F_create_TH.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_create_TH.c	(revision 26384)
+++ trunk/Ohana/src/libfits/table/F_create_TH.c	(revision 27435)
@@ -13,5 +13,5 @@
   char axis[10];
   
-  header[0].size = NBYTES;
+  header[0].datasize = NBYTES;
 
   ALLOCATE (header[0].buffer, char, NBYTES);
@@ -27,5 +27,5 @@
   for (i = 0; i < header[0].Naxes; i++) {
     sprintf (axis, "NAXIS%d", i + 1);
-    gfits_modify (header,  axis, "%d", 1, header[0].Naxis[i], 1);
+    gfits_modify (header,  axis, "%lld", 1, (long long) header[0].Naxis[i]);
   }
   
Index: trunk/Ohana/src/libfits/table/F_define_column.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_define_column.c	(revision 26384)
+++ trunk/Ohana/src/libfits/table/F_define_column.c	(revision 27435)
@@ -5,5 +5,6 @@
 int gfits_define_bintable_column (Header *header, char *format, char *label, char *comment, char *unit, double bscale, double bzero) {
 
-  int Nfields, Nbytes, Nval, Naxis1;
+  off_t Naxis1;
+  int Nfields, Nbytes, Nval;
   char type[16], field[16];
   
@@ -12,5 +13,5 @@
   Nfields = 0;
   gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Naxis1);
+  gfits_scan (header, "NAXIS1",  "%lld", 1, (long long *) &Naxis1);
   Nfields ++;
   Naxis1 += Nbytes*Nval;
@@ -18,5 +19,5 @@
   sprintf (field, "TTYPE%d", Nfields);
   gfits_modify (header, field, "%s", 1, label);
-  gfits_modify (header, field, "%C", 1, comment);
+  gfits_modify_alt (header, field, "%C", 1, comment);
   sprintf (field, "TUNIT%d", Nfields);
   gfits_modify (header, field, "%s", 1, unit);
@@ -34,5 +35,5 @@
   /* update TFIELDS & NAXIS1 */
   gfits_modify (header, "TFIELDS", "%d", 1, Nfields);
-  gfits_modify (header, "NAXIS1",  "%d", 1, Naxis1);
+  gfits_modify (header, "NAXIS1",  "%lld", 1, (long long) Naxis1);
   header[0].Naxis[0] = Naxis1;
 
@@ -43,5 +44,6 @@
 int gfits_define_table_column (Header *header, char *format, char *label, char *comment, char *unit) {
 
-  int Nstart, Nfields, Nbytes, Nval, Naxis1;
+  off_t Naxis1;
+  int Nstart, Nfields, Nbytes, Nval;
   char type[16], field[16], cformat[16];
 
@@ -51,5 +53,5 @@
   Nfields = 0;
   gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Naxis1);
+  gfits_scan (header, "NAXIS1",  "%lld", 1, (long long *) &Naxis1);
   Nstart = Naxis1 + 1;
   Nfields ++;
@@ -58,5 +60,5 @@
   sprintf (field, "TTYPE%d", Nfields);
   gfits_modify (header, field, "%s", 1, label);
-  gfits_modify (header, field, "%C", 1, comment);
+  gfits_modify_alt (header, field, "%C", 1, comment);
   sprintf (field, "TUNIT%d", Nfields);
   gfits_modify (header, field, "%s", 1, unit);
@@ -68,5 +70,5 @@
 
   gfits_modify (header, "TFIELDS", "%d", 1, Nfields);
-  gfits_modify (header, "NAXIS1",  "%d", 1, Naxis1);
+  gfits_modify (header, "NAXIS1",  "%lld", 1, (long long) Naxis1);
   header[0].Naxis[0] = Naxis1;
 
Index: trunk/Ohana/src/libfits/table/F_get_column.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_get_column.c	(revision 26384)
+++ trunk/Ohana/src/libfits/table/F_get_column.c	(revision 27435)
@@ -16,7 +16,8 @@
   tmp = Pin[3]; Pin[3] = Pin[4]; Pin[4] = tmp; }
 
-void *gfits_get_bintable_column_data (Header *header, FTable *table, char *label, char *type, int *Nrow, int *Ncol) {
-
-  int i, N, Nfields, Nval, Nbytes, Nx, Ny, Nstart, Nv, Nb;
+void *gfits_get_bintable_column_data (Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol) {
+
+  off_t Nx, Ny;
+  int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
   char tlabel[80], field[80], format[80], tmpline[16];
   char *Pin, *Pout, *array;
@@ -50,6 +51,6 @@
   
   /* check existing table dimensions */
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2",  "%lld", 1, (long long *) &Ny);
 
   /* scan columns to find insert point */
@@ -153,5 +154,6 @@
 int gfits_get_bintable_column (Header *header, FTable *table, char *label, void **data) {
 
-  int i, N, Nfields, Nval, Nbytes, Nx, Ny, Nstart, Nv, Nb;
+  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;
@@ -185,6 +187,6 @@
   
   /* check existing table dimensions */
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2",  "%lld", 1, (long long *) &Ny);
 
   /* scan columns to find insert point */
@@ -307,5 +309,6 @@
 int gfits_get_table_column (Header *header, FTable *table, char *label, void **data) {
 
-  int i, N, Nfields, Nval, Nbytes, Nx, Ny, Nstart, Nv, Nb;
+  off_t Nx, Ny;
+  int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
   char tlabel[80], field[80], format[80], cformat[80], type[16], tmp[16];
   char *array, *Pin, *Pout, *line;
@@ -333,6 +336,6 @@
   
   /* check existing table dimensions */
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2",  "%lld", 1, (long long *) &Ny);
 
   /* scan columns to find insert point */
Index: trunk/Ohana/src/libfits/table/F_read_T.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_read_T.c	(revision 26384)
+++ trunk/Ohana/src/libfits/table/F_read_T.c	(revision 27435)
@@ -19,10 +19,11 @@
 int gfits_fread_ftable (FILE *f, FTable *table, char *extname) {
 
-  int j, found, Nbytes;
+  int j, found;
+  off_t Nbytes;
   Header *header;
   char tname[80];
 
   header = table[0].header;
-  fseek (f, 0, SEEK_SET);
+  fseeko (f, 0, SEEK_SET);
 
   found = FALSE;
@@ -42,5 +43,5 @@
     /* skip to next header */
     Nbytes = gfits_data_size (header);
-    fseek (f, Nbytes, SEEK_CUR);
+    fseeko (f, Nbytes, SEEK_CUR);
     gfits_free_header (header);
   }
@@ -51,5 +52,5 @@
 int gfits_fread_ftable_data (FILE *f, FTable *table) {
 
-  int Nbytes, Nread;
+  off_t Nbytes, Nread;
   char string[128];
 
@@ -63,5 +64,5 @@
     perror (string);
     if (Nread < gfits_data_min_size (table[0].header)) {
-      fprintf (stderr, "error: fits read error in %s, read %d, need %d\n", __func__, Nread, gfits_data_min_size (table[0].header));
+      fprintf (stderr, "error: fits read error in %s, read %lld, need %lld\n", __func__, (long long) Nread, (long long) gfits_data_min_size (table[0].header));
       gfits_free_table  (table);
       return (FALSE);
@@ -69,12 +70,12 @@
     fprintf (stderr, "warning: file missing pad\n");
   }
-  table[0].size = Nbytes;
+  table[0].datasize = Nbytes;
   return (TRUE);
 }	
 
 /*********************** fits read ftable data ***********************************/
-int gfits_fread_ftable_range (FILE *f, FTable *table, int start, int Nrows) {
-
-  int Nbytes, Nread, Nskip, Nx, Ny;
+int gfits_fread_ftable_range (FILE *f, FTable *table, off_t start, off_t Nrows) {
+
+  off_t Nbytes, Nread, Nskip, Nx, Ny;
 
   /* find disk table size */
@@ -93,5 +94,5 @@
   ALLOCATE (table[0].buffer, char, MAX (Nbytes, 1));
 
-  fseek (f, Nskip, SEEK_CUR);
+  fseeko (f, Nskip, SEEK_CUR);
 
   Nread = fread (table[0].buffer, sizeof (char), Nbytes, f);
@@ -108,6 +109,6 @@
   /* modify structure and header to match actual read rows Ny */
   table[0].header[0].Naxis[1] = Nrows;
-  gfits_modify (table[0].header, "NAXIS2",  "%d", 1, Nrows);
-  table[0].size = gfits_data_size (table[0].header);
+  gfits_modify (table[0].header, "NAXIS2",  "%lld", 1, (long long) Nrows);
+  table[0].datasize = gfits_data_size (table[0].header);
 
   return (TRUE);
@@ -115,7 +116,7 @@
 
 /*********************** fits read ftable data ***********************************/
-int gfits_fread_vtable_range (FILE *f, VTable *table, int start, int Nrows) {
-
-  int i, Nbytes, Nread, Nskip, Nx, Ny;
+int gfits_fread_vtable_range (FILE *f, VTable *table, off_t start, off_t Nrows) {
+
+  off_t i, Nbytes, Nread, Nskip, Nx, Ny;
   char *buffer;
 
@@ -123,6 +124,6 @@
   Nx = table[0].header[0].Naxis[0];
   Ny = table[0].header[0].Naxis[1];
-  table[0].size = gfits_data_size (table[0].header);
-  table[0].pad = table[0].size - Nx*Ny;
+  table[0].datasize = gfits_data_size (table[0].header);
+  table[0].pad = table[0].datasize - Nx*Ny;
 
   if (start < 0) return (FALSE);
@@ -133,5 +134,5 @@
   ALLOCATE (buffer, char, MAX (Nbytes, 1));
 
-  fseek (f, Nskip, SEEK_CUR);
+  fseeko (f, Nskip, SEEK_CUR);
   Nread = fread (buffer, sizeof (char), Nbytes, f);
   if (Nread != Nbytes) {
@@ -141,5 +142,5 @@
   }
 
-  ALLOCATE (table[0].row, int, MAX (Nrows, 1));
+  ALLOCATE (table[0].row, off_t, MAX (Nrows, 1));
   ALLOCATE (table[0].buffer, char *, MAX (Nrows, 1));
   for (i = 0; i < Nrows; i++) {
@@ -154,13 +155,14 @@
 
 /*********************** fits read virtual table ***********************************/
-int gfits_fread_vtable (FILE *f, VTable *table, char *extname, int Nrow, int *row) {
-
-  int i, j, Nbytes, Nread;
-  int start, Nx, Ny, offset;
+int gfits_fread_vtable (FILE *f, VTable *table, char *extname, off_t Nrow, off_t *row) {
+
+  off_t i, j;
+  off_t Nbytes, Nread;
+  off_t start, Nx, Ny, offset;
   Header *header;
   char tname[80];
 
   header = table[0].header;
-  fseek (f, 0, SEEK_SET);
+  fseeko (f, 0, SEEK_SET);
 
   for (j = -1; TRUE; j++) {
@@ -176,5 +178,5 @@
     if (strcmp (tname, extname)) {
       /* skip to next header */
-      fseek (f, Nbytes, SEEK_CUR);
+      fseeko (f, Nbytes, SEEK_CUR);
       gfits_free_header (header);
       continue;
@@ -182,7 +184,7 @@
 
     /* file pointer is at beginning of desired table data */
-    start = ftell (f);
-    gfits_scan (header, "NAXIS1", "%d", 1, &Nx);
-    gfits_scan (header, "NAXIS2", "%d", 1, &Ny);
+    start = ftello (f);
+    gfits_scan (header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+    gfits_scan (header, "NAXIS2", "%lld", 1, (long long *) &Ny);
     for (i = 0; i < Nrow; i++) {
       if (row[i] > Ny) { return (FALSE); }
@@ -193,5 +195,5 @@
       ALLOCATE (table[0].buffer[i], char, MAX (1, Nx));
       offset = start + Nx*row[i];
-      fseek (f, offset, SEEK_SET);
+      fseeko (f, offset, SEEK_SET);
       Nread = fread (table[0].buffer[i], sizeof (char), Nx, f);
       if (Nread != Nx) { 
@@ -202,8 +204,8 @@
 
     table[0].Nrow  = Nrow;
-    ALLOCATE (table[0].row, int, MAX (1, Nrow));    
+    ALLOCATE (table[0].row, off_t, MAX (1, Nrow));    
     for (i = 0; i < Nrow; i++) table[0].row[i] = row[i];
-    table[0].size   = gfits_data_size (table[0].header);
-    table[0].pad    = table[0].size - Nx*Ny;
+    table[0].datasize = gfits_data_size (table[0].header);
+    table[0].pad      = table[0].datasize - Nx*Ny;
     return (TRUE);
   }
@@ -212,8 +214,8 @@
 int gfits_fread_header_extname (FILE *f, Header *header, char *extname) {
 
-  int Nbytes;
+  off_t Nbytes;
   char current[80];
 
-  fseek (f, 0, SEEK_SET);
+  fseeko (f, 0, SEEK_SET);
   gfits_fread_header (f, header);
 
@@ -221,5 +223,5 @@
 
   Nbytes = gfits_data_size (header);
-  fseek (f, Nbytes, SEEK_CUR);
+  fseeko (f, Nbytes, SEEK_CUR);
 
   while (gfits_fread_header (f, header)) {
@@ -227,5 +229,5 @@
     if (!strcmp (current, extname)) return (TRUE);
     Nbytes = gfits_data_size (header);
-    fseek (f, Nbytes, SEEK_CUR);
+    fseeko (f, Nbytes, SEEK_CUR);
   }
   return (FALSE);
Index: trunk/Ohana/src/libfits/table/F_read_TH.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_read_TH.c	(revision 26384)
+++ trunk/Ohana/src/libfits/table/F_read_TH.c	(revision 27435)
@@ -7,5 +7,6 @@
   FILE *f;
   Header header;
-  int status, Nbytes;
+  int status;
+  off_t Nbytes;
   
   status = gfits_read_header (filename, &header);
@@ -23,5 +24,5 @@
 
   Nbytes = gfits_data_size (&header);
-  fseek (f, Nbytes, SEEK_SET);
+  fseeko (f, Nbytes, SEEK_SET);
   gfits_free_header (&header);
 
@@ -36,7 +37,8 @@
   
   char *p;
-  int i, done, status, Nbytes;
+  int i, done, status;
+  off_t Nbytes;
   
-  Theader[0].size = 0;
+  Theader[0].datasize = 0;
   done = FALSE;
   ALLOCATE (Theader[0].buffer, char, 1);
@@ -44,13 +46,13 @@
   for (i = 0; !done; i++) {
     REALLOCATE (Theader[0].buffer, char, (i + 1)*FT_RECORD_SIZE);
-    Nbytes = fread (&Theader[0].buffer[i*FT_RECORD_SIZE], 
-		    sizeof(char), FT_RECORD_SIZE, f);
+    Nbytes = fread (&Theader[0].buffer[i*FT_RECORD_SIZE], sizeof(char), FT_RECORD_SIZE, f);
     if (Nbytes != FT_RECORD_SIZE) {
       perror ("fits matrix read error");
     }
 
-    Theader[0].size += Nbytes;
-    if (Nbytes != FT_RECORD_SIZE) 
+    Theader[0].datasize += Nbytes;
+    if (Nbytes != FT_RECORD_SIZE) {
       done = TRUE;
+    }
     p = gfits_header_field (Theader, "END", 1);
     if (p != NULL)
@@ -68,14 +70,14 @@
   if (!status) return (FALSE);
 				                           
-  gfits_scan (Theader,  "NAXIS1", "%d", 1, &Theader[0].Naxis[0]);
-  gfits_scan (Theader,  "NAXIS2", "%d", 1, &Theader[0].Naxis[1]);
-  gfits_scan (Theader,  "NAXIS3", "%d", 1, &Theader[0].Naxis[2]);
-  gfits_scan (Theader,  "NAXIS4", "%d", 1, &Theader[0].Naxis[3]);
-  gfits_scan (Theader,  "NAXIS5", "%d", 1, &Theader[0].Naxis[4]);
-  gfits_scan (Theader,  "NAXIS6", "%d", 1, &Theader[0].Naxis[5]);
-  gfits_scan (Theader,  "NAXIS7", "%d", 1, &Theader[0].Naxis[6]);
-  gfits_scan (Theader,  "NAXIS8", "%d", 1, &Theader[0].Naxis[7]);
-  gfits_scan (Theader,  "NAXIS9", "%d", 1, &Theader[0].Naxis[8]);
-  gfits_scan (Theader, "NAXIS10", "%d", 1, &Theader[0].Naxis[9]);
+  gfits_scan (Theader,  "NAXIS1", "%lld", 1, (long long *) &Theader[0].Naxis[0]);
+  gfits_scan (Theader,  "NAXIS2", "%lld", 1, (long long *) &Theader[0].Naxis[1]);
+  gfits_scan (Theader,  "NAXIS3", "%lld", 1, (long long *) &Theader[0].Naxis[2]);
+  gfits_scan (Theader,  "NAXIS4", "%lld", 1, (long long *) &Theader[0].Naxis[3]);
+  gfits_scan (Theader,  "NAXIS5", "%lld", 1, (long long *) &Theader[0].Naxis[4]);
+  gfits_scan (Theader,  "NAXIS6", "%lld", 1, (long long *) &Theader[0].Naxis[5]);
+  gfits_scan (Theader,  "NAXIS7", "%lld", 1, (long long *) &Theader[0].Naxis[6]);
+  gfits_scan (Theader,  "NAXIS8", "%lld", 1, (long long *) &Theader[0].Naxis[7]);
+  gfits_scan (Theader,  "NAXIS9", "%lld", 1, (long long *) &Theader[0].Naxis[8]);
+  gfits_scan (Theader, "NAXIS10", "%lld", 1, (long long *) &Theader[0].Naxis[9]);
 
   return (TRUE);
Index: trunk/Ohana/src/libfits/table/F_set_column.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_set_column.c	(revision 26384)
+++ trunk/Ohana/src/libfits/table/F_set_column.c	(revision 27435)
@@ -16,7 +16,9 @@
 
 /***********************/
-int gfits_set_bintable_column (Header *header, FTable *table, char *label, void *data, int Nrow) {
-
-  int i, N, Nfields, Nval, Nbytes, Nx, Ny, nbytes, Nstart, Nv, Nb;
+int gfits_set_bintable_column (Header *header, FTable *table, char *label, void *data, off_t Nrow) {
+
+  off_t Nx, Ny, nbytes;
+  int i, N, Nfields;
+  int Nval, Nbytes, Nstart, Nv, Nb;
   char tlabel[80], field[80], format[80], type[16], tmpline[16];
   char *Pin, *Pout, *array;
@@ -47,15 +49,15 @@
   
   /* check existing table dimensions */
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2", "%lld", 1, (long long *) &Ny);
   if (Ny == 0) { 
     Ny = Nrow;
     header[0].Naxis[1] = Ny;
-    gfits_modify (header, "NAXIS2",  "%d", 1, Ny);
+    gfits_modify (header, "NAXIS2", "%lld", 1, (long long) Ny);
 
     nbytes = gfits_data_size (header);
     REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
     bzero (table[0].buffer, nbytes);
-    table[0].size = nbytes;
+    table[0].datasize = nbytes;
   }
   if (Ny != Nrow) return (FALSE);
@@ -151,7 +153,8 @@
 
 /***********************/
-int gfits_set_table_column (Header *header, FTable *table, char *label, void *data, int Nrow) {
-
-  int i, N, Nfields, Nval, Nbytes, Nx, Ny, nbytes, Nstart, Nv, Nb;
+int gfits_set_table_column (Header *header, FTable *table, char *label, void *data, off_t Nrow) {
+
+  off_t Nx, Ny, nbytes;
+  int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
   char tlabel[80], field[80], format[80], cformat[80], type[16], tmp[16];
   char *array, *Pin, *Pout, *line;
@@ -178,15 +181,15 @@
   
   /* check existing table dimensions */
-  gfits_scan (header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2", "%lld", 1, (long long *) &Ny);
   if (Ny == 0) { 
     Ny = Nrow;
     header[0].Naxis[1] = Ny;
-    gfits_modify (header, "NAXIS2",  "%d", 1, Ny);
+    gfits_modify (header, "NAXIS2", "%lld", 1, (long long) Ny);
 
     nbytes = gfits_data_size (header);
     REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
     bzero (table[0].buffer, nbytes);
-    table[0].size = nbytes;
+    table[0].datasize = nbytes;
   }
   if (Ny != Nrow) return (FALSE);
Index: trunk/Ohana/src/libfits/table/F_table_format.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_table_format.c	(revision 26384)
+++ trunk/Ohana/src/libfits/table/F_table_format.c	(revision 27435)
@@ -3,4 +3,7 @@
 
 /***********************/
+// get the format of a table column
+// Nval : number of joined columns
+// Nbytes : width of column
 int gfits_bintable_format (char *format, char *type, int *Nval, int *Nbytes) {
 
@@ -119,5 +122,5 @@
 
 /** extract a table subset to a vtable ***/
-int gfits_table_to_vtable (FTable *ftable, VTable *vtable, int start, int Nkeep) {
+int gfits_table_to_vtable (FTable *ftable, VTable *vtable, off_t start, off_t Nkeep) {
 
   /* gfits_table_to_vtable (f, v, 0, Ny - 1) - keep all of table
@@ -125,8 +128,8 @@
   */  
 
-  int i, Nx, Ny;
-
-  gfits_scan (ftable[0].header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (ftable[0].header, "NAXIS2", "%d", 1, &Ny);
+  off_t i, Nx, Ny;
+
+  gfits_scan (ftable[0].header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (ftable[0].header, "NAXIS2", "%lld", 1, (long long *) &Ny);
   
   if (start + Nkeep > Ny) return (FALSE);
@@ -134,5 +137,5 @@
   if (Nkeep < 0) return (FALSE);
 
-  ALLOCATE (vtable[0].row, int, MAX (1, Nkeep));
+  ALLOCATE (vtable[0].row, off_t, MAX (1, Nkeep));
   ALLOCATE (vtable[0].buffer, char *, MAX (1, Nkeep));
   for (i = 0; i < Nkeep; i++) {
@@ -143,7 +146,7 @@
   
   vtable[0].header = ftable[0].header;
-  vtable[0].size = ftable[0].size;
+  vtable[0].datasize = ftable[0].datasize;
   vtable[0].Nrow = Nkeep;
-  vtable[0].pad = vtable[0].size - Nx*Ny;
+  vtable[0].pad = vtable[0].datasize - Nx*Ny;
 
   return (TRUE);
@@ -151,19 +154,19 @@
 
 /** convert specified rows to vtable */
-int gfits_vtable_from_ftable (FTable *ftable, VTable *vtable, int *row, int Nrow) {
-
-  int i, N, Nx, Ny;
-
-  gfits_scan (ftable[0].header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (ftable[0].header, "NAXIS2", "%d", 1, &Ny);
+int gfits_vtable_from_ftable (FTable *ftable, VTable *vtable, off_t *row, off_t Nrow) {
+
+  off_t i, N, Nx, Ny;
+
+  gfits_scan (ftable[0].header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (ftable[0].header, "NAXIS2", "%lld", 1, (long long *) &Ny);
 
   /* make empty vtable from table */
-  vtable[0].header = ftable[0].header;  /* make this a copy? */
-  vtable[0].size   = ftable[0].size;
-  vtable[0].pad    = vtable[0].size - Nx*Ny;
-  vtable[0].Nrow   = Ny;
+  vtable[0].header   = ftable[0].header;  /* make this a copy? */
+  vtable[0].datasize = ftable[0].datasize;
+  vtable[0].pad      = vtable[0].datasize - Nx*Ny;
+  vtable[0].Nrow     = Ny;
 
   /* insert selected rows in vtable (mask rows marked with -1) */ 
-  ALLOCATE (vtable[0].row, int, Nrow);
+  ALLOCATE (vtable[0].row, off_t, Nrow);
   ALLOCATE (vtable[0].buffer, char *, Nrow);
   for (N = i = 0; i < Nrow; i++) {
@@ -181,6 +184,6 @@
 char *gfits_table_print (FTable *table,...) { 
   
-  int i, Nx, Nfields;
-  int off, Nchar, Nval, Nbytes;
+  off_t Nx, off;
+  int i, Nchar, Nval, Nbytes, Nfields;
   char *line, format[64], field[16], type[16];
   va_list argp;
@@ -188,5 +191,5 @@
   va_start (argp, table);
 
-  gfits_scan (table[0].header, "NAXIS1",  "%d", 1, &Nx);
+  gfits_scan (table[0].header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
   gfits_scan (table[0].header, "TFIELDS", "%d", 1, &Nfields);
 
@@ -220,7 +223,8 @@
 // apply table tzero, tscal in situ (from storage to data)
 int gfits_table_scale_data (FTable *ftable) {
-
-  int i, j, n, Nx, Ny, Nfields;
-  int off, Nchar, Nval, Nbytes, status;
+  
+  off_t Nx, Ny, off;
+  int i, j, n, Nfields;
+  int Nchar, Nval, Nbytes, status;
   char format[64], field[16], type[16];
   double tzero, tscale;
@@ -232,6 +236,6 @@
   off = 0;
 
-  gfits_scan (ftable[0].header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (ftable[0].header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (ftable[0].header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
+  gfits_scan (ftable[0].header, "NAXIS2",  "%lld", 1, (long long *) &Ny);
   gfits_scan (ftable[0].header, "TFIELDS", "%d", 1, &Nfields);
 
@@ -304,6 +308,7 @@
 int gfits_table_scale_storage (FTable *ftable) {
 
-  int i, j, n, Nx, Ny, Nfields;
-  int off, Nchar, Nval, Nbytes, status;
+  off_t Nx, Ny, off;
+  int i, j, n, Nfields;
+  int Nchar, Nval, Nbytes, status;
   char format[64], field[16], type[16];
   double tzero, tscale;
@@ -315,6 +320,6 @@
   off = 0;
 
-  gfits_scan (ftable[0].header, "NAXIS1",  "%d", 1, &Nx);
-  gfits_scan (ftable[0].header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (ftable[0].header, "NAXIS1",  "%lld", 1, (long long *) &Nx);
+  gfits_scan (ftable[0].header, "NAXIS2",  "%lld", 1, (long long *) &Ny);
   gfits_scan (ftable[0].header, "TFIELDS", "%d", 1, &Nfields);
 
Index: trunk/Ohana/src/libfits/table/F_table_row.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_table_row.c	(revision 26384)
+++ trunk/Ohana/src/libfits/table/F_table_row.c	(revision 27435)
@@ -3,14 +3,14 @@
 
 /*********************** fits table column ****************************/
-int gfits_add_rows (FTable *table, char *data, int Nrow, int Nbytes) {
+int gfits_add_rows (FTable *table, char *data, off_t Nrow, off_t Nbytes) {
 
-  int Nx, Ny;
-  int nbytes, Nstart;
+  off_t Nx, Ny;
+  off_t nbytes, Nstart;
   Header *header;
 
   header = table[0].header;
 
-  gfits_scan (header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2", "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2", "%lld", 1, (long long *) &Ny);
   
   if (header[0].Naxis[1] != Ny) return (FALSE);
@@ -23,9 +23,9 @@
   Ny += Nrow;
   header[0].Naxis[1] = Ny;
-  gfits_modify (header, "NAXIS2",  "%d", 1, Ny);
+  gfits_modify (header, "NAXIS2",  "%lld", 1, (long long) Ny);
 
   nbytes = gfits_data_size (header);
   REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
-  table[0].size = nbytes;
+  table[0].datasize = nbytes;
   
   memcpy (&table[0].buffer[Nstart], data, Nbytes*Nrow);
@@ -35,14 +35,14 @@
 
 /*********************** fits add (real) rows to virtual table ****************************/
-int gfits_vadd_rows (VTable *table, char *data, int Nrow, int Nbytes) {
+int gfits_vadd_rows (VTable *table, char *data, off_t Nrow, off_t Nbytes) {
 
-  int i, Nx, Ny;
-  int Nstart;
+  off_t i, Nx, Ny;
+  off_t Nstart;
   Header *header;
 
   header = table[0].header;
 
-  gfits_scan (header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2", "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2", "%lld", 1, (long long *) &Ny);
   
   if (header[0].Naxis[1] != Ny) return (FALSE);
@@ -54,5 +54,5 @@
   table[0].Nrow += Nrow;
   REALLOCATE (table[0].buffer, char *, table[0].Nrow);
-  REALLOCATE (table[0].row, int, table[0].Nrow);
+  REALLOCATE (table[0].row, off_t, table[0].Nrow);
   for (i = 0; i < Nrow; i++) {
     ALLOCATE (table[0].buffer[Nstart+i], char, MAX (1, Nx));
@@ -64,8 +64,8 @@
   Ny += Nrow;
   header[0].Naxis[1] = Ny;
-  gfits_modify (header, "NAXIS2",  "%d", 1, Ny);
+  gfits_modify (header, "NAXIS2", "%lld", 1, (long long) Ny);
 
-  table[0].size   = gfits_data_size (table[0].header);
-  table[0].pad    = table[0].size - Nx*Ny;
+  table[0].datasize = gfits_data_size (table[0].header);
+  table[0].pad      = table[0].datasize - Nx*Ny;
 
   return (TRUE);
@@ -73,14 +73,14 @@
 
 /*********************** fits table column ****************************/
-int gfits_delete_rows (FTable *table, int Nstart, int Nrow) {
+int gfits_delete_rows (FTable *table, off_t Nstart, off_t Nrow) {
 
-  int Nx, Ny, N0, N1, N2;
-  int nbytes;
+  off_t Nx, Ny, N0, N1, N2;
+  off_t nbytes;
   Header *header;
 
   header = table[0].header;
 
-  gfits_scan (header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (header, "NAXIS2", "%d", 1, &Ny);
+  gfits_scan (header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (header, "NAXIS2", "%lld", 1, (long long *) &Ny);
   
   if (header[0].Naxis[1] != Ny) return (FALSE);
@@ -97,9 +97,9 @@
   Ny -= Nrow;
   header[0].Naxis[1] = Ny;
-  gfits_modify (header, "NAXIS2",  "%d", 1, Ny);
+  gfits_modify (header, "NAXIS2", "%lld", 1, (long long) Ny);
 
   nbytes = gfits_data_size (header);
   REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
-  table[0].size = nbytes;
+  table[0].datasize = nbytes;
   return (TRUE);
 }
Index: trunk/Ohana/src/libfits/table/F_table_varlength.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_table_varlength.c	(revision 26384)
+++ trunk/Ohana/src/libfits/table/F_table_varlength.c	(revision 27435)
@@ -4,5 +4,6 @@
 int gfits_varlength_column_define (FTable *ftable, VarLengthColumn *def, int column) {
 
-  int i, Nv, Nb;
+  int i;
+  int Nv, Nb;
   char *p1, *p2, *p3;
   char field[81];
@@ -32,5 +33,6 @@
   // now p1 must be 'P';
   if (*p1 == 0) return (FALSE);
-  if (*p1 != 'P') return (FALSE);
+  if ((*p1 != 'P') && (*p1 != 'Q')) return (FALSE);
+  def->mode = *p1;
 
   // next value is the actual varlength column format
@@ -61,5 +63,6 @@
   }
 
-  if (!gfits_scan (ftable->header, "THEAP", "%d", 1, &def->heap_start)) {
+  // heap_start must be long long so file may be very large
+  if (!gfits_scan (ftable->header, "THEAP", "%lld", 1, (long long *) &def->heap_start)) {
     def->heap_start = ftable->header->Naxis[0]*ftable->header->Naxis[1];
   }
@@ -68,8 +71,12 @@
 }
 
-void *gfits_varlength_column_pointer (FTable *ftable, VarLengthColumn *column, int row, int *length) {
+// return the data and length for row 'row' of a variable length column
+// is this capable of handling large files (value holding length and offset is an int)?
+void *gfits_varlength_column_pointer (FTable *ftable, VarLengthColumn *column, off_t row, off_t *length) {
 
   void *result;
-  int offset, Nx, *ptr;
+  off_t offset, Nx;
+
+  if ((column->mode != 'P') && (column->mode != 'Q')) abort();
 
   // find the values for the specified row
@@ -89,7 +96,16 @@
 # endif
 
-  ptr = (int *) &ftable->buffer[row*Nx + column->Nstart];
-  *length = ptr[0];
-  offset = ptr[1];
+  if (column->mode == 'P') {
+    int *ptr;
+    ptr = (int *) &ftable->buffer[row*Nx + column->Nstart];
+    *length = ptr[0];
+    offset = ptr[1];
+  }
+  if (column->mode == 'Q') {
+    off_t *ptr;
+    ptr = (off_t *) &ftable->buffer[row*Nx + column->Nstart];
+    *length = ptr[0];
+    offset = ptr[1];
+  }
 
   result = (void *) (ftable->buffer + column->heap_start + offset);
Index: trunk/Ohana/src/libfits/table/F_write_T.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_write_T.c	(revision 26384)
+++ trunk/Ohana/src/libfits/table/F_write_T.c	(revision 27435)
@@ -13,5 +13,5 @@
   if (f == (FILE *) NULL) return (FALSE);
   
-  status = fseek (f, 0, SEEK_END);  /* write table to end of file! */
+  status = fseeko (f, 0LL, SEEK_END);  /* write table to end of file! */
   status = gfits_fwrite_table (f, table);
 
@@ -23,9 +23,9 @@
 int gfits_fwrite_table (FILE *f, FTable *table) {
   
-  int Nbytes;
+  off_t Nbytes;
   
-  Nbytes = fwrite (table[0].buffer, sizeof(char), table[0].size, f);
+  Nbytes = fwrite (table[0].buffer, sizeof(char), table[0].datasize, f);
   
-  if (Nbytes != table[0].size) return (FALSE);
+  if (Nbytes != table[0].datasize) return (FALSE);
   return (TRUE);
 }	
@@ -34,29 +34,29 @@
 int gfits_fwrite_vtable (FILE *f, VTable *table) {
   
-  int i, Nx, Ny, Npad, offset, start;
-  int Nbytes, *row, Nrow;
+  off_t i, Nx, Ny, Npad, offset, start;
+  off_t Nbytes, *row, Nrow;
   char *pad;
 
   Nrow = table[0].Nrow;
   row = table[0].row;
-  gfits_scan (table[0].header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (table[0].header, "NAXIS2", "%d", 1, &Ny);
+  gfits_scan (table[0].header, "NAXIS1", "%lld", 1, (long long *) &Nx);
+  gfits_scan (table[0].header, "NAXIS2", "%lld", 1, (long long *) &Ny);
 
   /* file pointer is at beginning of desired table data */
-  start = ftell (f);
+  start = ftello (f);
   
   for (i = 0; i < Nrow; i++) {
     offset = start + Nx*row[i];
-    fseek (f, offset, SEEK_SET);
+    fseeko (f, offset, SEEK_SET);
     Nbytes = fwrite (table[0].buffer[i], sizeof (char), Nx, f);
     if (Nbytes != Nx) { return (FALSE); }
   }
   
-  Npad = table[0].size - Nx*Ny;
+  Npad = table[0].datasize - Nx*Ny;
   ALLOCATE (pad, char, Npad);
   bzero (pad, Npad);
 
   offset = start + Nx*Ny;
-  fseek (f, offset, SEEK_SET);
+  fseeko (f, offset, SEEK_SET);
   Nbytes = fwrite (pad, sizeof (char), Npad, f);
   if (Nbytes != Npad) { return (FALSE); }
@@ -71,7 +71,7 @@
 
 /*********************** fits read ftable data ***********************************/
-int gfits_fwrite_ftable_range (FILE *f, FTable *ftable, int start, int Nrows, int Ndisk, int Ntotal) {
+int gfits_fwrite_ftable_range (FILE *f, FTable *ftable, off_t start, off_t Nrows, off_t Ndisk, off_t Ntotal) {
 
-  int Nbytes, Nwrite, Nskip, Nx, Npad;
+  off_t Nbytes, Nwrite, Nskip, Nx, Npad;
   char *pad;
 
@@ -79,9 +79,9 @@
   
   /* modify vtable to represent full disk table */
-  gfits_modify (ftable[0].header, "NAXIS2", "%d", 1, Ntotal);
+  gfits_modify (ftable[0].header, "NAXIS2", "%lld", 1, (long long) Ntotal);
   ftable[0].header[0].Naxis[1] = Ntotal;
 
   Nx = ftable[0].header[0].Naxis[0]; // final output table size on disk 
-  ftable[0].size = gfits_data_size (ftable[0].header);
+  ftable[0].datasize = gfits_data_size (ftable[0].header);
 
   Nskip = start * Nx;
@@ -95,5 +95,5 @@
 
   // cursor must be at start of the table (after table header)
-  fseek (f, Nskip, SEEK_CUR);
+  fseeko (f, Nskip, SEEK_CUR);
   Nwrite = fwrite (ftable[0].buffer, sizeof (char), Nbytes, f);
   if (Nwrite != Nbytes) {
@@ -102,5 +102,5 @@
 
   if (Ntotal >= Ndisk) {
-    Npad = ftable[0].size - Nx*Ntotal;
+    Npad = ftable[0].datasize - Nx*Ntotal;
     ALLOCATE (pad, char, Npad);
     bzero (pad, Npad);
Index: trunk/Ohana/src/libfits/table/F_write_TH.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_write_TH.c	(revision 26384)
+++ trunk/Ohana/src/libfits/table/F_write_TH.c	(revision 27435)
@@ -13,5 +13,5 @@
   if (f == (FILE *) NULL) return (FALSE);
   
-  status = fseek (f, 0, SEEK_END);  /* write header to end of file! */
+  status = fseeko (f, 0LL, SEEK_END);  /* write header to end of file! */
   status = gfits_fwrite_Theader (f, header);
 
@@ -23,9 +23,9 @@
 int gfits_fwrite_Theader (FILE *f, Header *header) {
   
-  int Nbytes;
+  off_t Nbytes;
   
-  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].size, f);
+  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].datasize, f);
 
-  if (Nbytes != header[0].size) return (FALSE);
+  if (Nbytes != header[0].datasize) return (FALSE);
   return (TRUE);
 }	
