IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39727


Ignore:
Timestamp:
Sep 27, 2016, 12:09:04 PM (10 years ago)
Author:
eugene
Message:

handle lensobj in merge; modify names to use full names (Nmeas to Nmeasure, etc)

Location:
branches/czw_branch/20160809/Ohana/src/dvomerge
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20160809/Ohana/src/dvomerge/include/dvomerge.h

    r39536 r39727  
    6161int    SKIP_MEASURE;
    6262int    SKIP_LENSING;
     63int    SKIP_LENSOBJ;
    6364int    SKIP_STARPAR;
    6465int    SKIP_GALPHOT;
     
    171172off_t     *build_measure_links    PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
    172173off_t     *init_measure_links     PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
    173 int        add_meas_link          PROTO((Average *average, off_t *next, off_t Nmeasure, off_t NMEASURE));
     174int        add_measure_link       PROTO((Average *average, off_t *next, off_t Nmeasure, off_t NMEASURE));
    174175Measure   *sort_measure           PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next));
    175176
    176177off_t     *build_lensing_links    PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
    177178off_t     *init_lensing_links     PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
    178 int        add_lens_link          PROTO((Average *average, off_t *next, off_t Nlensing, off_t NLENSING));
     179int        add_lensing_link       PROTO((Average *average, off_t *next, off_t Nlensing, off_t NLENSING));
    179180Lensing   *sort_lensing           PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next));
     181
     182off_t     *build_lensobj_links    PROTO((Average *average, off_t Naverage, Lensobj *lensobj, off_t Nlensobj));
     183off_t     *init_lensobj_links     PROTO((Average *average, off_t Naverage, Lensobj *lensobj, off_t Nlensobj));
     184int        add_lensobj_link       PROTO((Average *average, off_t *next, off_t Nlensobj, off_t NLENSOBJ));
     185Lensobj   *sort_lensobj           PROTO((Average *average, off_t Naverage, Lensobj *lensobj, off_t Nlensobj, off_t *next));
    180186
    181187off_t     *build_starpar_links    PROTO((Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar));
    182188off_t     *init_starpar_links     PROTO((Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar));
    183 int        add_star_link          PROTO((Average *average, off_t *next, off_t Nstarpar, off_t NSTARPAR));
     189int        add_starpar_link               PROTO((Average *average, off_t *next, off_t Nstarpar, off_t NSTARPAR));
    184190StarPar   *sort_starpar           PROTO((Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar, off_t *next));
    185191
    186192off_t     *build_galphot_links    PROTO((Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot));
    187193off_t     *init_galphot_links     PROTO((Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot));
    188 int        add_galp_link          PROTO((Average *average, off_t *next, off_t Ngalphot, off_t NGALPHOT));
     194int        add_galphot_link               PROTO((Average *average, off_t *next, off_t Ngalphot, off_t NGALPHOT));
    189195GalPhot   *sort_galphot           PROTO((Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot, off_t *next));
    190196
    191197off_t     *init_missing_links     PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing));
    192 int        add_miss_link          PROTO((Average *average, off_t *next, off_t Nmissing));
     198int        add_missing_link               PROTO((Average *average, off_t *next, off_t Nmissing));
    193199Missing   *sort_missing           PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss));
    194200
  • branches/czw_branch/20160809/Ohana/src/dvomerge/src/LoadCatalog.c

    r39714 r39727  
    1010  // always load all of the data (if any exists)
    1111
    12   catalog[0].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT | DVO_LOAD_LENSOBJ;
     12  catalog[0].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    1313
    1414  if (SKIP_MEASURE) {
     
    2222  } else {
    2323    catalog[0].catflags = catalog[0].catflags | DVO_LOAD_LENSING;
     24  }
     25
     26  if (SKIP_LENSOBJ)  {
     27    catalog[0].catflags = catalog[0].catflags | DVO_SKIP_LENSOBJ;
     28  } else {
     29    catalog[0].catflags = catalog[0].catflags | DVO_LOAD_LENSOBJ;
    2430  }
    2531
  • branches/czw_branch/20160809/Ohana/src/dvomerge/src/args.c

    r39536 r39727  
    5656  if ((N = get_argument (*argc, argv, "-skip-lensing"))) {
    5757    SKIP_LENSING = TRUE;
     58    remove_argument (N, argc, argv);
     59  }
     60  SKIP_LENSOBJ = FALSE;
     61  if ((N = get_argument (*argc, argv, "-skip-lensobj"))) {
     62    SKIP_LENSOBJ = TRUE;
    5863    remove_argument (N, argc, argv);
    5964  }
     
    340345    remove_argument (N, argc, argv);
    341346  }
     347  SKIP_LENSOBJ = FALSE;
     348  if ((N = get_argument (*argc, argv, "-skip-lensobj"))) {
     349    SKIP_LENSOBJ = TRUE;
     350    remove_argument (N, argc, argv);
     351  }
    342352  SKIP_STARPAR = FALSE;
    343353  if ((N = get_argument (*argc, argv, "-skip-starpar"))) {
  • branches/czw_branch/20160809/Ohana/src/dvomerge/src/build_links.c

    r39536 r39727  
    1515data: they refer to the sequence number in the data blocks.
    1616
    17 next_meas is a list of the equivalent sequence of the measure block as if it were sorted.
     17next_measure is a list of the equivalent sequence of the measure block as if it were sorted.
    1818
    1919to find the sequence of measurements for a given average:
    2020n_0 = average->measureOffset
    21 n_1 = next_meas[n_0]
    22 n_i = next_meas[n_i-1]
     21n_1 = next_measure[n_0]
     22n_i = next_measure[n_i-1]
    2323
    2424*/
     
    3131
    3232  off_t i, j, N;
    33   off_t *next_meas;
     33  off_t *next_measure;
    3434
    3535  if (!measure) return NULL;
     
    3838  N = 0;
    3939
    40   ALLOCATE (next_meas, off_t, Nmeasure);
     40  ALLOCATE (next_measure, off_t, Nmeasure);
    4141  for (i = 0; i < Naverage; i++) {
    4242    if (!average[i].Nmeasure) continue;
     
    4545    for (j = 0; j < average[i].Nmeasure - 1; j++, N++) {
    4646      myAssert (measure[m+j+1].averef == i, "not sorted");
    47       next_meas[N] = N + 1;
     47      next_measure[N] = N + 1;
    4848      if (N >= Nmeasure) {
    4949        fprintf (stderr, "WARNING: N out of bounds (1)\n");
    5050      }
    5151    }
    52     next_meas[N] = -1;
     52    next_measure[N] = -1;
    5353    if (N >= Nmeasure) {
    5454      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     
    6161    N++;
    6262  }
    63   return (next_meas);
     63  return (next_measure);
    6464}
    6565
     
    7474
    7575  off_t i, m, k, Nm, averef;
    76   off_t *next_meas;
    77 
    78   ALLOCATE (next_meas, off_t, Nmeasure);
     76  off_t *next_measure;
     77
     78  ALLOCATE (next_measure, off_t, Nmeasure);
    7979
    8080  /* reset the Nm, offset values for average */
     
    8787    averef = measure[Nm].averef;
    8888    m = average[averef].measureOffset; 
    89     next_meas[Nm] = -1;
     89    next_measure[Nm] = -1;
    9090
    9191    if (m == -1) { /* no links yet for source */
     
    9595    }
    9696
    97     for (k = 0; next_meas[m] != -1; k++) {
    98       m = next_meas[m];
     97    for (k = 0; next_measure[m] != -1; k++) {
     98      m = next_measure[m];
    9999      if (m >= Nmeasure) {
    100100        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     
    103103
    104104    average[averef].Nmeasure = k + 2;
    105     next_meas[m] = Nm;
     105    next_measure[m] = Nm;
    106106    if (m >= Nmeasure) {
    107107      fprintf (stderr, "WARNING: m out of bounds (2)\n");
    108108    }
    109109  }
    110   return (next_meas);
     110  return (next_measure);
    111111}
    112112
    113113/* average[].measureOffset, average[].Nmeasure are valid within an addstar run */
    114 int add_meas_link (Average *average, off_t *next_meas, off_t Nmeasure, off_t NMEASURE) {
     114int add_measure_link (Average *average, off_t *next_measure, off_t Nmeasure, off_t NMEASURE) {
    115115
    116116  off_t k, m;
    117117
    118   /* if we have trouble, check validity of next_meas[m] : m < Nmeasure */
     118  /* if we have trouble, check validity of next_measure[m] : m < Nmeasure */
    119119  m = average[0].measureOffset; 
    120120
    121121  for (k = 0; k < average[0].Nmeasure - 1; k++)  {
    122     m = next_meas[m];
     122    m = next_measure[m];
    123123    if (m >= NMEASURE) {
    124124      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     
    127127
    128128  /* set up references */
    129   next_meas[Nmeasure] = -1;
     129  next_measure[Nmeasure] = -1;
    130130  if (Nmeasure >= NMEASURE) {
    131131    fprintf (stderr, "WARNING: Nmeasure out of bounds (1)\n");
     
    136136    average[0].measureOffset = Nmeasure;
    137137  } else {
    138     next_meas[m] = Nmeasure;
     138    next_measure[m] = Nmeasure;
    139139    if (m >= NMEASURE) {
    140140      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     
    145145}
    146146
    147 Measure *sort_measure (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next_meas) {
     147Measure *sort_measure (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next_measure) {
    148148
    149149  off_t i, k, n, np, N;
     
    169169      tmpmeasure[N].averef = i;
    170170      np = n;
    171       n = next_meas[n];
     171      n = next_measure[n];
    172172    }
    173173  }
     
    183183
    184184  off_t i, j, N;
    185   off_t *next_miss;
     185  off_t *next_missing;
    186186
    187187  N = 0;
    188188
    189   ALLOCATE (next_miss, off_t, Nmissing);
     189  ALLOCATE (next_missing, off_t, Nmissing);
    190190  for (i = 0; i < Naverage; i++) {
    191191    for (j = 0; j < average[i].Nmissing - 1; j++, N++) {
    192       next_miss[N] = N + 1;
     192      next_missing[N] = N + 1;
    193193    }
    194194    if (average[i].Nmissing > 0) {
    195       next_miss[N] = -1;
     195      next_missing[N] = -1;
    196196      if (N >= Nmissing) {
    197197        fprintf (stderr, "overflow in init_missing_links");
     
    202202
    203203  }
    204   return (next_miss);
    205 }
    206 
    207 int add_miss_link (Average *average, off_t *next_miss, off_t Nmissing) {
     204  return (next_missing);
     205}
     206
     207int add_missing_link (Average *average, off_t *next_missing, off_t Nmissing) {
    208208
    209209  off_t k, m;
     
    212212  if (average[0].Nmissing < 1) {
    213213    average[0].missingOffset = Nmissing;
    214     next_miss[Nmissing] = -1;
     214    next_missing[Nmissing] = -1;
    215215    return (TRUE);
    216216  }
    217217
    218218  m = average[0].missingOffset; 
    219   for (k = 0; k < average[0].Nmissing - 1; k++) m = next_miss[m];
     219  for (k = 0; k < average[0].Nmissing - 1; k++) m = next_missing[m];
    220220  /* set up references */
    221   next_miss[Nmissing] = -1;
    222   next_miss[m] = Nmissing;
     221  next_missing[Nmissing] = -1;
     222  next_missing[m] = Nmissing;
    223223  return (TRUE);
    224224}
     
    227227   we must always save the missing table, if it exists */
    228228
    229 Missing *sort_missing (Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss) {
     229Missing *sort_missing (Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_missing) {
    230230
    231231  off_t i, k, n, N;
     
    240240    for (k = 0; k < average[i].Nmissing; k++, N++) {
    241241      tmpmissing[N] = missing[n];
    242       n = next_miss[n];
     242      n = next_missing[n];
    243243    }
    244244  }
     
    254254
    255255  off_t i, j, N;
    256   off_t *next_lens;
     256  off_t *next_lensing;
    257257
    258258  if (!lensing) return NULL;
     
    261261  N = 0;
    262262
    263   ALLOCATE (next_lens, off_t, Nlensing);
     263  ALLOCATE (next_lensing, off_t, Nlensing);
    264264  for (i = 0; i < Naverage; i++) {
    265265    if (!average[i].Nlensing) continue;
     
    268268    for (j = 0; j < average[i].Nlensing - 1; j++, N++) {
    269269      myAssert (lensing[m+j+1].averef == i, "not sorted");
    270       next_lens[N] = N + 1;
     270      next_lensing[N] = N + 1;
    271271      if (N >= Nlensing) {
    272272        fprintf (stderr, "WARNING: N out of bounds (1)\n");
    273273      }
    274274    }
    275     next_lens[N] = -1;
     275    next_lensing[N] = -1;
    276276    if (N >= Nlensing) {
    277277      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     
    284284    N++;
    285285  }
    286   return (next_lens);
     286  return (next_lensing);
    287287}
    288288
     
    297297
    298298  off_t i, m, k, Nm, averef;
    299   off_t *next_lens;
    300 
    301   ALLOCATE (next_lens, off_t, Nlensing);
     299  off_t *next_lensing;
     300
     301  ALLOCATE (next_lensing, off_t, Nlensing);
    302302
    303303  /* reset the Nm, offset values for average */
     
    310310    averef = lensing[Nm].averef;
    311311    m = average[averef].lensingOffset; 
    312     next_lens[Nm] = -1;
     312    next_lensing[Nm] = -1;
    313313
    314314    if (m == -1) { /* no links yet for source */
     
    318318    }
    319319
    320     for (k = 0; next_lens[m] != -1; k++) {
    321       m = next_lens[m];
     320    for (k = 0; next_lensing[m] != -1; k++) {
     321      m = next_lensing[m];
    322322      if (m >= Nlensing) {
    323323        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     
    326326
    327327    average[averef].Nlensing = k + 2;
    328     next_lens[m] = Nm;
     328    next_lensing[m] = Nm;
    329329    if (m >= Nlensing) {
    330330      fprintf (stderr, "WARNING: m out of bounds (2)\n");
    331331    }
    332332  }
    333   return (next_lens);
     333  return (next_lensing);
    334334}
    335335
    336336/* average[].lensingOffset, average[].Nlensing are valid within an addstar run */
    337 int add_lens_link (Average *average, off_t *next_lens, off_t Nlensing, off_t NLENSING) {
     337int add_lensing_link (Average *average, off_t *next_lensing, off_t Nlensing, off_t NLENSING) {
    338338
    339339  off_t k, m;
    340340
    341   /* if we have trouble, check validity of next_lens[m] : m < Nlensing */
     341  /* if we have trouble, check validity of next_lensing[m] : m < Nlensing */
    342342  m = average[0].lensingOffset; 
    343343
    344344  for (k = 0; k < average[0].Nlensing - 1; k++)  {
    345     m = next_lens[m];
     345    m = next_lensing[m];
    346346    if (m >= NLENSING) {
    347347      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     
    350350
    351351  /* set up references */
    352   next_lens[Nlensing] = -1;
     352  next_lensing[Nlensing] = -1;
    353353  if (Nlensing >= NLENSING) {
    354354    fprintf (stderr, "WARNING: Nlensing out of bounds (1)\n");
     
    359359    average[0].lensingOffset = Nlensing;
    360360  } else {
    361     next_lens[m] = Nlensing;
     361    next_lensing[m] = Nlensing;
    362362    if (m >= NLENSING) {
    363363      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     
    368368}
    369369
    370 Lensing *sort_lensing (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next_lens) {
     370Lensing *sort_lensing (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next_lensing) {
    371371
    372372  off_t i, k, n, np, N;
     
    392392      tmplensing[N].averef = i;
    393393      np = n;
    394       n = next_lens[n];
     394      n = next_lensing[n];
    395395    }
    396396  }
    397397  free (lensing);
    398398  return (tmplensing);
     399}
     400
     401/*** Lensobj ****************************************************************************************/
     402
     403/* build the initial links assuming the table is sorted,
     404   not partial, and has a correct set of average[].lensobjOffset,Nlensobj values */
     405off_t *init_lensobj_links (Average *average, off_t Naverage, Lensobj *lensobj, off_t Nlensobj) {
     406
     407  off_t i, j, N;
     408  off_t *next_lensobj;
     409
     410  if (!lensobj) return NULL;
     411  if (SKIP_LENSOBJ) return NULL;
     412
     413  N = 0;
     414
     415  ALLOCATE (next_lensobj, off_t, Nlensobj);
     416  for (i = 0; i < Naverage; i++) {
     417    if (!average[i].Nlensobj) continue;
     418    // off_t m = average[i].lensobjOffset;
     419    // myAssert (lensobj[m].averef == i, "not sorted");
     420    for (j = 0; j < average[i].Nlensobj - 1; j++, N++) {
     421      // myAssert (lensobj[m+j+1].averef == i, "not sorted");
     422      next_lensobj[N] = N + 1;
     423      if (N >= Nlensobj) {
     424        fprintf (stderr, "WARNING: N out of bounds (1)\n");
     425      }
     426    }
     427    next_lensobj[N] = -1;
     428    if (N >= Nlensobj) {
     429      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     430    }
     431
     432    if (N >= Nlensobj) {
     433      fprintf (stderr, "overflow in init_lensobj_links\n");
     434      abort ();
     435    }
     436    N++;
     437  }
     438  return (next_lensobj);
     439}
     440
     441/* construct lensobj links which are valid FOR THIS LOAD
     442 * - if we have a full load, we will get links which can
     443 *   be used by other programs (eg, relphot, etc)
     444 * - if we have a partial load, the links are only valid
     445 *   for that partial load
     446 */
     447
     448off_t *build_lensobj_links (Average *average, off_t Naverage, Lensobj *lensobj, off_t Nlensobj) {
     449
     450  fprintf (stderr, "input is not sorted but contains lensobj -- trouble\n");
     451  exit (2);
     452
     453# if (0)
     454
     455  off_t i, m, k, Nm, averef;
     456  off_t *next_lensobj;
     457
     458  ALLOCATE (next_lensobj, off_t, Nlensobj);
     459
     460  /* reset the Nm, offset values for average */
     461  for (i = 0; i < Naverage; i++) {
     462    average[i].lensobjOffset = -1;
     463    average[i].Nlensobj     =  0;
     464  }
     465
     466  for (Nm = 0; Nm < Nlensobj; Nm++) {
     467    averef = lensobj[Nm].averef;
     468    m = average[averef].lensobjOffset; 
     469    next_lensobj[Nm] = -1;
     470
     471    if (m == -1) { /* no links yet for source */
     472      average[averef].lensobjOffset = Nm;
     473      average[averef].Nlensobj     = 1;
     474      continue;
     475    }
     476
     477    for (k = 0; next_lensobj[m] != -1; k++) {
     478      m = next_lensobj[m];
     479      if (m >= Nlensobj) {
     480        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     481      }
     482    }
     483
     484    average[averef].Nlensobj = k + 2;
     485    next_lensobj[m] = Nm;
     486    if (m >= Nlensobj) {
     487      fprintf (stderr, "WARNING: m out of bounds (2)\n");
     488    }
     489  }
     490  return (next_lensobj);
     491# endif
     492}
     493
     494/* average[].lensobjOffset, average[].Nlensobj are valid within an addstar run */
     495int add_lensobj_link (Average *average, off_t *next_lensobj, off_t Nlensobj, off_t NLENSOBJ) {
     496
     497  off_t k, m;
     498
     499  /* if we have trouble, check validity of next_lensobj[m] : m < Nlensobj */
     500  m = average[0].lensobjOffset; 
     501
     502  for (k = 0; k < average[0].Nlensobj - 1; k++)  {
     503    m = next_lensobj[m];
     504    if (m >= NLENSOBJ) {
     505      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     506    }
     507  }
     508
     509  /* set up references */
     510  next_lensobj[Nlensobj] = -1;
     511  if (Nlensobj >= NLENSOBJ) {
     512    fprintf (stderr, "WARNING: Nlensobj out of bounds (1)\n");
     513  }
     514
     515  // if Nlensobj is 0, m may have been mis-set; add to the end
     516  if ((average[0].Nlensobj == 0) || (m == -1)) {
     517    average[0].lensobjOffset = Nlensobj;
     518  } else {
     519    next_lensobj[m] = Nlensobj;
     520    if (m >= NLENSOBJ) {
     521      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     522    }
     523  }
     524
     525  return (TRUE);
     526}
     527
     528Lensobj *sort_lensobj (Average *average, off_t Naverage, Lensobj *lensobj, off_t Nlensobj, off_t *next_lensobj) {
     529
     530  off_t i, k, n, np, N;
     531  Lensobj *tmplensobj;
     532
     533  /* fix order of Lensobj (memory intensive, but fast) */
     534  np = -1;
     535  N = 0;
     536  ALLOCATE (tmplensobj, Lensobj, Nlensobj);
     537  for (i = 0; i < Naverage; i++) {
     538    if (!average[i].Nlensobj) continue;
     539    n = average[i].lensobjOffset;
     540    average[i].lensobjOffset = N;
     541    int myObjID = average[i].objID;
     542    for (k = 0; k < average[i].Nlensobj; k++, N++) {
     543      if (n == -1) {
     544        fprintf (stderr, "entry after %d has a problem\n", (int) np);
     545        abort();
     546      }
     547      tmplensobj[N] = lensobj[n];
     548      // myAssert (lensobj[n].averef == i, "error in averef");
     549      myAssert ((lensobj[n].objID == myObjID) || (lensobj[n].objID == -1), "error in objID?");
     550      // tmplensobj[N].averef = i;
     551      np = n;
     552      n = next_lensobj[n];
     553    }
     554  }
     555  free (lensobj);
     556  return (tmplensobj);
    399557}
    400558
     
    406564
    407565  off_t i, j, N;
    408   off_t *next_star;
     566  off_t *next_starpar;
    409567
    410568  if (!starpar) return NULL;
     
    415573  // NOTE that is we choose DVO_SKIP_STARPAR, catalog.starpar is NULL.
    416574  // this code will let merge_catalogs_old.c do nothing for starpar
    417   ALLOCATE (next_star, off_t, Nstarpar);
    418   if (!starpar) return next_star;
     575  ALLOCATE (next_starpar, off_t, Nstarpar);
     576  if (!starpar) return next_starpar;
    419577
    420578  for (i = 0; i < Naverage; i++) {
     
    424582    for (j = 0; j < average[i].Nstarpar - 1; j++, N++) {
    425583      myAssert (starpar[m+j+1].averef == i, "not sorted");
    426       next_star[N] = N + 1;
     584      next_starpar[N] = N + 1;
    427585      if (N >= Nstarpar) {
    428586        fprintf (stderr, "WARNING: N out of bounds (1)\n");
    429587      }
    430588    }
    431     next_star[N] = -1;
     589    next_starpar[N] = -1;
    432590    if (N >= Nstarpar) {
    433591      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     
    440598    N++;
    441599  }
    442   return (next_star);
     600  return (next_starpar);
    443601}
    444602
     
    453611
    454612  off_t i, m, k, Nm, averef;
    455   off_t *next_star;
    456 
    457   ALLOCATE (next_star, off_t, Nstarpar);
    458   if (!starpar) return next_star;
     613  off_t *next_starpar;
     614
     615  ALLOCATE (next_starpar, off_t, Nstarpar);
     616  if (!starpar) return next_starpar;
    459617
    460618  /* reset the Nm, offset values for average */
     
    467625    averef = starpar[Nm].averef;
    468626    m = average[averef].starparOffset; 
    469     next_star[Nm] = -1;
     627    next_starpar[Nm] = -1;
    470628
    471629    if (m == -1) { /* no links yet for source */
     
    475633    }
    476634
    477     for (k = 0; next_star[m] != -1; k++) {
    478       m = next_star[m];
     635    for (k = 0; next_starpar[m] != -1; k++) {
     636      m = next_starpar[m];
    479637      if (m >= Nstarpar) {
    480638        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     
    483641
    484642    average[averef].Nstarpar = k + 2;
    485     next_star[m] = Nm;
     643    next_starpar[m] = Nm;
    486644    if (m >= Nstarpar) {
    487645      fprintf (stderr, "WARNING: m out of bounds (2)\n");
    488646    }
    489647  }
    490   return (next_star);
     648  return (next_starpar);
    491649}
    492650
    493651/* average[].starparOffset, average[].Nstarpar are valid within an addstar run */
    494 int add_star_link (Average *average, off_t *next_star, off_t Nstarpar, off_t NSTARPAR) {
     652int add_starpar_link (Average *average, off_t *next_starpar, off_t Nstarpar, off_t NSTARPAR) {
    495653
    496654  off_t k, m;
    497655
    498   /* if we have trouble, check validity of next_star[m] : m < Nstarpar */
     656  /* if we have trouble, check validity of next_starpar[m] : m < Nstarpar */
    499657  m = average[0].starparOffset; 
    500658
    501659  for (k = 0; k < average[0].Nstarpar - 1; k++)  {
    502     m = next_star[m];
     660    m = next_starpar[m];
    503661    if (m >= NSTARPAR) {
    504662      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     
    507665
    508666  /* set up references */
    509   next_star[Nstarpar] = -1;
     667  next_starpar[Nstarpar] = -1;
    510668  if (Nstarpar >= NSTARPAR) {
    511669    fprintf (stderr, "WARNING: Nstarpar out of bounds (1)\n");
     
    516674    average[0].starparOffset = Nstarpar;
    517675  } else {
    518     next_star[m] = Nstarpar;
     676    next_starpar[m] = Nstarpar;
    519677    if (m >= NSTARPAR) {
    520678      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     
    525683}
    526684
    527 StarPar *sort_starpar (Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar, off_t *next_star) {
     685StarPar *sort_starpar (Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar, off_t *next_starpar) {
    528686
    529687  off_t i, k, n, np, N;
     
    552710      tmpstarpar[N].averef = i;
    553711      np = n;
    554       n = next_star[n];
     712      n = next_starpar[n];
    555713    }
    556714  }
     
    566724
    567725  off_t i, j, N;
    568   off_t *next_galp;
     726  off_t *next_galphot;
    569727
    570728  if (galphot) return NULL;
     
    573731  N = 0;
    574732
    575   ALLOCATE (next_galp, off_t, Ngalphot);
     733  ALLOCATE (next_galphot, off_t, Ngalphot);
    576734  for (i = 0; i < Naverage; i++) {
    577735    if (!average[i].Ngalphot) continue;
     
    580738    for (j = 0; j < average[i].Ngalphot - 1; j++, N++) {
    581739      myAssert (galphot[m+j+1].averef == i, "not sorted");
    582       next_galp[N] = N + 1;
     740      next_galphot[N] = N + 1;
    583741      if (N >= Ngalphot) {
    584742        fprintf (stderr, "WARNING: N out of bounds (1)\n");
    585743      }
    586744    }
    587     next_galp[N] = -1;
     745    next_galphot[N] = -1;
    588746    if (N >= Ngalphot) {
    589747      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     
    596754    N++;
    597755  }
    598   return (next_galp);
     756  return (next_galphot);
    599757}
    600758
     
    609767
    610768  off_t i, m, k, Nm, averef;
    611   off_t *next_galp;
    612 
    613   ALLOCATE (next_galp, off_t, Ngalphot);
     769  off_t *next_galphot;
     770
     771  ALLOCATE (next_galphot, off_t, Ngalphot);
    614772
    615773  /* reset the Nm, offset values for average */
     
    622780    averef = galphot[Nm].averef;
    623781    m = average[averef].galphotOffset; 
    624     next_galp[Nm] = -1;
     782    next_galphot[Nm] = -1;
    625783
    626784    if (m == -1) { /* no links yet for source */
     
    630788    }
    631789
    632     for (k = 0; next_galp[m] != -1; k++) {
    633       m = next_galp[m];
     790    for (k = 0; next_galphot[m] != -1; k++) {
     791      m = next_galphot[m];
    634792      if (m >= Ngalphot) {
    635793        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     
    638796
    639797    average[averef].Ngalphot = k + 2;
    640     next_galp[m] = Nm;
     798    next_galphot[m] = Nm;
    641799    if (m >= Ngalphot) {
    642800      fprintf (stderr, "WARNING: m out of bounds (2)\n");
    643801    }
    644802  }
    645   return (next_galp);
     803  return (next_galphot);
    646804}
    647805
    648806/* average[].galphotOffset, average[].Ngalphot are valid within an addstar run */
    649 int add_galp_link (Average *average, off_t *next_galp, off_t Ngalphot, off_t NGALPHOT) {
     807int add_galphot_link (Average *average, off_t *next_galphot, off_t Ngalphot, off_t NGALPHOT) {
    650808
    651809  off_t k, m;
    652810
    653   /* if we have trouble, check validity of next_galp[m] : m < Ngalphot */
     811  /* if we have trouble, check validity of next_galphot[m] : m < Ngalphot */
    654812  m = average[0].galphotOffset; 
    655813
    656814  for (k = 0; k < average[0].Ngalphot - 1; k++)  {
    657     m = next_galp[m];
     815    m = next_galphot[m];
    658816    if (m >= NGALPHOT) {
    659817      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     
    662820
    663821  /* set up references */
    664   next_galp[Ngalphot] = -1;
     822  next_galphot[Ngalphot] = -1;
    665823  if (Ngalphot >= NGALPHOT) {
    666824    fprintf (stderr, "WARNING: Ngalphot out of bounds (1)\n");
     
    671829    average[0].galphotOffset = Ngalphot;
    672830  } else {
    673     next_galp[m] = Ngalphot;
     831    next_galphot[m] = Ngalphot;
    674832    if (m >= NGALPHOT) {
    675833      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     
    680838}
    681839
    682 GalPhot *sort_galphot (Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot, off_t *next_galp) {
     840GalPhot *sort_galphot (Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot, off_t *next_galphot) {
    683841
    684842  off_t i, k, n, np, N;
     
    704862      tmpgalphot[N].averef = i;
    705863      np = n;
    706       n = next_galp[n];
     864      n = next_galphot[n];
    707865    }
    708866  }
  • branches/czw_branch/20160809/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c

    r39536 r39727  
    336336    if (SKIP_MEASURE)               { strextend (&command, "-skip-measure"); }
    337337    if (SKIP_LENSING)               { strextend (&command, "-skip-lensing"); }
     338    if (SKIP_LENSOBJ)               { strextend (&command, "-skip-lensobj"); }
    338339    if (SKIP_GALPHOT)               { strextend (&command, "-skip-galphot"); }
    339340    if (SKIP_STARPAR)               { strextend (&command, "-skip-starpar"); }
  • branches/czw_branch/20160809/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r39342 r39727  
    1414  double *X1, *Y1, *X2, *Y2;
    1515  double dX, dY, dR;
    16   off_t *N1, *N2, *next_meas, *next_lens, *next_star, *next_galp;
    17   off_t Nave, NAVE, Nmeas, NMEAS, Nmatch, Nlens, NLENS, Nstar, NSTAR, Ngalp, NGALP;
     16  off_t *N1, *N2, *next_measure, *next_lensing, *next_lensobj, *next_starpar, *next_galphot;
     17  off_t Nave, NAVE, Nmeasure, NMEASURE, Nmatch, Nlensing, NLENSING, Nlensobj, NLENSOBJ, Nstarpar, NSTARPAR, Ngalphot, NGALPHOT;
    1818  int NsecfiltIn;
    1919  int NsecfiltOut;
     
    5151  /* internal counters */
    5252  Nmatch = 0;
    53   NMEAS = Nmeas = output[0].Nmeasure;
    54   NLENS = Nlens = output[0].Nlensing;
    55   NSTAR = Nstar = output[0].Nstarpar;
    56   NGALP = Ngalp = output[0].Ngalphot;
     53  NMEASURE = Nmeasure = output[0].Nmeasure;
     54  NLENSING = Nlensing = output[0].Nlensing;
     55  NLENSOBJ = Nlensobj = output[0].Nlensobj;
     56  NSTARPAR = Nstarpar = output[0].Nstarpar;
     57  NGALPHOT = Ngalphot = output[0].Ngalphot;
    5758
    5859  // current max obj ID for this catalog
     
    116117    // this version is only valid if we have done a full catalog load, and if the catalog
    117118    // is sorted while processed
    118     next_meas = init_measure_links (output[0].average, Nave, output[0].measure, Nmeas);
    119     next_lens = init_lensing_links (output[0].average, Nave, output[0].lensing, Nlens);
    120     next_star = init_starpar_links (output[0].average, Nave, output[0].starpar, Nstar);
    121     next_galp = init_galphot_links (output[0].average, Nave, output[0].galphot, Ngalp);
     119    next_measure = init_measure_links (output[0].average, Nave, output[0].measure, Nmeasure);
     120    next_lensing = init_lensing_links (output[0].average, Nave, output[0].lensing, Nlensing);
     121    next_lensobj = init_lensobj_links (output[0].average, Nave, output[0].lensobj, Nlensobj);
     122    next_starpar = init_starpar_links (output[0].average, Nave, output[0].starpar, Nstarpar);
     123    next_galphot = init_galphot_links (output[0].average, Nave, output[0].galphot, Ngalphot);
    122124  } else {
    123     next_meas = build_measure_links (output[0].average, Nave, output[0].measure, Nmeas);
    124     next_lens = build_lensing_links (output[0].average, Nave, output[0].lensing, Nlens);
    125     next_star = build_starpar_links (output[0].average, Nave, output[0].starpar, Nstar);
    126     next_galp = build_galphot_links (output[0].average, Nave, output[0].galphot, Ngalp);
     125    next_measure = build_measure_links (output[0].average, Nave, output[0].measure, Nmeasure);
     126    next_lensing = build_lensing_links (output[0].average, Nave, output[0].lensing, Nlensing);
     127    next_lensobj = build_lensobj_links (output[0].average, Nave, output[0].lensobj, Nlensobj);
     128    next_starpar = build_starpar_links (output[0].average, Nave, output[0].starpar, Nstarpar);
     129    next_galphot = build_galphot_links (output[0].average, Nave, output[0].galphot, Ngalphot);
    127130  }   
    128131
     
    183186
    184187    /* make sure there is space for next Nmeasure entries */
    185     if (Nmeas + input[0].average[N].Nmeasure >= NMEAS) {
    186       NMEAS = Nmeas + input[0].average[N].Nmeasure + 1000;
    187       REALLOCATE (next_meas, off_t, NMEAS);
    188       REALLOCATE (output[0].measure, Measure, NMEAS);
    189     }
    190     if (Nlens + input[0].average[N].Nlensing >= NLENS) {
    191       NLENS = Nlens + input[0].average[N].Nlensing + 1000;
    192       REALLOCATE (next_lens, off_t, NLENS);
    193       REALLOCATE (output[0].lensing, Lensing, NLENS);
    194     }
    195     if (Nstar + input[0].average[N].Nstarpar >= NSTAR) {
    196       NSTAR = Nstar + input[0].average[N].Nstarpar + 1000;
    197       REALLOCATE (next_star, off_t, NSTAR);
    198       REALLOCATE (output[0].starpar, StarPar, NSTAR);
    199     }
    200     if (Ngalp + input[0].average[N].Ngalphot >= NGALP) {
    201       NGALP = Ngalp + input[0].average[N].Ngalphot + 1000;
    202       REALLOCATE (next_galp, off_t, NGALP);
    203       REALLOCATE (output[0].galphot, GalPhot, NGALP);
     188    if (Nmeasure + input[0].average[N].Nmeasure >= NMEASURE) {
     189      NMEASURE = Nmeasure + input[0].average[N].Nmeasure + 1000;
     190      REALLOCATE (next_measure, off_t, NMEASURE);
     191      REALLOCATE (output[0].measure, Measure, NMEASURE);
     192    }
     193    if (Nlensing + input[0].average[N].Nlensing >= NLENSING) {
     194      NLENSING = Nlensing + input[0].average[N].Nlensing + 1000;
     195      REALLOCATE (next_lensing, off_t, NLENSING);
     196      REALLOCATE (output[0].lensing, Lensing, NLENSING);
     197    }
     198    if (Nlensobj + input[0].average[N].Nlensobj >= NLENSOBJ) {
     199      NLENSOBJ = Nlensobj + input[0].average[N].Nlensobj + 1000;
     200      REALLOCATE (next_lensobj, off_t, NLENSOBJ);
     201      REALLOCATE (output[0].lensobj, Lensobj, NLENSOBJ);
     202    }
     203    if (Nstarpar + input[0].average[N].Nstarpar >= NSTARPAR) {
     204      NSTARPAR = Nstarpar + input[0].average[N].Nstarpar + 1000;
     205      REALLOCATE (next_starpar, off_t, NSTARPAR);
     206      REALLOCATE (output[0].starpar, StarPar, NSTARPAR);
     207    }
     208    if (Ngalphot + input[0].average[N].Ngalphot >= NGALPHOT) {
     209      NGALPHOT = Ngalphot + input[0].average[N].Ngalphot + 1000;
     210      REALLOCATE (next_galphot, off_t, NGALPHOT);
     211      REALLOCATE (output[0].galphot, GalPhot, NGALPHOT);
    204212    }
    205213
     
    212220      if (REPLACE_TYCHO) {
    213221        int Minp =  input[0].average[N].measureOffset;
    214         Nreplace = replace_tycho (&output[0].average[n], output[0].measure, next_meas, &input[0].average[N], &input[0].measure[Minp]);
     222        Nreplace = replace_tycho (&output[0].average[n], output[0].measure, next_measure, &input[0].average[N], &input[0].measure[Minp]);
    215223        if (Nreplace == 6) {
    216           output[0].found_t[n] = Nmeas;
     224          output[0].found_t[n] = Nmeasure;
    217225          i++;
    218226          continue;
     
    227235          // index to first measure for this object
    228236          // XXX this does not support lensing, starpar, or galphot measurements
    229           if (replace_match (&output[0].average[n], output[0].measure, next_meas, &input[0].average[N], &input[0].measure[offset])) {
     237          if (replace_match (&output[0].average[n], output[0].measure, next_measure, &input[0].average[N], &input[0].measure[offset])) {
    230238            continue;
    231239          }
    232240        }
    233241        /* add to end of measurement list */
    234         add_meas_link (&output[0].average[n], next_meas, Nmeas, NMEAS);
     242        add_measure_link (&output[0].average[n], next_measure, Nmeasure, NMEASURE);
    235243       
    236244        // set the new measurements
    237         output[0].measure[Nmeas] = input[0].measure[offset];
     245        output[0].measure[Nmeasure] = input[0].measure[offset];
    238246
    239247        // old code: find R,D using average_in[0], the get offset relative to average_out[0].  no longer
     
    241249        // Rin = input[0].average[N].R - input[0].measure[offset].dR / 3600.0;
    242250        // Din = input[0].average[N].D - input[0].measure[offset].dD / 3600.0;
    243         // output[0].measure[Nmeas].dR = 3600.0*(output[0].average[n].R - Rin);
    244         // output[0].measure[Nmeas].dD = 3600.0*(output[0].average[n].D - Din);
    245 
    246         output[0].measure[Nmeas].dbFlags  = 0;  // XXX why reset these?
    247         output[0].measure[Nmeas].averef   = n;
    248         output[0].measure[Nmeas].objID    = output[0].average[n].objID;
    249         output[0].measure[Nmeas].catID    = output[0].catID;
    250 
    251         assert (output[0].measure[Nmeas].averef < Nave);
    252 
    253         // fprintf (stderr, "Nave : "OFF_T_FMT", Nmeas : "OFF_T_FMT", dR: %f, dD: %f, catID: %d\n",  n,  Nmeas, output[0].measure[Nmeas].dR, output[0].measure[Nmeas].dD, output[0].measure[i].catID);
    254 
    255         float dRoff = dvoOffsetR(&output[0].measure[Nmeas], &output[0].average[n]);
     251        // output[0].measure[Nmeasure].dR = 3600.0*(output[0].average[n].R - Rin);
     252        // output[0].measure[Nmeasure].dD = 3600.0*(output[0].average[n].D - Din);
     253
     254        output[0].measure[Nmeasure].dbFlags  = 0;  // XXX why reset these?
     255        output[0].measure[Nmeasure].averef   = n;
     256        output[0].measure[Nmeasure].objID    = output[0].average[n].objID;
     257        output[0].measure[Nmeasure].catID    = output[0].catID;
     258
     259        assert (output[0].measure[Nmeasure].averef < Nave);
     260
     261        // fprintf (stderr, "Nave : "OFF_T_FMT", Nmeasure : "OFF_T_FMT", dR: %f, dD: %f, catID: %d\n",  n,  Nmeasure, output[0].measure[Nmeasure].dR, output[0].measure[Nmeasure].dD, output[0].measure[i].catID);
     262
     263        float dRoff = dvoOffsetR(&output[0].measure[Nmeasure], &output[0].average[n]);
    256264
    257265        // rationalize R
    258266        if (dRoff > +180.0*3600.0) {
    259267          // average on high end of boundary, move star up
    260           output[0].measure[Nmeas].R += 360.0;
     268          output[0].measure[Nmeasure].R += 360.0;
    261269          dRoff -= 360.0*3600.0;
    262270        }
    263271        if (dRoff < -180.0*3600.0) {
    264272          // average on low end of boundary, move star down
    265           output[0].measure[Nmeas].R -= 360.0;
     273          output[0].measure[Nmeasure].R -= 360.0;
    266274          dRoff += 360.0*3600.0;
    267275        }
     
    272280            fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
    273281                     output[0].average[n].R, output[0].average[n].D,
    274                      output[0].measure[Nmeas].R, output[0].measure[Nmeas].D,
     282                     output[0].measure[Nmeasure].R, output[0].measure[Nmeasure].D,
    275283                     X1[i], X2[Jmin], Y1[i], Y2[Jmin]);
    276284            // XXX abort on this? -- this is a bad failure...
     
    278286        }
    279287        output[0].average[n].Nmeasure ++;
    280         Nmeas ++;
     288        Nmeasure ++;
    281289      }
    282290    }
     
    286294      for (Nin = 0; Nin < input[0].average[N].Nlensing; Nin++) {
    287295        /* add to end of lensing list */
    288         add_lens_link (&output[0].average[n], next_lens, Nlens, NLENS);
     296        add_lensing_link (&output[0].average[n], next_lensing, Nlensing, NLENSING);
    289297       
    290298        // set the new lensing
    291299        off_t lensoff = input[0].average[N].lensingOffset + Nin;
    292         output[0].lensing[Nlens] = input[0].lensing[lensoff];
    293 
    294         output[0].lensing[Nlens].averef   = n;
    295         output[0].lensing[Nlens].objID    = output[0].average[n].objID;
    296         output[0].lensing[Nlens].catID    = output[0].catID;
     300        output[0].lensing[Nlensing] = input[0].lensing[lensoff];
     301
     302        output[0].lensing[Nlensing].averef   = n;
     303        output[0].lensing[Nlensing].objID    = output[0].average[n].objID;
     304        output[0].lensing[Nlensing].catID    = output[0].catID;
    297305        output[0].average[n].Nlensing ++;
    298         Nlens ++;
     306        Nlensing ++;
     307      }
     308    }
     309
     310    // if lensobj measurements exist, add them too
     311    if (output[0].lensobj && !SKIP_LENSOBJ) {
     312      for (Nin = 0; Nin < input[0].average[N].Nlensobj; Nin++) {
     313        /* add to end of lensobj list */
     314        add_lensobj_link (&output[0].average[n], next_lensobj, Nlensobj, NLENSOBJ);
     315       
     316        // set the new lensobj
     317        off_t lensoff = input[0].average[N].lensobjOffset + Nin;
     318        output[0].lensobj[Nlensobj] = input[0].lensobj[lensoff];
     319
     320        // output[0].lensobj[Nlensobj].averef   = n;
     321        output[0].lensobj[Nlensobj].objID    = output[0].average[n].objID;
     322        output[0].lensobj[Nlensobj].catID    = output[0].catID;
     323        output[0].average[n].Nlensobj ++;
     324        Nlensobj ++;
    299325      }
    300326    }
     
    304330      for (Nin = 0; Nin < input[0].average[N].Nstarpar; Nin++) {
    305331        /* add to end of lensing list */
    306         add_star_link (&output[0].average[n], next_star, Nstar, NSTAR);
     332        add_starpar_link (&output[0].average[n], next_starpar, Nstarpar, NSTARPAR);
    307333       
    308334        // set the new starpar
    309335        off_t staroff = input[0].average[N].starparOffset + Nin;
    310         output[0].starpar[Nstar] = input[0].starpar[staroff];
    311 
    312         output[0].starpar[Nstar].averef   = n;
    313         output[0].starpar[Nstar].objID    = output[0].average[n].objID;
    314         output[0].starpar[Nstar].catID    = output[0].catID;
     336        output[0].starpar[Nstarpar] = input[0].starpar[staroff];
     337
     338        output[0].starpar[Nstarpar].averef   = n;
     339        output[0].starpar[Nstarpar].objID    = output[0].average[n].objID;
     340        output[0].starpar[Nstarpar].catID    = output[0].catID;
    315341        output[0].average[n].Nstarpar ++;
    316         Nstar ++;
     342        Nstarpar ++;
    317343      }
    318344    }
     
    322348      for (Nin = 0; Nin < input[0].average[N].Ngalphot; Nin++) {
    323349        /* add to end of galphot list */
    324         add_galp_link (&output[0].average[n], next_galp, Ngalp, NGALP);
     350        add_galphot_link (&output[0].average[n], next_galphot, Ngalphot, NGALPHOT);
    325351       
    326352        // set the new galphot
    327353        off_t galpoff = input[0].average[N].galphotOffset + Nin;
    328         output[0].galphot[Ngalp] = input[0].galphot[galpoff];
    329 
    330         output[0].galphot[Ngalp].averef   = n;
    331         output[0].galphot[Ngalp].objID    = output[0].average[n].objID;
    332         output[0].galphot[Ngalp].catID    = output[0].catID;
     354        output[0].galphot[Ngalphot] = input[0].galphot[galpoff];
     355
     356        output[0].galphot[Ngalphot].averef   = n;
     357        output[0].galphot[Ngalphot].objID    = output[0].average[n].objID;
     358        output[0].galphot[Ngalphot].catID    = output[0].catID;
    333359        output[0].average[n].Ngalphot ++;
    334         Ngalp ++;
     360        Ngalphot ++;
    335361      }
    336362    }
     
    373399    /* Nm is updated, but not written out in -update mode (for existing entries)
    374400       Nm is recalculated in build_meas_links if loaded table is not sorted */
    375     output[0].found_t[n] = Nmeas;
     401    output[0].found_t[n] = Nmeasure;
    376402    i++;
    377403  }
    378   // MARKTIME("find matched stars: %f sec for "OFF_T_FMT","OFF_T_FMT" stars ("OFF_T_FMT" meas)\n", dtime, Nstars, Nave, Nmeas);
     404  // MARKTIME("find matched stars: %f sec for "OFF_T_FMT","OFF_T_FMT" stars ("OFF_T_FMT" meas)\n", dtime, Nstars, Nave, Nmeasure);
    379405
    380406  /** incorporate unmatched image stars, if this star is in field of this catalog **/
     
    384410
    385411    /* make sure there is space for next entry */
    386     if (Nmeas + input[0].average[N].Nmeasure >= NMEAS) {
    387       NMEAS = Nmeas + input[0].average[N].Nmeasure + 1000;
    388       REALLOCATE (next_meas, off_t, NMEAS);
    389       REALLOCATE (output[0].measure, Measure, NMEAS);
    390     }
    391     if (Nlens + input[0].average[N].Nlensing >= NLENS) {
    392       NLENS = Nlens + input[0].average[N].Nlensing + 1000;
    393       REALLOCATE (next_lens, off_t, NLENS);
    394       REALLOCATE (output[0].lensing, Lensing, NLENS);
    395     }
    396     if (Nstar + input[0].average[N].Nstarpar >= NSTAR) {
    397       NSTAR = Nstar + input[0].average[N].Nstarpar + 1000;
    398       REALLOCATE (next_star, off_t, NSTAR);
    399       REALLOCATE (output[0].starpar, StarPar, NSTAR);
    400     }
    401     if (Ngalp + input[0].average[N].Ngalphot >= NGALP) {
    402       NGALP = Ngalp + input[0].average[N].Ngalphot + 1000;
    403       REALLOCATE (next_galp, off_t, NGALP);
    404       REALLOCATE (output[0].galphot, GalPhot, NGALP);
     412    if (Nmeasure + input[0].average[N].Nmeasure >= NMEASURE) {
     413      NMEASURE = Nmeasure + input[0].average[N].Nmeasure + 1000;
     414      REALLOCATE (next_measure, off_t, NMEASURE);
     415      REALLOCATE (output[0].measure, Measure, NMEASURE);
     416    }
     417    if (Nlensing + input[0].average[N].Nlensing >= NLENSING) {
     418      NLENSING = Nlensing + input[0].average[N].Nlensing + 1000;
     419      REALLOCATE (next_lensing, off_t, NLENSING);
     420      REALLOCATE (output[0].lensing, Lensing, NLENSING);
     421    }
     422    if (Nlensobj + input[0].average[N].Nlensobj >= NLENSOBJ) {
     423      NLENSOBJ = Nlensobj + input[0].average[N].Nlensobj + 1000;
     424      REALLOCATE (next_lensobj, off_t, NLENSOBJ);
     425      REALLOCATE (output[0].lensobj, Lensobj, NLENSOBJ);
     426    }
     427    if (Nstarpar + input[0].average[N].Nstarpar >= NSTARPAR) {
     428      NSTARPAR = Nstarpar + input[0].average[N].Nstarpar + 1000;
     429      REALLOCATE (next_starpar, off_t, NSTARPAR);
     430      REALLOCATE (output[0].starpar, StarPar, NSTARPAR);
     431    }
     432    if (Ngalphot + input[0].average[N].Ngalphot >= NGALPHOT) {
     433      NGALPHOT = Ngalphot + input[0].average[N].Ngalphot + 1000;
     434      REALLOCATE (next_galphot, off_t, NGALPHOT);
     435      REALLOCATE (output[0].galphot, GalPhot, NGALPHOT);
    405436    }
    406437    if (Nave >= NAVE) {
     
    465496    /** add measurements for this input average object **/
    466497    if (output[0].measure && !SKIP_MEASURE && input[0].average[N].Nmeasure) {
    467       output[0].average[Nave].measureOffset  = Nmeas;
     498      output[0].average[Nave].measureOffset  = Nmeasure;
    468499      for (Nin = 0; Nin < input[0].average[N].Nmeasure; Nin ++) {
    469500        offset = input[0].average[N].measureOffset + Nin;
    470501       
    471502        // supply the measurments from this detection
    472         output[0].measure[Nmeas]           = input[0].measure[offset];
     503        output[0].measure[Nmeasure]           = input[0].measure[offset];
    473504       
    474505        // the following measure elements cannot be set until here:
    475         output[0].measure[Nmeas].dbFlags  = 0;
    476         output[0].measure[Nmeas].averef   = Nave;
    477         output[0].measure[Nmeas].objID    = output[0].average[Nave].objID;
    478         output[0].measure[Nmeas].catID    = output[0].catID;
     506        output[0].measure[Nmeasure].dbFlags  = 0;
     507        output[0].measure[Nmeasure].averef   = Nave;
     508        output[0].measure[Nmeasure].objID    = output[0].average[Nave].objID;
     509        output[0].measure[Nmeasure].catID    = output[0].catID;
    479510       
    480511        // as we add measurements, update Nmeasure to match
    481512        output[0].average[Nave].Nmeasure ++;
    482513
    483         /* we set next[Nmeas] to -1 here, and update correctly below */
    484         next_meas[Nmeas] = -1;
    485         Nmeas ++;
     514        /* we set next[Nmeasure] to -1 here, and update correctly below */
     515        next_measure[Nmeasure] = -1;
     516        Nmeasure ++;
    486517      }
    487518      int Ngroup = input[0].average[N].Nmeasure;
    488519      for (j = 0; j < Ngroup - 1; j++) {
    489         next_meas[Nmeas - Ngroup + j] = Nmeas - Ngroup + j + 1;
     520        next_measure[Nmeasure - Ngroup + j] = Nmeasure - Ngroup + j + 1;
    490521      }
    491522    }
     
    493524    /** add lensing for this input average object **/
    494525    if (output[0].lensing && !SKIP_LENSING && input[0].average[N].Nlensing) {
    495       output[0].average[Nave].lensingOffset  = Nlens;
     526      output[0].average[Nave].lensingOffset  = Nlensing;
    496527      for (Nin = 0; Nin < input[0].average[N].Nlensing; Nin ++) {
    497528        // supply the lensing values from this detection
    498529        off_t lensoff = input[0].average[N].lensingOffset + Nin;
    499         output[0].lensing[Nlens]           = input[0].lensing[lensoff];
     530        output[0].lensing[Nlensing]           = input[0].lensing[lensoff];
    500531
    501532        // the following lensing elements cannot be set until here:
    502         output[0].lensing[Nlens].averef   = Nave;
    503         output[0].lensing[Nlens].objID    = output[0].average[Nave].objID;
    504         output[0].lensing[Nlens].catID    = output[0].catID;
     533        output[0].lensing[Nlensing].averef   = Nave;
     534        output[0].lensing[Nlensing].objID    = output[0].average[Nave].objID;
     535        output[0].lensing[Nlensing].catID    = output[0].catID;
    505536
    506537        // as we add lensing, update Nlensing to match
    507538        output[0].average[Nave].Nlensing ++;
    508539
    509         /* we set next[Nlens] to -1 here, and update correctly below */
    510         next_lens[Nlens] = -1;
    511         Nlens ++;
     540        /* we set next[Nlensing] to -1 here, and update correctly below */
     541        next_lensing[Nlensing] = -1;
     542        Nlensing ++;
    512543      }
    513544      int Ngroup = input[0].average[N].Nlensing;
    514545      for (j = 0; j < Ngroup - 1; j++) {
    515         next_lens[Nlens - Ngroup + j] = Nlens - Ngroup + j + 1;
     546        next_lensing[Nlensing - Ngroup + j] = Nlensing - Ngroup + j + 1;
     547      }
     548    }
     549
     550    /** add lensobj for this input average object **/
     551    if (output[0].lensobj && !SKIP_LENSOBJ && input[0].average[N].Nlensobj) {
     552      output[0].average[Nave].lensobjOffset  = Nlensobj;
     553      for (Nin = 0; Nin < input[0].average[N].Nlensobj; Nin ++) {
     554        // supply the lensobj values from this detection
     555        off_t lensoff = input[0].average[N].lensobjOffset + Nin;
     556        output[0].lensobj[Nlensobj]           = input[0].lensobj[lensoff];
     557
     558        // the following lensobj elements cannot be set until here:
     559        // output[0].lensobj[Nlensobj].averef   = Nave;
     560        output[0].lensobj[Nlensobj].objID    = output[0].average[Nave].objID;
     561        output[0].lensobj[Nlensobj].catID    = output[0].catID;
     562
     563        // as we add lensobj, update Nlensobj to match
     564        output[0].average[Nave].Nlensobj ++;
     565
     566        /* we set next[Nlensobj] to -1 here, and update correctly below */
     567        next_lensobj[Nlensobj] = -1;
     568        Nlensobj ++;
     569      }
     570      int Ngroup = input[0].average[N].Nlensobj;
     571      for (j = 0; j < Ngroup - 1; j++) {
     572        next_lensobj[Nlensobj - Ngroup + j] = Nlensobj - Ngroup + j + 1;
    516573      }
    517574    }
     
    519576    /** add starpar for this input average object **/
    520577    if (output[0].starpar && !SKIP_STARPAR && input[0].average[N].Nstarpar) {
    521       output[0].average[Nave].starparOffset  = Nstar;
     578      output[0].average[Nave].starparOffset  = Nstarpar;
    522579      for (Nin = 0; Nin < input[0].average[N].Nstarpar; Nin ++) {
    523580        // supply the starpar values from this detection
    524581        off_t staroff = input[0].average[N].starparOffset + Nin;
    525         output[0].starpar[Nstar]           = input[0].starpar[staroff];
     582        output[0].starpar[Nstarpar]           = input[0].starpar[staroff];
    526583
    527584        // the following starpar elements cannot be set until here:
    528         output[0].starpar[Nstar].averef   = Nave;
    529         output[0].starpar[Nstar].objID    = output[0].average[Nave].objID;
    530         output[0].starpar[Nstar].catID    = output[0].catID;
     585        output[0].starpar[Nstarpar].averef   = Nave;
     586        output[0].starpar[Nstarpar].objID    = output[0].average[Nave].objID;
     587        output[0].starpar[Nstarpar].catID    = output[0].catID;
    531588
    532589        // as we add starpar, update Nstarpar to match
    533590        output[0].average[Nave].Nstarpar ++;
    534591
    535         /* we set next[Nstar] to -1 here, and update correctly below */
    536         next_star[Nstar] = -1;
    537         Nstar ++;
     592        /* we set next[Nstarpar] to -1 here, and update correctly below */
     593        next_starpar[Nstarpar] = -1;
     594        Nstarpar ++;
    538595      }
    539596      int Ngroup = input[0].average[N].Nstarpar;
    540597      for (j = 0; j < Ngroup - 1; j++) {
    541         next_star[Nstar - Ngroup + j] = Nstar - Ngroup + j + 1;
     598        next_starpar[Nstarpar - Ngroup + j] = Nstarpar - Ngroup + j + 1;
    542599      }
    543600    }
     
    545602    /** add galphot for this input average object **/
    546603    if (output[0].galphot && !SKIP_GALPHOT && input[0].average[N].Ngalphot) {
    547       output[0].average[Nave].galphotOffset  = Ngalp;
     604      output[0].average[Nave].galphotOffset  = Ngalphot;
    548605      for (Nin = 0; Nin < input[0].average[N].Ngalphot; Nin ++) {
    549606        // supply the galphot values from this detection
    550607        off_t galpoff = input[0].average[N].galphotOffset + Nin;
    551         output[0].galphot[Ngalp]           = input[0].galphot[galpoff];
     608        output[0].galphot[Ngalphot]           = input[0].galphot[galpoff];
    552609
    553610        // the following galphot elements cannot be set until here:
    554         output[0].galphot[Ngalp].averef   = Nave;
    555         output[0].galphot[Ngalp].objID    = output[0].average[Nave].objID;
    556         output[0].galphot[Ngalp].catID    = output[0].catID;
     611        output[0].galphot[Ngalphot].averef   = Nave;
     612        output[0].galphot[Ngalphot].objID    = output[0].average[Nave].objID;
     613        output[0].galphot[Ngalphot].catID    = output[0].catID;
    557614
    558615        // as we add galphot, update Ngalphot to match
    559616        output[0].average[Nave].Ngalphot ++;
    560617
    561         /* we set next[Ngalp] to -1 here, and update correctly below */
    562         next_galp[Ngalp] = -1;
    563         Ngalp ++;
     618        /* we set next[Ngalphot] to -1 here, and update correctly below */
     619        next_galphot[Ngalphot] = -1;
     620        Ngalphot ++;
    564621      }
    565622      int Ngroup = input[0].average[N].Ngalphot;
    566623      for (j = 0; j < Ngroup - 1; j++) {
    567         next_galp[Ngalp - Ngroup + j] = Ngalp - Ngroup + j + 1;
     624        next_galphot[Ngalphot - Ngroup + j] = Ngalphot - Ngroup + j + 1;
    568625      }
    569626    }
     
    575632
    576633  REALLOCATE (output[0].average, Average, Nave);
    577   if (!SKIP_MEASURE) { REALLOCATE (output[0].measure, Measure, Nmeas); }
    578   if (!SKIP_LENSING) { REALLOCATE (output[0].lensing, Lensing, Nlens); }
    579   if (!SKIP_STARPAR) { REALLOCATE (output[0].starpar, StarPar, Nstar); }
    580   if (!SKIP_GALPHOT) { REALLOCATE (output[0].galphot, GalPhot, Ngalp); }
     634  if (!SKIP_MEASURE) { REALLOCATE (output[0].measure, Measure, Nmeasure); }
     635  if (!SKIP_LENSING) { REALLOCATE (output[0].lensing, Lensing, Nlensing); }
     636  if (!SKIP_LENSOBJ) { REALLOCATE (output[0].lensobj, Lensobj, Nlensobj); }
     637  if (!SKIP_STARPAR) { REALLOCATE (output[0].starpar, StarPar, Nstarpar); }
     638  if (!SKIP_GALPHOT) { REALLOCATE (output[0].galphot, GalPhot, Ngalphot); }
    581639 
    582640# define NOSORT 0
     
    585643  } else {
    586644    output[0].sorted = TRUE;
    587     if (!SKIP_MEASURE) { output[0].measure = sort_measure (output[0].average, Nave, output[0].measure, Nmeas, next_meas); }
    588     if (!SKIP_LENSING) { output[0].lensing = sort_lensing (output[0].average, Nave, output[0].lensing, Nlens, next_lens); }
    589     if (!SKIP_STARPAR) { output[0].starpar = sort_starpar (output[0].average, Nave, output[0].starpar, Nstar, next_star); }
    590     if (!SKIP_GALPHOT) { output[0].galphot = sort_galphot (output[0].average, Nave, output[0].galphot, Ngalp, next_galp); }
     645    if (!SKIP_MEASURE) { output[0].measure = sort_measure (output[0].average, Nave, output[0].measure, Nmeasure, next_measure); }
     646    if (!SKIP_LENSING) { output[0].lensing = sort_lensing (output[0].average, Nave, output[0].lensing, Nlensing, next_lensing); }
     647    if (!SKIP_LENSOBJ) { output[0].lensobj = sort_lensobj (output[0].average, Nave, output[0].lensobj, Nlensobj, next_lensobj); }
     648    if (!SKIP_STARPAR) { output[0].starpar = sort_starpar (output[0].average, Nave, output[0].starpar, Nstarpar, next_starpar); }
     649    if (!SKIP_GALPHOT) { output[0].galphot = sort_galphot (output[0].average, Nave, output[0].galphot, Ngalphot, next_galphot); }
    591650  }
    592651
     
    594653  output[0].objID    = objID; // new max value, save on catalog close
    595654  output[0].Naverage = Nave;
    596   if (!SKIP_MEASURE) { output[0].Nmeasure = Nmeas; }
    597   if (!SKIP_LENSING) { output[0].Nlensing = Nlens; }
    598   if (!SKIP_STARPAR) { output[0].Nstarpar = Nstar; }
    599   if (!SKIP_GALPHOT) { output[0].Ngalphot = Ngalp; }
     655  if (!SKIP_MEASURE) { output[0].Nmeasure = Nmeasure; }
     656  if (!SKIP_LENSING) { output[0].Nlensing = Nlensing; }
     657  if (!SKIP_LENSOBJ) { output[0].Nlensobj = Nlensobj; }
     658  if (!SKIP_STARPAR) { output[0].Nstarpar = Nstarpar; }
     659  if (!SKIP_GALPHOT) { output[0].Ngalphot = Ngalphot; }
    600660  output[0].Nsecfilt_mem = Nave*NsecfiltOut;
    601   if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nlens, Ngalp: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeas,  Nlens, Ngalp, Nmatch);
    602 
    603   free (next_meas);
    604   free (next_lens);
    605   free (next_star);
    606   free (next_galp);
     661  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeasure, Nlensing, Ngalphot: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeasure,  Nlensing, Ngalphot, Nmatch);
     662
     663  free (next_measure);
     664  free (next_lensing);
     665  free (next_lensobj);
     666  free (next_starpar);
     667  free (next_galphot);
    607668
    608669  free (X2);
     
    625686   images have boundaries which are lines in pixels coords, but curve in RA and DEC
    626687   
    627    output[0].found_t[Ncat] but stars[Nstar].found
     688   output[0].found_t[Ncat] but stars[Nstars].found
    628689   
    629690*/
Note: See TracChangeset for help on using the changeset viewer.