Index: /branches/eam_branches/ohana.20150429/src/opihi/cmd.data/wd.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/opihi/cmd.data/wd.c	(revision 38329)
+++ /branches/eam_branches/ohana.20150429/src/opihi/cmd.data/wd.c	(revision 38330)
@@ -3,5 +3,5 @@
 int wd (int argc, char **argv) {
   
-  int N, Extend;
+  int N, Extend, Compress;
   int newUnsign, newBitpix, newScale, newZero;
   int outUnsign, outBitpix;
@@ -16,4 +16,10 @@
     remove_argument (N, &argc, argv);
     Extend  = TRUE;
+  }
+
+  Compress = FALSE;
+  if ((N = get_argument (argc, argv, "-compress"))) {
+    remove_argument (N, &argc, argv);
+    Compress = TRUE;
   }
 
@@ -162,4 +168,41 @@
   }
   
+  // not compatible with extend
+  if (Compress) {
+    Header myHeader;
+    Matrix myMatrix;
+
+    FILE *f = fopen (argv[2], "w");
+    if (!f) {
+      fprintf (stderr, "ERROR: cannot open image subset file for output %s\n", argv[2]);
+      return FALSE;
+    }
+    
+    gfits_init_header (&myHeader);
+    myHeader.extend = TRUE;
+    gfits_create_header (&myHeader);
+    gfits_create_matrix (&myHeader, &myMatrix);
+    gfits_fwrite_header  (f, &myHeader);
+    gfits_fwrite_matrix  (f, &myMatrix);
+    gfits_free_header (&myHeader);
+    gfits_free_matrix (&myMatrix);
+
+    FTable ftable;
+    Header theader;
+
+    ftable.header = &theader;
+
+    gfits_compress_image (&temp_header, &temp_matrix, &ftable, NULL, "GZIP_1");
+    gfits_byteswap_varlength_column (&ftable, 1);
+    
+    gfits_fwrite_Theader (f, &theader);
+    gfits_fwrite_table  (f, &ftable);
+    fclose (f);
+
+    gfits_free_header (&theader);
+    gfits_free_table (&ftable);
+    return (TRUE);
+  }
+
   /* the actual write-to-disk goes here */
   if (!gfits_write_header (argv[2], &temp_header)) {
Index: /branches/eam_branches/ohana.20150429/src/opihi/cmd.data/write_vectors.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/opihi/cmd.data/write_vectors.c	(revision 38329)
+++ /branches/eam_branches/ohana.20150429/src/opihi/cmd.data/write_vectors.c	(revision 38330)
@@ -3,9 +3,8 @@
 int write_vectors (int argc, char **argv) {
   
-  int append;
   int i, j, Nvec, Ne, N;
   FILE *f;
   char **fmtlist, *fmttype;
-  char *p0, *p1, *p2, *format, *FITS;
+  char *p0, *p1, *p2, *format;
   Vector **vec;
 
@@ -34,5 +33,5 @@
 
   /* option generate a FITS output table */
-  FITS = NULL;
+  char *FITS = NULL;
   if ((N = get_argument (argc, argv, "-fits"))) {
     remove_argument (N, &argc, argv);
@@ -58,8 +57,17 @@
   }
 
-  append = FALSE;
+  int append = FALSE;
   if ((N = get_argument (argc, argv, "-append"))) {
     remove_argument (N, &argc, argv);
     append = TRUE;
+  }
+
+  int compress = FALSE;
+  if ((N = get_argument (argc, argv, "-compress"))) {
+    remove_argument (N, &argc, argv);
+    compress = TRUE;
+    if (!FITS) {
+      fprintf (stderr, "NOTE: write_vectors -compress has no effect on non-FITS\n");
+    }
   }
 
@@ -105,5 +113,5 @@
 
   if (FITS) {
-    int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, format);
+    int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, compress, format);
     free (vec);
     return status;
Index: /branches/eam_branches/ohana.20150429/src/opihi/dvo/avextract.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/opihi/dvo/avextract.c	(revision 38329)
+++ /branches/eam_branches/ohana.20150429/src/opihi/dvo/avextract.c	(revision 38330)
@@ -256,5 +256,5 @@
   // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
   if (RESULT_FILE && !SKIP_RESULTS) {
-    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, NULL);
+    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, FALSE, NULL);
     if (!status) {
       goto escape;
Index: /branches/eam_branches/ohana.20150429/src/opihi/dvo/avmatch.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/opihi/dvo/avmatch.c	(revision 38329)
+++ /branches/eam_branches/ohana.20150429/src/opihi/dvo/avmatch.c	(revision 38330)
@@ -115,5 +115,5 @@
 
       CoordsFile = abspath("coords.fits", 1024);
-      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
+      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL);
       if (!status) goto escape;
     }
@@ -302,5 +302,5 @@
       vec[i][0].Nelements = Nfound;
     }
-    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields + 1, FALSE, NULL);
+    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields + 1, FALSE, FALSE, NULL);
     free (vec[Nfields]->elements.Int);
     free (vec[Nfields]);
Index: /branches/eam_branches/ohana.20150429/src/opihi/dvo/dvo_host_utils.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/opihi/dvo/dvo_host_utils.c	(revision 38329)
+++ /branches/eam_branches/ohana.20150429/src/opihi/dvo/dvo_host_utils.c	(revision 38330)
@@ -230,5 +230,5 @@
   // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
   if (ResultFile) {
-    int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nvec, FALSE, NULL);
+    int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nvec, FALSE, FALSE, NULL);
     if (!status) {
       gprint (GP_ERR, "failed to write result file %s\n", ResultFile);
Index: /branches/eam_branches/ohana.20150429/src/opihi/dvo/mextract.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/opihi/dvo/mextract.c	(revision 38329)
+++ /branches/eam_branches/ohana.20150429/src/opihi/dvo/mextract.c	(revision 38330)
@@ -317,5 +317,5 @@
   // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
   if (RESULT_FILE && !SKIP_RESULTS) {
-    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, NULL);
+    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, FALSE, NULL);
     if (!status) goto escape;
   }
Index: /branches/eam_branches/ohana.20150429/src/opihi/dvo/mmatch.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/opihi/dvo/mmatch.c	(revision 38329)
+++ /branches/eam_branches/ohana.20150429/src/opihi/dvo/mmatch.c	(revision 38330)
@@ -150,5 +150,5 @@
       // XXX this is now set for both cases...
       CoordsFile = abspath("coords.fits", 1024);
-      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
+      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL);
       if (!status) goto escape;
     }
@@ -349,5 +349,5 @@
       vec[Nfields-1] = IDXvec;
     }
-    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields, FALSE, NULL);
+    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields, FALSE, FALSE, NULL);
     if (!status) goto escape;
   }
Index: /branches/eam_branches/ohana.20150429/src/opihi/include/dvomath.h
===================================================================
--- /branches/eam_branches/ohana.20150429/src/opihi/include/dvomath.h	(revision 38329)
+++ /branches/eam_branches/ohana.20150429/src/opihi/include/dvomath.h	(revision 38330)
@@ -167,5 +167,5 @@
 
 /* vector IO functions */
-int           WriteVectorTableFITS  PROTO((char *filename, char *extname, Vector **vec, int Nvec, int append, char *format));
+int           WriteVectorTableFITS  PROTO((char *filename, char *extname, Vector **vec, int Nvec, int append, int compress, char *format));
 Vector      **ReadVectorTableFITS   PROTO((char *filename, char *extname, int *Nvec));
 
Index: /branches/eam_branches/ohana.20150429/src/opihi/lib.shell/VectorIO.c
===================================================================
--- /branches/eam_branches/ohana.20150429/src/opihi/lib.shell/VectorIO.c	(revision 38329)
+++ /branches/eam_branches/ohana.20150429/src/opihi/lib.shell/VectorIO.c	(revision 38330)
@@ -1,6 +1,6 @@
 # include "opihi.h"
   
-// write a set of vectors to a FITS file (vectors names become fits column names)
-int WriteVectorTable (Header *theader, FTable *ftable, char *extname, Vector **vec, int Nvec, char *format) {
+// write a set of vectors to a FITS FTable structure (vectors names become fits column names)
+static int WriteVectorTable (FTable *ftable, char *extname, Vector **vec, int Nvec, char *format) {
   
   int j;
@@ -8,4 +8,5 @@
   char *tformat = NULL;
 
+  Header *theader = ftable->header;
   gfits_create_table_header (theader, "BINTABLE", extname);
 
@@ -71,10 +72,10 @@
   
 // write a set of vectors to a FITS file (vectors names become fits column names)
-int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, char *format) {
-  
-  Header header;
-  Matrix matrix;
-  Header theader;
-  FTable ftable;
+int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, int compress, char *format) {
+  
+  Header rawheader;
+  Header cmpheader;
+  FTable rawtable;
+  FTable cmptable;
 
   FILE *f = NULL;
@@ -91,8 +92,28 @@
   }
 
-  if (!WriteVectorTable (&theader, &ftable, extname, vec, Nvec, format)) goto escape;
+  // init so free below does not fail if table is not created
+  gfits_init_header (&rawheader);
+  gfits_init_header (&cmpheader);
+  gfits_init_table (&rawtable);
+  gfits_init_table (&cmptable);
+
+  rawtable.header = &rawheader;
+  if (!WriteVectorTable (&rawtable, extname, vec, Nvec, format)) goto escape;
+
+  FTable *outtable = &rawtable;
+  Header *outheader = &rawheader;
+
+  if (compress) {
+    cmptable.header = &cmpheader;
+    if (!gfits_compress_table (&rawtable, &cmptable, 10, "GZIP_1")) goto escape;
+    outtable = &cmptable;
+    outheader = &cmpheader;
+  }
 
   if (!append) {
+    Header header;
+    Matrix matrix;
     gfits_init_header (&header);
+    gfits_init_matrix (&matrix);
     header.extend = TRUE;
     gfits_create_header (&header);
@@ -103,9 +124,16 @@
     gfits_free_matrix (&matrix);
   }
-  gfits_fwrite_Theader (f, &theader);
-  gfits_fwrite_table  (f, &ftable);
-
-  gfits_free_header (&theader);
-  gfits_free_table (&ftable);
+
+  // write the actual table data
+  gfits_fwrite_Theader (f, outheader);
+  gfits_fwrite_table  (f, outtable);
+
+  gfits_free_header (&rawheader);
+  gfits_free_table (&rawtable);
+
+  if (compress) {
+    gfits_free_header (&cmpheader);
+    gfits_free_table (&cmptable);
+  }
 
   fclose (f);
@@ -114,10 +142,11 @@
 
  escape:
-  if (!append) {
-    gfits_free_header (&header);
-    gfits_free_matrix (&matrix);
-  }
-  gfits_free_header (&theader);
-  gfits_free_table (&ftable);
+  gfits_free_header (&rawheader);
+  gfits_free_table (&rawtable);
+
+  if (compress) {
+    gfits_free_header (&cmpheader);
+    gfits_free_table (&cmptable);
+  }
 
   fclose (f);
