Index: /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/StarMaps.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/StarMaps.c	(revision 28685)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/StarMaps.c	(revision 28685)
@@ -0,0 +1,59 @@
+# include "relastro.h"
+
+typedef struct {
+  int  Nx;
+  int  Ny;
+  int *stars;
+} StarMap;
+
+static StarMap     *starmap;         
+static int         Nstarmap;
+
+/** we have two possible options for how the user defines the map bins:
+    a) the user specifies the number of cells in the map, leading to varying binning
+    b) the user specifies the binning factor, leading to variable grid sizes.
+    
+    We want to use (b) since we know the order of the model
+**/
+
+int initStarMaps () {
+
+  Image *images;
+  off_t i, Nimages;
+
+  images = getimages(&Nimages);
+
+  ALLOCATE (starmap, StarMap, Nimages);
+
+  for (i = 0; i < Nimages; i++) {
+    starmap[i].Nx = images[i].NX / NX_MAP;
+    starmap[i].Ny = images[i].NY / NY_MAP;
+    ALLOCATE (starmap[i].stars, int, NX_MAP*NY_MAP);
+    memset (starmap[i].stars, 0, sizeof(int)*NX_MAP*NY_MAP);
+  }
+  return (TRUE);
+}
+
+int updateStarMaps(Catalog *catalog) {
+
+  Image *images;
+  off_t i, Nimages;
+
+  images = getimages(&Nimages);
+
+  for (i = 0; i < catalog[0].Nmeasure; i++) {
+    
+    N = getImageByID(catalog[0].measure[i].imageID);
+    if (N < 0) continue;
+
+    xbin = catalog[0].measure[i].Xccd / starmap[N].Nx;
+    ybin = catalog[0].measure[i].Yccd / starmap[N].Ny;
+
+    xbin = MAX(0, MIN(NX_MAP-1, xbin));
+    ybin = MAX(0, MIN(NY_MAP-1, ybin));
+
+    starmap[N].stars[ybin*NX_MAP + xbin] ++;
+  }
+
+  return (TRUE);
+}
Index: /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/load_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/load_catalogs.c	(revision 28684)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relastro/src/load_catalogs.c	(revision 28685)
@@ -9,4 +9,6 @@
 
   ALLOCATE (catalog, Catalog, skylist[0].Nregions);
+
+  initStarMaps();
 
   // load data from each region file, only use bright stars
@@ -36,4 +38,6 @@
 
     // XXX mark the image grid based on the loaded detections
+    // XXX modify tcatalog to exclude any photcode or other choices that only affect image selection?
+    updateStarMaps (&tcatalog);
 
     // select only the brighter stars
