Index: /branches/eam_branches/ipp-20121130/Ohana/src/addstar/src/findskycell.c
===================================================================
--- /branches/eam_branches/ipp-20121130/Ohana/src/addstar/src/findskycell.c	(revision 34829)
+++ /branches/eam_branches/ipp-20121130/Ohana/src/addstar/src/findskycell.c	(revision 34830)
@@ -149,6 +149,6 @@
   ALLOCATE (tree.ra,   double *, tree.Nzone);
   ALLOCATE (tree.dec,  double *, tree.Nzone);
-  ALLOCATE (tree.Xo,      int *, tree.Nzone);
-  ALLOCATE (tree.Yo,      int *, tree.Nzone);
+  ALLOCATE (tree.Xo,   double *, tree.Nzone);
+  ALLOCATE (tree.Yo,   double *, tree.Nzone);
   ALLOCATE (tree.dX,      int *, tree.Nzone);
   ALLOCATE (tree.dY,      int *, tree.Nzone);
@@ -183,6 +183,6 @@
     ALLOCATE (tree.ra[zone],   double, tree.NBAND[zone]);
     ALLOCATE (tree.dec[zone],  double, tree.NBAND[zone]);
-    ALLOCATE (tree.Xo[zone],      int, tree.NBAND[zone]);
-    ALLOCATE (tree.Yo[zone],      int, tree.NBAND[zone]);
+    ALLOCATE (tree.Xo[zone],   double, tree.NBAND[zone]);
+    ALLOCATE (tree.Yo[zone],   double, tree.NBAND[zone]);
     ALLOCATE (tree.dX[zone],      int, tree.NBAND[zone]);
     ALLOCATE (tree.dY[zone],      int, tree.NBAND[zone]);
@@ -192,6 +192,6 @@
       tree.ra[zone][band] = NAN;
       tree.dec[zone][band] = NAN;
-      tree.Xo[zone][band] = -1;
-      tree.Yo[zone][band] = -1;
+      tree.Xo[zone][band] = NAN;
+      tree.Yo[zone][band] = NAN;
       tree.dX[zone][band] = -1;
       tree.dY[zone][band] = -1;
@@ -218,6 +218,6 @@
       REALLOCATE (tree.ra[zone],   double, tree.NBAND[zone]);
       REALLOCATE (tree.dec[zone],  double, tree.NBAND[zone]);
-      REALLOCATE (tree.Xo[zone],      int, tree.NBAND[zone]);
-      REALLOCATE (tree.Yo[zone],      int, tree.NBAND[zone]);
+      REALLOCATE (tree.Xo[zone],   double, tree.NBAND[zone]);
+      REALLOCATE (tree.Yo[zone],   double, tree.NBAND[zone]);
       REALLOCATE (tree.dX[zone],      int, tree.NBAND[zone]);
       REALLOCATE (tree.dY[zone],      int, tree.NBAND[zone]);
@@ -227,6 +227,6 @@
 	tree.ra[zone][j] = NAN;
 	tree.dec[zone][j] = NAN;
-	tree.Xo[zone][band] = -1;
-	tree.Yo[zone][band] = -1;
+	tree.Xo[zone][band] = NAN;
+	tree.Yo[zone][band] = NAN;
 	tree.dX[zone][band] = -1;
 	tree.dY[zone][band] = -1;
@@ -377,6 +377,4 @@
     }
 
-    fprintf (stdout, "%10.6f %10.6f  %3d %3d  %s\n", ra, dec, zone, band, tree->name[zone][band]);
-
     // I know the projection cell (band,zone), but I need to find the skycell within that projection cell.
     // the proj cell is divided into Nx, Ny bits.
@@ -390,5 +388,4 @@
     double y = 0.0;
     BoundaryTreeProjection (&x, &y, ra, dec, tree, zone, band);
-    fprintf (stdout, "%6.1f %6.1f\n", x, y);
 
     int xi = x / tree->dX[zone][band];
@@ -402,5 +399,5 @@
     snprintf (skycellname, 128, format, N);
 
-    fprintf (stderr, "skycell: %s\n", skycellname);
+    fprintf (stdout, "%10.6f %10.6f  %8.3f %8.3f  %3d %3d  %s\n", ra, dec, x, y, zone, band, skycellname);
   }
 
Index: /branches/eam_branches/ipp-20121130/Ohana/src/addstar/src/sky_tessalation.c
===================================================================
--- /branches/eam_branches/ipp-20121130/Ohana/src/addstar/src/sky_tessalation.c	(revision 34829)
+++ /branches/eam_branches/ipp-20121130/Ohana/src/addstar/src/sky_tessalation.c	(revision 34830)
@@ -275,5 +275,5 @@
       // convert the SkyRectangles to Images for output
       sky_subdivide_image (&image[j*NX_SUB*NY_SUB], &ring[j], NX_SUB, NY_SUB);
-      printf("%s %8.2f %8.2f\n", ring[j].name, ring[j].coords.crval1, ring[j].coords.crval2);
+      // printf("%s %8.2f %8.2f\n", ring[j].name, ring[j].coords.crval1, ring[j].coords.crval2);
     }
 
@@ -691,5 +691,5 @@
     // fprintf (stdout, "%f %f  %f  %f  %f %f  %f %f  %f %f %f\n", dec, decUpper, dRA, arg, root1, root2, theta1, theta2, r1, r2, k*r2);
   }
-  fprintf (stdout, "%f %f  %f x %f (%d)\n", dec, decUpper, dRA, theta, nRA);
+  // fprintf (stdout, "%f %f  %f x %f (%d)\n", dec, decUpper, dRA, theta, nRA);
 
   // I think we need to return the value of dec for the next ring, but I am not sure...
@@ -776,5 +776,5 @@
       ring[N].coords.crval2 = (j == 0) ? dec / d2r : -dec / d2r;
 
-      printf(" \t %d   %25.20f   %25.20f\n", i, ring[N].coords.crval2, ring[N].coords.crval1);
+      // printf(" \t %d   %25.20f   %25.20f\n", i, ring[N].coords.crval2, ring[N].coords.crval1);
 
       ring[N].coords.pc1_1 = +1.0 * X_PARITY;
Index: /branches/eam_branches/ipp-20121130/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branches/ipp-20121130/Ohana/src/libdvo/include/dvo.h	(revision 34829)
+++ /branches/eam_branches/ipp-20121130/Ohana/src/libdvo/include/dvo.h	(revision 34830)
@@ -331,6 +331,6 @@
   double dPix;
 
-  int **Xo;
-  int **Yo;
+  double **Xo;
+  double **Yo;
   int **dX;
   int **dY;
Index: /branches/eam_branches/ipp-20121130/Ohana/src/libdvo/src/BoundaryTree.c
===================================================================
--- /branches/eam_branches/ipp-20121130/Ohana/src/libdvo/src/BoundaryTree.c	(revision 34829)
+++ /branches/eam_branches/ipp-20121130/Ohana/src/libdvo/src/BoundaryTree.c	(revision 34830)
@@ -79,6 +79,6 @@
     ALLOCATE (tree->ra,   double *, tree->Nzone);
     ALLOCATE (tree->dec,  double *, tree->Nzone);
-    ALLOCATE (tree->Xo,      int *, tree->Nzone);
-    ALLOCATE (tree->Yo,      int *, tree->Nzone);
+    ALLOCATE (tree->Xo,   double *, tree->Nzone);
+    ALLOCATE (tree->Yo,   double *, tree->Nzone);
     ALLOCATE (tree->dX,      int *, tree->Nzone);
     ALLOCATE (tree->dY,      int *, tree->Nzone);
@@ -88,6 +88,6 @@
       ALLOCATE (tree->ra[i],   double, tree->Nband[i]);
       ALLOCATE (tree->dec[i],  double, tree->Nband[i]);
-      ALLOCATE (tree->Xo[i],      int, tree->Nband[i]);
-      ALLOCATE (tree->Yo[i],      int, tree->Nband[i]);
+      ALLOCATE (tree->Xo[i],   double, tree->Nband[i]);
+      ALLOCATE (tree->Yo[i],   double, tree->Nband[i]);
       ALLOCATE (tree->dX[i],      int, tree->Nband[i]);
       ALLOCATE (tree->dY[i],      int, tree->Nband[i]);
@@ -114,6 +114,6 @@
     GET_COLUMN_NEW(band,  "BAND",        int);
     GET_COLUMN_NEW(index, "INDEX",       int);
-    GET_COLUMN_NEW(Xo,    "X_CENT",      int);
-    GET_COLUMN_NEW(Yo,    "Y_CENT",      int);
+    GET_COLUMN_NEW(Xo,    "X_CENT",      double);
+    GET_COLUMN_NEW(Yo,    "Y_CENT",      double);
     GET_COLUMN_NEW(dX,    "X_GRID",      int);
     GET_COLUMN_NEW(dY,    "Y_GRID",      int);
@@ -251,6 +251,6 @@
     gfits_define_bintable_column (&theader, "J", "BAND", "band sequence number", "none", 1.0, 0.0);
     gfits_define_bintable_column (&theader, "J", "INDEX","cell index", "none", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "J", "X_CENT", "projection cell center pixel", "none", 1.0, 0.0);
-    gfits_define_bintable_column (&theader, "J", "Y_CENT", "projection cell center pixel", "none", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "D", "X_CENT", "projection cell center pixel", "none", 1.0, 0.0);
+    gfits_define_bintable_column (&theader, "D", "Y_CENT", "projection cell center pixel", "none", 1.0, 0.0);
     gfits_define_bintable_column (&theader, "J", "X_GRID", "skycell grid spacing", "none", 1.0, 0.0);
     gfits_define_bintable_column (&theader, "J", "Y_GRID", "skycell grid spacing", "none", 1.0, 0.0);
@@ -272,6 +272,6 @@
     int    *band          ; ALLOCATE (band,  int,    Ncell);
     int    *index         ; ALLOCATE (index, int,    Ncell);
-    int    *Xo            ; ALLOCATE (Xo,    int,    Ncell);
-    int    *Yo            ; ALLOCATE (Yo,    int,    Ncell);
+    double *Xo            ; ALLOCATE (Xo,    double, Ncell);
+    double *Yo            ; ALLOCATE (Yo,    double, Ncell);
     int    *dX            ; ALLOCATE (dX,    int,    Ncell);
     int    *dY            ; ALLOCATE (dY,    int,    Ncell);
@@ -372,6 +372,6 @@
 int BoundaryTreeProjection (double *x, double *y, double r, double d, BoundaryTree *tree, int zone, int band) {
 
-    double Xo = tree->Yo[zone][band];
-    double Yo = tree->Xo[zone][band];
+    double Xo = tree->Xo[zone][band];
+    double Yo = tree->Yo[zone][band];
     double Ro = tree->ra[zone][band];
     double Do = tree->dec[zone][band];
Index: /branches/eam_branches/ipp-20121130/Ohana/src/opihi/dvo/gimages.c
===================================================================
--- /branches/eam_branches/ipp-20121130/Ohana/src/opihi/dvo/gimages.c	(revision 34829)
+++ /branches/eam_branches/ipp-20121130/Ohana/src/opihi/dvo/gimages.c	(revision 34830)
@@ -212,4 +212,6 @@
 	status = XY_to_RD (&Rout, &Dout, X, Y, &image[i].coords);
 	fprintf (stderr, "r,d = %f,%f\n", Rout, Dout);
+	status = RD_to_XY (&X, &Y, Ra, Dec, &image[i].coords);
+	fprintf (stderr, "x,y = %f,%f\n", X, Y);
     }
 # endif
Index: /branches/eam_branches/ipp-20121130/Ohana/src/relphot/src/BoundaryTreeOps.c
===================================================================
--- /branches/eam_branches/ipp-20121130/Ohana/src/relphot/src/BoundaryTreeOps.c	(revision 34829)
+++ /branches/eam_branches/ipp-20121130/Ohana/src/relphot/src/BoundaryTreeOps.c	(revision 34830)
@@ -21,8 +21,28 @@
   }
   
+# 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;
Index: /branches/eam_branches/ipp-20121130/Ohana/src/relphot/src/ImageOps.c
===================================================================
--- /branches/eam_branches/ipp-20121130/Ohana/src/relphot/src/ImageOps.c	(revision 34829)
+++ /branches/eam_branches/ipp-20121130/Ohana/src/relphot/src/ImageOps.c	(revision 34830)
@@ -400,7 +400,9 @@
   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
+  // 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;
Index: /branches/eam_branches/ipp-20121130/Ohana/src/relphot/src/StarOps.c
===================================================================
--- /branches/eam_branches/ipp-20121130/Ohana/src/relphot/src/StarOps.c	(revision 34829)
+++ /branches/eam_branches/ipp-20121130/Ohana/src/relphot/src/StarOps.c	(revision 34830)
@@ -363,4 +363,5 @@
 
     if (isSetMrelFinal) {
+      // set the name of the primary skycell (this is used in a strcmp to match the skycells in stack detections)
       BoundaryTreePrimaryCell(primaryCell, catalog[Nc].average[j].R, catalog[Nc].average[j].D);
     }
