Index: trunk/Ohana/src/addstar/src/findskycell.c
===================================================================
--- trunk/Ohana/src/addstar/src/findskycell.c	(revision 34260)
+++ trunk/Ohana/src/addstar/src/findskycell.c	(revision 34291)
@@ -6,5 +6,5 @@
 				        4.044944,   4.090909,   4.186047,   4.285714,   4.390244,   4.556962,   4.736842,   5.000000,   
 				        5.294118,   5.625000,   6.000000,   6.545455,   7.200000,   8.000000,   9.230769,  10.909091,  
-				      13.333333,  17.142857,  24.000000,  40.000000,  360.000000};
+				       13.333333,  17.142857,  24.000000,  40.000000, 360.000000};
 
 // in the general case, projection cell centers are arbitrary
@@ -113,6 +113,10 @@
   ALLOCATE (tree.NBAND, int, tree.Nzone);
 
-  ALLOCATE (tree.RA_origin, double, tree.Nzone);
-  ALLOCATE (tree.RA_offset, double, tree.Nzone);
+  ALLOCATE (tree.RA_origin,   double, tree.Nzone);
+  ALLOCATE (tree.RA_offset,   double, tree.Nzone);
+  ALLOCATE (tree.DEC_min,     double, tree.Nzone);
+  ALLOCATE (tree.DEC_max,     double, tree.Nzone);
+  ALLOCATE (tree.DEC_min_raw, double, tree.Nzone);
+  ALLOCATE (tree.DEC_max_raw, double, tree.Nzone);
 
   ALLOCATE (tree.ra,   double *, tree.Nzone);
@@ -138,4 +142,12 @@
     tree.RA_origin[zone] = -0.5*RA_offset_RINGS_V3[zone];
     tree.RA_offset[zone] = RA_offset_RINGS_V3[zone];
+
+    // set the starting values here.  In fact, the MIN and MAX values need to be tweaked 
+    // on the basis of the real images...
+    tree.DEC_min_raw[zone] = +90.0;
+    tree.DEC_max_raw[zone] = -90.0;
+    tree.DEC_min[zone] = NAN;
+    tree.DEC_max[zone] = NAN;
+
     ALLOCATE (tree.ra[zone],   double, tree.NBAND[zone]);
     ALLOCATE (tree.dec[zone],  double, tree.NBAND[zone]);
@@ -179,4 +191,50 @@
     tree.dec[zone][band] = dec;
     tree.cell[zone][band] = i;
+
+    // what are the min and max DEC values for this zone? (test center and corners of top and bottom edge)  
+
+    if (dec > 0.0) {
+      // min DEC at bottom of the cell at the center
+      x = 0.5*image[i].NX;
+      y = 0.0*image[i].NY;
+      XY_to_RD (&ra, &dec, x, y, &image[i].coords);
+      tree.DEC_min_raw[zone] = MIN(tree.DEC_min_raw[zone], dec);
+  
+      // max DEC : find the intersection between the RA boundary and the top of the cell 
+      double ra_band_min = tree.RA_origin[zone] + tree.RA_offset[zone] * band;
+  
+      // does the parity matter?
+      x = 0.0*image[i].NX;
+      y = 1.0*image[i].NY;
+  
+      int Niter;
+      for (Niter = 0; Niter < 3; Niter ++) {
+        XY_to_RD (&ra, &dec, x, y, &image[i].coords);
+        RD_to_XY (&x, &y, ra_band_min, dec, &image[i].coords);
+        y = 1.0*image[i].NY;
+      }
+      tree.DEC_max_raw[zone] = MAX(tree.DEC_max_raw[zone], dec);
+    } else {
+      // max DEC at top of the cell at the center
+      x = 0.5*image[i].NX;
+      y = 1.0*image[i].NY;
+      XY_to_RD (&ra, &dec, x, y, &image[i].coords);
+      tree.DEC_max_raw[zone] = MAX(tree.DEC_max_raw[zone], dec);
+  
+      // max DEC : find the intersection between the RA boundary and the bottom of the cell 
+      double ra_band_min = tree.RA_origin[zone] + tree.RA_offset[zone] * band;
+  
+      // does the parity matter? (NO)
+      x = 0.0*image[i].NX;
+      y = 0.0*image[i].NY;
+  
+      int Niter;
+      for (Niter = 0; Niter < 3; Niter ++) {
+        XY_to_RD (&ra, &dec, x, y, &image[i].coords);
+        RD_to_XY (&x, &y, ra_band_min, dec, &image[i].coords);
+        y = 0.0*image[i].NY;
+      }
+      tree.DEC_min_raw[zone] = MIN(tree.DEC_min_raw[zone], dec);
+    }
     memcpy (tree.name[zone][band], image[i].name, BOUNDARY_TREE_NAME_LENGTH);
   }
@@ -206,4 +264,18 @@
   }
 
+  // figure out the max band value for each zone?
+  int Nm = 0;
+  tree.DEC_min[Nm] = -90.0;
+  tree.DEC_max[Nm] = 0.5*(tree.DEC_max_raw[Nm] + tree.DEC_min_raw[Nm + 1]);
+
+  int Np = tree.Nzone - 1;
+  tree.DEC_min[Np] = 0.5*(tree.DEC_min_raw[Np] + tree.DEC_max_raw[Np - 1]);
+  tree.DEC_max[Np] = +90.0;
+
+  for (zone = 1; zone < tree.Nzone - 1; zone++) {
+    tree.DEC_min[zone] = 0.5*(tree.DEC_min_raw[zone] + tree.DEC_max_raw[zone - 1]);
+    tree.DEC_max[zone] = 0.5*(tree.DEC_max_raw[zone] + tree.DEC_min_raw[zone + 1]);
+  }
+
   struct timeval start, stop;
   gettimeofday (&start, (void *) NULL);
