Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/cgrid.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/cgrid.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/cgrid.c	(revision 20860)
@@ -391,8 +391,8 @@
   graphmode.ptype = 100; /* connect a pair */
   graphmode.etype = 0;
-  PlotVectorPair (kapa, Xvec, Yvec, &graphmode);
-
-  free (Xvec.elements.Flt);
-  free (Yvec.elements.Flt);
+  PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode);
+
+  free (Xvec.elements.Ptr);
+  free (Yvec.elements.Ptr);
   return (TRUE);
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/cplot.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/cplot.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/cplot.c	(revision 20860)
@@ -31,6 +31,6 @@
   }
 
-  ResetVector (Xvec, OPIHI_FLT, xvec[0].Nelements);
-  ResetVector (Yvec, OPIHI_FLT, xvec[0].Nelements);
+  ResetVector (&Xvec, OPIHI_FLT, xvec[0].Nelements);
+  ResetVector (&Yvec, OPIHI_FLT, xvec[0].Nelements);
   
   r = xvec[0].elements.Flt;
@@ -77,8 +77,8 @@
 
   graphmode.etype = 0;
-  PlotVectorPair (kapa, Xvec, Yvec, &graphmode);
+  PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode);
   
-  free (Xvec.elements.Flt);
-  free (Yvec.elements.Flt);
+  free (Xvec.elements.Ptr);
+  free (Yvec.elements.Ptr);
     
   return (TRUE);
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/czplot.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/czplot.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/czplot.c	(revision 20860)
@@ -38,7 +38,7 @@
     return (FALSE);
   }
-  ResetVector (Xvec, OPIHI_FLT, xvec[0].Nelements);
-  ResetVector (Yvec, OPIHI_FLT, xvec[0].Nelements);
-  ResetVector (Zvec, OPIHI_FLT, xvec[0].Nelements);
+  ResetVector (&Xvec, OPIHI_FLT, xvec[0].Nelements);
+  ResetVector (&Yvec, OPIHI_FLT, xvec[0].Nelements);
+  ResetVector (&Zvec, OPIHI_FLT, xvec[0].Nelements);
   
   r   = xvec[0].elements.Flt;
@@ -67,5 +67,5 @@
   graphmode.size = -1; /* point size determined by Zvec */
   graphmode.etype = 0;
-  PlotVectorTriplet (kapa, Xvec, Yvec, Zvec, &graphmode);
+  PlotVectorTriplet (kapa, &Xvec, &Yvec, &Zvec, &graphmode);
 
   free (Xvec.elements.Flt);
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/profile.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/profile.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/profile.c	(revision 20860)
@@ -28,6 +28,6 @@
   if ((yvec = SelectVector (argv[3], ANYVECTOR, TRUE)) == NULL) return (FALSE);
 
-  ResetVector (xvec, OPIHI_FLT, (int)SQ(2*N+1);
-  ResetVector (yvec, OPIHI_FLT, (int)SQ(2*N+1);
+  ResetVector (xvec, OPIHI_FLT, (int)SQ(2*N+1));
+  ResetVector (yvec, OPIHI_FLT, (int)SQ(2*N+1));
 
   bzero (yvec[0].elements.Flt, (int)SQ(2*N+1)*sizeof(opihi_flt)+1);
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/applyfit.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/applyfit.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/applyfit.c	(revision 20860)
@@ -6,5 +6,5 @@
   char *c, name[64];
   double *C, X;
-  opihi_flt *x, *y;
+  opihi_flt *y;
   Vector *xvec, *yvec;
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/applyfit2d.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/applyfit2d.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/applyfit2d.c	(revision 20860)
@@ -6,5 +6,5 @@
   char *c, name[64];
   double **C, X, Y;
-  opihi_flt *x, *y, *z;
+  opihi_flt *z;
   Vector *xvec, *yvec, *zvec;
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/concat.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/concat.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/concat.c	(revision 20860)
@@ -5,4 +5,5 @@
   int  i, j, Nin;
   double value;
+  opihi_flt *temp;
   Vector *ivec, *ovec;
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/dbselect.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/dbselect.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/dbselect.c	(revision 20860)
@@ -86,4 +86,5 @@
 	ResetVector (vec[i], OPIHI_FLT, Nrows);
 	break;
+    }
   }
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/gaussj.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/gaussj.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/gaussj.c	(revision 20860)
@@ -7,5 +7,5 @@
   opihi_int *vi;
   double **a, **b;
-  int i, j, N, status, QUIET;
+  int i, j, N, status, QUIET, isFloat;
   Vector *B;
   Buffer *A;
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/grid.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/grid.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/grid.c	(revision 20860)
@@ -23,6 +23,6 @@
 
   N = 0;
-  ResetVector (Xvec, OPIHI_FLT, 200);
-  ResetVector (Yvec, OPIHI_FLT, 200);
+  ResetVector (&Xvec, OPIHI_FLT, 200);
+  ResetVector (&Yvec, OPIHI_FLT, 200);
 
   major = minor = 1;
@@ -191,5 +191,5 @@
   graphmode.ptype = 100; /* connect a pair */
   graphmode.etype = 0;
-  PlotVectorPair (kapa, Xvec, Yvec, &graphmode);
+  PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode);
 
   free (Xvec.elements.Flt);
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/histogram.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/histogram.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/histogram.c	(revision 20860)
@@ -35,5 +35,5 @@
   bzero (yvec[0].elements.Int, sizeof(opihi_int)*yvec[0].Nelements);
   if (Nbins < 1) return (TRUE);
-  *OUT = yvec[0].elements.Int;
+  OUT = yvec[0].elements.Int;
 
   if (xvec[0].type == OPIHI_FLT) {
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/integrate.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/integrate.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/integrate.c	(revision 20860)
@@ -4,5 +4,6 @@
   
   int i, N, VERBOSE, isFloat;
-  opihi_flt *X, *Y;
+  opihi_flt *Yf;
+  opihi_int *Yi;
   double start, end, value, range, dvalue;
   Vector *vecx, *vecy;
@@ -37,5 +38,5 @@
       if ((*X >= start) && (*X <= end)) {
 	dvalue = (isFloat) ? *Yf : *Yi;
-	value += *Y * (X[1] - X[0]);
+	value += dvalue * (X[1] - X[0]);
 	range += (X[1] - X[0]);
       }
@@ -46,5 +47,5 @@
       if ((*X >= start) && (*X <= end)) {
 	dvalue = (isFloat) ? *Yf : *Yi;
-	value += *Y * (X[1] - X[0]);
+	value += dvalue * (X[1] - X[0]);
 	range += (X[1] - X[0]);
       }
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/interpolate.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/interpolate.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/interpolate.c	(revision 20860)
@@ -21,7 +21,7 @@
   if ((yout = SelectVector (argv[4],  ANYVECTOR, TRUE)) == NULL) return (FALSE);
 
-  REQUIRE_VECTOR_FLT (in, FALSE); 
-  REQUIRE_VECTOR_FLT (xv, FALSE); 
-  REQUIRE_VECTOR_FLT (yv, FALSE); 
+  REQUIRE_VECTOR_FLT (xin, FALSE); 
+  REQUIRE_VECTOR_FLT (yin, FALSE); 
+  REQUIRE_VECTOR_FLT (xout, FALSE); 
   ResetVector (yout, OPIHI_FLT, xout[0].Nelements);
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/peak.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/peak.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/peak.c	(revision 20860)
@@ -5,5 +5,4 @@
   int i, N, imax, QUIET;
   double start, end, xmax, ymax;
-  opihi_flt *X, *Y;
   Vector *vecx, *vecy;
 
@@ -31,30 +30,53 @@
 
   imax = -1;
+  xmax = -HUGE_VAL;
+  ymax = -HUGE_VAL;
 
-  if (vecx[0].type == OPIHI_FLT) {
+  if ((vecx[0].type == OPIHI_FLT) && (vecy[0].type == OPIHI_FLT)) {
     opihi_flt *X = vecx[0].elements.Flt;
-    xmax = X[start];
-    ymax = (vecy[0].type == OPIHI_FLT) ? vecy[0].elements.Flt[start] : vecy[0].elements.Int[start];
-    for (i = 1; i < vecx[0].Nelements-1; i++, X++, Y++) {
-      if ((*X >= start) && (*X <= end)) {
-	if ((imax == -1) || (*Y > ymax)) {
-	  xmax = *X;
-	  ymax = (vecy[0].type == OPIHI_FLT) ? vecy[0].elements.Flt[i] : vecy[0].elements.Int[i];
-	  imax = i;
-	}
-      }
+    opihi_flt *Y = vecy[0].elements.Flt;
+    for (i = 0; i < vecx[0].Nelements; i++, X++, Y++) {
+      if (*X < start) continue;
+      if (*X > end) continue;
+      if (*Y < ymax) continue;
+      xmax = *X;
+      ymax = *Y;
+      imax = i;
     }      
-  } else {
+  }
+  if ((vecx[0].type == OPIHI_FLT) && (vecy[0].type == OPIHI_INT)) {
+    opihi_flt *X = vecx[0].elements.Flt;
+    opihi_int *Y = vecy[0].elements.Int;
+    for (i = 0; i < vecx[0].Nelements; i++, X++, Y++) {
+      if (*X < start) continue;
+      if (*X > end) continue;
+      if (*Y < ymax) continue;
+      xmax = *X;
+      ymax = *Y;
+      imax = i;
+    }      
+  }
+  if ((vecx[0].type == OPIHI_INT) && (vecy[0].type == OPIHI_FLT)) {
     opihi_int *X = vecx[0].elements.Int;
-    xmax = X[start];
-    ymax = (vecy[0].type == OPIHI_FLT) ? vecy[0].elements.Flt[start] : vecy[0].elements.Int[start];
-    for (i = 1; i < vecx[0].Nelements-1; i++, X++, Y++) {
-      if ((*X >= start) && (*X <= end)) {
-	if ((imax == -1) || (*Y > ymax)) {
-	  xmax = *X;
-	  ymax = (vecy[0].type == OPIHI_FLT) ? vecy[0].elements.Flt[i] : vecy[0].elements.Int[i];
-	  imax = i;
-	}
-      }
+    opihi_flt *Y = vecy[0].elements.Flt;
+    for (i = 0; i < vecx[0].Nelements; i++, X++, Y++) {
+      if (*X < start) continue;
+      if (*X > end) continue;
+      if (*Y < ymax) continue;
+      xmax = *X;
+      ymax = *Y;
+      imax = i;
+    }      
+  }
+  if ((vecx[0].type == OPIHI_INT) && (vecy[0].type == OPIHI_INT)) {
+    opihi_int *X = vecx[0].elements.Int;
+    opihi_int *Y = vecy[0].elements.Int;
+    for (i = 0; i < vecx[0].Nelements; i++, X++, Y++) {
+      if (*X < start) continue;
+      if (*X > end) continue;
+      if (*Y < ymax) continue;
+      xmax = *X;
+      ymax = *Y;
+      imax = i;
     }      
   }
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/read_vectors.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/read_vectors.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/read_vectors.c	(revision 20860)
@@ -159,5 +159,5 @@
 int read_table_vectors (int argc, char **argv, char *extname) {
 
-  int i, j, k, N, Nbytes, Nextend, Ny, Binary;
+  int i, j, k, N, Nbytes, Nextend, Ny, Binary, vecType;
   char type[16], ID[80], *CCDKeyword;
   FTable table;
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/sort.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/sort.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/sort.c	(revision 20860)
@@ -101,9 +101,10 @@
       }
       /* swap .elements.Flt (== V) and itemp */ 
-      vec[i][0].elements.Flt = itemp;
+      vec[i][0].elements.Int = itemp;
       itemp = V;
     }
   }
-  free (temp);
+  free (itemp);
+  free (ftemp);
   free (vec);
   free (index);
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/uniq.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/uniq.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/uniq.c	(revision 20860)
@@ -15,5 +15,5 @@
 
   /* allocate the maximum possible needed */
-  ResetVector (out, ivec->type, ivec->Nelements);
+  ResetVector (ovec, ivec->type, ivec->Nelements);
 
   Nnew = 0;
@@ -48,5 +48,5 @@
 
   // free up extra memory
-  ResetVector (out, ivec->type, Nnew);
+  ResetVector (ovec, ivec->type, Nnew);
 
   return (TRUE);
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/vbin.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/vbin.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/vbin.c	(revision 20860)
@@ -5,5 +5,5 @@
   int i, j, n, N, Nin, Nout;
   int Normalize, Ignore;
-  opihi_flt *Vout, *Vin, IgnoreValue;
+  opihi_flt *Vout, IgnoreValue;
   double scale;
   Vector *in, *out;
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/vclip.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/vclip.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/vclip.c	(revision 20860)
@@ -5,5 +5,4 @@
   int i, Npix, DO_NAN, DO_INF, DO_CLIP, N;
   double min, Vmin, max, Vmax, nan_val, inf_val;
-  opihi_flt *in;
   Vector *vec;
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/vload.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/vload.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/vload.c	(revision 20860)
@@ -82,6 +82,6 @@
     overlay[i].type = type;
     overlay[i].text = NULL;
-    overlay[i].x = (vec[0].type == OPIHI_FLT) ? vecx[0].elements.Flt[i] : vecx[0].elements.Int[i];
-    overlay[i].y = (vec[0].type == OPIHI_FLT) ? vecy[0].elements.Flt[i] : vecy[0].elements.Int[i];
+    overlay[i].x = (vecx[0].type == OPIHI_FLT) ? vecx[0].elements.Flt[i] : vecx[0].elements.Int[i];
+    overlay[i].y = (vecy[0].type == OPIHI_FLT) ? vecy[0].elements.Flt[i] : vecy[0].elements.Int[i];
     overlay[i].x += 0.5;
     overlay[i].y += 0.5;
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/zplot.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/zplot.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/zplot.c	(revision 20860)
@@ -41,5 +41,5 @@
     }
   } else {
-    opihi_int *in = zvec[0].elements.Flt;
+    opihi_int *in = zvec[0].elements.Int;
     for (i = 0; i < Zvec.Nelements; i++, in++, out++) {
       *out = MIN (1.0, MAX (0.01, (*in - min) / range));
@@ -51,7 +51,7 @@
   graphmode.size = -1; /* point size determined by Zvec */
   graphmode.etype = 0; /* no errorbars */
-  PlotVectorTriplet (kapa, xvec, yvec, Zvec, &graphmode);
+  PlotVectorTriplet (kapa, xvec, yvec, &Zvec, &graphmode);
 
-  free (Zvec.elements.Flt);
+  free (Zvec.elements.Ptr);
 
   return (TRUE);
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/avextract.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/avextract.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/avextract.c	(revision 20860)
@@ -1,5 +1,4 @@
 # include "dvoshell.h"
 
-// XXX need to promote values (and dbStack entries) to opihi_flt, but wait until done testing
 int avextract (int argc, char **argv) {
   
@@ -73,5 +72,5 @@
 
   /* create output storage vectors */
-  ALLOCATE (values, float, Nfields);
+  ALLOCATE (values, dbValue, Nfields);
   ALLOCATE (vec, Vector *, Nreturn);
   for (i = 0; i < Nreturn; i++) {
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbBooleanCond.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbBooleanCond.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbBooleanCond.c	(revision 20860)
@@ -4,5 +4,5 @@
 // supplied by fields, in order 0 - Nfields (validate before calling)
 // XXX fields needs to be typed (dbValue), stack math needs to deal with the type cases
-int dbBooleanCond (dbStack *inStack, int NinStack, float *fields) {
+int dbBooleanCond (dbStack *inStack, int NinStack, dbValue *fields) {
   
   float value;
@@ -22,5 +22,5 @@
 
     /***** binary operators *****/
-    if ((stack[i][0].type >= 3) && (stack[i][0].type <= 8)) {
+    if ((stack[i][0].type >= DB_STACK_LOGIC) && (stack[i][0].type <= DB_STACK_POWER)) {
 
       // pre-test that op and entries match
@@ -42,5 +42,5 @@
 
     /***** unary operators **/
-    if (stack[i][0].type == 9) {
+    if (stack[i][0].type == DB_STACK_UNARY) {
 
       // pre-test that op and entries match
@@ -62,9 +62,9 @@
 
   // the result here is a single stack entry with a value:
-  if (stack[0][0].type == 'F') {
+  if (stack[0][0].type & DB_STACK_FIELD) {
     N = stack[0][0].field;
-    value = fields[N];
+    value = (stack[0][0].type & DB_STACK_INT) ? fields[N].Int : fields[N].Flt;
   } else {
-    value = stack[0][0].Float;
+    value = (stack[0][0].type & DB_STACK_INT) ? stack[0][0].IntValue : stack[0][0].FltValue;
   }
     
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbCheckStack.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbCheckStack.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbCheckStack.c	(revision 20860)
@@ -1,8 +1,14 @@
 # include "dvoshell.h"
+
+// XXX we are using a fairly bogus set of char values to distinguish a few cases:
+// 's', 'S' : value is a scalar (upper == float; lower == int)
+// 'f', 'F' : value is a field (upper == float; lower == int)
+// 't', 'T' : value is a temp scalar (upper == float; lower == int)
+// these would be better done using bit values to test for field? temp? float?
 
 int dbCheckStack (dbStack *stack, int Nstack, int table, dbField **inFields, int *inNfields) {
 
   int i, j, status, NFIELDS, Nfields;
-  char *c;
+  char *c1, *c2;
   dbField *fields;
 
@@ -14,10 +20,16 @@
 
   for (i = 0; i < Nstack; i++) {
-    if (stack[i].type == 'X') {
+    if (stack[i].type == DB_STACK_VALUE) {
 
-      /** if this is a number, put it on the list of scalers and move on **/
-      stack[i].Float = strtod (stack[i].name, &c);
-      if (c == stack[i].name + strlen (stack[i].name)) {
-	stack[i].type  = 'S';
+      /** if this is a number, put it on the list of scalars and move on.  assume value is
+       * an int unless proven otherwise **/
+      stack[i].FltValue = strtod (stack[i].name, &c1);
+      stack[i].IntValue = strtol (stack[i].name, &c2, 0);
+      if (c2 == stack[i].name + strlen (stack[i].name)) {
+	stack[i].type  |= DB_STACK_INT;
+	continue;
+      } 
+      if (c1 == stack[i].name + strlen (stack[i].name)) {
+	// this is a float value
 	continue;
       } 
@@ -44,6 +56,6 @@
 	  code = GetPhotcodebyName (tmpstring);
 	  if (code) {
-	      stack[i].Float = code->code;
-	      stack[i].type  = 'S';
+	      stack[i].IntValue = code->code;
+	      stack[i].type = DB_STACK_INT;
 	      continue;
 	  } 
@@ -60,7 +72,11 @@
       if (j < Nfields) {
 	stack[i].field = j;
-	stack[i].type  = 'F';
+	stack[i].type |= DB_STACK_FIELD;
+	if (fields[j].type == OPIHI_INT) {
+	  stack[i].type |= DB_STACK_INT;
+	}
 	stack[i].name  = NULL;
-	stack[i].Float = 0.0;
+	stack[i].FltValue = 0.0;
+	stack[i].IntValue =   0;
 	continue;
       }
@@ -78,7 +94,11 @@
       }
       stack[i].field = Nfields;
-      stack[i].type  = 'F';
+      stack[i].type |= DB_STACK_FIELD;
+      if (fields[Nfields].type == OPIHI_INT) {
+	stack[i].type |= DB_STACK_INT;
+      }
       stack[i].name  = NULL;
-      stack[i].Float = 0.0;
+      stack[i].FltValue = 0.0; // 'F'
+      stack[i].IntValue =   0; // 'f'
 
       Nfields ++;
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbCmdlineFields.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbCmdlineFields.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbCmdlineFields.c	(revision 20860)
@@ -155,38 +155,36 @@
 
   stack[0][N +  0].name = strcreate (Rname);
-  stack[0][N +  0].type = 'X';
+  stack[0][N +  0].type = DB_STACK_VALUE;
   stack[0][N +  1].name = strfloat (Rmin);
-  stack[0][N +  1].type = 'X';
+  stack[0][N +  1].type = DB_STACK_VALUE;
   stack[0][N +  2].name = strcreate (">");
-  stack[0][N +  2].type = 4;
-  // stack[0][N +  3].name = strcreate ("A");
-  // stack[0][N +  3].type = 3;
+  stack[0][N +  2].type = DB_STACK_COMPARE;
 
   stack[0][N +  3].name = strcreate (Rname);
-  stack[0][N +  3].type = 'X';
+  stack[0][N +  3].type = DB_STACK_VALUE;
   stack[0][N +  4].name = strfloat (Rmax);
-  stack[0][N +  4].type = 'X';
+  stack[0][N +  4].type = DB_STACK_VALUE;
   stack[0][N +  5].name = strcreate ("<");
-  stack[0][N +  5].type = 4;
+  stack[0][N +  5].type = DB_STACK_COMPARE;
   stack[0][N +  6].name = strcreate ("A");
-  stack[0][N +  6].type = 3;
+  stack[0][N +  6].type = DB_STACK_LOGIC;
 
   stack[0][N +  7].name = strcreate (Dname);
-  stack[0][N +  7].type = 'X';
+  stack[0][N +  7].type = DB_STACK_VALUE;
   stack[0][N +  8].name = strfloat (Dmin);
-  stack[0][N +  8].type = 'X';
+  stack[0][N +  8].type = DB_STACK_VALUE;
   stack[0][N +  9].name = strcreate (">");
-  stack[0][N +  9].type = 4;
+  stack[0][N +  9].type = DB_STACK_COMPARE;
   stack[0][N + 10].name = strcreate ("A");
-  stack[0][N + 10].type = 3;
+  stack[0][N + 10].type = DB_STACK_LOGIC;
 
   stack[0][N + 11].name = strcreate (Dname);
-  stack[0][N + 11].type = 'X';
+  stack[0][N + 11].type = DB_STACK_VALUE;
   stack[0][N + 12].name = strfloat (Dmax);
-  stack[0][N + 12].type = 'X';
+  stack[0][N + 12].type = DB_STACK_VALUE;
   stack[0][N + 13].name = strcreate ("<");
-  stack[0][N + 13].type = 4;
+  stack[0][N + 13].type = DB_STACK_COMPARE;
   stack[0][N + 14].name = strcreate ("A");
-  stack[0][N + 14].type = 3;
+  stack[0][N + 14].type = DB_STACK_LOGIC;
 
   if (N == 0) {
@@ -194,5 +192,5 @@
   } else {
     stack[0][N + 15].name = strcreate ("A");
-    stack[0][N + 15].type = 3;
+    stack[0][N + 15].type = DB_STACK_LOGIC;
     N += 16;
   }    
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbFields.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbFields.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbFields.c	(revision 20860)
@@ -107,34 +107,34 @@
   if (!strcasecmp (fieldName, "GLON"))       {
     dbExtractMeasuresInitTransform (COORD_GALACTIC);
-    ESCAPE (MEAS_GLON, MAG_NONE);
+    ESCAPE (MEAS_GLON, MAG_NONE, OPIHI_FLT);
   }
   if (!strcasecmp (fieldName, "GLAT")) {
     dbExtractMeasuresInitTransform (COORD_GALACTIC);
-    ESCAPE (MEAS_GLAT, MAG_NONE);
+    ESCAPE (MEAS_GLAT, MAG_NONE, OPIHI_FLT);
   }
   if (!strcasecmp (fieldName, "GLON:AVE")) {
     dbExtractMeasuresInitTransform (COORD_GALACTIC);
-    ESCAPE (MEAS_GLON_AVE, MAG_NONE);
+    ESCAPE (MEAS_GLON_AVE, MAG_NONE, OPIHI_FLT);
   }
   if (!strcasecmp (fieldName, "GLAT:AVE")) {
     dbExtractMeasuresInitTransform (COORD_GALACTIC);
-    ESCAPE (MEAS_GLAT_AVE, MAG_NONE);
+    ESCAPE (MEAS_GLAT_AVE, MAG_NONE, OPIHI_FLT);
   }
 
   if (!strcasecmp (fieldName, "ELON"))       {
     dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
-    ESCAPE (MEAS_ELON, MAG_NONE);
+    ESCAPE (MEAS_ELON, MAG_NONE, OPIHI_FLT);
   }
   if (!strcasecmp (fieldName, "ELAT")) {
     dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
-    ESCAPE (MEAS_ELAT, MAG_NONE);
+    ESCAPE (MEAS_ELAT, MAG_NONE, OPIHI_FLT);
   }
   if (!strcasecmp (fieldName, "ELON:AVE")) {
     dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
-    ESCAPE (MEAS_ELON_AVE, MAG_NONE);
+    ESCAPE (MEAS_ELON_AVE, MAG_NONE, OPIHI_FLT);
   }
   if (!strcasecmp (fieldName, "ELAT:AVE")) {
     dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
-    ESCAPE (MEAS_ELAT_AVE, MAG_NONE);
+    ESCAPE (MEAS_ELAT_AVE, MAG_NONE, OPIHI_FLT);
   }
 
@@ -218,9 +218,9 @@
   if (!strcasecmp (fieldName, "GLON"))  { 
     dbExtractAveragesInitTransform (COORD_GALACTIC);
-    ESCAPE (AVE_GLON, MAG_NONE);
+    ESCAPE (AVE_GLON, MAG_NONE, OPIHI_FLT);
   }
   if (!strcasecmp (fieldName, "GLAT"))  {
     dbExtractAveragesInitTransform (COORD_GALACTIC);
-    ESCAPE (AVE_GLAT, MAG_NONE);
+    ESCAPE (AVE_GLAT, MAG_NONE, OPIHI_FLT);
   }
 
@@ -229,9 +229,9 @@
   if (!strcasecmp (fieldName, "ELON"))  { 
     dbExtractAveragesInitTransform (COORD_ECLIPTIC);
-    ESCAPE (AVE_ELON, MAG_NONE);
+    ESCAPE (AVE_ELON, MAG_NONE, OPIHI_FLT);
   }
   if (!strcasecmp (fieldName, "ELAT"))  {
     dbExtractAveragesInitTransform (COORD_ECLIPTIC);
-    ESCAPE (AVE_ELAT, MAG_NONE);
+    ESCAPE (AVE_ELAT, MAG_NONE, OPIHI_FLT);
   }
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbRPN.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbRPN.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbRPN.c	(revision 20860)
@@ -21,78 +21,74 @@
     
     /* decide on priority of object */
-    type = 0;
+    type = DB_STACK_NONE;
     /* unary operations */
-    if (!strcmp (argv[i], "abs"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "int"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "exp"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "ten"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "log"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "ln"))     { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "sqrt"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "erf"))    { type = 9; goto gotit; }
-
-    if (!strcmp (argv[i], "sinh"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "cosh"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "asinh"))  { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "acosh"))  { type = 9; goto gotit; }
-
-    if (!strcmp (argv[i], "sin"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "cos"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "tan"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "dsin"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "dcos"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "dtan"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "asin"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "acos"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "atan"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "dasin"))  { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "dacos"))  { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "datan"))  { type = 9; goto gotit; }
-
-    if (!strcmp (argv[i], "lgamma")) { type = 9; goto gotit; }
-
-    if (!strcmp (argv[i], "rnd"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "xramp"))  { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "yramp"))  { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "ramp"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "zero"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "--"))     { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "not"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "isinf"))  { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "isnan"))  { type = 9; goto gotit; }
+    if (!strcmp (argv[i], "abs"))    { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "int"))    { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "exp"))    { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "ten"))    { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "log"))    { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "ln"))     { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "sqrt"))   { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "erf"))    { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "sinh"))   { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "cosh"))   { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "asinh"))  { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "acosh"))  { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "sin"))    { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "cos"))    { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "tan"))    { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "dsin"))   { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "dcos"))   { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "dtan"))   { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "asin"))   { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "acos"))   { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "atan"))   { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "dasin"))  { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "dacos"))  { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "datan"))  { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "lgamma")) { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "rnd"))    { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "xramp"))  { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "yramp"))  { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "ramp"))   { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "zero"))   { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "--"))     { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "not"))    { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "isinf"))  { type = DB_STACK_UNARY; goto gotit; }
+    if (!strcmp (argv[i], "isnan"))  { type = DB_STACK_UNARY; goto gotit; }
 
     /* binary operations */
-    if (!strcmp (argv[i], "^"))      { type = 8; goto gotit; }
-
-    if (!strcmp (argv[i], "@"))      { type = 7; goto gotit; }
-    if (!strcmp (argv[i], "/"))      { type = 7; goto gotit; }
-    if (!strcmp (argv[i], "*"))      { type = 7; goto gotit; }
-    if (!strcmp (argv[i], "%"))      { type = 7; goto gotit; }
-
-    if (!strcmp (argv[i], "+"))      { type = 6; goto gotit; }
-    if (!strcmp (argv[i], "-"))      { type = 6; goto gotit; }
+    if (!strcmp (argv[i], "^"))      { type = DB_STACK_POWER; goto gotit; }
+
+    if (!strcmp (argv[i], "@"))      { type = DB_STACK_MULTIPLY; goto gotit; }
+    if (!strcmp (argv[i], "/"))      { type = DB_STACK_MULTIPLY; goto gotit; }
+    if (!strcmp (argv[i], "*"))      { type = DB_STACK_MULTIPLY; goto gotit; }
+    if (!strcmp (argv[i], "%"))      { type = DB_STACK_MULTIPLY; goto gotit; }
+
+    if (!strcmp (argv[i], "+"))      { type = DB_STACK_SUM; goto gotit; }
+    if (!strcmp (argv[i], "-"))      { type = DB_STACK_SUM; goto gotit; }
 	
-    if (!strcmp (argv[i], "&"))      { type = 5; goto gotit; }
-    if (!strcmp (argv[i], "|"))      { type = 5; goto gotit; }
-
-    if (!strcmp (argv[i], "<"))      { type = 4; goto gotit; }
-    if (!strcmp (argv[i], ">"))      { type = 4; goto gotit; }
-    if (!strcmp (argv[i], "=="))     { type = 4; strcpy (argv[i], "E"); goto gotit; }
-    if (!strcmp (argv[i], "!="))     { type = 4; strcpy (argv[i], "N"); goto gotit; }
-    if (!strcmp (argv[i], "<="))     { type = 4; strcpy (argv[i], "L"); goto gotit; }
-    if (!strcmp (argv[i], ">="))     { type = 4; strcpy (argv[i], "G"); goto gotit; }
-    if (!strcmp (argv[i], ">>"))     { type = 4; strcpy (argv[i], "U"); goto gotit; }
-    if (!strcmp (argv[i], "<<"))     { type = 4; strcpy (argv[i], "D"); goto gotit; }
-
-    if (!strcmp (argv[i], "&&"))     { type = 3; strcpy (argv[i], "A"); goto gotit; }
-    if (!strcmp (argv[i], "||"))     { type = 3; strcpy (argv[i], "O"); goto gotit; }
-
-    if (!strcmp (argv[i], "("))      { type = 2; goto gotit; }
-    if (!strcmp (argv[i], ")"))      { type = 1; goto gotit; }
+    if (!strcmp (argv[i], "&"))      { type = DB_STACK_BITWISE; goto gotit; }
+    if (!strcmp (argv[i], "|"))      { type = DB_STACK_BITWISE; goto gotit; }
+
+    if (!strcmp (argv[i], "<"))      { type = DB_STACK_COMPARE; goto gotit; }
+    if (!strcmp (argv[i], ">"))      { type = DB_STACK_COMPARE; goto gotit; }
+    if (!strcmp (argv[i], "=="))     { type = DB_STACK_COMPARE; strcpy (argv[i], "E"); goto gotit; }
+    if (!strcmp (argv[i], "!="))     { type = DB_STACK_COMPARE; strcpy (argv[i], "N"); goto gotit; }
+    if (!strcmp (argv[i], "<="))     { type = DB_STACK_COMPARE; strcpy (argv[i], "L"); goto gotit; }
+    if (!strcmp (argv[i], ">="))     { type = DB_STACK_COMPARE; strcpy (argv[i], "G"); goto gotit; }
+    if (!strcmp (argv[i], ">>"))     { type = DB_STACK_COMPARE; strcpy (argv[i], "U"); goto gotit; }
+    if (!strcmp (argv[i], "<<"))     { type = DB_STACK_COMPARE; strcpy (argv[i], "D"); goto gotit; }
+
+    if (!strcmp (argv[i], "&&"))     { type = DB_STACK_LOGIC; strcpy (argv[i], "A"); goto gotit; }
+    if (!strcmp (argv[i], "||"))     { type = DB_STACK_LOGIC; strcpy (argv[i], "O"); goto gotit; }
+
+    if (!strcmp (argv[i], "("))      { type = DB_STACK_OPEN_PAR; goto gotit; }
+    if (!strcmp (argv[i], ")"))      { type = DB_STACK_CLOSE_PAR; goto gotit; }
 
   gotit:
     /* choose how to deal with object */
     switch (type) {
-      case 8:  /* exponentiation: 2^2^3 = 64 != 256 (precedence is right-to-left, not left-to-right!) */
+      case DB_STACK_POWER:  /* exponentiation: 2^2^3 = 64 != 256 (precedence is right-to-left, not left-to-right!) */
 	/* pop previous, higher operators from OP stack to stack */
 	for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type > type); j--) {
@@ -107,10 +103,10 @@
 	Nop_stack ++;
 	break;
-      case 9: /* unary OPs */
-      case 7: /* binary OPs */
-      case 6:
-      case 5: 
-      case 4: 
-      case 3: 
+      case DB_STACK_UNARY: /* unary OPs */
+      case DB_STACK_MULTIPLY: /* binary OPs */
+      case DB_STACK_SUM:
+      case DB_STACK_BITWISE: 
+      case DB_STACK_COMPARE: 
+      case DB_STACK_LOGIC: 
 	/* pop previous, higher or equal operators from OP stack to stack */
 	for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type >= type); j--) {
@@ -125,5 +121,5 @@
 	Nop_stack ++;
 	break;
-      case 2:  
+      case DB_STACK_OPEN_PAR:  
 	/* push operator on OP stack */
 	op_stack[Nop_stack].name = strcreate (argv[i]);
@@ -131,7 +127,7 @@
 	Nop_stack ++;
 	break;
-      case 1: 
+      case DB_STACK_CLOSE_PAR: 
 	/* pop rest of operators from OP stack to stack, looking for '(' */
-	for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != 2); j--) {
+	for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != DB_STACK_OPEN_PAR); j--) {
 	  stack[Nstack] = op_stack[j];
 	  op_stack[j].name = NULL;
@@ -139,5 +135,5 @@
 	  Nop_stack --;
 	}
-	if ((j == -1) || (op_stack[j].type != 2)) {
+	if ((j == -1) || (op_stack[j].type != DB_STACK_OPEN_PAR)) {
 	  push_error ("syntax error: mismatched parenthesis");
 	  Nstack = 0;
@@ -150,5 +146,5 @@
 	/* value of 'X' is used as sentinel until we sort out values */
 	stack[Nstack].name = strcreate (argv[i]);
-	stack[Nstack].type = 'X';
+	stack[Nstack].type = DB_STACK_VALUE;
 	Nstack ++;
 	break;
@@ -156,7 +152,7 @@
   }
 
-  /* dump remaining operators on stack, checking for ')' */
+  /* dump remaining operators on stack, checking for '(' */
   for (j = Nop_stack - 1; j >= 0; j--) {
-    if (op_stack[j].type == 2) {
+    if (op_stack[j].type == DB_STACK_OPEN_PAR) {
       push_error ("syntax error: mismatched parenthesis");
       Nstack = 0;
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbStackMath.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbStackMath.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbStackMath.c	(revision 20860)
@@ -4,143 +4,133 @@
 static int NallocUnary = 0;
 
-dbStack *dbBinary (dbStack *V1, dbStack *V2, char *op, float *fields) {
+dbStack *dbBinary (dbStack *V1, dbStack *V2, char *op, dbValue *fields) {
 
-  int N;
-  float M1, M2;
   dbStack *OUT;
   
-  if (V1->type == 'F') {
-    N = V1->field;
-    M1 = fields[N];
-  } else {
-    M1 = V1->Float;
-  }
-  
-  if (V2->type == 'F') {
-    N = V2->field;
-    M2 = fields[N];
-  } else {
-    M2 = V2->Float;
+# define SS_FUNC(OP) {							\
+    if (!(V1->type & DB_STACK_INT) && !(V2->type & DB_STACK_INT)) {	\
+      opihi_flt M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Flt : V1->FltValue; \
+      opihi_flt M2 = (V2->type & DB_STACK_FIELD) ? fields[V2->field].Flt : V2->FltValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;			\
+      OUT[0].FltValue = OP;						\
+      break;								\
+    }									\
+    if ((V1->type & DB_STACK_INT) && !(V2->type & DB_STACK_INT)) {	\
+      opihi_int M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Int : V1->IntValue; \
+      opihi_flt M2 = (V2->type & DB_STACK_FIELD) ? fields[V2->field].Flt : V2->FltValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;			\
+      OUT[0].FltValue = OP;						\
+      break;								\
+    }									\
+    if (!(V1->type & DB_STACK_INT) && (V2->type & DB_STACK_INT)) {	\
+      opihi_flt M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Flt : V1->FltValue; \
+      opihi_int M2 = (V2->type & DB_STACK_FIELD) ? fields[V2->field].Int : V2->IntValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;			\
+      OUT[0].FltValue = OP;						\
+      break;								\
+    }									\
+    if ((V1->type & DB_STACK_INT) && (V2->type & DB_STACK_INT)) {	\
+      opihi_int M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Int : V1->IntValue; \
+      opihi_int M2 = (V2->type & DB_STACK_FIELD) ? fields[V2->field].Int : V2->IntValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP | DB_STACK_INT;	\
+      OUT[0].IntValue = OP;						\
+      break;								\
+    }									\
   }
 
   NallocBinary ++;
   ALLOCATE (OUT, dbStack, 1);
-  OUT->type = 'T';
   OUT->name = NULL;
 
-  // use an enum for the op...
+  // XXX use an enum for the op...
   switch (op[0]) { 
-  case '+': 
-    OUT->Float = M1 + M2;
-    break; 
-  case '-': 
-    OUT->Float = M1 - M2;
-    break; 
-  case '*': 
-    OUT->Float = M1 * M2;
-    break; 
-  case '/': 
-    OUT->Float = M1 / M2;
-    break; 
-  case '%': 
-    OUT->Float = (int) M1 % (int) M2;
-    break; 
-  case 0x5e: 
-    OUT->Float = pow (M1, M2);
-    break; 
-  case 'D': 
-    OUT->Float = MIN (M1, M2);
-    break; 
-  case 'U': 
-    OUT->Float = MAX (M1, M2);
-    break; 
-  case '<': 
-    OUT->Float = (M1 < M2) ? 1 : 0;
-    break; 
-  case '>': 
-    OUT->Float = (M1 > M2) ? 1 : 0;
-    break; 
-  case '&': 
-    OUT->Float = ((int)M1 & (int)M2);
-    break; 
-  case '|': 
-    OUT->Float = ((int)M1 | (int)M2);
-    break; 
-  case 'E': 
-    OUT->Float = (M1 == M2) ? 1 : 0;
-    break; 
-  case 'N': 
-    OUT->Float = (M1 != M2) ? 1 : 0;
-    break; 
-  case 'L': 
-    OUT->Float = (M1 <= M2) ? 1 : 0;
-    break; 
-  case 'G': 
-    OUT->Float = (M1 >= M2) ? 1 : 0;
-    break; 
-  case 'A': 
-    OUT->Float = (M1 && M2) ? 1 : 0;
-    break; 
-  case 'O': 
-    OUT->Float = (M1 || M2) ? 1 : 0;
-    break; 
+    case '+': SS_FUNC(M1 + M2);
+    case '-': SS_FUNC(M1 - M2);
+    case '*': SS_FUNC(M1 * M2);
+    case '/': SS_FUNC(M1 / M2);
+    case '%': SS_FUNC((int) M1 % (int) M2);
+    case '^': SS_FUNC(pow (M1, M2));
+    case 'D': SS_FUNC(MIN (M1, M2));
+    case 'U': SS_FUNC(MAX (M1, M2));
+    case '<': SS_FUNC((M1 < M2) ? 1 : 0);
+    case '>': SS_FUNC((M1 > M2) ? 1 : 0);
+    case '&': SS_FUNC(((int)M1 & (int)M2));
+    case '|': SS_FUNC(((int)M1 | (int)M2));
+    case 'E': SS_FUNC((M1 == M2) ? 1 : 0);
+    case 'N': SS_FUNC((M1 != M2) ? 1 : 0);
+    case 'L': SS_FUNC((M1 <= M2) ? 1 : 0);
+    case 'G': SS_FUNC((M1 >= M2) ? 1 : 0);
+    case 'A': SS_FUNC((M1 && M2) ? 1 : 0);
+    case 'O': SS_FUNC((M1 || M2) ? 1 : 0);
   default:
     return (NULL);
   }
-
+# undef SS_FUNC
+  
   return (OUT);
 }
 
-dbStack *dbUnary (dbStack *V1, char *op, float *fields) {
+dbStack *dbUnary (dbStack *V1, char *op, dbValue *fields) {
 
-  int N;
-  float M1;
   dbStack *OUT;
+  
+# define S_FUNC(OP,FTYPE) {						\
+    if (!(V1->type & DB_STACK_INT)) {					\
+      opihi_flt M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Flt : V1->FltValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;			\
+      OUT[0].FltValue = OP;						\
+      return (OUT);							\
+    }									\
+    if ((FTYPE != DB_STACK_INT) && (V1->type & DB_STACK_INT)) {		\
+      opihi_int M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Int : V1->IntValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;			\
+      OUT[0].FltValue = OP;						\
+      return (OUT);							\
+    }									\
+    if ((FTYPE == DB_STACK_INT) && (V1->type & DB_STACK_INT)) {		\
+      opihi_int M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Int : V1->IntValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP | DB_STACK_INT;	\
+      OUT[0].IntValue = OP;						\
+      return (OUT);							\
+    }									\
+  }
 
-  if (V1->type == 'F') {
-    N = V1->field;
-    M1 = fields[N];
-  } else {
-    M1 = V1->Float;
-  }
-  
   NallocUnary ++;
   ALLOCATE (OUT, dbStack, 1);
-  OUT->type = 'T';
   OUT->name = NULL;
 
-  if (!strcmp (op, "="))      {   OUT->Float = M1;                 }
-  if (!strcmp (op, "abs"))    {   OUT->Float = fabs(M1);           }
-  if (!strcmp (op, "int"))    {   OUT->Float = (float)(int)(M1);   }
-  if (!strcmp (op, "exp"))    {   OUT->Float = exp (M1);           }
-  if (!strcmp (op, "ten"))    {   OUT->Float = pow (10.0,M1);      }
-  if (!strcmp (op, "log"))    {   OUT->Float = log10 (M1);         }
-  if (!strcmp (op, "ln"))     {   OUT->Float = log (M1);           }
-  if (!strcmp (op, "sqrt"))   {   OUT->Float = sqrt (M1);          }
-  if (!strcmp (op, "erf"))    {   OUT->Float = erf (M1);           }
-			      			      
-  if (!strcmp (op, "sinh"))   {   OUT->Float = sinh (M1);          }
-  if (!strcmp (op, "cosh"))   {   OUT->Float = cosh (M1);          }
-  if (!strcmp (op, "asinh"))  {   OUT->Float = asinh (M1);         }
-  if (!strcmp (op, "acosh"))  {   OUT->Float = acosh (M1);         }
-  if (!strcmp (op, "lgamma")) {   OUT->Float = lgamma (M1);        }
+  if (!strcmp (op, "="))      S_FUNC(M1,0);
+  if (!strcmp (op, "abs"))    S_FUNC(fabs(M1),0);
+  if (!strcmp (op, "int"))    S_FUNC((int)(M1),DB_STACK_INT);
+  if (!strcmp (op, "exp"))    S_FUNC(exp (M1),0);
+  if (!strcmp (op, "ten"))    S_FUNC(pow (10.0,M1),0);
+  if (!strcmp (op, "log"))    S_FUNC(log10 (M1),0);
+  if (!strcmp (op, "ln"))     S_FUNC(log (M1),0);
+  if (!strcmp (op, "sqrt"))   S_FUNC(sqrt (M1),0);
+  if (!strcmp (op, "erf"))    S_FUNC(erf (M1),0);
 
-  if (!strcmp (op, "sin"))    {   OUT->Float = sin (M1);           }
-  if (!strcmp (op, "cos"))    {   OUT->Float = cos (M1);           }
-  if (!strcmp (op, "tan"))    {   OUT->Float = tan (M1);           }
-  if (!strcmp (op, "dsin"))   {   OUT->Float = sin (M1*RAD_DEG);   }
-  if (!strcmp (op, "dcos"))   {   OUT->Float = cos (M1*RAD_DEG);   }
-  if (!strcmp (op, "dtan"))   {   OUT->Float = tan (M1*RAD_DEG);   }
-  if (!strcmp (op, "asin"))   {   OUT->Float = asin (M1);          }
-  if (!strcmp (op, "acos"))   {   OUT->Float = acos (M1);          }
-  if (!strcmp (op, "atan"))   {   OUT->Float = atan (M1);          }
-  if (!strcmp (op, "dasin"))  {   OUT->Float = asin (M1)*DEG_RAD;  }
-  if (!strcmp (op, "dacos"))  {   OUT->Float = acos (M1)*DEG_RAD;  }
-  if (!strcmp (op, "datan"))  {   OUT->Float = atan (M1)*DEG_RAD;  }
-  if (!strcmp (op, "rnd"))    {   OUT->Float = drand48();          }
-  if (!strcmp (op, "not"))    {   OUT->Float = !(M1);              }
-  if (!strcmp (op, "--"))     {   OUT->Float = - (M1);             }
-  if (!strcmp (op, "isinf"))  {   OUT->Float = !finite(M1);        }
-  if (!strcmp (op, "isnan"))  {   OUT->Float = isnan(M1);          } 
+  if (!strcmp (op, "sinh"))   S_FUNC(sinh (M1),0);
+  if (!strcmp (op, "cosh"))   S_FUNC(cosh (M1),0);
+  if (!strcmp (op, "asinh"))  S_FUNC(asinh (M1),0);
+  if (!strcmp (op, "acosh"))  S_FUNC(acosh (M1),0);
+  if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1),0);
+
+  if (!strcmp (op, "sin"))    S_FUNC(sin (M1),0);
+  if (!strcmp (op, "cos"))    S_FUNC(cos (M1),0);
+  if (!strcmp (op, "tan"))    S_FUNC(tan (M1),0);
+  if (!strcmp (op, "dsin"))   S_FUNC(sin (M1*RAD_DEG),0);
+  if (!strcmp (op, "dcos"))   S_FUNC(cos (M1*RAD_DEG),0);
+  if (!strcmp (op, "dtan"))   S_FUNC(tan (M1*RAD_DEG),0);
+  if (!strcmp (op, "asin"))   S_FUNC(asin (M1),0);
+  if (!strcmp (op, "acos"))   S_FUNC(acos (M1),0);
+  if (!strcmp (op, "atan"))   S_FUNC(atan (M1),0);
+  if (!strcmp (op, "dasin"))  S_FUNC(asin (M1)*DEG_RAD,0);
+  if (!strcmp (op, "dacos"))  S_FUNC(acos (M1)*DEG_RAD,0);
+  if (!strcmp (op, "datan"))  S_FUNC(atan (M1)*DEG_RAD,0);
+  if (!strcmp (op, "rnd"))    S_FUNC(M1*0.0 + drand48(),0);
+  if (!strcmp (op, "not"))    S_FUNC(!(M1),DB_STACK_INT);
+  if (!strcmp (op, "--"))     S_FUNC(- (M1),DB_STACK_INT);
+  if (!strcmp (op, "isinf"))  S_FUNC(!finite(M1),DB_STACK_INT);
+  if (!strcmp (op, "isnan"))  S_FUNC(isnan(M1),DB_STACK_INT);
 
   return (OUT);
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbStackOps.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbStackOps.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbStackOps.c	(revision 20860)
@@ -2,5 +2,5 @@
 
 void dbInitStack (dbStack *stack) {
-  stack[0].type   = 0;
+  stack[0].type   = DB_STACK_NONE;
   stack[0].name   = NULL;
 }
@@ -34,5 +34,5 @@
 void dbFreeTempEntry (dbStack *stack) {
 
-  if (stack->type != 'T') return;
+  if (stack->type & DB_STACK_TEMP) return;
 
   if (stack[0].name != NULL)  free (stack[0].name);
Index: anches/eam_branch_20081124/Ohana/src/opihi/dvo/db_check_stack.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/db_check_stack.c	(revision 20859)
+++ 	(revision )
@@ -1,54 +1,0 @@
-# include "opihi.h"
-
-int db_check_stack (dvoStack *stack, int Nstack, int table, dvoField *fields, int *Nfields) {
-
-  int i, Nx, Ny, Nv, size;
-  char *c;
-
-  NFIELDS = *Nfields + 10;
-  REALLOCATE (fields, dvoField, NFIELDS);
-
-  for (i = 0; i < Nstack; i++) {
-    if (stack[i].type == 'X') {
-
-      /** if this is a number, put it on the list of scalers and move on **/
-      stack[i].Float = strtod (stack[i].name, &c);
-      if (c == stack[i].name + strlen (stack[i].name)) {
-	stack[i].type  = 'S';
-	continue;
-      } 
-
-      // this must be a field : is it already in the list?
-      for (j = 0; (j < *Nfields) && strcasecmp (stack[i].name, fields[j].name); j++);
-      if (j < *Nfields) {
-	stack[i].field = j;
-	stack[i].type  = 'F';
-	continue;
-      }
-
-      // this must be a field : is it a valid name?
-      if (table == DVO_TABLE_MEASURE) {
-	status = ParseMeasureField (&fields[*Nfields], stack[i].name);
-      } 
-      if (table == DVO_TABLE_AVERAGE) {
-	status = ParseAverageField (&fields[*Nfields], stack[i].name);
-      } 
-      if (!status) {
-	gprint (GP_ERR, "unknown database field %s\n", stack[i].name);
-	return (FALSE);
-      }
-      stack[i].field = *Nfields;
-      stack[i].type  = 'F';
-
-      *Nfields ++;
-      CHECK_REALLOCATE (fields, dvoField, NFIELDS, *Nfields, 10);
-    }
-  }
-  return (TRUE);
-}
-
-/* check stack identifies the data elements as plain scalars or table fields
-   operators have already been identified.  
-   check stack returns the total stack dimensionality (0,1,2)
-   on error, check stack returns FALSE
-*/
Index: anches/eam_branch_20081124/Ohana/src/opihi/dvo/db_convert_to_RPN.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/db_convert_to_RPN.c	(revision 20859)
+++ 	(revision )
@@ -1,210 +1,0 @@
-# include "opihi.h"
-# define DUMPSTACK 0
-
-dvoStack *convert_to_RPN (int argc, char **argv, int *nstack) {
-  
-  int type, Nx, Ny;
-  int i, j, Nstack, Nop_stack, NSTACK;
-  dvoStack *stack, *op_stack;
-
-  /* max total stack size is argc, though should be less, this is safe */
-  NSTACK = argc + 5;
-  ALLOCATE (stack, dvoStack, NSTACK);
-  ALLOCATE (op_stack, dvoStack, NSTACK);
-  for (i = 0; i < NSTACK; i++) {
-    init_stack (&stack[i]);
-    init_stack (&op_stack[i]);
-  }
-  
-  Nx = Ny = Nstack = Nop_stack = 0;
-  for (i = 0; i < argc; i++) {
-    
-    /* decide on priority of object */
-    type = 0;
-    /* unary operations */
-    if (!strcmp (argv[i], "abs"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "int"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "exp"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "ten"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "log"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "ln"))     { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "sqrt"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "erf"))    { type = 9; goto gotit; }
-
-    if (!strcmp (argv[i], "sinh"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "cosh"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "asinh"))  { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "acosh"))  { type = 9; goto gotit; }
-
-    if (!strcmp (argv[i], "sin"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "cos"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "tan"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "dsin"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "dcos"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "dtan"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "asin"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "acos"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "atan"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "dasin"))  { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "dacos"))  { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "datan"))  { type = 9; goto gotit; }
-
-    if (!strcmp (argv[i], "lgamma")) { type = 9; goto gotit; }
-
-    if (!strcmp (argv[i], "rnd"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "xramp"))  { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "yramp"))  { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "ramp"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "zero"))   { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "--"))     { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "not"))    { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "isinf"))  { type = 9; goto gotit; }
-    if (!strcmp (argv[i], "isnan"))  { type = 9; goto gotit; }
-
-    /* binary operations */
-    if (!strcmp (argv[i], "^"))      { type = 8; goto gotit; }
-
-    if (!strcmp (argv[i], "@"))      { type = 7; goto gotit; }
-    if (!strcmp (argv[i], "/"))      { type = 7; goto gotit; }
-    if (!strcmp (argv[i], "*"))      { type = 7; goto gotit; }
-    if (!strcmp (argv[i], "%"))      { type = 7; goto gotit; }
-
-    if (!strcmp (argv[i], "+"))      { type = 6; goto gotit; }
-    if (!strcmp (argv[i], "-"))      { type = 6; goto gotit; }
-	
-    if (!strcmp (argv[i], "&"))      { type = 5; goto gotit; }
-    if (!strcmp (argv[i], "|"))      { type = 5; goto gotit; }
-
-    if (!strcmp (argv[i], "<"))      { type = 4; goto gotit; }
-    if (!strcmp (argv[i], ">"))      { type = 4; goto gotit; }
-    if (!strcmp (argv[i], "=="))     { type = 4; strcpy (argv[i], "E"); goto gotit; }
-    if (!strcmp (argv[i], "!="))     { type = 4; strcpy (argv[i], "N"); goto gotit; }
-    if (!strcmp (argv[i], "<="))     { type = 4; strcpy (argv[i], "L"); goto gotit; }
-    if (!strcmp (argv[i], ">="))     { type = 4; strcpy (argv[i], "G"); goto gotit; }
-    if (!strcmp (argv[i], ">>"))     { type = 4; strcpy (argv[i], "U"); goto gotit; }
-    if (!strcmp (argv[i], "<<"))     { type = 4; strcpy (argv[i], "D"); goto gotit; }
-
-    if (!strcmp (argv[i], "&&"))     { type = 3; strcpy (argv[i], "A"); goto gotit; }
-    if (!strcmp (argv[i], "||"))     { type = 3; strcpy (argv[i], "O"); goto gotit; }
-
-    if (!strcmp (argv[i], "("))      { type = 2; goto gotit; }
-    if (!strcmp (argv[i], ")"))      { type = 1; goto gotit; }
-
-  gotit:
-    /* choose how to deal with object */
-    switch (type) {
-      case 8:  /* exponentiation: 2^2^3 = 64 != 256 (precedence is right-to-left, not left-to-right!) */
-	/* pop previous, higher operators from OP stack to stack */
-	for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type > type); j--) {
-	  strcpy (stack[Nstack].name, op_stack[j].name);
-	  stack[Nstack].type = op_stack[j].type;
-	  Nstack ++;
-	  Nop_stack --;
-	}
-	/* push operator on OP stack */
-	strcpy (op_stack[Nop_stack].name, argv[i]);
-	op_stack[Nop_stack].type = type;
-	Nop_stack ++;
-	break;
-      case 9: /* unary OPs */
-      case 7: /* binary OPs */
-      case 6:
-      case 5: 
-      case 4: 
-      case 3: 
-	/* pop previous, higher or equal operators from OP stack to stack */
-	for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type >= type); j--) {
-	  strcpy (stack[Nstack].name, op_stack[j].name);
-	  stack[Nstack].type = op_stack[j].type;
-	  Nstack ++;
-	  Nop_stack --;
-	}
-	/* push operator on OP stack */
-	strcpy (op_stack[Nop_stack].name, argv[i]);
-	op_stack[Nop_stack].type = type;
-	Nop_stack ++;
-	break;
-      case 2:  
-	/* push operator on OP stack */
-	strcpy (op_stack[Nop_stack].name, argv[i]);
-	op_stack[Nop_stack].type = type;
-	Nop_stack ++;
-	break;
-      case 1: 
-	/* pop rest of operators from OP stack to stack, looking for '(' */
-	for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != 2); j--) {
-	  strcpy (stack[Nstack].name, op_stack[j].name);
-	  stack[Nstack].type = op_stack[j].type;
-	  Nstack ++;
-	  Nop_stack --;
-	}
-	if ((j == -1) || (op_stack[j].type != 2)) {
-	  push_error ("syntax error: mismatched parenthesis");
-	  Nstack = 0;
-	  goto cleanup;
-	}
-	Nop_stack --;
-	break;
-      case 0:
-	/* place the value (number or vector/matrix name) on stack */
-	/* value of 'X' is used as sentinel until we sort out values */
-	strcpy (stack[Nstack].name, argv[i]);
-	stack[Nstack].type = 'X';
-	Nstack ++;
-	break;
-    }
-  }
-
-  /* dump remaining operators on stack, checking for ')' */
-  for (j = Nop_stack - 1; j >= 0; j--) {
-    if (op_stack[j].type == 2) {
-      push_error ("syntax error: mismatched parenthesis");
-      Nstack = 0;
-      goto cleanup;
-    }
-    strcpy (stack[Nstack].name, op_stack[j].name);
-    stack[Nstack].type = op_stack[j].type;
-    Nstack ++;
-  }
-
-cleanup: 
-  /*** free up unused stack space ***/
-  clean_stack (op_stack, NSTACK);
-  free (op_stack);
-  clean_stack (&stack[Nstack], NSTACK - Nstack);
-  REALLOCATE (stack, dvoStack, MAX (Nstack, 1));
-  *nstack = Nstack;
-
-  for (i = 0; i < argc; i++) {
-    free (argv[i]);
-  }
-  free (argv);
-
-# if (DUMPSTACK)
-  for (i = 0; i < Nstack; i++) {
-    gprint (GP_ERR, "%s ", stack[i].name);
-  }
-  if (Nstack > 0) gprint (GP_ERR, "\n");
-  for (i = 0; i < Nstack; i++) {
-    gprint (GP_ERR, "%d ", stack[i].type);
-  }
-  if (Nstack > 0) gprint (GP_ERR, "\n");
-# endif
-
-  return (stack);
-
-}
-
-/* here are the rules for parsing a math AOL line to RPN:
-
-1) if object is a number, push on stack
-2) if object is a third order operand (exp, sin, cos), push on op stack
-3) if object is an open paren, push on op stack,
-4) if object is a second order operand, push on stack
-5) if object is a first order operand, pop all second order operands from stack 
-until paren, push on stack
-6) if object is an end paren, pop all objects from stack until paren, 
-pop next stack, if third order op
-7) if end of line, pop all remaining objects, second order first, etc.
-   
-*/
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/fitcolors.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/fitcolors.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/fitcolors.c	(revision 20860)
@@ -318,5 +318,5 @@
 	graphdata.color = KapaColorByName ("red");
 
-	KapaPrepPlot (kapa, 11, graphmode);
+	KapaPrepPlot (kapa, 11, &graphdata);
 	KapaPlotVector (kapa, 11, colorFit, "x");
 	KapaPlotVector (kapa, 11, deltaFit, "y");
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/images.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/images.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/images.c	(revision 20860)
@@ -113,6 +113,6 @@
 
   npts = NPTS = 200;
-  ResetVector (Xvec, OPIHI_FLT, NPTS);
-  ResetVector (Yvec, OPIHI_FLT, NPTS);
+  ResetVector (&Xvec, OPIHI_FLT, NPTS);
+  ResetVector (&Yvec, OPIHI_FLT, NPTS);
 
   ALLOCATE (plist, int, NPTS);
@@ -281,5 +281,5 @@
     graphmode.ptype = 100; /* connect pairs of points */
     graphmode.etype = 0;
-    PlotVectorPair (kapa, Xvec, Yvec, &graphmode);
+    PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode);
   }
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imbox.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imbox.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imbox.c	(revision 20860)
@@ -36,6 +36,6 @@
   
   /* project this image to screen display coords */
-  ResetVector (Xvec, OPIHI_FLT, 8);
-  ResetVector (Yvec, OPIHI_FLT, 8);
+  ResetVector (&Xvec, OPIHI_FLT, 8);
+  ResetVector (&Yvec, OPIHI_FLT, 8);
 
   while (gfits_fread_header (f, &header)) {
@@ -104,5 +104,5 @@
       graphmode.ptype = 100; /* connect pairs of points */
       graphmode.etype = 0;
-      PlotVectorPair (kapa, Xvec, Yvec, &graphmode);
+      PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode);
     }
   skip:
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imdense.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imdense.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imdense.c	(revision 20860)
@@ -32,6 +32,6 @@
   N = 0;
   NPTS = 200;
-  ResetVector (Xvec, OPIHI_FLT, Npts);
-  ResetVector (Yvec, OPIHI_FLT, Npts);
+  ResetVector (&Xvec, OPIHI_FLT, NPTS);
+  ResetVector (&Yvec, OPIHI_FLT, NPTS);
 
   for (i = 0; i < Nimage; i++) {
@@ -64,5 +64,5 @@
     graphmode.style = 2; /* points */
     graphmode.etype = 0;
-    PlotVectorPair (kapa, Xvec, Yvec, &graphmode);
+    PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode);
   }
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imstats.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imstats.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imstats.c	(revision 20860)
@@ -33,6 +33,6 @@
 
   /* assign vector values */
-  ResetVector (Xvec, OPIHI_FLT, Nimage);
-  ResetVector (Yvec, OPIHI_FLT, Nimage);
+  ResetVector (&Xvec, OPIHI_FLT, Nimage);
+  ResetVector (&Yvec, OPIHI_FLT, Nimage);
 
   gprint (GP_LOG, "seq  ra (J2000) dec    time (s)   Nstars\n");
@@ -53,5 +53,5 @@
   graphmode.style = 2;
   graphmode.etype = 0;
-  PlotVectorPair (kapa, Xvec, Yvec, &graphmode);
+  PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode);
   
   free (Xvec.elements.Flt);
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/lcurve.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/lcurve.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/lcurve.c	(revision 20860)
@@ -104,9 +104,9 @@
   N = 0;
   NPTS = 100;
-  ResetVector (Xvec, OPIHI_FLT, NPTS);
-  ResetVector (Yvec, OPIHI_FLT, NPTS);
+  ResetVector (&Xvec, OPIHI_FLT, NPTS);
+  ResetVector (&Yvec, OPIHI_FLT, NPTS);
   dYvec.elements.Flt = NULL;
   if (ErrorBars) {   
-    ResetVector (Yvec, OPIHI_FLT, NPTS);
+    ResetVector (&dYvec, OPIHI_FLT, NPTS);
   }
 
@@ -157,7 +157,7 @@
 
   if (ErrorBars) {
-    PlotVectorPairErrors (kapa, Xvec, Yvec, dYvec, &graphmode);
+    PlotVectorPairErrors (kapa, &Xvec, &Yvec, &dYvec, &graphmode);
   } else {
-    PlotVectorPair (kapa, Xvec, Yvec, &graphmode);
+    PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode);
   }
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/lightcurve.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/lightcurve.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/lightcurve.c	(revision 20860)
@@ -87,7 +87,7 @@
   N = 0;
   NPTS = 100;
-  ResetVector (tvec, OPIHI_FLT, Npts);
-  ResetVector (mvec, OPIHI_FLT, Npts);
-  ResetVector (dmvec, OPIHI_FLT, Npts);
+  ResetVector (tvec, OPIHI_FLT, NPTS);
+  ResetVector (mvec, OPIHI_FLT, NPTS);
+  ResetVector (dmvec, OPIHI_FLT, NPTS);
   
   GetTimeFormat (&TimeReference, &TimeFormat);
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/mextract.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/mextract.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/mextract.c	(revision 20860)
@@ -88,4 +88,6 @@
 
   /* create storage vector */
+  Npts = 0;
+  NPTS = 1000;
   ALLOCATE (values, dbValue, Nfields);
   ALLOCATE (vec, Vector *, Nreturn);
@@ -97,9 +99,6 @@
     }
     if ((vec[i] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) goto escape;
-    ResetVector (vec[i], fields[i].type, NNN);
-  }
-
-  Npts = 0;
-  NPTS = 1;
+    ResetVector (vec[i], fields[i].type, NPTS);
+  }
 
   // grab data from all selected sky regions
@@ -166,6 +165,5 @@
 
   for (n = 0; n < Nreturn; n++) {
-    vec[n][0].Nelements = Npts;
-    REALLOCATE (vec[n][0].elements.Flt, opihi_flt, MAX(1,Npts));
+    ResetVector (vec[n], fields[n].type, MAX(1,Npts));
   }
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/paverage.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/paverage.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/paverage.c	(revision 20860)
@@ -144,5 +144,5 @@
       }
       if ((Npts > NCHUNK) || (Nloaded >= 25)) {
-	KapaPrepPlot (kapa, Npts, graphmode);
+	KapaPrepPlot (kapa, Npts, &graphmode);
 	KapaPlotVector (kapa, Npts, Xvec, "x");
 	KapaPlotVector (kapa, Npts, Yvec, "y");
@@ -156,5 +156,5 @@
   }
   if (Npts > 0) {
-    KapaPrepPlot (kapa, Npts, graphmode);
+    KapaPrepPlot (kapa, Npts, &graphmode);
     KapaPlotVector (kapa, Npts, Xvec, "x");
     KapaPlotVector (kapa, Npts, Yvec, "y");
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/pmeasure.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/pmeasure.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/pmeasure.c	(revision 20860)
@@ -229,5 +229,5 @@
 	}
 	if ((Npts > NCHUNK) || (Nloaded >= 25)) {
-	  KapaPrepPlot (kapa, Npts, graphmode);
+	  KapaPrepPlot (kapa, Npts, &graphmode);
 	  KapaPlotVector (kapa, Npts, Xvec, "x");
 	  KapaPlotVector (kapa, Npts, Yvec, "y");
@@ -242,5 +242,5 @@
   }
   if (Npts > 0) {
-    KapaPrepPlot (kapa, Npts, graphmode);
+    KapaPrepPlot (kapa, Npts, &graphmode);
     KapaPlotVector (kapa, Npts, Xvec, "x");
     KapaPlotVector (kapa, Npts, Yvec, "y");
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/procks.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/procks.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/procks.c	(revision 20860)
@@ -95,6 +95,6 @@
 
   /* data has been loaded, get ready to plot it */
-  ResetVector (Xvec, OPIHI_FLT, 3*Nrocks);
-  ResetVector (Yvec, OPIHI_FLT, 3*Nrocks);
+  ResetVector (&Xvec, OPIHI_FLT, 3*Nrocks);
+  ResetVector (&Yvec, OPIHI_FLT, 3*Nrocks);
   
   /* project stars to screen display coords */
@@ -113,5 +113,5 @@
   graphmode.style = 2; /* set style to points */
   graphmode.etype = 0; /* no errorbars */
-  PlotVectorPair (kapa, Xvec, Yvec, &graphmode);
+  PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode);
 
   /* now plot vectors between two extrema */
@@ -146,5 +146,5 @@
   graphmode.etype = 0; /* no errorbars */
 
-  PlotVectorPair (kapa, Xvec, Yvec, &graphmode);
+  PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode);
 
   free (Xvec.elements.Flt);
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/showtile.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/showtile.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/showtile.c	(revision 20860)
@@ -22,6 +22,6 @@
   N = 0;
   NPTS = 200;
-  ResetVector (Xvec, OPIHI_FLT, NPTS);
-  ResetVector (Yvec, OPIHI_FLT, NPTS);
+  ResetVector (&Xvec, OPIHI_FLT, NPTS);
+  ResetVector (&Yvec, OPIHI_FLT, NPTS);
 
   /* starting position */
@@ -86,5 +86,5 @@
     graphmode.ptype = 100; /* connect pairs of points */
     graphmode.etype = 0;
-    PlotVectorPair (kapa, Xvec, Yvec, &graphmode);
+    PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode);
   }
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/simage.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/simage.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/simage.c	(revision 20860)
@@ -92,7 +92,7 @@
 
   /* set up storage buffers */
-  ResetVector (Xvec, OPIHI_FLT, Ntars);
-  ResetVector (Yvec, OPIHI_FLT, Ntars);
-  ResetVector (Zvec, OPIHI_FLT, Ntars);
+  ResetVector (&Xvec, OPIHI_FLT, Nstars);
+  ResetVector (&Yvec, OPIHI_FLT, Nstars);
+  ResetVector (&Zvec, OPIHI_FLT, Nstars);
   ALLOCATE (buffer, char, (BLOCK*BYTES_STAR));
 
@@ -152,5 +152,5 @@
   Npts = Xvec.Nelements;
 
-  PlotVectorTriplet (kapa, Xvec, Yvec, Zvec, &graphmode);
+  PlotVectorTriplet (kapa, &Xvec, &Yvec, &Zvec, &graphmode);
 
   free (Xvec.elements.Flt);
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/skycat.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/skycat.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/skycat.c	(revision 20860)
@@ -101,9 +101,9 @@
     graphmode.ptype = 100; /* connect pairs of points */
     graphmode.etype = 0;
-    PlotVectorPair (kapa, Xvec, Yvec, &graphmode);
+    PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode);
   }
 
-  free (Xvec.elements.Flt);
-  free (Yvec.elements.Flt);
+  free (Xvec.elements.Ptr);
+  free (Yvec.elements.Ptr);
   free (regions);
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/include/dvomath.h
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/include/dvomath.h	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/include/dvomath.h	(revision 20860)
@@ -14,11 +14,11 @@
     gprint (GP_ERR, "function requires vector of type FLT\n"); \
     return (RVAL); \
-  }
+  } }
 
-# define REQUIRE_VECTOR_INT(VECT,RVAL) { \
+# define REQUIRE_VECTOR_INT(VECT,RVAL) {	\
   if (VECT->type != OPIHI_INT) { \
     gprint (GP_ERR, "function requires vector of type INT\n"); \
     return (RVAL); \
-  }
+  } }
 
 enum {ANYVECTOR, NEWVECTOR, OLDVECTOR};
@@ -109,4 +109,6 @@
 void          InitVectors           PROTO((void));
 int           CopyVector            PROTO((Vector *out, Vector *in));
+int           ResetVector           PROTO((Vector *vec, char type, int Nelements));
+int           CastVector            PROTO((Vector *vec, char type));
 int           MatchVector           PROTO((Vector *out, Vector *in, char type));
 int           MoveVector            PROTO((Vector *out, Vector *in));
Index: /branches/eam_branch_20081124/Ohana/src/opihi/include/dvoshell.h
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/include/dvoshell.h	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/include/dvoshell.h	(revision 20860)
@@ -5,4 +5,21 @@
 # ifndef DVOSHELL_H
 # define DVOSHELL_H
+
+typedef enum {
+  DB_STACK_NONE  = 0,
+  DB_STACK_INT   = 0x01,
+  DB_STACK_FIELD = 0x02,
+  DB_STACK_TEMP  = 0x04,
+  DB_STACK_VALUE = 0x08,
+  DB_STACK_CLOSE_PAR = 0x10,
+  DB_STACK_OPEN_PAR,
+  DB_STACK_LOGIC,
+  DB_STACK_COMPARE,
+  DB_STACK_BITWISE,
+  DB_STACK_SUM,
+  DB_STACK_MULTIPLY,
+  DB_STACK_POWER,
+  DB_STACK_UNARY,
+} dbStackTypes;
 
 /* magnitude types */
@@ -145,5 +162,6 @@
   char    type;
   int     field;
-  float   Float;
+  opihi_flt FltValue;
+  opihi_int IntValue;
 } dbStack;
 
@@ -234,5 +252,5 @@
 dbStack     *dbRPN                  PROTO((int argc, char **argv, int *nstack));
 int          dbCheckStack           PROTO((dbStack *stack, int Nstack, int table, dbField **inFields, int *Nfields));
-int          dbBooleanCond          PROTO((dbStack *inStack, int NinStack, float *fields));
+int          dbBooleanCond          PROTO((dbStack *inStack, int NinStack, dbValue *fields));
 void         dbInitStack            PROTO((dbStack *stack));
 void 	     dbFreeStack            PROTO((dbStack *stack, int Nstack));
@@ -240,6 +258,6 @@
 void         dbFreeTempEntry        PROTO((dbStack *stack));
 
-dbStack     *dbBinary               PROTO((dbStack *V1, dbStack *V2, char *op, float *fields));
-dbStack     *dbUnary                PROTO((dbStack *V1, char *op, float *fields));
+dbStack     *dbBinary               PROTO((dbStack *V1, dbStack *V2, char *op, dbValue *fields));
+dbStack     *dbUnary                PROTO((dbStack *V1, char *op, dbValue *fields));
 
 int          GetMagMode             PROTO((char *string));
@@ -248,6 +266,6 @@
 int          ParseAverageField      PROTO((dbField *field, char *fieldName));
 
-double       dbExtractAverages      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
-double       dbExtractMeasures      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
+dbValue      dbExtractAverages      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
+dbValue      dbExtractMeasures      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
 void         dbExtractMeasuresInit  PROTO(());
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/VectorOps.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/VectorOps.c	(revision 20859)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/VectorOps.c	(revision 20860)
@@ -190,4 +190,6 @@
 int CastVector (Vector *vec, char type) {
 
+  int i;
+
   // the trivial case
   if (vec[0].type == type) return TRUE;
