Index: branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/select_images.c
===================================================================
--- branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/select_images.c	(revision 33739)
+++ branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/select_images.c	(revision 33788)
@@ -33,6 +33,4 @@
   struct timeval start, stop;
   
-  double RmaxSkyRegion, RminSkyRegion, RmidSkyRegion, DminSkyRegion, DmaxSkyRegion;
-
   double *RmaxSky;
   off_t *index;
@@ -59,12 +57,20 @@
   ALLOCATE (index, off_t, skylist[0].Nregions);
 
-  RminSkyRegion = +360.0;
-  RmaxSkyRegion = -360.0;
-  DminSkyRegion = +90.0;
-  DmaxSkyRegion = -90.0;
+  double RminSkyRegion = +360.0;
+  double RmaxSkyRegion = -360.0;
+  double DminSkyRegion = +90.0;
+  double DmaxSkyRegion = -90.0;
 
   D_NIMAGE = 6000;
 
   // FILE *ftest = fopen ("relphot.dump.dat", "w");
+
+  // The regions have RA values in the range 0-360, which implies an RA midpoint of 180.
+  // A patch which covers the 0,360 boundary (but not much more) needs to treat the values
+  // as being centered on 0.0.  Run the following test with both and see which yields a
+  // smaller contiguious patch
+
+  double RminSkyRegionAlt = +360.0;
+  double RmaxSkyRegionAlt = -360.0;
 
   /* compare with each region file */
@@ -100,6 +106,22 @@
     DminSkyRegion = MIN(DminSkyRegion, skylist[0].regions[i][0].Dmin);
     DmaxSkyRegion = MAX(DmaxSkyRegion, skylist[0].regions[i][0].Dmax);
-  }
-  RmidSkyRegion = 0.5*(RminSkyRegion + RmaxSkyRegion);
+
+    double RminAlt   = ohana_normalize_angle_to_midpoint (skylist[0].regions[i][0].Rmin, 0.0);
+    double RmaxAlt   = ohana_normalize_angle_to_midpoint (skylist[0].regions[i][0].Rmax, 0.0);
+    RminSkyRegionAlt = MIN(RminSkyRegionAlt, RminAlt);
+    RmaxSkyRegionAlt = MAX(RmaxSkyRegionAlt, RmaxAlt);
+
+    RminSkyRegion = MIN(RminSkyRegion, skylist[0].regions[i][0].Rmin);
+    RmaxSkyRegion = MAX(RmaxSkyRegion, skylist[0].regions[i][0].Rmax);
+    DminSkyRegion = MIN(DminSkyRegion, skylist[0].regions[i][0].Dmin);
+    DmaxSkyRegion = MAX(DmaxSkyRegion, skylist[0].regions[i][0].Dmax);
+  }
+  // use the option which gives the smaller RA range
+  if ((RmaxSkyRegionAlt - RminSkyRegionAlt) < (RmaxSkyRegion - RminSkyRegion)) {
+    RminSkyRegion = RminSkyRegionAlt;
+    RmaxSkyRegion = RmaxSkyRegionAlt;
+  }
+  
+  double RmidSkyRegion = 0.5*(RminSkyRegion + RmaxSkyRegion);
   MARKTIME("create sky region coords: %f sec\n", dtime);
 
