IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38525


Ignore:
Timestamp:
Jun 24, 2015, 6:38:37 AM (11 years ago)
Author:
eugene
Message:

converting from Stars to Catalog

Location:
branches/eam_branches/ipp-20150616/Ohana/src/addstar
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20150616/Ohana/src/addstar/Makefile

    r38522 r38525  
    7676$(SRC)/MatchHeaders.$(ARCH).o \
    7777$(SRC)/LoadData.$(ARCH).o \
    78 $(SRC)/LoadDataSDSS.$(ARCH).o \
    79 $(SRC)/LoadDataUKIRT.$(ARCH).o \
    80 $(SRC)/LoadDataPMM.$(ARCH).o \
    8178$(SRC)/in_image.$(ARCH).o \
    8279$(SRC)/load_subpix.$(ARCH).o \
     
    10299$(SRC)/update_coords.$(ARCH).o \
    103100$(SRC)/psps_ids.$(ARCH).o
     101
     102## $(SRC)/LoadDataSDSS.$(ARCH).o \
     103## $(SRC)/LoadDataUKIRT.$(ARCH).o \
     104## $(SRC)/LoadDataPMM.$(ARCH).o \
     105##
    104106
    105107# this is the client for parallel operations
  • branches/eam_branches/ipp-20150616/Ohana/src/addstar/include/addstar.h

    r38522 r38525  
    216216Image     *fakeimage              PROTO((char *rootname, off_t *Nimage, int photcode));
    217217
     218int        find_matches_closest          PROTO((SkyRegion *region, Catalog *newcat, Catalog *catalog, AddstarClientOptions options));
     219
    218220int        find_matches                  PROTO((SkyRegion *region, Stars *stars,  unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
    219 int        find_matches_closest          PROTO((SkyRegion *region, Stars *stars,  unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
     221// int        find_matches_closest       PROTO((SkyRegion *region, Stars *stars,  unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
    220222int        find_matches_refstars         PROTO((SkyRegion *region, Stars **stars, unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
    221223int        find_matches_closest_refstars PROTO((SkyRegion *region, Stars **stars, unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
     
    234236Stars     *grefstars              PROTO((char *file, int photcode, unsigned int *Nstars));
    235237
    236 Stars     *LoadStars              PROTO((char *file, unsigned int *Nstars, Image **images, off_t *Nimages, AddstarClientOptions *options));
     238Catalog   *LoadStars              PROTO((char *file, Image **images, off_t *Nimages, AddstarClientOptions *options));
    237239Header   **LoadHeaders            PROTO((FILE *f, int *mode, int *Nheader));
    238240HeaderSet *MatchHeaders           PROTO((off_t **extsize, off_t *nimage, int mode, Header **headers, int Nheaders));
    239241void       HeaderSetFree          PROTO((HeaderSet *headerSets, off_t NheaderSets));
    240 int        LoadData               PROTO((FILE *f, AddstarFile *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, int NheaderSets, AddstarClientOptions *options));
     242Catalog   *LoadData               PROTO((FILE *f, AddstarFile *file, Image **images, off_t *nvalid, Header **headers, off_t *extsize, HeaderSet *headerSets, int NheaderSets, AddstarClientOptions *options));
    241243int        GetZeroPointExposure   PROTO((Header **headers, HeaderSet *headerSets, off_t Nimages));
    242244
     
    257259void       resort_catalog_old     PROTO((Catalog *catalog));
    258260
    259 Stars     *ReadStarsFITS          PROTO((FILE *f, Header *header, Header *in_theader, unsigned int *nstars));
     261Catalog   *ReadStarsFITS          PROTO((FILE *f, Header *header, Header *in_theader));
    260262Stars     *ReadStarsTEXT          PROTO((FILE *f, unsigned int *nstars));
    261263Stars     *ReadStarsSDSS          PROTO((FILE *f, char *name, Header *header, Header *in_theader, Image *images, off_t *nimages, unsigned int *nstars));
    262264int        ReadImageHeader        PROTO((Header *header, Image *image, int photcode));
    263 Stars     *FilterStars            PROTO((Stars *instars, Image *image, unsigned int imageID, const AddstarClientOptions *options));
    264 Stars     *MergeStars             PROTO((Stars *stars, unsigned int *Nstars, Stars *instars, unsigned int Ninstars));
    265 
    266 int        ReadXradFITS           PROTO((FILE *f, Header *theader, Stars *stars, unsigned int Nstars));
     265Catalog   *FilterStars            PROTO((Catalog *newcat, Image *image, unsigned int imageID, const AddstarClientOptions *options));
     266// Stars     *MergeStars             PROTO((Stars *stars, unsigned int *Nstars, Stars *instars, unsigned int Ninstars));
     267
     268// int        ReadXradFITS           PROTO((FILE *f, Header *theader, Stars *stars, unsigned int Nstars));
    267269
    268270double     scat_subpix            PROTO((double x, double y));
     
    310312int args_skycells (int argc, char **argv);
    311313int ConfigInit_skycells (int *argc, char **argv);
    312 int UpdateImageIDs (Stars *stars, unsigned int Nstars, Image *images, off_t Nimages);
     314int UpdateImageIDs (Catalog *catalog, Image *images, off_t Nimages);
    313315
    314316int CheckDuplicateImageIDs (Image *images, off_t Nimages);
     
    338340void saveMosaicCoords (Coords *input);
    339341
    340 
    341342Stars *ReadStarsUKIRT (FILE *f, char *name, Header *header, Image *images, off_t *nimages, unsigned int *nstars);
    342343int LoadDataUKIRT (FILE *f, char *file, Image **images, off_t *nimages, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t NheaderSets);
     
    344345AddstarFile *LoadFilenames (int *nfile, char *filename, AddstarClientOptions *options);
    345346void AddstarFileFree (AddstarFile *file, int Nfile);
     347
     348Catalog *addstar_catalog_init (int Nstars);
    346349
    347350/**
  • branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/FilterStars.c

    r38467 r38525  
    1010// the imageID supplied here is the sequence **within this set**
    1111// this value is updated based on the image table later (in UpdateImageIDs)
    12 Stars *FilterStars (Stars *instars, Image *image, unsigned int imageID, const AddstarClientOptions *options) {
     12Catalog *FilterStars (Catalog *newcat, Image *image, unsigned int imageID, const AddstarClientOptions *options) {
    1313
    1414  int j, N;
    1515  float MTIME, dMs, dMx;
    16   Stars *stars;
    1716  float RMIN, RMAX, DMIN, DMAX;
    1817
     
    2625
    2726  /* modify resulting star list */
    28   ALLOCATE (stars, Stars, image[0].nstar);
    29   for (N = j = 0; j < image[0].nstar; j++) {
     27  Catalog *outcat = addstar_catalog_init (newcat->Nmeasure);
     28  ALLOCATE (outcat->average, Average, newcat->Nmeasure);
     29 
     30  for (N = j = 0; j < newcat->Nmeasure; j++) {
    3031
    31     if (instars[j].measure.photFlags & options->detectionFilter) continue;
     32    if (newcat->measure[j].photFlags & options->detectionFilter) continue;
    3233
    3334    /* allow for some dynamic filtering of star list */
    34     if (SNLIMIT && instars[j].measure.dM > SNLIMIT) continue;
    35     if (XMAX && (instars[j].measure.Xccd > XMAX)) continue;
    36     if (XMIN && (instars[j].measure.Xccd < XMIN)) continue;
    37     if (YMAX && (instars[j].measure.Yccd > YMAX)) continue;
    38     if (YMIN && (instars[j].measure.Yccd < YMIN)) continue;
    39     if (PHOTFLAG_EXCLUDE && (instars[j].measure.photFlags & PHOTFLAG_EXCLUDE)) continue;
     35    if (SNLIMIT && newcat->measure[j].dM > SNLIMIT) continue;
     36    if (XMAX && (newcat->measure[j].Xccd > XMAX)) continue;
     37    if (XMIN && (newcat->measure[j].Xccd < XMIN)) continue;
     38    if (YMAX && (newcat->measure[j].Yccd > YMAX)) continue;
     39    if (YMIN && (newcat->measure[j].Yccd < YMIN)) continue;
     40    if (PHOTFLAG_EXCLUDE && (newcat->measure[j].photFlags & PHOTFLAG_EXCLUDE)) continue;
    4041
    41     stars[N] = instars[j];
     42    dvo_average_init (&outcat->average[N]);
     43    outcat->measure[N] = newcat->measure[j];
    4244
    43     XY_to_RD (&stars[N].average.R, &stars[N].average.D, stars[N].measure.Xccd, stars[N].measure.Yccd, &image[0].coords);
    44     stars[N].average.R = ohana_normalize_angle (stars[N].average.R);
    45     stars[N].measure.R = stars[N].average.R;
    46     stars[N].measure.D = stars[N].average.D;
     45    outcat->average[N].Nmeasure = 1;
     46    outcat->average[N].measureOffset = N;
    4747
    48     stars[N].measure.photcode = image[0].photcode;
     48    XY_to_RD (&outcat->average[N].R, &outcat->average[N].D, outcat->measure[N].Xccd, outcat->measure[N].Yccd, &image[0].coords);
     49    outcat->average[N].R = ohana_normalize_angle (outcat->average[N].R);
     50    outcat->measure[N].R = outcat->average[N].R;
     51    outcat->measure[N].D = outcat->average[N].D;
     52
     53    outcat->measure[N].photcode = image[0].photcode;
    4954
    5055    // determine the full coverage of this set of measurements
    51     RMIN = MIN (RMIN, stars[N].average.R);
    52     RMAX = MAX (RMAX, stars[N].average.R);
    53     DMIN = MIN (DMIN, stars[N].average.D);
    54     DMAX = MAX (DMAX, stars[N].average.D);
     56    RMIN = MIN (RMIN, outcat->average[N].R);
     57    RMAX = MAX (RMAX, outcat->average[N].R);
     58    DMIN = MIN (DMIN, outcat->average[N].D);
     59    DMAX = MAX (DMAX, outcat->average[N].D);
    5560
    5661    /** additional quantities to supply to Stars based on the image data **/
    5762
    5863    /* calculate accurate per-star airmass and azimuth */
    59     stars[N].measure.airmass = airmass (image[0].secz, stars[N].average.R, stars[N].average.D, image[0].sidtime, image[0].latitude);
    60     stars[N].measure.az      = azimuth (15.0*image[0].sidtime - stars[N].average.R, stars[N].average.D, image[0].latitude);
    61     stars[N].measure.Mcal    = image[0].Mcal;
    62     stars[N].measure.t       = image[0].tzero + 1e-4*stars[N].measure.Yccd*image[0].trate;  /* trate is in 0.1 msec / row */
    63     stars[N].measure.dt      = MTIME;
     64    outcat->measure[N].airmass = airmass (image[0].secz, outcat->average[N].R, outcat->average[N].D, image[0].sidtime, image[0].latitude);
     65    outcat->measure[N].az      = azimuth (15.0*image[0].sidtime - outcat->average[N].R, outcat->average[N].D, image[0].latitude);
     66    outcat->measure[N].Mcal    = image[0].Mcal;
     67    outcat->measure[N].t       = image[0].tzero + 1e-4*outcat->measure[N].Yccd*image[0].trate;  /* trate is in 0.1 msec / row */
     68    outcat->measure[N].dt      = MTIME;
    6469
    6570    // watch out for any strange values:
    66     if ((stars[N].measure.M > 25.0) && (stars[N].measure.M < 32.0)) {
     71    if ((outcat->measure[N].M > 25.0) && (outcat->measure[N].M < 32.0)) {
    6772      fprintf (stderr, "*");
    6873    }
     
    7378    dMx = 0.0;
    7479    if (SUBPIX) {
    75       dMs =  get_subpix (stars[N].measure.Xccd, stars[N].measure.Yccd);
    76       dMx = scat_subpix (stars[N].measure.Xccd, stars[N].measure.Yccd);
    77       if (!isnan(stars[N].measure.dM)) {
    78         stars[N].measure.dM = hypot (stars[N].measure.dM, dMx);
     80      dMs =  get_subpix (outcat->measure[N].Xccd, outcat->measure[N].Yccd);
     81      dMx = scat_subpix (outcat->measure[N].Xccd, outcat->measure[N].Yccd);
     82      if (!isnan(outcat->measure[N].dM)) {
     83        outcat->measure[N].dM = hypot (outcat->measure[N].dM, dMx);
    7984      }
    8085    }
    8186
    82     if (!isnan(stars[N].measure.M)) {
    83       stars[N].measure.M   += MTIME - dMs;
     87    if (!isnan(outcat->measure[N].M)) {
     88      outcat->measure[N].M   += MTIME - dMs;
    8489    }
    85     if (!isnan(stars[N].measure.Map)) {
    86       stars[N].measure.Map += MTIME - dMs;
     90    if (!isnan(outcat->measure[N].Map)) {
     91      outcat->measure[N].Map += MTIME - dMs;
    8792    }
    88     if (!isnan(stars[N].measure.Mkron)) {
    89       stars[N].measure.Mkron += MTIME - dMs;
     93    if (!isnan(outcat->measure[N].Mkron)) {
     94      outcat->measure[N].Mkron += MTIME - dMs;
    9095    }
    91     if (!isnan(stars[N].measure.FluxPSF)) {
    92       stars[N].measure.FluxPSF /= image[0].exptime;
     96    if (!isnan(outcat->measure[N].FluxPSF)) {
     97      outcat->measure[N].FluxPSF /= image[0].exptime;
    9398    }
    94     if (!isnan(stars[N].measure.dFluxPSF)) {
    95       stars[N].measure.dFluxPSF /= image[0].exptime;
     99    if (!isnan(outcat->measure[N].dFluxPSF)) {
     100      outcat->measure[N].dFluxPSF /= image[0].exptime;
    96101    }
    97     if (!isnan(stars[N].measure.FluxKron)) {
    98       stars[N].measure.FluxKron /= image[0].exptime;
     102    if (!isnan(outcat->measure[N].FluxKron)) {
     103      outcat->measure[N].FluxKron /= image[0].exptime;
    99104    }
    100     if (!isnan(stars[N].measure.dFluxKron)) {
    101       stars[N].measure.dFluxKron /= image[0].exptime;
     105    if (!isnan(outcat->measure[N].dFluxKron)) {
     106      outcat->measure[N].dFluxKron /= image[0].exptime;
    102107    }
    103     if (!isnan(stars[N].measure.FluxAp)) {
    104       stars[N].measure.FluxAp /= image[0].exptime;
     108    if (!isnan(outcat->measure[N].FluxAp)) {
     109      outcat->measure[N].FluxAp /= image[0].exptime;
    105110    }
    106     if (!isnan(stars[N].measure.dFluxAp)) {
    107       stars[N].measure.dFluxAp /= image[0].exptime;
     111    if (!isnan(outcat->measure[N].dFluxAp)) {
     112      outcat->measure[N].dFluxAp /= image[0].exptime;
    108113    }
    109     if (stars[N].lensing) {
    110       if (!isnan(stars[N].lensing-> F_ApR5)) stars[N].lensing-> F_ApR5 /= image[0].exptime;
    111       if (!isnan(stars[N].lensing->dF_ApR5)) stars[N].lensing->dF_ApR5 /= image[0].exptime;
    112       if (!isnan(stars[N].lensing->sF_ApR5)) stars[N].lensing->sF_ApR5 /= image[0].exptime;
    113       if (!isnan(stars[N].lensing->fF_ApR5)) stars[N].lensing->fF_ApR5 /= image[0].exptime;
    114 
    115       if (!isnan(stars[N].lensing-> F_ApR6)) stars[N].lensing-> F_ApR6 /= image[0].exptime;
    116       if (!isnan(stars[N].lensing->dF_ApR6)) stars[N].lensing->dF_ApR6 /= image[0].exptime;
    117       if (!isnan(stars[N].lensing->sF_ApR6)) stars[N].lensing->sF_ApR6 /= image[0].exptime;
    118       if (!isnan(stars[N].lensing->fF_ApR6)) stars[N].lensing->fF_ApR6 /= image[0].exptime;
    119 
    120       if (!isnan(stars[N].lensing-> F_ApR7)) stars[N].lensing-> F_ApR7 /= image[0].exptime;
    121       if (!isnan(stars[N].lensing->dF_ApR7)) stars[N].lensing->dF_ApR7 /= image[0].exptime;
    122       if (!isnan(stars[N].lensing->sF_ApR7)) stars[N].lensing->sF_ApR7 /= image[0].exptime;
    123       if (!isnan(stars[N].lensing->fF_ApR7)) stars[N].lensing->fF_ApR7 /= image[0].exptime;
     114    if (outcat->lensing) {
     115      if (!isnan(outcat->lensing[N]. F_ApR5)) outcat->lensing[N]. F_ApR5 /= image[0].exptime;
     116      if (!isnan(outcat->lensing[N].dF_ApR5)) outcat->lensing[N].dF_ApR5 /= image[0].exptime;
     117      if (!isnan(outcat->lensing[N].sF_ApR5)) outcat->lensing[N].sF_ApR5 /= image[0].exptime;
     118      if (!isnan(outcat->lensing[N].fF_ApR5)) outcat->lensing[N].fF_ApR5 /= image[0].exptime;
     119      if (!isnan(outcat->lensing[N]. F_ApR6)) outcat->lensing[N]. F_ApR6 /= image[0].exptime;
     120      if (!isnan(outcat->lensing[N].dF_ApR6)) outcat->lensing[N].dF_ApR6 /= image[0].exptime;
     121      if (!isnan(outcat->lensing[N].sF_ApR6)) outcat->lensing[N].sF_ApR6 /= image[0].exptime;
     122      if (!isnan(outcat->lensing[N].fF_ApR6)) outcat->lensing[N].fF_ApR6 /= image[0].exptime;
     123      if (!isnan(outcat->lensing[N]. F_ApR7)) outcat->lensing[N]. F_ApR7 /= image[0].exptime;
     124      if (!isnan(outcat->lensing[N].dF_ApR7)) outcat->lensing[N].dF_ApR7 /= image[0].exptime;
     125      if (!isnan(outcat->lensing[N].sF_ApR7)) outcat->lensing[N].sF_ApR7 /= image[0].exptime;
     126      if (!isnan(outcat->lensing[N].fF_ApR7)) outcat->lensing[N].fF_ApR7 /= image[0].exptime;
    124127    }
    125128   
    126129    // the external ID is supplied, but do we trust it?
    127130    if (!EXTERNAL_ID) {
    128       stars[N].measure.detID = N; // sequence number within image
     131      outcat->measure[N].detID = N; // sequence number within image
    129132    }
    130133
     
    135138
    136139      if (isStack) {
    137         stars[N].measure.extID = CreatePSPSStackDetectionID(image[0].sourceID, image[0].externID, stars[N].measure.detID);
     140        outcat->measure[N].extID = CreatePSPSStackDetectionID(image[0].sourceID, image[0].externID, outcat->measure[N].detID);
    138141      } else {
    139         stars[N].measure.extID = CreatePSPSDetectionID(mjd, image[0].ccdnum, stars[N].measure.detID);
     142        outcat->measure[N].extID = CreatePSPSDetectionID(mjd, image[0].ccdnum, outcat->measure[N].detID);
    140143      }
    141144    } else {
    142       stars[N].measure.extID = 0;
     145      outcat->measure[N].extID = 0;
    143146    }
    144147
    145     stars[N].measure.imageID = imageID; // this value is updated in UpdateImageIDs
     148    outcat->measure[N].imageID = imageID; // this value is updated in UpdateImageIDs
    146149
    147150    // add imageID to lensing entry, if it exists
    148     if (stars[N].lensing) {
    149       stars[N].lensing->imageID = imageID;
     151    if (outcat->lensing) {
     152      outcat->lensing[N].imageID = imageID;
    150153    }
    151154
     
    156159 
    157160  image[0].nstar = N;
    158   REALLOCATE (stars, Stars, image[0].nstar);
    159   free (instars);
    160161
    161   if (VERBOSE) fprintf (stderr, "read %d stars from target file\n", image[0].nstar);
     162  REALLOCATE (outcat->measure, Measure, N);
     163  REALLOCATE (outcat->average, Average, N);
     164  if (outcat->lensing) {
     165    REALLOCATE (outcat->average, Average, N);
     166  }
     167  dvo_catalog_free (newcat);
     168  free (newcat);
     169
     170  outcat->Naverage = N;
     171  outcat->Nmeasure = N;
     172  outcat->Nlensing = outcat->lensing ? N : 0;
     173
     174  if (VERBOSE) fprintf (stderr, "read %d stars from target file\n", N);
    162175  if (VERBOSE) fprintf (stderr, "stars cover region %f,%f - %f,%f\n", RMIN, DMIN, RMAX, DMAX);
    163   return (stars);
     176
     177  return (outcat);
    164178}
    165179
     180# if (0)
    166181Stars *MergeStars (Stars *stars, unsigned int *Nstars, Stars *instars, unsigned int Ninstars) {
    167182
     
    181196  return (stars);
    182197}
     198# endif
  • branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadData.c

    r38523 r38525  
    11# include "addstar.h"
    22
    3 // XXX this function is somewhat specific to the elixir format output files
    4 // it is capable of distinguishing several format versions defined for elixir/psphot
    5 
     3// load photometry data from psphot, sextractor, and a few other formats
    64// examine the header sets and set the Image entries for the the valid images
    7 Catalog *LoadData (FILE *f, AddstarFile *file, Image **images, off_t *nvalid, unsigned int *Ncatalog, Header **headers, off_t *extsize, HeaderSet *headerSets, int Nimages, AddstarClientOptions *options) {
     5Catalog *LoadData (FILE *f, AddstarFile *file, Image **images, off_t *nvalid, Header **headers, off_t *extsize, HeaderSet *headerSets, int Nimages, AddstarClientOptions *options) {
    86
    97  off_t Nskip, Nvalid, NVALID;
     
    119  uint32_t parentID = UINT32_MAX;
    1210
    13   int ncatalog = 0;
    14   int NCATALOG = Nimages;
    1511  Catalog *catalog = NULL;
    16   ALLOCATE (catalog, Catalog, NCATALOG);
     12  // ALLOCATE (catalog, Catalog, 1);
     13  // dvo_catalog_init (catalog, TRUE);
    1714
    1815  if (images[0] == NULL) {
     
    8077    fseeko (f, Nskip, SEEK_SET);
    8178         
    82     status = ReadStarsFITS (f, headers[Nhead], headers[Ndata], &images[0][Nvalid].nstar, &catalog[ncatalog]);
    83     if (!status) {
    84       // XXX need to free the data here or in ReadStarsFITS on error
     79    // ReadStarsFITS populates catalog->measure,Nmeasure
     80    Catalog *newcat = ReadStarsFITS (f, headers[Nhead], headers[Ndata]);
     81    if (!newcat) {
     82      dvo_catalog_free (newcat);
    8583      continue;
    8684    }
     85    images[0][Nvalid].nstar = newcat->Nmeasure;
    8786
     87# if (0)
    8888    // XRAD : if we want to read the xrad table, skip to that table here:
    8989    if (headerSets[i].extnum_xrad != -1) {
     
    9999      }
    100100    }
     101# endif
    101102
    102     FilterStars (&catalog[ncatalog], &images[0][Nvalid], Nvalid, options);
     103    // replace full input catalog newcat with subset version
     104    newcat = FilterStars (newcat, &images[0][Nvalid], Nvalid, options);
     105    catalog = newcat;
    103106
    104     // XXX merge catalogs here : I should only have one output catalog!
    105 
    106     // XXX need to merge here?
    107     // *stars = MergeStars (*stars, Nstars, inStars, images[0][Nvalid].nstar);
    108     // FREE (inStars);
     107    // XXX I need to use find_matches_closest here, but for testing:
     108    // find_matches_closest (region, catalog, newcat, options);
     109    // dvo_catalog_free (newcat);
     110    // free (newcat);
    109111
    110112    Nvalid++;
     
    113115
    114116  if (isfinite(OFFSET_ZPT)) {
    115     for (i = 0; i < *Nstars; i++) {
    116       stars[0][i].measure.M   += OFFSET_ZPT;
    117       stars[0][i].measure.Map += OFFSET_ZPT;
     117    for (i = 0; i < catalog->Nmeasure; i++) {
     118      catalog->measure[i].M   += OFFSET_ZPT;
     119      catalog->measure[i].Map += OFFSET_ZPT;
    118120    }
    119121  }
    120122
    121123  *nvalid = Nvalid;
    122   return (TRUE);
     124  return catalog;
    123125}
    124126
  • branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadStars.c

    r38523 r38525  
    11# include "addstar.h"
    22
    3 Catalog *LoadStars (char *filename, unsigned int *Ncatalog, Image **images, off_t *Nimages, AddstarClientOptions *options) {
     3Catalog *LoadStars (char *filename, Image **images, off_t *Nimages, AddstarClientOptions *options) {
    44
    55  off_t *extsize;
     
    99
    1010  *Nimages = 0;
    11   *Ncatalog = 0;
    1211  *images = NULL;
     12
    1313  Catalog *catalog = NULL;
     14  // ALLOCATE (catalog, Catalog, 1);
     15  // dvo_catalog_init (catalog, TRUE);
    1416
    1517  for (i = 0; i < Nfile; i++) {
     
    2224    // load PMM data if specified (these are not stored as FITS-tables)
    2325    if (PMM_CCD_TABLE != NULL) {
    24       *Ncatalog = 1;
    2526      // XXX catalog = LoadDataPMM (f, file[i].imagename, images, Nimages);
    2627      continue;
     
    5859    // if these are SDSS data, load with SDSS-specific wrapper
    5960    if (headerSets[0].exttype && !strcmp (headerSets[0].exttype, "SDSS_OBJ")) {
    60       *Ncatalog = 1;
    6161      // XXX catalog = LoadDataSDSS (f, file[i].imagename, images, Nimages, headers, extsize, headerSets, NheaderSets);
    6262      goto next_file;
     
    6565    // if these are SDSS data, load with SDSS-specific wrapper
    6666    if (headerSets[0].exttype && !strcmp (headerSets[0].exttype, "UKIRT_OBJ")) {
    67       *Ncatalog = 1;
    6867      // XXX catalog = LoadDataUKIRT (f, file[i].imagename, images, Nimages, headers, extsize, headerSets, NheaderSets);
    6968      goto next_file;
    7069    }
    7170
    72     catalog = LoadData (f, &file[i], images, Nimages, Ncatalog, headers, extsize, headerSets, NheaderSets, options);
     71    Catalog *newcat = LoadData (f, &file[i], images, Nimages, headers, extsize, headerSets, NheaderSets, options);
     72    catalog = newcat;
     73
     74    // XXX I need to use find_matches_closest here, but for testing:
     75    // find_matches_closest (region, catalog, newcat, options);
     76    // dvo_catalog_free (newcat);
     77    // free (newcat);
    7378
    7479  next_file:
  • branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsFITS.c

    r38501 r38525  
    44// (excluding SDSS data and reference database info, such as 2MASS)
    55// NOTE: these must also be listed in MatchHeaders.c (line ~ 62)
    6 Stars     *Convert_SMPDATA           PROTO((FTable *table, unsigned int *nstars));
    7 Stars     *Convert_PS1_DEV_0         PROTO((FTable *table, unsigned int *nstars));
    8 Stars     *Convert_PS1_DEV_1         PROTO((FTable *table, unsigned int *nstars));
    9 Stars     *Convert_PS1_V1            PROTO((FTable *table, unsigned int *nstars));
    10 Stars     *Convert_PS1_V1_Alt        PROTO((FTable *table, unsigned int *nstars));
    11 Stars     *Convert_PS1_V2            PROTO((FTable *table, unsigned int *nstars));
    12 Stars     *Convert_PS1_V3            PROTO((FTable *table, unsigned int *nstars));
    13 Stars     *Convert_PS1_V4            PROTO((FTable *table, unsigned int *nstars));
    14 Stars     *Convert_PS1_V5            PROTO((FTable *table, unsigned int *nstars));
    15 Stars     *Convert_PS1_V5_R0_Lensing PROTO((FTable *table, unsigned int *nstars));
    16 Stars     *Convert_PS1_V5_R1_Lensing PROTO((FTable *table, unsigned int *nstars));
    17 Stars     *Convert_PS1_V5_R2_Lensing PROTO((FTable *table, unsigned int *nstars));
    18 Stars     *Convert_PS1_SV1           PROTO((FTable *table, unsigned int *nstars));
    19 Stars     *Convert_PS1_SV1_Alt       PROTO((FTable *table, unsigned int *nstars));
    20 Stars     *Convert_PS1_SV2           PROTO((FTable *table, unsigned int *nstars));
    21 Stars     *Convert_PS1_SV3           PROTO((FTable *table, unsigned int *nstars));
    22 Stars     *Convert_PS1_SV4           PROTO((FTable *table, unsigned int *nstars));
    23 Stars     *Convert_PS1_DV3           PROTO((FTable *table, unsigned int *nstars));
    24 Stars     *Convert_PS1_DV4           PROTO((FTable *table, unsigned int *nstars));
    25 Stars     *Convert_PS1_DV5           PROTO((FTable *table, unsigned int *nstars));
     6Catalog *Convert_SMPDATA           PROTO((FTable *table));
     7Catalog *Convert_PS1_DEV_0         PROTO((FTable *table));
     8Catalog *Convert_PS1_DEV_1         PROTO((FTable *table));
     9Catalog *Convert_PS1_V1            PROTO((FTable *table));
     10Catalog *Convert_PS1_V1_Alt        PROTO((FTable *table));
     11Catalog *Convert_PS1_V2            PROTO((FTable *table));
     12Catalog *Convert_PS1_V3            PROTO((FTable *table));
     13Catalog *Convert_PS1_V4            PROTO((FTable *table));
     14Catalog *Convert_PS1_V5            PROTO((FTable *table));
     15Catalog *Convert_PS1_V5_R0_Lensing PROTO((FTable *table));
     16Catalog *Convert_PS1_V5_R1_Lensing PROTO((FTable *table));
     17Catalog *Convert_PS1_V5_R2_Lensing PROTO((FTable *table));
     18Catalog *Convert_PS1_SV1           PROTO((FTable *table));
     19Catalog *Convert_PS1_SV1_Alt       PROTO((FTable *table));
     20Catalog *Convert_PS1_SV2           PROTO((FTable *table));
     21Catalog *Convert_PS1_SV3           PROTO((FTable *table));
     22Catalog *Convert_PS1_SV4           PROTO((FTable *table));
     23Catalog *Convert_PS1_DV3           PROTO((FTable *table));
     24Catalog *Convert_PS1_DV4           PROTO((FTable *table));
     25Catalog *Convert_PS1_DV5           PROTO((FTable *table));
     26
     27Catalog *addstar_catalog_init (int Nstars) {
     28  Catalog *catalog = NULL;
     29  ALLOCATE (catalog, Catalog, 1);
     30  dvo_catalog_init (catalog, TRUE);
     31
     32  ALLOCATE (catalog->measure, Measure, Nstars);
     33
     34  int i;
     35  for (i = 0; i < Nstars; i++) {
     36    dvo_measure_init (&catalog->measure[i]);
     37  }
     38  catalog->Nmeasure = Nstars;
     39  return catalog;
     40}
    2641
    2742// given a file with the pointer at the start of the table block and the
    2843// corresponding image header, load the stars from the table
    29 Stars *ReadStarsFITS (FILE *f, Header *header, Header *in_theader, unsigned int *nstars) {
     44Catalog *ReadStarsFITS (FILE *f, Header *header, Header *in_theader) {
    3045
    3146  off_t Nskip;
    32   unsigned int Nstars;
    3347  char type[80];
    3448  Header theader;
    3549  FTable table;
    36   Stars *stars; // Stars contains Average and Measure
    3750 
    3851  if (in_theader == NULL) {
     
    5568  }
    5669
    57   stars = NULL;
     70  Catalog *catalog = NULL;
     71# if (0)
    5872  if (!strcmp (type, "SMPDATA")) {
    5973    stars = Convert_SMPDATA (&table, &Nstars);
     
    8195    stars = Convert_PS1_V4 (&table, &Nstars);
    8296  }
     97# endif
    8398  if (!strcmp (type, "PS1_V5")) {
    8499    switch (table.header[0].Naxis[0]) {
    85100      case 232:
    86         stars = Convert_PS1_V5 (&table, &Nstars);
     101        catalog = Convert_PS1_V5 (&table);
    87102        break;
     103# if (0)
    88104      case 312:
    89105        stars = Convert_PS1_V5_R0_Lensing (&table, &Nstars);
     
    95111        stars = Convert_PS1_V5_R2_Lensing (&table, &Nstars);
    96112        break;
     113# endif
    97114      default:
    98115        fprintf (stderr, "invalid PS1_V5 table size %d\n", (int) table.header[0].Naxis[0]);
     
    100117    }
    101118  }
     119# if (0)
    102120  if (!strcmp (type, "PS1_SV1")) {
    103121    stars = Convert_PS1_SV1 (&table, &Nstars);
     
    121139    stars = Convert_PS1_DV5 (&table, &Nstars);
    122140  }
    123   if (stars == NULL) {
     141# endif
     142  if (catalog == NULL) {
    124143    fprintf (stderr, "invalid table type %s\n", type);
    125144    return (NULL);
     
    127146
    128147  gfits_free_table (&table);
    129 
    130   // Nstars is not necessarily == *nstars (The former is the number of detections, the
    131   // latter are the 'good' detections reported by the photometry system.
    132   *nstars = Nstars;
    133 
    134   return stars;
     148  return catalog;
    135149}
    136150
     
    151165  return dFlux;
    152166}
     167
     168# if (0)
    153169
    154170Stars *Convert_SMPDATA (FTable *table, unsigned int *nstars) {
     
    784800}
    785801
    786 Stars *Convert_PS1_V5 (FTable *table, unsigned int *nstars) {
     802# endif
     803
     804Catalog *Convert_PS1_V5 (FTable *table) {
    787805
    788806  off_t Nstars;
    789807  unsigned int i;
    790808  double ZeroPt;
    791   Stars *stars;
    792809  CMF_PS1_V5 *ps1data;
    793810
     
    799816  ZeroPt = GetZeroPoint();
    800817
    801   ALLOCATE (stars, Stars, Nstars);
    802   for (i = 0; i < Nstars; i++) {
    803     InitStar (&stars[i]);
    804     stars[i].measure.Xccd       = ps1data[i].X;
    805     stars[i].measure.Yccd       = ps1data[i].Y;
    806     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    807     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    808 
    809     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    810     stars[i].measure.pltscale   = ps1data[i].pltscale;
     818  Catalog *catalog = addstar_catalog_init (Nstars);
     819
     820  for (i = 0; i < Nstars; i++) {
     821    catalog->measure[i].Xccd       = ps1data[i].X;
     822    catalog->measure[i].Yccd       = ps1data[i].Y;
     823    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     824    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     825
     826    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     827    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    811828
    812829    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    813       stars[i].measure.M      = NAN;
     830      catalog->measure[i].M      = NAN;
    814831    } else {
    815       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    816     }
    817     stars[i].measure.dM         = ps1data[i].dM;
    818     stars[i].measure.dMcal      = ps1data[i].dMcal;
    819     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    820     stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    821                        
    822     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    823     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     832      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     833    }
     834    catalog->measure[i].dM         = ps1data[i].dM;
     835    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     836    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     837    catalog->measure[i].dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     838                       
     839    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     840    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    824841                       
    825842    // these fluxes are converted from counts to counts/sec in FilterStars.c
    826     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    827     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    828     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    829     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    830     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
    831     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    832 
    833     stars[i].measure.Sky        = ps1data[i].sky;
    834     stars[i].measure.dSky       = ps1data[i].dSky;
    835                        
    836     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    837     stars[i].measure.psfQF      = ps1data[i].psfQF;
    838     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    839 
    840     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    841     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    842     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    843 
    844     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    845     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    846     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    847 
    848     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    849     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    850     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    851                        
    852     stars[i].measure.photFlags  = ps1data[i].flags;
    853     stars[i].measure.photFlags2 = ps1data[i].flags2;
    854 
    855     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    856     stars[i].measure.detID      = ps1data[i].detID;
     843    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     844    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     845    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     846    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     847    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     848    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     849
     850    catalog->measure[i].Sky        = ps1data[i].sky;
     851    catalog->measure[i].dSky       = ps1data[i].dSky;
     852                       
     853    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     854    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     855    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     856
     857    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     858    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     859    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     860
     861    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     862    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     863    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     864
     865    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     866    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     867    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     868                       
     869    catalog->measure[i].photFlags  = ps1data[i].flags;
     870    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     871
     872    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     873    catalog->measure[i].detID      = ps1data[i].detID;
    857874
    858875    // the Average fields and the following Measure fields are set in FilterStars after
     
    865882    // the following fields are currently not being set anywhere: t_msec
    866883  }   
    867   *nstars = Nstars;
    868   return (stars);
    869 }
     884  return (catalog);
     885}
     886
     887# if (0)
    870888
    871889Stars *Convert_PS1_V5_R0_Lensing (FTable *table, unsigned int *nstars) {
     
    19151933  return (stars);
    19161934}
    1917 
    1918 
    1919 
     1935# endif
     1936
     1937
  • branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/UpdateImageIDs.c

    r38501 r38525  
    11# include "addstar.h"
    22
    3 int UpdateImageIDs (Stars *stars, unsigned int Nstars, Image *images, off_t Nimages) {
     3int UpdateImageIDs (Catalog *catalog, Image *images, off_t Nimages) {
    44
    55  int i, status, isEmpty;
     
    5454  }
    5555
    56   for (i = 0; i < Nstars; i++) {
    57     stars[i].measure.imageID += imageID;
    58     if (stars[i].lensing) {
    59       stars[i].lensing->imageID += imageID;
     56  off_t j, m;
     57  for (i = 0; i < catalog->Naverage; i++) {
     58    m = catalog->average[i].measureOffset;
     59    for (j = 0; j < catalog->average[i].Nmeasure; j++, m++) {
     60      catalog->measure[m].imageID += imageID;
     61    }
     62    m = catalog->average[i].lensingOffset;
     63    for (j = 0; j < catalog->average[i].Nlensing; j++, m++) {
     64      catalog->lensing[m].imageID += imageID;
    6065    }
    6166  }
  • branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/addstar.c

    r38501 r38525  
    66int main (int argc, char **argv) {
    77
    8   unsigned int Nstars, Nsubset;
    98  int Nmatch, status, loadObjects;
    109  off_t i, Nimages;
     
    4645  MARKTIME ("init and config: %f sec\n", dtime); RESETTIME;
    4746
    48   Stars *stars = NULL;
     47  Catalog *newcat = NULL;
    4948  Image *images = NULL;
    5049
     
    5251  switch (options.mode) {
    5352    case ADDSTAR_MODE_IMAGE:
    54       stars = LoadStars (argv[1], &Nstars, &images, &Nimages, &options);
     53      newcat = LoadStars (argv[1], &images, &Nimages, &options);
    5554      MARKTIME ("load smf: %f sec\n", dtime); RESETTIME;
    5655
    5756      // set and update the imageID sequence
    58       UpdateImageIDs (stars, Nstars, images, Nimages);
    59 
    60       if ((DUMP != NULL) && !strcmp (DUMP, "rawstars")) dump_rawstars (stars, Nstars);
     57      UpdateImageIDs (newcat, images, Nimages);
     58
     59      // if ((DUMP != NULL) && !strcmp (DUMP, "rawstars")) dump_rawstars (stars, Nstars);
    6160      for (i = 0; i < Nimages; i++) {
    6261        newlist = SkyListByImage (sky, -1, &images[i]);
     
    6766      ImageOptions (&options, images, Nimages);
    6867      break;
     68# if (0)
    6969    case ADDSTAR_MODE_REFLIST:
    7070      stars = grefstars (argv[1], options.photcode, &Nstars);
     
    8080      skylist[0].ownElements = FALSE;
    8181      break;
     82# endif
    8283
    8384    default:
     
    145146    switch (options.mode) {
    146147      case ADDSTAR_MODE_IMAGE:
    147         Nsubset = Nstars;
     148        // Nsubset = Nstars;
    148149        if (options.closest) {
    149           Nmatch += find_matches_closest (skylist[0].regions[i], stars, Nstars, &catalog, options);
     150          Nmatch += find_matches_closest (skylist[0].regions[i], newcat, &catalog, options);
    150151        } else {
    151           Nmatch += find_matches (skylist[0].regions[i], stars, Nstars, &catalog, options);
     152          // XXX Nmatch += find_matches (skylist[0].regions[i], stars, Nstars, &catalog, options);
    152153        }
    153154        break;
     155# if (0)
    154156      case ADDSTAR_MODE_REFCAT:
    155157        stars = greference (argv[1], skylist[0].regions[i], options.photcode, &Nstars);
     
    164166        break;
    165167      }
     168# endif
     169      default:
     170        abort();
    166171    }
    167172    if (VERBOSE) MARKTIME ("match stars: %f sec\n", dtime); RESETTIME;
     
    173178
    174179    // write out catalog, if appropriate
    175     if (Nsubset && !options.only_images) {
     180    if (newcat->Naverage && !options.only_images) {
    176181      SetProtect (TRUE);
    177182      if (options.update) {
     
    187192    if (VERBOSE) MARKTIME ("save cpt: %f sec\n", dtime); RESETTIME;
    188193
    189     if (options.mode == ADDSTAR_MODE_REFCAT) free (stars);
     194    if (options.mode == ADDSTAR_MODE_REFCAT) dvo_catalog_free (newcat);
    190195  }
    191196  SkyListFree (skylist);
    192197
    193198  if (options.mode != ADDSTAR_MODE_REFCAT) {
    194     FREE (stars);
     199    dvo_catalog_free (newcat);
     200    free (newcat);
    195201  }
    196202
     
    229235  gettimeofday (&stopAddstar, (void *) NULL);
    230236  float dtime = DTIME (stopAddstar, startAddstar);
    231   fprintf (stderr, "SUCCESS: elapsed time %9.4f sec for %5d stars (%5d matches), "OFF_T_FMT" average, "OFF_T_FMT" measure, "OFF_T_FMT" lensing\n", dtime, Nstars, Nmatch,  Naverage,  Nmeasure, Nlensing);
     237  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec for "OFF_T_FMT" stars (%5d matches), "OFF_T_FMT" average, "OFF_T_FMT" measure, "OFF_T_FMT" lensing\n", dtime, newcat->Naverage, Nmatch,  Naverage,  Nmeasure, Nlensing);
    232238
    233239  // XXX test
  • branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/find_matches_closest.c

    r38467 r38525  
    11# include "addstar.h"
    22
    3 int find_matches_closest (SkyRegion *region, Stars *stars, unsigned int NstarsIn, Catalog *catalog, AddstarClientOptions options) {
     3int find_matches_closest (SkyRegion *region, Catalog *newcat, Catalog *catalog, AddstarClientOptions options) {
    44 
    55  off_t i, j, n, N, J, Jmin, status, Nstars;
     
    1313  Coords tcoords;
    1414
     15  // XXX this probably is no longer needed (absorbed by catalog->average[j].Nmeasure
    1516  if (NSTAR_GROUP <= 0) {
    1617      fprintf (stderr, "ERROR: NSTAR_GROUP NOT SET!\n");
     
    2627  Nsec     = GetPhotcodeNsec (options.photcode);
    2728
    28   /** allocate local arrays (stars) **/
    29   ALLOCATE (X1, double, NstarsIn);
    30   ALLOCATE (Y1, double, NstarsIn);
    31   ALLOCATE (N1, off_t,  NstarsIn);
     29  /** allocate local arrays (newcat) **/
     30  ALLOCATE (X1, double, newcat->Naverage);
     31  ALLOCATE (Y1, double, newcat->Naverage);
     32  ALLOCATE (N1, off_t,  newcat->Naverage);
     33
     34  if (!newcat->found_t) {
     35    ALLOCATE (newcat->found_t, off_t, newcat->Naverage);
     36    for (i = 0; i < newcat->Naverage; i++) {
     37      newcat->found_t[i] = -1;
     38    }
     39  }
    3240
    3341  /** allocate local arrays (catalog) **/
     
    6472  /* build spatial index (RA sort) referencing input array sequence */
    6573  Nstars = 0;
    66   for (i = 0; i < NstarsIn; i++) {
    67     status = RD_to_XY (&X1[Nstars], &Y1[Nstars], stars[i].average.R, stars[i].average.D, &tcoords);
     74  for (i = 0; i < newcat->Naverage; i++) {
     75    status = RD_to_XY (&X1[Nstars], &Y1[Nstars], newcat->average[i].R, newcat->average[i].D, &tcoords);
    6876    if (!status) continue;
    6977    N1[Nstars] = i;
     
    129137    }
    130138
    131     if (stars[N1[i]].found != -1) {
     139    // XXX check that this is allocated
     140    if (newcat->found_t[N1[i]] != -1) {
    132141        /* this star has already been assigned to an object in this or another catalog */
    133142        i++;
     
    186195
    187196    // set the new measurements
    188     catalog[0].measure[Nmeas]          = stars[N].measure;
     197    catalog[0].measure[Nmeas]          = newcat->measure[N];
    189198
    190199    // measure now carries R,D (not dR,dD)
     
    213222            fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
    214223                     catalog[0].average[n].R, catalog[0].average[n].D,
    215                      stars[N].average.R, stars[N].average.D,
     224                     newcat->average[N].R, newcat->average[N].D,
    216225                     X1[i], X2[Jmin],
    217226                     Y1[i], Y2[Jmin]);
     
    221230
    222231    // add the lensing values if they exist
    223     if (stars[N].lensing) {
     232    if (newcat->lensing) {
    224233      add_lens_link (&catalog[0].average[n], next_lens, Nlens, NLENS); // ?
    225       catalog[0].lensing[Nlens] = stars[N].lensing[0];
     234      catalog[0].lensing[Nlens] = newcat->lensing[N];
    226235     
    227236      catalog[0].lensing[Nlens].averef = n;
     
    251260    /* Nm is updated, but not written out in -update mode (for existing entries)
    252261       Nm is recalculated in build_meas_links if loaded table is not sorted */
    253     stars[N].found = Nmeas;
     262    newcat->found_t[N] = Nmeas;
    254263    catalog[0].found_t[n] = Nmeas;
    255264    catalog[0].average[n].Nmeasure ++;
     
    278287    }
    279288
    280     if (stars[i].found != -1) continue;
    281     if (!IN_REGION (stars[i].average.R, stars[i].average.D)) continue;
     289    if (newcat->found_t[i] != -1) continue;
     290    if (!IN_REGION (newcat->average[i].R, newcat->average[i].D)) continue;
    282291
    283292    dvo_average_init (&catalog[0].average[Nave]);
    284     catalog[0].average[Nave].R             = stars[i].average.R;
    285     catalog[0].average[Nave].D             = stars[i].average.D;
     293    catalog[0].average[Nave].R             = newcat->average[i].R;
     294    catalog[0].average[Nave].D             = newcat->average[i].D;
    286295
    287296    catalog[0].average[Nave].Nmeasure      = NSTAR_GROUP;
     
    303312      // supply the measurments from this detection
    304313      dvo_measure_init (&catalog[0].measure[Nmeas]);
    305       catalog[0].measure[Nmeas]           = stars[i + j].measure;
     314      catalog[0].measure[Nmeas] = newcat->measure[i + j];
    306315
    307316      // the following measure elements cannot be set until here:
     
    319328      /* next[Nmeas] should always be -1 in this context (it is always the only
    320329         measurement for the star) */
    321       stars[i+j].found = Nmeas;
     330      newcat->found_t[i+j] = Nmeas;
    322331      next_meas[Nmeas] = -1;  // inital value here update below
    323332      Nmeas ++;
     
    328337
    329338    // if we have lensing data, insert that as well
    330     if (stars[i].lensing) {
     339    if (newcat->lensing) {
    331340      catalog[0].average[Nave].Nlensing = NSTAR_GROUP;
    332341      catalog[0].average[Nave].lensingOffset = Nlens;
    333342      for (j = 0; j < NSTAR_GROUP; j++) {
    334343        // add the lensing values if they exist
    335         if (stars[i + j].lensing) {
     344        if (newcat->lensing) {
    336345          dvo_lensing_init (&catalog[0].lensing[Nlens]);
    337           catalog[0].lensing[Nlens] = stars[i + j].lensing[0];
     346          catalog[0].lensing[Nlens] = newcat->lensing[i + j];
    338347         
    339348          catalog[0].lensing[Nlens].averef = Nave;
     
    365374
    366375  /* note stars which have been found in this catalog */
    367   for (i = 0; i < NstarsIn; i++) {
    368     if (stars[i].found > -1) {
    369       stars[i].found = -2;
     376  for (i = 0; i < newcat->Naverage; i++) {
     377    if (newcat->found_t[i] > -1) {
     378      newcat->found_t[i] = -2;
    370379    }
    371380  }
Note: See TracChangeset for help on using the changeset viewer.