IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 19, 2014, 4:05:27 PM (12 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ps2-tc3-20130727
Files:
30 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ps2-tc3-20130727

  • branches/eam_branches/ps2-tc3-20130727/Ohana

  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/include/dvomerge.h

    r35765 r37403  
    129129int        merge_catalogs_old     PROTO((SkyRegion *region, Catalog *output, Catalog *input, double RADIUS, int *secflitMap));
    130130
     131off_t     *build_measure_links    PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
    131132off_t     *init_measure_links     PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
     133int        add_meas_link          PROTO((Average *average, off_t *next, off_t Nmeasure, off_t NMEASURE));
     134Measure   *sort_measure           PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next));
     135
     136off_t     *build_lensing_links    PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
     137off_t     *init_lensing_links     PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
     138int        add_lens_link          PROTO((Average *average, off_t *next, off_t Nlensing, off_t NLENSING));
     139Lensing   *sort_lensing           PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next));
     140
    132141off_t     *init_missing_links     PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing));
    133 off_t     *build_measure_links    PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
    134 int        add_meas_link          PROTO((Average *average, off_t *next, off_t Nmeasure, off_t NMEASURE));
    135142int        add_miss_link          PROTO((Average *average, off_t *next, off_t Nmissing));
    136 Measure   *sort_measure           PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next));
    137143Missing   *sort_missing           PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss));
    138144
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/include/dvoverify.h

    r34405 r37403  
    5656int LoadImageIDs (char *catdir);
    5757int CheckImageID (Catalog *catalog);
     58
     59int SaveImageIDsSmall(char *filename);
     60int LoadImageIDsSmall (char *filename);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/IDmapIO.c

    r34277 r37403  
    2727  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_ID_MAP");
    2828
    29   gfits_define_bintable_column (&theader, "J", "OLD_IDS", "old image IDs", NULL, 1.0, 1.0*0x8000);
    30   gfits_define_bintable_column (&theader, "J", "NEW_IDS", "new image IDs", NULL, 1.0, 1.0*0x8000);
     29  gfits_define_bintable_column (&theader, "J", "OLD_IDS", "old image IDs", NULL, 1.0, FT_BZERO_INT32);
     30  gfits_define_bintable_column (&theader, "J", "NEW_IDS", "new image IDs", NULL, 1.0, FT_BZERO_INT32);
    3131
    3232  // generate the output array that carries the data
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/LoadCatalog.c

    r29938 r37403  
    88
    99    // always load all of the data (if any exists)
    10     catalog[0].catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     10    catalog[0].catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF | LOAD_LENSING | LOAD_LENSOBJ;
    1111
    1212    catalog[0].catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/build_links.c

    r27435 r37403  
    11# include "dvomerge.h"
     2
     3/*
     4
     5There are two modes for the measure table: sorted and unsorted.
     6
     7In sorted mode, all measures associated with a given average are in a single block.  The block
     8is pointed to by average->measureOffset and the range is average->Nmeasure
     9
     10In unsorted mode, it is not possible to go directly from average to measure without scanning.
     11In this case, it is necessary to use the value measure->averef to find the corresponding
     12average entry. 
     13
     14Note that average->measureOffset and measure->averef are only valid for a given load of the
     15data: they refer to the sequence number in the data blocks.
     16
     17next_meas is a list of the equivalent sequence of the measure block as if it were sorted.
     18
     19to find the sequence of measurements for a given average:
     20n_0 = average->measureOffset
     21n_1 = next_meas[n_0]
     22n_i = next_meas[n_i-1]
     23
     24*/
    225
    326/* build the initial links assuming the table is sorted,
     
    629
    730  off_t i, j, N;
    8   off_t *next;
     31  off_t *next_meas;
    932
    1033  N = 0;
    1134
    12   ALLOCATE (next, off_t, Nmeasure);
     35  ALLOCATE (next_meas, off_t, Nmeasure);
    1336  for (i = 0; i < Naverage; i++, N++) {
    1437    for (j = 0; j < average[i].Nmeasure - 1; j++, N++) {
    15       next[N] = N + 1;
     38      next_meas[N] = N + 1;
    1639      if (N >= Nmeasure) {
    1740        fprintf (stderr, "WARNING: N out of bounds (1)\n");
    1841      }
    1942    }
    20     next[N] = -1;
     43    next_meas[N] = -1;
    2144    if (N >= Nmeasure) {
    2245      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     
    2851    }
    2952  }
    30   return (next);
    31 }
    32 
    33 /* average[].measureOffset, average[].Nmeasure are valid within an addstar run */
    34 int add_meas_link (Average *average, off_t *next, off_t Nmeasure, off_t NMEASURE) {
    35 
    36   off_t k, m;
    37 
    38   /* if we have trouble, check validity of next[m] : m < Nmeasure */
    39   m = average[0].measureOffset; 
    40 
    41   for (k = 0; k < average[0].Nmeasure - 1; k++)  {
    42     m = next[m];
    43     if (m >= NMEASURE) {
    44       fprintf (stderr, "WARNING: m out of bounds (3)\n");
    45     }
    46   }
    47 
    48   /* set up references */
    49   next[Nmeasure] = -1;
    50   if (Nmeasure >= NMEASURE) {
    51     fprintf (stderr, "WARNING: Nmeasure out of bounds (1)\n");
    52   }
    53 
    54   if (m == -1) {
    55     average[0].measureOffset = Nmeasure;
    56   } else {
    57     next[m] = Nmeasure;
    58     if (m >= NMEASURE) {
    59       fprintf (stderr, "WARNING: m out of bounds (4)\n");
    60     }
    61   }
    62 
    63   return (TRUE);
    64 }
    65 
    66 Measure *sort_measure (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next) {
    67 
    68   off_t i, k, n, N;
    69   Measure *tmpmeasure;
    70 
    71   /* fix order of Measure (memory intensive, but fast) */
    72   N = 0;
    73   ALLOCATE (tmpmeasure, Measure, Nmeasure);
    74   for (i = 0; i < Naverage; i++) {
    75     n = average[i].measureOffset;
    76     average[i].measureOffset = N;
    77     for (k = 0; k < average[i].Nmeasure; k++, N++) {
    78       tmpmeasure[N] = measure[n];
    79       tmpmeasure[N].averef = i;
    80       n = next[n];
    81     }
    82   }
    83   free (measure);
    84   return (tmpmeasure);
     53  return (next_meas);
    8554}
    8655
     
    9564
    9665  off_t i, m, k, Nm, averef;
    97   off_t *next;
    98 
    99   ALLOCATE (next, off_t, Nmeasure);
     66  off_t *next_meas;
     67
     68  ALLOCATE (next_meas, off_t, Nmeasure);
    10069
    10170  /* reset the Nm, offset values for average */
     
    10877    averef = measure[Nm].averef;
    10978    m = average[averef].measureOffset; 
    110     next[Nm] = -1;
     79    next_meas[Nm] = -1;
    11180
    11281    if (m == -1) { /* no links yet for source */
     
    11685    }
    11786
    118     for (k = 0; next[m] != -1; k++) {
    119       m = next[m];
     87    for (k = 0; next_meas[m] != -1; k++) {
     88      m = next_meas[m];
    12089      if (m >= Nmeasure) {
    12190        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     
    12493
    12594    average[averef].Nmeasure = k + 2;
    126     next[m] = Nm;
     95    next_meas[m] = Nm;
    12796    if (m >= Nmeasure) {
    12897      fprintf (stderr, "WARNING: m out of bounds (2)\n");
    12998    }
    13099  }
    131   return (next);
    132 }
     100  return (next_meas);
     101}
     102
     103/* average[].measureOffset, average[].Nmeasure are valid within an addstar run */
     104int add_meas_link (Average *average, off_t *next_meas, off_t Nmeasure, off_t NMEASURE) {
     105
     106  off_t k, m;
     107
     108  /* if we have trouble, check validity of next_meas[m] : m < Nmeasure */
     109  m = average[0].measureOffset; 
     110
     111  for (k = 0; k < average[0].Nmeasure - 1; k++)  {
     112    m = next_meas[m];
     113    if (m >= NMEASURE) {
     114      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     115    }
     116  }
     117
     118  /* set up references */
     119  next_meas[Nmeasure] = -1;
     120  if (Nmeasure >= NMEASURE) {
     121    fprintf (stderr, "WARNING: Nmeasure out of bounds (1)\n");
     122  }
     123
     124  if (m == -1) {
     125    average[0].measureOffset = Nmeasure;
     126  } else {
     127    next_meas[m] = Nmeasure;
     128    if (m >= NMEASURE) {
     129      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     130    }
     131  }
     132
     133  return (TRUE);
     134}
     135
     136Measure *sort_measure (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next_meas) {
     137
     138  off_t i, k, n, N;
     139  Measure *tmpmeasure;
     140
     141  /* fix order of Measure (memory intensive, but fast) */
     142  N = 0;
     143  ALLOCATE (tmpmeasure, Measure, Nmeasure);
     144  for (i = 0; i < Naverage; i++) {
     145    n = average[i].measureOffset;
     146    average[i].measureOffset = N;
     147    for (k = 0; k < average[i].Nmeasure; k++, N++) {
     148      if (n == -1) abort();
     149      tmpmeasure[N] = measure[n];
     150      if (measure[n].averef != i) abort();
     151      tmpmeasure[N].averef = i;
     152      n = next_meas[n];
     153    }
     154  }
     155  free (measure);
     156  return (tmpmeasure);
     157}
     158
     159/*******************************************************************************************/
    133160
    134161/* build the initial links assuming the table is sorted */
     
    136163
    137164  off_t i, j, N;
    138   off_t *next;
     165  off_t *next_miss;
    139166
    140167  N = 0;
    141168
    142   ALLOCATE (next, off_t, Nmissing);
     169  ALLOCATE (next_miss, off_t, Nmissing);
    143170  for (i = 0; i < Naverage; i++) {
    144171    for (j = 0; j < average[i].Nmissing - 1; j++, N++) {
    145       next[N] = N + 1;
     172      next_miss[N] = N + 1;
    146173    }
    147174    if (average[i].Nmissing > 0) {
    148       next[N] = -1;
     175      next_miss[N] = -1;
    149176      if (N >= Nmissing) {
    150177        fprintf (stderr, "overflow in init_missing_links");
     
    155182
    156183  }
    157   return (next);
    158 }
    159 
    160 int add_miss_link (Average *average, off_t *next, off_t Nmissing) {
     184  return (next_miss);
     185}
     186
     187int add_miss_link (Average *average, off_t *next_miss, off_t Nmissing) {
    161188
    162189  off_t k, m;
     
    165192  if (average[0].Nmissing < 1) {
    166193    average[0].missingOffset = Nmissing;
    167     next[Nmissing] = -1;
     194    next_miss[Nmissing] = -1;
    168195    return (TRUE);
    169196  }
    170197
    171198  m = average[0].missingOffset; 
    172   for (k = 0; k < average[0].Nmissing - 1; k++) m = next[m];
     199  for (k = 0; k < average[0].Nmissing - 1; k++) m = next_miss[m];
    173200  /* set up references */
    174   next[Nmissing] = -1;
    175   next[m] = Nmissing;
     201  next_miss[Nmissing] = -1;
     202  next_miss[m] = Nmissing;
    176203  return (TRUE);
    177204}
     
    180207   we must always save the missing table, if it exists */
    181208
    182 Missing *sort_missing (Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next) {
     209Missing *sort_missing (Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss) {
    183210
    184211  off_t i, k, n, N;
     
    193220    for (k = 0; k < average[i].Nmissing; k++, N++) {
    194221      tmpmissing[N] = missing[n];
    195       n = next[n];
     222      n = next_miss[n];
    196223    }
    197224  }
     
    199226  return (tmpmissing);
    200227}
     228
     229/*******************************************************************************************/
     230
     231/* build the initial links assuming the table is sorted,
     232   not partial, and has a correct set of average[].lensingOffset,Nlensing values */
     233off_t *init_lensing_links (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing) {
     234
     235  off_t i, j, N;
     236  off_t *next_lens;
     237
     238  N = 0;
     239
     240  ALLOCATE (next_lens, off_t, Nlensing);
     241  for (i = 0; i < Naverage; i++) {
     242    if (!average[i].Nlensing) continue;
     243    for (j = 0; j < average[i].Nlensing - 1; j++, N++) {
     244      next_lens[N] = N + 1;
     245      if (N >= Nlensing) {
     246        fprintf (stderr, "WARNING: N out of bounds (1)\n");
     247      }
     248    }
     249    next_lens[N] = -1;
     250    if (N >= Nlensing) {
     251      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     252    }
     253
     254    if (N >= Nlensing) {
     255      fprintf (stderr, "overflow in init_lensing_links\n");
     256      abort ();
     257    }
     258    N++;
     259  }
     260  return (next_lens);
     261}
     262
     263/* construct lensing links which are valid FOR THIS LOAD
     264 * - if we have a full load, we will get links which can
     265 *   be used by other programs (eg, relphot, etc)
     266 * - if we have a partial load, the links are only valid
     267 *   for that partial load
     268 */
     269
     270off_t *build_lensing_links (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing) {
     271
     272  off_t i, m, k, Nm, averef;
     273  off_t *next_lens;
     274
     275  ALLOCATE (next_lens, off_t, Nlensing);
     276
     277  /* reset the Nm, offset values for average */
     278  for (i = 0; i < Naverage; i++) {
     279    average[i].lensingOffset = -1;
     280    average[i].Nlensing     =  0;
     281  }
     282
     283  for (Nm = 0; Nm < Nlensing; Nm++) {
     284    averef = lensing[Nm].averef;
     285    m = average[averef].lensingOffset; 
     286    next_lens[Nm] = -1;
     287
     288    if (m == -1) { /* no links yet for source */
     289      average[averef].lensingOffset = Nm;
     290      average[averef].Nlensing     = 1;
     291      continue;
     292    }
     293
     294    for (k = 0; next_lens[m] != -1; k++) {
     295      m = next_lens[m];
     296      if (m >= Nlensing) {
     297        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     298      }
     299    }
     300
     301    average[averef].Nlensing = k + 2;
     302    next_lens[m] = Nm;
     303    if (m >= Nlensing) {
     304      fprintf (stderr, "WARNING: m out of bounds (2)\n");
     305    }
     306  }
     307  return (next_lens);
     308}
     309
     310/* average[].lensingOffset, average[].Nlensing are valid within an addstar run */
     311int add_lens_link (Average *average, off_t *next_lens, off_t Nlensing, off_t NLENSING) {
     312
     313  off_t k, m;
     314
     315  /* if we have trouble, check validity of next_lens[m] : m < Nlensing */
     316  m = average[0].lensingOffset; 
     317
     318  for (k = 0; k < average[0].Nlensing - 1; k++)  {
     319    m = next_lens[m];
     320    if (m >= NLENSING) {
     321      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     322    }
     323  }
     324
     325  /* set up references */
     326  next_lens[Nlensing] = -1;
     327  if (Nlensing >= NLENSING) {
     328    fprintf (stderr, "WARNING: Nlensing out of bounds (1)\n");
     329  }
     330
     331  if (m == -1) {
     332    average[0].lensingOffset = Nlensing;
     333  } else {
     334    next_lens[m] = Nlensing;
     335    if (m >= NLENSING) {
     336      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     337    }
     338  }
     339
     340  return (TRUE);
     341}
     342
     343Lensing *sort_lensing (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next_lens) {
     344
     345  off_t i, k, n, np, N;
     346  Lensing *tmplensing;
     347
     348  /*
     349  for (i = 0; i < Naverage; i++) {
     350    if (average[i].Nlensing != 4) {
     351      fprintf (stderr, "check %d %d %d\n", (int) i, (int) average[i].Nlensing, (int) average[i].lensingOffset);
     352    }
     353  }
     354  */
     355
     356  /* fix order of Lensing (memory intensive, but fast) */
     357  N = 0;
     358  ALLOCATE (tmplensing, Lensing, Nlensing);
     359  for (i = 0; i < Naverage; i++) {
     360    if (!average[i].Nlensing) continue;
     361    n = average[i].lensingOffset;
     362    average[i].lensingOffset = N;
     363    for (k = 0; k < average[i].Nlensing; k++, N++) {
     364      if (n == -1) {
     365        fprintf (stderr, "entry after %d has a problem\n", (int) np);
     366        abort();
     367      }
     368      tmplensing[N] = lensing[n];
     369      if (lensing[n].averef != i) abort();
     370      tmplensing[N].averef = i;
     371      np = n;
     372      n = next_lens[n];
     373    }
     374  }
     375  free (lensing);
     376  return (tmplensing);
     377}
     378
     379
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c

    r36680 r37403  
    172172  }
    173173
     174  if (!IDmap->Nmap) {
     175    fprintf (stderr, "input database has image IDs, but no Image table\n");
     176    return FALSE;
     177  }
     178
    174179  off_t lastID = IDmap->old[IDmap->Nmap-1];
    175180
     181  // update measure.imageID
    176182  for (i = 0; i < catalog[0].Nmeasure; i++) {
    177183    oldID = catalog[0].measure[i].imageID;
     
    195201    catalog[0].measure[i].imageID = newID;
    196202  }
     203
     204  // also update lensing.imageID if lensing exists
     205  for (i = 0; i < catalog[0].Nlensing; i++) {
     206    oldID = catalog[0].lensing[i].imageID;
     207    if (oldID == 0) continue;
     208
     209    newID = dvo_map_image_ID (IDmap, oldID);
     210    if (newID == 0) {
     211      if (oldID > lastID) {
     212        fprintf (stderr, "problem with image IDs : input out of range\n");
     213        fprintf (stderr, "old ID: "OFF_T_FMT", last ID: "OFF_T_FMT"\n", oldID, lastID);
     214        exit (2);
     215      }
     216      if (!IDmap->notFound[oldID]) {
     217        fprintf (stderr, "cannot find image ID "OFF_T_FMT"\n",  oldID);
     218        IDmap->notFound[oldID] = TRUE;
     219        // once we discover an imageID is not found, record that fact so we do not complain for every detection
     220      }
     221      // optionally exit here? or wait until end to report an error?
     222      // exit (2);
     223    }
     224    catalog[0].lensing[i].imageID = newID;
     225  }
    197226  return TRUE;
    198227}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvomergeContinue.c

    r34260 r37403  
    131131      merge_catalogs_old (&outsky[0].regions[j], &outcatalog, &incatalog, RADIUS, secfiltMap);
    132132
    133       outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    134 
    135133      // if we receive a signal which would cause us to exit, wait until the full catalog is written
    136134      SetProtect (TRUE);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvomergeContinue_threaded.c

    r34260 r37403  
    7474      merge_catalogs_old (&threadData->outsky->regions[j], &outcatalog, &incatalog, RADIUS, threadData->secfiltMap);
    7575
    76       outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    77 
    7876      // if we receive a signal which would cause us to exit, wait until the full catalog is written
    7977      SetProtect (TRUE);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvomergeCreate.c

    r33963 r37403  
    178178    SkyListFree (inlist);
    179179
    180     outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    181180    dvo_catalog_save (&outcatalog, VERBOSE);
    182181    dvo_catalog_unlock (&outcatalog);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvomergeFromList.c

    r35590 r37403  
    143143    merge_catalogs_old (&skyregion, &outcatalog, &incatalog, RADIUS, secfiltMap);
    144144   
    145     outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    146 
    147145    dmhObjectAdd (outstat[0].history, &outcatalog.header, inStats);
    148146
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvomergeImageIDs.c

    r35765 r37403  
    1818  if (inDB.dbstate == LCK_EMPTY) {
    1919    dvo_image_unlock (&inDB); // unlock input
     20    IDmap->old = NULL;
     21    IDmap->new = NULL;
    2022    IDmap->Nmap = 0;
    2123    return TRUE;
     
    99101  if (inDB.dbstate == LCK_EMPTY) {
    100102    dvo_image_unlock (&inDB); // unlock input
     103    IDmap->old = NULL;
     104    IDmap->new = NULL;
    101105    IDmap->Nmap = 0;
    102106    return TRUE;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvomergeUpdate.c

    r36680 r37403  
    1313  int NsecfiltInput, NsecfiltOutput;
    1414
    15   double dtime;
    16   struct timeval start, stop;
    17   gettimeofday (&start, NULL);
     15  INITTIME;
    1816
    1917  CONTINUE = FALSE;
     
    121119  }
    122120
    123   gettimeofday (&stop, NULL);
    124   dtime = DTIME (stop, start);
    125 
    126121  if (!status) {
    127     fprintf (stderr, "ERROR: elapsed time %9.4f sec\n", dtime);
     122    MARKTIME ("ERROR: elapsed time %9.4f sec\n", dtime);
    128123    exit (3);
    129124  }
    130125
    131   fprintf (stderr, "SUCCESS: elapsed time %9.4f sec\n", dtime);
     126  MARKTIME ("SUCCESS: elapsed time %9.4f sec\n", dtime);
    132127  exit (0);
    133128}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c

    r36680 r37403  
    140140    }
    141141
     142    if (!incatalog.sorted) {
     143      fprintf (stderr, "ERROR: input catalog %s is not sorted (and must be for dvomerge)\n", filename_input);
     144      exit (1);
     145    }
     146
    142147    dvo_update_image_IDs (IDmap, &incatalog);
    143148
     
    158163      LoadCatalog (&outcatalog, outlist[0].regions[j], outcatalog.filename, "w", NsecfiltOutput);
    159164
     165      // if no catalog already exists, use the input catalog to define the format
     166      if (outcatalog.Naves_disk == 0) {
     167        outcatalog.catformat = incatalog.catformat;
     168      }
     169
    160170      merge_catalogs_old (outlist[0].regions[j], &outcatalog, &incatalog, RADIUS, secfiltMap);
    161 
    162       outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    163171
    164172      if (outstat[j].missed) {
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvomergeUpdate_threaded.c

    r35765 r37403  
    7272      merge_catalogs_old (&threadData->outsky->regions[j], &outcatalog, &incatalog, RADIUS, threadData->secfiltMap);
    7373
    74       outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    75 
    7674      // if we receive a signal which would cause us to exit, wait until the full catalog is written
    7775      SetProtect (TRUE);
     
    115113  int NsecfiltInput, NsecfiltOutput;
    116114
    117   double dtime;
    118   struct timeval start, stop;
    119   gettimeofday (&start, NULL);
     115  INITTIME;
    120116
    121117  CONTINUE = FALSE;
     
    134130
    135131  fprintf (stderr, "WARNING / ERROR : multi-threaded dvomerge does not handle merge tracking yet\n");
     132  fprintf (stderr, "WARNING / ERROR : multi-threaded dvomerge does work in a parallel context\n");
    136133  exit (2);
    137134
     
    293290  }
    294291
    295   gettimeofday (&stop, NULL);
    296   dtime = DTIME (stop, start);
    297   fprintf (stderr, "SUCCESS: elapsed time %9.4f sec\n", dtime);
    298 
     292  MARKTIME ("SUCCESS: elapsed time %9.4f sec\n", dtime);
    299293  exit (0);
    300294
     
    318312    }
    319313  }
     314  MARKTIME ("ERROR: elapsed time %9.4f sec\n", dtime);
    320315  exit (1);
    321316}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvorepair.c

    r29938 r37403  
    22
    33int main (int argc, char **argv) {
     4
     5  fprintf (stderr, "this program needs to be updated to load old format Measure tables (pre PV1_V5) in which dR,dD are saved, not R,D\n");
     6  fprintf (stderr, "reminder: relastro can re-construct R,D from X,Y; FtableToMeasure and vice versa could just NAN those values\n");
     7  exit (2);
    48
    59  dvorepair_help(argc, argv);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvorepairCPT.c

    r33657 r37403  
    7676  }
    7777
    78   measure = FtableToMeasure (&cpmFtable, &Nmeasure, &catformat);
     78  measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat);
    7979  myAssert(measure, "failed to convert ftable to measure data");
    8080
     
    126126    average[Nave].measureOffset = -1;
    127127    average[Nave].missingOffset = -1;
    128     average[Nave].extendOffset = -1;
     128    average[Nave].refColorBlue = NAN;
     129    average[Nave].refColorRed = NAN;
    129130
    130131    average[Nave].objID = measure[i].objID;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvorepairDeleteImageList.c

    r29938 r37403  
    250250        gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow);
    251251
    252         measure = FtableToMeasure (&cpmFtable, &Nmeasure, &catformat);
     252        measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat);
    253253        myAssert(measure, "failed to convert ftable to measure data");
    254254   
     
    288288
    289289        // convert internal to external format
    290         if (!MeasureToFtable (&cpmFtable, measureNew, NmeasureNew, catformat)) {
     290        if (!MeasureToFtable (&cpmFtable, NULL, measureNew, NmeasureNew, catformat)) {
    291291          myAbort("trouble converting format");
    292292        }
     
    411411    average[Nave].measureOffset = -1;
    412412    average[Nave].missingOffset = -1;
    413     average[Nave].extendOffset = -1;
     413    average[Nave].refColorBlue = NAN;
     414    average[Nave].refColorRed = NAN;
    414415
    415416    average[Nave].objID = measure[i].objID;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvorepairFixCPT.c

    r29938 r37403  
    120120  }
    121121
    122   measure = FtableToMeasure (&cpmFtable, &Nmeasure, &catformat);
     122  measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat);
    123123  myAssert(measure, "failed to convert ftable to measure data");
    124124
     
    127127
    128128  // convert internal to external format
    129   if (!MeasureToFtable (&cpmFtable, measure, Nmeasure, catformat)) {
     129  if (!MeasureToFtable (&cpmFtable, NULL, measure, Nmeasure, catformat)) {
    130130    myAbort("trouble converting format");
    131131  }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvorepairFixTables.c

    r29938 r37403  
    103103
    104104      // convert internal to external format
    105       if (!MeasureToFtable (&cpmFtable, measureNew, NmeasureNew, catformat)) {
     105      if (!MeasureToFtable (&cpmFtable, NULL, measureNew, NmeasureNew, catformat)) {
    106106        myAbort("trouble converting format");
    107107      }
     
    183183  gfits_scan(&cpmHeaderTBL, "NAXIS2", "%d", 1, &Nrows);
    184184
    185   measure = FtableToMeasure (&cpmFtable, &Nmeasure, &catformat);
     185  measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat);
    186186  myAssert(measure, "failed to convert ftable to measure data");
    187187   
     
    266266    average[Nave].measureOffset = -1;
    267267    average[Nave].missingOffset = -1;
    268     average[Nave].extendOffset = -1;
     268    average[Nave].refColorBlue = NAN;
     269    average[Nave].refColorRef = NAN;
    269270
    270271    average[Nave].objID = measure[i].objID;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvorepairImageVsMeasure.c

    r33657 r37403  
    128128      gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow);
    129129
    130       measure = FtableToMeasure (&cpmFtable, &Nmeasure, &catformat);
     130      measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat);
    131131      myAssert(measure, "failed to convert ftable to measure data");
    132132   
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvorepairImagesVsMeasures.c

    r29938 r37403  
    134134      gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow);
    135135
    136       measure = FtableToMeasure (&cpmFtable, &Nmeasure, &catformat);
     136      measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat);
    137137      myAssert(measure, "failed to convert ftable to measure data");
    138138   
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvoverify_args.c

    r36680 r37403  
    5656  }
    5757
    58   /*** dvoverify -parallel (dvoverify_client, actually) ignores this argument
    59        dvoverify should save a subset table of just the IDs, and dvoverify_client should load it
    60        dvoverify -cpt should have CHECK_IMAGE_ID = F as default ***/
     58  /*** dvoverify -cpt should have CHECK_IMAGE_ID = F as default ***/
    6159       
    6260  CHECK_IMAGE_ID = TRUE;
     
    150148  }
    151149
     150  CHECK_IMAGE_ID = TRUE;
     151  if ((N = get_argument (*argc, argv, "-skip-image-ids"))) {
     152    CHECK_IMAGE_ID = FALSE;
     153    remove_argument (N, argc, argv);
     154  }
     155
    152156  // restrict to a portion of the sky
    153157  UserPatch.Rmin = 0;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvoverify_catalogs.c

    r36680 r37403  
    4747    }
    4848
     49    sprintf (filename, "%s/%s.cpx", mycatdir, skylist[0].regions[i][0].name);
     50    if (!VerifyTableFile (filename)) {
     51      Nbad ++;
     52      skipIndexCheck = TRUE;
     53      AddFailures (filename);
     54    }
     55
     56    sprintf (filename, "%s/%s.cpy", mycatdir, skylist[0].regions[i][0].name);
     57    if (!VerifyTableFile (filename)) {
     58      Nbad ++;
     59      skipIndexCheck = TRUE;
     60      AddFailures (filename);
     61    }
     62
    4963    sprintf (filename, "%s/%s.cpt", mycatdir, skylist[0].regions[i][0].name);
    5064    if (!skipIndexCheck) {
     
    8094    exit (1);
    8195  }   
     96
     97  // save the IDlist as a smaller FITS table
     98  if (CHECK_IMAGE_ID) {
     99    char filename[DVO_MAX_PATH];
     100    snprintf (filename, DVO_MAX_PATH, "%s/ImageIDs.fits", CATDIR);
     101    if (!SaveImageIDsSmall (filename)) {
     102      fprintf (stderr, "ERROR: failure to save image IDs\n");
     103      exit (2);
     104    }
     105  }
    82106
    83107  int i;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvoverify_client.c

    r34405 r37403  
    2222    // XXX in client mode, we should be reading a reduced table generated by the calling
    2323    // serial program
    24     LoadImageIDs (CATDIR);
     24    char filename[DVO_MAX_PATH];
     25    snprintf (filename, DVO_MAX_PATH, "%s/ImageIDs.fits", CATDIR);
     26    if (!LoadImageIDsSmall (filename)) {
     27      fprintf (stderr, "ERROR: failure to load image IDs\n");
     28      exit (2);
     29    }
    2530  }
    2631
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvoverify_utils.c

    r36680 r37403  
    178178  catalog.catformat = DVO_FORMAT_UNDEF; // read-only,do not set the catformat
    179179  catalog.catmode   = DVO_MODE_UNDEF; // read-only, do not set the catmode
    180   catalog.catflags  = LOAD_AVES | LOAD_MEAS;
     180  catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_LENSING | LOAD_LENSOBJ;
    181181  catalog.Nsecfilt  = 0;
    182182 
     
    214214  int NmeasureTotal = 0;
    215215  int measureOffsetOK = TRUE;
     216  int NlensingTotal = 0;
     217  int lensingOffsetOK = TRUE;
     218  int NlensobjTotal = 0;
     219  int lensobjOffsetOK = TRUE;
    216220  for (i = 0; i < catalog.Naverage; i++) {
    217221    NmeasureTotal += catalog.average[i].Nmeasure;
     
    227231      fprintf (stderr, "measureOffset + Nmeasure > catalog.Nmeasure : %d %d %d\n", i, catalog.average[i].Nmeasure, (int) catalog.Nmeasure);
    228232    }
     233
     234    // sum of Nlensing for each object < Nlensing for catalog
     235    NlensingTotal += catalog.average[i].Nlensing;
     236    if (VERBOSE && !(NlensingTotal <= catalog.Nlensing)) {
     237      fprintf (stderr, "NlensingTotal > catalog.Nlensing: %d %d %d\n", i, catalog.average[i].Nlensing, (int) catalog.Nlensing);
     238    }
     239    // lensingOffset needs to be in range for each object
     240    lensingOffsetOK &= (catalog.average[i].lensingOffset < catalog.Nlensing);
     241    if (VERBOSE && !(catalog.average[i].lensingOffset < catalog.Nlensing)) {
     242      fprintf (stderr, "lensingOffset >= catalog.Nlensing: %d %d %d\n", i, catalog.average[i].lensingOffset, (int) catalog.Nlensing);
     243    }
     244    lensingOffsetOK &= (catalog.average[i].lensingOffset + catalog.average[i].Nlensing <= catalog.Nlensing);
     245    if (VERBOSE && !(catalog.average[i].lensingOffset + catalog.average[i].Nlensing <= catalog.Nlensing)) {
     246      fprintf (stderr, "lensingOffset + Nlensing > catalog.Nlensing : %d %d %d\n", i, catalog.average[i].Nlensing, (int) catalog.Nlensing);
     247    }
     248
     249    NlensobjTotal += catalog.average[i].Nlensobj;
     250    if (VERBOSE && !(NlensobjTotal <= catalog.Nlensobj)) {
     251      fprintf (stderr, "NlensobjTotal > catalog.Nlensobj: %d %d %d\n", i, catalog.average[i].Nlensobj, (int) catalog.Nlensobj);
     252    }
     253    lensobjOffsetOK &= (catalog.average[i].lensobjOffset < catalog.Nlensobj);
     254    if (VERBOSE && !(catalog.average[i].lensobjOffset < catalog.Nlensobj)) {
     255      fprintf (stderr, "lensobjOffset >= catalog.Nlensobj: %d %d %d\n", i, catalog.average[i].lensobjOffset, (int) catalog.Nlensobj);
     256    }
     257    lensobjOffsetOK &= (catalog.average[i].lensobjOffset + catalog.average[i].Nlensobj <= catalog.Nlensobj);
     258    if (VERBOSE && !(catalog.average[i].lensobjOffset + catalog.average[i].Nlensobj <= catalog.Nlensobj)) {
     259      fprintf (stderr, "lensobjOffset + Nlensobj > catalog.Nlensobj : %d %d %d\n", i, catalog.average[i].Nlensobj, (int) catalog.Nlensobj);
     260    }
    229261  }
    230262
     
    236268  if (NmeasureTotal != catalog.Nmeasure) {
    237269    fprintf (stderr, "ERROR: catalog %s has an invalid Nmeasure\n", catalog.filename);
     270    status = FALSE;
     271  }
     272
     273  if (!lensingOffsetOK) {
     274    fprintf (stderr, "ERROR: catalog %s has an invalid lensingOffset\n", catalog.filename);
     275    status = FALSE;
     276  }
     277
     278  if (NlensingTotal != catalog.Nlensing) {
     279    fprintf (stderr, "ERROR: catalog %s has an invalid Nlensing\n", catalog.filename);
     280    status = FALSE;
     281  }
     282
     283  if (!lensobjOffsetOK) {
     284    fprintf (stderr, "ERROR: catalog %s has an invalid lensobjOffset\n", catalog.filename);
     285    status = FALSE;
     286  }
     287
     288  if (NlensobjTotal != catalog.Nlensobj) {
     289    fprintf (stderr, "ERROR: catalog %s has an invalid Nlensobj\n", catalog.filename);
    238290    status = FALSE;
    239291  }
     
    247299  }
    248300
    249   int objIDsOK = TRUE;
    250   int catIDsOK = TRUE;
    251   int averefOK = TRUE;
    252 
    253   for (i = 0; i < catalog.Naverage; i++) {
    254     m = catalog.average[i].measureOffset;
    255     for (j = 0; j < catalog.average[i].Nmeasure; j++) {
    256       objIDsOK &= (catalog.average[i].objID == catalog.measure[m+j].objID);
    257       catIDsOK &= (catalog.average[i].catID == catalog.measure[m+j].catID);
    258       averefOK &= (catalog.measure[m+j].averef == i);
    259     }
    260   }
     301  // check measure <-> average links
     302  {
     303    int objIDsOK = TRUE;
     304    int catIDsOK = TRUE;
     305    int averefOK = TRUE;
     306
     307    for (i = 0; i < catalog.Naverage; i++) {
     308      m = catalog.average[i].measureOffset;
     309      for (j = 0; j < catalog.average[i].Nmeasure; j++) {
     310        objIDsOK &= (catalog.average[i].objID == catalog.measure[m+j].objID);
     311        catIDsOK &= (catalog.average[i].catID == catalog.measure[m+j].catID);
     312        averefOK &= (catalog.measure[m+j].averef == i);
     313      }
     314    }
    261315   
    262   if (!objIDsOK) {
    263     fprintf (stderr, "ERROR: catalog %s has invalid obj IDs\n", catalog.filename);
    264     status = FALSE;
    265   }
    266   if (!catIDsOK) {
    267     fprintf (stderr, "ERROR: catalog %s has invalid cat IDs\n", catalog.filename);
    268     status = FALSE;
    269   }
    270   if (!averefOK) {
    271     fprintf (stderr, "ERROR: catalog %s has invalid averef values\n", catalog.filename);
    272     status = FALSE;
     316    if (!objIDsOK) {
     317      fprintf (stderr, "ERROR: catalog %s has invalid obj IDs\n", catalog.filename);
     318      status = FALSE;
     319    }
     320    if (!catIDsOK) {
     321      fprintf (stderr, "ERROR: catalog %s has invalid cat IDs\n", catalog.filename);
     322      status = FALSE;
     323    }
     324    if (!averefOK) {
     325      fprintf (stderr, "ERROR: catalog %s has invalid averef values\n", catalog.filename);
     326      status = FALSE;
     327    }
     328  }
     329
     330  // check lensing <-> average links
     331  {
     332    int objIDsOK = TRUE;
     333    int catIDsOK = TRUE;
     334    int averefOK = TRUE;
     335
     336    for (i = 0; i < catalog.Naverage; i++) {
     337      m = catalog.average[i].lensingOffset;
     338      for (j = 0; j < catalog.average[i].Nlensing; j++) {
     339        objIDsOK &= (catalog.average[i].objID == catalog.lensing[m+j].objID);
     340        catIDsOK &= (catalog.average[i].catID == catalog.lensing[m+j].catID);
     341        averefOK &= (catalog.lensing[m+j].averef == i);
     342      }
     343    }
     344   
     345    if (!objIDsOK) {
     346      fprintf (stderr, "ERROR: catalog %s has invalid lensing obj IDs\n", catalog.filename);
     347      status = FALSE;
     348    }
     349    if (!catIDsOK) {
     350      fprintf (stderr, "ERROR: catalog %s has invalid lensing cat IDs\n", catalog.filename);
     351      status = FALSE;
     352    }
     353    if (!averefOK) {
     354      fprintf (stderr, "ERROR: catalog %s has invalid lensing averef values\n", catalog.filename);
     355      status = FALSE;
     356    }
     357  }
     358
     359  // check lensobj <-> average links
     360  {
     361    int objIDsOK = TRUE;
     362    int catIDsOK = TRUE;
     363
     364    for (i = 0; i < catalog.Naverage; i++) {
     365      m = catalog.average[i].lensobjOffset;
     366      for (j = 0; j < catalog.average[i].Nlensobj; j++) {
     367        objIDsOK &= (catalog.average[i].objID == catalog.lensobj[m+j].objID);
     368        catIDsOK &= (catalog.average[i].catID == catalog.lensobj[m+j].catID);
     369      }
     370    }
     371   
     372    if (!objIDsOK) {
     373      fprintf (stderr, "ERROR: catalog %s has invalid lensobj obj IDs\n", catalog.filename);
     374      status = FALSE;
     375    }
     376    if (!catIDsOK) {
     377      fprintf (stderr, "ERROR: catalog %s has invalid lensobj cat IDs\n", catalog.filename);
     378      status = FALSE;
     379    }
    273380  }
    274381
     
    321428    }
    322429  }
     430
     431  for (i = 0; i < catalog[0].Naverage; i++) {
     432    m = catalog[0].average[i].lensingOffset;
     433    for (j = 0; j < catalog[0].average[i].Nlensing; j++) {
     434      id = catalog[0].lensing[m+j].imageID;
     435      if (id == 0) continue; // detections from ref photcodes can (should) have unset image IDs
     436      if (id > maxID) {
     437        Nfail ++;
     438        continue;
     439        // is this sufficient to catch IDs set without an image table?
     440      }
     441      if (IDlist) {
     442        if (IDlist[id] < 0) {
     443          Nfail ++;
     444          continue;
     445        }
     446      } else {
     447        if (id > 0) {
     448          Nfail ++;
     449          continue;
     450        }
     451      }
     452    }
     453  }
     454
    323455  return Nfail;
    324456}
     
    382514  return TRUE;
    383515}
     516
     517# define GET_COLUMN(OUT,NAME,TYPE) \
     518  OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \
     519  myAssert (!strcmp(type, #TYPE), "wrong column type");
     520
     521// STATUS is value expected for success
     522# define CHECK_STATUS(STATUS,MSG,...)                                   \
     523  if (!(STATUS)) {                                                      \
     524    fprintf (stderr, MSG, __VA_ARGS__);                                 \
     525    return FALSE;                                                       \
     526  }
     527
     528// write out the IDmap data for clients to read
     529int SaveImageIDsSmall(char *filename) {
     530
     531  Header header;
     532  Header theader;
     533  Matrix matrix;
     534  FTable ftable;
     535
     536  gfits_init_header (&header);
     537  header.extend = TRUE;
     538  gfits_create_header (&header);
     539  gfits_create_matrix (&header, &matrix);
     540
     541  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_IDS");
     542
     543  gfits_define_bintable_column (&theader, "J", "IMAGE_IDS", "image IDs", NULL, 1.0, FT_BZERO_INT32);
     544
     545  // generate the output array that carries the data
     546  gfits_create_table (&theader, &ftable);
     547
     548  // add the columns to the output array
     549  gfits_set_bintable_column (&theader, &ftable, "IMAGE_IDS", IDlist, maxID + 1);
     550
     551  FILE *f = fopen (filename, "w");
     552  if (!f) {
     553    fprintf (stderr, "ERROR: cannot open image ID file for output %s\n", filename);
     554    return FALSE;
     555  }
     556
     557  int status;
     558  status = gfits_fwrite_header  (f, &header);
     559  CHECK_STATUS (status, "ERROR: cannot write header for image ID file %s\n", filename);
     560
     561  status = gfits_fwrite_matrix  (f, &matrix);
     562  CHECK_STATUS (status, "ERROR: cannot write matrix for image ID file %s\n", filename);
     563
     564  status = gfits_fwrite_Theader (f, &theader);
     565  CHECK_STATUS (status, "ERROR: cannot write table header for image ID file %s\n", filename);
     566
     567  status = gfits_fwrite_table  (f, &ftable);
     568  CHECK_STATUS (status, "ERROR: cannot write table data for image ID file %s\n", filename);
     569
     570  gfits_free_header (&header);
     571  gfits_free_matrix (&matrix);
     572  gfits_free_header (&theader);
     573  gfits_free_table (&ftable);
     574
     575  int fd = fileno (f);
     576
     577  status = fflush (f);
     578  CHECK_STATUS (!status, "ERROR: cannot flush file image ID file %s\n", filename);
     579
     580  status = fsync (fd);
     581  CHECK_STATUS (!status, "ERROR: cannot flush file image ID file %s\n", filename);
     582
     583  status = fclose (f);
     584  CHECK_STATUS (!status, "ERROR: problem closing image ID file file %s\n", filename);
     585
     586  return TRUE;
     587}
     588
     589int LoadImageIDsSmall (char *filename) {
     590
     591  int Ncol;
     592  off_t Nrow;
     593  Header header;
     594  Header theader;
     595  Matrix matrix;
     596  FTable ftable;
     597
     598  FILE *f = fopen (filename, "r");
     599  if (!f) {
     600    fprintf (stderr, "ERROR: cannot open image subset file %s\n", filename);
     601    return FALSE;
     602  }
     603
     604  /* load in PHU segment (ignore) */
     605  if (!gfits_fread_header (f, &header)) {
     606    if (VERBOSE) fprintf (stderr, "can't read image subset header\n");
     607    fclose (f);
     608    return FALSE;
     609  }
     610  if (!gfits_fread_matrix (f, &matrix, &header)) {
     611    if (VERBOSE) fprintf (stderr, "can't read image subset matrix\n");
     612    gfits_free_header (&header);
     613    fclose (f);
     614    return FALSE;
     615  }
     616
     617  ftable.header = &theader;
     618
     619  // load data for this header
     620  if (!gfits_load_header (f, &theader)) {
     621    fclose (f);
     622    return FALSE;
     623  }
     624
     625  // read the fits table bytes
     626  if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
     627    fclose (f);
     628    return FALSE;
     629  }
     630  fclose (f);
     631
     632  char type[16];
     633
     634  GET_COLUMN (IDlist, "IMAGE_IDS", int);
     635  maxID = Nrow - 1;
     636  fprintf (stderr, "loaded data for %lld images\n", (long long) Nrow);
     637
     638  return TRUE;
     639}
     640
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/merge_catalogs_new.c

    r28855 r37403  
    88// input entries always define new objects
    99
    10 #define notyet 1
    11 
    1210int merge_catalogs_new (SkyRegion *region, Catalog *output, Catalog *input, int *secfiltMap) {
    1311 
    1412  off_t i, j, offset;
    15   off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, NsecfiltIn, NsecfiltOut, Nm;
     13  off_t NAVERAGE, NMEASURE, NLENSING, Naverage, Nmeasure, Nlensing, NsecfiltIn, NsecfiltOut, Nm;
    1614
    1715  Naverage = output[0].Naverage;
     
    6361      }
    6462      output[0].average[Naverage].Nmeasure = Nm;
     63
     64      Nm = 0;
     65      for (j = 0; j < input[0].average[i].Nlensing; j++) {
     66          offset = input[0].average[i].lensingOffset + j;
     67
     68          output[0].lensing[Nlensing] = input[0].lensing[offset];
     69          output[0].lensing[Nlensing].averef = Naverage;
     70
     71          Nlensing ++;
     72          Nm ++;
     73          if (Nlensing == NLENSING) {
     74              NLENSING += 1000;
     75              REALLOCATE (output[0].lensing, Lensing, NLENSING);
     76          }
     77      }
     78      output[0].average[Naverage].Nlensing = Nm;
     79
    6580      Naverage ++;
    6681      if (Naverage == NAVERAGE) {
     
    7287  REALLOCATE (output[0].average, Average, MAX (Naverage, 1));
    7388  REALLOCATE (output[0].measure, Measure, MAX (Nmeasure, 1));
     89  REALLOCATE (output[0].lensing, Lensing, MAX (Nlensing, 1));
    7490  REALLOCATE (output[0].secfilt, SecFilt, NsecfiltOut*MAX (Naverage, 1));
    7591  output[0].Naverage = Naverage;
    76   output[0].Nmeasure = Nmeasure;
     92  output[0].Nlensing = Nlensing;
    7793  output[0].Nsecf_mem = Naverage * NsecfiltOut;
    7894
     
    84100 
    85101  if (VERBOSE) {
    86       fprintf (stderr, OFF_T_FMT": using "OFF_T_FMT" stars ("OFF_T_FMT" measures) for catalog\n",
     102      fprintf (stderr, OFF_T_FMT": using "OFF_T_FMT" stars ("OFF_T_FMT" measures, "OFF_T_FMT" lensing) for catalog\n",
    87103                i,
    88104                output[0].Naverage,
    89                 output[0].Nmeasure);
     105                output[0].Nmeasure,
     106                output[0].Nlensing);
    90107  }
    91108  return (TRUE);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r36680 r37403  
    11# include "dvomerge.h"
    22# define PSPS_ID TRUE
    3 
    4 # define MARKTIME(MSG,...) {                    \
    5     float dtime;                                \
    6     gettimeofday (&stop, (void *) NULL);        \
    7     dtime = DTIME (stop, start);                \
    8     fprintf (stderr, MSG, __VA_ARGS__);         \
    9     gettimeofday (&start, (void *) NULL);       \
    10   }
    113
    124# define IN_REGION(R,D) (                                       \
     
    1911
    2012  off_t i, j, k, Nin, offset, J, Jmin, status, Nstars;
    21   double RADIUS2, Rmin, Rin, Din;
     13  double RADIUS2, Rmin;
    2214  double *X1, *Y1, *X2, *Y2;
    2315  double dX, dY, dR;
    24   off_t *N1, *N2,  *next_meas;
    25   off_t Nave, NAVE, Nmeas, NMEAS, Nmatch;
     16  off_t *N1, *N2, *next_meas, *next_lens;
     17  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch, Nlens, NLENS;
    2618  int NsecfiltIn;
    2719  int NsecfiltOut;
     
    2921  Coords tcoords;
    3022 
    31   // struct timeval start, stop;
    32   // gettimeofday (&start, (void *) NULL);
     23  // INITTIME;
    3324
    3425  NsecfiltOut = output[0].Nsecfilt;
     
    4031  ALLOCATE (Y1, double, input[0].Naverage);
    4132  ALLOCATE (N1, off_t,  input[0].Naverage);
    42   ALLOCATE (input[0].found, off_t, input[0].Naverage);
     33  if (!input[0].found_t) {
     34    ALLOCATE (input[0].found_t, off_t, input[0].Naverage);
     35  } else {
     36    REALLOCATE (input[0].found_t, off_t, input[0].Naverage);
     37  }
    4338
    4439  /** allocate local arrays (catalog) **/
     
    4742  ALLOCATE (Y2, double, NAVE);
    4843  ALLOCATE (N2, off_t,    NAVE);
    49   ALLOCATE (output[0].found, off_t, NAVE);
     44  if (!output[0].found_t) {
     45    ALLOCATE (output[0].found_t, off_t, NAVE);
     46  } else {
     47    REALLOCATE (output[0].found_t, off_t, NAVE);
     48  }
    5049  /* for secfilt j and star i, secfilt[i*Nsecfilt+j] */
    5150
     
    5352  Nmatch = 0;
    5453  NMEAS = Nmeas = output[0].Nmeasure;
     54  NLENS = Nlens = output[0].Nlensing;
    5555
    5656  // current max obj ID for this catalog
     
    8787    N1[Nstars] = i;
    8888    Nstars ++;
    89     input[0].found[i] = -1;
     89    input[0].found_t[i] = -1;
    9090  }
    9191  if (Nstars < 1) {
    9292    if (VERBOSE) fprintf (stderr, "skipping %s, no overlapping stars\n", output[0].filename);
    93     free (output[0].found);
    94     free (input[0].found);
    9593    free (X1);
    9694    free (Y1);
     
    106104  for (i = 0; i < Nave; i++) {
    107105    RD_to_XY (&X2[i], &Y2[i], output[0].average[i].R, output[0].average[i].D, &tcoords);
    108     output[0].found[i] = -1;
     106    output[0].found_t[i] = -1;
    109107    N2[i] = i;
    110108  }
     
    115113    exit (3);
    116114  }
    117 
    118115
    119116  /* set up pointers for linked list of measure */
     
    122119    // is sorted while processed
    123120    next_meas = init_measure_links (output[0].average, Nave, output[0].measure, Nmeas);
     121    next_lens = init_lensing_links (output[0].average, Nave, output[0].lensing, Nlens);
    124122  } else {
    125123    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);
    126125  }   
    127126
     
    185184      REALLOCATE (output[0].measure, Measure, NMEAS);
    186185    }
     186    if (Nlens + input[0].average[N].Nmeasure >= NLENS) {
     187      NLENS = Nlens + input[0].average[N].Nmeasure + 1000;
     188      REALLOCATE (next_lens, off_t, NLENS);
     189      REALLOCATE (output[0].lensing, Lensing, NLENS);
     190    }
    187191
    188192    // 4) average properties from the input and the output db need to be properly merged.
     
    194198      if (REPLACE_BY_PHOTCODE) {
    195199        // index to first measure for this object
     200        // XXX this does not support lensing measurements
    196201        int Mout = output[0].average[n].measureOffset; 
    197202        if (replace_match(&output[0].average[n], &output[0].measure[Mout], &input[0].average[N], &input[0].measure[offset])) {
    198           input[0].found[N] = Mout;
     203          input[0].found_t[N] = Mout;
    199204          continue;
    200205        }
     
    206211      output[0].measure[Nmeas] = input[0].measure[offset];
    207212
    208       Rin = input[0].average[N].R - input[0].measure[offset].dR / 3600.0;
    209       Din = input[0].average[N].D - input[0].measure[offset].dD / 3600.0;
    210 
    211       /** dR,dD now represent arcsec **/
    212       output[0].measure[Nmeas].dR       = 3600.0*(output[0].average[n].R - Rin);  // XXX update these based on choice of astromety
    213       output[0].measure[Nmeas].dD       = 3600.0*(output[0].average[n].D - Din);  // XXX update these based on choice of astromety
     213      // old code: find R,D using average_in[0], the get offset relative to average_out[0].  no longer
     214      // needed since we carry around R,D
     215      // Rin = input[0].average[N].R - input[0].measure[offset].dR / 3600.0;
     216      // Din = input[0].average[N].D - input[0].measure[offset].dD / 3600.0;
     217      // output[0].measure[Nmeas].dR = 3600.0*(output[0].average[n].R - Rin);
     218      // output[0].measure[Nmeas].dD = 3600.0*(output[0].average[n].D - Din);
     219
    214220      output[0].measure[Nmeas].dbFlags  = 0;  // XXX why reset these?
    215221      output[0].measure[Nmeas].averef   = n;
     
    221227      // 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);
    222228
    223       // rationalize dR
    224       if (output[0].measure[Nmeas].dR > +180.0*3600.0) {
     229      float dRoff = dvoOffsetR(&output[0].measure[Nmeas], &output[0].average[n]);
     230
     231      // rationalize R
     232      if (dRoff > +180.0*3600.0) {
    225233        // average on high end of boundary, move star up
    226         Rin += 360.0;
    227         output[0].measure[Nmeas].dR = 3600.0*(output[0].average[n].R - Rin);
    228       }
    229       if (output[0].measure[Nmeas].dR < -180.0*3600.0) {
     234        output[0].measure[Nmeas].R += 360.0;
     235        dRoff -= 360.0*3600.0;
     236      }
     237      if (dRoff < -180.0*3600.0) {
    230238        // average on low end of boundary, move star down
    231         Rin -= 360.0;
    232         output[0].measure[Nmeas].dR = 3600.0*(output[0].average[n].R - Rin);
    233       }
    234       if (fabs(output[0].measure[Nmeas].dR) > 10*RADIUS) {
    235         // ok take declination into account and check again.
    236         double cosD = cos(RAD_DEG*Din);
    237         if (fabs(output[0].measure[Nmeas].dR*cosD) > 10*RADIUS) {
    238 
    239             fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
    240              output[0].average[n].R, output[0].average[n].D, Rin, Din,
    241              X1[i], X2[Jmin], Y1[i], Y2[Jmin]);
    242 
    243             // XXX abort on this? -- this is a bad failure...
     239        output[0].measure[Nmeas].R -= 360.0;
     240        dRoff += 360.0*3600.0;
     241      }
     242      if (fabs(dRoff) > 10*RADIUS) {
     243        // take declination into account and check again.
     244        double cosD = cos(RAD_DEG*output[0].average[n].D);
     245        if (fabs(dRoff*cosD) > 10*RADIUS) {
     246          fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
     247                   output[0].average[n].R, output[0].average[n].D,
     248                   output[0].measure[Nmeas].R, output[0].measure[Nmeas].D,
     249                   X1[i], X2[Jmin], Y1[i], Y2[Jmin]);
     250          // XXX abort on this? -- this is a bad failure...
    244251        }
    245252      }
    246       input[0].found[N] = Nmeas;
     253      input[0].found_t[N] = Nmeas;
    247254      output[0].average[n].Nmeasure ++;
    248255      Nmeas ++;
     256    }
     257
     258    // if lensing measurements exist, add them too
     259    if (output[0].lensing) {
     260      for (Nin = 0; Nin < input[0].average[N].Nlensing; Nin++) {
     261        /* add to end of lensing list */
     262        add_lens_link (&output[0].average[n], next_lens, Nlens, NLENS);
     263       
     264        // set the new lensing
     265        off_t lensoff = input[0].average[N].lensingOffset + Nin;
     266        output[0].lensing[Nlens] = input[0].lensing[lensoff];
     267
     268        output[0].lensing[Nlens].averef   = n;
     269        output[0].lensing[Nlens].objID    = output[0].average[n].objID;
     270        output[0].lensing[Nlens].catID    = output[0].catID;
     271        output[0].average[n].Nlensing ++;
     272        Nlens ++;
     273      }
    249274    }
    250275
     
    273298    /* Nm is updated, but not written out in -update mode (for existing entries)
    274299       Nm is recalculated in build_meas_links if loaded table is not sorted */
    275     output[0].found[n] = Nmeas;
     300    output[0].found_t[n] = Nmeas;
    276301    i++;
    277302  }
     
    289314      REALLOCATE (output[0].measure, Measure, NMEAS);
    290315    }
     316    if (Nlens + input[0].average[N].Nlensing >= NLENS) {
     317      NLENS = Nlens + input[0].average[N].Nlensing + 1000;
     318      REALLOCATE (next_lens, off_t, NLENS);
     319      REALLOCATE (output[0].lensing, Lensing, NLENS);
     320    }
    291321    if (Nave >= NAVE) {
    292322      NAVE = Nave + 1000;
     
    295325    }
    296326
    297     if (input[0].found[N] >= 0) continue;
     327    if (input[0].found_t[N] >= 0) continue;
    298328    if (!IN_REGION (input[0].average[N].R, input[0].average[N].D)) continue;
    299329
     
    348378
    349379      /* we set next[Nmeas] to -1 here, and update correctly below */
    350       input[0].found[N] = Nmeas;
     380      input[0].found_t[N] = Nmeas;
    351381      next_meas[Nmeas] = -1;
    352382      Nmeas ++;
     
    356386      next_meas[Nmeas - Ngroup + j] = Nmeas - Ngroup + j + 1;
    357387    }
     388
     389    /** add lensing for this input average object **/
     390    if (output[0].lensing) {
     391      output[0].average[Nave].lensingOffset  = Nlens;
     392      for (Nin = 0; Nin < input[0].average[N].Nlensing; Nin ++) {
     393        // supply the lensing values from this detection
     394        off_t lensoff = input[0].average[N].lensingOffset + Nin;
     395        output[0].lensing[Nlens]           = input[0].lensing[lensoff];
     396
     397        // the following lensing elements cannot be set until here:
     398        output[0].lensing[Nlens].averef   = Nave;
     399        output[0].lensing[Nlens].objID    = output[0].average[Nave].objID;
     400        output[0].lensing[Nlens].catID    = output[0].catID;
     401
     402        // as we add lensing, update Nlensing to match
     403        output[0].average[Nave].Nlensing ++;
     404
     405        /* we set next[Nlens] to -1 here, and update correctly below */
     406        next_lens[Nlens] = -1;
     407        Nlens ++;
     408      }
     409      int Ngroup = input[0].average[N].Nlensing;
     410      for (j = 0; j < Ngroup - 1; j++) {
     411        next_lens[Nlens - Ngroup + j] = Nlens - Ngroup + j + 1;
     412      }
     413    }
     414
    358415    Nave ++;
    359416  }
     
    363420  REALLOCATE (output[0].average, Average, Nave);
    364421  REALLOCATE (output[0].measure, Measure, Nmeas);
     422  REALLOCATE (output[0].lensing, Lensing, Nlens);
    365423 
    366424# define NOSORT 0
     
    370428    output[0].sorted = TRUE;
    371429    output[0].measure = sort_measure (output[0].average, Nave, output[0].measure, Nmeas, next_meas);
     430    output[0].lensing = sort_lensing (output[0].average, Nave, output[0].lensing, Nlens, next_lens);
    372431  }
    373432
    374433  /* note stars which have been found in this catalog */
    375434  for (i = 0; i < input[0].Naverage; i++) {
    376     if (input[0].found[i] > -1) {
    377       input[0].found[i] = -2;
     435    if (input[0].found_t[i] > -1) {
     436      input[0].found_t[i] = -2;
    378437    } else {
    379       input[0].found[i] = -3;
     438      input[0].found_t[i] = -3;
    380439    }
    381440  }
     
    385444  output[0].Naverage = Nave;
    386445  output[0].Nmeasure = Nmeas;
     446  output[0].Nlensing = Nlens;
    387447  output[0].Nsecf_mem = Nave*NsecfiltOut;
    388   if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeas, Nmatch);
     448  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nlens: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeas,  Nlens, Nmatch);
    389449
    390450  free (next_meas);
    391 
    392   free (output[0].found);
     451  free (next_lens);
     452
    393453  free (X2);
    394454  free (Y2);
    395455  free (N2);
    396   free (input[0].found);
    397456  free (X1);
    398457  free (Y1);
     
    411470   images have boundaries which are lines in pixels coords, but curve in RA and DEC
    412471   
    413    output[0].found[Ncat] but stars[Nstar].found
     472   output[0].found_t[Ncat] but stars[Nstar].found
    414473   
    415474*/
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/replace_match.c

    r33963 r37403  
    77  unsigned int averef;
    88  unsigned int catID;
    9   double Rin, Din;
    109
    1110  // find the matching photcode in the object's list of measurements
     
    1817    measure_out[Nout] = measure_in[0];
    1918
    20     Rin = average_in[0].R - measure_in[0].dR / 3600.0;
    21     Din = average_in[0].D - measure_in[0].dD / 3600.0;
     19    // old code: find R,D using average_in[0], the get offset relative to average_out[0].  no longer
     20    // needed since we carry around R,D
     21    // double Rin = average_in[0].R - measure_in[0].dR / 3600.0;
     22    // double Din = average_in[0].D - measure_in[0].dD / 3600.0;
     23    // measure_out[Nout].dR = 3600.0*(average_out[0].R - Rin);
     24    // measure_out[Nout].dD = 3600.0*(average_out[0].D - Din);
    2225
    23     /** dR,dD now represent arcsec **/
    24     measure_out[Nout].dR       = 3600.0*(average_out[0].R - Rin);
    25     measure_out[Nout].dD       = 3600.0*(average_out[0].D - Din);
    2626    measure_out[Nout].dbFlags  = 0;  // XXX why reset these?
    2727    measure_out[Nout].averef   = averef;
     
    2929    measure_out[Nout].catID    = catID;
    3030
     31    float dRoff = dvoOffsetR(&measure_out[Nout], average_out);
     32
    3133    // rationalize dR
    32     if (measure_out[Nout].dR > +180.0*3600.0) {
     34    if (dRoff > +180.0*3600.0) {
    3335      // average on high end of boundary, move star up
    34       Rin += 360.0;
    35       measure_out[Nout].dR = 3600.0*(average_out[0].R - Rin);
     36      measure_out[Nout].R += 360.0;
     37      dRoff -= 360.0*3600.0;
    3638    }
    37     if (measure_out[Nout].dR < -180.0*3600.0) {
     39    if (dRoff < -180.0*3600.0) {
    3840      // average on low end of boundary, move star down
    39       Rin -= 360.0;
    40       measure_out[Nout].dR = 3600.0*(average_out[0].R - Rin);
     41      measure_out[Nout].R -= 360.0;
     42      dRoff += 360.0*3600.0;
    4143    }
    4244
    4345    // warn on surprisingly distant detections
    44     if (fabs(measure_out[Nout].dR) > 10*RADIUS) {
     46    if (fabs(dRoff) > 10*RADIUS) {
    4547      // ok take declination into account and check again.
    46       double cosD = cos(RAD_DEG*Din);
    47       if (fabs(measure_out[Nout].dR*cosD) > 10*RADIUS) {
    48 
     48      double cosD = cos(RAD_DEG*average_out[0].D);
     49      if (fabs(dRoff*cosD) > 10*RADIUS) {
    4950        fprintf (stderr, "surprisingly distant detection: %10.6f,%10.6f vs %10.6f,%10.6f\n",
    50                  average_out[0].R, average_out[0].D, Rin, Din);
     51                 average_out[0].R, average_out[0].D, measure_out[Nout].R, measure_out[Nout].D);
    5152      }
    5253    }
Note: See TracChangeset for help on using the changeset viewer.