Index: /branches/eam_branches/ipp-20230313/Ohana/src/opihi/cmd.data/medacc.c
===================================================================
--- /branches/eam_branches/ipp-20230313/Ohana/src/opihi/cmd.data/medacc.c	(revision 42514)
+++ /branches/eam_branches/ipp-20230313/Ohana/src/opihi/cmd.data/medacc.c	(revision 42515)
@@ -8,9 +8,23 @@
   Vector *val, *key, *out;
 
+  Vector *stdev = NULL;
+  if ((N = get_argument (argc, argv, "-stdev"))) {
+    remove_argument (N, &argc, argv);
+    stdev = SelectVector (argv[N], ANYVECTOR, TRUE);
+    remove_argument (N, &argc, argv);
+    if (!stdev) {
+      gprint (GP_ERR, "output vector for standard deviation not found\n");
+      return (FALSE);
+    }
+  }
+
   if ((argc != 6) && (argc != 7)) {
     gprint (GP_ERR, "USAGE: medacc <value> <vector> <key> start end [delta]\n");
     gprint (GP_ERR, "  value and key are vectors of the same length\n");
     gprint (GP_ERR, "  the output vector bins correspond to values ranging from start to end in steps of delta (default 1)\n");
-    gprint (GP_ERR, "  for a given output bin, all input values for which the key matches the output bin are averaged\n");
+    gprint (GP_ERR, "  for a given output bin, all input values for which the key matches the output bin are used to calculate the statistic\n");
+
+    gprint (GP_ERR, "  the output is the average of the inner 25%% of data values\n");
+    gprint (GP_ERR, "  -stdev (outvec) : optionally return the standard deviation, calculated based on the 68%%-ile range\n");
 
     return (FALSE);
@@ -43,4 +57,8 @@
   ResetVector (out, OPIHI_FLT, Nbins);
   bzero (out[0].elements.Flt, sizeof(opihi_flt)*out[0].Nelements);
+
+  if (stdev) {
+    ResetVector (stdev, OPIHI_FLT, Nbins);
+  }
 
   /* copy vec and key to temp vectors */
@@ -80,4 +98,12 @@
     }
     if (fn > 0) O[i] /= fn;
+
+    if (stdev) {
+      int Nmin = 0.16*N;
+      int Nmax = 0.84*N;
+      float Smin = tmpvec[N0 + Nmin];
+      float Smax = tmpvec[N0 + Nmax];
+      stdev[0].elements.Flt[i] = 0.5*(Smax - Smin);
+    }
   }      
   
