Index: /branches/eam_branches/ohana.20150429/src/libfits/table/F_table_varlength.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/libfits/table/F_table_varlength.c	(revision 38323)
+++ /branches/eam_branches/ohana.20150429/src/libfits/table/F_table_varlength.c	(revision 38324)
@@ -2,4 +2,5 @@
 # include <gfitsio.h>
 
+// fills the column definition structure for a specific column based on a given table.
 int gfits_varlength_column_define (FTable *ftable, VarLengthColumn *def, int column) {
 
@@ -101,12 +102,10 @@
     *length = ptr[0];
     offset = ptr[1];
-  } else if (column->mode == 'Q') {
+  } 
+  if (column->mode == 'Q') {
     off_t *ptr;
     ptr = (off_t *) &ftable->buffer[row*Nx + column->Nstart];
     *length = ptr[0];
     offset = ptr[1];
-  } else {
-  	// this was actually trapped above
-  	abort();
   }
 
@@ -114,2 +113,52 @@
   return result;
 }
+
+// to generate a compressed image or a compressed table, we need to be able to add data
+// for varlength columns to the heap.  To start, assume we have defined the cartesian
+// portion of the table correctly, and are only extending the heap.
+
+// XXX NOTE: this function assumes the table data is currently in local byte swap order.
+// swap before writing out
+
+// Here are operations we need to do:
+
+int gfits_varlength_column_add_data (FTable *table, char *data, off_t Ndata, int row) {
+
+  // find the current starting point for new data (end of current buffer main data + current heap
+  off_t heap_offset = gfits_data_min_size (table->header);
+  char *heap_ptr = ftable->buffer + heap_offset;
+
+  // extend the buffer size to add the new data
+  off_t Nbytes = heap_offset + Ndata;
+  REALLOCATE (table->buffer, char, Nbytes);
+
+  // add the new data to the table buffer
+  memcpy (heap_ptr, data, Ndata);
+
+  // *** now we add the data description to the table ***
+
+  if ((column->mode != 'P') && (column->mode != 'Q')) abort();
+
+  // find the cell for the specified row & column
+  // the values in the main table for this row and varlength column:
+  Nx = ftable->header->Naxis[0];
+
+  // set the cell values
+  if (column->mode == 'P') {
+    int *ptr;
+    ptr = (int *) &ftable->buffer[row*Nx + column->Nstart];
+    ptr[0] = Ndata;
+    ptr[1] = heap_offset;
+  } 
+  if (column->mode == 'Q') {
+    off_t *ptr;
+    ptr = (off_t *) &ftable->buffer[row*Nx + column->Nstart];
+    ptr[0] = Ndata;
+    ptr[1] = heap_offset;
+  }
+
+  // update maxlen
+  column->maxlen = MAX (column->maxlen, Ndata);
+
+  return TRUE;
+}
