Index: trunk/Ohana/src/opihi/mana/findpeaks.c
===================================================================
--- trunk/Ohana/src/opihi/mana/findpeaks.c	(revision 2826)
+++ trunk/Ohana/src/opihi/mana/findpeaks.c	(revision 2938)
@@ -7,7 +7,7 @@
   int Npeak, NPEAK, Npeaks;
   float *v;
-  int *peaks, *keep, *xp, *yp;
+  int *peaks, *keep, *xp, *yp, *zp;
   float threshold, vt, vo;
-  Vector *vecx, *vecy;
+  Vector *vecx, *vecy, *vecz;
   Buffer *buf;
 
@@ -19,4 +19,5 @@
   if ((vecx = SelectVector ("xp", ANYVECTOR, TRUE)) == NULL) return (FALSE);
   if ((vecy = SelectVector ("yp", ANYVECTOR, TRUE)) == NULL) return (FALSE);
+  if ((vecz = SelectVector ("zp", ANYVECTOR, TRUE)) == NULL) return (FALSE);
 
   Nx = buf[0].matrix.Naxis[0];
@@ -27,4 +28,5 @@
   ALLOCATE (xp, int, NPEAK);
   ALLOCATE (yp, int, NPEAK);
+  ALLOCATE (zp, int, NPEAK);
 
   /* find peaks for each row */
@@ -37,8 +39,10 @@
       REALLOCATE (xp, int, NPEAK);
       REALLOCATE (yp, int, NPEAK);
+      REALLOCATE (zp, int, NPEAK);
     }
     for (i = 0; i < Npeaks; i++) {
       xp[Npeak + i] = peaks[i];
       yp[Npeak + i] = j;
+      zp[Npeak + i] = v[peaks[i] + j*Nx];
     }
     Npeak += Npeaks;
@@ -74,4 +78,5 @@
   REALLOCATE (vecx[0].elements, float, MAX (Npeak, 1));
   REALLOCATE (vecy[0].elements, float, MAX (Npeak, 1));
+  REALLOCATE (vecz[0].elements, float, MAX (Npeak, 1));
   /* eliminate non-local peaks */
   for (N = n = 0; n < Npeak; n++) {
@@ -79,10 +84,16 @@
     vecx[0].elements[N] = xp[n];
     vecy[0].elements[N] = yp[n];
+    vecz[0].elements[N] = zp[n];
     N ++;
   }
+  free (xp);
+  free (yp);
+  free (zp);
+  free (keep);
 
   REALLOCATE (vecx[0].elements, float, MAX (N, 1));
   REALLOCATE (vecy[0].elements, float, MAX (N, 1));
-  vecx[0].Nelements = vecy[0].Nelements = N;
+  REALLOCATE (vecz[0].elements, float, MAX (N, 1));
+  vecx[0].Nelements = vecy[0].Nelements = vecz[0].Nelements = N;
 
   return (TRUE);
@@ -93,2 +104,3 @@
 }
 
+
