Index: trunk/Ohana/src/opihi/cmd.astro/cdhistogram.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/cdhistogram.c	(revision 41340)
+++ trunk/Ohana/src/opihi/cmd.astro/cdhistogram.c	(revision 41341)
@@ -13,4 +13,11 @@
   int kapa;
   Graphdata graphmode;
+
+  int binning = 1;
+  if ((N = get_argument (argc, argv, "-binning"))) {
+    remove_argument (N, &argc, argv);
+    binning = atoi(argv[N]);
+    remove_argument (N, &argc, argv);
+  }
 
   range = NULL;
@@ -79,6 +86,9 @@
   Ymax = graphmode.ymax;
   Ymin = graphmode.ymin;
-  dX = (Xmax - Xmin) / (Xpix - 1);
-  dY = (Ymax - Ymin) / (Ypix - 1);
+
+  // (dX, dY) are the pixel scale of the output image (output pixels / input pixels)
+
+  dX = binning * (Xmax - Xmin) / (Xpix - 1);
+  dY = binning * (Ymax - Ymin) / (Ypix - 1);
 
   CHECKVAL(Xmin);
@@ -90,6 +100,6 @@
   CHECKVAL(dY);
 
-  int Nx = (Xmax - Xmin) / dX + 1;
-  int Ny = (Ymax - Ymin) / dY + 1;
+  int Nx = abs((Xmax - Xmin) / dX) + 1;
+  int Ny = abs((Ymax - Ymin) / dY) + 1;
   
   Coords newcoords = graphmode.coords;
