Index: trunk/Ohana/src/opihi/cmd.data/Makefile
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/Makefile	(revision 29540)
+++ trunk/Ohana/src/opihi/cmd.data/Makefile	(revision 29938)
@@ -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: trunk/Ohana/src/opihi/cmd.data/densify.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/densify.c	(revision 29938)
+++ trunk/Ohana/src/opihi/cmd.data/densify.c	(revision 29938)
@@ -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: trunk/Ohana/src/opihi/cmd.data/init.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/init.c	(revision 29540)
+++ trunk/Ohana/src/opihi/cmd.data/init.c	(revision 29938)
@@ -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: trunk/Ohana/src/opihi/cmd.data/rd.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/rd.c	(revision 29540)
+++ trunk/Ohana/src/opihi/cmd.data/rd.c	(revision 29938)
@@ -184,5 +184,5 @@
     ftable.header[0].buffer = NULL;
     gfits_copy_header (&buf[0].header, ftable.header);
-    status = gfits_fread_ftable_data (f, &ftable);  // this just reads the bytes (not even a SWAP)
+    status = gfits_fread_ftable_data (f, &ftable, FALSE);  // this just reads the bytes (not even a SWAP)
     status = gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable);
     // uncompressing the image leaves the format as an extension
Index: trunk/Ohana/src/opihi/cmd.data/read_vectors.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/read_vectors.c	(revision 29540)
+++ trunk/Ohana/src/opihi/cmd.data/read_vectors.c	(revision 29938)
@@ -160,5 +160,5 @@
 
   off_t Nbytes;
-  int i, j, k, N, Nextend, Ny, Binary, vecType;
+  int i, j, k, N, Nextend, Ny, Binary, vecType, padIfShort;
   char type[16], ID[80], *CCDKeyword;
   FTable table;
@@ -174,4 +174,10 @@
     CCDKeyword = strcreate (argv[N]);
     remove_argument (N, &argc, argv);
+  }
+
+  padIfShort = FALSE;
+  if ((N = get_argument (argc, argv, "-pad-if-short"))) {
+    remove_argument (N, &argc, argv);
+    padIfShort = TRUE;
   }
 
@@ -205,5 +211,5 @@
     }
     if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension");
-    if (!gfits_fread_ftable_data (f, &table)) ESCAPE ("error reading table for extension");
+    if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension");
 
   } else {
@@ -236,5 +242,5 @@
 	continue;
       }
-      if (!gfits_fread_ftable_data (f, &table)) ESCAPE ("error reading table for extension");
+      if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension");
       break;
     }
Index: trunk/Ohana/src/opihi/cmd.data/resize.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/resize.c	(revision 29540)
+++ trunk/Ohana/src/opihi/cmd.data/resize.c	(revision 29938)
@@ -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: trunk/Ohana/src/opihi/cmd.data/section.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/section.c	(revision 29540)
+++ trunk/Ohana/src/opihi/cmd.data/section.c	(revision 29938)
@@ -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: trunk/Ohana/src/opihi/cmd.data/vgauss.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/vgauss.c	(revision 29540)
+++ trunk/Ohana/src/opihi/cmd.data/vgauss.c	(revision 29938)
@@ -45,4 +45,6 @@
   CastVector (yvec, OPIHI_FLT);
   CastVector (svec, OPIHI_FLT);
+  // XXX Cast is failing.
+    
 
   Npts = xvec[0].Nelements;
