IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26279


Ignore:
Timestamp:
Nov 25, 2009, 11:50:11 AM (16 years ago)
Author:
eugene
Message:

clean up to 1) have a more similar structure to find_matches.c (incl. skip missing), 2) do not update average positions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/addstar/src/find_matches_refstars.c

    r21508 r26279  
    33int find_matches_refstars (SkyRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options) {
    44
    5   int i, j, k, n, m, N, J;
     5  int 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  int *N1, *N2,  *next_meas;
     10  int Nave, NAVE, Nmeas, NMEAS, Nmatch;
    1111  unsigned int objID, catID;
    12   Measure *tmpmeasure;
    13   Missing *tmpmissing;
    1412  Coords tcoords;
    1513  int Nsecfilt;
     
    4240  Nmeas = catalog[0].Nmeasure;
    4341  NMEAS = Nmeas + 1000;
    44   ALLOCATE (next, int, NMEAS);
     42  ALLOCATE (next_meas, int, NMEAS);
    4543  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);
    5444 
    5545  // current max obj ID for this catalog
     
    8272
    8373  /* 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;
     74  if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeas_disk)) {
     75    // this version is only valid if we have done a full catalog load, and if the catalog
     76    // is sorted while processed
     77    next_meas = init_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas);
     78  } else {
     79    next_meas = build_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas);
     80  }   
    9581
    9682  /* choose a radius for matches */
     
    126112      n = N2[J];
    127113      N = N1[i];
    128       m = catalog[0].average[n].measureOffset; 
    129114
    130115      /** 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;
     116      if (options.replace && replace_match (&catalog[0].average[n], catalog[0].measure, stars[N])) continue;
     117
     118      /* add to end of measurement list */
     119      add_meas_link (&catalog[0].average[n], next_meas, Nmeas, NMEAS);
    143120       
    144121      /** add measurements for this star **/
     
    206183      if (Nmeas == NMEAS) {
    207184        NMEAS = Nmeas + 1000;
    208         REALLOCATE (next, int, NMEAS);
     185        REALLOCATE (next_meas, int, NMEAS);
    209186        REALLOCATE (catalog[0].measure, Measure, NMEAS);
    210187      }
    211188
    212       update_coords (&catalog[0].average[n], &catalog[0].measure[0], next);
     189      update_coords (&catalog[0].average[n], &catalog[0].measure[0], next_meas);
    213190    }
    214191    i++;
     
    295272
    296273      stars[N][0].found = Nmeas;
    297       next[last] = Nmeas;
    298       next[Nmeas] = -1;
    299       last = Nmeas;
    300274      Nmeas ++;
    301275      if (Nmeas == NMEAS) {
    302276        NMEAS = Nmeas + 1000;
    303         REALLOCATE (next, int, NMEAS);
     277        REALLOCATE (next_meas, int, NMEAS);
    304278        REALLOCATE (catalog[0].measure, Measure, NMEAS);
    305279      }
     
    314288  }
    315289     
    316   free (catalog[0].found);
    317290  REALLOCATE (catalog[0].average, Average, Nave);
    318291
    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;
     292  // XXX allow for unsorted output?
     293  catalog[0].measure = sort_measure (catalog[0].average, Nave, catalog[0].measure, Nmeas, next_meas);
    349294
    350295  /* note stars which have been found in this catalog */
     
    357302  }
    358303
     304  catalog[0].objID    = objID; // new max value, save on catalog close
     305  catalog[0].Naverage = Nave;
     306  catalog[0].Nmeasure = Nmeas;
     307  catalog[0].Nsecf_mem = Nave*Nsecfilt;
     308  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmatch);
     309
     310  free (catalog[0].found);
    359311  free (X1);
    360312  free (Y1);
     
    363315  free (Y2);
    364316  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);
     317  free (next_meas);
     318
    374319  return (Nmatch);
    375320}
Note: See TracChangeset for help on using the changeset viewer.