Index: branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/MosaicOps.c
===================================================================
--- branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/MosaicOps.c	(revision 33797)
+++ branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/MosaicOps.c	(revision 33798)
@@ -152,4 +152,10 @@
 }
 
+# define MARKTIME(MSG,...) { \
+  float dtime; \
+  gettimeofday (&stopTimer, (void *) NULL); \
+  dtime = DTIME (stopTimer, startTimer); \
+  fprintf (stderr, MSG, __VA_ARGS__); }
+
 /* find mosaic frames (unique time periods) (NOTE : we do NOT require matching photcodes...)
    this function will also identify the images NOT in the subset which belong to a selected mosaic
@@ -161,5 +167,9 @@
   char *pname;
 
+  struct timeval startTimer, stopTimer;
+
   if (!MOSAIC_ZEROPT) return;
+
+  gettimeofday (&startTimer, (void *) NULL);
 
   /* a 'mosaic' in relphot is (unlike relastro) a virtual concept: there is no 
@@ -174,4 +184,5 @@
   }
   sort_times (startTimes, Nsubset);
+  MARKTIME("create array of all image obstimes: %f sec\n", dtime);
   
   Nmosaic = 0;
@@ -195,4 +206,5 @@
   }
   Nmosaic ++;
+  MARKTIME("create subset array of mosaic obstimes: %f sec\n", dtime);
 
   int Nskip, Nmiss, Nmark;
@@ -212,6 +224,6 @@
 
     /* set image time range */
-    start = subset[i].tzero;
-    stop  = subset[i].tzero + MAX(1.01*subset[i].trate*subset[i].NY, 1);
+    start = image[i].tzero;
+    stop  = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1);
 
     /* find a matching mosaic */
@@ -226,4 +238,5 @@
   }
   fprintf (stderr, "%d images, %d skip, %d miss, %d mark\n", (int) Nimage, (int) Nskip, (int) Nmiss, (int) Nmark);
+  MARKTIME("find unselected images matching selected mosaics: %f sec\n", dtime);
 
   // now I have a list of uniq start times, and they are in order
@@ -318,5 +331,7 @@
 }
 
-// use bisection to find the overlapping mosaic
+// use bisection to find the overlapping mosaic (returns exact match)
+// startTimes is a sorted, unique list of times
+// start might not be in the list
 off_t findMosaic (unsigned int *startTimes, off_t Nmosaic, unsigned int start) {
 
@@ -324,7 +339,12 @@
 
   // find the last mosaic before start
-  Nlo = 0; // startTimes[Nlo] guaranteed to be <= start
-  Nhi = Nmosaic - 1; // startTimes[Nhi] guaranteed to be >= start
-  while (Nhi - Nlo > 10) {
+  Nlo = 0; // first valid startTimes value
+  Nhi = Nmosaic - 1; // last valid startTimes value
+
+  // if start is not in this range, return -1
+  if (start < startTimes[Nlo]) return (-1);
+  if (start > startTimes[Nhi]) return (-1);
+
+  while (Nhi - Nlo > 4) {
     N = 0.5*(Nlo + Nhi);
     if (startTimes[N] < start) {
@@ -334,9 +354,9 @@
     }
   }
-
-  // check for the matched mosaic starting from Nlo 
-  for (N = Nlo; N < Nmosaic; N++) { 
-    if (start > startTimes[N])  continue;
-    return (N);
+  // we now have : startTimes[Nlo] < start <= starTimes[Nhi]
+
+  // find a matched mosaic starting from Nlo, or return -1
+  for (N = Nlo; N <= Nhi; N++) { 
+    if (startTimes[N] == start) return N;
   }
   return (-1);
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 33797)
+++ branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/select_images.c	(revision 33798)
@@ -133,5 +133,5 @@
   if (VERBOSE) fprintf (stderr, "finding images\n");
   BuildChipMatch (timage, Ntimage);
-  MARKTIME("build chip match: %f sec\n", dtime);
+  MARKTIME("build chip match for %d images: %f sec\n", (int) Ntimage, dtime);
 
   nimage = 0;
