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.c

    r21508 r27838  
    11# include "addstar.h"
    22
    3 int find_matches (SkyRegion *region, Stars *stars, int NstarsIn, Catalog *catalog, AddstarClientOptions options) {
    4 
    5   int i, j, n, N, J, status, Nstars;
     3int find_matches (SkyRegion *region, Stars *stars, unsigned int NstarsIn, Catalog *catalog, AddstarClientOptions options) {
     4
     5  off_t i, j, n, N, J, status, Nstars;
    66  double RADIUS, RADIUS2;
    77  double *X1, *Y1, *X2, *Y2;
    88  double dX, dY, dR;
    9   int *N1, *N2, *next_meas;
    10   int Nave, NAVE, Nmeas, NMEAS, Nmatch;
     9  off_t *N1, *N2, *next_meas;
     10  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch;
    1111  int Nsecfilt, Nsec;
    1212  unsigned int objID, catID;
    1313  Coords tcoords;
     14
     15  if (NSTAR_GROUP <= 0) {
     16      fprintf (stderr, "ERROR: NSTAR_GROUP NOT SET!\n");
     17      exit (1);
     18  }
    1419
    1520  /* photcode data - must by of type DEP; options.photcode is equiv photcode for all input
     
    2429  ALLOCATE (X1, double, NstarsIn);
    2530  ALLOCATE (Y1, double, NstarsIn);
    26   ALLOCATE (N1, int,   NstarsIn);
     31  ALLOCATE (N1, off_t,  NstarsIn);
    2732
    2833  /** allocate local arrays (catalog) **/
     
    3035  ALLOCATE (X2, double, NAVE);
    3136  ALLOCATE (Y2, double, NAVE);
    32   ALLOCATE (N2, int,   NAVE);
    33   ALLOCATE (catalog[0].found, int, NAVE);
     37  ALLOCATE (N2, off_t,  NAVE);
     38  ALLOCATE (catalog[0].found, off_t, NAVE);
    3439  /* for secfilt j and star i, secfilt[i*Nsecfilt+j] */
    3540
     
    103108
    104109  /** find matched stars **/
     110  // XXX could use NSTAR_GROUP to do this match more quicky if NSTAR_GROUP > 1
    105111  for (i = j = 0; (i < Nstars) && (j < Nave); ) {
    106112    if (!finite(X1[i]) || !finite(Y1[i])) {
     
    115121    /* negative dX: j is too large */
    116122    dX = X1[i] - X2[j];
    117     if (dX <= -2*RADIUS) {
     123    if (dX <= -1.02*RADIUS) {
    118124      i++;
    119125      continue;
    120126    }
    121127    /* positive dX, i is too large */
    122     if (dX >= 2*RADIUS) {
     128    if (dX >= 1.02*RADIUS) {
    123129      j++;
    124130      continue;
     
    126132
    127133    /* within match range; look for matches */
    128     for (J = j; (dX > -2*RADIUS) && (J < Nave); J++) {
     134    for (J = j; (dX > -1.02*RADIUS) && (J < Nave); J++) {
    129135      dX = X1[i] - X2[J];
    130136      dY = Y1[i] - Y2[J];
     
    132138      if (dR > RADIUS2) continue;
    133139
     140      /*** a match is found, add to average, measure ***/
     141      Nmatch ++;
     142      n = N2[J];
     143      N = N1[i];
     144
    134145      /* make sure there is space for next entry */
    135146      if (Nmeas >= NMEAS) {
    136147        NMEAS = Nmeas + 1000;
    137         REALLOCATE (next_meas, int, NMEAS);
     148        REALLOCATE (next_meas, off_t, NMEAS);
     149
    138150        REALLOCATE (catalog[0].measure, Measure, NMEAS);
    139151      }
    140 
    141       Nmatch ++;
    142       n = N2[J];
    143       N = N1[i];
    144152
    145153      /* add to end of measurement list */
     
    226234  /* incorporate unmatched image stars, if this star is in field of this catalog */
    227235  /* these new entries are all written out in UPDATE mode */
    228   for (i = 0; (i < Nstars) && !options.only_match; i++) {
     236  for (i = 0; (i < Nstars) && !options.only_match; i += NSTAR_GROUP) {
    229237    /* make sure there is space for next entry */
    230     if (Nmeas >= NMEAS) {
     238    if (Nmeas >= NMEAS - NSTAR_GROUP) {
    231239      NMEAS = Nmeas + 1000;
    232       REALLOCATE (next_meas, int, NMEAS);
     240      REALLOCATE (next_meas, off_t, NMEAS);
    233241      REALLOCATE (catalog[0].measure, Measure, NMEAS);
    234242    }
     
    248256    catalog[0].average[Nave].dD            = 0;
    249257
    250     catalog[0].average[Nave].Nmeasure      = 1;
     258    catalog[0].average[Nave].Nmeasure      = NSTAR_GROUP;
    251259    catalog[0].average[Nave].Nmissing      = 0;
    252260    catalog[0].average[Nave].Nextend       = 0;
     
    264272
    265273    catalog[0].average[Nave].Xp            = 0;
    266     catalog[0].average[Nave].ChiSq         = 0.0;
     274    catalog[0].average[Nave].ChiSqAve      = 0.0;
     275    catalog[0].average[Nave].ChiSqPM       = 0.0;
     276    catalog[0].average[Nave].ChiSqPar      = 0.0;
     277    catalog[0].average[Nave].Tmean         = 0;
     278    catalog[0].average[Nave].Trange        = 0;
    267279    catalog[0].average[Nave].Npos          = 0;
    268280
     
    270282    catalog[0].average[Nave].catID         = catID;
    271283    catalog[0].average[Nave].flags         = 0;
     284    if (PSPS_ID) {
     285        catalog[0].average[Nave].extID = CreatePSPSObjectID(catalog[0].average[Nave].R,
     286                                                            catalog[0].average[Nave].D);
     287    } else {
     288        catalog[0].average[Nave].extID         = 0;
     289    }
    272290
    273291    objID ++;
     
    283301    }
    284302
    285     // supply the measurments from this detection
    286     catalog[0].measure[Nmeas]           = stars[N].measure;
    287 
    288     // the following measure elements cannot be set until here:
    289     catalog[0].measure[Nmeas].dR        = 0.0;
    290     catalog[0].measure[Nmeas].dD        = 0.0;
    291     catalog[0].measure[Nmeas].dbFlags   = 0;
    292     catalog[0].measure[Nmeas].averef    = Nave; // XXX EAM : must be absolute Nave if partial read
    293     catalog[0].measure[Nmeas].objID     = catalog[0].average[Nave].objID;
    294     catalog[0].measure[Nmeas].catID     = catalog[0].catID;
    295 
    296     /* set the average magnitude if not already set and the photcode.equiv is not 0 */
    297     /* in UPDATE mode, this value is not saved; use relphot to recalculate */
    298     if (Nsec > -1) {
    299         catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
    300     }
    301 
    302     /* next[Nmeas] should always be -1 in this context (it is always the only
    303        measurement for the star) */
    304     stars[N].found = Nmeas;
    305     next_meas[Nmeas] = -1;
    306     Nmeas ++;
     303    for (j = 0; j < NSTAR_GROUP; j++) {
     304      // supply the measurments from this detection
     305      catalog[0].measure[Nmeas]           = stars[N].measure;
     306      N = N1[i + j];
     307
     308      // the following measure elements cannot be set until here:
     309      catalog[0].measure[Nmeas].dR              = 0.0;
     310      catalog[0].measure[Nmeas].dD              = 0.0;
     311      catalog[0].measure[Nmeas].dbFlags         = 0;
     312      catalog[0].measure[Nmeas].averef          = Nave; // XXX EAM : must be absolute Nave if partial read
     313      catalog[0].measure[Nmeas].objID     = catalog[0].average[Nave].objID;
     314      catalog[0].measure[Nmeas].catID     = catalog[0].catID;
     315
     316      /* set the average magnitude if not already set and the photcode.equiv is not 0 */
     317      /* in UPDATE mode, this value is not saved; use relphot to recalculate */
     318      if (Nsec > -1) {
     319          catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
     320      }
     321
     322      /* next[Nmeas] should always be -1 in this context (it is always the only
     323         measurement for the star) */
     324      stars[N].found = Nmeas;
     325      next_meas[Nmeas] = -1;  // initial value here update below
     326      Nmeas ++;
     327    }
     328    for (j = 0; j < NSTAR_GROUP - 1; j++) {
     329      next_meas[Nmeas - NSTAR_GROUP + j] = Nmeas - NSTAR_GROUP + j + 1;
     330    }
    307331    Nave ++;
    308332  }
     
    332356  catalog[0].Nmeasure = Nmeas;
    333357  catalog[0].Nsecf_mem = Nave*Nsecfilt;
    334   if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmatch);
     358  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);
    335359
    336360  free (catalog[0].found);
     
    338362  free (Y1);
    339363  free (N1);
     364  free (N2);
    340365  free (X2);
    341366  free (Y2);
    342   free (N2);
     367  free (next_meas);
     368
    343369  return (Nmatch);
    344370}
Note: See TracChangeset for help on using the changeset viewer.