Index: trunk/Ohana/src/opihi/cmd.data/zplot.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/zplot.c	(revision 31667)
+++ trunk/Ohana/src/opihi/cmd.data/zplot.c	(revision 34584)
@@ -3,5 +3,6 @@
 int zplot (int argc, char **argv) {
   
-  int i, kapa;
+  char *outname;
+  int i, kapa, valid, size;
   opihi_flt *out;
   double min, range;
@@ -11,6 +12,9 @@
   if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
 
-  if (argc != 6) {
+  valid  = (argc == 6);
+  valid |= (argc > 7) && !strcmp (argv[6], "where");
+  if (!valid) {
     gprint (GP_ERR, "USAGE: zplot <x> <y> <z> min max\n");
+    gprint (GP_ERR, "   OR: zplot <x> <y> <z> min max where (condition)\n");
     return (FALSE);
   }
@@ -18,4 +22,21 @@
   min = atof(argv[4]);
   range = atof(argv[5]) - min;
+
+  // tvec is used for logical test (truth vector)
+  Vector *tvec = NULL;
+  char *mask = NULL;
+  if (argc > 7) {
+    outname = dvomath (argc - 7, &argv[7], &size, 1);
+    if (outname == NULL) {
+      print_error ();
+      return FALSE;
+    }
+    if ((tvec = SelectVector (outname, OLDVECTOR, TRUE)) == NULL) {
+      gprint (GP_ERR, " invalid logic result\n");
+      DeleteNamedVector (outname);
+      free (outname);
+      return (FALSE);
+    }
+  }
 
   /* find vectors */
@@ -29,4 +50,8 @@
   if (xvec[0].Nelements != zvec[0].Nelements) {
     gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[1], argv[3]);
+    return (FALSE);
+  }
+  if (tvec && tvec[0].Nelements != yvec[0].Nelements) {
+    gprint (GP_ERR, "logic test vector not the same length as data vectors\n");
     return (FALSE);
   }
@@ -46,11 +71,20 @@
   }
 
+  if (tvec) {
+    ALLOCATE (mask, char, tvec->Nelements);
+    for (i = 0; i < tvec->Nelements; i++) {
+      mask[i] = (tvec->type == OPIHI_FLT) ? (tvec->elements.Flt[i] == 0.0) : (tvec->elements.Int[i] == 0.0);
+    }
+  }
+
   /* point size determined by Zvec */
   graphmode.style = 2; /* plot points */
   graphmode.size = -1; /* point size determined by Zvec */
   graphmode.etype = 0; /* no errorbars */
-  PlotVectorTriplet (kapa, xvec, yvec, &Zvec, &graphmode);
+  PlotVectorTriplet (kapa, xvec, yvec, &Zvec, mask, &graphmode);
 
   free (Zvec.elements.Ptr);
+  if (mask) free (mask);
+  DeleteNamedVector (outname);
 
   return (TRUE);
@@ -60,5 +94,6 @@
 int zcplot (int argc, char **argv) {
   
-  int i, kapa;
+  char *outname;
+  int i, kapa, valid, size;
   opihi_flt *out;
   double min, range;
@@ -68,6 +103,9 @@
   if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
 
-  if (argc != 6) {
-    gprint (GP_ERR, "USAGE: zplot <x> <y> <z> min max\n");
+  valid  = (argc == 6);
+  valid |= (argc > 7) && !strcmp (argv[6], "where");
+  if (!valid) {
+    gprint (GP_ERR, "USAGE: zcplot <x> <y> <z> min max\n");
+    gprint (GP_ERR, "   OR: zcplot <x> <y> <z> min max where (condition)\n");
     return (FALSE);
   }
@@ -75,4 +113,21 @@
   min = atof(argv[4]);
   range = atof(argv[5]) - min;
+
+  // tvec is used for logical test (truth vector)
+  Vector *tvec = NULL;
+  char *mask = NULL;
+  if (argc > 7) {
+    outname = dvomath (argc - 7, &argv[7], &size, 1);
+    if (outname == NULL) {
+      print_error ();
+      return FALSE;
+    }
+    if ((tvec = SelectVector (outname, OLDVECTOR, TRUE)) == NULL) {
+      gprint (GP_ERR, " invalid logic result\n");
+      DeleteNamedVector (outname);
+      free (outname);
+      return (FALSE);
+    }
+  }
 
   /* find vectors */
@@ -86,4 +141,8 @@
   if (xvec[0].Nelements != zvec[0].Nelements) {
     gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[1], argv[3]);
+    return (FALSE);
+  }
+  if (tvec && tvec[0].Nelements != yvec[0].Nelements) {
+    gprint (GP_ERR, "logic test vector not the same length as data vectors\n");
     return (FALSE);
   }
@@ -103,11 +162,20 @@
   }
 
+  if (tvec) {
+    ALLOCATE (mask, char, tvec->Nelements);
+    for (i = 0; i < tvec->Nelements; i++) {
+      mask[i] = (tvec->type == OPIHI_FLT) ? (tvec->elements.Flt[i] == 0.0) : (tvec->elements.Int[i] == 0.0);
+    }
+  }
+
   /* point size determined by Zvec */
   graphmode.style = 2; /* plot points */
   graphmode.color = -1; /* point color determined by Zvec */
   graphmode.etype = 0; /* no errorbars */
-  PlotVectorTriplet (kapa, xvec, yvec, &Zvec, &graphmode);
+  PlotVectorTriplet (kapa, xvec, yvec, &Zvec, mask, &graphmode);
 
   free (Zvec.elements.Ptr);
+  if (mask) free (mask);
+  DeleteNamedVector (outname);
 
   return (TRUE);
