IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 23, 2010, 5:24:42 PM (16 years ago)
Author:
eugene
Message:

use sorted time vector and bracketing to speed up the mosaic match

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/largefiles.20100314/Ohana/src/libdvo/src/mosaic_astrom.c

    r27296 r27424  
    11# include <dvo.h>
     2
     3off_t getDISentry (e_time start, e_time stop, e_time *startMos, off_t *indexMos, off_t Nmosaic);
     4void SortDISindex (e_time *S, off_t *I, off_t N);
    25
    36/* chip-match table: j = ChipMatch[i], images[j] is DIS for images[i] WRP */
     
    7174  if (strcmp(&images[entry].coords.ctype[4], "-WRP")) {
    7275    /* not a wrp image, do nothing */
    73     return (TRUE); /* error or not */
     76    return (TRUE); /* error or not? */
    7477  }
    7578
     
    8588}
    8689
    87 int BuildChipMatch (Image *images, off_t Nimages) {
     90int BuildChipMatch_old (Image *images, off_t Nimages) {
    8891
    8992  off_t i, j, NDIS;
     
    131134  return (TRUE);
    132135}
     136
     137int BuildChipMatch (Image *images, off_t Nimages) {
     138
     139  off_t i, j, NDIS;
     140
     141  if (DISentry != NULL) free (DISentry);
     142  if (DIStzero != NULL) free (DIStzero);
     143  if (ChipMatch != NULL) free (ChipMatch);
     144
     145  // allocate containers for DIS indexing
     146  Ndis = 0;
     147  NDIS = 100;
     148  ALLOCATE (DISentry, off_t, NDIS);
     149  ALLOCATE (DIStzero, e_time, NDIS);
     150
     151  // find all DIS images, save tzero (& instrument)
     152  for (i = 0; i < Nimages; i++) {
     153    if (strcmp(&images[i].coords.ctype[4], "-DIS")) continue;
     154    DISentry[Ndis] = i;
     155    DIStzero[Ndis] = images[i].tzero;
     156    Ndis ++;
     157    if (Ndis >= NDIS) {
     158      NDIS += 100;
     159      REALLOCATE (DISentry, off_t, NDIS);
     160      REALLOCATE (DIStzero, e_time, NDIS);
     161    }
     162  }
     163
     164  // sort the index, start, and stop by the start times:
     165  SortDISindex (DIStzero, DISentry, Ndis);
     166
     167  /* find all matched WRP images */
     168  ALLOCATE (ChipMatch, off_t, Nimages);
     169  for (i = 0; i < Nimages; i++) {
     170    ChipMatch[i] = -1;
     171    if (strcmp(&images[i].coords.ctype[4], "-WRP")) continue;
     172
     173    j = getDISentry (images[i].tzero, images[i].tzero + (int) images[i].exptime, DIStzero, DISentry, Ndis);
     174    if (j == -1) {
     175      fprintf (stderr, "WARNING: can't find matching mosaic \n");
     176      ChipMatch[i] = -2;
     177      continue;
     178    }
     179    if (j >= Nimages) abort();
     180
     181    ChipMatch[i] = j;
     182  }
     183  return (TRUE);
     184}
     185
     186off_t getDISentry (e_time start, e_time stop, e_time *startMos, off_t *indexMos, off_t Nmosaic) {
     187
     188  // use bisection to find the overlapping mosaic
     189
     190  off_t Nlo, Nhi, N;
     191
     192  // find the last mosaic before start
     193  Nlo = 0; Nhi = Nmosaic;
     194  while (Nhi - Nlo > 10) {
     195    N = 0.5*(Nlo + Nhi);
     196    if (startMos[N] < start) {
     197      Nlo = MAX(N, 0);
     198    } else {
     199      Nhi = MIN(N + 1, Nmosaic);
     200    }
     201  }
     202
     203  // check for the matched mosaic starting from Nlo
     204  // we may have to go much beyond Nlo since stop is not sorted
     205  // can we use a sorted version of stop to check when we are beyond the valid range??
     206  for (N = Nlo; N < Nmosaic; N++) {
     207    if (startMos[N] < start) continue;
     208    if (startMos[N] > stop) return (-1);
     209    return (indexMos[N]);
     210  }
     211
     212  return (-1);
     213}
     214
     215// sort two times vectors and an index by first time vector
     216void SortDISindex (e_time *S, off_t *I, off_t N) {
     217
     218# define SWAPFUNC(A,B){ e_time tmp_t; off_t tmp_i; \
     219  tmp_t = S[A]; S[A] = S[B]; S[B] = tmp_t; \
     220  tmp_i = I[A]; I[A] = I[B]; I[B] = tmp_i; \
     221}
     222# define COMPARE(A,B)(S[A] < S[B])
     223
     224  OHANA_SORT (N, COMPARE, SWAPFUNC);
     225
     226# undef SWAPFUNC
     227# undef COMPARE
     228
     229}
     230
Note: See TracChangeset for help on using the changeset viewer.