Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/Makefile
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/Makefile	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/Makefile	(revision 38443)
@@ -92,4 +92,5 @@
 $(SRC)/mget.$(ARCH).o		\
 $(SRC)/mget3d.$(ARCH).o		\
+$(SRC)/mslice.$(ARCH).o		\
 $(SRC)/minterpolate.$(ARCH).o	\
 $(SRC)/medimage.$(ARCH).o	\
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/cast.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/cast.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/cast.c	(revision 38443)
@@ -17,7 +17,15 @@
   // out type 
   char outType = OPIHI_NOTYPE;
-  if (!strcasecmp(argv[5], "int")) outType = OPIHI_INT;
-  if (!strcasecmp(argv[5], "float")) outType = OPIHI_FLT;
+  if (!strcasecmp(argv[5], "int"))    outType = OPIHI_INT;
+  if (!strcasecmp(argv[5], "float"))  outType = OPIHI_FLT;
+  if (!strcasecmp(argv[5], "single")) outType = OPIHI_FLT;
+  if (!strcasecmp(argv[5], "int64"))  outType = OPIHI_FLT;
   if (outType == OPIHI_NOTYPE) goto usage;
+
+  int ForceSingle = FALSE;
+  if (!strcasecmp(argv[5], "single")) ForceSingle = TRUE;
+
+  int ForceI64 = FALSE;
+  if (!strcasecmp(argv[5], "int64")) ForceI64 = TRUE;
 
   if ((ovec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto error;
@@ -32,5 +40,13 @@
     opihi_flt *vo = ovec[0].elements.Flt;
     for (i = 0; i < ovec[0].Nelements; i++, vi++, vo++) {
-      *vo = *vi;
+      if (ForceSingle) {
+	float tmp = *vi;
+	*vo = tmp;
+      } else if (ForceI64) {
+	int64_t tmp = *vi;
+	*vo = tmp;
+      } else {
+	*vo = *vi;
+      }
     }
     return (TRUE);
@@ -48,5 +64,10 @@
     opihi_flt *vo = ovec[0].elements.Flt;
     for (i = 0; i < ovec[0].Nelements; i++, vi++, vo++) {
-      *vo = *vi;
+      if (ForceSingle) {
+	float tmp = *vi;
+	*vo = tmp;
+      } else {
+	*vo = *vi;
+      }
     }
     return (TRUE);
@@ -66,5 +87,6 @@
 
 usage:
-  gprint (GP_ERR, "SYNTAX: cast vec = vec as (int/float)\n");
+  gprint (GP_ERR, "SYNTAX: cast vec = vec as (int/float/single)\n");
+  gprint (GP_ERR, "  note: (single) forces vector to have single precision\n");
   return (FALSE);
 }
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/init.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/init.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/init.c	(revision 38443)
@@ -82,4 +82,5 @@
 int mget             PROTO((int, char **));
 int mget3d           PROTO((int, char **));
+int mslice           PROTO((int, char **));
 int minterp          PROTO((int, char **));
 int medimage_command PROTO((int, char **));
@@ -250,4 +251,5 @@
   {1, "mget",         mget,             "extract a vector from an image"},
   {1, "mget3d",       mget3d,           "extract a vector from a 3D image"},
+  {1, "mslice",       mslice,           "extract an image plane from a 3D image"},
   {1, "imget",        mget,             "extract a vector from an image"},
   {1, "minterp",      minterp,          "interpolate image pixels"},
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/mslice.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/mslice.c	(revision 38443)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/mslice.c	(revision 38443)
@@ -0,0 +1,46 @@
+# include "data.h"
+
+int mslice (int argc, char **argv) {
+  
+  int i;
+  Buffer *in, *out;
+
+  if (argc != 4) {
+    gprint (GP_ERR, "USAGE: mget <input> <output> plane\n");
+    return (FALSE);
+  }
+
+  int plane = atoi(argv[3]);
+
+  if ((in = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
+  if (in[0].matrix.Naxes < 3) {
+    gprint (GP_ERR, "buffer is not 3D\n");
+    return FALSE;
+  }
+  if ((out = SelectBuffer (argv[2], ANYBUFFER, TRUE)) == NULL) return (FALSE);
+
+  int Nx = in[0].matrix.Naxis[0];
+  int Ny = in[0].matrix.Naxis[1];
+  int Nz = in[0].matrix.Naxis[2];
+
+  int invalid = FALSE;
+  invalid = invalid || (plane < 0);
+  invalid = invalid || (plane >= Nz);
+  if (invalid) {
+    gprint (GP_ERR, "plane %d out of range\n", plane);
+    return (FALSE);
+  }
+
+  /* I should encapsulate this in a create_default_buffer */
+  gfits_free_matrix (&out[0].matrix);
+  gfits_free_header (&out[0].header);
+  CreateBuffer (out, Nx, Ny, -32, 1.0, 0.0);
+
+  float *inF  = (float *) in[0].matrix.buffer + plane*Nx*Ny;
+  float *outF = (float *) out[0].matrix.buffer;
+
+  for (i = 0; i < Nx*Ny; i++, inF ++, outF++) {
+    *outF = *inF;
+  }
+  return (TRUE);
+}
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/rd.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/rd.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/rd.c	(revision 38443)
@@ -9,8 +9,20 @@
   Buffer *buf;
 
+  int VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    remove_argument (N, &argc, argv);
+    VERBOSE = TRUE;
+  }
+
   int JustHead = FALSE;
   if ((N = get_argument (argc, argv, "-head"))) {
     remove_argument (N, &argc, argv);
     JustHead = TRUE;
+  }
+
+  int SwapRaw = FALSE;
+  if ((N = get_argument (argc, argv, "-swap-raw"))) {
+    remove_argument (N, &argc, argv);
+    SwapRaw = TRUE;
   }
 
@@ -85,5 +97,5 @@
       return (FALSE);
     }
-    if (gfits_extension_is_compressed (&buf[0].header)) {
+    if (gfits_extension_is_compressed_image (&buf[0].header)) {
 	IsCompressed = TRUE;
     }
@@ -118,5 +130,5 @@
       Nword = 1;
       IsCompressed = FALSE;
-      if (gfits_extension_is_compressed (&buf[0].header)) {
+      if (gfits_extension_is_compressed_image (&buf[0].header)) {
 	if (!strcmp (CCDKeyword, "EXTNAME")) Nword = 1;
 	IsCompressed = TRUE;
@@ -170,5 +182,5 @@
   if (plane >= 0) {
     // we are requesting a specific plane (-1 : all data)
-    int tooFar = Nz ? (plane >= Nz) : (plane > Nz);
+    int tooFar = (Nz > 0) ? (plane >= Nz) : (plane > 0);
     if (tooFar) {
       gprint (GP_ERR, "-plane is too large: %d total planes\n", Nz);
@@ -192,9 +204,14 @@
     ftable.header[0].buffer = NULL;
     gfits_copy_header (&buf[0].header, ftable.header);
-    status = gfits_fread_ftable_data (f, &ftable, FALSE);  // this just reads the bytes (not even a SWAP)
-    status = gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable);
+
+    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { gprint (GP_ERR, "problem reading compressed image table data\n"); fclose (f); return FALSE; }
+    if (!gfits_byteswap_varlength_column (&ftable, 1)) { gprint (GP_ERR, "problem doing byteswap on compressed image metadata column\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }
+    if (!gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable)) { gprint (GP_ERR, "problem uncompressing the image data\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }
+
     // uncompressing the image leaves the format as an extension
     gfits_extended_to_primary (&buf[0].header, TRUE, "Standard FITS");
     gfits_free_table (&ftable);
+
+    status = TRUE;
     // XXX this currently does not work for a cube (we get a cube back, not a specific plane)
   } else {
@@ -233,10 +250,13 @@
   buf[0].unsign = buf[0].header.unsign;
 
-  gprint (GP_LOG, "read "OFF_T_FMT" bytes from %s into buffer %s\n", 
-	   buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]);
+  if (VERBOSE) gprint (GP_LOG, "read "OFF_T_FMT" bytes from %s into buffer %s\n", buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]);
 
   blank = 0xffff;
   gfits_scan (&buf[0].header, "BLANK", "%d", 1, &blank);
 
+  if (SwapRaw) {
+    gfits_swap_raw (&buf[0].matrix);
+  }
+
   /** now - convert the matrix values to floats for internal use **/
   gfits_convert_format (&buf[0].header, &buf[0].matrix, -32, 1.0, 0.0, blank, gfits_get_unsign_mode());
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/read_vectors.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/read_vectors.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/read_vectors.c	(revision 38443)
@@ -1,3 +1,5 @@
 # include "data.h"
+int dump_raw_table (FTable *table, char *message);
+int dump_cmp_table (FTable *table, char *message);
 
 FILE *f = (FILE *) NULL;
@@ -412,5 +414,5 @@
   table.header = &header;
 
-  /* load appropriate extension (if extname is a number, use count) */
+  /**** find the appropriate extension and read header (if extname is a number, use count) ****/
   if (Nextend > -1) {
     // first extension is PHU, cannot be a table. 
@@ -429,28 +431,4 @@
     }
     if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension %d\n", Nextend);
-
-    if (getSizes) {
-      read_table_sizes (&header);
-      if (CCDKeyword != NULL) free (CCDKeyword); 
-      gfits_free_header (&header); 
-      return TRUE;
-    }
-
-    if (Nrows == -1) {
-      Nrows = header.Naxis[1] - start;
-    }
-    if (start < 0) ESCAPE ("invalid range: start < 0\n");
-    if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]);
-    if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
-
-    // just a warning:
-    if (start + Nrows > header.Naxis[1]) {
-      if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only %d rows\n", header.Naxis[1] - start);
-    }
-
-    // Ny = 100, start = 0, Nrows = -1 -> Nrows => 100
-    // Ny = 100, start = 10, Nrows = 90
-
-    if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);
   } else {
     if (CCDKeyword == NULL) {
@@ -460,5 +438,4 @@
       CCDKeyword = strcreate ("EXTNAME");
     }
-
     while (1) {
       if (!gfits_load_header (f, &header)) {
@@ -469,5 +446,4 @@
 	return (TRUE);  
       }
-
       Nbytes = gfits_data_size (&header);
 
@@ -482,30 +458,48 @@
 	continue;
       }
-
-      if (getSizes) {
-	read_table_sizes (&header);
-	if (CCDKeyword != NULL) free (CCDKeyword); 
-	gfits_free_header (&header); 
-	return TRUE;
-      }
-
-      if (Nrows == -1) {
-	Nrows = header.Naxis[1] - start;
-      }
-      if (start < 0) ESCAPE ("invalid range: start < 0\n");
-      if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]);
-      if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
-
-      // just a warning:
-      if (start + Nrows > header.Naxis[1]) {
-	if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only %d rows\n", header.Naxis[1] - start);
-      }
-
-      if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);
-
-      // if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension\n");
-
       break;
     }
+  }
+
+  int IsCompressed = gfits_extension_is_compressed_table (&header);
+
+  if (getSizes && !IsCompressed) {
+    read_table_sizes (&header);
+    if (CCDKeyword != NULL) free (CCDKeyword); 
+    gfits_free_header (&header); 
+    return TRUE;
+  }
+  if (IsCompressed) {
+    if (getSizes) {
+      gprint (GP_ERR, "%s[%s] is compressed: -sizes is invalid\n", filename, extname);
+      gfits_free_header (&header); 
+      return FALSE;
+    }
+    if ((start > 0) || (Nrows > -1)) {
+      gprint (GP_ERR, "%s[%s] is compressed: must read entire table\n", filename, extname);
+      gfits_free_header (&header); 
+      return FALSE;
+    }
+  }
+
+  if (Nrows == -1) {
+    Nrows = header.Naxis[1] - start;
+  }
+  if (start < 0) ESCAPE ("invalid range: start < 0\n");
+  if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny ("OFF_T_FMT")\n", header.Naxis[1]);
+  if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
+
+  // just a warning:
+  if (start + Nrows > header.Naxis[1]) {
+    if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only "OFF_T_FMT" rows\n", header.Naxis[1] - start);
+  }
+
+  // Ny = 100, start = 0, Nrows = -1 -> Nrows => 100
+  // Ny = 100, start = 10, Nrows = 90
+
+  if (IsCompressed) {
+    if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension %d\n", Nextend);
+  } else {
+    if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);
   }
 
@@ -518,4 +512,29 @@
   Binary = !strcmp (type, "BINTABLE");
   Ny = header.Naxis[1];
+
+  Header *outheader = &header;
+  FTable *outtable  = &table;
+
+  Header rawheader;
+  FTable rawtable;
+  if (IsCompressed) {
+    rawtable.header = &rawheader;
+
+    dump_cmp_table (&table, "rd cmp");
+
+    int Nfields;
+    if (!gfits_scan (&header, "TFIELDS", "%d", 1, &Nfields)) ESCAPE ("cannot find TFIELDS in header\n");
+    for (i = 0; i < Nfields; i++) {
+      gfits_byteswap_varlength_column (&table, i+1);
+    }
+    if (!gfits_uncompress_table (&table, &rawtable)) ESCAPE ("failed to uncompress table\n");
+    dump_raw_table (&rawtable, "rd raw");
+
+    outheader = &rawheader;
+    outtable  = &rawtable;
+    gfits_free_header (&header);
+    gfits_free_table (&table);
+    Ny = rawheader.Naxis[1];
+  }
 
   /* find columns which match requested vectors */
@@ -527,14 +546,14 @@
     Nval = 0;
     if (Binary) {
-      if (!gfits_get_bintable_column_type (&header, argv[i], type, &Nval)) ESCAPE ("requested field not found");
-      if (!gfits_get_bintable_column (&header, &table, argv[i], &data)) ESCAPE ("error reading data from specified field");
+      if (!gfits_get_bintable_column_type (outheader, argv[i], type, &Nval)) ESCAPE ("requested field not found\n");
+      if (!gfits_get_bintable_column_raw (outheader, outtable, argv[i], &data, IsCompressed)) ESCAPE ("error reading data from specified field\n");
     } else {
-      if (!gfits_get_table_column_type (&header, argv[i], type)) ESCAPE ("requested field not found");
-      if (!gfits_get_table_column (&header, &table, argv[i], &data)) ESCAPE ("error reading data from specified field");
-    }
-    if (Nval == 0) ESCAPE ("no data for field in table");
+      if (!gfits_get_table_column_type (outheader, argv[i], type)) ESCAPE ("requested field not found\n");
+      if (!gfits_get_table_column (outheader, outtable, argv[i], &data)) ESCAPE ("error reading data from specified field\n");
+    }
+    if (Nval == 0) ESCAPE ("no data for field in table\n");
     
     vecType = OPIHI_INT;
-    if (!strcmp (type, "double") || !strcmp (type, "float")) {
+    if (!strcmp (type, "double") || !strcmp (type, "float") || !strcmp (type, "int64_t")) {
       vecType = OPIHI_FLT;
     }
@@ -570,9 +589,9 @@
 	else
 	  sprintf (name, "%s:%d", argv[i], j);
-	if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
+	if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name\n");
 	ResetVector (vec[j], vecType, Ny);
       }
 
-      if (!VectorAssignData (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s", type);
+      if (!VectorAssignData (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s\n", type);
 
     } else {
@@ -584,9 +603,9 @@
 	else
 	  sprintf (name, "%s:%d", argv[i], j);
-	if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
+	if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name\n");
 	ResetVector (vec[j], vecType, Nval);
       }
 
-      if (!VectorAssignDataTranspose (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s", type);
+      if (!VectorAssignDataTranspose (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s\n", type);
     }
     free (data);
@@ -594,6 +613,6 @@
   }
   if (CCDKeyword != NULL) free (CCDKeyword);
-  gfits_free_table (&table);
-  gfits_free_header (&header);
+  gfits_free_table (outtable);
+  gfits_free_header (outheader);
   return (TRUE);
 }
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/tv.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/tv.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/tv.c	(revision 38443)
@@ -71,5 +71,5 @@
   int tooBig = buf[0].matrix.Naxis[2] ? (plane >= buf[0].matrix.Naxis[2]) : plane > 0;
   if (tooBig) {
-    gprint (GP_ERR, " ERROR: -plane (plane) : out of bounds (%d vs %d)\n", plane, buf[0].matrix.Naxis[2]);
+    gprint (GP_ERR, " ERROR: -plane (plane) : out of bounds (%d vs "OFF_T_FMT")\n", plane, buf[0].matrix.Naxis[2]);
     return (FALSE);
   }
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/vstats.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/vstats.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/vstats.c	(revision 38443)
@@ -121,4 +121,6 @@
       goto skip;
     }
+    // we can hit inf if pmax and pmin are close to the max range
+    if (isinf(dx)) dx = DBL_MAX / Nbin;
 
     ALLOCATE (Nval, int, Nbin + 2);
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/wd.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/wd.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/wd.c	(revision 38443)
@@ -18,4 +18,14 @@
   }
 
+  char *CompressMode = NULL;
+  if ((N = get_argument (argc, argv, "-compress-mode"))) {
+    remove_argument (N, &argc, argv);
+    CompressMode = strcreate(argv[N]);
+    remove_argument (N, &argc, argv);
+  } else if ((N = get_argument (argc, argv, "-compress"))) {
+    remove_argument (N, &argc, argv);
+    CompressMode = strcreate("GZIP_1");
+  }
+
   outZero = 0;
   newZero = FALSE;
@@ -54,4 +64,5 @@
     if (outUnsign == -1) {
       gprint (GP_ERR, "-unsign options: t, f, true, false\n");
+      FREE (CompressMode);
       return (FALSE);
     }
@@ -62,8 +73,9 @@
   if (argc != 3) {
     gprint (GP_ERR, "USAGE: wd <buffer> <filename> [-bitpix N] [-bscale X] [-bzero X] [-extend] [-newplane]\n");
+    FREE (CompressMode);
     return (FALSE);
   }
 
-  if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
+  if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) { FREE (CompressMode); return (FALSE); }
 
   if (!newBitpix) outBitpix = buf[0].bitpix;
@@ -159,7 +171,46 @@
     gfits_free_header (&temp_header);
     gfits_free_matrix (&temp_matrix);
+    FREE (CompressMode);
     return (status);
   }
   
+  // not compatible with extend
+  if (CompressMode) {
+    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]);
+      FREE (CompressMode);
+      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, CompressMode);
+    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);
+    FREE (CompressMode);
+    return (TRUE);
+  }
+
   /* the actual write-to-disk goes here */
   if (!gfits_write_header (argv[2], &temp_header)) {
@@ -167,4 +218,5 @@
     gfits_free_header (&temp_header);
     gfits_free_matrix (&temp_matrix);
+    FREE (CompressMode);
     return (FALSE);
   }
@@ -174,4 +226,5 @@
     gfits_free_header (&temp_header);
     gfits_free_matrix (&temp_matrix);
+    FREE (CompressMode);
     return (FALSE);
   }
@@ -180,4 +233,5 @@
   gfits_free_matrix (&temp_matrix);
   
+  FREE (CompressMode);
   return (TRUE);
 }
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/write_vectors.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/write_vectors.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/cmd.data/write_vectors.c	(revision 38443)
@@ -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,21 @@
   }
 
-  append = FALSE;
+  int append = FALSE;
   if ((N = get_argument (argc, argv, "-append"))) {
     remove_argument (N, &argc, argv);
     append = TRUE;
+  }
+
+  char *compress = NULL;
+  if ((N = get_argument (argc, argv, "-compress-mode"))) {
+    remove_argument (N, &argc, argv);
+    compress = strcreate(argv[N]);
+    remove_argument (N, &argc, argv);
+  } else if ((N = get_argument (argc, argv, "-compress"))) {
+    remove_argument (N, &argc, argv);
+    compress = strcreate("GZIP_1");
+    if (!FITS) {
+      fprintf (stderr, "NOTE: write_vectors -compress has no effect on non-FITS\n");
+    }
   }
 
@@ -105,5 +117,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;
@@ -243,8 +255,8 @@
     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");
-    gprint (GP_ERR, "    ascii / csv : format consists of c-style format codes in form %NN.Md\n");
+    gprint (GP_ERR, "    ascii / csv : format consists of c-style format codes in form %%NN.Md\n");
     gprint (GP_ERR, ",     the following codes are allowed\n");
-    gprint (GP_ERR, "        %e -- double, %f -- float\n");
-    gprint (GP_ERR, "        %d -- int, %c -- char, %x -- hex int\n");
+    gprint (GP_ERR, "        %%e -- double, %%f -- float\n");
+    gprint (GP_ERR, "        %%d -- int, %%c -- char, %%x -- hex int\n");
     gprint (GP_ERR, "    FITS : format consists of the following FITS binary table format codes:\n");
     gprint (GP_ERR, "      B : 1 byte int\n");    
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/avextract.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/avextract.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/avextract.c	(revision 38443)
@@ -185,8 +185,8 @@
     snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
     catalog.filename = (HOST_ID || PARALLEL_LOCAL) ? hostfile : skylist[0].filename[i];
-    catalog.catflags = LOAD_AVES | LOAD_SECF;
-    catalog.catflags |= needMeasure ? LOAD_MEAS : SKIP_MEAS;
-    catalog.catflags |= needLensobj ? LOAD_LENSOBJ : SKIP_LENSOBJ;
-    catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
+    catalog.catflags |= needMeasure ? DVO_LOAD_MEASURE : DVO_SKIP_MEASURE;
+    catalog.catflags |= needLensobj ? DVO_LOAD_LENSOBJ : DVO_SKIP_LENSOBJ;
+    catalog.catflags |= needStarpar ? DVO_LOAD_STARPAR : DVO_SKIP_STARPAR;
     catalog.Nsecfilt = 0;
 
@@ -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/ipp-20150419/Ohana/src/opihi/dvo/avmatch.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/avmatch.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/avmatch.c	(revision 38443)
@@ -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;
     }
@@ -190,8 +190,8 @@
     snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
     catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
-    catalog.catflags = LOAD_AVES | LOAD_SECF;
-    catalog.catflags |= needMeasure ? LOAD_MEAS    : SKIP_MEAS;
-    catalog.catflags |= needLensobj ? LOAD_LENSOBJ : SKIP_LENSOBJ;
-    catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
+    catalog.catflags |= needMeasure ? DVO_LOAD_MEASURE    : DVO_SKIP_MEASURE;
+    catalog.catflags |= needLensobj ? DVO_LOAD_LENSOBJ : DVO_SKIP_LENSOBJ;
+    catalog.catflags |= needStarpar ? DVO_LOAD_STARPAR : DVO_SKIP_STARPAR;
     catalog.Nsecfilt = 0;
 
@@ -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/ipp-20150419/Ohana/src/opihi/dvo/calextract.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/calextract.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/calextract.c	(revision 38443)
@@ -61,5 +61,5 @@
     /* lock, load, unlock catalog */
     catalog.filename = skylist[0].filename[Nr];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/calmextract.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/calmextract.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/calmextract.c	(revision 38443)
@@ -74,5 +74,5 @@
     /* lock, load, unlock catalog */
     catalog.filename = skylist[0].filename[Nr];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/catalog.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/catalog.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/catalog.c	(revision 38443)
@@ -315,5 +315,5 @@
       /* lock, load, unlock catalog */
       catalog.filename = filename;
-      catalog.catflags = LOAD_AVES;
+      catalog.catflags = DVO_LOAD_AVERAGE;
 
       // an error exit status here is a significant error
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/ccd.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/ccd.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/ccd.c	(revision 38443)
@@ -69,5 +69,5 @@
     /* lock, load, unlock catalog */
     catalog.filename = skylist[0].filename[k];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/cmatch.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/cmatch.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/cmatch.c	(revision 38443)
@@ -29,5 +29,5 @@
   /* load data from the photometry database file */
   catalog1.filename = filename;
-  catalog1.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+  catalog1.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
 
   // an error exit status here is a significant error
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/cmd.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/cmd.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/cmd.c	(revision 38443)
@@ -68,5 +68,5 @@
     /* lock, load, unlock catalog */
     catalog.filename = skylist[0].filename[j];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/cmpReadFile.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/cmpReadFile.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/cmpReadFile.c	(revision 38443)
@@ -19,5 +19,5 @@
   if (!gfits_fread_ftable (f, &table, "SMPFILE")) goto escape;
 
-  smpdata = gfits_table_get_SMPData (&table, &Nstars, NULL);
+  smpdata = gfits_table_get_SMPData (&table, &Nstars, NULL, NULL);
   if (!smpdata) {
     fprintf (stderr, "ERROR: failed to read stars\n");
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/ddmags.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/ddmags.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/ddmags.c	(revision 38443)
@@ -66,5 +66,5 @@
     /* lock, load, unlock catalog */
     catalog.filename = skylist[0].filename[k];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dmagaves.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dmagaves.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dmagaves.c	(revision 38443)
@@ -58,5 +58,5 @@
     /* lock, load, unlock catalog */
     catalog.filename = skylist[0].filename[j];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dmagmeas.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dmagmeas.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dmagmeas.c	(revision 38443)
@@ -66,5 +66,5 @@
     /* lock, load, unlock catalog */
     catalog.filename = skylist[0].filename[j];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dmags.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dmags.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dmags.c	(revision 38443)
@@ -64,5 +64,5 @@
     /* lock, load, unlock catalog */
     catalog.filename = skylist[0].filename[j];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dmt.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dmt.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dmt.c	(revision 38443)
@@ -77,5 +77,5 @@
     /* lock, load, unlock catalog */
     catalog.filename = skylist[0].filename[k];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dvo_host_utils.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dvo_host_utils.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/dvo_host_utils.c	(revision 38443)
@@ -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/ipp-20150419/Ohana/src/opihi/dvo/extract.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/extract.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/extract.c	(revision 38443)
@@ -252,7 +252,7 @@
       catalog.measure = (Measure *) NULL;
       catalog.secfilt = (SecFilt *) NULL;
-      loadmode = LOAD_AVES | LOAD_SECF;
+      loadmode = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
       if ((mode == REF) || (mode == TYPE) || (mode == NPHOT) || (mode == NCODE)) 
-	loadmode = loadmode | LOAD_MEAS;
+	loadmode = loadmode | DVO_LOAD_MEASURE;
 
       /* lock, load, unlock catalog */
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/fitcolors.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/fitcolors.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/fitcolors.c	(revision 38443)
@@ -162,5 +162,5 @@
     /* lock, load, unlock catalog */
     catalog[k].filename = skylist[0].filename[k];
-    catalog[k].catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog[k].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog[k].Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/fitsed.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/fitsed.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/fitsed.c	(revision 38443)
@@ -188,5 +188,5 @@
     /* lock, load, unlock catalog */
     catalog.filename = skylist[0].filename[k];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/gstar.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/gstar.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/gstar.c	(revision 38443)
@@ -254,6 +254,6 @@
 
   /* lock, load, unlock catalog */
-  catalog.catflags = LOAD_AVES | LOAD_SECF;
-  catalog.catflags |= GetMeasures ? LOAD_MEAS : SKIP_MEAS;
+  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
+  catalog.catflags |= GetMeasures ? DVO_LOAD_MEASURE : DVO_SKIP_MEASURE;
   catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/imdata.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/imdata.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/imdata.c	(revision 38443)
@@ -136,5 +136,5 @@
     /* get file name and open */
     catalog.filename = skylist[0].filename[j];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/lcurve.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/lcurve.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/lcurve.c	(revision 38443)
@@ -76,5 +76,5 @@
   /* set filename, read in header */
   catalog.filename = skylist[0].filename[0];
-  catalog.catflags = LOAD_AVES | LOAD_MEAS;
+  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE;
   catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/lightcurve.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/lightcurve.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/lightcurve.c	(revision 38443)
@@ -59,5 +59,5 @@
   /* set filename, read in header */
   catalog.filename = skylist[0].filename[0];
-  catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
   catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/mextract.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/mextract.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/mextract.c	(revision 38443)
@@ -19,4 +19,6 @@
     return FALSE;
 }
+
+void gfits_uncompress_timing ();
 
 int mextract (int argc, char **argv) {
@@ -229,7 +231,7 @@
     snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
     catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
-    // catalog.catflags |= needLensing ? LOAD_LENSING : SKIP_LENSING;
-    catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
+    // catalog.catflags |= needLensing ? DVO_LOAD_LENSING : DVO_SKIP_LENSING;
+    catalog.catflags |= needStarpar ? DVO_LOAD_STARPAR : DVO_SKIP_STARPAR;
     catalog.Nsecfilt = Nsecfilt;
 
@@ -317,5 +319,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;
   }
@@ -330,4 +332,6 @@
   SkyListFree (skylist);
   FreeSkyRegionSelection (selection);
+
+  gfits_uncompress_timing();
 
   // fprintf (stderr, "done extr...\n");
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/mmatch.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/mmatch.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/mmatch.c	(revision 38443)
@@ -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;
     }
@@ -248,6 +248,6 @@
     snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
     catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
-    catalog.catflags = LOAD_AVES | LOAD_SECF | LOAD_MEAS;
-    catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT | DVO_LOAD_MEASURE;
+    catalog.catflags |= needStarpar ? DVO_LOAD_STARPAR : DVO_SKIP_STARPAR;
     catalog.Nsecfilt = Nsecfilt;
 
@@ -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/ipp-20150419/Ohana/src/opihi/dvo/mmextract.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/mmextract.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/mmextract.c	(revision 38443)
@@ -183,5 +183,5 @@
     /* lock, load, unlock catalog */
     catalog.filename = skylist[0].filename[i];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = Nsecfilt;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/objectcoverage.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/objectcoverage.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/objectcoverage.c	(revision 38443)
@@ -184,5 +184,5 @@
     /* lock, load, unlock catalog */
     catalog.filename = skylist[0].filename[k];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/paverage.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/paverage.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/paverage.c	(revision 38443)
@@ -105,5 +105,5 @@
   for (j = 0; (j < skylist[0].Nregions) && !interrupt; j++) {
     catalog.filename = skylist[0].filename[j];
-    catalog.catflags = LOAD_AVES | LOAD_SECF;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
     catalog.Nsecfilt = Nsecfilt;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/pmeasure.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/pmeasure.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/pmeasure.c	(revision 38443)
@@ -178,5 +178,5 @@
   for (j = 0; (j < skylist[0].Nregions) && !interrupt; j++) {
     catalog.filename = skylist[0].filename[j];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS;
+    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE;
     catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/subpix.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/subpix.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/dvo/subpix.c	(revision 38443)
@@ -40,5 +40,5 @@
   /* lock, load, unlock catalog */
   catalog.filename = skylist[0].filename[0];
-  catalog.catflags = LOAD_AVES | LOAD_MEAS;
+  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE;
   catalog.Nsecfilt = 0;
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/include/dvomath.h
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/include/dvomath.h	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/include/dvomath.h	(revision 38443)
@@ -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, char *compress, char *format));
 Vector      **ReadVectorTableFITS   PROTO((char *filename, char *extname, int *Nvec));
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.data/SplineOps.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.data/SplineOps.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.data/SplineOps.c	(revision 38443)
@@ -178,7 +178,8 @@
   gfits_create_table (&theader, &ftable);
 
-  gfits_set_bintable_column_reformat (&theader, &ftable, "X_KNOT", "double", myspline->xk, myspline->Nknots);
-  gfits_set_bintable_column_reformat (&theader, &ftable, "Y_KNOT", "double", myspline->yk, myspline->Nknots);
-  gfits_set_bintable_column_reformat (&theader, &ftable, "DY2_DX", "double", myspline->y2, myspline->Nknots);
+  // NOTE: if we want to compress the output table, use native byte order here (last element)
+  gfits_set_bintable_column_reformat (&theader, &ftable, "X_KNOT", "double", myspline->xk, myspline->Nknots, FALSE);
+  gfits_set_bintable_column_reformat (&theader, &ftable, "Y_KNOT", "double", myspline->yk, myspline->Nknots, FALSE);
+  gfits_set_bintable_column_reformat (&theader, &ftable, "DY2_DX", "double", myspline->y2, myspline->Nknots, FALSE);
 
   if (!append) {
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.shell/VectorIO.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.shell/VectorIO.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.shell/VectorIO.c	(revision 38443)
@@ -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, char nativeOrder) {
   
   int j;
@@ -8,4 +8,5 @@
   char *tformat = NULL;
 
+  Header *theader = ftable->header;
   gfits_create_table_header (theader, "BINTABLE", extname);
 
@@ -58,7 +59,7 @@
   for (j = 0; j < Nvec; j++) {
     if (vec[j][0].type == OPIHI_FLT) {
-      gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "double", vec[j][0].elements.Flt, vec[j][0].Nelements);
+      gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "double", vec[j][0].elements.Flt, vec[j][0].Nelements, nativeOrder);
     } else {
-      gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "int", vec[j][0].elements.Int, vec[j][0].Nelements);
+      gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "int", vec[j][0].elements.Int, vec[j][0].Nelements, nativeOrder);
     }
   }
@@ -70,11 +71,42 @@
 }
   
+# define VERBOSE 0
+int dump_raw_table (FTable *table, char *message) {
+# if (VERBOSE)
+  int i;
+  fprintf (stderr, "%s data: ", message);
+  for (i = 0; i < table->header->Naxis[0]*table->header->Naxis[1]; i++) {
+    fprintf (stderr, "0x%02hhx ", table->buffer[i]);
+  }
+  fprintf (stderr, "\n");
+# endif
+  return TRUE;
+}
+
+int dump_cmp_table (FTable *table, char *message) {
+# if (VERBOSE)
+  int i;
+  fprintf (stderr, "%s pntr: ", message);
+  for (i = 0; i < table->header->Naxis[0]*table->header->Naxis[1]; i++) {
+    fprintf (stderr, "0x%02hhx ", table->buffer[i]);
+  }
+  fprintf (stderr, "\n");
+
+  fprintf (stderr, "%s data: ", message);
+  for (i = 0; i < table->header->pcount; i++) {
+    fprintf (stderr, "0x%02hhx ", table->buffer[table->heap_start + i]);
+  }
+  fprintf (stderr, "\n");
+# endif
+  return TRUE;
+}
+
 // 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, char *compress, char *format) {
+  
+  Header rawheader;
+  Header cmpheader;
+  FTable rawtable;
+  FTable cmptable;
 
   FILE *f = NULL;
@@ -91,8 +123,39 @@
   }
 
-  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, (compress != NULL))) goto escape;
+  // NOTE : for compression, the table is constructed in native by order 
+
+  FTable *outtable = &rawtable;
+  Header *outheader = &rawheader;
+
+  if (compress) {
+    cmptable.header = &cmpheader;
+
+    dump_raw_table (&rawtable, "wd raw");
+    if (!gfits_compress_table (&rawtable, &cmptable, 0, compress)) goto escape;
+
+    int i, Nfields;
+    if (!gfits_scan (&cmpheader, "TFIELDS", "%d", 1, &Nfields)) goto escape;
+    for (i = 0; i < Nfields; i++) {
+      gfits_byteswap_varlength_column (&cmptable, i+1);
+    }
+    dump_cmp_table (&cmptable, "wd cmp");
+
+    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 +166,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 +184,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);
@@ -249,5 +320,5 @@
   ASSIGN_DATA(short,   short,   Int);
   ASSIGN_DATA(int,     int,     Int);
-  ASSIGN_DATA(int64_t, int64_t, Int);
+  ASSIGN_DATA(int64_t, int64_t, Flt); // int64_t has a problem: Int is too small, Flt is wrong precision
   ASSIGN_DATA(float,   float,   Flt);
   ASSIGN_DATA(double,  double,  Flt);
@@ -274,5 +345,5 @@
   ASSIGN_DATA_TRANSPOSE(short,   short,   Int);
   ASSIGN_DATA_TRANSPOSE(int,     int,     Int);
-  ASSIGN_DATA_TRANSPOSE(int64_t, int64_t, Int);
+  ASSIGN_DATA_TRANSPOSE(int64_t, int64_t, Flt);
   ASSIGN_DATA_TRANSPOSE(float,   float,   Flt);
   ASSIGN_DATA_TRANSPOSE(double,  double,  Flt);
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.shell/convert_to_RPN.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.shell/convert_to_RPN.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.shell/convert_to_RPN.c	(revision 38443)
@@ -58,4 +58,7 @@
     if (!strcmp (argv[i], "lgamma")) { type = ST_UNARY; goto gotit; }
     if (!strcmp (argv[i], "rnd"))    { type = ST_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "drnd"))   { type = ST_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "lrnd"))   { type = ST_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "mrnd"))   { type = ST_UNARY; goto gotit; }
     if (!strcmp (argv[i], "xramp"))  { type = ST_UNARY; goto gotit; }
     if (!strcmp (argv[i], "yramp"))  { type = ST_UNARY; goto gotit; }
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.shell/evaluate_stack.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.shell/evaluate_stack.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.shell/evaluate_stack.c	(revision 38443)
@@ -115,5 +115,6 @@
 
 	/* there are no valid unary string operators */
-	push_error ("invalid operands for trinary operator (mismatch types?)");
+	snprintf (line, 512, "invalid operands for trinary operator %s (mismatch types?)", stack[i].name);
+	push_error (line);
 	clear_stack (&tmp_stack);
 	return (FALSE);
@@ -210,5 +211,6 @@
 
 	/* there are no valid unary string operators */
-	push_error ("syntax error: no valid string unary ops");
+	snprintf (line, 512, "invalid operand for unary operator %s (undefined value?)", stack[i].name);
+	push_error (line);
 	clear_stack (&tmp_stack);
 	return (FALSE);
Index: /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.shell/stack_math.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.shell/stack_math.c	(revision 38442)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/opihi/lib.shell/stack_math.c	(revision 38443)
@@ -12,19 +12,19 @@
   // set up the possible operations : int OP int -> int, all else yield float
   // OP is the operation performed on *M1 and *M2
-# define SSS_FUNC(OP) {						\
+# define SSS_FUNC(OP) {							\
     if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT) && (V3->type == ST_SCALAR_FLT)) { \
-      opihi_flt M1  =  V1[0].FltValue;			\
-      opihi_flt M2  =  V2[0].FltValue;			\
-      opihi_flt M3  =  V3[0].FltValue;			\
-      OUT[0].type = ST_SCALAR_FLT;			\
-      OUT[0].FltValue = OP;							\
+      opihi_flt M1  =  V1[0].FltValue;					\
+      opihi_flt M2  =  V2[0].FltValue;					\
+      opihi_flt M3  =  V3[0].FltValue;					\
+      OUT[0].type = ST_SCALAR_FLT;					\
+      OUT[0].FltValue = OP;						\
       break;								\
     }									\
     if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT) && (V3->type == ST_SCALAR_INT)) { \
-      opihi_int M1  =  V1[0].IntValue;			\
-      opihi_int M2  =  V2[0].IntValue;			\
-      opihi_int M3  =  V3[0].IntValue;			\
-      OUT[0].type = ST_SCALAR_INT;			\
-      OUT[0].IntValue = OP;							\
+      opihi_int M1  =  V1[0].IntValue;					\
+      opihi_int M2  =  V2[0].IntValue;					\
+      opihi_int M3  =  V3[0].IntValue;					\
+      OUT[0].type = ST_SCALAR_INT;					\
+      OUT[0].IntValue = OP;						\
       break;								\
     }									\
@@ -32,10 +32,10 @@
 
   switch (op[0]) {
-    case '?': SSS_FUNC(M1 ? M2: M3);
-    default:
-      snprintf (line, 512, "error: op %c not defined!", op[0]);
-      push_error (line);
-      return (FALSE);
-  }
+  case '?': SSS_FUNC(M1 ? M2: M3);
+  default:
+    snprintf (line, 512, "error: op %c not defined!", op[0]);
+    push_error (line);
+    return (FALSE);
+}
 # undef SSS_FUNC
 
@@ -68,5 +68,5 @@
   // set up the possible operations : int OP int -> int, all else yield float
   // OP is the operation performed on *M1 and *M2
-# define VVV_FUNC(OP) {						\
+# define VVV_FUNC(OP) {							\
     if ((V1->vector->type == OPIHI_FLT) && (V2->vector->type == OPIHI_FLT) && (V3->vector->type == OPIHI_FLT)) { \
       CopyVector (OUT[0].vector, V1[0].vector);				\
@@ -394,5 +394,5 @@
   // OP is the operation performed on *M1 and *M2
 # define SV_FUNC(FTYPE,OP) {						\
-    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type == OPIHI_FLT)) {		\
+    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type == OPIHI_FLT)) { \
       CopyVector (OUT[0].vector, V2[0].vector);				\
       opihi_flt  M1  =  V1[0].FltValue;					\
@@ -404,5 +404,5 @@
       break;								\
     }									\
-    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type != OPIHI_FLT)) {		\
+    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type != OPIHI_FLT)) { \
       MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);		\
       opihi_flt  M1  =  V1[0].FltValue;					\
@@ -414,5 +414,5 @@
       break;								\
     }									\
-    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type == OPIHI_FLT)) {		\
+    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type == OPIHI_FLT)) { \
       CopyVector (OUT[0].vector, V2[0].vector);				\
       opihi_int  M1  =  V1[0].IntValue;					\
@@ -434,5 +434,5 @@
       break;								\
     }									\
-    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) {		\
+    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) { \
       CopyVector (OUT[0].vector, V2[0].vector);				\
       opihi_int  M1  =  V1[0].IntValue;					\
@@ -447,36 +447,36 @@
 
   switch (op[0]) { 
-    case '+': SV_FUNC(ST_SCALAR_INT, M1 + *M2);
-    case '-': SV_FUNC(ST_SCALAR_INT, M1 - *M2);
-    case '*': SV_FUNC(ST_SCALAR_INT, M1 * *M2);
-    case '/': SV_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) *M2);
-    case '%': SV_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) *M2);
-    case '^': SV_FUNC(ST_SCALAR_FLT, pow (M1, *M2));
-    case '@': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
-    case 'a': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
-    case 'D': SV_FUNC(ST_SCALAR_INT, MIN (M1, *M2));
-    case 'U': SV_FUNC(ST_SCALAR_INT, MAX (M1, *M2));
-    case '<': SV_FUNC(ST_SCALAR_INT, (M1 < *M2) ? 1 : 0);
-    case '>': SV_FUNC(ST_SCALAR_INT, (M1 > *M2) ? 1 : 0);
-    case '&': SV_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)*M2));
-    case '|': SV_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)*M2));
-    case 'E': SV_FUNC(ST_SCALAR_INT, (M1 == *M2) ? 1 : 0);
-    case 'N': SV_FUNC(ST_SCALAR_INT, (M1 != *M2) ? 1 : 0);
-    case 'L': SV_FUNC(ST_SCALAR_INT, (M1 <= *M2) ? 1 : 0);
-    case 'G': SV_FUNC(ST_SCALAR_INT, (M1 >= *M2) ? 1 : 0);
-    case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0);
-    case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0);
-    default:
-      snprintf (line, 512, "error: op %c not defined!", op[0]);
-      push_error (line);
-      return (FALSE);
-  }
+  case '+': SV_FUNC(ST_SCALAR_INT, M1 + *M2);
+  case '-': SV_FUNC(ST_SCALAR_INT, M1 - *M2);
+  case '*': SV_FUNC(ST_SCALAR_INT, M1 * *M2);
+  case '/': SV_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) *M2);
+  case '%': SV_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) *M2);
+  case '^': SV_FUNC(ST_SCALAR_FLT, pow (M1, *M2));
+  case '@': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
+  case 'a': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
+  case 'D': SV_FUNC(ST_SCALAR_INT, MIN (M1, *M2));
+  case 'U': SV_FUNC(ST_SCALAR_INT, MAX (M1, *M2));
+  case '<': SV_FUNC(ST_SCALAR_INT, (M1 < *M2) ? 1 : 0);
+  case '>': SV_FUNC(ST_SCALAR_INT, (M1 > *M2) ? 1 : 0);
+  case '&': SV_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)*M2));
+  case '|': SV_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)*M2));
+  case 'E': SV_FUNC(ST_SCALAR_INT, (M1 == *M2) ? 1 : 0);
+  case 'N': SV_FUNC(ST_SCALAR_INT, (M1 != *M2) ? 1 : 0);
+  case 'L': SV_FUNC(ST_SCALAR_INT, (M1 <= *M2) ? 1 : 0);
+  case 'G': SV_FUNC(ST_SCALAR_INT, (M1 >= *M2) ? 1 : 0);
+  case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0);
+  case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0);
+  default:
+    snprintf (line, 512, "error: op %c not defined!", op[0]);
+    push_error (line);
+    return (FALSE);
+}
 # undef SV_FUNC
 
   /** free up any temporary buffers: **/
   if (V2[0].type == ST_VECTOR_TMP) {
-    free (V2[0].vector[0].elements.Ptr);
-    free (V2[0].vector);
-  }
+  free (V2[0].vector[0].elements.Ptr);
+  free (V2[0].vector);
+}
 
   clear_stack (V1);
@@ -501,5 +501,5 @@
   // OP is the operation performed on *M1 and *M2
 # define VS_FUNC(FTYPE,OP) {						\
-    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type == OPIHI_FLT)) {		\
+    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type == OPIHI_FLT)) { \
       CopyVector (OUT[0].vector, V1[0].vector);				\
       opihi_flt *M1  =  V1[0].vector[0].elements.Flt;			\
@@ -511,5 +511,5 @@
       break;								\
     }									\
-    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT)) {		\
+    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT)) { \
       MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);		\
       opihi_int *M1  =  V1[0].vector[0].elements.Int;			\
@@ -521,5 +521,5 @@
       break;								\
     }									\
-    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type == OPIHI_FLT)) {		\
+    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type == OPIHI_FLT)) { \
       CopyVector (OUT[0].vector, V1[0].vector);				\
       opihi_flt *M1  =  V1[0].vector[0].elements.Flt;			\
@@ -541,5 +541,5 @@
       break;								\
     }									\
-    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) {		\
+    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) { \
       CopyVector (OUT[0].vector, V1[0].vector);				\
       opihi_int *M1  =  V1[0].vector[0].elements.Int;			\
@@ -554,29 +554,29 @@
 
   switch (op[0]) { 
-    case '+': VS_FUNC(ST_SCALAR_INT, *M1 + M2);
-    case '-': VS_FUNC(ST_SCALAR_INT, *M1 - M2);
-    case '*': VS_FUNC(ST_SCALAR_INT, *M1 * M2);
-    case '/': VS_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) M2);
-    case '%': VS_FUNC(ST_SCALAR_INT, (long long) *M1 % (long long) M2);
-    case '^': VS_FUNC(ST_SCALAR_FLT, pow (*M1, M2));
-    case '@': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
-    case 'a': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
-    case 'D': VS_FUNC(ST_SCALAR_INT, MIN (*M1, M2));
-    case 'U': VS_FUNC(ST_SCALAR_INT, MAX (*M1, M2));
-    case '<': VS_FUNC(ST_SCALAR_INT, (*M1 < M2) ? 1 : 0);
-    case '>': VS_FUNC(ST_SCALAR_INT, (*M1 > M2) ? 1 : 0);
-    case '&': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)M2));
-    case '|': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)M2));
-    case 'E': VS_FUNC(ST_SCALAR_INT, (*M1 == M2) ? 1 : 0);
-    case 'N': VS_FUNC(ST_SCALAR_INT, (*M1 != M2) ? 1 : 0);
-    case 'L': VS_FUNC(ST_SCALAR_INT, (*M1 <= M2) ? 1 : 0);
-    case 'G': VS_FUNC(ST_SCALAR_INT, (*M1 >= M2) ? 1 : 0);
-    case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0);
-    case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0);
-    default:
-      snprintf (line, 512, "error: op %c not defined!", op[0]);
-      push_error (line);
-      return (FALSE);
-  }
+  case '+': VS_FUNC(ST_SCALAR_INT, *M1 + M2);
+  case '-': VS_FUNC(ST_SCALAR_INT, *M1 - M2);
+  case '*': VS_FUNC(ST_SCALAR_INT, *M1 * M2);
+  case '/': VS_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) M2);
+  case '%': VS_FUNC(ST_SCALAR_INT, (long long) *M1 % (long long) M2);
+  case '^': VS_FUNC(ST_SCALAR_FLT, pow (*M1, M2));
+  case '@': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
+  case 'a': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
+  case 'D': VS_FUNC(ST_SCALAR_INT, MIN (*M1, M2));
+  case 'U': VS_FUNC(ST_SCALAR_INT, MAX (*M1, M2));
+  case '<': VS_FUNC(ST_SCALAR_INT, (*M1 < M2) ? 1 : 0);
+  case '>': VS_FUNC(ST_SCALAR_INT, (*M1 > M2) ? 1 : 0);
+  case '&': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)M2));
+  case '|': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)M2));
+  case 'E': VS_FUNC(ST_SCALAR_INT, (*M1 == M2) ? 1 : 0);
+  case 'N': VS_FUNC(ST_SCALAR_INT, (*M1 != M2) ? 1 : 0);
+  case 'L': VS_FUNC(ST_SCALAR_INT, (*M1 <= M2) ? 1 : 0);
+  case 'G': VS_FUNC(ST_SCALAR_INT, (*M1 >= M2) ? 1 : 0);
+  case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0);
+  case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0);
+  default:
+    snprintf (line, 512, "error: op %c not defined!", op[0]);
+    push_error (line);
+    return (FALSE);
+}
 # undef VS_FUNC
 
@@ -584,7 +584,7 @@
 
   if (V1[0].type == ST_VECTOR_TMP) {
-    free (V1[0].vector[0].elements.Ptr);
-    free (V1[0].vector);
-  }
+  free (V1[0].vector[0].elements.Ptr);
+  free (V1[0].vector);
+}
 
   clear_stack (V1);
@@ -885,19 +885,19 @@
   float *out   = (float *)OUT[0].buffer[0].matrix.buffer;
 
-# define MS_FUNC(OP) {					\
-    if (V2->type == ST_SCALAR_FLT)  {				\
-      opihi_flt M2 = V2[0].FltValue;			\
+# define MS_FUNC(OP) {				\
+    if (V2->type == ST_SCALAR_FLT)  {		\
+      opihi_flt M2 = V2[0].FltValue;		\
       for (i = 0; i < Npix; i++, out++, M1++) {	\
-	*out = OP;					\
-      }							\
-      break;						\
-    }							\
-    if (V2->type == ST_SCALAR_INT)  {				\
-      opihi_int M2 = V2[0].IntValue;			\
+	*out = OP;				\
+      }						\
+      break;					\
+    }						\
+    if (V2->type == ST_SCALAR_INT)  {		\
+      opihi_int M2 = V2[0].IntValue;		\
       for (i = 0; i < Npix; i++, out++, M1++) {	\
-	*out = OP;					\
-      }							\
-      break;						\
-    }							\
+	*out = OP;				\
+      }						\
+      break;					\
+    }						\
   }
 
@@ -961,19 +961,19 @@
   float *out   = (float *)OUT[0].buffer[0].matrix.buffer;
 
-# define SM_FUNC(OP) {					\
-    if (V1->type == ST_SCALAR_FLT)  {				\
-      opihi_flt M1 = V1[0].FltValue;			\
+# define SM_FUNC(OP) {				\
+    if (V1->type == ST_SCALAR_FLT)  {		\
+      opihi_flt M1 = V1[0].FltValue;		\
       for (i = 0; i < Npix; i++, out++, M2++) {	\
-	*out = OP;					\
-      }							\
-      break;						\
-    }							\
-    if (V1->type == ST_SCALAR_INT)  {				\
-      opihi_int M1 = V1[0].IntValue;			\
+	*out = OP;				\
+      }						\
+      break;					\
+    }						\
+    if (V1->type == ST_SCALAR_INT)  {		\
+      opihi_int M1 = V1[0].IntValue;		\
       for (i = 0; i < Npix; i++, out++, M2++) {	\
-	*out = OP;					\
-      }							\
-      break;						\
-    }							\
+	*out = OP;				\
+      }						\
+      break;					\
+    }						\
   }
 
@@ -1023,36 +1023,36 @@
 
 # define SS_FUNC(FTYPE,OP) {						\
-    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT)) {			\
+    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT)) {	\
       opihi_flt M1 = V1[0].FltValue;					\
       opihi_flt M2 = V2[0].FltValue;					\
-      OUT[0].type = ST_SCALAR_FLT;						\
+      OUT[0].type = ST_SCALAR_FLT;					\
       OUT[0].FltValue = OP;						\
       break;								\
     }									\
-    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT)) {			\
+    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT)) {	\
       opihi_flt M1 = V1[0].FltValue;					\
       opihi_int M2 = V2[0].IntValue;					\
-      OUT[0].type = ST_SCALAR_FLT;						\
+      OUT[0].type = ST_SCALAR_FLT;					\
       OUT[0].FltValue = OP;						\
       break;								\
     }									\
-    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_FLT)) {			\
+    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_FLT)) {	\
       opihi_int M1 = V1[0].IntValue;					\
       opihi_flt M2 = V2[0].FltValue;					\
-      OUT[0].type = ST_SCALAR_FLT;						\
+      OUT[0].type = ST_SCALAR_FLT;					\
       OUT[0].FltValue = OP;						\
       break;								\
     }									\
-    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {	\
+    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) { \
       opihi_int M1 = V1[0].IntValue;					\
       opihi_int M2 = V2[0].IntValue;					\
-      OUT[0].type = ST_SCALAR_FLT;						\
+      OUT[0].type = ST_SCALAR_FLT;					\
       OUT[0].FltValue = OP;						\
       break;								\
     }									\
-    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {			\
+    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {	\
       opihi_int M1 = V1[0].IntValue;					\
       opihi_int M2 = V2[0].IntValue;					\
-      OUT[0].type = ST_SCALAR_INT;						\
+      OUT[0].type = ST_SCALAR_INT;					\
       OUT[0].IntValue = OP;						\
       break;								\
@@ -1061,29 +1061,29 @@
 
   switch (op[0]) { 
-    case '+': SS_FUNC(ST_SCALAR_INT, M1 + M2);
-    case '-': SS_FUNC(ST_SCALAR_INT, M1 - M2);
-    case '*': SS_FUNC(ST_SCALAR_INT, M1 * M2);
-    case '/': SS_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) M2);
-    case '%': SS_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) M2);
-    case '^': SS_FUNC(ST_SCALAR_FLT, pow (M1, M2));
-    case '@': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
-    case 'a': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
-    case 'D': SS_FUNC(ST_SCALAR_INT, MIN (M1, M2));
-    case 'U': SS_FUNC(ST_SCALAR_INT, MAX (M1, M2));
-    case '<': SS_FUNC(ST_SCALAR_INT, (M1 < M2) ? 1 : 0);
-    case '>': SS_FUNC(ST_SCALAR_INT, (M1 > M2) ? 1 : 0);
-    case '&': SS_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)M2));
-    case '|': SS_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)M2));
-    case 'E': SS_FUNC(ST_SCALAR_INT, (M1 == M2) ? 1 : 0);
-    case 'N': SS_FUNC(ST_SCALAR_INT, (M1 != M2) ? 1 : 0);
-    case 'L': SS_FUNC(ST_SCALAR_INT, (M1 <= M2) ? 1 : 0);
-    case 'G': SS_FUNC(ST_SCALAR_INT, (M1 >= M2) ? 1 : 0);
-    case 'A': SS_FUNC(ST_SCALAR_INT, (M1 && M2) ? 1 : 0);
-    case 'O': SS_FUNC(ST_SCALAR_INT, (M1 || M2) ? 1 : 0);
-    default:
-      snprintf (line, 512, "error: op %c not defined!", op[0]);
-      push_error (line);
-      return (FALSE);
-  }
+  case '+': SS_FUNC(ST_SCALAR_INT, M1 + M2);
+  case '-': SS_FUNC(ST_SCALAR_INT, M1 - M2);
+  case '*': SS_FUNC(ST_SCALAR_INT, M1 * M2);
+  case '/': SS_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) M2);
+  case '%': SS_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) M2);
+  case '^': SS_FUNC(ST_SCALAR_FLT, pow (M1, M2));
+  case '@': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
+  case 'a': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
+  case 'D': SS_FUNC(ST_SCALAR_INT, MIN (M1, M2));
+  case 'U': SS_FUNC(ST_SCALAR_INT, MAX (M1, M2));
+  case '<': SS_FUNC(ST_SCALAR_INT, (M1 < M2) ? 1 : 0);
+  case '>': SS_FUNC(ST_SCALAR_INT, (M1 > M2) ? 1 : 0);
+  case '&': SS_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)M2));
+  case '|': SS_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)M2));
+  case 'E': SS_FUNC(ST_SCALAR_INT, (M1 == M2) ? 1 : 0);
+  case 'N': SS_FUNC(ST_SCALAR_INT, (M1 != M2) ? 1 : 0);
+  case 'L': SS_FUNC(ST_SCALAR_INT, (M1 <= M2) ? 1 : 0);
+  case 'G': SS_FUNC(ST_SCALAR_INT, (M1 >= M2) ? 1 : 0);
+  case 'A': SS_FUNC(ST_SCALAR_INT, (M1 && M2) ? 1 : 0);
+  case 'O': SS_FUNC(ST_SCALAR_INT, (M1 || M2) ? 1 : 0);
+  default:
+    snprintf (line, 512, "error: op %c not defined!", op[0]);
+    push_error (line);
+    return (FALSE);
+}
 # undef SS_FUNC
 
@@ -1153,31 +1153,30 @@
 }
 
-
 int S_unary (StackVar *OUT, StackVar *V1, char *op) {
 
   char line[512]; // this is only used to report an error 
   
-# define S_FUNC(OP,FTYPE) {			\
-    if (V1->type == ST_SCALAR_FLT) {			\
-      opihi_flt M1  = V1[0].FltValue;		\
-      OUT[0].type = ST_SCALAR_FLT;			\
-      OUT[0].FltValue = OP;			\
-      clear_stack (V1);				\
-      return (TRUE);				\
-    }						\
+# define S_FUNC(OP,FTYPE) {						\
+    if (V1->type == ST_SCALAR_FLT) {					\
+      opihi_flt M1  = V1[0].FltValue;					\
+      OUT[0].type = ST_SCALAR_FLT;					\
+      OUT[0].FltValue = OP;						\
+      clear_stack (V1);							\
+      return (TRUE);							\
+    }									\
     if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT)) {	\
-      opihi_int M1  = V1[0].IntValue;		\
-      OUT[0].type = ST_SCALAR_FLT;			\
-      OUT[0].FltValue = OP;			\
-      clear_stack (V1);				\
-      return (TRUE);				\
-    }						\
+      opihi_int M1  = V1[0].IntValue;					\
+      OUT[0].type = ST_SCALAR_FLT;					\
+      OUT[0].FltValue = OP;						\
+      clear_stack (V1);							\
+      return (TRUE);							\
+    }									\
     if ((FTYPE == ST_SCALAR_INT) && (V1->type == ST_SCALAR_INT)) {	\
-      opihi_int M1  = V1[0].IntValue;		\
-      OUT[0].type = ST_SCALAR_INT;			\
-      OUT[0].IntValue = OP;			\
-      clear_stack (V1);				\
-      return (TRUE);				\
-    }						\
+      opihi_int M1  = V1[0].IntValue;					\
+      OUT[0].type = ST_SCALAR_INT;					\
+      OUT[0].IntValue = OP;						\
+      clear_stack (V1);							\
+      return (TRUE);							\
+    }									\
   }
 
@@ -1211,5 +1210,8 @@
   if (!strcmp (op, "dacos"))  S_FUNC(acos (M1)*DEG_RAD, ST_SCALAR_FLT);
   if (!strcmp (op, "datan"))  S_FUNC(atan (M1)*DEG_RAD, ST_SCALAR_FLT);
-  if (!strcmp (op, "rnd"))    S_FUNC(M1*0.0 + drand48(), ST_SCALAR_FLT);
+  if (!strcmp (op, "rnd"))    S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT);
+  if (!strcmp (op, "drnd"))   S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT);
+  if (!strcmp (op, "lrnd"))   S_FUNC(0*M1 + lrand48(), ST_SCALAR_INT);
+  if (!strcmp (op, "mrnd"))   S_FUNC(0*M1 + mrand48(), ST_SCALAR_INT);
   if (!strcmp (op, "not"))    S_FUNC(!(M1), ST_SCALAR_INT);
   if (!strcmp (op, "--"))     S_FUNC(-1*M1, ST_SCALAR_INT); // NOTE: opihi_int is signed, 
@@ -1235,31 +1237,31 @@
   OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/
 
-# define V_FUNC(OP,FTYPE) {					\
-    if (V1->vector->type == OPIHI_FLT) {			\
-      CopyVector (OUT[0].vector, V1[0].vector);			\
-      opihi_flt *M1  = V1[0].vector[0].elements.Flt;		\
-      opihi_flt *out = OUT[0].vector[0].elements.Flt;		\
-      for (i = 0; i < Nx; i++, out++, M1++) {			\
-	*out = OP;						\
-      }								\
-      goto escape;						\
-    }								\
+# define V_FUNC(OP,FTYPE) {						\
+    if (V1->vector->type == OPIHI_FLT) {				\
+      CopyVector (OUT[0].vector, V1[0].vector);				\
+      opihi_flt *M1  = V1[0].vector[0].elements.Flt;			\
+      opihi_flt *out = OUT[0].vector[0].elements.Flt;			\
+      for (i = 0; i < Nx; i++, out++, M1++) {				\
+	*out = OP;							\
+      }									\
+      goto escape;							\
+    }									\
     if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_FLT)) {	\
-      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);	\
-      opihi_int *M1  = V1[0].vector[0].elements.Int;		\
-      opihi_flt *out = OUT[0].vector[0].elements.Flt;		\
-      for (i = 0; i < Nx; i++, out++, M1++) {			\
-	*out = OP;						\
-      }								\
-      goto escape;						\
-    }								\
+      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);		\
+      opihi_int *M1  = V1[0].vector[0].elements.Int;			\
+      opihi_flt *out = OUT[0].vector[0].elements.Flt;			\
+      for (i = 0; i < Nx; i++, out++, M1++) {				\
+	*out = OP;							\
+      }									\
+      goto escape;							\
+    }									\
     if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_INT)) {	\
-      CopyVector (OUT[0].vector, V1[0].vector);			\
-      opihi_int *M1  = V1[0].vector[0].elements.Int;		\
-      opihi_int *out = OUT[0].vector[0].elements.Int;		\
-      for (i = 0; i < Nx; i++, out++, M1++) {			\
-	*out = OP;						\
-      }								\
-      goto escape;						\
+      CopyVector (OUT[0].vector, V1[0].vector);				\
+      opihi_int *M1  = V1[0].vector[0].elements.Int;			\
+      opihi_int *out = OUT[0].vector[0].elements.Int;			\
+      for (i = 0; i < Nx; i++, out++, M1++) {				\
+	*out = OP;							\
+      }									\
+      goto escape;							\
     } }							
 
@@ -1294,4 +1296,7 @@
   if (!strcmp (op, "datan"))  V_FUNC(atan(*M1)*DEG_RAD, ST_SCALAR_FLT);
   if (!strcmp (op, "rnd"))    V_FUNC(drand48(), ST_SCALAR_FLT);
+  if (!strcmp (op, "drnd"))   V_FUNC(drand48(), ST_SCALAR_FLT);
+  if (!strcmp (op, "lrnd"))   V_FUNC(lrand48(), ST_SCALAR_INT);
+  if (!strcmp (op, "mrnd"))   V_FUNC(mrand48(), ST_SCALAR_INT);
   if (!strcmp (op, "ramp"))   V_FUNC(i, ST_SCALAR_INT);
   if (!strcmp (op, "zero"))   V_FUNC(0, ST_SCALAR_INT);
@@ -1320,4 +1325,6 @@
 }
 
+# define M_FUNC(OP) { for (i = 0; i < Npix; i++, out++, M1++) { *out = (OP); }}
+
 int M_unary (StackVar *OUT, StackVar *V1, char *op) {
 
@@ -1337,45 +1344,45 @@
   M1  = (float *) V1[0].buffer[0].matrix.buffer;
   out = (float *)OUT[0].buffer[0].matrix.buffer;
-
+ 
+// if (!strcmp (op, "rint"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = nearbyint (*M1); }}
+  
   if (!strcmp (op, "="))     { }
-  if (!strcmp (op, "abs"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = fabs(*M1);         }}
-  if (!strcmp (op, "int"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = (opihi_flt)(long long)(*M1); }}
-
-  if (!strcmp (op, "floor")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = floor (*M1); }}
-  if (!strcmp (op, "ceil"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = ceil (*M1); }}
-  // if (!strcmp (op, "rint"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = nearbyint (*M1); }}
-
-  if (!strcmp (op, "exp"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = exp(*M1);          }}
-  if (!strcmp (op, "ten"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = pow(10.0,*M1);     }}
-  if (!strcmp (op, "log"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = log10(*M1);        }}
-  if (!strcmp (op, "ln"))    { for (i = 0; i < Npix; i++, out++, M1++) { *out = log(*M1);          }}
-  if (!strcmp (op, "sqrt"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = sqrt(*M1);         }}
-  if (!strcmp (op, "erf"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = erf(*M1);          }}
-
-  if (!strcmp (op, "sinh"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = sinh(*M1);         }}
-  if (!strcmp (op, "cosh"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = cosh(*M1);         }}
-  if (!strcmp (op, "asinh")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = asinh(*M1);        }}
-  if (!strcmp (op, "acosh")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = acosh(*M1);        }}
-  if (!strcmp (op, "lgamma")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = lgamma(*M1);      }}
-
-  if (!strcmp (op, "sin"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = sin(*M1);          }}
-  if (!strcmp (op, "cos"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = cos(*M1);          }}
-  if (!strcmp (op, "tan"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = tan(*M1);          }}
-  if (!strcmp (op, "dsin"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = sin(*M1*RAD_DEG);  }}
-  if (!strcmp (op, "dcos"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = cos(*M1*RAD_DEG);  }}
-  if (!strcmp (op, "dtan"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = tan(*M1*RAD_DEG);  }}
-  if (!strcmp (op, "asin"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = asin(*M1);         }}
-  if (!strcmp (op, "acos"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = acos(*M1);         }}
-  if (!strcmp (op, "atan"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = atan(*M1);         }}
-  if (!strcmp (op, "dasin")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = asin(*M1)*DEG_RAD; }}
-  if (!strcmp (op, "dacos")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = acos(*M1)*DEG_RAD; }}
-  if (!strcmp (op, "datan")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = atan(*M1)*DEG_RAD; }}
-  if (!strcmp (op, "not"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = !(*M1);            }}
-  if (!strcmp (op, "--"))    { for (i = 0; i < Npix; i++, out++, M1++) { *out = -(*M1);            }}
-  if (!strcmp (op, "rnd"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = drand48();         }}
-  if (!strcmp (op, "ramp"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = i;                 }}
-  if (!strcmp (op, "zero"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = 0;                 }}
-  if (!strcmp (op, "isinf")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = !finite(*M1);      }}
-  if (!strcmp (op, "isnan")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = isnan(*M1);        }}
+  if (!strcmp (op, "abs"))    M_FUNC(fabs(*M1));
+  if (!strcmp (op, "int"))    M_FUNC((opihi_flt)(long long)(*M1));
+  if (!strcmp (op, "floor"))  M_FUNC(floor (*M1));
+  if (!strcmp (op, "ceil"))   M_FUNC(ceil (*M1));
+  if (!strcmp (op, "exp"))    M_FUNC(exp(*M1));
+  if (!strcmp (op, "ten"))    M_FUNC(pow(10.0,*M1));
+  if (!strcmp (op, "log"))    M_FUNC(log10(*M1));
+  if (!strcmp (op, "ln"))     M_FUNC(log(*M1));
+  if (!strcmp (op, "sqrt"))   M_FUNC(sqrt(*M1));
+  if (!strcmp (op, "erf"))    M_FUNC(erf(*M1));
+  if (!strcmp (op, "sinh"))   M_FUNC(sinh(*M1));
+  if (!strcmp (op, "cosh"))   M_FUNC(cosh(*M1));
+  if (!strcmp (op, "asinh"))  M_FUNC(asinh(*M1));
+  if (!strcmp (op, "acosh"))  M_FUNC(acosh(*M1));
+  if (!strcmp (op, "lgamma")) M_FUNC(lgamma(*M1));
+  if (!strcmp (op, "sin"))    M_FUNC(sin(*M1));
+  if (!strcmp (op, "cos"))    M_FUNC(cos(*M1));
+  if (!strcmp (op, "tan"))    M_FUNC(tan(*M1));
+  if (!strcmp (op, "dsin"))   M_FUNC(sin(*M1*RAD_DEG));
+  if (!strcmp (op, "dcos"))   M_FUNC(cos(*M1*RAD_DEG));
+  if (!strcmp (op, "dtan"))   M_FUNC(tan(*M1*RAD_DEG));
+  if (!strcmp (op, "asin"))   M_FUNC(asin(*M1));
+  if (!strcmp (op, "acos"))   M_FUNC(acos(*M1));
+  if (!strcmp (op, "atan"))   M_FUNC(atan(*M1));
+  if (!strcmp (op, "dasin"))  M_FUNC(asin(*M1)*DEG_RAD);
+  if (!strcmp (op, "dacos"))  M_FUNC(acos(*M1)*DEG_RAD);
+  if (!strcmp (op, "datan"))  M_FUNC(atan(*M1)*DEG_RAD);
+  if (!strcmp (op, "not"))    M_FUNC(!(*M1));
+  if (!strcmp (op, "--"))     M_FUNC(-(*M1));
+  if (!strcmp (op, "rnd"))    M_FUNC(drand48());
+  if (!strcmp (op, "drnd"))   M_FUNC(drand48());
+  if (!strcmp (op, "lrnd"))   M_FUNC(lrand48());
+  if (!strcmp (op, "mrnd"))   M_FUNC(mrand48());
+  if (!strcmp (op, "ramp"))   M_FUNC(i);
+  if (!strcmp (op, "zero"))   M_FUNC(0);
+  if (!strcmp (op, "isinf"))  M_FUNC(!finite(*M1));
+  if (!strcmp (op, "isnan"))  M_FUNC(isnan(*M1));
 
   /* xrm and yrm only make sense for 2D matrices. see special meaning for vectors */
