Index: trunk/Ohana/src/relastro/src/bcatalog.c
===================================================================
--- trunk/Ohana/src/relastro/src/bcatalog.c	(revision 39993)
+++ trunk/Ohana/src/relastro/src/bcatalog.c	(revision 39994)
@@ -459,6 +459,6 @@
     if (isnan(X[i])) continue;
     if (isnan(Y[i])) continue;
-    ix = (X[i] - Xmin) / 200.0;
-    iy = (Y[i] - Ymin) / 200.0;
+    ix = MIN(0, MAX(NX - 1, (X[i] - Xmin) / 200.0));
+    iy = MIN(0, MAX(NY - 1, (Y[i] - Ymin) / 200.0));
     int Nn = Nn_grid[ix][iy];
     Nm_grid[ix][iy][Nn] = subcatalog[0].average[i].Nmeasure;
@@ -500,5 +500,5 @@
   }
 
-  // cycle over the grid until we ready Nmax
+  // cycle over the grid until we reach Nmax
   off_t *keepidx = NULL;
   ALLOCATE (keepidx, off_t, Naverage);
