Index: /trunk/Ohana/src/opihi/cmd.data/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/Makefile	(revision 40636)
+++ /trunk/Ohana/src/opihi/cmd.data/Makefile	(revision 40637)
@@ -175,4 +175,5 @@
 $(SRC)/vload.$(ARCH).o		   \
 $(SRC)/vzload.$(ARCH).o		   \
+$(SRC)/vpeaks.$(ARCH).o		   \
 $(SRC)/vpop.$(ARCH).o		   \
 $(SRC)/vroll.$(ARCH).o		   \
Index: /trunk/Ohana/src/opihi/cmd.data/init.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/init.c	(revision 40636)
+++ /trunk/Ohana/src/opihi/cmd.data/init.c	(revision 40637)
@@ -165,4 +165,5 @@
 int vroll            PROTO((int, char **));
 int vshift           PROTO((int, char **));
+int vpeaks           PROTO((int, char **));
 int vpop             PROTO((int, char **));
 int vsmooth          PROTO((int, char **));
@@ -353,4 +354,5 @@
   {1, "vload",        vload,            "load vectors as overlay on image display"},
   {1, "vmaxwell",     vmaxwell,         "fit a Maxwellian to a vector"},
+  {1, "vpeaks",       vpeaks,           "fine coord and flux of peaks in vector"},
   {1, "vpop",         vpop,             "remove first element of a vector"},
   {1, "vroll",        vroll,            "roll vector elements by 1 entry"},
Index: /trunk/Ohana/src/opihi/cmd.data/vpeaks.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/vpeaks.c	(revision 40637)
+++ /trunk/Ohana/src/opihi/cmd.data/vpeaks.c	(revision 40637)
@@ -0,0 +1,59 @@
+# include "data.h"
+
+int vpeaks (int argc, char **argv) {
+
+  int N;
+  Vector *vecx, *vecf, *vecv;
+
+  float collevel = NAN;
+  if ((N = get_argument (argc, argv, "-collevel"))) {
+    remove_argument (N, &argc, argv);
+    collevel = atof(argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  if (argc != 5) {
+    gprint (GP_ERR, "USAGE: vpeaks (vector) <xvec> <fvec> <threshold>\n");
+    gprint (GP_ERR, "  finds coordinate (x) and peak-flux (f) of peaks above threshold in vector\n");
+    return (FALSE);
+  }
+
+  if ((vecv = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
+  if ((vecx = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) return (FALSE);
+  if ((vecf = SelectVector (argv[3], ANYVECTOR, TRUE)) == NULL) return (FALSE);
+
+  float threshold = atof (argv[4]);
+  int Nv = vecv->Nelements;
+
+  // we cannot have more peaks than pixels in the input vector, just start with that:
+  ALLOCATE_PTR (peakX, opihi_flt, Nv);
+  opihi_flt *value = vecv->elements.Flt;
+
+  int OnPeak = FALSE;
+  int Npeaks = 0;
+  for (int i = 1; i < Nv - 1; i++) {
+
+    if (!isfinite(value[i])) continue;   // ignore NAN values
+    if (OnPeak && isfinite(collevel) && (value[i] < collevel)) OnPeak = FALSE;
+
+    if (value[i] <  threshold) continue; // only accept pixels above threshold
+    if (value[i] <  value[i - 1]) continue; // peak pixel must be at least exceed preceeding pixel
+    if (value[i] <= value[i + 1]) continue; // we accept the last pixel of a series of equal values
+    if (OnPeak && isfinite(collevel) && (value[i] > collevel)) continue;
+    
+    OnPeak = TRUE;
+    peakX[Npeaks] = i;
+    Npeaks ++;
+  }
+
+  ResetVector (vecf, OPIHI_FLT, Npeaks);
+  for (int i = 0; i < Npeaks; i++) {
+    int ix = peakX[i];
+    vecf->elements.Flt[i] = value[ix];
+  }  
+
+  // save the peakX values:
+  vecx->Nelements = Npeaks; free (vecx->elements.Flt); vecx->elements.Flt = peakX; 
+
+  return (TRUE);
+}
