Index: trunk/Ohana/src/libdvo/src/mosaic_astrom.c
===================================================================
--- trunk/Ohana/src/libdvo/src/mosaic_astrom.c	(revision 39324)
+++ trunk/Ohana/src/libdvo/src/mosaic_astrom.c	(revision 39325)
@@ -7,206 +7,13 @@
 void SortDISindex (e_time *S, off_t *I, off_t N);
 
-# if (0)
+// Generate the links images[i].coords.mosaic & images[i].parent which point at the parent
+// coords structure and the parent image structure, respectively.  These links are built
+// based on the date/time of the exposure (image->tzero) and will not necessarily work if
+// & when we use 2 cameras (e.g., gpc1 & gpc2).
 
-/* chip-match table: j = ChipMatch[i], images[j] is DIS for images[i] WRP */
+// for 22M images, this function takes about 5 seconds.
 
-static off_t  iDIS = -1;      // DIS entry in ChipMatch[]
-static off_t  Ndis = 0;
-static off_t  *DISentry = NULL;
-static e_time *DIStzero = NULL;
-static off_t  *ChipMatch = NULL;
-
-/* what is the currently registered mosaic image? */
-off_t GetRegisteredMosaic () {
-  return (iDIS);
-}
-
-/* what is the currently registered mosaic image? */
-off_t *GetChipMatch () {
-  return (ChipMatch);
-}
-
-/* given an image array and a current entry of type WRP, find matching DIS & Register it */
-int FindMosaicForImage (Image *images, off_t Nimages, off_t entry) {
-
-  int status;
-
-  if (ChipMatch == NULL) {
-    status = FindMosaicForImage_TableSearch (images, Nimages, entry);
-    return (status);
-  }
-  status = FindMosaicForImage_MatchSearch (images, Nimages, entry);
-  return (status);
-}
-
-/* given an image array and a current entry of type WRP, find matching DIS & Register it */
-int FindMosaicForImage_TableSearch (Image *images, off_t Nimages, off_t entry) {
-
-  e_time tzero;
-  off_t i;
-
-  /* search backwards for image with same time and type DIS */
-
-  if (strcmp(&images[entry].coords.ctype[4], "-WRP")) {
-    /* not a wrp image, do nothing */
-    return (entry + 1); /* error or not */
-  }
-
-  tzero = images[entry].tzero;
-  
-  for (i = entry - 1; i >= 0; i--) {
-    if (images[i].tzero != tzero) continue;
-    if (strcmp(&images[i].coords.ctype[4], "-DIS")) continue;
-
-    /* found a valid match */
-    RegisterMosaic (&images[i].coords);
-    iDIS = i;
-    return (i + 1);
-  }
-
-  for (i = entry + 1; i < Nimages; i++) {
-    if (images[i].tzero != tzero) continue;
-    if (strcmp(&images[i].coords.ctype[4], "-DIS")) continue;
-
-    /* found a valid match */
-    RegisterMosaic (&images[i].coords);
-    iDIS = i;
-    return (i + 1);
-  }
-  return (FALSE);
-}
-
-/* given an image array and a current entry of type WRP, find matching DIS & Register it */
-int FindMosaicForImage_MatchSearch (Image *images, off_t Nimages, off_t entry) {
-
-  off_t N;
-
-  if (strcmp(&images[entry].coords.ctype[4], "-WRP")) {
-    /* not a wrp image, do nothing */
-    return (entry + 1); /* error or not? */
-  }
-
-  if (ChipMatch == NULL) return (FALSE);
-
-  N = ChipMatch[entry];
-  if (N < 0) return (FALSE);
-  if (N >= Nimages) return (FALSE);
-
-  RegisterMosaic (&images[N].coords);
-  iDIS = N;
-  return (N + 1);
-}
-
-// this is a very old version of BuildChipMatch which does not use bisection
-int BuildChipMatch_nosort (Image *images, off_t Nimages) {
-
-  off_t i, j, NDIS;
-
-  if (DISentry != NULL) free (DISentry);
-  if (DIStzero != NULL) free (DIStzero);
-  if (ChipMatch != NULL) free (ChipMatch);
-
-  /* find all DIS images, save tzero (& instrument) */
-  Ndis = 0;
-  NDIS = 100;
-  ALLOCATE (DISentry, off_t, NDIS);
-  ALLOCATE (DIStzero, e_time, NDIS);
-
-  for (i = 0; i < Nimages; i++) {
-    if (strcmp(&images[i].coords.ctype[4], "-DIS")) continue;
-    DISentry[Ndis] = i;
-    DIStzero[Ndis] = images[i].tzero;
-    Ndis ++;
-    if (Ndis >= NDIS) {
-      NDIS += 100;
-      REALLOCATE (DISentry, off_t, NDIS);
-      REALLOCATE (DIStzero, e_time, NDIS);
-    }
-  }
-
-  /* find all matched WRP images */
-  ALLOCATE (ChipMatch, off_t, Nimages);
-  for (i = 0; i < Nimages; i++) {
-    ChipMatch[i] = -1;
-    if (strcmp(&images[i].coords.ctype[4], "-WRP")) continue;
-    for (j = 0; j < Ndis; j++) {
-      if (DIStzero[j] < images[i].tzero) continue;
-      if (DIStzero[j] > images[i].tzero + (int) images[i].exptime) continue;
-      ChipMatch[i] = DISentry[j];
-      goto got_match;
-    }
-
-    fprintf (stderr, "WARNING: can't find matching mosaic \n");
-    ChipMatch[i] = -2;
-
-  got_match:
-    continue;
-  }
-  return (TRUE);
-}
-
-// this is an old version of BuildChipMatch which stores the results here in a local static variable
-int BuildChipMatch_static (Image *images, off_t Nimages) {
-
-  off_t i, j, NDIS;
-
-  if (DISentry != NULL) free (DISentry);
-  if (DIStzero != NULL) free (DIStzero);
-  if (ChipMatch != NULL) free (ChipMatch);
-
-  // allocate containers for DIS indexing
-  Ndis = 0;
-  NDIS = 100;
-  ALLOCATE (DISentry, off_t, NDIS);
-  ALLOCATE (DIStzero, e_time, NDIS);
-
-  // find all DIS images, save tzero (& instrument) 
-  for (i = 0; i < Nimages; i++) {
-    if (strcmp(&images[i].coords.ctype[4], "-DIS")) continue;
-    DISentry[Ndis] = i;
-    DIStzero[Ndis] = images[i].tzero;
-    Ndis ++;
-    if (Ndis >= NDIS) {
-      NDIS += 100;
-      REALLOCATE (DISentry, off_t, NDIS);
-      REALLOCATE (DIStzero, e_time, NDIS);
-    }
-  }
-
-  // sort the index, start, and stop by the start times:
-  SortDISindex (DIStzero, DISentry, Ndis);
-
-  // ChipMatch has a few possible values: 
-  // -3 : image is a mosaic (DIS)
-  // -2 : image is an unassigned WRP image
-  // -1 : image is not a WRP or DIS images
-  // >= 0 : value is the mosaic seq number for this WRP image 
-
-  /* find all matched WRP images */
-  ALLOCATE (ChipMatch, off_t, Nimages);
-  for (i = 0; i < Nimages; i++) {
-    ChipMatch[i] = -1;
-    if (!strcmp(&images[i].coords.ctype[4], "-DIS")) {
-      ChipMatch[i] = -3;
-      continue;
-    }
-    if (strcmp(&images[i].coords.ctype[4], "-WRP")) continue;
-
-    j = getDISentry (images[i].tzero, images[i].tzero + (int) images[i].exptime, DIStzero, DISentry, Ndis);
-    if (j == -1) {
-      fprintf (stderr, "WARNING: can't find matching mosaic \n");
-      ChipMatch[i] = -2;
-      continue;
-    }
-    if (j >= Nimages) abort();
-
-    ChipMatch[i] = j;
-  }
-  return (TRUE);
-}
-# endif
-
-// XXX Note that this links (images[i].coords.mosaic, images[i].parent) will break
-// if we reallocate the Image array in the middle of program
+// Note that the links (images[i].coords.mosaic, images[i].parent) will break if we
+// reallocate the Image array in the middle of program
 int BuildChipMatch (Image *images, off_t Nimages) {
 
Index: trunk/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- trunk/Ohana/src/relphot/src/setMrelCatalog.c	(revision 39324)
+++ trunk/Ohana/src/relphot/src/setMrelCatalog.c	(revision 39325)
@@ -299,6 +299,6 @@
     dvo_secfilt_init (&secfilt[Nsec], SECFILT_RESET_CHIP); // this does not reset astrometry or STACK bits
 
-    // XXX hardwired
-    if ((Nsec < 4) || (Nsec == 8)) {
+    // XXX hardwired grizy = (01234) JHK = (567) w = (8)
+    if ((Nsec < 5) || (Nsec == 8)) {
       secfilt[Nsec].Ncode = results->NexpPS1[Nsec]; 
     } else {
