Index: /trunk/Ohana/src/relphot/include/relphot.h
===================================================================
--- /trunk/Ohana/src/relphot/include/relphot.h	(revision 36490)
+++ /trunk/Ohana/src/relphot/include/relphot.h	(revision 36491)
@@ -116,4 +116,5 @@
   unsigned int photom_map_id;
   unsigned int flags;
+  int tessID;
   int projID;
   int skycellID;
@@ -401,9 +402,12 @@
 
 int MatchImageName (off_t meas, int cat, char *name);
-int MatchImageSkycellID (off_t meas, int cat, int myProjectionID, int mySkycellID);
-
-int load_tree (char *treefile);
-int BoundaryTreePrimaryCell (char *primaryCellName, double ra, double dec);
-int BoundaryTreePrimaryCellIDs (int *projID, int *skycellID, double ra, double dec);
+int MatchImageSkycellID (off_t meas, int cat, int myTessID, int myProjectionID, int mySkycellID);
+
+int load_tess (char *treefile);
+int get_tess_ids (int *tessID, int *projID, int *skycellID, double ra, double dec);
+int TessellationIDsByImageName (int *tessID, int *projID, int *skycellID, char *name);
+
+// int BoundaryTreePrimaryCell (char *primaryCellName, double ra, double dec);
+// int BoundaryTreePrimaryCellIDs (int *projID, int *skycellID, double ra, double dec);
 
 int print_measure_set_alt (Average *average, SecFilt *secfilt, Measure *measure);
Index: /trunk/Ohana/src/relphot/src/BoundaryTreeOps.c
===================================================================
--- /trunk/Ohana/src/relphot/src/BoundaryTreeOps.c	(revision 36490)
+++ /trunk/Ohana/src/relphot/src/BoundaryTreeOps.c	(revision 36491)
@@ -1,88 +1,42 @@
 # include "relphot.h"
 
-// XXX for the moment, only load one boundary tree at a time
-// XXX in fact, only allow RINGS.V3...
+static int Ntess = 0;
+static TessellationTable *tess = NULL;
 
-static BoundaryTree *tree = NULL;
+int TessellationIDsByImageName (int *tessID, int *projID, int *skycellID, char *name) {
 
-int BoundaryTreePrimaryCell (char *primaryCellName, double ra, double dec) {
+  int i;
 
-  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;
-
+  *tessID = -1;
   *projID = -1;
   *skycellID = -1;
 
-  if (!tree) return FALSE;
+  if (!tess) return FALSE;
 
-  if (!BoundaryTreeCellCoords (tree, &zone, &band, ra, dec)) {
-    fprintf (stderr, "mismatch!\n");
-    return FALSE;
+  for (i = 0; i < Ntess; i++) {
+    // do this with a strhash of some kind?
+    if (!strncmp (name, tess[i].basename, tess[i].Nbasename)) {
+      *tessID    = i;
+      if (tess[i].projectIDoff >= 0) {
+	*projID    = atoi(&name[tess[i].projectIDoff]);
+      } else {
+	*projID    = 0;
+      }
+      if (tess[i].skycellIDoff >= 0) {
+	*skycellID = atoi(&name[tess[i].skycellIDoff]);
+      } else {
+	*skycellID = 0;
+      }
+      return TRUE;
+    }
   }
-  
-  // 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;
-  
-  *projID = tree->projID[zone][band];
-  *skycellID = N;
-
-  return TRUE;
+  return FALSE;
 }
 
-int load_tree (char *treefile) {
+int load_tess (char *tessfile) {
 
-  tree = BoundaryTreeLoad (treefile);
-  if (!tree) {
-    fprintf (stderr, "failed to load boundary tree %s\n", treefile);
+  tess = TessellationTableLoad (tessfile, &Ntess);
+  if (!tess) {
+    fprintf (stderr, "failed to load tessellation boundary file %s\n", tessfile);
     exit (2);
   }
@@ -90,2 +44,12 @@
   return TRUE;
 }
+
+int get_tess_ids (int *tessID, int *projID, int *skycellID, double ra, double dec) {
+
+  int status;
+
+  if (!tess) return FALSE;
+
+  status = TessellationPrimaryCellIDs(tess, Ntess, tessID, projID, skycellID, ra, dec);
+  return status;
+}
Index: /trunk/Ohana/src/relphot/src/ImageOps.c
===================================================================
--- /trunk/Ohana/src/relphot/src/ImageOps.c	(revision 36490)
+++ /trunk/Ohana/src/relphot/src/ImageOps.c	(revision 36491)
@@ -48,4 +48,5 @@
 // stack image.  for now, we generate these ID arrays based on the image names when we load in the image table (initImages).
 // When we pass data to the remote clients via the ImageSubset, the projID/skycellID values are carried directly in the table.
+int *tessID    = NULL;
 int *projectID = NULL;
 int *skycellID = NULL;
@@ -81,4 +82,5 @@
 
   // for stack images, assign projection cell ID and skycell ID based on filenames
+  ALLOCATE (tessID,      int, Nimage);
   ALLOCATE (projectID,   int, Nimage);
   ALLOCATE (skycellID,   int, Nimage);
@@ -87,13 +89,14 @@
     imageIdx[i] = i;
     imageIDs[i] = image[i].imageID;
+
+    tessID[i]    = -1;
     projectID[i] = -1;
     skycellID[i] = -1;
-    if (!strncmp (image[i].name, "RINGS.V3.skycell", strlen("RINGS.V3.skycell"))) {
-      projectID[i] = atoi(&image[i].name[17]);
-      skycellID[i] = atoi(&image[i].name[22]);
-    }
+
+    TessellationIDsByImageName (&tessID[i], &projectID[i], &skycellID[i], image[i].name);
   }
 
   // sort the image index by the IDs
+  // XXX does this break the imageID <-> projectID, etc match?
   llsortpair (imageIDs, imageIdx, Nimage);
 }
@@ -106,4 +109,6 @@
   // create full a Image array and save the needed values
   ALLOCATE (image, Image, N);
+
+  ALLOCATE (tessID,    int, N);
   ALLOCATE (projectID, int, N);
   ALLOCATE (skycellID, int, N);
@@ -118,4 +123,5 @@
     image[i].trate         = input[i].trate        ;
     image[i].ubercalDist   = input[i].ubercalDist  ;
+    tessID[i]              = input[i].tessID       ;
     projectID[i]           = input[i].projID       ;
     skycellID[i]           = input[i].skycellID    ;
@@ -153,4 +159,5 @@
     subset[i].trate         = image[i].trate        ;
     subset[i].ubercalDist   = image[i].ubercalDist  ;
+    subset[i].tessID        = tessID[i];
     subset[i].projID        = projectID[i];
     subset[i].skycellID     = skycellID[i];
@@ -461,5 +468,5 @@
 
 // returns image.Mcal - ff(x,y)
-int MatchImageSkycellID (off_t meas, int cat, int myProjectionID, int mySkycellID) {
+int MatchImageSkycellID (off_t meas, int cat, int myTessID, int myProjectionID, int mySkycellID) {
 
   off_t i;
@@ -470,7 +477,9 @@
   if (i == -1) return FALSE;
 
+  if (tessID[i]    == -1) return FALSE;
   if (projectID[i] == -1) return FALSE;
   if (skycellID[i] == -1) return FALSE;
 
+  if (tessID[i]    != myTessID) return FALSE;
   if (projectID[i] != myProjectionID) return FALSE;
   if (skycellID[i] != mySkycellID) return FALSE;
Index: /trunk/Ohana/src/relphot/src/ImageSubset.c
===================================================================
--- /trunk/Ohana/src/relphot/src/ImageSubset.c	(revision 36490)
+++ /trunk/Ohana/src/relphot/src/ImageSubset.c	(revision 36491)
@@ -63,4 +63,5 @@
   GET_COLUMN (map,     	 "PHOTOM_MAP",   int);
   GET_COLUMN (flags,   	 "FLAGS",        int);
+  GET_COLUMN (tessID,  	 "TESS_ID",      int);
   GET_COLUMN (projID,  	 "PROJ_ID",      int);
   GET_COLUMN (skycellID, "SKYCELL_ID",   int);
@@ -78,4 +79,5 @@
     image[i].photom_map_id = map[i];
     image[i].flags         = flags[i];
+    image[i].tessID        = tessID[i];
     image[i].projID        = projID[i];
     image[i].skycellID     = skycellID[i];
@@ -91,4 +93,5 @@
   free (map);
   free (flags);
+  free (tessID);
   free (projID);
   free (skycellID);
@@ -130,4 +133,5 @@
   gfits_define_bintable_column (&theader, "J", "FLAGS", "flags", NULL, 1.0, 1.0*0x8000);
 
+  gfits_define_bintable_column (&theader, "J", "TESS_ID", "ID", NULL, 1.0, 0.0);
   gfits_define_bintable_column (&theader, "J", "PROJ_ID", "ID", NULL, 1.0, 0.0);
   gfits_define_bintable_column (&theader, "J", "SKYCELL_ID", "ID", NULL, 1.0, 0.0);
@@ -143,5 +147,5 @@
   float *Mcal, *dMcal;
   unsigned int *imageID, *map, *flags, *tzero;
-  int *projID, *skycellID;
+  int *tessID, *projID, *skycellID;
   unsigned short *trate;
   short *ucdist;
@@ -153,4 +157,5 @@
   ALLOCATE (map,       unsigned int,   Nimage);
   ALLOCATE (flags,     unsigned int,   Nimage);
+  ALLOCATE (tessID,    int,            Nimage);
   ALLOCATE (projID,    int,            Nimage);
   ALLOCATE (skycellID, int,            Nimage);
@@ -169,4 +174,5 @@
     trate[i]     = image[i].trate;
     ucdist[i]    = image[i].ubercalDist;
+    tessID[i]    = image[i].tessID;
     projID[i]    = image[i].projID;
     skycellID[i] = image[i].skycellID;
@@ -179,4 +185,5 @@
   gfits_set_bintable_column (&theader, &ftable, "PHOTOM_MAP",   map,       Nimage);
   gfits_set_bintable_column (&theader, &ftable, "FLAGS",        flags,     Nimage);
+  gfits_set_bintable_column (&theader, &ftable, "TESS_ID",      tessID,    Nimage);
   gfits_set_bintable_column (&theader, &ftable, "PROJ_ID",      projID,    Nimage);
   gfits_set_bintable_column (&theader, &ftable, "SKYCELL_ID",   skycellID, Nimage);
@@ -190,4 +197,5 @@
   free (map);
   free (flags);
+  free (tessID);
   free (projID);
   free (skycellID);
Index: /trunk/Ohana/src/relphot/src/MosaicOps.c
===================================================================
--- /trunk/Ohana/src/relphot/src/MosaicOps.c	(revision 36490)
+++ /trunk/Ohana/src/relphot/src/MosaicOps.c	(revision 36491)
@@ -412,5 +412,5 @@
     }
     dS /= MosaicN_Image[i];
-    strcpy (mosaic[i].coords.ctype, "RA---TAN");
+    strcpy (mosaic[i].coords.ctype, "DEC--TAN");
     mosaic[i].coords.crval1 = Rmin;
     mosaic[i].coords.crval2 = Dmin;
Index: /trunk/Ohana/src/relphot/src/StarOps.c
===================================================================
--- /trunk/Ohana/src/relphot/src/StarOps.c	(revision 36490)
+++ /trunk/Ohana/src/relphot/src/StarOps.c	(revision 36491)
@@ -328,4 +328,7 @@
 int setMrel_catalog (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt) {
 
+  fprintf (stderr, "??? should you still be using the old version of setMrel_catalog??\n");
+  exit (3);
+
   off_t j, k, m, ID;
   int N;
@@ -366,5 +369,6 @@
     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);
+      // XXX : this whole function is deprecated
+      // BoundaryTreePrimaryCell(primaryCell, catalog[Nc].average[j].R, catalog[Nc].average[j].D);
     }
 
Index: /trunk/Ohana/src/relphot/src/args.c
===================================================================
--- /trunk/Ohana/src/relphot/src/args.c	(revision 36490)
+++ /trunk/Ohana/src/relphot/src/args.c	(revision 36491)
@@ -217,9 +217,11 @@
   }
 
+  // XXX should we load a tree from CATDIR by default?
+  // NOTE: a given catdir needs an appropriate boundary tree
   BOUNDARY_TREE = NULL;
   if ((N = get_argument (argc, argv, "-boundary-tree"))) {
     remove_argument (N, &argc, argv);
     BOUNDARY_TREE = strcreate(argv[N]);
-    load_tree (BOUNDARY_TREE);
+    load_tess (BOUNDARY_TREE);
     remove_argument (N, &argc, argv);
   }
@@ -424,5 +426,5 @@
     remove_argument (N, &argc, argv);
     BOUNDARY_TREE = strcreate(argv[N]);
-    load_tree (BOUNDARY_TREE);
+    load_tess (BOUNDARY_TREE);
     remove_argument (N, &argc, argv);
   }
Index: /trunk/Ohana/src/relphot/src/select_images.c
===================================================================
--- /trunk/Ohana/src/relphot/src/select_images.c	(revision 36490)
+++ /trunk/Ohana/src/relphot/src/select_images.c	(revision 36491)
@@ -40,5 +40,5 @@
   tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
   tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
-  strcpy (tcoords.ctype, "RA---TAN");
+  strcpy (tcoords.ctype, "DEC--TAN");
 
   double RminSkyRegion = region[0].Rmin;
@@ -412,5 +412,5 @@
   tcoords.Npolyterms = 0;
   memset (tcoords.polyterms, 0, 14*sizeof(float));
-  strcpy (tcoords.ctype, "RA---TAN");
+  strcpy (tcoords.ctype, "DEC--TAN");
 
   /* compare with each region file */
Index: /trunk/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- /trunk/Ohana/src/relphot/src/setMrelCatalog.c	(revision 36490)
+++ /trunk/Ohana/src/relphot/src/setMrelCatalog.c	(revision 36491)
@@ -405,9 +405,9 @@
   float Msys = 0, Mcal= 0, Mmos = 0, Mgrid = 0;
 
-  // set the name of the primary skycell (this is used in a strcmp to match the skycells in stack detections)
-  // XXX drop BoundaryTreePrimaryCell(primaryCell, average[0].R, average[0].D);
+  // set the primary projection cell and skycell for this coordinate
+  int tessID    = -1;
   int projectID = -1;
   int skycellID = -1;
-  BoundaryTreePrimaryCellIDs(&projectID, &skycellID, average[0].R, average[0].D);
+  get_tess_ids(&tessID, &projectID, &skycellID, average[0].R, average[0].D);
 
   int NstackGood = 0;
@@ -477,5 +477,5 @@
       // which stack image should we use for the mean value?
       // if we request the primary (USE_TREE_FOR_PRIMARY), then find the min distances for data from the primary cell
-      if (MatchImageSkycellID (meas, cat, projectID, skycellID)) {
+      if (MatchImageSkycellID (meas, cat, tessID, projectID, skycellID)) {
 	float stackPrimaryOffset = getCenterOffset (meas, cat, &measure[k], &stackImageID);
 	if (stackPrimaryOffset < stackPrimaryOffsetMin) {
