Index: /branches/eam_branches/ipp-20130509/Ohana/src/relphot/src/BoundaryTreeOps.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relphot/src/BoundaryTreeOps.c	(revision 35734)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relphot/src/BoundaryTreeOps.c	(revision 35735)
@@ -7,4 +7,47 @@
 
 int BoundaryTreePrimaryCell (char *primaryCellName, double ra, double dec) {
+
+  int zone, band;
+
+  if (!primaryCellName) return FALSE;
+
+  primaryCellName[0] = 0;
+
+  if (!tree) return FALSE;
+
+  if (!BoundaryTreeCellCoords (tree, &zone, &band, ra, dec)) {
+    fprintf (stderr, "mismatch!\n");
+    return FALSE;
+  }
+  
+# define USE_PROJECTION_CELL 0
+# if (USE_PROJECTION_CELL)
+  snprintf (primaryCellName, DVO_MAX_PATH, "RINGS.V3.%s", tree->name[zone][band]);
+# else
+
+  // I have ra, dec, and the primary projection cell.  In order to choose the primary skycell,
+  // I just need to project to ra,dec to X,Y based on the center of the cell and then get the subdivision right.
+    
+  double x = 0.0;
+  double y = 0.0;
+  BoundaryTreeProjection (&x, &y, ra, dec, tree, zone, band);
+  
+  int xi = x / tree->dX[zone][band];
+  int yi = y / tree->dY[zone][band];
+  int N = xi + tree->NX_SUB * yi;
+  
+  // XXX short-circuit this for now (we should use this code if we make tree have more variable NX,NY values
+  // char format[24], skycellname[128];
+  // int Ndigit = (int)(log10(tree->NX_SUB*tree->NY_SUB)) + 1 ;
+  // snprintf (format, 24, "%s.%%0%dd", tree->name[zone][band], Ndigit);
+  // snprintf (skycellname, 128, format, N);
+
+  snprintf (primaryCellName, DVO_MAX_PATH, "RINGS.V3.%s.%03d", tree->name[zone][band], N);
+# endif
+
+  return TRUE;
+}
+
+int BoundaryTreePrimaryCellIDs (int *projID, int *skycellID, double ra, double dec) {
 
   int zone, band;
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relphot/src/ImageOps.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relphot/src/ImageOps.c	(revision 35734)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relphot/src/ImageOps.c	(revision 35735)
@@ -414,4 +414,27 @@
 // returns image.Mcal - ff(x,y)
 int MatchImageName (off_t meas, int cat, char *name) {
+
+  off_t i;
+
+  if (!name) return FALSE;
+  if (!name[0]) return FALSE;
+
+  if (!MeasureToImage) return FALSE;
+
+  i = MeasureToImage[cat][meas];
+  if (i == -1) return FALSE;
+
+  // this is a bit crude: stack image names are of the form:
+  // RINGS.V3.skycell.1495.027.sky.191211.stk.988232.cmf.
+
+  // the primaryCell has a name of the form RINGS.V3.skycell.1495 or RINGS.V3.skycell.1495.027
+  // (if we use projection or skycell as the primary)
+
+  if (!strncmp(image[i].name, name, strlen(name))) return TRUE;
+  return FALSE;
+}
+
+// returns image.Mcal - ff(x,y)
+int MatchImageSkycellID (off_t meas, int cat, char *name) {
 
   off_t i;
