IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 17, 2014, 12:32:26 PM (12 years ago)
Author:
eugene
Message:

merge changes (from past YEAR) into trunk

Location:
branches/eam_branches/ipp-ops-20130712/Ohana
Files:
330 edited
94 copied

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-ops-20130712/Ohana

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/include/addstar.h

    r35579 r37067  
    4141
    4242typedef struct {
    43   Average average;
    44   Measure measure;
     43  Average  average;
     44  Measure  measure;
     45  Lensing *lensing; // optionally carry out the lensing measurements
    4546  int found;
    4647} Stars;
     
    250251void       update_coords          PROTO((Average *average, Measure *measure, off_t *next));
    251252off_t     *init_measure_links     PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
     253off_t     *init_lensing_links     PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
    252254off_t     *init_missing_links     PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing));
    253255off_t      add_meas_link          PROTO((Average *average, off_t *next_meas, off_t Nmeasure, off_t NMEASURE));
    254256off_t      add_miss_link          PROTO((Average *average, off_t *next_miss, off_t Nmissing));
     257off_t      add_lens_link          PROTO((Average *average, off_t *next_lens, off_t Nlensing, off_t NLENSING));
    255258off_t     *build_measure_links    PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
     259off_t     *build_lensing_links    PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
    256260Measure   *sort_measure           PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next_meas));
    257261Missing   *sort_missing           PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss));
     262Lensing   *sort_lensing           PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next_lens));
    258263int        ImageOptions           PROTO((AddstarClientOptions *options, Image *images, off_t Nimages));
    259264int        GetFileMode            PROTO((Header *header));
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/FilterStars.c

    r34260 r37067  
    9999      stars[N].measure.dFluxKron /= image[0].exptime;
    100100    }
     101    if (!isnan(stars[N].measure.FluxAp)) {
     102      stars[N].measure.FluxAp /= image[0].exptime;
     103    }
     104    if (!isnan(stars[N].measure.dFluxAp)) {
     105      stars[N].measure.dFluxAp /= image[0].exptime;
     106    }
    101107   
    102108    // the external ID is supplied, but do we trust it?
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/GetFileMode.c

    r35416 r37067  
    1010  int havePHOT_VER, haveTARG_VER;
    1111
     12  // NOTE target of %t must be int length
    1213  gfits_scan_alt (header, "SIMPLE", "%t", 1, &simple);
    1314  int haveNaxis = gfits_scan (header, "NAXIS",  "%d", 1, &Naxis);
    14   int haveCTYPE = gfits_scan (header, "CTYPE1", "%s", 1, ctype);
     15  int haveCTYPE = gfits_scan (header, "CTYPE2", "%s", 1, ctype);
    1516
    1617  gfits_scan_alt (header, "EXTEND", "%t", 1, &extend);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/LoadDataPMM.c

    r34088 r37067  
    193193
    194194    // XXX for now, we define a totally fake coordinate system centered on the plate center
    195     strcpy (image[0].coords.ctype, "RA---TAN");
     195    strcpy (image[0].coords.ctype, "DEC--TAN");
    196196   
    197197    image[0].coords.crval1  = pmm_get_ra (RA);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/MatchHeaders.c

    r35416 r37067  
    5959    if (!strcmp (exttype, "PS1_V3")) goto keep;
    6060    if (!strcmp (exttype, "PS1_V4")) goto keep;
     61    if (!strcmp (exttype, "PS1_V5")) goto keep;
     62
    6163    if (!strcmp (exttype, "PS1_SV1")) goto keep;
    6264    if (!strcmp (exttype, "PS1_SV2")) goto keep;
    63     if (!strcmp (exttype, "PS1_DV3")) {
    64       goto keep;
    65     }
     65    if (!strcmp (exttype, "PS1_SV3")) goto keep;
     66
     67    if (!strcmp (exttype, "PS1_DV1")) goto keep;
     68    if (!strcmp (exttype, "PS1_DV2")) goto keep;
     69    if (!strcmp (exttype, "PS1_DV3")) goto keep;
     70    if (!strcmp (exttype, "PS1_DV4")) goto keep;
    6671    continue;
    6772
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/ReadImageHeader.c

    r31395 r37067  
    4444  image[0].NX = Nx;
    4545  image[0].NY = Ny;
     46
     47  image[0].refColorBlue = NAN;
     48  image[0].refColorRed = NAN;
    4649
    4750  if (!gfits_scan (header, "TZERO",   "%d",  1, &image[0].tzero) && !ACCEPT_TIME) {
     
    133136
    134137  tmp = 0;
    135   gfits_scan (header, "FLIMIT",   "%lf", 1, &tmp);
     138  // gfits_scan (header, "FLIMIT",   "%lf", 1, &tmp);
     139  gfits_scan (header, "DETEFF.MAGREF", "%lf", 1, &tmp);
    136140  image[0].detection_limit = tmp * 10.0;
    137141
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/ReadStarsFITS.c

    r35416 r37067  
    1212Stars     *Convert_PS1_V3         PROTO((FTable *table, unsigned int *nstars));
    1313Stars     *Convert_PS1_V4         PROTO((FTable *table, unsigned int *nstars));
     14Stars     *Convert_PS1_V5         PROTO((FTable *table, unsigned int *nstars));
     15Stars     *Convert_PS1_V5_Lensing PROTO((FTable *table, unsigned int *nstars));
    1416Stars     *Convert_PS1_SV1        PROTO((FTable *table, unsigned int *nstars));
    1517Stars     *Convert_PS1_SV1_Alt    PROTO((FTable *table, unsigned int *nstars));
    1618Stars     *Convert_PS1_SV2        PROTO((FTable *table, unsigned int *nstars));
     19Stars     *Convert_PS1_SV3        PROTO((FTable *table, unsigned int *nstars));
    1720Stars     *Convert_PS1_DV3        PROTO((FTable *table, unsigned int *nstars));
     21Stars     *Convert_PS1_DV4        PROTO((FTable *table, unsigned int *nstars));
    1822
    1923// given a file with the pointer at the start of the table block and the
     
    7377    stars = Convert_PS1_V4 (&table, &Nstars);
    7478  }
     79  if (!strcmp (type, "PS1_V5")) {
     80    if (table.header[0].Naxis[0] == 312) {
     81      stars = Convert_PS1_V5_Lensing (&table, &Nstars);
     82    } else {
     83      stars = Convert_PS1_V5 (&table, &Nstars);
     84    }
     85  }
    7586  if (!strcmp (type, "PS1_SV1")) {
    7687    stars = Convert_PS1_SV1 (&table, &Nstars);
     
    7990    stars = Convert_PS1_SV2 (&table, &Nstars);
    8091  }
     92  if (!strcmp (type, "PS1_SV3")) {
     93    stars = Convert_PS1_SV3 (&table, &Nstars);
     94  }
    8195  if (!strcmp (type, "PS1_DV3")) {
    8296    stars = Convert_PS1_DV3 (&table, &Nstars);
    8397  }
     98  if (!strcmp (type, "PS1_DV4")) {
     99    stars = Convert_PS1_DV4 (&table, &Nstars);
     100  }
    84101  if (stars == NULL) {
    85102    fprintf (stderr, "invalid table type %s\n", type);
     
    91108
    92109  return stars;
     110}
     111
     112float GetFluxFromFluxOrMag (float flux, float mag) {
     113
     114  if (isnan(mag) && isnan(flux)) return NAN;
     115
     116  if (isnan(flux)) return pow(10.0,-0.4*mag);
     117  return flux;
     118}
     119
     120float GetFluxErrFromFluxOrMag (float dFlux, float flux, float dMag) {
     121
     122  if (isnan(dMag) && isnan(dFlux)) return NAN;
     123  if (isnan(dFlux) && isnan(flux)) return NAN;
     124
     125  if (isnan(dFlux)) return (fabs(dMag * flux));
     126  return dFlux;
    93127}
    94128
     
    360394    stars[i].measure.dMcal      = ps1data[i].dMcal;
    361395    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     396    stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    362397                       
    363398    stars[i].measure.Mkron      = NAN; // not provided by PS1_V1:
     
    445480    stars[i].measure.dMcal      = ps1data[i].dMcal;
    446481    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     482    stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    447483                       
    448484    stars[i].measure.Mkron      = NAN; // not provided by PS1_V1_Alt:
     
    522558    stars[i].measure.dMcal      = ps1data[i].dMcal;
    523559    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     560    stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    524561                       
    525562    stars[i].measure.Mkron      = NAN; // not provided by PS1_V2:
     
    595632    stars[i].measure.dMcal      = ps1data[i].dMcal;
    596633    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     634    stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    597635                       
    598636    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     
    600638                       
    601639    // these fluxes are converted from counts to counts/sec in FilterStars.c
    602     stars[i].measure.FluxPSF    = ps1data[i].Flux;
    603     stars[i].measure.dFluxPSF   = ps1data[i].dFlux;
     640    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     641    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    604642    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    605643    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     644    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (NAN, ps1data[i].Map);
     645    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (NAN, stars[i].measure.FluxAp, stars[i].measure.dMap);
    606646
    607647    stars[i].measure.Sky        = ps1data[i].sky;
     
    676716    stars[i].measure.dMcal      = ps1data[i].dMcal;
    677717    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     718    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    678719                       
    679720    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     
    681722                       
    682723    // these fluxes are converted from counts to counts/sec in FilterStars.c
    683     stars[i].measure.FluxPSF    = ps1data[i].Flux;
    684     stars[i].measure.dFluxPSF   = ps1data[i].dFlux;
     724    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     725    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    685726    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    686727    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     728    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     729    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    687730
    688731    stars[i].measure.Sky        = ps1data[i].sky;
     
    724767}
    725768
    726 Stars *Convert_PS1_SV1 (FTable *table, unsigned int *nstars) {
     769Stars *Convert_PS1_V5 (FTable *table, unsigned int *nstars) {
    727770
    728771  off_t Nstars;
     
    730773  double ZeroPt;
    731774  Stars *stars;
    732   CMF_PS1_SV1 *ps1data;
    733 
    734   if (table[0].header[0].Naxis[0] == 196) {
    735     stars = Convert_PS1_SV1_Alt (table, nstars);
    736     return (stars);
    737   }
    738 
    739   ps1data = gfits_table_get_CMF_PS1_SV1 (table, &Nstars, NULL);
     775  CMF_PS1_V5 *ps1data;
     776
     777  ps1data = gfits_table_get_CMF_PS1_V5 (table, &Nstars, NULL);
    740778  if (!ps1data) {
    741779    fprintf (stderr, "skipping inconsistent entry\n");
     
    763801    stars[i].measure.dMcal      = ps1data[i].dMcal;
    764802    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     803    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    765804                       
    766805    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    767806    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    768 
     807                       
    769808    // these fluxes are converted from counts to counts/sec in FilterStars.c
    770     stars[i].measure.FluxPSF    = ps1data[i].Flux;
    771     stars[i].measure.dFluxPSF   = ps1data[i].dFlux;
     809    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     810    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    772811    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    773812    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     813    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     814    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    774815
    775816    stars[i].measure.Sky        = ps1data[i].sky;
     
    799840
    800841    // the Average fields and the following Measure fields are set in FilterStars after
    801     // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID,
    802     // averef is set in find_matches, dbFlags is zero on ingest.
     842    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID.
     843
     844    // averef is set in find_matches
     845
     846    // dbFlags is zero on ingest.
    803847
    804848    // the following fields are currently not being set anywhere: t_msec
     
    808852}
    809853
    810 Stars *Convert_PS1_SV1_Alt (FTable *table, unsigned int *nstars) {
     854Stars *Convert_PS1_V5_Lensing (FTable *table, unsigned int *nstars) {
    811855
    812856  off_t Nstars;
     
    814858  double ZeroPt;
    815859  Stars *stars;
    816   CMF_PS1_SV1 *ps1data;
    817 
    818   // some test output files were produced called CMF_PS1_SV1 but with mismatch byte boundaries
    819 
    820   ps1data = gfits_table_get_CMF_PS1_SV1_Alt (table, &Nstars, NULL);
     860  CMF_PS1_V5_Lensing *ps1data;
     861
     862  ps1data = gfits_table_get_CMF_PS1_V5_Lensing (table, &Nstars, NULL);
    821863  if (!ps1data) {
    822864    fprintf (stderr, "skipping inconsistent entry\n");
     
    844886    stars[i].measure.dMcal      = ps1data[i].dMcal;
    845887    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     888    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    846889                       
    847890    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    848891    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    849 
     892                       
    850893    // these fluxes are converted from counts to counts/sec in FilterStars.c
    851     stars[i].measure.FluxPSF    = ps1data[i].Flux;
    852     stars[i].measure.dFluxPSF   = ps1data[i].dFlux;
     894    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     895    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    853896    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    854897    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     898    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     899    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
     900
     901    stars[i].measure.Sky        = ps1data[i].sky;
     902    stars[i].measure.dSky       = ps1data[i].dSky;
     903                       
     904    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     905    stars[i].measure.psfQF      = ps1data[i].psfQF;
     906    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
     907
     908    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
     909    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
     910    stars[i].measure.crNsigma   = ps1data[i].crNsigma;
     911    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
     912
     913    stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
     914    stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
     915    stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
     916
     917    stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
     918    stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     919    stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
     920                       
     921    stars[i].measure.photFlags  = ps1data[i].flags;
     922
     923    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     924    stars[i].measure.detID      = ps1data[i].detID;
     925
     926    ALLOCATE (stars[i].lensing, Lensing, 1);
     927    dvo_lensing_init (stars[i].lensing);
     928
     929    stars[i].lensing->X11_sm_obj  = ps1data[i].X11_sm_obj;
     930    stars[i].lensing->X12_sm_obj  = ps1data[i].X12_sm_obj;
     931    stars[i].lensing->X22_sm_obj  = ps1data[i].X22_sm_obj;
     932    stars[i].lensing->E1_sm_obj   = ps1data[i].E1_sm_obj;
     933    stars[i].lensing->E2_sm_obj   = ps1data[i].E2_sm_obj;
     934
     935    stars[i].lensing->X11_sh_obj  = ps1data[i].X11_sh_obj;
     936    stars[i].lensing->X12_sh_obj  = ps1data[i].X12_sh_obj;
     937    stars[i].lensing->X22_sh_obj  = ps1data[i].X22_sh_obj;
     938    stars[i].lensing->E1_sh_obj   = ps1data[i].E1_sh_obj;
     939    stars[i].lensing->E2_sh_obj   = ps1data[i].E2_sh_obj;
     940
     941    stars[i].lensing->X11_sm_psf  = ps1data[i].X11_sm_psf;
     942    stars[i].lensing->X12_sm_psf  = ps1data[i].X12_sm_psf;
     943    stars[i].lensing->X22_sm_psf  = ps1data[i].X22_sm_psf;
     944    stars[i].lensing->E1_sm_psf   = ps1data[i].E1_sm_psf;
     945    stars[i].lensing->E2_sm_psf   = ps1data[i].E2_sm_psf;
     946
     947    stars[i].lensing->X11_sh_psf  = ps1data[i].X11_sh_psf;
     948    stars[i].lensing->X12_sh_psf  = ps1data[i].X12_sh_psf;
     949    stars[i].lensing->X22_sh_psf  = ps1data[i].X22_sh_psf;
     950    stars[i].lensing->E1_sh_psf   = ps1data[i].E1_sh_psf;
     951    stars[i].lensing->E2_sh_psf   = ps1data[i].E2_sh_psf;
     952
     953    // stars[i].lensing->F_ApR5    = ps1data[i].F_ApR5;
     954    // stars[i].lensing->dF_ApR5   = ps1data[i].dF_ApR5;
     955    // stars[i].lensing->sF_ApR5   = ps1data[i].sF_ApR5;
     956    // stars[i].lensing->fF_ApR5   = ps1data[i].fF_ApR5;
     957    //
     958    // stars[i].lensing->F_ApR6    = ps1data[i].F_ApR6;
     959    // stars[i].lensing->dF_ApR6   = ps1data[i].dF_ApR6;
     960    // stars[i].lensing->sF_ApR6   = ps1data[i].sF_ApR6;
     961    // stars[i].lensing->fF_ApR6   = ps1data[i].fF_ApR6;
     962
     963    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     964    stars[i].lensing->detID      = ps1data[i].detID;
     965
     966    // the Average fields and the following Measure fields are set in FilterStars after
     967    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID.
     968
     969    // averef is set in find_matches
     970
     971    // dbFlags is zero on ingest.
     972
     973    // the following fields are currently not being set anywhere: t_msec
     974  }   
     975  *nstars = Nstars;
     976  return (stars);
     977}
     978
     979Stars *Convert_PS1_SV1 (FTable *table, unsigned int *nstars) {
     980
     981  off_t Nstars;
     982  unsigned int i;
     983  double ZeroPt;
     984  Stars *stars;
     985  CMF_PS1_SV1 *ps1data;
     986
     987  if (table[0].header[0].Naxis[0] == 196) {
     988    stars = Convert_PS1_SV1_Alt (table, nstars);
     989    return (stars);
     990  }
     991
     992  ps1data = gfits_table_get_CMF_PS1_SV1 (table, &Nstars, NULL);
     993  if (!ps1data) {
     994    fprintf (stderr, "skipping inconsistent entry\n");
     995    return (NULL);
     996  }
     997  ZeroPt = GetZeroPoint();
     998
     999  ALLOCATE (stars, Stars, Nstars);
     1000  for (i = 0; i < Nstars; i++) {
     1001    InitStar (&stars[i]);
     1002    stars[i].measure.Xccd       = ps1data[i].X;
     1003    stars[i].measure.Yccd       = ps1data[i].Y;
     1004    stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
     1005    stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
     1006
     1007    stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
     1008    stars[i].measure.pltscale   = ps1data[i].pltscale;
     1009
     1010    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
     1011      stars[i].measure.M      = NAN;
     1012    } else {
     1013      stars[i].measure.M      = ps1data[i].M + ZeroPt;
     1014    }
     1015    stars[i].measure.dM         = ps1data[i].dM;
     1016    stars[i].measure.dMcal      = ps1data[i].dMcal;
     1017    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1018    stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
     1019                       
     1020    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1021    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1022
     1023    // these fluxes are converted from counts to counts/sec in FilterStars.c
     1024    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1025    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
     1026    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
     1027    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1028    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (NAN, ps1data[i].Map);
     1029    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (NAN, stars[i].measure.FluxAp, stars[i].measure.dMap);
     1030
     1031    stars[i].measure.Sky        = ps1data[i].sky;
     1032    stars[i].measure.dSky       = ps1data[i].dSky;
     1033                       
     1034    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     1035    stars[i].measure.psfQF      = ps1data[i].psfQF;
     1036    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
     1037
     1038    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
     1039    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
     1040    stars[i].measure.crNsigma   = ps1data[i].crNsigma;
     1041    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
     1042
     1043    stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
     1044    stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
     1045    stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
     1046
     1047    stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
     1048    stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     1049    stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
     1050                       
     1051    stars[i].measure.photFlags  = ps1data[i].flags;
     1052
     1053    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1054    stars[i].measure.detID      = ps1data[i].detID;
     1055
     1056    // the Average fields and the following Measure fields are set in FilterStars after
     1057    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID,
     1058    // averef is set in find_matches, dbFlags is zero on ingest.
     1059
     1060    // the following fields are currently not being set anywhere: t_msec
     1061  }   
     1062  *nstars = Nstars;
     1063  return (stars);
     1064}
     1065
     1066Stars *Convert_PS1_SV1_Alt (FTable *table, unsigned int *nstars) {
     1067
     1068  off_t Nstars;
     1069  unsigned int i;
     1070  double ZeroPt;
     1071  Stars *stars;
     1072  CMF_PS1_SV1 *ps1data;
     1073
     1074  // some test output files were produced called CMF_PS1_SV1 but with mismatch byte boundaries
     1075
     1076  ps1data = gfits_table_get_CMF_PS1_SV1_Alt (table, &Nstars, NULL);
     1077  if (!ps1data) {
     1078    fprintf (stderr, "skipping inconsistent entry\n");
     1079    return (NULL);
     1080  }
     1081  ZeroPt = GetZeroPoint();
     1082
     1083  ALLOCATE (stars, Stars, Nstars);
     1084  for (i = 0; i < Nstars; i++) {
     1085    InitStar (&stars[i]);
     1086    stars[i].measure.Xccd       = ps1data[i].X;
     1087    stars[i].measure.Yccd       = ps1data[i].Y;
     1088    stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
     1089    stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
     1090
     1091    stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
     1092    stars[i].measure.pltscale   = ps1data[i].pltscale;
     1093
     1094    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
     1095      stars[i].measure.M      = NAN;
     1096    } else {
     1097      stars[i].measure.M      = ps1data[i].M + ZeroPt;
     1098    }
     1099    stars[i].measure.dM         = ps1data[i].dM;
     1100    stars[i].measure.dMcal      = ps1data[i].dMcal;
     1101    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1102    stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
     1103                       
     1104    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1105    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1106
     1107    // these fluxes are converted from counts to counts/sec in FilterStars.c
     1108    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1109    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
     1110    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
     1111    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1112    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (NAN, ps1data[i].Map);
     1113    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (NAN, stars[i].measure.FluxAp, stars[i].measure.dMap);
    8551114
    8561115    stars[i].measure.Sky        = ps1data[i].sky;
     
    9211180    stars[i].measure.dMcal      = ps1data[i].dMcal;
    9221181    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1182    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    9231183                       
    9241184    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     
    9261186
    9271187    // these fluxes are converted from counts to counts/sec in FilterStars.c
    928     stars[i].measure.FluxPSF    = ps1data[i].Flux;
    929     stars[i].measure.dFluxPSF   = ps1data[i].dFlux;
     1188    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1189    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    9301190    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    9311191    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1192    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1193    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    9321194
    9331195    stars[i].measure.Sky        = ps1data[i].sky;
     
    9661228}
    9671229
    968 Stars *Convert_PS1_DV3 (FTable *table, unsigned int *nstars) {
     1230Stars *Convert_PS1_SV3 (FTable *table, unsigned int *nstars) {
    9691231
    9701232  off_t Nstars;
     
    9721234  double ZeroPt;
    9731235  Stars *stars;
    974   CMF_PS1_DV3 *ps1data;
    975 
    976   ps1data = gfits_table_get_CMF_PS1_DV3 (table, &Nstars, NULL);
     1236  CMF_PS1_SV3 *ps1data;
     1237
     1238  ps1data = gfits_table_get_CMF_PS1_SV3 (table, &Nstars, NULL);
    9771239  if (!ps1data) {
    9781240    fprintf (stderr, "skipping inconsistent entry\n");
     
    10001262    stars[i].measure.dMcal      = ps1data[i].dMcal;
    10011263    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1264    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    10021265                       
    10031266    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    10041267    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    1005                        
     1268
    10061269    // these fluxes are converted from counts to counts/sec in FilterStars.c
    1007     stars[i].measure.FluxPSF    = ps1data[i].Flux;
    1008     stars[i].measure.dFluxPSF   = ps1data[i].dFlux;
     1270    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1271    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    10091272    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    10101273    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1274    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1275    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
     1276
     1277    stars[i].measure.Sky        = ps1data[i].sky;
     1278    stars[i].measure.dSky       = ps1data[i].dSky;
     1279                       
     1280    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     1281    stars[i].measure.psfQF      = ps1data[i].psfQF;
     1282    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
     1283
     1284    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
     1285    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
     1286    stars[i].measure.crNsigma   = ps1data[i].crNsigma;
     1287    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
     1288
     1289    stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
     1290    stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
     1291    stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
     1292
     1293    stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
     1294    stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     1295    stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
     1296                       
     1297    stars[i].measure.photFlags  = ps1data[i].flags;
     1298
     1299    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1300    stars[i].measure.detID      = ps1data[i].detID;
     1301
     1302    // the Average fields and the following Measure fields are set in FilterStars after
     1303    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID,
     1304    // averef is set in find_matches, dbFlags is zero on ingest.
     1305
     1306    // the following fields are currently not being set anywhere: t_msec
     1307  }   
     1308  *nstars = Nstars;
     1309  return (stars);
     1310}
     1311
     1312Stars *Convert_PS1_DV3 (FTable *table, unsigned int *nstars) {
     1313
     1314  off_t Nstars;
     1315  unsigned int i;
     1316  double ZeroPt;
     1317  Stars *stars;
     1318  CMF_PS1_DV3 *ps1data;
     1319
     1320  ps1data = gfits_table_get_CMF_PS1_DV3 (table, &Nstars, NULL);
     1321  if (!ps1data) {
     1322    fprintf (stderr, "skipping inconsistent entry\n");
     1323    return (NULL);
     1324  }
     1325  ZeroPt = GetZeroPoint();
     1326
     1327  ALLOCATE (stars, Stars, Nstars);
     1328  for (i = 0; i < Nstars; i++) {
     1329    InitStar (&stars[i]);
     1330    stars[i].measure.Xccd       = ps1data[i].X;
     1331    stars[i].measure.Yccd       = ps1data[i].Y;
     1332    stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
     1333    stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
     1334
     1335    stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
     1336    stars[i].measure.pltscale   = ps1data[i].pltscale;
     1337
     1338    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
     1339      stars[i].measure.M      = NAN;
     1340    } else {
     1341      stars[i].measure.M      = ps1data[i].M + ZeroPt;
     1342    }
     1343    stars[i].measure.dM         = ps1data[i].dM;
     1344    stars[i].measure.dMcal      = ps1data[i].dMcal;
     1345    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1346    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1347                       
     1348    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1349    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1350                       
     1351    // these fluxes are converted from counts to counts/sec in FilterStars.c
     1352    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1353    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
     1354    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
     1355    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1356    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1357    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    10111358
    10121359    stars[i].measure.Sky        = ps1data[i].sky;
     
    10471394}
    10481395
    1049 
    1050 
     1396Stars *Convert_PS1_DV4 (FTable *table, unsigned int *nstars) {
     1397
     1398  off_t Nstars;
     1399  unsigned int i;
     1400  double ZeroPt;
     1401  Stars *stars;
     1402  CMF_PS1_DV4 *ps1data;
     1403
     1404  ps1data = gfits_table_get_CMF_PS1_DV4 (table, &Nstars, NULL);
     1405  if (!ps1data) {
     1406    fprintf (stderr, "skipping inconsistent entry\n");
     1407    return (NULL);
     1408  }
     1409  ZeroPt = GetZeroPoint();
     1410
     1411  fprintf (stderr, "WARNING: Convert_PS1_DV4 not yet updated to match real format\n");
     1412
     1413  ALLOCATE (stars, Stars, Nstars);
     1414  for (i = 0; i < Nstars; i++) {
     1415    InitStar (&stars[i]);
     1416    stars[i].measure.Xccd       = ps1data[i].X;
     1417    stars[i].measure.Yccd       = ps1data[i].Y;
     1418    stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
     1419    stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
     1420
     1421    stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
     1422    stars[i].measure.pltscale   = ps1data[i].pltscale;
     1423
     1424    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
     1425      stars[i].measure.M      = NAN;
     1426    } else {
     1427      stars[i].measure.M      = ps1data[i].M + ZeroPt;
     1428    }
     1429    stars[i].measure.dM         = ps1data[i].dM;
     1430    stars[i].measure.dMcal      = ps1data[i].dMcal;
     1431    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1432    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1433                       
     1434    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1435    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1436                       
     1437    // these fluxes are converted from counts to counts/sec in FilterStars.c
     1438    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1439    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
     1440    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
     1441    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1442    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1443    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
     1444
     1445    stars[i].measure.Sky        = ps1data[i].sky;
     1446    stars[i].measure.dSky       = ps1data[i].dSky;
     1447                       
     1448    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     1449    stars[i].measure.psfQF      = ps1data[i].psfQF;
     1450    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
     1451    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
     1452    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
     1453    stars[i].measure.crNsigma   = ps1data[i].crNsigma;
     1454    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
     1455
     1456    stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
     1457    stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
     1458    stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
     1459
     1460    stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
     1461    stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     1462    stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
     1463                       
     1464    stars[i].measure.photFlags  = ps1data[i].flags;
     1465
     1466    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1467    stars[i].measure.detID      = ps1data[i].detID;
     1468
     1469    // the Average fields and the following Measure fields are set in FilterStars after
     1470    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID.
     1471
     1472    // averef is set in find_matches
     1473
     1474    // dbFlags is zero on ingest.
     1475
     1476    // the following fields are currently not being set anywhere: t_msec
     1477  }   
     1478  *nstars = Nstars;
     1479  return (stars);
     1480}
     1481
     1482
     1483
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/ReadStarsSDSS.c

    r34088 r37067  
    201201   
    202202    // XXX for now, we define a totally fake coordinate system centered on the first listed star
    203     strcpy (images[N].coords.ctype, "RA---TAN");
     203    strcpy (images[N].coords.ctype, "DEC--TAN");
    204204   
    205205    images[N].coords.crval1 = stars[0].average.R;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/SEDfit.c

    r34405 r37067  
    162162    }
    163163
     164    double R = incat[0].average[i].R;
     165    double D = incat[0].average[i].D;
     166
    164167    for (j = 0; valid && (j < Nmodel); j++) {
    165168      n = modelRow[j];
    166169      dvo_measure_init (&outcat[0].measure[Nmeas]);
    167       outcat[0].measure[Nmeas].dR        = 0.0;
    168       outcat[0].measure[Nmeas].dD        = 0.0;
     170      outcat[0].measure[Nmeas].R         = R;
     171      outcat[0].measure[Nmeas].D         = D;
    169172      outcat[0].measure[Nmeas].M         = table[0].row[minFit.row][0].mags[n] + minFit.Md;
    170173      outcat[0].measure[Nmeas].dM        = 0.0;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/StarOps.c

    r34260 r37067  
    88    star[0].found = -1; // found == -1 -> not yet found (use enums?)
    99
     10    star[0].lensing = NULL; // we only populate this if needed
    1011    return TRUE;
    1112}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/addstar.c

    r34405 r37067  
    77  int Nmatch, status, loadObjects;
    88  off_t i, Nimages;
    9   off_t Naverage, Nmeasure;
     9  off_t Naverage, Nmeasure, Nlensing;
    1010  Stars *stars, **subset;
    1111  Image *images;
     
    100100
    101101  /* match stars to existing catalog data (or otherwise manipulate catalog data) */
    102   Nmatch = Naverage = Nmeasure = 0;
     102  Nmatch = Naverage = Nmeasure = Nlensing = 0;
    103103  for (i = 0; loadObjects && (i < skylist[0].Nregions); i++) {
    104104
     
    107107    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    108108    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    109     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     109    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF | LOAD_LENSING;
    110110    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    111111
     
    182182    Naverage += catalog.Naverage;
    183183    Nmeasure += catalog.Nmeasure;
     184    Nlensing += catalog.Nlensing;
    184185
    185186    // write out catalog, if appropriate
     
    187188      SetProtect (TRUE);
    188189      if (options.update) {
    189         catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     190        catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF | LOAD_LENSING;
    190191        dvo_catalog_update (&catalog, VERBOSE);
    191192      } else {
     
    231232  gettimeofday (&stop, NULL);
    232233  dtime = DTIME (stop, start);
    233   fprintf (stderr, "SUCCESS: elapsed time %9.4f sec for %5d stars (%5d matches), "OFF_T_FMT" average, "OFF_T_FMT" measure\n", dtime, Nstars, Nmatch,  Naverage,  Nmeasure);
     234  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);
    234235
    235236  exit (0);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/build_links.c

    r27435 r37067  
    225225}
    226226
     227/*******************************************************************************************/
     228
     229/* build the initial links assuming the table is sorted,
     230   not partial, and has a correct set of average[].lensingOffset,Nlensing values */
     231off_t *init_lensing_links (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing) {
     232
     233  off_t i, j, N;
     234  off_t *next_lens;
     235
     236  N = 0;
     237
     238  ALLOCATE (next_lens, off_t, Nlensing);
     239  for (i = 0; i < Naverage; i++) {
     240    if (!average[i].Nlensing) continue;
     241    for (j = 0; j < average[i].Nlensing - 1; j++, N++) {
     242      next_lens[N] = N + 1;
     243      if (N >= Nlensing) {
     244        fprintf (stderr, "WARNING: N out of bounds (1)\n");
     245      }
     246    }
     247    next_lens[N] = -1;
     248    if (N >= Nlensing) {
     249      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     250    }
     251
     252    if (N >= Nlensing) {
     253      fprintf (stderr, "overflow in init_lensing_links\n");
     254      abort ();
     255    }
     256    N++;
     257  }
     258  return (next_lens);
     259}
     260
     261/* construct lensing links which are valid FOR THIS LOAD
     262 * - if we have a full load, we will get links which can
     263 *   be used by other programs (eg, relphot, etc)
     264 * - if we have a partial load, the links are only valid
     265 *   for that partial load
     266 */
     267
     268off_t *build_lensing_links (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing) {
     269
     270  off_t i, m, k, Nm, averef;
     271  off_t *next_lens;
     272
     273  ALLOCATE (next_lens, off_t, Nlensing);
     274
     275  /* reset the Nm, offset values for average */
     276  for (i = 0; i < Naverage; i++) {
     277    average[i].lensingOffset = -1;
     278    average[i].Nlensing     =  0;
     279  }
     280
     281  for (Nm = 0; Nm < Nlensing; Nm++) {
     282    averef = lensing[Nm].averef;
     283    m = average[averef].lensingOffset; 
     284    next_lens[Nm] = -1;
     285
     286    if (m == -1) { /* no links yet for source */
     287      average[averef].lensingOffset = Nm;
     288      average[averef].Nlensing     = 1;
     289      continue;
     290    }
     291
     292    for (k = 0; next_lens[m] != -1; k++) {
     293      m = next_lens[m];
     294      if (m >= Nlensing) {
     295        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     296      }
     297    }
     298
     299    average[averef].Nlensing = k + 2;
     300    next_lens[m] = Nm;
     301    if (m >= Nlensing) {
     302      fprintf (stderr, "WARNING: m out of bounds (2)\n");
     303    }
     304  }
     305  return (next_lens);
     306}
     307
     308/* average[].lensingOffset, average[].Nlensing are valid within an addstar run */
     309off_t add_lens_link (Average *average, off_t *next_lens, off_t Nlensing, off_t NLENSING) {
     310
     311  off_t k, m;
     312
     313  /* if we have trouble, check validity of next_lens[m] : m < Nlensing */
     314  m = average[0].lensingOffset; 
     315
     316  for (k = 0; k < average[0].Nlensing - 1; k++)  {
     317    m = next_lens[m];
     318    if (m >= NLENSING) {
     319      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     320    }
     321  }
     322
     323  /* set up references */
     324  next_lens[Nlensing] = -1;
     325  if (Nlensing >= NLENSING) {
     326    fprintf (stderr, "WARNING: Nlensing out of bounds (1)\n");
     327  }
     328
     329  if (m == -1) {
     330    average[0].lensingOffset = Nlensing;
     331  } else {
     332    next_lens[m] = Nlensing;
     333    if (m >= NLENSING) {
     334      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     335    }
     336  }
     337
     338  return (TRUE);
     339}
     340
     341Lensing *sort_lensing (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next_lens) {
     342
     343  off_t i, k, n, N;
     344  Lensing *tmplensing;
     345
     346  /* fix order of Lensing (memory intensive, but fast) */
     347  N = 0;
     348  ALLOCATE (tmplensing, Lensing, Nlensing);
     349  for (i = 0; i < Naverage; i++) {
     350    if (!average[i].Nlensing) continue;
     351    n = average[i].lensingOffset;
     352    average[i].lensingOffset = N;
     353    for (k = 0; k < average[i].Nlensing; k++, N++) {
     354      if (n == -1) abort();
     355      tmplensing[N] = lensing[n];
     356      if (lensing[n].averef != i) abort();
     357      tmplensing[N].averef = i;
     358      n = next_lens[n];
     359    }
     360  }
     361  free (lensing);
     362  return (tmplensing);
     363}
     364
     365
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/fakeimage.c

    r30613 r37067  
    66  double pltscale, pixscale;
    77  double Rmin, Rmax, Dmin, Dmax;
    8   // double Xmin, Xmax, Ymin, Ymax;
    98  double dX, dY, r, d;
    109  char chipname[80], chipdata[256], name[80];
     
    3433
    3534  /* create a mosaic distortion structure */
    36   strcpy (MOSAIC.ctype, "RA---DIS");
     35  strcpy (MOSAIC.ctype, "DEC--DIS");
    3736  MOSAIC.crval1 = FAKE_RA;
    3837  MOSAIC.crval2 = FAKE_DEC;
     
    8685    strcpy (image[i+1].name, name);
    8786
    88     strcpy (image[i+1].coords.ctype, "RA---WRP");
     87    strcpy (image[i+1].coords.ctype, "DEC--WRP");
    8988   
    9089    image[i+1].coords.crval1 = dX*pixscale;
     
    168167  image[0].cerror = 0.0;
    169168   
    170   // RD_to_XY (&Xmax, &Ymax, Rmax, Dmax, MOSAIC);
    171   // RD_to_XY (&Xmin, &Ymin, Rmin, Dmin, MOSAIC);
    172169  image[0].NX = Rmax - Rmin;
    173170  image[0].NY = Dmax - Dmin;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/find_matches.c

    r34361 r37067  
    1414
    1515  if (NSTAR_GROUP <= 0) {
    16       fprintf (stderr, "ERROR: NSTAR_GROUP NOT SET!\n");
    17       exit (1);
     16    fprintf (stderr, "ERROR: NSTAR_GROUP NOT SET!\n");
     17    exit (1);
    1818  }
    1919
     
    3636  ALLOCATE (Y2, double, NAVE);
    3737  ALLOCATE (N2, off_t,  NAVE);
    38   ALLOCATE (catalog[0].found, off_t, NAVE);
     38  ALLOCATE (catalog[0].found_t, off_t, NAVE);
    3939  /* for secfilt j and star i, secfilt[i*Nsecfilt+j] */
    4040
     
    6565  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    6666  tcoords.Npolyterms = 1;
    67   strcpy (tcoords.ctype, "RA---ARC");
     67  strcpy (tcoords.ctype, "DEC--ARC");
    6868
    6969  /* build spatial index (RA sort) referencing input array sequence */
     
    7777  if (Nstars < 1) {
    7878    if (VERBOSE) fprintf (stderr, "skipping %s, no overlapping stars\n", catalog[0].filename);
    79     free (catalog[0].found);
    8079    free (X1);
    8180    free (Y1);
     
    9291    RD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
    9392    N2[i] = i;
    94     catalog[0].found[N2[i]] = -1;
     93    catalog[0].found_t[N2[i]] = -1;
    9594  }
    9695  if (Nave > 1) sort_coords_index (X2, Y2, N2, Nave);
     
    160159
    161160      // the following measure elements cannot be set until here:
    162       catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N].average.R);
    163       catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N].average.D);
     161      catalog[0].measure[Nmeas].R        = stars[N].average.R;
     162      catalog[0].measure[Nmeas].D        = stars[N].average.D;
    164163      catalog[0].measure[Nmeas].dbFlags  = 0;
    165164      catalog[0].measure[Nmeas].averef   = n; // this must be an absolute sequence number, if partial average is loaded
     
    167166      catalog[0].measure[Nmeas].catID    = catalog[0].catID;
    168167
    169       // rationalize dR:
    170       if (catalog[0].measure[Nmeas].dR > +180.0*3600.0) {
    171           // average on high end of boundary, move star up
    172           stars[N].average.R += 360.0;
    173           catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].average.R);
    174       }
    175       if (catalog[0].measure[Nmeas].dR < -180.0*3600.0) {
    176           // average on low end of boundary, move star down
    177           stars[N].average.R -= 360.0;
    178           catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].average.R);
    179       }
    180       if (fabs(catalog[0].measure[Nmeas].dR) > 10*RADIUS) {
     168      float dRoff = dvoOffsetR(&catalog[0].measure[Nmeas], &catalog[0].average[n]);
     169
     170      // rationalize R:
     171      if (dRoff > +180.0*3600.0) {
     172        // average on high end of boundary, move star up
     173        catalog[0].measure[Nmeas].R += 360.0;
     174        dRoff -= 360.0*3600.0;
     175      }
     176      if (dRoff < -180.0*3600.0) {
     177        // average on low end of boundary, move star down
     178        catalog[0].measure[Nmeas].R -= 360.0;
     179        dRoff += 360.0*3600.0;
     180      }
     181      if (fabs(dRoff) > 10*RADIUS) {
     182        // take declination into account and check again.
     183        double cosD = cos(RAD_DEG*catalog[0].average[n].D);
     184        if (fabs(dRoff*cosD) > 10*RADIUS) {
    181185          fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
    182186                   catalog[0].average[n].R, catalog[0].average[n].D,
     
    184188                   X1[i], X2[J],
    185189                   Y1[i], Y2[J]);
     190        }
    186191      }
    187192
     
    196201      if (Nsec > -1) {
    197202        if (isnan(catalog[0].secfilt[n*Nsecfilt+Nsec].M)) {
    198           catalog[0].secfilt[n*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
     203          catalog[0].secfilt[n*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas], MAG_CLASS_PSF);
    199204        }
    200205      }
     
    213218      }
    214219      /* this catalog star matches more than one image star */
    215       if (catalog[0].found[n] > -1) {
    216         catalog[0].measure[catalog[0].found[n]].dbFlags |= ID_MEAS_BLEND_OBJ;
     220      if (catalog[0].found_t[n] > -1) {
     221        catalog[0].measure[catalog[0].found_t[n]].dbFlags |= ID_MEAS_BLEND_OBJ;
    217222        catalog[0].measure[Nmeas].dbFlags |= ID_MEAS_BLEND_OBJ;
    218223      } else {
    219         catalog[0].found[n] = Nmeas;
     224        catalog[0].found_t[n] = Nmeas;
    220225      }
    221226      /* Nm is updated, but not written out in -update mode (for existing entries)
     
    232237  }
    233238
    234   /* incorporate unmatched image stars, if this star is in field of this catalog */
    235   /* these new entries are all written out in UPDATE mode */
     239/* incorporate unmatched image stars, if this star is in field of this catalog */
     240/* these new entries are all written out in UPDATE mode */
    236241  for (i = 0; (i < Nstars) && !options.only_match; i += NSTAR_GROUP) {
    237242    /* make sure there is space for next entry */
     
    260265
    261266    if (PSPS_ID) {
    262         catalog[0].average[Nave].extID = CreatePSPSObjectID(catalog[0].average[Nave].R, catalog[0].average[Nave].D);
     267      catalog[0].average[Nave].extID = CreatePSPSObjectID(catalog[0].average[Nave].R, catalog[0].average[Nave].D);
    263268    }
    264269
     
    274279
    275280      // the following measure elements cannot be set until here:
    276       catalog[0].measure[Nmeas].dR              = 0.0;
    277       catalog[0].measure[Nmeas].dD              = 0.0;
     281      catalog[0].measure[Nmeas].R               = stars[i].average.R;
     282      catalog[0].measure[Nmeas].D               = stars[i].average.D;
    278283      catalog[0].measure[Nmeas].dbFlags         = 0;
    279284      catalog[0].measure[Nmeas].averef          = Nave; // XXX EAM : must be absolute Nave if partial read
     
    284289      /* in UPDATE mode, this value is not saved; use relphot to recalculate */
    285290      if (Nsec > -1) {
    286           catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
     291        catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas], MAG_CLASS_PSF);
    287292      }
    288293
    289294      /* next[Nmeas] should always be -1 in this context (it is always the only
    290         measurement for the star) */
     295        measurement for the star) */
    291296      stars[i].found = Nmeas;
    292297      next_meas[Nmeas] = -1;  // initial value here update below
     
    309314  }
    310315
    311   /* note stars which have been found in this catalog */
     316/* note stars which have been found in this catalog */
    312317  for (i = 0; i < NstarsIn; i++) {
    313318    if (stars[i].found > -1) {
     
    316321  }
    317322
    318   /* check if the catalog has changed?  if no change, no need to write */
     323/* check if the catalog has changed?  if no change, no need to write */
    319324  catalog[0].objID    = objID; // new max value, save on catalog close
    320325  catalog[0].Naverage = Nave;
     
    323328  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);
    324329
    325   free (catalog[0].found);
    326330  free (X1);
    327331  free (Y1);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/find_matches_closest.c

    r34361 r37067  
    77  double *X1, *Y1, *X2, *Y2;
    88  double dX, dY, dR;
    9   off_t *N1, *N2, *next_meas;
    10   off_t Nave, NAVE, Nmeas, NMEAS, Nmatch;
     9  off_t *N1, *N2, *next_meas, *next_lens;
     10  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch, Nlens, NLENS;
    1111  int Nsecfilt, Nsec;
    1212  unsigned int objID, catID;
     
    3636  ALLOCATE (Y2, double, NAVE);
    3737  ALLOCATE (N2, off_t,  NAVE);
    38   ALLOCATE (catalog[0].found, off_t, NAVE);
     38  ALLOCATE (catalog[0].found_t, off_t, NAVE);
    3939  /* for secfilt j and star i, secfilt[i*Nsecfilt+j] */
    4040
     
    4242  Nmatch = 0;
    4343  NMEAS = Nmeas = catalog[0].Nmeasure;
     44  NLENS = Nlens = catalog[0].Nlensing;
    4445
    4546  // current max obj ID for this catalog
     
    6465  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    6566  tcoords.Npolyterms = 1;
    66   strcpy (tcoords.ctype, "RA---ARC");
     67  strcpy (tcoords.ctype, "DEC--ARC");
    6768
    6869  /* build spatial index (RA sort) referencing input array sequence */
     
    7677  if (Nstars < 1) {
    7778    if (VERBOSE) fprintf (stderr, "skipping %s, no overlapping stars\n", catalog[0].filename);
    78     free (catalog[0].found);
    7979    free (X1);
    8080    free (Y1);
     
    9191    RD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
    9292    N2[i] = i;
    93     catalog[0].found[N2[i]] = -1;
     93    catalog[0].found_t[N2[i]] = -1;
    9494  }
    9595  if (Nave > 1) sort_coords_index (X2, Y2, N2, Nave);
     
    100100    // is sorted while processed
    101101    next_meas = init_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas);
     102    next_lens = init_lensing_links (catalog[0].average, Nave, catalog[0].lensing, Nlens);
    102103  } else {
    103104    next_meas = build_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas);
     105    next_lens = build_lensing_links (catalog[0].average, Nave, catalog[0].lensing, Nlens);
    104106  }   
    105107
     
    177179      REALLOCATE (catalog[0].measure, Measure, NMEAS);
    178180    }
     181    if (Nlens >= NLENS) {
     182      NLENS = Nlens + 1000;
     183      REALLOCATE (next_lens, off_t, NLENS);
     184      REALLOCATE (catalog[0].lensing, Lensing, NLENS);
     185    }
    179186
    180187    /* add to end of measurement list */
     
    186193    catalog[0].measure[Nmeas]          = stars[N].measure;
    187194
    188     /** dR,dD now represent arcsec **/
    189     catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N].average.R);
    190     catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N].average.D);
     195    // measure now carries R,D (not dR,dD)
     196    // note that ReadStarsFITS does not set measure.R,D and average.R,D
     197    catalog[0].measure[Nmeas].R        = stars[N].average.R;
     198    catalog[0].measure[Nmeas].D        = stars[N].average.D;
    191199    catalog[0].measure[Nmeas].dbFlags  = 0;
    192200    catalog[0].measure[Nmeas].averef   = n;
     
    194202    catalog[0].measure[Nmeas].catID    = catalog[0].catID;
    195203
     204    float dRoff = dvoOffsetR(&catalog[0].measure[Nmeas], &catalog[0].average[n]);
     205
    196206    // rationalize dR
    197     if (catalog[0].measure[Nmeas].dR > +180.0*3600.0) {
     207    if (dRoff > +180.0*3600.0) {
    198208      // average on high end of boundary, move star up
    199       stars[N].average.R += 360.0;
    200       catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].average.R);
    201     }
    202     if (catalog[0].measure[Nmeas].dR < -180.0*3600.0) {
     209      catalog[0].measure[Nmeas].R += 360.0;
     210      dRoff -= 360.0*3600.0;
     211    }
     212    if (dRoff < -180.0*3600.0) {
    203213      // average on low end of boundary, move star down
    204       stars[N].average.R -= 360.0;
    205       catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].average.R);
    206     }
    207     if (fabs(catalog[0].measure[Nmeas].dR) > 10*RADIUS) {
    208       fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
    209                catalog[0].average[n].R, catalog[0].average[n].D,
    210                stars[N].average.R, stars[N].average.D,
    211                X1[i], X2[Jmin],
    212                Y1[i], Y2[Jmin]);
    213         // XXX abort on this? -- this is a bad failure...
     214      catalog[0].measure[Nmeas].R -= 360.0;
     215      dRoff += 360.0*3600.0;
     216    }
     217    if (fabs(dRoff) > 10*RADIUS) {
     218        // take declination into account and check again.
     219        double cosD = cos(RAD_DEG*catalog[0].average[n].D);
     220        if (fabs(dRoff*cosD) > 10*RADIUS) {
     221            fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
     222                     catalog[0].average[n].R, catalog[0].average[n].D,
     223                     stars[N].average.R, stars[N].average.D,
     224                     X1[i], X2[Jmin],
     225                     Y1[i], Y2[Jmin]);
     226            // XXX abort on this? -- this is a bad failure...
     227        }
     228    }
     229
     230    // add the lensing values if they exist
     231    if (stars[N].lensing) {
     232      add_lens_link (&catalog[0].average[n], next_lens, Nlens, NLENS); // ?
     233      catalog[0].lensing[Nlens] = stars[N].lensing[0];
     234     
     235      catalog[0].lensing[Nlens].averef = n;
     236      catalog[0].lensing[Nlens].objID = catalog[0].average[n].objID;
     237      catalog[0].lensing[Nlens].catID = catalog[0].catID;
     238      catalog[0].average[n].Nlensing ++;
     239      Nlens ++;
    214240    }
    215241
     
    224250    if (Nsec > -1) {
    225251      if (isnan(catalog[0].secfilt[n*Nsecfilt+Nsec].M)) {
    226         catalog[0].secfilt[n*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
     252        catalog[0].secfilt[n*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas], MAG_CLASS_PSF);
    227253      }
    228254    }
     
    234260       Nm is recalculated in build_meas_links if loaded table is not sorted */
    235261    stars[N].found = Nmeas;
    236     catalog[0].found[n] = Nmeas;
     262    catalog[0].found_t[n] = Nmeas;
    237263    catalog[0].average[n].Nmeasure ++;
    238264    Nmeas ++;
     
    249275      REALLOCATE (catalog[0].measure, Measure, NMEAS);
    250276    }
     277    if (Nlens >= NLENS - NSTAR_GROUP) {
     278      NLENS = Nlens + 1000;
     279      REALLOCATE (next_lens, off_t, NLENS);
     280      REALLOCATE (catalog[0].lensing, Lensing, NLENS);
     281    }
    251282    if (Nave >= NAVE) {
    252283      NAVE = Nave + 1000;
     
    278309
    279310    for (j = 0; j < NSTAR_GROUP; j++) {
    280         // supply the measurments from this detection
    281         catalog[0].measure[Nmeas]           = stars[i + j].measure;
    282 
    283         // the following measure elements cannot be set until here:
    284         catalog[0].measure[Nmeas].dR       = 0.0; // astrometric offset, not error
    285         catalog[0].measure[Nmeas].dD       = 0.0; // astrometric offset, not error
    286         catalog[0].measure[Nmeas].dbFlags  = 0;
    287         catalog[0].measure[Nmeas].averef   = Nave;
    288         catalog[0].measure[Nmeas].objID    = catalog[0].average[Nave].objID;
    289         catalog[0].measure[Nmeas].catID    = catalog[0].catID;
    290 
    291         /* set the average magnitude if not already set and the photcode.equiv is not 0 */
    292         /* in UPDATE mode, this value is not saved; use relphot to recalculate */
    293         if (Nsec > -1) {
    294             catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
    295         }
    296 
    297         /* next[Nmeas] should always be -1 in this context (it is always the only
    298            measurement for the star) */
    299         stars[i+j].found = Nmeas;
    300         next_meas[Nmeas] = -1;  // inital value here update below
    301         Nmeas ++;
     311      // supply the measurments from this detection
     312      dvo_measure_init (&catalog[0].measure[Nmeas]);
     313      catalog[0].measure[Nmeas]           = stars[i + j].measure;
     314
     315      // the following measure elements cannot be set until here:
     316      catalog[0].measure[Nmeas].R        = stars[i].average.R;
     317      catalog[0].measure[Nmeas].D        = stars[i].average.D;
     318      catalog[0].measure[Nmeas].dbFlags  = 0;
     319      catalog[0].measure[Nmeas].averef   = Nave;
     320      catalog[0].measure[Nmeas].objID    = catalog[0].average[Nave].objID;
     321      catalog[0].measure[Nmeas].catID    = catalog[0].catID;
     322
     323      /* set the average magnitude if not already set and the photcode.equiv is not 0 */
     324      /* in UPDATE mode, this value is not saved; use relphot to recalculate */
     325      if (Nsec > -1) {
     326        catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas], MAG_CLASS_PSF);
     327      }
     328
     329      /* next[Nmeas] should always be -1 in this context (it is always the only
     330         measurement for the star) */
     331      stars[i+j].found = Nmeas;
     332      next_meas[Nmeas] = -1;  // inital value here update below
     333      Nmeas ++;
    302334    }
    303335    for (j = 0; j < NSTAR_GROUP - 1; j++) {
    304         next_meas[Nmeas - NSTAR_GROUP + j] = Nmeas - NSTAR_GROUP + j + 1;
    305     }
     336      next_meas[Nmeas - NSTAR_GROUP + j] = Nmeas - NSTAR_GROUP + j + 1;
     337    }
     338
     339    // if we have lensing data, insert that as well
     340    if (stars[i].lensing) {
     341      catalog[0].average[Nave].Nlensing = NSTAR_GROUP;
     342      catalog[0].average[Nave].lensingOffset = Nlens;
     343      for (j = 0; j < NSTAR_GROUP; j++) {
     344        // add the lensing values if they exist
     345        if (stars[i + j].lensing) {
     346          dvo_lensing_init (&catalog[0].lensing[Nlens]);
     347          catalog[0].lensing[Nlens] = stars[i + j].lensing[0];
     348         
     349          catalog[0].lensing[Nlens].averef = Nave;
     350          catalog[0].lensing[Nlens].objID = catalog[0].average[Nave].objID;
     351          catalog[0].lensing[Nlens].catID = catalog[0].catID;
     352          next_lens[Nlens] = -1;
     353          Nlens ++;
     354        }
     355      }
     356      for (j = 0; j < NSTAR_GROUP - 1; j++) {
     357        next_lens[Nlens - NSTAR_GROUP + j] = Nlens - NSTAR_GROUP + j + 1;
     358      }
     359    }
     360
    306361    Nave ++;
    307362  }
     
    309364  REALLOCATE (catalog[0].average, Average, Nave);
    310365  REALLOCATE (catalog[0].measure, Measure, Nmeas);
     366  REALLOCATE (catalog[0].lensing, Lensing, Nlens);
    311367 
    312368  if (options.nosort) {
     
    315371    catalog[0].sorted = TRUE;
    316372    catalog[0].measure = sort_measure (catalog[0].average, Nave, catalog[0].measure, Nmeas, next_meas);
     373    catalog[0].lensing = sort_lensing (catalog[0].average, Nave, catalog[0].lensing, Nlens, next_lens);
    317374  }
    318375
     
    328385  catalog[0].Naverage = Nave;
    329386  catalog[0].Nmeasure = Nmeas;
     387  catalog[0].Nlensing = Nlens;
    330388  catalog[0].Nsecf_mem = Nave*Nsecfilt;
    331   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);
    332 
    333   free (catalog[0].found);
     389  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);
     390
    334391  free (X1);
    335392  free (Y1);
     
    339396  free (Y2);
    340397  free (next_meas);
     398  free (next_lens);
    341399
    342400  return (Nmatch);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/find_matches_closest_refstars.c

    r34361 r37067  
    3131  ALLOCATE (Y2, double, NAVE);
    3232  ALLOCATE (N2, off_t,  NAVE);
    33   ALLOCATE (catalog[0].found, off_t, NAVE);
     33  ALLOCATE (catalog[0].found_t, off_t, NAVE);
    3434  /* for secfilt j and star i, secfilt[i*Nsecfilt+j] */
    3535
     
    5959  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    6060  tcoords.Npolyterms = 0;
    61   strcpy (tcoords.ctype, "RA---ARC");
     61  strcpy (tcoords.ctype, "DEC--ARC");
    6262 
    6363  /* build spatial index (RA sort) referencing input array sequence */
     
    7171  if (Nstars < 1) {
    7272    if (VERBOSE) fprintf (stderr, "skipping %s, no overlapping stars\n", catalog[0].filename);
    73     free (catalog[0].found);
    7473    free (X1);
    7574    free (Y1);
     
    8685    RD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
    8786    N2[i] = i;
    88     catalog[0].found[N2[i]] = -1;
     87    catalog[0].found_t[N2[i]] = -1;
    8988  }
    9089  if (Nave > 1) sort_coords_index (X2, Y2, N2, Nave);
     
    180179
    181180    /** *** dR,dD now in arcsec *** **/
    182     catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N][0].average.R);
    183     catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N][0].average.D);
     181    catalog[0].measure[Nmeas].R        = stars[N][0].average.R;
     182    catalog[0].measure[Nmeas].D        = stars[N][0].average.D;
    184183    catalog[0].measure[Nmeas].dbFlags  = 0;
    185184    catalog[0].measure[Nmeas].averef   = n;
     
    187186    catalog[0].measure[Nmeas].catID    = catalog[0].catID;
    188187
     188    float dRoff = dvoOffsetR(&catalog[0].measure[Nmeas], &catalog[0].average[n]);
     189
    189190    // rationalize dR:
    190     if (catalog[0].measure[Nmeas].dR > +180.0*3600.0) {
     191    if (dRoff > +180.0*3600.0) {
    191192      // average on high end of boundary, move star up
    192       stars[N][0].average.R += 360.0;
    193       catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N][0].average.R);
    194     }
    195     if (catalog[0].measure[Nmeas].dR < -180.0*3600.0) {
     193      catalog[0].measure[Nmeas].R += 360.0;
     194      dRoff -= 360.0*3600.0;
     195    }
     196    if (dRoff < -180.0*3600.0) {
    196197      // average on low end of boundary, move star down
    197       stars[N][0].average.R -= 360.0;
    198       catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N][0].average.R);
     198      catalog[0].measure[Nmeas].R -= 360.0;
     199      dRoff += 360.0*3600.0;
    199200    }
    200201
     
    218219    /* this catalog star matches more than one image star */
    219220    // XXX should this be an average flag?
    220     if (catalog[0].found[n] > -1) {
    221       catalog[0].measure[catalog[0].found[n]].dbFlags |= ID_MEAS_BLEND_OBJ;
     221    if (catalog[0].found_t[n] > -1) {
     222      catalog[0].measure[catalog[0].found_t[n]].dbFlags |= ID_MEAS_BLEND_OBJ;
    222223      catalog[0].measure[Nmeas].dbFlags |= ID_MEAS_BLEND_OBJ;
    223224    } else {
    224       catalog[0].found[n] = Nmeas;
     225      catalog[0].found_t[n] = Nmeas;
    225226    }
    226227
     
    290291      catalog[0].measure[Nmeas]          = stars[N][0].measure;
    291292
    292       catalog[0].measure[Nmeas].dR       = 0.0; // astrometric offset, not error
    293       catalog[0].measure[Nmeas].dD       = 0.0; // astrometric offset, not error
     293      catalog[0].measure[Nmeas].R       = catalog[0].average[Nave].R;
     294      catalog[0].measure[Nmeas].D       = catalog[0].average[Nave].D;
    294295      catalog[0].measure[Nmeas].dbFlags  = 0;
    295296      catalog[0].measure[Nmeas].averef   = Nave;
     
    329330  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);
    330331
    331   free (catalog[0].found);
    332332  free (X1);
    333333  free (Y1);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/find_matches_refstars.c

    r34260 r37067  
    3737  ALLOCATE (Y2, double, NAVE);
    3838  ALLOCATE (N2, off_t,  NAVE);
    39   ALLOCATE (catalog[0].found, off_t, NAVE);
     39  ALLOCATE (catalog[0].found_t, off_t, NAVE);
    4040  REALLOCATE (catalog[0].average, Average, NAVE);
    4141  REALLOCATE (catalog[0].secfilt, SecFilt, NAVE*catalog[0].Nsecfilt);
     
    5757  tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    5858  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    59   strcpy (tcoords.ctype, "RA---ZEA");
     59  strcpy (tcoords.ctype, "DEC--ZEA");
    6060  tcoords.Npolyterms = 0;
    6161 
     
    6969    RD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
    7070    N2[i] = i;
    71     catalog[0].found[N2[i]] = -1;
     71    catalog[0].found_t[N2[i]] = -1;
    7272  }
    7373  if (Nave > 1) sort_coords_index (X2, Y2, N2, Nave);
     
    141141      catalog[0].measure[Nmeas]          = stars[N][0].measure;
    142142
    143       /** *** dR,dD now in arcsec *** **/
    144       catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N][0].average.R);
    145       catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N][0].average.D);
     143      /** measure now stores R,D **/
     144      catalog[0].measure[Nmeas].R        = stars[N][0].average.R;
     145      catalog[0].measure[Nmeas].D        = stars[N][0].average.D;
    146146      catalog[0].measure[Nmeas].dbFlags  = 0;
    147147      catalog[0].measure[Nmeas].averef   = n;
     
    149149      catalog[0].measure[Nmeas].catID    = catalog[0].catID;
    150150
     151      float dRoff = dvoOffsetR(&catalog[0].measure[Nmeas], &catalog[0].average[n]);
     152
    151153      // rationalize dR:
    152       if (catalog[0].measure[Nmeas].dR > +180.0*3600.0) {
     154      if (dRoff > +180.0*3600.0) {
    153155          // average on high end of boundary, move star up
    154           stars[N][0].average.R += 360.0;
    155           catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N][0].average.R);
    156       }
    157       if (catalog[0].measure[Nmeas].dR < -180.0*3600.0) {
     156          catalog[0].measure[Nmeas].R += 360.0;
     157          dRoff -= 360.0*3600.0;
     158      }
     159      if (dRoff < -180.0*3600.0) {
    158160          // average on low end of boundary, move star down
    159           stars[N][0].average.R -= 360.0;
    160           catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N][0].average.R);
     161          catalog[0].measure[Nmeas].R -= 360.0;
     162          dRoff += 360.0*3600.0;
    161163      }
    162164
     
    188190      }
    189191      /* this catalog star matches more than one image star */
    190       if (catalog[0].found[n] > -1) {
    191         catalog[0].measure[catalog[0].found[n]].dbFlags |= ID_MEAS_BLEND_OBJ;
     192      if (catalog[0].found_t[n] > -1) {
     193        catalog[0].measure[catalog[0].found_t[n]].dbFlags |= ID_MEAS_BLEND_OBJ;
    192194        catalog[0].measure[Nmeas].dbFlags |= ID_MEAS_BLEND_OBJ;
    193195      } else {
    194         catalog[0].found[n] = Nmeas;
     196        catalog[0].found_t[n] = Nmeas;
    195197      }
    196198
     
    262264      catalog[0].measure[Nmeas]          = stars[N][0].measure;
    263265
    264       catalog[0].measure[Nmeas].dR       = 0.0;
    265       catalog[0].measure[Nmeas].dD       = 0.0;
     266      catalog[0].measure[Nmeas].R        = stars[N][0].average.R;
     267      catalog[0].measure[Nmeas].D        = stars[N][0].average.D;
    266268
    267269      catalog[0].measure[Nmeas].t        = (stars[N][0].measure.t == 0) ? TIMEREF : stars[N][0].measure.t;      /** careful : time_t vs e_time **/
     
    303305  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeas,  Nmatch);
    304306
    305   free (catalog[0].found);
    306307  free (X1);
    307308  free (Y1);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/findskycell.c

    r34844 r37067  
    1212// in an even more specific case, RA[i,zone] = RA_origin[zone] + RA_offset[zone]
    1313
    14 enum {TREE_NONE, TREE_MAKE, TREE_USE};
     14enum {TREE_NONE, TREE_MAKE, TREE_LOCAL, TREE_USE};
     15enum {REGION_NONE, REGION_USER, REGION_MIN, REGION_MAX};
    1516
    1617void usage (void) {
    1718  fprintf (stderr, "USAGE: findcell -mktree (tree) (catdir) [-nx Nx] [-ny Ny]\n");
     19  fprintf (stderr, "USAGE: findcell -mklocal (file) (catdir) [-nx Nx] [-ny Ny]\n");
    1820  fprintf (stderr, "USAGE: findcell -tree (tree) (datafile)\n");
    1921  fprintf (stderr, "   (datafile) should contain a list of RA,DEC pairs\n");
     
    2224
    2325int mktree (char *treefile, char *catdir);
     26int mklocal (char *treefile, char *catdir);
    2427int apply_tree (char *treefile, char *datafile);
    2528
     
    2831int NY_SUB = 1;
    2932
     33double R_MIN = 0.0;
     34double R_MAX = 0.0;
     35double D_MIN = 0.0;
     36double D_MAX = 0.0;
     37int REGION_OPTION = REGION_NONE;
     38
     39char *BASENAME = NULL;
     40int projectIDoff = -1;
     41int skycellIDoff = -1;
     42
     43int APPEND = FALSE;
     44
    3045int main (int argc, char **argv) {
    3146
     
    4257  if (get_argument (argc, argv, "-h")) usage ();
    4358
    44   NX_SUB = NY_SUB = 1;
    4559  if ((N = get_argument (argc, argv, "-nx"))) {
    4660    remove_argument (N, &argc, argv);
     
    5569
    5670  /* pixel scale (arcsec/pixel) */
    57   SCALE = 1.0;
    5871  if ((N = get_argument (argc, argv, "-scale"))) {
    5972    remove_argument (N, &argc, argv);
    6073    SCALE = atof (argv[N]);
     74    remove_argument (N, &argc, argv);
     75  }
     76
     77  /* pixel scale (arcsec/pixel) */
     78  if ((N = get_argument (argc, argv, "-append"))) {
     79    remove_argument (N, &argc, argv);
     80    APPEND = TRUE;
     81  }
     82
     83  // user-specified region
     84  R_MIN = NAN;
     85  R_MAX = NAN;
     86  D_MIN = NAN;
     87  D_MAX = NAN;
     88  if ((N = get_argument (argc, argv, "-region"))) {
     89    remove_argument (N, &argc, argv);
     90    if (N > argc - 4) {
     91      fprintf (stderr, "USAGE: -region requires 4 arguments (Rmin Rmax Dmin Dmax)\n");
     92      exit (1);
     93    }
     94    R_MIN = atof (argv[N]); remove_argument (N, &argc, argv);
     95    R_MAX = atof (argv[N]); remove_argument (N, &argc, argv);
     96    D_MIN = atof (argv[N]); remove_argument (N, &argc, argv);
     97    D_MAX = atof (argv[N]); remove_argument (N, &argc, argv);
     98    REGION_OPTION = REGION_USER;
     99  }
     100
     101  if ((N = get_argument (argc, argv, "-region-min"))) {
     102    remove_argument (N, &argc, argv);
     103    REGION_OPTION = REGION_MIN;
     104  }
     105
     106  if ((N = get_argument (argc, argv, "-region-max"))) {
     107    remove_argument (N, &argc, argv);
     108    REGION_OPTION = REGION_MAX;
     109  }
     110
     111  if ((N = get_argument (argc, argv, "-basename"))) {
     112    remove_argument (N, &argc, argv);
     113    if (N > argc - 3) {
     114      fprintf (stderr, "USAGE: -basename (name) (proj_offset) (skycell_offset)\n");
     115      exit (1);
     116    }
     117    BASENAME = strcreate  (argv[N]);
     118    remove_argument (N, &argc, argv);
     119    projectIDoff = atoi(argv[N]);
     120    remove_argument (N, &argc, argv);
     121    skycellIDoff = atoi(argv[N]);
    61122    remove_argument (N, &argc, argv);
    62123  }
     
    70131    remove_argument (N, &argc, argv);
    71132  }
     133  if ((N = get_argument (argc, argv, "-mklocal"))) {
     134    MODE = TREE_LOCAL;
     135    remove_argument (N, &argc, argv);
     136    treefile = strcreate (argv[N]);
     137    remove_argument (N, &argc, argv);
     138  }
    72139  if ((N = get_argument (argc, argv, "-tree"))) {
    73140    MODE = TREE_USE;
     
    86153  }
    87154
     155  if (MODE == TREE_LOCAL) {
     156    mklocal (treefile, argv[1]);
     157    exit (0);
     158  }
     159
    88160  apply_tree (treefile, argv[1]);
    89161  exit (0);
    90162}
    91 
    92 # define MARKTIME(MSG,...) {                    \
    93     float dtime;                                \
    94     gettimeofday (&stop, (void *) NULL);        \
    95     dtime = DTIME (stop, start);                \
    96     fprintf (stderr, MSG, __VA_ARGS__); }
    97163
    98164int mktree (char *treefile, char *catdir) {
     
    330396  }
    331397
    332   struct timeval start, stop;
    333   gettimeofday (&start, (void *) NULL);
     398  INITTIME;
    334399
    335400  int Npts = 10000000;
     
    348413  MARKTIME("-- test %d pts: %f sec\n", Npts, dtime);
    349414
    350   BoundaryTreeSave (treefile, &tree);
     415  if (APPEND) {
     416    int Ntess = 0;
     417    TessellationTable *tess = TessellationTableLoad (treefile, &Ntess);
     418    REALLOCATE (tess, TessellationTable, Ntess + 1);
     419    TessellationTableInit (&tess[Ntess], 1);
     420    tess[Ntess].tree = &tree;
     421    tess[Ntess].type = TESS_RINGS;
     422    tess[Ntess].Rmin =   0;
     423    tess[Ntess].Rmax = 360;
     424    tess[Ntess].Dmin = -90;
     425    tess[Ntess].Dmax = +90;
     426
     427    if (BASENAME) {
     428      tess[Ntess].Nbasename = strlen(BASENAME);
     429      tess[Ntess].basename = strcreate(BASENAME);
     430      tess[Ntess].projectIDoff = projectIDoff;
     431      tess[Ntess].skycellIDoff = skycellIDoff;
     432    }
     433     
     434    // add basename an related here...
     435    Ntess ++;
     436    TessellationTableSave (treefile, tess, Ntess);
     437  } else {
     438    BoundaryTreeSave (treefile, &tree);
     439  }
    351440
    352441  return TRUE;
     
    354443
    355444int apply_tree (char *treefile, char *datafile) {
     445
     446  int Ntess = 0;
     447  TessellationTable *tess = TessellationTableLoad (treefile, &Ntess);
     448  if (!tess) {
     449    fprintf (stderr, "error loading tessellation table file %s\n", treefile);
     450    exit (2);
     451  }
     452
     453  FILE *f = fopen (datafile, "r");
     454  if (!f) {
     455    fprintf (stderr, "error opening data file %s\n", datafile);
     456    exit (3);
     457  }
     458
     459  double ra, dec;
     460  int Nvalue = 0;
     461  while ((Nvalue = fscanf (f, "%lf %lf", &ra, &dec)) != EOF) {
     462
     463    int tessID, projID, skycellID;
     464
     465    if (!TessellationPrimaryCellIDs (tess, Ntess, &tessID, &projID, &skycellID, ra, dec)) {
     466      fprintf (stderr, "error finding cell for %f,%f\n", ra, dec);
     467      continue;
     468    }
     469
     470    fprintf (stdout, "%10.6f %10.6f : %2d  %04d %03d : %s\n", ra, dec, tessID, projID, skycellID, tess[tessID].basename);
     471  }
     472
     473  exit (0);
     474}
     475
     476int apply_tree_old (char *treefile, char *datafile) {
    356477
    357478  BoundaryTree *tree = BoundaryTreeLoad (treefile);
     
    405526}
    406527
     528// a given tess is defined by a catdir (more than one per catdir?)
     529// this function takes a catdir and generates an extension for a tess file for a local tess.
     530
     531/*
     532
     533  LOCAL projections are defined by single projection cells.  should I be supplying the info on
     534  the cmd line or figure out the bounds from the catdir? 
     535
     536 */
     537
     538int mklocal (char *treefile, char *catdir) {
     539
     540  int i, j, status;
     541  FITS_DB db;
     542  Image *image;
     543  off_t Nimage;
     544  double x, y, ra, dec;
     545
     546  if (REGION_OPTION == REGION_NONE) {
     547    fprintf (stderr, "ERROR: need to define bounding region (-region Rmin Rmax Dmin Dmax | -region-min | -region-max)\n");
     548    exit (2);
     549  }
     550
     551  if (!BASENAME) {
     552    fprintf (stderr, "ERROR: need to define BASENAME -basename (name) (proj_offset) (skycell_offset)\n");
     553    exit (2);
     554  }
     555
     556  char imagefile[DVO_MAX_PATH];
     557  snprintf (imagefile, DVO_MAX_PATH, "%s/Images.dat", catdir);
     558
     559  status = dvo_image_lock (&db, imagefile, 2.0, LCK_XCLD);
     560  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
     561
     562  /* load or create the image table */
     563  if (db.dbstate == LCK_EMPTY) Shutdown ("can't read image catalog %s", db.filename);
     564
     565  if (!dvo_image_load (&db, TRUE, FALSE)) Shutdown ("can't read image catalog %s", db.filename);
     566
     567  // convert database table to internal structure (binary to Image)
     568  // 'image' points to the same memory as db->ftable->buffer
     569  image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
     570  if (!image) {
     571    fprintf (stderr, "ERROR: failed to read images\n");
     572    exit (2);
     573  }
     574 
     575  // generate an empty BoundaryTree
     576  TessellationTable *tess = NULL;
     577
     578  int NtessDisk = 0;
     579  if (APPEND) {
     580    tess = TessellationTableLoad (treefile, &NtessDisk);
     581    REALLOCATE (tess, TessellationTable, Nimage + NtessDisk);
     582  } else {
     583    ALLOCATE (tess, TessellationTable, Nimage + NtessDisk);
     584  }
     585
     586  TessellationTableInit (&tess[NtessDisk], Nimage);
     587
     588  // find the RA,DEC of the image centers & assign to cells
     589  int Ntess = NtessDisk;
     590  for (i = 0; i < Nimage; i++) {
     591    // user supplied values, do not try to derive from Image.dat
     592    tess[Ntess].NX_SUB = NX_SUB;
     593    tess[Ntess].NY_SUB = NY_SUB;
     594    tess[Ntess].dPix = SCALE/3600.0;
     595
     596    x = 0.5*image[i].NX;
     597    y = 0.5*image[i].NY;
     598    XY_to_RD (&ra, &dec, x, y, &image[i].coords);
     599
     600    tess[Ntess].Ro  = ra;
     601    tess[Ntess].Do  = dec;
     602    tess[Ntess].Xo  = x;
     603    tess[Ntess].Yo  = y;
     604    tess[Ntess].dX  = image[i].NX / NX_SUB;
     605    tess[Ntess].dY  = image[i].NY / NY_SUB;
     606
     607    // find the minimum or maximum containing region
     608    if ((REGION_OPTION == REGION_MIN) || (REGION_OPTION == REGION_MAX)) {
     609      // XXX short cut for now : if the projection cell bounds the equator or 0,360 boundary, this will fail:
     610      double R[4], D[4];
     611      XY_to_RD (&R[0], &D[0],           0,           0, &image[i].coords);
     612      XY_to_RD (&R[1], &D[1], image[i].NX,           0, &image[i].coords);
     613      XY_to_RD (&R[2], &D[2],           0, image[i].NY, &image[i].coords);
     614      XY_to_RD (&R[3], &D[3], image[i].NX, image[i].NY, &image[i].coords);
     615
     616      if (REGION_OPTION == REGION_MIN) {
     617        for (j = 0; j < 4; j++) {
     618          R_MIN = (R[j] < ra)  ? (isfinite(R_MIN) ? MAX(R_MIN, R[j]) : R[j]) : R_MIN;
     619          R_MAX = (R[j] > ra)  ? (isfinite(R_MAX) ? MIN(R_MAX, R[j]) : R[j]) : R_MAX;
     620          D_MIN = (D[j] < dec) ? (isfinite(D_MIN) ? MAX(D_MIN, D[j]) : D[j]) : D_MIN;
     621          D_MAX = (D[j] > dec) ? (isfinite(D_MAX) ? MIN(D_MAX, D[j]) : D[j]) : D_MAX;
     622        }
     623      } else {
     624        for (j = 0; j < 4; j++) {
     625          R_MIN = (R[j] < ra)  ? (isfinite(R_MIN) ? MIN(R_MIN, R[j]) : R[j]) : R_MIN;
     626          R_MAX = (R[j] > ra)  ? (isfinite(R_MAX) ? MAX(R_MAX, R[j]) : R[j]) : R_MAX;
     627          D_MIN = (D[j] < dec) ? (isfinite(D_MIN) ? MIN(D_MIN, D[j]) : D[j]) : D_MIN;
     628          D_MAX = (D[j] > dec) ? (isfinite(D_MAX) ? MAX(D_MAX, D[j]) : D[j]) : D_MAX;
     629        }
     630      }
     631    }
     632    tess[Ntess].Rmin = R_MIN;
     633    tess[Ntess].Rmax = R_MAX;
     634    tess[Ntess].Dmin = D_MIN;
     635    tess[Ntess].Dmax = D_MAX;
     636
     637    tess[Ntess].type = TESS_LOCAL;
     638
     639    // XXX I don't really want to do the work of discovering the rule...
     640    tess[Ntess].Nbasename = strlen(BASENAME);
     641    tess[Ntess].basename = strcreate(BASENAME);
     642
     643    tess[Ntess].projectIDoff = projectIDoff;
     644    tess[Ntess].skycellIDoff = skycellIDoff;
     645
     646    Ntess ++;
     647  }
     648
     649  TessellationTableSave (treefile, tess, Ntess);
     650
     651  return TRUE;
     652}
     653
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/load2mass_catalog.c

    r35416 r37067  
    1717  for (i = 0; i < Nstars; i+=3) {
    1818
     19    double R = stars[i].average.R;
     20    double D = stars[i].average.D;
     21
    1922    // construct an average object for this object
    2023    // XXX for now, the output objects will have limited astrometric interpretation...
    2124    // XXX every 3 stars represents 3 measurements and 1 average
    2225    dvo_average_init (&catalog[0].average[Nave]);
    23     catalog[0].average[Nave].R     = stars[i].average.R;
    24     catalog[0].average[Nave].D     = stars[i].average.D;
     26    catalog[0].average[Nave].R     = R;
     27    catalog[0].average[Nave].D     = D;
    2528    catalog[0].average[Nave].measureOffset = Nmeas;
    2629
     
    3336      catalog[0].measure[Nmeas]           = stars[i+j].measure;
    3437
    35       catalog[0].measure[Nmeas].dR        = 0.0;
    36       catalog[0].measure[Nmeas].dD        = 0.0;
     38      catalog[0].measure[Nmeas].R         = R;
     39      catalog[0].measure[Nmeas].D         = D;
    3740      catalog[0].measure[Nmeas].dt        = NAN_S_SHORT;
    3841
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/loadsupercos_ops.c

    r33653 r37067  
    11# include "addstar.h"
    22# include "supercos.h"
    3 
    4 // this is defined in libohana/src/string.c but not generally exposed
    5 char *_parse_nextword_csv (char *string);
    63
    74int loadsupercos_getFilterInfo (char *line, char *emulsion, char *filterID) {
     
    1310  // emulsion is field 11, filterID is field 12
    1411  for (i = 1; i < 11; i++) {
    15     p1 = _parse_nextword_csv (p1);
     12    p1 = parse_nextword_csv (p1);
    1613    if (!p1) {
    1714      fprintf (stderr, "error parsing filter info for line %s\n", line);
     
    2421  }
    2522
    26   char *p2 = _parse_nextword_csv (p1);
     23  char *p2 = parse_nextword_csv (p1);
    2724  if (!p2) {
    2825    fprintf (stderr, "error parsing filter info for line %s\n", line);
     
    3431  }
    3532
    36   char *p3 = _parse_nextword_csv (p2);
     33  char *p3 = parse_nextword_csv (p2);
    3734  if (!p3) {
    3835    fprintf (stderr, "error parsing filter info for line %s\n", line);
     
    6057  // lstObs is field 20
    6158  for (i = 1; i < 20; i++) {
    62     p1 = _parse_nextword_csv (p1);
     59    p1 = parse_nextword_csv (p1);
    6360    if (!p1) {
    6461      fprintf (stderr, "error parsing filter info for line %s\n", line);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/loadsupercos_plates.c

    r33653 r37067  
    118118
    119119    // for now, we define a fake coordinate system based on the boresite center
    120     strcpy (image[Nimage].coords.ctype, "RA---TAN");
     120    strcpy (image[Nimage].coords.ctype, "DEC--TAN");
    121121   
    122122    image[Nimage].coords.crval1 = RAo;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/mkcmf.c

    r35760 r37067  
    11# include "mkcmf.h"
    22
     3# define ZERO_POINT 25.0
    34# define SKY 100.0
    45# define DSKY 2.0
     
    1415void gauss_init (int Nbin);
    1516double rnd_gauss (double mean, double sigma);
     17void writeStars_PS1_V5_Lensing (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars);
     18void writeStars_PS1_V5 (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars);
    1619void writeStars_PS1_V4 (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars);
    1720void writeStars_PS1_V3 (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars);
    1821void writeStars_PS1_V2 (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars);
    1922void writeStars_PS1_V1 (FTable *ftable, double *X, double *Y, double *M, int Nstars);
     23void writeStars_PS1_SV3 (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars);
    2024void writeStars_PS1_DEV_1 (FTable *ftable, double *X, double *Y, double *M, int Nstars);
    2125void writeStars_PS1_DEV_0 (FTable *ftable, double *X, double *Y, double *M, int Nstars);
     
    2327int ADDNOISE = TRUE;
    2428float BAD_PSFQF_FRAC = 0.0;
     29
     30static float exptime = 1.0;
     31static Coords coords;
    2532
    2633int main (int argc, char **argv) {
     
    3845  Matrix matrix;
    3946  FTable ftable;
    40   Coords coords;
    4147
    4248  int APPEND = FALSE;
     
    105111  }
    106112
    107   float exptime = 1.0;
    108113  if ((N = get_argument (argc, argv, "-exptime"))) {
    109114    remove_argument (N, &argc, argv);
     
    288293    gfits_modify (&header, "UTC-OBS",  "%s", 1, time);
    289294  }
    290   gfits_modify (&header, "ZERO_PT", "%lf", 1, 25.0);
     295  gfits_modify (&header, "ZERO_PT", "%lf", 1, ZERO_POINT);
    291296  gfits_modify (&header, "EXPTIME", "%lf", 1, exptime);
    292297  gfits_modify (&header, "AIRMASS", "%lf", 1, airmass);
     
    327332  if (!strcmp(type, "PS1_V4")) {
    328333    writeStars_PS1_V4 (&ftable, X, Y, M, Flag, Nstars);
     334    found = TRUE;
     335  }
     336  if (!strcmp(type, "PS1_V5")) {
     337    writeStars_PS1_V5 (&ftable, X, Y, M, Flag, Nstars);
     338    found = TRUE;
     339  }
     340  if (!strcmp(type, "PS1_V5_Lensing")) {
     341    writeStars_PS1_V5_Lensing (&ftable, X, Y, M, Flag, Nstars);
     342    found = TRUE;
     343  }
     344  if (!strcmp(type, "PS1_SV3")) {
     345    writeStars_PS1_SV3 (&ftable, X, Y, M, Flag, Nstars);
    329346    found = TRUE;
    330347  }
     
    764781}
    765782
     783void writeStars_PS1_V5 (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars) {
     784
     785  int i;
     786  CMF_PS1_V5 *stars;
     787  float flux, fSN;
     788
     789  // XXX add gaussian-distributed noise based on counts
     790  // this needs to make different output 'stars' entries depending on the desired type
     791  ALLOCATE (stars, CMF_PS1_V5, Nstars);
     792  for (i = 0; i < Nstars; i++) {
     793
     794    flux = pow (10.0, -0.4*M[i]);
     795    fSN = 1.0 / sqrt(flux);
     796
     797    stars[i].detID = i;
     798    stars[i].X = X[i];
     799    stars[i].Y = Y[i];
     800    stars[i].dX = FX * fSN;
     801    stars[i].dY = FY * fSN;
     802
     803    stars[i].posangle = 10.0;
     804    stars[i].pltscale = 0.25;
     805
     806    stars[i].M = M[i];
     807    stars[i].dM = fSN;
     808
     809    stars[i].Flux = flux;
     810    stars[i].dFlux = flux * fSN;
     811
     812    stars[i].Map = M[i] - 0.05;
     813    stars[i].MapRaw = M[i] - 0.10;
     814
     815    stars[i].apRadius = 8.0;
     816
     817    stars[i].apFlux = pow(10.0, -0.4*stars[i].Map);
     818    stars[i].apFluxErr = stars[i].apFlux * fSN;
     819
     820    stars[i].Mcalib = M[i] + ZERO_POINT + 2.5*log10(exptime);
     821    stars[i].dMcal = 0.05;
     822
     823    XY_to_RD (&stars[i].RA, &stars[i].DEC, X[i], Y[i], &coords);
     824    stars[i].apNpix = 3.14*8.0*8.0;
     825
     826    stars[i].Mpeak     = M[i] + 1.0;
     827    stars[i].sky       = SKY;
     828    stars[i].dSky      = DSKY;
     829    stars[i].psfChisq  = PSFCHI;
     830    stars[i].crNsigma  = CRN;
     831    stars[i].extNsigma = EXTN;
     832    stars[i].fx        = FX;
     833    stars[i].fy        = FY;
     834    stars[i].df        = DF;
     835
     836    stars[i].k         = 1.0;
     837    stars[i].fwhmMaj   = FX*2.8;
     838    stars[i].fwhmMin   = FY*2.8;
     839
     840    // randomly give poor PSFQF values
     841    if ((BAD_PSFQF_FRAC > 0.0) && (drand48() < BAD_PSFQF_FRAC)) {
     842      stars[i].psfQF     = 0.25;
     843      stars[i].psfQFperf = 0.24;
     844    } else {
     845      stars[i].psfQF     = PSFQUAL;
     846      stars[i].psfQFperf = MAX(PSFQUAL - 0.01, 0.0);
     847    }
     848
     849    stars[i].psfNdof   = 1;
     850    stars[i].psfNpix   = 2;
     851
     852    stars[i].Mxx       = FX;
     853    stars[i].Mxy       = 0.01;
     854    stars[i].Myy       = FX;
     855    stars[i].M3c       = FX;
     856    stars[i].M3s       = FX;
     857    stars[i].M4c       = FX;
     858    stars[i].M4s       = FX;
     859    stars[i].Mr1       = FX;
     860    stars[i].Mrh       = FX;
     861
     862    stars[i].kronFlux  = flux * 1.25;
     863    stars[i].kronFluxErr = fSN * flux * 1.25;
     864
     865    stars[i].kronInner = fSN * flux * 0.9;
     866    stars[i].kronOuter = fSN * flux * 1.5;
     867
     868    stars[i].skyLimitRad = 1;
     869    stars[i].skyLimitFlux = 2;
     870    stars[i].skyLimitSlope = 0.2;
     871
     872    stars[i].flags     = Flag[i];
     873    stars[i].flags2    = 0x80;
     874
     875    stars[i].nFrames   = 1;
     876
     877    if (ADDNOISE) {
     878      stars[i].X += FX * fSN * rnd_gauss(0.0, 1.0);
     879      stars[i].Y += FY * fSN * rnd_gauss(0.0, 1.0);
     880      float Moff = fSN*rnd_gauss(0.0, 1.0);
     881      stars[i].M += Moff;
     882      stars[i].Map += Moff;
     883      stars[i].MapRaw += Moff;
     884      stars[i].Mcalib += Moff;
     885    }
     886  }
     887
     888  gfits_table_set_CMF_PS1_V5 (ftable, stars, Nstars);
     889  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_V5");
     890}
     891
     892void writeStars_PS1_SV3 (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars) {
     893
     894  int i;
     895  CMF_PS1_SV3 *stars;
     896  float flux, fSN;
     897
     898  // XXX add gaussian-distributed noise based on counts
     899  // this needs to make different output 'stars' entries depending on the desired type
     900  ALLOCATE (stars, CMF_PS1_SV3, Nstars);
     901  for (i = 0; i < Nstars; i++) {
     902
     903    flux = pow (10.0, -0.4*M[i]);
     904    fSN = 1.0 / sqrt(flux);
     905
     906    stars[i].detID = i;
     907    stars[i].X = X[i];
     908    stars[i].Y = Y[i];
     909    stars[i].dX = FX * fSN;
     910    stars[i].dY = FY * fSN;
     911
     912    stars[i].posangle = 10.0;
     913    stars[i].pltscale = 0.25;
     914
     915    stars[i].M = M[i];
     916    stars[i].dM = fSN;
     917
     918    stars[i].Flux = flux;
     919    stars[i].dFlux = flux * fSN;
     920
     921    stars[i].Map = M[i] - 0.05;
     922    stars[i].MapRaw = M[i] - 0.10;
     923
     924    stars[i].apRadius = 8.0;
     925
     926    stars[i].apFlux = pow(10.0, -0.4*stars[i].Map);
     927    stars[i].apFluxErr = stars[i].apFlux * fSN;
     928
     929    stars[i].Mcalib = M[i] + ZERO_POINT + 2.5*log10(exptime);
     930    stars[i].dMcal = 0.05;
     931
     932    XY_to_RD (&stars[i].RA, &stars[i].DEC, X[i], Y[i], &coords);
     933    stars[i].apNpix = 3.14*8.0*8.0;
     934
     935    stars[i].Mpeak     = M[i] + 1.0;
     936    stars[i].sky       = SKY;
     937    stars[i].dSky      = DSKY;
     938    stars[i].psfChisq  = PSFCHI;
     939    stars[i].crNsigma  = CRN;
     940    stars[i].extNsigma = EXTN;
     941    stars[i].fx        = FX;
     942    stars[i].fy        = FY;
     943    stars[i].df        = DF;
     944
     945    stars[i].k         = 1.0;
     946    stars[i].fwhmMaj   = FX*2.8;
     947    stars[i].fwhmMin   = FY*2.8;
     948
     949    // randomly give poor PSFQF values
     950    if ((BAD_PSFQF_FRAC > 0.0) && (drand48() < BAD_PSFQF_FRAC)) {
     951      stars[i].psfQF     = 0.25;
     952      stars[i].psfQFperf = 0.24;
     953    } else {
     954      stars[i].psfQF     = PSFQUAL;
     955      stars[i].psfQFperf = MAX(PSFQUAL - 0.01, 0.0);
     956    }
     957
     958    stars[i].psfNdof   = 1;
     959    stars[i].psfNpix   = 2;
     960
     961    stars[i].Mxx       = FX;
     962    stars[i].Mxy       = 0.01;
     963    stars[i].Myy       = FX;
     964    stars[i].M3c       = FX;
     965    stars[i].M3s       = FX;
     966    stars[i].M4c       = FX;
     967    stars[i].M4s       = FX;
     968    stars[i].Mr1       = FX;
     969    stars[i].Mrh       = FX;
     970
     971    stars[i].kronFlux  = flux * 1.25;
     972    stars[i].kronFluxErr = fSN * flux * 1.25;
     973
     974    stars[i].kronInner = fSN * flux * 0.9;
     975    stars[i].kronOuter = fSN * flux * 1.5;
     976
     977    // stars[i].skyLimitRad = 1;
     978    // stars[i].skyLimitFlux = 2;
     979    // stars[i].skyLimitSlope = 0.2;
     980
     981    stars[i].flags     = Flag[i];
     982    stars[i].flags2    = 0x80;
     983
     984    stars[i].nFrames   = 1;
     985
     986    if (ADDNOISE) {
     987      stars[i].X += FX * fSN * rnd_gauss(0.0, 1.0);
     988      stars[i].Y += FY * fSN * rnd_gauss(0.0, 1.0);
     989      float Moff = fSN*rnd_gauss(0.0, 1.0);
     990      stars[i].M += Moff;
     991      stars[i].Map += Moff;
     992      stars[i].MapRaw += Moff;
     993      stars[i].Mcalib += Moff;
     994    }
     995  }
     996
     997  gfits_table_set_CMF_PS1_SV3 (ftable, stars, Nstars);
     998  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_SV3");
     999}
     1000
     1001void writeStars_PS1_V5_Lensing (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars) {
     1002
     1003  int i;
     1004  CMF_PS1_V5_Lensing *stars;
     1005  float flux, fSN;
     1006
     1007  // XXX add gaussian-distributed noise based on counts
     1008  // this needs to make different output 'stars' entries depending on the desired type
     1009  ALLOCATE (stars, CMF_PS1_V5_Lensing, Nstars);
     1010  for (i = 0; i < Nstars; i++) {
     1011
     1012    flux = pow (10.0, -0.4*M[i]);
     1013    fSN = 1.0 / sqrt(flux);
     1014
     1015    stars[i].detID = i;
     1016    stars[i].X = X[i];
     1017    stars[i].Y = Y[i];
     1018    stars[i].dX = FX * fSN;
     1019    stars[i].dY = FY * fSN;
     1020
     1021    stars[i].posangle = 10.0;
     1022    stars[i].pltscale = 0.25;
     1023
     1024    stars[i].M = M[i];
     1025    stars[i].dM = fSN;
     1026
     1027    stars[i].Flux = flux;
     1028    stars[i].dFlux = flux * fSN;
     1029
     1030    stars[i].Map = M[i] - 0.05;
     1031    stars[i].MapRaw = M[i] - 0.10;
     1032
     1033    stars[i].apRadius = 8.0;
     1034
     1035    stars[i].apFlux = pow(10.0, -0.4*stars[i].Map);
     1036    stars[i].apFluxErr = stars[i].apFlux * fSN;
     1037
     1038    stars[i].Mcalib = M[i] + ZERO_POINT + 2.5*log10(exptime);
     1039    stars[i].dMcal = 0.05;
     1040
     1041    XY_to_RD (&stars[i].RA, &stars[i].DEC, X[i], Y[i], &coords);
     1042    stars[i].apNpix = 3.14*8.0*8.0;
     1043
     1044    stars[i].Mpeak     = M[i] + 1.0;
     1045    stars[i].sky       = SKY;
     1046    stars[i].dSky      = DSKY;
     1047    stars[i].psfChisq  = PSFCHI;
     1048    stars[i].crNsigma  = CRN;
     1049    stars[i].extNsigma = EXTN;
     1050    stars[i].fx        = FX;
     1051    stars[i].fy        = FY;
     1052    stars[i].df        = DF;
     1053
     1054    stars[i].k         = 1.0;
     1055    stars[i].fwhmMaj   = FX*2.8;
     1056    stars[i].fwhmMin   = FY*2.8;
     1057
     1058    // randomly give poor PSFQF values
     1059    if ((BAD_PSFQF_FRAC > 0.0) && (drand48() < BAD_PSFQF_FRAC)) {
     1060      stars[i].psfQF     = 0.25;
     1061      stars[i].psfQFperf = 0.24;
     1062    } else {
     1063      stars[i].psfQF     = PSFQUAL;
     1064      stars[i].psfQFperf = MAX(PSFQUAL - 0.01, 0.0);
     1065    }
     1066
     1067    stars[i].psfNdof   = 1;
     1068    stars[i].psfNpix   = 2;
     1069
     1070    stars[i].Mxx       = FX;
     1071    stars[i].Mxy       = 0.01;
     1072    stars[i].Myy       = FX;
     1073    stars[i].M3c       = FX;
     1074    stars[i].M3s       = FX;
     1075    stars[i].M4c       = FX;
     1076    stars[i].M4s       = FX;
     1077    stars[i].Mr1       = FX;
     1078    stars[i].Mrh       = FX;
     1079
     1080    stars[i].X11_sm_obj = FX;
     1081    stars[i].X12_sm_obj = FX;
     1082    stars[i].X22_sm_obj = FY;
     1083    stars[i].E1_sm_obj  = FX;
     1084    stars[i].E2_sm_obj  = FX;
     1085
     1086    stars[i].X11_sh_obj = FX;
     1087    stars[i].X12_sh_obj = 0.2;
     1088    stars[i].X22_sh_obj = FY;
     1089    stars[i].E1_sh_obj  = FX*0.9;
     1090    stars[i].E2_sh_obj  = FX*0.8;
     1091
     1092    stars[i].X11_sm_psf = FX;
     1093    stars[i].X12_sm_psf = FX;
     1094    stars[i].X22_sm_psf = FX;
     1095    stars[i].E1_sm_psf  = FX;
     1096    stars[i].E2_sm_psf  = FX;
     1097
     1098    stars[i].X11_sh_psf = FX;
     1099    stars[i].X12_sh_psf = FX;
     1100    stars[i].X22_sh_psf = FX;
     1101    stars[i].E1_sh_psf  = FX;
     1102    stars[i].E2_sh_psf  = FX;
     1103
     1104    stars[i].kronFlux  = flux * 1.25;
     1105    stars[i].kronFluxErr = fSN * flux * 1.25;
     1106
     1107    stars[i].kronInner = fSN * flux * 0.9;
     1108    stars[i].kronOuter = fSN * flux * 1.5;
     1109
     1110    stars[i].skyLimitRad = 1;
     1111    stars[i].skyLimitFlux = 2;
     1112    stars[i].skyLimitSlope = 0.2;
     1113
     1114    stars[i].flags     = Flag[i];
     1115    stars[i].flags2    = 0x80;
     1116
     1117    stars[i].nFrames   = 1;
     1118
     1119    if (ADDNOISE) {
     1120      stars[i].X += FX * fSN * rnd_gauss(0.0, 1.0);
     1121      stars[i].Y += FY * fSN * rnd_gauss(0.0, 1.0);
     1122      float Moff = fSN*rnd_gauss(0.0, 1.0);
     1123      stars[i].M += Moff;
     1124      stars[i].Map += Moff;
     1125      stars[i].MapRaw += Moff;
     1126      stars[i].Mcalib += Moff;
     1127    }
     1128  }
     1129
     1130  gfits_table_set_CMF_PS1_V5_Lensing (ftable, stars, Nstars);
     1131  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_V5");
     1132}
     1133
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/replace_match.c

    r26278 r37067  
    1212    j = i + m;
    1313    if (measure[j].photcode != star[0].measure.photcode) continue;
    14     measure[j].dR = 3600.0*(average[0].R - star[0].average.R);
    15     measure[j].dD = 3600.0*(average[0].D - star[0].average.D);
     14    measure[j].R = star[0].average.R;
     15    measure[j].D = star[0].average.D;
    1616    measure[j].M  = star[0].measure.M;
    1717    measure[j].dM = star[0].measure.dM;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/resort_catalog.c

    r35760 r37067  
    11# include "addstar.h"
     2
     3void SortAveMatch (off_t *MEAS, off_t *AVE, off_t N);
     4void resort_catalog_measure (Catalog *catalog);
     5void resort_catalog_lensing (Catalog *catalog);
    26
    37void resort_catalog_old (Catalog *catalog) {
     
    59  off_t *next_meas;
    610  off_t Naves, Nmeas;
    7   double dtime;
    8   struct timeval start, stop;
    911
    1012  if (catalog[0].sorted == TRUE) return;
    1113
    12   gettimeofday (&start, NULL);
     14  INITTIME;
    1315
    1416  /* internal counters */
     
    2224  catalog[0].measure = sort_measure (catalog[0].average, Naves, catalog[0].measure, Nmeas, next_meas);
    2325
    24   gettimeofday (&stop, NULL);
    25   dtime = DTIME (stop, start);
    26   fprintf (stderr, "  match time %9.4f sec for %7lld measures, %6lld average\n", dtime, (long long) Nmeas, (long long) Naves);
     26  MARKTIME ("  match time %9.4f sec for %7lld measures, %6lld average\n", dtime, (long long) Nmeas, (long long) Naves);
    2727
    2828  return;
    2929}
    3030
    31 // sort the measure Sequence based on the average Sequence entries
    32 void SortAveMeasMatch (off_t *MEAS, off_t *AVE, off_t N) {
    33 
    34 # define SWAPFUNC(A,B){ off_t tmp_meas; off_t tmp_ave;          \
    35     tmp_meas = MEAS[A]; MEAS[A] = MEAS[B]; MEAS[B] = tmp_meas;  \
    36     tmp_ave  = AVE[A];  AVE[A]  = AVE[B];  AVE[B]  = tmp_ave;   \
    37   }
    38 # define COMPARE(A,B)(AVE[A] < AVE[B])
    39   OHANA_SORT (N, COMPARE, SWAPFUNC);
    40 # undef SWAPFUNC
    41 # undef COMPARE
    42 }
    43 
    44 # define MARKTIME(MSG,...) {                    \
    45     float dtime;                                \
    46     gettimeofday (&stop, (void *) NULL);        \
    47     dtime = DTIME (stop, start); start = stop;  \
    48     fprintf (stderr, MSG, __VA_ARGS__); }
    49 
    50 // XXX : where is the time going?  perhaps the ALLOCATE?
    51 // XXX : I don't thnk his is getting the right answer yet.
    52 
    5331void resort_catalog (Catalog *catalog) {
     32
     33  if (catalog[0].sorted == TRUE) return;
     34
     35  resort_catalog_measure (catalog);
     36  resort_catalog_lensing (catalog);
     37}
     38
     39void resort_catalog_measure (Catalog *catalog) {
    5440
    5541  off_t Naverage, Nmeasure;
     
    6248  Measure *measureTMP = NULL;
    6349
    64   if (catalog[0].sorted == TRUE) return;
    65 
    6650  // struct timeval start, stop;
    6751  // gettimeofday (&start, NULL);
     
    7054  Nmeasure = catalog[0].Nmeasure;
    7155  Naverage = catalog[0].Naverage;
     56
     57  if (!Nmeasure) return;
    7258
    7359  measure = catalog[0].measure;
     
    11399  // fprintf (stderr, "\n");
    114100
    115   SortAveMeasMatch(measureSeq, averageSeq, Nmeasure);
     101  SortAveMatch(measureSeq, averageSeq, Nmeasure);
    116102  // MARKTIME("sort : %f sec\n", dtime);
    117103
     
    188174}
    189175
     176void resort_catalog_lensing (Catalog *catalog) {
     177
     178  off_t Naverage, Nlensing;
     179  Lensing *lensing;
     180  Average *average;
     181  off_t i, j, N, currentAve;
     182
     183  off_t *lensingSeq = NULL;
     184  off_t *averageSeq = NULL;
     185  Lensing *lensingTMP = NULL;
     186
     187  // struct timeval start, stop;
     188  // gettimeofday (&start, NULL);
     189
     190  /* internal counters */
     191  Nlensing = catalog[0].Nlensing;
     192  Naverage = catalog[0].Naverage;
     193
     194  if (!Nlensing) return;
     195
     196  lensing = catalog[0].lensing;
     197  average = catalog[0].average;
     198 
     199  // we have a table of average objects and an unsorted table of measurements.  each measurement
     200  // has a reference to the average object sequence (as well as an ID)
     201  // lensing[i].averef -> average[averef]
     202  // lensing[i].objID = average[averef].objID
     203  // lensing[i].catID = average[averef].catID
     204
     205  // we want a sorted lensing array with all averef entries in sequence
     206
     207  ALLOCATE (lensingSeq, off_t,   Nlensing);
     208  ALLOCATE (averageSeq, off_t,   Nlensing);
     209
     210  for (i = 0; i < Nlensing; i++) {
     211    lensingSeq[i] = i;
     212    averageSeq[i] = lensing[i].averef;
     213   
     214    if (catalog[0].catformat >= DVO_FORMAT_PS1_V1) {
     215      // earlier formats did not carry the objID or catID, so they are not available (we could assign on load, but we don't)
     216      myAssert(average[averageSeq[i]].catID == lensing[lensingSeq[i]].catID, "object / detection mismatch");
     217# if (1)
     218      myAssert(average[averageSeq[i]].objID == lensing[lensingSeq[i]].objID, "object / detection mismatch");
     219# else
     220      // for reasons I do not understand, the mini dvodbs generated on stsci1X had a handful of detections with an inconsistency between averef and objID. 
     221      // this happened for 28 detections in the dbs on /data/stsci1?.0/eugene/dvo3pi.20130616, but not at all (as far as I know) in the rest of LAP DVO
     222      if (average[averageSeq[i]].objID != lensing[lensingSeq[i]].objID) {
     223        fprintf (stderr, "R");
     224        lensing[lensingSeq[i]].objID = average[averageSeq[i]].objID; // XXX I don't really like this...
     225      }
     226# endif
     227    }
     228  }
     229 
     230  // check that averageSeq is now in order
     231  // for (i = 1; i < Nlensing; i++) {
     232  //   if (averageSeq[i] < averageSeq[i-1]) {
     233  //     fprintf (stderr, "%d ", (int) i);
     234  //   }
     235  // }
     236  // fprintf (stderr, "\n");
     237
     238  SortAveMatch(lensingSeq, averageSeq, Nlensing);
     239  // MARKTIME("sort : %f sec\n", dtime);
     240
     241  // check that averageSeq is now in order
     242  // for (i = 1; i < Nlensing; i++) {
     243  //   if (averageSeq[i] < averageSeq[i-1]) {
     244  //     fprintf (stderr, "%d ", (int) i);
     245  //   }
     246  // }
     247  // fprintf (stderr, "\n");
     248
     249  // copy the lensing entries in the sorted order
     250  ALLOCATE (lensingTMP, Lensing, Nlensing);
     251  for (i = 0; i < Nlensing; i++) {
     252    j = lensingSeq[i];
     253    lensingTMP[i] = lensing[j];
     254  }
     255  // MARKTIME("assign lensing : %f sec\n", dtime);
     256
     257  // update the values of average.lensingOffset and average.Nlensing
     258  FREE(lensing);
     259  catalog[0].lensing = lensingTMP;
     260
     261  N = 0;
     262  currentAve = averageSeq[0];
     263  average[currentAve].lensingOffset = 0;
     264  for (i = 0; i < Nlensing; i++) {
     265    if (averageSeq[i] != currentAve) {
     266      // we have hit the next entry in the list
     267      average[currentAve].Nlensing = N;
     268      N = 0;
     269      currentAve = averageSeq[i];
     270      average[currentAve].lensingOffset = i;
     271    }
     272    N++;
     273  }
     274  // N++;
     275  average[currentAve].Nlensing = N;
     276  // MARKTIME("update Nlensing : %f sec\n", dtime);
     277
     278  int NlensingTotal = 0;
     279  int lensingOffsetOK = TRUE;
     280  for (i = 0; i < Naverage; i++) {
     281    NlensingTotal += catalog[0].average[i].Nlensing;
     282    if (VERBOSE && !(NlensingTotal <= catalog[0].Nlensing)) {
     283      fprintf (stderr, "too few lensing: %d %d %d\n", (int) i, NlensingTotal, (int) catalog[0].Nlensing);
     284    }
     285    lensingOffsetOK &= (catalog[0].average[i].lensingOffset < catalog[0].Nlensing);
     286    if (VERBOSE && !(catalog[0].average[i].lensingOffset < catalog[0].Nlensing)) {
     287      fprintf (stderr, "offset too large: %d %d %d\n", (int) i, catalog[0].average[i].Nlensing, (int) catalog[0].Nlensing);
     288    }
     289    lensingOffsetOK &= (catalog[0].average[i].lensingOffset + catalog[0].average[i].Nlensing <= catalog[0].Nlensing);
     290    if (VERBOSE && !(catalog[0].average[i].lensingOffset + catalog[0].average[i].Nlensing <= catalog[0].Nlensing)) {
     291      fprintf (stderr, "orrset + Nlensing too large: %d + %d > %d %d\n", (int) i, catalog[0].average[i].lensingOffset, catalog[0].average[i].Nlensing, (int) catalog[0].Nlensing);
     292    }
     293  }
     294
     295  if (!lensingOffsetOK) {
     296    fprintf (stderr, "ERROR: catalog %s has an invalid lensingOffset\n", catalog[0].filename);
     297  }
     298
     299  if (NlensingTotal != catalog[0].Nlensing) {
     300    fprintf (stderr, "ERROR: catalog %s has an invalid Nlensing\n", catalog[0].filename);
     301  }
     302
     303  // MARKTIME("  match time %9.4f sec for %7lld lensings, %6lld average\n", dtime, (long long) Nlensing, (long long) Naverage);
     304
     305  catalog[0].sorted = TRUE;
     306
     307  FREE (lensingSeq);
     308  FREE (averageSeq);
     309
     310  return;
     311}
     312
     313// sort the measure or lensing Sequence based on the average Sequence entries
     314void SortAveMatch (off_t *MEAS, off_t *AVE, off_t N) {
     315
     316# define SWAPFUNC(A,B){ off_t tmp_meas; off_t tmp_ave;          \
     317    tmp_meas = MEAS[A]; MEAS[A] = MEAS[B]; MEAS[B] = tmp_meas;  \
     318    tmp_ave  = AVE[A];  AVE[A]  = AVE[B];  AVE[B]  = tmp_ave;   \
     319  }
     320# define COMPARE(A,B)(AVE[A] < AVE[B])
     321  OHANA_SORT (N, COMPARE, SWAPFUNC);
     322# undef SWAPFUNC
     323# undef COMPARE
     324}
     325
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/resort_threaded.c

    r29938 r37067  
    4141    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    4242    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    43     catalog.catflags  = LOAD_AVES | LOAD_MEAS;
     43    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_LENSING;
    4444    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    4545 
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/resort_unthreaded_catalogs.c

    r33963 r37067  
    3030    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    3131    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    32     catalog.catflags  = LOAD_AVES | LOAD_MEAS;
     32    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_LENSING;
    3333    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    3434
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/sky_tessalation.c

    r34844 r37067  
    11061106  refcoords[0].Npolyterms = 0;
    11071107  memset (refcoords[0].polyterms, 0, 14*sizeof(float));
    1108   strcpy (refcoords[0].ctype, "RA---TAN");
     1108  strcpy (refcoords[0].ctype, "DEC--TAN");
    11091109  return (TRUE);
    11101110}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/src/update_coords.c

    r34405 r37067  
    1919      continue;
    2020    }
    21     R = measure[m].dR;
    22     D = measure[m].dD;
     21    R = measure[m].R;
     22    D = measure[m].D;
    2323    r += R;
    2424    d += D;
     
    3333  r = r / Npt;  /* these are corrections in 1/100 arcsec to RA and DEC */
    3434  d = d / Npt;
    35   average[0].R -= r / 3600.0;
    36   average[0].D -= d / 3600.0;
     35  average[0].R = r;
     36  average[0].D = d;
    3737  m = average[0].measureOffset;  /* first measurement of this star */
    38   for (i = 0; i < average[0].Nmeasure; i++) {
    39     measure[m].dR -= r;
    40     measure[m].dD -= d;
    41     m = next[m];
    42   }
    43  
     38
    4439  /* measure scatter, if possible */
    4540  if (Npt < 2) return;
     
    4742  dR2 = r2 / Npt - r*r;
    4843  dD2 = d2 / Npt - d*d;
    49   average[0].ChiSqAve = sqrt (dD2 + dR2 / SQ(cos(d*RAD_DEG)));
     44  average[0].ChiSqAve = 3600.0*sqrt (dD2 + dR2 / SQ(cos(d*RAD_DEG)));
    5045  /* ChiSqAve is supposed to be a chisq */
    5146
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/addstar/test/simple.dvo

    r35263 r37067  
    77  test.fields PS1_DEV_0 PS1_V1
    88  test.fields PS1_DEV_1 PS1_V1
    9   test.fields PS1_V1    PS1_V1
    10   test.fields PS1_V2    PS1_V1
    11   test.fields PS1_V3    PS1_V1
    12   test.fields PS1_V4    PS1_V1
     9  test.fields PS1_V1    PS1_V1
     10  test.fields PS1_V2    PS1_V1
     11  test.fields PS1_V3    PS1_V1
     12  test.fields PS1_V4    PS1_V1
    1313
    1414  test.fields PS1_DEV_0 PS1_V2
    1515  test.fields PS1_DEV_1 PS1_V2
    16   test.fields PS1_V1    PS1_V2
    17   test.fields PS1_V2    PS1_V2
    18   test.fields PS1_V3    PS1_V2
    19   test.fields PS1_V4    PS1_V4
     16  test.fields PS1_V1    PS1_V2
     17  test.fields PS1_V2    PS1_V2
     18  test.fields PS1_V3    PS1_V2
     19  test.fields PS1_V4    PS1_V4
    2020
    2121  test.fields PS1_DEV_0 PS1_V3
    2222  test.fields PS1_DEV_1 PS1_V3
    23   test.fields PS1_V1    PS1_V3
    24   test.fields PS1_V2    PS1_V3
    25   test.fields PS1_V3    PS1_V3
    26   test.fields PS1_V4    PS1_V4
     23  test.fields PS1_V1    PS1_V3
     24  test.fields PS1_V2    PS1_V3
     25  test.fields PS1_V3    PS1_V3
     26  test.fields PS1_V4    PS1_V4
    2727
    2828  test.fields PS1_DEV_0 PS1_V4
    2929  test.fields PS1_DEV_1 PS1_V4
    30   test.fields PS1_V1    PS1_V4
    31   test.fields PS1_V2    PS1_V4
    32   test.fields PS1_V3    PS1_V4
    33   test.fields PS1_V4    PS1_V4
     30  test.fields PS1_V1    PS1_V4
     31  test.fields PS1_V2    PS1_V4
     32  test.fields PS1_V3    PS1_V4
     33  test.fields PS1_V4    PS1_V4
    3434end 
     35
     36if (not($?NO_NOISE))
     37  $NO_NOISE = ""
     38end
    3539
    3640# create a populated catdir with a single cmf -- test each field
     
    5054
    5155  mkinput
    52   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1
     56  echo mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1 $NO_NOISE
     57  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1 $NO_NOISE
    5358  if ($TAP_VERBOSE)
    5459    echo exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
    5560    exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
    5661  else
     62    echo addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
    5763    exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass >& tmp.log
    5864  end
     
    112118
    113119    # some fields require arithmetic manipulations
    114     if ("$name:0" == "KRON_FLUX")
    115      set v1 = -2.5*log(v1)
    116     end
    117     if ("$name:0" == "KRON_FLUX_ERR")
    118      set v1 = KRON_FLUX_ERR / KRON_FLUX
     120    ## if ("$name:0" == "KRON_FLUX")
     121    ##  set v1 = -2.5*log(v1)
     122    ## end
     123    ## if ("$name:0" == "KRON_FLUX_ERR")
     124    ##  set v1 = KRON_FLUX_ERR / KRON_FLUX
     125    ## end
     126    if (("$name:0" == "X_PSF_SIG") || ("$name:0" == "Y_PSF_SIG"))
     127     set v1 = int(100*(v1))
     128     set v2 = int(100*(v2 + 0.0001))
     129    end
     130    if ("$name:0" == "POSANGLE")
     131     set v1 = int((0xffff/360.0)*(v1))
     132     set v2 = int((0xffff/360.0)*(v2 + 0.0028))
    119133    end
    120134
     
    206220# this list is good for PS1_V1
    207221list testfields_PS1_V1
    208   IPP_IDET          : detid     
    209   X_PSF             : xccd     
    210   Y_PSF             : yccd     
     222  IPP_IDET          : detid     
     223  X_PSF             : xccd     
     224  Y_PSF             : yccd     
    211225  X_PSF_SIG         : xccd:err #  FAIL
    212226  Y_PSF_SIG         : yccd:err # FAIL
     
    215229  POSANGLE          : SKIP # astrometry is not calibrated in the cmf
    216230  PLTSCALE          : SKIP # astrometry is not calibrated in the cmf
    217   PSF_INST_MAG      : mag:inst 
    218   PSF_INST_MAG_SIG  : mag:err   
     231  PSF_INST_MAG      : mag:inst 
     232  PSF_INST_MAG_SIG  : mag:err   
    219233  AP_MAG_STANDARD   : mag:ap # FAIL
    220234  AP_MAG_RADIUS     : SKIP # no accessor
     
    222236  CAL_PSF_MAG       : SKIP # photometry is not calibrated in the cmf
    223237  CAL_PSF_MAG_SIG   : SKIP # photometry is not calibrated in the cmf
    224   SKY               : sky       
    225   SKY_SIG           : sky_err   
    226   PSF_CHISQ         : psf_chisq 
    227   CR_NSIGMA         : cr_nsigma 
     238  SKY               : sky       
     239  SKY_SIG           : sky_err   
     240  PSF_CHISQ         : psf_chisq 
     241  CR_NSIGMA         : cr_nsigma 
    228242  EXT_NSIGMA        : ext_nsigma
    229   PSF_MAJOR         : FWHM_MAJ 
    230   PSF_MINOR         : FWHM_MIN 
     243  PSF_MAJOR         : FWHM_MAJ 
     244  PSF_MINOR         : FWHM_MIN 
    231245  PSF_THETA         : THETA # FAIL
    232   PSF_QF            : PSF_QF   
     246  PSF_QF            : PSF_QF   
    233247  PSF_NDOF          : SKIP # no accessor
    234248  PSF_NPIX          : SKIP # no accessor
     
    237251  MOMENTS_YY        : SKIP # no accessor
    238252  FLAGS             : phot_flags
    239   N_FRAMES          : SKIP # no accessor       
     253  N_FRAMES          : SKIP # no accessor       
    240254end
    241255
    242256# this list is good for PS1_V2
    243257list testfields_PS1_V2
    244   IPP_IDET          : detid     
    245   X_PSF             : xccd     
    246   Y_PSF             : yccd     
     258  IPP_IDET          : detid     
     259  X_PSF             : xccd     
     260  Y_PSF             : yccd     
    247261  X_PSF_SIG         : xccd:err # FAIL
    248262  Y_PSF_SIG         : yccd:err # FAIL
     
    251265  POSANGLE          : SKIP # astrometry is not calibrated in the cmf
    252266  PLTSCALE          : SKIP # astrometry is not calibrated in the cmf
    253   PSF_INST_MAG      : mag:inst 
    254   PSF_INST_MAG_SIG  : mag:err   
     267  PSF_INST_MAG      : mag:inst 
     268  PSF_INST_MAG_SIG  : mag:err   
    255269  AP_MAG_STANDARD   : mag:ap # FAIL
    256270  AP_MAG_RADIUS     : SKIP # no accessor
     
    258272  CAL_PSF_MAG       : SKIP # photometry is not calibrated in the cmf
    259273  CAL_PSF_MAG_SIG   : SKIP # photometry is not calibrated in the cmf
    260   SKY               : sky       
    261   SKY_SIG           : sky_err   
    262   PSF_CHISQ         : psf_chisq 
    263   CR_NSIGMA         : cr_nsigma 
     274  SKY               : sky       
     275  SKY_SIG           : sky_err   
     276  PSF_CHISQ         : psf_chisq 
     277  CR_NSIGMA         : cr_nsigma 
    264278  EXT_NSIGMA        : ext_nsigma
    265   PSF_MAJOR         : FWHM_MAJ 
    266   PSF_MINOR         : FWHM_MIN 
     279  PSF_MAJOR         : FWHM_MAJ 
     280  PSF_MINOR         : FWHM_MIN 
    267281  PSF_THETA         : THETA # FAIL
    268   PSF_QF            : PSF_QF   
     282  PSF_QF            : PSF_QF   
    269283  PSF_NDOF          : SKIP # no accessor
    270284  PSF_NPIX          : SKIP # no accessor
     
    273287  MOMENTS_YY        : SKIP # no accessor
    274288  FLAGS             : phot_flags
    275   N_FRAMES          : SKIP # no accessor       
     289  N_FRAMES          : SKIP # no accessor       
    276290end
    277291
    278292# this list is good for PS1_V3
    279293list testfields_PS1_V3
    280   IPP_IDET          : detid     
    281   X_PSF             : xccd     
    282   Y_PSF             : yccd     
     294  IPP_IDET          : detid     
     295  X_PSF             : xccd     
     296  Y_PSF             : yccd     
    283297  X_PSF_SIG         : xccd:err # FAIL
    284298  Y_PSF_SIG         : yccd:err # FAIL
    285299  POSANGLE          : SKIP # astrometry is not calibrated in the cmf
    286300  PLTSCALE          : SKIP # astrometry is not calibrated in the cmf
    287   PSF_INST_MAG      : mag:inst 
    288   PSF_INST_MAG_SIG  : mag:err   
     301  PSF_INST_MAG      : mag:inst 
     302  PSF_INST_MAG_SIG  : mag:err   
    289303  PSF_INST_FLUX     : SKIP # not ingested into DVO
    290304  PSF_INST_FLUX_SIG : SKIP # not ingested into DVO
     
    297311  DEC_PSF           : SKIP # astrometry is not calibrated in the cmf
    298312  PEAK_FLUX_AS_MAG  : SKIP # not ingested into DVO
    299   SKY               : sky       
    300   SKY_SIG           : sky_err   
    301   PSF_CHISQ         : psf_chisq 
    302   CR_NSIGMA         : cr_nsigma 
     313  SKY               : sky       
     314  SKY_SIG           : sky_err   
     315  PSF_CHISQ         : psf_chisq 
     316  CR_NSIGMA         : cr_nsigma 
    303317  EXT_NSIGMA        : ext_nsigma
    304   PSF_MAJOR         : FWHM_MAJ 
    305   PSF_MINOR         : FWHM_MIN 
     318  PSF_MAJOR         : FWHM_MAJ 
     319  PSF_MINOR         : FWHM_MIN 
    306320  PSF_THETA         : THETA # FAIL
    307   PSF_QF            : PSF_QF   
     321  PSF_QF            : PSF_QF   
    308322  PSF_QF_PERFECT    : SKIP # not ingested into DVO
    309323  PSF_NDOF          : PSF_NDOF
     
    326340end
    327341
    328 # this list is good for PS1_V4
    329 list testfields_PS1_V4
    330   IPP_IDET          : detid     
    331   X_PSF             : xccd     
    332   Y_PSF             : yccd     
    333   X_PSF_SIG         : xccd:err # FAIL
    334   Y_PSF_SIG         : yccd:err # FAIL
    335   POSANGLE          : SKIP # astrometry is not calibrated in the cmf
    336   PLTSCALE          : SKIP # astrometry is not calibrated in the cmf
    337   PSF_INST_MAG      : mag:inst 
    338   PSF_INST_MAG_SIG  : mag:err   
    339   PSF_INST_FLUX     : SKIP # not ingested into DVO
    340   PSF_INST_FLUX_SIG : SKIP # not ingested into DVO
    341   AP_MAG            : mag:aperinst # FAIL
     342# this list is good for PS1_V5
     343list testfields_PS1_V5
     344  IPP_IDET          : detid     
     345  X_PSF             : xccd     
     346  Y_PSF             : yccd     
     347  X_PSF_SIG         : xccd:err
     348  Y_PSF_SIG         : yccd:err
     349  POSANGLE          : posangle
     350  PLTSCALE          : platescale
     351  PSF_INST_MAG      : mag:inst 
     352  PSF_INST_MAG_SIG  : mag:err   
     353  PSF_INST_FLUX     : flux:inst
     354  PSF_INST_FLUX_SIG : flux:inst:err
     355  AP_MAG            : mag:aper:inst
    342356  AP_MAG_RAW        : SKIP # not ingested into DVO
    343357  AP_MAG_RADIUS     : SKIP # not ingested into DVO
    344   CAL_PSF_MAG       : SKIP # photometry is not calibrated in the cmf
    345   CAL_PSF_MAG_SIG   : SKIP # photometry is not calibrated in the cmf
    346   RA_PSF            : SKIP # astrometry is not calibrated in the cmf
    347   DEC_PSF           : SKIP # astrometry is not calibrated in the cmf
    348   PEAK_FLUX_AS_MAG  : SKIP # not ingested into DVO
    349   SKY               : sky       
    350   SKY_SIGMA         : sky_err   
    351   PSF_CHISQ         : psf_chisq
    352   CR_NSIGMA         : cr_nsigma
    353   EXT_NSIGMA        : ext_nsigma
    354   PSF_MAJOR         : FWHM_MAJ 
    355   PSF_MINOR         : FWHM_MIN 
    356   PSF_THETA         : THETA # FAIL
    357   PSF_QF            : PSF_QF   
    358   PSF_QF_PERFECT    : SKIP # not ingested into DVO
    359   PSF_NDOF          : PSF_NDOF
    360   PSF_NPIX          : PSF_NPIX
    361   MOMENTS_XX        : MXX
    362   MOMENTS_XY        : MXY
    363   MOMENTS_YY        : MYY
    364   MOMENTS_M3C       : SKIP # not ingested into DVO
    365   MOMENTS_M3S       : SKIP # not ingested into DVO
    366   MOMENTS_M4C       : SKIP # not ingested into DVO
    367   MOMENTS_M4S       : SKIP # not ingested into DVO
    368   MOMENTS_R1        : SKIP # not ingested into DVO
    369   MOMENTS_RH        : SKIP # not ingested into DVO
    370   KRON_FLUX         : mag:kroninst
    371   KRON_FLUX_ERR     : mag:kronerr
    372   KRON_FLUX_INNER   : SKIP # not ingested into DVO
    373   KRON_FLUX_OUTER   : SKIP # not ingested into DVO
    374   FLAGS             : phot_flags
    375   N_FRAMES          : SKIP # not ingested into DVO
    376 end
     358  AP_FLUX           : flux:aper:inst 
     359  AP_FLUX_SIG       : flux:aper:inst:err
     360  CAL_PSF_MAG       : mag:cal
     361  CAL_PSF_MAG_SIG   : mag:cal:err
     362  RA_PSF            : ra
     363  DEC_PSF           : dec
     364  AP_NPIX           : SKIP # not ingested into DVO                   
     365  PEAK_FLUX_AS_MAG  : SKIP # not ingested into DVO                   
     366  SKY               : sky                                             
     367  SKY_SIGMA         : sky_err                                         
     368  PSF_CHISQ         : psf_chisq                                       
     369  CR_NSIGMA         : cr_nsigma                                       
     370  EXT_NSIGMA        : ext_nsigma                                     
     371  PSF_MAJOR         : fwhm_maj # XXX technically, this is not FWHM but Sigma
     372  PSF_MINOR         : fwhm_min # XXX technically, this is not FWHM but Sigma
     373  PSF_THETA         : theta # FAIL                                   
     374  PSF_CORE          : SKIP # not ingested into DVO
     375  PSF_FWHM_MAJ      : SKIP # not ingested into DVO
     376  PSF_FWHM_MIN      : SKIP # not ingested into DVO
     377  PSF_QF            : psf_qf                                         
     378  PSF_QF_PERFECT    : SKIP # not ingested into DVO                   
     379  PSF_NDOF          : psf_ndof                               
     380  PSF_NPIX          : psf_npix                               
     381  MOMENTS_XX        : Mxx                                             
     382  MOMENTS_XY        : Mxy                                             
     383  MOMENTS_YY        : Myy                                             
     384  MOMENTS_M3C       : SKIP # not ingested into DVO                   
     385  MOMENTS_M3S       : SKIP # not ingested into DVO                   
     386  MOMENTS_M4C       : SKIP # not ingested into DVO                   
     387  MOMENTS_M4S       : SKIP # not ingested into DVO                   
     388  MOMENTS_R1        : SKIP # not ingested into DVO                   
     389  MOMENTS_RH        : SKIP # not ingested into DVO                   
     390  KRON_FLUX         : flux:kron:inst                                 
     391  KRON_FLUX_ERR     : flux:kron:inst:err                                     
     392  KRON_FLUX_INNER   : SKIP # not ingested into DVO                       
     393  KRON_FLUX_OUTER   : SKIP # not ingested into DVO                   
     394  SKY_LIMIT_RAD     : SKIP # not ingested into DVO                       
     395  SKY_LIMIT_FLUX    : SKIP # not ingested into DVO                       
     396  SKY_LIMIT_SLOPE   : SKIP # not ingested into DVO                       
     397  FLAGS             : phot_flags                                     
     398  FLAGS2            : SKIP # not ingested into DVO                       
     399  N_FRAMES          : SKIP # not ingested into DVO                   
     400end                                                                   
     401
     402# this list is good for PS1_SV3
     403list testfields_PS1_SV3
     404  IPP_IDET          : detid     
     405  X_PSF             : xccd     
     406  Y_PSF             : yccd     
     407  X_PSF_SIG         : xccd:err
     408  Y_PSF_SIG         : yccd:err
     409  POSANGLE          : posangle
     410  PLTSCALE          : platescale
     411  PSF_INST_MAG      : mag:inst 
     412  PSF_INST_MAG_SIG  : mag:err   
     413  PSF_INST_FLUX     : flux:inst
     414  PSF_INST_FLUX_SIG : flux:inst:err
     415  AP_MAG            : mag:aper:inst
     416  AP_MAG_RAW        : SKIP # not ingested into DVO
     417  AP_MAG_RADIUS     : SKIP # not ingested into DVO
     418  AP_FLUX           : flux:aper:inst 
     419  AP_FLUX_SIG       : flux:aper:inst:err
     420  CAL_PSF_MAG       : mag:cal
     421  CAL_PSF_MAG_SIG   : mag:cal:err
     422  RA_PSF            : ra
     423  DEC_PSF           : dec
     424  AP_NPIX           : SKIP # not ingested into DVO                   
     425  PEAK_FLUX_AS_MAG  : SKIP # not ingested into DVO                   
     426  SKY               : sky                                             
     427  SKY_SIGMA         : sky_err                                         
     428  PSF_CHISQ         : psf_chisq                                       
     429  CR_NSIGMA         : cr_nsigma                                       
     430  EXT_NSIGMA        : ext_nsigma                                     
     431  PSF_MAJOR         : fwhm_maj # XXX technically, this is not FWHM but Sigma
     432  PSF_MINOR         : fwhm_min # XXX technically, this is not FWHM but Sigma
     433  PSF_THETA         : theta # FAIL                                   
     434  PSF_CORE          : SKIP # not ingested into DVO
     435  PSF_FWHM_MAJ      : SKIP # not ingested into DVO
     436  PSF_FWHM_MIN      : SKIP # not ingested into DVO
     437  PSF_QF            : psf_qf                                         
     438  PSF_QF_PERFECT    : SKIP # not ingested into DVO                   
     439  PSF_NDOF          : psf_ndof                               
     440  PSF_NPIX          : psf_npix                               
     441  MOMENTS_XX        : Mxx                                             
     442  MOMENTS_XY        : Mxy                                             
     443  MOMENTS_YY        : Myy                                             
     444  MOMENTS_M3C       : SKIP # not ingested into DVO                   
     445  MOMENTS_M3S       : SKIP # not ingested into DVO                   
     446  MOMENTS_M4C       : SKIP # not ingested into DVO                   
     447  MOMENTS_M4S       : SKIP # not ingested into DVO                   
     448  MOMENTS_R1        : SKIP # not ingested into DVO                   
     449  MOMENTS_RH        : SKIP # not ingested into DVO                   
     450  KRON_FLUX         : flux:kron:inst                                 
     451  KRON_FLUX_ERR     : flux:kron:inst:err                                     
     452  KRON_FLUX_INNER   : SKIP # not ingested into DVO                       
     453  KRON_FLUX_OUTER   : SKIP # not ingested into DVO                   
     454  FLAGS             : phot_flags                                     
     455  FLAGS2            : SKIP # not ingested into DVO                       
     456  N_FRAMES          : SKIP # not ingested into DVO                   
     457end                                                                   
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/delstar/include/delstar.h

    r35758 r37067  
    6767int    UPDATE;
    6868int    IMAGE_DETAILS;
     69int    IMAGE_DUPLICATES_BY_OBSTIME;
    6970int    IMAGE_ONLY;
    7071int    ORPHAN;
     
    138139void SortAveMeasMatch (off_t *MEAS, off_t *AVE, off_t N);
    139140
    140 int delete_photcodes ();
     141int delete_photcodes (void);
    141142int delete_photcodes_parallel (SkyList *sky);
    142143int delete_photcodes_catalog (Catalog *catalog, PhotCode **photcodes, int Nphotcodes);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/delstar/src/ImageOpsFixLAP.c

    r35758 r37067  
    11# include "delstar.h"
    2 # define FT_BZERO_INT32 1.0*0x80000000
    32
    43off_t   Nimage = 0;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/delstar/src/ImageSubsetFixLAP.c

    r35758 r37067  
    11# include "delstar.h"
    2 # define FT_BZERO_INT16 1.0*0x8000       
    3 # define FT_BZERO_INT32 1.0*0x80000000
    42
    53# define GET_COLUMN(OUT,NAME,TYPE) \
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/delstar/src/MeasureEdgeOps.c

    r35758 r37067  
    11# include "delstar.h"
    2 # define FT_BZERO_INT32 1.0*0x80000000
    32
    43# define GET_COLUMN(OUT,NAME,TYPE) \
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/delstar/src/args.c

    r35758 r37067  
    1818  fprintf (stderr, "  -image-details : list info about the deleted images (-dup-images only)\n");
    1919  fprintf (stderr, "  -image-only : only examine the image table (changes are NOT saved; -dup-images only)\n");
     20  fprintf (stderr, "  -image-only-force : modify only the image table (-dup-images only)\n");
     21  fprintf (stderr, "  -image-by-obstime : use date/time and photcode (not externID) to find duplicates\n");
    2022  fprintf (stderr, "  -region Rmin Rmax Dmin Dmax : apply changes to this part of the sky\n");
    2123 
     
    6870  if ((N = get_argument (argc, argv, "-image-details"))) {
    6971    IMAGE_DETAILS = TRUE;
     72    remove_argument (N, &argc, argv);
     73  }
     74
     75  IMAGE_DUPLICATES_BY_OBSTIME = FALSE;
     76  if ((N = get_argument (argc, argv, "-image-by-obstime"))) {
     77    IMAGE_DUPLICATES_BY_OBSTIME = TRUE;
    7078    remove_argument (N, &argc, argv);
    7179  }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/delstar/src/delete_duplicate_images.c

    r35758 r37067  
    11# include "delstar.h"
     2
     3IndexArray *find_duplicates_obstime (Image *image, off_t Nimage, off_t *Nduplicates);
     4off_t find_obstime_range (Image *image, off_t Nimage, off_t firstEntry);
     5void sort_by_obstime (e_time *T, short *P, off_t *I, off_t N);
     6void sort_by_photcode (short *P, off_t *I, off_t N);
    27
    38// this function identifies the images to be deleted based on duplication of the
     
    1823
    1924  off_t Nduplicates = 0;
    20   IndexArray *imageID = find_duplicates (image, Nimage, &Nduplicates);
     25  IndexArray *imageID = NULL;
     26
     27  if (IMAGE_DUPLICATES_BY_OBSTIME) {
     28    imageID = find_duplicates_obstime (image, Nimage, &Nduplicates);
     29  } else {
     30    imageID = find_duplicates (image, Nimage, &Nduplicates);
     31  }
    2132
    2233  if (Nduplicates == 0) {
     
    494505}
    495506
     507// sort by increasing obstime
     508void sort_by_obstime (e_time *T, short *P, off_t *I, off_t N) {
     509
     510# define SWAPFUNC(A,B){ e_time tmpT; short tmpP; off_t tmpI; \
     511  tmpT = T[A]; T[A] = T[B]; T[B] = tmpT; \
     512  tmpP = P[A]; P[A] = P[B]; P[B] = tmpP; \
     513  tmpI = I[A]; I[A] = I[B]; I[B] = tmpI; \
     514}
     515# define COMPARE(A,B)(T[A] < T[B])
     516
     517  OHANA_SORT (N, COMPARE, SWAPFUNC);
     518
     519# undef SWAPFUNC
     520# undef COMPARE
     521
     522}
     523
     524// sort by increasing photcode
     525void sort_by_photcode (short *P, off_t *I, off_t N) {
     526
     527# define SWAPFUNC(A,B){ short tmpP; off_t tmpI; \
     528  tmpP = P[A]; P[A] = P[B]; P[B] = tmpP; \
     529  tmpI = I[A]; I[A] = I[B]; I[B] = tmpI; \
     530}
     531# define COMPARE(A,B)(P[A] < P[B])
     532
     533  OHANA_SORT (N, COMPARE, SWAPFUNC);
     534
     535# undef SWAPFUNC
     536# undef COMPARE
     537
     538}
     539
     540static e_time *obstime  = NULL;
     541static short  *photcode = NULL;
     542static off_t  *primary  = NULL;
     543static off_t  *idx      = NULL;
     544static char   *keep     = NULL;
     545
     546static short  *photcode_subset = NULL;
     547static off_t  *idx_subset      = NULL;
     548
     549static off_t Nsubset = 0;
     550static off_t NSUBSET = 300;
     551
     552off_t find_obstime_range (Image *image, off_t Nimage, off_t firstEntry) {
     553
     554  Nsubset = 0;
     555
     556  // find all entries with the same obstime:
     557  e_time firstTime = obstime[firstEntry];
     558
     559  idx_subset[Nsubset] = idx[firstEntry];
     560  photcode_subset[Nsubset] = photcode[firstEntry];
     561  Nsubset++;
     562
     563  off_t i = firstEntry + Nsubset;
     564  while ((i < Nimage) && (obstime[i] == firstTime)) {
     565    idx_subset[Nsubset] = idx[i];
     566    photcode_subset[Nsubset] = photcode[i];
     567    Nsubset++;
     568    i++;
     569    if (Nsubset >= NSUBSET) {
     570      NSUBSET += 1000;
     571      REALLOCATE (photcode_subset, short, NSUBSET);
     572      REALLOCATE (idx_subset, off_t, NSUBSET);
     573    }
     574  }     
     575
     576  sort_by_photcode (photcode_subset, idx_subset, Nsubset);
     577
     578  return i;
     579}
     580
     581// alternative version to find duplicates based on obstime and photcode
     582IndexArray *find_duplicates_obstime (Image *image, off_t Nimage, off_t *Nduplicates) {
     583
     584  if (Nimage < 1) return NULL;
     585
     586  // how to find duplicates:
     587  // generate a set of arrays (idx, obstime, photcode, keep)
     588  // sort the arrays by obstime
     589  // loop over obstime. 
     590  // for a given new obstime, scan through the entries with the same value
     591  // create a sub-array of photcodes, idx
     592  // sort by photcode
     593  // loop over entries
     594  // find matching photcodes
     595  // mark duplicate enties
     596
     597  ALLOCATE (obstime, e_time, Nimage);
     598  ALLOCATE (photcode, short, Nimage);
     599  ALLOCATE (primary, off_t, Nimage);
     600  ALLOCATE (idx, off_t, Nimage);
     601  ALLOCATE (keep, char, Nimage);
     602
     603  off_t i;
     604
     605  INITTIME;
     606
     607  // skip entries with photcode == 0?
     608  for (i = 0; i < Nimage; i++) {
     609    idx[i] = i;
     610    primary[i] = -1; // only duplicates get a value for primary
     611    keep[i] = TRUE;
     612    obstime[i] = image[i].tzero;
     613    photcode[i] = image[i].photcode;
     614  }
     615  MARKTIME("  generate index arrays: %f sec\n", dtime);
     616
     617  // sort the 4 arrays
     618  sort_by_obstime (obstime, photcode, idx, Nimage);
     619  MARKTIME("  sort index arrays: %f sec\n", dtime);
     620
     621  // image[idx[i]].tzero = obstime[i]
     622  // keep[i] -> keep image[i] ('keep' is NOT resorted)
     623
     624  // allocate arrays to store the subsets (these are global static)
     625  // These get reallocated if necessary in find_obstime_range()
     626  ALLOCATE (photcode_subset, short, NSUBSET);
     627  ALLOCATE (idx_subset, off_t, NSUBSET);
     628
     629  // entries of idx_subset correspond to the original image sequence:
     630  // image[idx_subset[i]].tzero = obstime[i]
     631
     632  off_t firstEntry = 0;
     633  off_t nextEntry = 0;
     634 
     635  while (nextEntry < Nimage) {
     636    if (firstEntry >= Nimage) {
     637      fprintf (stderr, "error, too far?\n");
     638    }
     639   
     640    // generate photcode_subset, idx_subset in order of photcode for this unique obstime[firstEntry]
     641    // returned value is the first value of the next entry
     642    nextEntry = find_obstime_range (image, Nimage, firstEntry);
     643   
     644    // step through the photcodes and find duplicates
     645    int j;
     646    int firstCodeEntry = 0;
     647    short firstCode = photcode_subset[firstCodeEntry];
     648    for (j = 1; j < Nsubset; j++) {
     649      if (photcode_subset[j] == firstCode) {
     650        // mark as duplicate
     651        off_t dupIndex = idx_subset[j];
     652        keep[dupIndex] = FALSE;
     653        primary[dupIndex] = idx_subset[firstCodeEntry];
     654      } else {
     655        // new value of photcode, call if the first one
     656        firstCodeEntry = j;
     657        firstCode = photcode_subset[firstCodeEntry];
     658      }
     659    }
     660    firstEntry = nextEntry;
     661  }
     662  MARKTIME("  find duplicates: %f sec\n", dtime);
     663
     664  IndexArray *imageID = make_index_array (image, Nimage, IMAGE_ID);
     665  MARKTIME("  make index array: %f sec\n", dtime);
     666
     667  // set imageID->value to TRUE for images we want to delete
     668  off_t Ndup = 0;
     669  for (i = 0; i < Nimage; i++) {
     670    if (keep[i]) continue;
     671    off_t Ni = image[i].imageID - imageID->minID;
     672    myAssert (Ni >= 0, "oops");
     673    myAssert (Ni < imageID->range, "oops");
     674    imageID->value[Ni] = TRUE;
     675    Ndup ++;
     676  }
     677  MARKTIME("  mark duplicates: %f sec\n", dtime);
     678
     679  for (i = 0; IMAGE_DETAILS && (i < Nimage); i++) {
     680    off_t Ni = image[i].imageID - imageID->minID;
     681    if (!imageID->value[Ni]) continue;
     682   
     683    char *date = NULL;
     684    date = ohana_sec_to_date (image[i].tzero);
     685    fprintf (stderr, "delete image : (" OFF_T_FMT "), extID = %d : %30s : %20s %5d  ==  ", i, image[i].externID, image[i].name, date, image[i].photcode);
     686    free (date);
     687
     688    off_t myPrimary = primary[i];
     689    if (myPrimary < 0) {
     690      fprintf (stderr, "ERROR: this should never happen\n");
     691      abort();
     692    }
     693    date = ohana_sec_to_date (image[myPrimary].tzero);
     694    fprintf (stderr, "parent image : (" OFF_T_FMT "), extID = %d : %30s : %20s %5d\n", myPrimary, image[myPrimary].externID, image[myPrimary].name, date, image[myPrimary].photcode);
     695    free (date);
     696  }
     697
     698  *Nduplicates = Ndup;
     699
     700  free (photcode_subset);
     701  free (idx_subset);
     702 
     703  free (obstime);
     704  free (photcode);
     705  free (primary);
     706  free (idx);
     707  free (keep);
     708
     709  return imageID;;
     710}
     711
    496712// find the min & max values of the given ID (externID or imageID)
    497713// construct an empty array with length needed to fit IDs
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/delstar/src/delete_fix_LAP_edges.c

    r35805 r37067  
    206206  double Dgapmin = Dmin + dD;
    207207  double Dgapmax = Dmax - dD;
     208 
     209  float cosDec = cos(RAD_DEG * 0.5 * (Dmin + Dmax));
    208210
    209211  // XXX should deal with pole, but not yet...
     
    218220    float maxOff = 0.0;
    219221    m = catalog[0].average[i].measureOffset;
     222
    220223    for (j = 0; j < catalog[0].average[i].Nmeasure; j++) {
    221       float dRoff = catalog[0].measure[m+j].dR * cos(RAD_DEG * 0.5 * (Dmin + Dmax));
    222       float dDoff = catalog[0].measure[m+j].dD;
     224
     225      float dRoff = dvoOffsetR(&catalog[0].measure[m+j], &catalog[0].average[i])*cosDec;
     226      float dDoff = dvoOffsetD(&catalog[0].measure[m+j], &catalog[0].average[i]);
    223227      float dOff = hypot (dRoff, dDoff);
    224228      maxOff = MAX (maxOff, dOff);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvomerge

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvomerge/src/IDmapIO.c

    r34277 r37067  
    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/ipp-ops-20130712/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c

    r34277 r37067  
    167167  off_t i, oldID, newID;
    168168
     169  if (!IDmap->old) {
     170    fprintf (stderr, "input database has image IDs, but no Image table\n");
     171    return FALSE;
     172  }
     173
     174  if (!IDmap->Nmap) {
     175    fprintf (stderr, "input database has image IDs, but no Image table\n");
     176    return FALSE;
     177  }
     178
     179  off_t lastID = IDmap->old[IDmap->Nmap-1];
     180
    169181  for (i = 0; i < catalog[0].Nmeasure; i++) {
    170182    oldID = catalog[0].measure[i].imageID;
    171183    if (oldID == 0) continue;
    172184
    173     if (!IDmap->old) {
    174       fprintf (stderr, "input database has image IDs, but no Image table\n");
    175     }
    176 
    177185    newID = dvo_map_image_ID (IDmap, oldID);
    178186    if (newID == 0) {
     187      if (oldID > lastID) {
     188        fprintf (stderr, "problem with image IDs : input out of range\n");
     189        fprintf (stderr, "old ID: "OFF_T_FMT", last ID: "OFF_T_FMT"\n", oldID, lastID);
     190        exit (2);
     191      }
    179192      if (!IDmap->notFound[oldID]) {
    180193        fprintf (stderr, "cannot find image ID "OFF_T_FMT"\n",  oldID);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvomerge/src/dvomergeImageIDs.c

    r35765 r37067  
    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/ipp-ops-20130712/Ohana/src/dvomerge/src/dvomergeUpdate.c

    r35765 r37067  
    111111  SetPhotcodeTable(NULL);
    112112
    113   dvomergeUpdate_catalogs (input, output, outsky, inlist, NsecfiltInput, NsecfiltOutput, &IDmap, secfiltMap);
     113  int status = dvomergeUpdate_catalogs (input, output, outsky, inlist, NsecfiltInput, NsecfiltOutput, &IDmap, secfiltMap);
    114114
    115115  // save the output sky table copy
     
    123123  gettimeofday (&stop, NULL);
    124124  dtime = DTIME (stop, start);
     125
     126  if (!status) {
     127    fprintf (stderr, "ERROR: elapsed time %9.4f sec\n", dtime);
     128    exit (3);
     129  }
     130
    125131  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec\n", dtime);
    126 
    127132  exit (0);
    128133}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c

    r35765 r37067  
    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
     147    dvo_update_image_IDs (IDmap, &incatalog);
     148
    142149    // merge input into the appropriate output tables
    143150    for (j = 0; j < outlist[0].Nregions; j++) {
     
    156163      LoadCatalog (&outcatalog, outlist[0].regions[j], outcatalog.filename, "w", NsecfiltOutput);
    157164
    158       dvo_update_image_IDs (IDmap, &incatalog);
    159165      merge_catalogs_old (outlist[0].regions[j], &outcatalog, &incatalog, RADIUS, secfiltMap);
    160166
    161167      outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    162168
    163       if (outstat[i].missed) {
     169      if (outstat[j].missed) {
    164170        dmhObjectAdd (outstat[j].history, &outcatalog.header, inStats);
    165171      }
     
    248254    if (FORCE_MERGE)         { snprintf (tmpline, DVO_MAX_PATH, "%s -force-merge",     command); strcpy (command, tmpline); }
    249255
     256    // add some config variables:
     257    snprintf (tmpline, DVO_MAX_PATH, "%s -D CATMODE %s",    command, CATMODE);   strcpy (command, tmpline);
     258    snprintf (tmpline, DVO_MAX_PATH, "%s -D CATFORMAT %s",  command, CATFORMAT); strcpy (command, tmpline);
     259    snprintf (tmpline, DVO_MAX_PATH, "%s -D SKY_DEPTH %d",  command, SKY_DEPTH); strcpy (command, tmpline);
     260
    250261    fprintf (stderr, "command: %s\n", command);
    251262
     
    275286  }
    276287  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
    277     HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE);
     288    int status = HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE);
     289    if (!status) {
     290      fprintf (stderr, "error running one of the remote clients\n");
     291      return status;
     292    }
    278293  }
    279294
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvomerge/src/dvomerge_client.c

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvomerge/src/dvorepair.c

    r29938 r37067  
    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/ipp-ops-20130712/Ohana/src/dvomerge/src/dvorepairCPT.c

    r33657 r37067  
    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/ipp-ops-20130712/Ohana/src/dvomerge/src/dvorepairDeleteImageList.c

    r29938 r37067  
    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/ipp-ops-20130712/Ohana/src/dvomerge/src/dvorepairFixCPT.c

    r29938 r37067  
    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/ipp-ops-20130712/Ohana/src/dvomerge/src/dvorepairFixTables.c

    r29938 r37067  
    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/ipp-ops-20130712/Ohana/src/dvomerge/src/dvorepairImageVsMeasure.c

    r33657 r37067  
    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/ipp-ops-20130712/Ohana/src/dvomerge/src/dvorepairImagesVsMeasures.c

    r29938 r37067  
    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/ipp-ops-20130712/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r35416 r37067  
    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;
     
    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
     
    7675  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    7776  tcoords.Npolyterms = 1;
    78   strcpy (tcoords.ctype, "RA---ARC");
     77  strcpy (tcoords.ctype, "DEC--ARC");
    7978
    8079  if (VERBOSE) fprintf (stderr, "merging %s into %s\n", input[0].filename, output[0].filename);
     
    8786    N1[Nstars] = i;
    8887    Nstars ++;
    89     input[0].found[i] = -1;
     88    input[0].found_t[i] = -1;
    9089  }
    9190  if (Nstars < 1) {
    9291    if (VERBOSE) fprintf (stderr, "skipping %s, no overlapping stars\n", output[0].filename);
    93     free (output[0].found);
    94     free (input[0].found);
    9592    free (X1);
    9693    free (Y1);
     
    106103  for (i = 0; i < Nave; i++) {
    107104    RD_to_XY (&X2[i], &Y2[i], output[0].average[i].R, output[0].average[i].D, &tcoords);
    108     output[0].found[i] = -1;
     105    output[0].found_t[i] = -1;
    109106    N2[i] = i;
    110107  }
     
    196193        int Mout = output[0].average[n].measureOffset; 
    197194        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;
     195          input[0].found_t[N] = Mout;
    199196          continue;
    200197        }
     
    206203      output[0].measure[Nmeas] = input[0].measure[offset];
    207204
    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
     205      // old code: find R,D using average_in[0], the get offset relative to average_out[0].  no longer
     206      // needed since we carry around R,D
     207      // Rin = input[0].average[N].R - input[0].measure[offset].dR / 3600.0;
     208      // Din = input[0].average[N].D - input[0].measure[offset].dD / 3600.0;
     209      // output[0].measure[Nmeas].dR = 3600.0*(output[0].average[n].R - Rin);
     210      // output[0].measure[Nmeas].dD = 3600.0*(output[0].average[n].D - Din);
     211
    214212      output[0].measure[Nmeas].dbFlags  = 0;  // XXX why reset these?
    215213      output[0].measure[Nmeas].averef   = n;
     
    221219      // 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);
    222220
    223       // rationalize dR
    224       if (output[0].measure[Nmeas].dR > +180.0*3600.0) {
     221      float dRoff = dvoOffsetR(&output[0].measure[Nmeas], &output[0].average[n]);
     222
     223      // rationalize R
     224      if (dRoff > +180.0*3600.0) {
    225225        // 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) {
     226        output[0].measure[Nmeas].R += 360.0;
     227        dRoff -= 360.0*3600.0;
     228      }
     229      if (dRoff < -180.0*3600.0) {
    230230        // 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...
     231        output[0].measure[Nmeas].R -= 360.0;
     232        dRoff += 360.0*3600.0;
     233      }
     234      if (fabs(dRoff) > 10*RADIUS) {
     235        // take declination into account and check again.
     236        double cosD = cos(RAD_DEG*output[0].average[n].D);
     237        if (fabs(dRoff*cosD) > 10*RADIUS) {
     238          fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
     239                   output[0].average[n].R, output[0].average[n].D,
     240                   output[0].measure[Nmeas].R, output[0].measure[Nmeas].D,
     241                   X1[i], X2[Jmin], Y1[i], Y2[Jmin]);
     242          // XXX abort on this? -- this is a bad failure...
    244243        }
    245244      }
    246       input[0].found[N] = Nmeas;
     245      input[0].found_t[N] = Nmeas;
    247246      output[0].average[n].Nmeasure ++;
    248247      Nmeas ++;
     
    273272    /* Nm is updated, but not written out in -update mode (for existing entries)
    274273       Nm is recalculated in build_meas_links if loaded table is not sorted */
    275     output[0].found[n] = Nmeas;
     274    output[0].found_t[n] = Nmeas;
    276275    i++;
    277276  }
     
    295294    }
    296295
    297     if (input[0].found[N] >= 0) continue;
     296    if (input[0].found_t[N] >= 0) continue;
    298297    if (!IN_REGION (input[0].average[N].R, input[0].average[N].D)) continue;
    299298
     
    348347
    349348      /* we set next[Nmeas] to -1 here, and update correctly below */
    350       input[0].found[N] = Nmeas;
     349      input[0].found_t[N] = Nmeas;
    351350      next_meas[Nmeas] = -1;
    352351      Nmeas ++;
     
    374373  /* note stars which have been found in this catalog */
    375374  for (i = 0; i < input[0].Naverage; i++) {
    376     if (input[0].found[i] > -1) {
    377       input[0].found[i] = -2;
     375    if (input[0].found_t[i] > -1) {
     376      input[0].found_t[i] = -2;
    378377    } else {
    379       input[0].found[i] = -3;
     378      input[0].found_t[i] = -3;
    380379    }
    381380  }
     
    390389  free (next_meas);
    391390
    392   free (output[0].found);
    393391  free (X2);
    394392  free (Y2);
    395393  free (N2);
    396   free (input[0].found);
    397394  free (X1);
    398395  free (Y1);
     
    411408   images have boundaries which are lines in pixels coords, but curve in RA and DEC
    412409   
    413    output[0].found[Ncat] but stars[Nstar].found
     410   output[0].found_t[Ncat] but stars[Nstar].found
    414411   
    415412*/
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvomerge/src/replace_match.c

    r33963 r37067  
    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    }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvopsps/include/dvopsps.h

    r35578 r37067  
    33# include <signal.h>
    44# include "mysql.h"
     5# include "limits.h"
    56
    67# define DVO_MAX_PATH 1024
     
    3839int          PARALLEL_MANUAL;
    3940int          PARALLEL_SERIAL;
     41
     42char        *TIME_START;
     43char        *TIME_END;
     44
     45int          PHOTCODE_START;
     46int          PHOTCODE_END;
    4047
    4148char        *SINGLE_CPT;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvopsps/src/initialize_dvopsps.c

    r35206 r37067  
    22
    33void usage_dvopsps () {
    4   fprintf (stderr, "USAGE: dvopsps (mode) [dbinfo] (mode) [options]\n");
     4  fprintf (stderr, "USAGE: dvopsps (mode) [dbinfo] [options]\n");
    55  fprintf (stderr, "    mysql database info is supplied with these:\n");
    66  fprintf (stderr, "    -dbhost : database host machine\n");
     
    1111  fprintf (stderr, "    -v : verbose mode\n");
    1212  fprintf (stderr, "    -region Rmin Rmax Dmin Dmax\n");
     13  fprintf (stderr, "    -cpt n0000/0000.00 : limit to the named cpt file\n");
    1314  fprintf (stderr, "    -parallel : run in parallel mode\n");
     15  fprintf (stderr, "    -insert-remote : in parallel mode, the client sends the data to the dbhost\n");
     16  fprintf (stderr, "    -time-start YYYY/MM/DD,hh:mm:ss : limit detections to >= this time\n");
     17  fprintf (stderr, "    -time-end   YYYY/MM/DD,hh:mm:ss : limit detections to <  this time\n");
     18
     19  fprintf (stderr, "    -photcode-start NN : limit detections to >= this photcode number\n");
     20  fprintf (stderr, "    -photcode-end   NN : limit detections to <  this photcode number\n");
     21  fprintf (stderr, "\n");
     22
     23  fprintf (stderr, " (mode) is one of detections, objects, skytable\n");
     24
     25  fprintf (stderr, "\n");
    1426  fprintf (stderr, "    -h     : this help list\n");
    1527  fprintf (stderr, "    -help  : this help list\n");
    1628  fprintf (stderr, "    --h    : this help list\n");
    1729  fprintf (stderr, "    --help : this help list\n");
     30
    1831  fprintf (stderr, "    Note that the dvo db can be specified by -D CATDIR (directory)\n");
    1932  exit (2);
     
    110123  if ((N = get_argument (argc, argv, "-insert-remote"))) {
    111124    SAVE_REMOTE = FALSE;
     125    remove_argument (N, &argc, argv);
     126  }
     127
     128  TIME_START = NULL;
     129  if ((N = get_argument (argc, argv, "-time-start"))) {
     130    remove_argument (N, &argc, argv);
     131    TIME_START = strcreate(argv[N]);
     132    remove_argument (N, &argc, argv);
     133    time_t TIME_START_SEC;
     134    if (!ohana_str_to_time (TIME_START, &TIME_START_SEC)) {
     135      fprintf (stderr, "error with starting time given by -time-start: %s\n", TIME_START);
     136      exit (2);
     137    }
     138  }
     139
     140  TIME_END = NULL;
     141  if ((N = get_argument (argc, argv, "-time-end"))) {
     142    remove_argument (N, &argc, argv);
     143    TIME_END = strcreate(argv[N]);
     144    remove_argument (N, &argc, argv);
     145    time_t TIME_END_SEC;
     146    if (!ohana_str_to_time (TIME_END, &TIME_END_SEC)) {
     147      fprintf (stderr, "error with starting time given by -time-end: %s\n", TIME_END);
     148      exit (2);
     149    }
     150  }
     151
     152  PHOTCODE_START = 0;
     153  if ((N = get_argument (argc, argv, "-photcode-start"))) {
     154    remove_argument (N, &argc, argv);
     155    PHOTCODE_START = atoi(argv[N]);
     156    remove_argument (N, &argc, argv);
     157  }
     158
     159  PHOTCODE_END = INT_MAX;
     160  if ((N = get_argument (argc, argv, "-photcode-end"))) {
     161    remove_argument (N, &argc, argv);
     162    PHOTCODE_END = atoi(argv[N]);
    112163    remove_argument (N, &argc, argv);
    113164  }
     
    260311  }
    261312
     313  TIME_START = NULL;
     314  if ((N = get_argument (argc, argv, "-time-start"))) {
     315    remove_argument (N, &argc, argv);
     316    TIME_START = strcreate(argv[N]);
     317    remove_argument (N, &argc, argv);
     318    time_t TIME_START_SEC;
     319    if (!ohana_str_to_time (TIME_START, &TIME_START_SEC)) {
     320      fprintf (stderr, "error with starting time given by -time-start: %s\n", TIME_START);
     321      exit (2);
     322    }
     323  }
     324
     325  TIME_END = NULL;
     326  if ((N = get_argument (argc, argv, "-time-end"))) {
     327    remove_argument (N, &argc, argv);
     328    TIME_END = strcreate(argv[N]);
     329    remove_argument (N, &argc, argv);
     330    time_t TIME_END_SEC;
     331    if (!ohana_str_to_time (TIME_END, &TIME_END_SEC)) {
     332      fprintf (stderr, "error with starting time given by -time-end: %s\n", TIME_END);
     333      exit (2);
     334    }
     335  }
     336
     337  PHOTCODE_START = 0;
     338  if ((N = get_argument (argc, argv, "-photcode-start"))) {
     339    remove_argument (N, &argc, argv);
     340    PHOTCODE_START = atoi(argv[N]);
     341    remove_argument (N, &argc, argv);
     342  }
     343
     344  PHOTCODE_END = INT_MAX;
     345  if ((N = get_argument (argc, argv, "-photcode-end"))) {
     346    remove_argument (N, &argc, argv);
     347    PHOTCODE_END = atoi(argv[N]);
     348    remove_argument (N, &argc, argv);
     349  }
     350
    262351  VERBOSE = FALSE;
    263352  if ((N = get_argument (argc, argv, "-v"))) {
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvopsps/src/insert_detections_dvopsps.c

    r35804 r37067  
    22# define USE_MYSQL 1
    33// # define SAVE_REMOTE 1
    4 
    5 # define MARKTIME(MSG,...) {                    \
    6     float dtime;                                \
    7     gettimeofday (&stop, (void *) NULL);        \
    8     dtime = DTIME (stop, start);                \
    9     fprintf (stderr, MSG, __VA_ARGS__); }
    104
    115// we have two ways of writing to the mysql database:
     
    153147    if (SAVE_REMOTE) { snprintf (tmpline, 1024, "%s -save %s", command, table->hosts[i].results); strcpy (command, tmpline); }
    154148
     149    // some filters -- these are the detections we skip
     150    if (TIME_START) { snprintf (tmpline, 1024, "%s -time-start %s", command, TIME_START); strcpy (command, tmpline); }
     151    if (TIME_END)   { snprintf (tmpline, 1024, "%s -time-end %s",   command, TIME_END);   strcpy (command, tmpline); }
     152   
     153    if (PHOTCODE_START > 0)      { snprintf (tmpline, 1024, "%s -photcode-start %d", command, PHOTCODE_START); strcpy (command, tmpline); }
     154    if (PHOTCODE_END <= INT_MAX) { snprintf (tmpline, 1024, "%s -photcode-end %d",   command, PHOTCODE_END);   strcpy (command, tmpline); }
     155
    155156    fprintf (stderr, "command: %s\n", command);
    156157
     
    238239  buffer.Nalloc = 0;
    239240
    240   struct timeval start, stop;
    241 
    242241  if (Ndetections == 0) return TRUE;
    243242
     
    247246  int Ninsert = 0;
    248247
    249   gettimeofday (&start, (void *) NULL);
     248  INITTIME;
    250249  for (i = 0; i < Ndetections; i++) {
    251250
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c

    r35777 r37067  
    11# include "dvopsps.h"
    22# define DEBUG 0
    3 
    4 # define MARKTIME(MSG,...) {                    \
    5     float dtime;                                \
    6     gettimeofday (&stop, (void *) NULL);        \
    7     dtime = DTIME (stop, start);                \
    8     fprintf (stderr, MSG, __VA_ARGS__); }
    93
    104int Ndetections = 0;
     
    2923  }
    3024
     25  time_t TIME_START_SEC = 0;
     26  time_t TIME_END_SEC   = 0;
     27  if (TIME_START) ohana_str_to_time (TIME_START, &TIME_START_SEC); // we validate this in the args.c
     28  if (TIME_END)   ohana_str_to_time (TIME_END,   &TIME_END_SEC);   // we validate this in the args.c
     29
    3130  for (i = 0; i < catalog[0].Naverage; i++) {
    3231
     
    4039      Average *average = &catalog->average[i];
    4140      Measure *measure = &catalog->measure[m + j];
     41
     42      // some filters -- these are the detections we skip
     43      if (TIME_START && (measure->t < TIME_START_SEC)) continue;
     44      if (TIME_END   && (measure->t >=  TIME_END_SEC)) continue;
     45
     46      if (measure->photcode < PHOTCODE_START) continue;
     47      if (measure->photcode >=  PHOTCODE_END) continue;
     48
    4249      PhotCode *code = GetPhotcodebyCode(measure->photcode);
    4350
     
    5562      detections[Ndetections].airMass      = measure->airmass;
    5663      detections[Ndetections].expTime      = pow(10.0, 0.4 * measure->dt);    // expTime
    57       detections[Ndetections].ra           = average->R - measure->dR / 3600.;    // ra
    58       detections[Ndetections].dec          = average->D - measure->dD / 3600.;    // dec
     64      detections[Ndetections].ra           = measure->R;    // ra
     65      detections[Ndetections].dec          = measure->D;    // dec
    5966      detections[Ndetections].raErr        = measure->dXccd * 0.01 * fabs(measure->pltscale); // estimate of raErr
    6067      detections[Ndetections].decErr       = measure->dYccd * 0.01 * fabs(measure->pltscale); // estimate of decErr
     
    8794}
    8895
     96time_t TIME_START_SEC = 0;
     97time_t TIME_END_SEC   = INT_MAX;
     98
    8999int insert_detections_dvopsps_catalog (Catalog *catalog, MYSQL *mysql) {
    90100
    91101  off_t i, j;
    92102  int missingID = 0;
    93   struct timeval start, stop;
    94103
    95104  IOBuffer buffer;
     
    101110  off_t found = 0;
    102111
    103   gettimeofday (&start, (void *) NULL);
     112  INITTIME;
    104113  insert_detections_mysql_init (&buffer);
    105114  int Ninsert = 0;
     
    108117  int status = TRUE;
    109118
     119  if (TIME_START) ohana_str_to_time (TIME_START, &TIME_START_SEC); // we validate this in the args.c
     120  if (TIME_END)   ohana_str_to_time (TIME_END,   &TIME_END_SEC);   // we validate this in the args.c
     121
    110122  // NOTE for testing, just do a few objects
    111123  if (!mysql) {
     
    121133    for (j = 0; j < average[i].Nmeasure; j++) {
    122134
     135      off_t Nmeas = m + j;
     136
     137      // some filters -- these are the detections we skip (not an error, just skipped)
     138      if (TIME_START && (measure[Nmeas].t < TIME_START_SEC)) continue;
     139      if (TIME_END   && (measure[Nmeas].t >=  TIME_END_SEC)) continue;
     140 
     141      if (measure[Nmeas].photcode < PHOTCODE_START) continue;
     142      if (measure[Nmeas].photcode >=  PHOTCODE_END) continue;
     143
    123144      // XXX check return status
    124       if (!insert_detections_mysql_value (&buffer, &average[i], &measure[m+j])) {
     145      if (!insert_detections_mysql_value (&buffer, &average[i], &measure[Nmeas])) {
    125146        fprintf (stderr, "failure to insert detections in mysql\n");
    126147        status = FALSE;
     
    198219  float zp = code->C * 0.001 + code->K * (measure->airmass - 1) - measure->Mcal;
    199220  float exptime = pow(10.0, 0.4 * measure->dt);
    200   double ra  = average->R - measure->dR / 3600.0;
    201   double dec = average->D - measure->dD / 3600.0;
     221  double ra  = measure->R;
     222  double dec = measure->D;
    202223  double dR = measure->dXccd * 0.01 * fabs(measure->pltscale);
    203224  double dD = measure->dYccd * 0.01 * fabs(measure->pltscale);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvopsps/src/insert_objects_dvopsps_catalog.c

    r35450 r37067  
    22# define DEBUG 0
    33
    4 # define MARKTIME(MSG,...) {                    \
    5     float dtime;                                \
    6     gettimeofday (&stop, (void *) NULL);        \
    7     dtime = DTIME (stop, start);                \
    8     fprintf (stderr, MSG, __VA_ARGS__); }
    9 
    104int insert_objects_dvopsps_catalog (Catalog *catalog, char *basename, MYSQL *mysql) {
    115
    126  off_t i;
    137  int missingID = 0;
    14   struct timeval start, stop;
    158
    169  IOBuffer ave_buffer, sec_buffer;
     
    3124  insert_objects_mysql_create_tables (cleanname, mysql);
    3225
    33   gettimeofday (&start, (void *) NULL);
     26  INITTIME;
    3427  insert_objects_mysql_init (&ave_buffer, &sec_buffer, cleanname);
    3528  int Ninsert = 0;
     
    292285  PrintIOBuffer (ave_buffer, "%d, ",  average->measureOffset); 
    293286  PrintIOBuffer (ave_buffer, "%d, ",  average->missingOffset); 
    294   PrintIOBuffer (ave_buffer, "%d, ",  average->extendOffset);   
     287  PrintIOBuffer (ave_buffer, "%d, ",  0); // was : average->extendOffset);   
    295288  PrintIOBuffer (ave_buffer, "%u, ",  average->flags);         
    296289  PrintIOBuffer (ave_buffer, "%u, ",  average->photFlagsUpper);
     
    323316    float stackPSFMag    = -999.0;
    324317    float stackPSFMagErr = -999.0;
    325     if (isfinite(secfilt->dFluxPSF) && isfinite(secfilt->FluxPSF) && (secfilt->dFluxPSF > 0.0)) {
    326       float SN = secfilt->FluxPSF / secfilt->dFluxPSF;
     318    if (isfinite(secfilt->dFpsfStk) && isfinite(secfilt->FpsfStk) && (secfilt->dFpsfStk > 0.0)) {
     319      float SN = secfilt->FpsfStk / secfilt->dFpsfStk;
    327320      if (SN > 3.0) {
    328         stackPSFMag = -2.5 * log10(secfilt->FluxPSF) + 8.9;
    329         stackPSFMagErr = secfilt->dFluxPSF / secfilt->FluxPSF;
     321        stackPSFMag = -2.5 * log10(secfilt->FpsfStk) + 8.9;
     322        stackPSFMagErr = secfilt->dFpsfStk / secfilt->FpsfStk;
    330323      }
    331324    }
     
    333326    float stackKronMag    = -999.0;
    334327    float stackKronMagErr = -999.0;
    335     if (isfinite(secfilt->dFluxKron) && isfinite(secfilt->FluxKron) && (secfilt->dFluxKron > 0.0)) {
    336       float SN = secfilt->FluxKron / secfilt->dFluxKron;
     328    if (isfinite(secfilt->dFkronStk) && isfinite(secfilt->FkronStk) && (secfilt->dFkronStk > 0.0)) {
     329      float SN = secfilt->FkronStk / secfilt->dFkronStk;
    337330      if (SN > 3.0) {
    338         stackKronMag = -2.5 * log10(secfilt->FluxKron) + 8.9;
    339         stackKronMagErr = secfilt->dFluxKron / secfilt->FluxKron;
     331        stackKronMag = -2.5 * log10(secfilt->FkronStk) + 8.9;
     332        stackKronMagErr = secfilt->dFkronStk / secfilt->FkronStk;
    340333      }
    341334    }
     
    347340    PRINT_FLOAT(sec_buffer, meanKronMagErr,  "%.6f, "); // umag precision
    348341    PRINT_FLOAT(sec_buffer, meanPSFMagErr,   "%.6f, "); // umag precision
    349     PRINT_FLOAT(sec_buffer, secfilt->Xm,    "%.6f, ");
     342    PRINT_FLOAT(sec_buffer, secfilt->Mchisq, "%.6f, ");
    350343    PRINT_FLOAT(sec_buffer, stackPSFMag,     "%.6f, "); // umag precision
    351344    PRINT_FLOAT(sec_buffer, stackPSFMagErr,  "%.6f, "); // umag precision
    352345    PRINT_FLOAT(sec_buffer, stackKronMag,    "%.6f, "); // umag precision
    353346    PRINT_FLOAT(sec_buffer, stackKronMagErr, "%.6f, "); // 0.36 umag precision
    354     PrintIOBuffer (sec_buffer, "%u,  ", secfilt->flags);       
    355     PrintIOBuffer (sec_buffer, "%hd, ", secfilt->Ncode);       
    356     PrintIOBuffer (sec_buffer, "%hd, ", secfilt->Nused);       
    357     PrintIOBuffer (sec_buffer, "%hd, ", secfilt->M_20);         
    358     PrintIOBuffer (sec_buffer, "%hd, ", secfilt->M_80);         
     347    PrintIOBuffer (sec_buffer, "%u,   ", secfilt->flags);       
     348    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->Ncode);       
     349    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->Nused);       
     350    PrintIOBuffer (sec_buffer, "%.6f, ", secfilt->Mmin);         
     351    PrintIOBuffer (sec_buffer, "%.6f, ", secfilt->Mmax);         
    359352    PrintIOBuffer (sec_buffer, "%hd, ", secfilt->ubercalDist); 
    360     PrintIOBuffer (sec_buffer, "%hd, ", secfilt->Mstdev);       
     353    PrintIOBuffer (sec_buffer, "%.6f, ", secfilt->Mstdev);       
    361354    PrintIOBuffer (sec_buffer, "%lu  ", secfilt->stackDetectID);
    362355    PrintIOBuffer (sec_buffer, "),\n");
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvopsps/src/insert_skytable.c

    r35098 r37067  
    22# define DEBUG 1
    33# define USE_MYSQL 1
    4 
    5 # define MARKTIME(MSG,...) {                    \
    6     float dtime;                                \
    7     gettimeofday (&stop, (void *) NULL);        \
    8     dtime = DTIME (stop, start);                \
    9     fprintf (stderr, MSG, __VA_ARGS__); }
    104
    115// determine the relevant catalogs, launch parallel clients if desired
     
    137
    148  off_t i;
    15   struct timeval start, stop;
    169  SkyTable *sky = NULL;
    1710
     
    3427# endif
    3528
    36   gettimeofday (&start, (void *) NULL);
     29  INITTIME;
     30
    3731  insert_skytable_mysql_init (&buffer);
    3832  int Ninsert = 0;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvosplit/src/dvosplit.c

    r33963 r37067  
    1616  ConfigInit (&argc, argv);
    1717  args (argc, argv);
     18
     19  /*
     20  fprintf (stderr,
     21  "this program has the ability to split dvo catalogs one file (cpt, cpm, etc) at a time.
     22  however, new updates to the cpm format requires the average RA,DEC coords to load the
     23  measures.  update the code to handle that first");
     24  exit (2);
     25  */
    1826
    1927  CATDIR = strcreate (argv[1]);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvosplit/src/split_averages.c

    r33656 r37067  
    11# include "dvosplit.h"
    2 # define NROWS 100000 /* ~10MB per block for measures */
     2# define NROWS 1000000 /* ~10MB per block for measures */
    33# define DNOUT 1000
    44
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/dvosplit/src/split_measures.c

    r33656 r37067  
    11# include "dvosplit.h"
    2 # define NROWS 100000 /* ~10MB per row for measures */
     2# define NROWS 1000000 /* ~10MB per row for measures */
    33# define DNOUT 1000
    44
     
    1919
    2020  // split out the measure entries:
    21   incatalog[0].catflags = LOAD_MEAS;
     21  incatalog[0].catflags = LOAD_MEAS | LOAD_AVES | LOAD_SECF;
     22
    2223  // if ((incatalog[0].catformat == DVO_FORMAT_ELIXIR) || (incatalog[0].catformat == DVO_FORMAT_LONEOS)) {
    2324  //   // for these two formats, we need the average and secfilt values around until we do the measures...
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/fixcat/src/gcatstats.c

    r27435 r37067  
    5252  catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
    5353  catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
    54   strcpy (catstats[0].coords.ctype, "RA---TAN");
     54  strcpy (catstats[0].coords.ctype, "DEC--TAN");
    5555
    5656  X1 = catstats[0].X;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/gastro/src/gstars.c

    r34088 r37067  
    7979  if (!strcasecmp (ROUGH_ASTROMETRY, "config")) {
    8080    /* default values for coords */
    81     strcpy (coords[0].ctype, "RA---TAN");
     81    strcpy (coords[0].ctype, "DEC--TAN");
    8282    coords[0].pc1_1 = CCD_PC1_1; coords[0].pc1_2 = CCD_PC1_2;
    8383    coords[0].pc2_1 = CCD_PC2_1; coords[0].pc2_2 = CCD_PC2_2;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/gastro2/src/coordtest.c

    r8300 r37067  
    8585  fit_eval ();
    8686
    87   strcpy (coords.ctype, "RA---PLY");
     87  strcpy (coords.ctype, "DEC--PLY");
    8888  coords.crval1 = 0.0;
    8989  coords.crval2 = 0.0;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/gastro2/src/gstars2.c

    r34088 r37067  
    2828
    2929  /* default values for coords */
    30   strcpy (Target[0].coords.ctype, "RA---TAN");
     30  strcpy (Target[0].coords.ctype, "DEC--TAN");
    3131  Target[0].coords.pc1_1 = CCD_PC1_1; Target[0].coords.pc1_2 = CCD_PC1_2;
    3232  Target[0].coords.pc2_1 = CCD_PC2_1; Target[0].coords.pc2_2 = CCD_PC2_2;
     
    125125  /* read from FITS table or from text table */
    126126  /* Is NAXIS == 0 a better test?? */
    127   gfits_scan_alt (&Target[0].header, "NAXIS",  "%t", 1, &naxis);
     127  gfits_scan_alt (&Target[0].header, "NAXIS",  "%d", 1, &naxis);
    128128  if ((naxis == 0) && !TEXTMODE) {
    129129    Nskip = gfits_data_size (&Target[0].header);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/getstar

  • branches/eam_branches/ipp-ops-20130712/Ohana/src/getstar/src/GetFileMode.c

    r34088 r37067  
    88  int simple, extend, haveNaxis, haveCTYPE;
    99
     10  // NOTE target of %t must be int length
    1011  gfits_scan_alt (header, "SIMPLE", "%t", 1, &simple);
    1112  haveNaxis = gfits_scan (header, "NAXIS",  "%d", 1, &Naxis);
    12   haveCTYPE = gfits_scan (header, "CTYPE1", "%s", 1, ctype);
     13  haveCTYPE = gfits_scan (header, "CTYPE2", "%s", 1, ctype);
    1314
    1415  gfits_scan_alt (header, "EXTEND", "%t", 1, &extend);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/getstar/src/MatchImages.c

    r34430 r37067  
    3636    tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    3737    tcoords.Npolyterms = 1;
    38     strcpy (tcoords.ctype, "RA---TAN");
     38    strcpy (tcoords.ctype, "DEC--TAN");
    3939    /* register so image->sky conversions below have correct mosaic */
    4040  } else {
     
    4444    tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    4545    tcoords.Npolyterms = 1;
    46     strcpy (tcoords.ctype, "RA---TAN");
     46    strcpy (tcoords.ctype, "DEC--TAN");
    4747  }
    4848
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/getstar/src/ReadImageFiles.c

    r34088 r37067  
    138138          !strcmp (tmpword, "PS1_V1") || 
    139139          !strcmp (tmpword, "PS1_V2") || 
    140           !strcmp (tmpword, "PS1_V3")) {
     140          !strcmp (tmpword, "PS1_V3") || 
     141          !strcmp (tmpword, "PS1_V4") || 
     142          !strcmp (tmpword, "PS1_V5")) {
    141143
    142144          exttype[Nimage] = strcreate (tmpword);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/getstar/src/dvoImagesAtCoords.c

  • branches/eam_branches/ipp-ops-20130712/Ohana/src/getstar/src/select_by_region.c

    r35066 r37067  
    7373        for (m = 0; m < catalog[0].average[i].Nmeasure; m++) {
    7474          if (catalog[0].measure[offset + m].photcode == code) {
    75             mag = PhotRel (&catalog[0].measure[offset + m], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt]);
     75            mag = PhotRel (&catalog[0].measure[offset + m], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], MAG_CLASS_PSF);
    7676            break;
    7777          }
     
    126126        for (m = 0; m < catalog[0].average[i].Nmeasure; m++) {
    127127          if (catalog[0].measure[offset + m].photcode == code) {
    128             mag = PhotRel (&catalog[0].measure[offset + m], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt]);
     128            mag = PhotRel (&catalog[0].measure[offset + m], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], MAG_CLASS_PSF);
    129129            break;
    130130          }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/getstar/src/write_getstar_ps1_dev_0.c

    r21508 r37067  
    6161      for (m = 0; m < average[i].Nmeasure; m++) {
    6262        if (measure[offset + m].photcode == code_c0) {
    63           output[i].mag = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
     63          output[i].mag = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt], MAG_CLASS_PSF);
    6464          break;
    6565        }
     
    7575      for (m = 0; m < average[i].Nmeasure; m++) {
    7676        if (measure[offset + m].photcode == code_c1) {
    77           output[i].c1 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
     77          output[i].c1 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt], MAG_CLASS_PSF);
    7878          break;
    7979        }
     
    8989      for (m = 0; m < average[i].Nmeasure; m++) {
    9090        if (measure[offset + m].photcode == code_c2) {
    91           output[i].c2 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
     91          output[i].c2 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt], MAG_CLASS_PSF);
    9292          break;
    9393        }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/getstar/src/write_getstar_ps1_dev_1.c

    r21508 r37067  
    6464      for (m = 0; m < average[i].Nmeasure; m++) {
    6565        if (measure[offset + m].photcode == code_c0) {
    66           output[i].mag = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
     66          output[i].mag = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt], MAG_CLASS_PSF);
    6767          break;
    6868        }
     
    7878      for (m = 0; m < average[i].Nmeasure; m++) {
    7979        if (measure[offset + m].photcode == code_c1) {
    80           output[i].c1 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
     80          output[i].c1 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt], MAG_CLASS_PSF);
    8181          break;
    8282        }
     
    9292      for (m = 0; m < average[i].Nmeasure; m++) {
    9393        if (measure[offset + m].photcode == code_c2) {
    94           output[i].c2 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
     94          output[i].c2 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt], MAG_CLASS_PSF);
    9595          break;
    9696        }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/getstar/src/write_getstar_ps1_dev_2.c

    r21508 r37067  
    7070      for (m = 0; m < average[i].Nmeasure; m++) {
    7171        if (measure[offset + m].photcode == code_c0) {
    72           output[i].mag = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
     72          output[i].mag = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt], MAG_CLASS_PSF);
    7373          break;
    7474        }
     
    8484      for (m = 0; m < average[i].Nmeasure; m++) {
    8585        if (measure[offset + m].photcode == code_c1) {
    86           output[i].c1 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
     86          output[i].c1 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt], MAG_CLASS_PSF);
    8787          break;
    8888        }
     
    9898      for (m = 0; m < average[i].Nmeasure; m++) {
    9999        if (measure[offset + m].photcode == code_c2) {
    100           output[i].c2 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
     100          output[i].c2 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt], MAG_CLASS_PSF);
    101101          break;
    102102        }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/kapa2/include/constants.h

    r35766 r37067  
    1515// XXX for the moment, this is set to match the values in SetColorScale3D_CC
    1616# define NPIXELS_STATIC 128
    17 // # define NPIXELS_STATIC 1000
     17// # define NPIXELS_STATIC 4600 -- if we want fullcolor to work, need this
    1818
    1919# define PAD1  3
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/kapa2/src/CheckPipe.c

    r29938 r37067  
    11# include "Ximage.h"
     2# include <errno.h>
    23# define STRCONST(A) ((int)(0x1000000*A[0] + 0x10000*A[1] + 0x100*A[2] + 0x1*A[3]))
    34
     
    4142  word[4] = 0;
    4243  switch (status) {
    43   case -1:                          /* no input from pipe: continue */
    44     return (TRUE);
     44  case -1:
     45    if (errno == EAGAIN) {
     46      /* no input from pipe: continue */
     47      return (TRUE);
     48    }
     49    perror ("exiting due to problem with socket connection in CheckPipe");
     50    return (FALSE);
    4551    break;
    4652
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/kapa2/src/DrawObjects.c

    r35416 r37067  
    608608    }
    609609  }
     610  if (object[0].ptype == 12) {  /* filled triangle (down) */
     611    XPoint points[4];
     612    for (i = 0; i < object[0].Npts; i++) {
     613      if (!(finite(x[i]) && finite(y[i]))) continue;
     614      sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     615      sy = x[i]*myi + y[i]*myj + by + YCENTER;
     616      if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     617          (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     618        if (scaleColor) {
     619          if (!finite(z[i])) continue;
     620          int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     621          XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     622        }
     623        D = scaleSize ? dz*z[i] : ds;
     624        points[0].x = sx - D;  points[0].y = sy - 0.58*D; 
     625        points[1].x = sx + D;  points[1].y = sy - 0.58*D; 
     626        points[2].x = sx;      points[2].y = sy + 1.15*D; 
     627        points[3].x = sx - D;  points[3].y = sy - 0.58*D; 
     628        XFillPolygon (graphic->display, graphic->window, graphic->gc, points, 4, Convex, CoordModeOrigin);
     629      }
     630    }
     631  }
    610632  if (object[0].ptype == 100) { /* connect a pair of points */
    611633
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/kapa2/src/EventLoop.c

    r21153 r37067  
    11# include "Ximage.h"
     2# define DEBUG 0
    23
    34/* list events being selected below, all other masks are ignored */
     
    67int LastEvent (Display *display, int type, XEvent *event) {
    78
    8   int found;
     9  int found, Nfound;
    910
    1011  found = FALSE;
     12  Nfound = 0;
    1113  while (XCheckTypedEvent (display, type, event)) {
     14    // If the link is slow, then I should wait a little while for some config events to
     15    // build up (typically, the window is being dragged around, so we get a whole series of
     16    // config events.  the flush / sync time is slow on a slow link, so we should try to wait
     17    // for the config events to stop, but on a timescale deteremined by the flush/sync time
     18    // if (type == ConfigureNotify) fprintf (stderr, "config (%d)\n", Nfound);
     19    Nfound ++;
    1220    found = TRUE;
     21  }
     22  if (DEBUG && found) {
     23    if (type == ConfigureNotify) fprintf (stderr, "config (%d)\n", Nfound);
     24    if (type == CirculateNotify) fprintf (stderr, "circul (%d)\n", Nfound);
     25    if (type == Expose) fprintf (stderr, "expose (%d)\n", Nfound);
     26  }
     27
     28  // if I have a ConfigureNotify event, I should purge all Expose events as well:
     29  if (found && (type == ConfigureNotify)) {
     30    XEvent discard;
     31    while (XCheckTypedEvent (display, Expose, &discard));
    1332  }
    1433  return (found);
     
    3857
    3958    if (XEventsQueued (display, QueuedAfterFlush) < 1) {
    40       /* fprintf (stderr, "."); */
    4159      usleep (50000);
    4260      continue;
    4361    }
    4462
     63    // If I have a config event, I want to also purge all expose events
     64
    4565    /* grab the last entry for these events */
    46     if (LastEvent (display, ConfigureNotify, &event)) Reconfig (&event);
    47     if (LastEvent (display, CirculateNotify, &event)) Reconfig (&event);
    48     if (LastEvent (display, Expose,          &event)) Refresh ();
     66    if (LastEvent (display, ConfigureNotify, &event)) { Reconfig (&event); continue; }
     67    if (LastEvent (display, CirculateNotify, &event)) { Reconfig (&event); continue; }
     68    if (LastEvent (display, Expose,          &event)) { Refresh (); continue; }
    4969    if (LastEvent (display, MappingNotify,   &event)) XRefreshKeyboardMapping ((XMappingEvent *) &event);
    5070    if (LastEvent (display, MotionNotify,    &event)) UpdatePointer (graphic, (XMotionEvent *) &event);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/kapa2/src/FlushDisplay.c

    r21153 r37067  
    3030
    3131  if (flush) {
    32     XFlush (graphic->display);
     32    // I changed XFlush to XSync to avoid lag
     33    // of the display (build up of config events)
     34    XSync (graphic->display, FALSE);
    3335    reftime = now;
    3436  }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/kapa2/src/Graphs.c

    r29539 r37067  
    6464  graph[0].data.coords.crpix2 = 0.0;
    6565  graph[0].data.coords.cdelt1 = graph[0].data.coords.cdelt2 = 1.0;
    66   strcpy (graph[0].data.coords.ctype, "RA---LIN");
     66  strcpy (graph[0].data.coords.ctype, "DEC--LIN");
    6767  strcpy (graph[0].data.axis, "2222");
    6868  strcpy (graph[0].data.ticks, "2222");
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/kapa2/src/Image.c

    r29938 r37067  
    1818  channel->coords.crpix2 = 0.0;
    1919  channel->coords.cdelt1 = channel->coords.cdelt2 = 1.0;
    20   strcpy (channel->coords.ctype, "RA---LIN");
     20  strcpy (channel->coords.ctype, "DEC--LIN");
    2121  channel->coords.Npolyterms = 0;
    2222
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/kapa2/src/Refresh.c

    r27790 r37067  
    4747  Y0 = graphic[0].dy - graphic[0].dy * section[0].y - dY;
    4848  X0 = graphic[0].dx * section[0].x;
    49   // fprintf (stderr, "section: (%s) %d %d - %d %d\n", section[0].name, X0, Y0, dX, dY);
    5049
    5150  XFillRectangle (graphic[0].display,  graphic[0].window, graphic[0].gc, X0, Y0, dX, dY);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/kapa2/src/bDrawObjects.c

    r35416 r37067  
    315315        D = scaleSize ? dz*z[i] : ds;
    316316        FillRectangle (buffer, sx, sy, 2*D, 2*D);
     317        // plot range saturated by bDrawRectFill
    317318      }
    318319    }
     
    335336        D = scaleSize ? dz*z[i] : ds;
    336337        DrawRectangle (buffer, sx, sy, 2*D, 2*D);
     338        // plot range saturated by bDrawRectOpen
    337339      }
    338340    }
     
    356358        DrawLine (buffer, sx - D, sy, sx + D, sy);
    357359        DrawLine (buffer, sx, sy - D, sx, sy + D);
     360        // out-of-range points skipped by bDrawPoint
    358361      }
    359362    }
     
    377380        DrawLine (buffer, sx + D, sy - D, sx - D, sy + D);
    378381        DrawLine (buffer, sx - D, sy - D, sx + D, sy + D);
     382        // out-of-range points skipped by bDrawPoint
    379383      }
    380384    }
     
    398402        // FillTriangle (buffer, sx - D, sy - 0.58*D, sx + D, sy - 0.58*D, sx, sy + 1.15*D);
    399403        FillTriangle (buffer, sx, sy + 0.58*D, D, -1.73*D);
     404        // out-of-range points skipped by bDrawPoint
    400405      }
    401406    }
     
    418423        D = scaleSize ? dz*z[i] : ds;
    419424        OpenTriangle (buffer, sx - D, sy + 0.58*D, sx + D, sy + 0.58*D, sx, sy - 1.15*D);
     425        // out-of-range points skipped by bDrawPoint
    420426      }
    421427    }
     
    440446        DrawLine (buffer, sx, sy, sx + D, sy - 0.58*D);
    441447        DrawLine (buffer, sx, sy, sx,     sy + 1.15*D);
     448        // out-of-range points skipped by bDrawPoint
    442449      }
    443450    }
     
    460467        D = scaleSize ? dz*z[i] : ds;
    461468        DrawCircle (buffer, sx, sy, D);
     469        // out-of-range points skipped by bDrawPoint
    462470      }
    463471    }
     
    484492        DrawLine (buffer, sx - 0.58*D, sy + 0.81*D, sx - 0.95*D, sy - 0.31*D);
    485493        DrawLine (buffer, sx - 0.95*D, sy - 0.31*D, sx + 0.00*D, sy - 1.00*D);
     494        // out-of-range points skipped by bDrawPoint
    486495      }
    487496    }
     
    509518        DrawLine (buffer, sx + 0.50*D, sy - 0.87*D, sx - 0.50*D, sy - 0.87*D);
    510519        DrawLine (buffer, sx - 0.50*D, sy - 0.87*D, sx -      D, sy);
     520        // out-of-range points skipped by bDrawPoint
    511521      }
    512522    }
     
    529539        D = scaleSize ? dz*z[i] : ds;
    530540        FillCircle (buffer, sx, sy, D);
     541        // out-of-range points skipped by bDrawLineHorizontal
     542      }
     543    }
     544  }
     545  if (object[0].ptype == 12) {  /* filled triangle (down) */
     546    for (i = 0; i < object[0].Npts; i++) {
     547      if (!(finite(x[i]) && finite(y[i]))) continue;
     548      sx = x[i]*mxi + y[i]*mxj + bx;
     549      sy = x[i]*myi + y[i]*myj + by;
     550      if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     551          (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     552      {
     553        if (scaleColor) {
     554          if (!finite(z[i])) continue;
     555          int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     556          buffer->bColor_R = pixel1[pixel];
     557          buffer->bColor_G = pixel2[pixel];
     558          buffer->bColor_B = pixel3[pixel];
     559        }
     560        D = scaleSize ? dz*z[i] : ds;
     561        // FillTriangle (buffer, sx - D, sy - 0.58*D, sx + D, sy - 0.58*D, sx, sy + 1.15*D);
     562        FillTriangle (buffer, sx, sy + 0.58*D, D, 1.73*D);
     563        // out-of-range points skipped by bDrawPoint
    531564      }
    532565    }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/Makefile.Targets

    r34405 r37067  
    1212$(ASRC)/average-ps1-v3.$(ARCH).o \
    1313$(ASRC)/average-ps1-v4.$(ARCH).o \
     14$(ASRC)/average-ps1-v5.$(ARCH).o \
    1415$(ASRC)/average-ps1-ref.$(ARCH).o \
    1516$(ASRC)/secfilt.$(ARCH).o \
     
    2425$(ASRC)/secfilt-ps1-v3.$(ARCH).o \
    2526$(ASRC)/secfilt-ps1-v4.$(ARCH).o \
     27$(ASRC)/secfilt-ps1-v5.$(ARCH).o \
    2628$(ASRC)/secfilt-ps1-ref.$(ARCH).o \
    2729$(ASRC)/measure.$(ARCH).o \
     
    3638$(ASRC)/measure-ps1-v3.$(ARCH).o \
    3739$(ASRC)/measure-ps1-v4.$(ARCH).o \
     40$(ASRC)/measure-ps1-v5.$(ARCH).o \
    3841$(ASRC)/measure-ps1-ref.$(ARCH).o \
     42$(ASRC)/lensing.$(ARCH).o \
     43$(ASRC)/lensing-ps1-v5.$(ARCH).o \
     44$(ASRC)/lensobj.$(ARCH).o \
     45$(ASRC)/lensobj-ps1-v5.$(ARCH).o \
    3946$(ASRC)/missing.$(ARCH).o \
    4047$(ASRC)/photcode.$(ARCH).o \
     
    4754$(ASRC)/photcode-ps1-v3.$(ARCH).o \
    4855$(ASRC)/photcode-ps1-v4.$(ARCH).o \
     56$(ASRC)/photcode-ps1-v5.$(ARCH).o \
    4957$(ASRC)/photcode-ps1-ref.$(ARCH).o \
    5058$(ASRC)/image.$(ARCH).o \
     
    6068$(ASRC)/image-ps1-v3.$(ARCH).o \
    6169$(ASRC)/image-ps1-v4.$(ARCH).o \
     70$(ASRC)/image-ps1-v5.$(ARCH).o \
    6271$(ASRC)/image-ps1-ref.$(ARCH).o \
    6372$(ASRC)/regimage.$(ARCH).o \
     
    7382$(ASRC)/cmf-ps1-sv1.$(ARCH).o \
    7483$(ASRC)/cmf-ps1-sv2.$(ARCH).o \
     84$(ASRC)/cmf-ps1-dv4.$(ARCH).o \
    7585$(ASRC)/cmf-smpdata.$(ARCH).o \
    7686$(ASRC)/getstar-ps1-dev-0.$(ARCH).o \
     
    8494$(ASRC)/FlatCorrectionImage.$(ARCH).o \
    8595$(ASRC)/FlatCorrection.$(ARCH).o
     96
     97# $(ASRC)/cmf-ps1-sv3.$(ARCH).o
    8698
    8799AINCS = \
     
    98110$(AINC)/average-ps1-v3.h \
    99111$(AINC)/average-ps1-v4.h \
     112$(AINC)/average-ps1-v5.h \
    100113$(AINC)/average-ps1-ref.h \
    101114$(AINC)/secfilt.h \
     
    110123$(AINC)/secfilt-ps1-v3.h \
    111124$(AINC)/secfilt-ps1-v4.h \
     125$(AINC)/secfilt-ps1-v5.h \
    112126$(AINC)/secfilt-ps1-ref.h \
    113127$(AINC)/measure.h \
     
    122136$(AINC)/measure-ps1-v3.h \
    123137$(AINC)/measure-ps1-v4.h \
     138$(AINC)/measure-ps1-v5.h \
    124139$(AINC)/measure-ps1-ref.h \
     140$(AINC)/lensing.h \
     141$(AINC)/lensing-ps1-v5.h \
     142$(AINC)/lensobj.h \
     143$(AINC)/lensobj-ps1-v5.h \
    125144$(AINC)/missing.h \
    126145$(AINC)/photcode.h \
     
    133152$(AINC)/photcode-ps1-v3.h \
    134153$(AINC)/photcode-ps1-v4.h \
     154$(AINC)/photcode-ps1-v5.h \
    135155$(AINC)/photcode-ps1-ref.h \
    136156$(AINC)/image.h \
     
    146166$(AINC)/image-ps1-v3.h \
    147167$(AINC)/image-ps1-v4.h \
     168$(AINC)/image-ps1-v5.h \
    148169$(AINC)/image-ps1-ref.h \
    149170$(AINC)/regimage.h \
     
    159180$(AINC)/cmf-ps1-sv1.h \
    160181$(AINC)/cmf-ps1-sv2.h \
     182$(AINC)/cmf-ps1-dv4.h \
    161183$(AINC)/cmf-smpdata.h \
    162184$(AINC)/getstar-ps1-dev-0.h \
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/average-ps1-dev-2.d

    r16810 r37067  
    2525FIELD measureOffset,  OFF_MEASURE, int,             offset to first psf measurement
    2626FIELD missingOffset,  OFF_MISSING, int,             offset to first missing obs
    27 FIELD extendOffset,   OFF_EXTEND,  int,             offset to first extended measurement
     27FIELD refColor,       REF_COLOR,   float,           color of astrometry ref stars
    2828
    2929FIELD code,           code,       unsigned short,   ID code (star; ghost; etc)
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/average-ps1-v1.d

    r21508 r37067  
    3030FIELD measureOffset,  OFF_MEASURE, uint32_t,        offset to first psf measurement
    3131FIELD missingOffset,  OFF_MISSING, uint32_t,        offset to first missing obs
    32 FIELD extendOffset,   OFF_EXTEND,  uint32_t,        offset to first extended measurement
     32FIELD refColor,       REF_COLOR,   float,           color of astrometry ref stars
    3333
    3434# 'flags' was called 'code' prior to 2009.02.07
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/average-ps1-v2.d

    r33647 r37067  
    3535FIELD measureOffset,  OFF_MEASURE, uint32_t,        offset to first psf measurement
    3636FIELD missingOffset,  OFF_MISSING, uint32_t,        offset to first missing obs
    37 FIELD extendOffset,   OFF_EXTEND,  uint32_t,        offset to first extended measurement
     37FIELD refColor,       REF_COLOR,   float,           color of astrometry ref stars
    3838
    3939# 'flags' was called 'code' prior to 2009.02.07
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/average-ps1-v3.d

    r33647 r37067  
    3535FIELD measureOffset,  OFF_MEASURE, uint32_t,        offset to first psf measurement
    3636FIELD missingOffset,  OFF_MISSING, uint32_t,        offset to first missing obs
    37 FIELD extendOffset,   OFF_EXTEND,  uint32_t,        offset to first extended measurement
     37FIELD refColor,       REF_COLOR,   float,           color of astrometry ref stars
    3838
    3939# 'flags' was called 'code' prior to 2009.02.07
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/average-ps1-v4.d

    r34405 r37067  
    3838FIELD measureOffset,  OFF_MEASURE, uint32_t,        offset to first psf measurement
    3939FIELD missingOffset,  OFF_MISSING, uint32_t,        offset to first missing obs
    40 FIELD extendOffset,   OFF_EXTEND,  uint32_t,        offset to first extended measurement
     40FIELD refColor,       REF_COLOR,   float,           color of reference stars
    4141
    4242# 'flags' was called 'code' prior to 2009.02.07
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/average.d

    r34405 r37067  
    22EXTNAME      DVO_AVERAGE
    33TYPE         BINTABLE
    4 SIZE         128
     4SIZE         184
    55DESCRIPTION  DVO Average Object Table
    66
     
    1919FIELD dP,             PAR_ERR,     float,           parallax error,               arcsec
    2020
     21FIELD Rstk,           RA_STK,      double,          RA on stack,                  decimal degrees
     22FIELD Dstk,           DEC_STK,     double,          DEC on stack,                 decimal degrees
     23FIELD dRstk,          RA_STK_ERR,  float,           RA error on stack,            arcsec
     24FIELD dDstk,          DEC_STK_ERR, float,           DEC error on stack,           arcsec
     25
    2126FIELD ChiSqAve,       CHISQ_POS,   float,           astrometry analysis chisq
    2227FIELD ChiSqPM,        CHISQ_PM,    float,           astrometry analysis chisq
     
    3439FIELD Nmeasure,       NMEASURE,    unsigned short,  number of psf measurements
    3540FIELD Nmissing,       NMISSING,    unsigned short,  number of missings
     41FIELD Nlensing,       NLENSING,    unsigned short,  number of lensing measurements
     42FIELD Nlensobj,       NLENSOBJ,    unsigned short,  number of lensing measurements
    3643FIELD Nextend,        NEXTEND,     unsigned short,  number of extended measurements
    3744
    3845FIELD measureOffset,  OFF_MEASURE, int,             offset to first psf measurement
    3946FIELD missingOffset,  OFF_MISSING, int,             offset to first missing obs
    40 FIELD extendOffset,   OFF_EXTEND,  int,             offset to first extended measurement
     47FIELD lensingOffset,  OFF_LENSING, int,             offset to first lensing obs
     48FIELD lensobjOffset,  OFF_LENSOBJ, int,             offset to mean lensing data
     49FIELD extendOffset,   OFF_EXTEND,  int,             offset to extended object entry
     50FIELD paramsOffset,   OFF_PARAMS,  int,             offset to stellar parameter data
     51
     52FIELD refColorBlue,   REF_COLOR_BLUE, float,        color of astrometry ref stars
     53FIELD refColorRed,    REF_COLOR_RED,  float,        color of astrometry ref stars
    4154
    4255# 'flags' was called 'code' prior to 2009.02.07
     
    4962FIELD catID,          CAT_ID,      unsigned int,    unique ID for table in which object was first realized
    5063FIELD extID,          EXT_ID,      uint64_t,        external ID for object (eg PSPS objID)
     64FIELD extIDgc,        EXT_ID_GC,   uint64_t,        external ID for object in galactic coords
    5165
    5266# this structure should only be used for internal representations
     
    5670
    5771# *** 20090206 : new fields : ChiSq, Npos, flags (was code, uint16_t), extID
    58 
    5972# *** 20100331 : new fields needed to assess astrometry analysis quality:
    60 
     73# *** 20140617 : new fields : Rstk, Dstk, dRstk,dDstk, Nlensing, Nlensobj, lensingOffset, lensobjOffset, refColor
    6174
    6275# photflagsUpper & photflagsLower: we have Nmeasures of a given source
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/common.h

    r34088 r37067  
    3232# define rawshort short
    3333
    34 # define DVO_IMAGE_NAME_LEN 121
     34# define DVO_IMAGE_NAME_LEN 117
    3535
    3636/*** rawshort is used to handle the broken pre-autocode photreg tables
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/image-ps1-v2.d

    r30604 r37067  
    4242FIELD     DECo,             DEC_CENTER,           float,          image center,              degrees
    4343FIELD     Radius,           RADIUS,               float,          image radius,              degrees
    44 FIELD     DUMMY,            DUMMY,                float,          dummy
     44FIELD     refColor,         REF_COLOR,            float,          dummy
    4545
    4646# should we define the max length of name as a macro?
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/image-ps1-v3.d

    r33647 r37067  
    4242FIELD     DECo,             DEC_CENTER,           float,          image center,              degrees
    4343FIELD     Radius,           RADIUS,               float,          image radius,              degrees
    44 FIELD     DUMMY,            DUMMY,                float,          dummy
     44FIELD     refColor,         REF_COLOR,            float,          dummy
    4545
    4646# should we define the max length of name as a macro?
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/image-ps1-v4.d

    r34260 r37067  
    4242FIELD     DECo,             DEC_CENTER,           float,          image center,              degrees
    4343FIELD     Radius,           RADIUS,               float,          image radius,              degrees
    44 FIELD     DUMMY,            DUMMY,                float,          dummy
     44FIELD     refColor,         REF_COLOR,            float,          dummy
    4545
    4646# should we define the max length of name as a macro?
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/image.d

    r33963 r37067  
    4444FIELD     DECo,             DEC_CENTER,           float,          image center,              degrees
    4545FIELD     Radius,           RADIUS,               float,          image radius,              degrees
    46 FIELD     DUMMY,            DUMMY,                float,          dummy
     46FIELD     refColorBlue,     REF_COLOR_BLUE,       float,          median astrometry ref color
     47FIELD     refColorRed,      REF_COLOR_RED,        float,          median astrometry ref color
    4748
    48 FIELD     name,             NAME,                 char[121],      name of original image
     49# should we define the max length of name as a macro?
     50FIELD     name,             NAME,                 char[117],      name of original image
    4951FIELD     detection_limit,  DETECTION_LIMIT,      unsigned char,  detection limit,           10*mag
    5052FIELD     saturation_limit, SATURATION_LIMIT,     unsigned char,  saturation limit,          10*mag
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/measure.d

    r35099 r37067  
    22EXTNAME      DVO_MEASURE
    33TYPE         BINTABLE
    4 SIZE         184
     4SIZE         228
    55DESCRIPTION  DVO Detection Measurement Table
    66
    7 FIELD dR,             D_RA,         float,          RA offset,                      arcsec
    8 FIELD dD,             D_DEC,        float,          DEC offset,                     arcsec
    9 FIELD M,              MAG,          float,          catalog mag,                    mag
    10 FIELD Mcal,           M_CAL,        float,          image cal mag,                  mag
    11 FIELD Map,            M_APER,       float,          aperture mag,                   mag
    12 FIELD Mkron,          M_KRON,       float,          kron magnitude,                 mag
    13 FIELD dMkron,         M_KRON_ERR,   float,          kron magnitude error,           mag
    14 FIELD dM,             MAG_ERR,      float,          mag error,                      mag
    15 FIELD dMcal,          MAG_CAL_ERR,  float,          systematic calibration error,   mag
    16 FIELD dt,             M_TIME,       float,          exposure time,                  2.5*log(exptime)
     7FIELD R,              RA,            double,         RA at epoch,                  degrees
     8FIELD D,              DEC,           double,         DEC at epoch,                 degrees
     9FIELD M,              MAG,           float,          catalog mag,                    mag
     10FIELD dM,             MAG_ERR,       float,          mag error,                      mag
     11FIELD Map,            M_APER,        float,          aperture mag,                   mag
     12FIELD dMap,           M_APER,        float,          aperture mag,                   mag
     13FIELD Mkron,          M_KRON,        float,          kron magnitude,                 mag
     14FIELD dMkron,         M_KRON_ERR,    float,          kron magnitude error,           mag
     15FIELD Mcal,           M_CAL,         float,          image cal mag,                  mag
     16FIELD dMcal,          MAG_CAL_ERR,   float,          systematic calibration error,   mag
     17FIELD dt,             M_TIME,        float,          exposure time,                  2.5*log(exptime)
    1718
    1819# for stacks only?
    19 FIELD FluxPSF,        FLUX_PSF,     float,          flux from psf fit,              counts/sec?
    20 FIELD dFluxPSF,       FLUX_PSF_ERR, float,          error on psf flux,              counts/sec?
    21 FIELD FluxKron,       FLUX_KRON,     float,         flux from kron ap,              counts/sec?
    22 FIELD dFluxKron,      FLUX_KRON_ERR, float,         error on kron flux,             counts/sec?
     20FIELD FluxPSF,        FLUX_PSF,      float,         flux from psf fit,              counts/sec
     21FIELD dFluxPSF,       FLUX_PSF_ERR,  float,         error on psf flux,              counts/sec
     22FIELD FluxKron,       FLUX_KRON,     float,         flux from kron ap,              counts/sec
     23FIELD dFluxKron,      FLUX_KRON_ERR, float,         error on kron flux,             counts/sec
     24FIELD FluxAp,         FLUX_AP,       float,         flux from ap,                   counts/sec
     25FIELD dFluxAp,        FLUX_AP_ERR,   float,         error on ap flux,               counts/sec
    2326
    2427# note that with airmass = 1.0 / cos(90 - alt), we have full alt/az representation
     
    3336FIELD Yfix,           Y_FIX,        float,          Y coord after correction,     pixels
    3437
     38FIELD XoffKH,         X_OFF_KH,      float,          X offset from correction,     pixels
     39FIELD YoffKH,         Y_OFF_KH,      float,          Y offset from correction,     pixels
     40FIELD XoffDCR,        X_OFF_DCR,     float,          X offset from correction,     pixels
     41FIELD YoffDCR,        Y_OFF_DCR,     float,          Y offset from correction,     pixels
     42FIELD RoffGAL,        R_OFF_GAL,     float,          RA offset from correction,    arcsec
     43FIELD DoffGAL,        D_OFF_GAL,     float,          DEC offset from correction,   arcsec
     44
    3545# could these be packed into fewer bits?
    3646FIELD Sky,            SKY_FLUX,     float,          local estimate of sky flux,     counts/sec
     
    3848
    3949FIELD t,              TIME,         int,            time in seconds (UNIX)
    40 FIELD t_msec,         TIME_MSEC,    unsigned short, time fraction of second,        milliseconds
    4150FIELD averef,         AVE_REF,      unsigned int,   reference to average entry     
    4251
    4352FIELD detID,          DET_ID,       unsigned int,   detection ID
    44 FIELD imageID,        IMAGE_ID,     unsigned int,   reference to DVO image ID
    4553FIELD objID,          OBJ_ID,       unsigned int,   unique ID for object in table
    4654FIELD catID,          CAT_ID,       unsigned int,   unique ID for table in which object was first realized
     
    4856# PSPS uses a 64-bit detection ID
    4957FIELD extID,          EXT_ID,       uint64_t,       external ID (eg PSPS detID)
     58
     59FIELD imageID,        IMAGE_ID,     unsigned int,   reference to DVO image ID
    5060
    5161# do we need more resolution than a short? should this be a log?
     
    6979FIELD Myy,            MYY,          short,          second moments in pixel coords, 1/100 of pixels^2
    7080
     81# fractional exposure time
     82FIELD t_msec,         TIME_MSEC,    unsigned short, time fraction of second,        milliseconds
     83FIELD photcode,       PHOTCODE,     unsigned short, photcode
     84
    7185# convert this to error in pixels on load?
    7286FIELD dXccd,          X_CCD_ERR,    short,          X coord error on chip,          1/100 of pixels
     
    7791FIELD pltscale,       PLTSCALE,     float,          plate scale,                    arcsec/pixel
    7892
    79 FIELD photcode,       PHOTCODE,     unsigned short, photcode
    8093FIELD dbFlags,        DB_FLAGS,     unsigned int,   flags supplied by analysis in database
    8194FIELD photFlags,      PHOT_FLAGS,   unsigned int,   flags supplied by photometry program
     
    8598#                Changed dbFlags, photFlags : uint16_t to uint64_t
    8699
     100# *** 20140617 : changed: dR,dD -> R,D (removed dependence on average.R,D)
     101                 added: dMap, FluxAp, dFluxAp, (X,Y)off(KH,DCR,GAL)
     102
    87103# XXX unsigned int values are probably not being saved in the FITS file correctly: no BZERO, BSCALE
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/photcode-ps1-v2.d

    r27579 r37067  
    2222FIELD  astromErrScale,    ASTROM_ERR_SCALE,      float,          astrometric error scale
    2323FIELD  astromErrMagScale, ASTROM_ERR_MAG_SCALE,  float,          astrometric error / mag error scale
    24 FIELD  astromPoorMask,    ASTROM_POOR_MASK,      short,          detections matching this mask should only be used in emergencies
    25 FIELD  astromBadMask,     ASTROM_BAD_MASK,       short,          detections matching this mask should not be used
     24FIELD  astromPoorMask,    ASTROM_POOR_MASK,      unsigned short,   detections matching this mask should only be used in emergencies
     25FIELD  astromBadMask,     ASTROM_BAD_MASK,       unsigned short,   detections matching this mask should not be used
    2626FIELD  photomErrSys,      PHOTOM_ERR_SYS,        float,          systematic photometric error
    27 FIELD  photomPoorMask,    PHOTOM_POOR_MASK,      short,          detections matching this mask should only be used in emergencies
    28 FIELD  photomBadMask,     PHOTOM_BAD_MASK,       short,          detections matching this mask should not be used
     27FIELD  photomPoorMask,    PHOTOM_POOR_MASK,      unsigned short,   detections matching this mask should only be used in emergencies
     28FIELD  photomBadMask,     PHOTOM_BAD_MASK,       unsigned short,   detections matching this mask should not be used
    2929
    3030#   dR_total^2 =  dR_sys^2 + AS * dR_obs^2 + MS * dM_obs^2
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/photcode-ps1-v3.d

    r33647 r37067  
    2222FIELD  astromErrScale,    ASTROM_ERR_SCALE,      float,          astrometric error scale
    2323FIELD  astromErrMagScale, ASTROM_ERR_MAG_SCALE,  float,          astrometric error / mag error scale
    24 FIELD  astromPoorMask,    ASTROM_POOR_MASK,      int,            detections matching this mask should only be used in emergencies
    25 FIELD  astromBadMask,     ASTROM_BAD_MASK,       int,            detections matching this mask should not be used
     24FIELD  astromPoorMask,    ASTROM_POOR_MASK,      unsigned int,   detections matching this mask should only be used in emergencies
     25FIELD  astromBadMask,     ASTROM_BAD_MASK,       unsigned int,   detections matching this mask should not be used
    2626FIELD  photomErrSys,      PHOTOM_ERR_SYS,        float,          systematic photometric error
    27 FIELD  photomPoorMask,    PHOTOM_POOR_MASK,      int,            detections matching this mask should only be used in emergencies
    28 FIELD  photomBadMask,     PHOTOM_BAD_MASK,       int,            detections matching this mask should not be used
     27FIELD  photomPoorMask,    PHOTOM_POOR_MASK,      unsigned int,   detections matching this mask should only be used in emergencies
     28FIELD  photomBadMask,     PHOTOM_BAD_MASK,       unsigned int,   detections matching this mask should not be used
    2929
    3030#   dR_total^2 =  dR_sys^2 + AS * dR_obs^2 + MS * dM_obs^2
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/photcode-ps1-v4.d

    r34260 r37067  
    2222FIELD  astromErrScale,    ASTROM_ERR_SCALE,      float,          astrometric error scale
    2323FIELD  astromErrMagScale, ASTROM_ERR_MAG_SCALE,  float,          astrometric error / mag error scale
    24 FIELD  astromPoorMask,    ASTROM_POOR_MASK,      int,            detections matching this mask should only be used in emergencies
    25 FIELD  astromBadMask,     ASTROM_BAD_MASK,       int,            detections matching this mask should not be used
     24FIELD  astromPoorMask,    ASTROM_POOR_MASK,      unsigned int,   detections matching this mask should only be used in emergencies
     25FIELD  astromBadMask,     ASTROM_BAD_MASK,       unsigned int,   detections matching this mask should not be used
    2626FIELD  photomErrSys,      PHOTOM_ERR_SYS,        float,          systematic photometric error
    27 FIELD  photomPoorMask,    PHOTOM_POOR_MASK,      int,            detections matching this mask should only be used in emergencies
    28 FIELD  photomBadMask,     PHOTOM_BAD_MASK,       int,            detections matching this mask should not be used
     27FIELD  photomPoorMask,    PHOTOM_POOR_MASK,      unsigned int,   detections matching this mask should only be used in emergencies
     28FIELD  photomBadMask,     PHOTOM_BAD_MASK,       unsigned int,   detections matching this mask should not be used
    2929
    3030#   dR_total^2 =  dR_sys^2 + AS * dR_obs^2 + MS * dM_obs^2
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/photcode.d

    r33647 r37067  
    2222FIELD  astromErrScale,    ASTROM_ERR_SCALE,      float,          astrometric error scale
    2323FIELD  astromErrMagScale, ASTROM_ERR_MAG_SCALE,  float,          astrometric error / mag error scale
    24 FIELD  astromPoorMask,    ASTROM_POOR_MASK,      int,            detections matching this mask should only be used in emergencies
    25 FIELD  astromBadMask,     ASTROM_BAD_MASK,       int,            detections matching this mask should not be used
     24FIELD  astromPoorMask,    ASTROM_POOR_MASK,      unsigned int,   detections matching this mask should only be used in emergencies
     25FIELD  astromBadMask,     ASTROM_BAD_MASK,       unsigned int,   detections matching this mask should not be used
    2626FIELD  photomErrSys,      PHOTOM_ERR_SYS,        float,          systematic photometric error
    27 FIELD  photomPoorMask,    PHOTOM_POOR_MASK,      int,            detections matching this mask should only be used in emergencies
    28 FIELD  photomBadMask,     PHOTOM_BAD_MASK,       int,            detections matching this mask should not be used
     27FIELD  photomPoorMask,    PHOTOM_POOR_MASK,      unsigned int,   detections matching this mask should only be used in emergencies
     28FIELD  photomBadMask,     PHOTOM_BAD_MASK,       unsigned int,   detections matching this mask should not be used
    2929
    3030#   dR_total^2 =  dR_sys^2 + AS * dR_obs^2 + MS * dM_obs^2
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/secfilt-ps1-v1.d

    r21508 r37067  
    66
    77# elements of data structure / FITS table
    8 FIELD  M,     MAG,      float,                average mag in this band, mags
    9 FIELD  dM,    MAG_ERR,  float,                error on average mag,     mags
    10 FIELD  Xm,    MAG_CHI,  float,                chisq on average mag,     [100*log(value)]
    11 FIELD  Ncode, NCODE,    short,                number of detections in band
    12 FIELD  Nused, NUSED,    short,                number of detections used in average
    13 FIELD  M_20,  MAG_20,   short,                lower 20percent mag,      millimags
    14 FIELD  M_80,  MAG_80,   short,                upper 20percent mag,      millimags
     8FIELD  M,      MAG,      float,                average mag in this band, mags
     9FIELD  dM,     MAG_ERR,  float,                error on average mag,     mags
     10FIELD  Mchisq, MAG_CHI,  float,                chisq on average mag,                  value
     11FIELD  Ncode,  NCODE,    short,                number of detections in band
     12FIELD  Nused,  NUSED,    short,                number of detections used in average
     13FIELD  M_20,   MAG_20,   short,                lower 20percent mag,      millimags
     14FIELD  M_80,   MAG_80,   short,                upper 20percent mag,      millimags
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/secfilt-ps1-v2.d

    r27579 r37067  
    66
    77# elements of data structure / FITS table
    8 FIELD  M,     MAG,      float,                average mag in this band, mags
    9 FIELD  dM,    MAG_ERR,  float,                error on average mag,     mags
    10 FIELD  Xm,    MAG_CHI,  float,                chisq on average mag,     [100*log(value)]
    11 FIELD  flags, FLAGS,    uint32_t,             photometry flags
    12 FIELD  Ncode, NCODE,    short,                number of detections in band
    13 FIELD  Nused, NUSED,    short,                number of detections used in average
    14 FIELD  M_20,  MAG_20,   short,                lower 20percent mag,      millimags
    15 FIELD  M_80,  MAG_80,   short,                upper 20percent mag,      millimags
     8FIELD  M,      MAG,      float,                average mag in this band, mags
     9FIELD  dM,     MAG_ERR,  float,                error on average mag,     mags
     10FIELD  Mchisq, MAG_CHI,  float,                chisq on average mag,     value
     11FIELD  flags,  FLAGS,    uint32_t,             photometry flags
     12FIELD  Ncode,  NCODE,    short,                number of detections in band
     13FIELD  Nused,  NUSED,    short,                number of detections used in average
     14FIELD  M_20,   MAG_20,   short,                lower 20percent mag,      millimags
     15FIELD  M_80,   MAG_80,   short,                upper 20percent mag,      millimags
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/secfilt-ps1-v3.d

    r33963 r37067  
    99FIELD  Map,         MAG_AP,       float,      ave aperture mag in this band,         mags
    1010FIELD  dM,          MAG_ERR,      float,      formal error on average mag,           mags
    11 FIELD  Xm,          MAG_CHI,      float,      chisq on average mag,                  [100*log(value)]
     11FIELD  Mchisq,      MAG_CHI,      float,      chisq on average mag,                  value
    1212FIELD  flags,       FLAGS,        uint32_t,   photometry flags
    1313FIELD  Ncode,       NCODE,        short,      number of detections in band
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/secfilt-ps1-v4.d

    r34620 r37067  
    1111FIELD  dMkron,        MAG_KRON_ERR,    float,      formal error on average kron mag,      mags
    1212FIELD  dM,            MAG_ERR,         float,      formal error on average mag,           mags
    13 FIELD  Xm,            MAG_CHI,         float,      chisq on average mag,                  [100*log(value)]
     13FIELD  Mchisq,        MAG_CHI,         float,      chisq on average mag,                  value
    1414FIELD  FluxPSF,       FLUX_PSF,        float,      mean flux psf fit (PS1: stack)
    1515FIELD  dFluxPSF,      FLUX_PSF_ERR,    float,      mean flux psf error
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libautocode/def/secfilt.d

    r35099 r37067  
    22EXTNAME      DVO_SECFILT
    33TYPE         BINTABLE
    4 SIZE         64
     4SIZE         160
    55DESCRIPTION  DVO SecFilt : Secondary Filter Data
    66
    7 # elements of data structure / FITS table
     7## *** this section is for per-exposure mean values *** (unlabled values are implicitly PSF values)
    88FIELD  M,             MAG,             float,      average mag in this band,              mags
     9FIELD  dM,            MAG_ERR,         float,      formal error on average mag,           mags
    910FIELD  Map,           MAG_AP,          float,      average mag in this band,              mags
     11FIELD  dMap,          MAG_AP_ERR,      float,      formal error on average mag,           mags
     12FIELD  sMap,          MAG_AP_STDEV,    float,      standard deviation of ap mags,         mags
    1013FIELD  Mkron,         MAG_KRON,        float,      ave kron mag in this band,             mags
    1114FIELD  dMkron,        MAG_KRON_ERR,    float,      formal error on average kron mag,      mags
    12 FIELD  dM,            MAG_ERR,         float,      formal error on average mag,           mags
    13 FIELD  Xm,            MAG_CHI,         float,      chisq on average mag,                  [100*log(value)]
    14 FIELD  FluxPSF,       FLUX_PSF,        float,      mean flux psf fit (PS1: stack)
    15 FIELD  dFluxPSF,      FLUX_PSF_ERR,    float,      mean flux psf error
    16 FIELD  FluxKron,      FLUX_KRON,       float,      mean flux kron ap (PS1: stack)
    17 FIELD  dFluxKron,     FLUX_KRON_ERR,   float,      mean flux kron err
    18 FIELD  flags,         FLAGS,           uint32_t,   photometry flags
     15FIELD  sMkron,        MAG_KRON_STDEV,  float,      standard deviation of kron mags,       mags
     16
     17# these statistics are PSF-specific     
     18FIELD  Mstdev,        MAG_STDEV,       float,      standard deviation of measurements,    mags
     19FIELD  Mmin,          MAG_MIN,         float,      minimum accepted mag,                  mags
     20FIELD  Mmax,          MAG_MAX,         float,      maximum accepted mag,                  mags
     21FIELD  Mchisq,        MAG_CHI,         float,      chisq on average mag,                  value
     22
    1923FIELD  Ncode,         NCODE,           short,      number of detections in band
    2024FIELD  Nused,         NUSED,           short,      number of detections used in average
    21 FIELD  M_20,          MAG_20,          short,      lower 20percent mag,                   millimags
    22 FIELD  M_80,          MAG_80,          short,      upper 20percent mag,                   millimags
     25FIELD  NusedKron,     NUSED_KRON,      short,      number of detections used in average
     26FIELD  NusedAp,       NUSED_AP,        short,      number of detections used in average
     27
     28FIELD  flags,         FLAGS,           uint32_t,   photometry flags
     29
     30## *** this section is for stack values ***
     31
     32FIELD  MpsfStk,       MAG_PSF_STK,       float,    magnitude from stack (primary if available)
     33FIELD  FpsfStk,       FLUX_PSF_STK,      float,    flux from stack (primary if available)
     34FIELD  dFpsfStk,      FLUX_PSF_STK_ERR,  float,    mean flux psf error
     35
     36FIELD  MkronStk,      MAG_KRON_STK,      float,    magnitude from stack (primary if available)
     37FIELD  FkronStk,      FLUX_KRON_STK,     float,    flux from stack (primary if available)
     38FIELD  dFkronStk,     FLUX_KRON_STK_ERR, float,    mean flux kron error
     39
     40FIELD  MapStk,        MAG_AP_STK,        float,    magnitude from stack (primary if available)
     41FIELD  FapStk,        FLUX_AP_STK,       float,    flux from stack (primary if available)
     42FIELD  dFapStk,       FLUX_AP_STK_ERR,   float,    mean flux ap error
     43
     44## need an 8-byte boundary here ##
     45FIELD  stackDetectID, STACK_DETECT_ID, uint64_t,   detection ID on stack used for fluxes (if any)
     46
     47## *** this section is for forced-warp mean values ***
     48
     49FIELD  MpsfWrp,       MAG_PSF_WRP,       float,    psf magnitude from stack (primary if available)
     50FIELD  FpsfWrp,       FLUX_PSF_WRP,      float,    psf flux from stack (primary if available)
     51FIELD  dFpsfWrp,      FLUX_PSF_WRP_ERR,  float,    mean flux psf error
     52FIELD  sFpsfWrp,      FLUX_PSF_WRP_STD,  float,    mean flux psf stdev
     53
     54FIELD  MkronWrp,      MAG_KRON_WRP,      float,    kron magnitude from stack (primary if available)
     55FIELD  FkronWrp,      FLUX_KRON_WRP,     float,    kron flux from stack (primary if available)
     56FIELD  dFkronWrp,     FLUX_KRON_WRP_ERR, float,    mean flux kron error
     57FIELD  sFkronWrp,     FLUX_KRON_WRP_STD, float,    mean flux kron stdev
     58
     59FIELD  MapWrp,        MAG_AP_WRP,        float,    aper magnitude from stack (primary if available)
     60FIELD  FapWrp,        FLUX_AP_WRP,       float,    aper flux from stack (primary if available)
     61FIELD  dFapWrp,       FLUX_AP_WRP_ERR,   float,    mean flux ap error
     62FIELD  sFapWrp,       FLUX_AP_WRP_STD,   float,    mean flux ap stdev
     63
     64FIELD  NusedWrp,      NUSED_WRP,         short,    number of detections used in average
     65FIELD  NusedKronWrp,  NUSED_KRON_WRP,    short,    number of detections used in average
     66FIELD  NusedApWrp,    NUSED_AP_WRP,      short,    number of detections used in average
     67
    2368FIELD  ubercalDist,   UBERCAL_DIST,    short,      number of images from an ubercal-image
    24 FIELD  Mstdev,        MAG_STDEV,       short,      standard deviation of measurements,    millimags
    25 FIELD  stackDetectID, STACK_DETECT_ID, uint64_t,   detection ID on stack used for fluxes (if any)
    2669
    2770# *** 20090206 : new fields : M_20, M_80; dropped dummy
    2871# *** 20120302 : new fields : ubercalDist, Map, Mstdev
    2972# *** 20120710 : new fields : Mkron, dMkron, FluxPSF, dFluxPSF, FluxKron, dFluxKron, stackID
     73
     74# *** 20140617 : added   : dMap, NusedKron, NusedAp, MpsfStk, MkronStk, MapStk, *Wrp
     75               : changed : Mstdev, M_20 (to Mmin,short:float),M_80 (to Mmax,short:float),
     76               : rename : FpsfStk, dFpsfStk, FkronStk, dFronStk (were FluxPSF, dFluxPSF, FluxKron, dFluxKron)
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/Makefile

    r35416 r37067  
    3636$(DESTINC)/ps1_v3_defs.h \
    3737$(DESTINC)/ps1_v4_defs.h \
     38$(DESTINC)/ps1_v5_defs.h \
    3839$(DESTINC)/ps1_ref_defs.h \
    39 $(DESTINC)/cmf-ps1-dv3.h
     40$(DESTINC)/cmf-ps1-dv3.h \
     41$(DESTINC)/cmf-ps1-v5.h \
     42$(DESTINC)/cmf-ps1-sv3.h \
     43$(DESTINC)/cmf-ps1-v5-lensing.h
    4044
    4145INCS = $(DEFS) $(DESTINC)/dvo.h $(DESTINC)/autocode.h $(DESTINC)/dvo_util.h $(DESTINC)/dvodb.h $(DESTINC)/libdvo_astro.h $(DESTINC)/convert.h $(DESTINC)/get_graphdata.h
     
    7680$(SRC)/dvo_convert_PS1_V3.$(ARCH).o \
    7781$(SRC)/dvo_convert_PS1_V4.$(ARCH).o \
     82$(SRC)/dvo_convert_PS1_V5.$(ARCH).o \
    7883$(SRC)/dvo_convert_PS1_REF.$(ARCH).o \
    7984$(SRC)/flatcorr_io.$(ARCH).o    \
     
    8691$(SRC)/cmf-ps1-sv1-alt.$(ARCH).o \
    8792$(SRC)/cmf-ps1-dv3.$(ARCH).o \
     93$(SRC)/cmf-ps1-sv3.$(ARCH).o \
     94$(SRC)/cmf-ps1-v5.$(ARCH).o \
     95$(SRC)/cmf-ps1-v5-lensing.$(ARCH).o \
    8896$(SRC)/dvo_util.$(ARCH).o \
    8997$(SRC)/dbBooleanCond.$(ARCH).o          \
     
    103111$(SRC)/ImageMetadata.$(ARCH).o \
    104112$(SRC)/ImageOps.$(ARCH).o               \
     113$(SRC)/RegionHostTable.$(ARCH).o                \
    105114$(SRC)/match_image.$(ARCH).o            \
    106115$(SRC)/db_utils.$(ARCH).o               \
    107116$(SRC)/convert.$(ARCH).o                \
    108117$(SRC)/HostTable.$(ARCH).o              \
    109 $(SRC)/BoundaryTree.$(ARCH).o
    110 
     118$(SRC)/BoundaryTree.$(ARCH).o           \
     119$(SRC)/TessellationTable.$(ARCH).o
    111120
    112121# $(SRC)/dvo_convert_panstarrs.$(ARCH).o
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/include/dvo.h

    r35755 r37067  
    2828  DVO_FORMAT_PS1_V3,
    2929  DVO_FORMAT_PS1_V4,
     30  DVO_FORMAT_PS1_V5,
    3031} DVOTableFormat;
    3132
     
    7879
    7980/* catalog values to be loaded */
    80 # define LOAD_NONE      0x00
    81 # define LOAD_AVES      0x01
    82 # define LOAD_MEAS      0x02
    83 # define LOAD_MISS      0x04
    84 # define LOAD_SECF      0x08
    85 # define SKIP_AVES      0x10
    86 # define SKIP_MEAS      0x20
    87 # define SKIP_MISS      0x40
    88 # define SKIP_SECF      0x80
    89 
    90 // # define LOAD_MEAS_META 0x100 -- is this used??
     81# define LOAD_NONE      0x000
     82# define LOAD_AVES      0x001
     83# define LOAD_MEAS      0x002
     84# define LOAD_MISS      0x004
     85# define LOAD_SECF      0x008
     86# define SKIP_AVES      0x010
     87# define SKIP_MEAS      0x020
     88# define SKIP_MISS      0x040
     89# define SKIP_SECF      0x080
     90# define LOAD_LENSING   0x100
     91# define LOAD_LENSOBJ   0x200
     92# define SKIP_LENSING   0x400
     93# define SKIP_LENSOBJ   0x800
    9194
    9295/* photometry code types */
     
    171174  ID_STAR_USE_PAR   = 0x00200000, // parallax used (not AVE or PM)
    172175  ID_STAR_NO_ASTROM = 0x00400000, // mean astrometry could not be measured
     176  ID_STAR_BAD_PM    = 0x00800000, // mean astrometry could not be measured
    173177  ID_OBJ_EXT        = 0x01000000, // extended in our data (eg, PS)
    174178  ID_OBJ_EXT_ALT    = 0x02000000, // extended in external data (eg, 2MASS)
     
    285289} HostTable;
    286290
     291// A RegionHost processes data for some region in parallel with other regions
     292typedef struct RegionHostInfo {
     293  double Rmin;        // (Rmin,Rmax),(Dmin,Dmax) arehard RA,DEC boundaries of the
     294  double Rmax;        // region for which each host is responsible.  A given host
     295  double Dmin;        // calibrates the images for which the fiducial point (center)
     296  double Dmax;        // lands in the region, and all objects in the region
     297
     298  double RminCat;      // (RminCat,RmaxCat),(DminCat,DmaxCat) are the region for which
     299  double RmaxCat;      // the catalogs need to be loaded : this is the outer bounds
     300  double DminCat;      // of the region containing all images completely
     301  double DmaxCat;
     302
     303  char *hostname;
     304
     305  int hostID;                 // remove machine ID in SkyTable
     306  int stdio[3];               // fd's for communication with the remote host
     307  int pid;                    // remote process ID
     308  int status;
     309  IOBuffer stdout;
     310  IOBuffer stderr;
     311
     312  off_t Nimage;
     313  off_t NIMAGE;
     314  Image *image;
     315  off_t *imseq;
     316
     317  int *neighbors;             // list of neighbor index values
     318  int Nneighbors;             // number of neighbors
     319  char isNeighbor;            // TRUE if I am a neighbor to the current region host
     320} RegionHostInfo;
     321
     322typedef struct {
     323  double Rmin;
     324  double Rmax;
     325  double Dmin;
     326  double Dmax;
     327
     328  int Nhosts;
     329  RegionHostInfo *hosts;
     330  short *index;
     331} RegionHostTable;
     332
    287333// special-case function:
    288334CMF_PS1_V2 *gfits_table_get_CMF_PS1_V1_Alt (FTable *ftable, off_t *Ndata, char *swapped);
     
    291337// another special case : does not match byte-boundaries
    292338# include "cmf-ps1-dv3.h"
     339# include "cmf-ps1-sv3.h"
     340# include "cmf-ps1-v5.h"
     341# include "cmf-ps1-v5-lensing.h"
    293342
    294343typedef struct {
     
    308357# define BOUNDARY_TREE_NAME_LENGTH 128
    309358
     359// BoundaryTree is a structure to describe the 3pi RINGS skycell boundaries in terms of lines of constant (RA,DEC)
     360// the structure is flexible for a variety of RINGS-like tessellations, but is not appropriate for the LOCAL style tess
    310361typedef struct {
    311362  int FixedGridDEC;           // is the DEC sequence linear?
     
    342393} BoundaryTree;
    343394
    344 // XXX DROP? // a reduced-subset structure for relastro
    345 // XXX DROP? typedef struct {
    346 // XXX DROP?   double         R;
    347 // XXX DROP?   double         D;
    348 // XXX DROP?   unsigned short Nmeasure;
    349 // XXX DROP?   int            measureOffset;
    350 // XXX DROP?   uint32_t       flags;
    351 // XXX DROP?   int            catID;
    352 // XXX DROP? } AverageTinyAstro;
     395typedef enum { TESS_NONE, TESS_LOCAL, TESS_RINGS } TessType;
     396
     397// TessellationTable is a structure to describe the parameters of a set of "tessellations"
     398// (these are not strictly tessellations but projection sets as only the non-local
     399// versions can cover the full sky).  For LOCAL projection cells, the structure describes
     400// the boundaries of a SINGLE projection cell with Nx * Ny skycells and includes some
     401// basic parameters (not used by the fullsky, eg RINGS, tessellations)
     402typedef struct {
     403  double Rmin; // this tessellation is valid only for RA >= Rmin
     404  double Rmax; // this tessellation is valid only for RA <  Rmax
     405  double Dmin; // this tessellation is valid only for DEC >= Dmin
     406  double Dmax; // this tessellation is valid only for DEC <  Dmax
     407
     408  double Xo;
     409  double Yo;
     410  double Ro;
     411  double Do;
     412  double dPix;
     413  int dX;
     414  int dY;
     415
     416  int NX_SUB;
     417  int NY_SUB;
     418
     419  char *basename;
     420  int Nbasename;
     421  int projectIDoff;
     422  int skycellIDoff;
     423
     424  TessType type; //
     425  BoundaryTree *tree;
     426} TessellationTable;
    353427
    354428// a reduced-subset structure for relphot
     
    360434  uint32_t       flags;
    361435  int            catID;
     436  int            objID;
     437  int            nOwn;
    362438} AverageTiny;
    363439
    364440// a reduced-subset structure for relphot & relastro
    365441typedef struct {
    366   float          dR;
    367   float          dD;
     442  double         R;
     443  double         D;
    368444  float          M;
    369445  float          Mcal;
     
    385461  short          dYccd;
    386462  short          dRsys;
     463  char           myDet;
    387464} MeasureTiny;
     465
     466/** STRUCT DEFINITION **/
     467typedef struct {
     468  double           R;                    // RA (decimal degrees )
     469  double           D;                    // DEC (decimal degrees )
     470  float            dR;                   // RA error (arcsec)
     471  float            dD;                   // DEC error (arcsec)
     472  float            uR;                   // RA*cos(D) proper-motion (arcsec/year)
     473  float            uD;                   // DEC proper-motion (arcsec/year)
     474  float            duR;                  // RA*cos(D) p-m error (arcsec/year)
     475  float            duD;                  // DEC p-m error (arcsec/year)
     476  float            P;                    // parallax (arcsec)
     477  float            dP;                   // parallax error (arcsec)
     478  float            ChiSqAve;             // astrometry analysis chisq
     479  float            ChiSqPM;              // astrometry analysis chisq
     480  float            ChiSqPar;             // astrometry analysis chisq
     481  int              Tmean;                // mean epoch (PM,PAR ref) (unix time seconds)
     482  int              Trange;               // mean epoch (PM,PAR ref) (unix time seconds)
     483  float            Xp;                   // unused
     484  unsigned short   Npos;                 // number of detections used for astrometry
     485  unsigned short   Nmeasure;             // number of psf measurements
     486  unsigned short   Nmissing;             // number of missings
     487  unsigned short   Nextend;              // number of extended measurements
     488  uint32_t         measureOffset;        // offset to first psf measurement
     489  uint32_t         missingOffset;        // offset to first missing obs
     490  float            refColor;            // offset to first extended measurement
     491  uint32_t         flags;                // average object flags (star; ghost; etc)
     492  uint32_t         photFlagsUpper;       // upper bit of 2 bit summary of per-measure photflags
     493  uint32_t         photFlagsLower;       // lower bit of 2 bit summary of per-measure photflags
     494  unsigned int     objID;                // unique ID for object in table
     495  unsigned int     catID;                // unique ID for table in which object was first realized
     496  uint64_t         extID;                // external ID for object (eg PSPS objID)
     497} Average_PS1_V4alt;
     498
     499Average_PS1_V4alt *gfits_table_get_Average_PS1_V4alt (FTable *table, off_t *Ndata, char *swapped);
     500Average *Average_PS1_V4alt_ToInternal (Average_PS1_V4alt *in, off_t Nvalues);
     501
     502/** STRUCT DEFINITION **/
     503typedef struct {
     504  float            dR;                   // RA offset (arcsec)
     505  float            dD;                   // DEC offset (arcsec)
     506  float            M;                    // catalog mag (mag)
     507  float            Mcal;                 // image cal mag (mag)
     508  float            Map;                  // aperture mag (mag)
     509  float            Mkron;                // kron magnitude (mag)
     510  float            dMkron;               // kron magnitude error (mag)
     511  float            dM;                   // mag error (mag)
     512  float            dMcal;                // systematic calibration error (mag)
     513  float            dt;                   // exposure time (2.5*log(exptime))
     514  float            FluxPSF;              // flux from psf fit (counts/sec?)
     515  float            dFluxPSF;             // error on psf flux (counts/sec?)
     516  float            FluxKron;             // flux from kron ap (counts/sec?)
     517  float            dFluxKron;            // error on kron flux (counts/sec?)
     518  float            airmass;              // (airmass - 1) (airmass)
     519  float            az;                   // telescope azimuth
     520  float            Xccd;                 // X coord on chip (raw value) (pixels)
     521  float            Yccd;                 // Y coord on chip (raw value) (pixels)
     522  float            Sky;                  // local estimate of sky flux (counts/sec)
     523  float            dSky;                 // local estimate of sky flux (counts/sec)
     524  int              t;                    // time in seconds (UNIX)
     525  unsigned int     averef;               // reference to average entry     
     526  unsigned int     detID;                // detection ID
     527  unsigned int     imageID;              // reference to DVO image ID
     528  unsigned int     objID;                // unique ID for object in table
     529  unsigned int     catID;                // unique ID for table in which object was first realized
     530  uint64_t         extID;                // external ID (eg PSPS detID)
     531  float            psfQF;                // psf coverage/quality factor
     532  float            psfQFperf;            // psf coverage / quality factor (all mask bits)
     533  float            psfChisq;             // psf fit chisq
     534  int              psfNdof;              // psf degrees of freedom
     535  int              psfNpix;              // psf number of pixels
     536  float            crNsigma;             // Nsigma deviation towards CR
     537  float            extNsigma;            // Nsigma deviation towards EXT
     538  short            FWx;                  // object fwhm major axis (1/100 of pixels)
     539  short            FWy;                  // object fwhm minor axis (1/100 of pixels )
     540  short            theta;                // angle wrt ccd X dir ((0xffff/360) deg)
     541  short            Mxx;                  // second moments in pixel coords (1/100 of pixels)
     542  short            Mxy;                  // second moments in pixel coords (1/100 of pixels)
     543  short            Myy;                  // second moments in pixel coords (1/100 of pixels)
     544  unsigned short   t_msec;               // time fraction of second (milliseconds)
     545  unsigned short   photcode;             // photcode
     546  short            dXccd;                // X coord error on chip (1/100 of pixels)
     547  short            dYccd;                // Y coord error on chip (1/100 of pixels)
     548  short            dRsys;                // systematic error from astrom (1/100 of pixels)
     549  short            posangle;             // position angle sky to chip ((0xffff/360) deg)
     550  float            pltscale;             // plate scale (arcsec/pixel)
     551  unsigned int     dbFlags;              // flags supplied by analysis in database
     552  unsigned int     photFlags;            // flags supplied by photometry program
     553} Measure_PS1_V4alt;
     554
     555Measure_PS1_V4alt *gfits_table_get_Measure_PS1_V4alt (FTable *table, off_t *Ndata, char *swapped);
     556Measure *Measure_PS1_V4alt_ToInternal (Average *ave, Measure_PS1_V4alt *in, off_t Nvalues);
     557
     558/* for some reason I have merged the set of tables and the file description,
     559   so I need to have an internal structure to point to the separate files */
    388560
    389561/* a catalog contains this data */
     
    399571  SecFilt *secfilt;
    400572
     573  // lensing data (optional?)
     574  Lensing *lensing;
     575  Lensobj *lensobj;
     576
    401577  int Nsecfilt;  /* number of secfilt entries for each average entry */
    402   off_t Naverage,   Nmeasure,   Nmissing,   Nsecf_mem;  /* current number of each component in memory */
    403   off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nsecf_disk; /* current number of each component on disk */
    404   off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nsecf_off;  /* index of first loaded data value */
     578  off_t Naverage,   Nmeasure,   Nmissing,   Nlensing,      Nlensobj,      Nsecf_mem;  /* current number of each component in memory */
     579  off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nlensing_disk, Nlensobj_disk, Nsecf_disk; /* current number of each component on disk */
     580  off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nlensing_off,  Nlensobj_off,  Nsecf_off;  /* index of first loaded data value */
    405581
    406582  // note that we use these for the full-sky relphot analysis
     
    421597  struct Catalog *missing_catalog;              /* missing catalog data (split) */
    422598  struct Catalog *secfilt_catalog;              /* secfilt catalog data (split) */
     599  struct Catalog *lensing_catalog;              /* lensing catalog data (split) */
     600  struct Catalog *lensobj_catalog;              /* lensobj catalog data (split) */
    423601
    424602  unsigned int objID;
     
    429607  char catmode;                         /* storage mode (raw, mef, split, mysql) */
    430608  char catformat;                       /* storage format (elixir, panstarrs, etc) */
    431   char catflags;                                /* choices to be loaded */
    432   char sorted;                          /* is measure table average-sorted? */
     609  int sorted;                           /* is measure table average-sorted? (NOTE this is an int only because gfits_scan %t requires it) */
    433610 
     611  short catflags; /* choices to be loaded */
     612
    434613  /* pointers for data manipulation */
    435   off_t *found;
    436   off_t *image;
    437   off_t *mosaic;
    438   float *X;
    439   float *Y;
     614  off_t *found_t;
     615  off_t *foundWarp_t;
     616//  off_t *image_t;
     617//  off_t *mosaic_t;
     618//  float *X_t;
     619//  float *Y_t;
     620  int   *nOwn_t; // relastro uses this to count owned detections per object
    440621
    441622} Catalog;
     
    497678char     *GetPhotcodeNamebyCode (int code);
    498679
    499 float PhotInst (Measure *measure);
    500 float PhotCat (Measure *measure);
    501 float PhotAper (Measure *measure);
    502 float PhotKron (Measure *measure);
    503 float PhotSys (Measure *measure, Average *average, SecFilt *secfilt);
    504 float PhotRel (Measure *measure, Average *average, SecFilt *secfilt);
    505 float PhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
    506 float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt);
    507 float PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure);
     680float PhotInst (Measure *measure, dvoMagClassType class);
     681float PhotCat (Measure *measure, dvoMagClassType class);
     682float PhotSys (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class);
     683float PhotRel (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class);
     684float PhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code, dvoMagClassType class);
     685float PhotErr (Measure *measure, dvoMagClassType class);
     686float PhotCalErr (Measure *measure, dvoMagClassType class);
     687
     688float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
     689float PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure, dvoMagClassType class, dvoMagSourceType source);
     690float PhotAveErr (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
     691
     692float PhotInstTiny (MeasureTiny *measure, dvoMagClassType class);
     693float PhotCatTiny (MeasureTiny *measure, dvoMagClassType class);
     694float PhotSysTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt, dvoMagClassType class);
     695float PhotRelTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt, dvoMagClassType class);
     696float PhotCalTiny (MeasureTiny *thisone, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code, dvoMagClassType class);
     697
     698float PhotAveTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
     699float PhotRefTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, dvoMagClassType class, dvoMagSourceType source);
     700
     701float PhotFluxInst (Measure *measure, dvoMagClassType class);
     702float PhotFluxCat (Measure *measure, dvoMagClassType class);
     703float PhotFluxSys (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class);
     704float PhotFluxRel (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class);
     705float PhotFluxCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code, dvoMagClassType class);
     706
     707float PhotFluxAve (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
     708float PhotFluxRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure, dvoMagClassType class, dvoMagSourceType source);
     709
     710float PhotFluxInstErr (Measure *measure, dvoMagClassType class);
     711float PhotFluxCatErr (Measure *measure, dvoMagClassType class);
     712
    508713float PhotXm (PhotCode *code, Average *average, SecFilt *secfilt);
    509 float PhotdM (PhotCode *code, Average *average, SecFilt *secfilt);
    510 
    511 float PhotAperInst (Measure *measure);
    512 float PhotKronInst (Measure *measure);
    513 float PhotKronAve (PhotCode *code, Average *average, SecFilt *secfilt);
    514 float PhotKronAveErr (PhotCode *code, Average *average, SecFilt *secfilt);
    515 
    516714float PhotZeroPoint (Measure *measure, Average *average, SecFilt *secfilt);
    517 float PhotAveFluxPSF (PhotCode *code, Average *average, SecFilt *secfilt);
    518 float PhotAvedFluxPSF (PhotCode *code, Average *average, SecFilt *secfilt);
    519 float PhotAveFluxKron (PhotCode *code, Average *average, SecFilt *secfilt);
    520 float PhotAvedFluxKron (PhotCode *code, Average *average, SecFilt *secfilt);
    521715
    522716float PhotMstdev (PhotCode *code, Average *average, SecFilt *secfilt);
    523 float PhotM20 (PhotCode *code, Average *average, SecFilt *secfilt);
    524 float PhotM80 (PhotCode *code, Average *average, SecFilt *secfilt);
     717float PhotMmin (PhotCode *code, Average *average, SecFilt *secfilt);
     718float PhotMmax (PhotCode *code, Average *average, SecFilt *secfilt);
    525719float PhotUCdist (PhotCode *code, Average *average, SecFilt *secfilt);
    526720unsigned int PhotStackID (PhotCode *code, Average *average, SecFilt *secfilt);
     
    529723int PhotColor (Average *average, SecFilt *secfilt, Measure *measure, int c1, int c2, double *color);
    530724
    531 float PhotInstTiny (MeasureTiny *measure);
    532 float PhotCatTiny (MeasureTiny *measure);
    533 float PhotAperTiny (MeasureTiny *measure);
    534 float PhotSysTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt);
    535 float PhotRelTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt);
    536 float PhotCalTiny (MeasureTiny *thisone, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code);
    537 float PhotAveTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt);
    538 float PhotRefTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure);
    539725float PhotXmTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt);
    540726float PhotdMTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt);
     
    607793/*** conversion functions / I/O conversions ***/
    608794Average *ReadRawAverage (FILE *f, off_t Naverage, char format, SecFilt **primary);
    609 Measure *ReadRawMeasure (FILE *f, off_t Nmeasure, char format);
     795Measure *ReadRawMeasure (FILE *f, Average *average, off_t Nmeasure, char format);
    610796SecFilt *ReadRawSecFilt (FILE *f, off_t Nsecfilt, char format);
    611797int WriteRawAverage (FILE *f, Average *average, off_t Naverage, char format, SecFilt *primary);
    612 int WriteRawMeasure (FILE *f, Measure *measure, off_t Nmeasure, char format);
     798int WriteRawMeasure (FILE *f, Average *average, Measure *measure, off_t Nmeasure, char format);
    613799int WriteRawSecFilt (FILE *f, SecFilt *secfilt, off_t Nsecfilt, char format);
    614800
     
    616802
    617803Average *FtableToAverage (FTable *ftable, off_t *Naverage, char *format, SecFilt **primary);
    618 Measure *FtableToMeasure (FTable *ftable, off_t *Nmeasure, char *format);
     804Measure *FtableToMeasure (FTable *ftable, Average *average, off_t *Nmeasure, char *format);
    619805SecFilt *FtableToSecFilt (FTable *ftable, off_t *Nsecfilt, char *format);
     806Lensing *FtableToLensing (FTable *ftable, off_t *Nlensing, char *format);
     807Lensobj *FtableToLensobj (FTable *ftable, off_t *Nlensobj, char *format);
    620808int      FtableToImage   (FTable *ftable, Header *theader, char *format);
    621809
    622810int AverageToFtable (FTable *ftable, Average *average, off_t Naverage, char format, SecFilt *primary);
    623 int MeasureToFtable (FTable *ftable, Measure *measure, off_t Nmeasure, char format);
     811int MeasureToFtable (FTable *ftable, Average *average, Measure *measure, off_t Nmeasure, char format);
    624812int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, off_t Nsecfilt, char format);
     813int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, char format);
     814int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, char format);
    625815int ImageToFtable (FTable *ftable, Header *theader, char format);
    626816int ImageToVtable (VTable *vtable, Header *theader, char format);
     
    637827# include "ps1_v3_defs.h"
    638828# include "ps1_v4_defs.h"
     829# include "ps1_v5_defs.h"
    639830# include "ps1_ref_defs.h"
    640831
     
    696887void sort_coords_index (double *X, double *Y, off_t *S, off_t N);
    697888void sort_coords_indexonly (double *X, double *Y, off_t *S, off_t N);
     889void sort_IDs_indexonly (opihi_int *X, off_t *S, off_t N);
    698890void sort_regions (SkyRegion *region, off_t N);
    699891
     
    716908int free_tiny_values (Catalog *catalog);
    717909
     910BoundaryTree *BoundaryTreeLoad(char *filename);
     911BoundaryTree *BoundaryTreeRead(Header *headerPHU, Header *headerZone, FILE *f);
     912
     913int BoundaryTreeSave(char *filename, BoundaryTree *tree);
     914int BoundaryTreeWrite(FILE *f, BoundaryTree *tree);
     915
    718916int BoundaryTreeCellCoords (BoundaryTree *tree, int *zone, int *band, double ra, double dec);
    719 int BoundaryTreeSave(char *filename, BoundaryTree *tree);
    720 BoundaryTree *BoundaryTreeLoad(char *filename);
    721917int BoundaryTreeProjection (double *x, double *y, double r, double d, BoundaryTree *tree, int zone, int band);
     918
     919TessellationTable *TessellationTableLoad(char *filename, int *Ntess);
     920int TessellationTableSave(char *filename, TessellationTable *tess, int Ntess);
     921int TessellationPrimaryCellIDs (TessellationTable *tess, int Ntess, int *tessID, int *projID, int *skycellID, double ra, double dec);
     922void TessellationTableInit (TessellationTable *tess, int Ntess);
     923
     924float dvoOffsetR (Measure *measure, Average *average);
     925float dvoOffsetD (Measure *measure, Average *average);
     926double dvoMeanR (float dR, Average *average);
     927double dvoMeanD (float dD, Average *average);
    722928
    723929void dvo_average_init (Average *average);
     
    727933void dvo_measureT_init (MeasureTiny *measure);
    728934
     935void dvo_lensing_init (Lensing *lensing);
     936void dvo_lensobj_init (Lensobj *lensobj);
     937
     938void InitRegionHosts (RegionHostInfo *hosts, int Nhosts, int NHOSTS);
     939void FreeRegionHosts (RegionHostInfo *hosts, int Nhosts);
     940void FreeRegionHostTable (RegionHostTable *table);
     941RegionHostTable *RegionHostTableLoad (char *catdir, char *rootname);
     942int RegionHostTableWaitJobs (RegionHostTable *regionHosts, char *file, int lineno);
     943int RegionHostTableWaitJobsGetIO (RegionHostTable *regionHosts, char *file, int lineno, int VERBOSE);
     944int RegionHostFindNeighbors (RegionHostTable *table, int Nhost);
     945
    729946# endif // DVO_H
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/include/dvodb.h

    r35416 r37067  
    2222
    2323/* magnitude types */
    24 enum {MAG_NONE,
    25       MAG_INST,
    26       MAG_CAT,
    27       MAG_APER,
    28       MAG_APER_INST,
    29       MAG_KRON,
    30       MAG_KRON_INST,
    31       MAG_KRON_ERR,
    32       MAG_SYS,
    33       MAG_REL,
    34       MAG_CAL,
    35       MAG_AVE,
    36       MAG_REF,
    37       MAG_ERR,
    38       MAG_STDEV,
    39       MAG_AVE_ERR,
    40       MAG_PHOT_FLAGS,
    41       MAG_CHISQ,
    42       MAG_NCODE,
    43       MAG_NPHOT,
    44       MAG_20,
    45       MAG_80,
    46       MAG_UC_DIST,
    47       MAG_STACK_DET_ID,
    48       MAG_FLUX_PSF,
    49       MAG_FLUX_PSF_ERR,
    50       MAG_FLUX_KRON,
    51       MAG_FLUX_KRON_ERR,
    52 };
     24
     25typedef enum {
     26  MAG_SRC_NONE,
     27  MAG_SRC_CHP,
     28  MAG_SRC_WRP,
     29  MAG_SRC_STK,
     30} dvoMagSourceType;
     31
     32typedef enum {
     33  MAG_LEVEL_NONE,       // -2.5*log(DN) [ie, not DN/sec]
     34  MAG_LEVEL_INST,               // -2.5*log(DN) [ie, not DN/sec]
     35  MAG_LEVEL_CAT,                // MAG_INST + 2.5*log(exptime) + C_lambda + K_lambda*(airmass - 1)
     36  MAG_LEVEL_SYS, // MAG_CAT + \sum_i A_i * (color_i - color_o) [color correction for measure photcode]
     37  MAG_LEVEL_REL, // MAG_SYS - Mcal [specific zero point for image]
     38  MAG_LEVEL_CAL, // MAG_REL + \sum_i A_i * (color_i - color_o) [color correction for average photcode]
     39  MAG_LEVEL_AVE,
     40  MAG_LEVEL_REF,
     41} dvoMagLevelType;
     42
     43typedef enum {
     44  MAG_OPTION_NONE,
     45  MAG_OPTION_MAG,
     46  MAG_OPTION_ERR,
     47  MAG_OPTION_FLUX,
     48  MAG_OPTION_FLUX_ERR,
     49  MAG_OPTION_STDEV,
     50  MAG_OPTION_CHISQ,
     51  MAG_OPTION_MIN,
     52  MAG_OPTION_MAX,
     53  MAG_OPTION_NCODE,
     54  MAG_OPTION_NPHOT, // Nused
     55  MAG_OPTION_UC_DIST,
     56  MAG_OPTION_STACK_DET_ID,
     57  MAG_OPTION_FLAGS,
     58} dvoMagOptionType;
     59
     60typedef enum {
     61  MAG_CLASS_NONE,
     62  MAG_CLASS_PSF,
     63  MAG_CLASS_KRON,
     64  MAG_CLASS_APER,
     65} dvoMagClassType;
    5366
    5467/* measure fields */
     
    90103      MEAS_OBJ_FLAGS,
    91104      MEAS_SECFILT_FLAGS,
    92       MEAS_MAG,
     105      MEAS_PHOT, // photometry class of measurements
    93106      MEAS_MINST,
    94107      MEAS_MCAT,
     
    144157      MEAS_EXTERN_ID,
    145158      MEAS_EXPNAME_AS_INT,
    146       MEAS_MCAL_OFFSET,
     159      MEAS_MCAL_OFFSET, // make this a dvoMagOption?
    147160      MEAS_FLAT,
    148161      MEAS_CENTER_OFFSET,
    149       MEAS_FLUX_PSF,
    150       MEAS_FLUX_PSF_ERR,
    151       MEAS_FLUX_KRON,
    152       MEAS_FLUX_KRON_ERR,
     162      MEAS_REF_COLOR,
    153163};
    154164
     
    174184      AVE_TMEAN,
    175185      AVE_TRANGE,
     186      AVE_PSF_QF,
     187      AVE_PSF_QF_PERF,
     188      AVE_STARGAL,
    176189      AVE_Xp,
    177190      AVE_NMEAS,
    178191      AVE_NMISS,
    179192      AVE_NPOS,
    180       AVE_NPHOT,
    181       AVE_NCODE,
    182       AVE_MAG,
    183       AVE_dMAG,
    184       AVE_Xm,
    185193      AVE_OBJ_FLAGS,
    186194      AVE_TYPE,
     
    190198      AVE_EXTID_HI,
    191199      AVE_EXTID_LO,
     200      AVE_REF_COLOR,
     201      AVE_PHOT, // photometry class of values
    192202};
     203
     204//       AVE_NPHOT,
     205//       AVE_NCODE,
     206//       AVE_MAG,
     207//       AVE_dMAG,
     208//       AVE_Xm,
    193209
    194210enum {IMAGE_ZERO,
     
    257273      IMAGE_NFIT_ASTROM,
    258274      IMAGE_NLINK_PHOTOM,
    259       IMAGE_NLINK_ASTROM
     275      IMAGE_NLINK_ASTROM,
     276      IMAGE_REF_COLOR
    260277};
    261278
     
    277294  int table;
    278295  int ID;
    279   int magMode;
     296
     297  dvoMagSourceType magSource; // chip, (forced) warp, stack [only relevant for averages]
     298  dvoMagLevelType magLevel;  // inst, cat, sys, rel, ave, ref, err, min, max, stdev, nphot, chisq,
     299  dvoMagOptionType magOption;  // psf, kron, aper
     300  dvoMagClassType magClass;
     301
    280302  char type;
    281303  PhotCode *photcode;
     
    339361
    340362int          GetMagMode             PROTO((char *string));
    341 PhotCode    *ParsePhotcodeField     PROTO((char *field, int *mode, int def));
     363int          ParsePhotcodeField     PROTO((dbField *field, char *fieldName, int fieldID));
    342364int          ParseMeasureField      PROTO((dbField *field, char *fieldName));
    343365int          ParseAverageField      PROTO((dbField *field, char *fieldName));
     
    372394
    373395// Some values used by code moved to libdvo from opihi.
    374 enum {OPIHI_FLT, OPIHI_INT};
     396enum {OPIHI_NOTYPE, OPIHI_FLT, OPIHI_INT};
    375397#define opihi_flt double
    376398#define opihi_int int
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/include/elixir_defs.h

    r35162 r37067  
    33Average                 *Average_Elixir_ToInternal (Average_Elixir *in, off_t Nvalues, SecFilt **primary);
    44Average_Elixir          *AverageInternalTo_Elixir (Average *in, off_t Nvalues, SecFilt *primary);
    5 Measure                 *Measure_Elixir_ToInternal (Measure_Elixir *in, off_t Nvalues);
    6 Measure_Elixir          *MeasureInternalTo_Elixir (Measure *in, off_t Nvalues);
     5Measure                 *Measure_Elixir_ToInternal (Average *ave, Measure_Elixir *in, off_t Nvalues);
     6Measure_Elixir          *MeasureInternalTo_Elixir (Average *ave, Measure *in, off_t Nvalues);
    77SecFilt                 *SecFilt_Elixir_ToInternal (SecFilt_Elixir *in, off_t Nvalues);
    88SecFilt_Elixir          *SecFiltInternalTo_Elixir (SecFilt *in, off_t Nvalues);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/include/loneos_defs.h

    r35162 r37067  
    33Average                 *Average_Loneos_ToInternal (Average_Loneos *in, off_t Nvalues, SecFilt **primary);
    44Average_Loneos          *AverageInternalTo_Loneos (Average *in, off_t Nvalues, SecFilt *primary);
    5 Measure                 *Measure_Loneos_ToInternal (Measure_Loneos *in, off_t Nvalues);
    6 Measure_Loneos          *MeasureInternalTo_Loneos (Measure *in, off_t Nvalues);
     5Measure                 *Measure_Loneos_ToInternal (Average *ave, Measure_Loneos *in, off_t Nvalues);
     6Measure_Loneos          *MeasureInternalTo_Loneos (Average *ave, Measure *in, off_t Nvalues);
    77SecFilt                 *SecFilt_Loneos_ToInternal (SecFilt_Loneos *in, off_t Nvalues);
    88SecFilt_Loneos          *SecFiltInternalTo_Loneos (SecFilt *in, off_t Nvalues);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/include/panstarrs_dev_0_defs.h

    r35162 r37067  
    33Average                 *Average_Panstarrs_DEV_0_ToInternal (Average_Panstarrs_DEV_0 *in, off_t Nvalues, SecFilt **primary);
    44Average_Panstarrs_DEV_0 *AverageInternalTo_Panstarrs_DEV_0 (Average *in, off_t Nvalues, SecFilt *primary);
    5 Measure                 *Measure_Panstarrs_DEV_0_ToInternal (Measure_Panstarrs_DEV_0 *in, off_t Nvalues);
    6 Measure_Panstarrs_DEV_0 *MeasureInternalTo_Panstarrs_DEV_0 (Measure *in, off_t Nvalues);
     5Measure                 *Measure_Panstarrs_DEV_0_ToInternal (Average *ave, Measure_Panstarrs_DEV_0 *in, off_t Nvalues);
     6Measure_Panstarrs_DEV_0 *MeasureInternalTo_Panstarrs_DEV_0 (Average *ave, Measure *in, off_t Nvalues);
    77SecFilt                 *SecFilt_Panstarrs_DEV_0_ToInternal (SecFilt_Panstarrs_DEV_0 *in, off_t Nvalues);
    88SecFilt_Panstarrs_DEV_0 *SecFiltInternalTo_Panstarrs_DEV_0 (SecFilt *in, off_t Nvalues);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/include/panstarrs_dev_1_defs.h

    r35162 r37067  
    33Average                 *Average_Panstarrs_DEV_1_ToInternal (Average_Panstarrs_DEV_1 *in, off_t Nvalues, SecFilt **primary);
    44Average_Panstarrs_DEV_1 *AverageInternalTo_Panstarrs_DEV_1 (Average *in, off_t Nvalues, SecFilt *primary);
    5 Measure                 *Measure_Panstarrs_DEV_1_ToInternal (Measure_Panstarrs_DEV_1 *in, off_t Nvalues);
    6 Measure_Panstarrs_DEV_1 *MeasureInternalTo_Panstarrs_DEV_1 (Measure *in, off_t Nvalues);
     5Measure                 *Measure_Panstarrs_DEV_1_ToInternal (Average *ave, Measure_Panstarrs_DEV_1 *in, off_t Nvalues);
     6Measure_Panstarrs_DEV_1 *MeasureInternalTo_Panstarrs_DEV_1 (Average *ave, Measure *in, off_t Nvalues);
    77SecFilt                 *SecFilt_Panstarrs_DEV_1_ToInternal (SecFilt_Panstarrs_DEV_1 *in, off_t Nvalues);
    88SecFilt_Panstarrs_DEV_1 *SecFiltInternalTo_Panstarrs_DEV_1 (SecFilt *in, off_t Nvalues);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/include/ps1_dev_1_defs.h

    r35162 r37067  
    33Average                 *Average_PS1_DEV_1_ToInternal (Average_PS1_DEV_1 *in, off_t Nvalues, SecFilt **primary);
    44Average_PS1_DEV_1       *AverageInternalTo_PS1_DEV_1 (Average *in, off_t Nvalues, SecFilt *primary);
    5 Measure                 *Measure_PS1_DEV_1_ToInternal (Measure_PS1_DEV_1 *in, off_t Nvalues);
    6 Measure_PS1_DEV_1       *MeasureInternalTo_PS1_DEV_1 (Measure *in, off_t Nvalues);
     5Measure                 *Measure_PS1_DEV_1_ToInternal (Average *ave, Measure_PS1_DEV_1 *in, off_t Nvalues);
     6Measure_PS1_DEV_1       *MeasureInternalTo_PS1_DEV_1 (Average *ave, Measure *in, off_t Nvalues);
    77SecFilt                 *SecFilt_PS1_DEV_1_ToInternal (SecFilt_PS1_DEV_1 *in, off_t Nvalues);
    88SecFilt_PS1_DEV_1       *SecFiltInternalTo_PS1_DEV_1 (SecFilt *in, off_t Nvalues);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/include/ps1_dev_2_defs.h

    r35162 r37067  
    33Average                 *Average_PS1_DEV_2_ToInternal (Average_PS1_DEV_2 *in, off_t Nvalues, SecFilt **primary);
    44Average_PS1_DEV_2       *AverageInternalTo_PS1_DEV_2 (Average *in, off_t Nvalues, SecFilt *primary);
    5 Measure                 *Measure_PS1_DEV_2_ToInternal (Measure_PS1_DEV_2 *in, off_t Nvalues);
    6 Measure_PS1_DEV_2       *MeasureInternalTo_PS1_DEV_2 (Measure *in, off_t Nvalues);
     5Measure                 *Measure_PS1_DEV_2_ToInternal (Average *ave, Measure_PS1_DEV_2 *in, off_t Nvalues);
     6Measure_PS1_DEV_2       *MeasureInternalTo_PS1_DEV_2 (Average *ave, Measure *in, off_t Nvalues);
    77SecFilt                 *SecFilt_PS1_DEV_2_ToInternal (SecFilt_PS1_DEV_2 *in, off_t Nvalues);
    88SecFilt_PS1_DEV_2       *SecFiltInternalTo_PS1_DEV_2 (SecFilt *in, off_t Nvalues);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/include/ps1_ref_defs.h

    r35162 r37067  
    33Average                 *Average_PS1_REF_ToInternal (Average_PS1_REF *in, off_t Nvalues, SecFilt **primary);
    44Average_PS1_REF          *AverageInternalTo_PS1_REF (Average *in, off_t Nvalues, SecFilt *primary);
    5 Measure                 *Measure_PS1_REF_ToInternal (Measure_PS1_REF *in, off_t Nvalues);
    6 Measure_PS1_REF          *MeasureInternalTo_PS1_REF (Measure *in, off_t Nvalues);
     5Measure                 *Measure_PS1_REF_ToInternal (Average *ave, Measure_PS1_REF *in, off_t Nvalues);
     6Measure_PS1_REF          *MeasureInternalTo_PS1_REF (Average *ave, Measure *in, off_t Nvalues);
    77SecFilt                 *SecFilt_PS1_REF_ToInternal (SecFilt_PS1_REF *in, off_t Nvalues);
    88SecFilt_PS1_REF          *SecFiltInternalTo_PS1_REF (SecFilt *in, off_t Nvalues);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/include/ps1_v1_defs.h

    r35162 r37067  
    33Average                 *Average_PS1_V1_ToInternal (Average_PS1_V1 *in, off_t Nvalues, SecFilt **primary);
    44Average_PS1_V1          *AverageInternalTo_PS1_V1 (Average *in, off_t Nvalues, SecFilt *primary);
    5 Measure                 *Measure_PS1_V1_ToInternal (Measure_PS1_V1 *in, off_t Nvalues);
    6 Measure_PS1_V1          *MeasureInternalTo_PS1_V1 (Measure *in, off_t Nvalues);
     5Measure                 *Measure_PS1_V1_ToInternal (Average *ave, Measure_PS1_V1 *in, off_t Nvalues);
     6Measure_PS1_V1          *MeasureInternalTo_PS1_V1 (Average *ave, Measure *in, off_t Nvalues);
    77SecFilt                 *SecFilt_PS1_V1_ToInternal (SecFilt_PS1_V1 *in, off_t Nvalues);
    88SecFilt_PS1_V1          *SecFiltInternalTo_PS1_V1 (SecFilt *in, off_t Nvalues);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/include/ps1_v2_defs.h

    r35162 r37067  
    33Average                 *Average_PS1_V2_ToInternal (Average_PS1_V2 *in, off_t Nvalues, SecFilt **primary);
    44Average_PS1_V2          *AverageInternalTo_PS1_V2 (Average *in, off_t Nvalues, SecFilt *primary);
    5 Measure                 *Measure_PS1_V2_ToInternal (Measure_PS1_V2 *in, off_t Nvalues);
    6 Measure_PS1_V2          *MeasureInternalTo_PS1_V2 (Measure *in, off_t Nvalues);
     5Measure                 *Measure_PS1_V2_ToInternal (Average *ave, Measure_PS1_V2 *in, off_t Nvalues);
     6Measure_PS1_V2          *MeasureInternalTo_PS1_V2 (Average *ave, Measure *in, off_t Nvalues);
    77SecFilt                 *SecFilt_PS1_V2_ToInternal (SecFilt_PS1_V2 *in, off_t Nvalues);
    88SecFilt_PS1_V2          *SecFiltInternalTo_PS1_V2 (SecFilt *in, off_t Nvalues);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/include/ps1_v3_defs.h

    r35162 r37067  
    33Average                 *Average_PS1_V3_ToInternal (Average_PS1_V3 *in, off_t Nvalues, SecFilt **primary);
    44Average_PS1_V3          *AverageInternalTo_PS1_V3 (Average *in, off_t Nvalues, SecFilt *primary);
    5 Measure                 *Measure_PS1_V3_ToInternal (Measure_PS1_V3 *in, off_t Nvalues);
    6 Measure_PS1_V3          *MeasureInternalTo_PS1_V3 (Measure *in, off_t Nvalues);
     5Measure                 *Measure_PS1_V3_ToInternal (Average *ave, Measure_PS1_V3 *in, off_t Nvalues);
     6Measure_PS1_V3          *MeasureInternalTo_PS1_V3 (Average *ave, Measure *in, off_t Nvalues);
    77SecFilt                 *SecFilt_PS1_V3_ToInternal (SecFilt_PS1_V3 *in, off_t Nvalues);
    88SecFilt_PS1_V3          *SecFiltInternalTo_PS1_V3 (SecFilt *in, off_t Nvalues);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/include/ps1_v4_defs.h

    r35162 r37067  
    33Average                 *Average_PS1_V4_ToInternal (Average_PS1_V4 *in, off_t Nvalues, SecFilt **primary);
    44Average_PS1_V4          *AverageInternalTo_PS1_V4 (Average *in, off_t Nvalues, SecFilt *primary);
    5 Measure                 *Measure_PS1_V4_ToInternal (Measure_PS1_V4 *in, off_t Nvalues);
    6 Measure_PS1_V4          *MeasureInternalTo_PS1_V4 (Measure *in, off_t Nvalues);
     5Measure                 *Measure_PS1_V4_ToInternal (Average *ave, Measure_PS1_V4 *in, off_t Nvalues);
     6Measure_PS1_V4          *MeasureInternalTo_PS1_V4 (Average *ave, Measure *in, off_t Nvalues);
    77SecFilt                 *SecFilt_PS1_V4_ToInternal (SecFilt_PS1_V4 *in, off_t Nvalues);
    88SecFilt_PS1_V4          *SecFiltInternalTo_PS1_V4 (SecFilt *in, off_t Nvalues);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/BoundaryTree.c

    r35755 r37067  
    11# include "dvo.h"
    22
    3 # define GET_COLUMN_NEW(OUT,NAME,TYPE)                                  \
    4   TYPE *OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \
     3# define GET_COLUMN_NEW(HEADER,FTABLE,OUT,NAME,TYPE)                            \
     4  TYPE *OUT = gfits_get_bintable_column_data (HEADER, FTABLE, NAME, type, &Nrow, &Ncol); \
    55  myAssert (!strcmp(type, #TYPE), "wrong column type");
    66
    7 # define GET_COLUMN_RAW(OUT,NAME,TYPE)                                  \
    8   OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \
     7# define GET_COLUMN_RAW(HEADER,FTABLE,OUT,NAME,TYPE)                    \
     8  OUT = gfits_get_bintable_column_data (HEADER, FTABLE, NAME, type, &Nrow, &Ncol); \
    99  myAssert (!strcmp(type, #TYPE), "wrong column type");
    1010
     
    1212
    1313BoundaryTree *BoundaryTreeLoad(char *filename) {
     14
     15  Header header;
     16  Header theader;
     17  Matrix matrix;
     18
     19  header.buffer = NULL;
     20  matrix.buffer = NULL;
     21  theader.buffer = NULL;
     22  BoundaryTree *tree = NULL;
     23
     24  FILE *f = fopen (filename, "r");
     25  if (!f) {
     26    fprintf (stderr, "ERROR: cannot open boundary tree file %s\n", filename);
     27    return NULL;
     28  }
     29
     30  /* load in PHU segment (ignore) */
     31  if (!gfits_fread_header (f, &header)) {
     32    if (DEBUG) fprintf (stderr, "can't read boundary tree header\n");
     33    goto escape;
     34  }
     35  if (!gfits_fread_matrix (f, &matrix, &header)) {
     36    if (DEBUG) fprintf (stderr, "can't read boundary tree matrix\n");
     37    goto escape;
     38  }
     39
     40  // load data for this header
     41  if (!gfits_load_header (f, &theader)) {
     42    if (DEBUG) fprintf (stderr, "can't read boundary tree zone table header\n");
     43    goto escape;
     44  }
     45
     46  tree = BoundaryTreeRead (&header, &theader, f);
     47
     48escape:
     49
     50  gfits_free_header (&theader);
     51  gfits_free_header (&header);
     52  gfits_free_matrix (&matrix);
     53  fclose (f);
     54
     55  return tree;
     56}
     57
     58// assume we are pointing at the relevant table portion
     59BoundaryTree *BoundaryTreeRead(Header *headerPHU, Header *headerZone, FILE *f) {
    1460
    1561  int i, j, nz, nb, Ncol;
    1662  off_t Nrow;
    1763  char type[16];
    18   Header header;
    19   Header theader;
    20   Matrix matrix;
    21   FTable ftable;
    22 
    23   header.buffer = NULL;
    24   matrix.buffer = NULL;
    25   ftable.buffer = NULL;
    26   theader.buffer = NULL;
     64
     65  FTable ftableZone;
     66
     67  Header headerCell;
     68  FTable ftableCell;
     69
     70  ftableZone.buffer = NULL;
     71  ftableCell.buffer = NULL;
     72  headerCell.buffer = NULL;
     73
     74  // we must have already read in the Zone table header section
     75  ftableZone.header =  headerZone;
     76  ftableCell.header = &headerCell;
     77
    2778  BoundaryTree *tree = NULL;
    2879
    29   FILE *f = fopen (filename, "r");
    30   if (!f) {
    31     fprintf (stderr, "ERROR: cannot open image subset file %s\n", filename);
    32     return NULL;
    33   }
    34 
    35   /* load in PHU segment (ignore) */
    36   if (!gfits_fread_header (f, &header)) {
    37     if (DEBUG) fprintf (stderr, "can't read image subset header\n");
    38     goto escape;
    39   }
    40   if (!gfits_fread_matrix (f, &matrix, &header)) {
    41     if (DEBUG) fprintf (stderr, "can't read image subset matrix\n");
    42     goto escape;
    43   }
    44 
    4580  ALLOCATE (tree, BoundaryTree, 1);
    4681
    47   gfits_scan (&header, "DEC_ORI", "%lf", 1, &tree->DEC_origin);
    48   gfits_scan (&header, "DEC_OFF", "%lf", 1, &tree->DEC_offset);
    49 
    50   gfits_scan (&header, "NX_SUB", "%d", 1, &tree->NX_SUB);
    51   gfits_scan (&header, "NY_SUB", "%d", 1, &tree->NY_SUB);
    52   gfits_scan (&header, "PIXSCALE", "%lf", 1, &tree->dPix);
    53 
    54   ftable.header = &theader;
     82  // we need to read the boundary tree parameters from the correct header
     83  // put them in the PHU header in any case?
     84  gfits_scan (headerPHU, "DEC_ORI",  "%lf", 1, &tree->DEC_origin);
     85  gfits_scan (headerPHU, "DEC_OFF",  "%lf", 1, &tree->DEC_offset);
     86  gfits_scan (headerPHU, "NX_SUB",   "%d",  1, &tree->NX_SUB);
     87  gfits_scan (headerPHU, "NY_SUB",   "%d",  1, &tree->NY_SUB);
     88  gfits_scan (headerPHU, "PIXSCALE", "%lf", 1, &tree->dPix);
    5589
    5690  /*** zone information table ***/
    57   {
    58     // load data for this header
    59     if (!gfits_load_header (f, &theader)) goto escape;
    60 
    61     // read the fits table bytes
    62     if (!gfits_fread_ftable_data (f, &ftable, FALSE)) goto escape;
     91
     92  // read the fits table bytes
     93  if (!gfits_fread_ftable_data (f, &ftableZone, FALSE)) goto escape;
    6394 
    64     // need to create and assign to flat-field correction
    65     GET_COLUMN_RAW(tree->Nband,       "NBAND",           int);
    66     GET_COLUMN_RAW(tree->RA_origin,   "RA_ORIGIN",   double);
    67     GET_COLUMN_RAW(tree->RA_offset,   "RA_OFFSET",   double);
    68     GET_COLUMN_RAW(tree->DEC_min  ,   "DEC_MIN",     double);
    69     GET_COLUMN_RAW(tree->DEC_max  ,   "DEC_MAX",     double);
    70     GET_COLUMN_RAW(tree->DEC_min_raw, "DEC_MIN_RAW", double);
    71     GET_COLUMN_RAW(tree->DEC_max_raw, "DEC_MAX_RAW", double);
    72     gfits_free_header (&theader);
    73     gfits_free_table  (&ftable);
    74 
    75     fprintf (stderr, "loaded data for %lld zones\n", (long long) Nrow);
    76     tree->Nzone = Nrow;
    77 
    78     // allocate the storage arrays
    79     ALLOCATE (tree->ra,   double *, tree->Nzone);
    80     ALLOCATE (tree->dec,  double *, tree->Nzone);
    81     ALLOCATE (tree->Xo,   double *, tree->Nzone);
    82     ALLOCATE (tree->Yo,   double *, tree->Nzone);
    83     ALLOCATE (tree->dX,      int *, tree->Nzone);
    84     ALLOCATE (tree->dY,      int *, tree->Nzone);
    85     ALLOCATE (tree->cell,    int *, tree->Nzone);
    86     ALLOCATE (tree->projID,  int *, tree->Nzone);
    87     ALLOCATE (tree->name,  char **, tree->Nzone);
    88     for (i = 0; i < tree->Nzone; i++) {
    89       ALLOCATE (tree->ra[i],   double, tree->Nband[i]);
    90       ALLOCATE (tree->dec[i],  double, tree->Nband[i]);
    91       ALLOCATE (tree->Xo[i],   double, tree->Nband[i]);
    92       ALLOCATE (tree->Yo[i],   double, tree->Nband[i]);
    93       ALLOCATE (tree->dX[i],      int, tree->Nband[i]);
    94       ALLOCATE (tree->dY[i],      int, tree->Nband[i]);
    95       ALLOCATE (tree->cell[i],    int, tree->Nband[i]);
    96       ALLOCATE (tree->projID[i],  int, tree->Nband[i]);
    97       ALLOCATE (tree->name[i], char *, tree->Nband[i]);
    98       for (j = 0; j < tree->Nband[i]; j++) {
    99         ALLOCATE (tree->name[i][j], char, BOUNDARY_TREE_NAME_LENGTH);
    100       }
     95  // need to create and assign to flat-field correction
     96  GET_COLUMN_RAW(headerZone, &ftableZone, tree->Nband,       "NBAND",       int);
     97  GET_COLUMN_RAW(headerZone, &ftableZone, tree->RA_origin,   "RA_ORIGIN",   double);
     98  GET_COLUMN_RAW(headerZone, &ftableZone, tree->RA_offset,   "RA_OFFSET",   double);
     99  GET_COLUMN_RAW(headerZone, &ftableZone, tree->DEC_min  ,   "DEC_MIN",     double);
     100  GET_COLUMN_RAW(headerZone, &ftableZone, tree->DEC_max  ,   "DEC_MAX",     double);
     101  GET_COLUMN_RAW(headerZone, &ftableZone, tree->DEC_min_raw, "DEC_MIN_RAW", double);
     102  GET_COLUMN_RAW(headerZone, &ftableZone, tree->DEC_max_raw, "DEC_MAX_RAW", double);
     103  gfits_free_table  (&ftableZone);
     104
     105  fprintf (stderr, "loaded data for %lld zones\n", (long long) Nrow);
     106  tree->Nzone = Nrow;
     107
     108  // allocate the storage arrays
     109  ALLOCATE (tree->ra,   double *, tree->Nzone);
     110  ALLOCATE (tree->dec,  double *, tree->Nzone);
     111  ALLOCATE (tree->Xo,   double *, tree->Nzone);
     112  ALLOCATE (tree->Yo,   double *, tree->Nzone);
     113  ALLOCATE (tree->dX,      int *, tree->Nzone);
     114  ALLOCATE (tree->dY,      int *, tree->Nzone);
     115  ALLOCATE (tree->cell,    int *, tree->Nzone);
     116  ALLOCATE (tree->projID,  int *, tree->Nzone);
     117  ALLOCATE (tree->name,  char **, tree->Nzone);
     118  for (i = 0; i < tree->Nzone; i++) {
     119    ALLOCATE (tree->ra[i],   double, tree->Nband[i]);
     120    ALLOCATE (tree->dec[i],  double, tree->Nband[i]);
     121    ALLOCATE (tree->Xo[i],   double, tree->Nband[i]);
     122    ALLOCATE (tree->Yo[i],   double, tree->Nband[i]);
     123    ALLOCATE (tree->dX[i],      int, tree->Nband[i]);
     124    ALLOCATE (tree->dY[i],      int, tree->Nband[i]);
     125    ALLOCATE (tree->cell[i],    int, tree->Nband[i]);
     126    ALLOCATE (tree->projID[i],  int, tree->Nband[i]);
     127    ALLOCATE (tree->name[i], char *, tree->Nband[i]);
     128    for (j = 0; j < tree->Nband[i]; j++) {
     129      ALLOCATE (tree->name[i][j], char, BOUNDARY_TREE_NAME_LENGTH);
    101130    }
    102131  }
    103132
    104133  /*** cell information table ***/
    105   {
    106     // load data for this header
    107     if (!gfits_load_header (f, &theader)) goto escape;
    108 
    109     // read the fits table bytes
    110     if (!gfits_fread_ftable_data (f, &ftable, FALSE)) goto escape;
     134
     135  // load data for this header
     136  if (!gfits_load_header (f, &headerCell)) goto escape;
     137
     138  // read the fits table bytes
     139  if (!gfits_fread_ftable_data (f, &ftableCell, FALSE)) goto escape;
    111140 
    112     // need to create and assign to flat-field correction
    113     GET_COLUMN_NEW(R,     "RA",          double);
    114     GET_COLUMN_NEW(D,     "DEC",         double);
    115     GET_COLUMN_NEW(zone,  "ZONE",        int);
    116     GET_COLUMN_NEW(band,  "BAND",        int);
    117     GET_COLUMN_NEW(index, "INDEX",       int);
    118     GET_COLUMN_NEW(Xo,    "X_CENT",      double);
    119     GET_COLUMN_NEW(Yo,    "Y_CENT",      double);
    120     GET_COLUMN_NEW(dX,    "X_GRID",      int);
    121     GET_COLUMN_NEW(dY,    "Y_GRID",      int);
    122     GET_COLUMN_NEW(name,  "NAME",        char); // XXX how is this done?
    123     gfits_free_header (&theader);
    124     gfits_free_table  (&ftable);
    125     fprintf (stderr, "loaded data for %lld cells\n", (long long) Nrow);
    126 
    127     // assign the storage arrays
    128     for (i = 0; i < Nrow; i++) {
    129       nz = zone[i];
    130       nb = band[i];
    131       tree->ra[nz][nb] = R[i];
    132       tree->dec[nz][nb] = D[i];
    133       tree->Xo[nz][nb] = Xo[i];
    134       tree->Yo[nz][nb] = Yo[i];
    135       tree->dX[nz][nb] = dX[i];
    136       tree->dY[nz][nb] = dY[i];
    137       tree->cell[nz][nb] = i; // XXX ?
    138       memcpy(tree->name[nz][nb], &name[i*BOUNDARY_TREE_NAME_LENGTH], BOUNDARY_TREE_NAME_LENGTH);
    139       // XXX parse out the ID from the name (skycell.NNNN)
    140       tree->projID[nz][nb] = atoi(&tree->name[nz][nb][8]);
    141     }
    142 
    143     free (R     );
    144     free (D     );
    145     free (zone  );
    146     free (band  );
    147     free (Xo    );
    148     free (Yo    );
    149     free (dX    );
    150     free (dY    );
    151     free (index );
    152     free (name  );
    153   }
    154 
    155   gfits_free_header (&header);
    156   gfits_free_matrix (&matrix);
    157   fclose (f);
     141  // need to create and assign to flat-field correction
     142  GET_COLUMN_NEW(&headerCell, &ftableCell, R,     "RA",          double);
     143  GET_COLUMN_NEW(&headerCell, &ftableCell, D,     "DEC",         double);
     144  GET_COLUMN_NEW(&headerCell, &ftableCell, zone,  "ZONE",        int);
     145  GET_COLUMN_NEW(&headerCell, &ftableCell, band,  "BAND",        int);
     146  GET_COLUMN_NEW(&headerCell, &ftableCell, index, "INDEX",       int);
     147  GET_COLUMN_NEW(&headerCell, &ftableCell, Xo,    "X_CENT",      double);
     148  GET_COLUMN_NEW(&headerCell, &ftableCell, Yo,    "Y_CENT",      double);
     149  GET_COLUMN_NEW(&headerCell, &ftableCell, dX,    "X_GRID",      int);
     150  GET_COLUMN_NEW(&headerCell, &ftableCell, dY,    "Y_GRID",      int);
     151  GET_COLUMN_NEW(&headerCell, &ftableCell, name,  "NAME",        char); // XXX how is this done?
     152  gfits_free_header (&headerCell);
     153  gfits_free_table  (&ftableCell);
     154
     155  fprintf (stderr, "loaded data for %lld cells\n", (long long) Nrow);
     156
     157  // assign the storage arrays
     158  for (i = 0; i < Nrow; i++) {
     159    nz = zone[i];
     160    nb = band[i];
     161    tree->ra[nz][nb] = R[i];
     162    tree->dec[nz][nb] = D[i];
     163    tree->Xo[nz][nb] = Xo[i];
     164    tree->Yo[nz][nb] = Yo[i];
     165    tree->dX[nz][nb] = dX[i];
     166    tree->dY[nz][nb] = dY[i];
     167    tree->cell[nz][nb] = i; // XXX ?
     168    memcpy(tree->name[nz][nb], &name[i*BOUNDARY_TREE_NAME_LENGTH], BOUNDARY_TREE_NAME_LENGTH);
     169    // XXX parse out the ID from the name (skycell.NNNN)
     170    tree->projID[nz][nb] = atoi(&tree->name[nz][nb][8]);
     171  }
     172
     173  free (R     );
     174  free (D     );
     175  free (zone  );
     176  free (band  );
     177  free (Xo    );
     178  free (Yo    );
     179  free (dX    );
     180  free (dY    );
     181  free (index );
     182  free (name  );
    158183
    159184  return tree;
    160185
    161186escape:
    162   gfits_free_header (&header);
    163   gfits_free_matrix (&matrix);
    164   gfits_free_header (&theader);
    165   gfits_free_table  (&ftable);
     187  gfits_free_header (&headerCell);
     188  gfits_free_table  (&ftableCell);
     189  gfits_free_table  (&ftableZone);
    166190  if (tree) free (tree);
    167191
    168   fclose (f);
    169192  return NULL;
    170193}
     
    173196int BoundaryTreeSave(char *filename, BoundaryTree *tree) {
    174197
    175   int i, nz, nb;
    176198  Header header;
    177   Header theader;
    178199  Matrix matrix;
    179   FTable ftable;
    180200
    181201  gfits_init_header (&header);
     
    202222  gfits_free_header (&header);
    203223  gfits_free_matrix (&matrix);
     224
     225  BoundaryTreeWrite (f, tree);
     226  fclose (f);
     227
     228  return TRUE;
     229}
     230
     231int BoundaryTreeWrite(FILE *f, BoundaryTree *tree) {
     232
     233  int i, nz, nb;
     234  Header theader;
     235  FTable ftable;
    204236
    205237  /*** zone information table ***/
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/HostTable.c

    r35102 r37067  
    8686      FreeHosts (hosts, Nhosts);
    8787      free (filename);
     88      fclose (f);
    8889      return NULL;
    8990    }
     
    133134
    134135  free (filename);
     136  fclose (f);
    135137  return table;
    136138}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/ImageMetadata.c

    r35416 r37067  
    124124  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_SUBSET");
    125125
    126   gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image ID", NULL, 1.0, 1.0*0x8000);
    127   gfits_define_bintable_column (&theader, "J", "EXTERN_ID", "extern ID", NULL, 1.0, 1.0*0x8000);
    128   gfits_define_bintable_column (&theader, "J", "EXPNAME_AS_INT", "expname as integer", NULL, 1.0, 1.0*0x8000);
    129   gfits_define_bintable_column (&theader, "D", "CRVAL1", "ra at center", "degrees", 1.0, 0.0);
    130   gfits_define_bintable_column (&theader, "D", "CRVAL2", "dec at center", "degrees", 1.0, 0.0);
    131   gfits_define_bintable_column (&theader, "E", "THETA", "camera rot angle", "degrees", 1.0, 0.0);
    132   gfits_define_bintable_column (&theader, "E", "MCAL", "zero point offset", "magnitudes", 1.0, 0.0);
    133   gfits_define_bintable_column (&theader, "E", "SECZ", "airmass", "none", 1.0, 0.0);
    134   gfits_define_bintable_column (&theader, "E", "X_CENTER", "chip center", "none", 1.0, 0.0);
    135   gfits_define_bintable_column (&theader, "E", "Y_CENTER", "chip center", "none", 1.0, 0.0);
     126  gfits_define_bintable_column (&theader, "J", "IMAGE_ID",       "image ID",           NULL,         1.0, FT_BZERO_INT32);
     127  gfits_define_bintable_column (&theader, "J", "EXTERN_ID",      "extern ID",          NULL,         1.0, FT_BZERO_INT32);
     128  gfits_define_bintable_column (&theader, "J", "EXPNAME_AS_INT", "expname as integer", NULL,         1.0, FT_BZERO_INT32);
     129  gfits_define_bintable_column (&theader, "D", "CRVAL1",         "ra at center",       "degrees",    1.0, 0.0);
     130  gfits_define_bintable_column (&theader, "D", "CRVAL2",         "dec at center",      "degrees",    1.0, 0.0);
     131  gfits_define_bintable_column (&theader, "E", "THETA",          "camera rot angle",   "degrees",    1.0, 0.0);
     132  gfits_define_bintable_column (&theader, "E", "MCAL",           "zero point offset", "magnitudes", 1.0, 0.0);
     133  gfits_define_bintable_column (&theader, "E", "SECZ",           "airmass",            "none",      1.0, 0.0);
     134  gfits_define_bintable_column (&theader, "E", "X_CENTER",       "chip center",        "none",      1.0, 0.0);
     135  gfits_define_bintable_column (&theader, "E", "Y_CENTER",       "chip center",        "none",      1.0, 0.0);
    136136
    137137  // generate the output array that carries the data
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/ImageMetadataSelection.c

    r35416 r37067  
    1818  field.pc1_2  = field.pc2_1  = 0.0;
    1919  field.Npolyterms = 0;
    20   strcpy (field.ctype, "RA---SIN");
     20  strcpy (field.ctype, "DEC--SIN");
    2121
    2222  /* mosaic defines a frame with 0,0 at the mosaic center, and 1 arcsec / pixel */
     
    2626  mosaic.pc1_2  = mosaic.pc2_1  = 0.0;
    2727  mosaic.Npolyterms = 0;
    28   strcpy (mosaic.ctype, "RA---SIN");
     28  strcpy (mosaic.ctype, "DEC--SIN");
    2929
    3030  if ((image = ImageMetadataLoad (filename, &Nimage)) == NULL) return (FALSE);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/ImageSelection.c

    r35416 r37067  
    2828      mosaic.pc1_2  = mosaic.pc2_1  = 0.0;
    2929      mosaic.Npolyterms = 0;
    30       strcpy (mosaic.ctype, "RA---SIN");
     30      strcpy (mosaic.ctype, "DEC--SIN");
    3131  }
    3232
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/LoadPhotcodesFITS.c

    r35755 r37067  
    6464  CONVERT_FORMAT("DVO_PHOTCODE_PS1_V3",    PS1_V3);
    6565  CONVERT_FORMAT("DVO_PHOTCODE_PS1_V4",    PS1_V4);
     66  CONVERT_FORMAT("DVO_PHOTCODE_PS1_V5",    PS1_V5);
    6667
    6768  table = GetPhotcodeTable ();
     
    100101  // photcode.equiv of 0 means "undefined"
    101102  for (i = 0; i < Ncode; i++) {
     103    if (!strcasecmp(photcode[i].name, "MAG")) {
     104      fprintf (stderr, "MAG is not an allowed photcode name (reserved to DVO internals)\n");
     105      free (photcode);
     106      return FALSE;
     107    }
     108    if (!strcasecmp(photcode[i].name, "FLUX")) {
     109      fprintf (stderr, "FLUX is not an allowed photcode name (reserved to DVO internals)\n");
     110      free (photcode);
     111      return FALSE;
     112    }
     113
    102114    if (photcode[i].type == PHOT_DEP) {
    103115      if (photcode[i].equiv == 0) continue;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/LoadPhotcodesText.c

    r28833 r37067  
    108108    }
    109109
     110    if (!strcasecmp(name, "MAG")) {
     111      fprintf (stderr, "MAG is not an allowed photcode name (reserved to DVO internals)\n");
     112      return FALSE;
     113    }
     114
    110115    photcode[Ncode].type = 0;
    111116    memset(photcode[Ncode].dummy, 0, sizeof(photcode[Ncode].dummy));
     
    137142    photcode[Ncode].photomErrSys      = atof (photomErrSys);
    138143
    139     photcode[Ncode].astromPoorMask    = strtol (astromPoorMask, NULL, 0);
    140     photcode[Ncode].astromBadMask     = strtol (astromBadMask, NULL, 0);
    141     photcode[Ncode].photomPoorMask    = strtol (photomPoorMask, NULL, 0);
    142     photcode[Ncode].photomBadMask     = strtol (photomBadMask, NULL, 0);
     144    photcode[Ncode].astromPoorMask    = strtoll (astromPoorMask, NULL, 0);
     145    photcode[Ncode].astromBadMask     = strtoll (astromBadMask, NULL, 0);
     146    photcode[Ncode].photomPoorMask    = strtoll (photomPoorMask, NULL, 0);
     147    photcode[Ncode].photomBadMask     = strtoll (photomBadMask, NULL, 0);
    143148
    144149    switch (photcode[Ncode].type) {
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/SavePhotcodesFITS.c

    r34260 r37067  
    3030  // for the moment, we simply support the latest photcode format for output
    3131  // XXX update this as needed as new formats are defined
    32   PhotCode_PS1_V4 *photcode_output = PhotCode_Internal_To_PS1_V4 (table[0].code, table[0].Ncode);
     32  PhotCode_PS1_V5 *photcode_output = PhotCode_Internal_To_PS1_V5 (table[0].code, table[0].Ncode);
    3333
    3434  /* convert FITS format data to internal format (byteswaps & EXTNAME) */
    3535  if (!gfits_db_create (&db)) return (FALSE);
    36   if (!gfits_table_set_PhotCode_PS1_V4 (&db.ftable, photcode_output, table[0].Ncode)) return (FALSE);
     36  if (!gfits_table_set_PhotCode_PS1_V5 (&db.ftable, photcode_output, table[0].Ncode)) return (FALSE);
    3737  if (!gfits_db_save (&db)) return (FALSE);
    3838  if (!gfits_db_close (&db)) return (FALSE);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/cmf-ps1-dv3.c

    r35416 r37067  
    22
    33/*** note : this file is derived from the autocode version, but is modified because
    4      the forma does not match with structure byte boundaries ***/
     4     the format does not match with structure byte boundaries ***/
    55
    66/* if we are not correctly including the ohana headers, this will fail */
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/coordops.c

    r34088 r37067  
    11# include <dvo.h>
     2
     3/* note that Coords.ctype carries the DEC (ctype2) value */
    24
    35static Coords mosaic;
     
    621623
    622624  /* modifications to the ctype? */
     625  /* note that Coords.ctype carries the DEC (ctype2) value */
    623626  OldAIPS = FALSE;
    624627  gfits_modify (header, "CTYPE2",   "%s",  1, coords[0].ctype);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dbCheckStack.c

    r35755 r37067  
    77// these would be better done using bit values to test for field? temp? float?
    88//
    9 
    10 #define OPIHI_INT 1
    119
    1210int dbCheckStack (dbStack *stack, int Nstack, int table, dbField **inFields, int *inNfields) {
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dbExtractAverages.c

    r35416 r37067  
    5252dbValue dbExtractAverages (Average *average, SecFilt *secfilt, Measure *measure, dbField *field) {
    5353
    54   off_t i;
    55   int Nsec;
     54  // off_t i;
    5655  dbValue value;
    5756
     
    153152      break;
    154153
     154    case AVE_PSF_QF:
     155      value.Flt = average[0].psfQF;
     156      break;
     157    case AVE_PSF_QF_PERF:
     158      value.Flt = average[0].psfQFperf;
     159      break;
     160    case AVE_STARGAL:
     161      value.Flt = average[0].stargal;
     162      break;
     163    case AVE_REF_COLOR:
     164      value.Flt = average[0].refColorBlue;
     165      break;
     166
    155167    case AVE_OBJ_FLAGS:
    156168      value.Int = average[0].flags;
     
    169181      break;
    170182
    171     case AVE_MAG:
     183    case AVE_PHOT:
     184      // if we request mag:ave, use equiv for photcode (ie a given measure, say GPC1.g.XY01, will return g for mag:ave)
     185      if  (field->photcode->type == PHOT_MAG) {
     186        // this is an error
     187        break;
     188      }
     189
     190      // if we ask for 2MASS_K, etc (REF values), return NAN unless measure->code matches
     191      if (field->photcode->type == PHOT_REF) {
     192        // need to ensure measure exists.
     193        break;
     194      }
     195
     196      // if we ask for GPC1.g.XY03:rel, etc (DEP values), return NAN unless measure->code matches
     197      if (field->photcode->type == PHOT_DEP) {
     198        // again.
     199        break;
     200      }
     201
     202      switch (field->magOption) {
     203        case MAG_OPTION_MAG:
     204          switch (field->magLevel) {
     205            case MAG_LEVEL_AVE:
     206              value.Flt = PhotAve  (field->photcode, average, secfilt, field->magClass, field->magSource);
     207              break;
     208            case MAG_LEVEL_REF:
     209              // why is measure needed here?
     210              // PhotRef  (field->photcode, average, secfilt, measure, field->magClass, field->magSource);
     211              break;
     212            case MAG_LEVEL_INST:
     213            case MAG_LEVEL_CAT:
     214            case MAG_LEVEL_SYS:
     215            case MAG_LEVEL_REL:
     216            case MAG_LEVEL_CAL:
     217            case MAG_LEVEL_NONE:
     218              break;
     219          }
     220          break;
     221
     222        case MAG_OPTION_ERR:
     223          switch (field->magLevel) {
     224            case MAG_LEVEL_AVE:
     225            case MAG_LEVEL_REF:
     226              value.Flt = PhotAveErr (field->photcode, average, secfilt, field->magClass, field->magSource); 
     227              break;
     228            case MAG_LEVEL_INST:
     229            case MAG_LEVEL_CAT:
     230            case MAG_LEVEL_SYS:
     231            case MAG_LEVEL_REL:
     232            case MAG_LEVEL_CAL:
     233            case MAG_LEVEL_NONE:
     234              break;
     235          }
     236          break;
     237
     238        case MAG_OPTION_FLUX:
     239          switch (field->magLevel) {
     240            case MAG_LEVEL_AVE:
     241              value.Flt = PhotFluxAve  (field->photcode, average, secfilt, field->magClass, field->magSource);
     242              break;
     243            case MAG_LEVEL_REF:
     244              // value.Flt = PhotFluxRef  (equiv, average, secfilt, measure, field->magClass, field->magSource);
     245              break;
     246            case MAG_LEVEL_INST:
     247            case MAG_LEVEL_CAT:
     248            case MAG_LEVEL_SYS:
     249            case MAG_LEVEL_REL:
     250            case MAG_LEVEL_CAL:
     251            case MAG_LEVEL_NONE:
     252              break;
     253          }
     254          break;
     255
     256        case MAG_OPTION_FLUX_ERR:
     257          switch (field->magLevel) {
     258            case MAG_LEVEL_AVE:
     259            case MAG_LEVEL_REF:
     260              // value.Flt = PhotFluxAveErr (equiv, average, secfilt, field->magClass, field->magSource); 
     261              break;
     262            case MAG_LEVEL_INST:
     263            case MAG_LEVEL_CAT:
     264            case MAG_LEVEL_SYS:
     265            case MAG_LEVEL_REL:
     266            case MAG_LEVEL_CAL:
     267            case MAG_LEVEL_NONE:
     268              break;
     269          }
     270          break;
     271
     272        case MAG_OPTION_STDEV:
     273        case MAG_OPTION_CHISQ:
     274        case MAG_OPTION_MIN:
     275        case MAG_OPTION_MAX:
     276        case MAG_OPTION_NCODE: {
     277          int Nsec = GetPhotcodeNsec (field->photcode->code);
     278          if (Nsec == -1) break;
     279          value.Int = secfilt[Nsec].Ncode;
     280          break;
     281        }
     282        case MAG_OPTION_NPHOT: {
     283          int Nsec = GetPhotcodeNsec (field->photcode->code);
     284          if (Nsec == -1) break;
     285          value.Int = secfilt[Nsec].Nused;
     286          break;
     287        }
     288        case MAG_OPTION_UC_DIST:
     289        case MAG_OPTION_STACK_DET_ID:
     290          value.Int = PhotStackID (field->photcode, average, secfilt);
     291          break;
     292        case MAG_OPTION_FLAGS: {
     293          int Nsec = GetPhotcodeNsec (field->photcode->code);
     294          if (Nsec == -1) break;
     295          value.Int = secfilt[Nsec].flags;
     296          break;
     297        }
     298        case MAG_OPTION_NONE:
     299          break;
     300      }
     301      break;
     302
     303# if (0)
    172304      switch (field->magMode) {
    173305        case MAG_AVE:
     
    201333            }
    202334          } else {
    203             value.Flt = PhotdM (field->photcode, average, secfilt);
     335            value.Flt = PhotAveErr (field->photcode, average, secfilt);
    204336          }
    205337          break;
     
    215347            }
    216348          } else {
    217             Nsec = GetPhotcodeNsec (field->photcode->code);
     349            int Nsec = GetPhotcodeNsec (field->photcode->code);
    218350            if (Nsec == -1) break;
    219351            value.Int = secfilt[Nsec].flags;
     
    223355          // XXX push these into dvo_photcode_ops APIs
    224356          // XXX do I need to allow for conversion to equiv?
    225           Nsec = GetPhotcodeNsec (field->photcode->code);
     357          int Nsec = GetPhotcodeNsec (field->photcode->code);
    226358          if (Nsec == -1) break;
    227359          value.Int = secfilt[Nsec].Ncode;
    228360          break;
    229361        case MAG_NPHOT:
    230           Nsec = GetPhotcodeNsec (field->photcode->code);
     362          int Nsec = GetPhotcodeNsec (field->photcode->code);
    231363          if (Nsec == -1) break;
    232364          value.Int = secfilt[Nsec].Nused;
    233365          break;
    234366
     367        case MAG_APER:
     368        case MAG_APER_AVE:
     369          value.Flt = PhotAperAve (field->photcode, average, secfilt);
     370          break;
     371
     372        case MAG_APER_REF:
     373          value.Flt = PhotAperRef (field->photcode, average, secfilt, measure);
     374          break;
     375
    235376        case MAG_KRON:
     377        case MAG_KRON_AVE:
    236378          value.Flt = PhotKronAve (field->photcode, average, secfilt);
     379          break;
     380
     381        case MAG_KRON_REF:
     382          value.Flt = PhotKronRef (field->photcode, average, secfilt, measure);
    237383          break;
    238384
     
    241387          break;
    242388
    243         case MAG_20:
    244           value.Flt = PhotM20 (field->photcode, average, secfilt);
    245           break;
    246         case MAG_80:
    247           value.Flt = PhotM80 (field->photcode, average, secfilt);
     389        case MAG_MIN:
     390          value.Flt = PhotMmin (field->photcode, average, secfilt);
     391          break;
     392        case MAG_MAX:
     393          value.Flt = PhotMmax (field->photcode, average, secfilt);
    248394          break;
    249395        case MAG_UC_DIST:
     
    269415      break;
    270416    case AVE_dMAG:
    271       value.Flt = PhotdM (field->photcode, average, secfilt);
     417      value.Flt = PhotAveErr (field->photcode, average, secfilt);
    272418      break;
    273419    case AVE_Xm:
    274420      value.Flt = PhotXm (field->photcode, average, secfilt);
    275421      break;
     422# endif
    276423    case AVE_TYPE:
    277424      break;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dbExtractImages.c

    r35102 r37067  
    6969      if (!haveCelestial) {
    7070        if (!FindMosaicForImage (image, Nimage, N)) return value;
    71         x = 0.5*image[N].NX;
    72         y = 0.5*image[N].NY;
     71        if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
     72          x = 0.0;
     73          y = 0.0;
     74        } else {
     75          x = 0.5*image[N].NX;
     76          y = 0.5*image[N].NY;
     77        }
    7378        XY_to_RD (&RAo, &DECo, x, y, &image[N].coords);
    7479        haveCelestial = TRUE;
     
    7984      if (!haveCelestial) {
    8085        if (!FindMosaicForImage (image, Nimage, N)) return value;
    81         x = 0.5*image[N].NX;
    82         y = 0.5*image[N].NY;
     86        if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
     87          x = 0.0;
     88          y = 0.0;
     89        } else {
     90          x = 0.5*image[N].NX;
     91          y = 0.5*image[N].NY;
     92        }
    8393        XY_to_RD (&RAo, &DECo, x, y, &image[N].coords);
    8494        haveCelestial = TRUE;
     
    90100        if (!haveCelestial) {
    91101          if (!FindMosaicForImage (image, Nimage, N)) return value;
    92           x = 0.5*image[N].NX;
    93           y = 0.5*image[N].NY;
     102          if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
     103            x = 0.0;
     104            y = 0.0;
     105          } else {
     106            x = 0.5*image[N].NX;
     107            y = 0.5*image[N].NY;
     108          }
    94109          XY_to_RD (&RAo, &DECo, x, y, &image[N].coords);
    95110          haveCelestial = TRUE;
     
    104119        if (!haveCelestial) {
    105120          if (!FindMosaicForImage (image, Nimage, N)) return value;
    106           x = 0.5*image[N].NX;
    107           y = 0.5*image[N].NY;
     121          if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
     122            x = 0.0;
     123            y = 0.0;
     124          } else {
     125            x = 0.5*image[N].NX;
     126            y = 0.5*image[N].NY;
     127          }
    108128          XY_to_RD (&RAo, &DECo, x, y, &image[N].coords);
    109129          haveCelestial = TRUE;
     
    118138        if (!haveCelestial) {
    119139          if (!FindMosaicForImage (image, Nimage, N)) return value;
    120           x = 0.5*image[N].NX;
    121           y = 0.5*image[N].NY;
     140          if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
     141            x = 0.0;
     142            y = 0.0;
     143          } else {
     144            x = 0.5*image[N].NX;
     145            y = 0.5*image[N].NY;
     146          }
    122147          XY_to_RD (&RAo, &DECo, x, y, &image[N].coords);
    123148          haveCelestial = TRUE;
     
    132157        if (!haveCelestial) {
    133158          if (!FindMosaicForImage (image, Nimage, N)) return value;
    134           x = 0.5*image[N].NX;
    135           y = 0.5*image[N].NY;
     159          if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
     160            x = 0.0;
     161            y = 0.0;
     162          } else {
     163            x = 0.5*image[N].NX;
     164            y = 0.5*image[N].NY;
     165          }
    136166          XY_to_RD (&RAo, &DECo, x, y, &image[N].coords);
    137167          haveCelestial = TRUE;
     
    344374      value.Int = image[N].nLinkAstrom;
    345375      break;
     376
     377    case IMAGE_REF_COLOR:
     378      value.Flt = image[N].refColorBlue;
     379      break;
    346380  }
    347381  return (value);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dbExtractMeasures.c

    r35508 r37067  
    9090  dbValue value;
    9191  double dT;
     92  float dR, dD;
    9293
    9394  Coords *mosaic, *fieldc;
     
    99100
    100101  switch (field->ID) {
    101     case MEAS_MAG: { /* magnitudes are already determined above */
     102    case MEAS_PHOT: { /* magnitudes are already determined above */
    102103      PhotCode *myEquiv = GetPhotcodeEquivbyCode (measure[0].photcode);
    103104
    104       // if we request mag:ave, use equiv for photcode
     105      // if we request mag:ave, use equiv for photcode (ie a given measure, say GPC1.g.XY01, will return g for mag:ave)
    105106      if  (field->photcode->type == PHOT_MAG) {
    106107        equiv = myEquiv;
     
    116117      // if we ask for g:ave, or other SEC-level values, return the corresponding field
    117118      if (field->photcode->type == PHOT_SEC) {
    118         switch (field->magMode) {
     119        switch (field->magLevel) {
    119120          // measure-like : return non-NAN if measure.equiv.photcode matches field.photcode
    120           case MAG_INST:
    121           case MAG_CAT:
    122           case MAG_SYS:
    123           case MAG_REL:
    124           case MAG_CAL:
    125           case MAG_APER:
    126           case MAG_APER_INST:
    127           case MAG_KRON:
    128           case MAG_KRON_INST:
    129           case MAG_KRON_ERR:
    130           case MAG_ERR:
    131           case MAG_PHOT_FLAGS:
     121          case MAG_LEVEL_INST:
     122          case MAG_LEVEL_CAT:
     123          case MAG_LEVEL_SYS:
     124          case MAG_LEVEL_REL:
     125          case MAG_LEVEL_CAL:
    132126            equiv = myEquiv;
    133127            if (equiv && (equiv->code == field->photcode->code)) goto valid_photcode;
     
    135129
    136130            // mean-like : return value for the given photcode
    137           case MAG_AVE:
    138           case MAG_REF:
    139           case MAG_CHISQ:
    140           case MAG_AVE_ERR:
    141           case MAG_NCODE:
    142           case MAG_NPHOT:
    143           case MAG_FLUX_PSF:
    144           case MAG_FLUX_PSF_ERR:
    145           case MAG_FLUX_KRON:
    146           case MAG_FLUX_KRON_ERR:
     131          case MAG_LEVEL_AVE:
     132          case MAG_LEVEL_REF:
    147133            equiv = field->photcode;
    148134            goto valid_photcode;
     
    156142
    157143  valid_photcode:
    158       switch (field->magMode) {
    159         case MAG_INST:
    160           value.Flt = PhotInst (measure); 
    161           break;
    162         case MAG_CAT:
    163           value.Flt = PhotCat  (measure);
    164           break;
    165         case MAG_SYS:
    166           value.Flt = PhotSys  (measure, average, secfilt);
    167           break;
    168         case MAG_REL:
    169           value.Flt = PhotRel  (measure, average, secfilt);
    170           break;
    171         case MAG_CAL:
    172           value.Flt = PhotCal  (measure, average, secfilt, measure, equiv);
    173           break;
    174         case MAG_AVE:
    175           value.Flt = PhotAve  (equiv, average, secfilt);
    176           break;
    177         case MAG_REF:
    178           value.Flt = PhotRef  (equiv, average, secfilt, measure);
    179           break;
    180         case MAG_APER:
    181           value.Flt = PhotAper (measure);
    182           break;
    183         case MAG_APER_INST:
    184           value.Flt = PhotAperInst (measure);
    185           break;
    186         case MAG_KRON:
    187           value.Flt = PhotKron (measure);
    188           break;
    189         case MAG_KRON_INST:
    190           value.Flt = PhotKronInst (measure);
    191           break;
    192         case MAG_KRON_ERR:
    193           value.Flt = measure[0].dMkron;
    194           break;
    195         case MAG_ERR:
    196           value.Flt = measure[0].dM;
    197           break;
    198         case MAG_AVE_ERR:
    199           value.Flt = PhotdM  (equiv, average, secfilt);
    200           break;
    201         case MAG_PHOT_FLAGS:
    202           if ((field->photcode->type == PHOT_REF) || (field->photcode->type == PHOT_DEP)) {
    203             value.Int = measure[0].photFlags;
    204           } else {
    205             value.Int = 0;
     144      switch (field->magOption) {
     145        case MAG_OPTION_MAG:
     146          switch (field->magLevel) {
     147            case MAG_LEVEL_INST:
     148              value.Flt = PhotInst (measure, field->magClass); 
     149              break;
     150            case MAG_LEVEL_CAT:
     151              value.Flt = PhotCat  (measure, field->magClass);
     152              break;
     153            case MAG_LEVEL_SYS:
     154              value.Flt = PhotSys  (measure, average, secfilt, field->magClass);
     155              break;
     156            case MAG_LEVEL_REL:
     157              value.Flt = PhotRel  (measure, average, secfilt, field->magClass);
     158              break;
     159            case MAG_LEVEL_CAL:
     160              value.Flt = PhotCal  (measure, average, secfilt, measure, equiv, field->magClass);
     161              break;
     162            case MAG_LEVEL_AVE:
     163              value.Flt = PhotAve  (equiv, average, secfilt, field->magClass, field->magSource);
     164              break;
     165            case MAG_LEVEL_REF:
     166              value.Flt = PhotRef  (equiv, average, secfilt, measure, field->magClass, field->magSource);
     167              break;
     168            case MAG_LEVEL_NONE:
     169              break;
    206170          }
    207171          break;
    208         case MAG_CHISQ:
    209           value.Flt = PhotXm  (equiv, average, secfilt);
     172
     173        case MAG_OPTION_ERR:
     174          switch (field->magLevel) {
     175            case MAG_LEVEL_INST:
     176            case MAG_LEVEL_CAT:
     177            case MAG_LEVEL_SYS:
     178            case MAG_LEVEL_REL:
     179              value.Flt = PhotErr (measure, field->magClass); 
     180              break;
     181            case MAG_LEVEL_CAL:
     182              value.Flt = PhotCalErr (measure, field->magClass); 
     183              break;
     184            case MAG_LEVEL_AVE:
     185            case MAG_LEVEL_REF:
     186              value.Flt = PhotAveErr (equiv, average, secfilt, field->magClass, field->magSource); 
     187              break;
     188            case MAG_LEVEL_NONE:
     189              break;
     190          }
    210191          break;
    211         case MAG_NCODE:
    212           if (equiv == NULL) {
    213             value.Int = 0;
    214             break;
     192
     193        case MAG_OPTION_FLUX:
     194          switch (field->magLevel) {
     195            case MAG_LEVEL_INST:
     196              value.Flt = PhotFluxInst (measure, field->magClass); 
     197              break;
     198            case MAG_LEVEL_CAT:
     199              value.Flt = PhotFluxCat  (measure, field->magClass);
     200              break;
     201            case MAG_LEVEL_SYS:
     202              value.Flt = PhotFluxSys  (measure, average, secfilt, field->magClass);
     203              break;
     204            case MAG_LEVEL_REL:
     205              value.Flt = PhotFluxRel  (measure, average, secfilt, field->magClass);
     206              break;
     207            case MAG_LEVEL_CAL:
     208              value.Flt = PhotFluxCal  (measure, average, secfilt, measure, equiv, field->magClass);
     209              break;
     210            case MAG_LEVEL_AVE:
     211              value.Flt = PhotFluxAve  (equiv, average, secfilt, field->magClass, field->magSource);
     212              break;
     213            case MAG_LEVEL_REF:
     214              value.Flt = PhotFluxRef  (equiv, average, secfilt, measure, field->magClass, field->magSource);
     215              break;
     216            case MAG_LEVEL_NONE:
     217              break;
    215218          }
    216           Nsec = GetPhotcodeNsec (equiv->code);
    217           if (Nsec == -1) break;
    218           value.Int = secfilt[Nsec].Ncode;
    219219          break;
    220         case MAG_NPHOT:
    221           if (equiv == NULL) {
    222             value.Int = 0;
    223             break;
     220
     221        case MAG_OPTION_FLUX_ERR:
     222          switch (field->magLevel) {
     223            case MAG_LEVEL_INST:
     224              value.Flt = PhotFluxInstErr (measure, field->magClass); 
     225              break;
     226            case MAG_LEVEL_CAT:
     227              value.Flt = PhotFluxCatErr (measure, field->magClass); 
     228              break;
     229            case MAG_LEVEL_SYS:
     230            case MAG_LEVEL_REL:
     231            case MAG_LEVEL_CAL:
     232              // value.Flt = PhotFluxErr (measure, field->magClass); 
     233              break;
     234            case MAG_LEVEL_AVE:
     235            case MAG_LEVEL_REF:
     236              // value.Flt = PhotFluxAveErr (equiv, average, secfilt, field->magClass, field->magSource); 
     237              break;
     238            case MAG_LEVEL_NONE:
     239              break;
    224240          }
    225           Nsec = GetPhotcodeNsec (equiv->code);
    226           if (Nsec == -1) break;
    227           value.Int = secfilt[Nsec].Nused;
    228241          break;
    229         case MAG_FLUX_PSF:
    230           value.Flt = PhotAveFluxPSF (field->photcode, average, secfilt);
    231           break;
    232         case MAG_FLUX_PSF_ERR:
    233           value.Flt = PhotAvedFluxPSF (field->photcode, average, secfilt);
    234           break;
    235         case MAG_FLUX_KRON:
    236           value.Flt = PhotAveFluxKron (field->photcode, average, secfilt);
    237           break;
    238         case MAG_FLUX_KRON_ERR:
    239           value.Flt = PhotAvedFluxKron (field->photcode, average, secfilt);
     242
     243        case MAG_OPTION_STDEV:
     244        case MAG_OPTION_CHISQ:
     245        case MAG_OPTION_MIN:
     246        case MAG_OPTION_MAX:
     247        case MAG_OPTION_NCODE:
     248        case MAG_OPTION_NPHOT:
     249        case MAG_OPTION_UC_DIST:
     250        case MAG_OPTION_STACK_DET_ID:
     251        case MAG_OPTION_FLAGS:
     252        case MAG_OPTION_NONE:
    240253          break;
    241254      }
     
    243256    }
    244257    case MEAS_RA: /* OK */
    245       value.Flt = average[0].R - measure[0].dR / 3600.0;
     258      value.Flt = measure[0].R;
    246259      break;
    247260    case MEAS_DEC: /* OK */
    248       value.Flt = average[0].D - measure[0].dD / 3600.0;
     261      value.Flt = measure[0].D;
    249262      break;
    250263    case MEAS_RA_AVE: /* OK */
     
    257270    case MEAS_GLON:
    258271      if (!haveGalacticMeas) {
    259         ApplyTransform (&GLON_MEAS, &GLAT_MEAS, average[0].R - measure[0].dR / 3600.0, average[0].D - measure[0].dD / 3600.0, celestial_to_galactic);
     272        ApplyTransform (&GLON_MEAS, &GLAT_MEAS, measure[0].R, measure[0].D, celestial_to_galactic);
    260273        haveGalacticMeas = TRUE;
    261274      }
     
    264277    case MEAS_GLAT:
    265278      if (!haveGalacticMeas) {
    266         ApplyTransform (&GLON_MEAS, &GLAT_MEAS, average[0].R - measure[0].dR / 3600.0, average[0].D - measure[0].dD / 3600.0, celestial_to_galactic);
     279        ApplyTransform (&GLON_MEAS, &GLAT_MEAS, measure[0].R, measure[0].D, celestial_to_galactic);
    267280        haveGalacticMeas = TRUE;
    268281      }
     
    271284    case MEAS_ELON:
    272285      if (!haveEclipticMeas) {
    273         ApplyTransform (&ELON_MEAS, &ELAT_MEAS, average[0].R - measure[0].dR / 3600.0, average[0].D - measure[0].dD / 3600.0, celestial_to_ecliptic);
     286        ApplyTransform (&ELON_MEAS, &ELAT_MEAS, measure[0].R, measure[0].D, celestial_to_ecliptic);
    274287        haveEclipticMeas = TRUE;
    275288      }
     
    278291    case MEAS_ELAT:
    279292      if (!haveEclipticMeas) {
    280         ApplyTransform (&ELON_MEAS, &ELAT_MEAS, average[0].R - measure[0].dR / 3600.0, average[0].D - measure[0].dD / 3600.0, celestial_to_ecliptic);
     293        ApplyTransform (&ELON_MEAS, &ELAT_MEAS, measure[0].R, measure[0].D, celestial_to_ecliptic);
    281294        haveEclipticMeas = TRUE;
    282295      }
     
    375388    // the error.
    376389    case MEAS_RA_OFFSET: /* OK */
    377       value.Flt = measure[0].dR;
     390      value.Flt = dvoOffsetR (measure, average);
    378391      break;
    379392    case MEAS_DEC_OFFSET: /* OK */
    380       value.Flt = measure[0].dD;
     393      value.Flt = dvoOffsetD (measure, average);
    381394      break;
    382395    case MEAS_RA_FIT_OFFSET: /* OK */
    383396      dT = (measure[0].t - average[0].Tmean) / (86400*365.25);
    384       value.Flt = average[0].uR * dT + measure[0].dR;
     397      dR = dvoOffsetR (measure, average);
     398      value.Flt = average[0].uR * dT + dR;
    385399      break;
    386400    case MEAS_DEC_FIT_OFFSET: /* OK */
    387401      dT = (measure[0].t - average[0].Tmean) / (86400*365.25);
    388       value.Flt = average[0].uD * dT + measure[0].dD;
     402      dD = dvoOffsetD (measure, average);
     403      value.Flt = average[0].uD * dT + dD;
    389404      break;
    390405    case MEAS_RA_OFFSET_ERR: /* OK */
     
    458473    case MEAS_PLATESCALE: /* OK */
    459474      value.Flt = measure[0].pltscale;
     475      break;
     476
     477    case MEAS_REF_COLOR:
     478      value.Flt = average[0].refColorBlue;
    460479      break;
    461480
     
    486505        // measure.xccd if we need it
    487506        Image *image;
    488         ra  = average[0].R - measure[0].dR / 3600.0;
    489         dec = average[0].D - measure[0].dD / 3600.0;
     507        ra  = measure[0].R;
     508        dec = measure[0].D;
    490509        image = MatchImageDVO (measure[0].t, measure[0].photcode, measure[0].imageID);
    491510        if (image == NULL) break;
     
    501520      {
    502521        Image *image;
    503         ra  = average[0].R - measure[0].dR / 3600.0;
    504         dec = average[0].D - measure[0].dD / 3600.0;
     522        ra  = measure[0].R;
     523        dec = measure[0].D;
    505524        image = MatchImageDVO (measure[0].t, measure[0].photcode, measure[0].imageID);
    506525        if (image == NULL) break;
     
    531550          fieldc = MatchFieldMetadata (measure[0].imageID);
    532551        } else {
    533           fprintf (stderr, "non-parallel Xmos broken\n");
    534           abort();
     552          // fprintf (stderr, "non-parallel Xmos broken\n");
     553          // abort();
    535554          // fieldc = MatchField (measure[0].t, measure[0].photcode);
     555          fieldc = MatchFieldMetadata (measure[0].imageID);
    536556        }
    537557        if (fieldc == NULL) break;
    538         double Rm = average[0].R - measure[0].dR / 3600.0;
    539         double Dm = average[0].D - measure[0].dD / 3600.0;
     558        double Rm = measure[0].R;
     559        double Dm = measure[0].D;
    540560        RD_to_XY (&XFIELD_MEAS, &YFIELD_MEAS, Rm, Dm, fieldc);
    541561      }
     
    547567          fieldc = MatchFieldMetadata (measure[0].imageID);
    548568        } else {
    549           fprintf (stderr, "non-parallel Xmos broken\n");
    550           abort();
     569          // fprintf (stderr, "non-parallel Xmos broken\n");
     570          // abort();
    551571          // fieldc = MatchField (measure[0].t, measure[0].photcode);
     572          fieldc = MatchFieldMetadata (measure[0].imageID);
    552573        }
    553574        if (fieldc == NULL) break;
    554         double Rm = average[0].R - measure[0].dR / 3600.0;
    555         double Dm = average[0].D - measure[0].dD / 3600.0;
     575        double Rm = measure[0].R;
     576        double Dm = measure[0].D;
    556577        RD_to_XY (&XFIELD_MEAS, &YFIELD_MEAS, Rm, Dm, fieldc);
    557578      }
     
    564585          mosaic = MatchMosaicMetadata (measure[0].imageID);
    565586        } else {
    566           fprintf (stderr, "non-parallel Xmos broken\n");
    567           abort();
    568           mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
     587          // fprintf (stderr, "non-parallel Xmos broken\n");
     588          // abort();
     589          // mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
     590          mosaic = MatchMosaicMetadata (measure[0].imageID);
    569591        }
    570592        if (mosaic == NULL) break;
    571         double Rm = average[0].R - measure[0].dR / 3600.0;
    572         double Dm = average[0].D - measure[0].dD / 3600.0;
     593        double Rm = measure[0].R;
     594        double Dm = measure[0].D;
    573595        RD_to_XY (&XMOS_MEAS, &YMOS_MEAS, Rm, Dm, mosaic);
    574596      }
     
    580602          mosaic = MatchMosaicMetadata (measure[0].imageID);
    581603        } else {
    582           fprintf (stderr, "non-parallel Xmos broken\n");
    583           abort();
    584           mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
     604          // fprintf (stderr, "non-parallel Xmos broken\n");
     605          // abort();
     606          // mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
     607          mosaic = MatchMosaicMetadata (measure[0].imageID);
    585608        }
    586609        if (mosaic == NULL) break;
    587         double Rm = average[0].R - measure[0].dR / 3600.0;
    588         double Dm = average[0].D - measure[0].dD / 3600.0;
     610        double Rm = measure[0].R;
     611        double Dm = measure[0].D;
    589612        RD_to_XY (&XMOS_MEAS, &YMOS_MEAS, Rm, Dm, mosaic);
    590613      }
     
    699722      break;
    700723
    701     case MEAS_FLUX_PSF: /* OK */
    702       value.Flt = measure[0].FluxPSF;
    703       break;
    704     case MEAS_FLUX_PSF_ERR: /* OK */
    705       value.Flt = measure[0].dFluxPSF;
    706       break;
    707     case MEAS_FLUX_KRON: /* OK */
    708       value.Flt = measure[0].FluxKron;
    709       break;
    710     case MEAS_FLUX_KRON_ERR: /* OK */
    711       value.Flt = measure[0].dFluxKron;
    712       break;
     724    // case MEAS_FLUX_PSF: /* OK */
     725    //   value.Flt = measure[0].FluxPSF;
     726    //   break;
     727    // case MEAS_FLUX_PSF_ERR: /* OK */
     728    //   value.Flt = measure[0].dFluxPSF;
     729    //   break;
     730    // case MEAS_FLUX_KRON: /* OK */
     731    //   value.Flt = measure[0].FluxKron;
     732    //   break;
     733    // case MEAS_FLUX_KRON_ERR: /* OK */
     734    //   value.Flt = measure[0].dFluxKron;
     735    //   break;
    713736  }
    714737  return (value);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dbFields.c

    r35416 r37067  
    99  for (i = 0; i < Nfields; i++) {
    1010    if (fields[i].name != NULL) free (fields[i].name);
    11     if (fields[i].photcode != NULL) {
    12       if (fields[i].photcode[0].type == PHOT_MAG) {
    13         free (fields[i].photcode);
    14       }
    15     }
    1611  }
    1712  free (fields);
     
    2419  field->ID = 0;
    2520  field->type = OPIHI_FLT;
    26   field->magMode = 0;
     21
     22  field->magSource = MAG_SRC_NONE;
     23  field->magLevel  = MAG_LEVEL_NONE;
     24  field->magClass  = MAG_CLASS_NONE;
     25  field->magOption = MAG_OPTION_NONE;
     26
    2727  field->photcode = NULL;
    2828}
    2929
     30dvoMagSourceType GetMagSource (char *string) {
     31
     32  if (!strcasecmp (string, "chip")) return (MAG_SRC_CHP);
     33  if (!strcasecmp (string, "warp")) return (MAG_SRC_WRP);
     34  if (!strcasecmp (string, "stack")) return (MAG_SRC_STK);
     35
     36  if (!strcasecmp (string, "chp")) return (MAG_SRC_CHP);
     37  if (!strcasecmp (string, "wrp")) return (MAG_SRC_WRP);
     38  if (!strcasecmp (string, "stk")) return (MAG_SRC_STK);
     39
     40  return MAG_SRC_NONE;
     41}
     42
     43dvoMagLevelType GetMagLevel (char *string) {
     44
     45  if (!strcasecmp (string, "inst")) return (MAG_LEVEL_INST);
     46  if (!strcasecmp (string, "cat"))  return (MAG_LEVEL_CAT);
     47  if (!strcasecmp (string, "sys"))  return (MAG_LEVEL_SYS);
     48  if (!strcasecmp (string, "rel"))  return (MAG_LEVEL_REL);
     49  if (!strcasecmp (string, "cal"))  return (MAG_LEVEL_CAL);
     50  if (!strcasecmp (string, "ave"))  return (MAG_LEVEL_AVE);
     51  if (!strcasecmp (string, "ref"))  return (MAG_LEVEL_REF);
     52
     53  return MAG_LEVEL_NONE;
     54}
     55
     56dvoMagClassType GetMagClass (char *string) {
     57
     58  if (!strcasecmp (string, "psf"))   return (MAG_CLASS_PSF);
     59  if (!strcasecmp (string, "kron"))  return (MAG_CLASS_KRON);
     60  if (!strcasecmp (string, "aper"))  return (MAG_CLASS_APER);
     61  if (!strcasecmp (string, "ap"))    return (MAG_CLASS_APER);
     62
     63  return MAG_CLASS_NONE;
     64}
     65
     66dvoMagOptionType GetMagOption (char *string) {
     67
     68  if (!strcasecmp (string, "mag"))          return (MAG_OPTION_MAG);
     69  if (!strcasecmp (string, "err"))          return (MAG_OPTION_ERR);
     70  if (!strcasecmp (string, "magerr"))       return (MAG_OPTION_ERR);
     71  if (!strcasecmp (string, "flux"))         return (MAG_OPTION_FLUX);
     72  if (!strcasecmp (string, "fluxerr"))      return (MAG_OPTION_FLUX_ERR);
     73  if (!strcasecmp (string, "stdev"))        return (MAG_OPTION_STDEV);
     74  if (!strcasecmp (string, "chisq"))        return (MAG_OPTION_CHISQ);
     75  if (!strcasecmp (string, "min"))          return (MAG_OPTION_MIN);
     76  if (!strcasecmp (string, "max"))          return (MAG_OPTION_MAX);
     77  if (!strcasecmp (string, "ncode"))        return (MAG_OPTION_NCODE);
     78  if (!strcasecmp (string, "nphot"))        return (MAG_OPTION_NPHOT);
     79  if (!strcasecmp (string, "uc_dist"))      return (MAG_OPTION_UC_DIST);
     80  if (!strcasecmp (string, "stack_det_id")) return (MAG_OPTION_STACK_DET_ID);
     81  if (!strcasecmp (string, "flags"))        return (MAG_OPTION_FLAGS);
     82
     83  return MAG_OPTION_NONE;
     84}
     85
     86# if (0)
    3087int GetMagMode (char *string) {
    3188
     89  // these all imply PSF mags:
    3290  if (!strcasecmp (string, "inst"))        return (MAG_INST);
    3391  if (!strcasecmp (string, "cat"))         return (MAG_CAT);
     
    3795  if (!strcasecmp (string, "ave"))         return (MAG_AVE);
    3896  if (!strcasecmp (string, "ref"))         return (MAG_REF);
     97  if (!strcasecmp (string, "err"))         return (MAG_ERR);
     98  if (!strcasecmp (string, "aveerr"))      return (MAG_AVE_ERR);
     99
     100  // these are explicit PSF mags:
     101  if (!strcasecmp (string, "psf_inst"))    return (MAG_INST);
     102  if (!strcasecmp (string, "psf_cat"))     return (MAG_CAT);
     103  if (!strcasecmp (string, "psf_sys"))     return (MAG_SYS);
     104  if (!strcasecmp (string, "psf_rel"))     return (MAG_REL);
     105  if (!strcasecmp (string, "psf_cal"))     return (MAG_CAL);
     106  if (!strcasecmp (string, "psf_ave"))     return (MAG_AVE);
     107  if (!strcasecmp (string, "psf_ref"))     return (MAG_REF);
     108  if (!strcasecmp (string, "psf_err"))     return (MAG_ERR);
     109  if (!strcasecmp (string, "psf_aveerr"))  return (MAG_AVE_ERR);
     110
     111  // these are aper mags:
    39112  if (!strcasecmp (string, "ap"))          return (MAG_APER);
    40113  if (!strcasecmp (string, "aper"))        return (MAG_APER);
    41114  if (!strcasecmp (string, "aperinst"))    return (MAG_APER_INST);
    42115  if (!strcasecmp (string, "aper_inst"))   return (MAG_APER_INST);
     116  if (!strcasecmp (string, "aper_cat"))    return (MAG_APER_CAT);
     117  if (!strcasecmp (string, "aper_sys"))    return (MAG_APER_SYS);
     118  if (!strcasecmp (string, "aper_rel"))    return (MAG_APER_REL);
     119  if (!strcasecmp (string, "aper_cal"))    return (MAG_APER_CAL);
     120  if (!strcasecmp (string, "aper_ave"))    return (MAG_APER_AVE);
     121  if (!strcasecmp (string, "aper_ref"))    return (MAG_APER_REF);
     122  if (!strcasecmp (string, "aper_err"))    return (MAG_APER_ERR);
     123
     124  // these are kron mags:
    43125  if (!strcasecmp (string, "kron"))        return (MAG_KRON);
     126  if (!strcasecmp (string, "kron_inst"))   return (MAG_KRON_INST);
     127  if (!strcasecmp (string, "kron_cat"))    return (MAG_KRON_CAT);
     128  if (!strcasecmp (string, "kron_sys"))    return (MAG_KRON_SYS);
     129  if (!strcasecmp (string, "kron_rel"))    return (MAG_KRON_REL);
     130  if (!strcasecmp (string, "kron_cal"))    return (MAG_KRON_CAL);
     131  if (!strcasecmp (string, "kron_ave"))    return (MAG_KRON_AVE);
     132  if (!strcasecmp (string, "kron_ref"))    return (MAG_KRON_REF);
     133  if (!strcasecmp (string, "kron_err"))    return (MAG_KRON_ERR);
    44134  if (!strcasecmp (string, "kroninst"))    return (MAG_KRON_INST);
    45   if (!strcasecmp (string, "kron_inst"))   return (MAG_KRON_INST);
    46135  if (!strcasecmp (string, "kronerr"))     return (MAG_KRON_ERR);
    47   if (!strcasecmp (string, "err"))         return (MAG_ERR);
    48   if (!strcasecmp (string, "aveerr"))      return (MAG_AVE_ERR);
     136
     137  // other fields:
    49138  if (!strcasecmp (string, "photflags"))   return (MAG_PHOT_FLAGS);
    50139  if (!strcasecmp (string, "flags"))       return (MAG_PHOT_FLAGS);
     
    53142  if (!strcasecmp (string, "nphot"))       return (MAG_NPHOT);
    54143  if (!strcasecmp (string, "stdev"))       return (MAG_STDEV);
    55   if (!strcasecmp (string, "20"))          return (MAG_20);
    56   if (!strcasecmp (string, "80"))          return (MAG_80);
     144  if (!strcasecmp (string, "min"))         return (MAG_MIN);
     145  if (!strcasecmp (string, "max"))         return (MAG_MAX);
    57146  if (!strcasecmp (string, "ucdist"))      return (MAG_UC_DIST);
    58147  if (!strcasecmp (string, "stackDetectID")) return (MAG_STACK_DET_ID);
     
    63152  return (MAG_NONE);
    64153}
    65 
    66 PhotCode *ParsePhotcodeField (char *field, int *mode, int defMode) {
    67 
    68   int useDefault;
    69   char *tmpstring, *p;
    70   PhotCode *code;
    71 
    72   *mode = defMode;
    73   useDefault = TRUE;
    74 
    75   p = strchr (field, ':');
    76   if (p != NULL) {
    77     *mode = GetMagMode (p + 1);
    78     useDefault = FALSE;
    79     if (*mode == MAG_NONE) return (NULL);
    80     tmpstring = strncreate (field, p - field);
    81   } else {
    82     tmpstring = strcreate (field);
    83   }
    84   if (!strcasecmp (tmpstring, "MAG")) {
    85     ALLOCATE (code, PhotCode, 1);
    86     code[0].code = 0;
    87     strcpy (code[0].name, "MAG");
    88     code[0].type = PHOT_MAG;
    89     // the field call 'mag' is only valid for mextract
    90     // it should default to REL, but other types should default to AVE
    91     if (useDefault) {
    92       *mode = MAG_REL;
     154# endif
     155
     156// field may be of the form mag:psf:inst:wrp.  except for the first subword,
     157// the words may be in any order
     158int ParsePhotcodeField (dbField *field, char *fieldName, int fieldID) {
     159
     160  int j;
     161
     162  // defaults:
     163  field->ID = fieldID; // change if not true in the end?
     164
     165  // check what options are provided.  do not allow duplicate types
     166  // except mag and flux may exist with err
     167  dvoMagSourceType mySource = MAG_SRC_NONE;
     168  dvoMagLevelType myLevel = MAG_LEVEL_NONE;
     169  dvoMagClassType myClass = MAG_CLASS_NONE;
     170  dvoMagOptionType myOption = MAG_OPTION_NONE;
     171
     172  field->magSource = MAG_SRC_CHP;
     173  field->magLevel  = MAG_LEVEL_AVE;
     174  field->magClass  = MAG_CLASS_PSF;
     175  field->magOption = MAG_OPTION_MAG;
     176
     177  // make a local working copy of fieldName and replace ':' with spaces
     178  char *fieldCopy = strcreate(fieldName);
     179  for (j = 0; fieldCopy[j]; j++) {
     180    if (fieldCopy[j] == ':') fieldCopy[j] = ' ';
     181  }
     182
     183  char *firstWord = getword(fieldCopy);
     184 
     185  // firstWord may be either flux, mag or photcode
     186  if (!strcasecmp (firstWord, "MAG")) {
     187    // default level for 'mag' is rel
     188    field->magLevel  = MAG_LEVEL_REL;
     189    myOption = MAG_OPTION_MAG;
     190  }
     191  if (!strcasecmp (firstWord, "FLUX")) {
     192    // default level for 'flux' is rel
     193    field->magLevel  = MAG_LEVEL_REL;
     194    myOption = MAG_OPTION_FLUX;
     195  }
     196  PhotCode *code = GetPhotcodebyName (firstWord);
     197  free (firstWord);
     198
     199  if (!code) return FALSE;
     200
     201  // defaults for photcode clases
     202  if (code->type == PHOT_DEP) {
     203    field->magLevel = MAG_LEVEL_REL;
     204  }
     205  if (code->type == PHOT_SEC) {
     206    field->magLevel = MAG_LEVEL_AVE;
     207  }
     208  if (code->type == PHOT_REF) {
     209    field->magLevel = MAG_LEVEL_CAT;
     210    // is this one required?
     211  }
     212 
     213  // look at the remaining words and assign properties as approrpiate
     214  char *ptr = skipword(fieldCopy);
     215  while (ptr) {
     216
     217    char *word = getword(ptr);
     218    if (!word) break;
     219   
     220    dvoMagSourceType source = GetMagSource (word);
     221    if (source != MAG_SRC_NONE) {
     222      if (mySource != MAG_SRC_NONE) { fprintf (stderr, "invalid selection %s in %s\n", word, fieldName); free (word); return FALSE; }
     223      mySource = source;
     224      ptr = skipword (ptr);
     225      continue;
    93226    }
    94     free (tmpstring);
    95     return (code);
    96   }
    97   code = GetPhotcodebyName (tmpstring);
    98   if (!code) {
    99       return NULL;
    100   }
    101 
    102   // enforce compatibility
    103   if (useDefault) {
    104     if (code[0].type == PHOT_REF) {
    105       *mode = MAG_CAT;
     227
     228    dvoMagLevelType level = GetMagLevel (word);
     229    if (level != MAG_LEVEL_NONE) {
     230      if (myLevel != MAG_LEVEL_NONE) { fprintf (stderr, "invalid selection %s in %s\n", word, fieldName); free (word); return FALSE; }
     231      myLevel = level;
     232      ptr = skipword (ptr);
     233      continue;
    106234    }
    107     if (code[0].type == PHOT_DEP) {
    108       *mode = MAG_REL;
     235
     236    dvoMagClassType class = GetMagClass (word);
     237    if (class != MAG_CLASS_NONE) {
     238      if (myClass != MAG_CLASS_NONE) { fprintf (stderr, "invalid selection %s in %s\n", word, fieldName); free (word); return FALSE; }
     239      myClass = class;
     240      ptr = skipword (ptr);
     241      continue;
    109242    }
    110   }
    111   free (tmpstring);
    112   return (code);
    113 }
    114 
    115 # define ESCAPE(F,M,T) { \
    116   field->ID = (F); \
    117   field->magMode = (M); \
    118   field->type = (T); \
    119   field->photcode = NULL; \
    120   return (TRUE); }
    121 
    122 int ParseMeasureField (dbField *field, char *fieldName) {
    123 
    124   int mode;
    125   PhotCode *code;
    126 
    127   field->table = DVO_TABLE_MEASURE;
    128   field->name  = strcreate (fieldName);
    129 
    130   if (!strcasecmp (fieldName, "GLON"))       {
    131     dbExtractMeasuresInitTransform (COORD_GALACTIC);
    132     ESCAPE (MEAS_GLON, MAG_NONE, OPIHI_FLT);
    133   }
    134   if (!strcasecmp (fieldName, "GLAT")) {
    135     dbExtractMeasuresInitTransform (COORD_GALACTIC);
    136     ESCAPE (MEAS_GLAT, MAG_NONE, OPIHI_FLT);
    137   }
    138   if (!strcasecmp (fieldName, "GLON:AVE")) {
    139     dbExtractMeasuresInitTransform (COORD_GALACTIC);
    140     ESCAPE (MEAS_GLON_AVE, MAG_NONE, OPIHI_FLT);
    141   }
    142   if (!strcasecmp (fieldName, "GLAT:AVE")) {
    143     dbExtractMeasuresInitTransform (COORD_GALACTIC);
    144     ESCAPE (MEAS_GLAT_AVE, MAG_NONE, OPIHI_FLT);
    145   }
    146 
    147   if (!strcasecmp (fieldName, "ELON"))       {
    148     dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
    149     ESCAPE (MEAS_ELON, MAG_NONE, OPIHI_FLT);
    150   }
    151   if (!strcasecmp (fieldName, "ELAT")) {
    152     dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
    153     ESCAPE (MEAS_ELAT, MAG_NONE, OPIHI_FLT);
    154   }
    155   if (!strcasecmp (fieldName, "ELON:AVE")) {
    156     dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
    157     ESCAPE (MEAS_ELON_AVE, MAG_NONE, OPIHI_FLT);
    158   }
    159   if (!strcasecmp (fieldName, "ELAT:AVE")) {
    160     dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
    161     ESCAPE (MEAS_ELAT_AVE, MAG_NONE, OPIHI_FLT);
    162   }
    163 
    164   if (!strcasecmp (fieldName, "RA"))             ESCAPE (MEAS_RA,             MAG_NONE, OPIHI_FLT);
    165   if (!strcasecmp (fieldName, "DEC"))            ESCAPE (MEAS_DEC,            MAG_NONE, OPIHI_FLT);
    166   if (!strcasecmp (fieldName, "RA:AVE"))         ESCAPE (MEAS_RA_AVE,         MAG_NONE, OPIHI_FLT);
    167   if (!strcasecmp (fieldName, "DEC:AVE"))        ESCAPE (MEAS_DEC_AVE,        MAG_NONE, OPIHI_FLT);
    168   if (!strcasecmp (fieldName, "RA:ERR"))         ESCAPE (MEAS_RA_AVE_ERR,     MAG_NONE, OPIHI_FLT);
    169   if (!strcasecmp (fieldName, "DEC:ERR"))        ESCAPE (MEAS_DEC_AVE_ERR,    MAG_NONE, OPIHI_FLT);
    170   if (!strcasecmp (fieldName, "uRA"))            ESCAPE (MEAS_U_RA,           MAG_NONE, OPIHI_FLT);
    171   if (!strcasecmp (fieldName, "uDEC"))           ESCAPE (MEAS_U_DEC,          MAG_NONE, OPIHI_FLT);
    172   if (!strcasecmp (fieldName, "duRA"))           ESCAPE (MEAS_U_RA_ERR,       MAG_NONE, OPIHI_FLT);
    173   if (!strcasecmp (fieldName, "duDEC"))          ESCAPE (MEAS_U_DEC_ERR,      MAG_NONE, OPIHI_FLT);
    174   if (!strcasecmp (fieldName, "PAR"))            ESCAPE (MEAS_PAR,            MAG_NONE, OPIHI_FLT);
    175   if (!strcasecmp (fieldName, "dPAR"))           ESCAPE (MEAS_PAR_ERR,        MAG_NONE, OPIHI_FLT);
    176   if (!strcasecmp (fieldName, "dR"))             ESCAPE (MEAS_RA_OFFSET,      MAG_NONE, OPIHI_FLT);
    177   if (!strcasecmp (fieldName, "dD"))             ESCAPE (MEAS_DEC_OFFSET,     MAG_NONE, OPIHI_FLT);
    178   if (!strcasecmp (fieldName, "dR:FIT"))         ESCAPE (MEAS_RA_FIT_OFFSET,  MAG_NONE, OPIHI_FLT);
    179   if (!strcasecmp (fieldName, "dD:FIT"))         ESCAPE (MEAS_DEC_FIT_OFFSET, MAG_NONE, OPIHI_FLT);
    180   if (!strcasecmp (fieldName, "dR:ERR"))         ESCAPE (MEAS_RA_OFFSET_ERR,  MAG_NONE, OPIHI_FLT);
    181   if (!strcasecmp (fieldName, "dD:ERR"))         ESCAPE (MEAS_DEC_OFFSET_ERR, MAG_NONE, OPIHI_FLT);
    182   if (!strcasecmp (fieldName, "ChiSqPos"))       ESCAPE (MEAS_CHISQ_POS,      MAG_NONE, OPIHI_FLT);
    183   if (!strcasecmp (fieldName, "ChiSqPM"))        ESCAPE (MEAS_CHISQ_PM,       MAG_NONE, OPIHI_FLT);
    184   if (!strcasecmp (fieldName, "ChiSqPar"))       ESCAPE (MEAS_CHISQ_PAR,      MAG_NONE, OPIHI_FLT);
    185   if (!strcasecmp (fieldName, "Tmean"))          ESCAPE (MEAS_TMEAN,          MAG_NONE, OPIHI_FLT);
    186   if (!strcasecmp (fieldName, "Trange"))         ESCAPE (MEAS_TRANGE,         MAG_NONE, OPIHI_FLT);
    187   if (!strcasecmp (fieldName, "nmeas"))          ESCAPE (MEAS_NMEAS,          MAG_NONE, OPIHI_INT);
    188   if (!strcasecmp (fieldName, "nmiss"))          ESCAPE (MEAS_NMISS,          MAG_NONE, OPIHI_INT);
    189   if (!strcasecmp (fieldName, "npos"))           ESCAPE (MEAS_NPOS,           MAG_NONE, OPIHI_INT);
    190   if (!strcasecmp (fieldName, "OBJFLAGS"))       ESCAPE (MEAS_OBJ_FLAGS,      MAG_NONE, OPIHI_INT);
    191   if (!strcasecmp (fieldName, "OBJ_FLAGS"))      ESCAPE (MEAS_OBJ_FLAGS,      MAG_NONE, OPIHI_INT);
    192   if (!strcasecmp (fieldName, "OBJ_PHOT_FLAGS")) ESCAPE (MEAS_SECFILT_FLAGS,      MAG_NONE, OPIHI_INT);
    193   if (!strcasecmp (fieldName, "SECFLAGS"))       ESCAPE (MEAS_SECFILT_FLAGS,      MAG_NONE, OPIHI_INT);
    194   if (!strcasecmp (fieldName, "SEC_FLAGS"))      ESCAPE (MEAS_SECFILT_FLAGS,      MAG_NONE, OPIHI_INT);
    195   if (!strcasecmp (fieldName, "SECFILT_FLAGS"))  ESCAPE (MEAS_SECFILT_FLAGS,      MAG_NONE, OPIHI_INT);
    196   if (!strcasecmp (fieldName, "DB_FLAGS"))       ESCAPE (MEAS_DB_FLAGS,       MAG_NONE, OPIHI_INT);
    197   if (!strcasecmp (fieldName, "PHOT_FLAGS"))     ESCAPE (MEAS_PHOT_FLAGS,     MAG_NONE, OPIHI_INT);
    198   if (!strcasecmp (fieldName, "DBFLAGS"))        ESCAPE (MEAS_DB_FLAGS,       MAG_NONE, OPIHI_INT);
    199   if (!strcasecmp (fieldName, "PHOTFLAGS"))      ESCAPE (MEAS_PHOT_FLAGS,     MAG_NONE, OPIHI_INT);
    200   if (!strcasecmp (fieldName, "AIRMASS"))        ESCAPE (MEAS_AIRMASS,        MAG_NONE, OPIHI_FLT);
    201   if (!strcasecmp (fieldName, "MEAN_AIRMASS"))   ESCAPE (MEAS_MEAN_AIRMASS,   MAG_NONE, OPIHI_FLT);
    202   if (!strcasecmp (fieldName, "ALT"))            ESCAPE (MEAS_ALT,            MAG_NONE, OPIHI_FLT);
    203   if (!strcasecmp (fieldName, "AZ"))             ESCAPE (MEAS_AZ,             MAG_NONE, OPIHI_FLT);
    204   if (!strcasecmp (fieldName, "EXPTIME"))        ESCAPE (MEAS_EXPTIME,        MAG_NONE, OPIHI_FLT);
    205   if (!strcasecmp (fieldName, "PHOTCODE"))       ESCAPE (MEAS_PHOTCODE,       MAG_NONE, OPIHI_INT);
    206   if (!strcasecmp (fieldName, "PHOTCODE:KLAM"))  ESCAPE (MEAS_PHOTCODE_KLAM,  MAG_NONE, OPIHI_FLT);
    207   if (!strcasecmp (fieldName, "PHOTCODE:C"))     ESCAPE (MEAS_PHOTCODE_C,     MAG_NONE, OPIHI_FLT);
    208   if (!strcasecmp (fieldName, "PHOTCODE:EQUIV")) ESCAPE (MEAS_PHOTCODE_EQUIV, MAG_NONE, OPIHI_INT);
    209   if (!strcasecmp (fieldName, "TIME"))           ESCAPE (MEAS_TIME,           MAG_NONE, OPIHI_FLT);
    210   if (!strcasecmp (fieldName, "FWHM"))           ESCAPE (MEAS_FWHM,           MAG_NONE, OPIHI_FLT);
    211   if (!strcasecmp (fieldName, "FWHM_MAJ"))       ESCAPE (MEAS_FWHM_MAJ,       MAG_NONE, OPIHI_FLT);
    212   if (!strcasecmp (fieldName, "FWHM_MIN"))       ESCAPE (MEAS_FWHM_MIN,       MAG_NONE, OPIHI_FLT);
    213   if (!strcasecmp (fieldName, "THETA"))          ESCAPE (MEAS_THETA,          MAG_NONE, OPIHI_FLT);
    214   if (!strcasecmp (fieldName, "POSANGLE"))       ESCAPE (MEAS_POSANGLE,       MAG_NONE, OPIHI_FLT);
    215   if (!strcasecmp (fieldName, "PLATESCALE"))     ESCAPE (MEAS_PLATESCALE,     MAG_NONE, OPIHI_FLT);
    216   if (!strcasecmp (fieldName, "MXX"))            ESCAPE (MEAS_MXX,            MAG_NONE, OPIHI_FLT);
    217   if (!strcasecmp (fieldName, "MYY"))            ESCAPE (MEAS_MYY,            MAG_NONE, OPIHI_FLT);
    218   if (!strcasecmp (fieldName, "MXY"))            ESCAPE (MEAS_MXY,            MAG_NONE, OPIHI_FLT);
    219   if (!strcasecmp (fieldName, "DOPHOT"))         ESCAPE (MEAS_DOPHOT,         MAG_NONE, OPIHI_INT);
    220   if (!strcasecmp (fieldName, "XCCD"))           ESCAPE (MEAS_XCCD,           MAG_NONE, OPIHI_FLT);
    221   if (!strcasecmp (fieldName, "YCCD"))           ESCAPE (MEAS_YCCD,           MAG_NONE, OPIHI_FLT);
    222   if (!strcasecmp (fieldName, "XCCD:ERR"))       ESCAPE (MEAS_XCCD_ERR,       MAG_NONE, OPIHI_FLT);
    223   if (!strcasecmp (fieldName, "YCCD:ERR"))       ESCAPE (MEAS_YCCD_ERR,       MAG_NONE, OPIHI_FLT);
    224   if (!strcasecmp (fieldName, "XFIX"))           ESCAPE (MEAS_XFIX,           MAG_NONE, OPIHI_FLT);
    225   if (!strcasecmp (fieldName, "YFIX"))           ESCAPE (MEAS_YFIX,           MAG_NONE, OPIHI_FLT);
    226   if (!strcasecmp (fieldName, "POS_SYS_ERR"))    ESCAPE (MEAS_POS_SYS_ERR,    MAG_NONE, OPIHI_FLT);
    227   if (!strcasecmp (fieldName, "XFIELD"))         ESCAPE (MEAS_XFIELD,         MAG_NONE, OPIHI_FLT);
    228   if (!strcasecmp (fieldName, "YFIELD"))         ESCAPE (MEAS_YFIELD,         MAG_NONE, OPIHI_FLT);
    229   if (!strcasecmp (fieldName, "XMOSAIC"))        ESCAPE (MEAS_XMOSAIC,        MAG_NONE, OPIHI_FLT);
    230   if (!strcasecmp (fieldName, "YMOSAIC"))        ESCAPE (MEAS_YMOSAIC,        MAG_NONE, OPIHI_FLT);
    231   if (!strcasecmp (fieldName, "XCHIP"))          ESCAPE (MEAS_XCCD,           MAG_NONE, OPIHI_FLT);
    232   if (!strcasecmp (fieldName, "YCHIP"))          ESCAPE (MEAS_YCCD,           MAG_NONE, OPIHI_FLT);
    233   if (!strcasecmp (fieldName, "XFPA"))           ESCAPE (MEAS_XMOSAIC,        MAG_NONE, OPIHI_FLT);
    234   if (!strcasecmp (fieldName, "YFPA"))           ESCAPE (MEAS_YMOSAIC,        MAG_NONE, OPIHI_FLT);
    235   if (!strcasecmp (fieldName, "DETID"))          ESCAPE (MEAS_DET_ID,         MAG_NONE, OPIHI_INT);
    236   if (!strcasecmp (fieldName, "OBJID"))          ESCAPE (MEAS_OBJ_ID,         MAG_NONE, OPIHI_INT);
    237   if (!strcasecmp (fieldName, "CATID"))          ESCAPE (MEAS_CAT_ID,         MAG_NONE, OPIHI_INT);
    238   if (!strcasecmp (fieldName, "IMAGEID"))        ESCAPE (MEAS_IMAGE_ID,       MAG_NONE, OPIHI_INT);
    239   if (!strcasecmp (fieldName, "EXTERNID"))       ESCAPE (MEAS_EXTERN_ID,      MAG_NONE, OPIHI_INT);
    240   if (!strcasecmp (fieldName, "EXPNAME"))        ESCAPE (MEAS_EXPNAME_AS_INT, MAG_NONE, OPIHI_INT);
    241   if (!strcasecmp (fieldName, "PSF_QF"))         ESCAPE (MEAS_PSF_QF,         MAG_NONE, OPIHI_FLT);
    242   if (!strcasecmp (fieldName, "PSF_QF_PERFECT")) ESCAPE (MEAS_PSF_QF_PERFECT, MAG_NONE, OPIHI_FLT);
    243   if (!strcasecmp (fieldName, "PSF_CHISQ"))      ESCAPE (MEAS_PSF_CHISQ,      MAG_NONE, OPIHI_FLT);
    244   if (!strcasecmp (fieldName, "PSF_NDOF"))       ESCAPE (MEAS_PSF_NDOF,       MAG_NONE, OPIHI_INT);
    245   if (!strcasecmp (fieldName, "PSF_NPIX"))       ESCAPE (MEAS_PSF_NPIX,       MAG_NONE, OPIHI_INT);
    246   if (!strcasecmp (fieldName, "CR_NSIGMA"))      ESCAPE (MEAS_CR_NSIGMA,      MAG_NONE, OPIHI_FLT);
    247   if (!strcasecmp (fieldName, "EXT_NSIGMA"))     ESCAPE (MEAS_EXT_NSIGMA,     MAG_NONE, OPIHI_FLT);
    248   if (!strcasecmp (fieldName, "SKY"))            ESCAPE (MEAS_SKY,            MAG_NONE, OPIHI_FLT);
    249   if (!strcasecmp (fieldName, "SKY_ERR"))        ESCAPE (MEAS_dSKY,           MAG_NONE, OPIHI_FLT);
    250   if (!strcasecmp (fieldName, "MCAL_OFFSET"))    ESCAPE (MEAS_MCAL_OFFSET,    MAG_NONE, OPIHI_FLT);
    251   if (!strcasecmp (fieldName, "FLAT"))           ESCAPE (MEAS_FLAT,           MAG_NONE, OPIHI_FLT);
    252   if (!strcasecmp (fieldName, "CENTER_OFFSET"))  ESCAPE (MEAS_CENTER_OFFSET,  MAG_NONE, OPIHI_FLT);
    253   if (!strcasecmp (fieldName, "FLUX"))           ESCAPE (MEAS_FLUX_PSF,       MAG_NONE, OPIHI_FLT);
    254   if (!strcasecmp (fieldName, "FLUX_ERR"))       ESCAPE (MEAS_FLUX_PSF_ERR,   MAG_NONE, OPIHI_FLT);
    255   if (!strcasecmp (fieldName, "FLUX_PSF"))       ESCAPE (MEAS_FLUX_PSF,       MAG_NONE, OPIHI_FLT);
    256   if (!strcasecmp (fieldName, "FLUX_PSF_ERR"))   ESCAPE (MEAS_FLUX_PSF_ERR,   MAG_NONE, OPIHI_FLT);
    257   if (!strcasecmp (fieldName, "FLUX_KRON"))      ESCAPE (MEAS_FLUX_KRON,      MAG_NONE, OPIHI_FLT);
    258   if (!strcasecmp (fieldName, "FLUX_KRON_ERR"))  ESCAPE (MEAS_FLUX_KRON_ERR,  MAG_NONE, OPIHI_FLT);
    259 
    260   // for words that don't parse, try a photcode
    261 
    262   // check for code:mode in photcode name
    263   code = ParsePhotcodeField (fieldName, &mode, MAG_AVE);
    264   if (code == NULL) {
    265     gprint (GP_ERR, "unknown field '%s' for measurement table in DVO database\n", fieldName);
    266     return (FALSE);
    267   }
    268 
    269   field->ID = MEAS_MAG;
    270   field->magMode = mode;
    271   switch (mode) {
    272     case MAG_STACK_DET_ID:
    273     case MAG_NCODE:
    274     case MAG_NPHOT:
    275     case MAG_PHOT_FLAGS:
     243
     244    dvoMagOptionType option = GetMagOption (word);
     245    if (option != MAG_OPTION_NONE) {
     246      // some combinations are OK: mag + err -> err
     247      if ((myOption == MAG_OPTION_MAG) && (option == MAG_OPTION_ERR)) {
     248        myOption = option;
     249        ptr = skipword (ptr);
     250        continue;
     251      }
     252      // some combinations are OK: err + mag -> err
     253      if ((myOption == MAG_OPTION_ERR) && (option == MAG_OPTION_MAG)) {
     254        ptr = skipword (ptr);
     255        continue;
     256      }
     257      // some combinations are OK: flux + err -> FLUX_ERR
     258      if ((myOption == MAG_OPTION_FLUX) && (option == MAG_OPTION_ERR)) {
     259        myOption = MAG_OPTION_FLUX_ERR;
     260        ptr = skipword (ptr);
     261        continue;
     262      }
     263      // some combinations are OK: err + flux -> FLUX_ERR
     264      if ((myOption == MAG_OPTION_ERR) && (option == MAG_OPTION_FLUX)) {
     265        myOption = MAG_OPTION_FLUX_ERR;
     266        ptr = skipword (ptr);
     267        continue;
     268      }
     269      // some combinations are OK: flux + fluxerr -> FLUX_ERR
     270      if ((myOption == MAG_OPTION_FLUX) && (option == MAG_OPTION_FLUX_ERR)) {
     271        myOption = MAG_OPTION_FLUX_ERR;
     272        ptr = skipword (ptr);
     273        continue;
     274      }
     275      // some combinations are OK: fluxerr + flux -> FLUX_ERR
     276      if ((myOption == MAG_OPTION_FLUX_ERR) && (option == MAG_OPTION_FLUX)) {
     277        myOption = MAG_OPTION_FLUX_ERR;
     278        ptr = skipword (ptr);
     279        continue;
     280      }
     281      if (myOption != MAG_OPTION_NONE) { fprintf (stderr, "invalid selection %s in %s\n", word, fieldName); free (word); return FALSE; }
     282      myOption = option;
     283      ptr = skipword (ptr);
     284      continue;
     285    }
     286
     287    fprintf (stderr, "ERROR: unknown mag/photocode argument %s\n", word);
     288    free (word);
     289  }
     290
     291  // if nothing is provided, use the defaults
     292  field->magSource = (mySource == MAG_SRC_NONE)    ? field->magSource : mySource;
     293  field->magLevel  = (myLevel  == MAG_LEVEL_NONE)  ? field->magLevel  : myLevel;
     294  field->magClass  = (myClass  == MAG_CLASS_NONE)  ? field->magClass  : myClass;
     295  field->magOption = (myOption == MAG_OPTION_NONE) ? field->magOption : myOption;
     296
     297  switch (field->magOption) {
     298    case MAG_OPTION_STACK_DET_ID:
     299    case MAG_OPTION_NCODE:
     300    case MAG_OPTION_NPHOT:
     301    case MAG_OPTION_FLAGS:
    276302      field->type = OPIHI_INT;
    277303      break;
     
    281307  }
    282308  field->photcode = code;
     309  return TRUE;
     310}
     311
     312// field needs to be initialized with dbInitField()
     313# define ESCAPE(F,T) { \
     314  field->ID = (F); \
     315  field->type = (T); \
     316  return (TRUE); }
     317
     318int ParseMeasureField (dbField *field, char *fieldName) {
     319
     320  field->table = DVO_TABLE_MEASURE;
     321  field->name  = strcreate (fieldName);
     322
     323  if (!strcasecmp (fieldName, "GLON"))       {
     324    dbExtractMeasuresInitTransform (COORD_GALACTIC);
     325    ESCAPE (MEAS_GLON, OPIHI_FLT);
     326  }
     327  if (!strcasecmp (fieldName, "GLAT")) {
     328    dbExtractMeasuresInitTransform (COORD_GALACTIC);
     329    ESCAPE (MEAS_GLAT, OPIHI_FLT);
     330  }
     331  if (!strcasecmp (fieldName, "GLON:AVE")) {
     332    dbExtractMeasuresInitTransform (COORD_GALACTIC);
     333    ESCAPE (MEAS_GLON_AVE, OPIHI_FLT);
     334  }
     335  if (!strcasecmp (fieldName, "GLAT:AVE")) {
     336    dbExtractMeasuresInitTransform (COORD_GALACTIC);
     337    ESCAPE (MEAS_GLAT_AVE, OPIHI_FLT);
     338  }
     339
     340  if (!strcasecmp (fieldName, "ELON"))       {
     341    dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
     342    ESCAPE (MEAS_ELON, OPIHI_FLT);
     343  }
     344  if (!strcasecmp (fieldName, "ELAT")) {
     345    dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
     346    ESCAPE (MEAS_ELAT, OPIHI_FLT);
     347  }
     348  if (!strcasecmp (fieldName, "ELON:AVE")) {
     349    dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
     350    ESCAPE (MEAS_ELON_AVE, OPIHI_FLT);
     351  }
     352  if (!strcasecmp (fieldName, "ELAT:AVE")) {
     353    dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
     354    ESCAPE (MEAS_ELAT_AVE, OPIHI_FLT);
     355  }
     356
     357  if (!strcasecmp (fieldName, "RA"))             ESCAPE (MEAS_RA,             OPIHI_FLT);
     358  if (!strcasecmp (fieldName, "DEC"))            ESCAPE (MEAS_DEC,            OPIHI_FLT);
     359  if (!strcasecmp (fieldName, "RA:AVE"))         ESCAPE (MEAS_RA_AVE,         OPIHI_FLT);
     360  if (!strcasecmp (fieldName, "DEC:AVE"))        ESCAPE (MEAS_DEC_AVE,        OPIHI_FLT);
     361  if (!strcasecmp (fieldName, "RA:ERR"))         ESCAPE (MEAS_RA_AVE_ERR,     OPIHI_FLT);
     362  if (!strcasecmp (fieldName, "DEC:ERR"))        ESCAPE (MEAS_DEC_AVE_ERR,    OPIHI_FLT);
     363  if (!strcasecmp (fieldName, "uRA"))            ESCAPE (MEAS_U_RA,           OPIHI_FLT);
     364  if (!strcasecmp (fieldName, "uDEC"))           ESCAPE (MEAS_U_DEC,          OPIHI_FLT);
     365  if (!strcasecmp (fieldName, "duRA"))           ESCAPE (MEAS_U_RA_ERR,       OPIHI_FLT);
     366  if (!strcasecmp (fieldName, "duDEC"))          ESCAPE (MEAS_U_DEC_ERR,      OPIHI_FLT);
     367  if (!strcasecmp (fieldName, "PAR"))            ESCAPE (MEAS_PAR,            OPIHI_FLT);
     368  if (!strcasecmp (fieldName, "dPAR"))           ESCAPE (MEAS_PAR_ERR,        OPIHI_FLT);
     369  if (!strcasecmp (fieldName, "dR"))             ESCAPE (MEAS_RA_OFFSET,      OPIHI_FLT);
     370  if (!strcasecmp (fieldName, "dD"))             ESCAPE (MEAS_DEC_OFFSET,     OPIHI_FLT);
     371  if (!strcasecmp (fieldName, "dR:FIT"))         ESCAPE (MEAS_RA_FIT_OFFSET,  OPIHI_FLT);
     372  if (!strcasecmp (fieldName, "dD:FIT"))         ESCAPE (MEAS_DEC_FIT_OFFSET, OPIHI_FLT);
     373  if (!strcasecmp (fieldName, "dR:ERR"))         ESCAPE (MEAS_RA_OFFSET_ERR,  OPIHI_FLT);
     374  if (!strcasecmp (fieldName, "dD:ERR"))         ESCAPE (MEAS_DEC_OFFSET_ERR, OPIHI_FLT);
     375  if (!strcasecmp (fieldName, "ChiSqPos"))       ESCAPE (MEAS_CHISQ_POS,      OPIHI_FLT);
     376  if (!strcasecmp (fieldName, "ChiSqPM"))        ESCAPE (MEAS_CHISQ_PM,       OPIHI_FLT);
     377  if (!strcasecmp (fieldName, "ChiSqPar"))       ESCAPE (MEAS_CHISQ_PAR,      OPIHI_FLT);
     378  if (!strcasecmp (fieldName, "Tmean"))          ESCAPE (MEAS_TMEAN,          OPIHI_FLT);
     379  if (!strcasecmp (fieldName, "Trange"))         ESCAPE (MEAS_TRANGE,         OPIHI_FLT);
     380  if (!strcasecmp (fieldName, "nmeas"))          ESCAPE (MEAS_NMEAS,          OPIHI_INT);
     381  if (!strcasecmp (fieldName, "nmiss"))          ESCAPE (MEAS_NMISS,          OPIHI_INT);
     382  if (!strcasecmp (fieldName, "npos"))           ESCAPE (MEAS_NPOS,           OPIHI_INT);
     383  if (!strcasecmp (fieldName, "OBJFLAGS"))       ESCAPE (MEAS_OBJ_FLAGS,      OPIHI_INT);
     384  if (!strcasecmp (fieldName, "OBJ_FLAGS"))      ESCAPE (MEAS_OBJ_FLAGS,      OPIHI_INT);
     385  if (!strcasecmp (fieldName, "OBJ_PHOT_FLAGS")) ESCAPE (MEAS_SECFILT_FLAGS,      OPIHI_INT);
     386  if (!strcasecmp (fieldName, "SECFLAGS"))       ESCAPE (MEAS_SECFILT_FLAGS,      OPIHI_INT);
     387  if (!strcasecmp (fieldName, "SEC_FLAGS"))      ESCAPE (MEAS_SECFILT_FLAGS,      OPIHI_INT);
     388  if (!strcasecmp (fieldName, "SECFILT_FLAGS"))  ESCAPE (MEAS_SECFILT_FLAGS,      OPIHI_INT);
     389  if (!strcasecmp (fieldName, "DB_FLAGS"))       ESCAPE (MEAS_DB_FLAGS,       OPIHI_INT);
     390  if (!strcasecmp (fieldName, "PHOT_FLAGS"))     ESCAPE (MEAS_PHOT_FLAGS,     OPIHI_INT);
     391  if (!strcasecmp (fieldName, "DBFLAGS"))        ESCAPE (MEAS_DB_FLAGS,       OPIHI_INT);
     392  if (!strcasecmp (fieldName, "PHOTFLAGS"))      ESCAPE (MEAS_PHOT_FLAGS,     OPIHI_INT);
     393  if (!strcasecmp (fieldName, "AIRMASS"))        ESCAPE (MEAS_AIRMASS,        OPIHI_FLT);
     394  if (!strcasecmp (fieldName, "MEAN_AIRMASS"))   ESCAPE (MEAS_MEAN_AIRMASS,   OPIHI_FLT);
     395  if (!strcasecmp (fieldName, "ALT"))            ESCAPE (MEAS_ALT,            OPIHI_FLT);
     396  if (!strcasecmp (fieldName, "AZ"))             ESCAPE (MEAS_AZ,             OPIHI_FLT);
     397  if (!strcasecmp (fieldName, "EXPTIME"))        ESCAPE (MEAS_EXPTIME,        OPIHI_FLT);
     398  if (!strcasecmp (fieldName, "PHOTCODE"))       ESCAPE (MEAS_PHOTCODE,       OPIHI_INT);
     399  if (!strcasecmp (fieldName, "PHOTCODE:KLAM"))  ESCAPE (MEAS_PHOTCODE_KLAM,  OPIHI_FLT);
     400  if (!strcasecmp (fieldName, "PHOTCODE:C"))     ESCAPE (MEAS_PHOTCODE_C,     OPIHI_FLT);
     401  if (!strcasecmp (fieldName, "PHOTCODE:EQUIV")) ESCAPE (MEAS_PHOTCODE_EQUIV, OPIHI_INT);
     402  if (!strcasecmp (fieldName, "TIME"))           ESCAPE (MEAS_TIME,           OPIHI_FLT);
     403  if (!strcasecmp (fieldName, "FWHM"))           ESCAPE (MEAS_FWHM,           OPIHI_FLT);
     404  if (!strcasecmp (fieldName, "FWHM_MAJ"))       ESCAPE (MEAS_FWHM_MAJ,       OPIHI_FLT);
     405  if (!strcasecmp (fieldName, "FWHM_MIN"))       ESCAPE (MEAS_FWHM_MIN,       OPIHI_FLT);
     406  if (!strcasecmp (fieldName, "THETA"))          ESCAPE (MEAS_THETA,          OPIHI_FLT);
     407  if (!strcasecmp (fieldName, "POSANGLE"))       ESCAPE (MEAS_POSANGLE,       OPIHI_FLT);
     408  if (!strcasecmp (fieldName, "PLATESCALE"))     ESCAPE (MEAS_PLATESCALE,     OPIHI_FLT);
     409  if (!strcasecmp (fieldName, "MXX"))            ESCAPE (MEAS_MXX,            OPIHI_FLT);
     410  if (!strcasecmp (fieldName, "MYY"))            ESCAPE (MEAS_MYY,            OPIHI_FLT);
     411  if (!strcasecmp (fieldName, "MXY"))            ESCAPE (MEAS_MXY,            OPIHI_FLT);
     412  if (!strcasecmp (fieldName, "DOPHOT"))         ESCAPE (MEAS_DOPHOT,         OPIHI_INT);
     413  if (!strcasecmp (fieldName, "XCCD"))           ESCAPE (MEAS_XCCD,           OPIHI_FLT);
     414  if (!strcasecmp (fieldName, "YCCD"))           ESCAPE (MEAS_YCCD,           OPIHI_FLT);
     415  if (!strcasecmp (fieldName, "XCCD:ERR"))       ESCAPE (MEAS_XCCD_ERR,       OPIHI_FLT);
     416  if (!strcasecmp (fieldName, "YCCD:ERR"))       ESCAPE (MEAS_YCCD_ERR,       OPIHI_FLT);
     417  if (!strcasecmp (fieldName, "XFIX"))           ESCAPE (MEAS_XFIX,           OPIHI_FLT);
     418  if (!strcasecmp (fieldName, "YFIX"))           ESCAPE (MEAS_YFIX,           OPIHI_FLT);
     419  if (!strcasecmp (fieldName, "POS_SYS_ERR"))    ESCAPE (MEAS_POS_SYS_ERR,    OPIHI_FLT);
     420  if (!strcasecmp (fieldName, "XFIELD"))         ESCAPE (MEAS_XFIELD,         OPIHI_FLT);
     421  if (!strcasecmp (fieldName, "YFIELD"))         ESCAPE (MEAS_YFIELD,         OPIHI_FLT);
     422  if (!strcasecmp (fieldName, "XMOSAIC"))        ESCAPE (MEAS_XMOSAIC,        OPIHI_FLT);
     423  if (!strcasecmp (fieldName, "YMOSAIC"))        ESCAPE (MEAS_YMOSAIC,        OPIHI_FLT);
     424  if (!strcasecmp (fieldName, "XCHIP"))          ESCAPE (MEAS_XCCD,           OPIHI_FLT);
     425  if (!strcasecmp (fieldName, "YCHIP"))          ESCAPE (MEAS_YCCD,           OPIHI_FLT);
     426  if (!strcasecmp (fieldName, "XFPA"))           ESCAPE (MEAS_XMOSAIC,        OPIHI_FLT);
     427  if (!strcasecmp (fieldName, "YFPA"))           ESCAPE (MEAS_YMOSAIC,        OPIHI_FLT);
     428  if (!strcasecmp (fieldName, "DETID"))          ESCAPE (MEAS_DET_ID,         OPIHI_INT);
     429  if (!strcasecmp (fieldName, "OBJID"))          ESCAPE (MEAS_OBJ_ID,         OPIHI_INT);
     430  if (!strcasecmp (fieldName, "CATID"))          ESCAPE (MEAS_CAT_ID,         OPIHI_INT);
     431  if (!strcasecmp (fieldName, "IMAGEID"))        ESCAPE (MEAS_IMAGE_ID,       OPIHI_INT);
     432  if (!strcasecmp (fieldName, "EXTERNID"))       ESCAPE (MEAS_EXTERN_ID,      OPIHI_INT);
     433  if (!strcasecmp (fieldName, "EXPNAME"))        ESCAPE (MEAS_EXPNAME_AS_INT, OPIHI_INT);
     434  if (!strcasecmp (fieldName, "PSF_QF"))         ESCAPE (MEAS_PSF_QF,         OPIHI_FLT);
     435  if (!strcasecmp (fieldName, "PSF_QF_PERFECT")) ESCAPE (MEAS_PSF_QF_PERFECT, OPIHI_FLT);
     436  if (!strcasecmp (fieldName, "PSF_CHISQ"))      ESCAPE (MEAS_PSF_CHISQ,      OPIHI_FLT);
     437  if (!strcasecmp (fieldName, "PSF_NDOF"))       ESCAPE (MEAS_PSF_NDOF,       OPIHI_INT);
     438  if (!strcasecmp (fieldName, "PSF_NPIX"))       ESCAPE (MEAS_PSF_NPIX,       OPIHI_INT);
     439  if (!strcasecmp (fieldName, "CR_NSIGMA"))      ESCAPE (MEAS_CR_NSIGMA,      OPIHI_FLT);
     440  if (!strcasecmp (fieldName, "EXT_NSIGMA"))     ESCAPE (MEAS_EXT_NSIGMA,     OPIHI_FLT);
     441  if (!strcasecmp (fieldName, "SKY"))            ESCAPE (MEAS_SKY,            OPIHI_FLT);
     442  if (!strcasecmp (fieldName, "SKY_ERR"))        ESCAPE (MEAS_dSKY,           OPIHI_FLT);
     443  if (!strcasecmp (fieldName, "MCAL_OFFSET"))    ESCAPE (MEAS_MCAL_OFFSET,    OPIHI_FLT);
     444  if (!strcasecmp (fieldName, "FLAT"))           ESCAPE (MEAS_FLAT,           OPIHI_FLT);
     445  if (!strcasecmp (fieldName, "CENTER_OFFSET"))  ESCAPE (MEAS_CENTER_OFFSET,  OPIHI_FLT);
     446  // if (!strcasecmp (fieldName, "FLUX"))                ESCAPE (MEAS_FLUX_PSF,       OPIHI_FLT);
     447  // if (!strcasecmp (fieldName, "FLUX_ERR"))       ESCAPE (MEAS_FLUX_PSF_ERR,   OPIHI_FLT);
     448  // if (!strcasecmp (fieldName, "FLUX_PSF"))       ESCAPE (MEAS_FLUX_PSF,       OPIHI_FLT);
     449  // if (!strcasecmp (fieldName, "FLUX_PSF_ERR"))   ESCAPE (MEAS_FLUX_PSF_ERR,   OPIHI_FLT);
     450  // if (!strcasecmp (fieldName, "FLUX_KRON"))      ESCAPE (MEAS_FLUX_KRON,      OPIHI_FLT);
     451  // if (!strcasecmp (fieldName, "FLUX_KRON_ERR"))  ESCAPE (MEAS_FLUX_KRON_ERR,  OPIHI_FLT);
     452  if (!strcasecmp (fieldName, "REF_COLOR"))      ESCAPE (MEAS_REF_COLOR,      OPIHI_FLT);
     453
     454  // for words that don't parse, try a photcode
     455
     456  // check for code:mode in photcode name
     457  if (!ParsePhotcodeField (field, fieldName, MEAS_PHOT)) {
     458    gprint (GP_ERR, "unknown field '%s' for measurement table in DVO database\n", fieldName);
     459    return (FALSE);
     460  }
     461
    283462  return (TRUE);
    284463}
    285464
    286465int ParseAverageField (dbField *field, char *fieldName) {
    287 
    288   int mode;
    289   PhotCode *code;
    290466
    291467  field->table = DVO_TABLE_AVERAGE;
     
    296472  if (!strcasecmp (fieldName, "GLON"))  {
    297473    dbExtractAveragesInitTransform (COORD_GALACTIC);
    298     ESCAPE (AVE_GLON, MAG_NONE, OPIHI_FLT);
     474    ESCAPE (AVE_GLON, OPIHI_FLT);
    299475  }
    300476  if (!strcasecmp (fieldName, "GLAT"))  {
    301477    dbExtractAveragesInitTransform (COORD_GALACTIC);
    302     ESCAPE (AVE_GLAT, MAG_NONE, OPIHI_FLT);
     478    ESCAPE (AVE_GLAT, OPIHI_FLT);
    303479  }
    304480
     
    307483  if (!strcasecmp (fieldName, "ELON"))  {
    308484    dbExtractAveragesInitTransform (COORD_ECLIPTIC);
    309     ESCAPE (AVE_ELON, MAG_NONE, OPIHI_FLT);
     485    ESCAPE (AVE_ELON, OPIHI_FLT);
    310486  }
    311487  if (!strcasecmp (fieldName, "ELAT"))  {
    312488    dbExtractAveragesInitTransform (COORD_ECLIPTIC);
    313     ESCAPE (AVE_ELAT, MAG_NONE, OPIHI_FLT);
    314   }
    315 
    316   if (!strcasecmp (fieldName, "RA"))        ESCAPE (AVE_RA,        MAG_NONE, OPIHI_FLT);
    317   if (!strcasecmp (fieldName, "DEC"))       ESCAPE (AVE_DEC,       MAG_NONE, OPIHI_FLT);
    318   if (!strcasecmp (fieldName, "GLON"))      ESCAPE (AVE_GLON,      MAG_NONE, OPIHI_FLT);
    319   if (!strcasecmp (fieldName, "GLAT"))      ESCAPE (AVE_GLAT,      MAG_NONE, OPIHI_FLT);
    320   if (!strcasecmp (fieldName, "ELON"))      ESCAPE (AVE_ELON,      MAG_NONE, OPIHI_FLT);
    321   if (!strcasecmp (fieldName, "ELAT"))      ESCAPE (AVE_ELAT,      MAG_NONE, OPIHI_FLT);
    322   if (!strcasecmp (fieldName, "dRA"))       ESCAPE (AVE_RA_ERR,    MAG_NONE, OPIHI_FLT);
    323   if (!strcasecmp (fieldName, "dDEC"))      ESCAPE (AVE_DEC_ERR,   MAG_NONE, OPIHI_FLT);
    324   if (!strcasecmp (fieldName, "uRA"))       ESCAPE (AVE_U_RA,      MAG_NONE, OPIHI_FLT);
    325   if (!strcasecmp (fieldName, "uDEC"))      ESCAPE (AVE_U_DEC,     MAG_NONE, OPIHI_FLT);
    326   if (!strcasecmp (fieldName, "duRA"))      ESCAPE (AVE_U_RA_ERR,  MAG_NONE, OPIHI_FLT);
    327   if (!strcasecmp (fieldName, "duDEC"))     ESCAPE (AVE_U_DEC_ERR, MAG_NONE, OPIHI_FLT);
    328   if (!strcasecmp (fieldName, "PAR"))       ESCAPE (AVE_PAR,       MAG_NONE, OPIHI_FLT);
    329   if (!strcasecmp (fieldName, "dPAR"))      ESCAPE (AVE_PAR_ERR,   MAG_NONE, OPIHI_FLT);
    330   if (!strcasecmp (fieldName, "ChiSqPos"))  ESCAPE (AVE_CHISQ_POS, MAG_NONE, OPIHI_FLT);
    331   if (!strcasecmp (fieldName, "ChiSqPM"))   ESCAPE (AVE_CHISQ_PM,  MAG_NONE, OPIHI_FLT);
    332   if (!strcasecmp (fieldName, "ChiSqPar"))  ESCAPE (AVE_CHISQ_PAR, MAG_NONE, OPIHI_FLT);
    333   if (!strcasecmp (fieldName, "Tmean"))     ESCAPE (AVE_TMEAN,     MAG_NONE, OPIHI_FLT);
    334   if (!strcasecmp (fieldName, "Trange"))    ESCAPE (AVE_TRANGE,    MAG_NONE, OPIHI_FLT);
    335   if (!strcasecmp (fieldName, "NMEAS"))     ESCAPE (AVE_NMEAS,     MAG_NONE, OPIHI_INT);
    336   if (!strcasecmp (fieldName, "NMISS"))     ESCAPE (AVE_NMISS,     MAG_NONE, OPIHI_INT);
    337   if (!strcasecmp (fieldName, "NPOS"))      ESCAPE (AVE_NPOS,      MAG_NONE, OPIHI_INT);
    338   if (!strcasecmp (fieldName, "NASTROM"))   ESCAPE (AVE_NPOS,      MAG_NONE, OPIHI_INT);
    339   if (!strcasecmp (fieldName, "FLAGS"))     ESCAPE (AVE_OBJ_FLAGS, MAG_NONE, OPIHI_INT);
    340   if (!strcasecmp (fieldName, "OBJ_FLAGS")) ESCAPE (AVE_OBJ_FLAGS, MAG_NONE, OPIHI_INT);
    341   if (!strcasecmp (fieldName, "OBJFLAGS"))  ESCAPE (AVE_OBJ_FLAGS, MAG_NONE, OPIHI_INT);
    342   if (!strcasecmp (fieldName, "OBJID"))     ESCAPE (AVE_OBJID,     MAG_NONE, OPIHI_INT);
    343   if (!strcasecmp (fieldName, "CATID"))     ESCAPE (AVE_CATID,     MAG_NONE, OPIHI_INT);
    344   if (!strcasecmp (fieldName, "EXTID_HI"))  ESCAPE (AVE_EXTID_HI,  MAG_NONE, OPIHI_INT);
    345   if (!strcasecmp (fieldName, "EXTID_LO"))  ESCAPE (AVE_EXTID_LO,  MAG_NONE, OPIHI_INT);
     489    ESCAPE (AVE_ELAT, OPIHI_FLT);
     490  }
     491
     492  if (!strcasecmp (fieldName, "RA"))          ESCAPE (AVE_RA,          OPIHI_FLT);
     493  if (!strcasecmp (fieldName, "DEC"))         ESCAPE (AVE_DEC,         OPIHI_FLT);
     494  if (!strcasecmp (fieldName, "GLON"))        ESCAPE (AVE_GLON,        OPIHI_FLT);
     495  if (!strcasecmp (fieldName, "GLAT"))        ESCAPE (AVE_GLAT,        OPIHI_FLT);
     496  if (!strcasecmp (fieldName, "ELON"))        ESCAPE (AVE_ELON,        OPIHI_FLT);
     497  if (!strcasecmp (fieldName, "ELAT"))        ESCAPE (AVE_ELAT,        OPIHI_FLT);
     498  if (!strcasecmp (fieldName, "dRA"))         ESCAPE (AVE_RA_ERR,      OPIHI_FLT);
     499  if (!strcasecmp (fieldName, "dDEC"))        ESCAPE (AVE_DEC_ERR,     OPIHI_FLT);
     500  if (!strcasecmp (fieldName, "uRA"))         ESCAPE (AVE_U_RA,        OPIHI_FLT);
     501  if (!strcasecmp (fieldName, "uDEC"))        ESCAPE (AVE_U_DEC,       OPIHI_FLT);
     502  if (!strcasecmp (fieldName, "duRA"))        ESCAPE (AVE_U_RA_ERR,    OPIHI_FLT);
     503  if (!strcasecmp (fieldName, "duDEC"))       ESCAPE (AVE_U_DEC_ERR,   OPIHI_FLT);
     504  if (!strcasecmp (fieldName, "PAR"))         ESCAPE (AVE_PAR,         OPIHI_FLT);
     505  if (!strcasecmp (fieldName, "dPAR"))        ESCAPE (AVE_PAR_ERR,     OPIHI_FLT);
     506  if (!strcasecmp (fieldName, "ChiSqPos"))    ESCAPE (AVE_CHISQ_POS,   OPIHI_FLT);
     507  if (!strcasecmp (fieldName, "ChiSqPM"))     ESCAPE (AVE_CHISQ_PM,    OPIHI_FLT);
     508  if (!strcasecmp (fieldName, "ChiSqPar"))    ESCAPE (AVE_CHISQ_PAR,   OPIHI_FLT);
     509  if (!strcasecmp (fieldName, "Tmean"))       ESCAPE (AVE_TMEAN,       OPIHI_FLT);
     510  if (!strcasecmp (fieldName, "Trange"))      ESCAPE (AVE_TRANGE,      OPIHI_FLT);
     511  if (!strcasecmp (fieldName, "psfqf"))       ESCAPE (AVE_PSF_QF,      OPIHI_FLT);
     512  if (!strcasecmp (fieldName, "psfqfperf"))   ESCAPE (AVE_PSF_QF_PERF, OPIHI_FLT);
     513  if (!strcasecmp (fieldName, "psf_qf"))      ESCAPE (AVE_PSF_QF,      OPIHI_FLT);
     514  if (!strcasecmp (fieldName, "psf_qf_perf")) ESCAPE (AVE_PSF_QF_PERF, OPIHI_FLT);
     515  if (!strcasecmp (fieldName, "stargal"))     ESCAPE (AVE_STARGAL,     OPIHI_FLT);
     516  if (!strcasecmp (fieldName, "NMEAS"))       ESCAPE (AVE_NMEAS,       OPIHI_INT);
     517  if (!strcasecmp (fieldName, "NMISS"))       ESCAPE (AVE_NMISS,       OPIHI_INT);
     518  if (!strcasecmp (fieldName, "NPOS"))        ESCAPE (AVE_NPOS,        OPIHI_INT);
     519  if (!strcasecmp (fieldName, "NASTROM"))     ESCAPE (AVE_NPOS,        OPIHI_INT);
     520  if (!strcasecmp (fieldName, "FLAGS"))       ESCAPE (AVE_OBJ_FLAGS,   OPIHI_INT);
     521  if (!strcasecmp (fieldName, "OBJ_FLAGS"))   ESCAPE (AVE_OBJ_FLAGS,   OPIHI_INT);
     522  if (!strcasecmp (fieldName, "OBJFLAGS"))    ESCAPE (AVE_OBJ_FLAGS,   OPIHI_INT);
     523  if (!strcasecmp (fieldName, "OBJID"))       ESCAPE (AVE_OBJID,       OPIHI_INT);
     524  if (!strcasecmp (fieldName, "CATID"))       ESCAPE (AVE_CATID,       OPIHI_INT);
     525  if (!strcasecmp (fieldName, "EXTID_HI"))    ESCAPE (AVE_EXTID_HI,    OPIHI_INT);
     526  if (!strcasecmp (fieldName, "EXTID_LO"))    ESCAPE (AVE_EXTID_LO,    OPIHI_INT);
     527  if (!strcasecmp (fieldName, "REF_COLOR"))   ESCAPE (AVE_REF_COLOR,   OPIHI_FLT);
    346528
    347529  // check for code:mode in photcode name
    348   code = ParsePhotcodeField (fieldName, &mode, MAG_AVE);
    349   if (code == NULL) {
     530  if (!ParsePhotcodeField (field, fieldName, AVE_PHOT)) {
    350531    gprint (GP_ERR, "unknown field '%s' for average table in DVO database\n", fieldName);
    351532    return (FALSE);
    352533  }
    353534
    354   if (code[0].type == PHOT_MAG) {
     535  if (field->photcode->type == PHOT_MAG) {
    355536    gprint (GP_ERR, "'mag' is ambiguous for avextract\n");
    356     free (code);
    357537    return (FALSE);
    358538  }
    359539
    360   field->ID = AVE_MAG;
    361   field->magMode = mode;
    362   switch (mode) {
    363     case MAG_STACK_DET_ID:
    364     case MAG_NCODE:
    365     case MAG_NPHOT:
    366     case MAG_PHOT_FLAGS:
    367       field->type = OPIHI_INT;
    368       break;
    369     default:
    370       field->type = OPIHI_FLT;
    371       break;
    372   }
    373   field->photcode = code;
    374540  return (TRUE);
    375541}
     
    385551  if (!strcasecmp (fieldName, "GLON"))  {
    386552    dbExtractImagesInitTransform (COORD_GALACTIC);
    387     ESCAPE (IMAGE_GLON, MAG_NONE, OPIHI_FLT);
     553    ESCAPE (IMAGE_GLON, OPIHI_FLT);
    388554  }
    389555  if (!strcasecmp (fieldName, "GLAT"))  {
    390556    dbExtractImagesInitTransform (COORD_GALACTIC);
    391     ESCAPE (IMAGE_GLAT, MAG_NONE, OPIHI_FLT);
     557    ESCAPE (IMAGE_GLAT, OPIHI_FLT);
    392558  }
    393559
     
    396562  if (!strcasecmp (fieldName, "ELON"))  {
    397563    dbExtractImagesInitTransform (COORD_ECLIPTIC);
    398     ESCAPE (IMAGE_ELON, MAG_NONE, OPIHI_FLT);
     564    ESCAPE (IMAGE_ELON, OPIHI_FLT);
    399565  }
    400566  if (!strcasecmp (fieldName, "ELAT"))  {
    401567    dbExtractImagesInitTransform (COORD_ECLIPTIC);
    402     ESCAPE (IMAGE_ELAT, MAG_NONE, OPIHI_FLT);
    403   }
    404 
    405   if (!strcasecmp (fieldName, "RA"       )) ESCAPE (IMAGE_RA,        MAG_NONE, OPIHI_FLT);
    406   if (!strcasecmp (fieldName, "DEC"      )) ESCAPE (IMAGE_DEC,       MAG_NONE, OPIHI_FLT);
    407   if (!strcasecmp (fieldName, "GLON"     )) ESCAPE (IMAGE_GLON,      MAG_NONE, OPIHI_FLT);
    408   if (!strcasecmp (fieldName, "GLAT"     )) ESCAPE (IMAGE_GLAT,      MAG_NONE, OPIHI_FLT);
    409   if (!strcasecmp (fieldName, "ELON"     )) ESCAPE (IMAGE_ELON,      MAG_NONE, OPIHI_FLT);
    410   if (!strcasecmp (fieldName, "ELAT"     )) ESCAPE (IMAGE_ELAT,      MAG_NONE, OPIHI_FLT);
    411 
    412   if (!strcasecmp (fieldName, "theta"    )) ESCAPE (IMAGE_THETA,     MAG_NONE, OPIHI_FLT);
    413   if (!strcasecmp (fieldName, "skew"     )) ESCAPE (IMAGE_SKEW,      MAG_NONE, OPIHI_FLT);
    414   if (!strcasecmp (fieldName, "scale"    )) ESCAPE (IMAGE_SCALE,     MAG_NONE, OPIHI_FLT);
    415   if (!strcasecmp (fieldName, "dscale"   )) ESCAPE (IMAGE_DSCALE,    MAG_NONE, OPIHI_FLT);
    416 
    417   if (!strcasecmp (fieldName, "time"     )) ESCAPE (IMAGE_TIME,      MAG_NONE, OPIHI_FLT);
    418   if (!strcasecmp (fieldName, "nstar"    )) ESCAPE (IMAGE_NSTAR,     MAG_NONE, OPIHI_INT);
    419   if (!strcasecmp (fieldName, "airmass"  )) ESCAPE (IMAGE_AIRMASS,   MAG_NONE, OPIHI_FLT);
    420   if (!strcasecmp (fieldName, "NX"       )) ESCAPE (IMAGE_NX_PIX,    MAG_NONE, OPIHI_INT);
    421   if (!strcasecmp (fieldName, "NY"       )) ESCAPE (IMAGE_NY_PIX,    MAG_NONE, OPIHI_INT);
    422   if (!strcasecmp (fieldName, "apresid"  )) ESCAPE (IMAGE_APRESID,   MAG_NONE, OPIHI_FLT);
    423   if (!strcasecmp (fieldName, "dapresid" )) ESCAPE (IMAGE_DAPRESID,  MAG_NONE, OPIHI_FLT);
    424 
    425   if (!strcasecmp (fieldName, "Mcal"     )) ESCAPE (IMAGE_MCAL,      MAG_NONE, OPIHI_FLT);
    426   if (!strcasecmp (fieldName, "dMcal"    )) ESCAPE (IMAGE_dMCAL,     MAG_NONE, OPIHI_FLT);
    427   if (!strcasecmp (fieldName, "Xm"       )) ESCAPE (IMAGE_XM,        MAG_NONE, OPIHI_FLT);
    428   if (!strcasecmp (fieldName, "photcode" )) ESCAPE (IMAGE_PHOTCODE,  MAG_NONE, OPIHI_INT);
    429   if (!strcasecmp (fieldName, "exptime"  )) ESCAPE (IMAGE_EXPTIME,   MAG_NONE, OPIHI_FLT);
    430   if (!strcasecmp (fieldName, "sidtime"  )) ESCAPE (IMAGE_SIDTIME,   MAG_NONE, OPIHI_FLT);
    431 
    432   if (!strcasecmp (fieldName, "latitude" )) ESCAPE (IMAGE_LATITUDE,  MAG_NONE, OPIHI_FLT);
    433 
    434   if (!strcasecmp (fieldName, "detlimit" )) ESCAPE (IMAGE_DET_LIMIT, MAG_NONE, OPIHI_FLT);
    435   if (!strcasecmp (fieldName, "satlimit" )) ESCAPE (IMAGE_SAT_LIMIT, MAG_NONE, OPIHI_FLT);
    436   if (!strcasecmp (fieldName, "cerror"   )) ESCAPE (IMAGE_CERROR,    MAG_NONE, OPIHI_FLT);
    437 
    438   if (!strcasecmp (fieldName, "FWHM"       )) ESCAPE (IMAGE_FWHM,      MAG_NONE, OPIHI_FLT);
    439   if (!strcasecmp (fieldName, "FWHM_MAJ"   )) ESCAPE (IMAGE_FWHM_MAJ,  MAG_NONE, OPIHI_FLT);
    440   if (!strcasecmp (fieldName, "FWHM_MIN"   )) ESCAPE (IMAGE_FWHM_MIN,  MAG_NONE, OPIHI_FLT);
    441   if (!strcasecmp (fieldName, "FWHM_MAJOR" )) ESCAPE (IMAGE_FWHM_MAJ,  MAG_NONE, OPIHI_FLT);
    442   if (!strcasecmp (fieldName, "FWHM_MINOR" )) ESCAPE (IMAGE_FWHM_MIN,  MAG_NONE, OPIHI_FLT);
    443 
    444   if (!strcasecmp (fieldName, "FWHM_MEDIAN"    ))   ESCAPE (IMAGE_FWHM_MEDIAN,      MAG_NONE, OPIHI_FLT);
    445   if (!strcasecmp (fieldName, "FWHM_MAJ_MEDIAN"))   ESCAPE (IMAGE_FWHM_MAJ_MEDIAN,  MAG_NONE, OPIHI_FLT);
    446   if (!strcasecmp (fieldName, "FWHM_MIN_MEDIAN"))   ESCAPE (IMAGE_FWHM_MIN_MEDIAN,  MAG_NONE, OPIHI_FLT);
    447   if (!strcasecmp (fieldName, "FWHM_MAJOR_MEDIAN")) ESCAPE (IMAGE_FWHM_MAJ_MEDIAN,  MAG_NONE, OPIHI_FLT);
    448   if (!strcasecmp (fieldName, "FWHM_MINOR_MEDIAN")) ESCAPE (IMAGE_FWHM_MIN_MEDIAN,  MAG_NONE, OPIHI_FLT);
    449 
    450   if (!strcasecmp (fieldName, "trate"    )) ESCAPE (IMAGE_TRATE,     MAG_NONE, OPIHI_FLT);
    451 
    452   if (!strcasecmp (fieldName, "ncal"     )) ESCAPE (IMAGE_NCAL,      MAG_NONE, OPIHI_INT);
    453   if (!strcasecmp (fieldName, "sky"      )) ESCAPE (IMAGE_SKY,       MAG_NONE, OPIHI_FLT); // deprecated for now
    454 
    455   if (!strcasecmp (fieldName, "imflags"  )) ESCAPE (IMAGE_FLAGS,     MAG_NONE, OPIHI_INT);
    456   if (!strcasecmp (fieldName, "flags"    )) ESCAPE (IMAGE_FLAGS,     MAG_NONE, OPIHI_INT);
    457   if (!strcasecmp (fieldName, "ccdnum"   )) ESCAPE (IMAGE_CCDNUM,    MAG_NONE, OPIHI_INT);
    458 
    459   if (!strcasecmp (fieldName, "imageID"  )) ESCAPE (IMAGE_IMAGE_ID,  MAG_NONE, OPIHI_INT);
    460   if (!strcasecmp (fieldName, "externID" )) ESCAPE (IMAGE_EXTERN_ID, MAG_NONE, OPIHI_INT);
    461   if (!strcasecmp (fieldName, "sourceID" )) ESCAPE (IMAGE_SOURCE_ID, MAG_NONE, OPIHI_INT);
    462 
    463   if (!strcasecmp (fieldName, "X_LL_CHIP")) ESCAPE (IMAGE_X_LL_CHIP, MAG_NONE, OPIHI_FLT);
    464   if (!strcasecmp (fieldName, "X_LR_CHIP")) ESCAPE (IMAGE_X_LR_CHIP, MAG_NONE, OPIHI_FLT);
    465   if (!strcasecmp (fieldName, "X_UL_CHIP")) ESCAPE (IMAGE_X_UL_CHIP, MAG_NONE, OPIHI_FLT);
    466   if (!strcasecmp (fieldName, "X_UR_CHIP")) ESCAPE (IMAGE_X_UR_CHIP, MAG_NONE, OPIHI_FLT);
    467   if (!strcasecmp (fieldName, "Y_LL_CHIP")) ESCAPE (IMAGE_Y_LL_CHIP, MAG_NONE, OPIHI_FLT);
    468   if (!strcasecmp (fieldName, "Y_LR_CHIP")) ESCAPE (IMAGE_Y_LR_CHIP, MAG_NONE, OPIHI_FLT);
    469   if (!strcasecmp (fieldName, "Y_UL_CHIP")) ESCAPE (IMAGE_Y_UL_CHIP, MAG_NONE, OPIHI_FLT);
    470   if (!strcasecmp (fieldName, "Y_UR_CHIP")) ESCAPE (IMAGE_Y_UR_CHIP, MAG_NONE, OPIHI_FLT);
    471   if (!strcasecmp (fieldName, "X_LL_FP"  )) ESCAPE (IMAGE_X_LL_FP,   MAG_NONE, OPIHI_FLT);
    472   if (!strcasecmp (fieldName, "X_LR_FP"  )) ESCAPE (IMAGE_X_LR_FP,   MAG_NONE, OPIHI_FLT);
    473   if (!strcasecmp (fieldName, "X_UL_FP"  )) ESCAPE (IMAGE_X_UL_FP,   MAG_NONE, OPIHI_FLT);
    474   if (!strcasecmp (fieldName, "X_UR_FP"  )) ESCAPE (IMAGE_X_UR_FP,   MAG_NONE, OPIHI_FLT);
    475   if (!strcasecmp (fieldName, "Y_LL_FP"  )) ESCAPE (IMAGE_Y_LL_FP,   MAG_NONE, OPIHI_FLT);
    476   if (!strcasecmp (fieldName, "Y_LR_FP"  )) ESCAPE (IMAGE_Y_LR_FP,   MAG_NONE, OPIHI_FLT);
    477   if (!strcasecmp (fieldName, "Y_UL_FP"  )) ESCAPE (IMAGE_Y_UL_FP,   MAG_NONE, OPIHI_FLT);
    478   if (!strcasecmp (fieldName, "Y_UR_FP"  )) ESCAPE (IMAGE_Y_UR_FP,   MAG_NONE, OPIHI_FLT);
    479 
    480   if (!strcasecmp (fieldName, "dX_SYS"  )) ESCAPE (IMAGE_X_ERR_SYS,  MAG_NONE, OPIHI_FLT);
    481   if (!strcasecmp (fieldName, "dY_SYS"  )) ESCAPE (IMAGE_Y_ERR_SYS,  MAG_NONE, OPIHI_FLT);
    482   if (!strcasecmp (fieldName, "dM_SYS"  )) ESCAPE (IMAGE_MAG_ERR_SYS,MAG_NONE, OPIHI_FLT);
    483 
    484   if (!strcasecmp (fieldName, "UBERCAL_DIST")) ESCAPE (IMAGE_UBERCAL_DIST,MAG_NONE, OPIHI_INT);
    485   if (!strcasecmp (fieldName, "UCDIST")) ESCAPE (IMAGE_UBERCAL_DIST,MAG_NONE, OPIHI_INT);
    486 
    487   if (!strcasecmp (fieldName, "NFIT_PHOTOM")) ESCAPE (IMAGE_NFIT_PHOTOM,MAG_NONE, OPIHI_INT);
    488   if (!strcasecmp (fieldName, "NFIT_ASTROM")) ESCAPE (IMAGE_NFIT_ASTROM,MAG_NONE, OPIHI_INT);
    489   if (!strcasecmp (fieldName, "NLINK_PHOTOM")) ESCAPE (IMAGE_NLINK_PHOTOM,MAG_NONE, OPIHI_INT);
    490   if (!strcasecmp (fieldName, "NLINK_ASTROM")) ESCAPE (IMAGE_NLINK_ASTROM,MAG_NONE, OPIHI_INT);
     568    ESCAPE (IMAGE_ELAT, OPIHI_FLT);
     569  }
     570
     571  if (!strcasecmp (fieldName, "RA"       )) ESCAPE (IMAGE_RA,        OPIHI_FLT);
     572  if (!strcasecmp (fieldName, "DEC"      )) ESCAPE (IMAGE_DEC,       OPIHI_FLT);
     573  if (!strcasecmp (fieldName, "GLON"     )) ESCAPE (IMAGE_GLON,      OPIHI_FLT);
     574  if (!strcasecmp (fieldName, "GLAT"     )) ESCAPE (IMAGE_GLAT,      OPIHI_FLT);
     575  if (!strcasecmp (fieldName, "ELON"     )) ESCAPE (IMAGE_ELON,      OPIHI_FLT);
     576  if (!strcasecmp (fieldName, "ELAT"     )) ESCAPE (IMAGE_ELAT,      OPIHI_FLT);
     577
     578  if (!strcasecmp (fieldName, "theta"    )) ESCAPE (IMAGE_THETA,     OPIHI_FLT);
     579  if (!strcasecmp (fieldName, "skew"     )) ESCAPE (IMAGE_SKEW,      OPIHI_FLT);
     580  if (!strcasecmp (fieldName, "scale"    )) ESCAPE (IMAGE_SCALE,     OPIHI_FLT);
     581  if (!strcasecmp (fieldName, "dscale"   )) ESCAPE (IMAGE_DSCALE,    OPIHI_FLT);
     582
     583  if (!strcasecmp (fieldName, "time"     )) ESCAPE (IMAGE_TIME,      OPIHI_FLT);
     584  if (!strcasecmp (fieldName, "nstar"    )) ESCAPE (IMAGE_NSTAR,     OPIHI_INT);
     585  if (!strcasecmp (fieldName, "airmass"  )) ESCAPE (IMAGE_AIRMASS,   OPIHI_FLT);
     586  if (!strcasecmp (fieldName, "NX"       )) ESCAPE (IMAGE_NX_PIX,    OPIHI_INT);
     587  if (!strcasecmp (fieldName, "NY"       )) ESCAPE (IMAGE_NY_PIX,    OPIHI_INT);
     588  if (!strcasecmp (fieldName, "apresid"  )) ESCAPE (IMAGE_APRESID,   OPIHI_FLT);
     589  if (!strcasecmp (fieldName, "dapresid" )) ESCAPE (IMAGE_DAPRESID,  OPIHI_FLT);
     590
     591  if (!strcasecmp (fieldName, "Mcal"     )) ESCAPE (IMAGE_MCAL,      OPIHI_FLT);
     592  if (!strcasecmp (fieldName, "dMcal"    )) ESCAPE (IMAGE_dMCAL,     OPIHI_FLT);
     593  if (!strcasecmp (fieldName, "Xm"       )) ESCAPE (IMAGE_XM,        OPIHI_FLT);
     594  if (!strcasecmp (fieldName, "photcode" )) ESCAPE (IMAGE_PHOTCODE,  OPIHI_INT);
     595  if (!strcasecmp (fieldName, "exptime"  )) ESCAPE (IMAGE_EXPTIME,   OPIHI_FLT);
     596  if (!strcasecmp (fieldName, "sidtime"  )) ESCAPE (IMAGE_SIDTIME,   OPIHI_FLT);
     597
     598  if (!strcasecmp (fieldName, "latitude" )) ESCAPE (IMAGE_LATITUDE,  OPIHI_FLT);
     599
     600  if (!strcasecmp (fieldName, "detlimit" )) ESCAPE (IMAGE_DET_LIMIT, OPIHI_FLT);
     601  if (!strcasecmp (fieldName, "satlimit" )) ESCAPE (IMAGE_SAT_LIMIT, OPIHI_FLT);
     602  if (!strcasecmp (fieldName, "cerror"   )) ESCAPE (IMAGE_CERROR,    OPIHI_FLT);
     603
     604  if (!strcasecmp (fieldName, "FWHM"       )) ESCAPE (IMAGE_FWHM,      OPIHI_FLT);
     605  if (!strcasecmp (fieldName, "FWHM_MAJ"   )) ESCAPE (IMAGE_FWHM_MAJ,  OPIHI_FLT);
     606  if (!strcasecmp (fieldName, "FWHM_MIN"   )) ESCAPE (IMAGE_FWHM_MIN,  OPIHI_FLT);
     607  if (!strcasecmp (fieldName, "FWHM_MAJOR" )) ESCAPE (IMAGE_FWHM_MAJ,  OPIHI_FLT);
     608  if (!strcasecmp (fieldName, "FWHM_MINOR" )) ESCAPE (IMAGE_FWHM_MIN,  OPIHI_FLT);
     609
     610  if (!strcasecmp (fieldName, "FWHM_MEDIAN"    ))   ESCAPE (IMAGE_FWHM_MEDIAN,      OPIHI_FLT);
     611  if (!strcasecmp (fieldName, "FWHM_MAJ_MEDIAN"))   ESCAPE (IMAGE_FWHM_MAJ_MEDIAN,  OPIHI_FLT);
     612  if (!strcasecmp (fieldName, "FWHM_MIN_MEDIAN"))   ESCAPE (IMAGE_FWHM_MIN_MEDIAN,  OPIHI_FLT);
     613  if (!strcasecmp (fieldName, "FWHM_MAJOR_MEDIAN")) ESCAPE (IMAGE_FWHM_MAJ_MEDIAN,  OPIHI_FLT);
     614  if (!strcasecmp (fieldName, "FWHM_MINOR_MEDIAN")) ESCAPE (IMAGE_FWHM_MIN_MEDIAN,  OPIHI_FLT);
     615
     616  if (!strcasecmp (fieldName, "trate"    )) ESCAPE (IMAGE_TRATE,     OPIHI_FLT);
     617
     618  if (!strcasecmp (fieldName, "ncal"     )) ESCAPE (IMAGE_NCAL,      OPIHI_INT);
     619  if (!strcasecmp (fieldName, "sky"      )) ESCAPE (IMAGE_SKY,       OPIHI_FLT); // deprecated for now
     620
     621  if (!strcasecmp (fieldName, "imflags"  )) ESCAPE (IMAGE_FLAGS,     OPIHI_INT);
     622  if (!strcasecmp (fieldName, "flags"    )) ESCAPE (IMAGE_FLAGS,     OPIHI_INT);
     623  if (!strcasecmp (fieldName, "ccdnum"   )) ESCAPE (IMAGE_CCDNUM,    OPIHI_INT);
     624
     625  if (!strcasecmp (fieldName, "imageID"  )) ESCAPE (IMAGE_IMAGE_ID,  OPIHI_INT);
     626  if (!strcasecmp (fieldName, "externID" )) ESCAPE (IMAGE_EXTERN_ID, OPIHI_INT);
     627  if (!strcasecmp (fieldName, "sourceID" )) ESCAPE (IMAGE_SOURCE_ID, OPIHI_INT);
     628
     629  if (!strcasecmp (fieldName, "X_LL_CHIP")) ESCAPE (IMAGE_X_LL_CHIP, OPIHI_FLT);
     630  if (!strcasecmp (fieldName, "X_LR_CHIP")) ESCAPE (IMAGE_X_LR_CHIP, OPIHI_FLT);
     631  if (!strcasecmp (fieldName, "X_UL_CHIP")) ESCAPE (IMAGE_X_UL_CHIP, OPIHI_FLT);
     632  if (!strcasecmp (fieldName, "X_UR_CHIP")) ESCAPE (IMAGE_X_UR_CHIP, OPIHI_FLT);
     633  if (!strcasecmp (fieldName, "Y_LL_CHIP")) ESCAPE (IMAGE_Y_LL_CHIP, OPIHI_FLT);
     634  if (!strcasecmp (fieldName, "Y_LR_CHIP")) ESCAPE (IMAGE_Y_LR_CHIP, OPIHI_FLT);
     635  if (!strcasecmp (fieldName, "Y_UL_CHIP")) ESCAPE (IMAGE_Y_UL_CHIP, OPIHI_FLT);
     636  if (!strcasecmp (fieldName, "Y_UR_CHIP")) ESCAPE (IMAGE_Y_UR_CHIP, OPIHI_FLT);
     637  if (!strcasecmp (fieldName, "X_LL_FP"  )) ESCAPE (IMAGE_X_LL_FP,   OPIHI_FLT);
     638  if (!strcasecmp (fieldName, "X_LR_FP"  )) ESCAPE (IMAGE_X_LR_FP,   OPIHI_FLT);
     639  if (!strcasecmp (fieldName, "X_UL_FP"  )) ESCAPE (IMAGE_X_UL_FP,   OPIHI_FLT);
     640  if (!strcasecmp (fieldName, "X_UR_FP"  )) ESCAPE (IMAGE_X_UR_FP,   OPIHI_FLT);
     641  if (!strcasecmp (fieldName, "Y_LL_FP"  )) ESCAPE (IMAGE_Y_LL_FP,   OPIHI_FLT);
     642  if (!strcasecmp (fieldName, "Y_LR_FP"  )) ESCAPE (IMAGE_Y_LR_FP,   OPIHI_FLT);
     643  if (!strcasecmp (fieldName, "Y_UL_FP"  )) ESCAPE (IMAGE_Y_UL_FP,   OPIHI_FLT);
     644  if (!strcasecmp (fieldName, "Y_UR_FP"  )) ESCAPE (IMAGE_Y_UR_FP,   OPIHI_FLT);
     645
     646  if (!strcasecmp (fieldName, "dX_SYS"  )) ESCAPE (IMAGE_X_ERR_SYS,  OPIHI_FLT);
     647  if (!strcasecmp (fieldName, "dY_SYS"  )) ESCAPE (IMAGE_Y_ERR_SYS,  OPIHI_FLT);
     648  if (!strcasecmp (fieldName, "dM_SYS"  )) ESCAPE (IMAGE_MAG_ERR_SYS,OPIHI_FLT);
     649
     650  if (!strcasecmp (fieldName, "UBERCAL_DIST")) ESCAPE (IMAGE_UBERCAL_DIST,OPIHI_INT);
     651  if (!strcasecmp (fieldName, "UCDIST")) ESCAPE (IMAGE_UBERCAL_DIST,OPIHI_INT);
     652
     653  if (!strcasecmp (fieldName, "NFIT_PHOTOM"))  ESCAPE (IMAGE_NFIT_PHOTOM,  OPIHI_INT);
     654  if (!strcasecmp (fieldName, "NFIT_ASTROM"))  ESCAPE (IMAGE_NFIT_ASTROM,  OPIHI_INT);
     655  if (!strcasecmp (fieldName, "NLINK_PHOTOM")) ESCAPE (IMAGE_NLINK_PHOTOM, OPIHI_INT);
     656  if (!strcasecmp (fieldName, "NLINK_ASTROM")) ESCAPE (IMAGE_NLINK_ASTROM, OPIHI_INT);
     657  if (!strcasecmp (fieldName, "REF_COLOR"))    ESCAPE (IMAGE_REF_COLOR,    OPIHI_FLT);
    491658
    492659  // for words that don't parse, try a photcode
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_catalog.c

    r35416 r37067  
    5656  if (!strcasecmp (catformat, "PS1_V3"))          return (DVO_FORMAT_PS1_V3);
    5757  if (!strcasecmp (catformat, "PS1_V4"))          return (DVO_FORMAT_PS1_V4);
     58  if (!strcasecmp (catformat, "PS1_V5"))          return (DVO_FORMAT_PS1_V5);
    5859  if (!strcasecmp (catformat, "PS1_REF"))         return (DVO_FORMAT_PS1_REF);
    5960  return (DVO_FORMAT_UNDEF);
     
    6970}
    7071
     72float dvoOffsetR (Measure *measure, Average *average) {
     73
     74  float dR = (measure[0].R - average[0].R) * 3600.0;
     75  return dR;
     76}
     77
     78float dvoOffsetD (Measure *measure, Average *average) {
     79
     80  float dD = (measure[0].D - average[0].D) * 3600.0;
     81  return dD;
     82}
     83
     84double dvoMeanR (float dR, Average *average) {
     85
     86  double ra = average[0].R - dR / 3600.0;
     87  return ra;
     88}
     89
     90double dvoMeanD (float dD, Average *average) {
     91
     92  double dec = average[0].D - dD / 3600.0;
     93  return dec;
     94}
     95
    7196// init all data, or just catalog data
    7297void dvo_average_init (Average *average) {
    7398  average->R               = 0;
    7499  average->D               = 0;
    75   average->dR              = 0;
    76   average->dD              = 0;
     100  average->dR              = NAN;
     101  average->dD              = NAN;
    77102
    78103  average->uR              = 0;
    79104  average->uD              = 0;
    80   average->duR             = 0;
    81   average->duD             = 0;
     105  average->duR             = NAN;
     106  average->duD             = NAN;
    82107  average->P               = 0;
    83   average->dP              = 0;
     108  average->dP              = NAN;
     109
     110  average->Rstk            = NAN;
     111  average->Dstk            = NAN;
     112  average->dRstk           = NAN;
     113  average->dDstk           = NAN;
    84114
    85115  average->ChiSqAve        = NAN;
     
    97127  average->Nmeasure        = 0;
    98128  average->Nmissing        = 0;
     129  average->Nlensing        = 0;
     130  average->Nlensobj        = 0;
    99131  average->Nextend         = 0;
     132
    100133  average->measureOffset   = -1;
    101134  average->missingOffset   = -1;
     135  average->lensingOffset   = -1;
     136  average->lensobjOffset   = -1;
    102137  average->extendOffset    = -1;
     138  average->paramsOffset    = -1;
     139
     140  average->refColorBlue    = NAN;
     141  average->refColorRed     = NAN;
    103142
    104143  average->flags           = 0;
     
    109148  average->catID           = 0;
    110149  average->extID           = 0;
     150  average->extIDgc         = 0;
    111151}
    112152
     
    119159  average->measureOffset   = -1;
    120160  average->catID           = 0;
     161  average->nOwn            = 0;
    121162}
    122163
     
    124165void dvo_secfilt_init (SecFilt *secfilt) {
    125166  secfilt->M           = NAN;
     167  secfilt->dM          = NAN;
    126168  secfilt->Map         = NAN;
     169  secfilt->dMap        = NAN;
     170  secfilt->sMap        = NAN;
    127171  secfilt->Mkron       = NAN;
    128172  secfilt->dMkron      = NAN;
    129   secfilt->dM          = NAN;
    130   secfilt->Xm          = NAN_S_SHORT;
    131 
    132   secfilt->FluxPSF     = NAN;
    133   secfilt->dFluxPSF    = NAN;
    134   secfilt->FluxKron    = NAN;
    135   secfilt->dFluxKron   = NAN;
    136 
    137   secfilt->flags       = 0;
     173  secfilt->sMkron      = NAN;
     174
     175  secfilt->Mstdev      = NAN;
     176  secfilt->Mmin        = NAN;
     177  secfilt->Mmax        = NAN;
     178  secfilt->Mchisq      = NAN;
     179
    138180  secfilt->Ncode       = 0;
    139181  secfilt->Nused       = 0;
    140 
    141   secfilt->M_20        = NAN_S_SHORT;
    142   secfilt->M_80        = NAN_S_SHORT;
     182  secfilt->NusedKron   = 0;
     183  secfilt->NusedAp     = 0;
     184
     185  secfilt->flags       = 0;
     186
     187  secfilt->MpsfStk     = NAN;
     188  secfilt->FpsfStk     = NAN;
     189  secfilt->dFpsfStk    = NAN;
     190
     191  secfilt->MkronStk    = NAN;
     192  secfilt->FkronStk    = NAN;
     193  secfilt->dFkronStk   = NAN;
     194
     195  secfilt->MapStk      = NAN;
     196  secfilt->FapStk      = NAN;
     197  secfilt->dFapStk     = NAN;
     198
     199  secfilt->stackDetectID = 0;
     200
     201  secfilt->MpsfWrp     = NAN;
     202  secfilt->FpsfWrp     = NAN;
     203  secfilt->dFpsfWrp    = NAN;
     204  secfilt->sFpsfWrp    = NAN;
     205
     206  secfilt->MkronWrp    = NAN;
     207  secfilt->FkronWrp    = NAN;
     208  secfilt->dFkronWrp   = NAN;
     209  secfilt->sFkronWrp   = NAN;
     210
     211  secfilt->MapWrp      = NAN;
     212  secfilt->FapWrp      = NAN;
     213  secfilt->dFapWrp     = NAN;
     214  secfilt->sFapWrp     = NAN;
     215
     216  secfilt->NusedWrp     = 0;
     217  secfilt->NusedKronWrp = 0;
     218  secfilt->NusedApWrp   = 0;
    143219
    144220  secfilt->ubercalDist = 1000;
    145   secfilt->Mstdev      = NAN_S_SHORT;
    146   secfilt->stackDetectID     = 0;
    147221}
    148222
    149223// init all data, or just catalog data
    150224void dvo_measure_init (Measure *measure) {
     225 measure->R         = NAN;
     226 measure->D         = NAN;
     227
    151228 measure->M         = NAN;
    152  measure->dR        = NAN;
    153  measure->dD        = NAN;
    154  measure->Mcal      = NAN;
     229 measure->dM        = NAN;
    155230 measure->Map       = NAN;
     231 measure->dMap      = NAN;
    156232 measure->Mkron     = NAN;
    157233 measure->dMkron    = NAN;
    158  measure->dM        = NAN;
     234 measure->Mcal      = NAN;
    159235 measure->dMcal     = NAN;
    160236 measure->dt        = NAN;
     
    164240 measure->FluxKron  = NAN;
    165241 measure->dFluxKron = NAN;
     242 measure->FluxAp    = NAN;
     243 measure->dFluxAp   = NAN;
    166244
    167245 measure->airmass   = NAN;
     
    173251 measure->Yfix      = NAN;
    174252
     253 measure->XoffKH    = NAN;
     254 measure->YoffKH    = NAN;
     255 measure->XoffDCR   = NAN;
     256 measure->YoffDCR   = NAN;
     257 measure->RoffGAL   = NAN;
     258 measure->DoffGAL   = NAN;
     259
    175260 measure->Sky       = NAN;
    176261 measure->dSky      = NAN;
    177262
    178263 measure->t         = 0;
    179  measure->t_msec    = 0;
    180264 measure->averef    = 0;
    181265
    182266 measure->detID     = 0;
    183  measure->imageID   = 0;
    184267 measure->objID     = 0;
    185268 measure->catID     = 0;
     269
    186270 measure->extID     = 0;
     271
     272 measure->imageID   = 0;
    187273
    188274 measure->psfQF     = NAN;
    189275 measure->psfQFperf = NAN;
    190276 measure->psfChisq  = NAN;
     277
    191278 measure->psfNdof   = 0;
    192279 measure->psfNpix   = 0;
     
    202289 measure->Myy       = 0;
    203290
     291 measure->t_msec    = 0;
     292 measure->photcode  = 0;
     293
    204294 measure->dXccd     = 0;
    205295 measure->dYccd     = 0;
     
    209299 measure->pltscale  = NAN;
    210300
    211  measure->photcode  = 0;
    212301 measure->dbFlags   = 0;
    213302 measure->photFlags = 0;
     
    215304
    216305void dvo_measureT_init (MeasureTiny *measure) {
    217  measure->dR        = NAN;
    218  measure->dD        = NAN;
     306 measure->R         = NAN;
     307 measure->D         = NAN;
    219308 measure->M         = NAN;
    220309 measure->Mcal      = NAN;
     
    242331 measure->dYccd     = 0;
    243332 measure->dRsys     = 0;
     333 measure->myDet     = FALSE;
     334}
     335
     336// init all data, or just catalog data
     337void dvo_lensing_init (Lensing *lensing) {
     338  lensing->X11_sm_obj = NAN;
     339  lensing->X12_sm_obj = NAN;
     340  lensing->X22_sm_obj = NAN;
     341  lensing->E1_sm_obj  = NAN;
     342  lensing->E2_sm_obj  = NAN;
     343
     344  lensing->X11_sh_obj = NAN;
     345  lensing->X12_sh_obj = NAN;
     346  lensing->X22_sh_obj = NAN;
     347  lensing->E1_sh_obj  = NAN;
     348  lensing->E2_sh_obj  = NAN;
     349
     350  lensing->X11_sm_psf = NAN;
     351  lensing->X12_sm_psf = NAN;
     352  lensing->X22_sm_psf = NAN;
     353  lensing->E1_sm_psf  = NAN;
     354  lensing->E2_sm_psf  = NAN;
     355
     356  lensing->X11_sh_psf = NAN;
     357  lensing->X12_sh_psf = NAN;
     358  lensing->X22_sh_psf = NAN;
     359  lensing->E1_sh_psf  = NAN;
     360  lensing->E2_sh_psf  = NAN;
     361
     362  lensing->F_ApR5     = NAN;
     363  lensing->dF_ApR5    = NAN;
     364  lensing->sF_ApR5    = NAN;
     365  lensing->fF_ApR5    = NAN;
     366
     367  lensing->F_ApR6     = NAN;
     368  lensing->dF_ApR6    = NAN;
     369  lensing->sF_ApR6    = NAN;
     370  lensing->fF_ApR6    = NAN;
     371
     372  lensing->detID = -1;
     373  lensing->objID = -1;
     374  lensing->catID = -1;
     375  lensing->averef = 0;
     376}
     377
     378// init all data, or just catalog data
     379void dvo_lensobj_init (Lensobj *lensobj) {
     380  lensobj->X11_sm_obj = NAN;
     381  lensobj->X12_sm_obj = NAN;
     382  lensobj->X22_sm_obj = NAN;
     383  lensobj->E1_sm_obj  = NAN;
     384  lensobj->E2_sm_obj  = NAN;
     385
     386  lensobj->X11_sh_obj = NAN;
     387  lensobj->X12_sh_obj = NAN;
     388  lensobj->X22_sh_obj = NAN;
     389  lensobj->E1_sh_obj  = NAN;
     390  lensobj->E2_sh_obj  = NAN;
     391
     392  lensobj->X11_sm_psf = NAN;
     393  lensobj->X12_sm_psf = NAN;
     394  lensobj->X22_sm_psf = NAN;
     395  lensobj->E1_sm_psf  = NAN;
     396  lensobj->E2_sm_psf  = NAN;
     397
     398  lensobj->X11_sh_psf = NAN;
     399  lensobj->X12_sh_psf = NAN;
     400  lensobj->X22_sh_psf = NAN;
     401  lensobj->E1_sh_psf  = NAN;
     402  lensobj->E2_sh_psf  = NAN;
     403
     404  lensobj->F_ApR5     = NAN;
     405  lensobj->dF_ApR5    = NAN;
     406  lensobj->sF_ApR5    = NAN;
     407  lensobj->fF_ApR5    = NAN;
     408
     409  lensobj->F_ApR6     = NAN;
     410  lensobj->dF_ApR6    = NAN;
     411  lensobj->sF_ApR6    = NAN;
     412  lensobj->fF_ApR6    = NAN;
     413
     414  lensobj->gamma = NAN;
     415  lensobj->E1 = NAN;
     416  lensobj->E2 = NAN;
     417
     418  lensobj->objID = -1;
     419  lensobj->catID = -1;
     420
     421  lensobj->pad = 0;
    244422}
    245423
     
    267445  catalog[0].secfilt = NULL;
    268446 
     447  catalog[0].lensing = NULL;
     448  catalog[0].lensobj = NULL;
     449
    269450  catalog[0].averageT = NULL;
    270451  catalog[0].measureT = NULL;
     
    279460  catalog[0].Nsecf_mem = 0;
    280461
     462  catalog[0].Nlensing = 0;
     463  catalog[0].Nlensobj = 0;
     464
    281465  catalog[0].Naves_disk = 0;
    282466  catalog[0].Nmeas_disk = 0;
     
    284468  catalog[0].Nsecf_disk = 0;
    285469
     470  catalog[0].Nlensing_disk = 0;
     471  catalog[0].Nlensobj_disk = 0;
     472
    286473  catalog[0].Naves_off  = 0;
    287474  catalog[0].Nmeas_off  = 0;
     
    289476  catalog[0].Nsecf_off  = 0;
    290477
     478  catalog[0].Nlensing_off  = 0;
     479  catalog[0].Nlensobj_off  = 0;
     480
    291481  /* pointers to SPLIT data files */
    292482  catalog[0].measure_catalog = NULL;
    293483  catalog[0].missing_catalog = NULL;
    294484  catalog[0].secfilt_catalog = NULL;
     485  catalog[0].lensing_catalog = NULL;
     486  catalog[0].lensobj_catalog = NULL;
    295487
    296488  /* pointers for data manipulation */
    297   catalog[0].found = NULL;
    298   catalog[0].image = NULL;
    299   catalog[0].mosaic = NULL;
    300   catalog[0].X = NULL;
    301   catalog[0].Y = NULL;
     489  // catalog[0].X_t = NULL;
     490  // catalog[0].Y_t = NULL;
     491  catalog[0].nOwn_t = NULL;
     492  catalog[0].found_t = NULL;
     493  // catalog[0].image_t = NULL;
     494  // catalog[0].mosaic_t = NULL;
     495  catalog[0].foundWarp_t = NULL;
    302496}
    303497
     
    343537  }
    344538
     539  // closes f but does not set back to NULL
    345540  fclearlockfile (catalog[0].filename, catalog[0].f, catalog[0].lockmode, &dbstate);
    346541
    347542  if (catalog[0].catmode == DVO_MODE_SPLIT) {
    348     if (catalog[0].measure_catalog != NULL) dvo_catalog_unlock (catalog[0].measure_catalog);
    349     if (catalog[0].missing_catalog != NULL) dvo_catalog_unlock (catalog[0].missing_catalog);
    350     if (catalog[0].secfilt_catalog != NULL) dvo_catalog_unlock (catalog[0].secfilt_catalog);
     543    if (catalog[0].measure_catalog) dvo_catalog_unlock (catalog[0].measure_catalog);
     544    if (catalog[0].missing_catalog) dvo_catalog_unlock (catalog[0].missing_catalog);
     545    if (catalog[0].secfilt_catalog) dvo_catalog_unlock (catalog[0].secfilt_catalog);
     546    if (catalog[0].lensing_catalog) dvo_catalog_unlock (catalog[0].lensing_catalog);
     547    if (catalog[0].lensobj_catalog) dvo_catalog_unlock (catalog[0].lensobj_catalog);
    351548  }
    352549  return (1);
     
    577774    for (in = out = i = 0; i < catalog[0].Naverage; i++) {
    578775      for (j = 0; j < catalog[0].Nsecfilt; j++, in++, out++) {
    579         outsec[out].M  = insec[in].M;
    580         outsec[out].dM = insec[in].dM;
    581         outsec[out].Xm = insec[in].Xm;
     776        outsec[out].M      = insec[in].M;
     777        outsec[out].dM     = insec[in].dM;
     778        outsec[out].Mchisq = insec[in].Mchisq;
    582779      }
    583780      for (j = 0; j < Nextra; j++, out++) {
    584         outsec[out].M  = NAN;
    585         outsec[out].dM = NAN;
    586         outsec[out].Xm = NAN_S_SHORT;
     781        outsec[out].M      = NAN;
     782        outsec[out].dM     = NAN;
     783        outsec[out].Mchisq = NAN;
    587784      }
    588785    }
     
    614811      free (catalog[0].secfilt_catalog);
    615812    }
     813    if (catalog[0].lensing_catalog) {
     814      free (catalog[0].lensing_catalog[0].filename);
     815      dvo_catalog_free (catalog[0].lensing_catalog);
     816      free (catalog[0].lensing_catalog);
     817    }
     818    if (catalog[0].lensobj_catalog) {
     819      free (catalog[0].lensobj_catalog[0].filename);
     820      dvo_catalog_free (catalog[0].lensobj_catalog);
     821      free (catalog[0].lensobj_catalog);
     822    }
    616823  }
    617824  dvo_catalog_free_data (catalog);
     
    623830
    624831  /* free, initialize data structures */
    625   if (catalog[0].average != NULL) {
     832  if (catalog[0].average) {
    626833    free (catalog[0].average);
    627834    catalog[0].Naverage = 0;
    628835    catalog[0].average = NULL;
    629836  }
    630   if (catalog[0].measure != NULL) {
     837  if (catalog[0].measure) {
    631838    free (catalog[0].measure);
    632839    catalog[0].Nmeasure = 0;
    633840    catalog[0].measure = NULL;
    634841  }
    635   if (catalog[0].missing != NULL) {
     842  if (catalog[0].missing) {
    636843    free (catalog[0].missing);
    637844    catalog[0].Nmissing = 0;
    638845    catalog[0].missing = NULL;
    639846  }
    640   if (catalog[0].secfilt != NULL) {
     847  if (catalog[0].secfilt) {
    641848    free (catalog[0].secfilt);
    642849    catalog[0].Nsecf_mem = 0;
    643850    catalog[0].secfilt = NULL;
    644851  }
     852  if (catalog[0].lensing) {
     853    free (catalog[0].lensing);
     854    catalog[0].Nlensing = 0;
     855    catalog[0].lensing = NULL;
     856  }
     857  if (catalog[0].lensobj) {
     858    free (catalog[0].lensobj);
     859    catalog[0].Nlensobj = 0;
     860    catalog[0].lensobj = NULL;
     861  }
     862  // if (catalog[0].X_t)      free (catalog[0].X_t);
     863  // if (catalog[0].Y_t)      free (catalog[0].Y_t);
     864  if (catalog[0].nOwn_t)      free (catalog[0].nOwn_t);
     865  if (catalog[0].found_t)     free (catalog[0].found_t);
     866  // if (catalog[0].image_t)  free (catalog[0].image_t);
     867  // if (catalog[0].mosaic_t) free (catalog[0].mosaic_t);
     868  if (catalog[0].foundWarp_t) free (catalog[0].foundWarp_t);
    645869}
    646870
     
    731955      }
    732956    }
     957    if (catalog[0].lensing_catalog != NULL) {
     958      if (catalog[0].Nlensing_disk == 0) {
     959        // need to relock (and re-open) file for close elsewhere
     960        status = dvo_catalog_lock (catalog[0].lensing_catalog, lockmode);
     961      } else {
     962        if (!dvo_catalog_backup (catalog[0].lensing_catalog, FALSE)) {
     963          return FALSE;
     964        }
     965      }
     966    }
     967    if (catalog[0].lensobj_catalog != NULL) {
     968      if (catalog[0].Nlensobj_disk == 0) {
     969        // need to relock (and re-open) file for close elsewhere
     970        status = dvo_catalog_lock (catalog[0].lensobj_catalog, lockmode);
     971      } else {
     972        if (!dvo_catalog_backup (catalog[0].lensobj_catalog, FALSE)) {
     973          return FALSE;
     974        }
     975      }
     976    }
    733977  }
    734978  return TRUE;
     
    752996  status = unlink (tmpfilename);
    753997  if (status) {
    754     fprintf (stderr, "failed to unlink catalog %s\n", catalog->filename);
     998    fprintf (stderr, "failed to unlink catalog %s~\n", catalog->filename);
    755999    return FALSE;
    7561000  }
     
    7721016      }
    7731017    }
     1018    if ((catalog[0].lensing_catalog != NULL) && (catalog[0].Nlensing_disk > 0)) {
     1019      if (!dvo_catalog_unlink_backup (catalog[0].lensing_catalog, FALSE)) {
     1020        return FALSE;
     1021      }
     1022    }
     1023    if ((catalog[0].lensobj_catalog != NULL) && (catalog[0].Nlensobj_disk > 0)) {
     1024      if (!dvo_catalog_unlink_backup (catalog[0].lensobj_catalog, FALSE)) {
     1025        return FALSE;
     1026      }
     1027    }
    7741028  }
    7751029  return TRUE;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_catalog_chipcoords.c

    r16810 r37067  
    5656    m = average[i].measureOffset;
    5757    for (j = 0; j < average[i].Nmeasure; j++, m++) {
    58       ra  = average[i].R - measure[m].dR / 3600.0;
    59       dec = average[i].D - measure[m].dD / 3600.0;
     58      ra  = measure[m].R;
     59      dec = measure[m].D;
    6060      N = dvo_match_image (image, Nimage, measure[m].t, measure[m].photcode);
    6161      if (N == -1) continue;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_catalog_create.c

    r27435 r37067  
    7070    gfits_modify (&catalog[0].header, "SECFILT", "%s", 1, file);
    7171    free (file);
     72
     73    /* define lensing catalog file */
     74    ALLOCATE (catalog[0].lensing_catalog, Catalog, 1);
     75    dvo_catalog_init (catalog[0].lensing_catalog, TRUE);
     76
     77    /* create basic data for lensing catalog file */
     78    gfits_create_header (&catalog[0].lensing_catalog[0].header);
     79    ALLOCATE (catalog[0].lensing_catalog[0].filename, char, length);
     80    sprintf (catalog[0].lensing_catalog[0].filename, "%s/%s.cpx", path, root);
     81    file = filebasename (catalog[0].lensing_catalog[0].filename);
     82    gfits_modify (&catalog[0].header, "LENSING", "%s", 1, file);
     83    free (file);
     84
     85    /* define lensobj catalog file */
     86    ALLOCATE (catalog[0].lensobj_catalog, Catalog, 1);
     87    dvo_catalog_init (catalog[0].lensobj_catalog, TRUE);
     88
     89    /* create basic data for lensobj catalog file */
     90    gfits_create_header (&catalog[0].lensobj_catalog[0].header);
     91    ALLOCATE (catalog[0].lensobj_catalog[0].filename, char, length);
     92    sprintf (catalog[0].lensobj_catalog[0].filename, "%s/%s.cpy", path, root);
     93    file = filebasename (catalog[0].lensobj_catalog[0].filename);
     94    gfits_modify (&catalog[0].header, "LENSOBJ", "%s", 1, file);
     95    free (file);
     96
    7297    free (path);
    7398    free (root);
     
    84109    }
    85110    if (dvo_catalog_lock (catalog[0].secfilt_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
     111      fprintf (stderr, "error with file lock\n");
     112      exit (2);
     113    }
     114    if (dvo_catalog_lock (catalog[0].lensing_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
     115      fprintf (stderr, "error with file lock\n");
     116      exit (2);
     117    }
     118    if (dvo_catalog_lock (catalog[0].lensobj_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
    86119      fprintf (stderr, "error with file lock\n");
    87120      exit (2);
     
    111144  ALLOCATE (catalog[0].missing, Missing, 1);
    112145  ALLOCATE (catalog[0].secfilt, SecFilt, 1);
     146  ALLOCATE (catalog[0].lensing, Lensing, 1);
     147  ALLOCATE (catalog[0].lensobj, Lensobj, 1);
    113148
    114149  /* setup secondary filters to match photcodes:
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_catalog_mef.c

    r33649 r37067  
    77  off_t Nmeasure;
    88  off_t Nmissing;
     9  off_t Nlensing;
     10  off_t Nlensobj;
    911  off_t Nitems, Nexpect;
    1012  int Nsecfilt;
     
    2224  if (!gfits_scan (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  &Nmissing)) return (FALSE);
    2325  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d",   1,               &Nsecfilt)) Nsecfilt = 0;
     26  if (!gfits_scan (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  &Nlensing)) return (FALSE);
     27  if (!gfits_scan (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  &Nlensobj)) return (FALSE);
    2428
    2529  /* the OBJID is a counter that uniquely defines an average entry and never changes.  if
     
    4044  catalog[0].Nmiss_disk = Nmissing;
    4145  catalog[0].Nsecf_disk = Naverage * Nsecfilt;
     46  catalog[0].Nlensing_disk = Nlensing;
     47  catalog[0].Nlensobj_disk = Nlensobj;
    4248
    4349  /**  Nsecfilt is unusual: it does not list the number of data items in the table
     
    5056  catalog[0].missing = NULL;
    5157  catalog[0].secfilt = NULL;
     58  catalog[0].lensing = NULL;
     59  catalog[0].lensobj = NULL;
    5260
    5361  /* validate table mode ?*/
     
    101109      return (FALSE);
    102110    }
    103     catalog[0].measure = FtableToMeasure (&ftable, &catalog[0].Nmeasure, &catalog[0].catformat);
     111    catalog[0].measure = FtableToMeasure (&ftable, catalog[0].average, &catalog[0].Nmeasure, &catalog[0].catformat);
    104112    if (Nmeasure != catalog[0].Nmeas_disk) {
    105113      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nmeasure,  catalog[0].Nmeas_disk);
     
    201209  }
    202210
     211  /* read Lensing table header */
     212  if (!gfits_fread_header (catalog[0].f, &header)) {
     213    if (VERBOSE) fprintf (stderr, "can't read table lensing header");
     214    return (FALSE);
     215  }
     216  /* read Lensing table data */
     217  if (catalog[0].catflags & LOAD_LENSING) {
     218    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
     219      if (VERBOSE) fprintf (stderr, "can't read table lensing data");
     220      return (FALSE);
     221    }
     222    catalog[0].lensing = FtableToLensing (&ftable, &catalog[0].Nlensing, &catalog[0].catformat);
     223    if (Nlensing != catalog[0].Nlensing_disk) {
     224      fprintf (stderr, "Warning: mismatch between Nlensing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensing,  catalog[0].Nlensing_disk);
     225    }
     226    catalog[0].Nlensing = catalog[0].Nlensing_disk;
     227    catalog[0].Nlensing_off = 0;
     228  } else {
     229    Nbytes = gfits_data_size (&header);
     230    fseeko (catalog[0].f, Nbytes, SEEK_CUR);
     231    ALLOCATE (catalog[0].lensing, Lensing, 1);
     232    catalog[0].Nlensing = 0;
     233    catalog[0].Nlensing_off = catalog[0].Nlensing_disk;
     234  }
     235
     236  /* read Lensobj table header */
     237  if (!gfits_fread_header (catalog[0].f, &header)) {
     238    if (VERBOSE) fprintf (stderr, "can't read table lensobj header");
     239    return (FALSE);
     240  }
     241  /* read Lensobj table data */
     242  if (catalog[0].catflags & LOAD_LENSOBJ) {
     243    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
     244      if (VERBOSE) fprintf (stderr, "can't read table lensobj data");
     245      return (FALSE);
     246    }
     247    catalog[0].lensobj = FtableToLensobj (&ftable, &catalog[0].Nlensobj, &catalog[0].catformat);
     248    if (Nlensobj != catalog[0].Nlensobj_disk) {
     249      fprintf (stderr, "Warning: mismatch between Nlensobj in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensobj,  catalog[0].Nlensobj_disk);
     250    }
     251    catalog[0].Nlensobj = catalog[0].Nlensobj_disk;
     252    catalog[0].Nlensobj_off = 0;
     253  } else {
     254    Nbytes = gfits_data_size (&header);
     255    fseeko (catalog[0].f, Nbytes, SEEK_CUR);
     256    ALLOCATE (catalog[0].lensobj, Lensobj, 1);
     257    catalog[0].Nlensobj = 0;
     258    catalog[0].Nlensobj_off = catalog[0].Nlensobj_disk;
     259  }
     260
    203261  return (TRUE);
    204262}
     
    249307  gfits_modify (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  catalog[0].Nmissing);
    250308  gfits_modify (&catalog[0].header, "NSECFILT", "%d",   1,                        Nsecfilt);
     309  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  catalog[0].Nlensing);
     310  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  catalog[0].Nlensobj);
    251311  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    252312  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    289349
    290350  /* write out Measure table (convert to FITS table format) */
    291   MeasureToFtable (&ftable, catalog[0].measure, catalog[0].Nmeasure, catalog[0].catformat);
     351  MeasureToFtable (&ftable, catalog[0].average, catalog[0].measure, catalog[0].Nmeasure, catalog[0].catformat);
    292352  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    293353    fprintf (stderr, "can't write table header");
     
    317377  Nitems = catalog[0].Naverage * Nsecfilt;
    318378  SecFiltToFtable (&ftable, secfilt, Nitems, catalog[0].catformat);
     379  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
     380    fprintf (stderr, "can't write table header");
     381    goto failure;
     382  }
     383  if (!gfits_fwrite_table (catalog[0].f, &ftable)) {
     384    fprintf (stderr, "can't write table data");
     385    goto failure;
     386  }
     387  gfits_free_table (&ftable);
     388  gfits_free_header (&header);
     389
     390  /* write out Lensing table (convert to FITS table format) */
     391  LensingToFtable (&ftable, catalog[0].lensing, catalog[0].Nlensing, catalog[0].catformat);
     392  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
     393    fprintf (stderr, "can't write table header");
     394    goto failure;
     395  }
     396  if (!gfits_fwrite_table (catalog[0].f, &ftable)) {
     397    fprintf (stderr, "can't write table data");
     398    goto failure;
     399  }
     400  gfits_free_table (&ftable);
     401  gfits_free_header (&header);
     402
     403  /* write out Lensobj table (convert to FITS table format) */
     404  LensobjToFtable (&ftable, catalog[0].lensobj, catalog[0].Nlensobj, catalog[0].catformat);
    319405  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    320406    fprintf (stderr, "can't write table header");
     
    356442  secfilt header
    357443  secfilt table
     444  lensing header
     445  lensing table
     446  lensobj header
     447  lensobj table
    358448*/
    359449   
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_catalog_raw.c

    r34260 r37067  
    9090      FORMAT_CASE (PS1_V3,    PS1_V3);
    9191      FORMAT_CASE (PS1_V4,    PS1_V4);
     92      FORMAT_CASE (PS1_V5,    PS1_V5);
    9293      FORMAT_CASE (PS1_REF,   PS1_REF);
    9394
     
    144145  /* read and convert the measures (use a macro to clean this up?) */
    145146  if (catalog[0].catflags & LOAD_MEAS) {
    146     catalog[0].measure = ReadRawMeasure (catalog[0].f, catalog[0].Nmeasure, catalog[0].catformat);
     147    catalog[0].measure = ReadRawMeasure (catalog[0].f, catalog[0].average, catalog[0].Nmeasure, catalog[0].catformat);
    147148  } else {
    148149    /* skip over measures */
     
    284285  if (catalog[0].catformat == DVO_FORMAT_PS1_V3)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V3");
    285286  if (catalog[0].catformat == DVO_FORMAT_PS1_V4)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V4");
     287  if (catalog[0].catformat == DVO_FORMAT_PS1_V5)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V5");
    286288  if (catalog[0].catformat == DVO_FORMAT_PS1_REF)         gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_REF");
    287289
     
    303305  /* write averages and measures */
    304306  WriteRawAverage (f, catalog[0].average, catalog[0].Naverage, catalog[0].catformat, primary);
    305   WriteRawMeasure (f, catalog[0].measure, catalog[0].Nmeasure, catalog[0].catformat);
     307  WriteRawMeasure (f, catalog[0].average, catalog[0].measure, catalog[0].Nmeasure, catalog[0].catformat);
    306308
    307309  /* write missing data */
     
    387389      FORMAT_CASE (PS1_V3,    PS1_V3);
    388390      FORMAT_CASE (PS1_V4,    PS1_V4);
     391      FORMAT_CASE (PS1_V5,    PS1_V5);
    389392      FORMAT_CASE (PS1_REF,   PS1_REF);
    390393
     
    438441      FORMAT_CASE (PS1_V3,    PS1_V3);
    439442      FORMAT_CASE (PS1_V4,    PS1_V4);
     443      FORMAT_CASE (PS1_V5,    PS1_V5);
    440444      FORMAT_CASE (PS1_REF,   PS1_REF);
    441445
     
    451455/** Average / Raw Table conversions **/
    452456
    453 Measure *ReadRawMeasure (FILE *f, off_t Nmeasure, char format) {
     457Measure *ReadRawMeasure (FILE *f, Average *average, off_t Nmeasure, char format) {
    454458
    455459  Measure *measure;
     
    467471      } \
    468472      gfits_convert_Measure_##TYPE (tmpMeasure, sizeof(Measure_##TYPE), Nmeasure); \
    469       measure = Measure_##TYPE##_ToInternal (tmpMeasure, Nmeasure); \
     473      measure = Measure_##TYPE##_ToInternal (average, tmpMeasure, Nmeasure); \
    470474      free (tmpMeasure); \
    471475      break; }
     
    481485      }
    482486      gfits_convert_Measure (measure, sizeof(Measure), Nmeasure);
     487      break; }
     488
     489      FORMAT_CASE (LONEOS, Loneos);
     490      FORMAT_CASE (ELIXIR, Elixir);
     491      FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
     492      FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
     493      FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
     494      FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
     495      FORMAT_CASE (PS1_V1,    PS1_V1);
     496      FORMAT_CASE (PS1_V2,    PS1_V2);
     497      FORMAT_CASE (PS1_V3,    PS1_V3);
     498      FORMAT_CASE (PS1_V5,    PS1_V5);
     499      FORMAT_CASE (PS1_REF,   PS1_REF);
     500
     501    default:
     502      fprintf (stderr, "error reading measures\n");
     503      return (NULL);
     504  }
     505# undef FORMAT_CASE
     506
     507  return (measure);
     508}
     509
     510/* accepts and converts internal measure formats and outputs
     511   raw data in the specified format */
     512int WriteRawMeasure (FILE *f, Average *average, Measure *measure, off_t Nmeasure, char format) {
     513
     514// this macro generates the case statements for each type
     515# define FORMAT_CASE(NAME,TYPE) \
     516    case DVO_FORMAT_##NAME: { \
     517      off_t nitems; \
     518      Measure_##TYPE *tmpMeasure; \
     519      tmpMeasure = MeasureInternalTo_##TYPE (average, measure, Nmeasure); \
     520      gfits_convert_Measure_##TYPE (tmpMeasure, sizeof(Measure_##TYPE), Nmeasure); \
     521      nitems = fwrite (tmpMeasure, sizeof(Measure_##TYPE), Nmeasure, f); \
     522      free (tmpMeasure); \
     523      if (nitems != Nmeasure) { \
     524        fprintf (stderr, "failed to write measures ("OFF_T_FMT" vs "OFF_T_FMT")\n",  nitems,  Nmeasure); \
     525        return (FALSE); \
     526      } \
     527      break; }
     528
     529  switch (format) {
     530    case DVO_FORMAT_INTERNAL: {
     531      off_t nitems;
     532      gfits_convert_Measure (measure, sizeof(Measure), Nmeasure);
     533      nitems = fwrite (measure, sizeof(Measure), Nmeasure, f);
     534      if (nitems != Nmeasure) {
     535        fprintf (stderr, "failed to write measures ("OFF_T_FMT" vs "OFF_T_FMT")\n",  nitems,  Nmeasure);
     536        return (FALSE);
     537      }
    483538      break; }
    484539
     
    493548      FORMAT_CASE (PS1_V3,    PS1_V3);
    494549      FORMAT_CASE (PS1_V4,    PS1_V4);
    495       FORMAT_CASE (PS1_REF,   PS1_REF);
    496 
    497     default:
    498       fprintf (stderr, "error reading measures\n");
    499       return (NULL);
    500   }
    501 # undef FORMAT_CASE
    502 
    503   return (measure);
    504 }
    505 
    506 /* accepts and converts internal measure formats and outputs
    507    raw data in the specified format */
    508 int WriteRawMeasure (FILE *f, Measure *measure, off_t Nmeasure, char format) {
    509 
    510 // this macro generates the case statements for each type
    511 # define FORMAT_CASE(NAME,TYPE) \
    512     case DVO_FORMAT_##NAME: { \
    513       off_t nitems; \
    514       Measure_##TYPE *tmpMeasure; \
    515       tmpMeasure = MeasureInternalTo_##TYPE (measure, Nmeasure); \
    516       gfits_convert_Measure_##TYPE (tmpMeasure, sizeof(Measure_##TYPE), Nmeasure); \
    517       nitems = fwrite (tmpMeasure, sizeof(Measure_##TYPE), Nmeasure, f); \
    518       free (tmpMeasure); \
    519       if (nitems != Nmeasure) { \
    520         fprintf (stderr, "failed to write measures ("OFF_T_FMT" vs "OFF_T_FMT")\n",  nitems,  Nmeasure); \
    521         return (FALSE); \
    522       } \
    523       break; }
    524 
    525   switch (format) {
    526     case DVO_FORMAT_INTERNAL: {
    527       off_t nitems;
    528       gfits_convert_Measure (measure, sizeof(Measure), Nmeasure);
    529       nitems = fwrite (measure, sizeof(Measure), Nmeasure, f);
    530       if (nitems != Nmeasure) {
    531         fprintf (stderr, "failed to write measures ("OFF_T_FMT" vs "OFF_T_FMT")\n",  nitems,  Nmeasure);
    532         return (FALSE);
    533       }
    534       break; }
    535 
    536       FORMAT_CASE (LONEOS, Loneos);
    537       FORMAT_CASE (ELIXIR, Elixir);
    538       FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
    539       FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
    540       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
    541       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
    542       FORMAT_CASE (PS1_V1,    PS1_V1);
    543       FORMAT_CASE (PS1_V2,    PS1_V2);
    544       FORMAT_CASE (PS1_V3,    PS1_V3);
    545       FORMAT_CASE (PS1_V4,    PS1_V4);
     550      FORMAT_CASE (PS1_V5,    PS1_V5);
    546551      FORMAT_CASE (PS1_REF,   PS1_REF);
    547552
     
    599604      FORMAT_CASE (PS1_V3,    PS1_V3);
    600605      FORMAT_CASE (PS1_V4,    PS1_V4);
     606      FORMAT_CASE (PS1_V5,    PS1_V5);
    601607      FORMAT_CASE (PS1_REF,   PS1_REF);
    602608
     
    650656      FORMAT_CASE (PS1_V3,    PS1_V3);
    651657      FORMAT_CASE (PS1_V4,    PS1_V4);
     658      FORMAT_CASE (PS1_V5,    PS1_V5);
    652659      FORMAT_CASE (PS1_REF,   PS1_REF);
    653660
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_catalog_split.c

    r34844 r37067  
    134134  if (!gfits_scan (&catalog[0].header, name,  "%s", 1, string)) {
    135135    free (path);
     136    // databases created prior to ~2014.07.01 did not have the LENSING or LENSOBJ paths in their headers.
     137    // in these cases, we do not try to lock or open the relevant file
     138    if (!strcmp (name, "LENSING")) return (DVO_CAT_OPEN_EMPTY);
     139    if (!strcmp (name, "LENSOBJ")) return (DVO_CAT_OPEN_EMPTY);
    136140    return (DVO_CAT_OPEN_FAIL);
    137141  }
     
    161165  fseeko (subcat[0].f, Nskip, SEEK_CUR);
    162166
    163   /* read Measure table header */
     167  /* read table header */
    164168  if (!gfits_fread_header (subcat[0].f, header)) {
    165169    if (VERBOSE) fprintf (stderr, "can't read %s PHU header\n", name);
     
    176180  off_t Nmeasure;
    177181  off_t Nmissing;
     182  off_t Nlensing;
     183  off_t Nlensobj;
    178184  off_t Nitems;
    179185  int status, Nsecfilt;
     
    190196
    191197  /* get the components from the header - these duplicate information in the split files (NAXIS2) */
     198  // NSTARS, NMEAS, NMISS are required; NLENSING, NLENSOBJ are not (0 if not found)
    192199  if (!gfits_scan (&catalog[0].header, "NSTARS",   OFF_T_FMT, 1,  &Naverage)) return (FALSE);
    193200  if (!gfits_scan (&catalog[0].header, "NMEAS",    OFF_T_FMT, 1,  &Nmeasure)) return (FALSE);
    194201  if (!gfits_scan (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  &Nmissing)) return (FALSE);
    195   if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d",   1,               &Nsecfilt)) Nsecfilt = 0;
     202  if (!gfits_scan (&catalog[0].header, "NSECFILT",      "%d", 1,  &Nsecfilt)) Nsecfilt = 0;
     203  if (!gfits_scan (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  &Nlensing)) Nlensing = 0;
     204  if (!gfits_scan (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  &Nlensobj)) Nlensobj = 0;
    196205
    197206  /* the OBJID is a counter that uniquely defines an average entry and never changes.  if
     
    212221  catalog[0].Nmiss_disk = Nmissing;
    213222  catalog[0].Nsecf_disk = Naverage * Nsecfilt;
     223  catalog[0].Nlensing_disk = Nlensing;
     224  catalog[0].Nlensobj_disk = Nlensobj;
    214225
    215226  /**  Nsecfilt is unusual: it does not list the number of data items in the table
     
    222233  catalog[0].missing = NULL;
    223234  catalog[0].secfilt = NULL;
     235  catalog[0].lensing = NULL;
     236  catalog[0].lensobj = NULL;
    224237
    225238  /*** Average Table ***/
     
    277290    }
    278291    /* convert data format to internal : returns number of row read in Nmeasure */
    279     catalog[0].measure = FtableToMeasure (&ftable, &Nmeasure, &catalog[0].catformat);
     292    catalog[0].measure = FtableToMeasure (&ftable, catalog[0].average, &Nmeasure, &catalog[0].catformat);
    280293    if (Nmeasure != catalog[0].Nmeas_disk) {
    281294      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nmeasure,  catalog[0].Nmeas_disk);
     
    372385  gfits_free_header (ftable.header);
    373386
     387  /*** Lensing Table ***/
     388  if (!(catalog[0].catflags & SKIP_LENSING)) {
     389    // unless we specify 'skip', we still need to load the Lensing table
     390    status = dvo_catalog_open_subcat (catalog, &catalog[0].lensing_catalog, ftable.header, "LENSING", VERBOSE);
     391    if (status == DVO_CAT_OPEN_FAIL) {
     392      return (FALSE);
     393    }
     394    // the Lensing file need not exist, unless we expect data to exist
     395    if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nlensing_disk > 0)) {
     396      return (FALSE);
     397    }
     398  }
     399  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_LENSING)) {
     400    // only read the Lensing table if the file actually exists
     401    /* read Lensing table data */
     402    if (!gfits_fread_ftable_data (catalog[0].lensing_catalog[0].f, &ftable, FALSE)) {
     403      if (VERBOSE) fprintf (stderr, "can't read table lensing data\n");
     404      return (FALSE);
     405    }
     406    /* convert data format to internal : returns number of row read in Nlensing */
     407    catalog[0].lensing = FtableToLensing (&ftable, &Nlensing, &catalog[0].catformat);
     408    if (Nlensing != catalog[0].Nlensing_disk) {
     409      fprintf (stderr, "Warning: mismatch between Nlensing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensing,  catalog[0].Nlensing_disk);
     410    }
     411    catalog[0].Nlensing = catalog[0].Nlensing_disk;
     412    catalog[0].Nlensing_off = 0;
     413  } else {
     414    if (catalog[0].lensing_catalog) {
     415      gfits_free_header (&catalog[0].lensing_catalog[0].header);
     416    } else {
     417      ALLOCATE (catalog[0].lensing_catalog, Catalog, 1);
     418      dvo_catalog_init (catalog[0].lensing_catalog, TRUE);
     419    }
     420    gfits_create_header (&catalog[0].lensing_catalog[0].header);
     421    ALLOCATE (catalog[0].lensing, Lensing, 1);
     422    catalog[0].Nlensing = 0;
     423    catalog[0].Nlensing_off = catalog[0].Nlensing_disk;
     424  }
     425  gfits_free_header (&header);
     426
     427  /*** Lensobj Table ***/
     428  if (!(catalog[0].catflags & SKIP_LENSOBJ)) {
     429    // unless we specify 'skip', we still need to load the
     430    status = dvo_catalog_open_subcat (catalog, &catalog[0].lensobj_catalog, ftable.header, "LENSOBJ", VERBOSE);
     431    if (status == DVO_CAT_OPEN_FAIL) {
     432      return (FALSE);
     433    }
     434    // the Lensobj file need not exist, unless we expect data to exist
     435    if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nlensobj_disk > 0)) {
     436      return (FALSE);
     437    }
     438  }
     439  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_LENSOBJ)) {
     440    // only read the Lensobj table if the file actually exists
     441    /* read Lensobj table data */
     442    if (!gfits_fread_ftable_data (catalog[0].lensobj_catalog[0].f, &ftable, FALSE)) {
     443      if (VERBOSE) fprintf (stderr, "can't read table lensobj data\n");
     444      return (FALSE);
     445    }
     446    /* convert data format to internal : returns number of row read in Nlensobj */
     447    catalog[0].lensobj = FtableToLensobj (&ftable, &Nlensobj, &catalog[0].catformat);
     448    if (Nlensobj != catalog[0].Nlensobj_disk) {
     449      fprintf (stderr, "Warning: mismatch between Nlensobj in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensobj,  catalog[0].Nlensobj_disk);
     450    }
     451    catalog[0].Nlensobj = catalog[0].Nlensobj_disk;
     452    catalog[0].Nlensobj_off = 0;
     453  } else {
     454    if (catalog[0].lensobj_catalog) {
     455      gfits_free_header (&catalog[0].lensobj_catalog[0].header);
     456    } else {
     457      ALLOCATE (catalog[0].lensobj_catalog, Catalog, 1);
     458      dvo_catalog_init (catalog[0].lensobj_catalog, TRUE);
     459    }
     460    gfits_create_header (&catalog[0].lensobj_catalog[0].header);
     461    ALLOCATE (catalog[0].lensobj, Lensobj, 1);
     462    catalog[0].Nlensobj = 0;
     463    catalog[0].Nlensobj_off = catalog[0].Nlensobj_disk;
     464  }
     465  gfits_free_header (&header);
     466
    374467  return (TRUE);
    375468}
     
    380473
    381474  off_t Nbytes;
    382   off_t Naverage, Nexpect, Nitems, Nmeasure, Nmissing;
     475  off_t Naverage, Nexpect, Nitems, Nmeasure, Nmissing, Nlensing, Nlensobj;
    383476  Header header;
    384477  FTable ftable;
     
    476569
    477570    /* convert data format to internal : returns number of row read in Nmeasure */
    478     catalog[0].measure = FtableToMeasure (&ftable, &Nmeasure, &catalog[0].catformat);
     571    catalog[0].measure = FtableToMeasure (&ftable, catalog[0].average, &Nmeasure, &catalog[0].catformat);
    479572    if (Nmeasure != Nrows) {
    480573      // XXX this condition denotes the eof has been reached; not an error or a warning
     
    519612    catalog[0].Nmiss_off = start;
    520613  }
     614
     615  // XXX check the open status of the catalog
     616  if (catalog[0].catflags & LOAD_LENSING) {
     617
     618    Catalog *subcat = catalog[0].lensing_catalog;
     619
     620    /* move pointer past header -- must be already read (load_catalog) */
     621    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
     622    fseeko (subcat[0].f, Nbytes, SEEK_SET);
     623
     624    /* read Lensing table header */
     625    if (!gfits_fread_header (subcat[0].f, &header)) {
     626      if (VERBOSE) fprintf (stderr, "can't read table lensing header");
     627      return (FALSE);
     628    }
     629    /* read Lensing table data : format is irrelevant here */
     630    if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     631      if (VERBOSE) fprintf (stderr, "can't read table lensing data");
     632      return (FALSE);
     633    }
     634
     635    /* convert data format to internal : returns number of row read in Nlensing */
     636    catalog[0].lensing = FtableToLensing (&ftable, &Nlensing, &catalog[0].catformat);
     637    if (Nlensing != Nrows) {
     638      // XXX this condition denotes the eof has been reached; not an error or a warning
     639      // fprintf (stderr, "Warning: mismatch between Nlensing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensing,  Nrows);
     640    }
     641    gfits_free_header (&header);
     642    catalog[0].Nlensing = Nlensing;
     643    catalog[0].Nlensing_off = start;
     644  }
     645
     646  // XXX check the open status of the catalog
     647  if (catalog[0].catflags & LOAD_LENSOBJ) {
     648
     649    Catalog *subcat = catalog[0].lensobj_catalog;
     650
     651    /* move pointer past header -- must be already read (load_catalog) */
     652    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
     653    fseeko (subcat[0].f, Nbytes, SEEK_SET);
     654
     655    /* read Lensobj table header */
     656    if (!gfits_fread_header (subcat[0].f, &header)) {
     657      if (VERBOSE) fprintf (stderr, "can't read table lensobj header");
     658      return (FALSE);
     659    }
     660    /* read Lensobj table data : format is irrelevant here */
     661    if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     662      if (VERBOSE) fprintf (stderr, "can't read table lensobj data");
     663      return (FALSE);
     664    }
     665
     666    /* convert data format to internal : returns number of row read in Nlensobj */
     667    catalog[0].lensobj = FtableToLensobj (&ftable, &Nlensobj, &catalog[0].catformat);
     668    if (Nlensobj != Nrows) {
     669      // XXX this condition denotes the eof has been reached; not an error or a warning
     670      // fprintf (stderr, "Warning: mismatch between Nlensobj in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensobj,  Nrows);
     671    }
     672    gfits_free_header (&header);
     673    catalog[0].Nlensobj = Nlensobj;
     674    catalog[0].Nlensobj_off = start;
     675  }
     676
    521677  return (TRUE);
    522678}
     
    530686  SecFilt *primary, *secfilt;
    531687  int Nsecfilt;
    532   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
     688  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new;
    533689  off_t first, start, Nrows;
    534690
     
    561717  Nmiss_disk_new = MAX (catalog[0].Nmiss_disk, catalog[0].Nmissing + catalog[0].Nmiss_off);
    562718  Nsecf_disk_new = MAX (catalog[0].Nsecf_disk, catalog[0].Naverage*Nsecfilt + catalog[0].Nsecf_off);
     719  Nlensing_disk_new = MAX (catalog[0].Nlensing_disk, catalog[0].Nlensing + catalog[0].Nlensing_off);
     720  Nlensobj_disk_new = MAX (catalog[0].Nlensobj_disk, catalog[0].Nlensobj + catalog[0].Nlensobj_off);
    563721
    564722  /* make sure header is consistent with data */
     
    567725  gfits_modify (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  Nmiss_disk_new);
    568726  gfits_modify (&catalog[0].header, "NSECFILT", "%d",   1, Nsecfilt);
     727  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
     728  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
    569729  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    570730  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    621781    assert (catalog[0].Nmeas_disk >= catalog[0].Nmeas_off);
    622782
    623     // convert to external table format
    624     if (!MeasureToFtable (&ftable, &catalog[0].measure[first], Nrows, catalog[0].catformat)) {
     783    // convert to external table format (note that the block above does not damage or free catalog.average)
     784    if (!MeasureToFtable (&ftable, catalog[0].average, &catalog[0].measure[first], Nrows, catalog[0].catformat)) {
    625785      fprintf (stderr, "trouble converting format\n");
    626786      goto failure;
     
    679839    if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecf_disk, Nsecf_disk_new)) {
    680840      fprintf (stderr, "failure writing SecFilt table\n");
     841      goto failure;
     842    }
     843    gfits_free_header (&header);
     844    gfits_free_table (&ftable);
     845  }
     846
     847  /*** Lensing Table ***/
     848  if ((catalog[0].catflags & LOAD_LENSING) && (catalog[0].lensing != NULL)) {
     849
     850    first  = 0;                    // first row in memory to write
     851    start  = catalog[0].Nlensing_off; // first disk row to write
     852    Nrows  = catalog[0].Nlensing - first;
     853
     854    assert (Nrows >= 0);
     855    assert (first >= 0);
     856    assert (first <= catalog[0].Nlensing);
     857    assert (catalog[0].Nlensing_disk >= catalog[0].Nlensing_off);
     858
     859    // convert to external table format (note that the block above does not damage or free catalog.average)
     860    if (!LensingToFtable (&ftable, &catalog[0].lensing[first], Nrows, catalog[0].catformat)) {
     861      fprintf (stderr, "trouble converting format\n");
     862      goto failure;
     863    }
     864
     865    // write out Lensing table
     866    if (!dvo_catalog_save_subcat (catalog[0].lensing_catalog, &ftable, start, Nrows, catalog[0].Nlensing_disk, Nlensing_disk_new)) {
     867      fprintf (stderr, "trouble writing Lensing table\n");
     868      goto failure;
     869    }
     870    gfits_free_header (&header);
     871    gfits_free_table (&ftable);
     872  }
     873
     874  /*** Lensobj Table ***/
     875  if ((catalog[0].catflags & LOAD_LENSOBJ) && (catalog[0].lensobj != NULL)) {
     876
     877    first  = 0;                    // first row in memory to write
     878    start  = catalog[0].Nlensobj_off; // first disk row to write
     879    Nrows  = catalog[0].Nlensobj - first;
     880
     881    assert (Nrows >= 0);
     882    assert (first >= 0);
     883    assert (first <= catalog[0].Nlensobj);
     884    assert (catalog[0].Nlensobj_disk >= catalog[0].Nlensobj_off);
     885
     886    // convert to external table format (note that the block above does not damage or free catalog.average)
     887    if (!LensobjToFtable (&ftable, &catalog[0].lensobj[first], Nrows, catalog[0].catformat)) {
     888      fprintf (stderr, "trouble converting format\n");
     889      goto failure;
     890    }
     891
     892    // write out Lensobj table
     893    if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
     894      fprintf (stderr, "trouble writing Lensobj table\n");
    681895      goto failure;
    682896    }
     
    711925  SecFilt *primary, *secfilt;
    712926  int Nsecfilt;
    713   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
     927  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new;
    714928  off_t first, start, Nrows;
    715929
     
    734948  if (catalog[0].Nsecf_off > 0) {
    735949    fprintf (stderr, "ERROR: only partial catalog (Secfilt) was loaded\n");
     950    goto failure;
     951  }
     952  if (catalog[0].Nlensing_off > 0) {
     953    fprintf (stderr, "ERROR: only partial catalog (Lensing) was loaded\n");
     954    goto failure;
     955  }
     956  if (catalog[0].Nlensobj_off > 0) {
     957    fprintf (stderr, "ERROR: only partial catalog (Lensobj) was loaded\n");
    736958    goto failure;
    737959  }
     
    760982  Nmiss_disk_new = catalog[0].Nmissing;
    761983  Nsecf_disk_new = catalog[0].Naverage*Nsecfilt;
     984  Nlensing_disk_new = catalog[0].Nlensing;
     985  Nlensobj_disk_new = catalog[0].Nlensobj;
    762986
    763987  /* make sure header is consistent with data */
     
    766990  gfits_modify (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  Nmiss_disk_new);
    767991  gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
     992  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
     993  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
    768994  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    769995  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    8211047
    8221048    // convert to external table format
    823     if (!MeasureToFtable (&ftable, &catalog[0].measure[first], Nrows, catalog[0].catformat)) {
     1049    if (!MeasureToFtable (&ftable, catalog[0].average, &catalog[0].measure[first], Nrows, catalog[0].catformat)) {
    8241050      fprintf (stderr, "trouble converting format\n");
    8251051      goto failure;
     
    8781104    if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecf_disk, Nsecf_disk_new)) {
    8791105      fprintf (stderr, "failure writing SecFilt table\n");
     1106      goto failure;
     1107    }
     1108    gfits_free_header (&header);
     1109    gfits_free_table (&ftable);
     1110  }
     1111
     1112  /*** Lensing Table ***/
     1113  if ((catalog[0].catflags & LOAD_LENSING) && (catalog[0].lensing != NULL)) {
     1114
     1115    first  = 0;                    // first row in memory to write
     1116    start  = catalog[0].Nlensing_off; // first disk row to write
     1117    Nrows  = catalog[0].Nlensing - first;
     1118
     1119    assert (Nrows >= 0);
     1120    assert (first >= 0);
     1121    assert (first <= catalog[0].Nlensing);
     1122    assert (catalog[0].Nlensing_disk >= catalog[0].Nlensing_off);
     1123
     1124    // convert to external table format
     1125    if (!LensingToFtable (&ftable, &catalog[0].lensing[first], Nrows, catalog[0].catformat)) {
     1126      fprintf (stderr, "trouble converting format\n");
     1127      goto failure;
     1128    }
     1129
     1130    // write out Lensing table
     1131    if (!dvo_catalog_save_subcat (catalog[0].lensing_catalog, &ftable, start, Nrows, catalog[0].Nlensing_disk, Nlensing_disk_new)) {
     1132      fprintf (stderr, "trouble writing Lensing table\n");
     1133      goto failure;
     1134    }
     1135    gfits_free_header (&header);
     1136    gfits_free_table (&ftable);
     1137  }
     1138
     1139  /*** Lensobj Table ***/
     1140  if ((catalog[0].catflags & LOAD_LENSOBJ) && (catalog[0].lensobj != NULL)) {
     1141
     1142    first  = 0;                    // first row in memory to write
     1143    start  = catalog[0].Nlensobj_off; // first disk row to write
     1144    Nrows  = catalog[0].Nlensobj - first;
     1145
     1146    assert (Nrows >= 0);
     1147    assert (first >= 0);
     1148    assert (first <= catalog[0].Nlensobj);
     1149    assert (catalog[0].Nlensobj_disk >= catalog[0].Nlensobj_off);
     1150
     1151    // convert to external table format
     1152    if (!LensobjToFtable (&ftable, &catalog[0].lensobj[first], Nrows, catalog[0].catformat)) {
     1153      fprintf (stderr, "trouble converting format\n");
     1154      goto failure;
     1155    }
     1156
     1157    // write out Lensobj table
     1158    if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
     1159      fprintf (stderr, "trouble writing Lensobj table\n");
    8801160      goto failure;
    8811161    }
     
    9091189  SecFilt *primary, *secfilt;
    9101190  int Nsecfilt;
    911   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
     1191  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new;
    9121192  off_t first, start, Nrows;
    9131193
     
    9391219  Nmiss_disk_new = MAX (catalog[0].Nmiss_disk, catalog[0].Nmissing + catalog[0].Nmiss_off);
    9401220  Nsecf_disk_new = MAX (catalog[0].Nsecf_disk, catalog[0].Naverage*Nsecfilt + catalog[0].Nsecf_off);
     1221  Nlensing_disk_new = MAX (catalog[0].Nlensing_disk, catalog[0].Nlensing + catalog[0].Nlensing_off);
     1222  Nlensobj_disk_new = MAX (catalog[0].Nlensobj_disk, catalog[0].Nlensobj + catalog[0].Nlensobj_off);
    9411223
    9421224  /* make sure header is consistent with data */
     
    9451227  gfits_modify (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  Nmiss_disk_new);
    9461228  gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
     1229  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
     1230  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
    9471231  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    9481232  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    10001284
    10011285    // convert to external table format
    1002     if (!MeasureToFtable (&ftable, &catalog[0].measure[first], Nrows, catalog[0].catformat)) {
     1286    // XXX does catalog.measure have averef correctly set up?
     1287    if (!MeasureToFtable (&ftable, catalog[0].average, &catalog[0].measure[first], Nrows, catalog[0].catformat)) {
    10031288      fprintf (stderr, "trouble converting format\n");
    10041289      goto failure;
     
    10581343    if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecf_disk, Nsecf_disk_new)) {
    10591344      fprintf (stderr, "failure writing SecFilt table\n");
     1345      goto failure;
     1346    }
     1347    gfits_free_header (&header);
     1348    gfits_free_table (&ftable);
     1349  }
     1350
     1351  /*** Lensing Table ***/
     1352  if (catalog[0].lensing != NULL) {
     1353
     1354    first  = catalog[0].Nlensing_disk - catalog[0].Nlensing_off;  // first row in memory to write
     1355    start  = catalog[0].Nlensing_disk; // first disk row to write
     1356    Nrows  = catalog[0].Nlensing - first;
     1357
     1358    assert (Nrows >= 0);
     1359    assert (first >= 0);
     1360    assert (first <= catalog[0].Nlensing);
     1361    assert (catalog[0].Nlensing_disk >= catalog[0].Nlensing_off);
     1362
     1363    // convert to external table format
     1364    // XXX does catalog.lensing have averef correctly set up?
     1365    if (!LensingToFtable (&ftable, &catalog[0].lensing[first], Nrows, catalog[0].catformat)) {
     1366      fprintf (stderr, "trouble converting format\n");
     1367      goto failure;
     1368    }
     1369
     1370    // write out Lensing table
     1371    if (!dvo_catalog_save_subcat (catalog[0].lensing_catalog, &ftable, start, Nrows, catalog[0].Nlensing_disk, Nlensing_disk_new)) {
     1372      fprintf (stderr, "trouble writing Lensing table\n");
     1373      goto failure;
     1374    }
     1375    gfits_free_header (&header);
     1376    gfits_free_table (&ftable);
     1377  }
     1378
     1379  /*** Lensobj Table ***/
     1380  if (catalog[0].lensobj != NULL) {
     1381
     1382    first  = catalog[0].Nlensobj_disk - catalog[0].Nlensobj_off;  // first row in memory to write
     1383    start  = catalog[0].Nlensobj_disk; // first disk row to write
     1384    Nrows  = catalog[0].Nlensobj - first;
     1385
     1386    assert (Nrows >= 0);
     1387    assert (first >= 0);
     1388    assert (first <= catalog[0].Nlensobj);
     1389    assert (catalog[0].Nlensobj_disk >= catalog[0].Nlensobj_off);
     1390
     1391    // convert to external table format
     1392    // XXX does catalog.lensobj have averef correctly set up?
     1393    if (!LensobjToFtable (&ftable, &catalog[0].lensobj[first], Nrows, catalog[0].catformat)) {
     1394      fprintf (stderr, "trouble converting format\n");
     1395      goto failure;
     1396    }
     1397
     1398    // write out Lensobj table
     1399    if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
     1400      fprintf (stderr, "trouble writing Lensobj table\n");
    10601401      goto failure;
    10611402    }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_convert.c

    r35172 r37067  
    4141  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V3",          PS1_V3);
    4242  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V4",          PS1_V4);
     43  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5",          PS1_V5);
    4344  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF);
    4445# undef CONVERT_FORMAT
     
    6364    fprintf (stderr, "EXTNAME missing for average table\n");
    6465    return (FALSE);
     66  }
     67
     68  // block to convert broken tables (PS1_V4 made before the Xfix addition)
     69  if (!strcmp (extname, "DVO_AVERAGE_PS1_V4") && (ftable[0].header[0].Naxis[0] == 120)) {
     70    Average_PS1_V4alt *tmpAverage;
     71    tmpAverage = gfits_table_get_Average_PS1_V4alt (ftable, Naverage, NULL);
     72    if (!tmpAverage) {
     73      fprintf (stderr, "ERROR: failed to read averages\n");
     74      exit (2);
     75    }
     76    average = Average_PS1_V4alt_ToInternal (tmpAverage, *Naverage);
     77    free (tmpAverage);
     78    *format = DVO_FORMAT_PS1_V4;
     79    return (average);
    6580  }
    6681
     
    98113  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V3",          PS1_V3,          PS1_V3);
    99114  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V4",          PS1_V4,          PS1_V4);
     115  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5",          PS1_V5,          PS1_V5);
    100116  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF,         PS1_REF);
    101117# undef CONVERT_FORMAT
     
    133149      FORMAT_CASE (PS1_V3,          PS1_V3);
    134150      FORMAT_CASE (PS1_V4,          PS1_V4);
     151      FORMAT_CASE (PS1_V5,          PS1_V5);
    135152      FORMAT_CASE (PS1_REF,         PS1_REF);
    136153# undef FORMAT_CASE
     
    145162/*** Measure / FTable conversion functions ***/
    146163
    147 Measure *FtableToMeasure (FTable *ftable, off_t *Nmeasure, char *format) {
     164// FtableToMeasure needs the Average since old formats stored measure.dR,dD only
     165Measure *FtableToMeasure (FTable *ftable, Average *average, off_t *Nmeasure, char *format) {
    148166
    149167  Measure *measure;
     
    156174  }
    157175
    158 # define CONVERT_FORMAT(NAME, FORMAT, TYPE) \
    159   if (!strcmp (extname, NAME)) { \
    160     Measure_##TYPE *tmpMeasure; \
     176  // block to convert broken tables (PS1_V4 made before the Xfix addition)
     177  if (!strcmp (extname, "DVO_MEASURE_PS1_V4") && (ftable[0].header[0].Naxis[0] == 176)) {
     178    fprintf (stderr, "reading alt PS1_V4 format\n");
     179    Measure_PS1_V4alt *tmpMeasure;
     180    tmpMeasure = gfits_table_get_Measure_PS1_V4alt (ftable, Nmeasure, NULL);
     181    if (!tmpMeasure) {
     182      fprintf (stderr, "ERROR: failed to read measures\n");
     183      exit (2);
     184    }
     185    myAssert (average, "conversion to internal needs average table");
     186    measure = Measure_PS1_V4alt_ToInternal (average, tmpMeasure, *Nmeasure);
     187    free (tmpMeasure);
     188    *format = DVO_FORMAT_PS1_V4;
     189    return (measure);
     190  }
     191
     192# define CONVERT_FORMAT(NAME, FORMAT, TYPE, ABS_COORDS)         \
     193  if (!strcmp (extname, NAME)) {                                        \
     194    Measure_##TYPE *tmpMeasure;                                         \
    161195    tmpMeasure = gfits_table_get_Measure_##TYPE (ftable, Nmeasure, NULL); \
    162     if (!tmpMeasure) { \
    163       fprintf (stderr, "ERROR: failed to read measures\n"); \
    164       exit (2); \
    165     } \
    166     measure = Measure_##TYPE##_ToInternal (tmpMeasure, *Nmeasure); \
    167     free (tmpMeasure); \
    168     *format = DVO_FORMAT_##FORMAT; \
     196    if (!tmpMeasure) {                                                  \
     197      fprintf (stderr, "ERROR: failed to read measures\n");             \
     198      exit (2);                                                         \
     199    }                                                                   \
     200    myAssert (ABS_COORDS || average, "conversion to internal needs average table"); \
     201    measure = Measure_##TYPE##_ToInternal (average, tmpMeasure, *Nmeasure); \
     202    free (tmpMeasure);                                                  \
     203    *format = DVO_FORMAT_##FORMAT;                                      \
    169204    return (measure); }
    170205
     
    179214  }
    180215
    181   CONVERT_FORMAT ("DVO_MEASURE_ELIXIR",          ELIXIR,          Elixir);
    182   CONVERT_FORMAT ("DVO_MEASURE_LONEOS",          LONEOS,          Loneos);
    183   CONVERT_FORMAT ("DVO_MEASURE_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
    184   CONVERT_FORMAT ("DVO_MEASURE_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
    185   CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
    186   CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
    187   CONVERT_FORMAT ("DVO_MEASURE_PS1_V1",          PS1_V1,          PS1_V1);
    188   CONVERT_FORMAT ("DVO_MEASURE_PS1_V2",          PS1_V2,          PS1_V2);
    189   CONVERT_FORMAT ("DVO_MEASURE_PS1_V3",          PS1_V3,          PS1_V3);
    190   CONVERT_FORMAT ("DVO_MEASURE_PS1_V4",          PS1_V4,          PS1_V4);
    191   CONVERT_FORMAT ("DVO_MEASURE_PS1_REF",         PS1_REF,         PS1_REF);
     216  CONVERT_FORMAT ("DVO_MEASURE_ELIXIR",          ELIXIR,          Elixir,          FALSE);
     217  CONVERT_FORMAT ("DVO_MEASURE_LONEOS",          LONEOS,          Loneos,          FALSE);
     218  CONVERT_FORMAT ("DVO_MEASURE_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0, FALSE);
     219  CONVERT_FORMAT ("DVO_MEASURE_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1, FALSE);
     220  CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1,       FALSE);
     221  CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2,       FALSE);
     222  CONVERT_FORMAT ("DVO_MEASURE_PS1_V1",          PS1_V1,          PS1_V1,          FALSE);
     223  CONVERT_FORMAT ("DVO_MEASURE_PS1_V2",          PS1_V2,          PS1_V2,          FALSE);
     224  CONVERT_FORMAT ("DVO_MEASURE_PS1_V3",          PS1_V3,          PS1_V3,          FALSE);
     225  CONVERT_FORMAT ("DVO_MEASURE_PS1_V4",          PS1_V4,          PS1_V4,          FALSE);
     226  CONVERT_FORMAT ("DVO_MEASURE_PS1_V5",          PS1_V5,          PS1_V5,          TRUE);
     227  CONVERT_FORMAT ("DVO_MEASURE_PS1_REF",         PS1_REF,         PS1_REF,         FALSE);
    192228# undef CONVERT_FORMAT
    193229
     
    198234}
    199235
    200 int MeasureToFtable (FTable *ftable, Measure *measure, off_t Nmeasure, char format) {
    201 
    202 # define FORMAT_CASE(FORMAT, TYPE) \
     236// MeasureToFtable needs the Average since old formats stored measure.dR,dD only
     237int MeasureToFtable (FTable *ftable, Average *average, Measure *measure, off_t Nmeasure, char format) {
     238
     239# define FORMAT_CASE(FORMAT, TYPE, ABS_COORDS)          \
    203240    case DVO_FORMAT_##FORMAT: { \
    204241      Measure_##TYPE *tmpMeasure; \
    205       tmpMeasure = MeasureInternalTo_##TYPE (measure, Nmeasure); \
     242      myAssert (ABS_COORDS || average, "conversion to internal needs average table"); \
     243      tmpMeasure = MeasureInternalTo_##TYPE (average, measure, Nmeasure); \
    206244      gfits_table_set_Measure_##TYPE (ftable, tmpMeasure, Nmeasure); \
    207245      free (tmpMeasure); \
     
    214252      break; }
    215253
    216       FORMAT_CASE (ELIXIR,          Elixir);
    217       FORMAT_CASE (LONEOS,          Loneos);
    218       FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
    219       FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
    220       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
    221       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
    222       FORMAT_CASE (PS1_V1,          PS1_V1);
    223       FORMAT_CASE (PS1_V2,          PS1_V2);
    224       FORMAT_CASE (PS1_V3,          PS1_V3);
    225       FORMAT_CASE (PS1_V4,          PS1_V4);
    226       FORMAT_CASE (PS1_REF,         PS1_REF);
     254      FORMAT_CASE (ELIXIR,          Elixir,          FALSE);
     255      FORMAT_CASE (LONEOS,          Loneos,          FALSE);
     256      FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0, FALSE);
     257      FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1, FALSE);
     258      FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1,       FALSE);
     259      FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2,       FALSE);
     260      FORMAT_CASE (PS1_V1,          PS1_V1,          FALSE);
     261      FORMAT_CASE (PS1_V2,          PS1_V2,          FALSE);
     262      FORMAT_CASE (PS1_V3,          PS1_V3,          FALSE);
     263      FORMAT_CASE (PS1_V4,          PS1_V4,          FALSE);
     264      FORMAT_CASE (PS1_V5,          PS1_V5,          TRUE);
     265      FORMAT_CASE (PS1_REF,         PS1_REF,         FALSE);
    227266# undef FORMAT_CASE
    228267
     
    280319  CONVERT_FORMAT ("DVO_SECFILT_PS1_V3",          PS1_V3,          PS1_V3);
    281320  CONVERT_FORMAT ("DVO_SECFILT_PS1_V4",          PS1_V4,          PS1_V4);
     321  CONVERT_FORMAT ("DVO_SECFILT_PS1_V5",          PS1_V5,          PS1_V5);
    282322  CONVERT_FORMAT ("DVO_SECFILT_PS1_REF",         PS1_REF,         PS1_REF);
    283323# undef CONVERT_FORMAT
     
    315355      FORMAT_CASE (PS1_V3,          PS1_V3);
    316356      FORMAT_CASE (PS1_V4,          PS1_V4);
     357      FORMAT_CASE (PS1_V5,          PS1_V5);
    317358      FORMAT_CASE (PS1_REF,         PS1_REF);
    318359# undef FORMAT_CASE
     
    320361    default:
    321362      fprintf (stderr, "table format unknown (secfilt)\n");
     363      return (FALSE);
     364  }
     365  return (TRUE);
     366}
     367
     368/*** Lensing / FTable conversion functions ***/
     369
     370Lensing *FtableToLensing (FTable *ftable, off_t *Nlensing, char *format) {
     371
     372  Lensing *lensing;
     373  char extname[80];
     374
     375  /* convert to the internal format */
     376  if (!gfits_scan (ftable[0].header, "EXTNAME", "%s", 1, extname)) {
     377    fprintf (stderr, "EXTNAME missing for lensing table\n");
     378    return (FALSE);
     379  }
     380
     381# define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     382  if (!strcmp (extname, NAME)) {                                        \
     383    Lensing_##TYPE *tmpLensing;                                         \
     384    tmpLensing = gfits_table_get_Lensing_##TYPE (ftable, Nlensing, NULL); \
     385    if (!tmpLensing) {                                                  \
     386      fprintf (stderr, "ERROR: failed to read lensings\n");             \
     387      exit (2);                                                         \
     388    }                                                                   \
     389    lensing = Lensing_##TYPE##_ToInternal (tmpLensing, *Nlensing); \
     390    free (tmpLensing);                                                  \
     391    *format = DVO_FORMAT_##FORMAT;                                      \
     392    return (lensing); }
     393
     394  if (!strcmp (extname, "DVO_LENSING")) {
     395    lensing = gfits_table_get_Lensing (ftable, Nlensing, NULL);
     396    if (!lensing) {
     397      fprintf (stderr, "ERROR: failed to read lensings\n");
     398      exit (2);
     399    }
     400    *format = DVO_FORMAT_INTERNAL;
     401    return (lensing);
     402  }
     403
     404// CONVERT_FORMAT ("DVO_LENSING_PS1_REF",         PS1_REF,         PS1_REF);
     405// CONVERT_FORMAT ("DVO_LENSING_ELIXIR",          ELIXIR,          Elixir);
     406// CONVERT_FORMAT ("DVO_LENSING_LONEOS",          LONEOS,          Loneos);
     407// CONVERT_FORMAT ("DVO_LENSING_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
     408// CONVERT_FORMAT ("DVO_LENSING_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
     409// CONVERT_FORMAT ("DVO_LENSING_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
     410// CONVERT_FORMAT ("DVO_LENSING_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     411// CONVERT_FORMAT ("DVO_LENSING_PS1_V1",          PS1_V1,          PS1_V1);
     412// CONVERT_FORMAT ("DVO_LENSING_PS1_V2",          PS1_V2,          PS1_V2);
     413// CONVERT_FORMAT ("DVO_LENSING_PS1_V3",          PS1_V3,          PS1_V3);
     414// CONVERT_FORMAT ("DVO_LENSING_PS1_V4",          PS1_V4,          PS1_V4);
     415  CONVERT_FORMAT ("DVO_LENSING_PS1_V5",          PS1_V5,          PS1_V5);
     416# undef CONVERT_FORMAT
     417
     418  fprintf (stderr, "table format unknown: %s\n", extname);
     419
     420  *Nlensing = 0;
     421  return (NULL);
     422}
     423
     424// LensingToFtable needs the Average since old formats stored lensing.dR,dD only
     425int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, char format) {
     426
     427# define FORMAT_CASE(FORMAT, TYPE)              \
     428    case DVO_FORMAT_##FORMAT: { \
     429      Lensing_##TYPE *tmpLensing; \
     430      tmpLensing = LensingInternalTo_##TYPE (lensing, Nlensing); \
     431      gfits_table_set_Lensing_##TYPE (ftable, tmpLensing, Nlensing); \
     432      free (tmpLensing); \
     433      break; }
     434
     435  /* convert from the internal format */
     436  switch (format) {
     437    case DVO_FORMAT_INTERNAL: {
     438      gfits_table_set_Lensing (ftable, lensing, Nlensing);
     439      break; }
     440
     441//    FORMAT_CASE (PS1_REF,         PS1_REF);
     442//    FORMAT_CASE (ELIXIR,          Elixir);
     443//    FORMAT_CASE (LONEOS,          Loneos);
     444//    FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
     445//    FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
     446//    FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
     447//    FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     448//    FORMAT_CASE (PS1_V1,          PS1_V1);
     449//    FORMAT_CASE (PS1_V2,          PS1_V2);
     450//    FORMAT_CASE (PS1_V3,          PS1_V3);
     451//    FORMAT_CASE (PS1_V4,          PS1_V4);
     452      FORMAT_CASE (PS1_V5,          PS1_V5);
     453# undef FORMAT_CASE
     454
     455    default:
     456      fprintf (stderr, "table format unknown (lensing)\n");
     457      return (FALSE);
     458  }
     459  return (TRUE);
     460}
     461
     462/*** Lensobj / FTable conversion functions ***/
     463
     464Lensobj *FtableToLensobj (FTable *ftable, off_t *Nlensobj, char *format) {
     465
     466  Lensobj *lensobj;
     467  char extname[80];
     468
     469  /* convert to the internal format */
     470  if (!gfits_scan (ftable[0].header, "EXTNAME", "%s", 1, extname)) {
     471    fprintf (stderr, "EXTNAME missing for lensobj table\n");
     472    return (FALSE);
     473  }
     474
     475# define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     476  if (!strcmp (extname, NAME)) {                                        \
     477    Lensobj_##TYPE *tmpLensobj;                                         \
     478    tmpLensobj = gfits_table_get_Lensobj_##TYPE (ftable, Nlensobj, NULL); \
     479    if (!tmpLensobj) {                                                  \
     480      fprintf (stderr, "ERROR: failed to read lensobjs\n");             \
     481      exit (2);                                                         \
     482    }                                                                   \
     483    lensobj = Lensobj_##TYPE##_ToInternal (tmpLensobj, *Nlensobj); \
     484    free (tmpLensobj);                                                  \
     485    *format = DVO_FORMAT_##FORMAT;                                      \
     486    return (lensobj); }
     487
     488  if (!strcmp (extname, "DVO_LENSOBJ")) {
     489    lensobj = gfits_table_get_Lensobj (ftable, Nlensobj, NULL);
     490    if (!lensobj) {
     491      fprintf (stderr, "ERROR: failed to read lensobjs\n");
     492      exit (2);
     493    }
     494    *format = DVO_FORMAT_INTERNAL;
     495    return (lensobj);
     496  }
     497
     498// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_REF",         PS1_REF,         PS1_REF);
     499// CONVERT_FORMAT ("DVO_LENSOBJ_ELIXIR",          ELIXIR,          Elixir);
     500// CONVERT_FORMAT ("DVO_LENSOBJ_LONEOS",          LONEOS,          Loneos);
     501// CONVERT_FORMAT ("DVO_LENSOBJ_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
     502// CONVERT_FORMAT ("DVO_LENSOBJ_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
     503// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
     504// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     505// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V1",          PS1_V1,          PS1_V1);
     506// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V2",          PS1_V2,          PS1_V2);
     507// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V3",          PS1_V3,          PS1_V3);
     508// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V4",          PS1_V4,          PS1_V4);
     509  CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V5",          PS1_V5,          PS1_V5);
     510# undef CONVERT_FORMAT
     511
     512  fprintf (stderr, "table format unknown: %s\n", extname);
     513
     514  *Nlensobj = 0;
     515  return (NULL);
     516}
     517
     518// LensobjToFtable needs the Average since old formats stored lensobj.dR,dD only
     519int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, char format) {
     520
     521# define FORMAT_CASE(FORMAT, TYPE)              \
     522    case DVO_FORMAT_##FORMAT: { \
     523      Lensobj_##TYPE *tmpLensobj; \
     524      tmpLensobj = LensobjInternalTo_##TYPE (lensobj, Nlensobj); \
     525      gfits_table_set_Lensobj_##TYPE (ftable, tmpLensobj, Nlensobj); \
     526      free (tmpLensobj); \
     527      break; }
     528
     529  /* convert from the internal format */
     530  switch (format) {
     531    case DVO_FORMAT_INTERNAL: {
     532      gfits_table_set_Lensobj (ftable, lensobj, Nlensobj);
     533      break; }
     534
     535//    FORMAT_CASE (PS1_REF,         PS1_REF);
     536//    FORMAT_CASE (ELIXIR,          Elixir);
     537//    FORMAT_CASE (LONEOS,          Loneos);
     538//    FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
     539//    FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
     540//    FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
     541//    FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     542//    FORMAT_CASE (PS1_V1,          PS1_V1);
     543//    FORMAT_CASE (PS1_V2,          PS1_V2);
     544//    FORMAT_CASE (PS1_V3,          PS1_V3);
     545//    FORMAT_CASE (PS1_V4,          PS1_V4);
     546      FORMAT_CASE (PS1_V5,          PS1_V5);
     547# undef FORMAT_CASE
     548
     549    default:
     550      fprintf (stderr, "table format unknown (lensobj)\n");
    322551      return (FALSE);
    323552  }
     
    399628  CONVERT_FORMAT ("DVO_IMAGE_PS1_V3",          PS1_V3,          PS1_V3);
    400629  CONVERT_FORMAT ("DVO_IMAGE_PS1_V4",          PS1_V4,          PS1_V4);
     630  CONVERT_FORMAT ("DVO_IMAGE_PS1_V5",          PS1_V5,          PS1_V5);
    401631  CONVERT_FORMAT ("DVO_IMAGE_PS1_REF",         PS1_REF,         PS1_REF);
    402632
     
    438668      FORMAT_CASE (PS1_V3,          PS1_V3);
    439669      FORMAT_CASE (PS1_V4,          PS1_V4);
     670      FORMAT_CASE (PS1_V5,          PS1_V5);
    440671      FORMAT_CASE (PS1_REF,         PS1_REF);
    441672
     
    493724      FORMAT_CASE (PS1_V3,          PS1_V3);
    494725      FORMAT_CASE (PS1_V4,          PS1_V4);
     726      FORMAT_CASE (PS1_V5,          PS1_V5);
    495727      FORMAT_CASE (PS1_REF,         PS1_REF);
    496728
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c

    r35162 r37067  
    33/* convert PS1_DEV_1 formats to internal formats */
    44
    5 Measure *Measure_PS1_DEV_1_ToInternal (Measure_PS1_DEV_1 *in, off_t Nvalues) {
     5Measure *Measure_PS1_DEV_1_ToInternal (Average *ave, Measure_PS1_DEV_1 *in, off_t Nvalues) {
    66
    77  off_t i;
     
    1212  for (i = 0; i < Nvalues; i++) {
    1313    dvo_measure_init (&out[i]);
    14     out[i].dR         = in[i].dR;
    15     out[i].dD         = in[i].dD;
     14
     15    int averef = in[i].averef;
     16    out[i].R          = ave[averef].R - in[i].dR / 3600.0;
     17    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1618    out[i].M          = in[i].M;
    1719    out[i].Mcal       = in[i].Mcal;
     
    5052}
    5153
    52 Measure_PS1_DEV_1 *MeasureInternalTo_PS1_DEV_1 (Measure *in, off_t Nvalues) {
     54Measure_PS1_DEV_1 *MeasureInternalTo_PS1_DEV_1 (Average *ave, Measure *in, off_t Nvalues) {
    5355
    5456  off_t i;
     
    5860
    5961  for (i = 0; i < Nvalues; i++) {
    60     out[i].dR         = in[i].dR;
    61     out[i].dD         = in[i].dD;
     62    int averef = in[i].averef;
     63
     64    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
     65    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    6266    out[i].M          = in[i].M;
    6367    out[i].Mcal       = in[i].Mcal;
     
    180184    out[i].M     = in[i].M;     
    181185    out[i].dM    = in[i].dM;     
    182     out[i].Xm    = in[i].Xm;     
     186    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    183187    out[i].Ncode = in[i].Ncode;
    184188    out[i].Nused = in[i].Nused;
     
    197201    out[i].M     = in[i].M;     
    198202    out[i].dM    = in[i].dM;     
    199     out[i].Xm    = in[i].Xm;     
     203    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
    200204    out[i].Ncode = in[i].Ncode;
    201205    out[i].Nused = in[i].Nused;
     
    203207  return (out);
    204208}
     209
     210# define RAW_IMAGE_NAME_LEN 64
    205211
    206212Image *Image_PS1_DEV_1_ToInternal (Image_PS1_DEV_1 *in, off_t Nvalues, off_t Nalloc) {
     
    217223    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    218224
    219     strncpy (out[i].name, in[i].name, 63); // out[128], in[64]
    220     out[i].name[63] = 0; // force termination
     225    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     226    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     227    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    221228
    222229    out[i].tzero            = in[i].tzero;
     
    284291    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    285292
    286     strncpy (out[i].name, in[i].name, 63); // out[128], in[64]
    287     out[i].name[63] = 0; // force termination
     293    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     294    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     295    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    288296
    289297    out[i].tzero            = in[i].tzero;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c

    r35162 r37067  
    33/* convert PS1_DEV_2 formats to internal formats */
    44
    5 Measure *Measure_PS1_DEV_2_ToInternal (Measure_PS1_DEV_2 *in, off_t Nvalues) {
     5Measure *Measure_PS1_DEV_2_ToInternal (Average *ave, Measure_PS1_DEV_2 *in, off_t Nvalues) {
    66
    77  off_t i;
     
    1212  for (i = 0; i < Nvalues; i++) {
    1313    dvo_measure_init (&out[i]);
    14     out[i].dR         = in[i].dR;
    15     out[i].dD         = in[i].dD;
     14
     15    int averef = in[i].averef;
     16    out[i].R          = ave[averef].R - in[i].dR / 3600.0;
     17    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1618    out[i].M          = in[i].M;
    1719    out[i].Mcal       = in[i].Mcal;
     
    4850}
    4951
    50 Measure_PS1_DEV_2 *MeasureInternalTo_PS1_DEV_2 (Measure *in, off_t Nvalues) {
     52Measure_PS1_DEV_2 *MeasureInternalTo_PS1_DEV_2 (Average *ave, Measure *in, off_t Nvalues) {
    5153
    5254  off_t i;
     
    5658
    5759  for (i = 0; i < Nvalues; i++) {
    58     out[i].dR         = in[i].dR;
    59     out[i].dD         = in[i].dD;
     60    int averef = in[i].averef;
     61
     62    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
     63    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    6064    out[i].M          = in[i].M;
    6165    out[i].Mcal       = in[i].Mcal;
     
    119123    out[i].measureOffset = in[i].measureOffset;
    120124    out[i].missingOffset = in[i].missingOffset;
    121     out[i].extendOffset  = in[i].extendOffset;
     125    out[i].refColorBlue  = in[i].refColor;
    122126    out[i].objID         = in[i].objID;
    123127    out[i].catID         = in[i].catID;
     
    153157    out[i].measureOffset = in[i].measureOffset;
    154158    out[i].missingOffset = in[i].missingOffset;
    155     out[i].extendOffset  = in[i].extendOffset;
     159    out[i].refColor  = in[i].refColorBlue;
    156160    out[i].objID         = in[i].objID;
    157161    out[i].catID         = in[i].catID;
     
    175179    out[i].M     = in[i].M;     
    176180    out[i].dM    = in[i].dM;     
    177     out[i].Xm    = in[i].Xm;     
     181    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    178182    out[i].Ncode = in[i].Ncode;
    179183    out[i].Nused = in[i].Nused;
     
    192196    out[i].M     = in[i].M;     
    193197    out[i].dM    = in[i].dM;     
    194     out[i].Xm    = in[i].Xm;     
     198    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
    195199    out[i].Ncode = in[i].Ncode;
    196200    out[i].Nused = in[i].Nused;
     
    198202  return (out);
    199203}
     204
     205# define RAW_IMAGE_NAME_LEN 64
    200206
    201207Image *Image_PS1_DEV_2_ToInternal (Image_PS1_DEV_2 *in, off_t Nvalues, off_t Nalloc) {
     
    212218    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    213219
    214     strncpy (out[i].name, in[i].name, 63); // out[121], in[64]
    215     out[i].name[63] = 0; // force termination
     220    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     221    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     222    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    216223
    217224    out[i].tzero            = in[i].tzero;
     
    276283    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    277284
    278     strncpy (out[i].name, in[i].name, 63); // in[121], out[64]
    279     out[i].name[63] = 0; // force termination
     285    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     286    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     287    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    280288
    281289    out[i].tzero            = in[i].tzero;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c

    r35162 r37067  
    44
    55// We only provide image and photcode conversion
     6
     7# define RAW_IMAGE_NAME_LEN 128
    68
    79Image *Image_PS1_DEV_3_ToInternal (Image_PS1_DEV_3 *in, off_t Nvalues, off_t Nalloc) {
     
    1820    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    1921
    20     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    21     out[i].name[120] = 0; // force termination
     22    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     23    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     24    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    2225
    2326    out[i].tzero            = in[i].tzero;
     
    7780    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    7881
    79     strncpy (out[i].name, in[i].name, 127); // out[128], in[128]
    80     out[i].name[127] = 0; // force termination
     82    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     83    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     84    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    8185
    8286    out[i].tzero            = in[i].tzero;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c

    r35162 r37067  
    33/* convert PS1_REF formats to internal formats */
    44
    5 Measure *Measure_PS1_REF_ToInternal (Measure_PS1_REF *in, off_t Nvalues) {
     5Measure *Measure_PS1_REF_ToInternal (Average *ave, Measure_PS1_REF *in, off_t Nvalues) {
    66
    77  off_t i;
     
    1313    dvo_measure_init (&out[i]);
    1414
    15     out[i].dR         = in[i].dR;
    16     out[i].dD         = in[i].dD;
     15    int averef = in[i].averef;
     16    out[i].R          = ave[averef].R - in[i].dR / 3600.0;
     17    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1718    out[i].M          = in[i].M;
    1819    out[i].dM         = in[i].dM;
     
    2829}
    2930
    30 Measure_PS1_REF *MeasureInternalTo_PS1_REF (Measure *in, off_t Nvalues) {
     31Measure_PS1_REF *MeasureInternalTo_PS1_REF (Average *ave, Measure *in, off_t Nvalues) {
    3132
    3233  off_t i;
     
    3637
    3738  for (i = 0; i < Nvalues; i++) {
    38     out[i].dR         = in[i].dR;
    39     out[i].dD         = in[i].dD;
     39    int averef = in[i].averef;
     40
     41    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
     42    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    4043    out[i].M          = in[i].M;
    4144    out[i].dM         = in[i].dM;
     
    129132}
    130133
     134# define RAW_IMAGE_NAME_LEN 121
     135
    131136Image *Image_PS1_REF_ToInternal (Image_PS1_REF *in, off_t Nvalues, off_t Nalloc) {
    132137
     
    142147    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    143148
    144     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    145     out[i].name[120] = 0; // force termination
     149    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     150    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     151    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    146152
    147153    out[i].tzero            = in[i].tzero;
     
    204210    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    205211
    206     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    207     out[i].name[120] = 0; // force termination
     212    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     213    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     214    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    208215
    209216    out[i].tzero            = in[i].tzero;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c

    r35162 r37067  
    33/* convert PS1_V1 formats to internal formats */
    44
    5 Measure *Measure_PS1_V1_ToInternal (Measure_PS1_V1 *in, off_t Nvalues) {
     5Measure *Measure_PS1_V1_ToInternal (Average *ave, Measure_PS1_V1 *in, off_t Nvalues) {
    66
    77  off_t i;
     
    1313    dvo_measure_init (&out[i]);
    1414
    15     out[i].dR         = in[i].dR;
    16     out[i].dD         = in[i].dD;
     15    int averef = in[i].averef;
     16    out[i].R          = ave[averef].R - in[i].dR / 3600.0;
     17    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1718    out[i].M          = in[i].M;
    1819    out[i].Mcal       = in[i].Mcal;
     
    5859}
    5960
    60 Measure_PS1_V1 *MeasureInternalTo_PS1_V1 (Measure *in, off_t Nvalues) {
     61Measure_PS1_V1 *MeasureInternalTo_PS1_V1 (Average *ave, Measure *in, off_t Nvalues) {
    6162
    6263  off_t i;
     
    6667
    6768  for (i = 0; i < Nvalues; i++) {
    68     out[i].dR         = in[i].dR;
    69     out[i].dD         = in[i].dD;
     69    int averef = in[i].averef;
     70
     71    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
     72    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    7073    out[i].M          = in[i].M;
    7174    out[i].Mcal       = in[i].Mcal;
     
    140143    out[i].measureOffset = in[i].measureOffset;
    141144    out[i].missingOffset = in[i].missingOffset;
    142     out[i].extendOffset  = in[i].extendOffset;
     145    out[i].refColorBlue  = in[i].refColor;
    143146    out[i].flags         = in[i].flags;   
    144147    out[i].objID         = in[i].objID;
     
    175178    out[i].measureOffset = in[i].measureOffset;
    176179    out[i].missingOffset = in[i].missingOffset;
    177     out[i].extendOffset  = in[i].extendOffset;
     180    out[i].refColor      = in[i].refColorBlue;
    178181    out[i].flags         = in[i].flags;   
    179182    out[i].objID         = in[i].objID;
     
    196199    out[i].M     = in[i].M;     
    197200    out[i].dM    = in[i].dM;     
    198     out[i].Xm    = in[i].Xm;     
     201    out[i].Mchisq= in[i].Mchisq;     
    199202    out[i].Ncode = in[i].Ncode;
    200203    out[i].Nused = in[i].Nused;
    201     out[i].M_20  = in[i].M_20;     
    202     out[i].M_80  = in[i].M_80;     
     204    out[i].Mmin  = in[i].M_20*0.001;     
     205    out[i].Mmax  = in[i].M_80*0.001;     
    203206 }
    204207  return (out);
     
    215218    out[i].M     = in[i].M;     
    216219    out[i].dM    = in[i].dM;     
    217     out[i].Xm    = in[i].Xm;     
     220    out[i].Mchisq= in[i].Mchisq;     
    218221    out[i].Ncode = in[i].Ncode;
    219222    out[i].Nused = in[i].Nused;
    220     out[i].M_20  = in[i].M_20;     
    221     out[i].M_80  = in[i].M_80;     
    222   }
    223   return (out);
    224 }
     223    out[i].M_20  = in[i].Mmin*1000.0;     
     224    out[i].M_80  = in[i].Mmax*1000.0;     
     225  }
     226  return (out);
     227}
     228
     229# define RAW_IMAGE_NAME_LEN 121
    225230
    226231Image *Image_PS1_V1_ToInternal (Image_PS1_V1 *in, off_t Nvalues, off_t Nalloc) {
     
    237242    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    238243
    239     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    240     out[i].name[120] = 0; // force termination
     244    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     245    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     246    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    241247
    242248    out[i].tzero            = in[i].tzero;
     
    300306    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    301307
    302     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    303     out[i].name[120] = 0; // force termination
     308    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     309    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     310    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    304311
    305312    out[i].tzero            = in[i].tzero;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c

    r35162 r37067  
    33/* convert PS1_V2 formats to internal formats */
    44
    5 Measure *Measure_PS1_V2_ToInternal (Measure_PS1_V2 *in, off_t Nvalues) {
     5Measure *Measure_PS1_V2_ToInternal (Average *ave, Measure_PS1_V2 *in, off_t Nvalues) {
    66
    77  off_t i;
     
    1313    dvo_measure_init (&out[i]);
    1414
    15     out[i].dR         = in[i].dR;
    16     out[i].dD         = in[i].dD;
     15    int averef = in[i].averef;
     16    out[i].R          = ave[averef].R - in[i].dR / 3600.0;
     17    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1718    out[i].M          = in[i].M;
    1819    out[i].Mcal       = in[i].Mcal;
     
    5960}
    6061
    61 Measure_PS1_V2 *MeasureInternalTo_PS1_V2 (Measure *in, off_t Nvalues) {
     62Measure_PS1_V2 *MeasureInternalTo_PS1_V2 (Average *ave, Measure *in, off_t Nvalues) {
    6263
    6364  off_t i;
     
    6768
    6869  for (i = 0; i < Nvalues; i++) {
    69     out[i].dR         = in[i].dR;
    70     out[i].dD         = in[i].dD;
     70    int averef = in[i].averef;
     71
     72    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
     73    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    7174    out[i].M          = in[i].M;
    7275    out[i].Mcal       = in[i].Mcal;
     
    145148    out[i].measureOffset = in[i].measureOffset;
    146149    out[i].missingOffset = in[i].missingOffset;
    147     out[i].extendOffset  = in[i].extendOffset;
     150    out[i].refColorBlue  = in[i].refColor;
    148151    out[i].flags         = in[i].flags;   
    149152    out[i].objID         = in[i].objID;
     
    184187    out[i].measureOffset = in[i].measureOffset;
    185188    out[i].missingOffset = in[i].missingOffset;
    186     out[i].extendOffset  = in[i].extendOffset;
     189    out[i].refColor  = in[i].refColorBlue;
    187190    out[i].flags         = in[i].flags;   
    188191    out[i].objID         = in[i].objID;
     
    205208    out[i].M     = in[i].M;     
    206209    out[i].dM    = in[i].dM;     
    207     out[i].Xm    = in[i].Xm;     
     210    out[i].Mchisq= in[i].Mchisq;     
    208211    out[i].flags = in[i].flags;     
    209212    out[i].Ncode = in[i].Ncode;
    210213    out[i].Nused = in[i].Nused;
    211     out[i].M_20  = in[i].M_20;     
    212     out[i].M_80  = in[i].M_80;     
     214    out[i].Mmin  = in[i].M_20*0.001;     
     215    out[i].Mmax  = in[i].M_80*0.001;     
    213216 }
    214217  return (out);
     
    225228    out[i].M     = in[i].M;     
    226229    out[i].dM    = in[i].dM;     
    227     out[i].Xm    = in[i].Xm;     
     230    out[i].Mchisq= in[i].Mchisq;     
    228231    out[i].flags = in[i].flags;     
    229232    out[i].Ncode = in[i].Ncode;
    230233    out[i].Nused = in[i].Nused;
    231     out[i].M_20  = in[i].M_20;     
    232     out[i].M_80  = in[i].M_80;     
    233   }
    234   return (out);
    235 }
     234    out[i].M_20  = in[i].Mmin*1000.0;     
     235    out[i].M_80  = in[i].Mmax*1000.0;     
     236  }
     237  return (out);
     238}
     239
     240# define RAW_IMAGE_NAME_LEN 121
    236241
    237242Image *Image_PS1_V2_ToInternal (Image_PS1_V2 *in, off_t Nvalues, off_t Nalloc) {
     
    248253    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    249254
    250     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    251     out[i].name[120] = 0; // force termination
     255    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     256    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     257    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    252258
    253259    out[i].tzero            = in[i].tzero;
     
    269275    out[i].DECo             = in[i].DECo;
    270276    out[i].Radius           = in[i].Radius;
     277    out[i].refColorBlue             = in[i].refColor;
    271278
    272279    out[i].detection_limit  = in[i].detection_limit;
     
    310317    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    311318
    312     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    313     out[i].name[120] = 0; // force termination
     319    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     320    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     321    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    314322
    315323    out[i].tzero            = in[i].tzero;
     
    331339    out[i].DECo             = in[i].DECo;
    332340    out[i].Radius           = in[i].Radius;
     341    out[i].refColor         = in[i].refColorBlue;
    333342
    334343    out[i].detection_limit  = in[i].detection_limit;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c

    r35162 r37067  
    33/* convert PS1_V3 formats to internal formats */
    44
    5 Measure *Measure_PS1_V3_ToInternal (Measure_PS1_V3 *in, off_t Nvalues) {
     5Measure *Measure_PS1_V3_ToInternal (Average *ave, Measure_PS1_V3 *in, off_t Nvalues) {
    66
    77  off_t i;
     
    1313    dvo_measure_init (&out[i]);
    1414
    15     out[i].dR         = in[i].dR;
    16     out[i].dD         = in[i].dD;
     15    int averef = in[i].averef;
     16    out[i].R          = ave[averef].R - in[i].dR / 3600.0;
     17    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1718    out[i].M          = in[i].M;
    1819    out[i].Mcal       = in[i].Mcal;
     
    5960}
    6061
    61 Measure_PS1_V3 *MeasureInternalTo_PS1_V3 (Measure *in, off_t Nvalues) {
     62Measure_PS1_V3 *MeasureInternalTo_PS1_V3 (Average *ave, Measure *in, off_t Nvalues) {
    6263
    6364  off_t i;
     
    6768
    6869  for (i = 0; i < Nvalues; i++) {
    69     out[i].dR         = in[i].dR;
    70     out[i].dD         = in[i].dD;
     70    int averef = in[i].averef;
     71
     72    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
     73    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    7174    out[i].M          = in[i].M;
    7275    out[i].Mcal       = in[i].Mcal;
     
    145148    out[i].measureOffset = in[i].measureOffset;
    146149    out[i].missingOffset = in[i].missingOffset;
    147     out[i].extendOffset  = in[i].extendOffset;
     150    out[i].refColorBlue  = in[i].refColor;
    148151    out[i].flags         = in[i].flags;   
    149152    out[i].photFlagsUpper = in[i].photFlagsUpper;   
     
    186189    out[i].measureOffset = in[i].measureOffset;
    187190    out[i].missingOffset = in[i].missingOffset;
    188     out[i].extendOffset  = in[i].extendOffset;
     191    out[i].refColor      = in[i].refColorBlue;
    189192    out[i].flags         = in[i].flags;   
    190193    out[i].photFlagsUpper = in[i].photFlagsUpper;   
     
    210213    out[i].Map         = in[i].Map;     
    211214    out[i].dM          = in[i].dM;     
    212     out[i].Xm          = in[i].Xm;     
     215    out[i].Mchisq      = in[i].Mchisq;     
    213216    out[i].flags       = in[i].flags;     
    214217    out[i].Ncode       = in[i].Ncode;
    215218    out[i].Nused       = in[i].Nused;
    216     out[i].M_20        = in[i].M_20;     
    217     out[i].M_80        = in[i].M_80;     
     219    out[i].Mmin        = in[i].M_20*0.001;     
     220    out[i].Mmax        = in[i].M_80*0.001;     
    218221    out[i].Mstdev      = in[i].Mstdev;     
    219222    out[i].ubercalDist = in[i].ubercalDist;     
     
    233236    out[i].Map         = in[i].Map;     
    234237    out[i].dM          = in[i].dM;     
    235     out[i].Xm          = in[i].Xm;     
     238    out[i].Mchisq      = in[i].Mchisq;     
    236239    out[i].flags       = in[i].flags;     
    237240    out[i].Ncode       = in[i].Ncode;
    238241    out[i].Nused       = in[i].Nused;
    239     out[i].M_20        = in[i].M_20;     
    240     out[i].M_80        = in[i].M_80;     
     242    out[i].M_20        = in[i].Mmin*1000.0;     
     243    out[i].M_80        = in[i].Mmax*1000.0;     
    241244    out[i].Mstdev      = in[i].Mstdev;     
    242245    out[i].ubercalDist = in[i].ubercalDist;     
     
    244247  return (out);
    245248}
     249
     250# define RAW_IMAGE_NAME_LEN 121
    246251
    247252Image *Image_PS1_V3_ToInternal (Image_PS1_V3 *in, off_t Nvalues, off_t Nalloc) {
     
    258263    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    259264
    260     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    261     out[i].name[120] = 0; // force termination
     265    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     266    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     267    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    262268
    263269    out[i].tzero            = in[i].tzero;
     
    279285    out[i].DECo             = in[i].DECo;
    280286    out[i].Radius           = in[i].Radius;
     287    out[i].refColorBlue     = in[i].refColor;
    281288
    282289    out[i].detection_limit  = in[i].detection_limit;
     
    320327    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    321328
    322     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    323     out[i].name[120] = 0; // force termination
     329    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     330    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     331    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    324332
    325333    out[i].tzero            = in[i].tzero;
     
    341349    out[i].DECo             = in[i].DECo;
    342350    out[i].Radius           = in[i].Radius;
     351    out[i].refColor         = in[i].refColorBlue;
    343352
    344353    out[i].detection_limit  = in[i].detection_limit;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c

    r35162 r37067  
    33/* convert PS1_V4 formats to internal formats */
    44
    5 Measure *Measure_PS1_V4_ToInternal (Measure_PS1_V4 *in, off_t Nvalues) {
     5Measure *Measure_PS1_V4_ToInternal (Average *ave, Measure_PS1_V4 *in, off_t Nvalues) {
    66
    77  off_t i;
     
    1313    dvo_measure_init (&out[i]);
    1414
    15     out[i].dR         = in[i].dR;
    16     out[i].dD         = in[i].dD;
     15    int averef = in[i].averef;
     16    out[i].R          = ave[averef].R - in[i].dR / 3600.0;
     17    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1718    out[i].M          = in[i].M;
    1819    out[i].Mcal       = in[i].Mcal;
     
    6869}
    6970
    70 Measure_PS1_V4 *MeasureInternalTo_PS1_V4 (Measure *in, off_t Nvalues) {
     71Measure_PS1_V4 *MeasureInternalTo_PS1_V4 (Average *ave, Measure *in, off_t Nvalues) {
    7172
    7273  off_t i;
     
    7677
    7778  for (i = 0; i < Nvalues; i++) {
    78     out[i].dR         = in[i].dR;
    79     out[i].dD         = in[i].dD;
     79    int averef = in[i].averef;
     80
     81    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
     82    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    8083    out[i].M          = in[i].M;
    8184    out[i].Mcal       = in[i].Mcal;
     
    166169    out[i].measureOffset = in[i].measureOffset;
    167170    out[i].missingOffset = in[i].missingOffset;
    168     out[i].extendOffset  = in[i].extendOffset;
     171    out[i].refColorBlue  = in[i].refColor;
    169172    out[i].flags         = in[i].flags;   
    170173    out[i].photFlagsUpper = in[i].photFlagsUpper;   
     
    210213    out[i].measureOffset = in[i].measureOffset;
    211214    out[i].missingOffset = in[i].missingOffset;
    212     out[i].extendOffset  = in[i].extendOffset;
     215    out[i].refColor      = in[i].refColorBlue;
    213216    out[i].flags         = in[i].flags;   
    214217    out[i].photFlagsUpper = in[i].photFlagsUpper;   
     
    236239    out[i].dMkron        = in[i].dMkron;     
    237240    out[i].dM            = in[i].dM;     
    238     out[i].Xm            = in[i].Xm;     
    239     out[i].FluxPSF       = in[i].FluxPSF;
    240     out[i].dFluxPSF      = in[i].dFluxPSF;
    241     out[i].FluxKron      = in[i].FluxKron;
    242     out[i].dFluxKron     = in[i].dFluxKron;
     241    out[i].Mchisq        = in[i].Mchisq;     
     242    out[i].FpsfStk       = in[i].FluxPSF;
     243    out[i].dFpsfStk      = in[i].dFluxPSF;
     244    out[i].FkronStk      = in[i].FluxKron;
     245    out[i].dFkronStk     = in[i].dFluxKron;
    243246    out[i].flags         = in[i].flags;     
    244247    out[i].Ncode         = in[i].Ncode;
    245248    out[i].Nused         = in[i].Nused;
    246     out[i].M_20          = in[i].M_20;     
    247     out[i].M_80          = in[i].M_80;     
     249    out[i].Mmin          = in[i].M_20*0.001;     
     250    out[i].Mmax          = in[i].M_80*0.001;     
    248251    out[i].Mstdev        = in[i].Mstdev;     
    249252    out[i].ubercalDist   = in[i].ubercalDist;     
     
    266269    out[i].dMkron        = in[i].dMkron;     
    267270    out[i].dM            = in[i].dM;     
    268     out[i].Xm            = in[i].Xm;     
    269     out[i].FluxPSF       = in[i].FluxPSF;
    270     out[i].dFluxPSF      = in[i].dFluxPSF;
    271     out[i].FluxKron      = in[i].FluxKron;
    272     out[i].dFluxKron     = in[i].dFluxKron;
     271    out[i].Mchisq        = in[i].Mchisq;
     272    out[i].FluxPSF       = in[i].FpsfStk;
     273    out[i].dFluxPSF      = in[i].dFpsfStk;
     274    out[i].FluxKron      = in[i].FkronStk;
     275    out[i].dFluxKron     = in[i].dFkronStk;
    273276    out[i].flags         = in[i].flags;     
    274277    out[i].Ncode         = in[i].Ncode;
    275278    out[i].Nused         = in[i].Nused;
    276     out[i].M_20          = in[i].M_20;     
    277     out[i].M_80          = in[i].M_80;     
     279    out[i].M_20          = in[i].Mmin*1000.0;     
     280    out[i].M_80          = in[i].Mmax*1000.0;     
    278281    out[i].Mstdev        = in[i].Mstdev;     
    279282    out[i].ubercalDist   = in[i].ubercalDist;     
     
    282285  return (out);
    283286}
     287
     288# define RAW_IMAGE_NAME_LEN 121
    284289
    285290Image *Image_PS1_V4_ToInternal (Image_PS1_V4 *in, off_t Nvalues, off_t Nalloc) {
     
    296301    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    297302
    298     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    299     out[i].name[120] = 0; // force termination
     303    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     304    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     305    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    300306
    301307    out[i].tzero            = in[i].tzero;
     
    317323    out[i].DECo             = in[i].DECo;
    318324    out[i].Radius           = in[i].Radius;
     325    out[i].refColorBlue     = in[i].refColor;
    319326
    320327    out[i].detection_limit  = in[i].detection_limit;
     
    358365    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    359366
    360     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    361     out[i].name[120] = 0; // force termination
     367    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     368    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     369    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    362370
    363371    out[i].tzero            = in[i].tzero;
     
    379387    out[i].DECo             = in[i].DECo;
    380388    out[i].Radius           = in[i].Radius;
     389    out[i].refColor         = in[i].refColorBlue;
    381390
    382391    out[i].detection_limit  = in[i].detection_limit;
     
    481490  return (out);
    482491}
     492
     493/*** there are some mini dvodbs with the wrong PS1_V4 format (missing Xoff,Yoff / Xfix,Yfix) ************/
     494
     495Measure *Measure_PS1_V4alt_ToInternal (Average *ave, Measure_PS1_V4alt *in, off_t Nvalues) {
     496
     497  off_t i;
     498  Measure *out;
     499
     500  ALLOCATE_ZERO (out, Measure, Nvalues);
     501
     502  for (i = 0; i < Nvalues; i++) {
     503    dvo_measure_init (&out[i]);
     504
     505    int averef = in[i].averef;
     506    out[i].R          = ave[averef].R - in[i].dR / 3600.0;
     507    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
     508    out[i].M          = in[i].M;
     509    out[i].Mcal       = in[i].Mcal;
     510    out[i].Map        = in[i].Map;
     511    out[i].Mkron      = in[i].Mkron;
     512    out[i].dMkron     = in[i].dMkron;
     513    out[i].dM         = in[i].dM;
     514    out[i].dMcal      = in[i].dMcal;
     515    out[i].dt         = in[i].dt;
     516    out[i].FluxPSF    = in[i].FluxPSF;
     517    out[i].dFluxPSF   = in[i].dFluxPSF;
     518    out[i].FluxKron   = in[i].FluxKron;
     519    out[i].dFluxKron  = in[i].dFluxKron;
     520    out[i].airmass    = in[i].airmass;
     521    out[i].az         = in[i].az;
     522    out[i].Xccd       = in[i].Xccd;
     523    out[i].Yccd       = in[i].Yccd;
     524    out[i].Xfix       = in[i].Xccd;
     525    out[i].Yfix       = in[i].Yccd;
     526    out[i].Sky        = in[i].Sky;
     527    out[i].dSky       = in[i].dSky;
     528    out[i].t          = in[i].t;
     529    out[i].t_msec     = in[i].t_msec;
     530    out[i].averef     = in[i].averef;
     531    out[i].detID      = in[i].detID;
     532    out[i].imageID    = in[i].imageID;
     533    out[i].objID      = in[i].objID;
     534    out[i].catID      = in[i].catID;
     535    out[i].extID      = in[i].extID;
     536    out[i].psfQF      = in[i].psfQF;
     537    out[i].psfQFperf  = in[i].psfQFperf;
     538    out[i].psfChisq   = in[i].psfChisq;
     539    out[i].psfNdof    = in[i].psfNdof;
     540    out[i].psfNpix    = in[i].psfNpix;
     541    out[i].crNsigma   = in[i].crNsigma;
     542    out[i].extNsigma  = in[i].extNsigma;
     543    out[i].FWx        = in[i].FWx;
     544    out[i].FWy        = in[i].FWy;
     545    out[i].theta      = in[i].theta;
     546    out[i].Mxx        = in[i].Mxx;
     547    out[i].Mxy        = in[i].Mxy;
     548    out[i].Myy        = in[i].Myy;
     549    out[i].dXccd      = in[i].dXccd;
     550    out[i].dYccd      = in[i].dYccd;
     551    out[i].dRsys      = in[i].dRsys;
     552    out[i].posangle   = in[i].posangle;
     553    out[i].pltscale   = in[i].pltscale;
     554    out[i].photcode   = in[i].photcode;
     555    out[i].dbFlags    = in[i].dbFlags;
     556    out[i].photFlags  = in[i].photFlags;
     557  }
     558  return (out);
     559}
     560
     561// XXX note that there are 2 bad versions of PS1_V4 : the other one does have have PSF_QF_PERFECT, but has PAD instead
     562int gfits_convert_Measure_PS1_V4alt (Measure_PS1_V4alt *data, off_t size, off_t nitems) {
     563
     564  off_t i;
     565  unsigned char *byte, tmp;
     566
     567  if (size != 176) {
     568    fprintf (stderr, "WARNING: mismatch in data types Measure_PS1_V4alt: "OFF_T_FMT" vs %d\n",  size,  176);
     569    return (FALSE);
     570  }
     571
     572  /* provide initial values to avoid compiler warnings for non-BYTE_SWAP arch */
     573  i = tmp = 0;
     574  byte = NULL;
     575
     576# ifdef BYTE_SWAP
     577  byte = (unsigned char *) data;
     578  for (i = 0; i < nitems; i++, byte += 176) {
     579    /** BYTE SWAP **/
     580    SWAP_WORD (0); // D_RA
     581    SWAP_WORD (4); // D_DEC
     582    SWAP_WORD (8); // MAG
     583    SWAP_WORD (12); // M_CAL
     584    SWAP_WORD (16); // M_APER
     585    SWAP_WORD (20); // M_KRON
     586    SWAP_WORD (24); // M_KRON_ERR
     587    SWAP_WORD (28); // MAG_ERR
     588    SWAP_WORD (32); // MAG_CAL_ERR
     589    SWAP_WORD (36); // M_TIME
     590    SWAP_WORD (40); // FLUX_PSF
     591    SWAP_WORD (44); // FLUX_PSF_ERR
     592    SWAP_WORD (48); // FLUX_KRON
     593    SWAP_WORD (52); // FLUX_KRON_ERR
     594    SWAP_WORD (56); // AIRMASS
     595    SWAP_WORD (60); // AZ
     596    SWAP_WORD (64); // X_CCD
     597    SWAP_WORD (68); // Y_CCD
     598    SWAP_WORD (72); // SKY_FLUX   
     599    SWAP_WORD (76); // SKY_FLUX_ERR
     600    SWAP_WORD (80); // TIME
     601    SWAP_WORD (84); // AVE_REF
     602    SWAP_WORD (88); // DET_ID
     603    SWAP_WORD (92); // IMAGE_ID
     604    SWAP_WORD (96); // OBJ_ID
     605    SWAP_WORD (100); // CAT_ID
     606    SWAP_DBLE (104); // EXT_ID
     607    SWAP_WORD (112); // PSF_QF       
     608    SWAP_WORD (116); // PSF_QF_PERFECT
     609    SWAP_WORD (120); // PSF_CHISQ     
     610    SWAP_WORD (124); // PSF_NDOF     
     611    SWAP_WORD (128); // PSF_NPIX     
     612    SWAP_WORD (132); // CR_NSIGMA     
     613    SWAP_WORD (136); // EXT_NSIGMA   
     614    SWAP_BYTE (140); // FWHM_MAJOR
     615    SWAP_BYTE (142); // FWHM_MINOR
     616    SWAP_BYTE (144); // PSF_THETA 
     617    SWAP_BYTE (146); // MXX       
     618    SWAP_BYTE (148); // MXY       
     619    SWAP_BYTE (150); // MYY       
     620    SWAP_BYTE (152); // TIME_MSEC 
     621    SWAP_BYTE (154); // PHOTCODE   
     622    SWAP_BYTE (156); // X_CCD_ERR 
     623    SWAP_BYTE (158); // Y_CCD_ERR 
     624    SWAP_BYTE (160); // POS_SYS_ERR
     625    SWAP_BYTE (162); // POSANGLE   
     626    SWAP_WORD (164); // PLTSCALE 
     627    SWAP_WORD (168); // DB_FLAGS 
     628    SWAP_WORD (172); // PHOT_FLAGS
     629  }
     630# endif 
     631
     632  return (TRUE);
     633}
     634
     635/*** add test of EXTNAME and header-defined columns? ***/
     636/* return internal structure representation */
     637Measure_PS1_V4alt *gfits_table_get_Measure_PS1_V4alt (FTable *ftable, off_t *Ndata, char *swapped) {
     638
     639  int Ncols;
     640  Measure_PS1_V4alt *data;
     641
     642  Ncols = ftable[0].header[0].Naxis[0];
     643  if (Ncols != 176) {
     644    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, 176);
     645    return NULL;
     646  }
     647
     648  *Ndata = ftable[0].header[0].Naxis[1];
     649  data = (Measure_PS1_V4alt *) ftable[0].buffer;
     650  if ((swapped == NULL) || (*swapped == FALSE)) {
     651    if (!gfits_convert_Measure_PS1_V4alt (data, sizeof (Measure_PS1_V4alt), *Ndata)) {
     652      return NULL;
     653    }
     654    gfits_table_scale_data (ftable);
     655    if (swapped != NULL) *swapped = TRUE;
     656  }
     657  return (data);
     658}
     659
     660// 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
     661Average *Average_PS1_V4alt_ToInternal (Average_PS1_V4alt *in, off_t Nvalues) {
     662
     663  off_t i;
     664  Average *out;
     665
     666  ALLOCATE_ZERO (out, Average, Nvalues);
     667
     668  for (i = 0; i < Nvalues; i++) {
     669    dvo_average_init (&out[i]);
     670
     671    out[i].R             = in[i].R;     
     672    out[i].D             = in[i].D;     
     673    out[i].dR            = in[i].dR;
     674    out[i].dD            = in[i].dD;
     675    out[i].uR            = in[i].uR;
     676    out[i].uD            = in[i].uD;
     677    out[i].duR           = in[i].duR;
     678    out[i].duD           = in[i].duD;
     679    out[i].P             = in[i].P;
     680    out[i].dP            = in[i].dP;
     681    out[i].ChiSqAve      = in[i].ChiSqAve;     
     682    out[i].ChiSqPM       = in[i].ChiSqPM;     
     683    out[i].ChiSqPar      = in[i].ChiSqPar;     
     684    out[i].Tmean         = in[i].Tmean;     
     685    out[i].Trange        = in[i].Trange;     
     686    out[i].Npos          = in[i].Npos;     
     687    out[i].Nmeasure      = in[i].Nmeasure;     
     688    out[i].Nmissing      = in[i].Nmissing;     
     689    out[i].Nextend       = in[i].Nextend;     
     690    out[i].measureOffset = in[i].measureOffset;
     691    out[i].missingOffset = in[i].missingOffset;
     692    out[i].refColorBlue  = in[i].refColor;
     693    out[i].flags         = in[i].flags;   
     694    out[i].photFlagsUpper = in[i].photFlagsUpper;   
     695    out[i].photFlagsLower = in[i].photFlagsLower;   
     696    out[i].objID         = in[i].objID;
     697    out[i].catID         = in[i].catID;
     698    out[i].extID         = in[i].extID;
     699  }
     700  return (out);
     701}
     702
     703/******/
     704
     705int gfits_convert_Average_PS1_V4alt (Average_PS1_V4alt *data, off_t size, off_t nitems) {
     706
     707  off_t i;
     708  unsigned char *byte, tmp;
     709
     710  if (size != 120) {
     711    fprintf (stderr, "WARNING: mismatch in data types Average_PS1_V4alt: "OFF_T_FMT" vs %d\n",  size,  120);
     712    return (FALSE);
     713  }
     714
     715  /* provide initial values to avoid compiler warnings for non-BYTE_SWAP arch */
     716  i = tmp = 0;
     717  byte = NULL;
     718
     719# ifdef BYTE_SWAP
     720  byte = (unsigned char *) data;
     721  for (i = 0; i < nitems; i++, byte += 120) {
     722    /** BYTE SWAP **/
     723    SWAP_DBLE (0); // RA
     724    SWAP_DBLE (8); // DEC
     725    SWAP_WORD (16); // RA_ERR
     726    SWAP_WORD (20); // DEC_ERR
     727    SWAP_WORD (24); // U_RA
     728    SWAP_WORD (28); // U_DEC
     729    SWAP_WORD (32); // V_RA_ERR
     730    SWAP_WORD (36); // V_DEC_ERR
     731    SWAP_WORD (40); // PAR
     732    SWAP_WORD (44); // PAR_ERR
     733    SWAP_WORD (48); // CHISQ_POS
     734    SWAP_WORD (52); // CHISQ_PM
     735    SWAP_WORD (56); // CHISQ_PAP
     736    SWAP_WORD (60); // MEAN_EPOCH
     737    SWAP_WORD (64); // TIME_RANGE
     738    SWAP_WORD (68); // SIGMA
     739    SWAP_BYTE (72); // NUMBER_POS
     740    SWAP_BYTE (74); // NMEASURE
     741    SWAP_BYTE (76); // NMISSING
     742    SWAP_BYTE (78); // NEXTEND
     743    SWAP_WORD (80); // OFF_MEASURE
     744    SWAP_WORD (84); // OFF_MISSING
     745    SWAP_WORD (88); // OFF_EXTEND
     746    SWAP_WORD (92); // FLAGS
     747    SWAP_WORD (96); // PHOTFLAGS_U
     748    SWAP_WORD (100); // PHOTFLAGS_L
     749    SWAP_WORD (104); // OBJ_ID
     750    SWAP_WORD (108); // CAT_ID
     751    SWAP_DBLE (112); // EXT_ID
     752  }
     753# endif 
     754
     755  return (TRUE);
     756}
     757
     758/*** add test of EXTNAME and header-defined columns? ***/
     759/* return internal structure representation */
     760Average_PS1_V4alt *gfits_table_get_Average_PS1_V4alt (FTable *ftable, off_t *Ndata, char *swapped) {
     761
     762  int Ncols;
     763  Average_PS1_V4alt *data;
     764
     765  Ncols = ftable[0].header[0].Naxis[0];
     766  if (Ncols != 120) {
     767    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, 120);
     768    return NULL;
     769  }
     770
     771  *Ndata = ftable[0].header[0].Naxis[1];
     772  data = (Average_PS1_V4alt *) ftable[0].buffer;
     773  if ((swapped == NULL) || (*swapped == FALSE)) {
     774    if (!gfits_convert_Average_PS1_V4alt (data, sizeof (Average_PS1_V4alt), *Ndata)) {
     775      return NULL;
     776    }
     777    gfits_table_scale_data (ftable);
     778    if (swapped != NULL) *swapped = TRUE;
     779  }
     780  return (data);
     781}
     782
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_convert_elixir.c

    r35162 r37067  
    22
    33/* convert elixir-format measures to internal measures */
    4 Measure *Measure_Elixir_ToInternal (Measure_Elixir *in, off_t Nvalues) {
     4Measure *Measure_Elixir_ToInternal (Average *ave, Measure_Elixir *in, off_t Nvalues) {
    55
    66  off_t i;
     
    1515    out[i].averef   = in[i].averef;
    1616
     17    // changed for PS1_V5
     18    int averef = out[i].averef;
     19    out[i].R          = (in[i].dR == NAN_S_SHORT) ? NAN : ave[averef].R - 0.01 * in[i].dR / 3600.0;
     20    out[i].D          = (in[i].dD == NAN_S_SHORT) ? NAN : ave[averef].D - 0.01 * in[i].dD / 3600.0;
     21
    1722    // changed for PANSTARRS_DEV_0
    18     out[i].dR       = (in[i].dR      == NAN_S_SHORT) ? NAN : in[i].dR     * 0.01;
    19     out[i].dD       = (in[i].dD      == NAN_S_SHORT) ? NAN : in[i].dD     * 0.01;
    2023    out[i].M        = (in[i].M       == NAN_S_SHORT) ? NAN : in[i].M      * 0.001;
    2124    out[i].dM       = (in[i].dM      == NAN_U_CHAR)  ? NAN : in[i].dM     * 0.001;
     
    4750
    4851/* convert internal measures to elixir-format measures */
    49 Measure_Elixir *MeasureInternalTo_Elixir (Measure *in, off_t Nvalues) {
     52Measure_Elixir *MeasureInternalTo_Elixir (Average *ave, Measure *in, off_t Nvalues) {
    5053
    5154  off_t i;
     
    5962    out[i].averef  = in[i].averef;
    6063
     64    // changed for PS1_V5
     65    int averef = in[i].averef;
     66    int isBad = isnan(in[i].R) || isnan(in[i].D);
     67    out[i].dR     = isBad ? NAN_S_SHORT : 100.0*3600.0*(ave[averef].R - in[i].R);
     68    out[i].dD     = isBad ? NAN_S_SHORT : 100.0*3600.0*(ave[averef].D - in[i].D);
     69
    6170    // changed for PANSTARRS_DEV_0
    62     out[i].dR       = isnan(in[i].dR     ) ? NAN_S_SHORT : in[i].dR      *  100.0;
    63     out[i].dD       = isnan(in[i].dD     ) ? NAN_S_SHORT : in[i].dD      *  100.0;
    6471    out[i].M        = isnan(in[i].M      ) ? NAN_S_SHORT : in[i].M       * 1000.0;
    6572    out[i].dM       = isnan(in[i].dM     ) ? NAN_U_CHAR  : in[i].dM      * 1000.0;
     
    104111    primary[0][i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;     
    105112    primary[0][i].dM    = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM * 0.001;     
    106     primary[0][i].Xm    = in[i].Xm;     
     113    primary[0][i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    107114
    108115    // added for PANSTARRS_DEV_0
     
    137144    out[i].M       = isnan(primary[i].M)  ? NAN_S_SHORT : primary[i].M   * 1000.0;
    138145    out[i].dM      = isnan(primary[i].dM) ? NAN_S_SHORT : primary[i].dM  * 1000.0;
    139     out[i].Xm      = primary[i].Xm;     
     146    out[i].Xm      = 100.0*log10(primary[i].Mchisq);     
    140147
    141148    // changed or added for PS1_DEV_2
     
    162169    dvo_secfilt_init (&out[i]);
    163170
    164     out[i].Xm    = in[i].Xm;     
     171    out[i].Mchisq = pow (10.0, 0.01*in[i].Xm);     
    165172
    166173    // added or changed for PANSTARRS_DEV_0
     
    180187
    181188  for (i = 0; i < Nvalues; i++) {
    182     out[i].Xm    = in[i].Xm;     
     189    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
    183190
    184191    // added or changed for PANSTARRS_DEV_0
     
    188195  return (out);
    189196}
     197
     198# define RAW_IMAGE_NAME_LEN 32
    190199
    191200/* convert elixir-format images to internal images */
     
    203212    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    204213
    205     strncpy (out[i].name, in[i].name, 31); // in[32], out[128]
    206     out[i].name[31] = 0; // force termination
     214    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     215    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     216    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    207217
    208218    out[i].tzero            = in[i].tzero;
     
    272282    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    273283
    274     strncpy (out[i].name, in[i].name, 31); // out[32], in[128]
    275     out[i].name[31] = 0; // force termination
     284    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     285    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     286    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    276287
    277288    out[i].tzero            = in[i].tzero;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_convert_loneos.c

    r35162 r37067  
    22
    33/* convert loneos-format measures to internal measures */
    4 Measure *Measure_Loneos_ToInternal (Measure_Loneos *in, off_t Nvalues) {
     4Measure *Measure_Loneos_ToInternal (Average *ave, Measure_Loneos *in, off_t Nvalues) {
    55
    66  off_t i;
     
    1818    out[i].t         = in[i].t;
    1919
     20    // changed for PS1_V5
     21    int averef = out[i].averef;
     22    out[i].R          = (in[i].dR == NAN_S_SHORT) ? NAN : ave[averef].R - 0.01 * in[i].dR / 3600.0;
     23    out[i].D          = (in[i].dD == NAN_S_SHORT) ? NAN : ave[averef].D - 0.01 * in[i].dD / 3600.0;
     24
    2025    // changed for PANSTARRS_DEV_0
    21     out[i].dR       = (in[i].dR      == NAN_S_SHORT) ? NAN : in[i].dR     * 0.01;
    22     out[i].dD       = (in[i].dD      == NAN_S_SHORT) ? NAN : in[i].dD     * 0.01;
    2326    out[i].M        = (in[i].M       == NAN_S_SHORT) ? NAN : in[i].M      * 0.001;
    2427    out[i].dM       = (in[i].dM      == NAN_U_CHAR)  ? NAN : in[i].dM     * 0.001;
     
    4043
    4144/* convert internal measures to loneos-format measures */
    42 Measure_Loneos *MeasureInternalTo_Loneos (Measure *in, off_t Nvalues) {
     45Measure_Loneos *MeasureInternalTo_Loneos (Average *ave, Measure *in, off_t Nvalues) {
    4346
    4447  off_t i;
     
    4851
    4952  for (i = 0; i < Nvalues; i++) {
    50 
    51     // changed for PANSTARRS_DEV_0
    52     out[i].dR     = isnan(in[i].dR     ) ? NAN_S_SHORT : in[i].dR      *  100.0;
    53     out[i].dD     = isnan(in[i].dD     ) ? NAN_S_SHORT : in[i].dD      *  100.0;
     53    // changed for PS1_V5
     54    int averef = in[i].averef;
     55    int isBad = isnan(in[i].R) || isnan(in[i].D);
     56    out[i].dR     = isBad ? NAN_S_SHORT : 100.0*3600.0*(ave[averef].R - in[i].R);
     57    out[i].dD     = isBad ? NAN_S_SHORT : 100.0*3600.0*(ave[averef].D - in[i].D);
     58
    5459    out[i].M      = isnan(in[i].M      ) ? NAN_S_SHORT : in[i].M       * 1000.0;
    5560    out[i].dM     = isnan(in[i].dM     ) ? NAN_U_CHAR  : in[i].dM      * 1000.0;
     
    8590    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
    8691    primary[0][i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;     
    87     primary[0][i].Xm    = in[i].Xm;     
     92    primary[0][i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    8893
    8994    // added for PANSTARRS_DEV_0
     
    119124    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
    120125    out[i].M       = isnan(primary[i].M)  ? NAN_S_SHORT : primary[i].M   * 1000.0;
    121     out[i].Xm      = primary[i].Xm;     
     126    out[i].Xm      = 100.0*log10(primary[i].Mchisq);     
    122127
    123128    // changed or added for PS1_DEV_2
     
    144149    dvo_secfilt_init (&out[i]);
    145150
    146     out[i].Xm    = in[i].Xm;      
     151    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    147152
    148153    // added or changed for PANSTARRS_DEV_0
     
    161166
    162167  for (i = 0; i < Nvalues; i++) {
    163     out[i].Xm   = in[i].Xm;     
     168    out[i].Xm   = 100.0*log10(in[i].Mchisq);     
    164169
    165170    // added or changed for PANSTARRS_DEV_0
     
    168173  return (out);
    169174}
     175
     176# define RAW_IMAGE_NAME_LEN 32
    170177
    171178/* convert loneos-format images to internal images */
     
    183190    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    184191
    185     strncpy (out[i].name, in[i].name, 31); // in[32], out[128]
    186     out[i].name[31] = 0; // force termination
     192    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     193    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     194    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    187195
    188196    out[i].tzero            = in[i].tzero;
     
    253261    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    254262
    255     strncpy (out[i].name, in[i].name, 31); // out[32], in[128]
    256     out[i].name[31] = 0; // force termination
     263    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     264    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     265    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    257266
    258267    out[i].tzero            = in[i].tzero;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c

    r35162 r37067  
    22
    33/* convert panstarrs-format measures to internal measures */
    4 Measure *Measure_Panstarrs_DEV_0_ToInternal (Measure_Panstarrs_DEV_0 *in, off_t Nvalues) {
     4Measure *Measure_Panstarrs_DEV_0_ToInternal (Average *ave, Measure_Panstarrs_DEV_0 *in, off_t Nvalues) {
    55
    66  off_t i;
     
    1111  for (i = 0; i < Nvalues; i++) {
    1212    dvo_measure_init (&out[i]);
    13     out[i].dR         = in[i].dR;
    14     out[i].dD         = in[i].dD;
     13
     14    int averef = in[i].averef;
     15    out[i].R          = ave[averef].R - in[i].dR / 3600.0;
     16    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1517    out[i].M          = in[i].M;
    1618    out[i].dM         = in[i].dM;
     
    5254
    5355/* convert internal measures to panstarrs-format measures */
    54 Measure_Panstarrs_DEV_0 *MeasureInternalTo_Panstarrs_DEV_0 (Measure *in, off_t Nvalues) {
     56Measure_Panstarrs_DEV_0 *MeasureInternalTo_Panstarrs_DEV_0 (Average *ave, Measure *in, off_t Nvalues) {
    5557
    5658  off_t i;
     
    6062
    6163  for (i = 0; i < Nvalues; i++) {
    62     out[i].dR         = in[i].dR;
    63     out[i].dD         = in[i].dD;
     64    int averef = in[i].averef;
     65
     66    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
     67    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    6468    out[i].M          = in[i].M;
    6569    out[i].dM         = in[i].dM;
     
    184188    out[i].M     = in[i].M;     
    185189    out[i].dM    = in[i].dM;     
    186     out[i].Xm    = in[i].Xm;     
     190    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    187191    out[i].Ncode = in[i].Ncode;
    188192    out[i].Nused = in[i].Nused;
     
    202206    out[i].M     = in[i].M;     
    203207    out[i].dM    = in[i].dM;     
    204     out[i].Xm    = in[i].Xm;     
     208    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
    205209    out[i].Ncode = in[i].Ncode;
    206210    out[i].Nused = in[i].Nused;
     
    208212  return (out);
    209213}
     214
     215# define RAW_IMAGE_NAME_LEN 32
    210216
    211217/* convert panstarrs-format images to internal images */
     
    223229    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    224230
    225     strncpy (out[i].name, in[i].name, 31); // out[128], in[32]
    226     out[i].name[31] = 0; // force termination
     231    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     232    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     233    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    227234
    228235    out[i].tzero            = in[i].tzero;
     
    292299    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    293300
    294     strncpy (out[i].name, in[i].name, 31); // out[32], in[128]
    295     out[i].name[31] = 0; // force termination
     301    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     302    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     303    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    296304
    297305    out[i].tzero            = in[i].tzero;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c

    r35162 r37067  
    22
    33/* convert panstarrs-format measures to internal measures */
    4 Measure *Measure_Panstarrs_DEV_1_ToInternal (Measure_Panstarrs_DEV_1 *in, off_t Nvalues) {
     4Measure *Measure_Panstarrs_DEV_1_ToInternal (Average *ave, Measure_Panstarrs_DEV_1 *in, off_t Nvalues) {
    55
    66  off_t i;
     
    1111  for (i = 0; i < Nvalues; i++) {
    1212    dvo_measure_init (&out[i]);
    13     out[i].dR         = in[i].dR;
    14     out[i].dD         = in[i].dD;
     13
     14    int averef = in[i].averef;
     15    out[i].R          = ave[averef].R - in[i].dR / 3600.0;
     16    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1517    out[i].M          = in[i].M;
    1618    out[i].dM         = in[i].dM;
     
    5254
    5355/* convert internal measures to panstarrs-format measures */
    54 Measure_Panstarrs_DEV_1 *MeasureInternalTo_Panstarrs_DEV_1 (Measure *in, off_t Nvalues) {
     56Measure_Panstarrs_DEV_1 *MeasureInternalTo_Panstarrs_DEV_1 (Average *ave, Measure *in, off_t Nvalues) {
    5557
    5658  off_t i;
     
    6062
    6163  for (i = 0; i < Nvalues; i++) {
    62     out[i].dR         = in[i].dR;
    63     out[i].dD         = in[i].dD;
     64    int averef = in[i].averef;
     65
     66    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
     67    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    6468    out[i].M          = in[i].M;
    6569    out[i].dM         = in[i].dM;
     
    184188    out[i].M     = in[i].M;     
    185189    out[i].dM    = in[i].dM;     
    186     out[i].Xm    = in[i].Xm;     
     190    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    187191    out[i].Ncode = in[i].Ncode;
    188192    out[i].Nused = in[i].Nused;
     
    202206    out[i].M     = in[i].M;     
    203207    out[i].dM    = in[i].dM;     
    204     out[i].Xm    = in[i].Xm;     
     208    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
    205209    out[i].Ncode = in[i].Ncode;
    206210    out[i].Nused = in[i].Nused;
     
    208212  return (out);
    209213}
     214
     215# define RAW_IMAGE_NAME_LEN 64
    210216
    211217/* convert panstarrs-format images to internal images */
     
    223229    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    224230
    225     strncpy (out[i].name, in[i].name, 63); // in[64], out[128]
    226     out[i].name[63] = 0; // force termination
     231    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     232    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     233    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    227234
    228235    out[i].tzero            = in[i].tzero;
     
    292299    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    293300
    294     strncpy (out[i].name, in[i].name, 63); // in[128], out[64]
    295     out[i].name[63] = 0; // force termination
     301    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     302    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     303    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    296304
    297305    out[i].tzero            = in[i].tzero;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_image.c

    r35162 r37067  
    219219  if (db[0].format == DVO_FORMAT_PS1_V3)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V3");
    220220  if (db[0].format == DVO_FORMAT_PS1_V4)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V4");
     221  if (db[0].format == DVO_FORMAT_PS1_V5)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V5");
    221222  if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_REF");
    222223 
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_image_raw.c

    r34260 r37067  
    5959  if (db[0].format == DVO_FORMAT_PS1_V3)          ImageSize = sizeof(Image_PS1_V3);
    6060  if (db[0].format == DVO_FORMAT_PS1_V4)          ImageSize = sizeof(Image_PS1_V4);
     61  if (db[0].format == DVO_FORMAT_PS1_V5)          ImageSize = sizeof(Image_PS1_V5);
    6162  if (db[0].format == DVO_FORMAT_PS1_REF)         ImageSize = sizeof(Image_PS1_REF);
    6263
     
    8990  if (db[0].format == DVO_FORMAT_PS1_V3)          gfits_table_mkheader_Image_PS1_V3 (&db[0].theader);
    9091  if (db[0].format == DVO_FORMAT_PS1_V4)          gfits_table_mkheader_Image_PS1_V4 (&db[0].theader);
     92  if (db[0].format == DVO_FORMAT_PS1_V5)          gfits_table_mkheader_Image_PS1_V5 (&db[0].theader);
    9193  if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_table_mkheader_Image_PS1_REF (&db[0].theader);
    9294   
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_photcode_ops.c

    r34844 r37067  
    1818
    1919static PhotCodeData *photcodes = NULL;
     20static PhotCode *genericCodeMag = NULL;
     21static PhotCode *genericCodeFlux = NULL;
    2022
    2123PhotCodeData *GetPhotcodeTable () {
     
    2628    photcodes[0].code = NULL;
    2729  }
     30  if (genericCodeMag == NULL) {
     31    ALLOCATE (genericCodeMag, PhotCode, 1);
     32    genericCodeMag->code = 0;
     33    strcpy (genericCodeMag->name, "MAG");
     34    genericCodeMag->type = PHOT_MAG;
     35  }
     36  if (genericCodeFlux == NULL) {
     37    ALLOCATE (genericCodeFlux, PhotCode, 1);
     38    genericCodeFlux->code = 0;
     39    strcpy (genericCodeFlux->name, "MAG");
     40    genericCodeFlux->type = PHOT_MAG;
     41  }
    2842  return photcodes;
    2943}
     
    5771  if (name == NULL) return (NULL);
    5872 
     73  // "MAG" is a special word, not allowed for a photcode name
     74  if (!strcasecmp (name, "MAG")) {
     75    return genericCodeMag;
     76  }
     77
     78  // "FLUX" is a special word, not allowed for a photcode name
     79  if (!strcasecmp (name, "FLUX")) {
     80    return genericCodeFlux;
     81  }
     82
    5983  for (i = 0; i < photcodes[0].Ncode; i++) {
    6084    if (!strcmp (photcodes[0].code[i].name, name)) {
     
    7094 
    7195  if (name == NULL) return (0);
     96
     97  // "MAG" is a special photcode name for internal use
     98  if (!strcasecmp (name, "MAG")) {
     99    return genericCodeMag->code;
     100  }
     101  // "FLUX" is a special photcode name for internal use
     102  if (!strcasecmp (name, "FLUX")) {
     103    return genericCodeFlux->code;
     104  }
    72105
    73106  for (i = 0; i < photcodes[0].Ncode; i++) {
     
    169202}
    170203
     204// returns Nsec if code is PRI/SEC, else -1
    171205int GetPhotcodeNsec (int code) {
    172206 
     
    221255
    222256/******** photometry conversion functions *********/
    223 float PhotInst (Measure *measure) {
    224 
    225   int Np;
    226   float M;
    227 
    228   Np = photcodes[0].hashcode[measure[0].photcode];
     257float PhotInst (Measure *measure, dvoMagClassType class) {
     258
     259  int Np = photcodes[0].hashcode[measure[0].photcode];
    229260  if (Np == -1) return (NAN);
    230 
    231   if (photcodes[0].code[Np].type == PHOT_REF) {
    232     M = measure[0].M;
    233     return (M);
    234   }
    235 
    236   M = measure[0].M - measure[0].dt - ZERO_POINT;
    237          
    238   return (M);
    239 
    240 }
    241 
    242 float PhotCat (Measure *measure) {
    243 
    244   int Np;
    245   float Mcat;
    246   PhotCode *code;
    247 
    248   Np = photcodes[0].hashcode[measure[0].photcode];
     261  PhotCode *code = &photcodes[0].code[Np];
     262
     263  float Mraw = NAN;
     264  switch (class) {
     265    case MAG_CLASS_PSF:
     266      Mraw = measure[0].M;
     267      break;
     268    case MAG_CLASS_KRON:
     269      Mraw = measure[0].Mkron;
     270      break;
     271    case MAG_CLASS_APER:
     272      Mraw = measure[0].Map;
     273      break;
     274    default:
     275      break;
     276  }
     277  if (code->type == PHOT_REF) {
     278    return (Mraw);
     279  }
     280  float Minst = Mraw - measure[0].dt - ZERO_POINT;
     281
     282  return (Minst);
     283}
     284
     285float PhotCat (Measure *measure, dvoMagClassType class) {
     286
     287  int Np = photcodes[0].hashcode[measure[0].photcode];
    249288  if (Np == -1) return (NAN);
    250 
    251   if (photcodes[0].code[Np].type == PHOT_REF) {
    252     Mcat = measure[0].M;
    253     return (Mcat);
    254   }
    255   code = &photcodes[0].code[Np];
    256   Mcat = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     289  PhotCode *code = &photcodes[0].code[Np];
     290
     291  float Mraw = NAN;
     292  switch (class) {
     293    case MAG_CLASS_PSF:
     294      Mraw = measure[0].M;
     295      break;
     296    case MAG_CLASS_KRON:
     297      Mraw = measure[0].Mkron;
     298      break;
     299    case MAG_CLASS_APER:
     300      Mraw = measure[0].Map;
     301      break;
     302    default:
     303      break;
     304  }
     305  if (code->type == PHOT_REF) {
     306    return (Mraw);
     307  }
     308
     309  float Mcat = Mraw - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    257310 
    258311  return (Mcat);
    259312}
    260313
    261 float PhotAper (Measure *measure) {
    262 
    263   int Np;
    264   float Mcat;
    265   PhotCode *code;
    266 
    267   Np = photcodes[0].hashcode[measure[0].photcode];
     314float PhotSys (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class) {
     315
     316  int Np = photcodes[0].hashcode[measure[0].photcode];
    268317  if (Np == -1) return (NAN);
    269 
    270   if (photcodes[0].code[Np].type == PHOT_REF) {
    271     Mcat = measure[0].Map;
    272     return (Mcat);
    273   }
    274   code = &photcodes[0].code[Np];
    275   Mcat = measure[0].Map - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    276  
    277   return (Mcat);
    278 }
    279 
    280 float PhotAperInst (Measure *measure) {
    281 
    282   int Np;
    283   float Minst;
    284 
    285   Np = photcodes[0].hashcode[measure[0].photcode];
    286   if (Np == -1) return (NAN);
    287 
    288   if (photcodes[0].code[Np].type == PHOT_REF) {
    289     Minst = measure[0].Map;
    290     return (Minst);
    291   }
    292   Minst = measure[0].Map - measure[0].dt - ZERO_POINT;
    293  
    294   return (Minst);
    295 }
    296 
    297 float PhotKron (Measure *measure) {
    298 
    299   int Np;
    300   float Mcat;
    301   PhotCode *code;
    302 
    303   Np = photcodes[0].hashcode[measure[0].photcode];
    304   if (Np == -1) return (NAN);
    305 
    306   if (photcodes[0].code[Np].type == PHOT_REF) {
    307     Mcat = measure[0].Mkron;
    308     return (Mcat);
    309   }
    310   code = &photcodes[0].code[Np];
    311   Mcat = measure[0].Mkron - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    312  
    313   return (Mcat);
    314 }
    315 
    316 float PhotKronInst (Measure *measure) {
    317 
    318   int Np;
    319   float Minst;
    320 
    321   Np = photcodes[0].hashcode[measure[0].photcode];
    322   if (Np == -1) return (NAN);
    323 
    324   if (photcodes[0].code[Np].type == PHOT_REF) {
    325     Minst = measure[0].Mkron;
    326     return (Minst);
    327   }
    328   Minst = measure[0].Mkron - measure[0].dt - ZERO_POINT;
    329  
    330   return (Minst);
    331 }
    332 
    333 float PhotSys (Measure *measure, Average *average, SecFilt *secfilt) {
    334 
    335   int i, Np;
    336   float Mcat, Mcol, Msys, mc, Mc;
    337   PhotCode *code;
    338 
    339   Np = photcodes[0].hashcode[measure[0].photcode];
    340   if (Np == -1) return (NAN);
    341 
    342   if (photcodes[0].code[Np].type == PHOT_REF) {
    343     Msys = measure[0].M;
    344     return (Msys);
    345   }
    346   code = &photcodes[0].code[Np];
    347   Mcat = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     318  PhotCode *code = &photcodes[0].code[Np];
     319
     320  float Mraw = NAN;
     321  switch (class) {
     322    case MAG_CLASS_PSF:
     323      Mraw = measure[0].M;
     324      break;
     325    case MAG_CLASS_KRON:
     326      Mraw = measure[0].Mkron;
     327      break;
     328    case MAG_CLASS_APER:
     329      Mraw = measure[0].Map;
     330      break;
     331    default:
     332      break;
     333  }
     334  if (code->type == PHOT_REF) {
     335    return (Mraw);
     336  }
     337  float Mcat = Mraw - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    348338
    349339  /* for DEP, color must be made of PRI/SEC */
    350   mc = PhotColorForCode (average, secfilt, NULL, code);
     340  float mc = PhotColorForCode (average, secfilt, NULL, code);
    351341  if (isnan(mc)) return (Mcat);
    352   mc = mc - SCALE*code[0].dX;
    353 
    354   Mc = mc;
    355   Mcol = 0;
     342  mc -= SCALE*code[0].dX;
     343
     344  int i = 0;
     345  double Mc = mc;
     346  float Mcol = 0;
    356347  for (i = 0; i < code[0].Nc; i++) {
    357348    Mcol += code[0].X[i]*Mc;
    358349    Mc *= mc;
    359350  }
    360   Msys = Mcat + Mcol;
     351  float Msys = Mcat + Mcol;
    361352  return (Msys);
    362353}
     354
     355float PhotRel (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class) {
     356
     357  int Np = photcodes[0].hashcode[measure[0].photcode];
     358  if (Np == -1) return (NAN);
     359  PhotCode *code = &photcodes[0].code[Np];
     360
     361  float Mraw = NAN;
     362  switch (class) {
     363    case MAG_CLASS_PSF:
     364      Mraw = measure[0].M;
     365      break;
     366    case MAG_CLASS_KRON:
     367      Mraw = measure[0].Mkron;
     368      break;
     369    case MAG_CLASS_APER:
     370      Mraw = measure[0].Map;
     371      break;
     372    default:
     373      break;
     374  }
     375  if (code->type == PHOT_REF) {
     376    return (Mraw);
     377  }
     378  float Mcat = Mraw - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
     379
     380  /* for DEP, color must be made of PRI/SEC */
     381  float mc = PhotColorForCode (average, secfilt, NULL, code);
     382  if (isnan(mc)) return (Mcat);
     383  mc -= SCALE*code[0].dX;
     384
     385  double Mc = mc;
     386  float Mcol = 0;
     387  int i = 0;
     388  for (i = 0; i < code[0].Nc; i++) {
     389    Mcol += code[0].X[i]*Mc;
     390    Mc *= mc;
     391  }
     392  float Mrel = Mcat + Mcol;
     393  return (Mrel);
     394}
     395
     396/* return calibrated magnitude from measure for given photcode */
     397float PhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code, dvoMagClassType class) {
     398
     399  int i;
     400
     401  if (code == NULL) return NAN;
     402
     403  /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
     404  int Np = photcodes[0].hashcode[thisone[0].photcode];
     405  if (Np == -1) return (NAN);
     406  PhotCode *myCode = &photcodes[0].code[Np];
     407
     408  if (code->code != myCode->equiv) return (NAN);
     409
     410  // if we are REF type, just get the right version and return
     411  if (myCode->type == PHOT_REF) {
     412    float Mraw = NAN;
     413    switch (class) {
     414      case MAG_CLASS_PSF:
     415        Mraw = thisone[0].M;
     416        break;
     417      case MAG_CLASS_KRON:
     418        Mraw = thisone[0].Mkron;
     419        break;
     420      case MAG_CLASS_APER:
     421        Mraw = thisone[0].Map;
     422        break;
     423      default:
     424        break;
     425    }
     426    return (Mraw);
     427  }
     428
     429  float Mcal = PhotRel (thisone, average, secfilt, class) + SCALE*code[0].C;
     430
     431  float mc = PhotColorForCode (average, secfilt, measure, code);
     432  if (isnan(mc)) return (Mcal);
     433  mc -= SCALE*code[0].dX;
     434
     435  double Mc = mc;
     436  float Mcol = 0;
     437  for (i = 0; i < code[0].Nc; i++) {
     438    Mcol += code[0].X[i]*Mc;
     439    Mc *= mc;
     440  }
     441  Mcal += Mcol;
     442  return (Mcal);
     443}
     444
     445/***/
     446float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source) {
     447
     448  if (code == NULL) return NAN;
     449
     450  int Ns = photcodes[0].hashNsec[code[0].code];
     451  if (Ns == -1) return (NAN);
     452
     453  float Mave = NAN;
     454  switch (source) {
     455    case MAG_SRC_CHP:
     456      switch (class) {
     457        case MAG_CLASS_PSF:
     458          Mave = secfilt[Ns].M;
     459          break;
     460        case MAG_CLASS_KRON:
     461          Mave = secfilt[Ns].Mkron;
     462          break;
     463        case MAG_CLASS_APER:
     464          Mave = secfilt[Ns].Map;
     465          break;
     466        default:
     467          break;
     468      }
     469      break;
     470    case MAG_SRC_WRP:
     471      switch (class) {
     472        case MAG_CLASS_PSF:
     473          Mave = secfilt[Ns].MpsfWrp;
     474          break;
     475        case MAG_CLASS_KRON:
     476          Mave = secfilt[Ns].MkronWrp;
     477          break;
     478        case MAG_CLASS_APER:
     479          Mave = secfilt[Ns].MapWrp;
     480          break;
     481        default:
     482          break;
     483      }
     484      break;
     485    case MAG_SRC_STK:
     486      switch (class) {
     487        case MAG_CLASS_PSF:
     488          Mave = secfilt[Ns].MpsfStk;
     489          break;
     490        case MAG_CLASS_KRON:
     491          Mave = secfilt[Ns].MkronStk;
     492          break;
     493        case MAG_CLASS_APER:
     494          Mave = secfilt[Ns].MapStk;
     495          break;
     496        default:
     497          break;
     498      }
     499      break;
     500    default:
     501      break;
     502  }
     503  return (Mave);
     504}
     505
     506/* return calibrated magnitude from average/secfilt for given photcode */
     507float PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure, dvoMagClassType class, dvoMagSourceType source) {
     508
     509  int i;
     510
     511  float Mave = PhotAve (code, average, secfilt, class, source);
     512  if (isnan(Mave)) return NAN;
     513
     514  // correct for relative zero-point
     515  float Mref = Mave + SCALE*code[0].C;
     516
     517  float mc = PhotColorForCode (average, secfilt, measure, code);
     518  if (isnan(mc)) return (Mref);
     519  mc -= SCALE*code[0].dX;
     520
     521  // correct for color terms
     522  double Mc = mc;
     523  float Mcol = 0;
     524  for (i = 0; i < code[0].Nc; i++) {
     525    Mcol += code[0].X[i]*Mc;
     526    Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
     527  }
     528  Mref += Mcol;
     529  return (Mref);
     530}
     531
     532float PhotErr (Measure *measure, dvoMagClassType class) {
     533
     534  float dMraw = NAN;
     535  switch (class) {
     536    case MAG_CLASS_PSF:
     537      dMraw = measure[0].dM;
     538      break;
     539    case MAG_CLASS_KRON:
     540      dMraw = measure[0].dMkron;
     541      break;
     542    case MAG_CLASS_APER:
     543      dMraw = measure[0].dMap;
     544      break;
     545    default:
     546      break;
     547  }
     548  return (dMraw);
     549}
     550
     551float PhotCalErr (Measure *measure, dvoMagClassType class) {
     552
     553  float dMcal = measure[0].dMcal;
     554  return (dMcal);
     555}
     556
     557float PhotAveErr (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source) {
     558
     559  if (code == NULL) return NAN;
     560
     561  int Ns = photcodes[0].hashNsec[code[0].code];
     562  if (Ns == -1) return (NAN);
     563
     564  float dMave = NAN;
     565  switch (source) {
     566    case MAG_SRC_CHP:
     567      switch (class) {
     568        case MAG_CLASS_PSF:
     569          dMave = secfilt[Ns].dM;
     570          break;
     571        case MAG_CLASS_KRON:
     572          dMave = secfilt[Ns].dMkron;
     573          break;
     574        case MAG_CLASS_APER:
     575          dMave = secfilt[Ns].dMap;
     576          break;
     577        default:
     578          break;
     579      }
     580      break;
     581    case MAG_SRC_WRP:
     582      switch (class) {
     583        case MAG_CLASS_PSF:
     584          dMave = secfilt[Ns].dFpsfWrp / secfilt[Ns].FpsfWrp;
     585          break;
     586        case MAG_CLASS_KRON:
     587          dMave = secfilt[Ns].dFkronWrp / secfilt[Ns].FkronWrp;
     588          break;
     589        case MAG_CLASS_APER:
     590          dMave = secfilt[Ns].dFapWrp / secfilt[Ns].FapWrp;
     591          break;
     592        default:
     593          break;
     594      }
     595      break;
     596    case MAG_SRC_STK:
     597      switch (class) {
     598        case MAG_CLASS_PSF:
     599          dMave = secfilt[Ns].dFpsfStk / secfilt[Ns].FpsfStk;
     600          break;
     601        case MAG_CLASS_KRON:
     602          dMave = secfilt[Ns].dFkronStk / secfilt[Ns].FkronStk;
     603          break;
     604        case MAG_CLASS_APER:
     605          dMave = secfilt[Ns].dFapStk / secfilt[Ns].FapStk;
     606          break;
     607        default:
     608          break;
     609      }
     610      break;
     611    default:
     612      break;
     613  }
     614  return (dMave);
     615}
     616
     617/********************* other support functions ********************************/
    363618
    364619float PhotZeroPoint (Measure *measure, Average *average, SecFilt *secfilt) {
     
    381636}
    382637
    383 float PhotRel (Measure *measure, Average *average, SecFilt *secfilt) {
    384 
    385   int i, Np;
    386   float Mcat, Mcol, Mrel, mc, Mc;
    387   PhotCode *code;
    388 
    389   Np = photcodes[0].hashcode[measure[0].photcode];
    390   if (Np == -1) return (NAN);
    391 
    392   if (photcodes[0].code[Np].type == PHOT_REF) {
    393     Mcat = measure[0].M;
    394     return (Mcat);
    395   }
    396   code = &photcodes[0].code[Np];
    397   Mrel = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
    398 
    399   /* for DEP, color must be made of PRI/SEC */
    400   mc = PhotColorForCode (average, secfilt, NULL, code);
    401   if (isnan(mc)) return (Mrel);
    402   mc = mc - SCALE*code[0].dX;
    403 
    404   Mc = mc;
    405   Mcol = 0;
    406   for (i = 0; i < code[0].Nc; i++) {
    407     Mcol += code[0].X[i]*Mc;
    408     Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
    409   }
    410   Mrel += Mcol;
    411   return (Mrel);
    412 }
    413 
    414 /* return calibrated magnitude from measure for given photcode */
    415 float PhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code) {
    416 
    417   int i, Np;
    418   float Mcal, Mrel, Mcol, mc, Mc;
    419 
    420   if (code == NULL) return NAN;
    421 
    422   /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
    423   Np = photcodes[0].hashcode[thisone[0].photcode];
    424   if (Np == -1) return (NAN);
    425 
    426   if (photcodes[0].code[Np].type == PHOT_REF) {
    427     Mrel = thisone[0].M;
    428     return (Mrel);
    429   }
    430   if (code[0].code != photcodes[0].code[Np].equiv) return (NAN);
    431 
    432   Mcal = PhotRel (thisone, average, secfilt) + SCALE*code[0].C;
    433 
    434   mc = PhotColorForCode (average, secfilt, measure, code);
    435   if (isnan(mc)) return (Mcal);
    436   mc = mc - SCALE*code[0].dX;
    437 
    438   Mc = mc;
    439   Mcol = 0;
    440   for (i = 0; i < code[0].Nc; i++) {
    441     Mcol += code[0].X[i]*Mc;
    442     Mc *= mc;
    443   }
    444   Mcal += Mcol;
    445   return (Mcal);
    446 }
    447 
    448638/* color term may not use DEP magnitude */
     639// currently only returns the PSF color
    449640float PhotColorForCode (Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code) {
    450641
     
    496687}
    497688
    498 /* return calibrated magnitude from average/secfilt for given photcode */
    499 float PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure) {
    500 
    501   int i, Ns;
    502   float Mave, Mref, Mcol, mc;
    503   double Mc;
    504 
    505   if (code == NULL) return NAN;
    506 
    507   Ns = photcodes[0].hashNsec[code[0].code];
    508   Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
    509   Mref = Mave + SCALE*code[0].C;
    510 
    511   mc = PhotColorForCode (average, secfilt, measure, code);
    512   if (isnan(mc)) return (Mref);
    513   mc = mc - SCALE*code[0].dX;
    514 
    515   Mc = mc;
    516   Mcol = 0;
    517   for (i = 0; i < code[0].Nc; i++) {
    518     Mcol += code[0].X[i]*Mc;
    519     Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
    520   }
    521   Mref += Mcol;
    522   return (Mref);
    523 }
    524 
    525 /***/
    526 float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt) {
    527 
    528   int Ns;
    529   float Mave;
    530 
    531   if (code == NULL) return NAN;
    532 
    533   Ns = photcodes[0].hashNsec[code[0].code];
    534   Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
    535   return (Mave);
    536 }
    537 
    538 float PhotdM (PhotCode *code, Average *average, SecFilt *secfilt) {
    539 
    540   int Ns;
    541   float dM;
    542 
    543   if (code == NULL) return NAN;
    544 
    545   Ns = photcodes[0].hashNsec[code[0].code];
    546   dM  = (Ns == -1) ? NAN : secfilt[Ns].dM;
    547   return (dM);
    548 }
    549 
    550689float PhotMstdev (PhotCode *code, Average *average, SecFilt *secfilt) {
    551690
     
    560699}
    561700
    562 float PhotKronAve (PhotCode *code, Average *average, SecFilt *secfilt) {
    563 
    564   int Ns;
    565   float Mkron;
    566 
    567   if (code == NULL) return NAN;
    568 
    569   Ns = photcodes[0].hashNsec[code[0].code];
    570   Mkron = (Ns == -1) ? NAN : secfilt[Ns].Mkron;
    571   return (Mkron);
    572 }
    573 
    574 float PhotKronAveErr (PhotCode *code, Average *average, SecFilt *secfilt) {
    575 
    576   int Ns;
    577   float dMkron;
    578 
    579   if (code == NULL) return NAN;
    580 
    581   Ns = photcodes[0].hashNsec[code[0].code];
    582   dMkron = (Ns == -1) ? NAN : secfilt[Ns].dMkron;
    583   return (dMkron);
    584 }
    585 
    586701float PhotAveFluxPSF (PhotCode *code, Average *average, SecFilt *secfilt) {
    587702
     
    592707
    593708  Ns = photcodes[0].hashNsec[code[0].code];
    594   Fpsf = (Ns == -1) ? NAN : secfilt[Ns].FluxPSF;
     709  Fpsf = (Ns == -1) ? NAN : secfilt[Ns].FpsfStk;
    595710  return (Fpsf);
    596711}
     
    604719
    605720  Ns = photcodes[0].hashNsec[code[0].code];
    606   dFpsf = (Ns == -1) ? NAN : secfilt[Ns].dFluxPSF;
     721  dFpsf = (Ns == -1) ? NAN : secfilt[Ns].dFpsfStk;
    607722  return (dFpsf);
    608723}
     
    616731
    617732  Ns = photcodes[0].hashNsec[code[0].code];
    618   Fkron = (Ns == -1) ? NAN : secfilt[Ns].FluxKron;
     733  Fkron = (Ns == -1) ? NAN : secfilt[Ns].FkronStk;
    619734  return (Fkron);
    620735}
     
    628743
    629744  Ns = photcodes[0].hashNsec[code[0].code];
    630   dFkron = (Ns == -1) ? NAN : secfilt[Ns].dFluxKron;
     745  dFkron = (Ns == -1) ? NAN : secfilt[Ns].dFkronStk;
    631746  return (dFkron);
    632747}
    633748
    634 float PhotM20 (PhotCode *code, Average *average, SecFilt *secfilt) {
     749float PhotMmin (PhotCode *code, Average *average, SecFilt *secfilt) {
    635750
    636751  int Ns;
    637   float M20;
     752  float Mmin;
    638753
    639754  if (code == NULL) return NAN;
    640755
    641756  Ns = photcodes[0].hashNsec[code[0].code];
    642   M20  = (Ns == -1) ? NAN : 0.001*secfilt[Ns].M_20;
    643   return (M20);
    644 }
    645 
    646 float PhotM80 (PhotCode *code, Average *average, SecFilt *secfilt) {
     757  Mmin  = (Ns == -1) ? NAN : secfilt[Ns].Mmin;
     758  return (Mmin);
     759}
     760
     761float PhotMmax (PhotCode *code, Average *average, SecFilt *secfilt) {
    647762
    648763  int Ns;
    649   float M80;
     764  float Mmax;
    650765
    651766  if (code == NULL) return NAN;
    652767
    653768  Ns = photcodes[0].hashNsec[code[0].code];
    654   M80  = (Ns == -1) ? NAN : 0.001*secfilt[Ns].M_80;
    655   return (M80);
     769  Mmax  = (Ns == -1) ? NAN : secfilt[Ns].Mmax;
     770  return (Mmax);
    656771}
    657772
     
    680795}
    681796
    682 // XXX return NAN or NAN_S_SHORT? (secfilt->Xm is short)
     797// Xm is now (2014.07.03) stored as the chisq except in dvo formats which use as short
    683798float PhotXm (PhotCode *code, Average *average, SecFilt *secfilt) {
    684799
    685800  int Ns;
    686   short Mi;
    687801  float Xm;
    688802
     
    690804
    691805  Ns = photcodes[0].hashNsec[code[0].code];
    692   Mi = (Ns == -1) ? NAN : secfilt[Ns].Xm;
    693   Xm = (isnan(Mi)) ? -1.0 : pow (10.0, 0.01*Mi);
     806  Xm = (Ns == -1) ? NAN : secfilt[Ns].Mchisq;
    694807  return (Xm);
    695808}
     
    741854}
    742855
    743 /******** alternate photometry conversion functions using MeasureTiny and AverageTiny *********/
    744 float PhotInstTiny (MeasureTiny *measure) {
    745 
    746   int Np;
    747   float M;
    748 
    749   Np = photcodes[0].hashcode[measure[0].photcode];
     856float MagToFlux (float Mag) {
     857  float Flux = pow(10.0, -0.4*(Mag));
     858  return (Flux);
     859}
     860
     861/** flux conversion *******************************************************************/
     862float PhotFluxInst (Measure *measure, dvoMagClassType class) {
     863
     864  float Moff = - measure[0].dt - ZERO_POINT;
     865  float Finst = NAN;
     866  switch (class) {
     867    case MAG_CLASS_PSF:
     868      Finst = isnan (measure[0].FluxPSF)  ? MagToFlux(measure[0].M + Moff)     : measure[0].FluxPSF;
     869      break;
     870    case MAG_CLASS_KRON:
     871      Finst = isnan (measure[0].FluxKron) ? MagToFlux(measure[0].Mkron + Moff) : measure[0].FluxKron;
     872      break;
     873    case MAG_CLASS_APER:
     874      Finst = isnan (measure[0].FluxAp)   ? MagToFlux(measure[0].Map + Moff)   : measure[0].FluxAp;
     875      break;
     876    default:
     877      break;
     878  }
     879  return (Finst);
     880}
     881
     882// returns Jy fluxes assuming mag in AB? (needs an extra AP factor, right?)
     883float PhotFluxCat (Measure *measure, dvoMagClassType class) {
     884
     885  int Np = photcodes[0].hashcode[measure[0].photcode];
    750886  if (Np == -1) return (NAN);
    751 
    752   if (photcodes[0].code[Np].type == PHOT_REF) {
    753     M = measure[0].M;
    754     return (M);
    755   }
    756 
    757   M = measure[0].M - measure[0].dt - ZERO_POINT;
    758          
    759   return (M);
    760 
    761 }
    762 
    763 float PhotCatTiny (MeasureTiny *measure) {
    764 
    765   int Np;
    766   float Mcat;
    767   PhotCode *code;
    768 
    769   Np = photcodes[0].hashcode[measure[0].photcode];
     887  PhotCode *code = &photcodes[0].code[Np];
     888
     889  // mag_AB = -2.5 log (flux_cgs) - 48.6 (by definition) [~Vega flux in V-band]
     890  // flux_Jy = flux_cgs * 10^23
     891  // -2.5 log (flux_cgs) = -2.5 log (flux_Jy * 10^-23) = -2.5 log (flux_Jy) + 2.5*23
     892
     893  // from these we get:
     894  // mag_AB = -2.5 log (flux_Jy) + 8.9
     895  // log (flux_Jy) = -0.4*mag_AB + 3.56
     896
     897  // mag_AB = mag_inst + ZP
     898
     899  // log(flux_Jy) = -0.4*mag_inst -0.4*ZP + 3.56
     900  // mag_inst = -2.5 log (flux_Jy) - ZP + 8.9
     901
     902  // log (flux_Jy) = -0.4*(mag_inst + ZP - 8.9)
     903
     904  // -2.5 log (flux_inst) = -2.5 log (flux_Jy) - ZP + 8.9
     905  // log (flux_inst) = log (flux_Jy) + 0.4 ZP - 3.56
     906  // flux_inst = flux_Jy * 10^(0.4*ZP - 3.56)
     907  // flux_Jy = flux_inst * 10^(3.56 - 0.4*ZP) = flux_inst * zpFactor
     908  // flux_Jy = flux_inst * 3630.8 * 10^(-0.4*ZP)
     909
     910  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
     911  float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     912  float Moff = Mcal - ZERO_POINT + 8.9;
     913  float Foff = 3630.8 * MagToFlux(Mcal);
     914  float Fcat = NAN;
     915  switch (class) {
     916    case MAG_CLASS_PSF:
     917      Fcat = isnan (measure[0].FluxPSF)  ? MagToFlux(measure[0].M + Moff)     : measure[0].FluxPSF * Foff;
     918      break;
     919    case MAG_CLASS_KRON:
     920      Fcat = isnan (measure[0].FluxKron) ? MagToFlux(measure[0].Mkron + Moff) : measure[0].FluxKron * Foff;
     921      break;
     922    case MAG_CLASS_APER:
     923      Fcat = isnan (measure[0].FluxAp)   ? MagToFlux(measure[0].Map + Moff)   : measure[0].FluxAp * Foff;
     924      break;
     925    default:
     926      break;
     927  }
     928  return (Fcat);
     929}
     930
     931// corrected for color trends
     932float PhotFluxSys (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class) {
     933
     934  int Np = photcodes[0].hashcode[measure[0].photcode];
    770935  if (Np == -1) return (NAN);
    771 
    772   if (photcodes[0].code[Np].type == PHOT_REF) {
    773     Mcat = measure[0].M;
    774     return (Mcat);
    775   }
    776   code = &photcodes[0].code[Np];
    777   Mcat = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    778  
    779   return (Mcat);
    780 }
    781 
    782 # if (0)
    783 float PhotAperTiny (MeasureTiny *measure) {
    784 
    785   int Np;
    786   float Mcat;
    787   PhotCode *code;
    788 
    789   Np = photcodes[0].hashcode[measure[0].photcode];
    790   if (Np == -1) return (NAN);
    791 
    792   if (photcodes[0].code[Np].type == PHOT_REF) {
    793     Mcat = measure[0].Map;
    794     return (Mcat);
    795   }
    796   code = &photcodes[0].code[Np];
    797   Mcat = measure[0].Map - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    798  
    799   return (Mcat);
    800 }
    801 # endif
    802 
    803 float PhotSysTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt) {
    804 
    805   int i, Np;
    806   float Mcat, Mcol, Msys, mc, Mc;
    807   PhotCode *code;
    808 
    809   Np = photcodes[0].hashcode[measure[0].photcode];
    810   if (Np == -1) return (NAN);
    811 
    812   if (photcodes[0].code[Np].type == PHOT_REF) {
    813     Msys = measure[0].M;
    814     return (Msys);
    815   }
    816   code = &photcodes[0].code[Np];
    817   Mcat = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    818 
    819   /* for DEP, color must be made of PRI/SEC */
    820   mc = PhotColorForCodeTiny (average, secfilt, NULL, code);
    821   if (isnan(mc)) return (Mcat);
    822   mc = mc - SCALE*code[0].dX;
    823 
    824   Mc = mc;
    825   Mcol = 0;
     936  PhotCode *code = &photcodes[0].code[Np];
     937
     938  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
     939  float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     940  float Moff = Mcal - ZERO_POINT + 8.9;
     941  float Foff = 3630.8 * MagToFlux(Mcal);
     942  float Fcat = NAN;
     943  switch (class) {
     944    case MAG_CLASS_PSF:
     945      Fcat = isnan (measure[0].FluxPSF)  ? MagToFlux(measure[0].M + Moff)     : measure[0].FluxPSF * Foff;
     946      break;
     947    case MAG_CLASS_KRON:
     948      Fcat = isnan (measure[0].FluxKron) ? MagToFlux(measure[0].Mkron + Moff) : measure[0].FluxKron * Foff;
     949      break;
     950    case MAG_CLASS_APER:
     951      Fcat = isnan (measure[0].FluxAp)   ? MagToFlux(measure[0].Map + Moff)   : measure[0].FluxAp * Foff;
     952      break;
     953    default:
     954      break;
     955  }
     956  if (isnan(Fcat)) return (NAN);
     957
     958  // find the relevant color
     959  float mc = PhotColorForCode (average, secfilt, NULL, code);
     960  if (isnan(mc)) return (Fcat);
     961  mc -= SCALE*code[0].dX;
     962
     963  // find the color correction in mags
     964  int i = 0;
     965  double Mc = mc;
     966  float Mcol = 0;
    826967  for (i = 0; i < code[0].Nc; i++) {
    827968    Mcol += code[0].X[i]*Mc;
    828969    Mc *= mc;
    829970  }
    830   Msys = Mcat + Mcol;
    831   return (Msys);
    832 }
    833 
    834 float PhotRelTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt) {
    835 
    836   int i, Np;
    837   float Mcat, Mcol, Mrel, mc, Mc;
    838   PhotCode *code;
    839 
    840   Np = photcodes[0].hashcode[measure[0].photcode];
     971  float Fcol = MagToFlux (Mcol);
     972
     973  float Fsys = Fcat * Fcol;
     974  return (Fsys);
     975}
     976
     977float PhotFluxRel (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class) {
     978
     979  int Np = photcodes[0].hashcode[measure[0].photcode];
    841980  if (Np == -1) return (NAN);
    842 
    843   if (photcodes[0].code[Np].type == PHOT_REF) {
    844     Mcat = measure[0].M;
    845     return (Mcat);
    846   }
    847   code = &photcodes[0].code[Np];
    848   Mrel = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
     981  PhotCode *code = &photcodes[0].code[Np];
     982
     983  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
     984  float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
     985  float Moff = Mcal - ZERO_POINT + 8.9;
     986  float Foff = 3630.8 * MagToFlux(Mcal);
     987  float Fcat = NAN;
     988  switch (class) {
     989    case MAG_CLASS_PSF:
     990      Fcat = isnan (measure[0].FluxPSF)  ? MagToFlux(measure[0].M + Moff)     : measure[0].FluxPSF * Foff;
     991      break;
     992    case MAG_CLASS_KRON:
     993      Fcat = isnan (measure[0].FluxKron) ? MagToFlux(measure[0].Mkron + Moff) : measure[0].FluxKron * Foff;
     994      break;
     995    case MAG_CLASS_APER:
     996      Fcat = isnan (measure[0].FluxAp)   ? MagToFlux(measure[0].Map + Moff)   : measure[0].FluxAp * Foff;
     997      break;
     998    default:
     999      break;
     1000  }
     1001  if (isnan(Fcat)) return (NAN);
    8491002
    8501003  /* for DEP, color must be made of PRI/SEC */
    851   mc = PhotColorForCodeTiny (average, secfilt, NULL, code);
    852   if (isnan(mc)) return (Mrel);
    853   mc = mc - SCALE*code[0].dX;
    854 
    855   Mc = mc;
    856   Mcol = 0;
     1004  float mc = PhotColorForCode (average, secfilt, NULL, code);
     1005  if (isnan(mc)) return (Fcat);
     1006  mc -= SCALE*code[0].dX;
     1007
     1008  double Mc = mc;
     1009  float Mcol = 0;
     1010  int i = 0;
     1011  for (i = 0; i < code[0].Nc; i++) {
     1012    Mcol += code[0].X[i]*Mc;
     1013    Mc *= mc;
     1014  }
     1015  float Fcol = MagToFlux (Mcol);
     1016
     1017  float Frel = Fcat * Fcol;
     1018  return (Frel);
     1019}
     1020
     1021/* return calibrated magnitude from measure for given photcode */
     1022float PhotFluxCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code, dvoMagClassType class) {
     1023
     1024  int i;
     1025
     1026  if (code == NULL) return NAN;
     1027
     1028  /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
     1029  int Np = photcodes[0].hashcode[thisone[0].photcode];
     1030  if (Np == -1) return (NAN);
     1031  PhotCode *myCode = &photcodes[0].code[Np];
     1032
     1033  if (code->code != myCode->equiv) return (NAN);
     1034
     1035  float Frel = PhotFluxRel (thisone, average, secfilt, class) + SCALE*code[0].C;
     1036
     1037  // get the relevant color term
     1038  float mc = PhotColorForCode (average, secfilt, measure, code);
     1039  if (isnan(mc)) return (Frel);
     1040  mc -= SCALE*code[0].dX;
     1041
     1042  // get the corresponding color correction in mags, convert to flux
     1043  double Mc = mc;
     1044  float Mcol = 0;
     1045  for (i = 0; i < code[0].Nc; i++) {
     1046    Mcol += code[0].X[i]*Mc;
     1047    Mc *= mc;
     1048  }
     1049  float Fcol = MagToFlux (Mcol);
     1050
     1051  float Fcal = Frel * Fcol;
     1052  return (Fcal);
     1053}
     1054
     1055/***/
     1056float PhotFluxAve (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source) {
     1057
     1058  if (code == NULL) return NAN;
     1059
     1060  int Ns = photcodes[0].hashNsec[code[0].code];
     1061  if (Ns == -1) return (NAN);
     1062
     1063  float Fave = NAN;
     1064  switch (source) {
     1065    case MAG_SRC_CHP:
     1066      switch (class) {
     1067        case MAG_CLASS_PSF:
     1068          Fave = MagToFlux(secfilt[Ns].M);
     1069          break;
     1070        case MAG_CLASS_KRON:
     1071          Fave = MagToFlux(secfilt[Ns].Mkron);
     1072          break;
     1073        case MAG_CLASS_APER:
     1074          Fave = MagToFlux(secfilt[Ns].Map);
     1075          break;
     1076        default:
     1077          break;
     1078      }
     1079      break;
     1080    case MAG_SRC_WRP:
     1081      switch (class) {
     1082        case MAG_CLASS_PSF:
     1083          Fave = isnan (secfilt[Ns].FpsfWrp)  ? MagToFlux(secfilt[Ns].MpsfWrp)  : secfilt[Ns].FpsfWrp;
     1084          break;
     1085        case MAG_CLASS_KRON:
     1086          Fave = isnan (secfilt[Ns].FkronWrp) ? MagToFlux(secfilt[Ns].MkronWrp) : secfilt[Ns].FkronWrp;
     1087          break;
     1088        case MAG_CLASS_APER:
     1089          Fave = isnan (secfilt[Ns].FapWrp)   ? MagToFlux(secfilt[Ns].MapWrp)   : secfilt[Ns].FapWrp;
     1090          break;
     1091        default:
     1092          break;
     1093      }
     1094      break;
     1095    case MAG_SRC_STK:
     1096      switch (class) {
     1097        case MAG_CLASS_PSF:
     1098          Fave = isnan (secfilt[Ns].FpsfStk)  ? MagToFlux(secfilt[Ns].MpsfStk)  : secfilt[Ns].FpsfStk;
     1099          break;
     1100        case MAG_CLASS_KRON:
     1101          Fave = isnan (secfilt[Ns].FkronStk) ? MagToFlux(secfilt[Ns].MkronStk) : secfilt[Ns].FkronStk;
     1102          break;
     1103        case MAG_CLASS_APER:
     1104          Fave = isnan (secfilt[Ns].FapStk)   ? MagToFlux(secfilt[Ns].MapStk)   : secfilt[Ns].FapStk;
     1105          break;
     1106        default:
     1107          break;
     1108      }
     1109      break;
     1110    default:
     1111      break;
     1112  }
     1113  return (Fave);
     1114}
     1115
     1116/* return calibrated magnitude from average/secfilt for given photcode */
     1117float PhotFluxRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure, dvoMagClassType class, dvoMagSourceType source) {
     1118
     1119  int i;
     1120
     1121  float Fave = PhotFluxAve (code, average, secfilt, class, source);
     1122  if (isnan(Fave)) return NAN;
     1123
     1124  // correct for relative zero-point
     1125  float Moff = SCALE*code[0].C;
     1126
     1127  float mc = PhotColorForCode (average, secfilt, measure, code);
     1128  if (isnan(mc)) return (Fave * MagToFlux(Moff));
     1129  mc -= SCALE*code[0].dX;
     1130
     1131  // correct for color terms
     1132  double Mc = mc;
     1133  float Mcol = 0;
    8571134  for (i = 0; i < code[0].Nc; i++) {
    8581135    Mcol += code[0].X[i]*Mc;
    8591136    Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
    8601137  }
    861   Mrel += Mcol;
    862   return (Mrel);
    863 }
    864 
    865 /* return calibrated magnitude from measure for given photcode */
    866 float PhotCalTiny (MeasureTiny *thisone, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code) {
    867 
    868   int i, Np;
    869   float Mcal, Mrel, Mcol, mc, Mc;
    870 
    871   if (code == NULL) return NAN;
    872 
    873   /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
    874   Np = photcodes[0].hashcode[thisone[0].photcode];
     1138  float Foff = MagToFlux(Mcol);
     1139  return (Fave * Foff);
     1140}
     1141
     1142float PhotFluxInstErr (Measure *measure, dvoMagClassType class) {
     1143
     1144  float Moff = - measure[0].dt - ZERO_POINT;
     1145
     1146  // use dFlux if we can, but use dMag if we must:
     1147  // dFlux = Flux * dMag
     1148
     1149  float dFinst = NAN;
     1150  switch (class) {
     1151    case MAG_CLASS_PSF:
     1152      if (isnan (measure[0].dFluxPSF)) {
     1153        float Finst = MagToFlux(measure[0].M + Moff);
     1154        dFinst = measure[0].dM * Finst;
     1155      } else {
     1156        dFinst = measure[0].dFluxPSF;
     1157      }
     1158      break;
     1159    case MAG_CLASS_KRON:
     1160      if (isnan (measure[0].dFluxKron)) {
     1161        float Finst = MagToFlux(measure[0].Mkron + Moff);
     1162        dFinst = measure[0].dMkron * Finst;
     1163      } else {
     1164        dFinst = measure[0].dFluxKron;
     1165      }
     1166      break;
     1167    case MAG_CLASS_APER:
     1168      if (isnan (measure[0].dFluxAp)) {
     1169        float Finst = MagToFlux(measure[0].Map + Moff);
     1170        dFinst = measure[0].dMap * Finst;
     1171      } else {
     1172        dFinst = measure[0].dFluxAp;
     1173      }
     1174      break;
     1175    default:
     1176      break;
     1177  }
     1178  return (dFinst);
     1179}
     1180
     1181float PhotFluxCatErr (Measure *measure, dvoMagClassType class) {
     1182
     1183  int Np = photcodes[0].hashcode[measure[0].photcode];
    8751184  if (Np == -1) return (NAN);
    876 
    877   if (photcodes[0].code[Np].type == PHOT_REF) {
    878     Mrel = thisone[0].M;
    879     return (Mrel);
    880   }
    881   if (code[0].code != photcodes[0].code[Np].equiv) return (NAN);
    882 
    883   Mcal = PhotRelTiny (thisone, average, secfilt) + SCALE*code[0].C;
    884 
    885   mc = PhotColorForCodeTiny (average, secfilt, measure, code);
    886   if (isnan(mc)) return (Mcal);
    887   mc = mc - SCALE*code[0].dX;
    888 
    889   Mc = mc;
    890   Mcol = 0;
     1185  PhotCode *code = &photcodes[0].code[Np];
     1186
     1187  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
     1188  float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     1189  float Moff = Mcal - ZERO_POINT + 8.9;
     1190  float Foff = 3630.8 * MagToFlux(Mcal);
     1191
     1192  // use dFlux if we can, but use dMag if we must:
     1193  // dFlux = Flux * dMag
     1194
     1195  float dFcat = NAN;
     1196  switch (class) {
     1197    case MAG_CLASS_PSF:
     1198      if (isnan (measure[0].dFluxPSF)) {
     1199        float Finst = MagToFlux(measure[0].M + Moff);
     1200        dFcat = measure[0].dM * Finst;
     1201      } else {
     1202        dFcat = measure[0].dFluxPSF * Foff;
     1203      }
     1204      break;
     1205    case MAG_CLASS_KRON:
     1206      if (isnan (measure[0].dFluxKron)) {
     1207        float Finst = MagToFlux(measure[0].Mkron + Moff);
     1208        dFcat = measure[0].dMkron * Finst;
     1209      } else {
     1210        dFcat = measure[0].dFluxKron * Foff;
     1211      }
     1212      break;
     1213    case MAG_CLASS_APER:
     1214      if (isnan (measure[0].dFluxAp)) {
     1215        float Finst = MagToFlux(measure[0].Map + Moff);
     1216        dFcat = measure[0].dMap * Finst;
     1217      } else {
     1218        dFcat = measure[0].dFluxAp * Foff;
     1219      }
     1220      break;
     1221    default:
     1222      break;
     1223  }
     1224  return (dFcat);
     1225}
     1226
     1227/******** alternate photometry conversion functions using MeasureTiny and AverageTiny *********/
     1228float PhotInstTiny (MeasureTiny *measure, dvoMagClassType class) {
     1229
     1230  int Np = photcodes[0].hashcode[measure[0].photcode];
     1231  if (Np == -1) return (NAN);
     1232  PhotCode *code = &photcodes[0].code[Np];
     1233
     1234  float Mraw = NAN;
     1235  switch (class) {
     1236    case MAG_CLASS_PSF:
     1237      Mraw = measure[0].M;
     1238      break;
     1239    case MAG_CLASS_KRON:
     1240      // Mraw = measure[0].Mkron;
     1241      break;
     1242    case MAG_CLASS_APER:
     1243      // Mraw = measure[0].Map;
     1244      break;
     1245    default:
     1246      break;
     1247  }
     1248  if (code->type == PHOT_REF) {
     1249    return (Mraw);
     1250  }
     1251  float Minst = Mraw - measure[0].dt - ZERO_POINT;
     1252
     1253  return (Minst);
     1254}
     1255
     1256float PhotCatTiny (MeasureTiny *measure, dvoMagClassType class) {
     1257
     1258  int Np = photcodes[0].hashcode[measure[0].photcode];
     1259  if (Np == -1) return (NAN);
     1260  PhotCode *code = &photcodes[0].code[Np];
     1261
     1262  float Mraw = NAN;
     1263  switch (class) {
     1264    case MAG_CLASS_PSF:
     1265      Mraw = measure[0].M;
     1266      break;
     1267    case MAG_CLASS_KRON:
     1268      // Mraw = measure[0].Mkron;
     1269      break;
     1270    case MAG_CLASS_APER:
     1271      // Mraw = measure[0].Map;
     1272      break;
     1273    default:
     1274      break;
     1275  }
     1276  if (code->type == PHOT_REF) {
     1277    return (Mraw);
     1278  }
     1279
     1280  float Mcat = Mraw - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     1281 
     1282  return (Mcat);
     1283}
     1284
     1285float PhotSysTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt, dvoMagClassType class) {
     1286
     1287  int Np = photcodes[0].hashcode[measure[0].photcode];
     1288  if (Np == -1) return (NAN);
     1289  PhotCode *code = &photcodes[0].code[Np];
     1290
     1291  float Mraw = NAN;
     1292  switch (class) {
     1293    case MAG_CLASS_PSF:
     1294      Mraw = measure[0].M;
     1295      break;
     1296    case MAG_CLASS_KRON:
     1297      // Mraw = measure[0].Mkron;
     1298      break;
     1299    case MAG_CLASS_APER:
     1300      // Mraw = measure[0].Map;
     1301      break;
     1302    default:
     1303      break;
     1304  }
     1305  if (code->type == PHOT_REF) {
     1306    return (Mraw);
     1307  }
     1308  float Mcat = Mraw - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     1309
     1310  /* for DEP, color must be made of PRI/SEC */
     1311  float mc = PhotColorForCodeTiny (average, secfilt, NULL, code);
     1312  if (isnan(mc)) return (Mcat);
     1313  mc -= SCALE*code[0].dX;
     1314
     1315  int i = 0;
     1316  double Mc = mc;
     1317  float Mcol = 0;
    8911318  for (i = 0; i < code[0].Nc; i++) {
    8921319    Mcol += code[0].X[i]*Mc;
    8931320    Mc *= mc;
    8941321  }
     1322  float Msys = Mcat + Mcol;
     1323  return (Msys);
     1324}
     1325
     1326float PhotRelTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt, dvoMagClassType class) {
     1327
     1328  int Np = photcodes[0].hashcode[measure[0].photcode];
     1329  if (Np == -1) return (NAN);
     1330  PhotCode *code = &photcodes[0].code[Np];
     1331
     1332  float Mraw = NAN;
     1333  switch (class) {
     1334    case MAG_CLASS_PSF:
     1335      Mraw = measure[0].M;
     1336      break;
     1337    case MAG_CLASS_KRON:
     1338      // Mraw = measure[0].Mkron;
     1339      break;
     1340    case MAG_CLASS_APER:
     1341      // Mraw = measure[0].Map;
     1342      break;
     1343    default:
     1344      break;
     1345  }
     1346  if (code->type == PHOT_REF) {
     1347    return (Mraw);
     1348  }
     1349  float Mcat = Mraw - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
     1350
     1351  /* for DEP, color must be made of PRI/SEC */
     1352  float mc = PhotColorForCodeTiny (average, secfilt, NULL, code);
     1353  if (isnan(mc)) return (Mcat);
     1354  mc -= SCALE*code[0].dX;
     1355
     1356  double Mc = mc;
     1357  float Mcol = 0;
     1358  int i = 0;
     1359  for (i = 0; i < code[0].Nc; i++) {
     1360    Mcol += code[0].X[i]*Mc;
     1361    Mc *= mc;
     1362  }
     1363  float Mrel = Mcat + Mcol;
     1364  return (Mrel);
     1365}
     1366
     1367/* return calibrated magnitude from measure for given photcode */
     1368float PhotCalTiny (MeasureTiny *thisone, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code, dvoMagClassType class) {
     1369
     1370  int i;
     1371
     1372  if (code == NULL) return NAN;
     1373
     1374  /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
     1375  int Np = photcodes[0].hashcode[thisone[0].photcode];
     1376  if (Np == -1) return (NAN);
     1377  PhotCode *myCode = &photcodes[0].code[Np];
     1378
     1379  if (code->code != myCode->equiv) return (NAN);
     1380
     1381  // if we are REF type, just get the right version and return
     1382  if (myCode->type == PHOT_REF) {
     1383    float Mraw = NAN;
     1384    switch (class) {
     1385      case MAG_CLASS_PSF:
     1386        Mraw = thisone[0].M;
     1387        break;
     1388      case MAG_CLASS_KRON:
     1389        // Mraw = thisone[0].Mkron;
     1390        break;
     1391      case MAG_CLASS_APER:
     1392        // Mraw = thisone[0].Map;
     1393        break;
     1394      default:
     1395        break;
     1396    }
     1397    return (Mraw);
     1398  }
     1399
     1400  float Mcal = PhotRelTiny (thisone, average, secfilt, class) + SCALE*code[0].C;
     1401
     1402  float mc = PhotColorForCodeTiny (average, secfilt, measure, code);
     1403  if (isnan(mc)) return (Mcal);
     1404  mc -= SCALE*code[0].dX;
     1405
     1406  double Mc = mc;
     1407  float Mcol = 0;
     1408  for (i = 0; i < code[0].Nc; i++) {
     1409    Mcol += code[0].X[i]*Mc;
     1410    Mc *= mc;
     1411  }
    8951412  Mcal += Mcol;
    8961413  return (Mcal);
     1414}
     1415
     1416/***/
     1417float PhotAveTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source) {
     1418
     1419  if (code == NULL) return NAN;
     1420
     1421  int Ns = photcodes[0].hashNsec[code[0].code];
     1422  if (Ns == -1) return (NAN);
     1423
     1424  float Mave = NAN;
     1425  switch (source) {
     1426    case MAG_SRC_CHP:
     1427      switch (class) {
     1428        case MAG_CLASS_PSF:
     1429          Mave = secfilt[Ns].M;
     1430          break;
     1431        case MAG_CLASS_KRON:
     1432          Mave = secfilt[Ns].Mkron;
     1433          break;
     1434        case MAG_CLASS_APER:
     1435          Mave = secfilt[Ns].Map;
     1436          break;
     1437        default:
     1438          break;
     1439      }
     1440      break;
     1441    case MAG_SRC_WRP:
     1442      switch (class) {
     1443        case MAG_CLASS_PSF:
     1444          Mave = secfilt[Ns].MpsfWrp;
     1445          break;
     1446        case MAG_CLASS_KRON:
     1447          Mave = secfilt[Ns].MkronWrp;
     1448          break;
     1449        case MAG_CLASS_APER:
     1450          Mave = secfilt[Ns].MapWrp;
     1451          break;
     1452        default:
     1453          break;
     1454      }
     1455      break;
     1456    case MAG_SRC_STK:
     1457      switch (class) {
     1458        case MAG_CLASS_PSF:
     1459          Mave = secfilt[Ns].MpsfStk;
     1460          break;
     1461        case MAG_CLASS_KRON:
     1462          Mave = secfilt[Ns].MkronStk;
     1463          break;
     1464        case MAG_CLASS_APER:
     1465          Mave = secfilt[Ns].MapStk;
     1466          break;
     1467        default:
     1468          break;
     1469      }
     1470      break;
     1471    default:
     1472      break;
     1473  }
     1474  return (Mave);
     1475}
     1476
     1477/* return calibrated magnitude from average/secfilt for given photcode */
     1478float PhotRefTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, dvoMagClassType class, dvoMagSourceType source) {
     1479
     1480  int i;
     1481
     1482  float Mave = PhotAveTiny (code, average, secfilt, class, source);
     1483  if (isnan(Mave)) return NAN;
     1484
     1485  // correct for relative zero-point
     1486  float Mref = Mave + SCALE*code[0].C;
     1487
     1488  float mc = PhotColorForCodeTiny (average, secfilt, measure, code);
     1489  if (isnan(mc)) return (Mref);
     1490  mc -= SCALE*code[0].dX;
     1491
     1492  // correct for color terms
     1493  double Mc = mc;
     1494  float Mcol = 0;
     1495  for (i = 0; i < code[0].Nc; i++) {
     1496    Mcol += code[0].X[i]*Mc;
     1497    Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
     1498  }
     1499  Mref += Mcol;
     1500  return (Mref);
    8971501}
    8981502
     
    9471551}
    9481552
    949 /* return calibrated magnitude from average/secfilt for given photcode */
    950 float PhotRefTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure) {
    951 
    952   int i, Ns;
    953   float Mave, Mref, Mcol, mc;
    954   double Mc;
    955 
    956   if (code == NULL) return NAN;
    957 
    958   Ns = photcodes[0].hashNsec[code[0].code];
    959   Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
    960   Mref = Mave + SCALE*code[0].C;
    961 
    962   mc = PhotColorForCodeTiny (average, secfilt, measure, code);
    963   if (isnan(mc)) return (Mref);
    964   mc = mc - SCALE*code[0].dX;
    965 
    966   Mc = mc;
    967   Mcol = 0;
    968   for (i = 0; i < code[0].Nc; i++) {
    969     Mcol += code[0].X[i]*Mc;
    970     Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
    971   }
    972   Mref += Mcol;
    973   return (Mref);
    974 }
    975 
    976 /***/
    977 float PhotAveTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt) {
    978 
    979   int Ns;
    980   float Mave;
    981 
    982   if (code == NULL) return NAN;
    983 
    984   Ns = photcodes[0].hashNsec[code[0].code];
    985   Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
    986   return (Mave);
    987 }
    988 
    9891553float PhotdMTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt) {
    9901554
     
    9991563}
    10001564
    1001 // XXX return NAN or NAN_S_SHORT? (secfilt->Xm is short)
     1565// Xm is now (2014.07.03) stored as the chisq except in dvo formats which use as short
    10021566float PhotXmTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt) {
    10031567
    10041568  int Ns;
    1005   short Mi;
    10061569  float Xm;
    10071570
     
    10091572
    10101573  Ns = photcodes[0].hashNsec[code[0].code];
    1011   Mi = (Ns == -1) ? NAN : secfilt[Ns].Xm;
    1012   Xm = (isnan(Mi)) ? -1.0 : pow (10.0, 0.01*Mi);
     1574  Xm = (Ns == -1) ? NAN : secfilt[Ns].Mchisq;
    10131575  return (Xm);
    10141576}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvo_tiny_values.c

    r35102 r37067  
    88  averageT[0].measureOffset = average[0].measureOffset;
    99  averageT[0].catID         = average[0].catID;
     10  averageT[0].objID         = average[0].objID;
     11  averageT[0].nOwn          = -1;
    1012  return;
    1113}
    1214
    1315void CopyMeasureToTiny (MeasureTiny *measureT, Measure *measure) {
    14   measureT[0].dR         = measure[0].dR;
    15   measureT[0].dD         = measure[0].dD;
     16  measureT[0].R          = measure[0].R;
     17  measureT[0].D          = measure[0].D;
    1618  measureT[0].M          = measure[0].M;
    1719  measureT[0].Mcal       = measure[0].Mcal;
     
    3335  measureT[0].dYccd      = measure[0].dYccd;
    3436  measureT[0].dRsys      = measure[0].dRsys;
     37  measureT[0].myDet      = 0;
    3538  return ;
    3639}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/dvosorts.c

    r35263 r37067  
    6060
    6161/* sort a coordinate pair (X,Y) and the associated index (S) */
     62void sort_IDs_indexonly (opihi_int *X, off_t *S, off_t N) {
     63 
     64# define SWAPFUNC(A,B){ off_t itmp; \
     65  itmp = S[A]; S[A] = S[B]; S[B] = itmp; \
     66}
     67# define COMPARE(A,B)(X[S[A]] < X[S[B]])
     68
     69  OHANA_SORT (N, COMPARE, SWAPFUNC);
     70
     71# undef SWAPFUNC
     72# undef COMPARE
     73
     74}
     75
     76/* sort a coordinate pair (X,Y) and the associated index (S) */
    6277void sort_coords_indexonly (double *X, double *Y, off_t *S, off_t N) {
    6378 
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libdvo/src/skyregion_io.c

    r33649 r37067  
    7878  gfits_free_matrix (&matrix);
    7979  gfits_free_header (&theader);
     80  fclose (f);
    8081
    8182  return (skytable);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libfits/include/gfitsio.h

    r35756 r37067  
    2727# define FT_RECORD_SIZE        2880  /* FITS block size */
    2828
     29# define FT_BZERO_INT8 -1.0*0x80
    2930# define FT_BZERO_INT16 1.0*0x8000       
    3031# define FT_BZERO_INT32 1.0*0x80000000
     32# define FT_BZERO_INT64 1.0*0x8000000000000000
    3133
    3234/* this structure defines the buffer which contains a header
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libfits/matrix/F_compress_M.c

    r34088 r37067  
    5858
    5959  // is ZIMAGE present?
     60  // NOTE target of %t must be int length
    6061  status = gfits_scan_alt (ftable->header, "ZIMAGE", "%t", 1, &zimage);
    6162  if (!status || !zimage) ESCAPE;
     
    125126  int have_ztension;
    126127
     128  // NOTE target of %t must be int length
    127129  have_zsimple  = gfits_scan_alt (header, "ZSIMPLE", "%t", 1, &zsimple);
    128130  have_ztension = gfits_scan (header, "ZTENSION", "%s", 1, exttype);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libfits/table/F_get_column.c

    r35101 r37067  
    7979    }
    8080  }
     81  if (!strcmp (type, "byte")) {
     82    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
     83      *(char *)Pout = *(char *)Pin*Bscale + Bzero;
     84    }
     85  }
    8186  if (!strcmp (type, "short")) {
    8287    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
     
    174179int gfits_get_bintable_column (Header *header, FTable *table, char *label, void **data) {
    175180
    176   off_t Nx, Ny;
    177   int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
    178   char tlabel[80], field[80], format[80], type[16], tmpline[16];
    179   char *Pin, *Pout, *array;
    180   double Bscale, Bzero;
    181 
    182   if (label == (char *) NULL) return (FALSE);
    183   if (label[0] == 0) return (FALSE);
    184 
    185   /* find label in header */
    186   tlabel[0] = 0;
    187   gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
    188   for (i = 1; strcasecmp (label, tlabel) && (i < Nfields + 1); i++) {
    189     sprintf (field, "TTYPE%d", i);
    190     gfits_scan (header, field, "%s", 1, tlabel);
    191   }
    192   if (strcasecmp (label, tlabel)) return (FALSE);
    193   N = i - 1;
    194 
    195   Bscale = 1;
    196   Bzero  = 0;
    197 
    198   /* interpret format */
    199   sprintf (field, "TSCAL%d", N);
    200   gfits_scan (header, field, "%lf", 1, &Bscale);
    201   sprintf (field, "TZERO%d", N);
    202   gfits_scan (header, field, "%lf", 1, &Bzero);
    203   sprintf (field, "TFORM%d", N);
    204   gfits_scan (header, field, "%s", 1, format);
    205 
    206   if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE);
    207  
    208   /* check existing table dimensions */
    209   gfits_scan (header, "NAXIS1",  OFF_T_FMT, 1,  &Nx);
    210   gfits_scan (header, "NAXIS2",  OFF_T_FMT, 1,  &Ny);
    211 
    212   /* scan columns to find insert point */
    213   Nstart = 0;
    214   for (i = 1; i < N; i++) {
    215     sprintf (field, "TFORM%d", i);
    216     gfits_scan (header, field, "%s", 1, format);
    217     gfits_bintable_format (format, tmpline, &Nv, &Nb);
    218     Nstart += Nv*Nb;
    219   }
    220 
    221   /* extract bytes from table into temporary array */
    222   ALLOCATE (array, char, Nbytes*Nval*Ny);
    223   Pin  = table[0].buffer + Nstart;
    224   Pout = array;
    225   for (i = 0; i < Ny; i++, Pin += Nx, Pout += Nval*Nbytes) {
    226     memcpy (Pout, Pin, Nval*Nbytes);
    227   }
    228 
    229   /* convert data in-situ with correct type, byte swap and Bzero/Bscale */
    230   Pin  = array;
    231   Pout = array;
    232   if (!strcmp (type, "char")) {
    233     for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    234       *(char *)Pout = *(char *)Pin*Bscale + Bzero;
    235     }
    236   }
    237   if (!strcmp (type, "short")) {
    238     for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    239 # ifdef BYTE_SWAP
    240       SWAP_BYTE;
    241 # endif
    242       *(short *)Pout = *(short *)Pin*Bscale + Bzero;
    243     } 
    244   }
    245   if (!strcmp (type, "int")) {
    246     for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    247 # ifdef BYTE_SWAP
    248       SWAP_WORD;
    249 # endif
    250       *(int *)Pout = *(int *)Pin*Bscale + Bzero;
    251     }
    252   }
    253   if (!strcmp (type, "int64_t")) {
    254     // XXX 64 bit int operations with Bzero & Bscale are inaccurate even with doubles
    255     if ((Bzero == 0.0) && (Bscale == 1.0)) {
    256       for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    257 # ifdef BYTE_SWAP
    258         SWAP_DBLE;
    259 # endif
    260         *(int64_t *)Pout = *(int64_t *)Pin;
    261       }
    262     } else {
    263       for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    264 # ifdef BYTE_SWAP
    265         SWAP_DBLE;
    266 # endif
    267         *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero;
    268       }
    269     }
    270   }
    271   if (!strcmp (type, "float")) {
    272     for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    273 # ifdef BYTE_SWAP
    274       SWAP_WORD;
    275 # endif
    276       *(float *)Pout = *(float *)Pin*Bscale + Bzero;
    277     }
    278   }
    279   if (!strcmp (type, "double")) {
    280     for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    281 # ifdef BYTE_SWAP
    282       SWAP_DBLE;
    283 # endif
    284       *(double *)Pout = *(double *)Pin*Bscale + Bzero;
    285     }
    286   }
     181  char type[16];
     182  off_t Nrow;
     183  int Ncol;
     184
     185  char *array = gfits_get_bintable_column_data (header, table, label, type, &Nrow, &Ncol);
     186  if (array == NULL) return (FALSE);
    287187
    288188  *data = array;
    289   return (TRUE);
     189  return TRUE;
    290190}
    291191
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libfits/table/F_set_column.c

    r35101 r37067  
    8181  Pin = data;
    8282  Pout = array;
     83  // does it makes sense to scale 'char' data?
    8384  if (!strcmp (type, "char")) {
     85    for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
     86      *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     87    }
     88  }
     89  if (!strcmp (type, "byte")) {
    8490    for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
    8591      *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     
    221227  Pout = array;
    222228
     229  // # define ASSIGN_DATA(ITYPE,INAME,ISIZE,OTYPE,ONAME)
     230  // if (!strcmp (intype, #ITYPE)) {
     231
    223232  /** input == char **/
    224233  if (!strcmp (outtype, "char") && !strcmp (intype, "char")) {
     
    228237    }
    229238  }
     239  if (!strcmp (outtype, "byte") && !strcmp (intype, "char")) {
     240    int NbytesIn = 1;
     241    for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
     242      *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     243    }
     244  }
    230245  if (!strcmp (outtype, "short") && !strcmp (intype, "char")) {
    231246    int NbytesIn = 1;
     
    265280  }
    266281  if (!strcmp (outtype, "double") && !strcmp (intype, "char")) {
     282    int NbytesIn = 1;
     283    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     284      *(double *)Pout = (*(char *)Pin - Bzero) / Bscale;
     285# ifdef BYTE_SWAP
     286      SWAP_DBLE;
     287# endif
     288    }
     289  }
     290
     291  /** input == byte **/
     292  if (!strcmp (outtype, "char") && !strcmp (intype, "byte")) {
     293    int NbytesIn = 1;
     294    for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
     295      *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     296    }
     297  }
     298  if (!strcmp (outtype, "byte") && !strcmp (intype, "byte")) {
     299    int NbytesIn = 1;
     300    for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
     301      *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     302    }
     303  }
     304  if (!strcmp (outtype, "short") && !strcmp (intype, "byte")) {
     305    int NbytesIn = 1;
     306    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     307      *(short *)Pout = (*(char *)Pin - Bzero) / Bscale;
     308# ifdef BYTE_SWAP
     309      SWAP_BYTE;
     310# endif
     311    } 
     312  }
     313  if (!strcmp (outtype, "int") && !strcmp (intype, "byte")) {
     314    int NbytesIn = 1;
     315    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     316      *(int *)Pout = (*(char *)Pin - Bzero) / Bscale;
     317# ifdef BYTE_SWAP
     318      SWAP_WORD;
     319# endif
     320    }
     321  }
     322  if (!strcmp (outtype, "int64_t") && !strcmp (intype, "byte")) {
     323    int NbytesIn = 1;
     324    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     325      *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale;
     326# ifdef BYTE_SWAP
     327      SWAP_DBLE;
     328# endif
     329    }
     330  }
     331  if (!strcmp (outtype, "float") && !strcmp (intype, "byte")) {
     332    int NbytesIn = 1;
     333    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     334      *(float *)Pout = (*(char *)Pin - Bzero) / Bscale;
     335# ifdef BYTE_SWAP
     336      SWAP_WORD;
     337# endif
     338    }
     339  }
     340  if (!strcmp (outtype, "double") && !strcmp (intype, "byte")) {
    267341    int NbytesIn = 1;
    268342    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     
    281355    }
    282356  }
     357  if (!strcmp (outtype, "byte") && !strcmp (intype, "short")) {
     358    int NbytesIn = 2;
     359    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     360      *(char *)Pout = (*(short *)Pin - Bzero) / Bscale;
     361    }
     362  }
    283363  if (!strcmp (outtype, "short") && !strcmp (intype, "short")) {
    284364    int NbytesIn = 2;
     
    334414    }
    335415  }
     416  if (!strcmp (outtype, "byte") && !strcmp (intype, "int")) {
     417    int NbytesIn = 4;
     418    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     419      *(char *)Pout = (*(int *)Pin - Bzero) / Bscale;
     420    }
     421  }
    336422  if (!strcmp (outtype, "short") && !strcmp (intype, "int")) {
    337423    int NbytesIn = 4;
     
    387473    }
    388474  }
     475  if (!strcmp (outtype, "byte") && !strcmp (intype, "int64_t")) {
     476    int NbytesIn = 8;
     477    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     478      *(char *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
     479    }
     480  }
    389481  if (!strcmp (outtype, "short") && !strcmp (intype, "int64_t")) {
    390482    int NbytesIn = 8;
     
    440532    }
    441533  }
     534  if (!strcmp (outtype, "byte") && !strcmp (intype, "float")) {
     535    int NbytesIn = 4;
     536    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     537      *(char *)Pout = (*(float *)Pin - Bzero) / Bscale;
     538    }
     539  }
    442540  if (!strcmp (outtype, "short") && !strcmp (intype, "float")) {
    443541    int NbytesIn = 4;
     
    488586  /** input == double **/
    489587  if (!strcmp (outtype, "char") && !strcmp (intype, "double")) {
     588    int NbytesIn = 8;
     589    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     590      *(char *)Pout = (*(double *)Pin - Bzero) / Bscale;
     591    }
     592  }
     593  if (!strcmp (outtype, "byte") && !strcmp (intype, "double")) {
    490594    int NbytesIn = 8;
    491595    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libfits/table/F_table_format.c

    r28241 r37067  
    1919  if ((Nv == 0) && (Fchar == format)) Nv = 1;
    2020
     21  // NOTE: X, L, B all are stored in 1-byte columns (X by default has at least room for 8 bits)
     22  // I report these as type 'byte' as opposed to 'char', which is interpreted as a string
     23
    2124  *Nbytes = 0;
    2225  switch (*Fchar) {
    2326  case  'X':
    24     { *Nbytes = 1;  strcpy (type, "char");   *Nval = 1 + (int) Nv / 8; }
     27    { *Nbytes = 1;  strcpy (type, "byte");   *Nval = 1 + (int) Nv / 8; }
    2528    break;
    2629  case  'L':
    27     { *Nbytes = 1;  strcpy (type, "char");   *Nval = Nv;               }
     30    { *Nbytes = 1;  strcpy (type, "byte");   *Nval = Nv;               }
    2831    break;
    2932  case  'A':
     
    3134    break;
    3235  case  'B':
    33     { *Nbytes = 1;  strcpy (type, "char");   *Nval = Nv;               }
     36    { *Nbytes = 1;  strcpy (type, "byte");   *Nval = Nv;               }
    3437    break;
    3538  case  'I':
     
    268271    }
    269272
     273    // Does it make sense to scale 'char' data (as opposed to 'byte')?
    270274    if (!strcmp (type, "char"))   {
     275      for (j = 0; j < Ny; j++) {
     276        for (n = 0; n < Nval; n++) {
     277          tmpChar = (char *)&ftable[0].buffer[j*Nx + n*Nbytes + off];
     278          *tmpChar = *tmpChar * tscale + tzero;
     279        }
     280      }
     281    }
     282    if (!strcmp (type, "byte"))   {
    271283      for (j = 0; j < Ny; j++) {
    272284        for (n = 0; n < Nval; n++) {
     
    352364    }
    353365
     366    // does this make sense? (see note above)
    354367    if (!strcmp (type, "char"))   {
    355368      for (j = 0; j < Ny; j++) {
     
    360373      }
    361374    }
     375    if (!strcmp (type, "byte"))   {
     376      for (j = 0; j < Ny; j++) {
     377        for (n = 0; n < Nval; n++) {
     378          tmpChar = (char *)&ftable[0].buffer[j*Nx + n*Nbytes + off];
     379          *tmpChar = (*tmpChar - tzero) / tscale;
     380        }
     381      }
     382    }
    362383    if (!strcmp (type, "short"))   {
    363384      for (j = 0; j < Ny; j++) {
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libkapa/src/IOfuncs.c

    r35761 r37067  
    5454  va_end (argp);
    5555
    56   if (!Nbyte) return (FALSE);
     56  if (!Nbyte) {
     57    KiiSendCommand (device, 16, "LEN: %11d", 0);
     58    return (FALSE);
     59  }
    5760
    5861  /* the message may contain up to 99,999,999,999 bytes (100MB) */
     
    8487  /* find the message length, allocate space */
    8588  sscanf (buffer, "%*s %d", &Nbytes);
     89  if (Nbytes == 0) {
     90    return TRUE;
     91  }
     92
    8693  ALLOCATE (message, char, Nbytes + 1);
    8794  memset (message, 0, Nbytes + 1);
     95
    8896
    8997  /* read Nbytes from the device */
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libkapa/src/KapaOpen.c

    r35761 r37067  
    11# include "kapa_internal.h"
     2
     3// kapa connection timeout is N_RETRY * 10000 usec
     4# define N_RETRY 2000
    25
    36# define MY_PORT 2500
     
    912static int *VALID = NULL;
    1013
    11 char *_parse_nextword (char *string);
    1214int KapaLaunchCommand (char *line);
    1315
     
    218220  // apparently, I can connect on someone else's port (eg GoogleTalkPlugin)
    219221  // do a simple handshake before we set !NONBLOCK:
    220   char line[5];
    221   int Nout = read (InitSocket, line, 4);
    222   if (Nout != 4) {
    223     if (DEBUG) fprintf (stderr, "connection failed\n");
    224     close (InitSocket);
    225     return (-1);
    226   }
    227   if (strncmp (line, "KAPA", 4)) {
    228     if (DEBUG) fprintf (stderr, "connection to the wrong server\n");
    229     close (InitSocket);
    230     return (-1);
     222
     223  // ensure the socket is NONBLOCK first...
     224  fcntl (InitSocket, F_SETFL, O_NONBLOCK);
     225
     226  int Ntry = 0;
     227retry_message:
     228  {
     229    char line[5];
     230    int Nout = read (InitSocket, line, 4);
     231    if ((Nout == -1) && (errno == EAGAIN)) {
     232      Ntry ++;
     233      if (Ntry > 500) {
     234        if (DEBUG) fprintf (stderr, "handshake failure\n");
     235        close (InitSocket);
     236        return (-1);
     237      }
     238      usleep (10000);
     239      goto retry_message;
     240    }
     241    if (Nout != 4) {
     242      if (DEBUG) fprintf (stderr, "connection failed\n");
     243      close (InitSocket);
     244      return (-1);
     245    }
     246    if (strncmp (line, "KAPA", 4)) {
     247      if (DEBUG) fprintf (stderr, "connection to the wrong server\n");
     248      close (InitSocket);
     249      return (-1);
     250    }
    231251  }
    232252
     
    265285  }
    266286
    267 # define NTRY 500
     287  INITTIME;
     288
    268289  Ntry = 0;
    269   while (Ntry < NTRY) {
     290  while (Ntry < N_RETRY) {
    270291    sock = KapaClientSocket ("localhost");
    271292    if (sock != -1) break;
    272     // if (errno != EAGAIN) break;
    273     if (errno != ECONNREFUSED) break;
     293    if (errno != ECONNREFUSED) {
     294      perror ("KapaOpen");
     295      break;
     296    }
    274297    // no connection yet. try again, but first check
    275298    // if the kapa job has exited
     
    288311  }
    289312
    290   if (sock < 0) return (-1);
     313  if (sock < 0) {
     314    MARKTIME ("failed to connect to kapa after %f seconds\n", dtime);
     315    int killStatus = kill (pid, SIGKILL);
     316    if (killStatus) {
     317      perror ("failed to kill process");
     318    }
     319    int waitStatus = waitpid (pid, NULL, 0);
     320    if (waitStatus == pid) {
     321      fprintf (stderr, "harvested process %d\n", pid);
     322    } else if (waitStatus < 0) {
     323      fprintf (stderr, "failed to harvest process %d\n", pid);
     324    } else if (waitStatus == 0) {
     325      fprintf (stderr, "process not exited: %d\n", pid);
     326    } else {
     327      fprintf (stderr, "odd exit status: %d vs pid %d\n", waitStatus, pid);
     328    }
     329    return (-1);
     330  }
     331
    291332  return (sock);
    292333}
     
    330371  fcntl (InitSocket, F_SETFL, O_NONBLOCK);
    331372
    332 # define NTRY 500
     373  INITTIME;
     374
    333375  Ntry = 0;
    334   while (Ntry < NTRY) {
     376  while (Ntry < N_RETRY) {
    335377    fd = accept (InitSocket, (struct sockaddr *)&Address, &AddressLength);
    336378    if (fd != -1) break;
     
    352394  }
    353395
    354   if (fd < 0) return (-1);
     396  if (fd < 0) {
     397    MARKTIME ("failed to connect to kapa after %f seconds\n", dtime);
     398    kill (pid, SIGKILL);
     399    waitpid (pid, NULL, WNOHANG);
     400    return (-1);
     401  }
    355402
    356403  // the client uses a BLOCKing socket by default
     
    394441  done = FALSE;
    395442  while (!done) {
    396     q = _parse_nextword (p);
     443    q = parse_nextword (p);
    397444    if (q && *q) {
    398445      argv[i] = strncreate (p, q - p);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libkapa/src/KapaWindow.c

    r35761 r37067  
    100100  graphdata[0].coords.pc1_1 = graphdata[0].coords.pc2_2 = 1.0;
    101101  graphdata[0].coords.pc1_2 = graphdata[0].coords.pc2_1 = 0.0;
    102   strcpy (graphdata[0].coords.ctype, "RA---LIN");
     102  strcpy (graphdata[0].coords.ctype, "DEC--LIN");
    103103  graphdata[0].coords.crval1 = 0.0;
    104104  graphdata[0].coords.crval2 = 0.0;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libkapa/src/KiiPicture.c

    r34088 r37067  
    2121int KiiNewPicture1D (int fd, KiiImage *image, KapaImageData *data, Coords *coords) {
    2222
    23   int Nwrite, Npix, Ncolors, size;
     23  int Ncolors;
     24  off_t Nwrite, Npix, size;
    2425  float min, max;
    2526
     
    3637  KiiSendMessage (fd, "%8d %8d", image[0].Nx, image[0].Ny);
    3738  KiiSendMessage (fd, "%f %f %s %s", data[0].zero, data[0].range, data[0].name, data[0].file);
    38   KiiSendMessage (fd, "%f %f %d ", min, max, size);
     39  KiiSendMessage (fd, "%f %f "OFF_T_FMT" ", min, max, size);
    3940  KiiSendMessage (fd, "%f %f %g %g %g ", coords[0].crval1, coords[0].crpix1, coords[0].cdelt1, coords[0].pc1_1, coords[0].pc1_2);
    4041  KiiSendMessage (fd, "%f %f %g %g %g ", coords[0].crval2, coords[0].crpix2, coords[0].cdelt2, coords[0].pc2_1, coords[0].pc2_2);
     
    4243
    4344  /* send the image data */
    44   Nwrite = write (fd, image[0].data1d, size);
    45   if (Nwrite != size) {
    46     fprintf (stderr, "error sending picture to kapa\n");
    47     return (FALSE);
     45  off_t bytes_left = size;
     46  while (bytes_left > 0) {
     47    Nwrite = write (fd, image[0].data1d, bytes_left);
     48    if (Nwrite == 0) {
     49      fprintf (stderr, "unable to send more data to kapa?\n");
     50      return FALSE;
     51    }
     52    if (Nwrite < 0) {
     53      if (errno == EAGAIN) continue;
     54      if (errno == EWOULDBLOCK) continue;
     55      perror ("KiiNewPicture1D:");
     56      return FALSE;
     57    }
     58    bytes_left -= Nwrite;
    4859  }
    4960
     
    114125int KiiNewPicture2D (int fd, KiiImage *image, KapaImageData *data, Coords *coords) {
    115126
    116   int j;
    117   int Nwrite, Nbytes, Npix, Ncolors, size;
     127  int Ncolors;
     128  off_t j, Nwrite, Nbytes, Npix, size;
    118129  float min, max;
    119130
     
    130141  KiiSendMessage (fd, "%8d %8d", image[0].Nx, image[0].Ny);
    131142  KiiSendMessage (fd, "%f %f %s %s", data[0].zero, data[0].range, data[0].name, data[0].file);
    132   KiiSendMessage (fd, "%f %f %d ", min, max, size);
     143  KiiSendMessage (fd, "%f %f "OFF_T_FMT" ", min, max, size);
    133144  KiiSendMessage (fd, "%f %f %g %g %g ", coords[0].crval1, coords[0].crpix1, coords[0].cdelt1, coords[0].pc1_1, coords[0].pc1_2);
    134145  KiiSendMessage (fd, "%f %f %g %g %g ", coords[0].crval2, coords[0].crpix2, coords[0].cdelt2, coords[0].pc2_1, coords[0].pc2_2);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libkapa/src/bDrawFuncs.c

    r33956 r37067  
    247247  int i;
    248248
     249  if (Y <  0) return;
     250  if (Y >= buffer[0].Ny) return;
     251
    249252  for (i = X1; i < X2; i++) {
     253    if (i <  0) continue;
     254    if (i >= buffer[0].Nx) continue;
    250255    if (buffer[0].Nbyte == 1) {
    251256      buffer[0].pixels[Y][i] = buffer->bColor;
     
    263268  int i;
    264269
     270  if (X <  0) return;
     271  if (X >= buffer[0].Nx) return;
     272
    265273  for (i = Y1; i < Y2; i++) {
     274    if (i <  0) continue;
     275    if (i >= buffer[0].Ny) continue;
    266276    if (buffer[0].Nbyte == 1) {
    267277      buffer[0].pixels[i][X] = buffer->bColor;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libohana/include/ohana.h

    r35754 r37067  
    7171# endif
    7272
     73# define MARKTIME(MSG,...) {                    \
     74    gettimeofday (&stopTimer, (void *) NULL);   \
     75    float dtime = DTIME (stopTimer, startTimer);        \
     76    fprintf (stderr, MSG, __VA_ARGS__); }
     77
     78# define INITTIME \
     79  struct timeval startTimer, stopTimer; \
     80  gettimeofday (&startTimer, (void *) NULL);
     81
    7382#ifdef __GNUC__
    7483#define OHANA_FORMAT(style, fmt, varargs) __attribute__((format(style, fmt, varargs)))
     
    252261int     scan_line              PROTO((FILE *f, char *line));
    253262int     scan_line_maxlen       PROTO((FILE *f, char *line, int maxlen));
     263char   *parse_nextword         PROTO((char *string));
     264char   *parse_nextword_csv     PROTO((char *string));
    254265int     dparse                 PROTO((double *X, int NX, char *line));
    255266int     dparse_csv             PROTO((double *X, int NX, char *line));
    256267int     iparse                 PROTO((int *X, int NX, char *line));
    257268int     iparse_csv             PROTO((int *X, int NX, char *line));
     269int     charparse_csv          PROTO((char *X, int NX, char *line));
     270char   *ptrparse               PROTO((int NX, char *line));
     271char   *ptrparse_csv           PROTO((int NX, char *line));
    258272int     charparse_csv          PROTO((char *X, int NX, char *line));
    259273int     charparse              PROTO((char *X, int NX, char *line));
     
    266280char   *strip_version          PROTO((char *input));
    267281char   *strsubs                PROTO((char *string, char *match, char *with));
     282
     283char   *getword                PROTO((char *string));
     284char   *skipword               PROTO((char *string));
    268285
    269286/* in findexec.c */
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libohana/src

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libohana/src/gaussj.c

    r24080 r37067  
    11# include <ohana.h>
    22# define GROWTHTEST 0
    3 # define MAX_RANGE 1.0e7
     3# define MAX_RANGE 1.0e9
    44
    55// Gauss-Jordan elimination using full pivots based on Press et al's description.  Substantially
     
    9191    /* rescale by pivot reciprocal */
    9292    double tmpval = 1.0 / A[maxcol][maxcol];
     93    // XXX why is this here (don't I double count this element?) A[maxcol][maxcol] = 1.0;
    9394    A[maxcol][maxcol] = 1.0;
    9495    for (col = 0; col < N; col++) A[maxcol][col] *= tmpval;
     
    117118    }
    118119  }
     120
     121# if (GROWTHTEST)
     122    fprintf (stderr, "final A matrix:\n");
     123    for (row = 0; row < N; row++) {
     124        for (col = 0; col < N; col++) {
     125            fprintf (stderr, "%10.3e ", A[row][col]);
     126        }
     127        fprintf (stderr, "\n");
     128    }
     129    fprintf (stderr, "\n");
     130# endif
    119131
    120132  // swap back the inverse matrix based on the row swaps above
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/libohana/src/string.c

    r34753 r37067  
    167167}
    168168
    169 char *_parse_nextword (char *string) {
     169char *parse_nextword (char *string) {
    170170
    171171  if (string == (char *) NULL) return ((char *) NULL);
     
    182182// ,,, : go from , to , to , to 0
    183183
    184 char *_parse_nextword_csv (char *string) {
     184char *parse_nextword_csv (char *string) {
    185185
    186186  if (string == (char *) NULL) return ((char *) NULL);
     
    199199  word = line;
    200200  for (i = 0; i < NX - 1; i++)
    201     word = _parse_nextword (word);
     201    word = parse_nextword (word);
    202202
    203203  *X = strtod (word, &ptr);
     
    215215  word = line;
    216216  for (i = 0; i < NX - 1; i++)
    217     word = _parse_nextword_csv (word);
     217    word = parse_nextword_csv (word);
    218218 
    219219  if (word[0] == '"') word[0] = ' ';
     
    237237  word = line;
    238238  for (i = 0; i < NX - 1; i++)
    239     word = _parse_nextword (word);
     239    word = parse_nextword (word);
    240240
    241241  *X = strtol (word, &ptr, 0);
     
    253253  word = line;
    254254  for (i = 0; i < NX - 1; i++)
    255     word = _parse_nextword_csv (word);
     255    word = parse_nextword_csv (word);
    256256 
    257257  if (word[0] == '"') word[0] = ' ';
     
    274274  word = line;
    275275  for (i = 0; i < NX - 1; i++)
    276     word = _parse_nextword (word);
     276    word = parse_nextword (word);
    277277
    278278  *X = word[0];
     
    287287  word = line;
    288288  for (i = 0; i < NX - 1; i++)
    289     word = _parse_nextword_csv (word);
     289    word = parse_nextword_csv (word);
    290290 
    291291  if (word[0] == '"') word[0] = word[1];
     
    299299}
    300300
     301// return a pointer to the start of the desired field
     302char *ptrparse (int NX, char *line) {
     303
     304  int i;
     305  char *word;
     306
     307  word = line;
     308  for (i = 0; i < NX - 1; i++) {
     309    word = parse_nextword (word);
     310  }
     311  return word;
     312}
     313
     314char *ptrparse_csv (int NX, char *line) {
     315
     316  int i;
     317  char *word;
     318
     319  word = line;
     320  for (i = 0; i < NX - 1; i++)
     321    word = parse_nextword_csv (word);
     322 
     323  if (word[0] == '"') word ++;
     324  if (word[0] == ',') return NULL;
     325  return word;
     326}
     327
    301328int tparse (time_t *X, int NX, char *line) {
    302329
     
    306333  word = line;
    307334  for (i = 0; i < NX - 1; i++)
    308     word = _parse_nextword (word);
     335    word = parse_nextword (word);
    309336
    310337  status = ohana_str_to_time (word, X);
     
    320347  word = line;
    321348  for (i = 0; i < NX - 1; i++)
    322     word = _parse_nextword_csv (word);
     349    word = parse_nextword_csv (word);
    323350 
    324351  if (word[0] == '"') word[0] = ' ';
     
    341368  word = line;
    342369  for (i = 0; i < NX - 1; i++)
    343     word = _parse_nextword (word);
     370    word = parse_nextword (word);
    344371
    345372  *X = strtod (word, &ptr);
     
    402429  return (q);
    403430}
     431
     432// return a newly allocated string containing the first complete set of non-whitespace
     433char *getword (char *string) {
     434
     435  int i, j;
     436  char *word;
     437
     438  if (!string) return (NULL);
     439
     440  // find the end of the whitespace (is there any non-whitespace?)
     441  for (i = 0; OHANA_WHITESPACE (string[i]); i++);
     442  if (!string[i]) return (NULL);
     443
     444  for (j = i; string[j] && !OHANA_WHITESPACE(string[j]); j++);
     445  word = strncreate (&string[i], j - i);
     446  return (word);
     447}
     448
     449// returns a pointer to the next word, or NULL if there is not a next word
     450char *skipword (char *string) {
     451
     452  int i;
     453
     454  if (!string) return (NULL);
     455
     456  // find the end of the whitespace (is there any non-whitespace?)
     457  for (i = 0; OHANA_WHITESPACE (string[i]); i++);
     458  if (!string[i]) return (NULL);
     459
     460  // find the end of the non-whitespace (this word)
     461  while (string[i] && !OHANA_WHITESPACE(string[i])) i++;
     462
     463  // find the end of the following whitespace
     464  while (string[i] &&  OHANA_WHITESPACE(string[i])) i++;
     465  if (!string[i]) return (NULL);
     466
     467  return (&string[i]);
     468}
     469
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/markrock/src/gcatstats.c

    r27435 r37067  
    4040  catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
    4141  catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
    42   strcpy (catstats[0].coords.ctype, "RA---TAN");
     42  strcpy (catstats[0].coords.ctype, "DEC--TAN");
    4343
    4444  X1 = catstats[0].X;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/markstar/src/gcatstats.c

    r27435 r37067  
    5050  catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
    5151  catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
    52   strcpy (catstats[0].coords.ctype, "RA---TAN");
     52  strcpy (catstats[0].coords.ctype, "DEC--TAN");
    5353
    5454  X1 = catstats[0].X;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/mosastro/src/warptest.c

    r3323 r37067  
    1515
    1616  /* bore site center guess */
    17   sprintf (coords.ctype, "RA---%s", argv[1]);
     17  sprintf (coords.ctype, "DEC--%s", argv[1]);
    1818  coords.crval1 = 0.0;
    1919  coords.crval2 = 0.0;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.astro

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.astro/Makefile

    r35416 r37067  
    2828$(SRC)/cval.$(ARCH).o              \
    2929$(SRC)/czplot.$(ARCH).o    \
     30$(SRC)/cdensify.$(ARCH).o          \
    3031$(SRC)/drizzle.$(ARCH).o           \
    3132$(SRC)/flux.$(ARCH).o              \
    3233$(SRC)/fitplx.$(ARCH).o    \
     34$(SRC)/fitpm.$(ARCH).o     \
    3335$(SRC)/fixwrap.$(ARCH).o           \
    3436$(SRC)/fixcols.$(ARCH).o           \
     
    6062$(SRC)/scale.$(ARCH).o             \
    6163$(SRC)/sexigesimal.$(ARCH).o       \
     64$(SRC)/sersic.$(ARCH).o    \
    6265$(SRC)/spec.$(ARCH).o              \
    6366$(SRC)/specpairfit.$(ARCH).o       \
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.astro/fitplx.c

    r35416 r37067  
    4141    remove_argument (N, &argc, argv);
    4242    VERBOSE = TRUE;
     43  }
     44  if ((N = get_argument (argc, argv, "-vv"))) {
     45    remove_argument (N, &argc, argv);
     46    VERBOSE = 2;
    4347  }
    4448
     
    108112  coords.pc1_2  = coords.pc2_1 = 0.0;
    109113  coords.Npolyterms = 1;
    110   strcpy (coords.ctype, "RA---SIN");
     114  strcpy (coords.ctype, "DEC--SIN");
    111115
    112116  double *X, *Y, *t, *pX, *pY, *dX, *dY;
     
    145149
    146150  PlxFit fit;
    147   FitPMandPar (&fit, X, dX, Y, dY, t, pX, pY, n, VERBOSE);
     151  if (!FitPMandPar (&fit, X, dX, Y, dY, t, pX, pY, n, VERBOSE)) {
     152    return FALSE;
     153  }
    148154
    149155  // fprintf (stderr, "Roff, Doff: %f, %f; dRo, dDo: %f, %f\n", fit.Ro, fit.Do, fit.dRo, fit.dDo);
     
    204210  for (i = 0; i < Npts; i++) {
    205211
    206     if (VERBOSE) fprintf (stderr, "%f %f : %f %f : %f : %f %f\n", X[i], dX[i], Y[i], dY[i], T[i], pR[i], pD[i]);
     212    if (VERBOSE == 2) fprintf (stderr, "%f %f : %f %f : %f : %f %f\n", X[i], dX[i], Y[i], dY[i], T[i], pR[i], pD[i]);
    207213
    208214    /* handle case where dX or dY = 0.0 */
    209     wx = 1.0 / SQ(dX[i]);
    210     wy = 1.0 / SQ(dY[i]);
     215    wx = (fabs(dX[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dX[i]);
     216    wy = (fabs(dY[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dY[i]);
    211217
    212218    Wx += wx;
     
    266272  B[4][0] = PRX + PDY;
    267273
    268   dgaussjordan ((double **)A, (double **)B, 5, 1);
     274  if (!dgaussjordan ((double **)A, (double **)B, 5, 1)) {
     275    if (VERBOSE) fprintf (stderr, "error in fit\n");
     276    if (VERBOSE == 2) {
     277      int j;
     278      for (i = 0; i < 5; i++) {
     279        for (j = 0; j < 5; j++) {
     280          fprintf (stderr, "%e ", A[i][j]);
     281        }
     282        fprintf (stderr, " : %e\n", A[i][0]);
     283      }
     284    }
     285    return FALSE;
     286  }
    269287
    270288  fit[0].Ro = B[0][0];
     
    285303    Xf = fit[0].Ro + fit[0].uR*T[i] + fit[0].p*pR[i];
    286304    Yf = fit[0].Do + fit[0].uD*T[i] + fit[0].p*pD[i];
    287     chisq += SQ(X[i] - Xf) / SQ(dX[i]);
    288     chisq += SQ(Y[i] - Yf) / SQ(dY[i]);
    289     if (VERBOSE) fprintf (stderr, "chisq contrib : %f %f : %f %f : %f %f : %f %f : %f\n", Xf, Yf, X[i] - Xf, Y[i] - Yf, dX[i], dY[i], (X[i] - Xf) / dX[i], (Y[i] - Yf) / dY[i], chisq);
     305    wx = (fabs(dX[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dX[i]);
     306    wy = (fabs(dY[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dY[i]);
     307    chisq += SQ(X[i] - Xf) * wx;
     308    chisq += SQ(Y[i] - Yf) * wy;
     309    // if (VERBOSE) fprintf (stderr, "chisq contrib : %f %f : %f %f : %f %f : %f %f : %f\n", Xf, Yf, X[i] - Xf, Y[i] - Yf, dX[i], dY[i], (X[i] - Xf) / dX[i], (Y[i] - Yf) / dY[i], chisq);
    290310  }
    291311  fit[0].Nfit = Npts;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.astro/gauss.c

    r34088 r37067  
    1010  Buffer *buf;
    1111  KapaImageData data;
     12  int VERBOSE;
     13
     14  VERBOSE = TRUE;
     15  if ((N = get_argument (argc, argv, "-q"))) {
     16    VERBOSE = FALSE;
     17    remove_argument (N, &argc, argv);
     18  }
     19  if ((N = get_argument (argc, argv, "-quiet"))) {
     20    VERBOSE = FALSE;
     21    remove_argument (N, &argc, argv);
     22  }
    1223
    1324  name = NULL;
     
    5869    KiiCursorRead (kapa, &X, &Y, &ZP, &RA, &DEC, key);
    5970    if (!strcasecmp (key, "Q")) break;
    60     get_aperture_stats (&buf[0].matrix, (int)(X+0.5), (int)(Y+0.5), Npix, Nborder, max);
     71    get_aperture_stats (&buf[0].matrix, (int)(X+0.5), (int)(Y+0.5), Npix, Nborder, max, VERBOSE);
    6172  }
    6273  KiiCursorOff (kapa);
     
    6475}
    6576
     77
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.astro/init.c

    r35757 r37067  
    1313int czplot                  PROTO((int, char **));
    1414int czcplot                 PROTO((int, char **));
     15int cdensify                PROTO((int, char **));
    1516int drizzle                 PROTO((int, char **));
    1617int flux                    PROTO((int, char **));
    1718int fitplx                  PROTO((int, char **));
     19int fitpm                   PROTO((int, char **));
    1820int fixwrap                 PROTO((int, char **));
    1921int fiximage                PROTO((int, char **));
     
    4951int scale                   PROTO((int, char **));
    5052int sexigesimal             PROTO((int, char **));
     53int sersic                  PROTO((int, char **));
    5154int spec                    PROTO((int, char **));
    5255int specpairfit             PROTO((int, char **));
     
    7275  {1, "czplot",      czplot,       "plot scaled vectors in sky coordinates"},
    7376  {1, "czcplot",     czcplot,      "plot color-scaled vectors in sky coordinates"},
     77  {1, "cdensify",    cdensify,      "vectors to density history on projection"},
    7478  {1, "drizzle",     drizzle,      "transform image to image"},
    7579  {1, "flux",        flux,         "flux in a convex contour"},
    7680  {1, "fitplx",      fitplx,       "fit proper motion and parallax"},
     81  {1, "fitpm",       fitpm,        "fit proper motion only"},
    7782  {1, "fixwrap",     fixwrap,      "fix megacam over-wrapped pixels"},
    7883  {1, "fiximage",    fiximage,     "fix pixels in an image by interpolation"},
     
    107112  {1, "scale",       scale,        "get / set real bzero / bscale values"},
    108113  {1, "sexigesimal", sexigesimal,  "convert to/from sexigesimal/decimal"},
     114  {1, "sersic",      sersic,       "generate sub-pixel resolved sersic model"},
    109115  {1, "spec",        spec,         "extract a spectrum"},
    110116  {1, "specpairfit", specpairfit,  "fit spectrum to another spectrum"},
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.astro/region.c

    r31160 r37067  
    8080  if (!ohana_str_to_radec (&Ra, &Dec, argv[1], argv[2])) return (FALSE);
    8181  Radius = atof (argv[3]);
    82   strcpy (graphmode.coords.ctype, "RA---TAN");
     82  strcpy (graphmode.coords.ctype, "DEC--TAN");
    8383  if (argc == 5) {
    8484    if (!strcasecmp (argv[4], "TAN"))
    85       strcpy (graphmode.coords.ctype, "RA---TAN");
     85      strcpy (graphmode.coords.ctype, "DEC--TAN");
    8686    if (!strcasecmp (argv[4], "SIN"))
    87       strcpy (graphmode.coords.ctype, "RA---SIN");
     87      strcpy (graphmode.coords.ctype, "DEC--SIN");
    8888    if (!strcasecmp (argv[4], "ARC"))
    89       strcpy (graphmode.coords.ctype, "RA---ARC");
     89      strcpy (graphmode.coords.ctype, "DEC--ARC");
    9090    if (!strcasecmp (argv[4], "STG"))
    91       strcpy (graphmode.coords.ctype, "RA---STG");
     91      strcpy (graphmode.coords.ctype, "DEC--STG");
    9292    if (!strcasecmp (argv[4], "ZEA"))
    93       strcpy (graphmode.coords.ctype, "RA---ZEA");
     93      strcpy (graphmode.coords.ctype, "DEC--ZEA");
    9494    if (!strcasecmp (argv[4], "AIT"))
    95       strcpy (graphmode.coords.ctype, "RA---AIT");
     95      strcpy (graphmode.coords.ctype, "DEC--AIT");
    9696    if (!strcasecmp (argv[4], "GLS"))
    97       strcpy (graphmode.coords.ctype, "RA---GLS");
     97      strcpy (graphmode.coords.ctype, "DEC--GLS");
    9898    if (!strcasecmp (argv[4], "PAR"))
    99       strcpy (graphmode.coords.ctype, "RA---PAR");
     99      strcpy (graphmode.coords.ctype, "DEC--PAR");
    100100  }
    101101
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.astro/star.c

    r34088 r37067  
    66  double max;
    77  Buffer *buf;
     8  int VERBOSE;
     9
     10  VERBOSE = TRUE;
     11  if ((N = get_argument (argc, argv, "-q"))) {
     12    VERBOSE = FALSE;
     13    remove_argument (N, &argc, argv);
     14  }
     15  if ((N = get_argument (argc, argv, "-quiet"))) {
     16    VERBOSE = FALSE;
     17    remove_argument (N, &argc, argv);
     18  }
    819
    920  Nborder = 3;
     
    3647  }
    3748
    38   get_aperture_stats (&buf[0].matrix, x, y, dx, Nborder, max);
     49  get_aperture_stats (&buf[0].matrix, x, y, dx, Nborder, max, VERBOSE);
    3950 
    4051  return (TRUE);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.basic/Makefile

    r35237 r37067  
    5555$(SRC)/substr.$(ARCH).o     \
    5656$(SRC)/strhash.$(ARCH).o     \
     57$(SRC)/strmatch.$(ARCH).o     \
    5758$(SRC)/strpop.$(ARCH).o     \
    5859$(SRC)/strsub.$(ARCH).o     \
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.basic/init.c

    r35237 r37067  
    4040int fprintf_opihi   PROTO((int, char **));
    4141int strlen_func     PROTO((int, char **));
     42int strmatch        PROTO((int, char **));
    4243int substr_func     PROTO((int, char **));
    4344int strpop          PROTO((int, char **));
     
    9798  {1, "strpop",        strpop,             "pop a string"},
    9899  {1, "strsub",        strsub,             "replace instances of a key in a string"},
     100  {1, "strmatch",      strmatch,           "string length"},
    99101  {1, "wait",          wait_func,          "wait until return is typed"},
    100102  {1, "which",         which,              "show command *"}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.basic/list.c

    r33662 r37067  
    2121  }
    2222
     23  int EXCEL_STYLE = FALSE;
     24  if ((N = get_argument (argc, argv, "-excel-style"))) {
     25    remove_argument (N, &argc, argv);
     26    EXCEL_STYLE = TRUE;
     27  }
     28  if ((N = get_argument (argc, argv, "-excel"))) {
     29    remove_argument (N, &argc, argv);
     30    EXCEL_STYLE = TRUE;
     31  }
     32
    2333  if ((N = get_argument (argc, argv, "-vectors"))) {
    2434    remove_argument (N, &argc, argv);
     
    4959   
    5060    for (i = 0; i < argc - 3; i++) {
    51       sprintf (line, "%s:%d", argv[1], i);
     61      set_list_varname (line, argv[1], i, EXCEL_STYLE);
    5262      set_str_variable (line, argv[i+3]);
    5363    }
     
    8393        if (!word) break;
    8494       
    85         sprintf (line, "%s:%d", argv[1], nWords);
     95        // sprintf (line, "%s:%d", argv[1], nWords);
     96        set_list_varname (line, argv[1], nWords, EXCEL_STYLE);
     97
    8698        set_str_variable (line, word);
    8799        FREE (word);
     
    120132      sprintf (line, "%s:%d", argv[3], i);
    121133      value = get_variable (line);
    122       sprintf (line, "%s:%d", argv[1], i);
     134      // sprintf (line, "%s:%d", argv[1], i);
     135      set_list_varname (line, argv[1], i, EXCEL_STYLE);
    123136      set_str_variable (line, value);
    124137    }
     
    136149    N = get_int_variable (line, &found);
    137150    for (i = 0; i < argc - 3; i++) {
    138       sprintf (line, "%s:%d", argv[1], N + i);
     151      // sprintf (line, "%s:%d", argv[1], N + i);
     152      set_list_varname (line, argv[1], N + i, EXCEL_STYLE);
    139153      set_str_variable (line, argv[i+3]);
    140154    }
     
    159173    N = get_int_variable (line, &found);
    160174    for (i = 0; i < N; i++) {
    161       sprintf (line, "%s:%d", argv[1], i);
     175      // sprintf (line, "%s:%d", argv[1], i);
     176      set_list_varname (line, argv[1], i, EXCEL_STYLE);
    162177      value = get_variable (line);
    163178      if (value == NULL) continue;
     
    165180        free (value);
    166181        for (j = i + 1; j < N; j++) {
    167           sprintf (line2, "%s:%d", argv[1], j);
     182          // sprintf (line2, "%s:%d", argv[1], j);
     183          set_list_varname (line2, argv[1], j, EXCEL_STYLE);
    168184          next_value = get_variable (line2);
    169185          set_str_variable (line, next_value);
     
    235251      if (B != (char *) NULL) { *B = 0; }
    236252      if (*A != 0) {
    237         sprintf (line, "%s:%d", argv[1], i);
     253        // sprintf (line, "%s:%d", argv[1], i);
     254        set_list_varname (line, argv[1], i, EXCEL_STYLE);
    238255        set_str_variable (line, A);
    239256        A = B + 1;
     
    283300
    284301    if (*input) {
    285       sprintf (line, "%s:%d", argv[1], i);
     302      // sprintf (line, "%s:%d", argv[1], i);
     303      set_list_varname (line, argv[1], i, EXCEL_STYLE);
    286304      set_str_variable (line, input);
    287305      free (input);
    288306      i++;
    289    }
     307    }
    290308  }
    291309  return (TRUE);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.data

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.data/Makefile

    r35416 r37067  
    2525$(SRC)/book.$(ARCH).o           \
    2626$(SRC)/book_commands.$(ARCH).o  \
     27$(SRC)/cast.$(ARCH).o           \
    2728$(SRC)/center.$(ARCH).o \
    2829$(SRC)/clear.$(ARCH).o          \
     
    6364$(SRC)/imcut.$(ARCH).o          \
    6465$(SRC)/imhist.$(ARCH).o \
     66$(SRC)/impeaks.$(ARCH).o        \
    6567$(SRC)/imsmooth.$(ARCH).o       \
     68$(SRC)/imsmooth.generic.$(ARCH).o       \
     69$(SRC)/imsmooth.2d.$(ARCH).o    \
    6670$(SRC)/integrate.$(ARCH).o      \
    6771$(SRC)/interpolate.$(ARCH).o    \
     72$(SRC)/join.$(ARCH).o           \
    6873$(SRC)/jpeg.$(ARCH).o           \
    6974$(SRC)/kern.$(ARCH).o           \
     
    8489$(SRC)/mget.$(ARCH).o           \
    8590$(SRC)/minterpolate.$(ARCH).o   \
     91$(SRC)/medimage.$(ARCH).o       \
     92$(SRC)/medimage_commands.$(ARCH).o \
    8693$(SRC)/mset.$(ARCH).o           \
    8794$(SRC)/peak.$(ARCH).o           \
     
    9198$(SRC)/point.$(ARCH).o          \
    9299$(SRC)/ps.$(ARCH).o             \
     100$(SRC)/print_vectors.$(ARCH).o  \
    93101$(SRC)/queuedelete.$(ARCH).o    \
    94102$(SRC)/queuedrop.$(ARCH).o      \
     
    143151$(SRC)/vmaxwell.$(ARCH).o          \
    144152$(SRC)/vgrid.$(ARCH).o             \
     153$(SRC)/vlist.$(ARCH).o             \
    145154$(SRC)/vload.$(ARCH).o             \
    146155$(SRC)/vzload.$(ARCH).o            \
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.data/densify.c

    r34088 r37067  
    22
    33# define CHECKVAL(ARG) if (!isfinite(ARG)) { gprint (GP_ERR, "illegal value for %s: %f\n", #ARG, ARG); return (FALSE); }
     4enum {IS_DOT, IS_SQUARE, IS_CIRCLE, IS_GAUSS};
    45
    56int densify (int argc, char **argv) {
    67
    7   int i, Nx, Ny, Xb, Yb, N, Xpix, Ypix, good, UseGraph;
     8  int i, Nx, Ny, Xb, Yb, ix, iy, N, Xpix, Ypix, good, UseGraph;
    89  double Xmin, Xmax, dX, Ymin, Ymax, dY;
    910  float *val;
     
    2425  }
    2526
     27  float scale = 0.0;
     28  if ((N = get_argument (argc, argv, "-scale"))) {
     29    remove_argument (N, &argc, argv);
     30    scale = atof(argv[N]);
     31    remove_argument (N, &argc, argv);
     32  }
     33
     34  int PSFTYPE = IS_DOT;
     35  if ((N = get_argument (argc, argv, "-psf"))) {
     36    remove_argument (N, &argc, argv);
     37    if (!strcasecmp(argv[N], "dot"))    PSFTYPE = IS_DOT;
     38    if (!strcasecmp(argv[N], "square")) PSFTYPE = IS_SQUARE;
     39    if (!strcasecmp(argv[N], "circle")) PSFTYPE = IS_CIRCLE;
     40    if (!strcasecmp(argv[N], "gauss"))  PSFTYPE = IS_GAUSS;
     41    remove_argument (N, &argc, argv);
     42  }
     43
    2644  good = UseGraph ? (argc == 4) : (argc == 10);
    2745  if (!good) {
    2846    gprint (GP_ERR, "USAGE: densify buffer x y Xmin Xmax dX Ymin Ymax dY\n");
    2947    gprint (GP_ERR, "   OR: densify buffer x y -graph\n");
     48    gprint (GP_ERR, " option: -psf [dot] (circle) (square) (gauss)\n");
    3049    return (FALSE);
    3150  }
     
    6988  CHECKVAL(dY);
    7089
     90  float scaleX = (scale > 0.0) ? scale / dX : 3.0;
     91  float scaleY = (scale > 0.0) ? scale / dY : 3.0;
     92
    7193  Nx = (Xmax - Xmin) / dX + 1;
    7294  Ny = (Ymax - Ymin) / dY + 1;
     
    7698  CreateBuffer (bf, Nx, Ny, -32, 0.0, 1.0);
    7799  strcpy (bf[0].file, "(empty)");
     100 
     101  float scale2 = (scaleX + 1.0) * (scaleY + 1.0);
     102  float fSquare = 1.0 / scale2;
     103  float fCircle = 1.0 / (3.141592 * scale2);
     104  float fSigma  = 0.5 / scale2;
     105  float fGauss  = 1.0 / (2.0 * 3.141592 * scale2);
    78106
    79107  x = vx[0].elements.Flt;
     
    83111    Xb = (*x - Xmin) / dX;
    84112    Yb = (*y - Ymin) / dY;
    85     if (Xb >= Nx) continue;
    86     if (Yb >= Ny) continue;
    87     if (Xb < 0) continue;
    88     if (Yb < 0) continue;
    89     val[Xb + Yb*Nx] ++;
     113    switch (PSFTYPE) {
     114      case IS_DOT:
     115        if (Xb >= Nx) continue;
     116        if (Yb >= Ny) continue;
     117        if (Xb < 0) continue;
     118        if (Yb < 0) continue;
     119        val[Xb + Yb*Nx] ++;
     120        break;
     121      case IS_SQUARE:
     122        for (ix = Xb - scaleX; ix <= Xb + scaleX; ix++) {
     123          for (iy = Yb - scaleY; iy <= Yb + scaleY; iy++) {
     124            if (ix >= Nx) continue;
     125            if (iy >= Ny) continue;
     126            if (ix < 0) continue;
     127            if (iy < 0) continue;
     128            val[ix + iy*Nx] += fSquare;
     129          }
     130        }
     131        break;
     132      case IS_CIRCLE:
     133        for (ix = Xb - scaleX; ix <= Xb + scaleX; ix++) {
     134          float dX = ix - Xb;
     135          for (iy = Yb - scaleY; iy <= Yb + scaleY; iy++) {
     136            float dY = iy - Yb;
     137            float r2 = dX*dX + dY*dY;
     138            if (r2 > 9) continue;
     139            if (ix >= Nx) continue;
     140            if (iy >= Ny) continue;
     141            if (ix < 0) continue;
     142            if (iy < 0) continue;
     143            val[ix + iy*Nx] += fCircle;
     144          }
     145        }
     146        break;
     147      case IS_GAUSS:
     148        for (ix = Xb - scaleX; ix <= Xb + scaleX; ix++) {
     149          float dX = ix - Xb;
     150          for (iy = Yb - scaleY; iy <= Yb + scaleY; iy++) {
     151            float dY = iy - Yb;
     152            float r2 = dX*dX + dY*dY;
     153            if (ix >= Nx) continue;
     154            if (iy >= Ny) continue;
     155            if (ix < 0) continue;
     156            if (iy < 0) continue;
     157            val[ix + iy*Nx] += fGauss*exp(-fSigma*r2);
     158          }
     159        }
     160        break;
     161    }
    90162  }
    91163  return (TRUE);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.data/init.c

    r35416 r37067  
    1010int center           PROTO((int, char **));
    1111int parity           PROTO((int, char **));
     12int cast             PROTO((int, char **));
    1213int circstats        PROTO((int, char **));
    1314int clear            PROTO((int, char **));
     
    5253int imcut            PROTO((int, char **));
    5354int imhist           PROTO((int, char **));
     55int impeaks          PROTO((int, char **));
    5456int imsmooth         PROTO((int, char **));
     57int imsmooth_generic PROTO((int, char **));
     58int imsmooth_2d      PROTO((int, char **));
    5559int integrate        PROTO((int, char **));
    5660int interpolate      PROTO((int, char **));
     61int join             PROTO((int, char **));
    5762int jpeg             PROTO((int, char **));
    5863int kern             PROTO((int, char **));
     
    7479int mget             PROTO((int, char **));
    7580int minterp          PROTO((int, char **));
     81int medimage_command PROTO((int, char **));
    7682int mset             PROTO((int, char **));
    7783int peak             PROTO((int, char **));
     
    8187int point            PROTO((int, char **));
    8288int ps               PROTO((int, char **));
     89int print_vectors    PROTO((int, char **));
    8390int queuelist        PROTO((int, char **));
    8491int queueload        PROTO((int, char **));
     
    133140int vmaxwell         PROTO((int, char **));
    134141int vload            PROTO((int, char **));
     142int vlist            PROTO((int, char **));
    135143int vzload           PROTO((int, char **));
    136144int vstats           PROTO((int, char **));
     
    160168  {1, "buffers",      list_buffers,     "list the currently allocated buffers (images)"},
    161169  {1, "center",       center,           "center image on coords"},
     170  {1, "cast",         cast,             "cast input vector to specified type"},
    162171  {1, "circstats",    circstats,        "circular statistics"},
    163172  {1, "clear",        clear,            "erase plot"},
     
    205214  {1, "imcut",        imcut,            "linear image cut between arbitrary coords"},
    206215  {1, "imhistogram",  imhist,           "histogram of an image region"},
     216  {1, "impeaks",      impeaks,          "find peaks in an image (return vectors)"},
    207217  {1, "imsmooth",     imsmooth,         "circular gaussian smoothing"},
     218  {1, "imsmooth.generic", imsmooth_generic, "circular non-gaussian smoothing"},
     219  {1, "imsmooth.2d",  imsmooth_2d,      "circular non-gaussian smoothing"},
    208220  {1, "imstats",      imstats,          "statistics on a portion of an image"},
    209221  {1, "integrate",    integrate,        "integrate a vector"},
    210222  {1, "interpolate",  interpolate,      "interpolate between vector pairs"},
     223  {1, "join",         join,             "find the join of two ID vectors"},
    211224  {1, "jpeg",         jpeg,             "convert display image to JPEG"},
    212225  {1, "kern",         kern,             "convolve with 3x3 kernel"},
     
    224237  {1, "minterp",      minterp,          "interpolate image pixels"},
    225238  {1, "iminterp",     minterp,          "interpolate image pixels"},
     239  {1, "medimage",     medimage_command, "median image manipulation"},
    226240  {1, "matrix",       matrix,           "matrix math operations"},
    227241  {1, "match2d",      match2d,          "match 2 pairs of X,Y vectors and return matched indexes"},
     
    237251  {1, "ppm",          jpeg,             "convert display graphic to PPM"},
    238252  {1, "ps",           ps,               "convert display to PostScript"},
     253  {1, "print_vectors", print_vectors,   "print a set of vectors"},
    239254  {1, "queuedelete",  queuedelete,      "delete a queue"},
    240255  {1, "queuedrop",    queuedrop,        "drop values from queue matching a key"},
     
    290305  {1, "vgrid",        vgrid,            "generate an image from a triplet of vectors"},
    291306  {1, "vhistogram",   histogram,        "generate histogram from vector"},
     307  {1, "vlist",        vlist,            "append values to a vector from command line"},
    292308  {1, "vload",        vload,            "load vectors as overlay on image display"},
    293309  {1, "vmaxwell",     vmaxwell,         "fit a Maxwellian to a vector"},
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.data/match2d.c

    r33963 r37067  
    1414  Vector *index1, *index2;
    1515
     16  if ((N = get_argument (argc, argv, "-h"))) goto usage;
     17  if ((N = get_argument (argc, argv, "--help"))) goto usage;
     18
    1619  CLOSEST = FALSE;
    1720  if ((N = get_argument (argc, argv, "-closest"))) {
     
    3841  if (argc != 6) {
    3942    gprint (GP_ERR, "USAGE: match2d X1 Y1 X2 Y2 Radius [-index1 (index1)] [-index2 (index2)] [-closest]\n");
    40     gprint (GP_ERR, "  if -closest is provided, index1 & index2 will have the same length as X1 and X2 (respectively)\n");
    41     gprint (GP_ERR, "    with either the index of the match or a value of -1 for non-matches\n");
     43    gprint (GP_ERR, "  use -h or --help for more detail\n");
    4244    return (FALSE);
    4345  }
     
    9092
    9193  return (TRUE);
     94
     95usage:
     96  gprint (GP_ERR, "we have two modes of operation:\n\n");
     97
     98  gprint (GP_ERR, "without -closest, we are finding all matched pairs within the match radius.  in this\n");
     99  gprint (GP_ERR, "case, the two index vectors have the same length, one entry per matched pair.\n");
     100  gprint (GP_ERR, "x1[index1],y1[index1] matches to x2[index2],y2[index2].\n\n");
     101
     102  gprint (GP_ERR, "with -closest selected, we are finding the closest element of set 1 to each of set 2\n");
     103  gprint (GP_ERR, "and vice versa.  in this case, index1 is always the same length as x1,y1, while index2\n");
     104  gprint (GP_ERR, "is the same lengths as x2,y2.  x2[index1],y2[index1] matches x1,y1 while\n");
     105  gprint (GP_ERR, "x1[index2],y1[index2] matches x2,y2\n\n");
     106
     107  gprint (GP_ERR, "if -index1 or -index2 is not supplied, the vectors are created with names index1 or index2\n");
     108  gprint (GP_ERR, "use 'reindex' to generate new vectors based on these index vectors\n");
     109
     110  return FALSE;
    92111}
    93112
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.data/read_vectors.c

    r34753 r37067  
    33FILE *f = (FILE *) NULL;
    44char filename[2048];
     5
     6void read_vectors_cleanup ();
    57
    68int datafile (int argc, char **argv) {
     
    2426enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME, COLTYPE_CHAR};
    2527
     28static int      Nvec     = 0;
     29static Vector **vec      = NULL;
     30static char   **listname = NULL;
     31static int     *col      = NULL;
     32static int     *coltype  = NULL;
     33static char    *buffer   = NULL;
     34
    2635int read_vectors (int argc, char **argv) {
    2736 
    2837  int TimeFormat;
    2938  time_t TimeReference;
    30   int i, j, Nskip, Narg, Nvec, *col, IsCSV, VERBOSE;
    31   int Nbytes, Nstart, NELEM, Nelem, nread, *coltype;
     39  int i, j, Nskip, Narg, IsCSV, VERBOSE;
     40  int Nbytes, Nstart, NELEM, Nelem, nread;
    3241  char *colstr, *c0, *c1, *extname;
    33   Vector **vec;
    34 
    35   char *buffer = NULL;
     42  char varname[1024];  // used as a buffer for the names of string fields
    3643
    3744  /* auto-sense table type */
     
    8188
    8289  Nvec = (argc - 1) / 2;
     90  ALLOCATE (listname, char *, Nvec);
    8391  ALLOCATE (vec, Vector *, Nvec);
    8492  ALLOCATE (col, int, Nvec);
    8593  ALLOCATE (coltype, int, Nvec);
     94  for (i = 0; i < Nvec; i++) {
     95    listname[i] = NULL;
     96    vec[i] = NULL;
     97  }
    8698
    8799  for (i = 0; i < Nvec; i++) {
     
    108120    }
    109121
    110     if ((vec[i] = SelectVector (argv[2*i + 1], ANYVECTOR, TRUE)) == NULL) {
    111       gprint (GP_ERR, "USAGE: read name N name N ...\n");
    112       free (vec);
    113       free (col);
    114       return (FALSE);   
     122    if (coltype[i] == COLTYPE_CHAR) {
     123      listname[i] = strcreate (argv[2*i + 1]);
     124    } else {
     125      if ((vec[i] = SelectVector (argv[2*i + 1], ANYVECTOR, TRUE)) == NULL) {
     126        gprint (GP_ERR, "USAGE: read name N name N ...\n");
     127        read_vectors_cleanup();
     128        return (FALSE);   
     129      }
    115130    }
    116131
     
    137152    bad_colname:
    138153      gprint (GP_ERR, "USAGE: read name N name N ...\n");
    139       free (vec);
    140       free (col);
     154      read_vectors_cleanup();
    141155      return (FALSE);   
    142156    }
     
    146160  NELEM = 1000;
    147161  for (i = 0; i < Nvec; i++) {
    148     if ((coltype[i] == COLTYPE_INT) || (coltype[i] == COLTYPE_CHAR)) {
    149       ResetVector (vec[i], OPIHI_INT, NELEM);
    150     } else {
    151       // note that COLTYPE_TIME is a type of float
    152       ResetVector (vec[i], OPIHI_FLT, NELEM);
     162    switch (coltype[i]) {
     163      case COLTYPE_INT:
     164        ResetVector (vec[i], OPIHI_INT, NELEM);
     165        break;
     166      case COLTYPE_FLT:
     167      case COLTYPE_TIME:
     168        // note that COLTYPE_TIME is a type of float
     169        ResetVector (vec[i], OPIHI_FLT, NELEM);
     170        break;
     171      case COLTYPE_CHAR:
     172      default:
     173        break;
    153174    }
    154175  }
     
    159180    if (scan_line_maxlen (f, buffer, 0x10000) == EOF) {
    160181      gprint (GP_ERR, "problem reading file %s\n", filename);
    161       free (vec);
    162       free (col);
     182      read_vectors_cleanup();
    163183      return FALSE;
    164184    }
     
    206226      for (i = 0; i < Nvec; i++) {
    207227        int ivalue;
    208         char cvalue;
    209228        double dvalue;
    210229        time_t tvalue;
     
    217236            break;
    218237          case COLTYPE_CHAR:
    219             readStatus = IsCSV ? charparse_csv (&cvalue, col[i], c0) : charparse (&cvalue, col[i], c0);
    220             vec[i][0].elements.Int[Nelem] = readStatus ? cvalue : 0;
    221             break;
     238            {
     239              // I need to get an isolated word in 'value' with the string value of this field
     240              char *ptr = IsCSV ? ptrparse_csv (col[i], c0) : ptrparse (col[i], c0);
     241              char *value = NULL;
     242              if (IsCSV) {
     243                char *end = parse_nextword_csv (ptr);
     244                if (end) {
     245                  value = end ? strncreate (ptr, end - ptr) : strcreate (ptr);
     246                }
     247              } else {
     248                value = thisword(ptr);
     249              }
     250              set_list_varname (varname, listname[i], Nelem, FALSE);
     251              set_str_variable (varname, value);
     252              free (value);
     253              break;
     254            }
    222255          case COLTYPE_FLT:
    223256            readStatus = IsCSV ? dparse_csv (&dvalue, col[i], c0) : dparse (&dvalue, col[i], c0);
     
    249282        NELEM += 1000;
    250283        for (i = 0; i < Nvec; i++) {
    251           if (coltype[i] == COLTYPE_INT) {
    252             REALLOCATE (vec[i][0].elements.Int, opihi_int, NELEM);
    253           } else {
    254             REALLOCATE (vec[i][0].elements.Flt, opihi_flt, NELEM);
     284          switch (coltype[i]) {
     285            case COLTYPE_INT:
     286              ResetVector (vec[i], OPIHI_INT, NELEM);
     287              break;
     288            case COLTYPE_FLT:
     289            case COLTYPE_TIME:
     290              ResetVector (vec[i], OPIHI_FLT, NELEM);
     291              break;
     292            case COLTYPE_CHAR:
     293            default:
     294              break;
    255295          }
    256296        }
     
    259299    }
    260300  }
     301  // set the final vector / list length
    261302  for (i = 0; i < Nvec; i++) {
    262     if (coltype[i] == COLTYPE_INT) {
    263       REALLOCATE (vec[i][0].elements.Int, opihi_int, MAX (Nelem,1));
    264     } else {
    265       REALLOCATE (vec[i][0].elements.Flt, opihi_flt, MAX (Nelem,1));
    266     }
    267     vec[i][0].Nelements = Nelem;
    268   }
    269  
    270   free (vec);
    271   free (col);
    272   if (buffer) free (buffer);
     303    switch (coltype[i]) {
     304      case COLTYPE_INT:
     305        ResetVector (vec[i], OPIHI_INT, Nelem);
     306        break;
     307      case COLTYPE_FLT:
     308      case COLTYPE_TIME:
     309        ResetVector (vec[i], OPIHI_FLT, Nelem);
     310        break;
     311      case COLTYPE_CHAR:
     312        sprintf (varname, "%s:n", listname[i]);
     313        set_int_variable (varname, Nelem);
     314        break;
     315      default:
     316        break;
     317    }
     318  }
     319  read_vectors_cleanup();
    273320  return (TRUE);
    274 
    275321}
    276322
    277 # define ESCAPE(MSG) { \
    278   gprint (GP_ERR, "%s\n", MSG); \
     323# define ESCAPE(...) {          \
     324  gprint (GP_ERR, __VA_ARGS__); \
    279325  if (CCDKeyword != NULL) free (CCDKeyword); \
    280326  gfits_free_table  (&table); \
     
    285331
    286332  off_t Nbytes;
    287   int i, j, k, N, Nextend, Ny, Binary, vecType, padIfShort;
     333  int i, j, N, Nextend, Ny, Binary, vecType, padIfShort;
    288334  char type[16], ID[80], *CCDKeyword;
    289335  FTable table;
    290336  Header header;
    291337  Vector **vec;
     338  int FITS_TRANSPOSE;
    292339
    293340  table.buffer = NULL;
    294341  header.buffer = NULL;
     342
     343  FITS_TRANSPOSE = FALSE;
     344  if ((N = get_argument (argc, argv, "-transpose"))) {
     345    remove_argument (N, &argc, argv);
     346    FITS_TRANSPOSE = TRUE;
     347  }
    295348
    296349  CCDKeyword = NULL;
     
    321374  // }
    322375
    323   if (argc < 2) ESCAPE ("USAGE: read -fits extension [-extnum] [-keyword key] name name ...");
    324 
    325   if (f == NULL) ESCAPE ("file not found");
     376  if (argc < 2) ESCAPE ("USAGE: read -fits extension [-extnum] [-keyword key] name name ...\n");
     377
     378  if (f == NULL) ESCAPE ("file not found\n");
    326379  fseeko (f, 0LL, SEEK_SET);
    327380  table.header = &header;
     
    331384    // first extension is PHU, cannot be a table.
    332385    // Nextend counts from 0 for first extension
    333     if (!gfits_load_header (f, &header)) ESCAPE ("error reading primary header for file");
     386    if (!gfits_load_header (f, &header)) ESCAPE ("error reading primary header for file\n");
    334387    Nbytes = gfits_data_size (&header);
    335388    fseeko (f, Nbytes, SEEK_CUR);
     
    337390
    338391    for (i = 0; i < Nextend; i++) {
    339       if (!gfits_load_header (f, &header)) ESCAPE ("extension not found");
     392      if (!gfits_load_header (f, &header)) ESCAPE ("extension %d not found\n", i);
    340393      Nbytes = gfits_data_size (&header);
    341394      /* skip the prior data buffers */
     
    343396      gfits_free_header (&header);
    344397    }
    345     if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension");
    346     if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension");
     398    if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension %d\n", Nextend);
     399    if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension %d\n", Nextend);
    347400
    348401  } else {
     
    375428        continue;
    376429      }
    377       if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension");
     430      if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension\n");
    378431      break;
    379432    }
     
    384437  gfits_scan (&header, "XTENSION", "%s", 1, type);
    385438  if (strcmp (type, "BINTABLE") && strcmp (type, "TABLE")) {
    386     ESCAPE ("specified extension is not a table\n");
     439    ESCAPE ("specified extension %s is not a table\n", type);
    387440  }
    388441  Binary = !strcmp (type, "BINTABLE");
     
    410463    }
    411464       
    412     // define the multifield vector names
    413     ALLOCATE (vec, Vector *, Nval);
    414     for (j = 0; j < Nval; j++) {
    415       if (Nval == 1)
    416         sprintf (name, "%s", argv[i]);
    417       else
    418         sprintf (name, "%s:%d", argv[i], j);
    419       if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
    420       ResetVector (vec[j], vecType, Ny);
    421     }
    422 
    423     if (!strcmp (type, "char")) {
    424       char *Ptr = data;
     465    if (!FITS_TRANSPOSE) {
     466      // read string column into a list rather than a vector
     467      if (!strcmp (type, "char")) {
     468        char *fieldName = argv[i];
     469        char *Ptr = data;
     470        char varname[1024];  // used as a buffer for the names of string fields
     471        for (j = 0; j < Ny; j++) {
     472          set_list_varname (varname, fieldName, j, FALSE);
     473          char *value = strncreate (&Ptr[j*Nval], Nval);
     474          // replace instances of $ with _
     475          char *p = strchr (value, '$');
     476          while (p) {
     477            *p = '_';
     478            p = strchr (p, '$');
     479          }
     480          set_str_variable (varname, value);
     481          free (value);
     482        }
     483        sprintf (varname, "%s:n", fieldName);
     484        set_int_variable (varname, Ny);
     485        continue;
     486      }
     487
     488      // define the multifield vector names (Nval vectors x Ny elements)
     489      ALLOCATE (vec, Vector *, Nval);
     490      for (j = 0; j < Nval; j++) {
     491        if (Nval == 1)
     492          sprintf (name, "%s", argv[i]);
     493        else
     494          sprintf (name, "%s:%d", argv[i], j);
     495        if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
     496        ResetVector (vec[j], vecType, Ny);
     497      }
     498
     499      if (!VectorAssignData (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s", type);
     500
     501    } else {
     502      // define the multifield vector names (Ny vectors x Nval elements)
     503      ALLOCATE (vec, Vector *, Ny);
    425504      for (j = 0; j < Ny; j++) {
    426         for (k = 0; k < Nval; k++, Ptr++) {
    427           vec[k][0].elements.Int[j] = *Ptr;
    428         }
    429       }
    430     }
    431     if (!strcmp (type, "short")) {
    432       short *Ptr = data;
    433       for (j = 0; j < Ny; j++) {
    434         for (k = 0; k < Nval; k++, Ptr++) {
    435           vec[k][0].elements.Int[j] = *Ptr;
    436         }
    437       }
    438     }
    439     if (!strcmp (type, "int")) {
    440       int *Ptr = data;
    441       for (j = 0; j < Ny; j++) {
    442         for (k = 0; k < Nval; k++, Ptr++) {
    443           vec[k][0].elements.Int[j] = *Ptr;
    444         }
    445       }
    446     }
    447     if (!strcmp (type, "int64_t")) {
    448       int64_t *Ptr = data;
    449       for (j = 0; j < Ny; j++) {
    450         for (k = 0; k < Nval; k++, Ptr++) {
    451           vec[k][0].elements.Int[j] = *Ptr;
    452         }
    453       }
    454     }
    455     if (!strcmp (type, "float")) {
    456       float *Ptr = data;
    457       for (j = 0; j < Ny; j++) {
    458         for (k = 0; k < Nval; k++, Ptr++) {
    459           vec[k][0].elements.Flt[j] = *Ptr;
    460         }
    461       }
    462     }
    463     if (!strcmp (type, "double")) {
    464       double *Ptr = data;
    465       for (j = 0; j < Ny; j++) {
    466         for (k = 0; k < Nval; k++, Ptr++) {
    467           vec[k][0].elements.Flt[j] = *Ptr;
    468         }
    469       }
     505        if (Ny == 1)
     506          sprintf (name, "%s", argv[i]);
     507        else
     508          sprintf (name, "%s:%d", argv[i], j);
     509        if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
     510        ResetVector (vec[j], vecType, Nval);
     511      }
     512
     513      if (!VectorAssignDataTranspose (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s", type);
    470514    }
    471515    free (data);
     
    477521  return (TRUE);
    478522}
     523
     524void read_vectors_cleanup () {
     525
     526  int i;
     527
     528  if (col) free (col);
     529  if (coltype) free (coltype);
     530  if (buffer) free (buffer);
     531  if (listname) {
     532    for (i = 0; i < Nvec; i++) {
     533      if (listname[i]) free (listname[i]);
     534    }
     535    free (listname);
     536  }
     537  if (vec) free (vec);
     538}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.data/rebin.c

    r28241 r37067  
    133133              *Vout += *Vin;
    134134              if (Normalize) {(*Vn) ++;}
     135              // if ((i == 1) && (j == 1)) fprintf (stderr, "%d,%d : %d,%d : %f : %f : %d\n", i, j, x, y, *Vin, *Vout, *Vn);
    135136            }
    136137            if (Normalize) {Vn ++;}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.data/vellipse.c

    r25757 r37067  
    228228 */
    229229
     230// XXX NOTE that PHI is defined with the wrong sign, should fix this...
    230231opihi_flt fellipseOD (opihi_flt alpha, opihi_flt *par, int Npar, opihi_flt *dpar) {
    231232 
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/cmd.data/vgauss.c

    r35109 r37067  
    4848  if ((ovec = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE);
    4949
     50  CastVector (xvec, OPIHI_FLT);
     51  CastVector (yvec, OPIHI_FLT);
     52
    5053  int Nsvec = strlen(argv[3]);
    5154
     
    6972  }
    7073
    71   CastVector (xvec, OPIHI_FLT);
    72   CastVector (yvec, OPIHI_FLT);
    7374  CastVector (svec, OPIHI_FLT);
    7475  // XXX Cast is failing.
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/Makefile

    r34461 r37067  
    2525$(SRC)/dvo_host_utils.$(ARCH).o         \
    2626$(SRC)/region_list.$(ARCH).o            \
    27 $(SRC)/find_matches.$(ARCH).o           \
    28 $(SRC)/photometry.$(ARCH).o             
     27$(SRC)/photcode_ops.$(ARCH).o           \
     28$(SRC)/find_matches.$(ARCH).o           
     29
     30# $(SRC)/photometry.$(ARCH).o             
     31
     32broken = \
     33$(SRC)/calextract.$(ARCH).o             \
     34$(SRC)/calmextract.$(ARCH).o            \
     35$(SRC)/ccd.$(ARCH).o                    \
     36$(SRC)/cmd.$(ARCH).o                    \
     37$(SRC)/dmagaves.$(ARCH).o               \
     38$(SRC)/dmagmeas.$(ARCH).o               \
     39$(SRC)/dmags.$(ARCH).o                  \
     40$(SRC)/ddmags.$(ARCH).o         \
     41$(SRC)/fitcolors.$(ARCH).o
    2942
    3043cmds = \
     
    3245$(SRC)/avmatch.$(ARCH).o                \
    3346$(SRC)/badimages.$(ARCH).o              \
    34 $(SRC)/calextract.$(ARCH).o             \
    35 $(SRC)/calmextract.$(ARCH).o            \
    3647$(SRC)/catdir.$(ARCH).o                 \
    37 $(SRC)/ccd.$(ARCH).o                    \
    3848$(SRC)/cmatch.$(ARCH).o         \
    39 $(SRC)/cmd.$(ARCH).o                    \
    4049$(SRC)/cmpload.$(ARCH).o                \
    4150$(SRC)/cmpread.$(ARCH).o                \
    42 $(SRC)/ddmags.$(ARCH).o         \
     51$(SRC)/coordimage.$(ARCH).o             \
     52$(SRC)/coordmosaic.$(ARCH).o            \
    4353$(SRC)/detrend.$(ARCH).o                \
    44 $(SRC)/dmagaves.$(ARCH).o               \
    45 $(SRC)/dmagmeas.$(ARCH).o               \
    46 $(SRC)/dmags.$(ARCH).o                  \
    4754$(SRC)/dmt.$(ARCH).o                    \
    4855$(SRC)/elixir.$(ARCH).o                \
    49 $(SRC)/fitcolors.$(ARCH).o             \
    5056$(SRC)/fitsed.$(ARCH).o                \
    5157$(SRC)/gcat.$(ARCH).o                   \
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/avextract.c

    r35416 r37067  
    166166  needMeasures = FALSE;
    167167  for (i = 0; !needMeasures && (i < Nfields); i++) {
    168     if (fields[i].magMode == MAG_NONE) continue;
    169     if (fields[i].photcode == NULL) continue; // assert this?
     168    if (fields[i].photcode == NULL) continue; // non-measure fields do not have a photcode
    170169    if (fields[i].photcode[0].type == PHOT_REF) needMeasures = TRUE;
    171170    if (fields[i].photcode[0].type == PHOT_DEP) needMeasures = TRUE;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/avmatch.c

    r35416 r37067  
    7070  dbExtractAveragesInit ();
    7171
    72   // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
    7372  RAvec  = NULL;
    7473  DECvec = NULL;
    75   if (PARALLEL && !HOST_ID) {
    76     if (!CoordsFile) {
    77       // get vectors corresponding to coordinates of interest
    78       if ((RAvec  = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help;
    79       if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help;
    80      
    81       ALLOCATE (vec, Vector *, 2);
    82       vec[0] = RAvec;
    83       vec[1] = DECvec;
    84 
    85       CoordsFile = abspath("coords.fits", 1024);
    86       int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
    87       if (!status) goto escape;
    88     }
    89 
    90     char *targv1 = argv[1];
    91     char *targv2 = argv[2];
    92     argv[1] = strcreate ("-coords");
    93     argv[2] = strcreate (CoordsFile);
    94     free (CoordsFile);
    95 
    96     // I need to pass the RA & DEC vectors to the remote clients...
    97     int status = HostTableParallelOps (skylist, argc, argv, RESULT_FILE, TRUE, RAvec->Nelements, VERBOSE);
    98     if (vec) free (vec);
    99    
    100     free (argv[1]);
    101     free (argv[2]);
    102     argv[1] = targv1;
    103     argv[2] = targv2;
    104 
    105     return status;
    106   }
    107 
    10874  // get vectors corresponding to coordinates of interest
    10975  if (CoordsFile) {
     
    12086    remove_argument (1, &argc, argv);
    12187  }
     88
     89  /* load regions which contain all supplied RA,DEC coordinates */
     90  if ((skylist = SelectRegionsByCoordVectors (RAvec, DECvec)) == NULL) goto escape;
     91
     92  // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
     93  if (PARALLEL && !HOST_ID) {
     94
     95    // We need to copy the args to a temp array and modify them so that we send the
     96    // correct set to the remote client.  The args list looks like this:
     97    // if (!CoordsFile) : avmatch (RADIUS) field, ... [we removed RA & DEC above]
     98    // if ( CoordsFile) : avmatch (RADIUS) field, ... [because we stripped off the -coords filename elements]
     99
     100    // allocate the temp array and copy all but (RA) (DEC)
     101    int targc = 0;
     102    char **targv = NULL;
     103    ALLOCATE (targv, char *, argc + 2);
     104    for (i = 0; i < argc; i++) {
     105      targv[targc] = strcreate (argv[i]);
     106      targc ++;
     107    }
     108
     109    // if not specified, create the coords.fits input file
     110    // NOTE: RAvec, DECvec were set above
     111    if (!CoordsFile) {
     112      ALLOCATE (vec, Vector *, 2);
     113      vec[0] = RAvec;
     114      vec[1] = DECvec;
     115
     116      CoordsFile = abspath("coords.fits", 1024);
     117      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
     118      if (!status) goto escape;
     119    }
     120
     121    // add the coords file to the args list
     122    targv[targc+0] = strcreate ("-coords");
     123    targv[targc+1] = CoordsFile; // this gets freed with targv
     124    targc += 2;
     125   
     126    // I need to pass the RA & DEC vectors to the remote clients...
     127    int status = HostTableParallelOps (skylist, targc, targv, RESULT_FILE, TRUE, RAvec->Nelements, VERBOSE);
     128    if (vec) free (vec);
     129   
     130    // free up targv
     131    for (i = 0; i < targc; i++) {
     132      free (targv[i]);
     133    }
     134    free (targv);
     135
     136    return status;
     137  }
     138
    122139  RADIUS = atof (argv[1]);
    123140  remove_argument (1, &argc, argv);
     
    135152  int needMeasures = FALSE;
    136153  for (i = 0; !needMeasures && (i < Nfields); i++) {
    137     if (fields[i].magMode == MAG_NONE) continue;
    138154    if (fields[i].photcode == NULL) continue; // assert this?
    139155    if (fields[i].photcode[0].type == PHOT_REF) needMeasures = TRUE;
    140156    if (fields[i].photcode[0].type == PHOT_DEP) needMeasures = TRUE;
    141157  }
    142 
    143   /* load regions which contain all supplied RA,DEC coordinates */
    144   if ((skylist = SelectRegionsByCoordVectors (RAvec, DECvec)) == NULL) goto escape;
    145158
    146159  /* create output storage vectors */
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/dvo_client.c

    r35263 r37067  
    9090  }
    9191
     92  // these are set in 'startup.c' for readline-based programs
     93  set_variable ("PID", getpid());
     94  set_str_variable ("KAPA", "kapa");
     95  set_int_variable ("UNSIGN", 0);
     96  gfits_set_unsign_mode (FALSE);
     97
    9298  return;
    9399}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/find_matches.c

    r29759 r37067  
    5050  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    5151  tcoords.Npolyterms = 1;
    52   strcpy (tcoords.ctype, "RA---ARC");
     52  strcpy (tcoords.ctype, "DEC--ARC");
    5353
    5454  // this region includes a boundary layer of size RADIUS
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/fitsed.c

    r34088 r37067  
    8383  /* interpret command-line options */
    8484  if ((selection = SetRegionSelection (&argc, argv)) == NULL) goto escape;
    85   if (!SetPhotSelections (&argc, argv, 4)) goto usage;
     85  // if (!SetPhotSelections (&argc, argv, 4)) goto usage;
    8686
    8787  PLOT = FALSE;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/gimages.c

    r34844 r37067  
    136136      local.pc2_1 = local.pc1_2 = 0.0;
    137137      local.Npolyterms = 1;
    138       strcpy (local.ctype, "RA---TAN");
     138      strcpy (local.ctype, "DEC--TAN");
    139139
    140140      if (typehash == DistortImage) {
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/gstar.c

    r35109 r37067  
    1515  GSTAR_UCDIST,
    1616  GSTAR_AVE_AP_MAG,
    17   GSTAR_AVE_MAG_20,
    18   GSTAR_AVE_MAG_80,
     17  GSTAR_AVE_MAG_MIN,
     18  GSTAR_AVE_MAG_MAX,
    1919  GSTAR_AVE_KRON_MAG,
    2020  GSTAR_AVE_KRON_MAG_ERR,
     
    307307          gprint (GP_LOG, "\n");
    308308
    309           /* M_20 */
    310           for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_AVE_MAG_20);
    311           gprint (GP_LOG, "\n");
    312 
    313           /* M_80 */
    314           for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_AVE_MAG_80);;
     309          /* Mmin */
     310          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_AVE_MAG_MIN);
     311          gprint (GP_LOG, "\n");
     312
     313          /* Mmax */
     314          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_AVE_MAG_MAX);;
    315315          gprint (GP_LOG, "\n");
    316316
     
    374374          int Nv = index[j];
    375375
    376           Mcat = PhotCat (&catalog.measure[Nv]);
     376          Mcat = PhotCat (&catalog.measure[Nv], MAG_CLASS_PSF);
    377377          if (INST) {
    378             Mrel = PhotInst (&catalog.measure[Nv]);
     378            Mrel = PhotInst (&catalog.measure[Nv], MAG_CLASS_PSF);
    379379          } else {
    380             Mrel = PhotRel (&catalog.measure[Nv], &catalog.average[k], &catalog.secfilt[k*Nsecfilt]);
     380            Mrel = PhotRel (&catalog.measure[Nv], &catalog.average[k], &catalog.secfilt[k*Nsecfilt], MAG_CLASS_PSF);
    381381          }
     382
     383          float dRoff = dvoOffsetR(&catalog.measure[Nv], &catalog.average[k]);
     384          float dDoff = dvoOffsetD(&catalog.measure[Nv], &catalog.average[k]);
    382385
    383386          if (GetMeasures && !QUIET) {
     
    387390            gprint (GP_LOG, "%6.3f  ", catalog.measure[Nv].dM);
    388391            gprint (GP_LOG, "%20s  ",  date);
    389             gprint (GP_LOG, "%7.4f ",  catalog.measure[Nv].dR);
    390             gprint (GP_LOG, "%7.4f ",  catalog.measure[Nv].dD);
     392           
     393            gprint (GP_LOG, "%7.4f ",  dRoff);
     394            gprint (GP_LOG, "%7.4f ",  dDoff);
    391395            gprint (GP_LOG, "0x%08x ", catalog.measure[Nv].photFlags);
    392396            gprint (GP_LOG, "0x%08x ", catalog.measure[Nv].dbFlags);
     
    447451            vec3[0].elements.Flt[N] = catalog.measure[Nv].airmass;
    448452            vec4[0].elements.Flt[N] = catalog.measure[Nv].photcode;
    449             vec5[0].elements.Flt[N] = catalog.measure[Nv].dR;
    450             vec6[0].elements.Flt[N] = catalog.measure[Nv].dD;
     453            vec5[0].elements.Flt[N] = dRoff;
     454            vec6[0].elements.Flt[N] = dDoff;
    451455            N ++;
    452456            if (N == NPTS - 1) {
     
    561565    case GSTAR_AVE_MAG_CHISQ: /* average mag chisq */
    562566      if (seq == -1) {
    563         print_short (NAN_S_SHORT, NAN_S_SHORT);
    564       } else {
    565         print_short (pow (10.0, 0.01*secfilt[seq].Xm), secfilt[seq].Xm);
     567        print_double (NAN);
     568      } else {
     569        print_double (secfilt[seq].Mchisq);
    566570      }
    567571      break;
     
    596600      break;
    597601
    598     case GSTAR_AVE_MAG_20: /* average ap mags */
    599       if (seq == -1) {
    600         print_double (NAN);
    601       } else {
    602         print_short (0.001*secfilt[seq].M_20, secfilt[seq].M_20);
    603       }
    604       break;
    605 
    606     case GSTAR_AVE_MAG_80: /* average ap mags */
    607       if (seq == -1) {
    608         print_double (NAN);
    609       } else {
    610         print_short (0.001*secfilt[seq].M_80, secfilt[seq].M_80);
     602    case GSTAR_AVE_MAG_MIN: /* average ap mags */
     603      if (seq == -1) {
     604        print_double (NAN);
     605      } else {
     606        print_double (secfilt[seq].Mmin);
     607      }
     608      break;
     609
     610    case GSTAR_AVE_MAG_MAX: /* average ap mags */
     611      if (seq == -1) {
     612        print_double (NAN);
     613      } else {
     614        print_double (secfilt[seq].Mmax);
    611615      }
    612616      break;
     
    632636        print_double (NAN);
    633637      } else {
    634         print_double_exp (secfilt[seq].FluxPSF);
     638        print_double_exp (secfilt[seq].FpsfStk);
    635639      }
    636640      break;
     
    640644        print_double (NAN);
    641645      } else {
    642         print_double_exp (secfilt[seq].dFluxPSF);
     646        print_double_exp (secfilt[seq].dFpsfStk);
    643647      }
    644648      break;
     
    648652        print_double (NAN);
    649653      } else {
    650         print_double_exp (secfilt[seq].FluxKron);
     654        print_double_exp (secfilt[seq].FkronStk);
    651655      }
    652656      break;
     
    656660        print_double (NAN);
    657661      } else {
    658         print_double_exp (secfilt[seq].dFluxKron);
    659       }
    660       break;
    661 
    662   }
    663 }
     662        print_double_exp (secfilt[seq].dFkronStk);
     663      }
     664      break;
     665
     666  }
     667}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/hosts.c

    r35757 r37067  
    33# define DVO_MAX_PATH 1024
    44
    5 enum {TEMP_NONE, TEMP_DVO_RESULTS, TEMP_DVO_LOG, TEMP_RELASTRO_CATALOG, TEMP_RELPHOT_CATALOG, TEMP_RELPHOT_LOG, TEMP_DVOPSPS_DET, TEMP_FIXSTKIDS_RESULTS};
     5enum {TEMP_NONE, TEMP_DVO_RESULTS, TEMP_DVO_LOG,
     6      TEMP_RELASTRO_CATALOG, TEMP_RELPHOT_CATALOG, TEMP_RELPHOT_LOG, TEMP_DVOPSPS_DET, TEMP_FIXSTKIDS_RESULTS,
     7      TEMP_RELASTRO_CAT_FULL, TEMP_RELPHOT_CAT_FULL, TEMP_CHECKASTRO_CAT_FULL,
     8};
    69
    710// functions to manage the remote hosts
     
    1215    gprint (GP_ERR, "  commands:\n");
    1316    gprint (GP_ERR, "    purge-temp : delete all tempfiles for this shell\n");
    14     gprint (GP_ERR, "               : [-old-pid] [-all-pid] [-v] [-verbose] [-commit] [-type type]\n");
     17    gprint (GP_ERR, "               : [-old-pid] [-all-pid] [-v] [-verbose] [-commit] [-type type] [-age hours]\n");
    1518    gprint (GP_ERR, "    get-results : determine name of RESULTS file\n");
    1619    return FALSE;
     
    3336    }
    3437   
     38    struct timeval now;
     39    gettimeofday (&now, NULL);
     40
     41    float AGE = 0;
     42    int NOW = now.tv_sec;
     43    if ((N = get_argument (argc, argv, "-age"))) {
     44      remove_argument (N, &argc, argv);
     45      AGE = atof(argv[N]);
     46      remove_argument (N, &argc, argv);
     47    }
     48
    3549    int VERBOSE = FALSE;
    3650    if ((N = get_argument (argc, argv, "-v"))) {
     
    6074      if (!strcasecmp(argv[N], "dvo.results"))       TEMP_TYPE = TEMP_DVO_RESULTS;
    6175      if (!strcasecmp(argv[N], "dvo.log"))           TEMP_TYPE = TEMP_DVO_LOG;
    62       if (!strcasecmp(argv[N], "relastro.catalog"))   TEMP_TYPE = TEMP_RELASTRO_CATALOG;
     76      if (!strcasecmp(argv[N], "relastro.catalog"))  TEMP_TYPE = TEMP_RELASTRO_CATALOG;
    6377      if (!strcasecmp(argv[N], "relphot.catalog"))   TEMP_TYPE = TEMP_RELPHOT_CATALOG;
     78      if (!strcasecmp(argv[N], "relastro.catfull"))  TEMP_TYPE = TEMP_RELASTRO_CAT_FULL;
     79      if (!strcasecmp(argv[N], "checkastro.catfull"))TEMP_TYPE = TEMP_CHECKASTRO_CAT_FULL;
     80      if (!strcasecmp(argv[N], "relphot.catfull"))   TEMP_TYPE = TEMP_RELPHOT_CAT_FULL;
    6481      if (!strcasecmp(argv[N], "relphot.log"))       TEMP_TYPE = TEMP_RELPHOT_LOG;
    6582      if (!strcasecmp(argv[N], "dvopsps.det"))       TEMP_TYPE = TEMP_DVOPSPS_DET;
     
    6784      if (TEMP_TYPE == TEMP_NONE) {
    6885        gprint (GP_ERR, "USAGE: hosts purge-temp [-type (type)]\n");
    69         gprint (GP_ERR, "  allowed types dvo.results, dvo.log, relphot.results, relphot.log]\n");
     86        gprint (GP_ERR, "  allowed types dvo.results, dvo.log, relphot.catalog, relphot.log, relphot.catfull, relastro.catalog, relastro.catfull, checkastro.catfull, dvopsps.det, fixstkids.results]\n");
    7087        return FALSE;
    7188      }
     
    107124        if (TEMP_TYPE == TEMP_RELPHOT_CATALOG)   snprintf (name, DVO_MAX_PATH, "%s/relphot.catalog.subset.dat", table->hosts[i].pathname);
    108125        if (TEMP_TYPE == TEMP_RELPHOT_LOG)       snprintf (name, DVO_MAX_PATH, "%s/log.rlpc.*", table->hosts[i].pathname);
     126        if (TEMP_TYPE == TEMP_RELASTRO_CAT_FULL) snprintf (name, DVO_MAX_PATH, "%s/relastro.catalog.?????.?????.dat", table->hosts[i].pathname);
     127        if (TEMP_TYPE == TEMP_CHECKASTRO_CAT_FULL) snprintf (name, DVO_MAX_PATH, "%s/checkastro.catalog.?????.?????.dat", table->hosts[i].pathname);
     128        if (TEMP_TYPE == TEMP_RELPHOT_CAT_FULL)  snprintf (name, DVO_MAX_PATH, "%s/relphot.catalog.?????.?????.dat", table->hosts[i].pathname);
    109129        if (TEMP_TYPE == TEMP_DVOPSPS_DET)       snprintf (name, DVO_MAX_PATH, "%s/dvopsps.*.det.dat", table->hosts[i].pathname);
    110130        if (TEMP_TYPE == TEMP_FIXSTKIDS_RESULTS) snprintf (name, DVO_MAX_PATH, "%s/fixstkids.results.*.dat", table->hosts[i].pathname);
     
    115135        if (TEMP_TYPE == TEMP_RELPHOT_CATALOG)   snprintf (name, DVO_MAX_PATH, "%s/relphot.catalog.subset.dat", table->hosts[i].pathname);
    116136        if (TEMP_TYPE == TEMP_RELPHOT_LOG)       snprintf (name, DVO_MAX_PATH, "%s/log.rlpc.*", table->hosts[i].pathname);
     137        if (TEMP_TYPE == TEMP_RELASTRO_CAT_FULL) snprintf (name, DVO_MAX_PATH, "%s/relastro.catalog.%05d.?????.dat", table->hosts[i].pathname, PID);
     138        if (TEMP_TYPE == TEMP_CHECKASTRO_CAT_FULL) snprintf (name, DVO_MAX_PATH, "%s/checkastro.catalog.%05d.?????.dat", table->hosts[i].pathname, PID);
     139        if (TEMP_TYPE == TEMP_RELPHOT_CAT_FULL)  snprintf (name, DVO_MAX_PATH, "%s/relphot.catalog.%05d.?????.dat", table->hosts[i].pathname, PID);
    117140        if (TEMP_TYPE == TEMP_DVOPSPS_DET)       snprintf (name, DVO_MAX_PATH, "%s/dvopsps.%05d.*.det.dat", table->hosts[i].pathname, PID);
    118141        if (TEMP_TYPE == TEMP_FIXSTKIDS_RESULTS) snprintf (name, DVO_MAX_PATH, "%s/fixstkids.results.%05d.*.dat", table->hosts[i].pathname, PID);
     
    121144      glob (name, 0, NULL, &pglob);
    122145      int j;
     146      struct stat filestats;
    123147      for (j = 0; j < pglob.gl_pathc; j++) {
     148        if (AGE > 0) {
     149          if (stat(pglob.gl_pathv[j], &filestats)) {
     150            gprint (GP_ERR, "failed to get stats for %s\n", pglob.gl_pathv[j]);
     151            continue;
     152          }
     153          float myAge = (NOW - filestats.st_mtime) / 3600.0;
     154          if (myAge < AGE) continue;
     155        }
    124156        if (VERBOSE) gprint (GP_ERR, "unlink %s\n", pglob.gl_pathv[j]);
    125157        if (!DRYRUN) unlink (pglob.gl_pathv[j]);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/imdata.c

    r34088 r37067  
    33int imdata (int argc, char **argv) {
    44 
    5   off_t i, j, k, n, I;
     5  off_t i, j, k, I;
    66  int N, NPTS, found, mode, TimeSelect, TimeFormat;
    77  off_t Nregions, NREGIONS;
     
    152152        for (i = 0; i < catalog.Nmeasure; i++) {
    153153          if ((catalog.measure[i].t < start) || (catalog.measure[i].t > stop)) continue;
    154           n = catalog.measure[i].averef;
    155           vec[0].elements.Flt[N] = catalog.average[n].R - catalog.measure[i].dR / 3600.0;
     154          vec[0].elements.Flt[N] = catalog.measure[i].R;
    156155          N++;
    157156          CHECK_REALLOCATE (vec[0].elements.Flt, opihi_flt, NPTS, N, 1000);
     
    161160        for (i = 0; i < catalog.Nmeasure; i++) {
    162161          if ((catalog.measure[i].t < start) || (catalog.measure[i].t > stop)) continue;
    163           n = catalog.measure[i].averef;
    164           vec[0].elements.Flt[N] = catalog.average[n].D - catalog.measure[i].dD / 3600.0;
     162          vec[0].elements.Flt[N] = catalog.measure[i].D;
    165163          N++;
    166164          CHECK_REALLOCATE (vec[0].elements.Flt, opihi_flt, NPTS, N, 1000);
     
    194192        for (i = 0; i < catalog.Nmeasure; i++) {
    195193          if ((catalog.measure[i].t < start) || (catalog.measure[i].t > stop)) continue;
    196           n = catalog.measure[i].averef;
     194          //n = catalog.measure[i].averef;
    197195          // vec[0].elements.Flt[N] = catalog.average[n].M;
    198196          N++;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/imextract.c

    r34088 r37067  
    185185    gprint (GP_ERR, "  Mcal : photometry calibration (mags)\n");
    186186    gprint (GP_ERR, "  dMcal : photometry calibration error (mags)\n");
    187     gprint (GP_ERR, "  Xm : chisq of photometry calibration\n");
     187    gprint (GP_ERR, "  Mchisq : chisq of photometry calibration\n");
    188188    gprint (GP_ERR, "  photcode : numeric photcode value for image\n");
    189189    gprint (GP_ERR, "  exptime : exposure duration (seconds)\n");
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/init.c

    r34461 r37067  
    1313int cmpload         PROTO((int, char **));
    1414int cmpread         PROTO((int, char **));
     15int coordimage      PROTO((int, char **));
     16int coordmosaic     PROTO((int, char **));
     17int psastro_model   PROTO((int, char **));
    1518int ddmags          PROTO((int, char **));
    1619int detrend         PROTO((int, char **));
     
    6366  {1, "avmatch",     avmatch,      "extract average data values matched to RA,DEC points"},
    6467  {1, "badimages",   badimages,    "look for images with anomalous astrometry"},
    65   {1, "calextract",  calextract,   "extract photometry calibration"},
    66   {1, "calmextract", calmextract,  "extract photometry calibration"},
     68//  {1, "calextract",  calextract,   "extract photometry calibration"},
     69//  {1, "calmextract", calmextract,  "extract photometry calibration"},
    6770  {1, "catdir",      catdir_define,"re-define CATDIR"},
    68   {1, "ccd",         ccd,          "plot color-color diagram"},
     71//  {1, "ccd",         ccd,          "plot color-color diagram"},
    6972  {1, "cmatch",      cmatch,       "match two catalogs"},
    70   {1, "cmd",         cmd,          "plot cmd of stars in current region"},
     73//  {1, "cmd",         cmd,          "plot cmd of stars in current region"},
    7174  {1, "cmpload",     cmpload,      "load cmp file into ?"},
    7275  {1, "cmpread",     cmpread,      "read data from cmp format files"},
    73   {1, "ddmags",      ddmags,       "plot magnitude differences"},
     76  {1, "coordimage",  coordimage,   "generate a map of the transformation residuals"},
     77  {1, "coordmosaic", coordmosaic,  "generate a map of the distortion"},
     78  {1, "psastro_model", psastro_model, "save psastro-format astrometry model"},
     79//  {1, "ddmags",      ddmags,       "plot magnitude differences"},
    7480  {1, "detrend",     detrend,      "extract from detrend database?"},
    75   {1, "dmagaves",    dmagaves,     "foo"},
    76   {1, "dmagmeas",    dmagmeas,     "foo"},
    77   {1, "dmags",       dmags,        "plot differential magnitudes between filters"},
     81//  {1, "dmagaves",    dmagaves,     "foo"},
     82//  {1, "dmagmeas",    dmagmeas,     "foo"},
     83//  {1, "dmags",       dmags,        "plot differential magnitudes between filters"},
    7884  {1, "dmt",         dmt,          "plot mag scatter"},
    7985  {1, "elixir",      elixir,       "talk to elixir"},
    80   {1, "fitcolors",   fitcolors,    "fit chip-to-chip color terms"},
     86//  {1, "fitcolors",   fitcolors,    "fit chip-to-chip color terms"},
    8187  {1, "fitsed",      fitsed,       "fit stellar SEDs to objects"},
    8288  {1, "gcat",        gcat,         "get catalog at location"},
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/lcurve.c

    r34584 r37067  
    129129        if (ErrorBars) dYvec.elements.Flt[N] = catalog.measure[m].dM;
    130130        Xvec.elements.Flt[N] = TimeValue (catalog.measure[m].t, TimeReference, TimeFormat);
    131         Yvec.elements.Flt[N] = PhotCat (&catalog.measure[m]);
     131        Yvec.elements.Flt[N] = PhotCat (&catalog.measure[m], MAG_CLASS_PSF);
    132132        /**** need to use PhotRel optionally here ****/
    133133        N++;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/lightcurve.c

    r27435 r37067  
    121121        dmvec[0].elements.Flt[N] = catalog.measure[m].dM;
    122122        if (RELPHOT) {
    123           mvec[0].elements.Flt[N] = PhotCat (&catalog.measure[m]);
     123          mvec[0].elements.Flt[N] = PhotCat (&catalog.measure[m], MAG_CLASS_PSF);
    124124        } else {
    125           mvec[0].elements.Flt[N] = PhotRel (&catalog.measure[m], &catalog.average[k], &catalog.secfilt[k*Nsecfilt]);
     125          mvec[0].elements.Flt[N] = PhotRel (&catalog.measure[m], &catalog.average[k], &catalog.secfilt[k*Nsecfilt], MAG_CLASS_PSF);
    126126        }
    127127        N++;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/photometry.c

    r35416 r37067  
    4141  }
    4242
     43# if (0)
    4344/* selection criteria */
    4445/* selections based on Measure quantities */
     
    7879static time_t TimeReference;
    7980static int TimeFormat;
    80 
     81# endif
     82
     83# if (0)
    8184int GetTimeSelection (time_t *tz, time_t *te) {
    8285  *tz = tzero;
     
    298301  return;
    299302}
    300 
    301 /* (re)load photcodes from photcode table */
    302 int InitPhotcodes () {
    303 
    304   double ZERO_POINT;
    305   char MasterPhotcodeFile[256];
    306   char CatdirPhotcodeFile[256];
    307   char *catdir;
    308 
    309   if (VarConfig ("ZERO_PT", "%lf", &ZERO_POINT) == (char *) NULL) {
    310     gprint (GP_ERR, "ZERO_PT undefined in config\n");
    311     return (FALSE);
    312   }
    313   SetZeroPoint (ZERO_POINT);
    314 
    315   catdir = GetCATDIR();
    316   if (catdir == NULL) {
    317     CatdirPhotcodeFile[0] = 0;
    318   } else {
    319     sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", catdir);
    320   }
    321 
    322   if (VarConfig ("PHOTCODE_FILE", "%s", MasterPhotcodeFile) == (char *) NULL) {
    323     gprint (GP_ERR, "PHOTCODE_FILE undefined in config\n");
    324     return (FALSE);
    325   }
    326 
    327   // XXX now that DVO does not allow write access, we can drop the MasterPhotcodeFile
    328   if (!LoadPhotcodes (CatdirPhotcodeFile, MasterPhotcodeFile, FALSE)) {
    329     gprint (GP_ERR, "error loading photcode table %s or master file %s\n", CatdirPhotcodeFile, MasterPhotcodeFile);
    330     return (FALSE);
    331   }
    332   return (TRUE);
    333 }
    334 
     303# endif
     304
     305# if (0)
    335306int ListPhotSelections () {
    336307
     
    662633      break;
    663634    case AVE_dMAG:
    664       value = PhotdM (code, average, secfilt);
     635      value = PhotAveErr (code, average, secfilt);
    665636      break;
    666637    case AVE_Xm:
     
    865836  /* for ErrSelect, check average errors */
    866837  if (ErrSelect) {
    867     dM = PhotdM (code, average, secfilt);
     838    dM = PhotAveErr (code, average, secfilt);
    868839    if (dM > ErrValue) return (FALSE);
    869840  }
     
    11211092  return (list);
    11221093}
    1123 
     1094# endif
     1095
     1096# if (0)
    11241097double GetMeasure (int param, Average *average, Measure *measure, double mag) {
    11251098
     
    11351108      break;
    11361109    case MEAS_RA: /* OK */
    1137       value = average[0].R - measure[0].dR / 3600.0;
     1110      value = measure[0].R;
    11381111      break;
    11391112    case MEAS_DEC: /* OK */
    1140       value = average[0].D - measure[0].dD / 3600.0;
     1113      value = measure[0].D;
    11411114      break;
    11421115    case MEAS_DOPHOT: /* OK */
     
    11561129      break;
    11571130    case MEAS_RA_OFFSET: /* OK */
    1158       value = measure[0].dR;
     1131      value = dvoOffsetR(measure, average);
    11591132      break;
    11601133    case MEAS_DEC_OFFSET: /* OK */
    1161       value = measure[0].dD;
     1134      value = dvoOffsetD(measure, average);
    11621135      break;
    11631136    case MEAS_FWHM: /* OK */
     
    11721145      value = measure[0].Xccd;
    11731146# else
    1174       ra  = average[0].R - measure[0].dR / 3600.0;
    1175       dec = average[0].D - measure[0].dD / 3600.0;
     1147      ra  = measure[0].R;
     1148      dec = measure[0].D;
    11761149      image = MatchImageDVO (measure[0].t, measure[0].photcode, measure[0].imageID);
    11771150      if (image == NULL) break;
     
    11851158      value = measure[0].Yccd;
    11861159# else
    1187       ra  = average[0].R - measure[0].dR / 3600.0;
    1188       dec = average[0].D - measure[0].dD / 3600.0;
     1160      ra  = measure[0].R;
     1161      dec = measure[0].D;
    11891162      image = MatchImageDVO (measure[0].t, measure[0].photcode, measure[0].imageID);
    11901163      if (image == NULL) break;
     
    11951168# if 0
    11961169    case MEAS_XMOSAIC: /* OK */
    1197       ra  = average[0].R - measure[0].dR / 3600.0;
    1198       dec = average[0].D - measure[0].dD / 3600.0;
     1170      ra  = measure[0].R;
     1171      dec = measure[0].D;
    11991172      mosaic = MatchMosaic (measure[0].t, measure[0].photcode); // XXX not used anymore
    12001173      if (mosaic == NULL) break;
     
    12031176      break;
    12041177    case MEAS_YMOSAIC: /* OK */
    1205       ra  = average[0].R - measure[0].dR / 3600.0;
    1206       dec = average[0].D - measure[0].dD / 3600.0;
     1178      ra  = measure[0].R;
     1179      dec = measure[0].D;
    12071180      mosaic = MatchMosaic (measure[0].t, measure[0].photcode); // XXX not used anymore
    12081181      if (mosaic == NULL) break;
     
    12141187  return (value);
    12151188}
     1189# endif
    12161190
    12171191/** the mosaic entries do not use the registered mosaic found
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/pmeasure.c

    r34088 r37067  
    203203        if (TimeSelect && (catalog.measure[m+k].t > tzero + trange)) continue;
    204204        if ((PhotcodeClip != -1) && (catalog.measure[m+k].photcode != PhotcodeClip)) continue;
    205         mag = PhotCat (&catalog.measure[m+k]);
     205        mag = PhotCat (&catalog.measure[m+k], MAG_CLASS_PSF);
    206206        Zvec[Npts] = MIN (1.0, MAX (0.01, (mag - Mz) / Mr));
    207207        if (LimExclude && (Zvec[Npts] > 0.99)) continue;
    208208        if (Zvec[Npts] < 0.011) continue;
    209         R = catalog.average[i].R - catalog.measure[m+k].dR/3600.0;
    210         D = catalog.average[i].D - catalog.measure[m+k].dD/3600.0;
     209        R = catalog.measure[m+k].R;
     210        D = catalog.measure[m+k].D;
    211211        // XXX drop this check
    212212        if ((R < Rmin) || (R > Rmax) || (D < -90.0) || (D > 90.0)) {
    213213          char *date;
    214214          date = ohana_sec_to_date (catalog.measure[m+k].t);
    215           gprint (GP_LOG, "out: %f, %f : %s : (%f, %f) + (%f, %f)\n", R, D, date, catalog.average[i].R, catalog.average[i].D, catalog.measure[m+k].dR/3600.0, catalog.measure[m+k].dD/3600.0);
     215          gprint (GP_LOG, "out: %f, %f : %s : (%f, %f) + (%f, %f)\n", R, D, date, catalog.average[i].R, catalog.average[i].D, catalog.measure[m+k].R, catalog.measure[m+k].D);
    216216          free (date);
    217217        }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/showtile.c

    r34584 r37067  
    3434  coords.pc1_2  = coords.pc2_1  = 0.0;
    3535  coords.Npolyterms = 0;
    36   strcpy (coords.ctype, "RA---TAN");
     36  strcpy (coords.ctype, "DEC--TAN");
    3737 
    3838  /* fill in top-left region */
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/simage.c

    r34584 r37067  
    4343  /* get astrometry information */
    4444  strcpy (coords.ctype, "NONE");
    45   gfits_scan (&header, "CTYPE1",   "%s",  1, coords.ctype);
    46   if (strcmp (coords.ctype, "RA---PLY")) {
     45  gfits_scan (&header, "CTYPE2",   "%s",  1, coords.ctype);
     46  if (strcmp (coords.ctype, "DEC--PLY")) {
    4747    gprint (GP_ERR, "ERROR: wrong astrometric info in header\n");
    4848    return (FALSE);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/dvo/subpix.c

    r31635 r37067  
    138138    for (j = 0; j < Nmeasure; j++) {
    139139      if (measure[j].t == Timage) {
    140         Mabs = PhotCat (&measure[j]);
     140        Mabs = PhotCat (&measure[j], MAG_CLASS_PSF);
    141141        RD_to_XY (&X, &Y, Ra, Dec, &image[I].coords);
    142142        t = TimeValue (measure[j].t, TimeReference, TimeFormat);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/include/data.h

    r34584 r37067  
    3333  char **pageIDs;
    3434} Book;
     35
     36// the interpolating spline has valu
     37typedef struct {
     38  int Nknots;
     39  opihi_flt *xk;
     40  opihi_flt *yk;
     41  opihi_flt *y2;
     42  char *name;
     43} Spline;
     44
     45typedef struct {
     46  char *name;
     47  int Ninput;
     48  int Nx;
     49  int Ny;
     50  float **buffers;
     51} MedImageType;
    3552
    3653void InitData (void);
     
    144161
    145162/* starfuncs.c */
    146 double get_aperture_stats (Matrix *matrix, int X, int Y, int Npix, int Nborder, double max);
     163double get_aperture_stats (Matrix *matrix, int X, int Y, int Npix, int Nborder, double max, int VERBOSE);
    147164int set_rough_radii (double Ra, double Ri, double Ro);
    148165int get_rough_star (float *data, int Nx, int Ny, int x, int y, opihi_flt *xc, opihi_flt *yc, opihi_flt *sx, opihi_flt *sy, opihi_flt *sxy, opihi_flt *zs, opihi_flt *zp, opihi_flt *sk);
     
    170187void FreeQueues (void);
    171188void FreeBooks (void);
    172 
    173 // the interpolating spline has valu
    174 typedef struct {
    175   int Nknots;
    176   opihi_flt *xk;
    177   opihi_flt *yk;
    178   opihi_flt *y2;
    179   char *name;
    180 } Spline;
    181189
    182190/* in SplineOps.c */
     
    207215double hermitian_10(double x);
    208216
     217/* in MedImageOps.c */
     218void InitMedImages ();
     219void FreeMedImages ();
     220void FreeMedImage (MedImageType *medimage);
     221MedImageType *FindMedImage (char *name);
     222MedImageType *CreateMedImage (char *name, int Nx, int Ny);
     223int DeleteMedImage (MedImageType *medimage);
     224void ListMedImages ();
     225
    209226# endif
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/include/dvomath.h

    r33662 r37067  
    5555} Buffer;
    5656
     57typedef enum {
     58  ST_NONE,
     59  ST_LEFT,
     60  ST_RIGHT,
     61  ST_COMMA,
     62  ST_TRINARY,
     63  ST_OR,
     64  ST_AND,
     65  ST_LOGIC,
     66  ST_BITWISE,
     67  ST_ADD,
     68  ST_TIMES,
     69  ST_POWER,
     70  ST_UNARY,
     71  ST_BINARY,
     72
     73  ST_VALUE,
     74  ST_SCALAR_INT,
     75  ST_SCALAR_FLT,
     76  ST_VECTOR,
     77  ST_VECTOR_TMP,
     78  ST_MATRIX,
     79  ST_MATRIX_TMP,
     80
     81  ST_STRING,
     82  ST_STRING_TMP,
     83} StackVarType;
     84
    5785typedef struct {                        /* math stack structure */
    5886  char   *name;
    59   char    type;
     87  StackVarType type;
    6088  Buffer *buffer;
    6189  Vector *vector;
     
    77105void          delete_stack          PROTO((StackVar *stack, int Nstack));
    78106void          clear_stack           PROTO((StackVar *stack));
    79 void          assign_stack          PROTO((StackVar *stack, char *name, int type));
     107void          assign_stack          PROTO((StackVar *stack, char *name, StackVarType type));
     108
     109int           SSS_trinary           PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op));
     110int           VVV_trinary           PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op));
     111int           MMM_trinary           PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op));
    80112
    81113int           VV_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
     
    138170Vector      **ReadVectorTableFITS   PROTO((char *filename, char *extname, int *Nvec));
    139171
     172int           VectorAssignData          PROTO((Vector **vec, char *type, void *data, int Nrows, int Nval));
     173int           VectorAssignDataTranspose PROTO((Vector **vec, char *type, void *data, int Nrows, int Nval));
     174
    140175/* buffer handling */
    141176Buffer       *InitBuffer            PROTO((void));
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/include/dvoshell.h

    r35416 r37067  
    9090int           wordhash              PROTO((char *word));
    9191
    92 int          GetMagMode             PROTO((char *string));
    93 PhotCode    *ParsePhotcodeField     PROTO((char *field, int *mode, int def));
    94 int          ParseMeasureField      PROTO((dbField *field, char *fieldName));
    95 int          ParseAverageField      PROTO((dbField *field, char *fieldName));
    96 int          ParseImageField        PROTO((dbField *field, char *fieldName));
    97 
    98 dbValue      dbExtractMeasures      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
    99 dbValue      dbExtractImages        PROTO((Image *image, off_t Nimage, off_t N, dbField *field));
    100 
    10192int          HostTableLaunchJobs    PROTO((SkyList *sky, HostTable *table, char *basecmd, char *options, int VERBOSE));
    10293int          HostTableParallelOps   PROTO((SkyList *sky, int argc, char **argv, char *ResultFile, int ReadVectors, int Nelements, int VERBOSE));
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/include/pantasks.h

    r32632 r37067  
    116116
    117117  int active;
    118   int priority;
     118  int nicelevel;
    119119
    120120} Task;
     
    161161
    162162  JobMode     mode;                     /* local or controller? */
    163   int     priority;
     163  int     nicelevel;
    164164  char   *realhost;
    165165
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/include/pcontrol.h

    r33662 r37067  
    88/** job status values **/
    99typedef enum {
     10  PCONTROL_JOB_NONE, // XXX OK?
    1011  PCONTROL_JOB_ALLJOBS,
    1112  PCONTROL_JOB_PENDING,
     
    119120  int          exit_status;
    120121  int          Reset;
    121   int          priority;
     122  int          nicelevel;
    122123  JobMode      mode;
    123124  JobStat      state;
     
    309310char  *GetJobStackName (int StackID);
    310311Stack *GetJobStackByName (char *name);
     312int GetJobStackIDbyName (char *name);
    311313int    PutJob (Job *job, int StackID, int where);
    312314int    PutJobSetState (Job *job, int StackID, int where, int state);
    313315Job   *PullJobByID (IDtype JobID, int *StackID);
    314316Job   *PullJobFromStackByID (int StackID, int ID);
    315 IDtype AddJob (char *hostname, JobMode mode, int timeout, int priority, int argc, char **argv, int Nxhosts, char **xhosts);
     317IDtype AddJob (char *hostname, JobMode mode, int timeout, int nicelevel, int argc, char **argv, int Nxhosts, char **xhosts);
    316318void   DelJob (Job *job);
    317319Host  *UnlinkJobAndHost (Job *job);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/include/shell.h

    r33662 r37067  
    166166// wrap readline in ohana mem functions:
    167167char         *opihi_readline            PROTO((char *prompt));
     168
     169int set_list_varname (char *line, char *base, int N, int excelStyle);
    168170
    169171/* gprint functions */
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/lib.data/Makefile

    r34584 r37067  
    2424$(SDIR)/spline.$(ARCH).o                \
    2525$(SDIR)/SplineOps.$(ARCH).o             \
     26$(SDIR)/MedImageOps.$(ARCH).o           \
    2627$(SDIR)/mrqmin.$(ARCH).o                \
    2728$(SDIR)/mrq2dmin.$(ARCH).o              \
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/lib.data/starfuncs.c

    r34088 r37067  
    11# include "data.h"
    22
    3 double get_aperture_stats (Matrix *matrix, int X, int Y, int Npix, int Nborder, double max) {
     3double get_aperture_stats (Matrix *matrix, int X, int Y, int Npix, int Nborder, double max, int VERBOSE) {
    44
    55  double *ring;
     
    9595  set_int_variable ("Npts", Npts);
    9696 
    97   gprint (GP_LOG, "%f %f %f %f %f %f %f %f\n", x, y, FWHMx, FWHMy, sky, I, mag, dmag);
     97  if (VERBOSE) gprint (GP_LOG, "%f %f %f %f %f %f %f %f\n", x, y, FWHMx, FWHMy, sky, I, mag, dmag);
    9898
    9999  return (mag);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/lib.shell/ListOps.c

    r33963 r37067  
    185185
    186186// list (word) : nested list
    187 // list (word) -x : not nested list
    188 // list (word) -split : not nested list
     187// list (word) -x : not nested list [-x may be the list of options below]
     188// list -excel (word) -x :
    189189int is_list_data (char *line) {
    190190
    191   char *comm, *temp;
    192 
    193   temp = thisword (nextword (nextword (line)));
    194   comm = thisword (line);
    195 
     191  char *comm = NULL;
     192  char *temp = NULL;
     193  char *name  = NULL;
     194  char *opts  = NULL;
     195
     196  comm = thisword (line);
    196197  if (comm == NULL) goto escape;
    197 
    198198  if (strcmp (comm, "list")) goto escape;
     199
     200  // name == name of the list in question
     201  name = nextword (line);
     202
     203  // skip a -excel or -excel-style modifier
     204  if (!strncmp("-excel", name, strlen("-excel"))) name = nextword (name);
     205  if (!strncmp("-excel-style", name, strlen("-excel-style"))) name = nextword (name);
     206
     207  // get the thing following ptr, if any (opts points at a substring, temp is a new string)
     208  opts = nextword (name);
     209  temp = thisword (opts);
    199210
    200211  /* if (cond) (command) does not define a complete block */
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/lib.shell/VectorIO.c

    r35109 r37067  
    134134  FTable ftable;
    135135
    136   int i, j, k;
     136  int i, j;
    137137  FILE *f = NULL;
    138138
     
    202202    assert (status);
    203203
    204 # define ASSIGN_DATA(TYPE,OPTYPE) \
    205     /* assign the data to the actual vector */ \
    206     if (!strcmp (type, #TYPE)) { \
    207       TYPE *Ptr = data;     \
    208       for (k = 0; k < Nrows; k++) { \
    209         for (j = 0; j < Nval; j++, Ptr++) { \
    210           vec[Nvec + j][0].elements.OPTYPE[k] = *Ptr; \
    211         } } }
    212 
    213     // assign the data to the actual vector
    214     ASSIGN_DATA(char,    Int);
    215     ASSIGN_DATA(short,   Int);
    216     ASSIGN_DATA(int,     Int);
    217     ASSIGN_DATA(int64_t, Int);
    218     ASSIGN_DATA(float,   Flt);
    219     ASSIGN_DATA(double,  Flt);
     204    if (!VectorAssignData(&vec[Nvec], type, data, Nrows, Nval)) {
     205      // free unneeded things
     206      gprint (GP_ERR, "trouble parsing data block type %s\n", type);
     207      return (NULL);
     208    }
    220209
    221210    free (data);
     
    241230//  return (FALSE);
    242231}
     232
     233# define ASSIGN_DATA(TYPE,DTYPE,OPTYPE)        \
     234    /* assign the data to the actual vector */ \
     235    if (!strcmp (type, #TYPE)) { \
     236      DTYPE *Ptr = data;                    \
     237      for (k = 0; k < Nrows; k++) { \
     238        for (j = 0; j < Nval; j++, Ptr++) { \
     239          vec[j][0].elements.OPTYPE[k] = *Ptr; \
     240          } } return TRUE; }
     241
     242int VectorAssignData (Vector **vec, char *type, void *data, int Nrows, int Nval) {
     243
     244  int j, k;
     245
     246  // assign the data to the actual vector
     247  ASSIGN_DATA(byte,    char,    Int);
     248  ASSIGN_DATA(char,    char,    Int);
     249  ASSIGN_DATA(short,   short,   Int);
     250  ASSIGN_DATA(int,     int,     Int);
     251  ASSIGN_DATA(int64_t, int64_t, Int);
     252  ASSIGN_DATA(float,   float,   Flt);
     253  ASSIGN_DATA(double,  double,  Flt);
     254
     255  return FALSE;
     256}
     257
     258# define ASSIGN_DATA_TRANSPOSE(TYPE,DTYPE,OPTYPE)       \
     259    /* assign the data to the actual vector */ \
     260    if (!strcmp (type, #TYPE)) { \
     261      DTYPE *Ptr = data;                    \
     262      for (k = 0; k < Nrows; k++) { \
     263        for (j = 0; j < Nval; j++, Ptr++) { \
     264          vec[k][0].elements.OPTYPE[j] = *Ptr; \
     265          } } return TRUE; }
     266
     267int VectorAssignDataTranspose (Vector **vec, char *type, void *data, int Nrows, int Nval) {
     268
     269  int j, k;
     270
     271  // assign the data to the actual vector
     272  ASSIGN_DATA_TRANSPOSE(byte,    char,    Int);
     273  ASSIGN_DATA_TRANSPOSE(char,    char,    Int);
     274  ASSIGN_DATA_TRANSPOSE(short,   short,   Int);
     275  ASSIGN_DATA_TRANSPOSE(int,     int,     Int);
     276  ASSIGN_DATA_TRANSPOSE(int64_t, int64_t, Int);
     277  ASSIGN_DATA_TRANSPOSE(float,   float,   Flt);
     278  ASSIGN_DATA_TRANSPOSE(double,  double,  Flt);
     279
     280  return FALSE;
     281}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/lib.shell/check_stack.c

    r34260 r37067  
    1212
    1313  for (i = 0; i < Nstack; i++) {
    14     if (stack[i].type == 'X') {
     14    if (stack[i].type == ST_VALUE) {
    1515
    1616      /** if this is a number, put it on the list of scalars and move on.  assume value is
     
    2727      stack[i].IntValue = strtol (stack[i].name, &c2, 0);
    2828      if ((fabs(stack[i].FltValue) > MAX_INT) && (c1 == stack[i].name + strlen (stack[i].name))) {
    29         stack[i].type  = 'S'; // 'S' == (float)
     29        stack[i].type  = ST_SCALAR_FLT; // (float)
    3030        continue;
    3131      }
    3232      if (c2 == stack[i].name + strlen (stack[i].name)) {
    33         stack[i].type  = 's'; // 's' == (int)
     33        stack[i].type  = ST_SCALAR_INT; // (int)
    3434        continue;
    3535      }
    3636      if (c1 == stack[i].name + strlen (stack[i].name)) {
    37         stack[i].type  = 'S'; // 'S' == (float)
     37        stack[i].type  = ST_SCALAR_FLT; // (float)
    3838        continue;
    3939      }
     
    4242      if (IsBuffer (stack[i].name)) {
    4343        stack[i].buffer = SelectBuffer (stack[i].name, OLDBUFFER, TRUE);
    44         stack[i].type   = 'M';
     44        stack[i].type   = ST_MATRIX;
    4545        if (Nx == -1) {
    4646          Nx = stack[i].buffer[0].matrix.Naxis[0];
     
    6363      if (IsVector (stack[i].name)) {
    6464        stack[i].vector = SelectVector (stack[i].name, OLDVECTOR, FALSE);
    65         stack[i].type   = 'V';
     65        stack[i].type   = ST_VECTOR;
    6666
    6767        if (Nv == -1) Nv = stack[i].vector[0].Nelements;
     
    8080
    8181      /* this is not a scalar, vector, or matrix.  must be string */
    82       stack[i].type  = 'W';
     82      stack[i].type  = ST_STRING;
    8383    }
    8484  }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/lib.shell/convert_to_RPN.c

    r34088 r37067  
    44StackVar *convert_to_RPN (int argc, char **argv, int *nstack) {
    55 
    6   int type;
     6 StackVarType type;
    77  int i, j, Nstack, Nop_stack, NSTACK;
    88  StackVar *stack, *op_stack;
     
    2121   
    2222    /* decide on priority of object */
    23     type = 0;
     23    type = ST_NONE;
     24
     25    /* trinary operations */
     26    if (!strcmp (argv[i], "?"))      { type = ST_TRINARY; goto gotit; }
     27    if (!strcmp (argv[i], ":"))      { type = ST_COMMA; goto gotit; }
     28
    2429    /* unary operations */
    25     if (!strcmp (argv[i], "abs"))    { type = 9; goto gotit; }
    26     if (!strcmp (argv[i], "int"))    { type = 9; goto gotit; }
    27     if (!strcmp (argv[i], "exp"))    { type = 9; goto gotit; }
    28     if (!strcmp (argv[i], "ten"))    { type = 9; goto gotit; }
    29     if (!strcmp (argv[i], "log"))    { type = 9; goto gotit; }
    30     if (!strcmp (argv[i], "ln"))     { type = 9; goto gotit; }
    31     if (!strcmp (argv[i], "sqrt"))   { type = 9; goto gotit; }
    32     if (!strcmp (argv[i], "erf"))    { type = 9; goto gotit; }
    33 
    34     if (!strcmp (argv[i], "sinh"))   { type = 9; goto gotit; }
    35     if (!strcmp (argv[i], "cosh"))   { type = 9; goto gotit; }
    36     if (!strcmp (argv[i], "asinh"))  { type = 9; goto gotit; }
    37     if (!strcmp (argv[i], "acosh"))  { type = 9; goto gotit; }
    38 
    39     if (!strcmp (argv[i], "sin"))    { type = 9; goto gotit; }
    40     if (!strcmp (argv[i], "cos"))    { type = 9; goto gotit; }
    41     if (!strcmp (argv[i], "tan"))    { type = 9; goto gotit; }
    42     if (!strcmp (argv[i], "dsin"))   { type = 9; goto gotit; }
    43     if (!strcmp (argv[i], "dcos"))   { type = 9; goto gotit; }
    44     if (!strcmp (argv[i], "dtan"))   { type = 9; goto gotit; }
    45     if (!strcmp (argv[i], "asin"))   { type = 9; goto gotit; }
    46     if (!strcmp (argv[i], "acos"))   { type = 9; goto gotit; }
    47     if (!strcmp (argv[i], "atan"))   { type = 9; goto gotit; }
    48     if (!strcmp (argv[i], "dasin"))  { type = 9; goto gotit; }
    49     if (!strcmp (argv[i], "dacos"))  { type = 9; goto gotit; }
    50     if (!strcmp (argv[i], "datan"))  { type = 9; goto gotit; }
    51 
    52     if (!strcmp (argv[i], "lgamma")) { type = 9; goto gotit; }
    53 
    54     if (!strcmp (argv[i], "rnd"))    { type = 9; goto gotit; }
    55     if (!strcmp (argv[i], "xramp"))  { type = 9; goto gotit; }
    56     if (!strcmp (argv[i], "yramp"))  { type = 9; goto gotit; }
    57     if (!strcmp (argv[i], "ramp"))   { type = 9; goto gotit; }
    58     if (!strcmp (argv[i], "zero"))   { type = 9; goto gotit; }
    59     if (!strcmp (argv[i], "--"))     { type = 9; goto gotit; }
    60     if (!strcmp (argv[i], "not"))    { type = 9; goto gotit; }
    61     if (!strcmp (argv[i], "isinf"))  { type = 9; goto gotit; }
    62     if (!strcmp (argv[i], "isnan"))  { type = 9; goto gotit; }
     30    if (!strcmp (argv[i], "abs"))    { type = ST_UNARY; goto gotit; }
     31    if (!strcmp (argv[i], "int"))    { type = ST_UNARY; goto gotit; }
     32    if (!strcmp (argv[i], "floor"))  { type = ST_UNARY; goto gotit; }
     33    if (!strcmp (argv[i], "round"))  { type = ST_UNARY; goto gotit; }
     34    if (!strcmp (argv[i], "ceil"))   { type = ST_UNARY; goto gotit; }
     35    if (!strcmp (argv[i], "rint"))   { type = ST_UNARY; goto gotit; }
     36    if (!strcmp (argv[i], "exp"))    { type = ST_UNARY; goto gotit; }
     37    if (!strcmp (argv[i], "ten"))    { type = ST_UNARY; goto gotit; }
     38    if (!strcmp (argv[i], "log"))    { type = ST_UNARY; goto gotit; }
     39    if (!strcmp (argv[i], "ln"))     { type = ST_UNARY; goto gotit; }
     40    if (!strcmp (argv[i], "sqrt"))   { type = ST_UNARY; goto gotit; }
     41    if (!strcmp (argv[i], "erf"))    { type = ST_UNARY; goto gotit; }
     42    if (!strcmp (argv[i], "sinh"))   { type = ST_UNARY; goto gotit; }
     43    if (!strcmp (argv[i], "cosh"))   { type = ST_UNARY; goto gotit; }
     44    if (!strcmp (argv[i], "asinh"))  { type = ST_UNARY; goto gotit; }
     45    if (!strcmp (argv[i], "acosh"))  { type = ST_UNARY; goto gotit; }
     46    if (!strcmp (argv[i], "sin"))    { type = ST_UNARY; goto gotit; }
     47    if (!strcmp (argv[i], "cos"))    { type = ST_UNARY; goto gotit; }
     48    if (!strcmp (argv[i], "tan"))    { type = ST_UNARY; goto gotit; }
     49    if (!strcmp (argv[i], "dsin"))   { type = ST_UNARY; goto gotit; }
     50    if (!strcmp (argv[i], "dcos"))   { type = ST_UNARY; goto gotit; }
     51    if (!strcmp (argv[i], "dtan"))   { type = ST_UNARY; goto gotit; }
     52    if (!strcmp (argv[i], "asin"))   { type = ST_UNARY; goto gotit; }
     53    if (!strcmp (argv[i], "acos"))   { type = ST_UNARY; goto gotit; }
     54    if (!strcmp (argv[i], "atan"))   { type = ST_UNARY; goto gotit; }
     55    if (!strcmp (argv[i], "dasin"))  { type = ST_UNARY; goto gotit; }
     56    if (!strcmp (argv[i], "dacos"))  { type = ST_UNARY; goto gotit; }
     57    if (!strcmp (argv[i], "datan"))  { type = ST_UNARY; goto gotit; }
     58    if (!strcmp (argv[i], "lgamma")) { type = ST_UNARY; goto gotit; }
     59    if (!strcmp (argv[i], "rnd"))    { type = ST_UNARY; goto gotit; }
     60    if (!strcmp (argv[i], "xramp"))  { type = ST_UNARY; goto gotit; }
     61    if (!strcmp (argv[i], "yramp"))  { type = ST_UNARY; goto gotit; }
     62    if (!strcmp (argv[i], "ramp"))   { type = ST_UNARY; goto gotit; }
     63    if (!strcmp (argv[i], "zero"))   { type = ST_UNARY; goto gotit; }
     64    if (!strcmp (argv[i], "--"))     { type = ST_UNARY; goto gotit; }
     65    if (!strcmp (argv[i], "not"))    { type = ST_UNARY; goto gotit; }
     66    if (!strcmp (argv[i], "isinf"))  { type = ST_UNARY; goto gotit; }
     67    if (!strcmp (argv[i], "isnan"))  { type = ST_UNARY; goto gotit; }
    6368
    6469    /* binary operations */
    65     if (!strcmp (argv[i], "^"))      { type = 8; goto gotit; }
    66 
    67     if (!strcmp (argv[i], "@"))      { type = 7; goto gotit; }
    68     if (!strcmp (argv[i], "/"))      { type = 7; goto gotit; }
    69     if (!strcmp (argv[i], "*"))      { type = 7; goto gotit; }
    70     if (!strcmp (argv[i], "%"))      { type = 7; goto gotit; }
    71 
    72     if (!strcmp (argv[i], "+"))      { type = 6; goto gotit; }
    73     if (!strcmp (argv[i], "-"))      { type = 6; goto gotit; }
     70    if (!strcmp (argv[i], "^"))      { type = ST_POWER; goto gotit; }
     71
     72    if (!strcmp (argv[i], "max"))    { type = ST_BINARY; strcpy (argv[i], "U"); goto gotit; }
     73    if (!strcmp (argv[i], "min"))    { type = ST_BINARY; strcpy (argv[i], "D"); goto gotit; }
     74    if (!strcmp (argv[i], "atan2"))  { type = ST_BINARY; goto gotit; }
     75    if (!strcmp (argv[i], ","))      { type = ST_COMMA; goto gotit; }
     76
     77    if (!strcmp (argv[i], "@"))      { type = ST_TIMES; goto gotit; }
     78    if (!strcmp (argv[i], "/"))      { type = ST_TIMES; goto gotit; }
     79    if (!strcmp (argv[i], "*"))      { type = ST_TIMES; goto gotit; }
     80    if (!strcmp (argv[i], "%"))      { type = ST_TIMES; goto gotit; }
     81
     82    if (!strcmp (argv[i], "+"))      { type = ST_ADD; goto gotit; }
     83    if (!strcmp (argv[i], "-"))      { type = ST_ADD; goto gotit; }
    7484       
    75     if (!strcmp (argv[i], "&"))      { type = 5; goto gotit; }
    76     if (!strcmp (argv[i], "|"))      { type = 5; goto gotit; }
    77 
    78     if (!strcmp (argv[i], "<"))      { type = 4; goto gotit; }
    79     if (!strcmp (argv[i], ">"))      { type = 4; goto gotit; }
    80     if (!strcmp (argv[i], "=="))     { type = 4; strcpy (argv[i], "E"); goto gotit; }
    81     if (!strcmp (argv[i], "!="))     { type = 4; strcpy (argv[i], "N"); goto gotit; }
    82     if (!strcmp (argv[i], "<="))     { type = 4; strcpy (argv[i], "L"); goto gotit; }
    83     if (!strcmp (argv[i], ">="))     { type = 4; strcpy (argv[i], "G"); goto gotit; }
    84     if (!strcmp (argv[i], ">>"))     { type = 4; strcpy (argv[i], "U"); goto gotit; }
    85     if (!strcmp (argv[i], "<<"))     { type = 4; strcpy (argv[i], "D"); goto gotit; }
    86 
    87     if (!strcmp (argv[i], "&&"))     { type = 3; strcpy (argv[i], "A"); goto gotit; }
    88     if (!strcmp (argv[i], "||"))     { type = 3; strcpy (argv[i], "O"); goto gotit; }
    89 
    90     if (!strcmp (argv[i], "("))      { type = 2; goto gotit; }
    91     if (!strcmp (argv[i], ")"))      { type = 1; goto gotit; }
     85    if (!strcmp (argv[i], "&"))      { type = ST_BITWISE; goto gotit; }
     86    if (!strcmp (argv[i], "|"))      { type = ST_BITWISE; goto gotit; }
     87
     88    if (!strcmp (argv[i], "<"))      { type = ST_LOGIC; goto gotit; }
     89    if (!strcmp (argv[i], ">"))      { type = ST_LOGIC; goto gotit; }
     90    if (!strcmp (argv[i], "=="))     { type = ST_LOGIC; strcpy (argv[i], "E"); goto gotit; }
     91    if (!strcmp (argv[i], "!="))     { type = ST_LOGIC; strcpy (argv[i], "N"); goto gotit; }
     92    if (!strcmp (argv[i], "<="))     { type = ST_LOGIC; strcpy (argv[i], "L"); goto gotit; }
     93    if (!strcmp (argv[i], ">="))     { type = ST_LOGIC; strcpy (argv[i], "G"); goto gotit; }
     94    if (!strcmp (argv[i], ">>"))     { type = ST_LOGIC; strcpy (argv[i], "U"); goto gotit; }
     95    if (!strcmp (argv[i], "<<"))     { type = ST_LOGIC; strcpy (argv[i], "D"); goto gotit; }
     96
     97    if (!strcmp (argv[i], "&&"))     { type = ST_AND; strcpy (argv[i], "A"); goto gotit; }
     98    if (!strcmp (argv[i], "||"))     { type = ST_OR ; strcpy (argv[i], "O"); goto gotit; }
     99
     100    if (!strcmp (argv[i], "("))      { type = ST_LEFT; goto gotit; }
     101    if (!strcmp (argv[i], ")"))      { type = ST_RIGHT; goto gotit; }
    92102
    93103  gotit:
    94104    /* choose how to deal with object */
    95105    switch (type) {
    96       case 8:  /* exponentiation: 2^2^3 = 64 != 256 (precedence is right-to-left, not left-to-right!) */
     106      case ST_POWER:  /* exponentiation: 2^2^3 = 64 != 256 (precedence is right-to-left, not left-to-right!) */
    97107        /* pop previous, higher operators from OP stack to stack */
    98108        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type > type); j--) {
     
    105115        Nop_stack ++;
    106116        break;
    107       case 9: /* unary OPs */
    108       case 7: /* binary OPs */
    109       case 6:
    110       case 5:
    111       case 4:
    112       case 3:
     117      case ST_UNARY:
     118      case ST_BINARY:
     119      case ST_TRINARY:
     120      case ST_TIMES:
     121      case ST_ADD:
     122      case ST_BITWISE:
     123      case ST_LOGIC:
     124      case ST_AND:
     125      case ST_OR:
    113126        /* pop previous, higher or equal operators from OP stack to stack */
    114127        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type >= type); j--) {
     
    121134        Nop_stack ++;
    122135        break;
    123       case 2
     136      case ST_LEFT
    124137        /* push operator on OP stack */
    125138        assign_stack (&op_stack[Nop_stack], argv[i], type);
     
    127140        Nop_stack ++;
    128141        break;
    129       case 1:
     142      case ST_RIGHT:
    130143        /* pop rest of operators from OP stack to stack, looking for '(' */
    131         for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != 2); j--) {
    132           move_stack (&stack[Nstack], &op_stack[j]);
    133           Nstack ++;
    134           Nop_stack --;
    135         }
    136         if ((j == -1) || (op_stack[j].type != 2)) {
     144        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != ST_LEFT); j--) {
     145          move_stack (&stack[Nstack], &op_stack[j]);
     146          Nstack ++;
     147          Nop_stack --;
     148        }
     149        if ((j == -1) || (op_stack[j].type != ST_LEFT)) {
    137150          push_error ("syntax error: mismatched parenthesis");
    138151          Nstack = 0;
     
    144157        Nop_stack --;
    145158        break;
    146       case 0:
     159      case ST_COMMA:
     160        /* pop rest of operators from OP stack to stack, looking for '(' (but do not pop the '(')*/
     161        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != ST_LEFT) && (op_stack[j].type != ST_TRINARY); j--) {
     162          move_stack (&stack[Nstack], &op_stack[j]);
     163          Nstack ++;
     164          Nop_stack --;
     165        }
     166        break;
     167      case ST_NONE:
    147168        /* place the value (number or vector/matrix name) on stack */
    148169        /* value of 'X' is used as sentinel until we sort out values */
    149         assign_stack (&stack[Nstack], argv[i], 'X');
     170        assign_stack (&stack[Nstack], argv[i], ST_VALUE);
    150171        Nstack ++;
    151172        break;
     173
     174      default:
     175        push_error ("invalid stack typ");
     176        Nstack = 0;
     177        goto cleanup;
    152178    }
    153179  }
    154180
    155   /* dump remaining operators on stack, checking for ')' */
     181  /* dump remaining operators on stack, checking for '(' */
    156182  for (j = Nop_stack - 1; j >= 0; j--) {
    157     if (op_stack[j].type == 2) {
     183    if (op_stack[j].type == ST_LEFT) {
    158184      push_error ("syntax error: mismatched parenthesis");
    159185      Nstack = 0;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/lib.shell/dvomath.c

    r31635 r37067  
    8080        sprintf (outname, "%s", stack[0].name);
    8181      } else {
    82         if (stack[0].type == 's') {
     82        if (stack[0].type == ST_SCALAR_INT) {
    8383          sprintf (outname, "%d", stack[0].IntValue);
    8484        } else {
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/lib.shell/evaluate_stack.c

    r34088 r37067  
    22# define VERBOSE 0
    33
    4 # define TWO_OP(A,B,FUNC) \
    5   if (!strncasecmp (&stack[i - 2].type, A, 1) && !strncasecmp (&stack[i - 1].type, B, 1)) \
    6     status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
    7 
    8 # define ONE_OP(A,FUNC) \
    9   if (!strncasecmp (&stack[i - 1].type, A, 1)) \
    10     status = FUNC (&tmp_stack, &stack[i - 1], stack[i].name);
     4// all three operands must have the same type
     5# define THREE_OP(A,FUNC)                                               \
     6  if ((stack[i - 3].type == A) && (stack[i - 2].type == A) && (stack[i - 1].type == A)) { \
     7    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     8    goto got_three_op; } \
     9  if ((stack[i - 3].type == A+1) && (stack[i - 2].type == A) && (stack[i - 1].type == A)) { \
     10    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     11    goto got_three_op; } \
     12  if ((stack[i - 3].type == A) && (stack[i - 2].type == A+1) && (stack[i - 1].type == A)) { \
     13    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     14    goto got_three_op; } \
     15  if ((stack[i - 3].type == A+1) && (stack[i - 2].type == A+1) && (stack[i - 1].type == A)) { \
     16    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     17    goto got_three_op; } \
     18  if ((stack[i - 3].type == A) && (stack[i - 2].type == A) && (stack[i - 1].type == A+1)) { \
     19    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     20    goto got_three_op; } \
     21  if ((stack[i - 3].type == A+1) && (stack[i - 2].type == A) && (stack[i - 1].type == A+1)) { \
     22    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     23    goto got_three_op; } \
     24  if ((stack[i - 3].type == A) && (stack[i - 2].type == A+1) && (stack[i - 1].type == A+1)) { \
     25    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     26    goto got_three_op; } \
     27  if ((stack[i - 3].type == A+1) && (stack[i - 2].type == A+1) && (stack[i - 1].type == A+1)) { \
     28    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     29    goto got_three_op; } \
     30
     31// A & B value types all have 2 possible values
     32# define TWO_OP(A,B,FUNC) {                                             \
     33    if ((stack[i - 2].type == A) && (stack[i - 1].type == B)) {         \
     34      status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); \
     35      goto got_two_op; }                                                \
     36    if ((stack[i - 2].type == A+1) && (stack[i - 1].type == B)) {       \
     37      status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); \
     38      goto got_two_op; }                                                \
     39    if ((stack[i - 2].type == A) && (stack[i - 1].type == B+1)) {       \
     40      status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); \
     41      goto got_two_op; }                                                \
     42    if ((stack[i - 2].type == A+1) && (stack[i - 1].type == B+1)) {     \
     43      status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); \
     44      goto got_two_op; } \
     45  }
     46
     47# define ONE_OP(A,FUNC)                                         \
     48  if (stack[i - 1].type == A) {                                 \
     49    status = FUNC (&tmp_stack, &stack[i - 1], stack[i].name);   \
     50    goto got_one_op; }
    1151
    1252int evaluate_stack (StackVar *stack, int *Nstack) {
     
    2060
    2161  if (*Nstack == 1) {
    22     if ((stack[0].type == 'S') || (stack[0].type == 's')) {
     62    if ((stack[0].type == ST_SCALAR_INT) || (stack[0].type == ST_SCALAR_FLT)) {
    2363      clear_stack (&tmp_stack);
    2464      return (TRUE);
    2565    }
    26     if (stack[0].type == 'V') {
     66    if (stack[0].type == ST_VECTOR) {
    2767      /* need to make a copy so we set output value? */
    2868      V_unary (&tmp_stack, &stack[0], "=");
     
    3070      return (TRUE);
    3171    }
    32     if (stack[0].type == 'M') {
     72    if (stack[0].type == ST_MATRIX) {
    3373      /* need to make a copy so we set output value? */
    3474      M_unary (&tmp_stack, &stack[0], "=");
     
    5696    }
    5797
    58     /***** binary operators *****/
    59     if ((stack[i].type >= 3) && (stack[i].type <= 8)) {
    60 
    61       if (i < 2) {  /* need two variables to operate on */
    62         sprintf (line, "syntax error: binary operator with one operand: %s\n", stack[i].name);
     98    /***** trinary operators *****/
     99    switch (stack[i].type) {
     100      case ST_TRINARY:
     101
     102        if (i < 3) {  /* need two variables to operate on */
     103          snprintf (line, 512, "syntax error: trinary operator without three operands: %s\n", stack[i].name);
     104          push_error (line);
     105          clear_stack (&tmp_stack);
     106          return (FALSE);
     107        }
     108
     109        status = FALSE;
     110        THREE_OP (ST_MATRIX,MMM_trinary);
     111        THREE_OP (ST_VECTOR,VVV_trinary);
     112
     113        THREE_OP (ST_SCALAR_FLT,SSS_trinary);
     114        THREE_OP (ST_SCALAR_INT,SSS_trinary);
     115
     116        /* there are no valid unary string operators */
     117        push_error ("invalid operands for trinary operator (mismatch types?)");
     118        clear_stack (&tmp_stack);
     119        return (FALSE);
     120
     121      got_three_op:
     122        if (!status) {
     123          snprintf (line, 512, "syntax error: invalid operand for binary operation: %s or %s or %s\n", stack[i-1].name, stack[i-2].name, stack[i-3].name);
     124          push_error (line);
     125          clear_stack (&tmp_stack);
     126          return (FALSE);
     127        }
     128        move_stack (&stack[i-3], &tmp_stack);
     129        delete_stack (&stack[i-2], 3);
     130        for (j = i + 1; j < *Nstack; j++) {
     131          move_stack (&stack[j-3], &stack[j]);
     132        }
     133        *Nstack -= 3;
     134        i -= 3;
     135        init_stack (&tmp_stack);
     136        continue;
     137
     138        /***** binary operators *****/
     139      case ST_OR:
     140      case ST_AND:
     141      case ST_LOGIC:
     142      case ST_BITWISE:
     143      case ST_ADD:
     144      case ST_TIMES:
     145      case ST_POWER:
     146      case ST_BINARY:
     147
     148        if (i < 2) {  /* need two variables to operate on */
     149          snprintf (line, 512, "syntax error: binary operator with one operand: %s\n", stack[i].name);
     150          push_error (line);
     151          clear_stack (&tmp_stack);
     152          return (FALSE);
     153        }
     154
     155        status = FALSE;
     156        TWO_OP (ST_MATRIX,ST_MATRIX,MM_binary);
     157        TWO_OP (ST_MATRIX,ST_VECTOR,MV_binary);
     158        TWO_OP (ST_MATRIX,ST_SCALAR_INT,MS_binary);
     159
     160        TWO_OP (ST_VECTOR,ST_MATRIX,VM_binary);
     161        TWO_OP (ST_VECTOR,ST_VECTOR,VV_binary);
     162        TWO_OP (ST_VECTOR,ST_SCALAR_INT,VS_binary);
     163
     164        TWO_OP (ST_SCALAR_INT,ST_MATRIX,SM_binary);
     165        TWO_OP (ST_SCALAR_INT,ST_VECTOR,SV_binary);
     166        TWO_OP (ST_SCALAR_INT,ST_SCALAR_INT,SS_binary);     
     167
     168        TWO_OP (ST_SCALAR_FLT,ST_MATRIX,SM_binary);
     169        TWO_OP (ST_SCALAR_FLT,ST_VECTOR,SV_binary);
     170        TWO_OP (ST_SCALAR_FLT,ST_SCALAR_INT,SS_binary);     
     171
     172        TWO_OP (ST_STRING,ST_STRING,WW_binary);     
     173        TWO_OP (ST_STRING,ST_SCALAR_INT,WW_binary);     
     174        TWO_OP (ST_SCALAR_INT,ST_STRING,WW_binary);     
     175     
     176      got_two_op:
     177        if (!status) {
     178          snprintf (line, 512, "syntax error: invalid operand for binary operation: %s or %s\n", stack[i-1].name, stack[i-2].name);
     179          push_error (line);
     180          clear_stack (&tmp_stack);
     181          return (FALSE);
     182        }
     183        move_stack (&stack[i-2], &tmp_stack);
     184        delete_stack (&stack[i-1], 2);
     185        for (j = i + 1; j < *Nstack; j++) {
     186          move_stack (&stack[j - 2], &stack[j]);
     187        }
     188        *Nstack -= 2;
     189        i -= 2;
     190        init_stack (&tmp_stack);
     191        continue;
     192
     193        /***** unary operators **/
     194      case ST_UNARY:
     195
     196        if (i < 1) {  /* need one variable to operate on */
     197          push_error ("syntax error: unary operator with no operand");
     198          clear_stack (&tmp_stack);
     199          return (FALSE);
     200        }
     201
     202        ONE_OP (ST_MATRIX, M_unary);
     203        ONE_OP (ST_MATRIX_TMP, M_unary);
     204
     205        ONE_OP (ST_VECTOR, V_unary);
     206        ONE_OP (ST_VECTOR_TMP, V_unary);
     207
     208        ONE_OP (ST_SCALAR_INT, S_unary);
     209        ONE_OP (ST_SCALAR_FLT, S_unary);
     210
     211        /* there are no valid unary string operators */
     212        push_error ("syntax error: no valid string unary ops");
     213        clear_stack (&tmp_stack);
     214        return (FALSE);
     215
     216      got_one_op:
     217        move_stack (&stack[i-1], &tmp_stack);
     218        delete_stack (&stack[i], 1);
     219        for (j = i + 1; j < *Nstack; j++) {
     220          move_stack (&stack[j - 1], &stack[j]);
     221        }
     222        init_stack (&tmp_stack);
     223        *Nstack -= 1;
     224        i -= 1;
     225        continue;
     226
     227      case ST_SCALAR_INT:
     228      case ST_SCALAR_FLT:
     229      case ST_VECTOR:
     230      case ST_VECTOR_TMP:
     231      case ST_MATRIX:
     232      case ST_MATRIX_TMP:
     233      case ST_STRING:
     234        continue;
     235
     236      default:
     237        snprintf (line, 512, "syntax error: unexpected operator type %s", stack[i].name);
    63238        push_error (line);
    64239        clear_stack (&tmp_stack);
    65240        return (FALSE);
    66       }
    67 
    68       status = FALSE;
    69       TWO_OP ("M","M",MM_binary);
    70       TWO_OP ("M","V",MV_binary);
    71       TWO_OP ("M","S",MS_binary);
    72       TWO_OP ("V","M",VM_binary);
    73       TWO_OP ("V","V",VV_binary);
    74       TWO_OP ("V","S",VS_binary);
    75       TWO_OP ("S","M",SM_binary);
    76       TWO_OP ("S","V",SV_binary);
    77       TWO_OP ("S","S",SS_binary);     
    78       TWO_OP ("W","W",WW_binary);     
    79       TWO_OP ("W","S",WW_binary);     
    80       TWO_OP ("S","W",WW_binary);     
    81      
    82       if (!status) {
    83         sprintf (line, "syntax error: invalid operand for binary operation: %s or %s\n", stack[i-1].name, stack[i-2].name);
    84         push_error (line);
    85         clear_stack (&tmp_stack);
    86         return (FALSE);
    87       }
    88       move_stack (&stack[i-2], &tmp_stack);
    89       delete_stack (&stack[i-1], 2);
    90       for (j = i + 1; j < *Nstack; j++) {
    91         move_stack (&stack[j - 2], &stack[j]);
    92       }
    93       *Nstack -= 2;
    94       i -= 2;
    95       init_stack (&tmp_stack);
    96       continue;
    97     }
    98 
    99     /***** unary operators **/
    100     if (stack[i].type == 9) {
    101 
    102       if (i < 1) {  /* need one variable to operate on */
    103         push_error ("syntax error: unary operator with no operand");
    104         clear_stack (&tmp_stack);
    105         return (FALSE);
    106       }
    107 
    108       ONE_OP ("M", M_unary);
    109       ONE_OP ("V", V_unary);
    110       ONE_OP ("S", S_unary);
    111 
    112       /* there are no valid unary string operators */
    113       if (!strncasecmp (&stack[i - 1].type, "W", 1)) {
    114         push_error ("syntax error: no valid string unary ops");
    115         clear_stack (&tmp_stack);
    116         return (FALSE);
    117       }
    118 
    119       move_stack (&stack[i-1], &tmp_stack);
    120       delete_stack (&stack[i], 1);
    121       for (j = i + 1; j < *Nstack; j++) {
    122         move_stack (&stack[j - 1], &stack[j]);
    123       }
    124       init_stack (&tmp_stack);
    125       *Nstack -= 1;
    126       i -= 1;
    127       continue;
    128     }
     241    }
    129242  }
    130243  clear_stack (&tmp_stack);
     
    160273
    161274  for (i = 0; i < Nstack; i++) {
    162     if (IsBufferPtr (stack[i].buffer) && (stack[i].type == 'm')) {
     275    if (IsBufferPtr (stack[i].buffer) && (stack[i].type == ST_MATRIX_TMP)) {
    163276      if (VERBOSE) gprint (GP_ERR, "free %s (buff) (%lx)\n", stack[i].name, (long) stack[i].buffer);
    164277      free (stack[i].buffer[0].header.buffer);
     
    167280      stack[i].buffer = NULL;
    168281    }   
    169     if (IsVectorPtr (stack[i].vector) && (stack[i].type == 'v')) {
     282    if (IsVectorPtr (stack[i].vector) && (stack[i].type == ST_VECTOR_TMP)) {
    170283      if (VERBOSE) gprint (GP_ERR, "free %s (vect) (%lx)\n", stack[i].name, (long) stack[i].vector);
    171284      free (stack[i].vector[0].elements.Ptr);
     
    193306}
    194307
    195 void assign_stack (StackVar *stack, char *name, int type) {
     308void assign_stack (StackVar *stack, char *name, StackVarType type) {
    196309  stack->name = strcreate (name);
    197310  stack->type = type;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/lib.shell/macro_list.c

    r7917 r37067  
    1111  }
    1212
    13   macro = MatchMacro (argv[0], FALSE, TRUE);
     13  macro = MatchMacro (argv[1], FALSE, TRUE);
    1414  if (macro == NULL) {
    1515    gprint (GP_ERR, "%s: Macro not found\n", argv[1]);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/lib.shell/stack_math.c

    r34342 r37067  
    66*/
    77
    8 // XXX we temporarily drop the concept of using one of the temporary input vectors for
    9 // the output vector (thus saving an ALLOC): we have to juggle the size of the input vectors
    10 // as well as their temporary state
    11 
    12 int VV_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) {
     8int SSS_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) {
     9
     10  char line[512]; // this is only used to report an error
     11 
     12  // set up the possible operations : int OP int -> int, all else yield float
     13  // OP is the operation performed on *M1 and *M2
     14# define SSS_FUNC(OP) {                                         \
     15    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT) && (V3->type == ST_SCALAR_FLT)) { \
     16      opihi_flt M1  =  V1[0].FltValue;                  \
     17      opihi_flt M2  =  V2[0].FltValue;                  \
     18      opihi_flt M3  =  V3[0].FltValue;                  \
     19      OUT[0].type = ST_SCALAR_FLT;                      \
     20      OUT[0].FltValue = OP;                                                     \
     21      break;                                                            \
     22    }                                                                   \
     23    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT) && (V3->type == ST_SCALAR_INT)) { \
     24      opihi_int M1  =  V1[0].IntValue;                  \
     25      opihi_int M2  =  V2[0].IntValue;                  \
     26      opihi_int M3  =  V3[0].IntValue;                  \
     27      OUT[0].type = ST_SCALAR_INT;                      \
     28      OUT[0].IntValue = OP;                                                     \
     29      break;                                                            \
     30    }                                                                   \
     31  }
     32
     33  switch (op[0]) {
     34    case '?': SSS_FUNC(M1 ? M2: M3);
     35    default:
     36      snprintf (line, 512, "error: op %c not defined!", op[0]);
     37      push_error (line);
     38      return (FALSE);
     39  }
     40# undef SSS_FUNC
     41
     42  clear_stack (V1);
     43  clear_stack (V2);
     44  clear_stack (V3);
     45  return (TRUE);
     46
     47}
     48
     49int VVV_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) {
    1350
    1451  int i, Nx;
     
    1956    return (FALSE);
    2057  }
     58  if (V1[0].vector[0].Nelements != V3[0].vector[0].Nelements) {
     59    return (FALSE);
     60  }
    2161
    2262  Nx = V1[0].vector[0].Nelements;
     
    2464  // create the output vector guaranteed to be temporary until the very end
    2565  OUT[0].vector = InitVector ();
    26   OUT[0].type = 'v';
     66  OUT[0].type = ST_VECTOR_TMP;
     67
     68  // set up the possible operations : int OP int -> int, all else yield float
     69  // OP is the operation performed on *M1 and *M2
     70# define VVV_FUNC(OP) {                                         \
     71    if ((V1->vector->type == OPIHI_FLT) && (V2->vector->type == OPIHI_FLT) && (V3->vector->type == OPIHI_FLT)) { \
     72      CopyVector (OUT[0].vector, V1[0].vector);                         \
     73      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     74      opihi_flt *M2  =  V2[0].vector[0].elements.Flt;                   \
     75      opihi_flt *M3  =  V3[0].vector[0].elements.Flt;                   \
     76      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     77      for (i = 0; i < Nx; i++, out++, M1++, M2++, M3++) {               \
     78        *out = OP;                                                      \
     79      }                                                                 \
     80      break;                                                            \
     81    }                                                                   \
     82    if ((V1->vector->type == OPIHI_INT) && (V2->vector->type == OPIHI_INT) && (V3->vector->type == OPIHI_INT)) { \
     83      CopyVector (OUT[0].vector, V1[0].vector);                         \
     84      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     85      opihi_int *M2  =  V2[0].vector[0].elements.Int;                   \
     86      opihi_int *M3  =  V3[0].vector[0].elements.Int;                   \
     87      opihi_int *out = OUT[0].vector[0].elements.Int;                   \
     88      for (i = 0; i < Nx; i++, out++, M1++, M2++, M3++) {               \
     89        *out = OP;                                                      \
     90      }                                                                 \
     91      break;                                                            \
     92    }                                                                   \
     93  }
     94
     95  switch (op[0]) {
     96    case '?': VVV_FUNC(*M1 ? *M2: *M3);
     97    default:
     98      snprintf (line, 512, "error: op %c not defined!", op[0]);
     99      push_error (line);
     100      return (FALSE);
     101  }
     102# undef VVV_FUNC
     103
     104  /** free up any temporary buffers: **/
     105
     106  if (V1[0].type == ST_VECTOR_TMP) {
     107    free (V1[0].vector[0].elements.Ptr);
     108    free (V1[0].vector);
     109  }
     110  if (V2[0].type == ST_VECTOR_TMP) {
     111    free (V2[0].vector[0].elements.Ptr);
     112    free (V2[0].vector);
     113  }
     114  if (V3[0].type == ST_VECTOR_TMP) {
     115    free (V3[0].vector[0].elements.Ptr);
     116    free (V3[0].vector);
     117  }
     118  /* at the end, V1 and V2 are deleted only if they were temporary */
     119
     120  clear_stack (V1);
     121  clear_stack (V2);
     122  clear_stack (V3);
     123  return (TRUE);
     124
     125}
     126
     127int MMM_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) {
     128
     129  int i, Nx, Ny;
     130  float *out, *M1, *M2, *M3;
     131  char line[512]; // this is only used to report an error
     132 
     133  Nx = V1[0].buffer[0].matrix.Naxis[0];
     134  Ny = V1[0].buffer[0].matrix.Naxis[1];
     135
     136  if (V1[0].type == ST_MATRIX_TMP) {  /** use V1 as temp buffer **/
     137    OUT[0].buffer = V1[0].buffer;
     138    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
     139  } else {
     140    if (V2[0].type == ST_MATRIX_TMP) { /** use V2 as temp buffer, but header of V1 **/
     141      OUT[0].buffer = V2[0].buffer;
     142      V2[0].type = ST_MATRIX; /* prevent it from being freed below */
     143    } else {  /* no spare temp buffer */
     144      OUT[0].buffer = InitBuffer ();
     145      CopyBuffer (OUT[0].buffer, V1[0].buffer);
     146    }
     147  }
     148  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
     149
     150  M1  = (float *)V1[0].buffer[0].matrix.buffer;
     151  M2  = (float *)V2[0].buffer[0].matrix.buffer;
     152  M3  = (float *)V3[0].buffer[0].matrix.buffer;
     153  out = (float *)OUT[0].buffer[0].matrix.buffer;
     154
     155# define MMM_FUNC(OP)                                   \
     156  for (i = 0; i < Nx*Ny; i++, out++, M1++, M2++, M3++) {        \
     157    *out = OP;                                          \
     158  }                                                     \
     159  break;
     160
     161  switch (op[0]) {
     162    case '?': MMM_FUNC(*M1 ? *M2: *M3);
     163    default:
     164      snprintf (line, 512, "error: op %c not defined!", op[0]);
     165      push_error (line);
     166      return (FALSE);
     167  }
     168# undef MMM_FUNC
     169
     170  /** free up any temporary buffers: **/
     171
     172  if (V1[0].type == ST_MATRIX_TMP) {
     173    free (V1[0].buffer[0].header.buffer);
     174    free (V1[0].buffer[0].matrix.buffer);
     175    free (V1[0].buffer);
     176  }
     177  if (V2[0].type == ST_MATRIX_TMP) {
     178    free (V2[0].buffer[0].header.buffer);
     179    free (V2[0].buffer[0].matrix.buffer);
     180    free (V2[0].buffer);
     181  }
     182  if (V3[0].type == ST_MATRIX_TMP) {
     183    free (V3[0].buffer[0].header.buffer);
     184    free (V3[0].buffer[0].matrix.buffer);
     185    free (V3[0].buffer);
     186  }
     187
     188  /* at the end, V1 and V2 are deleted only if they were temporary */
     189
     190  clear_stack (V1);
     191  clear_stack (V2);
     192  clear_stack (V3);
     193  return (TRUE);
     194
     195}
     196
     197// XXX we temporarily drop the concept of using one of the temporary input vectors for
     198// the output vector (thus saving an ALLOC): we have to juggle the size of the input vectors
     199// as well as their temporary state
     200
     201int VV_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) {
     202
     203  int i, Nx;
     204  char line[512]; // this is only used to report an error
     205 
     206  // the vectors have to match in length
     207  if (V1[0].vector[0].Nelements != V2[0].vector[0].Nelements) {
     208    return (FALSE);
     209  }
     210
     211  Nx = V1[0].vector[0].Nelements;
     212
     213  // create the output vector guaranteed to be temporary until the very end
     214  OUT[0].vector = InitVector ();
     215  OUT[0].type = ST_VECTOR_TMP;
    27216
    28217  // set up the possible operations : int OP int -> int, all else yield float
     
    59248      break;                                                            \
    60249    }                                                                   \
    61     if ((FTYPE == 'S') && (V1->vector->type != OPIHI_FLT) && (V2->vector->type != OPIHI_FLT)) { \
     250    if ((FTYPE == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT) && (V2->vector->type != OPIHI_FLT)) { \
    62251      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);             \
    63252      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    82271
    83272  switch (op[0]) {
    84     case '+': VV_FUNC('s', *M1 + *M2);
    85     case '-': VV_FUNC('s', *M1 - *M2);
    86     case '*': VV_FUNC('s', *M1 * *M2);
    87     case '/': VV_FUNC('S', *M1 / (opihi_flt) *M2);
    88     case '%': VV_FUNC('s', (long long)*M1 % (long long)*M2);
    89     case '^': VV_FUNC('S', pow (*M1, *M2));
    90     case '@': VV_FUNC('S', DEG_RAD*atan2 (*M1, *M2));
    91     case 'D': VV_FUNC('s', MIN (*M1, *M2));
    92     case 'U': VV_FUNC('s', MAX (*M1, *M2));
    93     case '<': VV_FUNC('s', (*M1 < *M2) ? 1 : 0);
    94     case '>': VV_FUNC('s', (*M1 > *M2) ? 1 : 0);
    95     case '&': VV_FUNC('s', ((long long)*M1 & (long long)*M2));
    96     case '|': VV_FUNC('s', ((long long)*M1 | (long long)*M2));
    97     case 'E': VV_FUNC('s', (*M1 == *M2) ? 1 : 0);
    98     case 'N': VV_FUNC('s', (*M1 != *M2) ? 1 : 0);
    99     case 'L': VV_FUNC('s', (*M1 <= *M2) ? 1 : 0);
    100     case 'G': VV_FUNC('s', (*M1 >= *M2) ? 1 : 0);
    101     case 'A': VV_FUNC('s', (*M1 && *M2) ? 1 : 0);
    102     case 'O': VV_FUNC('s', (*M1 || *M2) ? 1 : 0);
     273    case '+': VV_FUNC(ST_SCALAR_INT, *M1 + *M2);
     274    case '-': VV_FUNC(ST_SCALAR_INT, *M1 - *M2);
     275    case '*': VV_FUNC(ST_SCALAR_INT, *M1 * *M2);
     276    case '/': VV_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) *M2);
     277    case '%': VV_FUNC(ST_SCALAR_INT, (long long)*M1 % (long long)*M2);
     278    case '^': VV_FUNC(ST_SCALAR_FLT, pow (*M1, *M2));
     279    case '@': VV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, *M2));
     280    case 'a': VV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, *M2));
     281    case 'D': VV_FUNC(ST_SCALAR_INT, MIN (*M1, *M2));
     282    case 'U': VV_FUNC(ST_SCALAR_INT, MAX (*M1, *M2));
     283    case '<': VV_FUNC(ST_SCALAR_INT, (*M1 < *M2) ? 1 : 0);
     284    case '>': VV_FUNC(ST_SCALAR_INT, (*M1 > *M2) ? 1 : 0);
     285    case '&': VV_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)*M2));
     286    case '|': VV_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)*M2));
     287    case 'E': VV_FUNC(ST_SCALAR_INT, (*M1 == *M2) ? 1 : 0);
     288    case 'N': VV_FUNC(ST_SCALAR_INT, (*M1 != *M2) ? 1 : 0);
     289    case 'L': VV_FUNC(ST_SCALAR_INT, (*M1 <= *M2) ? 1 : 0);
     290    case 'G': VV_FUNC(ST_SCALAR_INT, (*M1 >= *M2) ? 1 : 0);
     291    case 'A': VV_FUNC(ST_SCALAR_INT, (*M1 && *M2) ? 1 : 0);
     292    case 'O': VV_FUNC(ST_SCALAR_INT, (*M1 || *M2) ? 1 : 0);
    103293    default:
    104       sprintf (line, "error: op %c not defined!", op[0]);
     294      snprintf (line, 512, "error: op %c not defined!", op[0]);
    105295      push_error (line);
    106296      return (FALSE);
     
    110300  /** free up any temporary buffers: **/
    111301
    112   if (V1[0].type == 'v') {
     302  if (V1[0].type == ST_VECTOR_TMP) {
    113303    free (V1[0].vector[0].elements.Ptr);
    114304    free (V1[0].vector);
    115305  }
    116   if (V2[0].type == 'v') {
     306  if (V2[0].type == ST_VECTOR_TMP) {
    117307    free (V2[0].vector[0].elements.Ptr);
    118308    free (V2[0].vector);
     
    134324
    135325  OUT[0].vector = InitVector ();
    136   OUT[0].type = 'v';   /*** <<--- says this is a temporary matrix ***/
     326  OUT[0].type = ST_VECTOR_TMP;   /*** <<--- says this is a temporary matrix ***/
    137327
    138328  // set up the possible operations : int OP int -> int, all else yield float
    139329  // OP is the operation performed on *M1 and *M2
    140330# define SV_FUNC(FTYPE,OP) {                                            \
    141     if ((V1->type == 'S') && (V2->vector->type == OPIHI_FLT)) {         \
     331    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type == OPIHI_FLT)) {               \
    142332      CopyVector (OUT[0].vector, V2[0].vector);                         \
    143333      opihi_flt  M1  =  V1[0].FltValue;                                 \
     
    149339      break;                                                            \
    150340    }                                                                   \
    151     if ((V1->type == 'S') && (V2->vector->type != OPIHI_FLT)) {         \
     341    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type != OPIHI_FLT)) {               \
    152342      MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);             \
    153343      opihi_flt  M1  =  V1[0].FltValue;                                 \
     
    159349      break;                                                            \
    160350    }                                                                   \
    161     if ((V1->type == 's') && (V2->vector->type == OPIHI_FLT)) {         \
     351    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type == OPIHI_FLT)) {               \
    162352      CopyVector (OUT[0].vector, V2[0].vector);                         \
    163353      opihi_int  M1  =  V1[0].IntValue;                                 \
     
    169359      break;                                                            \
    170360    }                                                                   \
    171     if ((FTYPE == 'S') && (V1->type == 's') && (V2->vector->type != OPIHI_FLT)) { \
     361    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) { \
    172362      MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);             \
    173363      opihi_int  M1  =  V1[0].IntValue;                                 \
     
    179369      break;                                                            \
    180370    }                                                                   \
    181     if ((V1->type == 's') && (V2->vector->type != OPIHI_FLT)) {         \
     371    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) {               \
    182372      CopyVector (OUT[0].vector, V2[0].vector);                         \
    183373      opihi_int  M1  =  V1[0].IntValue;                                 \
     
    192382
    193383  switch (op[0]) {
    194     case '+': SV_FUNC('s', M1 + *M2);
    195     case '-': SV_FUNC('s', M1 - *M2);
    196     case '*': SV_FUNC('s', M1 * *M2);
    197     case '/': SV_FUNC('S', M1 / (opihi_flt) *M2);
    198     case '%': SV_FUNC('s', (long long) M1 % (long long) *M2);
    199     case '^': SV_FUNC('S', pow (M1, *M2));
    200     case '@': SV_FUNC('S', DEG_RAD*atan2 (M1, *M2));
    201     case 'D': SV_FUNC('s', MIN (M1, *M2));
    202     case 'U': SV_FUNC('s', MAX (M1, *M2));
    203     case '<': SV_FUNC('s', (M1 < *M2) ? 1 : 0);
    204     case '>': SV_FUNC('s', (M1 > *M2) ? 1 : 0);
    205     case '&': SV_FUNC('s', ((long long)M1 & (long long)*M2));
    206     case '|': SV_FUNC('s', ((long long)M1 | (long long)*M2));
    207     case 'E': SV_FUNC('s', (M1 == *M2) ? 1 : 0);
    208     case 'N': SV_FUNC('s', (M1 != *M2) ? 1 : 0);
    209     case 'L': SV_FUNC('s', (M1 <= *M2) ? 1 : 0);
    210     case 'G': SV_FUNC('s', (M1 >= *M2) ? 1 : 0);
    211     case 'A': SV_FUNC('s', (M1 && *M2) ? 1 : 0);
    212     case 'O': SV_FUNC('s', (M1 || *M2) ? 1 : 0);
     384    case '+': SV_FUNC(ST_SCALAR_INT, M1 + *M2);
     385    case '-': SV_FUNC(ST_SCALAR_INT, M1 - *M2);
     386    case '*': SV_FUNC(ST_SCALAR_INT, M1 * *M2);
     387    case '/': SV_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) *M2);
     388    case '%': SV_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) *M2);
     389    case '^': SV_FUNC(ST_SCALAR_FLT, pow (M1, *M2));
     390    case '@': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
     391    case 'a': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
     392    case 'D': SV_FUNC(ST_SCALAR_INT, MIN (M1, *M2));
     393    case 'U': SV_FUNC(ST_SCALAR_INT, MAX (M1, *M2));
     394    case '<': SV_FUNC(ST_SCALAR_INT, (M1 < *M2) ? 1 : 0);
     395    case '>': SV_FUNC(ST_SCALAR_INT, (M1 > *M2) ? 1 : 0);
     396    case '&': SV_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)*M2));
     397    case '|': SV_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)*M2));
     398    case 'E': SV_FUNC(ST_SCALAR_INT, (M1 == *M2) ? 1 : 0);
     399    case 'N': SV_FUNC(ST_SCALAR_INT, (M1 != *M2) ? 1 : 0);
     400    case 'L': SV_FUNC(ST_SCALAR_INT, (M1 <= *M2) ? 1 : 0);
     401    case 'G': SV_FUNC(ST_SCALAR_INT, (M1 >= *M2) ? 1 : 0);
     402    case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0);
     403    case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0);
    213404    default:
    214       sprintf (line, "error: op %c not defined!", op[0]);
     405      snprintf (line, 512, "error: op %c not defined!", op[0]);
    215406      push_error (line);
    216407      return (FALSE);
     
    219410
    220411  /** free up any temporary buffers: **/
    221   if (V2[0].type == 'v') {
     412  if (V2[0].type == ST_VECTOR_TMP) {
    222413    free (V2[0].vector[0].elements.Ptr);
    223414    free (V2[0].vector);
     
    240431
    241432  OUT[0].vector = InitVector ();
    242   OUT[0].type = 'v';   /*** <<--- says this is a temporary matrix ***/
     433  OUT[0].type = ST_VECTOR_TMP;   /*** <<--- says this is a temporary matrix ***/
    243434
    244435  // set up the possible operations : int OP int -> int, all else yield float
    245436  // OP is the operation performed on *M1 and *M2
    246437# define VS_FUNC(FTYPE,OP) {                                            \
    247     if ((V2->type == 'S') && (V1->vector->type == OPIHI_FLT)) {         \
     438    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type == OPIHI_FLT)) {               \
    248439      CopyVector (OUT[0].vector, V1[0].vector);                         \
    249440      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     
    255446      break;                                                            \
    256447    }                                                                   \
    257     if ((V2->type == 'S') && (V1->vector->type != OPIHI_FLT)) {         \
     448    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT)) {               \
    258449      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);             \
    259450      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    265456      break;                                                            \
    266457    }                                                                   \
    267     if ((V2->type == 's') && (V1->vector->type == OPIHI_FLT)) {         \
     458    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type == OPIHI_FLT)) {               \
    268459      CopyVector (OUT[0].vector, V1[0].vector);                         \
    269460      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     
    275466      break;                                                            \
    276467    }                                                                   \
    277     if ((FTYPE == 'S') && (V2->type == 's') && (V1->vector->type != OPIHI_FLT)) { \
     468    if ((FTYPE == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) { \
    278469      CopyVector (OUT[0].vector, V1[0].vector);                         \
    279470      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    285476      break;                                                            \
    286477    }                                                                   \
    287     if ((V2->type == 's') && (V1->vector->type != OPIHI_FLT)) {         \
     478    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) {               \
    288479      CopyVector (OUT[0].vector, V1[0].vector);                         \
    289480      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    298489
    299490  switch (op[0]) {
    300     case '+': VS_FUNC('s', *M1 + M2);
    301     case '-': VS_FUNC('s', *M1 - M2);
    302     case '*': VS_FUNC('s', *M1 * M2);
    303     case '/': VS_FUNC('S', *M1 / (opihi_flt) M2);
    304     case '%': VS_FUNC('s', (long long) *M1 % (long long) M2);
    305     case '^': VS_FUNC('S', pow (*M1, M2));
    306     case '@': VS_FUNC('S', DEG_RAD*atan2 (*M1, M2));
    307     case 'D': VS_FUNC('s', MIN (*M1, M2));
    308     case 'U': VS_FUNC('s', MAX (*M1, M2));
    309     case '<': VS_FUNC('s', (*M1 < M2) ? 1 : 0);
    310     case '>': VS_FUNC('s', (*M1 > M2) ? 1 : 0);
    311     case '&': VS_FUNC('s', ((long long)*M1 & (long long)M2));
    312     case '|': VS_FUNC('s', ((long long)*M1 | (long long)M2));
    313     case 'E': VS_FUNC('s', (*M1 == M2) ? 1 : 0);
    314     case 'N': VS_FUNC('s', (*M1 != M2) ? 1 : 0);
    315     case 'L': VS_FUNC('s', (*M1 <= M2) ? 1 : 0);
    316     case 'G': VS_FUNC('s', (*M1 >= M2) ? 1 : 0);
    317     case 'A': VS_FUNC('s', (*M1 && M2) ? 1 : 0);
    318     case 'O': VS_FUNC('s', (*M1 || M2) ? 1 : 0);
     491    case '+': VS_FUNC(ST_SCALAR_INT, *M1 + M2);
     492    case '-': VS_FUNC(ST_SCALAR_INT, *M1 - M2);
     493    case '*': VS_FUNC(ST_SCALAR_INT, *M1 * M2);
     494    case '/': VS_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) M2);
     495    case '%': VS_FUNC(ST_SCALAR_INT, (long long) *M1 % (long long) M2);
     496    case '^': VS_FUNC(ST_SCALAR_FLT, pow (*M1, M2));
     497    case '@': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
     498    case 'a': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
     499    case 'D': VS_FUNC(ST_SCALAR_INT, MIN (*M1, M2));
     500    case 'U': VS_FUNC(ST_SCALAR_INT, MAX (*M1, M2));
     501    case '<': VS_FUNC(ST_SCALAR_INT, (*M1 < M2) ? 1 : 0);
     502    case '>': VS_FUNC(ST_SCALAR_INT, (*M1 > M2) ? 1 : 0);
     503    case '&': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)M2));
     504    case '|': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)M2));
     505    case 'E': VS_FUNC(ST_SCALAR_INT, (*M1 == M2) ? 1 : 0);
     506    case 'N': VS_FUNC(ST_SCALAR_INT, (*M1 != M2) ? 1 : 0);
     507    case 'L': VS_FUNC(ST_SCALAR_INT, (*M1 <= M2) ? 1 : 0);
     508    case 'G': VS_FUNC(ST_SCALAR_INT, (*M1 >= M2) ? 1 : 0);
     509    case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0);
     510    case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0);
    319511    default:
    320       sprintf (line, "error: op %c not defined!", op[0]);
     512      snprintf (line, 512, "error: op %c not defined!", op[0]);
    321513      push_error (line);
    322514      return (FALSE);
     
    326518  /** free up any temporary buffers: **/
    327519
    328   if (V1[0].type == 'v') {
     520  if (V1[0].type == ST_VECTOR_TMP) {
    329521    free (V1[0].vector[0].elements.Ptr);
    330522    free (V1[0].vector);
     
    353545
    354546  /* if possible, use V1 as temp buffer, otherwise create new one */
    355   if (V1[0].type == 'm') { 
     547  if (V1[0].type == ST_MATRIX_TMP) { 
    356548    OUT[0].buffer = V1[0].buffer;
    357     V1[0].type = 'M'; /* prevent it from being freed below */
     549    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
    358550  } else { 
    359551    /* do buffer.matrix.buffer and buffer.header.buffer get correctly zeroed? */
     
    361553    CopyBuffer (OUT[0].buffer, V1[0].buffer);
    362554  }
    363   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
     555  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
    364556
    365557  float     *M1  = (float *) V1[0].buffer[0].matrix.buffer;
     
    395587    case '^': MV_FUNC(pow (*M1, *M2));
    396588    case '@': MV_FUNC(DEG_RAD*atan2 (*M1, *M2));
     589    case 'a': MV_FUNC(DEG_RAD*atan2 (*M1, *M2));
    397590    case 'D': MV_FUNC(MIN (*M1, *M2));
    398591    case 'U': MV_FUNC(MAX (*M1, *M2));
     
    408601    case 'O': MV_FUNC((*M1 || *M2) ? 1 : 0);
    409602    default:
    410       sprintf (line, "error: op %c not defined!", op[0]);
     603      snprintf (line, 512, "error: op %c not defined!", op[0]);
    411604      push_error (line);
    412605      return (FALSE);
     
    416609  /** free up any temporary buffers: **/
    417610
    418   if (V1[0].type == 'm') {
     611  if (V1[0].type == ST_MATRIX_TMP) {
    419612    free (V1[0].buffer[0].header.buffer);
    420613    free (V1[0].buffer[0].matrix.buffer);
    421614    free (V1[0].buffer);
    422615  }
    423   if (V2[0].type == 'v') {
     616  if (V2[0].type == ST_VECTOR_TMP) {
    424617    free (V2[0].vector[0].elements.Ptr);
    425618    free (V2[0].vector);
     
    446639
    447640  /* if possible, use V2 as temp buffer, otherwise create new one */
    448   if (V2[0].type == 'm') {
     641  if (V2[0].type == ST_MATRIX_TMP) {
    449642    OUT[0].buffer = V2[0].buffer;
    450     V2[0].type = 'M'; /* prevent it from being freed below */
     643    V2[0].type = ST_MATRIX; /* prevent it from being freed below */
    451644  } else {  /* no spare temp buffer */
    452645    OUT[0].buffer = InitBuffer ();
    453646    CopyBuffer (OUT[0].buffer, V2[0].buffer);
    454647  }
    455   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
     648  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
    456649
    457650  float     *M2  = (float *) V2[0].buffer[0].matrix.buffer;
     
    487680    case '^': VM_FUNC(pow (*M1, *M2));
    488681    case '@': VM_FUNC(DEG_RAD*atan2 (*M1, *M2));
     682    case 'a': VM_FUNC(DEG_RAD*atan2 (*M1, *M2));
    489683    case 'D': VM_FUNC(MIN (*M1, *M2));
    490684    case 'U': VM_FUNC(MAX (*M1, *M2));
     
    500694    case 'O': VM_FUNC((*M1 || *M2) ? 1 : 0);
    501695    default:
    502       sprintf (line, "error: op %c not defined!", op[0]);
     696      snprintf (line, 512, "error: op %c not defined!", op[0]);
    503697      push_error (line);
    504698      return (FALSE);
     
    508702  /** free up any temporary buffers: **/
    509703
    510   if (V1[0].type == 'v') {
     704  if (V1[0].type == ST_VECTOR_TMP) {
    511705    free (V1[0].vector[0].elements.Ptr);
    512706    free (V1[0].vector);
    513707  }
    514   if (V2[0].type == 'm') {
     708  if (V2[0].type == ST_MATRIX_TMP) {
    515709    free (V2[0].buffer[0].header.buffer);
    516710    free (V2[0].buffer[0].matrix.buffer);
     
    535729  Ny = V1[0].buffer[0].matrix.Naxis[1];
    536730
    537   if (V1[0].type == 'm') {  /** use V1 as temp buffer **/
     731  if (V1[0].type == ST_MATRIX_TMP) {  /** use V1 as temp buffer **/
    538732    OUT[0].buffer = V1[0].buffer;
    539     V1[0].type = 'M'; /* prevent it from being freed below */
     733    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
    540734  } else {
    541     if (V2[0].type == 'm') { /** use V2 as temp buffer, but header of V1 **/
     735    if (V2[0].type == ST_MATRIX_TMP) { /** use V2 as temp buffer, but header of V1 **/
    542736      OUT[0].buffer = V2[0].buffer;
    543       V2[0].type = 'M'; /* prevent it from being freed below */
     737      V2[0].type = ST_MATRIX; /* prevent it from being freed below */
    544738    } else {  /* no spare temp buffer */
    545739      OUT[0].buffer = InitBuffer ();
     
    547741    }
    548742  }
    549   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
     743  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
    550744
    551745  M1  = (float *)V1[0].buffer[0].matrix.buffer;
     
    567761    case '^': MM_FUNC(pow (*M1, *M2));
    568762    case '@': MM_FUNC(DEG_RAD*atan2 (*M1, *M2));
     763    case 'a': MM_FUNC(DEG_RAD*atan2 (*M1, *M2));
    569764    case 'D': MM_FUNC(MIN (*M1, *M2));
    570765    case 'U': MM_FUNC(MAX (*M1, *M2));
     
    580775    case 'O': MM_FUNC((*M1 || *M2) ? 1 : 0);
    581776    default:
    582       sprintf (line, "error: op %c not defined!", op[0]);
     777      snprintf (line, 512, "error: op %c not defined!", op[0]);
    583778      push_error (line);
    584779      return (FALSE);
     
    588783  /** free up any temporary buffers: **/
    589784
    590   if (V1[0].type == 'm') {
     785  if (V1[0].type == ST_MATRIX_TMP) {
    591786    free (V1[0].buffer[0].header.buffer);
    592787    free (V1[0].buffer[0].matrix.buffer);
    593788    free (V1[0].buffer);
    594789  }
    595   if (V2[0].type == 'm') {
     790  if (V2[0].type == ST_MATRIX_TMP) {
    596791    free (V2[0].buffer[0].header.buffer);
    597792    free (V2[0].buffer[0].matrix.buffer);
     
    615810
    616811  /* if possible, use V1 as temp buffer, otherwise create new one */
    617   if (V1[0].type == 'm') {
     812  if (V1[0].type == ST_MATRIX_TMP) {
    618813    OUT[0].buffer = V1[0].buffer;
    619     V1[0].type = 'M'; /* prevent it from being freed below */
     814    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
    620815  } else {
    621816    OUT[0].buffer = InitBuffer ();
    622817    CopyBuffer (OUT[0].buffer, V1[0].buffer);
    623818  }
    624   OUT[0].type = 'm';      /*** <<--- says this is a temporary matrix ***/
     819  OUT[0].type = ST_MATRIX_TMP;      /*** <<--- says this is a temporary matrix ***/
    625820
    626821  float *M1    = (float *)V1[0].buffer[0].matrix.buffer;
     
    628823
    629824# define MS_FUNC(OP) {                                  \
    630     if (V2->type == 'S')  {                             \
     825    if (V2->type == ST_SCALAR_FLT)  {                           \
    631826      opihi_flt M2 = V2[0].FltValue;                    \
    632827      for (i = 0; i < Nx*Ny; i++, out++, M1++) {        \
     
    635830      break;                                            \
    636831    }                                                   \
    637     if (V2->type == 's')  {                             \
     832    if (V2->type == ST_SCALAR_INT)  {                           \
    638833      opihi_int M2 = V2[0].IntValue;                    \
    639834      for (i = 0; i < Nx*Ny; i++, out++, M1++) {        \
     
    652847    case '^': MS_FUNC(pow (*M1, M2));
    653848    case '@': MS_FUNC(DEG_RAD*atan2 (*M1, M2));
     849    case 'a': MS_FUNC(DEG_RAD*atan2 (*M1, M2));
    654850    case 'D': MS_FUNC(MIN (*M1, M2));
    655851    case 'U': MS_FUNC(MAX (*M1, M2));
     
    665861    case 'O': MS_FUNC((*M1 || M2) ? 1 : 0);
    666862    default:
    667       sprintf (line, "error: op %c not defined!", op[0]);
     863      snprintf (line, 512, "error: op %c not defined!", op[0]);
    668864      push_error (line);
    669865      return (FALSE);
     
    671867# undef MS_FUNC
    672868
    673   if (V1[0].type == 'm') {
     869  if (V1[0].type == ST_MATRIX_TMP) {
    674870    free (V1[0].buffer[0].header.buffer);
    675871    free (V1[0].buffer[0].matrix.buffer);
     
    691887  Ny = V2[0].buffer[0].matrix.Naxis[1];
    692888
    693   if (V2[0].type == 'm') {  /* V2[0] is NOT temporary, we can't use it for storage */
     889  if (V2[0].type == ST_MATRIX_TMP) {  /* V2[0] is NOT temporary, we can't use it for storage */
    694890    OUT[0].buffer = V2[0].buffer;
    695     V2[0].type = 'M'; /* prevent it from being freed below */
     891    V2[0].type = ST_MATRIX; /* prevent it from being freed below */
    696892  } else {
    697893    OUT[0].buffer = InitBuffer ();
    698894    CopyBuffer (OUT[0].buffer, V2[0].buffer);
    699895  }
    700   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
     896  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
    701897
    702898  float *M2    = (float *)V2[0].buffer[0].matrix.buffer;
     
    704900
    705901# define SM_FUNC(OP) {                                  \
    706     if (V1->type == 'S')  {                             \
     902    if (V1->type == ST_SCALAR_FLT)  {                           \
    707903      opihi_flt M1 = V1[0].FltValue;                    \
    708904      for (i = 0; i < Nx*Ny; i++, out++, M2++) {        \
     
    711907      break;                                            \
    712908    }                                                   \
    713     if (V1->type == 's')  {                             \
     909    if (V1->type == ST_SCALAR_INT)  {                           \
    714910      opihi_int M1 = V1[0].IntValue;                    \
    715911      for (i = 0; i < Nx*Ny; i++, out++, M2++) {        \
     
    728924    case '^': SM_FUNC(pow (M1, *M2));
    729925    case '@': SM_FUNC(DEG_RAD*atan2 (M1, *M2));
     926    case 'a': SM_FUNC(DEG_RAD*atan2 (M1, *M2));
    730927    case 'D': SM_FUNC(MIN (M1, *M2));
    731928    case 'U': SM_FUNC(MAX (M1, *M2));
     
    741938    case 'O': SM_FUNC((M1 || *M2) ? 1 : 0);
    742939    default:
    743       sprintf (line, "error: op %c not defined!", op[0]);
     940      snprintf (line, 512, "error: op %c not defined!", op[0]);
    744941      push_error (line);
    745942      return (FALSE);
     
    747944# undef SM_FUNC
    748945
    749   if (V2[0].type == 'm') {
     946  if (V2[0].type == ST_MATRIX_TMP) {
    750947    free (V2[0].buffer[0].header.buffer);
    751948    free (V2[0].buffer[0].matrix.buffer);
     
    764961
    765962# define SS_FUNC(FTYPE,OP) {                                            \
    766     if ((V1->type == 'S') && (V2->type == 'S')) {                       \
     963    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT)) {                   \
    767964      opihi_flt M1 = V1[0].FltValue;                                    \
    768965      opihi_flt M2 = V2[0].FltValue;                                    \
    769       OUT[0].type = 'S';                                                \
     966      OUT[0].type = ST_SCALAR_FLT;                                              \
    770967      OUT[0].FltValue = OP;                                             \
    771968      break;                                                            \
    772969    }                                                                   \
    773     if ((V1->type == 'S') && (V2->type == 's')) {                       \
     970    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT)) {                   \
    774971      opihi_flt M1 = V1[0].FltValue;                                    \
    775972      opihi_int M2 = V2[0].IntValue;                                    \
    776       OUT[0].type = 'S';                                                \
     973      OUT[0].type = ST_SCALAR_FLT;                                              \
    777974      OUT[0].FltValue = OP;                                             \
    778975      break;                                                            \
    779976    }                                                                   \
    780     if ((V1->type == 's') && (V2->type == 'S')) {                       \
     977    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_FLT)) {                   \
    781978      opihi_int M1 = V1[0].IntValue;                                    \
    782979      opihi_flt M2 = V2[0].FltValue;                                    \
    783       OUT[0].type = 'S';                                                \
     980      OUT[0].type = ST_SCALAR_FLT;                                              \
    784981      OUT[0].FltValue = OP;                                             \
    785982      break;                                                            \
    786983    }                                                                   \
    787     if ((FTYPE == 'S') && (V1->type == 's') && (V2->type == 's')) {     \
     984    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {       \
    788985      opihi_int M1 = V1[0].IntValue;                                    \
    789986      opihi_int M2 = V2[0].IntValue;                                    \
    790       OUT[0].type = 'S';                                                \
     987      OUT[0].type = ST_SCALAR_FLT;                                              \
    791988      OUT[0].FltValue = OP;                                             \
    792989      break;                                                            \
    793990    }                                                                   \
    794     if ((V1->type == 's') && (V2->type == 's')) {                       \
     991    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {                   \
    795992      opihi_int M1 = V1[0].IntValue;                                    \
    796993      opihi_int M2 = V2[0].IntValue;                                    \
    797       OUT[0].type = 's';                                                \
     994      OUT[0].type = ST_SCALAR_INT;                                              \
    798995      OUT[0].IntValue = OP;                                             \
    799996      break;                                                            \
     
    802999
    8031000  switch (op[0]) {
    804     case '+': SS_FUNC('s', M1 + M2);
    805     case '-': SS_FUNC('s', M1 - M2);
    806     case '*': SS_FUNC('s', M1 * M2);
    807     case '/': SS_FUNC('S', M1 / (opihi_flt) M2);
    808     case '%': SS_FUNC('s', (long long) M1 % (long long) M2);
    809     case '^': SS_FUNC('S', pow (M1, M2));
    810     case '@': SS_FUNC('S', DEG_RAD*atan2 (M1, M2));
    811     case 'D': SS_FUNC('s', MIN (M1, M2));
    812     case 'U': SS_FUNC('s', MAX (M1, M2));
    813     case '<': SS_FUNC('s', (M1 < M2) ? 1 : 0);
    814     case '>': SS_FUNC('s', (M1 > M2) ? 1 : 0);
    815     case '&': SS_FUNC('s', ((long long)M1 & (long long)M2));
    816     case '|': SS_FUNC('s', ((long long)M1 | (long long)M2));
    817     case 'E': SS_FUNC('s', (M1 == M2) ? 1 : 0);
    818     case 'N': SS_FUNC('s', (M1 != M2) ? 1 : 0);
    819     case 'L': SS_FUNC('s', (M1 <= M2) ? 1 : 0);
    820     case 'G': SS_FUNC('s', (M1 >= M2) ? 1 : 0);
    821     case 'A': SS_FUNC('s', (M1 && M2) ? 1 : 0);
    822     case 'O': SS_FUNC('s', (M1 || M2) ? 1 : 0);
     1001    case '+': SS_FUNC(ST_SCALAR_INT, M1 + M2);
     1002    case '-': SS_FUNC(ST_SCALAR_INT, M1 - M2);
     1003    case '*': SS_FUNC(ST_SCALAR_INT, M1 * M2);
     1004    case '/': SS_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) M2);
     1005    case '%': SS_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) M2);
     1006    case '^': SS_FUNC(ST_SCALAR_FLT, pow (M1, M2));
     1007    case '@': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
     1008    case 'a': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
     1009    case 'D': SS_FUNC(ST_SCALAR_INT, MIN (M1, M2));
     1010    case 'U': SS_FUNC(ST_SCALAR_INT, MAX (M1, M2));
     1011    case '<': SS_FUNC(ST_SCALAR_INT, (M1 < M2) ? 1 : 0);
     1012    case '>': SS_FUNC(ST_SCALAR_INT, (M1 > M2) ? 1 : 0);
     1013    case '&': SS_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)M2));
     1014    case '|': SS_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)M2));
     1015    case 'E': SS_FUNC(ST_SCALAR_INT, (M1 == M2) ? 1 : 0);
     1016    case 'N': SS_FUNC(ST_SCALAR_INT, (M1 != M2) ? 1 : 0);
     1017    case 'L': SS_FUNC(ST_SCALAR_INT, (M1 <= M2) ? 1 : 0);
     1018    case 'G': SS_FUNC(ST_SCALAR_INT, (M1 >= M2) ? 1 : 0);
     1019    case 'A': SS_FUNC(ST_SCALAR_INT, (M1 && M2) ? 1 : 0);
     1020    case 'O': SS_FUNC(ST_SCALAR_INT, (M1 || M2) ? 1 : 0);
    8231021    default:
    824       sprintf (line, "error: op %c not defined!", op[0]);
     1022      snprintf (line, 512, "error: op %c not defined!", op[0]);
    8251023      push_error (line);
    8261024      return (FALSE);
     
    8441042
    8451043  if ((op[0] != 'N') && (op[0] != 'E')) {
    846     sprintf (line, "error: op %c not defined for string operations!", op[0]);
     1044    snprintf (line, 512, "error: op %c not defined for string operations!", op[0]);
    8471045    push_error (line);
    8481046    return (FALSE);
     
    8531051     thus: string == number -> false */
    8541052
    855   if (!strncasecmp (&V1[0].type, "S", 1)) {
     1053  if (V1[0].type == ST_SCALAR_INT) {
    8561054    value = (op[0] == 'N');
    8571055    goto escape;
    8581056  }
    859   if (!strncasecmp (&V2[0].type, "S", 1)) {
     1057  if (V1[0].type == ST_SCALAR_FLT) {
     1058    value = (op[0] == 'N');
     1059    goto escape;
     1060  }
     1061  if (V2[0].type == ST_SCALAR_INT) {
     1062    value = (op[0] == 'N');
     1063    goto escape;
     1064  }
     1065  if (V2[0].type == ST_SCALAR_FLT) {
    8601066    value = (op[0] == 'N');
    8611067    goto escape;
     
    8701076    break;
    8711077    default:
    872       sprintf (line, "error: op %c not defined for string operations!", op[0]);
     1078      snprintf (line, 512, "error: op %c not defined for string operations!", op[0]);
    8731079      push_error (line);
    8741080      return (FALSE);
     
    8771083escape:
    8781084  OUT[0].FltValue = value;
    879   OUT[0].type = 'S';
     1085  OUT[0].type = ST_SCALAR_FLT;
    8801086
    8811087  clear_stack (V1);
     
    8911097 
    8921098# define S_FUNC(OP,FTYPE) {                     \
    893     if (V1->type == 'S') {                      \
     1099    if (V1->type == ST_SCALAR_FLT) {                    \
    8941100      opihi_flt M1  = V1[0].FltValue;           \
    895       OUT[0].type = 'S';                        \
     1101      OUT[0].type = ST_SCALAR_FLT;                      \
    8961102      OUT[0].FltValue = OP;                     \
    8971103      clear_stack (V1);                         \
    8981104      return (TRUE);                            \
    8991105    }                                           \
    900     if ((FTYPE == 'S') && (V1->type == 's')) {  \
     1106    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT)) {      \
    9011107      opihi_int M1  = V1[0].IntValue;           \
    902       OUT[0].type = 'S';                        \
     1108      OUT[0].type = ST_SCALAR_FLT;                      \
    9031109      OUT[0].FltValue = OP;                     \
    9041110      clear_stack (V1);                         \
    9051111      return (TRUE);                            \
    9061112    }                                           \
    907     if ((FTYPE == 's') && (V1->type == 's')) {  \
     1113    if ((FTYPE == ST_SCALAR_INT) && (V1->type == ST_SCALAR_INT)) {      \
    9081114      opihi_int M1  = V1[0].IntValue;           \
    909       OUT[0].type = 's';                        \
     1115      OUT[0].type = ST_SCALAR_INT;                      \
    9101116      OUT[0].IntValue = OP;                     \
    9111117      clear_stack (V1);                         \
     
    9141120  }
    9151121
    916   if (!strcmp (op, "="))      S_FUNC(M1, 's');
    917   if (!strcmp (op, "abs"))    S_FUNC(fabs(M1), 's');
    918   if (!strcmp (op, "int"))    S_FUNC((long long)(M1), 's');
    919   if (!strcmp (op, "exp"))    S_FUNC(exp (M1), 'S');
    920   if (!strcmp (op, "ten"))    S_FUNC(pow (10.0,M1), 'S');
    921   if (!strcmp (op, "log"))    S_FUNC(log10 (M1), 'S');
    922   if (!strcmp (op, "ln"))     S_FUNC(log (M1), 'S');
    923   if (!strcmp (op, "sqrt"))   S_FUNC(sqrt (M1), 'S');
    924   if (!strcmp (op, "erf"))    S_FUNC(erf (M1), 'S');
    925   if (!strcmp (op, "sinh"))   S_FUNC(sinh (M1), 'S');
    926   if (!strcmp (op, "cosh"))   S_FUNC(cosh (M1), 'S');
    927   if (!strcmp (op, "asinh"))  S_FUNC(asinh (M1), 'S');
    928   if (!strcmp (op, "acosh"))  S_FUNC(acosh (M1), 'S');
    929   if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1), 'S');
    930   if (!strcmp (op, "sin"))    S_FUNC(sin (M1), 'S');
    931   if (!strcmp (op, "cos"))    S_FUNC(cos (M1), 'S');
    932   if (!strcmp (op, "tan"))    S_FUNC(tan (M1), 'S');
    933   if (!strcmp (op, "dsin"))   S_FUNC(sin (M1*RAD_DEG), 'S');
    934   if (!strcmp (op, "dcos"))   S_FUNC(cos (M1*RAD_DEG), 'S');
    935   if (!strcmp (op, "dtan"))   S_FUNC(tan (M1*RAD_DEG), 'S');
    936   if (!strcmp (op, "asin"))   S_FUNC(asin (M1), 'S');
    937   if (!strcmp (op, "acos"))   S_FUNC(acos (M1), 'S');
    938   if (!strcmp (op, "atan"))   S_FUNC(atan (M1), 'S');
    939   if (!strcmp (op, "dasin"))  S_FUNC(asin (M1)*DEG_RAD, 'S');
    940   if (!strcmp (op, "dacos"))  S_FUNC(acos (M1)*DEG_RAD, 'S');
    941   if (!strcmp (op, "datan"))  S_FUNC(atan (M1)*DEG_RAD, 'S');
    942   if (!strcmp (op, "rnd"))    S_FUNC(M1*0.0 + drand48(), 'S');
    943   if (!strcmp (op, "not"))    S_FUNC(!(M1), 's');
    944   if (!strcmp (op, "--"))     S_FUNC(-1*M1, 's'); // NOTE: opihi_int is signed,
    945   if (!strcmp (op, "isinf"))  S_FUNC(!finite(M1), 'S'); // XXX modify in future
    946   if (!strcmp (op, "isnan"))  S_FUNC(isnan(M1), 'S'); // XXX modify in future   
     1122  if (!strcmp (op, "="))      S_FUNC(M1, ST_SCALAR_INT);
     1123  if (!strcmp (op, "abs"))    S_FUNC(fabs(M1), ST_SCALAR_INT);
     1124  if (!strcmp (op, "int"))    S_FUNC((long long)(M1), ST_SCALAR_INT);
     1125  if (!strcmp (op, "floor"))  S_FUNC(floor (M1), ST_SCALAR_FLT);
     1126  if (!strcmp (op, "ceil"))   S_FUNC(ceil (M1), ST_SCALAR_FLT);
     1127  // if (!strcmp (op, "rint"))   S_FUNC(nearbyint (M1), ST_SCALAR_FLT);
     1128  if (!strcmp (op, "exp"))    S_FUNC(exp (M1), ST_SCALAR_FLT);
     1129  if (!strcmp (op, "ten"))    S_FUNC(pow (10.0,M1), ST_SCALAR_FLT);
     1130  if (!strcmp (op, "log"))    S_FUNC(log10 (M1), ST_SCALAR_FLT);
     1131  if (!strcmp (op, "ln"))     S_FUNC(log (M1), ST_SCALAR_FLT);
     1132  if (!strcmp (op, "sqrt"))   S_FUNC(sqrt (M1), ST_SCALAR_FLT);
     1133  if (!strcmp (op, "erf"))    S_FUNC(erf (M1), ST_SCALAR_FLT);
     1134  if (!strcmp (op, "sinh"))   S_FUNC(sinh (M1), ST_SCALAR_FLT);
     1135  if (!strcmp (op, "cosh"))   S_FUNC(cosh (M1), ST_SCALAR_FLT);
     1136  if (!strcmp (op, "asinh"))  S_FUNC(asinh (M1), ST_SCALAR_FLT);
     1137  if (!strcmp (op, "acosh"))  S_FUNC(acosh (M1), ST_SCALAR_FLT);
     1138  if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1), ST_SCALAR_FLT);
     1139  if (!strcmp (op, "sin"))    S_FUNC(sin (M1), ST_SCALAR_FLT);
     1140  if (!strcmp (op, "cos"))    S_FUNC(cos (M1), ST_SCALAR_FLT);
     1141  if (!strcmp (op, "tan"))    S_FUNC(tan (M1), ST_SCALAR_FLT);
     1142  if (!strcmp (op, "dsin"))   S_FUNC(sin (M1*RAD_DEG), ST_SCALAR_FLT);
     1143  if (!strcmp (op, "dcos"))   S_FUNC(cos (M1*RAD_DEG), ST_SCALAR_FLT);
     1144  if (!strcmp (op, "dtan"))   S_FUNC(tan (M1*RAD_DEG), ST_SCALAR_FLT);
     1145  if (!strcmp (op, "asin"))   S_FUNC(asin (M1), ST_SCALAR_FLT);
     1146  if (!strcmp (op, "acos"))   S_FUNC(acos (M1), ST_SCALAR_FLT);
     1147  if (!strcmp (op, "atan"))   S_FUNC(atan (M1), ST_SCALAR_FLT);
     1148  if (!strcmp (op, "dasin"))  S_FUNC(asin (M1)*DEG_RAD, ST_SCALAR_FLT);
     1149  if (!strcmp (op, "dacos"))  S_FUNC(acos (M1)*DEG_RAD, ST_SCALAR_FLT);
     1150  if (!strcmp (op, "datan"))  S_FUNC(atan (M1)*DEG_RAD, ST_SCALAR_FLT);
     1151  if (!strcmp (op, "rnd"))    S_FUNC(M1*0.0 + drand48(), ST_SCALAR_FLT);
     1152  if (!strcmp (op, "not"))    S_FUNC(!(M1), ST_SCALAR_INT);
     1153  if (!strcmp (op, "--"))     S_FUNC(-1*M1, ST_SCALAR_INT); // NOTE: opihi_int is signed,
     1154  if (!strcmp (op, "isinf"))  S_FUNC(!finite(M1), ST_SCALAR_FLT); // XXX modify in future
     1155  if (!strcmp (op, "isnan"))  S_FUNC(isnan(M1), ST_SCALAR_FLT); // XXX modify in future   
    9471156
    9481157# undef S_FUNC
    9491158
    9501159  clear_stack (V1);
    951   sprintf (line, "error: op %s not defined!", op);
     1160  snprintf (line, 512, "error: op %s not defined!", op);
    9521161  push_error (line);
    9531162  return (FALSE);
     
    9621171
    9631172  OUT[0].vector = InitVector ();
    964   OUT[0].type = 'v'; /*** <<--- says this is a temporary matrix ***/
     1173  OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/
    9651174
    9661175# define V_FUNC(OP,FTYPE) {                                     \
     
    9741183      goto escape;                                              \
    9751184    }                                                           \
    976     if ((V1->vector->type == OPIHI_INT) && (FTYPE == 'S')) {    \
     1185    if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_FLT)) {  \
    9771186      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);     \
    9781187      opihi_int *M1  = V1[0].vector[0].elements.Int;            \
     
    9831192      goto escape;                                              \
    9841193    }                                                           \
    985     if ((V1->vector->type == OPIHI_INT) && (FTYPE == 's')) {    \
     1194    if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_INT)) {  \
    9861195      CopyVector (OUT[0].vector, V1[0].vector);                 \
    9871196      opihi_int *M1  = V1[0].vector[0].elements.Int;            \
     
    9931202    } }                                                 
    9941203
    995   if (!strcmp (op, "="))      V_FUNC(*M1, 's');
    996   if (!strcmp (op, "abs"))    V_FUNC(fabs(*M1), 's');
    997   if (!strcmp (op, "int"))    V_FUNC((long long)(*M1), 's');
    998   if (!strcmp (op, "exp"))    V_FUNC(exp(*M1), 'S');
    999   if (!strcmp (op, "ten"))    V_FUNC(pow(10.0,*M1), 'S');
    1000   if (!strcmp (op, "log"))    V_FUNC(log10(*M1), 'S');
    1001   if (!strcmp (op, "ln"))     V_FUNC(log(*M1), 'S');
    1002   if (!strcmp (op, "sqrt"))   V_FUNC(sqrt(*M1), 'S');
    1003   if (!strcmp (op, "erf"))    V_FUNC(erf(*M1), 'S');
    1004   if (!strcmp (op, "sinh"))   V_FUNC(sinh(*M1), 'S');
    1005   if (!strcmp (op, "cosh"))   V_FUNC(cosh(*M1), 'S');
    1006   if (!strcmp (op, "asinh"))  V_FUNC(asinh(*M1), 'S');
    1007   if (!strcmp (op, "acosh"))  V_FUNC(acosh(*M1), 'S');
    1008   if (!strcmp (op, "lgamma")) V_FUNC(lgamma(*M1), 'S');
    1009   if (!strcmp (op, "sin"))    V_FUNC(sin(*M1), 'S');
    1010   if (!strcmp (op, "cos"))    V_FUNC(cos(*M1), 'S');
    1011   if (!strcmp (op, "tan"))    V_FUNC(tan(*M1), 'S');
    1012   if (!strcmp (op, "dsin"))   V_FUNC(sin(*M1*RAD_DEG), 'S');
    1013   if (!strcmp (op, "dcos"))   V_FUNC(cos(*M1*RAD_DEG), 'S');
    1014   if (!strcmp (op, "dtan"))   V_FUNC(tan(*M1*RAD_DEG), 'S');
    1015   if (!strcmp (op, "asin"))   V_FUNC(asin(*M1), 'S');
    1016   if (!strcmp (op, "acos"))   V_FUNC(acos(*M1), 'S');
    1017   if (!strcmp (op, "atan"))   V_FUNC(atan(*M1), 'S');
    1018   if (!strcmp (op, "dasin"))  V_FUNC(asin(*M1)*DEG_RAD, 'S');
    1019   if (!strcmp (op, "dacos"))  V_FUNC(acos(*M1)*DEG_RAD, 'S');
    1020   if (!strcmp (op, "datan"))  V_FUNC(atan(*M1)*DEG_RAD, 'S');
    1021   if (!strcmp (op, "rnd"))    V_FUNC(drand48(), 'S');
    1022   if (!strcmp (op, "ramp"))   V_FUNC(i, 's');
    1023   if (!strcmp (op, "zero"))   V_FUNC(0, 's');
    1024   if (!strcmp (op, "not"))    V_FUNC(!(*M1), 's');
    1025   if (!strcmp (op, "--"))     V_FUNC(-1*(*M1), 's'); // NOTE: opihi_int is signed
    1026   if (!strcmp (op, "isinf"))  V_FUNC(!finite(*M1), 'S');
    1027   if (!strcmp (op, "isnan"))  V_FUNC(isnan(*M1), 'S');
    1028   if (!strcmp (op, "xramp"))  V_FUNC(i, 's');
    1029   if (!strcmp (op, "yramp"))  V_FUNC(0, 's');
     1204  if (!strcmp (op, "="))      V_FUNC(*M1, ST_SCALAR_INT);
     1205  if (!strcmp (op, "abs"))    V_FUNC(fabs(*M1), ST_SCALAR_INT);
     1206  if (!strcmp (op, "int"))    V_FUNC((long long)(*M1), ST_SCALAR_INT);
     1207  if (!strcmp (op, "floor"))  V_FUNC(floor (*M1), ST_SCALAR_FLT);
     1208  if (!strcmp (op, "ceil"))   V_FUNC(ceil (*M1), ST_SCALAR_FLT);
     1209  // if (!strcmp (op, "rint"))   V_FUNC(nearbyint (*M1), ST_SCALAR_FLT);
     1210  if (!strcmp (op, "exp"))    V_FUNC(exp(*M1), ST_SCALAR_FLT);
     1211  if (!strcmp (op, "ten"))    V_FUNC(pow(10.0,*M1), ST_SCALAR_FLT);
     1212  if (!strcmp (op, "log"))    V_FUNC(log10(*M1), ST_SCALAR_FLT);
     1213  if (!strcmp (op, "ln"))     V_FUNC(log(*M1), ST_SCALAR_FLT);
     1214  if (!strcmp (op, "sqrt"))   V_FUNC(sqrt(*M1), ST_SCALAR_FLT);
     1215  if (!strcmp (op, "erf"))    V_FUNC(erf(*M1), ST_SCALAR_FLT);
     1216  if (!strcmp (op, "sinh"))   V_FUNC(sinh(*M1), ST_SCALAR_FLT);
     1217  if (!strcmp (op, "cosh"))   V_FUNC(cosh(*M1), ST_SCALAR_FLT);
     1218  if (!strcmp (op, "asinh"))  V_FUNC(asinh(*M1), ST_SCALAR_FLT);
     1219  if (!strcmp (op, "acosh"))  V_FUNC(acosh(*M1), ST_SCALAR_FLT);
     1220  if (!strcmp (op, "lgamma")) V_FUNC(lgamma(*M1), ST_SCALAR_FLT);
     1221  if (!strcmp (op, "sin"))    V_FUNC(sin(*M1), ST_SCALAR_FLT);
     1222  if (!strcmp (op, "cos"))    V_FUNC(cos(*M1), ST_SCALAR_FLT);
     1223  if (!strcmp (op, "tan"))    V_FUNC(tan(*M1), ST_SCALAR_FLT);
     1224  if (!strcmp (op, "dsin"))   V_FUNC(sin(*M1*RAD_DEG), ST_SCALAR_FLT);
     1225  if (!strcmp (op, "dcos"))   V_FUNC(cos(*M1*RAD_DEG), ST_SCALAR_FLT);
     1226  if (!strcmp (op, "dtan"))   V_FUNC(tan(*M1*RAD_DEG), ST_SCALAR_FLT);
     1227  if (!strcmp (op, "asin"))   V_FUNC(asin(*M1), ST_SCALAR_FLT);
     1228  if (!strcmp (op, "acos"))   V_FUNC(acos(*M1), ST_SCALAR_FLT);
     1229  if (!strcmp (op, "atan"))   V_FUNC(atan(*M1), ST_SCALAR_FLT);
     1230  if (!strcmp (op, "dasin"))  V_FUNC(asin(*M1)*DEG_RAD, ST_SCALAR_FLT);
     1231  if (!strcmp (op, "dacos"))  V_FUNC(acos(*M1)*DEG_RAD, ST_SCALAR_FLT);
     1232  if (!strcmp (op, "datan"))  V_FUNC(atan(*M1)*DEG_RAD, ST_SCALAR_FLT);
     1233  if (!strcmp (op, "rnd"))    V_FUNC(drand48(), ST_SCALAR_FLT);
     1234  if (!strcmp (op, "ramp"))   V_FUNC(i, ST_SCALAR_INT);
     1235  if (!strcmp (op, "zero"))   V_FUNC(0, ST_SCALAR_INT);
     1236  if (!strcmp (op, "not"))    V_FUNC(!(*M1), ST_SCALAR_INT);
     1237  if (!strcmp (op, "--"))     V_FUNC(-1*(*M1), ST_SCALAR_INT); // NOTE: opihi_int is signed
     1238  if (!strcmp (op, "isinf"))  V_FUNC(!finite(*M1), ST_SCALAR_FLT);
     1239  if (!strcmp (op, "isnan"))  V_FUNC(isnan(*M1), ST_SCALAR_FLT);
     1240  if (!strcmp (op, "xramp"))  V_FUNC(i, ST_SCALAR_INT);
     1241  if (!strcmp (op, "yramp"))  V_FUNC(0, ST_SCALAR_INT);
    10301242  /* xramp and yramp above only make sense for matrices. for vectors, xramp = ramp, yramp = zero */
    10311243
     
    10341246escape:
    10351247
    1036   if (V1[0].type == 'v') {
     1248  if (V1[0].type == ST_VECTOR_TMP) {
    10371249    free (V1[0].vector[0].elements.Ptr);
    10381250    free (V1[0].vector);
     
    10531265  Ny = V1[0].buffer[0].matrix.Naxis[1];
    10541266
    1055   if (V1[0].type == 'm') {
     1267  if (V1[0].type == ST_MATRIX_TMP) {
    10561268    OUT[0].buffer = V1[0].buffer;
    1057     V1[0].type = 'M'; /* prevent it from being freed below */
     1269    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
    10581270  } else {
    10591271    OUT[0].buffer = InitBuffer ();
    10601272    CopyBuffer (OUT[0].buffer, V1[0].buffer);
    10611273  }
    1062   OUT[0].type = 'm';      /*** <<--- says this is a temporary matrix ***/
     1274  OUT[0].type = ST_MATRIX_TMP;      /*** <<--- says this is a temporary matrix ***/
    10631275  M1  = (float *) V1[0].buffer[0].matrix.buffer;
    10641276  out = (float *)OUT[0].buffer[0].matrix.buffer;
     
    10671279  if (!strcmp (op, "abs"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = fabs(*M1);         }}
    10681280  if (!strcmp (op, "int"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = (opihi_flt)(long long)(*M1); }}
     1281
     1282  if (!strcmp (op, "floor")) { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = floor (*M1); }}
     1283  if (!strcmp (op, "ceil"))  { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = ceil (*M1); }}
     1284  // if (!strcmp (op, "rint"))  { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = nearbyint (*M1); }}
     1285
    10691286  if (!strcmp (op, "exp"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = exp(*M1);          }}
    10701287  if (!strcmp (op, "ten"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = pow(10.0,*M1);     }}
     
    11161333  }
    11171334 
    1118   if (V1[0].type == 'm') {
     1335  if (V1[0].type == ST_MATRIX_TMP) {
    11191336    free (V1[0].buffer[0].header.buffer);
    11201337    free (V1[0].buffer[0].matrix.buffer);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/lib.shell/string.c

    r33662 r37067  
    322322}
    323323
     324int set_list_varname (char *line, char *base, int N, int excelStyle) {
     325
     326  int i;
     327   
     328  // A-Z correspond to 0 - 25
     329
     330  if (excelStyle) {
     331    float f = log(26.0);
     332    float g = (N == 0) ? 0.0 : log(1.0*N);
     333    int Ndigit = (int) (g / f) + 1;
     334    if (Ndigit > 10) {
     335      sprintf (line, "%s:ZZZZZZZZZZ", base);
     336      return FALSE;
     337    }
     338    char name[12];
     339    memset (name, 0, 12);
     340    for (i = 0; i < Ndigit; i++) {
     341      float Npow = Ndigit - i - 1;
     342      float g = pow(26.0, Npow);
     343      int V = (int) (N / g);
     344      name[i] = (Npow == 0.0) ? 'A' + V : 'A' + V - 1;
     345      N -= V * g;
     346    }
     347    sprintf (line, "%s:%s", base, name);
     348  } else {
     349    sprintf (line, "%s:%d", base, N);
     350  }
     351  return TRUE;
     352}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pantasks/CheckController.c

    r23530 r37067  
    2929  if (p != NULL) goto escape;
    3030
     31  /** skip past any leading garbage? ***/
     32
     33  /** find "Njobs: **/
     34  p = memstr (buffer.buffer, "BEGIN BLOCK Njobs:", MIN(buffer.Nbuffer, 256));
     35  p += strlen("BEGIN BLOCK Njobs:");
     36
    3137  /** parse job list **/
    32   status = sscanf (buffer.buffer, "%*s %d", &Njobs);
     38  status = sscanf (p, "%d", &Njobs);
    3339  if (status != 1) goto escape;
    3440  if (VerboseMode()) gprint (GP_ERR, "parse %d jobs on stack %f\n", Njobs, TimerElapsed(&start, TRUE));
    3541
    36   p = buffer.buffer;
     42  /* output looks like:
     43     BEGIN BLOCK Njobs: NN\n
     44     ID name machine\n
     45     ID name machine\n
     46  */
     47
     48  // p is currently pointing at "BEGIN BLOCK Njobs"
     49
    3750  for (i = 0; i < Njobs; i++) {
    3851    q = strchr (p, '\n');
     
    6780  if (p != NULL) goto escape;
    6881
     82  /** skip past any leading garbage? ***/
     83
     84  /** find "Njobs: **/
     85  p = memstr (buffer.buffer, "BEGIN BLOCK Njobs:", MIN(buffer.Nbuffer, 256));
     86  p += strlen("BEGIN BLOCK Njobs:");
     87
    6988  /** parse job list **/
    70   status = sscanf (buffer.buffer, "%*s %d", &Njobs);
     89  status = sscanf (p, "%d", &Njobs);
    7190  if (status != 1) goto escape;
    7291  if (VerboseMode()) gprint (GP_ERR, "check crash stack %f\n", TimerElapsed(&start, TRUE));
    7392
    74   p = buffer.buffer;
     93  /* output looks like:
     94     BEGIN BLOCK Njobs: NN\n
     95     ID name machine\n
     96     ID name machine\n
     97  */
     98
     99  // p is currently pointing at "BEGIN BLOCK Njobs"
     100
    75101  for (i = 0; i < Njobs; i++) {
    76102    q = strchr (p, '\n');
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pantasks/ControllerOps.c

    r34088 r37067  
    259259  }
    260260 
    261   if (job[0].priority) {
     261  if (job[0].nicelevel) {
    262262    char tmp[64];
    263     snprintf (tmp, 64, " -nice %d", job[0].priority);
     263    snprintf (tmp, 64, " -nice %d", job[0].nicelevel);
    264264    strcat (cmd, tmp);
    265265  }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pantasks/JobOps.c

    r32632 r37067  
    107107    job[0].mode = JOB_CONTROLLER;
    108108  }
    109   job[0].priority = task[0].priority;
     109  job[0].nicelevel = task[0].nicelevel;
    110110
    111111  /* we need our own copy of task[0].argv argc is the number of valid args, like the usual command line.  we
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pantasks/LocalJob.c

    r32632 r37067  
    162162
    163163  /* set nice level for the child process -- maybe I should not exit here... */
    164   if (job[0].priority) {
    165       status = setpriority (PRIO_PROCESS, pid, job[0].priority);
     164  if (job[0].nicelevel) {
     165      status = setpriority (PRIO_PROCESS, pid, job[0].nicelevel);
    166166      if (status == -1) {
    167           gprint (GP_ERR, "error setting priority\n");
     167          gprint (GP_ERR, "error setting nice level\n");
    168168          perror ("setpriority: ");
    169169          exit (2);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pantasks/TaskOps.c

    r32632 r37067  
    487487
    488488  NewTask[0].active = TRUE;
    489   NewTask[0].priority = 0;
     489  NewTask[0].nicelevel = 0;
    490490  return (NewTask);
    491491}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pantasks/init.c

    r32632 r37067  
    3434  {1, "halt",       halt,          "halt the scheduler (no job harvesting)"},
    3535  {1, "host",       task_host,     "define host machine for a task"},
    36   {1, "nice",       task_nice,     "set nice priority level for a task"},
     36  {1, "nice",       task_nice,     "set nice level for a task"},
    3737  {1, "ipptool2book", ipptool2book, "convert queue with ipptool output to book"},
    3838  {1, "kill",       kill_job,      "kill job"},
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pantasks/init_server.c

    r32632 r37067  
    3535  {1, "delete",     delete_job,    "delete job"},
    3636  {1, "host",       task_host,     "define host machine for a task"},
    37   {1, "nice",       task_nice,     "set nice priority level for a task"},
     37  {1, "nice",       task_nice,     "set nice level for a task"},
    3838  {1, "ipptool2book", ipptool2book, "convert queue with ipptool output to book"},
    3939  {1, "kill",       kill_job,      "kill job"},
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pantasks/task_nice.c

    r32632 r37067  
    44
    55  char *endptr = NULL;
    6   int priority;
     6  int nicelevel;
    77  Task *task;
    88
    99  if (argc != 2) {
    10     gprint (GP_ERR, "USAGE: nice (priority)\n");
     10    gprint (GP_ERR, "USAGE: nice (nicelevel)\n");
    1111    return (FALSE);
    1212  }
     
    2020  }
    2121
    22   priority = strtol (argv[1], &endptr, 10);
     22  nicelevel = strtol (argv[1], &endptr, 10);
    2323  if (*endptr) goto fail;
    24   if (priority < 0) goto fail;
    25   if (priority > 20) goto fail;
     24  if (nicelevel < 0) goto fail;
     25  if (nicelevel > 20) goto fail;
    2626
    27   task[0].priority = priority;
     27  task[0].nicelevel = nicelevel;
    2828  JobTaskUnlock();
    2929  return (TRUE);
    3030
    3131fail:
    32     gprint (GP_ERR, "ERROR: nice (priority) -- priority must be an integer 0 to 20\n");
     32    gprint (GP_ERR, "ERROR: nice (nicelevel) -- nicelevel must be an integer 0 to 20\n");
    3333    return (FALSE);
    3434}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pclient/job.c

    r32632 r37067  
    33int job (int argc, char **argv) {
    44
    5   int i, N, pid, status, priority;
     5  int i, N, pid, status, nicelevel;
    66  char **targv;
    77
    8   priority = 0;
     8  nicelevel = 0;
    99  if ((N = get_argument (argc, argv, "-nice"))) {
    1010    remove_argument (N, &argc, argv);
    11     priority = atoi (argv[N]);
     11    nicelevel = atoi (argv[N]);
    1212    remove_argument (N, &argc, argv);
    1313  }
     
    6262
    6363  /* set nice level for the child process */
    64   if (priority) {
    65       status = setpriority (PRIO_PROCESS, pid, priority);
     64  if (nicelevel) {
     65      status = setpriority (PRIO_PROCESS, pid, nicelevel);
    6666      if (status == -1) {
    67           gprint (GP_ERR, "error setting priority\n");
     67          gprint (GP_ERR, "error setting nicelevel\n");
    6868          perror ("setpriority: ");
    6969          exit (2);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pcontrol/CheckBusyJob.c

    r28242 r37067  
    9999
    100100  // XXX runaway job if output too large?
    101   if (job[0].stdout_buf.size > 0x1000000) abort();
    102   if (job[0].stderr_buf.size > 0x1000000) abort();
     101  if (job[0].stdout_buf.size > 0x10000000) abort();
     102  if (job[0].stderr_buf.size > 0x10000000) abort();
    103103
    104104  // job has exited : move to DONE stack
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pcontrol/JobOps.c

    r32632 r37067  
    6161}
    6262
     63int GetJobStackIDbyName (char *name) {
     64  if (!strcasecmp (name, "ALLJOBS"))  return PCONTROL_JOB_ALLJOBS;
     65  if (!strcasecmp (name, "PENDING"))  return PCONTROL_JOB_PENDING;
     66  if (!strcasecmp (name, "BUSY"))     return PCONTROL_JOB_BUSY   ;
     67  if (!strcasecmp (name, "RESP"))     return PCONTROL_JOB_RESP   ;
     68  if (!strcasecmp (name, "DONE"))     return PCONTROL_JOB_DONE   ;
     69  if (!strcasecmp (name, "KILL"))     return PCONTROL_JOB_KILL   ;
     70  if (!strcasecmp (name, "EXIT"))     return PCONTROL_JOB_EXIT   ;
     71  if (!strcasecmp (name, "CRASH"))    return PCONTROL_JOB_CRASH  ;
     72  return (PCONTROL_JOB_NONE);
     73}
     74
    6375Stack *GetJobStack (int StackID) {
    6476  switch (StackID) {
     
    195207}
    196208
    197 IDtype AddJob (char *hostname, JobMode mode, int timeout, int priority, int argc, char **argv, int Nxhosts, char **xhosts) {
     209IDtype AddJob (char *hostname, JobMode mode, int timeout, int nicelevel, int argc, char **argv, int Nxhosts, char **xhosts) {
    198210
    199211  int JobID;
     
    220232
    221233  job[0].mode     = mode;
    222   job[0].priority = priority;
     234  job[0].nicelevel = nicelevel;
    223235
    224236  job[0].state = 0;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pcontrol/StartJob.c

    r32632 r37067  
    2525  bzero (line, Nline);
    2626  strcpy (line, "job");
    27   if (job[0].priority) {
     27  if (job[0].nicelevel) {
    2828    char tmp[64];
    29     snprintf (tmp, 64, " -nice %d", job[0].priority);
     29    snprintf (tmp, 64, " -nice %d", job[0].nicelevel);
    3030    strcat (line, tmp);
    3131  }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pcontrol/job.c

    r32632 r37067  
    55  char *Host = NULL;
    66  char **targv = NULL;
    7   int i, N, Mode, targc, Timeout, priority;
     7  int i, N, Mode, targc, Timeout, nicelevel;
    88  IDtype JobID;
    99  char **xhosts = NULL;
     
    4343  }
    4444
    45   priority = 0;
     45  nicelevel = 0;
    4646  if ((N = get_argument (argc, argv, "-nice"))) {
    4747    remove_argument (N, &argc, argv);
    48     priority = atoi (argv[N]);
     48    nicelevel = atoi (argv[N]);
    4949    remove_argument (N, &argc, argv);
    5050  }
     
    7676
    7777  // a JobID < 0 mean the job was not accepted
    78   JobID = AddJob (Host, Mode, Timeout, priority, targc, targv, Nxhosts, xhosts);
     78  JobID = AddJob (Host, Mode, Timeout, nicelevel, targc, targv, Nxhosts, xhosts);
    7979  gprint (GP_LOG, "JobID: %d\n", (int) JobID);
    8080  return (TRUE);
     
    8282 usage:
    8383    gprint (GP_ERR, "USAGE: job [options] (arg0) (arg1) ... (argN)\n");
    84     gprint (GP_ERR, "  options: -host, +host, -timeout, -xhost (host)\n");
     84    gprint (GP_ERR, "  options: -host, +host, -timeout, -xhost (host) -nice (level)\n");
    8585    gprint (GP_ERR, "  arguments of the form @MAX_THREADS@ will be replaced when the job is launched\n");
    8686
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pcontrol/jobstack.c

    r12470 r37067  
    2222  /* print list */
    2323  LockStack (stack);
    24   gprint (GP_LOG, "Njobs: %d\n", stack[0].Nobject);
     24  gprint (GP_LOG, "BEGIN BLOCK Njobs: %d\n", stack[0].Nobject);
    2525  for (i = 0; i < stack[0].Nobject; i++) {
    2626    job = stack[0].object[i];
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/opihi/pcontrol/status.c

    r32632 r37067  
    11# include "pcontrol.h"
    22
    3 int PrintJobStack (int Nstack);
     3int PrintJobStack (int Nstack, char *command, char *hostname, int state, float age);
    44int PrintHostStack (int Nstack);
    55
    66int status (int argc, char **argv) {
    77
    8   PrintJobStack (PCONTROL_JOB_ALLJOBS);
    9   PrintHostStack (PCONTROL_HOST_ALLHOSTS);
     8  int N;
     9
     10  if (get_argument (argc, argv, "-h")) goto usage;
     11  if (get_argument (argc, argv, "-help")) goto usage;
     12  if (get_argument (argc, argv, "--help")) goto usage;
     13
     14  /* I would like to add the following options:
     15   * strsub on argv[0]
     16   * strsub on hostname, realhost
     17   * list hostname and realhost
     18   * filter by state
     19   * filter by dtime
     20  */
     21
     22  // -cmd (cmd)
     23  // -host (hostname)
     24  // -state (busy, pending, done, kill, exit, crash, resp, hung
     25  // -age (seconds?) (minutes?)
     26  // -nohost
     27
     28  char *COMMAND = NULL;
     29  if ((N = get_argument (argc, argv, "-cmd"))) {
     30    remove_argument (N, &argc, argv);
     31    COMMAND = strcreate (argv[N]);
     32    remove_argument (N, &argc, argv);
     33  }
     34
     35  char *HOSTNAME = NULL;
     36  if ((N = get_argument (argc, argv, "-host"))) {
     37    remove_argument (N, &argc, argv);
     38    HOSTNAME = strcreate (argv[N]);
     39    remove_argument (N, &argc, argv);
     40  }
     41
     42  int STATE = PCONTROL_JOB_ALLJOBS;
     43  if ((N = get_argument (argc, argv, "-state"))) {
     44    remove_argument (N, &argc, argv);
     45    STATE = GetJobStackIDbyName (argv[N]);
     46    remove_argument (N, &argc, argv);
     47    if (STATE == PCONTROL_JOB_NONE) goto usage;
     48  }
     49
     50  float AGE = 0.0;
     51  if ((N = get_argument (argc, argv, "-age"))) {
     52    remove_argument (N, &argc, argv);
     53    AGE = atof (argv[N]);
     54    remove_argument (N, &argc, argv);
     55  }
     56
     57  int SHOWHOST = TRUE;
     58  if ((N = get_argument (argc, argv, "-nohost"))) {
     59    remove_argument (N, &argc, argv);
     60    SHOWHOST = FALSE;
     61  }
     62  if ((N = get_argument (argc, argv, "+jobs"))) {
     63    remove_argument (N, &argc, argv);
     64    SHOWHOST = FALSE;
     65  }
     66
     67  int SHOWJOBS = TRUE;
     68  if ((N = get_argument (argc, argv, "-nojobs"))) {
     69    remove_argument (N, &argc, argv);
     70    SHOWJOBS = FALSE;
     71  }
     72  if ((N = get_argument (argc, argv, "+host"))) {
     73    remove_argument (N, &argc, argv);
     74    SHOWJOBS = FALSE;
     75  }
     76
     77  if (SHOWJOBS) {
     78    PrintJobStack (PCONTROL_JOB_ALLJOBS, COMMAND, HOSTNAME, STATE, AGE);
     79  }
     80  if (SHOWHOST) {
     81    PrintHostStack (PCONTROL_HOST_ALLHOSTS);
     82  }
    1083
    1184  return (TRUE);
     85
     86usage:
     87  gprint (GP_ERR, "USAGE: status [-cmd command] [-host hostname] [-state state] [-age seconds] [+jobs,-nohost] [+host,-nojobs]\n");
     88  return FALSE;
    1289}
    1390
    14 int PrintJobStack (int Nstack) {
     91int PrintJobStack (int Nstack, char *command, char *hostname, int state, float age) {
    1592
    1693  int i, j, Nobject;
     
    30107    job = stack[0].object[i];
    31108    ASSERT (job != NULL, "programming error");
    32     if (job[0].realhost == NULL) {
    33         gprint (GP_LOG, "%3d %9s ", i, job[0].hostname);
    34     } else {
    35         gprint (GP_LOG, "%3d %9s ", i, job[0].realhost);
    36     }
    37     gprint (GP_LOG, "%7s  ", GetJobStackName (job[0].state));
     109
     110    char *thishost = (job[0].realhost == NULL) ? job[0].hostname : job[0].realhost;
    38111
    39112    switch (job[0].state) {
     
    45118        gettimeofday (&now, (void *) NULL);
    46119        dtime = DTIME (now, job[0].start);
    47         gprint (GP_LOG, "%8.2f ", dtime);
    48120        break;
    49121
     
    55127      default:
    56128        dtime = DTIME (job[0].stop, job[0].start);
    57         gprint (GP_LOG, "%8.2f ", dtime);
    58129        break;
    59130    }
    60131
     132    // check on the filters
     133    if (command) {
     134      if (!strstr (job[0].argv[0], command)) continue;
     135    }
     136    if (hostname) {
     137      if (!strstr (thishost, hostname)) continue;
     138    }
     139    if (age > 0.0) {
     140      if (dtime < age) continue;
     141    }
     142    if (state != PCONTROL_JOB_ALLJOBS) {
     143      // allow PCONTROL_JOB_RESP == BUSY
     144      int validState = FALSE;
     145      validState |= (state == PCONTROL_JOB_RESP) && (job[0].state == PCONTROL_JOB_BUSY);
     146      validState |= (state == PCONTROL_JOB_BUSY) && (job[0].state == PCONTROL_JOB_RESP);
     147      validState |= (state == job[0].state);
     148      if (!validState) continue;
     149    }
     150
     151    gprint (GP_LOG, "%3d %9s ", i, thishost);
     152    gprint (GP_LOG, "%7s  ", GetJobStackName (job[0].state));
     153    gprint (GP_LOG, "%8.2f ", dtime);
     154
    61155    PrintID (GP_LOG, job[0].JobID);
    62     gprint (GP_LOG, " %2d ", job[0].priority);
     156    gprint (GP_LOG, " %2d ", job[0].nicelevel);
    63157    for (j = 0; j < job[0].argc; j++) {
    64158      gprint (GP_LOG, "%s ", job[0].argv[j]);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/photdbc/Makefile

    r33655 r37067  
    3131$(SRC)/args.$(ARCH).o              \
    3232$(SRC)/copy_images.$(ARCH).o       \
     33$(SRC)/select_images.$(ARCH).o     \
    3334$(SRC)/Shutdown.$(ARCH).o          \
    3435$(SRC)/join_stars.$(ARCH).o        \
     
    4142$(SRC)/ConfigInit.$(ARCH).o        \
    4243$(SRC)/args.$(ARCH).o              \
    43 $(SRC)/copy_images.$(ARCH).o       \
    4444$(SRC)/Shutdown.$(ARCH).o          \
    4545$(SRC)/join_stars.$(ARCH).o        \
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/photdbc/include/photdbc.h

    r33963 r37067  
    2020  int    Nmeas;
    2121} StatType;
     22
     23typedef struct {
     24  double Xc[5];
     25  double Yc[5];
     26  double Rc;
     27  double Dc;
     28} SkyRegionCoords;
    2229
    2330int    PARALLEL;
     
    8087PhotCodeData photcodes;
    8188
    82 char          *PHOTCODE_DROP_LIST, *PHOTCODE_SKIP_LIST;
    83 int           NphotcodesDrop,      NphotcodesSkip;
    84 PhotCode     **photcodesDrop,     **photcodesSkip;
     89char          *PHOTCODE_DROP_LIST, *PHOTCODE_KEEP_LIST;
     90int           NphotcodesDrop,      NphotcodesKeep;
     91PhotCode     **photcodesDrop,     **photcodesKeep;
    8592
    8693# define FLAG_AREA            0X0001
     
    131138void SetProtect (int mode);
    132139int SetSignals (void);
    133 int copy_images (char *outdir);
     140int copy_images (char *outdir, SkyList *skylist);
    134141void usage();
     142
     143void dsortindex (double *X, off_t *Y, int N);
     144off_t getRegionStartByRA (double R, double *Rref, off_t Nregions);
     145
     146Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage, int UseFullOverlap);
    135147
    136148int photdbc_catalogs (char *outroot, SkyList *skylist, int hostID);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/photdbc/src/args.c

    r33655 r37067  
    8585  }
    8686
     87  // measurements with these photcodes are not copied to the output
    8788  PHOTCODE_DROP_LIST = NULL;
    8889  if ((N = get_argument (argc, argv, "-photcode-drop"))) {
     
    9293  }
    9394
    94   PHOTCODE_SKIP_LIST = NULL;
    95   if ((N = get_argument (argc, argv, "-photcode-skip"))) {
    96     remove_argument (N, &argc, argv);
    97     PHOTCODE_SKIP_LIST = strcreate(argv[N]);
     95  // measurements with these photcodes are kept ***regardless of quality***
     96  // -photcode-keep J will keep all J-band measurements of all kinds
     97  // -photcode-keep GPC1.02.g will keep all g-band measurements from chip XY02
     98  PHOTCODE_KEEP_LIST = NULL;
     99  if ((N = get_argument (argc, argv, "-photcode-keep"))) {
     100    remove_argument (N, &argc, argv);
     101    PHOTCODE_KEEP_LIST = strcreate(argv[N]);
    98102    remove_argument (N, &argc, argv);
    99103  }
     
    254258  }
    255259
    256   PHOTCODE_SKIP_LIST = NULL;
    257   if ((N = get_argument (argc, argv, "-photcode-skip"))) {
    258     remove_argument (N, &argc, argv);
    259     PHOTCODE_SKIP_LIST = strcreate(argv[N]);
     260  PHOTCODE_KEEP_LIST = NULL;
     261  if ((N = get_argument (argc, argv, "-photcode-keep"))) {
     262    remove_argument (N, &argc, argv);
     263    PHOTCODE_KEEP_LIST = strcreate(argv[N]);
    260264    remove_argument (N, &argc, argv);
    261265  }
     
    290294 
    291295  fprintf (stderr, " -photcode-drop   : remove these photcodes from the output (REF or DEP only)\n");
    292   fprintf (stderr, " -photcode-skip  : ignore these photcodes when assessing the validity (keep unless object is dropped)\n");
     296  fprintf (stderr, " -photcode-keep  : ignore these photcodes when assessing the validity (keep unless object is dropped)\n");
    293297
    294298  fprintf (stderr, " -instmag (min) (max) : range of valid instrumental magnitudes (or measurements are dropped)\n");
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/photdbc/src/copy_images.c

    r33655 r37067  
    11# include "photdbc.h"
    22
    3 int copy_images (char *outdir) {
     3int copy_images (char *outdir, SkyList *skylist) {
    44
    55  int status;
    6   off_t Nimage;
     6  off_t Nimage, Nsubset;
     7  off_t *LineNumber;
    78  char *ImageOut;
    89  unsigned int imageID;
    910  FITS_DB in;
    1011  FITS_DB out;
    11   Image *image;
     12  Image *image, *subset;
    1213  struct stat filestat;
    1314  char *path;
     
    5051      exit (2);
    5152  }
    52   dvo_image_addrows (&out, image, Nimage);
     53
     54  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset, FALSE);
     55
     56  dvo_image_addrows (&out, subset, Nsubset);
    5357
    5458  // note that imageID is unsigned int
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/photdbc/src/find_images.c

    r30616 r37067  
    2525  tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    2626  tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    27   strcpy (tcoords.ctype, "RA---TAN");
     27  strcpy (tcoords.ctype, "DEC--TAN");
    2828
    2929  timage = gfits_table_get_Image (&db[0].ftable, &Ntimage, &db[0].swapped);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/photdbc/src/get_mags.c

    r15509 r37067  
    2222      catalog[0].secfilt[i*Nsecfilt+j].M  = NAN;
    2323      catalog[0].secfilt[i*Nsecfilt+j].dM = NAN;
    24       catalog[0].secfilt[i*Nsecfilt+j].Xm = NAN_S_SHORT;
     24      catalog[0].secfilt[i*Nsecfilt+j].Mchisq = NAN;
    2525    }
    2626  }
     
    5656      Mval = (Nsec == -1) ? &catalog[0].average[i].dM : &catalog[0].secfilt[i*Nsecfilt+Nsec].dM;
    5757      *Mval = stats.sigma;
    58       Mval = (Nsec == -1) ? &catalog[0].average[i].Xm : &catalog[0].secfilt[i*Nsecfilt+Nsec].Xm;
    59       *Mval = 100.0*log10(stats.chisq);
     58      Mval = (Nsec == -1) ? &catalog[0].average[i].Mchisq : &catalog[0].secfilt[i*Nsecfilt+Nsec].Mchisq;
     59      *Mval = stats.chisq;
    6060    }
    6161  }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/photdbc/src/initialize.c

    r33655 r37067  
    1313
    1414  photcodesDrop = ParsePhotcodeList (PHOTCODE_DROP_LIST, &NphotcodesDrop, FALSE);
    15   photcodesSkip = ParsePhotcodeList (PHOTCODE_SKIP_LIST, &NphotcodesSkip, FALSE);
     15  photcodesKeep = ParsePhotcodeList (PHOTCODE_KEEP_LIST, &NphotcodesKeep, FALSE);
    1616
    1717  if (SHOW_PARAMS) {
     
    5454
    5555  photcodesDrop = ParsePhotcodeList (PHOTCODE_DROP_LIST, &NphotcodesDrop, FALSE);
    56   photcodesSkip = ParsePhotcodeList (PHOTCODE_SKIP_LIST, &NphotcodesSkip, FALSE);
     56  photcodesKeep = ParsePhotcodeList (PHOTCODE_KEEP_LIST, &NphotcodesKeep, FALSE);
    5757
    5858  if (SHOW_PARAMS) {
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/photdbc/src/join_stars.c

    r29938 r37067  
    33void join_stars (Catalog *catalog) {
    44
    5   off_t i, j, k, m, M, Ni, Nj, first_j, Nfirst;
     5  off_t i, j, k, m, Ni, Nj, first_j;
    66  off_t Naves, Nmeas, Ncurr;
    77  off_t Naverage, Nmeasure, *index;
     
    5757  tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    5858  tcoords.Npolyterms = 0;
    59   strcpy (tcoords.ctype, "RA---TAN");
     59  strcpy (tcoords.ctype, "DEC--TAN");
    6060 
    6161  /* project & sort coordinates in local linear frame */
     
    109109        mpointer[Nmeas].measure = m;
    110110        mpointer[Nmeas].averef  = Naves;
    111         mpointer[Nmeas].R       = average[Ni].R - measure[m].dR / 3600.0;
    112         mpointer[Nmeas].D       = average[Ni].D - measure[m].dD / 3600.0;
     111        mpointer[Nmeas].R       = measure[m].R;
     112        mpointer[Nmeas].D       = measure[m].D;
    113113        Nmeas ++;
    114114      }
     
    155155          mpointer[Nmeas].measure = m;
    156156          mpointer[Nmeas].averef  = Ncurr;
    157           mpointer[Nmeas].R       = average[Nj].R - measure[m].dR / 3600.0;
    158           mpointer[Nmeas].D       = average[Nj].D - measure[m].dD / 3600.0;
     157          mpointer[Nmeas].R       = measure[m].R;
     158          mpointer[Nmeas].D       = measure[m].D;
    159159          Nmeas ++;
    160160        }
    161         Nfirst = average[Nj].Nmeasure;
    162161        naverage[Ncurr].Nmeasure += average[Nj].Nmeasure;
    163162        found[j] = TRUE;
     
    178177
    179178        /* update original measurement offsets for new detections */
    180         for (k = Nfirst; k < naverage[Ncurr].Nmeasure; k++) {
    181           m = naverage[Ncurr].measureOffset + k;
    182           M = mpointer[m].measure;
    183           measure[M].dR = 3600.0*(Sr - mpointer[m].R);
    184           measure[M].dD = 3600.0*(Sd - mpointer[m].D);
    185         }
     179        // for (k = Nfirst; k < naverage[Ncurr].Nmeasure; k++) {
     180        //   m = naverage[Ncurr].measureOffset + k;
     181        //   M = mpointer[m].measure;
     182        //   measure[M].dR = 3600.0*(Sr - mpointer[m].R);
     183        //   measure[M].dD = 3600.0*(Sd - mpointer[m].D);
     184        // }
    186185
    187186        /* update current reference star position */
     
    189188# else
    190189        /* update original measurement offsets for new detections */
    191         for (k = Nfirst; k < naverage[Ncurr].Nmeasure; k++) {
    192           m = naverage[Ncurr].measureOffset + k;
    193           M = mpointer[m].measure;
    194           measure[M].dR = 3600.0*(naverage[Ncurr].R - mpointer[m].R);
    195           measure[M].dD = 3600.0*(naverage[Ncurr].D - mpointer[m].D);
    196         }
     190        // now not needed measure[M] carries R,D
     191        // for (k = Nfirst; k < naverage[Ncurr].Nmeasure; k++) {
     192        //   m = naverage[Ncurr].measureOffset + k;
     193        //   M = mpointer[m].measure;
     194        //   measure[M].dR = 3600.0*(naverage[Ncurr].R - mpointer[m].R);
     195        //   measure[M].dD = 3600.0*(naverage[Ncurr].D - mpointer[m].D);
     196        // }
    197197# endif
    198198      }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/photdbc/src/make_subcatalog.c

    r31635 r37067  
    99  off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm, Nsecfilt;
    1010  double mag, minMag, minSigma;
    11   int keep, *secSkip;
     11  int keep, *secKeep;
    1212  PhotCode *photcode;
    1313 
     
    1616
    1717  // set up a list of SEC entries to ignore when evaluating a source
    18   ALLOCATE (secSkip, int, Nsecfilt);
     18  ALLOCATE (secKeep, int, Nsecfilt);
    1919  for (i = 0; i < Nsecfilt; i++) {
    20       secSkip[i] = FALSE;
     20      secKeep[i] = FALSE;
    2121      photcode = GetPhotcodebyNsec(i);
    22       for (k = 0; k < NphotcodesSkip; k++) {
    23           if (photcodesSkip[k][0].code != photcode[0].code) continue;
    24           secSkip[i] = TRUE;
     22      for (k = 0; k < NphotcodesKeep; k++) {
     23          if (photcodesKeep[k][0].code != photcode[0].code) continue;
     24          secKeep[i] = TRUE;
    2525      }
    2626  }
     
    6767      keep = FALSE;
    6868      for (j = 0; !keep && (j < Nsecfilt); j++) {
    69           if (secSkip[j]) continue;
     69          if (secKeep[j]) continue;
    7070          if (catalog[0].secfilt[Nsecfilt*i+j].Ncode >= NCODE_MIN) {
    7171              keep = TRUE;
     
    101101      if (NphotcodesDrop > 0) {
    102102          found = FALSE;
    103           for (k = 0; (k < NphotcodesSkip) && !found; k++) {
    104               if (photcodesSkip[k][0].code == catalog[0].measure[offset].photcode) found = TRUE;
    105               if (photcodesSkip[k][0].code == GetPhotcodeEquivCodebyCode(catalog[0].measure[offset].photcode)) found = TRUE;
     103          for (k = 0; (k < NphotcodesDrop) && !found; k++) {
     104              if (photcodesDrop[k][0].code == catalog[0].measure[offset].photcode) found = TRUE;
     105              if (photcodesDrop[k][0].code == GetPhotcodeEquivCodebyCode(catalog[0].measure[offset].photcode)) found = TRUE;
    106106          }
    107107          if (found) continue;
     
    109109 
    110110      // ignore certain photcodes to assess the measurements
    111       if (NphotcodesSkip > 0) {
     111      if (NphotcodesKeep > 0) {
    112112          found = FALSE;
    113           for (k = 0; (k < NphotcodesSkip) && !found; k++) {
    114               if (photcodesSkip[k][0].code == catalog[0].measure[offset].photcode) found = TRUE;
    115               if (photcodesSkip[k][0].code == GetPhotcodeEquivCodebyCode(catalog[0].measure[offset].photcode)) found = TRUE;
     113          for (k = 0; (k < NphotcodesKeep) && !found; k++) {
     114              if (photcodesKeep[k][0].code == catalog[0].measure[offset].photcode) found = TRUE;
     115              if (photcodesKeep[k][0].code == GetPhotcodeEquivCodebyCode(catalog[0].measure[offset].photcode)) found = TRUE;
    116116          }
    117117          if (found) goto keep;
     
    123123      // select measurements by mag limit -- drop exactly this measurement 
    124124      if (ExcludeByInstMag) {
    125         mag = PhotInst (&catalog[0].measure[offset]);
     125        mag = PhotInst (&catalog[0].measure[offset], MAG_CLASS_PSF);
    126126        if (mag < INST_MAG_MIN) continue;
    127127        if (mag > INST_MAG_MAX) continue;
     
    135135      // check measurements for this object -- drop object if no measurements pass
    136136      if (ExcludeByMaxMinMag) {
    137         mag = PhotSys (&catalog[0].measure[offset], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt]);
     137        mag = PhotSys (&catalog[0].measure[offset], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], MAG_CLASS_PSF);
    138138        minMag = MIN (minMag, mag);
    139139      }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/photdbc/src/photdbc.c

    r33655 r37067  
    99  initialize (argc, argv);
    1010
    11   // load and copy the image table
    12   copy_images (argv[1]);
    13 
    1411  // the output catalog needs to inherit the SKY_DEPTH of the input catalog
    1512  sky = SkyTableLoadOptimal (CATDIR, NULL, NULL, TRUE, 0, VERBOSE);
    1613  SkyTableSetFilenames (sky, CATDIR, "cpt");
    1714  skylist = SkyListByPatch (sky, -1, &REGION);
     15
     16  // load and copy the image table
     17  copy_images (argv[1], skylist);
    1818
    1919  // hostID is 0 for master program
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/photdbc/src/photdbc_catalogs.c

    r33963 r37067  
    120120    if (ExcludeByMaxMinMag) { snprintf (tmpline, DVO_MAX_PATH, "%s -maxminmag %f",     command, MAX_MIN_MAG);                   strcpy (command, tmpline); }
    121121    if (PHOTCODE_DROP_LIST) { snprintf (tmpline, DVO_MAX_PATH, "%s -photcode-drop %s", command, PHOTCODE_DROP_LIST);    strcpy (command, tmpline); }
    122     if (PHOTCODE_SKIP_LIST) { snprintf (tmpline, DVO_MAX_PATH, "%s -photcode-skip %s", command, PHOTCODE_SKIP_LIST);    strcpy (command, tmpline); }
     122    if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, DVO_MAX_PATH, "%s -photcode-keep %s", command, PHOTCODE_KEEP_LIST);    strcpy (command, tmpline); }
    123123    if (CATFORMAT)          { snprintf (tmpline, DVO_MAX_PATH, "%s -set-format %s",    command, CATFORMAT);                     strcpy (command, tmpline); }
    124124    if (CATMODE)            { snprintf (tmpline, DVO_MAX_PATH, "%s -set-mode %s",      command, CATMODE);                       strcpy (command, tmpline); }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/Makefile

    r35416 r37067  
    6969$(SRC)/resort_catalog.$(ARCH).o  \
    7070$(SRC)/BrightCatalog.$(ARCH).o  \
     71$(SRC)/assign_images.$(ARCH).o \
     72$(SRC)/launch_region_hosts.$(ARCH).o \
     73$(SRC)/relastro_parallel_images.$(ARCH).o \
     74$(SRC)/relastro_parallel_regions.$(ARCH).o \
     75$(SRC)/MeanPosIO.$(ARCH).o \
     76$(SRC)/share_mean_pos.$(ARCH).o \
     77$(SRC)/share_images_pos.$(ARCH).o \
     78$(SRC)/ImagePosIO.$(ARCH).o \
     79$(SRC)/ImageTable.$(ARCH).o \
     80$(SRC)/markObjects.$(ARCH).o \
     81$(SRC)/indexCatalogs.$(ARCH).o \
     82$(SRC)/syncfile.$(ARCH).o \
    7183$(SRC)/relastroVisual.$(ARCH).o
    7284
     
    115127$(SRC)/plotstuff.$(ARCH).o           \
    116128$(SRC)/relastroVisual.$(ARCH).o \
     129$(SRC)/syncfile.$(ARCH).o \
    117130$(SRC)/BrightCatalog.$(ARCH).o
    118131
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/include/relastro.h

    r35763 r37067  
    2020typedef enum {FIT_NONE, FIT_AVERAGE, FIT_PM_ONLY, FIT_PAR_ONLY, FIT_PM_AND_PAR} FitMode;
    2121
    22 typedef enum {TARGET_NONE, TARGET_SIMPLE, TARGET_CHIPS, TARGET_MOSAICS, TARGET_HIGH_SPEED, TARGET_MERGE_SOURCE, TARGET_UPDATE_OBJECTS, TARGET_UPDATE_OFFSETS, TARGET_LOAD_OBJECTS, TARGET_HPM} FitTarget;
     22typedef enum {OP_NONE, OP_IMAGES, OP_HIGH_SPEED, OP_MERGE_SOURCE, OP_UPDATE_OBJECTS, OP_UPDATE_OFFSETS, OP_LOAD_OBJECTS, OP_HPM, OP_PARALLEL_REGIONS, OP_PARALLEL_IMAGES} RelastroOp;
     23
     24typedef enum {TARGET_NONE, TARGET_SIMPLE, TARGET_CHIPS, TARGET_MOSAICS} FitTarget;
    2325
    2426typedef enum {
     
    3032  MARK_BIG_OFFSET    = 0x0010,
    3133} MeasurementMask;
     34
     35typedef struct {
     36  float R;
     37  float D;
     38  unsigned int objID;
     39  unsigned int catID;
     40} MeanPos;
     41
     42typedef struct {
     43  Coords coords;
     44  float dXpixSys;
     45  float dYpixSys;
     46  unsigned int imageID;
     47  int nFitAstrom;
     48  int flags;
     49} ImagePos;
    3250
    3351typedef struct {
     
    5674  double L, M;  /* Focal Plane   - pixels  */
    5775  double X, Y;  /* Chip Coords   - pixels  */
    58   double Mag;
    59   double dMag;
    60   double dPos;
     76  float Mag;
     77  float ColorBlue;
     78  float ColorRed;
     79  float dMag;
     80  float dPos;
    6181  int mask;
    6282  int Nmeas;
     
    93113  unsigned int start;
    94114  unsigned int stop;
     115  off_t myImage;
    95116  float Mcal;
    96117  float dMcal;
     
    113134} StatType;
    114135
    115 # define MARKTIME(MSG,...) { \
    116   float dtime; \
    117   gettimeofday (&stop, (void *) NULL); \
    118   dtime = DTIME (stop, start); \
    119   fprintf (stderr, MSG, __VA_ARGS__); }
    120 
    121136/* global variables set in parameter file */
    122137# define DVO_MAX_PATH 1024
     
    129144char   SKY_TABLE[DVO_MAX_PATH];
    130145int    SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */
     146
     147// globals for parallel region operations
     148char  *REGION_FILE;
     149char  *IMAGE_TABLE;
     150int    REGION_HOST_ID;
     151int    PARALLEL_REGIONS_MANUAL;
    131152
    132153int          HOST_ID;
     
    179200double MaxDensityValue;
    180201
    181 char          *PHOTCODE_KEEP_LIST, *PHOTCODE_SKIP_LIST;
    182 int           NphotcodesKeep,      NphotcodesSkip;
    183 PhotCode     **photcodesKeep,     **photcodesSkip;
     202char          *PHOTCODE_KEEP_LIST, *PHOTCODE_SKIP_LIST, *PHOTCODE_RESET_LIST;
     203int           NphotcodesKeep,      NphotcodesSkip,      NphotcodesReset;
     204PhotCode     **photcodesKeep,     **photcodesSkip,     **photcodesReset;
    184205
    185206char          *PHOTCODE_A_LIST,  *PHOTCODE_B_LIST;
     
    189210SkyRegionSelection SELECTION;
    190211
     212char         *DCR_BLUE_COLOR_POS,    *DCR_BLUE_COLOR_NEG;
     213PhotCode     *DCR_BLUE_PHOTCODE_POS, *DCR_BLUE_PHOTCODE_NEG;
     214int           DCR_BLUE_NSEC_POS,      DCR_BLUE_NSEC_NEG;
     215
     216char         *DCR_RED_COLOR_POS,    *DCR_RED_COLOR_NEG;
     217PhotCode     *DCR_RED_PHOTCODE_POS, *DCR_RED_PHOTCODE_NEG;
     218int           DCR_RED_NSEC_POS,      DCR_RED_NSEC_NEG;
     219
    191220int ImagSelect;
    192221double ImagMin, ImagMax;
     
    206235int USE_BASIC_CHECK;
    207236
     237int ExcludeBogus;
     238double ExcludeBogusRadius;
     239
    208240FitMode FIT_MODE;
    209241
     242RelastroOp RELASTRO_OP;
    210243FitTarget FIT_TARGET;
    211244
     
    278311int           liststats           PROTO((double *value, double *dvalue, int N, StatType *stats));
    279312int           liststats_pos       PROTO((double *value, double *dvalue, int N, StatType *stats, int XVERB));
    280 Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath));
     313Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath, char *syncfile));
    281314int           load_images         PROTO((FITS_DB *db, SkyList *skylist, int UseFullOverlap));
    282315Image        *select_images       PROTO((SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage, int UseFullOverlap));
     
    388421int setMeanR (double ra_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt);
    389422int setMeanD (double dec_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt);
     423double getMeanR_Big (Measure *measure, Average *average, SecFilt *secfilt);
     424double getMeanD_Big (Measure *measure, Average *average, SecFilt *secfilt);
    390425int setMeanR_Big (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt);
    391426int setMeanD_Big (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt);
     
    450485int hpm_catalogs_parallel (SkyList *skylist);
    451486int hpm_objects (SkyRegion *region, Catalog *catalog);
     487
     488int strextend (char *input, char *format,...);
     489int launch_region_hosts (RegionHostTable *regionHosts);
     490
     491int assign_images (FITS_DB *db, RegionHostTable *regionHosts);
     492int select_images_hostregion (RegionHostTable *regionHosts, Image *image, off_t Nimage);
     493int calculate_image_bounds (Image *image, double *rmin, double *rmax, double *dmin, double *dmax, double Rmid);
     494int calculate_host_image_bounds (RegionHostTable *regionHosts);
     495int find_host_for_coords (RegionHostTable *regionHosts, double Rc, double Dc);
     496
     497int relastro_parallel_regions ();
     498int relastro_parallel_images ();
     499
     500char *make_filename (char *dirname, char *hostname, int hostID, char *tailname);
     501int check_sync_file (char *filename, int nloop);
     502int clear_sync_file (char *filename);
     503int update_sync_file (char *filename, int nloop);
     504
     505int share_mean_pos (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     506int slurp_mean_pos (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     507int set_mean_pos (MeanPos *meanpos, Average *average);
     508MeanPos *merge_mean_pos (MeanPos *target, int *ntarget, MeanPos *source, int Nsource);
     509
     510int MeanPosSave(char *filename, MeanPos *meanpos, off_t Nmeanpos);
     511MeanPos *MeanPosLoad(char *filename, off_t *nmeanpos);
     512
     513int indexCatalogs (Catalog *catalog, int Ncatalog);
     514int catID_and_objID_to_seq (int catID, int objID, int *catSeq, off_t *objSeq);
     515
     516int markObjects (Catalog *catalog, int Ncatalog);
     517
     518int ImagePosSave(char *filename, ImagePos *image_pos, off_t Nimage_pos);
     519ImagePos *ImagePosLoad(char *filename, off_t *nimage_pos);
     520
     521int share_image_pos (RegionHostTable *regionHosts, int nloop);
     522int slurp_image_pos (RegionHostTable *regionHosts, int nloop);
     523ImagePos *merge_image_pos (ImagePos *target, int *ntarget, ImagePos *source, int Nsource);
     524int set_image_pos (ImagePos *image_pos, Image *image);
     525
     526Image *ImageTableLoad(char *filename, off_t *nimage);
     527int ImageTableSave (char *filename, Image *images, off_t Nimages);
     528int select_mosaics_hostregion (RegionHostTable *regionHosts, Image *image, off_t Nimage);
     529
     530float getColorBlue (off_t meas, int cat);
     531float getColorRed (off_t meas, int cat);
     532
     533int strextend (char *input, char *format,...);
     534
     535int areImagesLoaded ();
     536int areImagesMatched ();
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/BrightCatalog.c

    r35105 r37067  
    6868 
    6969    // need to create and assign to flat-field correction
    70     GET_COLUMN(dR,        "RA_OFF",     float);
    71     GET_COLUMN(dD,        "DEC_OFF",    float);
     70    GET_COLUMN(R,         "RA",         double);
     71    GET_COLUMN(D,         "DEC",        double);
    7272    GET_COLUMN(M,         "MAG_SYS",    float);
    7373    GET_COLUMN(Mcal,      "MAG_CAL",    float);
     
    9292    ALLOCATE (measure, MeasureTiny, Nrow);
    9393    for (i = 0; i < Nrow; i++) {
    94       measure[i].dR        = dR[i];
    95       measure[i].dD        = dD[i];
     94      measure[i].R         = R[i];
     95      measure[i].D         = D[i];
    9696      measure[i].M         = M[i];
    9797      measure[i].Mcal      = Mcal[i];
     
    113113    // fprintf (stderr, "loaded data for %lld measures\n", (long long) Nrow);
    114114
    115     free (dR      );
    116     free (dD      );
     115    free (R       );
     116    free (D       );
    117117    free (M       );
    118118    free (Mcal    );
     
    145145    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) goto escape;
    146146
    147     GET_COLUMN(R,              "RA",          double);
    148     GET_COLUMN(D,              "DEC",         double);
    149     GET_COLUMN(dR,             "RA_ERR",      float);
    150     GET_COLUMN(dD,             "DEC_ERR",     float);
    151     GET_COLUMN(uR,             "U_RA",        float);
    152     GET_COLUMN(uD,             "U_DEC",       float);
    153     GET_COLUMN(duR,            "V_RA_ERR",    float);
    154     GET_COLUMN(duD,            "V_DEC_ERR",   float);
    155     GET_COLUMN(P,              "PAR",         float);
    156     GET_COLUMN(dP,             "PAR_ERR",     float);
    157     GET_COLUMN(ChiSqAve,       "CHISQ_POS",   float);
    158     GET_COLUMN(ChiSqPM,        "CHISQ_PM",    float);
    159     GET_COLUMN(ChiSqPar,       "CHISQ_PAP",   float);
    160     GET_COLUMN(Tmean,          "MEAN_EPOCH",  int);
    161     GET_COLUMN(Trange,         "TIME_RANGE",  int);
    162     GET_COLUMN(stargal,        "STARGAL_SEP", float);
    163     GET_COLUMN(Npos,           "NUMBER_POS",  short);
    164     GET_COLUMN(Nmeasure,       "NMEASURE",    short);
    165     GET_COLUMN(Nmissing,       "NMISSING",    short);
    166     GET_COLUMN(Nextend,        "NEXTEND",     short);
    167     GET_COLUMN(measureOffset,  "OFF_MEASURE", int);
    168     GET_COLUMN(missingOffset,  "OFF_MISSING", int);
    169     GET_COLUMN(extendOffset,   "OFF_EXTEND",  int);
    170     GET_COLUMN(flags,          "FLAGS",       int);
    171     GET_COLUMN(photFlagsUpper, "PHOTFLAGS_U", int);
    172     GET_COLUMN(photFlagsLower, "PHOTFLAGS_L", int);
    173     GET_COLUMN(objID,          "OBJ_ID",      int);
    174     GET_COLUMN(catID,          "CAT_ID",      int);
    175     GET_COLUMN(extID,          "EXT_ID",      int64_t);
     147    GET_COLUMN(R,              "RA",             double);
     148    GET_COLUMN(D,              "DEC",            double);
     149    GET_COLUMN(dR,             "RA_ERR",         float);
     150    GET_COLUMN(dD,             "DEC_ERR",        float);
     151    GET_COLUMN(uR,             "U_RA",           float);
     152    GET_COLUMN(uD,             "U_DEC",          float);
     153    GET_COLUMN(duR,            "V_RA_ERR",       float);
     154    GET_COLUMN(duD,            "V_DEC_ERR",      float);
     155    GET_COLUMN(P,              "PAR",            float);
     156    GET_COLUMN(dP,             "PAR_ERR",        float);
     157    GET_COLUMN(ChiSqAve,       "CHISQ_POS",      float);
     158    GET_COLUMN(ChiSqPM,        "CHISQ_PM",       float);
     159    GET_COLUMN(ChiSqPar,       "CHISQ_PAP",      float);
     160    GET_COLUMN(Tmean,          "MEAN_EPOCH",     int);
     161    GET_COLUMN(Trange,         "TIME_RANGE",     int);
     162    GET_COLUMN(stargal,        "STARGAL_SEP",    float);
     163    GET_COLUMN(Npos,           "NUMBER_POS",     short);
     164    GET_COLUMN(Nmeasure,       "NMEASURE",       short);
     165    GET_COLUMN(Nmissing,       "NMISSING",       short);
     166    GET_COLUMN(Nextend,        "NEXTEND",        short);
     167    GET_COLUMN(measureOffset,  "OFF_MEASURE",    int);
     168    GET_COLUMN(missingOffset,  "OFF_MISSING",    int);
     169    GET_COLUMN(refColorBlue,   "REF_COLOR_BLUE", float);
     170    GET_COLUMN(refColorRed,    "REF_COLOR_RED",  float);
     171    GET_COLUMN(flags,          "FLAGS",          int);
     172    GET_COLUMN(photFlagsUpper, "PHOTFLAGS_U",    int);
     173    GET_COLUMN(photFlagsLower, "PHOTFLAGS_L",    int);
     174    GET_COLUMN(objID,          "OBJ_ID",         int);
     175    GET_COLUMN(catID,          "CAT_ID",         int);
     176    GET_COLUMN(extID,          "EXT_ID",         int64_t);
    176177    gfits_free_header (&theader);
    177178    gfits_free_table  (&ftable);
     
    202203      average[i].measureOffset   = measureOffset[i]   ;
    203204      average[i].missingOffset   = missingOffset[i]   ;
    204       average[i].extendOffset    = extendOffset[i]    ; 
     205      average[i].refColorBlue    = refColorBlue[i]    ; 
     206      average[i].refColorRed     = refColorRed[i]     ; 
    205207      average[i].flags           = flags[i]           ;
    206208      average[i].photFlagsUpper  = photFlagsUpper[i]  ;
     
    234236    free (measureOffset);
    235237    free (missingOffset);
    236     free (extendOffset);
     238    free (refColorBlue);
     239    free (refColorRed);
    237240    free (flags);
    238241    free (photFlagsUpper);
     
    256259 
    257260    // need to create and assign to flat-field correction
    258     GET_COLUMN(M,     "MAG",      float);
    259     GET_COLUMN(dM,    "MAG_ERR",  float);
    260     GET_COLUMN(Xm,    "MAG_CHI",  float);
    261     GET_COLUMN(flags, "FLAGS",    int);
    262     GET_COLUMN(Ncode, "NCODE",    short);
    263     GET_COLUMN(Nused, "NUSED",    short);
    264     GET_COLUMN(M_20,  "MAG_20",   short);
    265     GET_COLUMN(M_80,  "MAG_80",   short);
     261    GET_COLUMN(M,      "MAG",      float);
     262    GET_COLUMN(dM,     "MAG_ERR",  float);
     263    GET_COLUMN(Mchisq, "MAG_CHI",  float);
     264    GET_COLUMN(flags,  "FLAGS",    int);
     265    GET_COLUMN(Ncode,  "NCODE",    short);
     266    GET_COLUMN(Nused,  "NUSED",    short);
     267    GET_COLUMN(Mmin,   "MAG_MIN",  float);
     268    GET_COLUMN(Mmax,   "MAG_MAX",  float);
    266269    gfits_free_header (&theader);
    267270    gfits_free_table  (&ftable);
     
    270273    ALLOCATE (secfilt, SecFilt, Nrow);
    271274    for (i = 0; i < Nrow; i++) {
    272       secfilt[i].M     = M[i];         
    273       secfilt[i].dM    = dM[i];
    274       secfilt[i].Xm    = Xm[i];
    275       secfilt[i].flags = flags[i];
    276       secfilt[i].Ncode = Ncode[i];
    277       secfilt[i].Nused = Nused[i];
    278       secfilt[i].M_20  = M_20[i];
    279       secfilt[i].M_80  = M_80[i];
     275      secfilt[i].M      = M[i];         
     276      secfilt[i].dM     = dM[i];
     277      secfilt[i].Mchisq = Mchisq[i];
     278      secfilt[i].flags  = flags[i];
     279      secfilt[i].Ncode  = Ncode[i];
     280      secfilt[i].Nused  = Nused[i];
     281      secfilt[i].Mmin   = Mmin[i];
     282      secfilt[i].Mmax   = Mmax[i];
    280283    }
    281284    fprintf (stderr, "loaded data for %lld averages\n", (long long) Nrow);
     
    283286    free (M    );
    284287    free (dM   );
    285     free (Xm   );
     288    free (Mchisq);
    286289    free (flags);
    287290    free (Ncode);
    288291    free (Nused);
    289     free (M_20 );
    290     free (M_80 );
     292    free (Mmin );
     293    free (Mmax );
    291294    catalog->secfilt = secfilt;
    292295    // assert Nsecfilt * Naverage = Nrow?
     
    351354    gfits_define_bintable_column (&theader, "E", "Y_FIX",    "ccd y fiex coord",           "pix",    1.0, 0.0);
    352355    gfits_define_bintable_column (&theader, "E", "EXPTIME",  "-2.5 * log (exposure time)", "sec",    1.0, 0.0);
    353     gfits_define_bintable_column (&theader, "J", "TIME",     "time of exp",                "sec",    1.0, 1.0*0x8000);
    354     gfits_define_bintable_column (&theader, "J", "AVE_REF",  "pointer to average table",    NULL,    1.0, 1.0*0x8000);
    355     gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image",                       NULL,    1.0, 1.0*0x8000);
    356     gfits_define_bintable_column (&theader, "J", "DB_FLAGS", "flags",                       NULL,    1.0, 1.0*0x8000);
    357     gfits_define_bintable_column (&theader, "J", "PHOT_FLAGS", "photflags",                 NULL,    1.0, 1.0*0x8000);
    358     gfits_define_bintable_column (&theader, "J", "CAT_ID",   "catalog",                     NULL,    1.0, 1.0*0x8000);
    359     gfits_define_bintable_column (&theader, "I", "PHOTCODE", "photcode",                    NULL,    1.0, 1.0*0x80);
     356    gfits_define_bintable_column (&theader, "J", "TIME",     "time of exp",                "sec",    1.0, 0.0);
     357    gfits_define_bintable_column (&theader, "J", "AVE_REF",  "pointer to average table",    NULL,    1.0, 0.0);
     358    gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image",                       NULL,    1.0, 0.0);
     359    gfits_define_bintable_column (&theader, "J", "DB_FLAGS", "flags",                       NULL,    1.0, 0.0);
     360    gfits_define_bintable_column (&theader, "J", "PHOT_FLAGS", "photflags",                 NULL,    1.0, 0.0);
     361    gfits_define_bintable_column (&theader, "J", "CAT_ID",   "catalog",                     NULL,    1.0, 0.0);
     362    gfits_define_bintable_column (&theader, "I", "PHOTCODE", "photcode",                    NULL,    1.0, 0.0);
    360363
    361364    // generate the output array that carries the data
     
    363366
    364367    // create intermediate storage arrays
    365     float *dR        ; ALLOCATE (dR       ,  float, catalog->Nmeasure);
    366     float *dD        ; ALLOCATE (dD       ,  float, catalog->Nmeasure);
    367     float *M         ; ALLOCATE (M        ,  float, catalog->Nmeasure);
    368     float *Mcal      ; ALLOCATE (Mcal     ,  float, catalog->Nmeasure);
    369     float *dM        ; ALLOCATE (dM       ,  float, catalog->Nmeasure);
    370     float *airmass   ; ALLOCATE (airmass  ,  float, catalog->Nmeasure);
    371     float *Xccd      ; ALLOCATE (Xccd     ,  float, catalog->Nmeasure);
    372     float *Yccd      ; ALLOCATE (Yccd     ,  float, catalog->Nmeasure);
    373     float *Xfix      ; ALLOCATE (Xfix     ,  float, catalog->Nmeasure);
    374     float *Yfix      ; ALLOCATE (Yfix     ,  float, catalog->Nmeasure);
    375     float *dt        ; ALLOCATE (dt       ,  float, catalog->Nmeasure);
    376     int   *t         ; ALLOCATE (t        ,  int  , catalog->Nmeasure);
    377     int   *averef    ; ALLOCATE (averef   ,  int  , catalog->Nmeasure);
    378     int   *imageID   ; ALLOCATE (imageID  ,  int  , catalog->Nmeasure);
    379     int   *dbFlags   ; ALLOCATE (dbFlags  ,  int  , catalog->Nmeasure);
    380     int   *photFlags ; ALLOCATE (photFlags,  int  , catalog->Nmeasure);
    381     int   *catID     ; ALLOCATE (catID    ,  int  , catalog->Nmeasure);
    382     short *photcode  ; ALLOCATE (photcode ,  short, catalog->Nmeasure);
     368    double *R         ; ALLOCATE (R        ,  double, catalog->Nmeasure);
     369    double *D         ; ALLOCATE (D        ,  double, catalog->Nmeasure);
     370    float  *M         ; ALLOCATE (M        ,  float, catalog->Nmeasure);
     371    float  *Mcal      ; ALLOCATE (Mcal     ,  float, catalog->Nmeasure);
     372    float  *dM        ; ALLOCATE (dM       ,  float, catalog->Nmeasure);
     373    float  *airmass   ; ALLOCATE (airmass  ,  float, catalog->Nmeasure);
     374    float  *Xccd      ; ALLOCATE (Xccd     ,  float, catalog->Nmeasure);
     375    float  *Yccd      ; ALLOCATE (Yccd     ,  float, catalog->Nmeasure);
     376    float  *Xfix      ; ALLOCATE (Xfix     ,  float, catalog->Nmeasure);
     377    float  *Yfix      ; ALLOCATE (Yfix     ,  float, catalog->Nmeasure);
     378    float  *dt        ; ALLOCATE (dt       ,  float, catalog->Nmeasure);
     379    int    *t         ; ALLOCATE (t        ,  int  , catalog->Nmeasure);
     380    int    *averef    ; ALLOCATE (averef   ,  int  , catalog->Nmeasure);
     381    int    *imageID   ; ALLOCATE (imageID  ,  int  , catalog->Nmeasure);
     382    int    *dbFlags   ; ALLOCATE (dbFlags  ,  int  , catalog->Nmeasure);
     383    int    *photFlags ; ALLOCATE (photFlags,  int  , catalog->Nmeasure);
     384    int    *catID     ; ALLOCATE (catID    ,  int  , catalog->Nmeasure);
     385    short  *photcode  ; ALLOCATE (photcode ,  short, catalog->Nmeasure);
    383386
    384387    // assign the storage arrays
    385388    MeasureTiny *measure = catalog->measure;
    386389    for (i = 0; i < catalog->Nmeasure; i++) {
    387       dR[i]       = measure[i].dR       ;
    388       dD[i]       = measure[i].dD       ;
     390      R[i]        = measure[i].R        ;
     391      D[i]        = measure[i].D        ;
    389392      M[i]        = measure[i].M        ;
    390393      Mcal[i]     = measure[i].Mcal     ;
     
    406409
    407410    // add the columns to the output array
    408     gfits_set_bintable_column (&theader, &ftable, "RA_OFF",     dR,        catalog->Nmeasure);
    409     gfits_set_bintable_column (&theader, &ftable, "DEC_OFF",    dD,        catalog->Nmeasure);
     411    gfits_set_bintable_column (&theader, &ftable, "RA",         R,         catalog->Nmeasure);
     412    gfits_set_bintable_column (&theader, &ftable, "DEC",        D,         catalog->Nmeasure);
    410413    gfits_set_bintable_column (&theader, &ftable, "MAG_SYS",    M,         catalog->Nmeasure);
    411414    gfits_set_bintable_column (&theader, &ftable, "MAG_CAL",    Mcal,      catalog->Nmeasure);
     
    425428    gfits_set_bintable_column (&theader, &ftable, "PHOTCODE",   photcode,  catalog->Nmeasure);
    426429
    427     free (dR      );
    428     free (dD      );
     430    free (R       );
     431    free (D       );
    429432    free (M       );
    430433    free (Mcal    );
     
    454457    gfits_create_table_header (&theader, "BINTABLE", "AVERAGE");
    455458
    456     gfits_define_bintable_column (&theader, "D", "RA",          "RA",                                                     "", 1.0, 0.0);
    457     gfits_define_bintable_column (&theader, "D", "DEC",         "DEC",                                                    "", 1.0, 0.0);
    458     gfits_define_bintable_column (&theader, "E", "RA_ERR",      "RA error",                                               "", 1.0, 0.0);
    459     gfits_define_bintable_column (&theader, "E", "DEC_ERR",     "DEC error",                                              "", 1.0, 0.0);
    460     gfits_define_bintable_column (&theader, "E", "U_RA",        "RA*cos(D) proper-motion",                                "", 1.0, 0.0);
    461     gfits_define_bintable_column (&theader, "E", "U_DEC",       "DEC proper-motion",                                      "", 1.0, 0.0);
    462     gfits_define_bintable_column (&theader, "E", "V_RA_ERR",    "RA*cos(D) p-m error",                                    "", 1.0, 0.0);
    463     gfits_define_bintable_column (&theader, "E", "V_DEC_ERR",   "DEC p-m error",                                          "", 1.0, 0.0);
    464     gfits_define_bintable_column (&theader, "E", "PAR",         "parallax",                                               "", 1.0, 0.0);
    465     gfits_define_bintable_column (&theader, "E", "PAR_ERR",     "parallax error",                                         "", 1.0, 0.0);
    466     gfits_define_bintable_column (&theader, "E", "CHISQ_POS",   "astrometry analysis chisq",                              "", 1.0, 0.0);
    467     gfits_define_bintable_column (&theader, "E", "CHISQ_PM",    "astrometry analysis chisq",                              "", 1.0, 0.0);
    468     gfits_define_bintable_column (&theader, "E", "CHISQ_PAP",   "astrometry analysis chisq",                              "", 1.0, 0.0);
    469     gfits_define_bintable_column (&theader, "J", "MEAN_EPOCH",  "mean epoch (PM-PAR ref)",                                "", 1.0, 1.0*0x8000);
    470     gfits_define_bintable_column (&theader, "J", "TIME_RANGE",  "mean epoch (PM-PAR ref)",                                "", 1.0, 1.0*0x8000);
    471     gfits_define_bintable_column (&theader, "E", "STARGAL_SEP", "star/galaxy separator",                                  "", 1.0, 0.0);   
    472     gfits_define_bintable_column (&theader, "I", "NUMBER_POS",  "number of detections used for astrometry",               "", 1.0, 1.0*0x80);
    473     gfits_define_bintable_column (&theader, "I", "NMEASURE",    "number of psf measurements",                             "", 1.0, 1.0*0x80);
    474     gfits_define_bintable_column (&theader, "I", "NMISSING",    "number of missings",                                     "", 1.0, 1.0*0x80);
    475     gfits_define_bintable_column (&theader, "I", "NEXTEND",     "number of extended measurements",                        "", 1.0, 1.0*0x80);
    476     gfits_define_bintable_column (&theader, "J", "OFF_MEASURE", "offset to first psf measurement",                        "", 1.0, 1.0*0x8000);
    477     gfits_define_bintable_column (&theader, "J", "OFF_MISSING", "offset to first missing obs",                            "", 1.0, 1.0*0x8000);
    478     gfits_define_bintable_column (&theader, "J", "OFF_EXTEND",  "offset to first extended measurement",                   "", 1.0, 1.0*0x8000);
    479     gfits_define_bintable_column (&theader, "J", "FLAGS",       "average object flags (star; ghost; etc)",                "", 1.0, 1.0*0x8000);
    480     gfits_define_bintable_column (&theader, "J", "PHOTFLAGS_U", "upper bit of 2 bit summary of per-measure photflags",    "", 1.0, 1.0*0x8000);
    481     gfits_define_bintable_column (&theader, "J", "PHOTFLAGS_L", "lower bit of 2 bit summary of per-measure photflags",    "", 1.0, 1.0*0x8000);
    482     gfits_define_bintable_column (&theader, "J", "OBJ_ID",      "unique ID for object in table",                          "", 1.0, 1.0*0x8000);
    483     gfits_define_bintable_column (&theader, "J", "CAT_ID",      "unique ID for table in which object was first realized", "", 1.0, 1.0*0x8000);
    484     gfits_define_bintable_column (&theader, "K", "EXT_ID",      "external ID for object (eg PSPS objID)",                 "", 1.0, 1.0*0x80000000);
     459    gfits_define_bintable_column (&theader, "D", "RA",             "RA",                                                  "", 1.0, 0.0);
     460    gfits_define_bintable_column (&theader, "D", "DEC",            "DEC",                                                 "", 1.0, 0.0);
     461    gfits_define_bintable_column (&theader, "E", "RA_ERR",         "RA error",                                            "", 1.0, 0.0);
     462    gfits_define_bintable_column (&theader, "E", "DEC_ERR",        "DEC error",                                           "", 1.0, 0.0);
     463    gfits_define_bintable_column (&theader, "E", "U_RA",           "RA*cos(D) proper-motion",                             "", 1.0, 0.0);
     464    gfits_define_bintable_column (&theader, "E", "U_DEC",          "DEC proper-motion",                                   "", 1.0, 0.0);
     465    gfits_define_bintable_column (&theader, "E", "V_RA_ERR",       "RA*cos(D) p-m error",                                 "", 1.0, 0.0);
     466    gfits_define_bintable_column (&theader, "E", "V_DEC_ERR",      "DEC p-m error",                                       "", 1.0, 0.0);
     467    gfits_define_bintable_column (&theader, "E", "PAR",            "parallax",                                            "", 1.0, 0.0);
     468    gfits_define_bintable_column (&theader, "E", "PAR_ERR",        "parallax error",                                      "", 1.0, 0.0);
     469    gfits_define_bintable_column (&theader, "E", "CHISQ_POS",      "astrometry analysis chisq",                           "", 1.0, 0.0);
     470    gfits_define_bintable_column (&theader, "E", "CHISQ_PM",       "astrometry analysis chisq",                           "", 1.0, 0.0);
     471    gfits_define_bintable_column (&theader, "E", "CHISQ_PAP",      "astrometry analysis chisq",                           "", 1.0, 0.0);
     472    gfits_define_bintable_column (&theader, "J", "MEAN_EPOCH",     "mean epoch (PM-PAR ref)",                             "", 1.0, 0.00);
     473    gfits_define_bintable_column (&theader, "J", "TIME_RANGE",     "mean epoch (PM-PAR ref)",                             "", 1.0, 0.00);
     474    gfits_define_bintable_column (&theader, "E", "STARGAL_SEP",    "star/galaxy separator",                               "", 1.0, 0.0);   
     475    gfits_define_bintable_column (&theader, "I", "NUMBER_POS",     "number of detections used for astrometry",            "", 1.0, 0.0);
     476    gfits_define_bintable_column (&theader, "I", "NMEASURE",       "number of psf measurements",                          "", 1.0, 0.0);
     477    gfits_define_bintable_column (&theader, "I", "NMISSING",       "number of missings",                                  "", 1.0, 0.0);
     478    gfits_define_bintable_column (&theader, "I", "NEXTEND",        "number of extended measurements",                     "", 1.0, 0.0);
     479    gfits_define_bintable_column (&theader, "J", "OFF_MEASURE",    "offset to first psf measurement",                     "", 1.0, 0.0);
     480    gfits_define_bintable_column (&theader, "J", "OFF_MISSING",    "offset to first missing obs",                         "", 1.0, 0.0);
     481    gfits_define_bintable_column (&theader, "E", "REF_COLOR_BLUE", "reference color",                                     "", 1.0, 0.0);
     482    gfits_define_bintable_column (&theader, "E", "REF_COLOR_RED",  "reference color",                                     "", 1.0, 0.0);
     483    gfits_define_bintable_column (&theader, "J", "FLAGS",          "average object flags (star; ghost; etc)",             "", 1.0, 0.0);
     484    gfits_define_bintable_column (&theader, "J", "PHOTFLAGS_U",    "upper bit of 2 bit summary of per-measure photflags", "", 1.0, 0.0);
     485    gfits_define_bintable_column (&theader, "J", "PHOTFLAGS_L",    "lower bit of 2 bit summary of per-measure photflags", "", 1.0, 0.0);
     486    gfits_define_bintable_column (&theader, "J", "OBJ_ID",         "unique ID for object in table",                       "", 1.0, 0.0);
     487    gfits_define_bintable_column (&theader, "J", "CAT_ID",         "unique ID for table in which object was first realized", "", 1.0, 0.0);
     488    gfits_define_bintable_column (&theader, "K", "EXT_ID",         "external ID for object (eg PSPS objID)",              "", 1.0, 0.0);
    485489
    486490    // generate the output array that carries the data
     
    510514    int      *measureOffset ; ALLOCATE (measureOffset , int     , catalog->Naverage);
    511515    int      *missingOffset ; ALLOCATE (missingOffset , int     , catalog->Naverage);
    512     int      *extendOffset  ; ALLOCATE (extendOffset  , int     , catalog->Naverage);
     516    float    *refColorBlue  ; ALLOCATE (refColorBlue  , float   , catalog->Naverage);
     517    float    *refColorRed   ; ALLOCATE (refColorRed   , float   , catalog->Naverage);
    513518    int      *flags         ; ALLOCATE (flags         , int     , catalog->Naverage);
    514519    int      *photFlagsUpper; ALLOCATE (photFlagsUpper, int     , catalog->Naverage);
     
    543548      measureOffset[i]   = average[i].measureOffset   ;
    544549      missingOffset[i]   = average[i].missingOffset   ;
    545       extendOffset[i]    = average[i].extendOffset    ; 
     550      refColorBlue[i]    = average[i].refColorBlue    ; 
     551      refColorRed[i]     = average[i].refColorRed     ; 
    546552      flags[i]           = average[i].flags           ;
    547553      photFlagsUpper[i]  = average[i].photFlagsUpper  ;
     
    553559
    554560    // add the columns to the output array
    555     gfits_set_bintable_column (&theader, &ftable, "RA",          R,               catalog->Naverage);
    556     gfits_set_bintable_column (&theader, &ftable, "DEC",         D,               catalog->Naverage);
    557     gfits_set_bintable_column (&theader, &ftable, "RA_ERR",      dR,              catalog->Naverage);
    558     gfits_set_bintable_column (&theader, &ftable, "DEC_ERR",     dD,              catalog->Naverage);
    559     gfits_set_bintable_column (&theader, &ftable, "U_RA",        uR,              catalog->Naverage);
    560     gfits_set_bintable_column (&theader, &ftable, "U_DEC",       uD,              catalog->Naverage);
    561     gfits_set_bintable_column (&theader, &ftable, "V_RA_ERR",    duR,             catalog->Naverage);
    562     gfits_set_bintable_column (&theader, &ftable, "V_DEC_ERR",   duD,             catalog->Naverage);
    563     gfits_set_bintable_column (&theader, &ftable, "PAR",         P,               catalog->Naverage);
    564     gfits_set_bintable_column (&theader, &ftable, "PAR_ERR",     dP,              catalog->Naverage);
    565     gfits_set_bintable_column (&theader, &ftable, "CHISQ_POS",   ChiSqAve,        catalog->Naverage);
    566     gfits_set_bintable_column (&theader, &ftable, "CHISQ_PM",    ChiSqPM,         catalog->Naverage);
    567     gfits_set_bintable_column (&theader, &ftable, "CHISQ_PAP",   ChiSqPar,        catalog->Naverage);
    568     gfits_set_bintable_column (&theader, &ftable, "MEAN_EPOCH",  Tmean,           catalog->Naverage);
    569     gfits_set_bintable_column (&theader, &ftable, "TIME_RANGE",  Trange,          catalog->Naverage);
    570     gfits_set_bintable_column (&theader, &ftable, "STARGAL_SEP", stargal,         catalog->Naverage);
    571     gfits_set_bintable_column (&theader, &ftable, "NUMBER_POS",  Npos,            catalog->Naverage);
    572     gfits_set_bintable_column (&theader, &ftable, "NMEASURE",    Nmeasure,        catalog->Naverage);
    573     gfits_set_bintable_column (&theader, &ftable, "NMISSING",    Nmissing,        catalog->Naverage);
    574     gfits_set_bintable_column (&theader, &ftable, "NEXTEND",     Nextend,         catalog->Naverage);
    575     gfits_set_bintable_column (&theader, &ftable, "OFF_MEASURE", measureOffset,   catalog->Naverage);
    576     gfits_set_bintable_column (&theader, &ftable, "OFF_MISSING", missingOffset,   catalog->Naverage);
    577     gfits_set_bintable_column (&theader, &ftable, "OFF_EXTEND",  extendOffset,    catalog->Naverage);
    578     gfits_set_bintable_column (&theader, &ftable, "FLAGS",       flags,           catalog->Naverage);
    579     gfits_set_bintable_column (&theader, &ftable, "PHOTFLAGS_U", photFlagsUpper,  catalog->Naverage);
    580     gfits_set_bintable_column (&theader, &ftable, "PHOTFLAGS_L", photFlagsLower,  catalog->Naverage);
    581     gfits_set_bintable_column (&theader, &ftable, "OBJ_ID",      objID,           catalog->Naverage);
    582     gfits_set_bintable_column (&theader, &ftable, "CAT_ID",      catID,           catalog->Naverage);
    583     gfits_set_bintable_column (&theader, &ftable, "EXT_ID",      extID,           catalog->Naverage);
     561    gfits_set_bintable_column (&theader, &ftable, "RA",             R,               catalog->Naverage);
     562    gfits_set_bintable_column (&theader, &ftable, "DEC",            D,               catalog->Naverage);
     563    gfits_set_bintable_column (&theader, &ftable, "RA_ERR",         dR,              catalog->Naverage);
     564    gfits_set_bintable_column (&theader, &ftable, "DEC_ERR",        dD,              catalog->Naverage);
     565    gfits_set_bintable_column (&theader, &ftable, "U_RA",           uR,              catalog->Naverage);
     566    gfits_set_bintable_column (&theader, &ftable, "U_DEC",          uD,              catalog->Naverage);
     567    gfits_set_bintable_column (&theader, &ftable, "V_RA_ERR",       duR,             catalog->Naverage);
     568    gfits_set_bintable_column (&theader, &ftable, "V_DEC_ERR",      duD,             catalog->Naverage);
     569    gfits_set_bintable_column (&theader, &ftable, "PAR",            P,               catalog->Naverage);
     570    gfits_set_bintable_column (&theader, &ftable, "PAR_ERR",        dP,              catalog->Naverage);
     571    gfits_set_bintable_column (&theader, &ftable, "CHISQ_POS",      ChiSqAve,        catalog->Naverage);
     572    gfits_set_bintable_column (&theader, &ftable, "CHISQ_PM",       ChiSqPM,         catalog->Naverage);
     573    gfits_set_bintable_column (&theader, &ftable, "CHISQ_PAP",      ChiSqPar,        catalog->Naverage);
     574    gfits_set_bintable_column (&theader, &ftable, "MEAN_EPOCH",     Tmean,           catalog->Naverage);
     575    gfits_set_bintable_column (&theader, &ftable, "TIME_RANGE",     Trange,          catalog->Naverage);
     576    gfits_set_bintable_column (&theader, &ftable, "STARGAL_SEP",    stargal,         catalog->Naverage);
     577    gfits_set_bintable_column (&theader, &ftable, "NUMBER_POS",     Npos,            catalog->Naverage);
     578    gfits_set_bintable_column (&theader, &ftable, "NMEASURE",       Nmeasure,        catalog->Naverage);
     579    gfits_set_bintable_column (&theader, &ftable, "NMISSING",       Nmissing,        catalog->Naverage);
     580    gfits_set_bintable_column (&theader, &ftable, "NEXTEND",        Nextend,         catalog->Naverage);
     581    gfits_set_bintable_column (&theader, &ftable, "OFF_MEASURE",    measureOffset,   catalog->Naverage);
     582    gfits_set_bintable_column (&theader, &ftable, "OFF_MISSING",    missingOffset,   catalog->Naverage);
     583    gfits_set_bintable_column (&theader, &ftable, "REF_COLOR_BLUE", refColorBlue,    catalog->Naverage);
     584    gfits_set_bintable_column (&theader, &ftable, "REF_COLOR_RED",  refColorRed,     catalog->Naverage);
     585    gfits_set_bintable_column (&theader, &ftable, "FLAGS",          flags,           catalog->Naverage);
     586    gfits_set_bintable_column (&theader, &ftable, "PHOTFLAGS_U",    photFlagsUpper,  catalog->Naverage);
     587    gfits_set_bintable_column (&theader, &ftable, "PHOTFLAGS_L",    photFlagsLower,  catalog->Naverage);
     588    gfits_set_bintable_column (&theader, &ftable, "OBJ_ID",         objID,           catalog->Naverage);
     589    gfits_set_bintable_column (&theader, &ftable, "CAT_ID",         catID,           catalog->Naverage);
     590    gfits_set_bintable_column (&theader, &ftable, "EXT_ID",         extID,           catalog->Naverage);
    584591
    585592    free (R);
     
    605612    free (measureOffset);
    606613    free (missingOffset);
    607     free (extendOffset);
     614    free (refColorBlue);
     615    free (refColorRed);
    608616    free (flags);
    609617    free (photFlagsUpper);
     
    629637    gfits_define_bintable_column (&theader, "I", "NCODE",    "magnitude (err)",           NULL,    1.0, 0.0);
    630638    gfits_define_bintable_column (&theader, "I", "NUSED",    "airmass",                   NULL,    1.0, 0.0);
    631     gfits_define_bintable_column (&theader, "I", "MAG_20",   "ccd x coord",              "pix",    1.0, 0.0);
    632     gfits_define_bintable_column (&theader, "I", "MAG_80",   "ccd y coord",              "pix",    1.0, 0.0);
     639    gfits_define_bintable_column (&theader, "E", "MAG_MIN",   "ccd x coord",              "pix",    1.0, 0.0);
     640    gfits_define_bintable_column (&theader, "E", "MAG_MAX",   "ccd y coord",              "pix",    1.0, 0.0);
    633641
    634642    // generate the output array that carries the data
     
    642650    float *M        ; ALLOCATE (M      ,  float, Nsec);
    643651    float *dM       ; ALLOCATE (dM     ,  float, Nsec);
    644     float *Xm       ; ALLOCATE (Xm    ,  float, Nsec);
     652    float *Mchisq   ; ALLOCATE (Mchisq ,  float, Nsec);
    645653    int   *flags    ; ALLOCATE (flags  ,  int,   Nsec);
    646654    short *Ncode    ; ALLOCATE (Ncode  ,  short, Nsec);
    647655    short *Nused    ; ALLOCATE (Nused  ,  short, Nsec);
    648     short *M_20     ; ALLOCATE (M_20   ,  short, Nsec);
    649     short *M_80     ; ALLOCATE (M_80   ,  short, Nsec);
     656    float *Mmin     ; ALLOCATE (Mmin   ,  float, Nsec);
     657    float *Mmax     ; ALLOCATE (Mmax   ,  float, Nsec);
    650658
    651659    // assign the storage arrays
    652660    SecFilt *secfilt = catalog->secfilt;
    653661    for (i = 0; i < Nsec; i++) {
    654       M     [i]       = secfilt[i]. M      ;
    655       dM    [i]       = secfilt[i]. dM     ;
    656       Xm    [i]       = secfilt[i]. Xm    ;
    657       flags [i]       = secfilt[i]. flags  ;
    658       Ncode [i]       = secfilt[i]. Ncode  ;
    659       Nused [i]       = secfilt[i]. Nused  ;
    660       M_20  [i]       = secfilt[i]. M_20   ;
    661       M_80  [i]       = secfilt[i]. M_80   ;
     662      M     [i]       = secfilt[i].M      ;
     663      dM    [i]       = secfilt[i].dM     ;
     664      Mchisq[i]       = secfilt[i].Mchisq ;
     665      flags [i]       = secfilt[i].flags  ;
     666      Ncode [i]       = secfilt[i].Ncode  ;
     667      Nused [i]       = secfilt[i].Nused  ;
     668      Mmin  [i]       = secfilt[i].Mmin   ;
     669      Mmax  [i]       = secfilt[i].Mmax   ;
    662670    }
    663671
    664672    // add the columns to the output array
    665     gfits_set_bintable_column (&theader, &ftable, "MAG",      M    , Nsec);
    666     gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",  dM   , Nsec);
    667     gfits_set_bintable_column (&theader, &ftable, "MAG_CHI",  Xm   , Nsec);
    668     gfits_set_bintable_column (&theader, &ftable, "FLAGS",    flags, Nsec);
    669     gfits_set_bintable_column (&theader, &ftable, "NCODE",    Ncode, Nsec);
    670     gfits_set_bintable_column (&theader, &ftable, "NUSED",    Nused, Nsec);
    671     gfits_set_bintable_column (&theader, &ftable, "MAG_20",   M_20 , Nsec);
    672     gfits_set_bintable_column (&theader, &ftable, "MAG_80",   M_80 , Nsec);
     673    gfits_set_bintable_column (&theader, &ftable, "MAG",      M     , Nsec);
     674    gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",  dM    , Nsec);
     675    gfits_set_bintable_column (&theader, &ftable, "MAG_CHI",  Mchisq, Nsec);
     676    gfits_set_bintable_column (&theader, &ftable, "FLAGS",    flags , Nsec);
     677    gfits_set_bintable_column (&theader, &ftable, "NCODE",    Ncode , Nsec);
     678    gfits_set_bintable_column (&theader, &ftable, "NUSED",    Nused , Nsec);
     679    gfits_set_bintable_column (&theader, &ftable, "MAG_MIN",  Mmin , Nsec);
     680    gfits_set_bintable_column (&theader, &ftable, "MAG_MAX",  Mmax , Nsec);
    673681
    674682    free (M      );
    675683    free (dM     );
    676     free (Xm    );
     684    free (Mchisq );
    677685    free (flags  );
    678686    free (Ncode  );
    679687    free (Nused  );
    680     free (M_20   );
    681     free (M_80   );
     688    free (Mmin   );
     689    free (Mmax   );
    682690
    683691    gfits_fwrite_Theader (f, &theader);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/ConfigInit.c

    r35105 r37067  
    1818  if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);
    1919
    20   GetConfig (config, "RELASTRO_SIGMA_LIM",         "%lf", 0, &SIGMA_LIM); // exclude measurements on this basis
    21   GetConfig (config, "RELASTRO_SRC_MEAS_TOOFEW",   "%d",  0, &SRC_MEAS_TOOFEW);
     20  // set defaults for all of these if they are not used by parallel / remote clients
     21  if (!ScanConfig (config, "RELASTRO_SIGMA_LIM",         "%lf", 0, &SIGMA_LIM))       SIGMA_LIM = 0.01;
     22  if (!ScanConfig (config, "RELASTRO_SRC_MEAS_TOOFEW",   "%d",  0, &SRC_MEAS_TOOFEW)) SRC_MEAS_TOOFEW = 3;
    2223
    2324  if (!ScanConfig (config, "RELASTRO_IMFIT_CLIP_NITER",    "%d",  0, &IMFIT_CLIP_NITER))    IMFIT_CLIP_NITER  = 3;
     
    2526  if (!ScanConfig (config, "RELASTRO_IMFIT_SYS_SIGMA_LIM", "%lf", 0, &IMFIT_SYS_SIGMA_LIM)) IMFIT_SYS_SIGMA_LIM = 0.01;
    2627
    27   GetConfig (config, "PM_DT_MIN",              "%lf", 0, &PM_DT_MIN);
    28   GetConfig (config, "PM_TOOFEW",              "%d",  0, &PM_TOOFEW);
    29   GetConfig (config, "POS_TOOFEW",             "%d",  0, &POS_TOOFEW);
     28  if (!ScanConfig (config, "PM_DT_MIN",              "%lf", 0, &PM_DT_MIN))        PM_DT_MIN = 0.25;   
     29  if (!ScanConfig (config, "PM_TOOFEW",              "%d",  0, &PM_TOOFEW))        PM_TOOFEW = 4;   
     30  if (!ScanConfig (config, "POS_TOOFEW",             "%d",  0, &POS_TOOFEW))       POS_TOOFEW = 1; 
     31  if (!ScanConfig (config, "PAR_FACTOR_MIN",         "%lf", 0, &PAR_FACTOR_MIN))   PAR_FACTOR_MIN = 0.2;
     32  if (!ScanConfig (config, "RELASTRO_MAP_NX",        "%d",  0, &NX_MAP))           NX_MAP = 5;
     33  if (!ScanConfig (config, "RELASTRO_MAP_NY",        "%d",  0, &NY_MAP))           NY_MAP = 5;
     34  if (!ScanConfig (config, "RELASTRO_DPOS_MAX",      "%lf", 0, &DPOS_MAX))         DPOS_MAX = 6.0;   
     35  if (!ScanConfig (config, "ADDSTAR_RADIUS",         "%lf", 0, &ADDSTAR_RADIUS))   ADDSTAR_RADIUS = 1.0;
    3036
    31   GetConfig (config, "PAR_FACTOR_MIN",         "%lf", 0, &PAR_FACTOR_MIN);
    32 
    33   GetConfig (config, "RELASTRO_MAP_NX",        "%d",  0, &NX_MAP);
    34   GetConfig (config, "RELASTRO_MAP_NY",        "%d",  0, &NY_MAP);
    35   GetConfig (config, "RELASTRO_DPOS_MAX",      "%lf", 0, &DPOS_MAX);
    36   GetConfig (config, "ADDSTAR_RADIUS",         "%lf", 0, &ADDSTAR_RADIUS);
    37 
    38   if (!ScanConfig (config, "USE_FIXED_PIXCOORDS", "%d", 0, &USE_FIXED_PIXCOORDS)) {
    39     USE_FIXED_PIXCOORDS = FALSE;
    40   }
     37  if (!ScanConfig (config, "USE_FIXED_PIXCOORDS", "%d", 0, &USE_FIXED_PIXCOORDS))  USE_FIXED_PIXCOORDS = FALSE;
    4138
    4239  // force CATDIR to be absolute (so parallel mode will work)
     
    5653  sprintf (ImageCat, "%s/Images.dat", CATDIR);
    5754
    58   if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
    59     SKY_DEPTH = 2;
    60   }
    61   if (!ScanConfig (config, "SKY_TABLE",         "%s",  0, SKY_TABLE)) {
    62     SKY_TABLE[0] = 0;
    63   }
     55  if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) SKY_DEPTH = 2;
     56  if (!ScanConfig (config, "SKY_TABLE",         "%s",  0, SKY_TABLE)) SKY_TABLE[0] = 0;
    6457
    6558  if (*CATMODE == 0) strcpy (CATMODE, "RAW");
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/FitChip.c

    r33652 r37067  
    44int FitChip (StarData *raw, StarData *ref, int Nmatch, Image *image) {
    55
    6   int i, NstatFull, Nstat, Niter;
     6  int i, NstatFull, Nstat, Niter, Nkeep;
    77  float dLsig, dMsig, dRsig;
    88  float dLsigFull, dMsigFull, dRsigFull;
     
    2424
    2525    // measure the scatter distribution (use only the bright end detections)
     26    Nkeep = 0;
    2627    for (i = 0; i < Nmatch; i++) {
    2728      if (raw[i].mask) continue;
     
    4243        continue;
    4344      }
    44     }
     45      Nkeep ++;
     46    }
     47
     48    // I'm rejecting some points from the fit above; I count the remainders and actually
     49    // use that count to set order_use below
    4550
    4651    // figures to assess the fitting process:
     
    5055    relastroVisualPlotChipFit(raw, ref, dRmax, Nmatch);
    5156
    52     // fit the requested order polynomial
    53     if (CHIPORDER > 0) {
    54       int Ndof_min = 3;
    55       int order_max = 0.5*(sqrt(4*Nmatch - 4*Ndof_min + 1) - 3);
    56       int order_use = MIN (CHIPORDER, order_max);
    57       if (order_use < 1) {
    58         if (VERBOSE2) fprintf (stderr, "insufficient measurements (%d) for linear fit\n", Nmatch);
    59         image[0].flags |= ID_IMAGE_ASTROM_FEW;
    60         return FALSE;
    61       }
    62       image[0].coords.Npolyterms = order_use;
    63     }
     57    // set the maximum order for the polynomial (based on number of stars kept above)
     58    int order_use = 0;
     59    if (Nkeep >  5) order_use = 1; // 4 stars per polynomial term (per dimension)
     60    if (Nkeep > 30) order_use = 2; // 5 stars per polynomial term (per dimension)
     61    if (Nkeep > 60) order_use = 3; // 6 stars per polynomial term (per dimension)
     62    if (order_use < 1) {
     63      if (VERBOSE2) fprintf (stderr, "insufficient measurements (%d) for linear fit\n", Nkeep);
     64      image[0].flags |= ID_IMAGE_ASTROM_FEW;
     65      return FALSE;
     66    }
     67    image[0].coords.Npolyterms = order_use;
    6468
    6569    if (fit) fit_free (fit);
     
    7175      fit_add (fit, raw[i].X, raw[i].Y, ref[i].L, ref[i].M, raw[i].dPos);
    7276    }
    73 
    74 # if (0)
    75     // check if the fit has enough data points for the polynomial order
    76     skip = FALSE;
    77     switch (image[0].coords.Npolyterms) {
    78       case 0:
    79       case 1:
    80         skip = (fit[0].Npts < 8);
    81         break;
    82       case 2:
    83         skip = (fit[0].Npts < 11);
    84         break;
    85       case 3:
    86         skip = (fit[0].Npts < 15);
    87         break;
    88       default:
    89         fprintf (stderr, "invalid chip order %d\n", image[0].coords.Npolyterms);
    90         skip = TRUE;
    91     }
    92     if (skip) {
    93       if (VERBOSE2) fprintf (stderr, "insufficient measurements (%d) for requested order (%d)\n", fit[0].Npts, image[0].coords.Npolyterms);
    94       fit_free (fit);
    95       image[0].flags |= ID_IMAGE_ASTROM_FEW;
    96       return FALSE;
    97     }
    98 # endif
    9977
    10078    // measure the fit, update the coords & object coordinates
     
    134112  }
    135113
     114  int Ncolor;
     115  float colorMedian;
     116  float *colorList = NULL;
     117  ALLOCATE (colorList, float, Nmatch);
     118
     119  // calculate the median blue color
     120  Ncolor = 0;
     121  for (i = 0; i < Nmatch; i++) {
     122    if (!raw[i].mask) continue;
     123    if (isnan(ref[i].ColorBlue)) continue;
     124    colorList[Ncolor] = ref[i].ColorBlue;
     125    Ncolor ++;
     126  }
     127  fsort (colorList, Ncolor);
     128  colorMedian = (Ncolor > 0) ? colorList[(int)(0.5*Ncolor)] : NAN;
     129  image[0].refColorBlue = colorMedian;
     130
     131  // calculate the median red color
     132  Ncolor = 0;
     133  for (i = 0; i < Nmatch; i++) {
     134    if (!raw[i].mask) continue;
     135    if (isnan(ref[i].ColorRed)) continue;
     136    colorList[Ncolor] = ref[i].ColorRed;
     137    Ncolor ++;
     138  }
     139  fsort (colorList, Ncolor);
     140  colorMedian = (Ncolor > 0) ? colorList[(int)(0.5*Ncolor)] : NAN;
     141  image[0].refColorRed = colorMedian;
     142
     143  free (colorList);
     144
    136145  GetScatterRawRef(&dLsigFull, &dMsigFull, &dRsigFull, &NstatFull, raw, ref, Nmatch, SIGMA_LIM);
    137146  GetScatterRawRef(&dLsig,     &dMsig,     &dRsig,     &Nstat,     raw, ref, Nmatch, IMFIT_SYS_SIGMA_LIM);
     
    151160  image[0].dYpixSys = dMsig;
    152161  image[0].nFitAstrom = fit[0].Npts;
     162
     163  // fprintf (stderr, "%s %6.3f %4d %4d\n", image[0].name, image[0].refColor, Ncolor, image[0].nFitAstrom);
    153164
    154165  if (fit) fit_free (fit);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/GetAstromError.c

    r33652 r37067  
    3030
    3131  code  = GetPhotcodebyCode (measure[0].photcode);
     32  if (!code) return NAN;
    3233
    3334  // do not raise an exception, just send back the result
     
    7273
    7374  code  = GetPhotcodebyCode (measure[0].photcode);
     75  if (!code) return NAN;
    7476
    7577  // do not raise an exception, just send back the result
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/ImageOps.c

    r35763 r37067  
    3939// N_onImage was 'Nlist'
    4040// N_ONIMAGE was 'NLIST'
     41
     42int areImagesLoaded () {
     43
     44  if (image) return TRUE;
     45  return FALSE;
     46}
     47
     48int areImagesMatched () {
     49
     50  if (MeasureToImage) return TRUE;
     51  return FALSE;
     52}
    4153
    4254Image *getimages (off_t *N, off_t **line_number) {
     
    226238    Measure *measureBig = &catalog[cat].measure[meas];
    227239    int TESTPT = FALSE;
    228     TESTPT |= (measureBig->imageID == CAT_ID_SRC) && (measureBig->detID == OBJ_ID_SRC);
    229     TESTPT |= (measureBig->imageID == CAT_ID_DST) && (measureBig->detID == OBJ_ID_DST);
     240    TESTPT |= CAT_ID_SRC && OBJ_ID_SRC && (measureBig->imageID == CAT_ID_SRC) && (measureBig->detID == OBJ_ID_SRC);
     241    TESTPT |= CAT_ID_DST && OBJ_ID_DST && (measureBig->imageID == CAT_ID_DST) && (measureBig->detID == OBJ_ID_DST);
    230242    if (TESTPT) {
    231243      fprintf (stderr, "got test det\n");
     
    333345*/
    334346
     347float getColorBlue (off_t meas, int cat) {
     348
     349  off_t i;
     350
     351  i = MeasureToImage[cat][meas];
     352  if (i == -1) return (NAN);
     353  return (image[i].refColorBlue);
     354}
     355
     356float getColorRed (off_t meas, int cat) {
     357
     358  off_t i;
     359
     360  i = MeasureToImage[cat][meas];
     361  if (i == -1) return (NAN);
     362  return (image[i].refColorRed);
     363}
     364
    335365void plot_images () {
    336366
     
    385415  for (j = 0; j < average[0].Nmeasure; j++) {
    386416    off = average[0].measureOffset + j;
    387     fprintf (stderr, "dR, dD, mag, dMag: %f, %f, %f, %f\n", measure[off].dR, measure[off].dD, measure[off].M, measure[off].dM);
     417    fprintf (stderr, "R, D, mag, dMag: %lf, %lf, %f, %f\n", measure[off].R, measure[off].D, measure[off].M, measure[off].dM);
    388418  }
    389419  return;
     
    462492    int TESTPT = FALSE;
    463493
    464     TESTPT |= (measure->imageID == CAT_ID_SRC) && (measure->detID == OBJ_ID_SRC);
    465     TESTPT |= (measure->imageID == CAT_ID_DST) && (measure->detID == OBJ_ID_DST);
     494    TESTPT |= CAT_ID_SRC && OBJ_ID_SRC && (measure->imageID == CAT_ID_SRC) && (measure->detID == OBJ_ID_SRC);
     495    TESTPT |= CAT_ID_DST && OBJ_ID_DST && (measure->imageID == CAT_ID_DST) && (measure->detID == OBJ_ID_DST);
    466496    if (TESTPT) {
    467497      fprintf (stderr, "got test det\n");
    468498    }
    469499
     500    X = measure[0].Xccd;
     501    Y = measure[0].Yccd;
    470502    if (USE_FIXED_PIXCOORDS) {
    471       X = isfinite(measure[0].Xfix) ? measure[0].Xfix : measure[0].Xccd;
    472       Y = isfinite(measure[0].Yfix) ? measure[0].Yfix : measure[0].Yccd;
    473     } else {
    474       X = measure[0].Xccd;
    475       Y = measure[0].Yccd;
     503      if (isfinite(measure[0].Xfix) && isfinite(measure[0].Yfix)) {
     504        float dX = measure[0].Xfix - measure[0].Xccd;
     505        float dY = measure[0].Yfix - measure[0].Yccd;
     506        if (hypot(dX,dY) < 2.0) {
     507          X = measure[0].Xfix;
     508          Y = measure[0].Yfix;
     509        }
     510      }
    476511    }
    477512    n = measure[0].averef;
     
    528563
    529564    // complain if the new location is far from the old location
    530     if (fabs(csdec*(measure[0].dR - dR)) > DPOS_MAX_ASEC) {
     565    if (fabs(csdec*(measure[0].R - R)) > DPOS_MAX_ASEC) {
    531566      NoffRAori ++;
    532567      if (VERBOSE2) {
    533         fprintf (stderr, "measurement moves far from original location (R): %f %f (%f %f %f %f)\n", average[0].R, average[0].D, measure[0].dR, dR, csdec*(measure[0].dR - dR), dD);
     568        fprintf (stderr, "measurement moves far from original location (R): %f %f (%f %f %f %f)\n", average[0].R, average[0].D, measure[0].R, dR, csdec*(measure[0].R - R), dD);
    534569        dump_measures (&average[0], catalog[c].measure);
    535570      }
    536571      // abort();
    537572    }
    538     if (fabs(measure[0].dD - dD) > DPOS_MAX_ASEC) {
     573    if (fabs(measure[0].D - D) > DPOS_MAX_ASEC) {
    539574      NoffDECori ++;
    540575      if (VERBOSE2) {
    541         fprintf (stderr, "measurement moves far from original location (D): %f %f (%f %f %f)\n", average[0].R, average[0].D, dR, measure[0].dD, dD);
     576        fprintf (stderr, "measurement moves far from original location (D): %f %f (%f %f %f)\n", average[0].R, average[0].D, dR, measure[0].D, dD);
    542577        dump_measures (&average[0], catalog[c].measure);
    543578      }      // abort();
    544579    }
    545580
    546     dPos += SQ(measure[0].dR - dR) + SQ(measure[0].dD - dD);
     581    // XXX NOTE : apply csdec:
     582    dPos += SQ(measure[0].R - R) + SQ(measure[0].D - D);
    547583    nPos ++;
    548584
    549     measure[0].dR = dR;
    550     measure[0].dD = dD;
    551     measureT[0].dR = dR;
    552     measureT[0].dD = dD;
     585    measure[0].R = R;
     586    measure[0].D = D;
     587    measureT[0].R = R;
     588    measureT[0].D = D;
    553589   
    554590    // set the systematic error for this image:
     
    560596
    561597  int Noff = NoffRAave + NoffDECave + NoffRAori + NoffDECori;
    562   if (VERBOSE && (Noff > 0)) fprintf (stderr, "Noff ave RA %d, Noff ave DEC %d, Noff ori RA %d, Noff ori DEC %d\n", NoffRAave, NoffDECave, NoffRAori, NoffDECori);
     598  if (VERBOSE2 && (Noff > 0)) fprintf (stderr, "Noff ave RA %d, Noff ave DEC %d, Noff ori RA %d, Noff ori DEC %d\n", NoffRAave, NoffDECave, NoffRAori, NoffDECori);
    563599  saveOffsets (dPos, nPos, im);
    564600
     
    575611
    576612  off_t i, m, c, n;
    577   double X, Y, L, M, P, Q, R, D, dR, dD;
     613  double X, Y, L, M, P, Q, R, D;
    578614
    579615  Mosaic *mosaic;
     
    609645    Measure *measure = &catalog[c].measure[m];
    610646
     647    X = measure[0].Xccd;
     648    Y = measure[0].Yccd;
    611649    if (USE_FIXED_PIXCOORDS) {
    612       X = isfinite(measure[0].Xfix) ? measure[0].Xfix : measure[0].Xccd;
    613       Y = isfinite(measure[0].Yfix) ? measure[0].Yfix : measure[0].Yccd;
    614     } else {
    615       X = measure[0].Xccd;
    616       Y = measure[0].Yccd;
     650      if (isfinite(measure[0].Xfix) && isfinite(measure[0].Yfix)) {
     651        float dX = measure[0].Xfix - measure[0].Xccd;
     652        float dY = measure[0].Yfix - measure[0].Yccd;
     653        if (hypot(dX,dY) < 2.0) {
     654          X = measure[0].Xfix;
     655          Y = measure[0].Yfix;
     656        }
     657      }
    617658    }
    618659    n = measure[0].averef;
    619660
    620     dR = dD = 0.0;
    621661    if (moscoords == NULL) {
    622662      // this is a Simple image (not a mosaic)
     
    629669      LM_to_RD (&R, &D, P, Q, moscoords);
    630670    }
    631 
    632     measure[0].dR = dR;
    633     measure[0].dD = dD;
    634 
    635     if (measure[0].dR > +180.0*3600.0) {
     671    measure[0].R = R;
     672    measure[0].D = D;
     673
     674    float dRoff = dvoOffsetR(measure, &catalog[c].average[n]);
     675
     676    if (dRoff > +180.0*3600.0) {
    636677      // average on high end of boundary, move star up
    637       R += 360.0;
    638       measure[0].dR = 3600.0*(catalog[c].average[n].R - R);
    639     }
    640     if (measure[0].dR < -180.0*3600.0) {
    641       // average on low end of boundary, move star down
    642       R -= 360.0;
    643       measure[0].dR = 3600.0*(catalog[c].average[n].R - R);
     678      measure[0].R += 360.0;
     679      dRoff -= 360.0*3600.0;
     680    }
     681    if (dRoff < -180.0*3600.0) {
     682      measure[0].R -= 360.0;
     683      dRoff += 360.0*3600.0;
    644684    }
    645685  }
     
    679719
    680720    /* apply the current image transformation or use the current value of R+dR, D+dD? */
     721    raw[i].X = measure[0].Xccd;
     722    raw[i].Y = measure[0].Yccd;
    681723    if (USE_FIXED_PIXCOORDS) {
    682       raw[i].X = isfinite(measure[0].Xfix) ? measure[0].Xfix : measure[0].Xccd;
    683       raw[i].Y = isfinite(measure[0].Yfix) ? measure[0].Yfix : measure[0].Yccd;
    684     } else {
    685       raw[i].X = measure[0].Xccd;
    686       raw[i].Y = measure[0].Yccd;
    687     }
    688 
     724      if (isfinite(measure[0].Xfix) && isfinite(measure[0].Yfix)) {
     725        float dX = measure[0].Xfix - measure[0].Xccd;
     726        float dY = measure[0].Yfix - measure[0].Yccd;
     727        if (hypot(dX,dY) < 2.0) {
     728          raw[i].X = measure[0].Xfix;
     729          raw[i].Y = measure[0].Yfix;
     730        }
     731      }
     732    }
    689733    raw[i].Mag  = measure[0].M;
    690734    raw[i].dMag = measure[0].dM;
     
    699743      raw[i].mask |= MARK_TOO_FEW_MEAS;
    700744    }
    701     if (!finite(measure[0].dR) || !finite(measure[0].dD)) {
     745    if (!finite(measure[0].R) || !finite(measure[0].D)) {
    702746      raw[i].mask |= MARK_NAN_POS_ERROR;
    703747    }
     
    738782  StarData *ref;
    739783
     784  int Nsecfilt = GetPhotcodeNsecfilt();
     785
    740786  mosaic = NULL;
    741787  moscoords = NULL;
     
    765811    ref[i].dMag = measure[0].dM;
    766812    ref[i].dPos = GetAstromErrorTiny (&measure[0], ERROR_MODE_POS);
     813
     814    if ((DCR_BLUE_NSEC_POS >= 0) && (DCR_BLUE_NSEC_NEG >= -1)) {
     815      ref[i].ColorBlue = catalog[c].secfilt[n*Nsecfilt + DCR_BLUE_NSEC_POS].M - catalog[c].secfilt[n*Nsecfilt + DCR_BLUE_NSEC_NEG].M;
     816    }
     817    if ((DCR_RED_NSEC_POS >= 0) && (DCR_RED_NSEC_NEG >= -1)) {
     818      ref[i].ColorRed = catalog[c].secfilt[n*Nsecfilt + DCR_RED_NSEC_POS].M - catalog[c].secfilt[n*Nsecfilt + DCR_RED_NSEC_NEG].M;
     819    }
    767820
    768821    ref[i].mask = FALSE;
     
    839892      // skip measurements based on user selected criteria
    840893      if (!MeasFilterTest(&measure[k], FALSE)) continue;
    841       R[N] = measure[k].dR;
    842       D[N] = measure[k].dD;
     894      R[N] = measure[k].R;
     895      D[N] = measure[k].D;
    843896      dR[N] = GetAstromError (&measure[k], ERROR_MODE_RA);
    844897      dD[N] = GetAstromError (&measure[k], ERROR_MODE_DEC);
     
    859912    N = 0;
    860913    for (k = 0; k < catalog[0].average[j].Nmeasure; k++) {
    861       //reset flag on each invocation
     914      // reset flag on each invocation
    862915      measure[k].dbFlags &= ~ID_MEAS_POOR_ASTROM;
    863916
     
    865918      if (!MeasFilterTest(&measure[k], FALSE)) continue;
    866919     
    867       x = measure[k].dR - statsR.median;
    868       y = measure[k].dD - statsD.median;
     920      x = measure[k].R - statsR.median;
     921      y = measure[k].D - statsD.median;
    869922      theta = atan2(y,x);
    870923      if ((x*x + y*y) > (SQR(statsR.sigma * Ns * cos(theta)) +
     
    898951  double *R, *D, *dR, *dD, *d2;
    899952  StatType statsR, statsD;
     953
     954  // XXX we are not going to use this for now
     955  return;
    900956
    901957  Nsecfilt = GetPhotcodeNsecfilt();
     
    937993      // skip measurements based on user selected criteria
    938994      if (!MeasFilterTest(&measure[k], FALSE)) continue;
    939       R[N] = measure[k].dR;
    940       D[N] = measure[k].dD;
     995      R[N] = measure[k].R;
     996      D[N] = measure[k].D;
    941997      dR[N] = GetAstromError(&measure[k], ERROR_MODE_RA);
    942998      dD[N] = GetAstromError(&measure[k], ERROR_MODE_DEC);
     
    9581014      // skip bad measurements
    9591015      if (!MeasFilterTest(&measure[k], FALSE)) continue; 
    960       x = measure[k].dR - statsR.median;
    961       y = measure[k].dD - statsD.median;
     1016      x = measure[k].R - statsR.median;
     1017      y = measure[k].D - statsD.median;
    9621018      theta = atan2(y,x);
    9631019      d2[N] = (x*x + y*y) / (SQR(statsR.sigma * Ns * cos(theta)) +
     
    9741030    for (k = 0;  k < N; k++) {
    9751031      off_t ind = (off_t) index[k];
    976       R[k] = measure[ind].dR;
    977       D[k] = measure[ind].dD;
     1032      R[k] = measure[ind].R;
     1033      D[k] = measure[ind].D;
    9781034      dR[k] = GetAstromError(&measure[ind], ERROR_MODE_RA);
    9791035      dD[k] = GetAstromError(&measure[ind], ERROR_MODE_DEC);
     
    9891045      //skip bad measurements
    9901046      if (!MeasFilterTest(&measure[k], FALSE)) continue; 
    991       x = measure[k].dR - statsR.median;
    992       y = measure[k].dD - statsD.median;
     1047      x = measure[k].R - statsR.median;
     1048      y = measure[k].D - statsD.median;
    9931049      theta = atan2(y,x);
    9941050      d2[N] = (x*x + y*y) / (SQR(statsR.sigma * Ns * cos(theta)) +
     
    10241080  float mag;
    10251081
    1026   if (!finite(measure[0].dR) || !finite(measure[0].dD)) return FALSE;
     1082  if (!finite(measure[0].R) || !finite(measure[0].D)) return FALSE;
    10271083  if (!finite(measure[0].M)) return FALSE; //XXX is this necessary for all relastro tasks?
    10281084  if (!finite(measure[0].dM)) return FALSE; //XXX is this necessary for all relastro tasks?
     
    10631119    } else {
    10641120      code = GetPhotcodebyCode (measure[0].photcode);
     1121      if (!code) return FALSE;
    10651122      mask = code[0].astromBadMask;
    10661123    }
     
    10751132  /* select measurements by mag limit */
    10761133  if (ImagSelect) {
    1077     mag = PhotInstTiny (measure);
     1134    mag = PhotInstTiny (measure, MAG_CLASS_PSF);
    10781135    if (mag < ImagMin || mag > ImagMax) return FALSE;
    10791136  }
     
    10901147  float mag;
    10911148
    1092   if (!finite(measure[0].dR) || !finite(measure[0].dD)) return FALSE;
     1149  if (!finite(measure[0].R) || !finite(measure[0].D)) return FALSE;
    10931150  if (!finite(measure[0].M)) return FALSE; //XXX is this necessary for all relastro tasks?
    10941151  if (!finite(measure[0].dM)) return FALSE; //XXX is this necessary for all relastro tasks?
     
    11291186    } else {
    11301187      code = GetPhotcodebyCode (measure[0].photcode);
     1188      if (!code) return FALSE;
    11311189      mask = code[0].astromBadMask;
    11321190    }
     
    11411199  /* select measurements by mag limit */
    11421200  if (ImagSelect) {
    1143     mag = PhotInst (measure);
     1201    mag = PhotInst (measure, MAG_CLASS_PSF);
    11441202    if (mag < ImagMin || mag > ImagMax) return FALSE;
    11451203  }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/MosaicOps.c

    r27581 r37067  
    1111
    1212// list of mosaic associated with each image 
    13 static off_t    Nmosaic_for_images; // number of images (for off_ternal checks)
     13static off_t    Nmosaic_for_images; // number of images (for internal checks)
    1414static off_t    *mosaic_for_images; // array of: image -> mosaic
    1515
     
    9797
    9898    /* a new mosaic, define ranges */
    99     mosaic[Nmosaic].start = start;
    100     mosaic[Nmosaic].stop  = stop;
    101     mosaic[Nmosaic].Mcal  = 0.0;
    102     mosaic[Nmosaic].dMcal = 0.0;
    103     mosaic[Nmosaic].Xm    = 0.0;
    104     mosaic[Nmosaic].flags  = image[i].flags;
    105     mosaic[Nmosaic].secz  = image[i].secz;
    106     mosaic[Nmosaic].coords = image[i].coords;
     99    mosaic[Nmosaic].start   = start;
     100    mosaic[Nmosaic].stop    = stop;
     101    mosaic[Nmosaic].Mcal    = 0.0;
     102    mosaic[Nmosaic].dMcal   = 0.0;
     103    mosaic[Nmosaic].Xm      = 0.0;
     104    mosaic[Nmosaic].flags   = image[i].flags;
     105    mosaic[Nmosaic].secz    = image[i].secz;
     106    mosaic[Nmosaic].coords  = image[i].coords;
     107    mosaic[Nmosaic].myImage = i;
    107108
    108109    // init the mosaic_own_images array data
     
    135136  ALLOCATE (mosaic_for_images, off_t, Nmosaic_for_images);
    136137
     138  // emit an error if we miss mosaics, but stop if we miss too many
     139  int NmissMosaic = 0;
     140  int NtestMosaic = 0;
     141
    137142  /* now assign the WRP images to these mosaics */
    138143  for (i = 0; i < Nimage; i++) {
     
    140145
    141146    if (strcmp(&image[i].coords.ctype[4], "-WRP")) continue;
     147    NtestMosaic ++;
    142148
    143149    /* set image time range */
     
    147153    Nmos = getMosaicByTimes (start, stop, startMos, stopMos, indexMos);
    148154    if (Nmos == -1) {
    149       fprintf (stderr, "cannot match mosaic for %s\n", image[i].name);
     155      if (NmissMosaic < 1000) {
     156        fprintf (stderr, "cannot match mosaic for %s\n", image[i].name);
     157      }
     158      NmissMosaic ++;
    150159      continue;
    151160    }
     
    164173  }
    165174
     175  fprintf (stderr, "mosaic matching : %d of possible %d failed to match\n", NmissMosaic, NtestMosaic);
     176  if (NmissMosaic > 0.5*NtestMosaic) {
     177    fprintf (stderr, "serious problem with mosaic matching\n");
     178    exit (5);
     179  }
     180
    166181  free (startMos);
    167182  free (stopMos);
     
    250265  if (im >= Nmosaic_for_images) abort();
    251266
    252   // search for the mosaic that
     267  // search for the mosaic that matches this image
    253268  mos = mosaic_for_images[im];
    254269  if (mos < 0) return NULL;
     
    256271  return &mosaic[mos];
    257272}
     273
     274// extend each host image table to include the mosaic 'images' needed by the host
     275int select_mosaics_hostregion (RegionHostTable *regionHosts, Image *image, off_t Nimage) {
     276
     277  int i;
     278  off_t j;
     279  char *mosaicUsed;
     280
     281  ALLOCATE (mosaicUsed, char, Nmosaic);
     282
     283  // we need to add the mosaics to each of the region hosts lists of images
     284  for (i = 0; i < regionHosts->Nhosts; i++) {
     285
     286    int Nadd = 0;
     287    int NADD = 100;
     288    off_t *addMosaic = NULL;
     289    ALLOCATE (addMosaic, off_t, NADD);
     290
     291    // reset the mosaicUsed flags (valid only for this host)
     292    memset (mosaicUsed, 0, Nmosaic * sizeof(char));
     293
     294    RegionHostInfo *host = &regionHosts->hosts[i];
     295
     296    // find the mosaics associated with a given
     297    for (j = 0; j < host->Nimage; j++) {
     298
     299      int im = host->imseq[j];
     300     
     301      if (im < 0) abort();
     302      if (im >= Nmosaic_for_images) abort();
     303
     304      // search for the mosaic that matches this image (skip unmatched images)
     305      off_t mos = mosaic_for_images[im];
     306      if (mos < 0) continue;
     307
     308      if (mosaicUsed[mos]) continue;
     309
     310      mosaicUsed[mos] = TRUE;
     311      addMosaic[Nadd] = mos;
     312      Nadd ++;
     313     
     314      CHECK_REALLOCATE (addMosaic, off_t, NADD, Nadd, 100);
     315    }
     316
     317    REALLOCATE (host->image, Image, host->Nimage + Nadd);
     318
     319    for (j = 0; j < Nadd; j++) {
     320      off_t mos = addMosaic[j];
     321      off_t mos_im = mosaic[mos].myImage;
     322
     323      host->image[host->Nimage + j] = image[mos_im];
     324    }
     325   
     326    host->Nimage += Nadd;
     327  }
     328  return TRUE;
     329}
     330
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/Shutdown.c

    r12332 r37067  
    2323  SetProtect (TRUE);
    2424  gfits_db_close (db);
    25   fprintf (stderr, "ERROR: addstar halted\n");
     25  fprintf (stderr, "ERROR: relastro halted\n");
    2626  exit (1);
    2727}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/StarMaps.c

    r35105 r37067  
    5959  off_t i, N, Nimages;
    6060  int xbin, ybin;
    61   struct timeval start, stop;
    6261
    63   gettimeofday (&start, (void *) NULL);
     62  INITTIME;
    6463
    6564  // Images *images = getimages(&Nimages, NULL); return value ignored
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/UpdateObjectOffsets.c

    r35763 r37067  
    126126              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, MIN_ERROR);
    127127
    128     char tmpline[1024];
    129     if (FIT_MODE == FIT_PM_ONLY)         { snprintf (tmpline, 1024, "%s -pm",    command);           strcpy (command, tmpline); }
    130     if (FIT_MODE == FIT_PAR_ONLY)        { snprintf (tmpline, 1024, "%s -par",   command);           strcpy (command, tmpline); }
    131     if (FIT_MODE == FIT_PM_AND_PAR)      { snprintf (tmpline, 1024, "%s -pmpar", command);           strcpy (command, tmpline); }
    132 
    133     if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",              command);                    strcpy (command, tmpline); }
    134     if (VERBOSE2)      { snprintf (tmpline, 1024, "%s -vv",             command);                    strcpy (command, tmpline); }
    135     if (RESET)         { snprintf (tmpline, 1024, "%s -reset",          command);                    strcpy (command, tmpline); }
    136     if (UPDATE)        { snprintf (tmpline, 1024, "%s -update",         command);                    strcpy (command, tmpline); }
    137 
    138     if (RESET_BAD_IMAGES) { snprintf (tmpline, 1024, "%s -reset-bad-images", command);               strcpy (command, tmpline); }
    139 
    140     if (ImagSelect)    { snprintf (tmpline, 1024, "%s -instmag %f %f",  command, ImagMin, ImagMax);  strcpy (command, tmpline); }
    141     if (MaxDensityUse) { snprintf (tmpline, 1024, "%s -max-density %f", command, MaxDensityValue);   strcpy (command, tmpline); }
     128    if (FIT_MODE == FIT_PM_ONLY)         strextend (command, "-pm");
     129    if (FIT_MODE == FIT_PAR_ONLY)        strextend (command, "-par");
     130    if (FIT_MODE == FIT_PM_AND_PAR)      strextend (command, "-pmpar");
     131
     132    if (VERBOSE)       strextend (command, "-v");
     133    if (VERBOSE2)      strextend (command, "-vv");
     134    if (RESET)         strextend (command, "-reset");
     135    if (UPDATE)        strextend (command, "-update");
     136
     137    if (RESET_BAD_IMAGES) strextend (command, "-reset-bad-images");
     138
     139    if (ImagSelect)    strextend (command, "-instmag %f %f", ImagMin, ImagMax);
     140    if (MaxDensityUse) strextend (command, "-max-density %f", MaxDensityValue);
    142141   
    143     if (USE_BASIC_CHECK) { snprintf (tmpline, 1024, "%s -basic-image-search", command);              strcpy (command, tmpline); }
    144     if (FlagOutlier)   { snprintf (tmpline, 1024, "%s -clip %d",        command, CLIP_THRESH);       strcpy (command, tmpline); }
     142    if (USE_BASIC_CHECK) strextend (command, "-basic-image-search");
     143    if (FlagOutlier)     strextend (command, "-clip %d", CLIP_THRESH);
     144    if (ExcludeBogus)    strextend (command, "-exclude-bogus %f", ExcludeBogusRadius);
    145145   
    146     if (USE_FIXED_PIXCOORDS) { snprintf (tmpline, 1024, "%s -D USE_FIXED_PIXCOORDS 1", command);     strcpy (command, tmpline); }
    147 
    148     if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, 1024, "%s +photcode %s", command, PHOTCODE_KEEP_LIST); strcpy (command, tmpline); }
    149     if (PHOTCODE_SKIP_LIST) { snprintf (tmpline, 1024, "%s -photcode %s", command, PHOTCODE_SKIP_LIST); strcpy (command, tmpline); }
    150     if (PhotFlagSelect)    { snprintf (tmpline, 1024, "%s +photflags",   command);                     strcpy (command, tmpline); }
    151     if (PhotFlagBad)       { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad);     strcpy (command, tmpline); }
    152     if (PhotFlagPoor)      { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor);   strcpy (command, tmpline); }
     146    if (USE_FIXED_PIXCOORDS) strextend (command, "-D USE_FIXED_PIXCOORDS 1");
     147
     148    if (PHOTCODE_KEEP_LIST) strextend (command, "+photcode %s", PHOTCODE_KEEP_LIST);
     149    if (PHOTCODE_SKIP_LIST) strextend (command, "-photcode %s", PHOTCODE_SKIP_LIST);
     150    if (PhotFlagSelect)     strextend (command, "+photflags");
     151    if (PhotFlagBad)        strextend (command, "+photflagbad %d", PhotFlagBad);
     152    if (PhotFlagPoor)       strextend (command, "+photflagpoor %d", PhotFlagPoor);
    153153    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
    154154
    155     if (MinBadQF > 0.0)    { snprintf (tmpline, 1024, "%s -min-bad-psfqf %f",        command, MinBadQF);      strcpy (command, tmpline); }
    156     if (MaxMeanOffset != 10.0) { snprintf (tmpline, 1024, "%s -max-mean-offset  %f", command, MaxMeanOffset); strcpy (command, tmpline); }
     155    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
     156      strextend (command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     157    }
     158    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
     159      strextend (command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
     160    }
     161
     162    if (MinBadQF > 0.0)        strextend (command, "-min-bad-psfqf %f", MinBadQF);
     163    if (MaxMeanOffset != 10.0) strextend (command, "-max-mean-offset  %f", MaxMeanOffset);
    157164
    158165    if (TimeSelect) {
    159166      char *tstart = ohana_sec_to_date (TSTART);
    160167      char *tstop  = ohana_sec_to_date (TSTOP);
    161       snprintf (tmpline, 1024, "%s -time %s %s", command, tstart, tstop);
     168      strextend (command, "-time %s %s", tstart, tstop);
    162169      free (tstart);
    163170      free (tstop);
    164       strcpy (command, tmpline);
    165171    }
    166172    fprintf (stderr, "command: %s\n", command);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/UpdateObjects.c

    r35763 r37067  
    11# include "relastro.h"
    22
    3 static off_t   Nmax;
     3static off_t Nmax;
    44static double *X, *dX;
    55static double *Y, *dY;
     
    1010static double *T;
    1111static double *dT;
     12static double *C_blue;
     13static double *C_red;
    1214
    1315void initObjectData (Catalog *catalog, int Ncatalog) {
     
    3638  ALLOCATE (pX, double, MAX (1, Nmax));
    3739  ALLOCATE (pY, double, MAX (1, Nmax));
     40
     41  ALLOCATE (C_blue, double, MAX (1, Nmax));
     42  ALLOCATE (C_red,  double, MAX (1, Nmax));
     43
     44
     45void freeObjectData () {
     46
     47  free (R);
     48  free (D);
     49  free (T);
     50  free (X);
     51  free (Y);
     52
     53  free (dR);
     54  free (dD);
     55  free (dT);
     56  free (dX);
     57  free (dY);
     58
     59  free (pX);
     60  free (pY);
     61
     62  free (C_blue);
     63  free (C_red);
    3864
    3965
     
    4369
    4470  off_t j, k, m;
    45   int i, N, Nsecfilt, mode, result, status, XVERB;
     71  int i, N, NcBlue, NcRed, Nsecfilt, mode, result, status, XVERB;
    4672  StatType statsR, statsD;
    4773  Coords coords;
     
    5783  memset (&fitPAR, 0, sizeof(fitPAR));
    5884  initObjectData (catalog, Ncatalog);
     85
     86  int setRefColor = areImagesMatched();
    5987
    6088  /* project coordinates to a plane centered on the object with units of arcsec */
     
    6795  coords.pc1_2  = coords.pc2_1 = 0.0;
    6896  coords.Npolyterms = 1;
    69   strcpy (coords.ctype, "RA---SIN");
     97  strcpy (coords.ctype, "DEC--SIN");
    7098
    7199  XVERB = FALSE;
     
    94122      fitPAR.chisq = NAN;
    95123
     124      // if we fail to fit the astrometry for some reason, we need to set/reset these
     125      catalog[i].average[j].flags |= ID_STAR_NO_ASTROM;
     126      catalog[i].average[j].ChiSqAve  = NAN;
     127      catalog[i].average[j].ChiSqPM   = NAN;
     128      catalog[i].average[j].ChiSqPar  = NAN;
     129      catalog[i].average[j].Npos = 0;
     130
    96131      if (catalog[i].average[j].Nmeasure == 0) {
    97           continue;
    98       }
    99 
     132        continue;
     133      }
     134
     135      NcBlue = 0;
     136      NcRed = 0;
    100137      N = 0;
    101138      m = catalog[i].average[j].measureOffset;
     
    116153          char *date = ohana_sec_to_date (measure[k].t);
    117154          int dbFlagsBig = measureBig ? measureBig[k].dbFlags : 0;
    118           fprintf (stderr, OFF_T_FMT" %f %f %s : 0x%08x : 0x%08x\n",  k, measure[k].dR, measure[k].dD, date, measure[k].dbFlags, dbFlagsBig);
     155          fprintf (stderr, OFF_T_FMT" %f %f %s : 0x%08x : 0x%08x\n",  k, measure[k].R, measure[k].D, date, measure[k].dbFlags, dbFlagsBig);
    119156          free (date);
    120157        }
     158
     159        // reset the bit to note that a detection was used (or not)
     160        measure[k].dbFlags &= ~ID_MEAS_USED_OBJ;
     161        if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; }
    121162
    122163        // does the measurement pass the supplied filtering constraints?
    123164        // MeasFilterTestTiny does not test psfQF
     165        // exclude bad detections based on: photcodes, psfQF, time range, photflags & astromBadMask, mag_inst
    124166        int keepMeasure = measureBig ? MeasFilterTest(&measureBig[k], FALSE) : MeasFilterTestTiny(&measure[k], FALSE);
    125167        if (!keepMeasure) {
    126           measure[k].dbFlags &= ~ID_MEAS_USED_OBJ;
    127           if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; }
    128168          continue;
    129169        }
    130170
     171        // mark (as POOR) any measurements which are deviant from the mean by > ExcludeBogusRadius
     172        if (ExcludeBogus) {
     173          double Ri = getMeanR (&measure[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
     174          double Di = getMeanD (&measure[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
     175          coords.crval1 = catalog[i].average[j].R;
     176          coords.crval2 = catalog[i].average[j].D;
     177          double Xi, Yi;
     178          RD_to_XY (&Xi, &Yi, Ri, Di, &coords);
     179          double radius = hypot(Xi, Yi);
     180          if (radius > ExcludeBogusRadius) {
     181              measure[k].dbFlags |= ID_MEAS_POOR_ASTROM;
     182              if (measureBig) { measureBig[k].dbFlags |= ID_MEAS_POOR_ASTROM; }
     183              continue;
     184          }
     185          measure[k].dbFlags &= ~ID_MEAS_POOR_ASTROM;
     186          if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_POOR_ASTROM; }
     187        }
     188
    131189        // outlier rejection
    132         if (FlagOutlier && (measure[k].dbFlags & ID_MEAS_POOR_ASTROM)) {
    133           measure[k].dbFlags &= ~ID_MEAS_USED_OBJ;
    134           if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; }
     190        if (FALSE && FlagOutlier && (measure[k].dbFlags & ID_MEAS_POOR_ASTROM)) {
    135191          continue;
    136192        }
    137 
    138         measure[k].dbFlags |= ID_MEAS_USED_OBJ;
    139         if (measureBig) { measureBig[k].dbFlags |= ID_MEAS_USED_OBJ; }
    140193
    141194        R[N] = getMeanR (&measure[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
     
    152205        // allow a given photcode or measurement to be
    153206        // ignored if the error is NAN (for photcode, set astromErrSys to NaN)
    154         if (isnan(dX[N])) {
    155           measure[k].dbFlags &= ~ID_MEAS_USED_OBJ;
    156           if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; }
    157           continue;
    158         }
    159         if (isnan(dY[N])) {
    160           measure[k].dbFlags &= ~ID_MEAS_USED_OBJ;
    161           if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; }
    162           continue;
    163         }
     207        if (isnan(dX[N])) continue;
     208        if (isnan(dY[N])) continue;
    164209
    165210        // add systematic error in quadrature, if desired
     
    183228        dD[N] = dY[N] / 3600.0;
    184229
     230        if (setRefColor) {
     231          float colorBlue = getColorBlue (m+k, i);
     232          if (!isnan(colorBlue)) {
     233            C_blue[NcBlue] = colorBlue;
     234            NcBlue++;
     235          }
     236          float colorRed = getColorRed (m+k, i);
     237          if (!isnan(colorRed)) {
     238            C_red[NcRed] = colorRed;
     239            NcRed++;
     240          }
     241        }
     242
     243        measure[k].dbFlags |= ID_MEAS_USED_OBJ;
     244        if (measureBig) { measureBig[k].dbFlags |= ID_MEAS_USED_OBJ; }
     245
    185246        N++;
    186       }
     247      } // loop over measurements : catalog[i].average[j].Nmeasure
    187248
    188249      // if we have too few good detections for the desired fit, or too limited a
    189250      // baseline, use a fit with fewer parameters.  XXX if we have too few measurements
    190251      // for even the average position, consider including the lower-quality detections?
    191 
    192       catalog[i].average[j].flags &= ~ID_STAR_NO_ASTROM;
    193252
    194253      // find Tmin & Tmax from the list of accepted measurements
     
    205264      if (((mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) && (N <= PM_TOOFEW)) mode = FIT_AVERAGE;
    206265
    207       if (FIT_TARGET == TARGET_HIGH_SPEED) {
     266      if (RELASTRO_OP == OP_HIGH_SPEED) {
    208267          Tmean = 0.5*(Tmax - Tmin);
    209268      } else {
     
    213272      // too few measurements for average position (require 2 values)
    214273      if (N < SRC_MEAS_TOOFEW) {
    215         // XXX need to define PHOTOM and ASTROM object flags
    216         // XXX reset the average value fields?
    217         catalog[i].average[j].flags |= ID_STAR_NO_ASTROM;
    218         catalog[i].average[j].ChiSqAve  = NAN;
    219         catalog[i].average[j].ChiSqPM   = NAN;
    220         catalog[i].average[j].ChiSqPar  = NAN;
    221274        if (N < 2) continue;
    222275      }
     
    250303        catalog[i].average[j].flags |= ID_STAR_FIT_PM;
    251304        Npm ++;
     305
     306        // XXX a hard-wired hack...
     307        if ((fabs(fitPM.uR) > 2.0) || (fabs(fitPM.uD) > 2.0)) {
     308          mode = FIT_AVERAGE;
     309          catalog[i].average[j].flags |= ID_STAR_BAD_PM;
     310        }
    252311      }
    253312
    254313      if (mode == FIT_PM_AND_PAR) {
    255         // fprintf (stderr, "parallax fitting is still untested (%s, %d)\n", __FILE__, __LINE__);
    256 
    257314        float pXmin = +2.0;
    258315        float pXmax = -2.0;
     
    278335          catalog[i].average[j].flags |= ID_STAR_FIT_PAR;
    279336          Npar ++;
     337
     338          // XXX a hard-wired hack...
     339          if ((fabs(fitPAR.uR) > 2.0) || (fabs(fitPAR.uD) > 2.0)) {
     340            mode = FIT_AVERAGE;
     341            catalog[i].average[j].flags |= ID_STAR_BAD_PM;
     342          }
    280343        } else {
    281344          // need to set mode = FIT_PM_ONLY if we do not fit for parallax
     
    303366        catalog[i].average[j].flags |= ID_STAR_FIT_AVE;
    304367        Nave ++;
     368      }
     369
     370      if (setRefColor) {
     371        float colorMedian;
     372        dsort (C_blue, NcBlue);
     373        colorMedian = (NcBlue > 0) ? C_blue[(int)(0.5*NcBlue)] : NAN;
     374        catalog[i].average[j].refColorBlue = colorMedian;
     375        dsort (C_red, NcRed);
     376        colorMedian = (NcRed > 0) ? C_red[(int)(0.5*NcRed)] : NAN;
     377        catalog[i].average[j].refColorRed = colorMedian;
    305378      }
    306379
     
    393466      catalog[i].average[j].Trange = (Trange * 86400 * 365.25);
    394467      catalog[i].average[j].Npos = fit.Nfit;
     468
     469      // unset the NO_ASTROM bit (not(NO_ASTROM) == HAVE_ASTROM)
     470      catalog[i].average[j].flags &= ~ID_STAR_NO_ASTROM;
     471
    395472      if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f) pm=(%f %f) chisq=(%f, %f, %f)\n",
    396473                          catalog[i].average[j].R,
     
    412489  }
    413490
     491  freeObjectData ();
     492
    414493  if (VERBOSE) fprintf (stderr, "fitted "OFF_T_FMT" objects ("OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par), skipped "OFF_T_FMT", "OFF_T_FMT" have too large an offset\n",  (NaveSum + NpmSum + NparSum),  NaveSum,  NpmSum,  NparSum,  NskipSum, NoffSum);
    415494  return (TRUE);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/args.c

    r35763 r37067  
    1313  /* possible operations */
    1414  FIT_TARGET = TARGET_NONE;
     15  RELASTRO_OP = OP_NONE;
    1516  FIT_MODE = FIT_AVERAGE;
    1617
     
    2122    if (N > argc - 6) usage_merge_source();
    2223    if (strcmp(argv[N+3], "into")) usage_merge_source();
    23     FIT_TARGET = TARGET_MERGE_SOURCE;
     24    RELASTRO_OP = OP_MERGE_SOURCE;
    2425    remove_argument (N, &argc, argv);
    2526    OBJ_ID_SRC = strtol(argv[N], &endptr, 0);
     
    4344  if ((N = get_argument (argc, argv, "-update-objects"))) {
    4445    remove_argument (N, &argc, argv);
    45     FIT_TARGET = TARGET_UPDATE_OBJECTS;
     46    RELASTRO_OP = OP_UPDATE_OBJECTS;
    4647  }
    4748
    4849  if ((N = get_argument (argc, argv, "-update-offsets"))) {
    4950    remove_argument (N, &argc, argv);
    50     FIT_TARGET = TARGET_UPDATE_OFFSETS;
     51    RELASTRO_OP = OP_UPDATE_OFFSETS;
     52  }
     53
     54  // elements needed for parallel regions / parallel images
     55  REGION_FILE = NULL;
     56  if ((N = get_argument (argc, argv, "-region-hosts"))) {
     57    remove_argument (N, &argc, argv);
     58    REGION_FILE = strcreate (argv[N]);
     59    remove_argument (N, &argc, argv);
     60  }
     61
     62  REGION_HOST_ID = 0;
     63  if ((N = get_argument (argc, argv, "-region-hostID"))) {
     64    remove_argument (N, &argc, argv);
     65    REGION_HOST_ID = atoi (argv[N]);
     66    remove_argument (N, &argc, argv);
     67  }
     68
     69  IMAGE_TABLE = NULL;
     70  if ((N = get_argument (argc, argv, "-parallel-images"))) {
     71    remove_argument (N, &argc, argv);
     72    RELASTRO_OP = OP_PARALLEL_IMAGES;
     73    if (N >= argc) usage();
     74    IMAGE_TABLE = strcreate (argv[N]);
     75    remove_argument (N, &argc, argv);
     76    if (!REGION_FILE) usage();
     77  }
     78
     79  if ((N = get_argument (argc, argv, "-images"))) {
     80    remove_argument (N, &argc, argv);
     81    RELASTRO_OP = OP_IMAGES;
     82  }
     83
     84  PARALLEL_REGIONS_MANUAL = FALSE;
     85  if ((N = get_argument (argc, argv, "-parallel-regions"))) {
     86    remove_argument (N, &argc, argv);
     87    RELASTRO_OP = OP_PARALLEL_REGIONS;
     88    if (!REGION_FILE) usage();
     89    if ((N = get_argument (argc, argv, "-parallel-regions-manual"))) {
     90      remove_argument (N, &argc, argv);
     91      PARALLEL_REGIONS_MANUAL = TRUE;
     92    }
    5193  }
    5294
     
    90132    // XXX include a parallax / no-parallax option
    91133    if (N >= argc - 4) usage();
    92     FIT_TARGET = TARGET_HIGH_SPEED;
     134    RELASTRO_OP = OP_HIGH_SPEED;
    93135    remove_argument (N, &argc, argv);
    94136    PHOTCODE_A_LIST = strcreate(argv[N]);
     
    104146  if ((N = get_argument (argc, argv, "-hpm"))) {
    105147    if (N >= argc - 2) usage();
    106     FIT_TARGET = TARGET_HPM;
     148    RELASTRO_OP = OP_HPM;
    107149    remove_argument (N, &argc, argv);
    108150    RADIUS = atof(argv[N]);
     
    116158    remove_argument (N, &argc, argv);
    117159    PARALLEL_OUTPUT = TRUE;
    118     if ((FIT_TARGET != TARGET_HIGH_SPEED) && (FIT_TARGET != TARGET_HPM)) {
     160    if ((RELASTRO_OP != OP_HIGH_SPEED) && (RELASTRO_OP != OP_HPM)) {
    119161      fprintf (stderr, "-parallel-output only valid for -high-speed or -hpm modes\n");
    120162      exit (1);
     
    137179  FlagOutlier = FALSE;
    138180  if ((N = get_argument (argc, argv, "-clip"))) {
     181    fprintf (stderr, "-clip is currently disabled\n");
    139182    remove_argument (N, &argc, argv);
    140183    CLIP_THRESH = atof (argv[N]);
     
    143186  }
    144187
    145   if (FIT_TARGET == TARGET_NONE) usage();
     188  ExcludeBogus = FALSE;
     189  ExcludeBogusRadius = 0.0;
     190  if ((N = get_argument (argc, argv, "-exclude-bogus"))) {
     191    remove_argument (N, &argc, argv);
     192    ExcludeBogusRadius = atof (argv[N]);
     193    remove_argument (N, &argc, argv);
     194    ExcludeBogus = TRUE;
     195  }
     196
     197  if (RELASTRO_OP == OP_NONE) usage();
     198
     199  if (((RELASTRO_OP == OP_IMAGES) || (RELASTRO_OP == OP_PARALLEL_REGIONS) || (RELASTRO_OP == OP_PARALLEL_IMAGES)) && (FIT_TARGET == TARGET_NONE)) usage();
    146200
    147201  /* specify portion of the sky : allow default of all sky? */
     
    240294  }
    241295
     296  // eg g - r or r - i
     297  DCR_BLUE_COLOR_POS = NULL;
     298  DCR_BLUE_COLOR_NEG = NULL;
     299  if ((N = get_argument (argc, argv, "-dcr-blue-color"))) {
     300    remove_argument (N, &argc, argv);
     301    DCR_BLUE_COLOR_POS = strcreate(argv[N]);
     302    remove_argument (N, &argc, argv);
     303    DCR_BLUE_COLOR_NEG = strcreate(argv[N]);
     304    remove_argument (N, &argc, argv);
     305  }
     306
     307  // eg, z - y or i - z
     308  DCR_RED_COLOR_POS = NULL;
     309  DCR_RED_COLOR_NEG = NULL;
     310  if ((N = get_argument (argc, argv, "-dcr-red-color"))) {
     311    remove_argument (N, &argc, argv);
     312    DCR_RED_COLOR_POS = strcreate(argv[N]);
     313    remove_argument (N, &argc, argv);
     314    DCR_RED_COLOR_NEG = strcreate(argv[N]);
     315    remove_argument (N, &argc, argv);
     316  }
     317
     318  PHOTCODE_RESET_LIST = NULL;
     319  if ((N = get_argument (argc, argv, "-reset-to-photcode"))) {
     320    remove_argument (N, &argc, argv);
     321    PHOTCODE_RESET_LIST = strcreate(argv[N]);
     322    remove_argument (N, &argc, argv);
     323  }
     324
    242325  PHOTCODE_KEEP_LIST = NULL;
    243326  if ((N = get_argument (argc, argv, "+photcode"))) {
     
    247330  }
    248331
    249   PHOTCODE_SKIP_LIST = strcreate("SCOS.103a.E,SCOS.4414.OG590,SCOS.4415.OG590,SCOS.IIIaF.OG590,SCOS.IIIaF.RG610,SCOS.IIIaF.RG630,SCOS.IIIaJ.GG385,SCOS.IIIaJ.GG395,SCOS.IVN.RG715,SCOS.IVN.RG9");
     332  char *SuperCOSMOS_SKIP = strcreate("SCOS.103a.E,SCOS.4414.OG590,SCOS.4415.OG590,SCOS.IIIaF.OG590,SCOS.IIIaF.RG610,SCOS.IIIaF.RG630,SCOS.IIIaJ.GG385,SCOS.IIIaJ.GG395,SCOS.IVN.RG715,SCOS.IVN.RG9");
     333
     334  PHOTCODE_SKIP_LIST = NULL;
    250335  if ((N = get_argument (argc, argv, "-photcode"))) {
    251336    remove_argument (N, &argc, argv);
    252     char *tmp1 = strcreate(argv[N]);
    253 
    254     int Ntotal = strlen(tmp1) + strlen(PHOTCODE_SKIP_LIST) + 5;
    255 
    256     char *tmp2 = NULL;
    257     ALLOCATE (tmp2, char, Ntotal);
    258     snprintf (tmp2, Ntotal, "%s,%s", PHOTCODE_SKIP_LIST, tmp1);
    259 
    260     free (tmp1);
    261     free (PHOTCODE_SKIP_LIST);
    262 
    263     PHOTCODE_SKIP_LIST = tmp2;
     337    char *RawSkip = strcreate(argv[N]);
     338
     339    char *GotSkip = strstr (RawSkip, SuperCOSMOS_SKIP);
     340    if (!GotSkip) {
     341      int Ntotal = strlen(RawSkip) + strlen(SuperCOSMOS_SKIP) + 5;
     342      ALLOCATE (PHOTCODE_SKIP_LIST, char, Ntotal);
     343      snprintf (PHOTCODE_SKIP_LIST, Ntotal, "%s,%s", SuperCOSMOS_SKIP, RawSkip);
     344      free (RawSkip);
     345      free (SuperCOSMOS_SKIP);
     346    } else {
     347      PHOTCODE_SKIP_LIST = RawSkip;
     348    }
    264349    remove_argument (N, &argc, argv);
    265350  }
     
    427512
    428513  /* possible operations */
    429   FIT_TARGET = TARGET_NONE;
     514  RELASTRO_OP = TARGET_NONE;
    430515  FIT_MODE = FIT_AVERAGE;
    431516
     
    437522  BCATALOG = NULL;
    438523
     524  REGION_FILE = NULL;
     525  REGION_HOST_ID = 0;
     526  IMAGE_TABLE = NULL;
     527  PARALLEL_REGIONS_MANUAL = FALSE;
     528
    439529  HOST_ID = 0;
    440530  if ((N = get_argument (argc, argv, "-hostID"))) {
     
    457547    BCATALOG = strcreate(argv[N]);
    458548    remove_argument (N, &argc, argv);
    459     FIT_TARGET = TARGET_LOAD_OBJECTS;
     549    RELASTRO_OP = OP_LOAD_OBJECTS;
    460550  }
    461551
    462552  if ((N = get_argument (argc, argv, "-update-objects"))) {
    463553    remove_argument (N, &argc, argv);
    464     FIT_TARGET = TARGET_UPDATE_OBJECTS;
     554    RELASTRO_OP = OP_UPDATE_OBJECTS;
    465555  }
    466556
    467557  if ((N = get_argument (argc, argv, "-update-offsets"))) {
    468558    remove_argument (N, &argc, argv);
    469     FIT_TARGET = TARGET_UPDATE_OFFSETS;
     559    RELASTRO_OP = OP_UPDATE_OFFSETS;
    470560  }
    471561
     
    487577    // XXX include a parallax / no-parallax option
    488578    if (N >= argc - 5) usage_client();
    489     FIT_TARGET = TARGET_HIGH_SPEED;
     579    RELASTRO_OP = OP_HIGH_SPEED;
    490580    remove_argument (N, &argc, argv);
    491581    PHOTCODE_A_LIST = strcreate(argv[N]);
     
    501591  if ((N = get_argument (argc, argv, "-hpm"))) {
    502592    if (N >= argc - 3) usage();
    503     FIT_TARGET = TARGET_HPM;
     593    RELASTRO_OP = OP_HPM;
    504594    remove_argument (N, &argc, argv);
    505595    RADIUS = atof(argv[N]);
     
    533623  FlagOutlier = FALSE;
    534624  if ((N = get_argument (argc, argv, "-clip"))) {
     625    fprintf (stderr, "-clip is currently disabled\n");
    535626    remove_argument (N, &argc, argv);
    536627    CLIP_THRESH = atof (argv[N]);
     
    539630  }
    540631
    541   if (FIT_TARGET == TARGET_NONE) usage_client();
     632  ExcludeBogus = FALSE;
     633  ExcludeBogusRadius = 0.0;
     634  if ((N = get_argument (argc, argv, "-exclude-bogus"))) {
     635    remove_argument (N, &argc, argv);
     636    ExcludeBogusRadius = atof (argv[N]);
     637    remove_argument (N, &argc, argv);
     638    ExcludeBogus = TRUE;
     639  }
     640
     641  if (RELASTRO_OP == OP_NONE) usage_client();
    542642
    543643  /* specify portion of the sky : allow default of all sky? */
     
    608708  }
    609709
     710  DCR_BLUE_COLOR_POS = NULL;
     711  DCR_BLUE_COLOR_NEG = NULL;
     712  if ((N = get_argument (argc, argv, "-dcr-blue-color"))) {
     713    remove_argument (N, &argc, argv);
     714    DCR_BLUE_COLOR_POS = strcreate(argv[N]);
     715    remove_argument (N, &argc, argv);
     716    DCR_BLUE_COLOR_NEG = strcreate(argv[N]);
     717    remove_argument (N, &argc, argv);
     718  }
     719  DCR_RED_COLOR_POS = NULL;
     720  DCR_RED_COLOR_NEG = NULL;
     721  if ((N = get_argument (argc, argv, "-dcr-red-color"))) {
     722    remove_argument (N, &argc, argv);
     723    DCR_RED_COLOR_POS = strcreate(argv[N]);
     724    remove_argument (N, &argc, argv);
     725    DCR_RED_COLOR_NEG = strcreate(argv[N]);
     726    remove_argument (N, &argc, argv);
     727  }
     728
     729  PHOTCODE_RESET_LIST = NULL;
     730  if ((N = get_argument (argc, argv, "-reset-to-photcode"))) {
     731    remove_argument (N, &argc, argv);
     732    PHOTCODE_RESET_LIST = strcreate(argv[N]);
     733    remove_argument (N, &argc, argv);
     734  }
     735
    610736  PHOTCODE_KEEP_LIST = NULL;
    611737  if ((N = get_argument (argc, argv, "+photcode"))) {
     
    718844
    719845void usage () {
    720   fprintf (stderr, "ERROR: USAGE: relastro -update-simple [options]\n");
    721   fprintf (stderr, "       OR:    relastro -update-chips [options]\n");
    722   fprintf (stderr, "       OR:    relastro -update-mosaic [options]\n");
     846  fprintf (stderr, "ERROR: USAGE: relastro -images -update-simple [options]\n");
     847  fprintf (stderr, "       OR:    relastro -images -update-chips [options]\n");
     848  fprintf (stderr, "       OR:    relastro -images -update-mosaic [options]\n");
     849  fprintf (stderr, "       OR:    relastro -parallel-regions -update-simple [options]\n");
     850  fprintf (stderr, "       OR:    relastro -parallel-regions -update-chips [options]\n");
     851  fprintf (stderr, "       OR:    relastro -parallel-regions -update-mosaic [options]\n");
     852  fprintf (stderr, "       OR:    relastro -parallel-images -update-simple [options]\n");
     853  fprintf (stderr, "       OR:    relastro -parallel-images -update-chips [options]\n");
     854  fprintf (stderr, "       OR:    relastro -parallel-images -update-mosaic [options]\n");
    723855  fprintf (stderr, "       OR:    relastro -update-objects [options]\n");
    724856  fprintf (stderr, "       OR:    relastro -high-speed [options]\n");
     
    806938  exit (2);
    807939}
     940
     941int strextend (char *input, char *format,...) {
     942
     943  char tmpextra[1024], tmpline[1024];
     944  va_list argp;
     945
     946  va_start (argp, format);
     947  vsnprintf (tmpextra, 1024, format, argp);
     948  snprintf (tmpline, 1024, "%s %s", input, tmpextra);
     949  strcpy (input, tmpline);
     950
     951  return TRUE;
     952}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/bcatalog.c

    r34429 r37067  
    11# include "relastro.h"
    22
     3static int Nkeep1 = 0;
     4static int Nkeep2 = 0;
    35static int Nskip1 = 0;
    46static int Nskip2 = 0;
    5 static unsigned int Tref = 1323353985;
    6 static short Cref = 10355;
     7
     8FILE *fbogus = NULL;
     9static int NskipBogus = 0;
     10
     11// test image: 2013/06/15,13:25:51, GPC1.r.XY50
     12static int CHECK_TEST_IMAGE = FALSE;
     13// static unsigned int Tref = 1378812312;
     14// static short Cref = 10001;
     15
     16static unsigned int Tref = 1379570672;
     17static short Cref = 10341;
     18
     19int LimitDensityCatalog_ByNmeasureGrid (Catalog *subcatalog, Catalog *oldcatalog);
    720
    821int bcatalog (Catalog *subcatalog, Catalog *catalog) {
     
    1124  off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm;
    1225  int Nsecfilt;
     26  Coords coords;
     27
     28  /* for outlier rejection, project coordinates to a plane centered on the object with units of arcsec */
     29  coords.crval1 = 0;
     30  coords.crval2 = 0;
     31  coords.crpix1 = 0;
     32  coords.crpix2 = 0;
     33  coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
     34  coords.pc1_1  = coords.pc2_2 = 1.0;
     35  coords.pc1_2  = coords.pc2_1 = 0.0;
     36  coords.Npolyterms = 1;
     37  strcpy (coords.ctype, "DEC--SIN");
    1338
    1439  // XXX in the future, use catalog[0].Nsecfilt only?  allow catalogs to have variable Nsecfilt?
     
    3459    ID_STAR_NO_ASTROM ;
    3560
     61  if (VERBOSE2 && ExcludeBogus && (fbogus == NULL)) {
     62    char name[1024];
     63    snprintf (name, 1024, "%s/bogus.%02d.dat", CATDIR, HOST_ID);
     64    fbogus = fopen (name, "w");
     65    if (!fbogus) {
     66      fprintf (stderr, "trouble opening bogus detection dump : %s\n", name);
     67    }
     68  }
     69
    3670  /* exclude stars not in range or with too few measurements */
    3771  for (i = 0; i < catalog[0].Naverage; i++) {
     
    6094      if (!MeasFilterTest(&catalog[0].measure[offset], TRUE)) {
    6195        catalog[0].measure[offset].dbFlags &= ~ID_MEAS_USED_CHIP;
    62         if (FALSE && (abs(catalog[0].measure[offset].t - Tref) < 10) && (catalog[0].measure[offset].photcode == Cref)) {
     96        if (CHECK_TEST_IMAGE && (abs(catalog[0].measure[offset].t - Tref) < 10) && (catalog[0].measure[offset].photcode == Cref)) {
    6397          Nskip1 ++;
    6498        }
    6599        continue;
    66100      }
    67 
    68       // filter out outliers
    69       if (FlagOutlier && (catalog[0].measure[offset].dbFlags & ID_MEAS_POOR_ASTROM)) {
     101      if (CHECK_TEST_IMAGE && (abs(catalog[0].measure[offset].t - Tref) < 10) && (catalog[0].measure[offset].photcode == Cref)) {
     102        Nkeep1 ++;
     103      }
     104
     105      // filter out outliers - these are detections inconsistent with the offset distribution
     106      // XXX disable this for now
     107      if (FALSE && FlagOutlier && (catalog[0].measure[offset].dbFlags & ID_MEAS_POOR_ASTROM)) {
    70108        catalog[0].measure[offset].dbFlags &= ~ID_MEAS_USED_CHIP;
    71109        if (FALSE && (abs(catalog[0].measure[offset].t - Tref) < 10) && (catalog[0].measure[offset].photcode == Cref)) {
     
    76114      catalog[0].measure[offset].dbFlags |= ID_MEAS_USED_CHIP;
    77115
     116      // exclude bogus
     117      if (ExcludeBogus) {
     118          double Ri = getMeanR_Big (&catalog[0].measure[offset], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt]);
     119          double Di = getMeanD_Big (&catalog[0].measure[offset], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt]);
     120          coords.crval1 = catalog[0].average[i].R;
     121          coords.crval2 = catalog[0].average[i].D;
     122          double Xi, Yi;
     123          RD_to_XY (&Xi, &Yi, Ri, Di, &coords);
     124          double radius = hypot(Xi, Yi);
     125          if (radius > ExcludeBogusRadius) {
     126              NskipBogus ++;
     127              if (VERBOSE2) {
     128                FILE *foutput = fbogus ? fbogus : stderr;
     129                char *date = ohana_sec_to_date(catalog[0].measure[offset].t);
     130                fprintf (foutput, "exclude bogus: %10.6f %10.6f : %10.6f %10.6f : %6.2f %6.2f : %6.2f : %5d %s\n", catalog[0].average[i].R, catalog[0].average[i].D, Ri, Di, Xi, Yi, radius, catalog[0].measure[offset].photcode, date);
     131                free (date);
     132              }
     133              continue;
     134          }
     135      }
     136
    78137      // re-assess on each run of relastro if a measurement should be used
    79138
     
    87146      // but before the final average properties are calculated, these measurements may be
    88147      // allowed.
     148
     149      if (CHECK_TEST_IMAGE && (abs(catalog[0].measure[offset].t - Tref) < 10) && (catalog[0].measure[offset].photcode == Cref)) {
     150        Nkeep2 ++;
     151      }
    89152
    90153      CopyMeasureToTiny (&subcatalog[0].measureT[Nmeasure], &catalog[0].measure[offset]);
     
    125188  // limit the total number of stars in the catalog
    126189  if (MaxDensityUse) {
    127     LimitDensityCatalog_ByNmeasure (subcatalog, catalog);
     190    LimitDensityCatalog_ByNmeasureGrid (subcatalog, catalog);
    128191  } else {
    129192    if (VERBOSE2) {
     
    134197    }
    135198  }
     199  if (CHECK_TEST_IMAGE && (Nkeep1 + Nkeep2 + Nskip1 + Nskip2 > 0)) {
     200    fprintf (stderr, "kept %d %d, skipped %d %d\n", Nkeep1, Nkeep2, Nskip1, Nskip2);
     201  }
     202
    136203  return (TRUE);
    137204}
    138205
    139206void bcatalog_show_skips () {
    140   fprintf (stderr, "Nskip: %d, %d\n", Nskip1, Nskip2);
     207  if (ExcludeBogus) {
     208    if (fbogus) fclose (fbogus);
     209    fprintf (stderr, "NskipBogus: %d\n", NskipBogus);
     210    // fprintf (stderr, "Nskip: %d, %d\n", Nskip1, Nskip2);
     211    // fprintf (stderr, "Nkeep: %d, %d\n", Nkeep1, Nkeep2);
     212  }
    141213}
    142214
     
    155227# undef COMPARE
    156228
     229}
     230
     231/* generate a grid in a locally-projected coordinate system, try to select average entries
     232   from each grid cell in decending Nmeasure order.
     233 */
     234int LimitDensityCatalog_ByNmeasureGrid (Catalog *subcatalog, Catalog *oldcatalog) {
     235
     236  off_t i, j;
     237  int ix, iy;
     238
     239  Catalog tmpcatalog;
     240
     241  double Rmin, Rmax, Dmin, Dmax;
     242
     243  int Nsecfilt = GetPhotcodeNsecfilt ();
     244
     245  gfits_scan (&oldcatalog[0].header, "RA0",  "%lf", 1, &Rmin);
     246  gfits_scan (&oldcatalog[0].header, "DEC0", "%lf", 1, &Dmin);
     247  gfits_scan (&oldcatalog[0].header, "RA1",  "%lf", 1, &Rmax);
     248  gfits_scan (&oldcatalog[0].header, "DEC1", "%lf", 1, &Dmax);
     249
     250  if (VERBOSE2) fprintf (stderr, "extracting from catalog covering region %f,%f to %f,%f\n", Rmin, Dmin, Rmax, Dmax);
     251
     252  float AREA = fabs(Dmax - Dmin) * fabs(Rmax - Rmin) * cos (0.5*RAD_DEG*(Dmax + Dmin));
     253  assert (AREA > 0);
     254
     255  off_t Nmax = MaxDensityValue * AREA;
     256  if (subcatalog[0].Naverage <= Nmax) {
     257    if (VERBOSE) {
     258      fprintf (stderr, "subcatalog has less than the max density\n");
     259    }
     260    return (TRUE);
     261  }
     262
     263  off_t Naverage = subcatalog[0].Naverage;
     264
     265  // generate a grid in locally projected space
     266  double Rc = 0.5*(Rmin + Rmax);
     267  double Dc = 0.5*(Dmin + Dmax);
     268
     269  /* project coordinates to a plane centered on the object with units of arcsec */
     270  Coords coords;
     271  coords.crval1 = Rc;
     272  coords.crval2 = Dc;
     273  coords.crpix1 = 0;
     274  coords.crpix2 = 0;
     275  coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
     276  coords.pc1_1  = coords.pc2_2 = 1.0;
     277  coords.pc1_2  = coords.pc2_1 = 0.0;
     278  coords.Npolyterms = 1;
     279  strcpy (coords.ctype, "DEC--SIN");
     280
     281  // convert all average R,D values to X,Y:
     282  double *X, *Y;
     283  ALLOCATE (X, double, Naverage);
     284  ALLOCATE (Y, double, Naverage);
     285  float Xmin = +10000.0, Ymin = +10000.0;
     286  float Xmax = -10000.0, Ymax = -10000.0;
     287  for (i = 0; i < Naverage; i++) {
     288    X[i] = NAN;
     289    Y[i] = NAN;
     290    // skip any stars which are outside of nominal catalog range
     291    if (subcatalog[0].average[i].R < Rmin) continue;
     292    if (subcatalog[0].average[i].R > Rmax) continue;
     293    if (subcatalog[0].average[i].D < Dmin) continue;
     294    if (subcatalog[0].average[i].D > Dmax) continue;
     295    RD_to_XY (&X[i], &Y[i], subcatalog[0].average[i].R, subcatalog[0].average[i].D, &coords);
     296    Xmin = MIN (Xmin, X[i]);
     297    Xmax = MAX (Xmax, X[i]);
     298    Ymin = MIN (Ymin, Y[i]);
     299    Ymax = MAX (Ymax, Y[i]);
     300  }
     301
     302  // how many grid cells? what is the grid spacing?
     303  float dX = Xmax - Xmin;
     304  float dY = Ymax - Ymin;
     305
     306  // *** XXX for the moment, I'm using a hard-wired cell size (200 arcsec ~ 3.3 arcmin)
     307  int NX = (int)(dX / 200) + 1;
     308  int NY = (int)(dY / 200) + 1;
     309  // fprintf (stderr, "Density Grid: %d x %d\n", NX, NY);
     310  // XXX check that NX,NY are sensible (5 degrees / 200 arcsec seems like the absolute max)
     311  if (NX > 1000) {
     312    fprintf (stderr, "serious problem with %s: NX = %d\n", subcatalog[0].filename, NX);
     313    exit (3);
     314  }
     315  if (NY > 1000) {
     316    fprintf (stderr, "serious problem with %s: NY = %d\n", subcatalog[0].filename, NY);
     317    exit (3);
     318  }
     319 
     320  // kind of ugly : generate a grid of index, Nmeasure arrays
     321  // to be filled below (I also need NN and Nn to track the number of
     322  // entries in each).
     323  int    **NN_grid;
     324  int    **Nn_grid;
     325  int   ***Nm_grid;
     326  off_t ***idxgrid;
     327  ALLOCATE (NN_grid, int *, NX);
     328  ALLOCATE (Nn_grid, int *, NX);
     329  ALLOCATE (Nm_grid, int **, NX);
     330  ALLOCATE (idxgrid, off_t **, NX);
     331
     332  for (ix = 0; ix < NX; ix++) {
     333    ALLOCATE (NN_grid[ix], int, NY);
     334    ALLOCATE (Nn_grid[ix], int, NY);
     335    ALLOCATE (Nm_grid[ix], int *, NY);
     336    ALLOCATE (idxgrid[ix], off_t *, NY);
     337    for (iy = 0; iy < NY; iy++) {
     338      Nn_grid[ix][iy] = 0;
     339      NN_grid[ix][iy] = 100;
     340      ALLOCATE (Nm_grid[ix][iy], int,   NN_grid[ix][iy]);
     341      ALLOCATE (idxgrid[ix][iy], off_t, NN_grid[ix][iy]);
     342    }
     343  }
     344
     345  // assign all of the average entries to a grid cell
     346  for (i = 0; i < Naverage; i++) {
     347    if (isnan(X[i])) continue;
     348    if (isnan(Y[i])) continue;
     349    ix = (X[i] - Xmin) / 200.0;
     350    iy = (Y[i] - Ymin) / 200.0;
     351    int Nn = Nn_grid[ix][iy];
     352    Nm_grid[ix][iy][Nn] = subcatalog[0].average[i].Nmeasure;
     353   
     354    // if we are resetting to a given photcode, we need to have that photcode...
     355    if (NphotcodesReset) {
     356      int k;
     357      int foundReset = FALSE;
     358      int m = subcatalog[0].average[i].measureOffset;
     359      MeasureTiny *measure = &subcatalog[0].measureT[m];
     360      for (j = 0; (j < subcatalog[0].average[i].Nmeasure) && !foundReset; j++) {
     361        if (CHECK_TEST_IMAGE && (abs(measure[j].t - Tref) < 10) && (measure[j].photcode == Cref)) {
     362          fprintf (stderr, ".");
     363        }
     364        for (k = 0; (k < NphotcodesReset) && !foundReset; k++) {
     365          if (photcodesReset[k][0].code == measure[j].photcode) foundReset = TRUE;
     366        }
     367      }
     368      if (!foundReset) {
     369        Nm_grid[ix][iy][Nn] = 0;
     370      }
     371    }
     372
     373    idxgrid[ix][iy][Nn] = i;
     374    Nn_grid[ix][iy] ++;
     375    if (Nn_grid[ix][iy] >= NN_grid[ix][iy]) {
     376      NN_grid[ix][iy] += 100;
     377      REALLOCATE (Nm_grid[ix][iy], int,   NN_grid[ix][iy]);
     378      REALLOCATE (idxgrid[ix][iy], off_t, NN_grid[ix][iy]);
     379    }
     380  }
     381   
     382  // sort all of the grid cells
     383  for (ix = 0; ix < NX; ix++) {
     384    for (iy = 0; iy < NY; iy++) {
     385      sort_by_Nmeasure (Nm_grid[ix][iy], idxgrid[ix][iy], Nn_grid[ix][iy]);
     386      NN_grid[ix][iy] = 0; // I'm going to use this array to track which element I've already selected
     387    }
     388  }
     389
     390  // cycle over the grid until we ready Nmax
     391  off_t *keepidx = NULL;
     392  ALLOCATE (keepidx, off_t, Naverage);
     393  memset (keepidx, 0, Naverage*sizeof(off_t));
     394  int Nkeep = 0;
     395
     396  for (i = 0; (i < 20) && (Nkeep < Nmax); i++) {
     397    for (ix = 0; (ix < NX) && (Nkeep < Nmax); ix++) {
     398      for (iy = 0; (iy < NY) && (Nkeep < Nmax); iy++) {
     399        if (NN_grid[ix][iy] >= Nn_grid[ix][iy]) continue; // all used up!
     400        int Nn = NN_grid[ix][iy];
     401        keepidx[Nkeep] = idxgrid[ix][iy][Nn];
     402        Nkeep ++;
     403        NN_grid[ix][iy] ++;
     404      }
     405    }
     406  }
     407
     408  // count the number of measurements this selection will yield
     409  off_t ave, NMEASURE = 0;
     410  for (i = 0; i < Nkeep; i++) {
     411    ave = keepidx[i];
     412    NMEASURE += subcatalog[0].average[ave].Nmeasure;
     413  }
     414
     415  // test catID : 37262 37261 37257 37258
     416  int dumpit = FALSE;
     417  dumpit |= (oldcatalog[0].catID == 37007);
     418  // dumpit |= (oldcatalog[0].catID == 37261);
     419  // dumpit |= (oldcatalog[0].catID == 37257);
     420  // dumpit |= (oldcatalog[0].catID == 37258);
     421  if (dumpit) {
     422    char name[64];
     423    snprintf (name, 64, "cat.%05d.dump.dat", oldcatalog[0].catID);
     424    FILE *fdump = fopen (name, "w");
     425    for (i = 0; i < Nkeep; i++) {
     426      ave = keepidx[i];
     427      fprintf (fdump, "%10.6f %10.6f %d\n", subcatalog[0].average[ave].R, subcatalog[0].average[ave].D, subcatalog[0].average[ave].Nmeasure);
     428    }
     429    fclose (fdump);
     430  }
     431
     432  // allocate the output data
     433  ALLOCATE (tmpcatalog.average,  Average,     Nkeep);
     434  ALLOCATE (tmpcatalog.measureT, MeasureTiny, NMEASURE);
     435  ALLOCATE (tmpcatalog.secfilt,  SecFilt,     Nkeep * Nsecfilt);
     436
     437  off_t Nmeasure = 0;
     438
     439  // copy the Nkeep selected entries from subcatalog to tmpcatalog (adjusting links)
     440  for (i = 0; i < Nkeep; i++) {
     441    ave = keepidx[i];
     442    tmpcatalog.average[i] = subcatalog[0].average[ave];
     443    tmpcatalog.average[i].measureOffset = Nmeasure;
     444    for (j = 0; j < tmpcatalog.average[i].Nmeasure; j++) {
     445      off_t offset = subcatalog[0].average[ave].measureOffset + j;
     446      tmpcatalog.measureT[Nmeasure] = subcatalog[0].measureT[offset];
     447      tmpcatalog.measureT[Nmeasure].averef = i;
     448      Nmeasure ++;
     449    }
     450    for (j = 0; j < Nsecfilt; j++) {
     451      tmpcatalog.secfilt[i*Nsecfilt + j] = subcatalog[0].secfilt[ave*Nsecfilt + j];
     452    }
     453  }
     454
     455  if (VERBOSE2) {
     456    char *basename = filebasename (oldcatalog[0].filename);
     457    fprintf (stderr, "limited to %d ("OFF_T_FMT" subset, "OFF_T_FMT" total) stars, "OFF_T_FMT" ("OFF_T_FMT" subset, "OFF_T_FMT" total) measures for catalog %s\n",
     458             Nkeep, subcatalog[0].Naverage, oldcatalog[0].Naverage, Nmeasure, subcatalog[0].Nmeasure,  oldcatalog[0].Nmeasure, basename);
     459    free (basename);
     460  }
     461
     462  free (X);
     463  free (Y);
     464
     465  for (ix = 0; ix < NX; ix++) {
     466    for (iy = 0; iy < NY; iy++) {
     467      free (Nm_grid[ix][iy]);
     468      free (idxgrid[ix][iy]);
     469    }
     470    free (NN_grid[ix]);
     471    free (Nn_grid[ix]);
     472    free (Nm_grid[ix]);
     473    free (idxgrid[ix]);
     474  }
     475  free (NN_grid);
     476  free (Nn_grid);
     477  free (Nm_grid);
     478  free (idxgrid);
     479
     480  free (keepidx);
     481
     482  free (subcatalog[0].average);
     483  free (subcatalog[0].measureT);
     484  free (subcatalog[0].secfilt);
     485
     486  subcatalog[0].average = tmpcatalog.average;
     487  subcatalog[0].measureT = tmpcatalog.measureT;
     488  subcatalog[0].secfilt = tmpcatalog.secfilt;
     489  subcatalog[0].Naverage = Nkeep;
     490  subcatalog[0].Nmeasure = Nmeasure;
     491  subcatalog[0].Nsecfilt = oldcatalog[0].Nsecfilt;
     492  subcatalog[0].Nsecf_mem = Naverage * oldcatalog[0].Nsecfilt;
     493
     494  return (TRUE);
    157495}
    158496
     
    205543    NMEASURE += subcatalog[0].average[ave].Nmeasure;
    206544  }
     545
     546# if (0)
     547  if (oldcatalog[0].catID == 59962) {
     548    FILE *fdump = fopen ("cat.dump.dat", "w");
     549    for (i = 0; i < Nmax; i++) {
     550      ave = index[i];
     551      fprintf (fdump, "%10.6f %10.6f %d\n", subcatalog[0].average[ave].R, subcatalog[0].average[ave].D, subcatalog[0].average[ave].Nmeasure);
     552    }
     553    fclose (fdump);
     554  }
     555# endif
    207556
    208557  // allocate the output data
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/dvo_astrom_ops.c

    r33652 r37067  
    11# include "relastro.h"
     2/* the Measure carries the instantaneous mean position at the epoch t */
    23
    34double getMeanR (MeasureTiny *measure, Average *average, SecFilt *secfilt) {
     
    56  double ra;
    67
    7   /* the measure carries the instantaneous mean position at the epoch t */
    8   ra = average[0].R - measure[0].dR / 3600.0;
     8  // old: ra = average[0].R - measure[0].dR / 3600.0;
     9  if (!measure) return NAN;
     10  ra = measure[0].R;
     11
     12  return (ra);
     13}
     14
     15double getMeanD (MeasureTiny *measure, Average *average, SecFilt *secfilt) {
     16
     17  double dec;
     18
     19  // old: dec = average[0].D - measure[0].dD / 3600.0;
     20  if (!measure) return NAN;
     21  dec = measure[0].D;
     22
     23  return (dec);
     24}
     25
     26int setMeanR (double ra_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt) {
     27
     28  // old: measure[0].dR += (ra_fit - average[0].R) * 3600.0;
     29  if (!measure) return FALSE;
     30  measure[0].R = ra_fit;
     31
     32  return (TRUE);
     33}
     34
     35int setMeanD (double dec_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt) {
     36
     37  // old: measure[0].dD += (dec_fit - average[0].D) * 3600.0;
     38  if (!measure) return FALSE;
     39  measure[0].D = dec_fit;
     40
     41  return (TRUE);
     42}
     43
     44double getMeanR_Big (Measure *measure, Average *average, SecFilt *secfilt) {
     45
     46  double ra;
     47
     48  // old: ra = average[0].R - measure[0].dR / 3600.0;
     49  if (!measure) return NAN;
     50  ra = measure[0].R;
     51
     52  return (ra);
     53}
     54
     55double getMeanD_Big (Measure *measure, Average *average, SecFilt *secfilt) {
     56
     57  double dec;
     58
     59  // old: dec = average[0].D - measure[0].dD / 3600.0;
     60  if (!measure) return NAN;
     61  dec = measure[0].D;
     62
     63  return (dec);
     64}
     65
     66int setMeanR_Big (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt) {
     67
     68  // old: measure[0].dR += (ra_fit - average[0].R) * 3600.0;
     69  if (!measure) return TRUE;
     70  measure[0].R = ra_fit;
     71
     72  return (TRUE);
     73}
     74
     75int setMeanD_Big (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt) {
     76
     77  // measure[0].dD += (dec_fit - average[0].D) * 3600.0;
     78  if (!measure) return TRUE;
     79  measure[0].D = dec_fit;
     80
     81  return (TRUE);
     82}
    983
    1084  /* possible corrections to mean ra:
     
    1892  */
    1993
    20   return (ra);
    21 }
    22 
    23 double getMeanD (MeasureTiny *measure, Average *average, SecFilt *secfilt) {
    24 
    25   double dec;
    26 
    27   /* the measure carries the instantaneous mean position at the epoch t */
    28   dec = average[0].D - measure[0].dD / 3600.0;
    29 
    30   /* possible corrections to mean ra:
    31 
    32   - proper-motion and parallax
    33   - abberation
    34   - precession and nutation, etc
    35   - refraction
    36   - DCR
    37 
    38   */
    39 
    40   return (dec);
    41 }
    42 
    43 int setMeanR (double ra_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt) {
    44 
    45   /* math to get from new fitted position to new measure offset
    46      ra_obs = average[0].R - measure[0].dR / 3600.0;
    47      measure[0].dR = (ra_fit - ra_obs) * 3600.0;
    48      measure[0].dR = (ra_fit - average[0].R + measure[0].dR/3600) * 3600.0
    49      measure[0].dR = (ra_fit - average[0].R) * 3600.0 + measure[0].dR;
    50   */
    51 
    52   /* the measure carries the instantaneous mean position at the epoch t */
    53   measure[0].dR += (ra_fit - average[0].R) * 3600.0;
    54 
    55   /* possible corrections to mean ra:
    56 
    57   - proper-motion and parallax
    58   - abberation
    59   - precession and nutation, etc
    60   - refraction
    61   - DCR
    62 
    63   */
    64 
    65   return (TRUE);
    66 }
    67 
    68 int setMeanD (double dec_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt) {
    69 
    70   /* math to get from new fitted position to new measure offset
    71      dec_obs = average[0].D - measure[0].dD / 3600.0;
    72      measure[0].dD = (dec_fit - dec_obs) * 3600.0;
    73      measure[0].dD = (dec_fit - average[0].D + measure[0].dD/3600) * 3600.0
    74      measure[0].dD = (dec_fit - average[0].D) * 3600.0 + measure[0].dD;
    75   */
    76 
    77   /* the measure carries the instantaneous mean position at the epoch t */
    78   measure[0].dD += (dec_fit - average[0].D) * 3600.0;
    79 
    80   /* possible corrections to mean ra:
    81 
    82   - proper-motion and parallax
    83   - abberation
    84   - precession and nutation, etc
    85   - refraction
    86   - DCR
    87 
    88   */
    89 
    90   return (TRUE);
    91 }
    92 
    93 int setMeanR_Big (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt) {
    94 
    95   if (!measure) return TRUE;
    96 
    97   /* math to get from new fitted position to new measure offset
    98      ra_obs = average[0].R - measure[0].dR / 3600.0;
    99      measure[0].dR = (ra_fit - ra_obs) * 3600.0;
    100      measure[0].dR = (ra_fit - average[0].R + measure[0].dR/3600) * 3600.0
    101      measure[0].dR = (ra_fit - average[0].R) * 3600.0 + measure[0].dR;
    102   */
    103 
    104   /* the measure carries the instantaneous mean position at the epoch t */
    105   measure[0].dR += (ra_fit - average[0].R) * 3600.0;
    106 
    107   /* possible corrections to mean ra:
    108 
    109   - proper-motion and parallax
    110   - abberation
    111   - precession and nutation, etc
    112   - refraction
    113   - DCR
    114 
    115   */
    116 
    117   return (TRUE);
    118 }
    119 
    120 int setMeanD_Big (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt) {
    121 
    122   if (!measure) return TRUE;
    123 
    124   /* math to get from new fitted position to new measure offset
    125      dec_obs = average[0].D - measure[0].dD / 3600.0;
    126      measure[0].dD = (dec_fit - dec_obs) * 3600.0;
    127      measure[0].dD = (dec_fit - average[0].D + measure[0].dD/3600) * 3600.0
    128      measure[0].dD = (dec_fit - average[0].D) * 3600.0 + measure[0].dD;
    129   */
    130 
    131   /* the measure carries the instantaneous mean position at the epoch t */
    132   measure[0].dD += (dec_fit - average[0].D) * 3600.0;
    133 
    134   /* possible corrections to mean ra:
    135 
    136   - proper-motion and parallax
    137   - abberation
    138   - precession and nutation, etc
    139   - refraction
    140   - DCR
    141 
    142   */
    143 
    144   return (TRUE);
    145 }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/high_speed_objects.c

    r35494 r37067  
    161161  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    162162  tcoords.Npolyterms = 1;
    163   strcpy (tcoords.ctype, "RA---ARC");
     163  strcpy (tcoords.ctype, "DEC--ARC");
    164164
    165165  /* build spatial index (RA sort) referencing input array sequence */
     
    241241          for(i1=0;i1<catalog[0].average[nv[l]].Nmeasure;i1++) {
    242242              catalogOut.measure[Nmatchmeas]=catalog[0].measure[m+i1];
    243               /*Set offset RA and Dec wrt correct average value*/
    244               catalogOut.measure[Nmatchmeas].dR=catalog[0].measure[m+i1].dR+3600.0*(catalog[0].average[nv[0]].R-catalog[0].average[nv[l]].R);
    245               catalogOut.measure[Nmatchmeas].dD=catalog[0].measure[m+i1].dD+3600.0*(catalog[0].average[nv[0]].D-catalog[0].average[nv[l]].D);
     243              // DROP no longer necessary to repoint R,D
     244              // catalogOut.measure[Nmatchmeas].dR=catalog[0].measure[m+i1].dR+3600.0*(catalog[0].average[nv[0]].R-catalog[0].average[nv[l]].R);
     245              // catalogOut.measure[Nmatchmeas].dD=catalog[0].measure[m+i1].dD+3600.0*(catalog[0].average[nv[0]].D-catalog[0].average[nv[l]].D);
    246246              catalogOut.measure[Nmatchmeas].averef = Nmatch;
    247247              Nmatchmeasobj++;
     
    297297  // XXX require a set or not?  assert (Nset > 0);
    298298
    299   if (!finite(measure[0].dR)) return FALSE;
    300   if (!finite(measure[0].dD)) return FALSE;
    301   if (!finite(measure[0].M))  return FALSE;
     299  if (!finite(measure[0].R)) return FALSE;
     300  if (!finite(measure[0].D)) return FALSE;
     301  if (!finite(measure[0].M)) return FALSE;
    302302 
    303303  float dX = GetAstromError (measure, ERROR_MODE_RA);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/hpm_objects.c

    r35494 r37067  
    138138  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    139139  tcoords.Npolyterms = 1;
    140   strcpy (tcoords.ctype, "RA---ARC");
     140  strcpy (tcoords.ctype, "DEC--ARC");
    141141
    142142  /* build spatial index (RA sort) referencing input array sequence */
     
    240240      for (k = 0; k < catalog[0].average[nj].Nmeasure; k++) {
    241241        testcat.measure[Nmatchmeas] = catalog[0].measure[m+k];
    242         /* Set offset RA and Dec wrt correct average value*/
    243         testcat.measure[Nmatchmeas].dR = catalog[0].measure[m+k].dR + 3600.0*(catalog[0].average[ni].R - catalog[0].average[nj].R);
    244         testcat.measure[Nmatchmeas].dD = catalog[0].measure[m+k].dD + 3600.0*(catalog[0].average[ni].D - catalog[0].average[nj].D);
     242        // DROP: was needed when dR,dD were relative to average.R,D
     243        // testcat.measure[Nmatchmeas].R = catalog[0].measure[m+k].R;
     244        // testcat.measure[Nmatchmeas].D = catalog[0].measure[m+k].D;
    245245        testcat.measure[Nmatchmeas].averef = 0;
    246246        Nmatchmeas++;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/initialize.c

    r34429 r37067  
    66  args (argc, argv);
    77
    8   if (FIT_TARGET == TARGET_MERGE_SOURCE) return;
     8  if (RELASTRO_OP == OP_MERGE_SOURCE) return;
    99
    10   fprintf (stderr, "PHOTCODE_KEEP_LIST: %s\n", PHOTCODE_KEEP_LIST);
    11   fprintf (stderr, "PHOTCODE_SKIP_LIST: %s\n", PHOTCODE_SKIP_LIST);
    12   fprintf (stderr, "PHOTCODE_A_LIST: %s\n", PHOTCODE_A_LIST);
    13   fprintf (stderr, "PHOTCODE_B_LIST: %s\n", PHOTCODE_B_LIST);
     10  if (DCR_BLUE_COLOR_POS)  fprintf (stderr, "DCR_BLUE_COLOR_POS:  %s - %s\n", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     11  if (DCR_BLUE_COLOR_POS)  fprintf (stderr, "DCR_BLUE_COLOR_POS:  %s - %s\n", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
    1412
    15   photcodesKeep = ParsePhotcodeList (PHOTCODE_KEEP_LIST, &NphotcodesKeep, FALSE);
    16   photcodesSkip = ParsePhotcodeList (PHOTCODE_SKIP_LIST, &NphotcodesSkip, FALSE);
    17   photcodesGroupA = ParsePhotcodeList (PHOTCODE_A_LIST, &NphotcodesGroupA, TRUE);
    18   photcodesGroupB = ParsePhotcodeList (PHOTCODE_B_LIST, &NphotcodesGroupB, TRUE);
     13  if (PHOTCODE_KEEP_LIST)  fprintf (stderr, "PHOTCODE_KEEP_LIST:  %s\n", PHOTCODE_KEEP_LIST);
     14  if (PHOTCODE_SKIP_LIST)  fprintf (stderr, "PHOTCODE_SKIP_LIST:  %s\n", PHOTCODE_SKIP_LIST);
     15  if (PHOTCODE_RESET_LIST) fprintf (stderr, "PHOTCODE_RESET_LIST: %s\n", PHOTCODE_RESET_LIST);
     16  if (PHOTCODE_A_LIST)     fprintf (stderr, "PHOTCODE_A_LIST:     %s\n", PHOTCODE_A_LIST);
     17  if (PHOTCODE_B_LIST)     fprintf (stderr, "PHOTCODE_B_LIST:     %s\n", PHOTCODE_B_LIST);
     18
     19  photcodesKeep   = ParsePhotcodeList (PHOTCODE_KEEP_LIST,  &NphotcodesKeep,   FALSE);
     20  photcodesSkip   = ParsePhotcodeList (PHOTCODE_SKIP_LIST,  &NphotcodesSkip,   FALSE);
     21  photcodesReset  = ParsePhotcodeList (PHOTCODE_RESET_LIST, &NphotcodesReset,  FALSE);
     22  photcodesGroupA = ParsePhotcodeList (PHOTCODE_A_LIST,     &NphotcodesGroupA, TRUE);
     23  photcodesGroupB = ParsePhotcodeList (PHOTCODE_B_LIST,     &NphotcodesGroupB, TRUE);
     24
     25  // blue color elements
     26  DCR_BLUE_NSEC_POS = DCR_BLUE_NSEC_NEG = -1;
     27  if (DCR_BLUE_COLOR_POS) {
     28    DCR_BLUE_PHOTCODE_POS = GetPhotcodebyName (DCR_BLUE_COLOR_POS);
     29    if (!DCR_BLUE_PHOTCODE_POS) {
     30      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", DCR_BLUE_COLOR_POS);
     31      exit (1);
     32    }
     33    DCR_BLUE_NSEC_POS = GetPhotcodeNsec (DCR_BLUE_PHOTCODE_POS[0].code);
     34  }
     35  if (DCR_BLUE_COLOR_NEG) {
     36    DCR_BLUE_PHOTCODE_NEG = GetPhotcodebyName (DCR_BLUE_COLOR_NEG);
     37    if (!DCR_BLUE_PHOTCODE_NEG) {
     38      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", DCR_BLUE_COLOR_NEG);
     39      exit (1);
     40    }
     41    DCR_BLUE_NSEC_NEG = GetPhotcodeNsec (DCR_BLUE_PHOTCODE_NEG[0].code);
     42  }
     43
     44  // red color elements
     45  DCR_RED_NSEC_POS = DCR_RED_NSEC_NEG = -1;
     46  if (DCR_RED_COLOR_POS) {
     47    DCR_RED_PHOTCODE_POS = GetPhotcodebyName (DCR_RED_COLOR_POS);
     48    if (!DCR_RED_PHOTCODE_POS) {
     49      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", DCR_RED_COLOR_POS);
     50      exit (1);
     51    }
     52    DCR_RED_NSEC_POS = GetPhotcodeNsec (DCR_RED_PHOTCODE_POS[0].code);
     53  }
     54  if (DCR_RED_COLOR_NEG) {
     55    DCR_RED_PHOTCODE_NEG = GetPhotcodebyName (DCR_RED_COLOR_NEG);
     56    if (!DCR_RED_PHOTCODE_NEG) {
     57      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", DCR_RED_COLOR_NEG);
     58      exit (1);
     59    }
     60    DCR_RED_NSEC_NEG = GetPhotcodeNsec (DCR_RED_PHOTCODE_NEG[0].code);
     61  }
    1962
    2063  initstats (STATMODE);
     
    4285  args_client (argc, argv);
    4386
    44   fprintf (stderr, "PHOTCODE_KEEP_LIST: %s\n", PHOTCODE_KEEP_LIST);
    45   fprintf (stderr, "PHOTCODE_SKIP_LIST: %s\n", PHOTCODE_SKIP_LIST);
    46   fprintf (stderr, "PHOTCODE_A_LIST: %s\n", PHOTCODE_A_LIST);
    47   fprintf (stderr, "PHOTCODE_B_LIST: %s\n", PHOTCODE_B_LIST);
     87  if (PHOTCODE_KEEP_LIST)  fprintf (stderr, "PHOTCODE_KEEP_LIST:  %s\n", PHOTCODE_KEEP_LIST);
     88  if (PHOTCODE_SKIP_LIST)  fprintf (stderr, "PHOTCODE_SKIP_LIST:  %s\n", PHOTCODE_SKIP_LIST);
     89  if (PHOTCODE_RESET_LIST) fprintf (stderr, "PHOTCODE_RESET_LIST: %s\n", PHOTCODE_RESET_LIST);
     90  if (PHOTCODE_A_LIST)     fprintf (stderr, "PHOTCODE_A_LIST:     %s\n", PHOTCODE_A_LIST);
     91  if (PHOTCODE_B_LIST)     fprintf (stderr, "PHOTCODE_B_LIST:     %s\n", PHOTCODE_B_LIST);
    4892
    49   photcodesKeep = ParsePhotcodeList (PHOTCODE_KEEP_LIST, &NphotcodesKeep, FALSE);
    50   photcodesSkip = ParsePhotcodeList (PHOTCODE_SKIP_LIST, &NphotcodesSkip, FALSE);
    51   photcodesGroupA = ParsePhotcodeList (PHOTCODE_A_LIST, &NphotcodesGroupA, TRUE);
    52   photcodesGroupB = ParsePhotcodeList (PHOTCODE_B_LIST, &NphotcodesGroupB, TRUE);
     93  photcodesKeep   = ParsePhotcodeList (PHOTCODE_KEEP_LIST,  &NphotcodesKeep,   FALSE);
     94  photcodesSkip   = ParsePhotcodeList (PHOTCODE_SKIP_LIST,  &NphotcodesSkip,   FALSE);
     95  photcodesReset  = ParsePhotcodeList (PHOTCODE_RESET_LIST, &NphotcodesReset,  FALSE);
     96  photcodesGroupA = ParsePhotcodeList (PHOTCODE_A_LIST,     &NphotcodesGroupA, TRUE);
     97  photcodesGroupB = ParsePhotcodeList (PHOTCODE_B_LIST,     &NphotcodesGroupB, TRUE);
    5398
    5499  initstats (STATMODE);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/load_catalogs.c

    r35105 r37067  
    11# include "relastro.h"
    22
    3 Catalog *load_catalogs_parallel (SkyList *sky, int *Ncatalog);
     3Catalog *load_catalogs_parallel (SkyList *sky, int *Ncatalog, char *syncfile);
    44void bcatalog_show_skips ();
    55
    6 Catalog *load_catalogs (SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath) {
    7 
    8   int i, j, k, m, Nstar;
     6Catalog *load_catalogs (SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath, char *syncfile) {
     7
     8  int i, j, Nstar;
     9  // int k, m;
    910  Catalog *catalog, *pcatalog, tcatalog;
    1011
    1112  // XXX need to decide how to determine PARALLEL mode...
    1213  if (PARALLEL && !hostID) {
    13     catalog = load_catalogs_parallel (skylist, Ncatalog);
     14    catalog = load_catalogs_parallel (skylist, Ncatalog, syncfile);
    1415    return catalog;
    1516  }
     
    7374      if (RESET) {
    7475        for (j = 0; j < catalog[Ncat].Naverage; j++) {
     76# if (0)         
    7577          catalog[Ncat].average[j].flags = 0;
    7678          m = catalog[Ncat].average[j].measureOffset;
     
    7880            catalog[Ncat].measure[m+k].dbFlags = 0;
    7981          }
     82# endif
    8083        }
    8184      }
     
    8487  }
    8588
    86   // XXX TEST : bcatalog_show_skips();
     89  bcatalog_show_skips();
    8790
    8891  Nstar = 0;
     
    99102  }
    100103
     104  // if we are running with parallel_images but not a parallel database, we need to
     105  // release the lock so the next image host can proceed
     106  if (!hostID && syncfile) {
     107    update_sync_file (syncfile, 1);
     108  }
     109
    101110  // only return the populated catalogs
    102111  REALLOCATE (catalog, Catalog, Ncat);
     
    113122// CATDIR is supplied globally
    114123# define DEBUG 1
    115 Catalog *load_catalogs_parallel (SkyList *sky, int *Ncatalog) {
     124Catalog *load_catalogs_parallel (SkyList *sky, int *Ncatalog, char *syncfile) {
     125
     126  char uniquer[12];
     127  int TIME = time(NULL);
     128  int PID = getpid();
     129  snprintf (uniquer, 12, "%05d.%05d", PID, TIME % 100000);
    116130
    117131  // load the list of hosts
     
    131145
    132146    ALLOCATE (table->hosts[i].results, char, 1024);
    133     snprintf (table->hosts[i].results, 1024, "%s/relastro.catalog.subset.dat", table->hosts[i].pathname);
     147    snprintf (table->hosts[i].results, 1024, "%s/relastro.catalog.%s.dat", table->hosts[i].pathname, uniquer);
    134148
    135149    // options / arguments that can affect relastro_client -load:
     
    145159              table->hosts[i].results, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, MIN_ERROR, SIGMA_LIM);
    146160
    147     char tmpline[1024];
    148     if (FIT_MODE == FIT_PM_ONLY)         { snprintf (tmpline, 1024, "%s -pm",    command);           strcpy (command, tmpline); }
    149     if (FIT_MODE == FIT_PAR_ONLY)        { snprintf (tmpline, 1024, "%s -par",   command);           strcpy (command, tmpline); }
    150     if (FIT_MODE == FIT_PM_AND_PAR)      { snprintf (tmpline, 1024, "%s -pmpar", command);           strcpy (command, tmpline); }
    151 
    152     if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",              command);                    strcpy (command, tmpline); }
    153     if (VERBOSE2)      { snprintf (tmpline, 1024, "%s -vv",             command);                    strcpy (command, tmpline); }
    154     if (RESET)         { snprintf (tmpline, 1024, "%s -reset",          command);                    strcpy (command, tmpline); }
    155     if (ImagSelect)    { snprintf (tmpline, 1024, "%s -instmag %f %f",  command, ImagMin, ImagMax);  strcpy (command, tmpline); }
    156     if (MaxDensityUse) { snprintf (tmpline, 1024, "%s -max-density %f", command, MaxDensityValue);   strcpy (command, tmpline); }
     161    if (FIT_MODE == FIT_PM_ONLY)         strextend (command, "-pm");
     162    if (FIT_MODE == FIT_PAR_ONLY)        strextend (command, "-par");
     163    if (FIT_MODE == FIT_PM_AND_PAR)      strextend (command, "-pmpar");
     164
     165    if (VERBOSE)       strextend (command, "-v");
     166    if (VERBOSE2)      strextend (command, "-vv");
     167    if (RESET)         strextend (command, "-reset");
     168    if (ImagSelect)    strextend (command, "-instmag %f %f", ImagMin, ImagMax);
     169    if (MaxDensityUse) strextend (command, "-max-density %f", MaxDensityValue);
     170    if (FlagOutlier)   strextend (command, "-clip %d", CLIP_THRESH);
     171    if (ExcludeBogus)  strextend (command, "-exclude-bogus %f", ExcludeBogusRadius);
    157172   
    158     if (FlagOutlier)   { snprintf (tmpline, 1024, "%s -clip %d",        command, CLIP_THRESH);       strcpy (command, tmpline); }
    159    
    160     if (USE_FIXED_PIXCOORDS) { snprintf (tmpline, 1024, "%s -D USE_FIXED_PIXCOORDS 1", command);     strcpy (command, tmpline); }
    161 
    162     if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, 1024, "%s +photcode %s", command, PHOTCODE_KEEP_LIST); strcpy (command, tmpline); }
    163     if (PHOTCODE_SKIP_LIST) { snprintf (tmpline, 1024, "%s -photcode %s", command, PHOTCODE_SKIP_LIST); strcpy (command, tmpline); }
    164     if (PhotFlagSelect)    { snprintf (tmpline, 1024, "%s +photflags",   command);                     strcpy (command, tmpline); }
    165     if (PhotFlagBad)       { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad);     strcpy (command, tmpline); }
    166     if (PhotFlagPoor)      { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor);   strcpy (command, tmpline); }
     173    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
     174      strextend (command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     175    }
     176    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
     177      strextend (command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
     178    }
     179
     180    if (USE_FIXED_PIXCOORDS) strextend (command, "-D USE_FIXED_PIXCOORDS 1");
     181    if (PHOTCODE_KEEP_LIST)  strextend (command, "+photcode %s", PHOTCODE_KEEP_LIST);
     182    if (PHOTCODE_SKIP_LIST)  strextend (command, "-photcode %s", PHOTCODE_SKIP_LIST);
     183    if (PhotFlagSelect)      strextend (command, "+photflags");
     184    if (PhotFlagBad)         strextend (command, "+photflagbad %d", PhotFlagBad);
     185    if (PhotFlagPoor)        strextend (command, "+photflagpoor %d", PhotFlagPoor);
    167186    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
    168187
     
    170189      char *tstart = ohana_sec_to_date (TSTART);
    171190      char *tstop  = ohana_sec_to_date (TSTOP);
    172       snprintf (tmpline, 1024, "%s -time %s %s", command, tstart, tstop);
     191      strextend (command, "-time %s %s", tstart, tstop);
    173192      free (tstart);
    174193      free (tstop);
    175       strcpy (command, tmpline);
    176194    }
    177195
     
    206224  }
    207225
     226  // update syncfile here (save lots of I/O time):
     227
     228  // at this point, the remote relastro_client jobs are done loading their data.  in a
     229  // parallel_images mode, the next image host can be launched while this image host now
     230  // reads that
     231
     232  // NOTE: if I let all hosts load blindly, I saturate the data clients with too many
     233  // relastro_client requests.  I need to have the master mediate this.  the master
     234  // will not launch the next remote job until this one says it is done
     235  if (syncfile) {
     236    update_sync_file (syncfile, 1);
     237  }
     238
    208239  // each host generates a BrightCatalog structure, with the measure, average, etc value
    209240  // loaded into a single set of arrays (of MeasureTiny, AverageTiny, Secfilt).  I need to
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/load_images.c

    r35763 r37067  
    11# include "relastro.h"
    2 
    3 # define MARKTIME(MSG,...) { \
    4   float dtime; \
    5   gettimeofday (&stop, (void *) NULL); \
    6   dtime = DTIME (stop, start); \
    7   fprintf (stderr, MSG, __VA_ARGS__); }
    82
    93int load_images (FITS_DB *db, SkyList *skylist, int UseFullOverlap) {
     
    126  off_t      Nimage, Nsubset;
    137  off_t     *LineNumber;
    14   struct timeval start, stop;
    158
    16   gettimeofday (&start, (void *) NULL);
     9  INITTIME;
    1710
    1811  // convert database table to internal structure
     
    3528 
    3629  /* unlock, if we can (else, unlocked below) */
    37   int unlockImages = !UPDATE || (FIT_TARGET == TARGET_UPDATE_OFFSETS);
     30  int unlockImages = !UPDATE || (RELASTRO_OP == OP_UPDATE_OFFSETS);
    3831  if (unlockImages) dvo_image_unlock (db);
    3932
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/relastro.c

    r35763 r37067  
    1010  SkyList *skylist = SkyListByPatch (sky, -1, &UserPatch);
    1111
    12   switch (FIT_TARGET) {
    13     case TARGET_UPDATE_OBJECTS:
     12  switch (RELASTRO_OP) {
     13    case OP_UPDATE_OBJECTS:
    1414      /* the object analysis is a separate process iterating over catalogs */
    1515      relastro_objects (skylist, 0, NULL);
    1616      exit (0);
    1717
    18     case TARGET_HIGH_SPEED:
     18    case OP_HIGH_SPEED:
    1919      /* high-speed is a 2pt cross-correlation process for linking moving objects (high PM) */
    2020      high_speed_catalogs (sky, skylist, 0, NULL);
    2121      exit (0);
    2222
    23     case TARGET_HPM:
     23    case OP_HPM:
    2424      hpm_catalogs (sky, skylist, 0, NULL);
    2525      exit (0);
    2626
    27     case TARGET_MERGE_SOURCE:
     27    case OP_MERGE_SOURCE:
    2828      /* a special method to manually merge unlinked detections of sources togther (not parallel) */
    2929      relastro_merge_source (sky);
    3030      exit (0);
    3131
    32     case TARGET_SIMPLE:
    33     case TARGET_CHIPS:
    34     case TARGET_MOSAICS:
     32    case OP_IMAGES:
    3533      relastro_images (skylist);
    3634      exit (0);
    3735
    38     case TARGET_UPDATE_OFFSETS:
     36    case OP_UPDATE_OFFSETS:
    3937      // iterate over catalogs to make detection coordinates consistant
    4038      UpdateObjectOffsets (skylist, 0, NULL);
     39      exit (0);
     40
     41    case OP_PARALLEL_REGIONS:
     42      // run image updates in parallel across multiple remote machines
     43      relastro_parallel_regions ();
     44      exit (0);
     45
     46    case OP_PARALLEL_IMAGES:
     47      // operation on the remote machines in the PARALLEL_REGION mode
     48      relastro_parallel_images ();
    4149      exit (0);
    4250
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/relastroVisual.c

    r31635 r37067  
    431431 
    432432  // populate vectors
    433   ALLOCATE(Din, float, Nmeasure);
    434   ALLOCATE(Rin, float, Nmeasure);
     433  ALLOCATE(Din,  float, Nmeasure);
     434  ALLOCATE(Rin,  float, Nmeasure);
    435435  ALLOCATE(Dout, float, Nmeasure);
    436436  ALLOCATE(Rout, float, Nmeasure);
     
    451451    meas = catalog[0].measure[m];
    452452    if (!MeasFilterTest(&meas, FALSE)) continue;
    453     xmin = MIN(xmin, meas.dR);
    454     xmax = MAX(xmax, meas.dR);
    455     ymin = MIN(ymin, meas.dD);
    456     ymax = MAX(ymax, meas.dD);
     453    xmin = MIN(xmin, meas.R);
     454    xmax = MAX(xmax, meas.R);
     455    ymin = MIN(ymin, meas.D);
     456    ymax = MAX(ymax, meas.D);
    457457   
    458458    if (meas.dbFlags & ID_MEAS_POOR_ASTROM) {
    459       Rout[Nout] = (float)(meas.dR);
    460       Dout[Nout] = (float)(meas.dD);
     459      Rout[Nout] = (meas.R);
     460      Dout[Nout] = (meas.D);
    461461      fprintf(stderr, "r: %f\td: %f\t outlier: 1\n", Rout[Nout], Dout[Nout]);
    462462      Nout++;
    463463    } else {
    464       Rin[Nin] = (float)(meas.dR);
    465       Din[Nin] = (float)(meas.dD);
     464      Rin[Nin] = (meas.R);
     465      Din[Nin] = (meas.D);
    466466      fprintf(stderr, "r: %f\td: %f\t outlier: 0\n", Rin[Nin], Din[Nin]);
    467467      Nin++;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/relastro_client.c

    r35763 r37067  
    2828  SkyList *skylist = SkyListByPatch (sky, -1, &UserPatch);
    2929
    30   switch (FIT_TARGET) {
     30  switch (RELASTRO_OP) {
    3131
    32     case TARGET_LOAD_OBJECTS: {
     32    case OP_LOAD_OBJECTS: {
    3333      // USAGE: relastro_client -load-objects
    3434      int Ncatalog;
    35       Catalog *catalog = load_catalogs (skylist, &Ncatalog, TRUE, HOST_ID, HOSTDIR);
     35      Catalog *catalog = load_catalogs (skylist, &Ncatalog, TRUE, HOST_ID, HOSTDIR, NULL);
    3636      if (!catalog) {
    37           fprintf (stderr, "ERROR loading catalogs from %s\n", CATDIR);
    38           exit (2);
     37        fprintf (stderr, "ERROR loading catalogs from %s\n", CATDIR);
     38        exit (2);
    3939      }
    4040      BrightCatalog *bcatalog = BrightCatalogMerge (catalog, Ncatalog);
    4141      if (!BrightCatalogSave (BCATALOG, bcatalog)) {
    42           fprintf (stderr, "ERROR saving bright catalog from %s\n", CATDIR);
    43           exit (2);
     42        fprintf (stderr, "ERROR saving bright catalog from %s\n", CATDIR);
     43        exit (2);
    4444      }
    4545      break;
    4646    }
    4747     
    48     case TARGET_UPDATE_OBJECTS: {
     48    case OP_UPDATE_OBJECTS: {
    4949      // USAGE: relastro_client -update-objects
    5050      relastro_objects (skylist, HOST_ID, HOSTDIR);
     
    5252    }
    5353
    54     case TARGET_HIGH_SPEED: {
     54    case OP_HIGH_SPEED: {
    5555      // USAGE: relastro_client -high-speed
    5656      high_speed_catalogs (sky, skylist, HOST_ID, HOSTDIR);
     
    5858    }
    5959
    60     case TARGET_HPM: {
     60    case OP_HPM: {
    6161      // USAGE: relastro_client -high-speed
    6262      hpm_catalogs (sky, skylist, HOST_ID, HOSTDIR);
     
    6464    }
    6565
    66       // XXX loading the images is fairly costly -- see if we can do an image subset
    67     case TARGET_UPDATE_OFFSETS: {
     66      // XXX loading the images is fairly costly -- see if we can do an image subset?
     67    case OP_UPDATE_OFFSETS: {
    6868      FITS_DB db;
    6969     
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/relastro_images.c

    r35763 r37067  
    66  Catalog *catalog;
    77  FITS_DB db;
    8   struct timeval start, stop;
    98
    10   gettimeofday (&start, (void *) NULL);
     9  INITTIME;
    1110
    1211  /* register database handle with shutdown procedure */
     
    2928  // XXX pass in the image table
    3029  // XXX who carries the image grid?
    31   catalog = load_catalogs (skylist, &Ncatalog, TRUE, 0, NULL);
     30
     31  // photcodesKeep is used here to allow measurements from the images being calibrated
     32  // note if -reset-to-photcode is selected, photocodesKeep is replaced with below with photcodesReset
     33  catalog = load_catalogs (skylist, &Ncatalog, TRUE, 0, NULL, NULL);
    3234  MARKTIME("load catalog data: %f sec\n", dtime);
     35
     36  if (photcodesReset) {
     37    photcodesKeep  = photcodesReset;
     38    NphotcodesKeep = NphotcodesReset;
     39  }
    3340
    3441  if (Ncatalog == 0) {
     
    5158  // set test points based on the starmap
    5259  createStarMap (catalog, Ncatalog);
     60
     61  // XXX NOTE : for 2mass reset, photcodesKeep should now limit to 2MASS measurements
    5362
    5463  /* major modes */
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/relastro_merge_source.c

    r34088 r37067  
    100100      catalog_src.measure[m].averef = index_dst;
    101101
     102      // OLD CODE: when measure.dR,dD were relative to average.R,D it was necessary to modify them
    102103      // get the instantaneous positions:
    103       double R = catalog_src.average[index_src].R - catalog_src.measure[m].dR / 3600.0;
    104       double D = catalog_src.average[index_src].D - catalog_src.measure[m].dD / 3600.0;
     104      // DROP double R = catalog_src.average[index_src].R - catalog_src.measure[m].dR / 3600.0;
     105      // DROP double D = catalog_src.average[index_src].D - catalog_src.measure[m].dD / 3600.0;
    105106
    106107      // update the offset coordinates to match the new source
    107       catalog_src.measure[m].dR = 3600.0*(catalog_src.average[index_dst].R - R);
    108       catalog_src.measure[m].dD = 3600.0*(catalog_src.average[index_dst].D - D);
     108      // DROP catalog_src.measure[m].dR = 3600.0*(catalog_src.average[index_dst].R - R);
     109      // DROP catalog_src.measure[m].dD = 3600.0*(catalog_src.average[index_dst].D - D);
    109110    }
    110111
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/relastro_objects.c

    r35763 r37067  
    4040    snprintf (hostfile, 1024, "%s/%s.cpt", hostpath, skylist[0].regions[i]->name);
    4141    catalog.filename  = hostID ? hostfile : skylist[0].filename[i];
     42
     43    // set up the basic catalog info
    4244    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    4345    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
     
    144146    // PM_TOOFEW
    145147    // SRC_MEAS_TOOFEW
    146     // FIT_TARGET
    147148
    148149    char command[1024];
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/resort_catalog.c

    r34088 r37067  
    3030  if (catalog[0].sorted == TRUE) return;
    3131
    32   // struct timeval start, stop;
    33   // gettimeofday (&start, NULL);
     32  // INITTIME;
    3433
    3534  /* internal counters */
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/select_images.c

    r35763 r37067  
    1515void dsortindex (double *X, off_t *Y, int N);
    1616off_t getRegionStartByRA (double R, double *Rref, off_t Nregions);
    17 
    18 # define MARKTIME(MSG,...) { \
    19   float dtime; \
    20   gettimeofday (&stop, (void *) NULL); \
    21   dtime = DTIME (stop, start); \
    22   fprintf (stderr, MSG, __VA_ARGS__); }
    2317
    2418Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage, int UseFullOverlap) {
     
    3125  Coords tcoords;
    3226  SkyRegionCoords *skycoords;
    33   struct timeval start, stop;
    3427 
    3528  double RmaxSkyRegion, RminSkyRegion, RmidSkyRegion, DminSkyRegion, DmaxSkyRegion;
     
    5043  }
    5144
    52   gettimeofday (&start, (void *) NULL);
     45  INITTIME;
    5346
    5447  // the comparison is made in the catalog local projection. below we set crval1,2
     
    5750  tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    5851  tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    59   strcpy (tcoords.ctype, "RA---TAN");
     52  strcpy (tcoords.ctype, "DEC--TAN");
    6053
    6154  ALLOCATE (skycoords, SkyRegionCoords, skylist[0].Nregions);
     
    132125    if (NphotcodesKeep > 0) {
    133126      found = FALSE;
    134       // XXX this bit of code excludes DIS mosaics and should be fixed
     127      // we have to keep DIS mosaics explicitly (photcode = 0)
     128      if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) found = TRUE;
    135129      for (k = 0; (k < NphotcodesKeep) && !found; k++) {
    136130        if (photcodesKeep[k][0].code == timage[i].photcode) found = TRUE;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relastro/src/testparallax.c

    r34088 r37067  
    5757  coords.pc1_2  = coords.pc2_1 = 0.0;
    5858  coords.Npolyterms = 1;
    59   strcpy (coords.ctype, "RA---SIN");
     59  strcpy (coords.ctype, "DEC--SIN");
    6060
    6161  // use one point as a local reference
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/Makefile

    r35416 r37067  
    3434$(SRC)/args.$(ARCH).o            \
    3535$(SRC)/help.$(ARCH).o            \
     36$(SRC)/extra.$(ARCH).o           \
    3637$(SRC)/bcatalog.$(ARCH).o        \
    3738$(SRC)/global_stats.$(ARCH).o    \
     
    4748$(SRC)/relphot_images.$(ARCH).o  \
    4849$(SRC)/relphot_objects.$(ARCH).o         \
     50$(SRC)/relphot_parallel_regions.$(ARCH).o \
     51$(SRC)/relphot_parallel_images.$(ARCH).o \
    4952$(SRC)/select_images.$(ARCH).o   \
     53$(SRC)/assign_images.$(ARCH).o   \
     54$(SRC)/launch_region_hosts.$(ARCH).o     \
     55$(SRC)/ImageTable.$(ARCH).o      \
     56$(SRC)/ImageMagIO.$(ARCH).o      \
     57$(SRC)/syncfile.$(ARCH).o        \
     58$(SRC)/share_image_mags.$(ARCH).o        \
     59$(SRC)/share_mean_mags.$(ARCH).o         \
     60$(SRC)/MeanMagIO.$(ARCH).o       \
     61$(SRC)/indexCatalog.$(ARCH).o    \
    5062$(SRC)/client_logger.$(ARCH).o   \
    5163$(SRC)/setExclusions.$(ARCH).o   \
     
    7183$(SRC)/args.$(ARCH).o            \
    7284$(SRC)/help.$(ARCH).o            \
     85$(SRC)/extra.$(ARCH).o           \
    7386$(SRC)/synthetic_mags.$(ARCH).o  \
    7487$(SRC)/plotstuff.$(ARCH).o       \
    7588$(SRC)/liststats.$(ARCH).o       \
    7689$(SRC)/initialize.$(ARCH).o      \
     90$(SRC)/syncfile.$(ARCH).o        \
    7791$(SRC)/load_catalogs.$(ARCH).o   \
    7892$(SRC)/reload_catalogs.$(ARCH).o \
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/doc/mosaic.txt

    r33963 r37067  
     1
     2
     32014.07.09
     4
     5* trying to make sense of mosaic.Mcal vs image.Mcal in the context of UBERCAL:
     6
     7  * relphot_images:
     8    * load_images (convert raw FITS table to Image structure, select subset matching selection)
     9      * initMosaics (associate mosaics to images (gpc1 photcodes only))
     10        * initMosaicGrid (define spatial range of mosaics [only used by grid analysis]; set Mcal to <image.Mcal> and image.Mcal to 0.0)
     11    --- calculate image or mosaic Mcal values
     12    * setMcalFinal (set image.Mcal = mosaicMcal)
     13
     14  * relphot_parallel_regions:
     15    * assign_images
     16      * makeMosaics (equivalent to initMosaics, but works on full image table, not subset)
     17      * setMosaicCenters (set Mcal to <image.Mcal> and image.Mcal to 0.0) <--- this is wrong!
     18      (sends images ONLY, not mosaics, to remote machines)
     19      (slurps back new image values, applies to db)
     20     
     21  * relphot_parallel_images:
     22    * makeMosaics (associate mosaics to images, gpc1 photcodes only)
     23      * initMosaicGrid (needed in this one)
     24---
    125
    226For 'mosaic' zero points, I define the mosaics by grouping the images
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/doc/parallel.txt

    r33651 r37067  
     1
     22014.02.15
     3
     4Nearly done with the relphot mods.  some outstanding questions;
     5
     6 * image vs mosaic?
     7 * how do decide which images need to be shared?
     8
     92014.02.14
     10
     11 more relphot notes:
     12
     13 * I load the catalogs, with a 
     14
     152014.02.12
     16
     17I am making progess on the relphot -parallel-regions implementation.  some things I need to deal with:
     18
     19 * assign_images: select mosaics for all images saved for a given host (need to supply them as well)
     20   ** I need to decide on the Image / Mosaic split.  If I am calibrating by image, then the image center defines ownership
     21   ** if I am calibrating by exposure, then the mosaic center must define ownership
     22 o determine SkyList covering the images for region host
     23 o tag detections and objects which I own or do not own
     24   o ImageOps.c / matchImage matches detections to images and needs to handle mine / not mine cases
     25   o ditto for matchMosaics
     26 o load_catalogs : I need to make my requested catalogs unique (just add uniquer to load_catalogs.c:130
     27 o figure out what fields I'm saving in meanmags and how to construct it
     28   -- mag, objID, catID, photcode, (dmag or other stats?)
     29 * from which hosts do I slurp mean mags?
     30 o function to merge a new meanmag array into the existing one
     31 o how to go from (objID,catID) to a given catalog[i].average[j]
     32
     332014.02.06
     34
     35** a single region-level host owns images for which the center lands
     36   in its region.
     37
     38** it owns detections which come from images which it owns
     39   
     40** it owns objects which land in its region
     41
     42Extending parallel relphot processing to split the sky (and images)
     43into regions, each of which runs in parallel at the same time:
     44
     45Top Level (relphot -parallel-images):
     46 * define regions of the sky -> hosts
     47 * load images, assign to hosts
     48 * launch region-level jobs on remote hosts
     49
     50 Region Level (relphot -parallel-images-region)
     51  * load my image subset table
     52  * request objects and detections for my skyregion
     53  * match images & objects, etc
     54
     55  * update my image parameters
     56  * update my detections
     57  * write out detections
     58  * load detections from my border hosts
     59  * match to my objects
     60  * update my objects
     61  * write out objects
     62  * load objects from my border hosts
     63  * update images
     64    (iterate N times)
     65  * write out image parameters
     66
     67Top Level
     68  * read image parameters, update
     69  * update objects
    170
    2712012.02.13
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/include/relphot.h

    r35806 r37067  
    55# include <pthread.h>
    66
    7 # define MARKTIME(MSG,...) {                    \
    8     gettimeofday (&stopTimer, (void *) NULL);   \
    9     float dtime = DTIME (stopTimer, startTimer);        \
    10     fprintf (stderr, MSG, __VA_ARGS__); }
    11 
    12 # define INITTIME \
    13   struct timeval startTimer, stopTimer; \
    14   gettimeofday (&startTimer, (void *) NULL);
    15 
    167/* # define GRID_V1 */
    178# define GRID_V2
     
    2314// # define IDX_T off_t
    2415# define IDX_T int
     16
     17typedef enum {
     18  MODE_ERROR = 0,
     19  UPDATE_IMAGES,
     20  UPDATE_AVERAGES,
     21  PARALLEL_REGIONS,
     22  PARALLEL_IMAGES,
     23  APPLY_OFFSETS,
     24} RelphotMode;
    2525
    2626typedef enum {
     
    8686  // others are only used on the final output steps.
    8787
    88   double *list;               // list of measure.mag values for a given star
    89   double *dlist;              // mag errors for a star
    90   double *wlist;              // weights to use for mean mags
    91   double *aplist;             // ap mags for a star
    92   double *kronlist;           // kron mags for a star
     88  double *Mpsflist;           // list of measure.mag values for a given star
     89  double *dpsflist;           // mag errors for a star
     90  double *wpsflist;           // weights to use for mean mags
     91
     92  double *Maplist;            // ap mags for a star
     93  double *daplist;            // ap mags for a star
     94  double *waplist;            // ap mags for a star
     95
     96  double *Mkronlist;          // kron mags for a star
    9397  double *dkronlist;          // kron mag errors
     98  double *wkronlist;          // kron mag errors
    9499
    95100  double *psfqf_list;         // psfqf for all filters
     
    97102  double *stargal_list;       // stargal for all filters
    98103
    99   StatType stats;
     104  StatType psfstats;
    100105  StatType apstats;
    101106  StatType kronstats;
    102107} SetMrelInfo;
     108
     109typedef struct {
     110  float M;
     111  float dM;
     112  float Mchisq;
     113  int Nsec;
     114  unsigned int objID;
     115  unsigned int catID;
     116  int photcode;
     117} MeanMag;
     118
     119typedef struct {
     120  float Mcal;
     121  float dMcal;
     122  float dMagSys;
     123  short Xm;
     124  int nFitPhotom;
     125  int flags;
     126  unsigned int imageID;
     127  short ubercalDist;
     128} ImageMag;
    103129
    104130typedef struct {
     
    116142  unsigned int photom_map_id;
    117143  unsigned int flags;
     144  int tessID;
    118145  int projID;
    119146  int skycellID;
     
    149176int    SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */
    150177
     178// globals for parallel region operations
     179char  *REGION_FILE;
     180char  *IMAGE_TABLE;
     181int    REGION_HOST_ID;
     182
    151183int          HOST_ID;
    152184char        *HOSTDIR;
     
    173205int    PARALLEL_MANUAL;
    174206int    PARALLEL_SERIAL;
     207
     208int    PARALLEL_REGIONS_MANUAL;
    175209
    176210int    NTHREADS;
     
    260294void          InterpolateGrid     PROTO((float *buffer, int Nx, int Ny, Coords *ccd, Coords *gcoords));
    261295off_t        *SelectRefMosaic     PROTO((Mosaic **refmosaic, off_t *Nimage));
    262 int           args                PROTO((int argc, char **argv));
     296RelphotMode   args                PROTO((int argc, char **argv));
    263297int           args_client         PROTO((int argc, char **argv));
    264298int           bcatalog            PROTO((Catalog *subcatalog, Catalog *catalog, int Ncat));
     
    273307void          findImages          PROTO((Catalog *catalog, int Ncatalog, int doImageList));
    274308int           findMosaics         PROTO((Catalog *catalog, int Ncatalog, int doMosaicList));
     309
     310void makeMosaics (Image *image, off_t Nimage, int mergeMcal);
     311Mosaic *getMosaicForImage (off_t im);
     312void setMosaicCenters (Image *image, off_t Nimage);
    275313
    276314void set_db (FITS_DB *in);
     
    309347void          initMosaics         PROTO((Image *subset, off_t Nsubset, Image *image, char *inSubset, off_t Nimage));
    310348void          initMrel            PROTO((Catalog *catalog, int Ncatalog));
    311 void          initialize          PROTO((int argc, char **argv));
     349RelphotMode   initialize          PROTO((int argc, char **argv));
    312350void          initialize_client   PROTO((int argc, char **argv));
    313351void          liststats_setmode   PROTO((StatType *stats, char *strmode));
    314352int           liststats           PROTO((double *value, double *dvalue, double *wvalue, int N, StatType *stats));
    315 Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int hostID, char *hostpath));
    316 Catalog      *load_catalogs_parallel PROTO((SkyList *sky, int *Ncatalog));
     353Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int hostID, char *hostpath, char *syncfile));
     354Catalog      *load_catalogs_parallel PROTO((SkyList *sky, int *Ncatalog, char *syncfile));
    317355
    318356SkyList      *load_images         PROTO((FITS_DB *db, char *regionName, SkyRegion *region));
     
    397435ImageSubset *ImageSubsetLoad(char *filename, off_t *nimage);
    398436
    399 int client_logger_init ();
     437int client_logger_init (char *dirname);
    400438int client_logger_message (char *format,...);
    401439
    402440int MatchImageName (off_t meas, int cat, char *name);
    403 int MatchImageSkycellID (off_t meas, int cat, int myProjectionID, int mySkycellID);
    404 
    405 int load_tree (char *treefile);
    406 int BoundaryTreePrimaryCell (char *primaryCellName, double ra, double dec);
    407 int BoundaryTreePrimaryCellIDs (int *projID, int *skycellID, double ra, double dec);
     441int MatchImageSkycellID (off_t meas, int cat, int myTessID, int myProjectionID, int mySkycellID);
     442
     443int load_tess (char *treefile);
     444int get_tess_ids (int *tessID, int *projID, int *skycellID, double ra, double dec);
     445int TessellationIDsByImageName (int *tessID, int *projID, int *skycellID, char *name);
     446
     447// int BoundaryTreePrimaryCell (char *primaryCellName, double ra, double dec);
     448// int BoundaryTreePrimaryCellIDs (int *projID, int *skycellID, double ra, double dec);
    408449
    409450int print_measure_set_alt (Average *average, SecFilt *secfilt, Measure *measure);
     
    417458int init_synthetic_mags ();
    418459int add_synthetic_mags (AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, off_t *Nmeasure, off_t *Nm);
     460
     461int relphot_parallel_regions ();
     462
     463int assign_images (FITS_DB *db, RegionHostTable *regionHosts);
     464int select_images_hostregion (RegionHostTable *hosts, Image *image, off_t Nimage);
     465int find_host_for_coords (RegionHostTable *regionHosts, double R, double d);
     466int calculate_image_bounds (Image *image, double *rmin, double *rmax, double *dmin, double *dmax, double Rmid);
     467
     468int launch_region_hosts (RegionHostTable *regionHosts);
     469int strextend (char *input, char *format,...);
     470
     471Image *ImageTableLoad(char *filename, off_t *nimage);
     472int ImageTableSave (char *filename, Image *images, off_t Nimages);
     473
     474int indexCatalogs (Catalog *catalog, int Ncatalog);
     475int catID_and_objID_to_seq (int catID, int objID, int *catSeq, off_t *objSeq);
     476
     477int check_sync_file (char *filename, int nloop);
     478int clear_sync_file (char *filename);
     479int update_sync_file (char *filename, int nloop);
     480char *make_filename (char *dirname, char *hostname, int hostID, char *tailname);
     481
     482int share_mean_mags (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     483int slurp_mean_mags (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     484int set_mean_mags (MeanMag *meanmags, AverageTiny *average, SecFilt *secfilt, int Nsec);
     485MeanMag *merge_mean_mags (MeanMag *target, int *ntarget, MeanMag *source, int Nsource);
     486
     487MeanMag *MeanMagLoad(char *filename, off_t *nmeanmags);
     488int MeanMagSave(char *filename, MeanMag *meanmags, off_t Nmeanmags);
     489
     490int share_image_mags (RegionHostTable *regionHosts, int nloop);
     491int slurp_image_mags (RegionHostTable *regionHosts, int nloop);
     492int set_image_mags (ImageMag *image_mags, Image *image);
     493ImageMag *merge_image_mags (ImageMag *target, int *ntarget, ImageMag *source, int Nsource);
     494
     495ImageMag *ImageMagLoad(char *filename, off_t *nimage_mags);
     496int ImageMagSave(char *filename, ImageMag *image_mags, off_t Nimage_mags);
     497
     498int markObjects (Catalog *catalog, int Ncatalog);
     499
     500int relphot_parallel_images ();
     501int relphot_parallel_regions ();
     502
     503// in extra.c
     504int isGPC1chip  (int photcode);
     505int isGPC1stack (int photcode);
     506int isGPC1warp  (int photcode);
     507
     508
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/BoundaryTreeOps.c

    r35759 r37067  
    11# include "relphot.h"
    22
    3 // XXX for the moment, only load one boundary tree at a time
    4 // XXX in fact, only allow RINGS.V3...
     3static int Ntess = 0;
     4static TessellationTable *tess = NULL;
    55
    6 static BoundaryTree *tree = NULL;
     6int TessellationIDsByImageName (int *tessID, int *projID, int *skycellID, char *name) {
    77
    8 int BoundaryTreePrimaryCell (char *primaryCellName, double ra, double dec) {
     8  int i;
    99
    10   int zone, band;
    11 
    12   if (!primaryCellName) return FALSE;
    13 
    14   primaryCellName[0] = 0;
    15 
    16   if (!tree) return FALSE;
    17 
    18   if (!BoundaryTreeCellCoords (tree, &zone, &band, ra, dec)) {
    19     fprintf (stderr, "mismatch!\n");
    20     return FALSE;
    21   }
    22  
    23 # define USE_PROJECTION_CELL 0
    24 # if (USE_PROJECTION_CELL)
    25   snprintf (primaryCellName, DVO_MAX_PATH, "RINGS.V3.%s", tree->name[zone][band]);
    26 # else
    27 
    28   // I have ra, dec, and the primary projection cell.  In order to choose the primary skycell,
    29   // I just need to project to ra,dec to X,Y based on the center of the cell and then get the subdivision right.
    30    
    31   double x = 0.0;
    32   double y = 0.0;
    33   BoundaryTreeProjection (&x, &y, ra, dec, tree, zone, band);
    34  
    35   int xi = x / tree->dX[zone][band];
    36   int yi = y / tree->dY[zone][band];
    37   int N = xi + tree->NX_SUB * yi;
    38  
    39   // XXX short-circuit this for now (we should use this code if we make tree have more variable NX,NY values
    40   // char format[24], skycellname[128];
    41   // int Ndigit = (int)(log10(tree->NX_SUB*tree->NY_SUB)) + 1 ;
    42   // snprintf (format, 24, "%s.%%0%dd", tree->name[zone][band], Ndigit);
    43   // snprintf (skycellname, 128, format, N);
    44 
    45   snprintf (primaryCellName, DVO_MAX_PATH, "RINGS.V3.%s.%03d", tree->name[zone][band], N);
    46 # endif
    47 
    48   return TRUE;
    49 }
    50 
    51 int BoundaryTreePrimaryCellIDs (int *projID, int *skycellID, double ra, double dec) {
    52 
    53   int zone, band;
    54 
     10  *tessID = -1;
    5511  *projID = -1;
    5612  *skycellID = -1;
    5713
    58   if (!tree) return FALSE;
     14  if (!tess) return FALSE;
    5915
    60   if (!BoundaryTreeCellCoords (tree, &zone, &band, ra, dec)) {
    61     fprintf (stderr, "mismatch!\n");
    62     return FALSE;
     16  for (i = 0; i < Ntess; i++) {
     17    // do this with a strhash of some kind?
     18    if (!strncmp (name, tess[i].basename, tess[i].Nbasename)) {
     19      *tessID    = i;
     20      if (tess[i].projectIDoff >= 0) {
     21        *projID    = atoi(&name[tess[i].projectIDoff]);
     22      } else {
     23        *projID    = 0;
     24      }
     25      if (tess[i].skycellIDoff >= 0) {
     26        *skycellID = atoi(&name[tess[i].skycellIDoff]);
     27      } else {
     28        *skycellID = 0;
     29      }
     30      return TRUE;
     31    }
    6332  }
    64  
    65   // I have ra, dec, and the primary projection cell.  In order to choose the primary skycell,
    66   // I just need to project to ra,dec to X,Y based on the center of the cell and then get the subdivision right.
    67    
    68   double x = 0.0;
    69   double y = 0.0;
    70   BoundaryTreeProjection (&x, &y, ra, dec, tree, zone, band);
    71  
    72   int xi = x / tree->dX[zone][band];
    73   int yi = y / tree->dY[zone][band];
    74   int N = xi + tree->NX_SUB * yi;
    75  
    76   *projID = tree->projID[zone][band];
    77   *skycellID = N;
    78 
    79   return TRUE;
     33  return FALSE;
    8034}
    8135
    82 int load_tree (char *treefile) {
     36int load_tess (char *tessfile) {
    8337
    84   tree = BoundaryTreeLoad (treefile);
    85   if (!tree) {
    86     fprintf (stderr, "failed to load boundary tree %s\n", treefile);
     38  tess = TessellationTableLoad (tessfile, &Ntess);
     39  if (!tess) {
     40    fprintf (stderr, "failed to load tessellation boundary file %s\n", tessfile);
    8741    exit (2);
    8842  }
     
    9044  return TRUE;
    9145}
     46
     47int get_tess_ids (int *tessID, int *projID, int *skycellID, double ra, double dec) {
     48
     49  int status;
     50
     51  if (!tess) return FALSE;
     52
     53  status = TessellationPrimaryCellIDs(tess, Ntess, tessID, projID, skycellID, ra, dec);
     54  return status;
     55}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/BrightCatalog.c

    r33651 r37067  
    6363 
    6464    // need to create and assign to flat-field correction
    65     GET_COLUMN(dR,        "RA_OFF",     float);
    66     GET_COLUMN(dD,        "DEC_OFF",    float);
     65    GET_COLUMN(R,         "RA",         double);
     66    GET_COLUMN(D,         "DEC",        double);
    6767    GET_COLUMN(M,         "MAG_SYS",    float);
    6868    GET_COLUMN(Mcal,      "MAG_CAL",    float);
     
    8585    ALLOCATE (measure, MeasureTiny, Nrow);
    8686    for (i = 0; i < Nrow; i++) {
    87       measure[i].dR        = dR[i];
    88       measure[i].dD        = dD[i];
     87      measure[i].R         = R[i];
     88      measure[i].D         = D[i];
    8989      measure[i].M         = M[i];
    9090      measure[i].Mcal      = Mcal[i];
     
    101101      measure[i].catID     = catID[i];
    102102      measure[i].photcode  = photcode[i];
     103      measure[i].myDet     = FALSE;
    103104    }
    104105    fprintf (stderr, "loaded data for %lld measure\n", (long long) Nrow);
    105106
    106     free (dR      );
    107     free (dD      );
     107    free (R       );
     108    free (D       );
    108109    free (M       );
    109110    free (Mcal    );
     
    135136 
    136137    // need to create and assign to flat-field correction
    137     GET_COLUMN(R,             "RA",        double);
    138     GET_COLUMN(D,             "DEC",       double);
     138    GET_COLUMN(R,             "RA",          double);
     139    GET_COLUMN(D,             "DEC",         double);
    139140    GET_COLUMN(Nmeasure,      "NMEAS",       int);
    140141    GET_COLUMN(measureOffset, "MEASURE_OFF", int);
    141142    GET_COLUMN(flags,         "FLAGS",       int);
    142143    GET_COLUMN(catID,         "CAT_ID",      int);
     144    GET_COLUMN(objID,         "OBJ_ID",      int);
    143145    gfits_free_header (&theader);
    144146    gfits_free_table  (&ftable);
     
    153155      average[i].flags          = flags[i];
    154156      average[i].catID          = catID[i];
     157      average[i].objID          = objID[i];
     158      average[i].nOwn           = 0;
    155159    }
    156160    fprintf (stderr, "loaded data for %lld average\n", (long long) Nrow);
     
    162166    free (flags         );
    163167    free (catID         );
     168    free (objID         );
    164169
    165170    catalog->average = average;
     
    177182 
    178183    // need to create and assign to flat-field correction
    179     GET_COLUMN(M,     "MAG",      float);
    180     GET_COLUMN(dM,    "MAG_ERR",  float);
    181     GET_COLUMN(Xm,    "MAG_CHI",  float);
    182     GET_COLUMN(flags, "FLAGS",    int);
    183     GET_COLUMN(Ncode, "NCODE",    short);
    184     GET_COLUMN(Nused, "NUSED",    short);
    185     GET_COLUMN(M_20,  "MAG_20",   short);
    186     GET_COLUMN(M_80,  "MAG_80",   short);
     184    GET_COLUMN(M,      "MAG",      float);
     185    GET_COLUMN(dM,     "MAG_ERR",  float);
     186    GET_COLUMN(Mchisq, "MAG_CHI",  float);
     187    GET_COLUMN(flags,  "FLAGS",    int);
     188    GET_COLUMN(Ncode,  "NCODE",    short);
     189    GET_COLUMN(Nused,  "NUSED",    short);
     190    GET_COLUMN(Mmin,   "MAG_MIN",  float);
     191    GET_COLUMN(Mmax,   "MAG_MAX",  float);
    187192    gfits_free_header (&theader);
    188193    gfits_free_table  (&ftable);
     
    191196    ALLOCATE (secfilt, SecFilt, Nrow);
    192197    for (i = 0; i < Nrow; i++) {
    193       secfilt[i].M     = M[i];         
    194       secfilt[i].dM    = dM[i];
    195       secfilt[i].Xm    = Xm[i];
    196       secfilt[i].flags = flags[i];
    197       secfilt[i].Ncode = Ncode[i];
    198       secfilt[i].Nused = Nused[i];
    199       secfilt[i].M_20  = M_20[i];
    200       secfilt[i].M_80  = M_80[i];
     198      secfilt[i].M      = M[i];         
     199      secfilt[i].dM     = dM[i];
     200      secfilt[i].Mchisq = Mchisq[i];
     201      secfilt[i].flags  = flags[i];
     202      secfilt[i].Ncode  = Ncode[i];
     203      secfilt[i].Nused  = Nused[i];
     204      secfilt[i].Mmin   = Mmin[i];
     205      secfilt[i].Mmax   = Mmax[i];
    201206    }
    202207    fprintf (stderr, "loaded data for %lld secfilt\n", (long long) Nrow);
    203208
    204     free (M    );
    205     free (dM   );
    206     free (Xm   );
    207     free (flags);
    208     free (Ncode);
    209     free (Nused);
    210     free (M_20 );
    211     free (M_80 );
     209    free (M     );
     210    free (dM    );
     211    free (Mchisq);
     212    free (flags );
     213    free (Ncode );
     214    free (Nused );
     215    free (Mmin );
     216    free (Mmax );
    212217    catalog->secfilt = secfilt;
    213218    // assert Nsecfilt * Naverage = Nrow?
     
    260265    gfits_create_table_header (&theader, "BINTABLE", "MEASURE_TINY");
    261266
    262     gfits_define_bintable_column (&theader, "E", "RA_OFF",   "ra offset",                  "arcsec", 1.0, 0.0);
    263     gfits_define_bintable_column (&theader, "E", "DEC_OFF",  "dec offset",                 "arcsec", 1.0, 0.0);
     267    gfits_define_bintable_column (&theader, "D", "RA",       "ra",                         "degree", 1.0, 0.0);
     268    gfits_define_bintable_column (&theader, "D", "DEC",      "dec",                        "degree", 1.0, 0.0);
    264269    gfits_define_bintable_column (&theader, "E", "MAG_SYS",  "magnitude (sys)",             NULL,    1.0, 0.0);
    265270    gfits_define_bintable_column (&theader, "E", "MAG_CAL",  "magnitude (cal)",             NULL,    1.0, 0.0);
     
    269274    gfits_define_bintable_column (&theader, "E", "Y_CCD",    "ccd y coord",                "pix",    1.0, 0.0);
    270275    gfits_define_bintable_column (&theader, "E", "EXPTIME",  "-2.5 * log (exposure time)", "sec",    1.0, 0.0);
    271     gfits_define_bintable_column (&theader, "J", "TIME",     "time of exp",                "sec",    1.0, 1.0*0x8000);
    272     gfits_define_bintable_column (&theader, "J", "AVE_REF",  "pointer to average table",    NULL,    1.0, 1.0*0x8000);
    273     gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image",                       NULL,    1.0, 1.0*0x8000);
    274     gfits_define_bintable_column (&theader, "J", "DB_FLAGS", "flags",                       NULL,    1.0, 1.0*0x8000);
    275     gfits_define_bintable_column (&theader, "J", "PHOT_FLAGS", "photflags",                 NULL,    1.0, 1.0*0x8000);
    276     gfits_define_bintable_column (&theader, "J", "CAT_ID",   "catalog",                     NULL,    1.0, 1.0*0x8000);
    277     gfits_define_bintable_column (&theader, "I", "PHOTCODE", "photcode",                    NULL,    1.0, 1.0*0x80);
     276    gfits_define_bintable_column (&theader, "J", "TIME",     "time of exp",                "sec",    1.0, FT_BZERO_INT32);
     277    gfits_define_bintable_column (&theader, "J", "AVE_REF",  "pointer to average table",    NULL,    1.0, FT_BZERO_INT32);
     278    gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image",                       NULL,    1.0, FT_BZERO_INT32);
     279    gfits_define_bintable_column (&theader, "J", "DB_FLAGS", "flags",                       NULL,    1.0, FT_BZERO_INT32);
     280    gfits_define_bintable_column (&theader, "J", "PHOT_FLAGS", "photflags",                 NULL,    1.0, FT_BZERO_INT32);
     281    gfits_define_bintable_column (&theader, "J", "CAT_ID",   "catalog",                     NULL,    1.0, FT_BZERO_INT32);
     282    gfits_define_bintable_column (&theader, "I", "PHOTCODE", "photcode",                    NULL,    1.0, FT_BZERO_INT16);
    278283
    279284    // generate the output array that carries the data
     
    281286
    282287    // create intermediate storage arrays
    283     float *dR        ; ALLOCATE (dR       ,  float, catalog->Nmeasure);
    284     float *dD        ; ALLOCATE (dD       ,  float, catalog->Nmeasure);
    285     float *M         ; ALLOCATE (M        ,  float, catalog->Nmeasure);
    286     float *Mcal      ; ALLOCATE (Mcal     ,  float, catalog->Nmeasure);
    287     float *dM        ; ALLOCATE (dM       ,  float, catalog->Nmeasure);
    288     float *airmass   ; ALLOCATE (airmass  ,  float, catalog->Nmeasure);
    289     float *Xccd      ; ALLOCATE (Xccd     ,  float, catalog->Nmeasure);
    290     float *Yccd      ; ALLOCATE (Yccd     ,  float, catalog->Nmeasure);
    291     float *dt        ; ALLOCATE (dt       ,  float, catalog->Nmeasure);
    292     int   *t         ; ALLOCATE (t        ,  int  , catalog->Nmeasure);
    293     int   *averef    ; ALLOCATE (averef   ,  int  , catalog->Nmeasure);
    294     int   *imageID   ; ALLOCATE (imageID  ,  int  , catalog->Nmeasure);
    295     int   *dbFlags   ; ALLOCATE (dbFlags  ,  int  , catalog->Nmeasure);
    296     int   *photFlags ; ALLOCATE (photFlags,  int  , catalog->Nmeasure);
    297     int   *catID     ; ALLOCATE (catID    ,  int  , catalog->Nmeasure);
    298     short *photcode  ; ALLOCATE (photcode ,  short, catalog->Nmeasure);
     288    double *R         ; ALLOCATE (R        ,  double, catalog->Nmeasure);
     289    double *D         ; ALLOCATE (D        ,  double, catalog->Nmeasure);
     290    float  *M         ; ALLOCATE (M        ,  float, catalog->Nmeasure);
     291    float  *Mcal      ; ALLOCATE (Mcal     ,  float, catalog->Nmeasure);
     292    float  *dM        ; ALLOCATE (dM       ,  float, catalog->Nmeasure);
     293    float  *airmass   ; ALLOCATE (airmass  ,  float, catalog->Nmeasure);
     294    float  *Xccd      ; ALLOCATE (Xccd     ,  float, catalog->Nmeasure);
     295    float  *Yccd      ; ALLOCATE (Yccd     ,  float, catalog->Nmeasure);
     296    float  *dt        ; ALLOCATE (dt       ,  float, catalog->Nmeasure);
     297    int    *t         ; ALLOCATE (t        ,  int  , catalog->Nmeasure);
     298    int    *averef    ; ALLOCATE (averef   ,  int  , catalog->Nmeasure);
     299    int    *imageID   ; ALLOCATE (imageID  ,  int  , catalog->Nmeasure);
     300    int    *dbFlags   ; ALLOCATE (dbFlags  ,  int  , catalog->Nmeasure);
     301    int    *photFlags ; ALLOCATE (photFlags,  int  , catalog->Nmeasure);
     302    int    *catID     ; ALLOCATE (catID    ,  int  , catalog->Nmeasure);
     303    short  *photcode  ; ALLOCATE (photcode ,  short, catalog->Nmeasure);
    299304
    300305    // assign the storage arrays
    301306    MeasureTiny *measure = catalog->measure;
    302307    for (i = 0; i < catalog->Nmeasure; i++) {
    303       dR[i]       = measure[i].dR       ;
    304       dD[i]       = measure[i].dD       ;
     308      R[i]        = measure[i].R       ;
     309      D[i]        = measure[i].D       ;
    305310      M[i]        = measure[i].M        ;
    306311      Mcal[i]     = measure[i].Mcal     ;
     
    320325
    321326    // add the columns to the output array
    322     gfits_set_bintable_column (&theader, &ftable, "RA_OFF",     dR,        catalog->Nmeasure);
    323     gfits_set_bintable_column (&theader, &ftable, "DEC_OFF",    dD,        catalog->Nmeasure);
     327    gfits_set_bintable_column (&theader, &ftable, "RA",         R,         catalog->Nmeasure);
     328    gfits_set_bintable_column (&theader, &ftable, "DEC",        D,         catalog->Nmeasure);
    324329    gfits_set_bintable_column (&theader, &ftable, "MAG_SYS",    M,         catalog->Nmeasure);
    325330    gfits_set_bintable_column (&theader, &ftable, "MAG_CAL",    Mcal,      catalog->Nmeasure);
     
    337342    gfits_set_bintable_column (&theader, &ftable, "PHOTCODE",   photcode,  catalog->Nmeasure);
    338343
    339     free (dR      );
    340     free (dD      );
     344    free (R       );
     345    free (D       );
    341346    free (M       );
    342347    free (Mcal    );
     
    370375    gfits_define_bintable_column (&theader, "J", "FLAGS",       "flags",                  NULL,    1.0, 0.0);
    371376    gfits_define_bintable_column (&theader, "J", "CAT_ID",      "catalog ref",            NULL,    1.0, 0.0);
     377    gfits_define_bintable_column (&theader, "J", "OBJ_ID",      "object ref",             NULL,    1.0, 0.0);
    372378
    373379    // generate the output array that carries the data
     
    381387    int   *flags          ; ALLOCATE (flags,         int,    catalog->Naverage);
    382388    int   *catID          ; ALLOCATE (catID,         int,    catalog->Naverage);
     389    int   *objID          ; ALLOCATE (objID,         int,    catalog->Naverage);
    383390
    384391    // assign the storage arrays
     
    391398      flags[i]          = average[i].flags;
    392399      catID[i]          = average[i].catID;
     400      objID[i]          = average[i].objID;
    393401    }
    394402
     
    400408    gfits_set_bintable_column (&theader, &ftable, "FLAGS",       flags,         catalog->Naverage);
    401409    gfits_set_bintable_column (&theader, &ftable, "CAT_ID",      catID,         catalog->Naverage);
     410    gfits_set_bintable_column (&theader, &ftable, "OBJ_ID",      objID,         catalog->Naverage);
    402411
    403412    free (R             );
     
    407416    free (flags         );
    408417    free (catID         );
     418    free (objID         );
    409419
    410420    gfits_fwrite_Theader (f, &theader);
     
    418428    gfits_create_table_header (&theader, "BINTABLE", "SECFILT");
    419429
    420     gfits_define_bintable_column (&theader, "E", "MAG",      "ra offset",                "arcsec", 1.0, 0.0);
    421     gfits_define_bintable_column (&theader, "E", "MAG_ERR",  "dec offset",               "arcsec", 1.0, 0.0);
    422     gfits_define_bintable_column (&theader, "E", "MAG_CHI",  "magnitude (sys)",           NULL,    1.0, 0.0);
    423     gfits_define_bintable_column (&theader, "J", "FLAGS",    "magnitude (cal)",           NULL,    1.0, 0.0);
    424     gfits_define_bintable_column (&theader, "I", "NCODE",    "magnitude (err)",           NULL,    1.0, 0.0);
    425     gfits_define_bintable_column (&theader, "I", "NUSED",    "airmass",                   NULL,    1.0, 0.0);
    426     gfits_define_bintable_column (&theader, "I", "MAG_20",   "ccd x coord",              "pix",    1.0, 0.0);
    427     gfits_define_bintable_column (&theader, "I", "MAG_80",   "ccd y coord",              "pix",    1.0, 0.0);
     430    gfits_define_bintable_column (&theader, "E", "MAG",      "",              "arcsec", 1.0, 0.0);
     431    gfits_define_bintable_column (&theader, "E", "MAG_ERR",  "",              "arcsec", 1.0, 0.0);
     432    gfits_define_bintable_column (&theader, "E", "MAG_CHI",  "",              NULL,    1.0, 0.0);
     433    gfits_define_bintable_column (&theader, "J", "FLAGS",    "",              NULL,    1.0, 0.0);
     434    gfits_define_bintable_column (&theader, "I", "NCODE",    "",              NULL,    1.0, 0.0);
     435    gfits_define_bintable_column (&theader, "I", "NUSED",    "",              NULL,    1.0, 0.0);
     436    gfits_define_bintable_column (&theader, "E", "MAG_MIN",  "min valid mag", "mag",   1.0, 0.0);
     437    gfits_define_bintable_column (&theader, "E", "MAG_MAX",  "max valid mag", "mag",   1.0, 0.0);
    428438
    429439    // generate the output array that carries the data
     
    437447    float *M        ; ALLOCATE (M      ,  float, Nsec);
    438448    float *dM       ; ALLOCATE (dM     ,  float, Nsec);
    439     float *Xm       ; ALLOCATE (Xm    ,  float, Nsec);
     449    float *Mchisq   ; ALLOCATE (Mchisq ,  float, Nsec);
    440450    int   *flags    ; ALLOCATE (flags  ,  int,   Nsec);
    441451    short *Ncode    ; ALLOCATE (Ncode  ,  short, Nsec);
    442452    short *Nused    ; ALLOCATE (Nused  ,  short, Nsec);
    443     short *M_20     ; ALLOCATE (M_20   ,  short, Nsec);
    444     short *M_80     ; ALLOCATE (M_80   ,  short, Nsec);
     453    float *Mmin     ; ALLOCATE (Mmin   ,  float, Nsec);
     454    float *Mmax     ; ALLOCATE (Mmax   ,  float, Nsec);
    445455
    446456    // assign the storage arrays
    447457    SecFilt *secfilt = catalog->secfilt;
    448458    for (i = 0; i < Nsec; i++) {
    449       M     [i]       = secfilt[i]. M      ;
    450       dM    [i]       = secfilt[i]. dM     ;
    451       Xm    [i]       = secfilt[i]. Xm    ;
    452       flags [i]       = secfilt[i]. flags  ;
    453       Ncode [i]       = secfilt[i]. Ncode  ;
    454       Nused [i]       = secfilt[i]. Nused  ;
    455       M_20  [i]       = secfilt[i]. M_20   ;
    456       M_80  [i]       = secfilt[i]. M_80   ;
     459      M     [i]       = secfilt[i].M      ;
     460      dM    [i]       = secfilt[i].dM     ;
     461      Mchisq[i]       = secfilt[i].Mchisq ;
     462      flags [i]       = secfilt[i].flags  ;
     463      Ncode [i]       = secfilt[i].Ncode  ;
     464      Nused [i]       = secfilt[i].Nused  ;
     465      Mmin  [i]       = secfilt[i].Mmin   ;
     466      Mmax  [i]       = secfilt[i].Mmax   ;
    457467    }
    458468
    459469    // add the columns to the output array
    460     gfits_set_bintable_column (&theader, &ftable, "MAG",      M    , Nsec);
    461     gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",  dM   , Nsec);
    462     gfits_set_bintable_column (&theader, &ftable, "MAG_CHI",  Xm   , Nsec);
    463     gfits_set_bintable_column (&theader, &ftable, "FLAGS",    flags, Nsec);
    464     gfits_set_bintable_column (&theader, &ftable, "NCODE",    Ncode, Nsec);
    465     gfits_set_bintable_column (&theader, &ftable, "NUSED",    Nused, Nsec);
    466     gfits_set_bintable_column (&theader, &ftable, "MAG_20",   M_20 , Nsec);
    467     gfits_set_bintable_column (&theader, &ftable, "MAG_80",   M_80 , Nsec);
     470    gfits_set_bintable_column (&theader, &ftable, "MAG",      M     , Nsec);
     471    gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",  dM    , Nsec);
     472    gfits_set_bintable_column (&theader, &ftable, "MAG_CHI",  Mchisq, Nsec);
     473    gfits_set_bintable_column (&theader, &ftable, "FLAGS",    flags , Nsec);
     474    gfits_set_bintable_column (&theader, &ftable, "NCODE",    Ncode , Nsec);
     475    gfits_set_bintable_column (&theader, &ftable, "NUSED",    Nused , Nsec);
     476    gfits_set_bintable_column (&theader, &ftable, "MAG_MIN",  Mmin , Nsec);
     477    gfits_set_bintable_column (&theader, &ftable, "MAG_MAX",  Mmax , Nsec);
    468478
    469479    free (M      );
    470480    free (dM     );
    471     free (Xm    );
     481    free (Mchisq );
    472482    free (flags  );
    473483    free (Ncode  );
    474484    free (Nused  );
    475     free (M_20   );
    476     free (M_80   );
     485    free (Mmin   );
     486    free (Mmax   );
    477487
    478488    gfits_fwrite_Theader (f, &theader);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/GridOps.c

    r34088 r37067  
    414414        // select the color- and airmass-corrected observed magnitude for this star
    415415        // XXX need to be able to turn off the color-correction until initial average mags are found
    416         Msys = PhotCatTiny (&catalog[c].measureT[m]);
     416        Msys = PhotCatTiny (&catalog[c].measureT[m], MAG_CLASS_PSF);
    417417        if (isnan(Msys)) {
    418418          Nsys++;
     
    573573     
    574574      n = catalog[c].measureT[m].averef;
    575       Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
     575      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
    576576      if (isnan(Msys)) {
    577577        Nsys++;
     
    651651
    652652      n = catalog[c].measureT[m].averef;
    653       Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
     653      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
    654654
    655655      xlist[N] = Xmeas[c][m];
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/ImageOps.c

    r35759 r37067  
    4848// stack image.  for now, we generate these ID arrays based on the image names when we load in the image table (initImages).
    4949// When we pass data to the remote clients via the ImageSubset, the projID/skycellID values are carried directly in the table.
     50int *tessID    = NULL;
    5051int *projectID = NULL;
    5152int *skycellID = NULL;
     
    8182
    8283  // for stack images, assign projection cell ID and skycell ID based on filenames
     84  ALLOCATE (tessID,      int, Nimage);
    8385  ALLOCATE (projectID,   int, Nimage);
    8486  ALLOCATE (skycellID,   int, Nimage);
     
    8789    imageIdx[i] = i;
    8890    imageIDs[i] = image[i].imageID;
     91
     92    tessID[i]    = -1;
    8993    projectID[i] = -1;
    9094    skycellID[i] = -1;
    91     if (!strncmp (image[i].name, "RINGS.V3.skycell", strlen("RINGS.V3.skycell"))) {
    92       projectID[i] = atoi(&image[i].name[17]);
    93       skycellID[i] = atoi(&image[i].name[22]);
    94     }
     95
     96    TessellationIDsByImageName (&tessID[i], &projectID[i], &skycellID[i], image[i].name);
    9597  }
    9698
    9799  // sort the image index by the IDs
     100  // XXX does this break the imageID <-> projectID, etc match?
    98101  llsortpair (imageIDs, imageIdx, Nimage);
    99102}
     
    106109  // create full a Image array and save the needed values
    107110  ALLOCATE (image, Image, N);
     111
     112  ALLOCATE (tessID,    int, N);
    108113  ALLOCATE (projectID, int, N);
    109114  ALLOCATE (skycellID, int, N);
     
    118123    image[i].trate         = input[i].trate        ;
    119124    image[i].ubercalDist   = input[i].ubercalDist  ;
     125    tessID[i]              = input[i].tessID       ;
    120126    projectID[i]           = input[i].projID       ;
    121127    skycellID[i]           = input[i].skycellID    ;
     
    153159    subset[i].trate         = image[i].trate        ;
    154160    subset[i].ubercalDist   = image[i].ubercalDist  ;
     161    subset[i].tessID        = tessID[i];
    155162    subset[i].projID        = projectID[i];
    156163    subset[i].skycellID     = skycellID[i];
     
    237244 
    238245  int Nmatch = 0;
    239  for (i = 0; i < Ncatalog; i++) {
     246  for (i = 0; i < Ncatalog; i++) {
    240247    for (j = 0; j < catalog[i].Nmeasure; j++) {
     248      catalog[i].measureT[j].myDet = FALSE; // a detetion is not mine until proven otherwise
    241249      ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[j].photcode);
     250
     251      // skip measurements which do not match one of the requested photcodes (
     252      // (do we not already exclude in bcatalog -- maybe needed for reload_objects?
    242253      found = FALSE;
    243254      for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     
    245256      }
    246257      if (!found) continue;
     258
     259      // if we match one of our images, myDet gets set to TRUE
    247260      matchImage (catalog, j, i, doImageList);
    248261      Nmatch ++;
     
    315328    return;
    316329  }
     330  catalog[cat].measureT[meas].myDet = TRUE;
    317331
    318332  if (USE_GRID) {
     
    461475
    462476// returns image.Mcal - ff(x,y)
    463 int MatchImageSkycellID (off_t meas, int cat, int myProjectionID, int mySkycellID) {
     477int MatchImageSkycellID (off_t meas, int cat, int myTessID, int myProjectionID, int mySkycellID) {
    464478
    465479  off_t i;
     
    470484  if (i == -1) return FALSE;
    471485
     486  if (tessID[i]    == -1) return FALSE;
    472487  if (projectID[i] == -1) return FALSE;
    473488  if (skycellID[i] == -1) return FALSE;
    474489
     490  if (tessID[i]    != myTessID) return FALSE;
    475491  if (projectID[i] != myProjectionID) return FALSE;
    476492  if (skycellID[i] != mySkycellID) return FALSE;
     
    515531  liststats_setmode (&stats, STATMODE);
    516532
    517   if (FREEZE_IMAGES) return;
     533  // FREEZE_IMAGES only applies to mosaic data (eg, gpc1)
    518534
    519535  fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE);
     
    545561      if (!bad) continue;
    546562    }     
     563
     564    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    547565
    548566    // UBERCAL image: if this is an ubercal image, set minUbercalDist to 0:
     
    592610
    593611      n = catalog[c].measureT[m].averef;
    594       Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
     612      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
    595613      if (isnan(Msys)) {
    596614        Nsys++;
     
    679697  double MaxOffset, MaxScatter, MedOffset;
    680698
    681   if (FREEZE_IMAGES) return;
     699  // if (FREEZE_IMAGES) return;
    682700
    683701  if (VERBOSE) fprintf (stderr, "marking poor images\n");
     
    690708  for (i = N = 0; i < Nimage; i++) {
    691709    if (image[i].flags & IMAGE_BAD) continue;
     710
     711    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
     712
    692713    mlist[N] = image[i].Mcal;
    693714    slist[N] = image[i].dMcal;
     
    781802  Graphdata graphdata;
    782803
    783   if (FREEZE_IMAGES) return;
     804  // if (FREEZE_IMAGES) return;
    784805
    785806  ALLOCATE (xlist, double, Nimage);
     
    794815  float mindMcal    = +100.0;
    795816  float maxdMcal    = -100.0;
    796   for (i = 0; i < Nimage; i++) {
    797     Mlist[i] = image[i].Mcal;
    798     dlist[i] = image[i].dMcal;
    799     xlist[i] = image[i].secz;
     817
     818  int Nplot = 0;
     819
     820  for (i = 0; i < Nimage; i++) {
     821
     822    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
     823
     824    Mlist[Nplot] = image[i].Mcal;
     825    dlist[Nplot] = image[i].dMcal;
     826    xlist[Nplot] = image[i].secz;
    800827    minAirmass = MIN (image[i].secz, minAirmass);
    801828    maxAirmass = MAX (image[i].secz, maxAirmass);
     
    804831    mindMcal = MIN (image[i].dMcal, mindMcal);
    805832    maxdMcal = MAX (image[i].dMcal, maxdMcal);
     833   
     834    Nplot ++;
    806835  }
    807836
     
    836865  for (i = 0; i < NBIN; i++) xlist[i] = 0.00025*i;
    837866  bzero (Mlist, NBIN*sizeof(double));
    838   for (i = 0; i < Nimage; i++) {
     867
     868  for (i = 0; i < Nimage; i++) {
     869    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
     870
    839871    bin = image[i].dMcal / 0.00025;
    840872    bin = MAX (0, MIN (NBIN - 1, bin));
     
    861893  StatType stats;
    862894  bzero (&stats, sizeof (StatType));
    863   if (FREEZE_IMAGES) return (stats);
     895
     896  // we no longer blindly apply FREEZE_IMAGES to all images, only to mosaics
     897  // if (FREEZE_IMAGES) return (stats);
    864898
    865899  ALLOCATE (list, double, Nimage);
     
    869903  for (i = 0; i < Nimage; i++) {
    870904    if (image[i].flags & IMAGE_BAD)  continue;
     905
     906    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    871907
    872908    N = 0;
     
    904940
    905941  bzero (&stats, sizeof (StatType));
    906   if (FREEZE_IMAGES) return (stats);
     942  // if (FREEZE_IMAGES) return (stats);
    907943
    908944  ALLOCATE (list, double, Nimage);
     
    913949
    914950    if (image[i].flags & IMAGE_BAD)  continue;
     951
     952    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    915953
    916954    list[n] = pow (10.0, 0.01*image[i].Xm);
     
    934972
    935973  bzero (&stats, sizeof (StatType));
    936   if (FREEZE_IMAGES) return (stats);
     974  // if (FREEZE_IMAGES) return (stats);
    937975
    938976  ALLOCATE (list, double, Nimage);
     
    943981
    944982    if (image[i].flags & IMAGE_BAD)  continue;
     983
     984    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    945985
    946986    list[n] = image[i].Mcal;
     
    9641004
    9651005  bzero (&stats, sizeof (StatType));
    966   if (FREEZE_IMAGES) return (stats);
     1006  // if (FREEZE_IMAGES) return (stats);
    9671007
    9681008  ALLOCATE (list, double, Nimage);
     
    9731013
    9741014    if (image[i].flags & IMAGE_BAD)  continue;
     1015
     1016    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    9751017
    9761018    list[n] = image[i].dMcal;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/ImageSubset.c

    r35759 r37067  
    6363  GET_COLUMN (map,       "PHOTOM_MAP",   int);
    6464  GET_COLUMN (flags,     "FLAGS",        int);
     65  GET_COLUMN (tessID,    "TESS_ID",      int);
    6566  GET_COLUMN (projID,    "PROJ_ID",      int);
    6667  GET_COLUMN (skycellID, "SKYCELL_ID",   int);
     
    7879    image[i].photom_map_id = map[i];
    7980    image[i].flags         = flags[i];
     81    image[i].tessID        = tessID[i];
    8082    image[i].projID        = projID[i];
    8183    image[i].skycellID     = skycellID[i];
     
    9193  free (map);
    9294  free (flags);
     95  free (tessID);
    9396  free (projID);
    9497  free (skycellID);
     
    123126  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_SUBSET");
    124127
    125   gfits_define_bintable_column (&theader, "E", "MCAL", "zero point offset", "magnitudes", 1.0, 0.0);
    126   gfits_define_bintable_column (&theader, "E", "MCAL_ERR", "zero point error", "magnitudes", 1.0, 0.0);
    127 
    128   gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image ID", NULL, 1.0, 1.0*0x8000);
    129   gfits_define_bintable_column (&theader, "J", "PHOTOM_MAP", "map", NULL, 1.0, 1.0*0x8000);
    130   gfits_define_bintable_column (&theader, "J", "FLAGS", "flags", NULL, 1.0, 1.0*0x8000);
    131 
    132   gfits_define_bintable_column (&theader, "J", "PROJ_ID", "ID", NULL, 1.0, 0.0);
    133   gfits_define_bintable_column (&theader, "J", "SKYCELL_ID", "ID", NULL, 1.0, 0.0);
    134 
    135   gfits_define_bintable_column (&theader, "J", "TZERO", "exposure start", NULL, 1.0, 1.0*0x8000);
    136   gfits_define_bintable_column (&theader, "I", "TRATE", "tti rate", NULL, 1.0, 0.0);
    137 
    138   gfits_define_bintable_column (&theader, "I", "UBERCAL_DIST", "ubercal distance", NULL, 1.0, 1.0*0x80);
     128  gfits_define_bintable_column (&theader, "E", "MCAL",         "zero point offset", "magnitudes", 1.0, 0.0);
     129  gfits_define_bintable_column (&theader, "E", "MCAL_ERR",     "zero point error",  "magnitudes", 1.0, 0.0);
     130  gfits_define_bintable_column (&theader, "J", "IMAGE_ID",     "image ID",          NULL,         1.0, FT_BZERO_INT32);
     131  gfits_define_bintable_column (&theader, "J", "PHOTOM_MAP",   "map",               NULL,         1.0, FT_BZERO_INT32);
     132  gfits_define_bintable_column (&theader, "J", "FLAGS",        "flags",             NULL,         1.0, FT_BZERO_INT32);
     133  gfits_define_bintable_column (&theader, "J", "TESS_ID",      "ID",                NULL,         1.0, 0.0);
     134  gfits_define_bintable_column (&theader, "J", "PROJ_ID",      "ID",                NULL,         1.0, 0.0);
     135  gfits_define_bintable_column (&theader, "J", "SKYCELL_ID",   "ID",                NULL,         1.0, 0.0);
     136  gfits_define_bintable_column (&theader, "J", "TZERO",        "exposure start",    NULL,         1.0, FT_BZERO_INT32);
     137  gfits_define_bintable_column (&theader, "I", "TRATE",        "tti rate",          NULL,         1.0, FT_BZERO_INT16);
     138  gfits_define_bintable_column (&theader, "I", "UBERCAL_DIST", "ubercal distance",  NULL,         1.0, 0.0);
    139139
    140140  // generate the output array that carries the data
     
    143143  float *Mcal, *dMcal;
    144144  unsigned int *imageID, *map, *flags, *tzero;
    145   int *projID, *skycellID;
     145  int *tessID, *projID, *skycellID;
    146146  unsigned short *trate;
    147147  short *ucdist;
    148148
    149149  // create intermediate storage arrays
    150   ALLOCATE (Mcal,      float,        Nimage);
    151   ALLOCATE (dMcal,     float,        Nimage);
     150  ALLOCATE (Mcal,      float,          Nimage);
     151  ALLOCATE (dMcal,     float,          Nimage);
    152152  ALLOCATE (imageID,   unsigned int,   Nimage);
    153153  ALLOCATE (map,       unsigned int,   Nimage);
    154154  ALLOCATE (flags,     unsigned int,   Nimage);
     155  ALLOCATE (tessID,    int,            Nimage);
    155156  ALLOCATE (projID,    int,            Nimage);
    156157  ALLOCATE (skycellID, int,            Nimage);
     
    169170    trate[i]     = image[i].trate;
    170171    ucdist[i]    = image[i].ubercalDist;
     172    tessID[i]    = image[i].tessID;
    171173    projID[i]    = image[i].projID;
    172174    skycellID[i] = image[i].skycellID;
     
    179181  gfits_set_bintable_column (&theader, &ftable, "PHOTOM_MAP",   map,       Nimage);
    180182  gfits_set_bintable_column (&theader, &ftable, "FLAGS",        flags,     Nimage);
     183  gfits_set_bintable_column (&theader, &ftable, "TESS_ID",      tessID,    Nimage);
    181184  gfits_set_bintable_column (&theader, &ftable, "PROJ_ID",      projID,    Nimage);
    182185  gfits_set_bintable_column (&theader, &ftable, "SKYCELL_ID",   skycellID, Nimage);
     
    190193  free (map);
    191194  free (flags);
     195  free (tessID);
    192196  free (projID);
    193197  free (skycellID);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/MosaicOps.c

    r35806 r37067  
    11# include "relphot.h"
    22void plot_setMcal (double *list, int Npts, StatType *stats, float clouds);
     3off_t findMosaic (unsigned int *startTimes, off_t Nmosaic, unsigned int start);
    34
    45// see discussion in ImagesOps.c re: IDX_T
     
    3637// MosaicN_image was 'Nimlist'
    3738// MosaicToImage was 'imlist'
     39
     40void sort_times (unsigned int *T, int N) {
     41
     42# define SWAPFUNC(A,B){ unsigned int tmp; \
     43  tmp = T[A]; T[A] = T[B]; T[B] = tmp; \
     44}
     45# define COMPARE(A,B)(T[A] < T[B])
     46
     47  OHANA_SORT (N, COMPARE, SWAPFUNC);
     48
     49# undef SWAPFUNC
     50# undef COMPARE
     51
     52}
    3853
    3954/* find mosaic frames (unique time periods & photcode name matches mosaic) */
     
    96111   
    97112    /* a new mosaic, define ranges -- preserve the original values incase this image is not used */
    98     mosaic[Nmosaic].start = start;
    99     mosaic[Nmosaic].stop  = stop;
    100     mosaic[Nmosaic].Mcal  = 0.0; // note : mosaic stores only offsets relative to the original image values
    101     mosaic[Nmosaic].dMcal = 0.0; // note : at the end, mosaic.Mcal is added back to the input images
    102     mosaic[Nmosaic].dMsys = 0.0;
    103     mosaic[Nmosaic].Xm    = 0.0;
     113    mosaic[Nmosaic].start  = start;
     114    mosaic[Nmosaic].stop   = stop;
     115    mosaic[Nmosaic].Mcal   = 0.0; // note : mosaic stores only offsets relative to the original image values
     116    mosaic[Nmosaic].dMcal  = 0.0; // note : at the end, mosaic.Mcal is added back to the input images
     117    mosaic[Nmosaic].dMsys  = 0.0;
     118    mosaic[Nmosaic].Xm = 0.0;
    104119    mosaic[Nmosaic].flags  = image[i].flags;
    105     mosaic[Nmosaic].secz  = image[i].secz;
     120    mosaic[Nmosaic].secz   = image[i].secz;
    106121    mosaic[Nmosaic].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode);
    107122
     
    136151}
    137152
    138 off_t findMosaic (unsigned int *startTimes, off_t Nmosaic, unsigned int start);
    139 
    140 void sort_times (unsigned int *T, int N) {
    141 
    142 # define SWAPFUNC(A,B){ unsigned int tmp; \
    143   tmp = T[A]; T[A] = T[B]; T[B] = tmp; \
    144 }
    145 # define COMPARE(A,B)(T[A] < T[B])
    146 
    147   OHANA_SORT (N, COMPARE, SWAPFUNC);
    148 
    149 # undef SWAPFUNC
    150 # undef COMPARE
    151 
    152 }
    153 
    154153/* find mosaic frames (unique time periods) (NOTE : we do NOT require matching photcodes...)
    155154   this function will also identify the images NOT in the subset which belong to a selected mosaic
     
    157156void initMosaics (Image *subset, off_t Nsubset, Image *image, char *inSubset, off_t Nimage) {
    158157
    159   off_t i, j, status, found, NMOSAIC, *MosaicN_IMAGE;
     158  off_t i, j, found, NMOSAIC, *MosaicN_IMAGE;
    160159  unsigned int start, stop, *startTimes, *startTimesMosaic;
    161   char *pname;
    162160
    163161  if (!MOSAIC_ZEROPT) return;
     
    172170  // generate a list of all subset image start times
    173171  ALLOCATE (startTimes, unsigned int, Nsubset);
     172  int Nmoschip = 0;
    174173  for (i = 0; i < Nsubset; i++) {
    175     startTimes[i] = subset[i].tzero;
    176   }
    177   sort_times (startTimes, Nsubset);
     174    if (!isGPC1chip(subset[i].photcode)) continue;
     175    startTimes[Nmoschip] = subset[i].tzero;
     176    Nmoschip ++;
     177  }
     178  sort_times (startTimes, Nmoschip);
    178179  MARKTIME("create array of all image obstimes: %f sec\n", dtime);
    179180 
     
    184185
    185186  // generate a list of the unique start times (these define the mosaics)
    186   for (i = 0; i < Nsubset; i++) {
    187     if (startTimes[i] < startTimesMosaic[Nmosaic]) {
    188       fprintf (stderr, "error?\n");
    189       abort();
    190     }
     187  for (i = 0; i < Nmoschip; i++) {
     188    myAssert (startTimes[i] >= startTimesMosaic[Nmosaic], "times out of order?");
    191189    if (startTimes[i] == startTimesMosaic[Nmosaic]) continue;
    192190    Nmosaic ++;
     
    210208  for (i = 0; i < Nmosaic; i++) {
    211209    /* a new mosaic, define ranges */
    212     mosaic[i].start = startTimesMosaic[i];
    213     mosaic[i].stop  = 0;
    214     mosaic[i].Mcal  = 0.0;
    215     mosaic[i].dMcal = 0.0;
    216     mosaic[i].dMsys = 0.0;
    217     mosaic[i].Xm    = 0.0;
    218     mosaic[i].flags = 0;
    219     mosaic[i].secz  = NAN;
     210    mosaic[i].start    = startTimesMosaic[i];
     211    mosaic[i].stop     = 0;
     212    mosaic[i].Mcal     = 0.0;
     213    mosaic[i].dMcal    = 0.0;
     214    mosaic[i].dMsys    = 0.0;
     215    mosaic[i].Xm       = 0.0;
     216    mosaic[i].flags    = 0;
     217    mosaic[i].secz     = NAN;
    220218    mosaic[i].photcode = 0;
    221     mosaic[i].skipCal = FALSE;
     219    mosaic[i].skipCal  = FALSE;
    222220   
    223221    memset (&mosaic[i].coords, 0, sizeof(Coords));
     
    238236    }
    239237   
    240     /* select valid mosaic images by photcode */
    241     pname = GetPhotcodeNamebyCode (image[i].photcode);
    242     if (!pname) continue;
    243     status = strncmp (pname, MOSAICNAME, strlen (MOSAICNAME));
    244     if (status) continue;
     238    if (!isGPC1chip(image[i].photcode)) continue;
    245239
    246240    /* set image time range */
     
    262256
    263257  // assign each image to a mosaic
     258  int Nsimple = 0;
    264259  for (i = 0; i < Nsubset; i++) {
    265260    ImageToMosaic[i] = -1;
    266261
    267     /* select valid mosaic images by photcode */
    268     pname = GetPhotcodeNamebyCode (subset[i].photcode);
    269     status = strncmp (pname, MOSAICNAME, strlen (MOSAICNAME));
    270     if (status) continue;
     262    if (!isGPC1chip(subset[i].photcode)) {
     263      Nsimple ++;
     264      continue;
     265    }
    271266
    272267    start = subset[i].tzero;
     
    299294      abort();
    300295    }
    301     mosaic[j].stop  = stop;
    302     mosaic[j].Mcal  = 0.0;
    303     mosaic[j].dMcal = 0.0;
    304     mosaic[j].Xm    = 0.0;
    305     mosaic[j].dMsys = subset[i].flags;
    306     mosaic[j].flags = subset[i].flags;
    307     mosaic[j].secz  = subset[i].secz;
     296    mosaic[j].stop     = stop;
     297    mosaic[j].Mcal     = 0.0;
     298    mosaic[j].dMcal    = 0.0;
     299    mosaic[j].Xm       = 0.0;
     300    mosaic[j].dMsys    = subset[i].flags;
     301    mosaic[j].flags    = subset[i].flags;
     302    mosaic[j].secz     = subset[i].secz;
    308303    mosaic[j].photcode = GetPhotcodeEquivCodebyCode (subset[i].photcode);
    309304  }
     
    316311  initMosaicGrid (subset, Nsubset);
    317312
    318   fprintf (stderr, "matched %d images to %d mosaics\n", (int) Nsubset, (int) Nmosaic);
     313  fprintf (stderr, "matched %d images to %d mosaics, %d simple chips not matched to mosaics\n", (int) (Nsubset - Nsimple), (int) Nmosaic, (int) Nsimple);
    319314  return;
     315}
     316
     317/* find mosaic frames (unique time periods) (NOTE : require gpc1 chips, which is pretty limiting)
     318   if mergeMcal is TRUE, <image.Mcal> values will be saved on Mosaic.Mcal
     319 */
     320void makeMosaics (Image *image, off_t Nimage, int mergeMcal) {
     321
     322  off_t i, j, found, NMOSAIC, *MosaicN_IMAGE;
     323  unsigned int start, stop, *startTimes, *startTimesMosaic;
     324
     325  if (!MOSAIC_ZEROPT) return;
     326
     327  INITTIME;
     328
     329  /* a 'mosaic' in relphot is (unlike relastro) a virtual concept: there is no
     330   * entry in the image table that represents this mosaic.  Instead, it is an
     331   * internal construct that defines a group of related images
     332   */
     333
     334  // generate a list of all image start times
     335  ALLOCATE (startTimes, unsigned int, Nimage);
     336  int Nmoschip = 0;
     337  for (i = 0; i < Nimage; i++) {
     338    if (!isGPC1chip(image[i].photcode)) continue;
     339    startTimes[Nmoschip] = image[i].tzero;
     340    Nmoschip ++;
     341  }
     342  sort_times (startTimes, Nmoschip);
     343  MARKTIME("create array of all image obstimes: %f sec\n", dtime);
     344 
     345  Nmosaic = 0;
     346  NMOSAIC = 1000;
     347  ALLOCATE (startTimesMosaic, unsigned int, NMOSAIC);
     348  startTimesMosaic[0] = startTimes[0];
     349
     350  // generate a list of the unique start times (these define the mosaics)
     351  for (i = 0; i < Nmoschip; i++) {
     352    myAssert (startTimes[i] >= startTimesMosaic[Nmosaic], "times out of order?");
     353    if (startTimes[i] == startTimesMosaic[Nmosaic]) continue;
     354    Nmosaic ++;
     355    if (Nmosaic >= NMOSAIC) {
     356      NMOSAIC += 1000;
     357      REALLOCATE (startTimesMosaic, unsigned int, NMOSAIC);
     358    }
     359    startTimesMosaic[Nmosaic] = startTimes[i];
     360  }
     361  Nmosaic ++;
     362  MARKTIME("create array of mosaic obstimes: %f sec\n", dtime);
     363
     364  // now I have a list of uniq start times, and they are in order
     365  // create the mosaic arrays for these times
     366  ALLOCATE (mosaic, Mosaic, Nmosaic);
     367
     368  ALLOCATE (MosaicToImage, off_t *, Nmosaic);
     369  ALLOCATE (MosaicN_Image, off_t,   Nmosaic);
     370  ALLOCATE (MosaicN_IMAGE, off_t,   Nmosaic);
     371
     372  // init the mosaic array values
     373  for (i = 0; i < Nmosaic; i++) {
     374    mosaic[i].start    = startTimesMosaic[i];
     375    mosaic[i].stop     = 0;
     376    mosaic[i].Mcal     = 0.0;
     377    mosaic[i].dMcal    = 0.0;
     378    mosaic[i].dMsys    = 0.0;
     379    mosaic[i].Xm       = 0.0;
     380    mosaic[i].flags    = 0;
     381    mosaic[i].secz     = NAN;
     382    mosaic[i].photcode = 0;
     383    mosaic[i].skipCal  = FALSE;
     384   
     385    memset (&mosaic[i].coords, 0, sizeof(Coords));
     386
     387    MosaicN_IMAGE[i] = 10;
     388    MosaicN_Image[i] = 0;
     389    ALLOCATE (MosaicToImage[i], off_t, MosaicN_IMAGE[i]);
     390    MosaicToImage[i][0] = -1;
     391  }
     392
     393  ALLOCATE (ImageToMosaic, off_t, Nimage); // mosaic to which image belongs
     394
     395  // assign each image to a mosaic
     396  int Nsimple = 0;
     397  for (i = 0; i < Nimage; i++) {
     398    ImageToMosaic[i] = -1;
     399
     400    if (!isGPC1chip(image[i].photcode)) {
     401      Nsimple ++;
     402      continue;
     403    }
     404
     405    start = image[i].tzero;
     406    stop  = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1);
     407
     408    j = findMosaic(startTimesMosaic, Nmosaic, start);
     409    if (j == -1) {
     410      fprintf (stderr, "programming error? all image images should belong to a mosaic\n");
     411      abort();
     412    }
     413
     414    // add reference from image to mosaic
     415    ImageToMosaic[i] = j;
     416
     417    // have we already found this mosaic?
     418    found = (MosaicN_Image[j] > 0);
     419
     420    /* add image to mosaic image list */
     421    MosaicToImage[j][MosaicN_Image[j]] = i;
     422    MosaicN_Image[j] ++;
     423    if (MosaicN_Image[j] == MosaicN_IMAGE[j]) {
     424      MosaicN_IMAGE[j] += 10;
     425      REALLOCATE (MosaicToImage[j], off_t, MosaicN_IMAGE[j]);
     426    }
     427    if (found) continue;
     428   
     429    /* a new mosaic, define ranges */
     430    if (mosaic[j].start != start) {
     431      fprintf (stderr, "error?\n");
     432      abort();
     433    }
     434    mosaic[j].stop     = stop;
     435    mosaic[j].Mcal     = 0.0;
     436    mosaic[j].dMcal    = 0.0;
     437    mosaic[j].Xm       = 0.0;
     438    mosaic[j].dMsys    = image[i].flags;
     439    mosaic[j].flags    = image[i].flags;
     440    mosaic[j].secz     = image[i].secz;
     441    mosaic[j].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode);
     442  }
     443  MARKTIME("assign images to mosaic: %f sec\n", dtime);
     444
     445  // free this or not?
     446  free (MosaicN_IMAGE);
     447  free (startTimes);
     448  free (startTimesMosaic);
     449
     450  if (mergeMcal) {
     451    initMosaicGrid (image, Nimage);
     452  }
     453
     454  fprintf (stderr, "matched %d images to %d mosaics\n", (int) Nimage, (int) Nmosaic);
     455  return;
     456}
     457
     458Mosaic *getMosaicForImage (off_t im) {
     459
     460  if (im < 0) return NULL;
     461  if (!ImageToMosaic) return NULL;
     462
     463  off_t m = ImageToMosaic[im];
     464  if (m < 0) return NULL;
     465  if (m >= Nmosaic) return NULL;
     466
     467  return (&mosaic[m]);
    320468}
    321469
     
    352500}
    353501
     502void setMosaicCenters (Image *image, off_t Nimage) {
     503
     504  /* find max dR, dD range for all mosaics */
     505  /* define mosaic.coords to cover dR, dD */
     506  /* send results to initGridBins */
     507
     508  off_t i, j, m, NX, NY, NC, Nc;
     509  double R, D, Rmid, Dmid;
     510  double *Rc, *Dc;
     511
     512  NC = 100;
     513  ALLOCATE (Rc, double, NC);
     514  ALLOCATE (Dc, double, NC);
     515
     516  for (i = 0; i < Nmosaic; i++) {
     517    Nc = 0;
     518    Rmid = Dmid = NAN;
     519    for (j = 0; j < MosaicN_Image[i]; j++) {
     520      m = MosaicToImage[i][j];
     521
     522      if (!FindMosaicForImage (image, Nimage, m)) {
     523        if (VERBOSE2) fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
     524        continue;
     525      }
     526
     527      NX = image[m].NX;
     528      NY = image[m].NY;
     529      XY_to_RD (&R, &D, 0.5*NX, 0.5*NY, &image[m].coords);
     530      R = ohana_normalize_angle_to_midpoint (R, 180.0);
     531
     532      // Exclude images with crazy astrometry
     533      // XXX NOTE : this is gpc1-specific
     534      {
     535        double dP1 = hypot(image[m].coords.pc1_1, image[m].coords.pc1_2);
     536        double dP2 = hypot(image[m].coords.pc2_1, image[m].coords.pc2_2);
     537        if (fabs(dP1 - 1.0) > 0.02) continue;
     538        if (fabs(dP2 - 1.0) > 0.02) continue;
     539
     540        double X00, Y00, X10, Y10, X01, Y01;
     541        XY_to_LM (&X00, &Y00, 0.0, 0.0, &image[m].coords);
     542        XY_to_LM (&X10, &Y10, image[m].NX, 0.0, &image[m].coords);
     543        XY_to_LM (&X01, &Y01, 0.0, image[m].NY, &image[m].coords);
     544        double dS0 = hypot ((X00 - X10), (Y00 - Y10));
     545        double dS1 = hypot ((X00 - X01), (Y00 - Y01));
     546        if (dS0 > 6000) continue;
     547        if (dS1 > 6500) continue;
     548      }
     549
     550      Rc[Nc] = R;
     551      Dc[Nc] = D;
     552      Nc ++;
     553      if (Nc >= NC) {
     554        NC += 100;
     555        REALLOCATE (Rc, double, NC);
     556        REALLOCATE (Dc, double, NC);
     557      }
     558    }
     559
     560    if (Nc > 0) {
     561      dsort (Rc, Nc);
     562      if (Rc[Nc-1] - Rc[0] > 180.0) {
     563        // in our list, Rc is in the range 0.0 to 360.0. 
     564        // any mosaic which is close to the 0.0, 360.0 boundary may have some on
     565        // one side or the other.  count how many have values more than Rc[0] + 180.
     566        // if more than half are at the large end, re-normalize to that range
     567        int Nbig = 0;
     568        for (j = 1; j < Nc; j++) {
     569          if (Rc[j] - Rc[0] > 180.0) Nbig ++;
     570        }
     571        if (Nbig  > 0.5*Nc) {
     572          for (j = 0; j < Nc; j++) {
     573            Rc[j] = ohana_normalize_angle_to_midpoint (Rc[j], 360.0);
     574          }
     575          dsort (Rc, Nc);
     576        } else if (Nbig > 0) {
     577          for (j = 0; j < Nc; j++) {
     578            Rc[j] = ohana_normalize_angle_to_midpoint (Rc[j], 0.0);
     579          }
     580          dsort (Rc, Nc);
     581        }
     582      }
     583      dsort (Dc, Nc);
     584
     585      Rmid = Rc[(int)(0.5*Nc)];
     586      Dmid = Dc[(int)(0.5*Nc)];
     587    }
     588
     589    strcpy (mosaic[i].coords.ctype, "DEC--TAN");
     590    mosaic[i].coords.crval1 = Rmid;
     591    mosaic[i].coords.crval2 = Dmid;
     592    mosaic[i].coords.crpix1 = 0.0;
     593    mosaic[i].coords.crpix2 = 0.0;
     594    mosaic[i].coords.cdelt1 = 1.0 / 3600.0;
     595    mosaic[i].coords.cdelt2 = 1.0 / 3600.0;
     596    mosaic[i].coords.pc1_1  = 1.0;
     597    mosaic[i].coords.pc2_2  = 1.0;
     598    mosaic[i].coords.pc1_2  = 0.0;
     599    mosaic[i].coords.pc2_1  = 0.0;
     600
     601    mosaic[i].Mcal   = 0.0;
     602    mosaic[i].dMcal  = 0.0;
     603    mosaic[i].Xm     = 0.0;
     604  }
     605  return;
     606}
     607
    354608void initMosaicGrid (Image *image, off_t Nimage) {
    355609
     
    363617  double R, D, Rmin, Rmax, Dmin, Dmax;
    364618  double Mcal, dMcal, Xm;
     619
     620  fprintf (stderr, "*** moving Mcal from image.Mcal to mosaic.Mcal ***\n");
    365621
    366622  dXmax = dYmax = 0.0;
     
    395651      Dmin = MIN (Dmin, D);
    396652      Dmax = MAX (Dmax, D);
     653
     654      /* we are using mosaic.Mcal, not image.Mcal. reset image.Mcal */
     655
     656      // XXX: how does this work with UBERCAL?  We want to keep the Mcal values supplied by ubercal, but
     657      // solve for a single offset for each exposure (Mosaic.Mcal). 
     658      // we also want to keep the flat-field terms for each exposure (regardless of ubercal or not)
     659      // if it helps, note that ubercal uses a single zp per exposure, so the mean of those values is the same as the value
     660
    397661      Mcal  += image[m].Mcal;
    398662      dMcal += image[m].dMcal;
    399663      Xm    += image[m].Xm;
    400664
    401       // XXX: how does this work with UBERCAL?  We want to keep the Mcal values supplied by ubercal, but
    402       // solve for a single offset for each exposure (Mosaic.Mcal). 
    403 
    404       // we also want to keep the flat-field terms for each exposure (regardless of ubercal or not)
    405 
    406       // if it helps, note that ubercal uses a single zp per exposure, so the mean of those values is the same as the value
    407 
    408       /* we are using mosaic.Mcal, not image.Mcal. reset image.Mcal */
    409       image[m].Mcal  = 0.0;
    410       image[m].dMcal = NAN;
    411       image[m].Xm    = NAN_S_SHORT;
     665      image[m].Mcal   = 0.0;
     666      image[m].dMcal  = NAN;
     667      image[m].Xm     = NAN_S_SHORT;
    412668    }
    413669    dS /= MosaicN_Image[i];
    414     strcpy (mosaic[i].coords.ctype, "RA---TAN");
     670    strcpy (mosaic[i].coords.ctype, "DEC--TAN");
    415671    mosaic[i].coords.crval1 = Rmin;
    416672    mosaic[i].coords.crval2 = Dmin;
     
    425681    RD_to_XY (&dX, &dY, Rmax, Dmax, &mosaic[i].coords);
    426682
    427     mosaic[i].Mcal  = Mcal / MosaicN_Image[i];
    428     mosaic[i].dMcal = dMcal / MosaicN_Image[i];
    429     mosaic[i].Xm    = Xm / MosaicN_Image[i];
     683    mosaic[i].Mcal   = Mcal / MosaicN_Image[i];
     684    mosaic[i].dMcal  = dMcal / MosaicN_Image[i];
     685    mosaic[i].Xm     = Xm / MosaicN_Image[i];
    430686  }
    431687  if (!USE_GRID) return;
     
    437693}
    438694
    439 // XXX : what about mosaics with skipCal == TRUE?
    440695void setMcalFinal () {
    441696
     
    447702  image = getimages (&Nimage, NULL);
    448703
    449   // XXX I think this is OK in the ubercal context, but probably need to skip UBERCAL
    450   // images? (no need to update them)
     704  fprintf (stderr, "*** return Mcal from mosaic.Mcal to image.Mcal ***\n");
    451705
    452706  // copy the mosaic results to the images.  set the mosaic Mcal to 0.0 since we have moved its
     
    527781
    528782  if (!MOSAIC_ZEROPT) return (FALSE);
     783  // if we are calibrating by mosaic, redefine myDet == on one of my mosaics
    529784
    530785  int Nmatch = 0;
    531786  for (i = 0; i < Ncatalog; i++) {
    532787    for (j = 0; j < catalog[i].Nmeasure; j++) {
     788      catalog[i].measureT[j].myDet = FALSE; // a detetion is not mine until proven otherwise
     789
    533790      if (TimeSelect) {
    534791        if (catalog[i].measureT[j].t < TSTART) continue;
     
    565822  mosID = ImageToMosaic[idx];
    566823  if (mosID < 0) {
    567     Image *image = getimage(idx);
    568     fprintf (stderr, "unmatched image %s\n", image[0].name);
     824    // Image *image = getimage(idx);
     825    // fprintf (stderr, "unmatched image %s\n", image[0].name);
     826    // skip measurements from simple chips (not matched to a mosaic by definition)
    569827    return;
    570828  }
     
    582840  }
    583841
     842  // this measurement is on one of my mosaics, mark it as mine.
     843  catalog[cat].measureT[meas].myDet = TRUE;
    584844  MeasureToMosaic[cat][meas] = mosID;
    585845
     
    605865  if (!MOSAIC_ZEROPT) return (0);
    606866
     867  // unassigned measurements belong to simple chips
    607868  i = MeasureToMosaic[cat][meas];
    608   if (i == -1) return (NAN);
     869  if (i == -1) return (0.0);
    609870
    610871  if (mosaic[i].flags & IMAGE_BAD) return (NAN); 
     
    8501111
    8511112      off_t n = catalog[c].measureT[m].averef;
    852       Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
     1113      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
    8531114
    8541115      float delta = Msys - Mrel - Mcal - Mgrid + Mflat;
     
    8871148
    8881149    off_t n = catalog[c].measureT[m].averef;
    889     Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
     1150    Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
    8901151    if (isnan(Msys)) {
    8911152      info->Nsys++;
     
    9621223
    9631224  if (testImage) {
    964     fprintf (stderr, "%f %f  :  %d %f\n", myMosaic[0].Mcal, myMosaic[0].dMsys, myMosaic[0].Xm, pow(10.0, 0.01*myMosaic[0].Xm));
     1225    fprintf (stderr, "%f %f  :  %f\n", myMosaic[0].Mcal, myMosaic[0].dMsys, pow (10.0, 0.01*myMosaic[0].Xm));
    9651226  }
    9661227
     
    13151576    if (mosaic[i].flags & IMAGE_BAD) continue;
    13161577    if (mosaic[i].skipCal) continue;
     1578    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
     1579
    13171580    list[n] = mosaic[i].Mcal;
    13181581    dlist[n] = 1;
     
    13451608    if (mosaic[i].flags & IMAGE_BAD) continue;
    13461609    if (mosaic[i].skipCal) continue;
     1610    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
     1611
    13471612    list[n] = mosaic[i].dMcal;
    13481613    dlist[n] = 1;
     
    13761641    if (mosaic[i].flags & IMAGE_BAD)  continue;
    13771642    if (mosaic[i].skipCal) continue;
     1643    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
    13781644
    13791645    N = 0;
     
    14221688    if (mosaic[i].flags & IMAGE_BAD) continue;
    14231689    if (mosaic[i].skipCal) continue;
    1424     list[n] = pow(10.0, 0.01*mosaic[i].Xm);
     1690    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
     1691
     1692    list[n]  = pow (10.0, 0.01*mosaic[i].Xm);
    14251693    dlist[n] = 1;
    14261694    n++;
     
    15051773void plot_mosaic_fields (Catalog *catalog) {
    15061774
    1507   off_t i, j, m, c, N, ave, Nimage;
     1775  off_t i, j, m, c, N, Nimage;
    15081776  double *xlist, *ylist;
    1509   // double Xmin, Xmax, Ymin, Ymax;
    15101777  char string[64];
    15111778  Graphdata graphdata;
     
    15261793  for (i = 0; i < Nmosaic; i++) {
    15271794    N = 0;
    1528     // Xmin = Ymin = +360.0;
    1529     // Xmax = Ymax = -360.0;
    15301795    for (j = 0; j < N_onMosaic[i]; j++) {
    15311796     
     
    15351800      if (catalog[c].measureT[m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;
    15361801
    1537       ave = catalog[c].measureT[m].averef;
    1538       xlist[N] = catalog[c].averageT[ave].R - catalog[c].measureT[m].dR / 3600.0;
    1539       ylist[N] = catalog[c].averageT[ave].D - catalog[c].measureT[m].dD / 3600.0;
     1802      // ave = catalog[c].measureT[m].averef;
     1803      xlist[N] = catalog[c].measureT[m].R;
     1804      ylist[N] = catalog[c].measureT[m].D;
    15401805      N++;
    15411806    }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/Shutdown.c

    r33651 r37067  
    2323  SetProtect (TRUE);
    2424  if (db) gfits_db_close (db);
    25   fprintf (stderr, "ERROR: addstar halted\n");
     25  fprintf (stderr, "ERROR: relphot halted\n");
    2626  exit (1);
    2727}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/StarOps.c

    r35759 r37067  
    6363  results->Ngrid = 0;
    6464  if (allocLists) {
    65     ALLOCATE (results->list, double, Nmax);
    66     ALLOCATE (results->dlist, double, Nmax);
    67     ALLOCATE (results->wlist, double, Nmax);
     65    ALLOCATE (results->Mpsflist, double, Nmax);
     66    ALLOCATE (results->dpsflist, double, Nmax);
     67    ALLOCATE (results->wpsflist, double, Nmax);
    6868  }
    6969}
    7070
    7171void SetMrelInfoFree (SetMrelInfo *results) {
    72   free (results->list);
    73   free (results->dlist);
    74   free (results->wlist);
     72  free (results->Mpsflist);
     73  free (results->dpsflist);
     74  free (results->wpsflist);
    7575}
    7676
    7777void SetMrelInfoAccum (SetMrelInfo *summary, SetMrelInfo *results) {
    7878  summary->Nfew  += results->Nfew ;
    79   summary->Ncode  += results->Ncode ;
     79  summary->Ncode += results->Ncode ;
    8080  summary->Nsys  += results->Nsys ;
    8181  summary->Nbad  += results->Nbad ;
     
    153153  int i;
    154154
     155  // fprintf (stderr, "this version of setMrel is invalid for now\n");
     156  // exit (1);
     157       
    155158  int Nsecfilt = GetPhotcodeNsecfilt ();
    156159
     
    158161  SetMrelInfoInit (&summary, FALSE);
    159162  SetMrelInfoInit (&results, TRUE); // allocates results->list,dlist,wlist
    160   ALLOCATE (results.aplist, double, Nmax);
    161   ALLOCATE (results.kronlist, double, Nmax);
     163
     164  ALLOCATE (results.Maplist,  double, Nmax);
     165  ALLOCATE (results.daplist,  double, Nmax);
     166  ALLOCATE (results.waplist,  double, Nmax);
     167
     168  ALLOCATE (results.Mkronlist, double, Nmax);
    162169  ALLOCATE (results.dkronlist, double, Nmax);
     170  ALLOCATE (results.wkronlist, double, Nmax);
    163171
    164172  ALLOCATE (results.psfqf_list, double, Nmax);
     
    183191
    184192  SetMrelInfoFree (&results);
    185   free (results.aplist);
    186   free (results.kronlist);
     193  free (results.Maplist);
     194  free (results.daplist);
     195  free (results.waplist);
     196
     197  free (results.Mkronlist);
    187198  free (results.dkronlist);
     199  free (results.wkronlist);
    188200
    189201  free (results.psfqf_list);
     
    328340int setMrel_catalog (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt) {
    329341
     342  fprintf (stderr, "??? should you still be using the old version of setMrel_catalog??\n");
     343  exit (3);
     344
     345# if (0)
     346
    330347  off_t j, k, m, ID;
    331348  int N;
     
    333350
    334351  StatType stats, apstats, kronstats;
    335   liststats_setmode (&stats, STATMODE);
     352  liststats_setmode (&psfstats, STATMODE);
    336353  liststats_setmode (&apstats, STATMODE);
    337354  liststats_setmode (&kronstats, STATMODE);
     
    366383    if (isSetMrelFinal) {
    367384      // set the name of the primary skycell (this is used in a strcmp to match the skycells in stack detections)
    368       BoundaryTreePrimaryCell(primaryCell, catalog[Nc].average[j].R, catalog[Nc].average[j].D);
     385      // XXX : this whole function is deprecated
     386      // BoundaryTreePrimaryCell(primaryCell, catalog[Nc].average[j].R, catalog[Nc].average[j].D);
    369387    }
    370388
     
    392410
    393411      /* star/photcodes already calibrated */
    394       if ( isSetMrelFinal && catalog[Nc].found[Nsecfilt*j+Nsec]) continue; 
     412      if ( isSetMrelFinal && catalog[Nc].found_t[Nsecfilt*j+Nsec]) continue; 
    395413     
    396414      // skip bad stars
     
    452470
    453471        // skip some absurd values NAN, < 0.0, > 30.0
    454         Msys = PhotSysTiny (&catalog[Nc].measureT[m], &catalog[Nc].averageT[j], &catalog[Nc].secfilt[j*Nsecfilt]);
     472        Msys = PhotSysTiny (&catalog[Nc].measureT[m], &catalog[Nc].averageT[j], &catalog[Nc].secfilt[j*Nsecfilt], MAG_CLASS_PSF);
    455473        if (isnan(Msys)) SKIP_THIS_MEAS(Nsys);
    456474        if (Msys <  0.0) SKIP_THIS_MEAS(Nsys);
     
    655673      liststats (list, dlist, wlist, N, &stats);
    656674
    657       catalog[Nc].secfilt[Nsecfilt*j+Nsec].M  = stats.mean;
    658       catalog[Nc].secfilt[Nsecfilt*j+Nsec].dM = stats.error;
    659       catalog[Nc].secfilt[Nsecfilt*j+Nsec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq + 1e-4) : NAN_S_SHORT;
     675      catalog[Nc].secfilt[Nsecfilt*j+Nsec].M      = stats.mean;
     676      catalog[Nc].secfilt[Nsecfilt*j+Nsec].dM     = stats.error;
     677      catalog[Nc].secfilt[Nsecfilt*j+Nsec].Mchisq = (stats.Nmeas > 1) ? stats.chisq : NAN;
    660678
    661679      // when running -averages, we have no information about the images, so we cannot set this
     
    665683
    666684      if (isSetMrelFinal) {
    667         catalog[Nc].found[Nsecfilt*j+Nsec] = TRUE;
     685        catalog[Nc].found_t[Nsecfilt*j+Nsec] = TRUE;
    668686
    669687        catalog[Nc].secfilt[Nsecfilt*j+Nsec].Mstdev = 1000.0*stats.sigma; // Mstdev is in millimags (not enough space for more precision)
     
    833851  if (primaryCell) free (primaryCell);
    834852  return (TRUE);
     853# endif
    835854}
    836855
     
    892911}
    893912
     913int markObjects (Catalog *catalog, int Ncatalog) {
     914
     915  int i, n;
     916  off_t j;
     917
     918  // How strongly do I own this object?
     919  for (i = 0; i < Ncatalog; i++) {
     920    for (j = 0; j < catalog[i].Naverage; j++) {
     921      int nOwn = 0;
     922      int m = catalog[i].averageT[j].measureOffset;
     923      for (n = 0; n < catalog[i].averageT[j].Nmeasure; n++) {
     924        if (!catalog[i].measureT[m+n].myDet) continue;
     925        nOwn ++;
     926      }
     927      catalog[i].averageT[j].nOwn = nOwn;
     928    }
     929  }
     930  return TRUE;
     931}
     932
     933int dumpObjects (char *filename, Catalog *catalog, int Ncatalog) {
     934
     935  int i, n;
     936  off_t j;
     937
     938  FILE *ftest = fopen (filename, "w");
     939
     940  for (i = 0; i < Ncatalog; i++) {
     941    for (j = 0; j < catalog[i].Naverage; j++) {
     942      int m = catalog[i].averageT[j].measureOffset;
     943      for (n = 0; n < catalog[i].averageT[j].Nmeasure; n++) {
     944        fprintf (ftest, "%08x %08x %10.6f %10.6f  %3d %1d\n", catalog[i].averageT[j].catID, catalog[i].averageT[j].objID, catalog[i].averageT[j].R, catalog[i].averageT[j].D, catalog[i].averageT[j].Nmeasure, catalog[i].measureT[m+n].myDet);
     945      }
     946    }
     947  }
     948  fclose (ftest);
     949  return TRUE;
     950}
     951
    894952void clean_stars (Catalog *catalog, int Ncatalog) {
    895953
    896954  int i, j, Ndel, Nave, Ntot, mark, Ns, Nscat, Nchi, Nnan;
    897   float dM, Xm;
    898   double Chisq, MaxScatter, MaxChisq;
     955  float dM;
     956  double MaxScatter, MaxChisq;
    899957  double *xlist, *slist, *dlist;
    900958
     
    923981      for (j = 0; j < catalog[i].Naverage; j++) {
    924982        if ( catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD ) continue;
    925         Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
    926         if (Xm == -1) continue;
    927         Chisq = pow (10.0, 0.01*Xm);
    928         xlist[Ntot] = Chisq;
     983        float Mchisq = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq;
     984        if (isnan(Mchisq)) continue;
     985        xlist[Ntot] = Mchisq;
    929986        slist[Ntot] = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
    930987        dlist[Ntot] = 1;
     
    9441001      for (j = 0; j < catalog[i].Naverage; j++) {
    9451002        dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
    946         Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
    947         Chisq = pow (10.0, 0.01*Xm);
    948         mark = (dM > MaxScatter) || (Xm == NAN_S_SHORT) || (Chisq > MaxChisq);
     1003        float Mchisq = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq;
     1004        mark = (dM > MaxScatter) || (isnan(Mchisq)) || (Mchisq > MaxChisq);
    9491005        if (mark) {
    9501006          catalog[i].secfilt[Nsecfilt*j+Nsec].flags |= ID_STAR_POOR;
    9511007          Ndel ++;
    952           if (dM > MaxScatter) { Nscat ++; }
    953           if (Xm == NAN_S_SHORT) { Nnan ++; }
    954           if (Chisq > MaxChisq) { Nchi ++; }
     1008          if (dM > MaxScatter)   { Nscat ++; }
     1009          if (isnan(Mchisq))    { Nnan ++; }
     1010          if (Mchisq > MaxChisq) { Nchi ++; }
    9551011        } else {
    9561012          catalog[i].secfilt[Nsecfilt*j+Nsec].flags &= ~ID_STAR_POOR;
     
    10171073       
    10181074        /* on final processing, skip stars already measured */
    1019         if (final && catalog[i].found[Nsecfilt*j + Nsec]) continue; 
     1075        if (final && catalog[i].found_t[Nsecfilt*j + Nsec]) continue; 
    10201076
    10211077        /* skip bad stars to prevent them from becoming good (on inner sample) */
     
    10381094          if (isnan(Mgrid)) { Ngrid ++; continue; }
    10391095
    1040           Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]);
     1096          Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF);
    10411097          list[N] = Msys - Mcal - Mmos - Mgrid;
    10421098          dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);
     
    10831139          if (isnan(Mgrid)) continue;
    10841140
    1085           Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]);
     1141          Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF);
    10861142          list[N] = Msys - Mcal - Mmos - Mgrid;
    10871143          dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);
     
    11781234
    11791235  off_t j, Ntot;
    1180   int i, n, Xm;
     1236  int i, n;
    11811237  double *list, *dlist;
    11821238  StatType stats;
     
    11991255      if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 
    12001256       
    1201       Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
    1202       if (Xm == NAN_S_SHORT) continue;
    1203       list[n] = pow (10.0, 0.01*Xm);
     1257      float Mchisq = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq;
     1258      if (isnan(Mchisq)) continue;
     1259      list[n] = Mchisq;
    12041260      dlist[n] = 1;
    12051261      n++;
     
    13221378        if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue;
    13231379        xlist[N] = catalog[i].secfilt[Nsecfilt*j+Nsec].M;
    1324         value    = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
    1325         if (value == NAN_S_SHORT) continue;
    1326         ylist[N] = 0.01*value;
     1380        value    = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq;
     1381        if (isnan(value)) continue;
     1382        ylist[N] = value;
    13271383        N++;
    13281384      }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/args.c

    r35806 r37067  
    11# include "relphot.h"
    22
    3 int args (int argc, char **argv) {
     3RelphotMode args (int argc, char **argv) {
    44
    55  int N;
    66  double trange;
     7
     8  /* define time */
     9  TimeSelect = FALSE;
     10  if ((N = get_argument (argc, argv, "-time"))) {
     11    remove_argument (N, &argc, argv);
     12    if (!ohana_str_to_time (argv[N], &TSTART)) {
     13      fprintf (stderr, "ERROR: syntax error\n");
     14      return (MODE_ERROR);
     15    }
     16    remove_argument (N, &argc, argv);
     17    if (!ohana_str_to_dtime (argv[N], &trange)) {
     18      if (!ohana_str_to_time (argv[N], &TSTOP)) {
     19        fprintf (stderr, "ERROR: syntax error\n");
     20        return (MODE_ERROR);
     21      }
     22    } else {
     23      if (trange < 0) {
     24        trange = fabs (trange);
     25        TSTOP = TSTART;
     26        TSTART -= trange;
     27      } else {
     28        TSTOP = TSTART + trange;
     29      }
     30    }
     31    remove_argument (N, &argc, argv);
     32    TimeSelect = TRUE;
     33  }
     34
     35  /* specify portion of the sky */
     36  UserPatch.Rmin = 0;
     37  UserPatch.Rmax = 360;
     38  UserPatch.Dmin = -90;
     39  UserPatch.Dmax = +90;
     40  if ((N = get_argument (argc, argv, "-region"))) {
     41    remove_argument (N, &argc, argv);
     42    UserPatch.Rmin = atof (argv[N]);
     43    remove_argument (N, &argc, argv);
     44    UserPatch.Rmax = atof (argv[N]);
     45    remove_argument (N, &argc, argv);
     46    UserPatch.Dmin = atof (argv[N]);
     47    remove_argument (N, &argc, argv);
     48    UserPatch.Dmax = atof (argv[N]);
     49    remove_argument (N, &argc, argv);
     50  }
     51
     52  /* specify region file by name (eg n0000/0000.00) */
     53  UserCatalog = NULL;
     54  if ((N = get_argument (argc, argv, "-catalog"))) {
     55    remove_argument (N, &argc, argv);
     56    UserCatalog = strcreate (argv[N]);
     57    remove_argument (N, &argc, argv);
     58  }
     59
     60  USE_BASIC_CHECK = FALSE;
     61  if ((N = get_argument (argc, argv, "-basic-image-search"))) {
     62    remove_argument (N, &argc, argv);
     63    USE_BASIC_CHECK = TRUE;
     64  }
     65
     66  USE_FULL_OVERLAP = TRUE;
     67  if ((N = get_argument (argc, argv, "-sloppy-image-overlap"))) {
     68    remove_argument (N, &argc, argv);
     69    USE_FULL_OVERLAP = FALSE;
     70  }
     71
     72  SET_MREL_VERSION = 1;
     73  if ((N = get_argument (argc, argv, "-set-mrel-version"))) {
     74    remove_argument (N, &argc, argv);
     75    SET_MREL_VERSION = atof(argv[N]);
     76    remove_argument (N, &argc, argv);
     77  }
     78
     79  VERBOSE = VERBOSE2 = FALSE;
     80  if ((N = get_argument (argc, argv, "-v"))) {
     81    VERBOSE = TRUE;
     82    remove_argument (N, &argc, argv);
     83  }
     84  if ((N = get_argument (argc, argv, "-vv"))) {
     85    VERBOSE2 = VERBOSE = TRUE;
     86    remove_argument (N, &argc, argv);
     87  }
     88
     89  NTHREADS = 0;
     90  if ((N = get_argument (argc, argv, "-threads"))) {
     91    remove_argument (N, &argc, argv);
     92    NTHREADS = atof (argv[N]);
     93    remove_argument (N, &argc, argv);
     94  }
     95
     96  // XXX for the moment, make this selection manual.  it needs to be automatic
     97  // based on the state of the SkyTable
     98  HOST_ID = 0;
     99  PARALLEL = FALSE;
     100  if ((N = get_argument (argc, argv, "-parallel"))) {
     101    PARALLEL = TRUE;
     102    remove_argument (N, &argc, argv);
     103  }
     104  // this is a test mode : rather than launching the remote jobs and waiting for completion,
     105  // relphot will simply list the remote command and wait for the user to signal completion
     106  PARALLEL_MANUAL = FALSE;
     107  if ((N = get_argument (argc, argv, "-parallel-manual"))) {
     108    PARALLEL = TRUE; // -parallel-manual implies -parallel
     109    PARALLEL_MANUAL = TRUE;
     110    remove_argument (N, &argc, argv);
     111  }
     112  // this is a test mode : rather than launching the relphot_client jobs remotely, they are
     113  // run in serial via 'system'
     114  PARALLEL_SERIAL = FALSE;
     115  if ((N = get_argument (argc, argv, "-parallel-serial"))) {
     116    if (PARALLEL_MANUAL) {
     117      fprintf (stderr, "ERROR: cannot mix -parallel-manual and -parallel-serial\n");
     118      exit (1);
     119    }
     120    PARALLEL = TRUE; // -parallel-serial implies -parallel
     121    PARALLEL_SERIAL = TRUE;
     122    remove_argument (N, &argc, argv);
     123  }
     124
     125  PLOTSTUFF = FALSE;
     126  if ((N = get_argument (argc, argv, "-plot"))) {
     127    PLOTSTUFF = TRUE;
     128    remove_argument (N, &argc, argv);
     129  }
     130
     131  PLOTDELAY = 500000;
     132  if ((N = get_argument (argc, argv, "-plotdelay"))) {
     133    remove_argument (N, &argc, argv);
     134    PLOTDELAY = 1e6*atof(argv[N]);
     135    PLOTSTUFF = TRUE; // always turn on plotting if i request a plot delay
     136    remove_argument (N, &argc, argv);
     137  }
     138
     139  if ((N = get_argument (argc, argv, "-outroot"))) {
     140    remove_argument (N, &argc, argv);
     141    OUTROOT = strcreate (argv[N]);
     142    remove_argument (N, &argc, argv);
     143  } else {
     144    OUTROOT = strcreate ("relphot");
     145  }     
     146
     147  strcpy (STATMODE, "WT_MEAN");
     148  if ((N = get_argument (argc, argv, "-statmode"))) {
     149    remove_argument (N, &argc, argv);
     150    strcpy (STATMODE, argv[N]);
     151    remove_argument (N, &argc, argv);
     152  }
     153
     154  NLOOP = 8;
     155  if ((N = get_argument (argc, argv, "-n"))) {
     156    remove_argument (N, &argc, argv);
     157    NLOOP = atof (argv[N]);
     158    remove_argument (N, &argc, argv);
     159  }
     160  if ((N = get_argument (argc, argv, "-nloop"))) {
     161    remove_argument (N, &argc, argv);
     162    NLOOP = atof (argv[N]);
     163    remove_argument (N, &argc, argv);
     164  }
     165
     166  NGRID = 8;
     167  if ((N = get_argument (argc, argv, "-ngrid"))) {
     168    remove_argument (N, &argc, argv);
     169    NGRID = atof (argv[N]);
     170    remove_argument (N, &argc, argv);
     171  }
     172
     173  RESET = FALSE;
     174  if ((N = get_argument (argc, argv, "-reset"))) {
     175    remove_argument (N, &argc, argv);
     176    RESET = TRUE;
     177  }
     178
     179  RESET_ZEROPTS = FALSE;
     180  if ((N = get_argument (argc, argv, "-reset-zpts"))) {
     181    remove_argument (N, &argc, argv);
     182    RESET_ZEROPTS = TRUE;
     183  }
     184
     185  UPDATE = FALSE;
     186  if ((N = get_argument (argc, argv, "-update"))) {
     187    remove_argument (N, &argc, argv);
     188    UPDATE = TRUE;
     189  }
     190
     191  UPDATE_CATFORMAT = NULL;
     192  if ((N = get_argument (argc, argv, "-update-catformat"))) {
     193    remove_argument (N, &argc, argv);
     194    UPDATE_CATFORMAT = strcreate (argv[N]);
     195    remove_argument (N, &argc, argv);
     196  }
     197
     198  SAVE_IMAGE_UPDATES = TRUE;
     199  if ((N = get_argument (argc, argv, "-skip-image-updates"))) {
     200    remove_argument (N, &argc, argv);
     201    SAVE_IMAGE_UPDATES = FALSE;
     202  }
     203
     204  MaxDensityUse = FALSE;
     205  if ((N = get_argument (argc, argv, "-max-density"))) {
     206    remove_argument (N, &argc, argv);
     207    MaxDensityValue = atof(argv[N]);
     208    remove_argument (N, &argc, argv);
     209    MaxDensityUse = TRUE;
     210  }
     211
     212  CLOUD_TOLERANCE = 0.02;
     213  if ((N = get_argument (argc, argv, "-cloud-limit"))) {
     214    remove_argument (N, &argc, argv);
     215    CLOUD_TOLERANCE = atof(argv[N]);
     216    remove_argument (N, &argc, argv);
     217  }
     218
     219  // XXX should we load a tree from CATDIR by default?
     220  // NOTE: a given catdir needs an appropriate boundary tree
     221  BOUNDARY_TREE = NULL;
     222  if ((N = get_argument (argc, argv, "-boundary-tree"))) {
     223    remove_argument (N, &argc, argv);
     224    BOUNDARY_TREE = strcreate(argv[N]);
     225    load_tess (BOUNDARY_TREE);
     226    remove_argument (N, &argc, argv);
     227  }
     228
     229  SHOW_PARAMS = TRUE;
     230  if ((N = get_argument (argc, argv, "-params"))) {
     231    remove_argument (N, &argc, argv);
     232    SHOW_PARAMS = FALSE;
     233  }
     234
     235  PlotMmin = 10.0; PlotMmax = 20.0; PlotdMmin = -1.0; PlotdMmax = 1.0;
     236  if ((N = get_argument (argc, argv, "-plrange"))) {
     237    remove_argument (N, &argc, argv);
     238    PlotMmin = atof (argv[N]);
     239    remove_argument (N, &argc, argv);
     240    PlotMmax = atof (argv[N]);
     241    remove_argument (N, &argc, argv);
     242    PlotdMmin = atof (argv[N]);
     243    remove_argument (N, &argc, argv);
     244    PlotdMmax = atof (argv[N]);
     245    remove_argument (N, &argc, argv);
     246  }
     247
     248  /* XXX this argument used to do two things: specify the camera name and tell the analysis to
     249     calculate a common zero point for a single mosaic.  I've moved the MOSAICNAME concept into the
     250     config system, but need to use this argument to specify that the mosaic zeropoints should be
     251     calculated. */
     252  MOSAIC_ZEROPT = FALSE;
     253  if ((N = get_argument (argc, argv, "-mosaic"))) {
     254    remove_argument (N, &argc, argv);
     255    MOSAIC_ZEROPT = TRUE;
     256    if (!strcasecmp (MOSAICNAME, "none")) {
     257      fprintf (stderr, "mosaic astrometry selected by MOSAICNAME not defined\n");
     258      exit (2);
     259    }
     260  }
     261
     262  FREEZE_IMAGES = FALSE;
     263  if ((N = get_argument (argc, argv, "-imfreeze"))) {
     264    remove_argument (N, &argc, argv);
     265    FREEZE_IMAGES = TRUE;
     266  }
     267
     268  FREEZE_MOSAICS = FALSE;
     269  if ((N = get_argument (argc, argv, "-mosfreeze"))) {
     270    remove_argument (N, &argc, argv);
     271    FREEZE_MOSAICS = TRUE;
     272  }
     273
     274  // USE_GRID is not valid for all cases, probably should be its own mode...
     275  USE_GRID = FALSE;
     276  if ((N = get_argument (argc, argv, "-grid"))) {
     277    remove_argument (N, &argc, argv);
     278    USE_GRID = TRUE;
     279  }
     280
     281  KEEP_UBERCAL = TRUE;
     282  if ((N = get_argument (argc, argv, "-reset-ubercal"))) {
     283    remove_argument (N, &argc, argv);
     284    KEEP_UBERCAL = FALSE;
     285  }
     286
     287  MIN_ERROR = 0.001;
     288  if ((N = get_argument (argc, argv, "-minerror"))) {
     289    remove_argument (N, &argc, argv);
     290    MIN_ERROR = atof (argv[N]);
     291    remove_argument (N, &argc, argv);
     292    /* require MIN_ERROR > 0 */
     293  } 
     294
     295  AreaSelect = FALSE;
     296  if ((N = get_argument (argc, argv, "-area"))) {
     297    remove_argument (N, &argc, argv);
     298    AreaXmin = atof (argv[N]);
     299    remove_argument (N, &argc, argv);
     300    AreaXmax = atof (argv[N]);
     301    remove_argument (N, &argc, argv);
     302    AreaYmin = atof (argv[N]);
     303    remove_argument (N, &argc, argv);
     304    AreaYmax = atof (argv[N]);
     305    remove_argument (N, &argc, argv);
     306    AreaSelect = TRUE;
     307  }
     308
     309  ImagSelect = FALSE;
     310  if ((N = get_argument (argc, argv, "-instmag"))) {
     311    remove_argument (N, &argc, argv);
     312    ImagMin = atof (argv[N]);
     313    remove_argument (N, &argc, argv);
     314    ImagMax = atof (argv[N]);
     315    remove_argument (N, &argc, argv);
     316    ImagSelect = TRUE;
     317  }
     318
     319  DophotSelect = FALSE;
     320  if ((N = get_argument (argc, argv, "-dophot"))) {
     321    remove_argument (N, &argc, argv);
     322    DophotValue = atof (argv[N]);
     323    remove_argument (N, &argc, argv);
     324    DophotSelect = TRUE;
     325  }
     326
     327  SyntheticPhotometry = FALSE;
     328  if ((N = get_argument (argc, argv, "-synthphot"))) {
     329    remove_argument (N, &argc, argv);
     330    SyntheticPhotometry = TRUE;
     331    init_synthetic_mags();
     332  }
     333
     334  refPhotcode = NULL;
     335  if ((N = get_argument (argc, argv, "-refcode"))) {
     336    remove_argument (N, &argc, argv);
     337    refPhotcode = GetPhotcodebyName (argv[N]);
     338    if (!refPhotcode) {
     339      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", argv[N]);
     340      exit (1);
     341    }
     342    remove_argument (N, &argc, argv);
     343  }
     344
     345  REGION_FILE = NULL;
     346  if ((N = get_argument (argc, argv, "-region-hosts"))) {
     347    remove_argument (N, &argc, argv);
     348    REGION_FILE = strcreate (argv[N]);
     349    remove_argument (N, &argc, argv);
     350  }
     351
     352  REGION_HOST_ID = 0;
     353  if ((N = get_argument (argc, argv, "-region-hostID"))) {
     354    remove_argument (N, &argc, argv);
     355    REGION_HOST_ID = atoi (argv[N]);
     356    remove_argument (N, &argc, argv);
     357  }
     358
     359  RelphotMode mode = MODE_ERROR;
     360  if ((N = get_argument (argc, argv, "-images"))) {
     361    remove_argument (N, &argc, argv);
     362    mode = UPDATE_IMAGES;
     363  }
     364  if ((N = get_argument (argc, argv, "-averages"))) {
     365    remove_argument (N, &argc, argv);
     366    mode = UPDATE_AVERAGES;
     367  }
     368  if ((N = get_argument (argc, argv, "-apply-offsets"))) {
     369    remove_argument (N, &argc, argv);
     370    mode = APPLY_OFFSETS;
     371  }
     372  IMAGE_TABLE = NULL;
     373  if ((N = get_argument (argc, argv, "-parallel-images"))) {
     374    remove_argument (N, &argc, argv);
     375    mode = PARALLEL_IMAGES;
     376    if (N >= argc) relphot_usage();
     377    IMAGE_TABLE = strcreate (argv[N]);
     378    remove_argument (N, &argc, argv);
     379    if (!REGION_FILE) relphot_usage();
     380  }
     381
     382  PARALLEL_REGIONS_MANUAL = FALSE;
     383  if ((N = get_argument (argc, argv, "-parallel-regions"))) {
     384    remove_argument (N, &argc, argv);
     385    mode = PARALLEL_REGIONS;
     386    if (!REGION_FILE) relphot_usage();
     387    if ((N = get_argument (argc, argv, "-parallel-regions-manual"))) {
     388      remove_argument (N, &argc, argv);
     389      PARALLEL_REGIONS_MANUAL = TRUE;
     390    }
     391  }
     392
     393  switch (mode) {
     394    case UPDATE_AVERAGES:
     395      if (argc != 1) relphot_usage();
     396      break;
     397     
     398    case UPDATE_IMAGES:
     399    case PARALLEL_IMAGES:
     400    case PARALLEL_REGIONS:
     401      PhotcodeList = strcreate (argv[1]);
     402      photcodes = ParsePhotcodeList (PhotcodeList, &Nphotcodes, TRUE); // require SEC photcodes
     403      remove_argument (1, &argc, argv);
     404      break;
     405
     406    default:
     407      fprintf (stderr, "no valid mode selected\n");
     408      relphot_usage();
     409      break;
     410  }
     411  if (argc != 1) relphot_usage ();
     412
     413  return mode;
     414}
     415
     416int args_client (int argc, char **argv) {
     417
     418  int N;
     419  double trange;
     420
     421  // by definition, the client is not parallel
     422  PARALLEL = FALSE;
     423  PARALLEL_MANUAL = FALSE;
     424  PARALLEL_SERIAL = FALSE;
     425
     426  HOST_ID = 0;
     427  if ((N = get_argument (argc, argv, "-hostID"))) {
     428    remove_argument (N, &argc, argv);
     429    HOST_ID = atoi (argv[N]);
     430    remove_argument (N, &argc, argv);
     431  }
     432  if (!HOST_ID) relphot_client_usage();
     433
     434  HOSTDIR = NULL;
     435  if ((N = get_argument (argc, argv, "-hostdir"))) {
     436    remove_argument (N, &argc, argv);
     437    HOSTDIR = strcreate (argv[N]);
     438    remove_argument (N, &argc, argv);
     439  }
     440  if (!HOSTDIR) relphot_client_usage();
     441
     442  IMAGES = NULL; // used in -update mode
     443  BCATALOG = NULL; // used in -load mode
     444  MODE = MODE_NONE;
     445  if ((N = get_argument (argc, argv, "-load"))) {
     446    MODE = MODE_LOAD;
     447    remove_argument (N, &argc, argv);
     448    BCATALOG = strcreate (argv[N]);
     449    remove_argument (N, &argc, argv);
     450  }
     451  if ((N = get_argument (argc, argv, "-update-catalogs"))) {
     452    if (MODE) {
     453      fprintf (stderr, "ERROR: cannot mix modes (-load, -update-catalogs, -update-objects)\n");
     454      relphot_client_usage();
     455    }
     456    MODE = MODE_UPDATE;
     457    remove_argument (N, &argc, argv);
     458    IMAGES = strcreate (argv[N]);
     459    remove_argument (N, &argc, argv);
     460  }
     461  if ((N = get_argument (argc, argv, "-update-objects"))) {
     462    if (MODE) {
     463      fprintf (stderr, "ERROR: cannot mix modes (-load, -update-catalogs, -update-objects)\n");
     464      relphot_client_usage();
     465    }
     466    MODE = MODE_UPDATE_OBJECTS;
     467    remove_argument (N, &argc, argv);
     468  }
     469  if (!MODE) relphot_client_usage();
     470
     471  strcpy (STATMODE, "WT_MEAN");
     472  if ((N = get_argument (argc, argv, "-statmode"))) {
     473    remove_argument (N, &argc, argv);
     474    strcpy (STATMODE, argv[N]);
     475    remove_argument (N, &argc, argv);
     476  }
     477
     478  BOUNDARY_TREE = NULL;
     479  if ((N = get_argument (argc, argv, "-boundary-tree"))) {
     480    remove_argument (N, &argc, argv);
     481    BOUNDARY_TREE = strcreate(argv[N]);
     482    load_tess (BOUNDARY_TREE);
     483    remove_argument (N, &argc, argv);
     484  }
     485
     486  /* specify portion of the sky */
     487  UserPatch.Rmin = 0;
     488  UserPatch.Rmax = 360;
     489  UserPatch.Dmin = -90;
     490  UserPatch.Dmax = +90;
     491  if ((N = get_argument (argc, argv, "-region"))) {
     492    remove_argument (N, &argc, argv);
     493    UserPatch.Rmin = atof (argv[N]);
     494    remove_argument (N, &argc, argv);
     495    UserPatch.Rmax = atof (argv[N]);
     496    remove_argument (N, &argc, argv);
     497    UserPatch.Dmin = atof (argv[N]);
     498    remove_argument (N, &argc, argv);
     499    UserPatch.Dmax = atof (argv[N]);
     500    remove_argument (N, &argc, argv);
     501  }
     502
     503  SET_MREL_VERSION = 1;
     504  if ((N = get_argument (argc, argv, "-set-mrel-version"))) {
     505    remove_argument (N, &argc, argv);
     506    SET_MREL_VERSION = atof(argv[N]);
     507    remove_argument (N, &argc, argv);
     508  }
     509
     510  VERBOSE = VERBOSE2 = FALSE;
     511  if ((N = get_argument (argc, argv, "-v"))) {
     512    VERBOSE = TRUE;
     513    remove_argument (N, &argc, argv);
     514  }
     515  if ((N = get_argument (argc, argv, "-vv"))) {
     516    VERBOSE2 = VERBOSE = TRUE;
     517    remove_argument (N, &argc, argv);
     518  }
     519
     520  RESET = FALSE;
     521  if ((N = get_argument (argc, argv, "-reset"))) {
     522    remove_argument (N, &argc, argv);
     523    RESET = TRUE;
     524  }
     525
     526  RESET_ZEROPTS = FALSE;
     527  if ((N = get_argument (argc, argv, "-reset-zpts"))) {
     528    remove_argument (N, &argc, argv);
     529    RESET_ZEROPTS = TRUE;
     530  }
     531
     532  KEEP_UBERCAL = TRUE;
     533  if ((N = get_argument (argc, argv, "-reset-ubercal"))) {
     534    remove_argument (N, &argc, argv);
     535    KEEP_UBERCAL = FALSE;
     536  }
    7537
    8538  /* define time */
     
    33563  }
    34564
    35   /* specify portion of the sky */
    36   UserPatch.Rmin = 0;
    37   UserPatch.Rmax = 360;
    38   UserPatch.Dmin = -90;
    39   UserPatch.Dmax = +90;
    40   if ((N = get_argument (argc, argv, "-region"))) {
    41     remove_argument (N, &argc, argv);
    42     UserPatch.Rmin = atof (argv[N]);
    43     remove_argument (N, &argc, argv);
    44     UserPatch.Rmax = atof (argv[N]);
    45     remove_argument (N, &argc, argv);
    46     UserPatch.Dmin = atof (argv[N]);
    47     remove_argument (N, &argc, argv);
    48     UserPatch.Dmax = atof (argv[N]);
    49     remove_argument (N, &argc, argv);
    50   }
    51 
    52   /* specify region file by name (eg n0000/0000.00) */
    53   UserCatalog = NULL;
    54   if ((N = get_argument (argc, argv, "-catalog"))) {
    55     remove_argument (N, &argc, argv);
    56     UserCatalog = strcreate (argv[N]);
    57     remove_argument (N, &argc, argv);
    58   }
    59 
    60   USE_BASIC_CHECK = FALSE;
    61   if ((N = get_argument (argc, argv, "-basic-image-search"))) {
    62     remove_argument (N, &argc, argv);
    63     USE_BASIC_CHECK = TRUE;
    64   }
    65 
    66   USE_FULL_OVERLAP = TRUE;
    67   if ((N = get_argument (argc, argv, "-sloppy-image-overlap"))) {
    68     remove_argument (N, &argc, argv);
    69     USE_FULL_OVERLAP = FALSE;
    70   }
    71 
    72   SET_MREL_VERSION = 1;
    73   if ((N = get_argument (argc, argv, "-set-mrel-version"))) {
    74     remove_argument (N, &argc, argv);
    75     SET_MREL_VERSION = atof(argv[N]);
    76     remove_argument (N, &argc, argv);
    77   }
    78 
    79   VERBOSE = VERBOSE2 = FALSE;
    80   if ((N = get_argument (argc, argv, "-v"))) {
    81     VERBOSE = TRUE;
    82     remove_argument (N, &argc, argv);
    83   }
    84   if ((N = get_argument (argc, argv, "-vv"))) {
    85     VERBOSE2 = VERBOSE = TRUE;
    86     remove_argument (N, &argc, argv);
    87   }
    88 
    89   NTHREADS = 0;
    90   if ((N = get_argument (argc, argv, "-threads"))) {
    91     remove_argument (N, &argc, argv);
    92     NTHREADS = atof (argv[N]);
    93     remove_argument (N, &argc, argv);
    94   }
    95 
    96   // XXX for the moment, make this selection manual.  it needs to be automatic
    97   // based on the state of the SkyTable
    98   HOST_ID = 0;
    99   PARALLEL = FALSE;
    100   if ((N = get_argument (argc, argv, "-parallel"))) {
    101     PARALLEL = TRUE;
    102     remove_argument (N, &argc, argv);
    103   }
    104   // this is a test mode : rather than launching the remote jobs and waiting for completion,
    105   // relphot will simply list the remote command and wait for the user to signal completion
    106   PARALLEL_MANUAL = FALSE;
    107   if ((N = get_argument (argc, argv, "-parallel-manual"))) {
    108     PARALLEL = TRUE; // -parallel-manual implies -parallel
    109     PARALLEL_MANUAL = TRUE;
    110     remove_argument (N, &argc, argv);
    111   }
    112   // this is a test mode : rather than launching the relphot_client jobs remotely, they are
    113   // run in serial via 'system'
    114   PARALLEL_SERIAL = FALSE;
    115   if ((N = get_argument (argc, argv, "-parallel-serial"))) {
    116     if (PARALLEL_MANUAL) {
    117       fprintf (stderr, "ERROR: cannot mix -parallel-manual and -parallel-serial\n");
    118       exit (1);
    119     }
    120     PARALLEL = TRUE; // -parallel-serial implies -parallel
    121     PARALLEL_SERIAL = TRUE;
    122     remove_argument (N, &argc, argv);
    123   }
    124 
    125   PLOTSTUFF = FALSE;
    126   if ((N = get_argument (argc, argv, "-plot"))) {
    127     PLOTSTUFF = TRUE;
    128     remove_argument (N, &argc, argv);
    129   }
    130 
    131   PLOTDELAY = 500000;
    132   if ((N = get_argument (argc, argv, "-plotdelay"))) {
    133     remove_argument (N, &argc, argv);
    134     PLOTDELAY = 1e6*atof(argv[N]);
    135     PLOTSTUFF = TRUE; // always turn on plotting if i request a plot delay
    136     remove_argument (N, &argc, argv);
    137   }
    138 
    139   if ((N = get_argument (argc, argv, "-outroot"))) {
    140     remove_argument (N, &argc, argv);
    141     OUTROOT = strcreate (argv[N]);
    142     remove_argument (N, &argc, argv);
    143   } else {
    144     OUTROOT = strcreate ("relphot");
    145   }     
    146 
    147   strcpy (STATMODE, "WT_MEAN");
    148   if ((N = get_argument (argc, argv, "-statmode"))) {
    149     remove_argument (N, &argc, argv);
    150     strcpy (STATMODE, argv[N]);
    151     remove_argument (N, &argc, argv);
    152   }
    153 
    154   NLOOP = 8;
    155   if ((N = get_argument (argc, argv, "-n"))) {
    156     remove_argument (N, &argc, argv);
    157     NLOOP = atof (argv[N]);
    158     remove_argument (N, &argc, argv);
    159   }
    160   if ((N = get_argument (argc, argv, "-nloop"))) {
    161     remove_argument (N, &argc, argv);
    162     NLOOP = atof (argv[N]);
    163     remove_argument (N, &argc, argv);
    164   }
    165 
    166   NGRID = 8;
    167   if ((N = get_argument (argc, argv, "-ngrid"))) {
    168     remove_argument (N, &argc, argv);
    169     NGRID = atof (argv[N]);
    170     remove_argument (N, &argc, argv);
    171   }
    172 
    173   RESET = FALSE;
    174   if ((N = get_argument (argc, argv, "-reset"))) {
    175     remove_argument (N, &argc, argv);
    176     RESET = TRUE;
    177   }
    178 
    179   RESET_ZEROPTS = FALSE;
    180   if ((N = get_argument (argc, argv, "-reset-zpts"))) {
    181     remove_argument (N, &argc, argv);
    182     RESET_ZEROPTS = TRUE;
    183   }
     565
     566  MIN_ERROR = 0.001;
     567  if ((N = get_argument (argc, argv, "-minerror"))) {
     568    remove_argument (N, &argc, argv);
     569    MIN_ERROR = atof (argv[N]);
     570    remove_argument (N, &argc, argv);
     571    /* require MIN_ERROR > 0 */
     572  } 
    184573
    185574  UPDATE = FALSE;
     
    196585  }
    197586
    198   SAVE_IMAGE_UPDATES = TRUE;
    199   if ((N = get_argument (argc, argv, "-skip-image-updates"))) {
    200     remove_argument (N, &argc, argv);
    201     SAVE_IMAGE_UPDATES = FALSE;
     587  AreaSelect = FALSE;
     588  if ((N = get_argument (argc, argv, "-area"))) {
     589    remove_argument (N, &argc, argv);
     590    AreaXmin = atof (argv[N]);
     591    remove_argument (N, &argc, argv);
     592    AreaXmax = atof (argv[N]);
     593    remove_argument (N, &argc, argv);
     594    AreaYmin = atof (argv[N]);
     595    remove_argument (N, &argc, argv);
     596    AreaYmax = atof (argv[N]);
     597    remove_argument (N, &argc, argv);
     598    AreaSelect = TRUE;
     599  }
     600
     601  SyntheticPhotometry = FALSE;
     602  if ((N = get_argument (argc, argv, "-synthphot"))) {
     603    remove_argument (N, &argc, argv);
     604    SyntheticPhotometry = FALSE;
     605    init_synthetic_mags();
     606  }
     607
     608  ImagSelect = FALSE;
     609  if ((N = get_argument (argc, argv, "-instmag"))) {
     610    remove_argument (N, &argc, argv);
     611    ImagMin = atof (argv[N]);
     612    remove_argument (N, &argc, argv);
     613    ImagMax = atof (argv[N]);
     614    remove_argument (N, &argc, argv);
     615    ImagSelect = TRUE;
     616  }
     617
     618  DophotSelect = FALSE;
     619  if ((N = get_argument (argc, argv, "-dophot"))) {
     620    remove_argument (N, &argc, argv);
     621    DophotValue = atof (argv[N]);
     622    remove_argument (N, &argc, argv);
     623    DophotSelect = TRUE;
    202624  }
    203625
     
    210632  }
    211633
    212   CLOUD_TOLERANCE = 0.02;
    213   if ((N = get_argument (argc, argv, "-cloud-limit"))) {
    214     remove_argument (N, &argc, argv);
    215     CLOUD_TOLERANCE = atof(argv[N]);
    216     remove_argument (N, &argc, argv);
    217   }
    218 
    219   BOUNDARY_TREE = NULL;
    220   if ((N = get_argument (argc, argv, "-boundary-tree"))) {
    221     remove_argument (N, &argc, argv);
    222     BOUNDARY_TREE = strcreate(argv[N]);
    223     load_tree (BOUNDARY_TREE);
    224     remove_argument (N, &argc, argv);
    225   }
    226 
    227   SHOW_PARAMS = FALSE;
    228   if ((N = get_argument (argc, argv, "-params"))) {
    229     remove_argument (N, &argc, argv);
    230     SHOW_PARAMS = TRUE;
    231   }
    232 
    233   PlotMmin = 10.0; PlotMmax = 20.0; PlotdMmin = -1.0; PlotdMmax = 1.0;
    234   if ((N = get_argument (argc, argv, "-plrange"))) {
    235     remove_argument (N, &argc, argv);
    236     PlotMmin = atof (argv[N]);
    237     remove_argument (N, &argc, argv);
    238     PlotMmax = atof (argv[N]);
    239     remove_argument (N, &argc, argv);
    240     PlotdMmin = atof (argv[N]);
    241     remove_argument (N, &argc, argv);
    242     PlotdMmax = atof (argv[N]);
    243     remove_argument (N, &argc, argv);
    244   }
    245 
    246   /* XXX this argument used to do two things: specify the camera name and tell the analysis to
    247      calculate a common zero point for a single mosaic.  I've moved the MOSAICNAME concept into the
    248      config system, but need to use this argument to specify that the mosaic zeropoints should be
    249      calculated. */
    250   MOSAIC_ZEROPT = FALSE;
    251   if ((N = get_argument (argc, argv, "-mosaic"))) {
    252     remove_argument (N, &argc, argv);
    253     MOSAIC_ZEROPT = TRUE;
    254     if (!strcasecmp (MOSAICNAME, "none")) {
    255       fprintf (stderr, "mosaic astrometry selected by MOSAICNAME not defined\n");
    256       exit (2);
    257     }
    258   }
    259 
    260   FREEZE_IMAGES = FALSE;
    261   if ((N = get_argument (argc, argv, "-imfreeze"))) {
    262     remove_argument (N, &argc, argv);
    263     FREEZE_IMAGES = TRUE;
    264   }
    265 
    266   FREEZE_MOSAICS = FALSE;
    267   if ((N = get_argument (argc, argv, "-mosfreeze"))) {
    268     remove_argument (N, &argc, argv);
    269     FREEZE_MOSAICS = TRUE;
    270   }
    271 
    272   USE_GRID = FALSE;
    273   if ((N = get_argument (argc, argv, "-grid"))) {
    274     remove_argument (N, &argc, argv);
    275     USE_GRID = TRUE;
    276   }
    277 
    278   KEEP_UBERCAL = TRUE;
    279   if ((N = get_argument (argc, argv, "-reset-ubercal"))) {
    280     remove_argument (N, &argc, argv);
    281     KEEP_UBERCAL = FALSE;
    282   }
    283 
    284   MIN_ERROR = 0.001;
    285   if ((N = get_argument (argc, argv, "-minerror"))) {
    286     remove_argument (N, &argc, argv);
    287     MIN_ERROR = atof (argv[N]);
    288     remove_argument (N, &argc, argv);
    289     /* require MIN_ERROR > 0 */
    290   } 
    291 
    292   AreaSelect = FALSE;
    293   if ((N = get_argument (argc, argv, "-area"))) {
    294     remove_argument (N, &argc, argv);
    295     AreaXmin = atof (argv[N]);
    296     remove_argument (N, &argc, argv);
    297     AreaXmax = atof (argv[N]);
    298     remove_argument (N, &argc, argv);
    299     AreaYmin = atof (argv[N]);
    300     remove_argument (N, &argc, argv);
    301     AreaYmax = atof (argv[N]);
    302     remove_argument (N, &argc, argv);
    303     AreaSelect = TRUE;
    304   }
    305 
    306   ImagSelect = FALSE;
    307   if ((N = get_argument (argc, argv, "-instmag"))) {
    308     remove_argument (N, &argc, argv);
    309     ImagMin = atof (argv[N]);
    310     remove_argument (N, &argc, argv);
    311     ImagMax = atof (argv[N]);
    312     remove_argument (N, &argc, argv);
    313     ImagSelect = TRUE;
    314   }
    315 
    316   DophotSelect = FALSE;
    317   if ((N = get_argument (argc, argv, "-dophot"))) {
    318     remove_argument (N, &argc, argv);
    319     DophotValue = atof (argv[N]);
    320     remove_argument (N, &argc, argv);
    321     DophotSelect = TRUE;
    322   }
    323 
    324   SyntheticPhotometry = FALSE;
    325   if ((N = get_argument (argc, argv, "-synthphot"))) {
    326     remove_argument (N, &argc, argv);
    327     SyntheticPhotometry = TRUE;
    328     init_synthetic_mags();
    329   }
    330 
    331   refPhotcode = NULL;
    332   if ((N = get_argument (argc, argv, "-refcode"))) {
    333     remove_argument (N, &argc, argv);
    334     refPhotcode = GetPhotcodebyName (argv[N]);
    335     if (!refPhotcode) {
    336       fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", argv[N]);
    337       exit (1);
    338     }
    339     remove_argument (N, &argc, argv);
    340   }
    341 
    342   UpdateAverages = FALSE;
    343   if ((N = get_argument (argc, argv, "-averages"))) {
    344     remove_argument (N, &argc, argv);
    345     UpdateAverages = TRUE;
    346   }
    347 
    348   ApplyOffsets = FALSE;
    349   if ((N = get_argument (argc, argv, "-apply-offsets"))) {
    350     remove_argument (N, &argc, argv);
    351     ApplyOffsets = TRUE;
    352   }
    353 
    354   if (UpdateAverages && (argc == 1)) return TRUE;
    355   if (argc != 2) relphot_usage ();
     634  if ((MODE == MODE_UPDATE_OBJECTS)  && (argc == 1)) return TRUE;
     635  if (argc != 2) relphot_client_usage ();
    356636
    357637  return TRUE;
    358638}
    359639
    360 int args_client (int argc, char **argv) {
    361 
    362   int N;
    363   double trange;
    364 
    365   // by definition, the client is not parallel
    366   PARALLEL = FALSE;
    367   PARALLEL_MANUAL = FALSE;
    368   PARALLEL_SERIAL = FALSE;
    369 
    370   HOST_ID = 0;
    371   if ((N = get_argument (argc, argv, "-hostID"))) {
    372     remove_argument (N, &argc, argv);
    373     HOST_ID = atoi (argv[N]);
    374     remove_argument (N, &argc, argv);
    375   }
    376   if (!HOST_ID) relphot_client_usage();
    377 
    378   HOSTDIR = NULL;
    379   if ((N = get_argument (argc, argv, "-hostdir"))) {
    380     remove_argument (N, &argc, argv);
    381     HOSTDIR = strcreate (argv[N]);
    382     remove_argument (N, &argc, argv);
    383   }
    384   if (!HOSTDIR) relphot_client_usage();
    385 
    386   IMAGES = NULL; // used in -update mode
    387   BCATALOG = NULL; // used in -load mode
    388   MODE = MODE_NONE;
    389   if ((N = get_argument (argc, argv, "-load"))) {
    390     MODE = MODE_LOAD;
    391     remove_argument (N, &argc, argv);
    392     BCATALOG = strcreate (argv[N]);
    393     remove_argument (N, &argc, argv);
    394   }
    395   if ((N = get_argument (argc, argv, "-update-catalogs"))) {
    396     if (MODE) {
    397       fprintf (stderr, "ERROR: cannot mix modes (-load, -update-catalogs, -update-objects)\n");
    398       relphot_client_usage();
    399     }
    400     MODE = MODE_UPDATE;
    401     remove_argument (N, &argc, argv);
    402     IMAGES = strcreate (argv[N]);
    403     remove_argument (N, &argc, argv);
    404   }
    405   if ((N = get_argument (argc, argv, "-update-objects"))) {
    406     if (MODE) {
    407       fprintf (stderr, "ERROR: cannot mix modes (-load, -update-catalogs, -update-objects)\n");
    408       relphot_client_usage();
    409     }
    410     MODE = MODE_UPDATE_OBJECTS;
    411     remove_argument (N, &argc, argv);
    412   }
    413   if (!MODE) relphot_client_usage();
    414 
    415   strcpy (STATMODE, "WT_MEAN");
    416   if ((N = get_argument (argc, argv, "-statmode"))) {
    417     remove_argument (N, &argc, argv);
    418     strcpy (STATMODE, argv[N]);
    419     remove_argument (N, &argc, argv);
    420   }
    421 
    422   BOUNDARY_TREE = NULL;
    423   if ((N = get_argument (argc, argv, "-boundary-tree"))) {
    424     remove_argument (N, &argc, argv);
    425     BOUNDARY_TREE = strcreate(argv[N]);
    426     load_tree (BOUNDARY_TREE);
    427     remove_argument (N, &argc, argv);
    428   }
    429 
    430   /* specify portion of the sky */
    431   UserPatch.Rmin = 0;
    432   UserPatch.Rmax = 360;
    433   UserPatch.Dmin = -90;
    434   UserPatch.Dmax = +90;
    435   if ((N = get_argument (argc, argv, "-region"))) {
    436     remove_argument (N, &argc, argv);
    437     UserPatch.Rmin = atof (argv[N]);
    438     remove_argument (N, &argc, argv);
    439     UserPatch.Rmax = atof (argv[N]);
    440     remove_argument (N, &argc, argv);
    441     UserPatch.Dmin = atof (argv[N]);
    442     remove_argument (N, &argc, argv);
    443     UserPatch.Dmax = atof (argv[N]);
    444     remove_argument (N, &argc, argv);
    445   }
    446 
    447   SET_MREL_VERSION = 1;
    448   if ((N = get_argument (argc, argv, "-set-mrel-version"))) {
    449     remove_argument (N, &argc, argv);
    450     SET_MREL_VERSION = atof(argv[N]);
    451     remove_argument (N, &argc, argv);
    452   }
    453 
    454   VERBOSE = VERBOSE2 = FALSE;
    455   if ((N = get_argument (argc, argv, "-v"))) {
    456     VERBOSE = TRUE;
    457     remove_argument (N, &argc, argv);
    458   }
    459   if ((N = get_argument (argc, argv, "-vv"))) {
    460     VERBOSE2 = VERBOSE = TRUE;
    461     remove_argument (N, &argc, argv);
    462   }
    463 
    464   RESET = FALSE;
    465   if ((N = get_argument (argc, argv, "-reset"))) {
    466     remove_argument (N, &argc, argv);
    467     RESET = TRUE;
    468   }
    469 
    470   RESET_ZEROPTS = FALSE;
    471   if ((N = get_argument (argc, argv, "-reset-zpts"))) {
    472     remove_argument (N, &argc, argv);
    473     RESET_ZEROPTS = TRUE;
    474   }
    475 
    476   KEEP_UBERCAL = TRUE;
    477   if ((N = get_argument (argc, argv, "-reset-ubercal"))) {
    478     remove_argument (N, &argc, argv);
    479     KEEP_UBERCAL = FALSE;
    480   }
    481 
    482   /* define time */
    483   TimeSelect = FALSE;
    484   if ((N = get_argument (argc, argv, "-time"))) {
    485     remove_argument (N, &argc, argv);
    486     if (!ohana_str_to_time (argv[N], &TSTART)) {
    487       fprintf (stderr, "ERROR: syntax error\n");
    488       return (FALSE);
    489     }
    490     remove_argument (N, &argc, argv);
    491     if (!ohana_str_to_dtime (argv[N], &trange)) {
    492       if (!ohana_str_to_time (argv[N], &TSTOP)) {
    493         fprintf (stderr, "ERROR: syntax error\n");
    494         return (FALSE);
    495       }
    496     } else {
    497       if (trange < 0) {
    498         trange = fabs (trange);
    499         TSTOP = TSTART;
    500         TSTART -= trange;
    501       } else {
    502         TSTOP = TSTART + trange;
    503       }
    504     }
    505     remove_argument (N, &argc, argv);
    506     TimeSelect = TRUE;
    507   }
    508 
    509 
    510   MIN_ERROR = 0.001;
    511   if ((N = get_argument (argc, argv, "-minerror"))) {
    512     remove_argument (N, &argc, argv);
    513     MIN_ERROR = atof (argv[N]);
    514     remove_argument (N, &argc, argv);
    515     /* require MIN_ERROR > 0 */
    516   } 
    517 
    518   UPDATE = FALSE;
    519   if ((N = get_argument (argc, argv, "-update"))) {
    520     remove_argument (N, &argc, argv);
    521     UPDATE = TRUE;
    522   }
    523 
    524   UPDATE_CATFORMAT = NULL;
    525   if ((N = get_argument (argc, argv, "-update-catformat"))) {
    526     remove_argument (N, &argc, argv);
    527     UPDATE_CATFORMAT = strcreate (argv[N]);
    528     remove_argument (N, &argc, argv);
    529   }
    530 
    531   AreaSelect = FALSE;
    532   if ((N = get_argument (argc, argv, "-area"))) {
    533     remove_argument (N, &argc, argv);
    534     AreaXmin = atof (argv[N]);
    535     remove_argument (N, &argc, argv);
    536     AreaXmax = atof (argv[N]);
    537     remove_argument (N, &argc, argv);
    538     AreaYmin = atof (argv[N]);
    539     remove_argument (N, &argc, argv);
    540     AreaYmax = atof (argv[N]);
    541     remove_argument (N, &argc, argv);
    542     AreaSelect = TRUE;
    543   }
    544 
    545   SyntheticPhotometry = FALSE;
    546   if ((N = get_argument (argc, argv, "-synthphot"))) {
    547     remove_argument (N, &argc, argv);
    548     SyntheticPhotometry = FALSE;
    549     init_synthetic_mags();
    550   }
    551 
    552   ImagSelect = FALSE;
    553   if ((N = get_argument (argc, argv, "-instmag"))) {
    554     remove_argument (N, &argc, argv);
    555     ImagMin = atof (argv[N]);
    556     remove_argument (N, &argc, argv);
    557     ImagMax = atof (argv[N]);
    558     remove_argument (N, &argc, argv);
    559     ImagSelect = TRUE;
    560   }
    561 
    562   DophotSelect = FALSE;
    563   if ((N = get_argument (argc, argv, "-dophot"))) {
    564     remove_argument (N, &argc, argv);
    565     DophotValue = atof (argv[N]);
    566     remove_argument (N, &argc, argv);
    567     DophotSelect = TRUE;
    568   }
    569 
    570   MaxDensityUse = FALSE;
    571   if ((N = get_argument (argc, argv, "-max-density"))) {
    572     remove_argument (N, &argc, argv);
    573     MaxDensityValue = atof(argv[N]);
    574     remove_argument (N, &argc, argv);
    575     MaxDensityUse = TRUE;
    576   }
    577 
    578   if ((MODE == MODE_UPDATE_OBJECTS)  && (argc == 1)) return TRUE;
    579   if (argc != 2) relphot_client_usage ();
    580 
    581   return TRUE;
    582 }
    583 
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/bcatalog.c

    r35416 r37067  
    2323  Nmeasure = Naverage = 0;
    2424
     25  int NmMax = 0;
     26  int NmMin = catalog[0].Nmeasure;
     27
    2528  Ncode = Ntime = Ndophot = Nmag = Nsigma = Nimag = Nfew = Npsfqf = Ngalaxy = Nnan = Nbad = Npoor = 0;
    2629
     
    5558    if (RESET) {
    5659      int Ns;
     60
     61# if (0)     
    5762      DVOSecfiltFlags secfiltBits =
    5863        ID_SECF_STAR_FEW |
     
    6671        ID_SECF_USE_UBERCAL |
    6772        ID_SECF_OBJ_EXT;
     73# endif
     74
    6875      for (Ns = 0; Ns < Nphotcodes; Ns++) {
    6976
     
    7178        int Nsec = GetPhotcodeNsec(thisCode);
    7279
    73         subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].M      = NAN;
    74         subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].Map    = NAN;
    75         subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].dM     = NAN;
    76         subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].Mstdev = NAN_S_SHORT;
    77         subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].Xm     = NAN;
    78         subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].M_20   = NAN_S_SHORT;
    79         subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].M_80   = NAN_S_SHORT;
    80         subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].Ncode  = 0;
    81         subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].Nused  = 0;
    82         subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].flags &= ~secfiltBits;
    83         subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].ubercalDist = 1000;
     80        fprintf (stderr, "really use dvo_secfilt_init?");
     81        dvo_secfilt_init (&subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec]);
     82
     83        // subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].M      = NAN;
     84        // subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].Map    = NAN;
     85        // subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].dM     = NAN;
     86        // subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].Mstdev = NAN_S_SHORT;
     87        // subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].Mchisq = NAN;
     88        // subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].M_20   = NAN_S_SHORT;
     89        // subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].M_80   = NAN_S_SHORT;
     90        // subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].Ncode  = 0;
     91        // subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].Nused  = 0;
     92        // subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].flags &= ~secfiltBits;
     93        // subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].ubercalDist = 1000;
    8494      }
    8595    }
     
    136146
    137147      /* select measurements by mag limit */
    138       mag = PhotCat (&catalog[0].measure[offset]);
     148      mag = PhotCat (&catalog[0].measure[offset], MAG_CLASS_PSF);
    139149      if (mag > MAG_LIM) { Nmag ++; continue; }
    140150
     
    144154      /* select measurements by mag limit */
    145155      if (ImagSelect) {
    146         mag = PhotInst (&catalog[0].measure[offset]);
     156        mag = PhotInst (&catalog[0].measure[offset], MAG_CLASS_PSF);
    147157        if (mag < ImagMin) { Nimag ++; continue; }
    148158        if (mag > ImagMax) { Nimag ++; continue; }
     
    180190      }
    181191      myAssert (Nmeasure < NMEASURE, "realloc failure");
    182     }
     192    } // end of catalog.average.Nmeasure loop
    183193
    184194    // skip object if it is likely to be a galaxy
     
    205215      continue;
    206216    }
     217    NmMin = MIN (Nm, NmMin);
     218    NmMax = MAX (Nm, NmMax);
    207219
    208220    // for w-band photometry (& other cases?) convert gri photometry
     
    235247  subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt;
    236248
     249  if (VERBOSE) {
     250    fprintf (stderr, "using "OFF_T_FMT" stars ("OFF_T_FMT" measures) of "OFF_T_FMT" ("OFF_T_FMT" measures) for catalog %s, %d < Nm < %d\n",
     251             subcatalog[0].Naverage,  subcatalog[0].Nmeasure,  catalog[0].Naverage, catalog[0].Nmeasure, catalog[0].filename, NmMin, NmMax);
     252    fprintf (stderr, "rejections: %d stars have too few measures:\n   %d code, %d time, %d dophot, %d mag, %d sigma, %d imag, %d psfqf, %d Nnan, %d galaxies, %d bad, %d poor\n",
     253             Nfew, Ncode, Ntime, Ndophot, Nmag, Nsigma, Nimag, Npsfqf, Nnan, Ngalaxy, Nbad, Npoor);
     254  }
     255
    237256  // limit the total number of stars in the catalog
    238257  if (MaxDensityUse) {
     
    240259  }
    241260
    242   if (VERBOSE) {
    243     fprintf (stderr, "using "OFF_T_FMT" stars ("OFF_T_FMT" measures) of "OFF_T_FMT" for catalog %s\n",
    244              subcatalog[0].Naverage,  subcatalog[0].Nmeasure,  i, catalog[0].filename);
    245     fprintf (stderr, "rejections: %d code, %d time, %d dophot, %d mag, %d sigma, %d imag, %d few, %d psfqf, %d Nnan, %d galaxies, %d bad, %d poor\n",
    246              Ncode, Ntime, Ndophot, Nmag, Nsigma, Nimag, Nfew, Npsfqf, Nnan, Ngalaxy, Nbad, Npoor);
    247   }
    248261  return (TRUE);
    249262}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/client_logger.c

    r33963 r37067  
    55
    66static FILE *logfile = NULL;
    7 int client_logger_init () {
     7int client_logger_init (char *dirname) {
    88
    99  char filename[DVO_MAX_PATH];
    1010
    11   snprintf (filename, DVO_MAX_PATH, "%s/log.rlpc.XXXXXX", HOSTDIR);
     11  snprintf (filename, DVO_MAX_PATH, "%s/log.rlpc.XXXXXX", dirname);
    1212   
    1313  int fd = mkstemp (filename);
    1414  if (fd == -1) {
    15     fprintf (stderr, "failed to open client logger, exiting\n");
     15    fprintf (stderr, "failed to open client logger %s, exiting\n", filename);
    1616    exit (50);
    1717  }
     
    3232  vfprintf (logfile, format, argp);
    3333  va_end (argp);
     34
     35  fflush (logfile);
    3436  return TRUE;
    3537}
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/help.c

    r33651 r37067  
    22
    33void relphot_usage (void) {
    4   fprintf (stderr, "ERROR: USAGE: relphot (photcodes) -region RA RA DEC DEC\n");
    5   fprintf (stderr, "       or:    relphot (photcodes) -catalog (name)\n");
    6   fprintf (stderr, "       or:    relphot -averages -region RA RA DEC DEC\n");
     4  fprintf (stderr, "ERROR: USAGE: relphot (photcodes) -images\n");
     5  fprintf (stderr, "       or:    relphot -averages\n");
     6  fprintf (stderr, "       or:    relphot -apply-offsets\n");
     7  fprintf (stderr, "       or:    relphot (photcodes) -parallel-regions -region-hosts (RegionFile)\n");
     8  fprintf (stderr, "       or:    relphot (photcodes) -parallel-images (ImageTable) -region-hosts (RegionFile)\n\n");
     9  fprintf (stderr, "  regions:    -region RA RA DEC DEC)\n");
     10  fprintf (stderr, "       or:    -catalog (name)\n");
    711  fprintf (stderr, "  use -h for more usage information\n");
    812  exit (2);
     
    1822
    1923show_help:
    20   fprintf (stderr, "ERROR: USAGE: relphot (photcode) -region RA RA DEC DEC\n");
    21   fprintf (stderr, "       or:    relphot (photcode) -catalog (name)\n");
    22   fprintf (stderr, "       or:    relphot -averages -region RA RA DEC DEC\n");
     24  fprintf (stderr, "ERROR: USAGE: relphot (photcodes) -images\n");
     25  fprintf (stderr, "       or:    relphot -averages\n");
     26  fprintf (stderr, "       or:    relphot -apply-offsets\n");
     27  fprintf (stderr, "       or:    relphot (photcodes) -parallel-regions -region-hosts (RegionFile)\n");
     28  fprintf (stderr, "       or:    relphot (photcodes) -parallel-images (ImageTable) -region-hosts (RegionFile)\n\n");
     29  fprintf (stderr, "  regions:    -region RA RA DEC DEC)\n");
     30  fprintf (stderr, "       or:    -catalog (name)\n");
    2331  fprintf (stderr, "  options: \n");
    2432  fprintf (stderr, "  -time (start) (stop)\n");
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/initialize.c

    r34429 r37067  
    11# include "relphot.h"
    22
    3 void initialize (int argc, char **argv) {
     3RelphotMode initialize (int argc, char **argv) {
    44
    55  relphot_help (argc, argv);
    66  ConfigInit (&argc, argv);
    7   args (argc, argv);
     7  RelphotMode mode = args (argc, argv);
     8  if (!mode) exit (2);
    89
    9   if (!UpdateAverages) {
    10     // load the list of photcodes into the globals (photcodes, Nphotcodes)
    11     // only a single remaining argument in this mode (the list of photcodes, eg g,r,i)
    12     PhotcodeList = strcreate (argv[1]);
    13     photcodes = ParsePhotcodeList (PhotcodeList, &Nphotcodes, TRUE); // require SEC photcodes
    14   } else {
     10  // UPDATE_AVERAGES always operates on all photcodes?
     11  if (mode == UPDATE_AVERAGES) {
    1512    char tmpline1[256];
    1613    int Ns;
     
    3936
    4037  if (SHOW_PARAMS) {
    41     fprintf (stderr, "current parameter settings:\n");
     38    int Ns;
     39    fprintf (stderr, "subset selection criteria:\n");
     40    fprintf (stderr, "  photcodes ");
     41    for (Ns = 0; Ns < Nphotcodes; Ns++) {
     42      if (Ns == Nphotcodes - 1) {
     43        fprintf (stderr, "%s\n", photcodes[Ns][0].name);
     44      } else {
     45        fprintf (stderr, "%s, ", photcodes[Ns][0].name);
     46      }
     47    }
    4248    if (TimeSelect) {
    4349      fprintf (stderr, "TimeSelect: TRUE (%s - %s)\n", ohana_sec_to_date (TSTART), ohana_sec_to_date (TSTOP));
     
    4551      fprintf (stderr, "TimeSelect: FALSE\n");
    4652    }
     53    if (DophotSelect) {
     54      fprintf (stderr, "DophotSelect: TRUE (%d)\n", DophotValue);
     55    } else {
     56      fprintf (stderr, "DophotSelect: FALSE\n");
     57    }
     58    fprintf (stderr, "PSF_QF limit: 0.85 (hardwired)\n");
     59
     60    // fprintf (stderr, "Photom Bad Mask: 0x%08x, Photom Poor Mask: 0x%08x\n");
     61
     62    fprintf (stderr, "MAG_LIM: %f, SIGMA_LIM: %f\n", MAG_LIM, SIGMA_LIM);
     63    fprintf (stderr, "INST_MAG_MIN: %f, INST_MAG_MAX: %f\n", ImagMin, ImagMax);
     64
     65    fprintf (stderr, "STAR_TOOFEW: %d\n", STAR_TOOFEW);
     66
    4767    fprintf (stderr, "VERBOSE: %d, PLOTSTUFF: %d\n", VERBOSE, PLOTSTUFF);
    4868    fprintf (stderr, "GRID_X: %d, GRID_Y: %d, BINNING: %d == Nmx: %d, Nmy: %d\n",
     
    5272             (int)(RELPHOT_GRID_X/RELPHOT_GRID_BINNING), (int)(RELPHOT_GRID_Y/RELPHOT_GRID_BINNING));
    5373
    54     fprintf (stderr, "MAG_LIM                %lf\n", MAG_LIM);
    5574    fprintf (stderr, "STAR_SCATTER           %lf\n", STAR_SCATTER);
    5675    fprintf (stderr, "IMAGE_SCATTER          %lf\n", IMAGE_SCATTER);
     
    5978    fprintf (stderr, "GSCFILE                %s\n",  GSCFILE);
    6079    fprintf (stderr, "CATDIR                 %s\n",  CATDIR);
    61     exit (0);
    6280  }
    6381
     
    6785  for (B = 0; A == time(NULL); B++);
    6886  srand48(B);
     87
     88  return mode;
    6989}
    7090
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/load_catalogs.c

    r35416 r37067  
    1212// if this function is called with a specified hostID, then only the fraction of the
    1313// database hosted by that hostID is loaded
    14 Catalog *load_catalogs (SkyList *skylist, int *Ncatalog, int hostID, char *hostpath) {
     14Catalog *load_catalogs (SkyList *skylist, int *Ncatalog, int hostID, char *hostpath, char *syncfile) {
    1515
    1616  off_t i, Nmeas, Nstar, Nmeas_total, Nstar_total;
     
    1919  // XXX need to decide how to determine PARALLEL mode...
    2020  if (PARALLEL && !hostID) {
    21     catalog = load_catalogs_parallel (skylist, Ncatalog);
     21    catalog = load_catalogs_parallel (skylist, Ncatalog, syncfile);
    2222    return catalog;
    2323  }
     
    8989
    9090  fprintf (stderr, "using "OFF_T_FMT" of "OFF_T_FMT" stars ("OFF_T_FMT" of "OFF_T_FMT" measurements)\n", Nstar, Nstar_total, Nmeas, Nmeas_total);
    91   if (!hostID && (Nstar < 1)) Shutdown ("%s", "ERROR: no stars match the minimum requirements; exiting \n");
     91  if (!hostID && !REGION_HOST_ID && (Nstar < 1)) Shutdown ("%s", "ERROR: no stars match the minimum requirements; exiting \n");
    9292  // in regular relphot, we shutdown here; in relphot_client, we generate and return an empty table (for consistency)
    93    
     93
     94  // if we are running with parallel_images but not a parallel database, we need to
     95  // release the lock so the next image host can proceed
     96  if (!hostID && syncfile) {
     97    update_sync_file (syncfile, 1);
     98  }
    9499
    95100  // XXX consider only returning the populated catalogs
     
    106111// CATDIR is supplied globally
    107112# define DEBUG 1
    108 Catalog *load_catalogs_parallel (SkyList *sky, int *Ncatalog) {
     113Catalog *load_catalogs_parallel (SkyList *sky, int *Ncatalog, char *syncfile) {
     114
     115  char uniquer[12];
     116  int TIME = time(NULL);
     117  int PID = getpid();
     118  snprintf (uniquer, 12, "%05d.%05d", PID, TIME % 100000);
    109119
    110120  int Nsecfilt  = GetPhotcodeNsecfilt ();               // set the desired number in case we need to create the catalog
     
    128138
    129139    ALLOCATE (table->hosts[i].results, char, 1024);
    130     snprintf (table->hosts[i].results, 1024, "%s/relphot.catalog.subset.dat", table->hosts[i].pathname);
     140    snprintf (table->hosts[i].results, 1024, "%s/relphot.catalog.%s.dat", table->hosts[i].pathname, uniquer);
    131141
    132142    // options / arguments that can affect relphot_client -load:
     
    202212  }
    203213
     214  // update syncfile here (save lots of I/O time):
     215
     216  // at this point, the remote relastro_client jobs are done loading their data.  in a
     217  // parallel_images mode, the next image host can be launched while this image host now
     218  // reads that
     219
     220  // NOTE: if I let all hosts load blindly, I saturate the data clients with too many
     221  // relphot_client requests.  I need to have the master mediate this.  the master
     222  // will not launch the next remote job until this one says it is done
     223  if (syncfile) {
     224    update_sync_file (syncfile, 1);
     225  }
     226
    204227  // each host generates a BrightCatalog structure, with the measure, average, etc value
    205228  // loaded into a single set of arrays (of MeasureTiny, AverageTiny, Secfilt).  I need to
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/plot_scatter.c

    r35759 r37067  
    5151
    5252                xlist[N] = Mrel;
    53                 ylist[N] = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]) - Mcal - Mmos - Mgrid - Mrel;
    54                 ilist[N] = PhotInstTiny (&catalog[i].measureT[m]);
     53                ylist[N] = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF) - Mcal - Mmos - Mgrid - Mrel;
     54                ilist[N] = PhotInstTiny (&catalog[i].measureT[m], MAG_CLASS_PSF);
    5555                N++;
    5656            }
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/reload_catalogs.c

    r35806 r37067  
    156156  // load the list of hosts
    157157  HostTable *table = HostTableLoad (CATDIR, sky->hosts);
     158  if (!table) {
     159    fprintf (stderr, "ERROR: problem with parallel host table\n");
     160    exit (2);
     161  }
    158162
    159163  if (BOUNDARY_TREE) {
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/relphot.c

    r35416 r37067  
    33int main (int argc, char **argv) {
    44
    5   /* get configuration info, args */
    6   initialize (argc, argv);
     5  // get configuration info, args
     6  RelphotMode mode = initialize (argc, argv);
     7  if (!mode) exit (2);
    78
    8   /* the object analysis is a separate process iterating over catalogs */
    9   if (UpdateAverages) {
    10     relphot_objects (0, NULL);
    11     exit (0);
     9  switch (mode) {
     10    case UPDATE_IMAGES:
     11      relphot_images ();
     12      exit (0);
     13
     14    case UPDATE_AVERAGES:
     15      // take the current set of detections and set the mean magnitudes
     16      relphot_objects (0, NULL);
     17      exit (0);
     18
     19    case PARALLEL_REGIONS:
     20      // run image updates in parallel across multiple remote machines
     21      relphot_parallel_regions ();
     22      exit (0);
     23
     24    case PARALLEL_IMAGES:
     25      // operation on the remote machines in the PARALLEL_REGION mode
     26      relphot_parallel_images ();
     27      exit (0);
     28
     29    case APPLY_OFFSETS:
     30      // re-run this step from a previous attempt (assumes an existing Images.subset.dat file)
     31      if (!PARALLEL) {
     32        fprintf (stderr, "-apply-offsets only makes sense in an parallel context\n");
     33        exit (2);
     34      }
     35      reload_catalogs (NULL, NULL, 0, NULL);
     36      exit (0);
     37
     38    default:
     39      fprintf (stderr, "ERROR: no valid relphot mode chosen\n");
     40      exit (2);
    1241  }
    13 
    14   if (ApplyOffsets) {
    15     // re-run this step from a previous attempt (assumes an existing Images.subset.dat file)
    16     if (!PARALLEL) {
    17       fprintf (stderr, "-apply-offsets only makes sense in an parallel context\n");
    18       exit (2);
    19     }
    20     reload_catalogs (NULL, NULL, 0, NULL);
    21     exit (0);
    22   }
    23 
    24   relphot_images ();
    25 
    26   exit (0);
     42  fprintf (stderr, "IMPOSSIBLE: skipped out of switch?\n");
     43  exit (1);
    2744}
    28 
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/relphot_client.c

    r33963 r37067  
    1919  // get configuration info, args, lockfile (set CATDIR, HOST_ID, HOSTDIR, etc)
    2020  initialize_client (argc, argv);
    21   client_logger_init ();
     21  client_logger_init (HOSTDIR);
    2222
    2323  // load the current sky table (layout of all SkyRegions)
     
    3939    case MODE_LOAD: {
    4040      int Ncatalog;
    41       Catalog *catalog = load_catalogs (skylist, &Ncatalog, HOST_ID, HOSTDIR);
     41      Catalog *catalog = load_catalogs (skylist, &Ncatalog, HOST_ID, HOSTDIR, NULL);
    4242      if (!catalog) {
    4343          fprintf (stderr, "ERROR loading catalogs from %s\n", CATDIR);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/relphot_images.c

    r35806 r37067  
    5252  if (NLOOP > 0) {
    5353    /* load catalog data from region files (hostID is 0 since we are not a client */
    54     catalog = load_catalogs (skylist, &Ncatalog, 0, NULL);
     54    catalog = load_catalogs (skylist, &Ncatalog, 0, NULL, NULL);
    5555    MARKTIME("-- load catalog data: %f sec\n", dtime);
    5656 
     
    244244  if (!UPDATE) exit (0);
    245245 
    246   /* load catalog data from region files, update Mrel include all data */
     246  /* Load catalog data from region files, update Mrel include all data.  In a parallel
     247     context, this function writes the image parameters as a subset table for the remote
     248     clients */
    247249  reload_catalogs (skylist, flatcorr, 0, NULL);
    248250  MARKTIME("-- updated all catalogs: %f sec\n", dtime);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/select_images.c

    r35806 r37067  
    4040  tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    4141  tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    42   strcpy (tcoords.ctype, "RA---TAN");
     42  strcpy (tcoords.ctype, "DEC--TAN");
    4343
    4444  double RminSkyRegion = region[0].Rmin;
     
    412412  tcoords.Npolyterms = 0;
    413413  memset (tcoords.polyterms, 0, 14*sizeof(float));
    414   strcpy (tcoords.ctype, "RA---TAN");
     414  strcpy (tcoords.ctype, "DEC--TAN");
    415415
    416416  /* compare with each region file */
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/setExclusions.c

    r33651 r37067  
    3535        /* select measurements by mag limit */
    3636        if (AreaSelect) {
    37           r = catalog[i].averageT[j].R + catalog[i].measureT[m].dR / 3600.0;
    38           d = catalog[i].averageT[j].D + catalog[i].measureT[m].dD / 3600.0;
     37          r = catalog[i].measureT[m].R;
     38          d = catalog[i].measureT[m].D;
    3939          if ((coords = getCoords (m, i)) == NULL) goto markbad;
    4040          RD_to_XY (&x, &y, r, d, coords);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/setMrelCatalog.c

    r35759 r37067  
    11# include "relphot.h"
     2# define UBERCAL_WEIGHT 100.0
    23
    34# define SKIP_THIS_MEAS(REASON) {                               \
     
    1314    continue; }
    1415
     16static float MagToFlux (float Mag) {
     17  float Flux = pow(10.0, -0.4*(Mag));
     18  return (Flux);
     19}
     20
    1521int print_measure_set_alt (Average *average, SecFilt *secfilt, Measure *measure) {
    1622
     
    3036}
    3137
     38int setMrelAverageForcedWarp (off_t measureOffset, int cat, int pass, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t *found);
     39
    3240int setMrel_catalog_alt (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt) {
    3341
    3442  off_t j;
    3543
    36   liststats_setmode (&results->stats, STATMODE);
     44  liststats_setmode (&results->psfstats, STATMODE);
    3745  liststats_setmode (&results->apstats, STATMODE);
    3846  liststats_setmode (&results->kronstats, STATMODE);
     
    5260    Average *average = catalog[Nc].average ? &catalog[Nc].average[j] : NULL;
    5361    Measure *measure = catalog[Nc].measure ? &catalog[Nc].measure[m] : NULL;
    54     setMrelAverageExposure (m, Nc, pass, flatcorr, results, average, &catalog[Nc].averageT[j], &catalog[Nc].secfilt[j*Nsecfilt], measure, &catalog[Nc].measureT[m], &catalog[Nc].found[Nsecfilt*j]);
     62    setMrelAverageExposure (m, Nc, pass, flatcorr, results, average, &catalog[Nc].averageT[j], &catalog[Nc].secfilt[j*Nsecfilt], measure, &catalog[Nc].measureT[m], &catalog[Nc].found_t[Nsecfilt*j]);
    5563
    5664    // only apply Stack operation on setMrelFinal in first pass
     
    5967      setGlobalObjStats (&catalog[Nc].average[j], &catalog[Nc].measure[m]);
    6068    }
     69
     70    // only measure force-warp mean values if issetMrelFinal (make it optional?)
     71    if (isSetMrelFinal) {
     72      setMrelAverageForcedWarp (m, Nc, pass, results, &catalog[Nc].average[j], &catalog[Nc].secfilt[j*Nsecfilt], &catalog[Nc].measure[m], &catalog[Nc].foundWarp_t[Nsecfilt*j]);
     73      setGlobalObjStats (&catalog[Nc].average[j], &catalog[Nc].measure[m]);
     74    }
    6175  }
    6276  if (primaryCell) free (primaryCell);
     
    6478}
    6579
     80// set mean of chip measurements (selected by photcode range for now):
    6681int setMrelAverageExposure (off_t measureOffset, int cat, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, AverageTiny *averageT, SecFilt *secfilt, Measure *measure, MeasureTiny *measureT, off_t *found) {
    6782
    6883  off_t k;
    69   int N;
    7084  float Msys = 0, Mcal= 0, Mmos = 0, Mgrid = 0;
    7185
    72   double *list      = results->list;
    73   double *dlist     = results->dlist;
    74   double *wlist     = results->wlist;
    75   double *aplist    = results->aplist;
    76   double *kronlist  = results->kronlist;
     86  // we are measuring means for 3 types of mags: psf, ap, kron.  I am using the psf mag
     87  // error for the ap mags, but krons have their own errors.  it is an open question if I
     88  // should be doing weighted or unweighted fits (this is a user option)
     89  double *Mpsflist  = results->Mpsflist;
     90  double *dpsflist  = results->dpsflist;
     91  double *wpsflist  = results->wpsflist;
     92
     93  double *Maplist   = results->Maplist;
     94  double *daplist   = results->daplist;
     95  double *waplist   = results->waplist;
     96
     97  double *Mkronlist = results->Mkronlist;
    7798  double *dkronlist = results->dkronlist;
    78 
    79   StatType *stats = &results->stats;
    80   StatType *apstats = &results->apstats;
     99  double *wkronlist = results->wkronlist;
     100
     101  StatType *psfstats  = &results->psfstats;
     102  StatType *apstats   = &results->apstats;
    81103  StatType *kronstats = &results->kronstats;
    82104
     
    125147    off_t meas = measureOffset;
    126148
    127     N = 0;
     149    int Nap = 0;
     150    int Npsf = 0;
     151    int Nkron = 0;
    128152    for (k = 0; k < averageT[0].Nmeasure; k++, meas++) {
    129153
     
    135159
    136160      // are we a PS1 exposure photcode?
    137       if ((measure[k].photcode >= 10000) && (measure[k].photcode <= 10500)) {
    138         NexpPS1 ++;
    139       }
     161      if (isGPC1chip(measureT[k].photcode)) NexpPS1 ++;
     162
     163      // SKIP gpc1 stack data
     164      if (isGPC1stack(measureT[k].photcode)) continue;
     165
     166      // SKIP gpc1 forced-warp data
     167      if (isGPC1warp(measureT[k].photcode)) continue;
    140168
    141169      if (measureT[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS(Nbad);
     
    157185
    158186      // skip some absurd values NAN, < 0.0, > 30.0
    159       Msys = PhotSysTiny (&measureT[k], &averageT[0], &secfilt[0]);
     187      Msys = PhotSysTiny (&measureT[k], &averageT[0], &secfilt[0], MAG_CLASS_PSF);
    160188      if (isnan(Msys)) SKIP_THIS_MEAS(Nsys);
    161189      if (Msys <  0.0) SKIP_THIS_MEAS(Nsys);
     
    164192      int myUbercalDist = getUbercalDist(meas, cat);
    165193      minUbercalDist = MIN(minUbercalDist, myUbercalDist);
     194
     195      int isUbercal = (measureT[k].dbFlags & ID_MEAS_PHOTOM_UBERCAL);
     196      float dMpsf = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR);
     197
     198      if (isUbercal) haveUbercal = TRUE; // haveUbercal is set per secfilt, isUbercal is per measure
    166199
    167200      if (isSetMrelFinal) {
     
    183216          }
    184217          havePS1 = TRUE;
    185         }
    186 
    187         // gpc1 stack data
    188         if ((measure[k].photcode >= 11000) && (measure[k].photcode <= 11400)) {
    189           continue;
    190218        }
    191219
     
    231259          if (measureT[k].M < MaxMagForceSynth) {
    232260            forceSynth = TRUE;
    233             forceSynthEntry = N;
     261            forceSynthEntry = Npsf;
    234262          } else {
    235263            if (pass < 4) {
     
    240268        }
    241269
    242         // Map (aplist) and Mkron (kronlist,dkronlist) are used to calculate mean mags per filter
    243         float Map = PhotAper (&measure[k]);
    244         aplist[N] = Map - Mcal - Mmos - Mgrid;
    245 
    246         float Mkron = PhotKron (&measure[k]);
    247         kronlist[N] = Mkron - Mcal - Mmos - Mgrid;
    248         dkronlist[N] = measure[k].dMkron;
    249       }
     270        // Map (Maplist) and Mkron (Mkronlist,dkronlist) are used to calculate mean mags per filter
     271        float Map = PhotCat (&measure[k], MAG_CLASS_APER);
     272        if (!isnan(Map)) {
     273            Maplist[Nap] = Map - Mcal - Mmos - Mgrid;
     274            daplist[Nap] = dMpsf;// XXX check on this...
     275            waplist[Nap] = isUbercal ? UBERCAL_WEIGHT : 1.0;
     276            Nap ++;
     277        }
     278
     279        float Mkron = PhotCat (&measure[k], MAG_CLASS_KRON);
     280        if (!isnan(Mkron)) {
     281          Mkronlist[Nkron] = Mkron - Mcal - Mmos - Mgrid;
     282          dkronlist[Nkron] = measure[k].dMkron;
     283          wkronlist[Nkron] = isUbercal ? UBERCAL_WEIGHT : 1.0;
     284          Nkron ++;
     285        }
     286      } // if (isSetMrelFinal)
    250287
    251288      // dlist gives the error per measurement, wlist gives the weight
     
    255292      // 3) UBERCAL measurements can have their weight increased by a big factor to help tie down the averages
    256293      // 4) some reference photcode of some kind can be specified as fixed and have a high weight
    257       dlist[N] = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR);
    258       wlist[N] = 1.0;
    259       list[N]  = Msys - Mcal - Mmos - Mgrid;
    260 
    261       // up-weight the ubercal values (or convergence can take a long time...)
    262       if (measureT[k].dbFlags & ID_MEAS_PHOTOM_UBERCAL) {
    263         haveUbercal = TRUE;
    264         wlist[N] = 10.0;
    265       }
     294      Mpsflist[Npsf] = Msys - Mcal - Mmos - Mgrid;
     295      dpsflist[Npsf] = dMpsf;
     296      wpsflist[Npsf] = isUbercal ? UBERCAL_WEIGHT : 1.0;
     297
     298      // NOTE:
     299      // Msys is measure[i].M + zp corrections
     300      // Mcal is image[j].Mcal
     301      // Mmos and Mgrid are offsets for mosaic and grid
    266302
    267303      // tie down reference photometry if the -refcode (code) option is selected
    268304      // eg, -refcode g_SDSS
    269305      // this probably makes no sense in the context of multifilter analysis
     306      // XXX probably need to use the photocde table to assign reference mag weights.
    270307      if (refPhotcode) {
    271308        if (code->code == refPhotcode->code) {
    272           wlist[N] = 100.0;
     309          wpsflist[Npsf] = UBERCAL_WEIGHT;
    273310        }
    274311      }
    275       N++;
     312      Npsf ++;
    276313    }
    277314
     
    281318    if (isSetMrelFinal && (pass == 0)) {
    282319      if ((thisCode < 6) || (thisCode == 9)) {
    283         secfilt[Nsec].Ncode = NexpPS1;
     320        secfilt[Nsec].Ncode = NexpPS1; 
    284321      } else {
    285322        secfilt[Nsec].Ncode = Ncode; // 2MASS data if it exists
     
    288325
    289326    // when performing the grid analysis, STAR_TOOFEW should be set to 1;
    290     if (N < Nminmeas) { /* too few measurements */
    291       // fprintf (f, "%10.6f %10.6f %d %d %d\n", averageT[0].R, averageT[0].D, measureT[0].imageID, N, STAR_TOOFEW);
     327    if (Npsf < Nminmeas) { /* too few measurements */
     328      // fprintf (f, "%10.6f %10.6f %d %d %d\n", averageT[0].R, averageT[0].D, measureT[0].imageID, Npsf, STAR_TOOFEW);
    292329      secfilt[Nsec].flags |= ID_STAR_FEW;
    293330      if (Ncode == 0) {
     
    303340    if (forceSynth) {
    304341      // use the single SYNTH value instead of the other mags here
    305       myAssert ((forceSynthEntry < N) && (forceSynthEntry >= 0), "programming error");
    306       list[0]  = list[forceSynthEntry];
    307       dlist[0] = dlist[forceSynthEntry];
    308       wlist[0] = wlist[forceSynthEntry];
    309       N = 1;
    310     }
    311     liststats (list, dlist, wlist, N, stats);
    312 
    313     secfilt[Nsec].M  = stats->mean;
    314     secfilt[Nsec].dM = stats->error;
    315     secfilt[Nsec].Xm = (stats->Nmeas > 1) ? 100.0*log10(stats->chisq + 1e-4) : NAN_S_SHORT;
     342      myAssert ((forceSynthEntry < Npsf) && (forceSynthEntry >= 0), "programming error");
     343      Mpsflist[0] = Mpsflist[forceSynthEntry];
     344      dpsflist[0] = dpsflist[forceSynthEntry];
     345      wpsflist[0] = wpsflist[forceSynthEntry];
     346      Npsf = 1;
     347    }
     348    liststats (Mpsflist, dpsflist, wpsflist, Npsf, psfstats);
     349
     350    secfilt[Nsec].M      = psfstats->mean;
     351    secfilt[Nsec].dM     = psfstats->error;
     352    secfilt[Nsec].Mchisq = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN;
    316353
    317354    // when running -averages, we have no information about the images, so we cannot set this
     
    323360      found[Nsec] = TRUE;
    324361
    325       secfilt[Nsec].Mstdev = 1000.0*stats->sigma; // Mstdev is in millimags (not enough space for more precision)
     362      secfilt[Nsec].Mstdev = psfstats->sigma; // Mstdev is in millimags (not enough space for more precision)
    326363      // secfilt[Nsec].Ncode = Ncode;
    327       secfilt[Nsec].Nused = stats->Nmeas;
    328 
    329       secfilt[Nsec].M_80 = 1000 * stats->Upper80;
    330       secfilt[Nsec].M_20 = 1000 * stats->Lower20;
     364      secfilt[Nsec].Nused = psfstats->Nmeas;
     365
     366      secfilt[Nsec].Mmax = psfstats->max;
     367      secfilt[Nsec].Mmin = psfstats->min;
    331368
    332369      // NOTE : use the modified weight for apmags as well as psf mags
    333       liststats (aplist, dlist, wlist, N, apstats);
    334       secfilt[Nsec].Map  = apstats->mean;
    335 
    336       liststats (kronlist, dkronlist, wlist, N, kronstats);
    337       secfilt[Nsec].Mkron  = kronstats->mean;
    338       secfilt[Nsec].dMkron = kronstats->error;
     370      liststats (Maplist, daplist, waplist, Nap, apstats);
     371      secfilt[Nsec].Map  = Nap > 0 ? apstats->mean : NAN;
     372      secfilt[Nsec].dMap  = Nap > 0 ? apstats->error : NAN;
     373      secfilt[Nsec].sMap  = Nap > 0 ? apstats->sigma : NAN;
     374      secfilt[Nsec].NusedAp  = Nap;
     375
     376      liststats (Mkronlist, dkronlist, wkronlist, Nkron, kronstats);
     377      secfilt[Nsec].Mkron  = Nkron > 0 ? kronstats->mean  : NAN;
     378      secfilt[Nsec].dMkron = Nkron > 0 ? kronstats->error : NAN;
     379      secfilt[Nsec].sMkron = Nkron > 0 ? kronstats->sigma : NAN;
     380      secfilt[Nsec].NusedKron  = Nkron;
    339381
    340382      // NOTE: for 2MASS measurements, Next should be 1, as should N
    341       if ((Next > 0) && (Next > 0.5*N)) {
     383      if ((Next > 0) && (Next > 0.5*Npsf)) {
    342384        secfilt[Nsec].flags |= ID_SECF_OBJ_EXT;
    343385      }
     
    405447  float Msys = 0, Mcal= 0, Mmos = 0, Mgrid = 0;
    406448
    407   // set the name of the primary skycell (this is used in a strcmp to match the skycells in stack detections)
    408   // XXX drop BoundaryTreePrimaryCell(primaryCell, average[0].R, average[0].D);
     449  // set the primary projection cell and skycell for this coordinate
     450  int tessID    = -1;
    409451  int projectID = -1;
    410452  int skycellID = -1;
    411   BoundaryTreePrimaryCellIDs(&projectID, &skycellID, average[0].R, average[0].D);
     453  get_tess_ids(&tessID, &projectID, &skycellID, average[0].R, average[0].D);
    412454
    413455  int NstackGood = 0;
     
    449491
    450492      // only examine gpc1 stack data
    451       // XXX this is absurdly hardwired (along with several photcode tests)
    452       if (measure[k].photcode < 11000) continue;
    453       if (measure[k].photcode > 11400) continue;
     493      if (!isGPC1stack(measure[k].photcode)) continue;
    454494
    455495      haveStack = TRUE;
     
    470510      if (isnan(Mgrid)) SKIP_THIS_MEAS_STACK(Ngrid);
    471511
    472       Msys = PhotSys (&measure[k], &average[0], &secfilt[0]);
     512      Msys = PhotSys (&measure[k], &average[0], &secfilt[0], MAG_CLASS_PSF);
    473513      if (isnan(Msys)) SKIP_THIS_MEAS_STACK(Nsys);
    474514
     
    477517      // which stack image should we use for the mean value?
    478518      // if we request the primary (USE_TREE_FOR_PRIMARY), then find the min distances for data from the primary cell
    479       if (MatchImageSkycellID (meas, cat, projectID, skycellID)) {
     519      if (MatchImageSkycellID (meas, cat, tessID, projectID, skycellID)) {
    480520        float stackPrimaryOffset = getCenterOffset (meas, cat, &measure[k], &stackImageID);
    481521        if (stackPrimaryOffset < stackPrimaryOffsetMin) {
     
    558598
    559599    // need to put in AB mag factor to get to Janskies (or uJy?)
    560     secfilt[Nsec].FluxPSF   = zpFactor * measure[k].FluxPSF; 
    561     secfilt[Nsec].dFluxPSF  = zpFactor * measure[k].dFluxPSF;
    562     secfilt[Nsec].FluxKron  = zpFactor * measure[k].FluxKron;
    563     secfilt[Nsec].dFluxKron = zpFactor * measure[k].dFluxKron;
     600    secfilt[Nsec].FpsfStk   = zpFactor * measure[k].FluxPSF; 
     601    secfilt[Nsec].dFpsfStk  = zpFactor * measure[k].dFluxPSF;
     602    secfilt[Nsec].FkronStk  = zpFactor * measure[k].FluxKron;
     603    secfilt[Nsec].dFkronStk = zpFactor * measure[k].dFluxKron;
     604    secfilt[Nsec].FapStk    = zpFactor * measure[k].FluxAp;
     605    secfilt[Nsec].dFapStk   = zpFactor * measure[k].dFluxAp;
     606
     607    secfilt[Nsec].MpsfStk   = (measure[k].FluxPSF  > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FpsfStk) : NAN;
     608    secfilt[Nsec].MkronStk  = (measure[k].FluxKron > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FkronStk) : NAN;
     609    secfilt[Nsec].MapStk    = (measure[k].FluxAp   > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FapStk) : NAN;
    564610
    565611    secfilt[Nsec].stackDetectID = ID;
     
    584630}
    585631
     632# undef SKIP_THIS_MEAS
     633# define SKIP_THIS_MEAS(REASON) {                               \
     634    measure[k].dbFlags |= ID_MEAS_SKIP_PHOTOM;  \
     635    results->REASON ++;                                         \
     636    continue; }
     637
     638// set mean of forced-warp measurements (selected by photcode range for now):
     639// somewhat simplified relative to chip-photometry:
     640// * no grid, no mosaic, no 2MASS, no SYNTH, no Ubercal, no flatcorr
     641int setMrelAverageForcedWarp (off_t measureOffset, int cat, int pass, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t *found) {
     642
     643  off_t k;
     644  float Fsys = 0, Mcal= 0;
     645
     646  // we are measuring means for 3 types of FLUXes: psf, ap, kron.  I am using the psf mag
     647  // error for the ap mags, but krons have their own errors.  it is an open question if I
     648  // should be doing weighted or unweighted fits (this is a user option)
     649  double *Fpsflist  = results->Mpsflist;
     650  double *dpsflist  = results->dpsflist;
     651  double *wpsflist  = results->wpsflist;
     652
     653  double *Faplist   = results->Maplist;
     654  double *daplist   = results->daplist;
     655  double *waplist   = results->waplist;
     656
     657  double *Fkronlist = results->Mkronlist;
     658  double *dkronlist = results->dkronlist;
     659  double *wkronlist = results->wkronlist;
     660
     661  StatType *psfstats  = &results->psfstats;
     662  StatType *apstats   = &results->apstats;
     663  StatType *kronstats = &results->kronstats;
     664
     665  // option for a test print
     666  if (FALSE && (average[0].objID == 0x7146) && (average[0].catID == 0x49d8)) {
     667    fprintf (stderr, "test obj\n");
     668    print_measure_set_alt (average, secfilt, measure);
     669  }
     670
     671  int Ns;
     672  for (Ns = 0; Ns < Nphotcodes; Ns++) {
     673
     674    int thisCode = photcodes[Ns][0].code;
     675    int Nsec = GetPhotcodeNsec(thisCode);
     676
     677    /* calculate the average mag in this SEC photcode for a single star */
     678
     679    /* star/photcodes already calibrated */
     680    if (found[Nsec]) continue; 
     681     
     682    off_t meas = measureOffset;
     683
     684    int Nap = 0;
     685    int Npsf = 0;
     686    int Nkron = 0;
     687    for (k = 0; k < average[0].Nmeasure; k++, meas++) {
     688
     689      // only examine gpc1 forced-warp data
     690      if (!isGPC1warp(measure[k].photcode)) continue;
     691
     692      // skip measurements that do not match the current photcode
     693      PhotCode *code = GetPhotcodebyCode (measure[k].photcode);
     694      if (!code) continue;
     695      if (code->equiv != thisCode) { continue; }
     696
     697      if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS(Nbad);
     698
     699      if (getImageEntry (meas, cat) < 0) {
     700        // measurements without an image are either external reference photometry or
     701        // data for which the associated image has not been loaded (probably because of
     702        // overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
     703        Mcal = measure[k].Mcal; // check that this is zero for loaded REF value
     704      } else {
     705        // use getMcal not getMcal_alt?
     706        Mcal  = getMcal_alt (meas, cat, NULL, measure[k].Xccd, measure[k].Yccd);
     707        // Mcal  = getMcal (meas, cat);
     708        if (isnan(Mcal))  SKIP_THIS_MEAS(Ncal);
     709      }
     710      float Fcal = MagToFlux(-Mcal);
     711
     712      // in the calculations below,
     713      // ...list gives the error per measurement, wlist gives the weight
     714      // we can modify the error and weight in a few ways:
     715      // 1) MIN_ERROR guarantees a floor
     716      // 2) photomErrSys is added in quadrature as a sytematic error, set per photcode
     717
     718      // skip some absurd values NAN
     719      // NOTE : I am using PhotCat not PhotSys for now since GPC1 chip-to-chip color terms
     720      // are small (and not measured)
     721      float Fpsf = PhotFluxCat (&measure[k], MAG_CLASS_PSF);
     722      if (isnan(Fsys)) SKIP_THIS_MEAS(Nsys);
     723      // if (Msys <  0.0) SKIP_THIS_MEAS(Nsys);
     724      // if (Msys > 30.0) SKIP_THIS_MEAS(Nsys);
     725
     726      float dFpsf = PhotFluxCatErr (&measure[k], MAG_CLASS_PSF);
     727      dFpsf = MAX (dFpsf, MIN_ERROR*Fpsf); // MIN_ERROR is a fractional error
     728      Fpsflist[Npsf] = Fpsf * Fcal;
     729      dpsflist[Npsf] = dFpsf * Fcal;
     730      wpsflist[Npsf] = 1.0;
     731      Npsf ++;
     732
     733      float Fap = PhotFluxCat (&measure[k], MAG_CLASS_APER);
     734      float dFap = PhotFluxCatErr (&measure[k], MAG_CLASS_APER);
     735      if (!isnan(Fap)) {
     736        Faplist[Nap] = Fap * Fcal;
     737        daplist[Nap] = dFap * Fcal;
     738        waplist[Nap] = 1.0; // drop weight lists?
     739        Nap ++;
     740      }
     741
     742      float Fkron = PhotFluxCat (&measure[k], MAG_CLASS_KRON);
     743      float dFkron = PhotFluxCatErr (&measure[k], MAG_CLASS_KRON);
     744      if (!isnan(Fkron)) {
     745        Fkronlist[Nkron] = Fkron * Fcal;
     746        dkronlist[Nkron] = dFkron * Fcal;
     747        wkronlist[Nkron] = 1.0;
     748        Nkron ++;
     749      }
     750    }
     751    if (Npsf < 1) continue;
     752
     753    found[Nsec] = TRUE;
     754
     755    liststats (Fpsflist, dpsflist, wpsflist, Npsf, psfstats);
     756
     757    secfilt[Nsec].FpsfWrp  = psfstats->mean;
     758    secfilt[Nsec].dFpsfWrp = psfstats->error;
     759    secfilt[Nsec].sFpsfWrp = psfstats->sigma; // Mstdev is in millimags (not enough space for more precision)
     760    secfilt[Nsec].NusedWrp = psfstats->Nmeas;
     761    secfilt[Nsec].MpsfWrp  = isnan(secfilt[Nsec].FpsfWrp) ? NAN : 8.9 - 2.5*log10(secfilt[Nsec].FpsfWrp); // 8.9 since flux is in Jy
     762
     763    // NOTE : use the modified weight for apmags as well as psf mags
     764    liststats (Faplist, daplist, waplist, Nap, apstats);
     765    secfilt[Nsec].FapWrp     = Nap > 0 ? apstats->mean : NAN;
     766    secfilt[Nsec].dFapWrp    = Nap > 0 ? apstats->error : NAN;
     767    secfilt[Nsec].sFapWrp    = Nap > 0 ? apstats->sigma : NAN;
     768    secfilt[Nsec].NusedApWrp = Nap;
     769    secfilt[Nsec].MapWrp  = isnan(secfilt[Nsec].FapWrp) ? NAN : 8.9 - 2.5*log10(secfilt[Nsec].FapWrp); // 8.9 since flux is in Jy
     770
     771    liststats (Fkronlist, dkronlist, wkronlist, Nkron, kronstats);
     772    secfilt[Nsec].FkronWrp     = Nkron > 0 ? kronstats->mean  : NAN;
     773    secfilt[Nsec].dFkronWrp    = Nkron > 0 ? kronstats->error : NAN;
     774    secfilt[Nsec].sFkronWrp    = Nkron > 0 ? kronstats->sigma : NAN;
     775    secfilt[Nsec].NusedKronWrp = Nkron;
     776    secfilt[Nsec].MkronWrp  = isnan(secfilt[Nsec].FkronWrp) ? NAN : 8.9 - 2.5*log10(secfilt[Nsec].FkronWrp); // 8.9 since flux is in Jy
     777  }
     778  return (TRUE);
     779}
     780
    586781int setGlobalObjStats (Average *average, Measure *measure) {
    587782
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/relphot/src/setMrelFinal.c

    r35759 r37067  
    8585
    8686  /* set catalog[0].found[i] = FALSE */
    87   ALLOCATE (catalog[0].found, off_t, MAX (1, Nsecfilt*catalog[0].Naverage));
     87  ALLOCATE (catalog[0].found_t, off_t, MAX (1, Nsecfilt*catalog[0].Naverage));
     88  ALLOCATE (catalog[0].foundWarp_t, off_t, MAX (1, Nsecfilt*catalog[0].Naverage));
    8889  for (i = 0; i < Nsecfilt*catalog[0].Naverage; i++) {
    89     catalog[0].found[i] = FALSE;
     90    catalog[0].found_t[i] = FALSE;
     91    catalog[0].foundWarp_t[i] = FALSE;
    9092  }
    9193
     
    194196     
    195197      /* star/photcodes already calibrated */
    196       if (catalog[0].found[Nsecfilt*i+Nsec]) continue; 
     198      if (catalog[0].found_t[Nsecfilt*i+Nsec]) continue; 
    197199
    198200      m = catalog[0].average[i].measureOffset;
     
    229231        if ((pass < 4) && ImagSelect) {
    230232          if (Nim > -1) {
    231             mag = PhotInst (&catalog[0].measure[m]);
     233            mag = PhotInst (&catalog[0].measure[m], MAG_CLASS_PSF);
    232234            if (mag < ImagMin) goto skip;
    233235            if (mag > ImagMax) goto skip;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/tools/Makefile

    r31496 r37067  
    1717PROGRAMS = gconfig fhead ftable fields list_astro glockfile \
    1818radec mktemp precess csystem fits_insert \
    19 medianfilter mefhead ckfits roc
     19medianfilter mefhead ckfits roc random
    2020
    2121all tools: $(PROGRAMS)
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/tools/src/ftable.c

    r34260 r37067  
    460460      } else {
    461461        for (j = 0; j < Nv; j++) {
     462          if (!strcmp (type, "byte")) {
     463            memcpy (line, &data[i*Nv*Nb + Nb*j], Nb);
     464            fprintf (stdout, "%d ", *(char *)line);
     465          }
     466          if (!strcmp (type, "short")) {
     467            memcpy (line, &data[i*Nv*Nb + Nb*j], Nb);
     468            fprintf (stdout, "%d ", *(short *)line);
     469          }
    462470          if (!strcmp (type, "int")) {
    463471            memcpy (line, &data[i*Nv*Nb + Nb*j], Nb);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/tools/src/medianfilter.c

    r20652 r37067  
    9696    for (j = 0; j < Npixrd; j++, O++) {
    9797      Nvalid = 0;
     98      int debug = FALSE && (n == 5) && (j >= 1776779) && (j <= 1776789);
    9899      for (k = 0; k < Nfiles; k++) {
    99100        v = (float *)tmpmatr[k].buffer;
     101        if (debug) {
     102            fprintf (stderr, "%8.2f ", v[j]);
     103        }
    100104        if (v[j] < MinValid) continue;
    101         if (isnan(v[j])) continue;
    102         if (isinf(v[j])) continue;
    103         list[k] = v[j];
     105        if (isnan(v[j])) {
     106            continue;
     107        }
     108        if (isinf(v[j])) {
     109            continue;
     110        }
     111        list[Nvalid] = v[j];
    104112        Nvalid ++;
    105113      }
     114      if (debug) fprintf (stderr, "\n");
    106115      if (Nvalid == 0) {
    107         *O = 0.0;
     116        *O = NAN;
     117        if (debug) {
     118            fprintf (stderr, "Nvalid is 0\n");
     119        }
    108120        continue;
    109121      }
     
    111123      sum = 0;
    112124      Nval = 0;
     125      if (debug) fprintf (stderr, "list : ");
    113126      for (k = fmin*Nvalid; k < fmax*Nvalid; k++) {
     127        if (debug) {
     128            fprintf (stderr, "%8.2f ", list[k]);
     129        }
    114130        sum += list[k];
    115131        Nval ++;
    116132      }
    117133      *O = (sum / Nval);
     134      if (debug) {
     135          fprintf (stderr, " = %f / %f = %f\n", sum, Nval, *O);
     136          fprintf (stderr, "\n");
     137      }
    118138    }
    119139
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/uniphot/src/ImageSubset.c

    r33654 r37067  
    9999  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_SUBSET");
    100100
    101   gfits_define_bintable_column (&theader, "E", "MCAL", "zero point offset", "magnitudes", 1.0, 0.0);
    102   gfits_define_bintable_column (&theader, "E", "MCAL_ERR", "zero point error", "magnitudes", 1.0, 0.0);
    103 
    104   // an unsigned int needs to have bzero of 0x8000
    105   gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image ID", NULL, 1.0, 1.0*0x8000);
    106   gfits_define_bintable_column (&theader, "J", "PHOTOM_MAP", "map", NULL, 1.0, 1.0*0x8000);
    107   gfits_define_bintable_column (&theader, "J", "FLAGS", "flags", NULL, 1.0, 1.0*0x8000);
     101  gfits_define_bintable_column (&theader, "E", "MCAL",       "zero point offset", "magnitudes", 1.0, 0.0);
     102  gfits_define_bintable_column (&theader, "E", "MCAL_ERR",   "zero point error",  "magnitudes", 1.0, 0.0);
     103  gfits_define_bintable_column (&theader, "J", "IMAGE_ID",   "image ID",          NULL,         1.0, FT_BZERO_INT32);
     104  gfits_define_bintable_column (&theader, "J", "PHOTOM_MAP", "map",               NULL,         1.0, FT_BZERO_INT32);
     105  gfits_define_bintable_column (&theader, "J", "FLAGS",      "flags",             NULL,         1.0, FT_BZERO_INT32);
    108106
    109107  // generate the output array that carries the data
     
    114112
    115113  // create intermediate storage arrays
    116   ALLOCATE (Mcal,  float, Nimage);
    117   ALLOCATE (dMcal, float, Nimage);
     114  ALLOCATE (Mcal,    float,        Nimage);
     115  ALLOCATE (dMcal,   float,        Nimage);
    118116  ALLOCATE (imageID, unsigned int, Nimage);
    119117  ALLOCATE (map,     unsigned int, Nimage);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/uniphot/src/ImageSubsetFixImageIDs.c

    r35764 r37067  
    11# include "fiximids.h"
    2 # define FT_BZERO_INT16 1.0*0x8000       
    3 # define FT_BZERO_INT32 1.0*0x80000000
    42
    53# define GET_COLUMN(OUT,NAME,TYPE) \
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/uniphot/src/ImageSubsetFixStackIDs.c

    r35764 r37067  
    11# include "fixstkids.h"
    2 # define FT_BZERO_INT16 1.0*0x8000       
    3 # define FT_BZERO_INT32 1.0*0x80000000
    42
    53# define GET_COLUMN(OUT,NAME,TYPE) \
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/uniphot/src/ImageSubsetSetPosangle.c

    r34749 r37067  
    149149  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_SUBSET");
    150150
    151   // an unsigned int needs to have bzero of 0x8000
    152   gfits_define_bintable_column (&theader, "J",   "IMAGE_ID",   "image ID", NULL, 1.0, 1.0*0x8000);
     151  gfits_define_bintable_column (&theader, "J",   "IMAGE_ID",   "image ID", NULL, 1.0, FT_BZERO_INT32);
    153152  gfits_define_bintable_column (&theader, "E",   "TZERO",      "tmp",      "mp", 1.0, 0.0);
    154153  gfits_define_bintable_column (&theader, "E",   "TRATE",      "tmp",      "mp", 1.0, 0.0);
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/uniphot/src/find_image_sgroups.c

    r31160 r37067  
    2222  coords.pc1_1 = coords.pc2_2 = 1.0;
    2323  coords.pc1_2 = coords.pc2_1 = 0.0;
    24   strcpy (coords.ctype, "RA---TAN");
     24  strcpy (coords.ctype, "DEC--TAN");
    2525 
    2626  Ngroup = 0;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/uniphot/src/load_images_fiximids.c

    r35764 r37067  
    11# include "fiximids.h"
    2 # define FT_BZERO_INT32 1.0*0x80000000
    32
    43off_t   Nimage = 0;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/uniphot/src/load_images_fixstkids.c

    r35764 r37067  
    11# include "fixstkids.h"
    2 # define FT_BZERO_INT32 1.0*0x80000000
    32
    43off_t Nimage = 0;
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/uniphot/src/update_catalog_fiximids.c

    r35764 r37067  
    11# include "fiximids.h"
     2
     3// test image: 2013/06/15,13:25:51, GPC1.r.XY50
     4static int CHECK_TEST_IMAGE = FALSE;
     5static unsigned int Tref = 1378812312;
     6static short Cref = 10001;
    27
    38void update_catalog_fiximids (Catalog *catalog) {
     
    1823    short photcode = catalog[0].measure[i].photcode;
    1924    e_time time = catalog[0].measure[i].t;
     25
     26    if (CHECK_TEST_IMAGE && (abs(time - Tref) < 10) && (photcode == Cref)) {
     27      fprintf (stderr, ".");
     28    }
    2029
    2130    // skip detections with no valid imageID (eg, ref photcode)
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/uniphot/src/update_catalog_setastrom.c

    r35103 r37067  
    7676    // correction may be Minst or Minst + 5.0*log(fwhm
    7777    float fwhm_maj = FromShortPixels(measure[0].FWx);
    78     float Minst = PhotInst (measure);
     78    float Minst = PhotInst (measure, MAG_CLASS_PSF);
    7979    float MinstSB = Minst + 5.0*log10(fwhm_maj);
    8080
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/uniphot/src/update_dvo_setphot.c

    r35103 r37067  
    22int update_dvo_setphot_parallel (SkyTable *sky, Image *image, off_t Nimage);
    33
     4// XXX convert this to use the ImageSubset to save space
    45int update_dvo_setphot (Image *image, off_t Nimage, FlatCorrectionTable *flatcorr) {
    56
  • branches/eam_branches/ipp-ops-20130712/Ohana/src/uniphot/src/update_dvo_uniphot.c

    r34088 r37067  
    6161  coords.pc1_1 = coords.pc2_2 = 1.0;
    6262  coords.pc1_2 = coords.pc2_1 = 0.0;
    63   strcpy (coords.ctype, "RA---TAN");
     63  strcpy (coords.ctype, "DEC--TAN");
    6464 
    6565  for (i = 0; i < pglob.gl_pathc; i++) {
Note: See TracChangeset for help on using the changeset viewer.