Index: /branches/eam_branches/ipp-20140206/Ohana/src/relphot/include/relphot.h
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relphot/include/relphot.h	(revision 36611)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relphot/include/relphot.h	(revision 36612)
@@ -473,5 +473,5 @@
 int select_images_hostregion (RegionHostTable *hosts, Image *image, off_t Nimage);
 int find_host_for_coords (RegionHostTable *regionHosts, double R, double d);
-int calculate_image_bounds (Image *image, double *rmin, double *rmax, double *dmin, double *dmax);
+int calculate_image_bounds (Image *image, double *rmin, double *rmax, double *dmin, double *dmax, double Rmid);
 
 int launch_region_hosts (RegionHostTable *regionHosts);
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/MosaicOps.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/MosaicOps.c	(revision 36611)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/MosaicOps.c	(revision 36612)
@@ -575,7 +575,30 @@
       image[m].Xm    = NAN_S_SHORT;
     }
+
     if (Nc > 0) {
       dsort (Rc, Nc);
+      if (Rc[Nc-1] - Rc[0] > 180.0) {
+	// in our list, Rc is in the range 0.0 to 360.0.  
+	// any mosaic which is close to the 0.0, 360.0 boundary may have some on
+	// one side or the other.  count how many have values more than Rc[0] + 180.
+	// if more than half are at the large end, re-normalize to that range
+	int Nbig = 0;
+	for (j = 1; j < Nc; j++) {
+	  if (Rc[j] - Rc[0] > 180.0) Nbig ++;
+	}
+	if (Nbig  > 0.5*Nc) {
+	  for (j = 0; j < Nc; j++) {
+	    Rc[j] = ohana_normalize_angle_to_midpoint (Rc[j], 360.0);
+	  }
+	  dsort (Rc, Nc);
+	} else if (Nbig > 0) {
+	  for (j = 0; j < Nc; j++) {
+	    Rc[j] = ohana_normalize_angle_to_midpoint (Rc[j], 0.0);
+	  }
+	  dsort (Rc, Nc);
+	}
+      }
       dsort (Dc, Nc);
+
       Rmid = Rc[(int)(0.5*Nc)];
       Dmid = Dc[(int)(0.5*Nc)];
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/assign_images.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/assign_images.c	(revision 36611)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/assign_images.c	(revision 36612)
@@ -40,6 +40,4 @@
   // even faster would be to use a tree to get to the real regions...
   select_images_hostregion (regionHosts, image, Nimage);
-
-  // calculate_host_image_bounds (regionHosts);
 
   return TRUE;
@@ -120,4 +118,8 @@
     image[j].DECo = Dc;
 
+    // NOTE: if we are NOT using mosaic centers, we don't need to keep chips with centers
+    // on opposite sides of 0,360 together.  in which case, it is OK for the range of Rc
+    // to be 0.0 to 360.0.  also NOTE: RAo,DECo are only used for debugging reference.
+
     if (MOSAIC_ZEROPT) {
       // use the coords of the associated mosaic to select
@@ -125,4 +127,6 @@
       Rc = mosaic->coords.crval1;
       Dc = mosaic->coords.crval2;
+      // NOTE : have defined mosaic Rc,Dc to choose the side of 0,360 on which most of the
+      // chips are located.  but, for host assignment, we rationalize to 0.0 - 360.0
       Rc = ohana_normalize_angle_to_midpoint (Rc, 180.0);
     }
@@ -134,6 +138,9 @@
     RegionHostInfo *host = &regionHosts->hosts[i];
 
+    // image bounds are defined for a range centered on the mosaic center thus, a mosaic
+    // with center 0.5 will have chips bounds ranging from ~ -1.5 to +2.5 or so, while a mosaic
+    // with center 359.5 will have chips bounds ranging from ~ 357.5 to 361.5 or so
     double Rmin, Rmax, Dmin, Dmax;
-    calculate_image_bounds (&image[j], &Rmin, &Rmax, &Dmin, &Dmax);
+    calculate_image_bounds (&image[j], &Rmin, &Rmax, &Dmin, &Dmax, Rc);
 
     host->RminCat = MIN(Rmin, host->RminCat);
@@ -168,5 +175,5 @@
 double Yf[] = {0.0, 0.0, 1.0, 1.0};
 
-int calculate_image_bounds (Image *image, double *rmin, double *rmax, double *dmin, double *dmax) {
+int calculate_image_bounds (Image *image, double *rmin, double *rmax, double *dmin, double *dmax, double Rmid) {
 
   int n;
@@ -183,5 +190,5 @@
     Yc = Yf[n]*image->NY;
     XY_to_RD (&Rc, &Dc, Xc, Yc, &image->coords);
-    Rc = ohana_normalize_angle_to_midpoint (Rc, 180.0);
+    Rc = ohana_normalize_angle_to_midpoint (Rc, Rmid);
       
     Rmin = MIN (Rmin, Rc);
@@ -199,5 +206,5 @@
 }
 
-int calculate_host_image_bounds (RegionHostTable *regionHosts) {
+int calculate_host_image_bounds (RegionHostTable *regionHosts, double Rmid) {
 
   int i, n;
@@ -212,7 +219,7 @@
     BuildChipMatch (host->image, host->Nimage);
 
-    double Rmin = 360.0;
-    double Rmax =   0.0;
-    double Dmin = +90.0;
+    double Rmin =  720.0;
+    double Rmax = -360.0;
+    double Dmin =  +90.0;
     double Dmax = -90.0;
 
@@ -232,5 +239,5 @@
 	Yc = Yf[n]*image->NY;
 	XY_to_RD (&Rc, &Dc, Xc, Yc, &image->coords);
-	Rc = ohana_normalize_angle_to_midpoint (Rc, 180.0);
+	Rc = ohana_normalize_angle_to_midpoint (Rc, Rmid);
       
 	Rmin = MIN (Rmin, Rc);
@@ -243,4 +250,5 @@
     }
 
+    // RminCat, RmaxCat may extended beyond 0.0 - 360.0
     host->RminCat = Rmin;
     host->DminCat = Dmin;
@@ -259,5 +267,5 @@
 
 
-// XXX add a search tree to speed this up?
+// Rc is in range 0.0 - 360.0, hosts Rmin,Rmax in range 0.0 - 360.0
 int find_host_for_coords (RegionHostTable *regionHosts, double Rc, double Dc) {
 
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/relphot_parallel_images.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/relphot_parallel_images.c	(revision 36611)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/relphot_parallel_images.c	(revision 36612)
@@ -50,4 +50,7 @@
   SkyTable *sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
   SkyTableSetFilenames (sky, CATDIR, "cpt");
+
+  // UserPatch.Rmin,Rmax may have range from a few degrees < 0.0 to few degrees > 360.0.
+  // the following function correctly chooses the sky regions on the 0,360 boundary
   SkyList *skylist = SkyListByBounds (sky, -1, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
 
