Index: /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.astro/region.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.astro/region.c	(revision 29815)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.astro/region.c	(revision 29816)
@@ -55,4 +55,5 @@
   if ((argc != 4) && (argc != 5)) {
     gprint (GP_ERR, "USAGE: region Ra Dec Radius [projection] [orientation]\n");
+    gprint (GP_ERR, "  [-image] [-ew] [+ew] [-ns] [+ns] [-no-clear]\n");
     gprint (GP_ERR, " current: %f %f (%f x %f) (%s)\n", 
 	     graphmode.coords.crval1, graphmode.coords.crval2, 
Index: /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/Makefile
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/Makefile	(revision 29815)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/Makefile	(revision 29816)
@@ -36,4 +36,5 @@
 $(SRC)/cut.$(ARCH).o		\
 $(SRC)/delete.$(ARCH).o	\
+$(SRC)/densify.$(ARCH).o	\
 $(SRC)/device.$(ARCH).o	\
 $(SRC)/dimendown.$(ARCH).o	\
Index: /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/densify.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/densify.c	(revision 29816)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/densify.c	(revision 29816)
@@ -0,0 +1,61 @@
+# include "data.h"
+
+int densify (int argc, char **argv) {
+
+  int i, Nx, Ny, Xb, Yb, Normalize, N;
+  float Xmin, Xmax, dX, Ymin, Ymax, dY;
+  float *val;
+  Buffer *bf;
+  Vector *vx, *vy;
+  opihi_flt *x, *y;
+
+  Normalize = TRUE;
+  if ((N = get_argument (argc, argv, "-raw"))) {
+    remove_argument (N, &argc, argv);
+    Normalize = FALSE;
+  }
+
+  if (argc != 10) {
+    gprint (GP_ERR, "USAGE: densify buffer x y Xmin Xmax dX Ymin Ymax dY\n");
+    return (FALSE);
+  }
+  
+  if ((bf = SelectBuffer (argv[1], ANYBUFFER, TRUE)) == NULL) return (FALSE);
+  if ((vx = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);
+  if ((vy = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE);
+
+  if (vx[0].Nelements != vy[0].Nelements) return (FALSE);
+
+  REQUIRE_VECTOR_FLT (vx, FALSE); 
+  REQUIRE_VECTOR_FLT (vy, FALSE); 
+
+  Xmin = atof (argv[4]);
+  Xmax = atof (argv[5]);
+  dX   = atof (argv[6]);
+
+  Ymin = atof (argv[7]);
+  Ymax = atof (argv[8]);
+  dY   = atof (argv[9]);
+
+  Nx = (Xmax - Xmin) / dX + 1;
+  Ny = (Ymax - Ymin) / dY + 1;
+  
+  gfits_free_matrix (&bf[0].matrix);
+  gfits_free_header (&bf[0].header);
+  CreateBuffer (bf, Nx, Ny, -32, 0.0, 1.0);
+  strcpy (bf[0].file, "(empty)");
+
+  x = vx[0].elements.Flt;
+  y = vy[0].elements.Flt;
+  val = (float *)bf[0].matrix.buffer;
+  for (i = 0; i < vx[0].Nelements; i++, x++, y++) {
+    Xb = (*x - Xmin) / dX;
+    Yb = (*y - Ymin) / dY;
+    if (Xb >= Nx) continue;
+    if (Yb >= Ny) continue;
+    if (Xb < 0) continue;
+    if (Yb < 0) continue;
+    val[Xb + Yb*Nx] ++;
+  }
+  return (TRUE);
+}
Index: /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/init.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/init.c	(revision 29815)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/init.c	(revision 29816)
@@ -25,4 +25,5 @@
 int dbselect         PROTO((int, char **));
 int delete           PROTO((int, char **));
+int densify          PROTO((int, char **));
 int device           PROTO((int, char **));
 int dimendown        PROTO((int, char **));
@@ -161,4 +162,5 @@
   {1, "dbselect",     dbselect,         "extract vectors from mysql database table"},
   {1, "delete",       delete,           "delete vectors or images"},
+  {1, "densify",      densify,          "create an image histogram from a set of vectors"},
   {1, "device",       device,           "set / get current graphics device"},
   {1, "dimendown",    dimendown,        "convert image to vector"},
Index: /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/resize.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/resize.c	(revision 29815)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/resize.c	(revision 29816)
@@ -17,4 +17,10 @@
   if (!GetImage (NULL, &kapa, name)) return (FALSE);
   FREE (name);
+
+  if ((N = get_argument (argc, argv, "-by-image"))) {
+    remove_argument (N, &argc, argv);
+    KiiResizeByImage (kapa);
+    return (TRUE);
+  }
 
   if (argc != 3) {
Index: /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/section.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/section.c	(revision 29815)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/section.c	(revision 29816)
@@ -1,5 +1,5 @@
 # include "data.h"
 
-enum {NONE, LIST, UP, DOWN, TOP, BOTTOM, TOOL, BG};
+enum {NONE, LIST, UP, DOWN, TOP, BOTTOM, TOOL, BG, IMAGE};
 
 int section (int argc, char **argv) {
@@ -49,4 +49,9 @@
     remove_argument (N, &argc, argv);
     action = BG;
+  }
+
+  if ((N = get_argument (argc, argv, "-image"))) {
+    remove_argument (N, &argc, argv);
+    action = IMAGE;
   }
 
@@ -130,4 +135,14 @@
   } 
   
+  if (argc == 4) {
+    /* set section */
+    section.name = argv[1];
+    section.x = atof (argv[2]);
+    section.y = atof (argv[3]);
+    section.bg = background;
+    KapaSetSectionByImage (kapa, &section);
+    return (TRUE);
+  }
+
   if (argc == 6) {
     /* set section */
@@ -142,4 +157,5 @@
   }
   gprint (GP_ERR, "USAGE: section name [x y dx dy]\n");
+  gprint (GP_ERR, "USAGE: section name [-image x y] : width based on current image\n");
   gprint (GP_ERR, "USAGE: section name [-list] [-up] [-down] [-top] [-bottom]\n");
   return (FALSE);
Index: /branches/eam_branches/ipp-20101103/Ohana/src/opihi/lib.data/starfuncs.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/opihi/lib.data/starfuncs.c	(revision 29815)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/opihi/lib.data/starfuncs.c	(revision 29816)
@@ -5,5 +5,5 @@
   double *ring;
   double x, y, x2, y2, xy, I, sky, FWHMx, FWHMy, value, mag, Sxy;
-  int i, j, n, Npix2, Nring, Nmax;
+  int i, j, n, Radius, Nring, Nmax;
   double Npts, gain, dsky2, dmag, peak, offset;
   char *string;
@@ -19,6 +19,6 @@
   Nborder = MIN (1000, Nborder);
   
-  Npix2 = (int)(0.5*Npix);
-  Npix = 2 * Npix2 + 1;
+  Radius = (int)(0.5*Npix);
+  Npix = 2 * Radius + 1;
   Nring = 4*Nborder*(Nborder + Npix);
   ALLOCATE (ring, double, Nring);
@@ -27,11 +27,11 @@
   n = 0;  
   for (j = 0; j < Nborder; j++) {
-    for (i = X - Npix2 - Nborder; i < X + Npix2 + Nborder + 1; i++, n+=2) {
-      ring[n]   = gfits_get_matrix_value (matrix, i, (int)(Y - Npix2 - j));
-      ring[n+1] = gfits_get_matrix_value (matrix, i, (int)(Y + Npix2 + j));
-    }
-    for (i = Y - Npix2; i < Y + Npix2 + 1; i++, n+=2) {
-      ring[n]   = gfits_get_matrix_value (matrix, (int)(X - Npix2 - j), i);
-      ring[n+1] = gfits_get_matrix_value (matrix, (int)(X + Npix2 + j), i);
+    for (i = X - Radius - Nborder; i < X + Radius + Nborder + 1; i++, n+=2) {
+      ring[n]   = gfits_get_matrix_value (matrix, i, (int)(Y - Radius - j));
+      ring[n+1] = gfits_get_matrix_value (matrix, i, (int)(Y + Radius + j));
+    }
+    for (i = Y - Radius; i < Y + Radius + 1; i++, n+=2) {
+      ring[n]   = gfits_get_matrix_value (matrix, (int)(X - Radius - j), i);
+      ring[n+1] = gfits_get_matrix_value (matrix, (int)(X + Radius + j), i);
     }
   }
@@ -50,6 +50,7 @@
   Npts = Nmax = 0;
   x = y = x2 = y2 = xy = I = 0;
-  for (i = X - Npix2; i < X + Npix2 + 1; i++) {
-    for (j = Y - Npix2; j < Y + Npix2 + 1; j++) {
+  for (i = X - Radius; i < X + Radius + 1; i++) {
+    for (j = Y - Radius; j < Y + Radius + 1; j++) {
+      if (hypot((i-X), (j-Y)) > Radius) continue;
       value = gfits_get_matrix_value (matrix, i, j);
       offset = value - sky;
@@ -92,4 +93,5 @@
   set_variable ("Zpk", peak);
   set_int_variable ("Nsat", Nmax);
+  set_int_variable ("Npts", Npts);
   
   gprint (GP_LOG, "%f %f %f %f %f %f %f %f\n", x, y, FWHMx, FWHMy, sky, I, mag, dmag);
