Index: branches/eam_branches/ohana.20190329/src/opihi/cmd.data/write_vectors.c
===================================================================
--- branches/eam_branches/ohana.20190329/src/opihi/cmd.data/write_vectors.c	(revision 40784)
+++ branches/eam_branches/ohana.20190329/src/opihi/cmd.data/write_vectors.c	(revision 40791)
@@ -32,12 +32,23 @@
   }
 
-  /* option generate a FITS output table */
+  // option generate a FITS output table (FITS holds the filename) 
+  // in FITS output context, -header is interpretted as a buffer containing
+  // header keywords to supplement the FITS table header
   char *FITS = NULL;
+  Header *fitsheader = NULL;
+  Buffer *headbuffer = NULL;
   if ((N = get_argument (argc, argv, "-fits"))) {
     remove_argument (N, &argc, argv);
     FITS = strcreate (argv[N]);
     remove_argument (N, &argc, argv);
-  }
-
+
+    if ((N = get_argument (argc, argv, "-header"))) {
+      remove_argument (N, &argc, argv);
+      if ((headbuffer = SelectBuffer (argv[N], OLDBUFFER, TRUE)) == NULL) return (FALSE);
+      fitsheader = &headbuffer->header;
+      remove_argument (N, &argc, argv);
+    }
+  }
+  
   /* option generate a FITS output table */
   int CSV = FALSE;
@@ -124,5 +135,5 @@
 
   if (FITS) {
-    int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, compress, format, Ntile);
+    int status = WriteVectorTableFITS (argv[1], FITS, fitsheader, vec, Nvec, append, compress, format, Ntile);
     free (vec);
     return status;
@@ -260,4 +271,6 @@
     gprint (GP_ERR, "  -append : write to the end of the existing file\n");
     gprint (GP_ERR, "  -fits NAME : write a fits table (extention name is NAME, column names match vector names)\n");
+    gprint (GP_ERR, "     in FITS output context, -header takes an additional argument which is interpretted\n");
+    gprint (GP_ERR, "     as a buffer containing header keywords to supplement the FITS table header\n");
     gprint (GP_ERR, "  -csv : write a comma-separated values file (eg, to read in excel)\n");
     gprint (GP_ERR, "  -f \"format\" : provide formatting codes for output:\n");
Index: branches/eam_branches/ohana.20190329/src/opihi/dvo/avextract.c
===================================================================
--- branches/eam_branches/ohana.20190329/src/opihi/dvo/avextract.c	(revision 40784)
+++ branches/eam_branches/ohana.20190329/src/opihi/dvo/avextract.c	(revision 40791)
@@ -272,5 +272,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, FALSE, NULL, 0);
+    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", NULL, vec, Nreturn, FALSE, FALSE, NULL, 0);
     if (!status) {
       goto escape;
Index: branches/eam_branches/ohana.20190329/src/opihi/dvo/avmatch.c
===================================================================
--- branches/eam_branches/ohana.20190329/src/opihi/dvo/avmatch.c	(revision 40784)
+++ branches/eam_branches/ohana.20190329/src/opihi/dvo/avmatch.c	(revision 40791)
@@ -114,5 +114,5 @@
 
       CoordsFile = abspath("coords.fits", 1024);
-      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL, 0);
+      int status = WriteVectorTableFITS (CoordsFile, "COORDS", NULL, vec, 2, FALSE, FALSE, NULL, 0);
       if (!status) goto escape;
     }
@@ -301,5 +301,5 @@
       vec[i][0].Nelements = Nfound;
     }
-    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields + 1, FALSE, FALSE, NULL, 0);
+    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", NULL, vec, Nfields + 1, FALSE, FALSE, NULL, 0);
     free (vec[Nfields]->elements.Int);
     free (vec[Nfields]);
Index: branches/eam_branches/ohana.20190329/src/opihi/dvo/avperiodomatch.c
===================================================================
--- branches/eam_branches/ohana.20190329/src/opihi/dvo/avperiodomatch.c	(revision 40784)
+++ branches/eam_branches/ohana.20190329/src/opihi/dvo/avperiodomatch.c	(revision 40791)
@@ -99,5 +99,5 @@
 
       CoordsFile = abspath("coords.fits", 1024);
-      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL, 0);
+      int status = WriteVectorTableFITS (CoordsFile, "COORDS", NULL, vec, 2, FALSE, FALSE, NULL, 0);
       if (!status) goto escape;
       free (vec);
Index: branches/eam_branches/ohana.20190329/src/opihi/dvo/avselect.c
===================================================================
--- branches/eam_branches/ohana.20190329/src/opihi/dvo/avselect.c	(revision 40784)
+++ branches/eam_branches/ohana.20190329/src/opihi/dvo/avselect.c	(revision 40791)
@@ -132,5 +132,5 @@
 
       CoordsFile = abspath("coords.fits", 1024);
-      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL, 0);
+      int status = WriteVectorTableFITS (CoordsFile, "COORDS", NULL, vec, 2, FALSE, FALSE, NULL, 0);
       if (!status) goto escape;
     }
@@ -327,5 +327,5 @@
       vec[NfieldsOut-1] = RADvec;
     }
-    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, NfieldsOut, FALSE, FALSE, NULL, 0);
+    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", NULL, vec, NfieldsOut, FALSE, FALSE, NULL, 0);
     if (!status) goto escape;
   }
Index: branches/eam_branches/ohana.20190329/src/opihi/dvo/dvo_host_utils.c
===================================================================
--- branches/eam_branches/ohana.20190329/src/opihi/dvo/dvo_host_utils.c	(revision 40784)
+++ branches/eam_branches/ohana.20190329/src/opihi/dvo/dvo_host_utils.c	(revision 40791)
@@ -233,5 +233,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, FALSE, NULL, 0);
+    int status = WriteVectorTableFITS (ResultFile, "RESULT", NULL, vec, Nvec, FALSE, FALSE, NULL, 0);
     if (!status) {
       gprint (GP_ERR, "failed to write result file %s\n", ResultFile);
Index: branches/eam_branches/ohana.20190329/src/opihi/dvo/mextract.c
===================================================================
--- branches/eam_branches/ohana.20190329/src/opihi/dvo/mextract.c	(revision 40784)
+++ branches/eam_branches/ohana.20190329/src/opihi/dvo/mextract.c	(revision 40791)
@@ -352,5 +352,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, FALSE, NULL, 0);
+    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", NULL, vec, Nreturn, FALSE, FALSE, NULL, 0);
     if (!status) goto escape;
   }
Index: branches/eam_branches/ohana.20190329/src/opihi/dvo/mmatch.c
===================================================================
--- branches/eam_branches/ohana.20190329/src/opihi/dvo/mmatch.c	(revision 40784)
+++ branches/eam_branches/ohana.20190329/src/opihi/dvo/mmatch.c	(revision 40791)
@@ -148,5 +148,5 @@
       // XXX this is now set for both cases...
       CoordsFile = abspath("coords.fits", 1024);
-      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL, 0);
+      int status = WriteVectorTableFITS (CoordsFile, "COORDS", NULL, vec, 2, FALSE, FALSE, NULL, 0);
       if (!status) goto escape;
     }
@@ -349,5 +349,5 @@
       vec[Nfields-1] = IDXvec;
     }
-    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields, FALSE, FALSE, NULL, 0);
+    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", NULL, vec, Nfields, FALSE, FALSE, NULL, 0);
     if (!status) goto escape;
   }
Index: branches/eam_branches/ohana.20190329/src/opihi/include/dvomath.h
===================================================================
--- branches/eam_branches/ohana.20190329/src/opihi/include/dvomath.h	(revision 40784)
+++ branches/eam_branches/ohana.20190329/src/opihi/include/dvomath.h	(revision 40791)
@@ -169,5 +169,5 @@
 
 /* vector IO functions */
-int           WriteVectorTableFITS  PROTO((char *filename, char *extname, Vector **vec, int Nvec, int append, char *compress, char *format, int Ntile));
+int           WriteVectorTableFITS  PROTO((char *filename, char *extname, Header *extraheader, Vector **vec, int Nvec, int append, char *compress, char *format, int Ntile));
 Vector      **ReadVectorTableFITS   PROTO((char *filename, char *extname, int *Nvec));
 
Index: branches/eam_branches/ohana.20190329/src/opihi/lib.shell/VectorIO.c
===================================================================
--- branches/eam_branches/ohana.20190329/src/opihi/lib.shell/VectorIO.c	(revision 40784)
+++ branches/eam_branches/ohana.20190329/src/opihi/lib.shell/VectorIO.c	(revision 40791)
@@ -110,6 +110,50 @@
 }
 
+// insert a new header line, return end pointer
+char *gfits_insert_header_line (Header *header, char *endptr, char *newline) {
+
+  if (0) {
+    char temp1[32], temp2[32];
+    memset (temp1, 0, 32);
+    memset (temp2, 0, 32);
+
+    if (endptr) {
+      memcpy (temp1, endptr, 8);
+    }
+    memcpy (temp2, newline, 8);
+    fprintf (stderr, "insert: %s : %s\n", temp1, temp2);
+  }
+
+  /* find the END of the header, if not supplied */
+  if (!endptr) {
+    endptr = gfits_header_field (header, "END", 1);
+    if (endptr == NULL) return NULL; 
+  }
+
+  /* is there enough space for 1 more line? */
+  if (header[0].datasize - (endptr - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
+    // no, so expand by a full header block (FT_RECORD_SIZE = 32*80 = 2880)
+    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 
+    endptr = gfits_header_field (header, "END", 1);
+    if (endptr == NULL) return NULL; 
+    memset (endptr + FT_LINE_LENGTH, ' ', FT_RECORD_SIZE);
+  }
+
+  /* push END line back 1 */
+  memmove ((endptr + FT_LINE_LENGTH), endptr, FT_LINE_LENGTH);
+  memset (endptr, ' ', FT_LINE_LENGTH);
+
+  strncpy (endptr, newline, 80);
+  endptr += FT_LINE_LENGTH;
+
+  return endptr;
+}
+  
+static char *rawkeywords[] = {"SIMPLE", "BITPIX", "NAXIS", "PCOUNT", "GCOUNT", "EXTEND", "EXTNAME", "BSCALE", "BZERO", "TFIELDS", "TFORM", "TZERO", "TSCAL", "        ", NULL};
+
 // 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 *compress, char *format, int Ntile) {
+int WriteVectorTableFITS (char *filename, char *extname, Header *extraheader, Vector **vec, int Nvec, int append, char *compress, char *format, int Ntile) {
   
   Header rawheader;
@@ -139,5 +183,5 @@
   rawtable.header = &rawheader;
   if (!WriteVectorTable (&rawtable, extname, vec, Nvec, format, (compress != NULL))) goto escape;
-  // NOTE : for compression, the table is constructed in native by order 
+  // NOTE : for compression, the table is constructed in native byte order 
 
   FTable *outtable = &rawtable;
@@ -163,4 +207,5 @@
 
   if (!append) {
+    // generate a blank PHU header
     Header header;
     Matrix matrix;
@@ -176,4 +221,30 @@
   }
 
+  if (extraheader) {
+    // copy keywords which are not the standard or table keywords
+    char *buf = extraheader->buffer;
+    char *endptr = NULL;
+    for (int i = 0; i < extraheader->datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
+
+      if (0) { 
+	char temp1[32];
+	memset (temp1, 0, 32);
+	memcpy (temp1, buf, 8);
+	fprintf (stderr, "buffer: %s\n", temp1);
+      }
+
+      for (int j = 0; rawkeywords[j] != NULL; j++) {
+	if (!strncmp (buf, rawkeywords[j], strlen(rawkeywords[j]))) goto skip_insert;
+      }
+      endptr = gfits_insert_header_line (outheader, endptr, buf);
+      if (!endptr) {
+	gprint (GP_ERR, "failed to update FITS header with extra keywords\n");
+	return (FALSE);
+      }
+    skip_insert:
+      continue;
+    }
+  }
+
   // write the actual table data
   gfits_fwrite_Theader (f, outheader);
