IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:41:49 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/tap_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/tap_branches

  • branches/tap_branches/Ohana

  • branches/tap_branches/Ohana/src/addstar/src/find_matches_refstars.c

    r21508 r27838  
    11# include "addstar.h"
    22
    3 int find_matches_refstars (SkyRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options) {
    4 
    5   int i, j, k, n, m, N, J;
     3int find_matches_refstars (SkyRegion *region, Stars **stars, unsigned int Nstars, Catalog *catalog, AddstarClientOptions options) {
     4
     5  off_t i, j, n, N, J;
    66  double RADIUS, RADIUS2;
    77  double *X1, *Y1, *X2, *Y2;
    88  double dX, dY, dR;
    9   int *N1, *N2,  *next, *next_miss, last, last_miss;
    10   int Nave, NAVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch;
     9  off_t *N1, *N2,  *next_meas;
     10  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch;
    1111  unsigned int objID, catID;
    12   Measure *tmpmeasure;
    13   Missing *tmpmissing;
    1412  Coords tcoords;
    1513  int Nsecfilt;
     
    2624  ALLOCATE (X1, double, Nstars);
    2725  ALLOCATE (Y1, double, Nstars);
    28   ALLOCATE (N1, int,   Nstars);
     26  ALLOCATE (N1, off_t,  Nstars);
    2927
    3028  /** allocate local arrays (catalog) **/
     
    3331  ALLOCATE (X2, double, NAVE);
    3432  ALLOCATE (Y2, double, NAVE);
    35   ALLOCATE (N2, int, NAVE);
    36   ALLOCATE (catalog[0].found, int, NAVE);
     33  ALLOCATE (N2, off_t, NAVE);
     34  ALLOCATE (catalog[0].found, off_t, NAVE);
    3735  REALLOCATE (catalog[0].average, Average, NAVE);
    3836  REALLOCATE (catalog[0].secfilt, SecFilt, NAVE*catalog[0].Nsecfilt);
     
    4038
    4139  Nmatch = 0;
    42   Nmeas = catalog[0].Nmeasure;
    43   NMEAS = Nmeas + 1000;
    44   ALLOCATE (next, int, NMEAS);
    45   REALLOCATE (catalog[0].measure, Measure, NMEAS);
    46  
    47   Nmiss = catalog[0].Nmissing;
    48   NMISS = Nmiss + 1000;
    49   if ((NMISS < 1) || (NMISS > 1e10)) {
    50       fprintf (stderr, "weird value for NMISS: %d\n", NMISS);
    51   }
    52   ALLOCATE (next_miss, int, NMISS);
    53   REALLOCATE (catalog[0].missing, Missing, NMISS);
     40  NMEAS = Nmeas = catalog[0].Nmeasure;
    5441 
    5542  // current max obj ID for this catalog
     
    8269
    8370  /* set up pointers for linked list of measurements */
    84   for (i = 0; i < Nmeas - 1; i++) {
    85     next[i] = i+1;
    86   }
    87   next[i] = -1;
    88   last = i;
    89 
    90   for (i = 0; i < Nmiss - 1; i++) {
    91     next_miss[i] = i+1;
    92   }
    93   next_miss[i] = -1;
    94   last_miss = i;
     71  if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeas_disk)) {
     72    // this version is only valid if we have done a full catalog load, and if the catalog
     73    // is sorted while processed
     74    next_meas = init_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas);
     75  } else {
     76    next_meas = build_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas);
     77  }   
    9578
    9679  /* choose a radius for matches */
     
    10588  // XXX could use NREFSTAR_GROUP to do this match more quicky
    10689  for (i = j = 0; (i < Nstars) && (j < Nave); ) {
     90    if (!finite(X1[i]) || !finite(Y1[i])) {
     91      i++;
     92      continue;
     93    }
     94    if (!finite(X2[j]) || !finite(Y2[j])) {
     95      j++;
     96      continue;
     97    }
    10798   
    10899    dX = X1[i] - X2[j];
    109     if (dX <= -2*RADIUS) {
     100    if (dX <= -1.02*RADIUS) {
    110101      i++;
    111102      continue;
    112103    }
    113     if (dX >= 2*RADIUS) {
     104    if (dX >= 1.02*RADIUS) {
    114105      j++;
    115106      continue;
     
    117108
    118109    /* negative dX: j is too large, positive dX, i is too large */
    119     for (J = j; (dX > -2*RADIUS) && (J < Nave); J++) {
     110    for (J = j; (dX > -1.02*RADIUS) && (J < Nave); J++) {
    120111      dX = X1[i] - X2[J];
    121112      dY = Y1[i] - Y2[J];
     
    123114      if (dR > RADIUS2) continue;
    124115
     116      /*** a match is found, add to average, measure ***/
    125117      Nmatch ++;
    126118      n = N2[J];
    127119      N = N1[i];
    128       m = catalog[0].average[n].measureOffset; 
    129120
    130121      /** in replace mode, search for entry and replace values M, dM, R, D */
    131       if (options.replace && replace_match (&catalog[0].average[n], &catalog[0].measure[m], stars[N])) continue;
    132 
    133       /** insert star in measurement list */
    134       /* find last measurement of this star */
    135       for (k = 0; k < catalog[0].average[n].Nmeasure - 1; k++) m = next[m];
    136 
    137       /* set up references */
    138       next[Nmeas] = next[m];
    139       next[m] = Nmeas;
    140 
    141       /* last just was moved */
    142       if (next[Nmeas] == -1) last = Nmeas;
     122      if (options.replace && replace_match (&catalog[0].average[n], catalog[0].measure, stars[N])) continue;
     123
     124      if (Nmeas == NMEAS) {
     125        NMEAS = Nmeas + 1000;
     126        REALLOCATE (next_meas, off_t, NMEAS);
     127        REALLOCATE (catalog[0].measure, Measure, NMEAS);
     128      }
     129
     130      /* add to end of measurement list */
     131      add_meas_link (&catalog[0].average[n], next_meas, Nmeas, NMEAS);
    143132       
    144133      /** add measurements for this star **/
     
    150139      catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N][0].average.R);
    151140      catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N][0].average.D);
     141      catalog[0].measure[Nmeas].dbFlags  = 0;
     142      catalog[0].measure[Nmeas].averef   = n;
     143      catalog[0].measure[Nmeas].objID    = catalog[0].average[n].objID;
     144      catalog[0].measure[Nmeas].catID    = catalog[0].catID;
    152145
    153146      // rationalize dR:
     
    162155          catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N][0].average.R);
    163156      }
    164 
    165       catalog[0].measure[Nmeas].averef   = n;
    166       catalog[0].measure[Nmeas].dbFlags  = 0;
    167       catalog[0].measure[Nmeas].objID    = catalog[0].average[n].objID;
    168       catalog[0].measure[Nmeas].catID    = catalog[0].catID;
    169157
    170158      catalog[0].measure[Nmeas].t        = (TIMEREF == 0) ? stars[N][0].measure.t      : TIMEREF; /** careful : time_t vs e_time **/
     
    204192      catalog[0].average[n].Nmeasure ++;
    205193      Nmeas ++;
    206       if (Nmeas == NMEAS) {
    207         NMEAS = Nmeas + 1000;
    208         REALLOCATE (next, int, NMEAS);
    209         REALLOCATE (catalog[0].measure, Measure, NMEAS);
    210       }
    211 
    212       update_coords (&catalog[0].average[n], &catalog[0].measure[0], next);
     194
     195      // update_coords (&catalog[0].average[n], &catalog[0].measure[0], next_meas);
    213196    }
    214197    i++;
     
    224207
    225208  for (i = 0; (i < Nstars) && !options.only_match; i+=NREFSTAR_GROUP) {
     209    if (Nmeas >= NMEAS - NREFSTAR_GROUP) {
     210      NMEAS = Nmeas + 1000;
     211      REALLOCATE (next_meas, off_t, NMEAS);
     212      REALLOCATE (catalog[0].measure, Measure, NMEAS);
     213    }
     214    if (Nave == NAVE) {
     215      NAVE = Nave + 1000;
     216      REALLOCATE (catalog[0].average, Average, NAVE);
     217      REALLOCATE (catalog[0].secfilt, SecFilt, NAVE*catalog[0].Nsecfilt);
     218    }
     219
    226220    N = N1[i];
    227221    if (stars[N][0].found > -1) continue;
     222    if (!IN_REGION (stars[N][0].average.R, stars[N][0].average.D)) continue;
    228223
    229224    catalog[0].average[Nave].R             = stars[N][0].average.R;
     
    260255
    261256    catalog[0].average[Nave].Xp            = 0;
    262     catalog[0].average[Nave].ChiSq         = 0.0;
     257    catalog[0].average[Nave].ChiSqAve      = 0.0;
     258    catalog[0].average[Nave].ChiSqPM       = 0.0;
     259    catalog[0].average[Nave].ChiSqPar      = 0.0;
     260    catalog[0].average[Nave].Tmean         = 0;
     261    catalog[0].average[Nave].Trange        = 0;
    263262    catalog[0].average[Nave].Npos          = 0;
    264263
     
    266265    catalog[0].average[Nave].catID         = catID;
    267266    catalog[0].average[Nave].flags         = 0;
     267    if (PSPS_ID) {
     268        catalog[0].average[Nave].extID = CreatePSPSObjectID(catalog[0].average[Nave].R,
     269                                                            catalog[0].average[Nave].D);
     270    } else {
     271        catalog[0].average[Nave].extID         = 0;
     272    }
     273
    268274
    269275    objID ++;
     
    295301
    296302      stars[N][0].found = Nmeas;
    297       next[last] = Nmeas;
    298       next[Nmeas] = -1;
    299       last = Nmeas;
    300       Nmeas ++;
    301       if (Nmeas == NMEAS) {
    302         NMEAS = Nmeas + 1000;
    303         REALLOCATE (next, int, NMEAS);
    304         REALLOCATE (catalog[0].measure, Measure, NMEAS);
    305       }
    306     }
    307 
     303      next_meas[Nmeas] = -1;  // initial value here, update below
     304      Nmeas ++;
     305    }
     306
     307    for (j = 0; j < NREFSTAR_GROUP - 1; j++) {
     308        next_meas[Nmeas - NREFSTAR_GROUP + j] = Nmeas - NREFSTAR_GROUP + j + 1;
     309    }
    308310    Nave ++;
    309     if (Nave == NAVE) {
    310       NAVE = Nave + 1000;
    311       REALLOCATE (catalog[0].average, Average, NAVE);
    312       REALLOCATE (catalog[0].secfilt, SecFilt, NAVE*catalog[0].Nsecfilt);
    313     }
    314311  }
    315312     
    316   free (catalog[0].found);
    317313  REALLOCATE (catalog[0].average, Average, Nave);
    318314
    319   /* fix order of Measure (memory intensive, but fast) */
    320   N = 0;
    321   ALLOCATE (tmpmeasure, Measure, Nmeas);
    322   for (i = 0; i < Nave; i++) {
    323     n = catalog[0].average[i].measureOffset;
    324     catalog[0].average[i].measureOffset = N;
    325     for (k = 0; k < catalog[0].average[i].Nmeasure; k++, N++) {
    326       tmpmeasure[N] = catalog[0].measure[n];
    327       tmpmeasure[N].averef = i;
    328       n = next[n];
    329     }
    330   }
    331   free (catalog[0].measure);
    332   catalog[0].measure = tmpmeasure;
    333    
    334   /* fix order of Missing (memory intensive, but fast) */
    335   N = 0;
    336   ALLOCATE (tmpmissing, Missing, Nmiss);
    337   for (i = 0; i < Nave; i++) {
    338     if (catalog[0].average[i].Nmissing > 0) {
    339       n = catalog[0].average[i].missingOffset;
    340       catalog[0].average[i].missingOffset = N;
    341       for (k = 0; k < catalog[0].average[i].Nmissing; k++, N++) {
    342         tmpmissing[N] = catalog[0].missing[n];
    343         n = next_miss[n];
    344       }
    345     }
    346   }
    347   free (catalog[0].missing);
    348   catalog[0].missing = tmpmissing;
     315  // XXX allow for unsorted output?
     316  catalog[0].measure = sort_measure (catalog[0].average, Nave, catalog[0].measure, Nmeas, next_meas);
    349317
    350318  /* note stars which have been found in this catalog */
     
    357325  }
    358326
     327  catalog[0].objID    = objID; // new max value, save on catalog close
     328  catalog[0].Naverage = Nave;
     329  catalog[0].Nmeasure = Nmeas;
     330  catalog[0].Nsecf_mem = Nave*Nsecfilt;
     331  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %lld %lld %lld, (%lld matches)\n", (long long) Nstars, (long long) Nave, (long long) Nmeas, (long long) Nmatch);
     332
     333  free (catalog[0].found);
    359334  free (X1);
    360335  free (Y1);
     
    363338  free (Y2);
    364339  free (N2);
    365   free (next);
    366   free (next_miss);
    367 
    368   catalog[0].objID    = objID; // new max value, save on catalog close
    369   catalog[0].Naverage = Nave;
    370   catalog[0].Nmeasure = Nmeas;
    371   catalog[0].Nmissing = Nmiss;
    372   catalog[0].Nsecf_mem = Nave*Nsecfilt;
    373   if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nmiss: %d %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmiss, Nmatch);
     340  free (next_meas);
     341
    374342  return (Nmatch);
    375343}
Note: See TracChangeset for help on using the changeset viewer.