Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/cgrid.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/cgrid.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/cgrid.c	(revision 20873)
@@ -95,8 +95,8 @@
   
   /* prepare vectors to hold data */
+  N = 0;
   NELEMENTS = 200;
-  ALLOCATE (Xvec.elements.Flt, opihi_flt, NELEMENTS);
-  ALLOCATE (Yvec.elements.Flt, opihi_flt, NELEMENTS);
-  N = 0;
+  SetVector (&Xvec, OPIHI_FLT, NELEMENTS);
+  SetVector (&Yvec, OPIHI_FLT, NELEMENTS);
   
   /***  do consecutive RA lines, first increasing **/
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/cplot.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/cplot.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/cplot.c	(revision 20873)
@@ -31,6 +31,6 @@
   }
 
-  ResetVector (&Xvec, OPIHI_FLT, xvec[0].Nelements);
-  ResetVector (&Yvec, OPIHI_FLT, xvec[0].Nelements);
+  SetVector (&Xvec, OPIHI_FLT, xvec[0].Nelements);
+  SetVector (&Yvec, OPIHI_FLT, xvec[0].Nelements);
   
   r = xvec[0].elements.Flt;
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/czplot.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/czplot.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.astro/czplot.c	(revision 20873)
@@ -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);
+  SetVector (&Xvec, OPIHI_FLT, xvec[0].Nelements);
+  SetVector (&Yvec, OPIHI_FLT, xvec[0].Nelements);
+  SetVector (&Zvec, OPIHI_FLT, xvec[0].Nelements);
   
   r   = xvec[0].elements.Flt;
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.basic/test/sprintf.sh
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.basic/test/sprintf.sh	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.basic/test/sprintf.sh	(revision 20873)
@@ -35,5 +35,5 @@
  $PASS = 1
 
- if ($endmem - $startmem > 10)
+ if (($endmem - $startmem)/10000 > 1.0)
    $PASS = 0
    echo "growth: {$endmem-$startmem}"
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/grid.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/grid.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/grid.c	(revision 20873)
@@ -23,6 +23,6 @@
 
   N = 0;
-  ResetVector (&Xvec, OPIHI_FLT, 200);
-  ResetVector (&Yvec, OPIHI_FLT, 200);
+  SetVector (&Xvec, OPIHI_FLT, 200);
+  SetVector (&Yvec, OPIHI_FLT, 200);
 
   major = minor = 1;
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/test/applyfit2d.sh
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/test/applyfit2d.sh	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/test/applyfit2d.sh	(revision 20873)
@@ -32,4 +32,5 @@
 
 # Memory test
+# NOTE: requires test1 to be run first
 macro memtest1
 
@@ -48,5 +49,5 @@
  $PASS = 1
 
- if ($endmem - $startmem > 10)
+ if (($endmem - $startmem)/1000 > 1.0)
    $PASS = 0
    echo "growth: {$endmem-$startmem}"
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/test/vgauss.sh
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/test/vgauss.sh	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/test/vgauss.sh	(revision 20873)
@@ -20,4 +20,6 @@
 
  vgauss -q x y dy yfit
+ # lim x y; clear; box; plot -x 1 -c black x y; plot -c red x yfit
+ # cursor
 
  if (abs($C0 - 0.0) > 0.01)
@@ -51,4 +53,6 @@
 
  vgauss -q x y dy yfit
+ # lim x y; clear; box; plot -x 1 -c black x y; plot -c red x yfit
+ # cursor
 
  if (abs($C0 - 0.0) > 0.01)
@@ -71,6 +75,11 @@
  break -auto off
 
+ $C0o = 0.5
+ $C1o = 2
+ $C2o = 900
+ $C3o = 1
+
  create x -10 10 0.1
- set y = 1000 * exp(-0.5*x^2/3^2)
+ set y = $C3o + $C2o * exp(-0.5*(x - $C0o)^2/$C1o^2)
 
  gaussdev dY y[] 0.0 1.0
@@ -78,21 +87,25 @@
  set y = y + dy
 
- $C0 = 0.5
- $C1 = 2
- $C2 = 900
- $C3 = 1
+ $C0 = $C0o + 2
+ $C1 = $C1o + 2
+ $C2 = $C2o + 50
+ $C3 = $C3o + 10
 
  vgauss -q x y dy yfit
+ # lim x y; clear; box; plot -x 1 -c black x y; plot -c red x yfit
+ # cursor
 
- if (abs($C0 - 0.0) > 0.01)
+ $dS = 3.0 / sqrt(y[])
+
+ if (abs($C0 - $C0o) > $dS)
    $PASS = 0
  end
- if (abs($C1 - 3.0) > 0.01)
+ if (abs($C1 - $C1o)/$C1o > $dS)
    $PASS = 0
  end
- if (abs($C2 - 1000.0) > 1)
+ if (abs($C2 - $C2o)/$C2o > $dS)
    $PASS = 0
  end
- if (abs($C3 - 0.0) > 0.2)
+ if (abs($C3 - $C3o) > $dS)
    $PASS = 0
  end
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/test/vmaxwell.sh
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/test/vmaxwell.sh	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/test/vmaxwell.sh	(revision 20873)
@@ -40,30 +40,40 @@
  break -auto off
 
+ $C0o = 250
+ $C1o = 25
+ $C2o = 100
+ $C3o = 1
+ $C4o = 10
+
  create x 0 1000 1
- set y = 1000 * (x-200)^2 * exp(-0.5*(x-300)^2/30^2)
- set dy = (rnd(y) - 0.5)/0.5
+ set y = $C2o * (x-$C4o)^2 * exp(-0.5*(x-$C0o)^2/$C1o^2) + $C3o
+ gaussdev dY y[] 0.0 1.0
+ set dy = dY * sqrt(y)
  set y = y + dy
 
- lim x y; clear; box; plot -x 1 -c black x y
+ $C0 = $C0o + 20
+ $C1 = $C1o + 2
+ $C2 = $C2o + 100
+ $C3 = $C3o + 10
+ $C4 = $C4o + 20
 
- $C0 = 250
- $C1 = 25
- $C2 = 900
- $C3 = 1
- $C4 = 190
+ vmaxwell -q x y dy yfit
+ lim x y; clear; box; plot -x 1 -c black x y; plot x yfit -c red
 
- vmaxwell x y dy yfit
- plot x yfit -c red
+ $dS = 6.0 / sqrt(y[])
 
- if (abs($C0 - 0.0) > 0.01)
+ if (abs($C0 - $C0o) > $dS)
    $PASS = 0
  end
- if (abs($C1 - 3.0) > 0.01)
+ if (abs($C1 - $C1o)/$C1o > $dS)
    $PASS = 0
  end
- if (abs($C2 - 1000.0) > 0.1)
+ if (abs($C2 - $C2o)/$C2o > $dS)
    $PASS = 0
  end
- if (abs($C3 - 0.0) > 0.1)
+ if (abs($C3 - $C3o) > $dS)
+   $PASS = 0
+ end
+ if (abs($C4 - $C4o)/$C4o > $dS)
    $PASS = 0
  end
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/vmaxwell.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/vmaxwell.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/vmaxwell.c	(revision 20873)
@@ -65,5 +65,5 @@
   dchisq = ochisq + 2*Npts;
 
-  for (i = 0; (i < 20) && ((dchisq > 0.1*(Npts - Npar)) || (dchisq <= 0.0)); i++) {
+  for (i = 0; (i < 30) && ((dchisq > 0.1*(Npts - Npar)) || (dchisq <= 0.0)); i++) {
     chisq = mrqmin (xvec[0].elements.Flt, yvec[0].elements.Flt, dy, Npts, par, Npar, fmaxwellOD, !Quiet);
     dchisq = ochisq - chisq;
@@ -94,4 +94,5 @@
 
 /* pars: x_o, -0.5/sigma^2, I, back, ref */
+// f = C3 + C2*(x - C4)^2 * exp(-0.5*(x - C0)^2 / C1^2)
 opihi_flt fmaxwellOD (opihi_flt x, opihi_flt *par, int Npar, opihi_flt *dpar) {
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/zplot.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/zplot.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/cmd.data/zplot.c	(revision 20873)
@@ -31,6 +31,5 @@
     return (FALSE);
   }
-  Zvec.Nelements = zvec[0].Nelements;
-  ALLOCATE (Zvec.elements.Flt, opihi_flt, Zvec.Nelements);
+  SetVector (&Zvec, OPIHI_FLT, zvec[0].Nelements);
   out = Zvec.elements.Flt;
  
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/Makefile
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/Makefile	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/Makefile	(revision 20873)
@@ -29,5 +29,4 @@
 $(SRC)/dvomisc.$(ARCH).o		\
 $(SRC)/region_list.$(ARCH).o		\
-$(SRC)/dvomisc.$(ARCH).o		\
 $(SRC)/dbBooleanCond.$(ARCH).o		\
 $(SRC)/dbCheckStack.$(ARCH).o		\
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/avextract.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/avextract.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/avextract.c	(revision 20873)
@@ -11,5 +11,4 @@
 
   Vector **vec;
-  PhotCode *code;
   dbStack *stack;
   dbField *fields;
@@ -20,5 +19,4 @@
   /* defaults */
   vec = NULL;
-  code = NULL;
   stack = NULL;
   fields = NULL;
@@ -51,5 +49,11 @@
   // parse the fields to be extracted and returned
   fields = dbCmdlineFields (argc, argv, DVO_TABLE_AVERAGE, &last, &Nfields);
-  if (fields == NULL) return (FALSE);
+  if (fields == NULL) goto escape;
+  if (Nfields == 0) {
+    FreeSkyRegionSelection (selection);
+    dbFreeFields (fields, Nfields);
+    dvo_catalog_free (&catalog);
+    goto help;
+  }
 
   // examine line for 'where' or 'match to'.  'match to' is forbidden
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbCheckStack.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbCheckStack.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbCheckStack.c	(revision 20873)
@@ -83,4 +83,5 @@
 
       // this must be a field : is it a valid name?
+      status = FALSE;
       if (table == DVO_TABLE_MEASURE) {
 	status = ParseMeasureField (&fields[Nfields], stack[i].name);
@@ -89,6 +90,8 @@
 	status = ParseAverageField (&fields[Nfields], stack[i].name);
       } 
+      if (table == DVO_TABLE_IMAGE) {
+	status = ParseImageField (&fields[Nfields], stack[i].name);
+      } 
       if (!status) {
-	gprint (GP_ERR, "unknown database field %s\n", stack[i].name);
 	goto failure;
       }
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbCmdlineFields.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbCmdlineFields.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbCmdlineFields.c	(revision 20873)
@@ -77,6 +77,8 @@
 	status = ParseAverageField (&fields[Nfields], field);
       } 
+      if (table == DVO_TABLE_IMAGE) {
+	status = ParseImageField (&fields[Nfields], field);
+      } 
       if (!status) {
-	gprint (GP_ERR, "unknown database field %s\n", field);
 	free (field);
 	dbFreeFields (fields, Nfields);
@@ -143,11 +145,18 @@
   REALLOCATE (*stack, dbStack, N + 20);
 
+  Rname = Dname = NULL;
+  if (table == DVO_TABLE_MEASURE) {
+    Rname = strcreate ("RA:AVE");
+    Dname = strcreate ("DEC:AVE");
+  }
   if (table == DVO_TABLE_AVERAGE) {
     Rname = strcreate ("RA");
     Dname = strcreate ("DEC");
-  } else {
-    Rname = strcreate ("RA:AVE");
-    Dname = strcreate ("DEC:AVE");
-  }
+  }
+  if (table == DVO_TABLE_IMAGE) {
+    Rname = strcreate ("RA");
+    Dname = strcreate ("DEC");
+  } 
+  if (Rname == NULL) return (FALSE);
 
   // add: ((ra > rmin) && (ra < rmax) && (dec > dmin) && (dec < dmax))
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbExtractImages.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbExtractImages.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbExtractImages.c	(revision 20873)
@@ -154,5 +154,5 @@
       break;
     case IMAGE_PHOTCODE:
-      value.Flt = image[N].photcode;
+      value.Int = image[N].photcode;
       break;
     case IMAGE_TIME:
@@ -167,8 +167,8 @@
       break;
     case IMAGE_NSTAR:
-      value.Flt = image[N].nstar;
+      value.Int = image[N].nstar;
       break;
     case IMAGE_NCAL:
-      value.Flt = image[N].Mxxxx;
+      value.Int = image[N].Mxxxx;
       break;
     case IMAGE_SKY:
@@ -176,14 +176,14 @@
       break;
     case IMAGE_FLAG:
-      value.Flt = image[N].code;
+      value.Int = image[N].code;
       break;
     case IMAGE_NX_PIX:
-      value.Flt = image[N].NX;
+      value.Int = image[N].NX;
       break;
     case IMAGE_NY_PIX:
-      value.Flt = image[N].NY;
+      value.Int = image[N].NY;
       break;
     case IMAGE_IMAGE_ID:
-      value.Flt = image[N].imageID;
+      value.Int = image[N].imageID;
       break;
     case IMAGE_THETA: {
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbFields.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbFields.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbFields.c	(revision 20873)
@@ -197,5 +197,8 @@
   // check for code:mode in photcode name 
   code = ParsePhotcodeField (fieldName, &mode, MAG_REL);
-  if (code == NULL) return (FALSE);
+  if (code == NULL) {
+    gprint (GP_ERR, "unknown field '%s' for measurement table in DVO database\n", fieldName);
+    return (FALSE);
+  }
 
   field->ID = MEAS_MAG;
@@ -257,5 +260,9 @@
   // check for code:mode in photcode name 
   code = ParsePhotcodeField (fieldName, &mode, MAG_AVE);
-  if (code == NULL) return (FALSE);
+  if (code == NULL) {
+    gprint (GP_ERR, "unknown field '%s' for average table in DVO database\n", fieldName);
+    return (FALSE);
+  }
+
   if (code[0].type == PHOT_MAG) {
     gprint (GP_ERR, "'mag' is ambiguous for avextract\n");
@@ -337,5 +344,5 @@
 
   // for words that don't parse, try a photcode
-  gprint (GP_ERR, "unknown image field %s\n", fieldName);
+  gprint (GP_ERR, "unknown field '%s' for image table in DVO database\n", fieldName);
   return (FALSE);
 }
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbStackOps.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbStackOps.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbStackOps.c	(revision 20873)
@@ -34,5 +34,5 @@
 void dbFreeTempEntry (dbStack *stack) {
 
-  if (stack->type & DB_STACK_TEMP) 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/dvodb.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dvodb.c	(revision 20872)
+++ 	(revision )
@@ -1,77 +1,0 @@
-
-/* dvo fields and boolean expressions
-   - evaluate the command line:
-     * avextract ra,dec,g,r,i where (uRA < 0.1)
-     1) identify all fields in extraction list
-     2) parse boolean expression
-     3) identify additional fields from expression
-*/
-
-enum {DVO_TABLE_AVERAGE, DVO_TABLE_MEASURE};
-
-// a single db field 
-typedef struct {
-  char *name;
-  int extract;
-  int table;
-  int ID;
-  int magMode;
-  PhotCode *photcode;
-} dvoField;
-
-// db boolean operations
-typedef struct {
-  char   *name;
-  char    type;
-  int     field;
-  float   Float;
-} dvoStack;
-
-dvoField *ParseCmdlineFields (int argc, char **argv, int table, int *last, int *nfields) {
-
-  int i, Nfields, NFIELDS, 
-
-  *nfields = 0;
-  Nfields = 0;
-  NFIELDS = 10;
-  ALLOCATE (fields, dvoField, NFIELDS);
-
-  // examine each argv[i] entry until we reach a where 
-  for (i = 1; (i < argc) && strcasecmp (argv[i], "where"); i++) {
-    // split the word by ","
-    p = argv[i];
-    while (*p) {
-      q = strchr (p, ',');
-      if (q == NULL) {
-	field = strcreate (p);
-	p = p + strlen(p);
-      } else {
-	field = strncreate (p, q-p);
-	p = q + 1;
-      }
-      // identify field for word
-      // need to know which type of fields to look for...
-      // xxx extend this more generally later
-      if (table == DVO_TABLE_MEASURE) {
-	status = ParseMeasureField (&fields[Nfields], field);
-      } 
-      if (table == DVO_TABLE_AVERAGE) {
-	status = ParseAverageField (&fields[Nfields], field);
-      } 
-      if (!status) {
-	gprint (GP_ERR, "unknown database field %s\n", field);
-	free (field);
-	free (fields);
-	return (NULL);
-      }
-      free (field);
-
-      Nfields ++;
-      CHECK_REALLOCATE (fields, dvoField, NFIELDS, Nfields, 10);
-    }
-  }
-
-  *last = i;
-  *nfields = Nfields;
-  return (fields);
-}
Index: anches/eam_branch_20081124/Ohana/src/opihi/dvo/dvofields.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/dvofields.c	(revision 20872)
+++ 	(revision )
@@ -1,129 +1,0 @@
-
-int GetMagMode (char *string) {
-
-  if (!strcasecmp (string, "inst"))  return (MAG_INST);
-  if (!strcasecmp (string, "cat"))   return (MAG_CAT);
-  if (!strcasecmp (string, "sys"))   return (MAG_SYS);
-  if (!strcasecmp (string, "rel"))   return (MAG_REL);
-  if (!strcasecmp (string, "cal"))   return (MAG_CAL);
-  if (!strcasecmp (string, "ave"))   return (MAG_AVE);
-  if (!strcasecmp (string, "ref"))   return (MAG_REF);
-  if (!strcasecmp (string, "err"))   return (MAG_ERR);
-  if (!strcasecmp (string, "chisq")) return (MAG_CHISQ);
-  return (MAG_NONE);
-}
-
-PhotCode *ParsePhotcodeField (char *field, int *mode, int default) {
-
-  char *tmpstring, *p;
-  PhotCode *code;
-
-  *mode = default;
-
-  p = strchr (field, ':');
-  if (p != NULL) {
-    *mode = GetMagMode (p + 1);
-    if (*mode == MAG_NONE) return (NULL);
-    tmpstring = strncreate (field, p - field);
-  } else {
-    tmpstring = strcreate (field);
-  }
-  code = GetPhotcodebyName (tmpstring);
-  free (tmpstring);
-
-  return (code);
-}
-
-# define ESCAPE(F,M) { \
-  field->ID = (F); \
-  field->magMode = (M); \
-  field->photcode = NULL; \
-  return (TRUE);
-
-int ParseMeasureField (dvoField *field, char *fieldName) {
-
-  PhotCode *code;
-
-  field->table = DVO_TABLE_MEASURE;
-  field->name  = strcreate (fieldName);
-
-  if (!strcasecmp (fieldName, "RA"))       ESCAPE (MEAS_RA,   	  MAG_NONE);
-  if (!strcasecmp (fieldName, "DEC"))      ESCAPE (MEAS_DEC,  	  MAG_NONE);
-  if (!strcasecmp (fieldName, "MAG"))      ESCAPE (MEAS_MAG,  	  MAG_REL);
-  if (!strcasecmp (fieldName, "dMAG"))     ESCAPE (MEAS_dMAG, 	  MAG_ERR);
-  if (!strcasecmp (fieldName, "AIRMASS"))  ESCAPE (MEAS_AIRMASS,  MAG_NONE);
-  if (!strcasecmp (fieldName, "EXPTIME"))  ESCAPE (MEAS_EXPTIME,  MAG_NONE);
-  if (!strcasecmp (fieldName, "PHOTCODE")) ESCAPE (MEAS_PHOTCODE, MAG_NONE);
-  if (!strcasecmp (fieldName, "TIME"))     ESCAPE (MEAS_TIME,     MAG_NONE);
-  if (!strcasecmp (fieldName, "dR"))       ESCAPE (MEAS_dR, 	  MAG_NONE);
-  if (!strcasecmp (fieldName, "dD"))       ESCAPE (MEAS_dD, 	  MAG_NONE);
-  if (!strcasecmp (fieldName, "FWHM"))     ESCAPE (MEAS_FWHM,     MAG_NONE);
-  if (!strcasecmp (fieldName, "DOPHOT"))   ESCAPE (MEAS_DOPHOT,   MAG_NONE);
-  if (!strcasecmp (fieldName, "FLAGS"))    ESCAPE (MEAS_FLAGS,    MAG_NONE);
-  if (!strcasecmp (fieldName, "XCCD"))     ESCAPE (MEAS_XCCD, 	  MAG_NONE);
-  if (!strcasecmp (fieldName, "YCCD"))     ESCAPE (MEAS_YCCD, 	  MAG_NONE);
-  if (!strcasecmp (fieldName, "XMOSAIC"))  ESCAPE (MEAS_XMOSAIC,  MAG_NONE);
-  if (!strcasecmp (fieldName, "YMOSAIC"))  ESCAPE (MEAS_YMOSAIC,  MAG_NONE);
-
-  // for words that don't parse, try a photcode
-
-  // check for code:mode in photcode name 
-  code = ParsePhotcodeField (&mode, MAG_REL);
-  if (code == NULL) return (FALSE);
-
-  if (mode == MAG_ERR) {
-    field->ID = MEAS_dMAG;
-  } else {
-    field->ID = MEAS_MAG;
-  }    
-  
-  field->magMode = mode;
-  field->photcode = code;
-  return (TRUE);
-}
-  
-int ParseAverageField (char *fieldName) {
-
-  PhotCode *code;
-
-  field->table = DVO_TABLE_AVERAGE;
-
-  if (!strcasecmp (fieldName, "RA"))    ESCAPE (AVE_RA,        MAG_NONE);
-  if (!strcasecmp (fieldName, "DEC"))   ESCAPE (AVE_DEC,       MAG_NONE);
-  if (!strcasecmp (fieldName, "dRA"))   ESCAPE (AVE_RA_ERR,    MAG_NONE);
-  if (!strcasecmp (fieldName, "dDEC"))  ESCAPE (AVE_DEC_ERR,   MAG_NONE);
-  if (!strcasecmp (fieldName, "uRA"))   ESCAPE (AVE_U_RA,      MAG_NONE);
-  if (!strcasecmp (fieldName, "uDEC"))  ESCAPE (AVE_U_DEC,     MAG_NONE);
-  if (!strcasecmp (fieldName, "duRA"))  ESCAPE (AVE_U_RA_ERR,  MAG_NONE);
-  if (!strcasecmp (fieldName, "duDEC")) ESCAPE (AVE_U_DEC_ERR, MAG_NONE);
-  if (!strcasecmp (fieldName, "PAR"))   ESCAPE (AVE_PAR,       MAG_NONE);
-  if (!strcasecmp (fieldName, "dPAR"))  ESCAPE (AVE_PAR_ERR,   MAG_NONE);
-  if (!strcasecmp (fieldName, "MAG"))   ESCAPE (AVE_MAG,       MAG_AVE);
-  if (!strcasecmp (fieldName, "dMAG"))  ESCAPE (AVE_dMAG,      MAG_AVE_ERR);
-  if (!strcasecmp (fieldName, "NMEAS")) ESCAPE (AVE_NMEAS,     MAG_NONE);
-  if (!strcasecmp (fieldName, "NMISS")) ESCAPE (AVE_NMISS,     MAG_NONE);
-  if (!strcasecmp (fieldName, "Xp"))    ESCAPE (AVE_Xp,        MAG_NONE);
-  if (!strcasecmp (fieldName, "Xm"))    ESCAPE (AVE_Xm,        MAG_CHISQ);
-  if (!strcasecmp (fieldName, "FLAG"))  ESCAPE (AVE_FLAG,      MAG_NONE);
-  if (!strcasecmp (fieldName, "TYPE"))  ESCAPE (AVE_TYPE,      MAG_NONE);
-  if (!strcasecmp (fieldName, "NPHOT")) ESCAPE (AVE_NPHOT,     MAG_NONE);
-  if (!strcasecmp (fieldName, "NCODE")) ESCAPE (AVE_NCODE,     MAG_NONE);
-  if (!strcasecmp (fieldName, "NCRIT")) ESCAPE (AVE_NCRIT,     MAG_NONE);
-
-  // for words that don't parse, try a photcode
-
-  // check for code:mode in photcode name 
-  code = ParsePhotcodeField (&mode, MAG_AVE);
-  if (code == NULL) return (FALSE);
-
-  // need to distinguish phot, sys errors and scatter
-  if (mode == MAG_ERR) {
-    field->ID = MEAS_dMAG;
-  } else {
-    field->ID = MEAS_MAG;
-  }    
-  
-  field->magMode = mode;
-  field->photcode = code;
-  return (TRUE);
-}
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/images.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/images.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/images.c	(revision 20873)
@@ -113,6 +113,6 @@
 
   npts = NPTS = 200;
-  ResetVector (&Xvec, OPIHI_FLT, NPTS);
-  ResetVector (&Yvec, OPIHI_FLT, NPTS);
+  SetVector (&Xvec, OPIHI_FLT, NPTS);
+  SetVector (&Yvec, OPIHI_FLT, NPTS);
 
   ALLOCATE (plist, int, NPTS);
@@ -276,5 +276,5 @@
 
   gprint (GP_ERR, "plotting %d images\n", n);
-  Xvec.Nelements = Xvec.Nelements = N;
+  Xvec.Nelements = Yvec.Nelements = N;
   if (N > 0) {
     graphmode.style = 2; /* points */
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imbox.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imbox.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imbox.c	(revision 20873)
@@ -36,6 +36,6 @@
   
   /* project this image to screen display coords */
-  ResetVector (&Xvec, OPIHI_FLT, 8);
-  ResetVector (&Yvec, OPIHI_FLT, 8);
+  SetVector (&Xvec, OPIHI_FLT, 8);
+  SetVector (&Yvec, OPIHI_FLT, 8);
 
   while (gfits_fread_header (f, &header)) {
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imdense.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imdense.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imdense.c	(revision 20873)
@@ -32,6 +32,6 @@
   N = 0;
   NPTS = 200;
-  ResetVector (&Xvec, OPIHI_FLT, NPTS);
-  ResetVector (&Yvec, OPIHI_FLT, NPTS);
+  SetVector (&Xvec, OPIHI_FLT, NPTS);
+  SetVector (&Yvec, OPIHI_FLT, NPTS);
 
   for (i = 0; i < Nimage; i++) {
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imextract.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imextract.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imextract.c	(revision 20873)
@@ -39,5 +39,5 @@
   if ((selection = SetRegionSelection (&argc, argv)) == NULL) {
     gprint (GP_ERR, "invalid sky region selection\n");
-    return FALSE;
+    goto escape;
   }
 
@@ -46,5 +46,10 @@
   // parse the fields to be extracted and returned
   fields = dbCmdlineFields (argc, argv, DVO_TABLE_IMAGE, &last, &Nfields);
-  if (fields == NULL) return (FALSE);
+  if (fields == NULL) goto escape;
+  if (Nfields == 0) {
+    FreeSkyRegionSelection (selection);
+    dbFreeFields (fields, Nfields);
+    goto help;
+  }
 
   // examine line for 'where' or 'match to'.  'match to' is forbidden
@@ -158,4 +163,39 @@
     gprint (GP_ERR, "  RA : right ascension of field center (J2000)\n");
     gprint (GP_ERR, "  DEC : declination of field center\n");
+    gprint (GP_ERR, "  Xm : chisq of photometry calibration\n");
+    gprint (GP_ERR, "  airmass : mean airmass of exposure\n");
+    gprint (GP_ERR, "  Mcal : photometry calibration (mags)\n");
+    gprint (GP_ERR, "  dMcal : photometry calibration error (mags)\n");
+    gprint (GP_ERR, "  photcode : numeric photcode value for image\n");
+    gprint (GP_ERR, "  time : time of exposure\n");
+    gprint (GP_ERR, "  FWHM : mean fwhm of exposure\n");
+    gprint (GP_ERR, "  exptime : exposure duration (seconds)\n");
+    gprint (GP_ERR, "  nstar : number of stars detected in exposure\n");
+    gprint (GP_ERR, "  ncal : number of stars used for photometry calibration\n");
+    gprint (GP_ERR, "  sky : mean background flux\n");
+    gprint (GP_ERR, "  flag : processing bit flags\n");
+    gprint (GP_ERR, "  NX : image dimensions\n");
+    gprint (GP_ERR, "  NY : image dimensions\n");
+    gprint (GP_ERR, "  theta : position angle of image\n");
+    gprint (GP_ERR, "  skew : distortion from rectangle\n");
+    gprint (GP_ERR, "  scale : pixel scale\n");
+    gprint (GP_ERR, "  dscale : pixel-scale error (or variation?)\n");
+    gprint (GP_ERR, "  imageID : unique image identifier\n");
+    gprint (GP_ERR, "  X_LL_CHIP : chip x-pixel coordinate of lower left corner\n");
+    gprint (GP_ERR, "  X_LR_CHIP : chip x-pixel coordinate of lower right corner\n");
+    gprint (GP_ERR, "  X_UL_CHIP : chip x-pixel coordinate of upper left corner\n");
+    gprint (GP_ERR, "  X_UR_CHIP : chip x-pixel coordinate of upper right corner\n");
+    gprint (GP_ERR, "  Y_LL_CHIP : chip y-pixel coordinate of lower left corner\n");
+    gprint (GP_ERR, "  Y_LR_CHIP : chip y-pixel coordinate of lower right corner\n");
+    gprint (GP_ERR, "  Y_UL_CHIP : chip y-pixel coordinate of upper left corner\n");
+    gprint (GP_ERR, "  Y_UR_CHIP : chip y-pixel coordinate of upper right corner\n");
+    gprint (GP_ERR, "  X_LL_FP   : focal-plane x-pixel coordinate of lower left corner\n");
+    gprint (GP_ERR, "  X_LR_FP   : focal-plane x-pixel coordinate of lower right corner\n");
+    gprint (GP_ERR, "  X_UL_FP   : focal-plane x-pixel coordinate of upper left corner\n");
+    gprint (GP_ERR, "  X_UR_FP   : focal-plane x-pixel coordinate of upper right corner\n");
+    gprint (GP_ERR, "  Y_LL_FP   : focal-plane y-pixel coordinate of lower left corner\n");
+    gprint (GP_ERR, "  Y_LR_FP   : focal-plane y-pixel coordinate of lower right corner\n");
+    gprint (GP_ERR, "  Y_UL_FP   : focal-plane y-pixel coordinate of upper left corner\n");
+    gprint (GP_ERR, "  Y_UR_FP   : focal-plane y-pixel coordinate of upper right corner\n");
     return (FALSE);
   }
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imstats.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imstats.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/imstats.c	(revision 20873)
@@ -33,6 +33,6 @@
 
   /* assign vector values */
-  ResetVector (&Xvec, OPIHI_FLT, Nimage);
-  ResetVector (&Yvec, OPIHI_FLT, Nimage);
+  SetVector (&Xvec, OPIHI_FLT, Nimage);
+  SetVector (&Yvec, OPIHI_FLT, Nimage);
 
   gprint (GP_LOG, "seq  ra (J2000) dec    time (s)   Nstars\n");
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/lcurve.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/lcurve.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/lcurve.c	(revision 20873)
@@ -104,9 +104,9 @@
   N = 0;
   NPTS = 100;
-  ResetVector (&Xvec, OPIHI_FLT, NPTS);
-  ResetVector (&Yvec, OPIHI_FLT, NPTS);
+  SetVector (&Xvec, OPIHI_FLT, NPTS);
+  SetVector (&Yvec, OPIHI_FLT, NPTS);
   dYvec.elements.Flt = NULL;
   if (ErrorBars) {   
-    ResetVector (&dYvec, OPIHI_FLT, NPTS);
+    SetVector (&dYvec, OPIHI_FLT, NPTS);
   }
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/mextract.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/mextract.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/mextract.c	(revision 20873)
@@ -11,5 +11,4 @@
   Catalog catalog;
   SkyList *skylist;
-  PhotCode *code;
   Vector **vec;
   dbField *fields;
@@ -18,8 +17,10 @@
 
   /* defaults */
+  vec = NULL;
+  stack = NULL;
+  fields = NULL;
+  values = NULL;
   skylist = NULL;
-  code = NULL;
-  fields = NULL;
-  stack = NULL;
+  selection = NULL;
 
   if ((N = get_argument (argc, argv, "-h"))) goto help;
@@ -49,4 +50,10 @@
   fields = dbCmdlineFields (argc, argv, DVO_TABLE_MEASURE, &last, &Nfields);
   if (fields == NULL) return (FALSE);
+  if (Nfields == 0) {
+    FreeSkyRegionSelection (selection);
+    dbFreeFields (fields, Nfields);
+    dvo_catalog_free (&catalog);
+    goto help;
+  }
 
   // examine line for 'where' or 'match to'.  'match to' is forbidden
@@ -168,5 +175,6 @@
   }
 
-  free (values);
+  if (vec) free (vec);
+  if (values) free (values);
   dbFreeFields (fields, Nfields);
   dbFreeStack (stack, Nstack);
@@ -178,4 +186,5 @@
 
 escape:
+  if (vec) free (vec);
   free (values);
   dbFreeFields (fields, Nfields);
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/mmextract.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/mmextract.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/mmextract.c	(revision 20873)
@@ -13,5 +13,4 @@
   Catalog catalog;
   SkyList *skylist;
-  PhotCode *code;
   Vector **vec;
   dbField *fields;
@@ -21,9 +20,11 @@
 
   /* defaults */
-  skylist = NULL;
-  code = NULL;
-  fields = NULL;
+  vec = NULL;
   stack1 = NULL;
   stack2 = NULL;
+  fields = NULL;
+  values = NULL;
+  skylist = NULL;
+  selection = NULL;
 
   if ((N = get_argument (argc, argv, "-h"))) goto help;
@@ -57,5 +58,11 @@
   // parse the fields to be extracted and returned : last points to end, or first 'where' or 'matched'
   fields = dbCmdlineFields (argc, argv, DVO_TABLE_MEASURE, &last, &Nfields);
-  if (fields == NULL) return (FALSE);
+  if (fields == NULL) goto escape;
+  if (Nfields == 0) {
+    FreeSkyRegionSelection (selection);
+    dbFreeFields (fields, Nfields);
+    dvo_catalog_free (&catalog);
+    goto help;
+  }
 
   // examine line for 'where' and 'match to'.  neither is required, but order is fixed
@@ -298,4 +305,6 @@
 
 escape:
+  if (vec) free (vec);
+  if (values) free (values);
   dbFreeFields (fields, Nfields);
   dbFreeStack (stack1, Nstack1);
@@ -310,5 +319,6 @@
 
  help:
-  gprint (GP_ERR, "USAGE: mextract field[,field,field...] where (expression)\n");
+  gprint (GP_ERR, "USAGE: mmextract field[,field,field...] where (expression) match to (expression)\n");
+  gprint (GP_ERR, "  pairs of fields are returned: the first set are restricted by the 'where' expression, the second by the 'match to' expression\n");
 
   if ((argc > N + 1) && !strcasecmp (argv[N+1], "fields")) {
@@ -362,5 +372,5 @@
     return (FALSE);
   }
-  gprint (GP_ERR, " mextract --help fields : for a complete listing of allowed fields\n");
+  gprint (GP_ERR, " mmextract --help fields : for a complete listing of allowed fields\n");
   return (FALSE);
 }
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/procks.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/procks.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/procks.c	(revision 20873)
@@ -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);
+  SetVector (&Xvec, OPIHI_FLT, 3*Nrocks);
+  SetVector (&Yvec, OPIHI_FLT, 3*Nrocks);
   
   /* project stars to screen display coords */
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/showtile.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/showtile.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/showtile.c	(revision 20873)
@@ -22,6 +22,6 @@
   N = 0;
   NPTS = 200;
-  ResetVector (&Xvec, OPIHI_FLT, NPTS);
-  ResetVector (&Yvec, OPIHI_FLT, NPTS);
+  SetVector (&Xvec, OPIHI_FLT, NPTS);
+  SetVector (&Yvec, OPIHI_FLT, NPTS);
 
   /* starting position */
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/simage.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/simage.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/simage.c	(revision 20873)
@@ -92,7 +92,7 @@
 
   /* set up storage buffers */
-  ResetVector (&Xvec, OPIHI_FLT, Nstars);
-  ResetVector (&Yvec, OPIHI_FLT, Nstars);
-  ResetVector (&Zvec, OPIHI_FLT, Nstars);
+  SetVector (&Xvec, OPIHI_FLT, Nstars);
+  SetVector (&Yvec, OPIHI_FLT, Nstars);
+  SetVector (&Zvec, OPIHI_FLT, Nstars);
   ALLOCATE (buffer, char, (BLOCK*BYTES_STAR));
 
Index: /branches/eam_branch_20081124/Ohana/src/opihi/dvo/skycat.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/dvo/skycat.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/dvo/skycat.c	(revision 20873)
@@ -55,6 +55,6 @@
   Npts = 0;
   NPTS = 200;
-  ResetVector (&Xvec, OPIHI_FLT, NPTS);
-  ResetVector (&Yvec, OPIHI_FLT, NPTS);
+  SetVector (&Xvec, OPIHI_FLT, NPTS);
+  SetVector (&Yvec, OPIHI_FLT, NPTS);
    
   regions = skylist[0].regions;
Index: /branches/eam_branch_20081124/Ohana/src/opihi/include/dvomath.h
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/include/dvomath.h	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/include/dvomath.h	(revision 20873)
@@ -8,5 +8,7 @@
 # define NCHARS 256
 # define opihi_flt double
-# define opihi_int unsigned int
+# define opihi_int int
+// NOTE: if opihi_int is changed to unsigned, all subtraction and negation operations
+// need to result in a float value (or 3 - 5 will yield the unexpected value 2^32 - 2)
 
 # define REQUIRE_VECTOR_FLT(VECT,RVAL) { \
@@ -110,4 +112,5 @@
 int           CopyVector            PROTO((Vector *out, Vector *in));
 int           ResetVector           PROTO((Vector *vec, char type, int Nelements));
+int           SetVector             PROTO((Vector *vec, char type, int Nelements));
 int           CastVector            PROTO((Vector *vec, char type));
 int           MatchVector           PROTO((Vector *out, Vector *in, char type));
Index: /branches/eam_branch_20081124/Ohana/src/opihi/include/dvoshell.h
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/include/dvoshell.h	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/include/dvoshell.h	(revision 20873)
@@ -309,4 +309,5 @@
 int          ParseMeasureField      PROTO((dbField *field, char *fieldName));
 int          ParseAverageField      PROTO((dbField *field, char *fieldName));
+int          ParseImageField        PROTO((dbField *field, char *fieldName));
 
 dbValue      dbExtractAverages      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
Index: /branches/eam_branch_20081124/Ohana/src/opihi/lib.data/graphtools.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/lib.data/graphtools.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/lib.data/graphtools.c	(revision 20873)
@@ -32,5 +32,5 @@
 
   if (yvec != NULL) {
-    if (xvec->type == OPIHI_FLT) {
+    if (yvec->type == OPIHI_FLT) {
       maxY = minY = yvec[0].elements.Flt[0];
       for (i = 1; i < yvec[0].Nelements; i++) {
Index: /branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/VectorOps.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/VectorOps.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/VectorOps.c	(revision 20873)
@@ -187,4 +187,18 @@
 }
 
+// SetVector (vecx, OPIHI_FLT, MAX (Npts, 1));
+int SetVector (Vector *vec, char type, int Nelements) {
+
+  vec[0].Nelements = Nelements;
+  if (type == OPIHI_FLT) {
+    ALLOCATE (vec[0].elements.Flt, opihi_flt, Nelements);
+    vec[0].type = OPIHI_FLT;
+  } else {
+    ALLOCATE (vec[0].elements.Int, opihi_int, Nelements);
+    vec[0].type = OPIHI_INT;
+  }
+  return TRUE;
+}
+
 // recast the vector to the specified type
 int CastVector (Vector *vec, char type) {
Index: /branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/stack_math.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/stack_math.c	(revision 20872)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/stack_math.c	(revision 20873)
@@ -819,5 +819,5 @@
     }						\
     if ((FTYPE == 's') && (V1->type == 's')) {	\
-      opihi_int M1  = V1[0].FltValue;		\
+      opihi_int M1  = V1[0].IntValue;		\
       OUT[0].type = 's';			\
       OUT[0].IntValue = OP;			\
@@ -855,5 +855,5 @@
   if (!strcmp (op, "rnd"))    S_FUNC(M1*0.0 + drand48(), 'S');
   if (!strcmp (op, "not"))    S_FUNC(!(M1), 's');
-  if (!strcmp (op, "--"))     S_FUNC(-(M1), 's');
+  if (!strcmp (op, "--"))     S_FUNC(-1*M1, 's'); // NOTE: opihi_int is signed, 
   if (!strcmp (op, "isinf"))  S_FUNC(!finite(M1), 'S'); // XXX modify in future 
   if (!strcmp (op, "isnan"))  S_FUNC(isnan(M1), 'S'); // XXX modify in future   
@@ -939,5 +939,5 @@
   if (!strcmp (op, "zero"))   V_FUNC(0, 's');
   if (!strcmp (op, "not"))    V_FUNC(!(*M1), 's');
-  if (!strcmp (op, "--"))     V_FUNC(-(*M1), 's');
+  if (!strcmp (op, "--"))     V_FUNC(-1*(*M1), 's'); // NOTE: opihi_int is signed
   if (!strcmp (op, "isinf"))  V_FUNC(!finite(*M1), 'S');
   if (!strcmp (op, "isnan"))  V_FUNC(isnan(*M1), 'S');
@@ -980,5 +980,5 @@
   if (!strcmp (op, "="))     { }
   if (!strcmp (op, "abs"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = fabs(*M1);         }}
-  if (!strcmp (op, "int"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = (float)(int)(*M1); }}
+  if (!strcmp (op, "int"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = (opihi_flt)(int)(*M1); }}
   if (!strcmp (op, "exp"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = exp(*M1);          }}
   if (!strcmp (op, "ten"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = pow(10.0,*M1);     }}
