Index: /trunk/Ohana/src/opihi/cmd.data/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/Makefile	(revision 2825)
+++ /trunk/Ohana/src/opihi/cmd.data/Makefile	(revision 2826)
@@ -49,6 +49,7 @@
 $(SDIR)/gridify.$(ARCH).o       \
 $(SDIR)/histogram.$(ARCH).o	\
+$(SDIR)/imcut.$(ARCH).o	 	\
 $(SDIR)/imhist.$(ARCH).o	\
-$(SDIR)/imcut.$(ARCH).o	\
+$(SDIR)/imsmooth.$(ARCH).o	\
 $(SDIR)/integrate.$(ARCH).o	\
 $(SDIR)/interpolate.$(ARCH).o	\
@@ -106,4 +107,5 @@
 $(SDIR)/vclip.$(ARCH).o		   \
 $(SDIR)/vgrid.$(ARCH).o		   \
+$(SDIR)/vload.$(ARCH).o		   \
 $(SDIR)/vstat.$(ARCH).o		   \
 $(SDIR)/vroll.$(ARCH).o		   \
Index: /trunk/Ohana/src/opihi/cmd.data/imsmooth.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/imsmooth.c	(revision 2826)
+++ /trunk/Ohana/src/opihi/cmd.data/imsmooth.c	(revision 2826)
@@ -0,0 +1,68 @@
+# include "data.h"
+# define NSIGMA 3
+
+int imsmooth (int argc, char **argv) {
+  
+  int i, j, n, Nx, Ny, Ns, Ngauss;
+  float *vi, *vo, *gauss, *gaussnorm;
+  float g, s, sigma;
+  Buffer *in;
+  float *temp;
+
+  if (argc != 3) {
+    fprintf (stderr, "USAGE: imsmooth (input) sigma\n");
+    return (FALSE);
+  }
+  
+  if ((in  = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
+  sigma = atof (argv[2]);
+
+  Nx = in[0].matrix.Naxis[0];
+  Ny = in[0].matrix.Naxis[1];
+  ALLOCATE (temp, float, Nx*Ny);
+
+  /* build a 1D gaussian */
+  Ns = (int) (NSIGMA*sigma + 0.5);
+  Ngauss = 2*Ns + 1;
+  ALLOCATE (gaussnorm, float, Ngauss);
+  gauss = &gaussnorm[Ns];
+  for (i = -Ns; i < Ns + 1; i++) {
+    gauss[i] = exp ((i*i)/(-2*sigma*sigma));
+  }
+
+  /* smooth in X direction */
+  for (j = 0; j < Ny; j++) {
+    vi = (float *) in[0].matrix.buffer + j*Nx;
+    vo = &temp[j*Nx];
+    for (i = 0; i < Nx; i++) {
+      g = s = 0;
+      for (n = -Ns; n < Ns + 1; n++) {
+	if (i+n < 0) continue;
+	if (i+n >= Nx) continue;
+	s += gauss[n]*vi[i+n];
+	g += gauss[n];
+      }
+      vo[i] = s / g;
+    }
+  }
+
+  /* smooth in Y direction */
+  for (i = 0; i < Nx; i++) {
+    vi = &temp[i];
+    vo = (float *)in[0].matrix.buffer + i;
+    for (j = 0; j < Ny; j++) {
+      g = s = 0;
+      for (n = -Ns; n < Ns + 1; n++) {
+	if (j+n < 0) continue;
+	if (j+n >= Ny) continue;
+	s += gauss[n]*vi[(n+j)*Nx];
+	g += gauss[n];
+      }
+      vo[j*Nx] = s / g;
+    }
+  }
+
+  free (gaussnorm);
+  return (TRUE);
+}
+
Index: /trunk/Ohana/src/opihi/cmd.data/init.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/init.c	(revision 2825)
+++ /trunk/Ohana/src/opihi/cmd.data/init.c	(revision 2826)
@@ -30,6 +30,7 @@
 int gridify          PROTO((int, char **));
 int histogram        PROTO((int, char **));
+int imcut            PROTO((int, char **));
 int imhist           PROTO((int, char **));
-int imcut            PROTO((int, char **));
+int imsmooth         PROTO((int, char **));
 int integrate        PROTO((int, char **));
 int interpolate      PROTO((int, char **));
@@ -87,4 +88,5 @@
 int vect_select      PROTO((int, char **));
 int vgrid            PROTO((int, char **));
+int vload            PROTO((int, char **));
 int vstat            PROTO((int, char **));
 int vroll            PROTO((int, char **));
@@ -126,8 +128,9 @@
   {"header",       header,	     "print buffer header"},
   {"histogram",    histogram,	     "generate histogram from vector"},
+  {"imcut",        imcut,	     "linear image cut between arbitrary coords"},
   {"imhist",       imhist,	     "histogram of an image region"},
+  {"imsmooth",     imsmooth,	     "circular gaussian smoothing"},
   {"integrate",    integrate,	     "integrate a vector"},
   {"interpolate",  interpolate,	     "interpolate between vector pairs"},
-  {"imcut",        imcut,	     "linear image cut between arbitrary coords"},
   {"jpeg",         jpeg,	     "write text line on graph"},
   {"kern",         kern,	     "convolve with 3x3 kernel"},
@@ -182,4 +185,5 @@
   {"select",	   vect_select,	     "selective vector assignment"},
   {"vgrid",        vgrid,	     "get info from imreg database"},
+  {"vload",        vload,	     "load vectors on Kii"},
   {"vstat",        vstat,	     "get info from imreg database"},
   {"vroll",        vroll,	     "roll vector elements"},
Index: /trunk/Ohana/src/opihi/cmd.data/vload.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/vload.c	(revision 2826)
+++ /trunk/Ohana/src/opihi/cmd.data/vload.c	(revision 2826)
@@ -0,0 +1,70 @@
+# include "data.h"
+
+int vload (int argc, char **argv) {
+  
+  int i, N, n, Nline, ISCEL;
+  int Ximage, Nimage;
+  double dx, dy;
+  char *buffer, *line;
+  Buffer *buf;
+  Vector *vecx, *vecy;
+  
+  Nimage = -1;
+  if (N = get_argument (argc, argv, "-n")) {
+    remove_argument (N, &argc, argv);
+    Nimage = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  if (!GetImage (&Ximage, &Nimage)) return (FALSE);
+
+  if (argc != 4) {
+    fprintf (stderr, "USAGE: vload (overlay) (xvec) (yvec) [-n]\n");
+    return (FALSE);
+  }
+  
+  if (!SelectOverlay (argv[1], &n)) return (FALSE);
+
+  if ((vecx = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);
+  if ((vecy = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE);
+  if (vecx[0].Nelements != vecy[0].Nelements) {
+    fprintf (stderr, "mismatched vector lengths\n");
+    return (FALSE);
+  }
+
+  ALLOCATE (buffer, char, 65536);  /* space for 512 lines of 128 bytes */
+  bzero (buffer, 65536);
+  ALLOCATE (line, char, 1024);     /* space to read the file */
+  Nline = 0;
+
+  write (Ximage, "LOAD", 4); /* force Ximage to look for the incoming image */
+  sprintf (line, "OVER %9d ", n);
+  write (Ximage, line, 16);
+  
+  dx = dy = 1.0;
+
+  for (i = 0; i < vecx[0].Nelements; i++) {
+    snprintf (&buffer[Nline*128], 128, "%15s %20.10f %20.10f %20.10f %20.10f ", "BOX", 
+	      vecx[0].elements[i]+0.5, vecy[0].elements[i]+0.5, dx, dy);
+    Nline ++;
+    if (Nline == 512) {
+      sprintf (line, "NLINES  %7d ", Nline);
+      write (Ximage, line, 16);
+      write (Ximage, buffer, Nline*128);
+      bzero (buffer, 65536);
+      Nline = 0;
+    }
+  }
+
+  sprintf (line, "NLINES  %7d ", Nline);
+  write (Ximage, line, 16);
+  write (Ximage, buffer, Nline*128);
+  sprintf (line, "DONE ");
+  write (Ximage, line, 16);
+
+  free (buffer);
+  free (line);
+  fprintf (stderr, "loaded %d objects\n", n);
+
+  return (TRUE);
+}
+
Index: /trunk/Ohana/src/opihi/include/mana.h
===================================================================
--- /trunk/Ohana/src/opihi/include/mana.h	(revision 2825)
+++ /trunk/Ohana/src/opihi/include/mana.h	(revision 2826)
@@ -1,7 +1,7 @@
+# include "opihi.h"
 
-/* place in program-specific file? */
-# define opihi_name "DVO"
-# define opihi_prompt "dvo: "
-# define opihi_description "Desktop Virtual Observatory\n"
-# define opihi_history ".dvo"
-# define opihi_resource ".dvorc"
+# ifndef MANA_H
+
+int *findrowpeaks (float *row, int Nrow, float threshold, int *npeaks);
+
+# endif
Index: /trunk/Ohana/src/opihi/lib.data/starfuncs.c
===================================================================
--- /trunk/Ohana/src/opihi/lib.data/starfuncs.c	(revision 2825)
+++ /trunk/Ohana/src/opihi/lib.data/starfuncs.c	(revision 2826)
@@ -6,5 +6,5 @@
   double x, y, x2, y2, I, sky, FWHMx, FWHMy, value, mag;
   int i, j, n, Npix2, Nring, Nmax;
-  double Npts, gain, dsky2, dmag;
+  double Npts, gain, dsky2, dmag, peak, offset;
   char *string;
   
@@ -45,4 +45,5 @@
   free (ring);
 
+  peak = 0;
   Npts = Nmax = 0;
   x = y = x2 = y2 = I = 0;
@@ -50,13 +51,15 @@
     for (j = Y - Npix2; j < Y + Npix2 + 1; j++) {
       value = fits_get_matrix_value (matrix, i, j);
-      x  += i*(value - sky);
-      y  += j*(value - sky);
-      x2 += i*i*(value - sky);
-      y2 += j*j*(value - sky);
-      I  += (value - sky);
+      offset = value - sky;
+      x  += i*offset;
+      y  += j*offset;
+      x2 += i*i*offset;
+      y2 += j*j*offset;
+      I  += offset;
       Npts ++;
       if (value > max) {
 	Nmax ++;
       }
+      if (value > peak) peak = value;
     }
   }
@@ -80,4 +83,5 @@
   set_variable ("dZg", dmag);
   set_variable ("Zcg", I);
+  set_variable ("Zpk", peak);
   set_int_variable ("Nsat", Nmax);
   
Index: /trunk/Ohana/src/opihi/mana/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/mana/Makefile	(revision 2825)
+++ /trunk/Ohana/src/opihi/mana/Makefile	(revision 2826)
@@ -25,6 +25,13 @@
 # mana user commands and support functions ########################
 
-mana = \
-$(SDIR)/mana.$(ARCH).o
+manafuncs = \
+$(SDIR)/init.$(ARCH).o \
+$(SDIR)/mana.$(ARCH).o \
+$(SDIR)/findrowpeaks.$(ARCH).o 
+
+manacmds = \
+$(SDIR)/findpeaks.$(ARCH).o 
+
+mana = $(manacmds) $(manafuncs)
 
 libs = \
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 2826)
@@ -0,0 +1,94 @@
+# include "mana.h"
+
+int findpeaks (int argc, char **argv) {
+  
+  int i, j, n, N, Nx, Ny;
+  int xo, yo;
+  int Npeak, NPEAK, Npeaks;
+  float *v;
+  int *peaks, *keep, *xp, *yp;
+  float threshold, vt, vo;
+  Vector *vecx, *vecy;
+  Buffer *buf;
+
+  if (argc < 3) goto usage;
+
+  if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
+  threshold = atof (argv[2]);
+
+  if ((vecx = SelectVector ("xp", ANYVECTOR, TRUE)) == NULL) return (FALSE);
+  if ((vecy = SelectVector ("yp", ANYVECTOR, TRUE)) == NULL) return (FALSE);
+
+  Nx = buf[0].matrix.Naxis[0];
+  Ny = buf[0].matrix.Naxis[1];
+
+  Npeak = 0;
+  NPEAK = Nx;
+  ALLOCATE (xp, int, NPEAK);
+  ALLOCATE (yp, int, NPEAK);
+
+  /* find peaks for each row */
+  v = (float *) buf[0].matrix.buffer;
+  for (j = 0; j < Ny; j++) {
+    peaks = findrowpeaks (&v[j*Nx], Nx, threshold, &Npeaks);
+
+    if (Npeak + Npeaks >= NPEAK) {
+      NPEAK = Npeak + Npeaks + Nx;
+      REALLOCATE (xp, int, NPEAK);
+      REALLOCATE (yp, int, NPEAK);
+    }
+    for (i = 0; i < Npeaks; i++) {
+      xp[Npeak + i] = peaks[i];
+      yp[Npeak + i] = j;
+    }
+    Npeak += Npeaks;
+    free (peaks);
+  }
+  
+  /* identify non-local peaks */
+  ALLOCATE (keep, int, MAX (Npeak, 1));
+  v = (float *) buf[0].matrix.buffer;
+  for (n = 0; n < Npeak; n++) {
+    xo = xp[n];
+    yo = yp[n];
+    vo = v[xo + yo*Nx];
+    keep[n] = TRUE;
+    for (i = xo - 1; i <= xo + 1; i++) {
+      if (i < 0) continue;
+      if (i >= Nx) continue;
+      for (j = yo - 1; j <= yo + 1; j++) {
+	if ((i == xo) && (j == yo)) continue;
+	if (j < 0) continue;
+	if (j >= Ny) continue;
+	vt = v[i + j*Nx];
+	if (vt > vo) {
+	  keep[n] = FALSE;
+	  goto next_peak;
+	}
+      }
+    }
+  next_peak:
+    continue;
+  }
+
+  REALLOCATE (vecx[0].elements, float, MAX (Npeak, 1));
+  REALLOCATE (vecy[0].elements, float, MAX (Npeak, 1));
+  /* eliminate non-local peaks */
+  for (N = n = 0; n < Npeak; n++) {
+    if (!keep[n]) continue;
+    vecx[0].elements[N] = xp[n];
+    vecy[0].elements[N] = yp[n];
+    N ++;
+  }
+
+  REALLOCATE (vecx[0].elements, float, MAX (N, 1));
+  REALLOCATE (vecy[0].elements, float, MAX (N, 1));
+  vecx[0].Nelements = vecy[0].Nelements = N;
+
+  return (TRUE);
+
+ usage:
+  fprintf (stderr, "findpeaks (buffer) (threshold)\n");
+  return (FALSE);
+}
+
Index: /trunk/Ohana/src/opihi/mana/findrowpeaks.c
===================================================================
--- /trunk/Ohana/src/opihi/mana/findrowpeaks.c	(revision 2826)
+++ /trunk/Ohana/src/opihi/mana/findrowpeaks.c	(revision 2826)
@@ -0,0 +1,56 @@
+# include "mana.h"
+
+int *findrowpeaks (float *row, int Nrow, float threshold, int *npeaks) {
+  
+  int i, rising;
+  int Npeaks, NPEAKS;
+  int *peaks;
+
+# if (0)
+  ALLOCATE (peaks, int, 3);
+  peaks[0] = 20;
+  peaks[1] = 30;
+  peaks[2] = 40;
+  *npeaks = 3;
+  return (peaks);
+# endif
+
+  Npeaks = 0;
+  NPEAKS = 100;
+  ALLOCATE (peaks, int, NPEAKS);
+
+  if (Nrow < 3) {
+    *npeaks = Npeaks;
+    return (peaks);
+  }
+    
+  rising = (row[1] > row[0]);
+
+  for (i = 2; i < Nrow; i++) {
+    if (row[i] < threshold) {
+      rising = TRUE;
+      continue;
+    }
+    if (rising) {
+      if (row[i] < row[i-1]) {
+	rising = FALSE;
+	peaks[Npeaks] = i-1;
+	Npeaks ++;
+	if (Npeaks >= NPEAKS) {
+	  NPEAKS += 100;
+	  REALLOCATE (peaks, int, NPEAKS);
+	  fprintf (stderr, "#");
+	}
+      }
+      continue;
+    }
+    if (!rising) {
+      if (row[i] > row[i-1]) {
+	rising = TRUE;
+      }
+      continue;
+    }
+  }      
+  *npeaks = Npeaks;
+  return (peaks);
+}
Index: /trunk/Ohana/src/opihi/mana/init.c
===================================================================
--- /trunk/Ohana/src/opihi/mana/init.c	(revision 2826)
+++ /trunk/Ohana/src/opihi/mana/init.c	(revision 2826)
@@ -0,0 +1,17 @@
+# include "opihi.h"
+
+int findpeaks	    PROTO((int, char **));
+
+static Command cmds[] = {  
+  {"findpeaks",   findpeaks,    "find image peaks"},
+}; 
+
+void InitMana () {
+  
+  int i;
+
+  for (i = 0; i < sizeof (cmds) / sizeof (Command); i++) {
+    AddCommand (&cmds[i]);
+  }
+
+}
Index: /trunk/Ohana/src/opihi/mana/mana.c
===================================================================
--- /trunk/Ohana/src/opihi/mana/mana.c	(revision 2825)
+++ /trunk/Ohana/src/opihi/mana/mana.c	(revision 2826)
@@ -10,5 +10,5 @@
 void InitData ();
 void InitAstro ();
-
+void InitMana ();
 
 void welcome () {
@@ -44,4 +44,5 @@
   InitAstro ();
   InitOutfile ();
+  InitMana ();
 
   rl_readline_name = opihi_name;
