IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

merge changes from trunk

Location:
branches/eam_branches/ps2-tc3-20130727
Files:
1 deleted
278 edited
73 copied

Legend:

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

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

  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/Makefile

    r35263 r37403  
    7878$(SRC)/parse_time.$(ARCH).o \
    7979$(SRC)/replace_match.$(ARCH).o \
    80 $(SRC)/resort_catalog.$(ARCH).o \
     80$(SRC)/resort_catalogs.$(ARCH).o \
    8181$(SRC)/resort_threaded.$(ARCH).o \
    8282$(SRC)/resort_unthreaded.$(ARCH).o \
    83 $(SRC)/resort_unthreaded_catalogs.$(ARCH).o \
     83$(SRC)/resort_catalog.$(ARCH).o \
    8484$(SRC)/StarOps.$(ARCH).o \
    8585$(SRC)/ReadStarsFITS.$(ARCH).o \
    8686$(SRC)/ReadStarsTEXT.$(ARCH).o \
    8787$(SRC)/ReadStarsSDSS.$(ARCH).o \
     88$(SRC)/ReadXradFITS.$(ARCH).o \
    8889$(SRC)/FilterStars.$(ARCH).o \
    8990$(SRC)/ImageOptions.$(ARCH).o \
     
    105106$(SRC)/addstar_client.$(ARCH).o \
    106107$(SRC)/args_parallel_client.$(ARCH).o \
    107 $(SRC)/resort_catalog.$(ARCH).o \
     108$(SRC)/resort_catalogs.$(ARCH).o \
    108109$(SRC)/resort_threaded.$(ARCH).o \
    109110$(SRC)/resort_unthreaded.$(ARCH).o \
    110 $(SRC)/resort_unthreaded_catalogs.$(ARCH).o
     111$(SRC)/resort_catalog.$(ARCH).o
    111112
    112113ADDSTARD = \
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/include/addstar.h

    r35579 r37403  
    3535  char *exthead;
    3636  char *extdata;
     37  char *extxrad;
    3738  char *exttype;
    3839  int extnum_head;
    3940  int extnum_data;
     41  int extnum_xrad;
    4042} HeaderSet;
    4143
    4244typedef struct {
    43   Average average;
    44   Measure measure;
     45  Average  average;
     46  Measure  measure;
     47  Lensing *lensing; // optionally carry out the lensing measurements
    4548  int found;
    4649} Stars;
     
    145148
    146149int     OLD_RESORT;
     150int     READ_XRAD_DATA;
    147151
    148152int    PARALLEL;
     
    236240Stars     *rd_gsc                 PROTO((char *filename, unsigned int *nstars));
    237241int        replace_match          PROTO((Average *average, Measure *measure, Stars *star));
    238 int        resort_threaded        PROTO((AddstarClientOptions *options, SkyTable *sky));
    239 int        resort_unthreaded      PROTO((AddstarClientOptions *options, SkyTable *sky, int hostID, char *hostpath));
    240 int        resort_unthreaded_catalogs PROTO((AddstarClientOptions *options, SkyList *skylist, int hostID, char *hostpath));
     242int        resort_catalogs        PROTO((AddstarClientOptions *options, SkyTable *sky));
     243int        resort_catalogs_parallel PROTO((AddstarClientOptions *options, SkyList *sky));
     244int        resort_threaded        PROTO((SkyList *skylist, int ForceSort));
     245int        resort_unthreaded      PROTO((SkyList *skylist, int ForceSort));
    241246void       resort_catalog         PROTO((Catalog *catalog));
    242247void       resort_catalog_old     PROTO((Catalog *catalog));
     248
    243249Stars     *ReadStarsFITS          PROTO((FILE *f, Header *header, Header *in_theader, unsigned int *nstars));
    244250Stars     *ReadStarsTEXT          PROTO((FILE *f, unsigned int *nstars));
     
    247253Stars     *FilterStars            PROTO((Stars *instars, Image *image, unsigned int imageID, const AddstarClientOptions *options));
    248254Stars     *MergeStars             PROTO((Stars *stars, unsigned int *Nstars, Stars *instars, unsigned int Ninstars));
     255
     256int        ReadXradFITS           PROTO((FILE *f, Header *theader, Stars *stars, unsigned int Nstars));
     257
    249258double     scat_subpix            PROTO((double x, double y));
    250259void       update_coords          PROTO((Average *average, Measure *measure, off_t *next));
    251260off_t     *init_measure_links     PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
     261off_t     *init_lensing_links     PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
    252262off_t     *init_missing_links     PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing));
    253 off_t      add_meas_link          PROTO((Average *average, off_t *next_meas, off_t Nmeasure, off_t NMEASURE));
    254 off_t      add_miss_link          PROTO((Average *average, off_t *next_miss, off_t Nmissing));
     263int        add_meas_link          PROTO((Average *average, off_t *next_meas, off_t Nmeasure, off_t NMEASURE));
     264int        add_miss_link          PROTO((Average *average, off_t *next_miss, off_t Nmissing));
     265int        add_lens_link          PROTO((Average *average, off_t *next_lens, off_t Nlensing, off_t NLENSING));
    255266off_t     *build_measure_links    PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
     267off_t     *build_lensing_links    PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
    256268Measure   *sort_measure           PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next_meas));
    257269Missing   *sort_missing           PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss));
     270Lensing   *sort_lensing           PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next_lens));
    258271int        ImageOptions           PROTO((AddstarClientOptions *options, Image *images, off_t Nimages));
    259272int        GetFileMode            PROTO((Header *header));
     
    311324void *memrchr(const void *s, int c, size_t n);
    312325int addstar_create_ID ();
     326int strextend (char *input, char *format,...);
    313327
    314328/**
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/BoundaryTreeIO.c

    r34260 r37403  
    11# include "addstar.h"
     2
     3/** this file is deprecated (functions moved to libdvo) ***/
    24
    35# define GET_COLUMN_NEW(OUT,NAME,TYPE)                                  \
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/FilterStars.c

    r34260 r37403  
    99
    1010// the imageID supplied here is the sequence **within this set**
    11 // this value is updated based on the image table later
     11// this value is updated based on the image table later (in UpdateImageIDs)
    1212Stars *FilterStars (Stars *instars, Image *image, unsigned int imageID, const AddstarClientOptions *options) {
    1313
     
    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?
     
    120126
    121127    stars[N].measure.imageID = imageID; // this value is updated in UpdateImageIDs
     128
     129    // add imageID to lensing entry, if it exists
     130    if (stars[N].lensing) {
     131      stars[N].lensing->imageID = imageID;
     132    }
    122133
    123134    N ++;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/GetFileMode.c

    r36680 r37403  
    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);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/LoadData.c

    r34088 r37403  
    8383      continue;
    8484    }
     85
     86    // XRAD : if we want to read the xrad table, skip to that table here:
     87    if (headerSets[i].extnum_xrad != -1) {
     88      int Nxrad = headerSets[i].extnum_xrad;
     89      Nskip = 0;
     90      for (j = 0; j < Nxrad; j++) {
     91        Nskip += extsize[j];
     92      }
     93      fseeko (f, Nskip, SEEK_SET);
     94     
     95      if (!ReadXradFITS (f, headers[Nxrad], inStars, images[0][Nvalid].nstar)) {
     96        fprintf (stderr, "problem reading the radial flux data for %s\n", headerSets[i].extdata);
     97      }
     98    }
     99
    85100    inStars = FilterStars (inStars, &images[0][Nvalid], Nvalid, options);
    86101    *stars = MergeStars (*stars, Nstars, inStars, images[0][Nvalid].nstar);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/MatchHeaders.c

    r35416 r37403  
    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
     
    7479    headerSets[Nimage].extdata     = strcreate (extname);
    7580    headerSets[Nimage].exthead     = strcreate (exthead);
     81    headerSets[Nimage].extxrad     = NULL;
    7682    headerSets[Nimage].extnum_data = i;
    7783    headerSets[Nimage].extnum_head = -1;
     84    headerSets[Nimage].extnum_xrad = -1;
     85
     86    // XXX a special case for fforce xrad data
     87    if (READ_XRAD_DATA) {
     88      // extname is foobar.psf, convert to foobar.xrad
     89      int Nchar = strlen (extname); // foobar.psf : Nchar = 10
     90      ALLOCATE (headerSets[Nimage].extxrad, char, Nchar + 2); // xrad is 1 longer than psf
     91      memcpy   (headerSets[Nimage].extxrad, extname, Nchar - 3); // Nchar - 3 = 7
     92      memcpy  (&headerSets[Nimage].extxrad[Nchar-3], "xrad", 4);
     93      headerSets[Nimage].extxrad[Nchar + 1] = 0; // put the 0 at element 11 for foobar.xrad\0
     94    }
    7895
    7996    // find the matching exthead entry
    8097    for (j = 0; j < Nheaders; j++) {
    8198      if (!gfits_scan (headers[j], ExtnameKeyword, "%s", 1, extname)) continue;
    82       if (strcmp (extname, headerSets[Nimage].exthead)) continue;
    83       headerSets[Nimage].extnum_head = j;
    84       break;
     99      if (!strcmp (extname, headerSets[Nimage].exthead)) {
     100        headerSets[Nimage].extnum_head = j;
     101        if (!READ_XRAD_DATA) break;
     102      }
     103      if (READ_XRAD_DATA && !strcmp (extname, headerSets[Nimage].extxrad)) {
     104        headerSets[Nimage].extnum_xrad = j;
     105      }
     106      if ((headerSets[Nimage].extnum_head > -1) && (headerSets[Nimage].extnum_xrad > -1)) {
     107        // we can only get here if READ_XRAD_DATA is true
     108        break;
     109      }
    85110    }
    86111
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/ReadImageHeader.c

    r31395 r37403  
    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/ps2-tc3-20130727/Ohana/src/addstar/src/ReadStarsFITS.c

    r35416 r37403  
    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
     
    148182    stars[i].measure.psfNdof    = NAN_S_INT; // not provided by SMPDATA:
    149183    stars[i].measure.psfNpix    = NAN_S_INT; // not provided by SMPDATA:
    150     stars[i].measure.crNsigma   = NAN;       // not provided by SMPDATA:
    151184    stars[i].measure.extNsigma  = NAN;       // not provided by SMPDATA:
    152185
     
    217250    stars[i].measure.psfNdof    = NAN_S_INT; // not provided by PS1_DEV_0:
    218251    stars[i].measure.psfNpix    = NAN_S_INT; // not provided by PS1_DEV_0:
    219     stars[i].measure.crNsigma   = NAN;       // not provided by PS1_DEV_0:
    220252    stars[i].measure.extNsigma  = NAN;        // not provided by PS1_DEV_0:
    221253
     
    289321    stars[i].measure.psfNdof    = NAN_S_INT; // not provided by PS1_DEV_1:
    290322    stars[i].measure.psfNpix    = NAN_S_INT; // not provided by PS1_DEV_1:
    291     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    292323    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    293324
     
    360391    stars[i].measure.dMcal      = ps1data[i].dMcal;
    361392    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     393    stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    362394                       
    363395    stars[i].measure.Mkron      = NAN; // not provided by PS1_V1:
     
    373405    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    374406    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    375     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    376407    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    377408
     
    445476    stars[i].measure.dMcal      = ps1data[i].dMcal;
    446477    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     478    stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    447479                       
    448480    stars[i].measure.Mkron      = NAN; // not provided by PS1_V1_Alt:
     
    458490    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    459491    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    460     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    461492    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    462493
     
    522553    stars[i].measure.dMcal      = ps1data[i].dMcal;
    523554    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     555    stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    524556                       
    525557    stars[i].measure.Mkron      = NAN; // not provided by PS1_V2:
     
    535567    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    536568    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    537     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    538569    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    539570
     
    595626    stars[i].measure.dMcal      = ps1data[i].dMcal;
    596627    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     628    stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    597629                       
    598630    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     
    600632                       
    601633    // 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;
     634    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     635    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    604636    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    605637    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     638    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (NAN, ps1data[i].Map);
     639    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (NAN, stars[i].measure.FluxAp, stars[i].measure.dMap);
    606640
    607641    stars[i].measure.Sky        = ps1data[i].sky;
     
    613647    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    614648    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    615     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    616649    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    617650
     
    625658                       
    626659    stars[i].measure.photFlags  = ps1data[i].flags;
     660    stars[i].measure.photFlags2 = ps1data[i].flags2;
    627661
    628662    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    676710    stars[i].measure.dMcal      = ps1data[i].dMcal;
    677711    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     712    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    678713                       
    679714    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     
    681716                       
    682717    // 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;
     718    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     719    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    685720    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    686721    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     722    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     723    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    687724
    688725    stars[i].measure.Sky        = ps1data[i].sky;
     
    695732    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    696733    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    697     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    698734    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    699735
     
    707743                       
    708744    stars[i].measure.photFlags  = ps1data[i].flags;
     745    stars[i].measure.photFlags2 = ps1data[i].flags2;
    709746
    710747    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    724761}
    725762
    726 Stars *Convert_PS1_SV1 (FTable *table, unsigned int *nstars) {
     763Stars *Convert_PS1_V5 (FTable *table, unsigned int *nstars) {
    727764
    728765  off_t Nstars;
     
    730767  double ZeroPt;
    731768  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);
     769  CMF_PS1_V5 *ps1data;
     770
     771  ps1data = gfits_table_get_CMF_PS1_V5 (table, &Nstars, NULL);
    740772  if (!ps1data) {
    741773    fprintf (stderr, "skipping inconsistent entry\n");
     
    763795    stars[i].measure.dMcal      = ps1data[i].dMcal;
    764796    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     797    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    765798                       
    766799    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    767800    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    768 
     801                       
    769802    // 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;
     803    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     804    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    772805    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    773806    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     807    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     808    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    774809
    775810    stars[i].measure.Sky        = ps1data[i].sky;
     
    782817    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    783818    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    784     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    785819    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    786820
     
    794828                       
    795829    stars[i].measure.photFlags  = ps1data[i].flags;
     830    stars[i].measure.photFlags2 = ps1data[i].flags2;
    796831
    797832    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    799834
    800835    // 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.
     836    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID.
     837
     838    // averef is set in find_matches
     839
     840    // dbFlags is zero on ingest.
    803841
    804842    // the following fields are currently not being set anywhere: t_msec
     
    808846}
    809847
    810 Stars *Convert_PS1_SV1_Alt (FTable *table, unsigned int *nstars) {
     848Stars *Convert_PS1_V5_Lensing (FTable *table, unsigned int *nstars) {
    811849
    812850  off_t Nstars;
     
    814852  double ZeroPt;
    815853  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);
     854  CMF_PS1_V5_Lensing *ps1data;
     855
     856  ps1data = gfits_table_get_CMF_PS1_V5_Lensing (table, &Nstars, NULL);
    821857  if (!ps1data) {
    822858    fprintf (stderr, "skipping inconsistent entry\n");
     
    844880    stars[i].measure.dMcal      = ps1data[i].dMcal;
    845881    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     882    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    846883                       
    847884    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    848885    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    849 
     886                       
    850887    // 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;
     888    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     889    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    853890    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    854891    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     892    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     893    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
     894
     895    stars[i].measure.Sky        = ps1data[i].sky;
     896    stars[i].measure.dSky       = ps1data[i].dSky;
     897                       
     898    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     899    stars[i].measure.psfQF      = ps1data[i].psfQF;
     900    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
     901
     902    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
     903    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
     904    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
     905
     906    stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
     907    stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
     908    stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
     909
     910    stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
     911    stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     912    stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
     913                       
     914    stars[i].measure.photFlags  = ps1data[i].flags;
     915    stars[i].measure.photFlags2 = ps1data[i].flags2;
     916
     917    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     918    stars[i].measure.detID      = ps1data[i].detID;
     919
     920    ALLOCATE (stars[i].lensing, Lensing, 1);
     921    dvo_lensing_init (stars[i].lensing);
     922
     923    stars[i].lensing->X11_sm_obj  = ps1data[i].X11_sm_obj;
     924    stars[i].lensing->X12_sm_obj  = ps1data[i].X12_sm_obj;
     925    stars[i].lensing->X22_sm_obj  = ps1data[i].X22_sm_obj;
     926    stars[i].lensing->E1_sm_obj   = ps1data[i].E1_sm_obj;
     927    stars[i].lensing->E2_sm_obj   = ps1data[i].E2_sm_obj;
     928
     929    stars[i].lensing->X11_sh_obj  = ps1data[i].X11_sh_obj;
     930    stars[i].lensing->X12_sh_obj  = ps1data[i].X12_sh_obj;
     931    stars[i].lensing->X22_sh_obj  = ps1data[i].X22_sh_obj;
     932    stars[i].lensing->E1_sh_obj   = ps1data[i].E1_sh_obj;
     933    stars[i].lensing->E2_sh_obj   = ps1data[i].E2_sh_obj;
     934
     935    stars[i].lensing->X11_sm_psf  = ps1data[i].X11_sm_psf;
     936    stars[i].lensing->X12_sm_psf  = ps1data[i].X12_sm_psf;
     937    stars[i].lensing->X22_sm_psf  = ps1data[i].X22_sm_psf;
     938    stars[i].lensing->E1_sm_psf   = ps1data[i].E1_sm_psf;
     939    stars[i].lensing->E2_sm_psf   = ps1data[i].E2_sm_psf;
     940
     941    stars[i].lensing->X11_sh_psf  = ps1data[i].X11_sh_psf;
     942    stars[i].lensing->X12_sh_psf  = ps1data[i].X12_sh_psf;
     943    stars[i].lensing->X22_sh_psf  = ps1data[i].X22_sh_psf;
     944    stars[i].lensing->E1_sh_psf   = ps1data[i].E1_sh_psf;
     945    stars[i].lensing->E2_sh_psf   = ps1data[i].E2_sh_psf;
     946
     947    // stars[i].lensing->F_ApR5    = ps1data[i].F_ApR5;
     948    // stars[i].lensing->dF_ApR5   = ps1data[i].dF_ApR5;
     949    // stars[i].lensing->sF_ApR5   = ps1data[i].sF_ApR5;
     950    // stars[i].lensing->fF_ApR5   = ps1data[i].fF_ApR5;
     951    //
     952    // stars[i].lensing->F_ApR6    = ps1data[i].F_ApR6;
     953    // stars[i].lensing->dF_ApR6   = ps1data[i].dF_ApR6;
     954    // stars[i].lensing->sF_ApR6   = ps1data[i].sF_ApR6;
     955    // stars[i].lensing->fF_ApR6   = ps1data[i].fF_ApR6;
     956
     957    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     958    stars[i].lensing->detID      = ps1data[i].detID;
     959
     960    // the Average fields and the following Measure fields are set in FilterStars after
     961    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID.
     962
     963    // averef is set in find_matches
     964
     965    // dbFlags is zero on ingest.
     966
     967    // the following fields are currently not being set anywhere: t_msec
     968  }   
     969  *nstars = Nstars;
     970  return (stars);
     971}
     972
     973Stars *Convert_PS1_SV1 (FTable *table, unsigned int *nstars) {
     974
     975  off_t Nstars;
     976  unsigned int i;
     977  double ZeroPt;
     978  Stars *stars;
     979  CMF_PS1_SV1 *ps1data;
     980
     981  if (table[0].header[0].Naxis[0] == 196) {
     982    stars = Convert_PS1_SV1_Alt (table, nstars);
     983    return (stars);
     984  }
     985
     986  ps1data = gfits_table_get_CMF_PS1_SV1 (table, &Nstars, NULL);
     987  if (!ps1data) {
     988    fprintf (stderr, "skipping inconsistent entry\n");
     989    return (NULL);
     990  }
     991  ZeroPt = GetZeroPoint();
     992
     993  ALLOCATE (stars, Stars, Nstars);
     994  for (i = 0; i < Nstars; i++) {
     995    InitStar (&stars[i]);
     996    stars[i].measure.Xccd       = ps1data[i].X;
     997    stars[i].measure.Yccd       = ps1data[i].Y;
     998    stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
     999    stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
     1000
     1001    stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
     1002    stars[i].measure.pltscale   = ps1data[i].pltscale;
     1003
     1004    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
     1005      stars[i].measure.M      = NAN;
     1006    } else {
     1007      stars[i].measure.M      = ps1data[i].M + ZeroPt;
     1008    }
     1009    stars[i].measure.dM         = ps1data[i].dM;
     1010    stars[i].measure.dMcal      = ps1data[i].dMcal;
     1011    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1012    stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
     1013                       
     1014    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1015    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1016
     1017    // these fluxes are converted from counts to counts/sec in FilterStars.c
     1018    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1019    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
     1020    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
     1021    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1022    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (NAN, ps1data[i].Map);
     1023    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (NAN, stars[i].measure.FluxAp, stars[i].measure.dMap);
     1024
     1025    stars[i].measure.Sky        = ps1data[i].sky;
     1026    stars[i].measure.dSky       = ps1data[i].dSky;
     1027                       
     1028    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     1029    stars[i].measure.psfQF      = ps1data[i].psfQF;
     1030    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
     1031
     1032    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
     1033    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
     1034    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
     1035
     1036    stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
     1037    stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
     1038    stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
     1039
     1040    stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
     1041    stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     1042    stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
     1043                       
     1044    stars[i].measure.photFlags  = ps1data[i].flags;
     1045    stars[i].measure.photFlags2 = ps1data[i].flags2;
     1046
     1047    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1048    stars[i].measure.detID      = ps1data[i].detID;
     1049
     1050    // the Average fields and the following Measure fields are set in FilterStars after
     1051    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID,
     1052    // averef is set in find_matches, dbFlags is zero on ingest.
     1053
     1054    // the following fields are currently not being set anywhere: t_msec
     1055  }   
     1056  *nstars = Nstars;
     1057  return (stars);
     1058}
     1059
     1060Stars *Convert_PS1_SV1_Alt (FTable *table, unsigned int *nstars) {
     1061
     1062  off_t Nstars;
     1063  unsigned int i;
     1064  double ZeroPt;
     1065  Stars *stars;
     1066  CMF_PS1_SV1 *ps1data;
     1067
     1068  // some test output files were produced called CMF_PS1_SV1 but with mismatch byte boundaries
     1069
     1070  ps1data = gfits_table_get_CMF_PS1_SV1_Alt (table, &Nstars, NULL);
     1071  if (!ps1data) {
     1072    fprintf (stderr, "skipping inconsistent entry\n");
     1073    return (NULL);
     1074  }
     1075  ZeroPt = GetZeroPoint();
     1076
     1077  ALLOCATE (stars, Stars, Nstars);
     1078  for (i = 0; i < Nstars; i++) {
     1079    InitStar (&stars[i]);
     1080    stars[i].measure.Xccd       = ps1data[i].X;
     1081    stars[i].measure.Yccd       = ps1data[i].Y;
     1082    stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
     1083    stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
     1084
     1085    stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
     1086    stars[i].measure.pltscale   = ps1data[i].pltscale;
     1087
     1088    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
     1089      stars[i].measure.M      = NAN;
     1090    } else {
     1091      stars[i].measure.M      = ps1data[i].M + ZeroPt;
     1092    }
     1093    stars[i].measure.dM         = ps1data[i].dM;
     1094    stars[i].measure.dMcal      = ps1data[i].dMcal;
     1095    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1096    stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
     1097                       
     1098    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1099    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1100
     1101    // these fluxes are converted from counts to counts/sec in FilterStars.c
     1102    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1103    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
     1104    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
     1105    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1106    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (NAN, ps1data[i].Map);
     1107    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (NAN, stars[i].measure.FluxAp, stars[i].measure.dMap);
    8551108
    8561109    stars[i].measure.Sky        = ps1data[i].sky;
     
    8611114    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    8621115    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    863     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    8641116    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    8651117
     
    8731125                       
    8741126    stars[i].measure.photFlags  = ps1data[i].flags;
     1127    stars[i].measure.photFlags2 = ps1data[i].flags2;
    8751128
    8761129    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    9211174    stars[i].measure.dMcal      = ps1data[i].dMcal;
    9221175    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1176    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    9231177                       
    9241178    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     
    9261180
    9271181    // 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;
     1182    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1183    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    9301184    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    9311185    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1186    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1187    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    9321188
    9331189    stars[i].measure.Sky        = ps1data[i].sky;
     
    9401196    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    9411197    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    942     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    9431198    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    9441199
     
    9521207                       
    9531208    stars[i].measure.photFlags  = ps1data[i].flags;
     1209    stars[i].measure.photFlags2 = ps1data[i].flags2;
    9541210
    9551211    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    9661222}
    9671223
    968 Stars *Convert_PS1_DV3 (FTable *table, unsigned int *nstars) {
     1224Stars *Convert_PS1_SV3 (FTable *table, unsigned int *nstars) {
    9691225
    9701226  off_t Nstars;
     
    9721228  double ZeroPt;
    9731229  Stars *stars;
    974   CMF_PS1_DV3 *ps1data;
    975 
    976   ps1data = gfits_table_get_CMF_PS1_DV3 (table, &Nstars, NULL);
     1230  CMF_PS1_SV3 *ps1data;
     1231
     1232  ps1data = gfits_table_get_CMF_PS1_SV3 (table, &Nstars, NULL);
    9771233  if (!ps1data) {
    9781234    fprintf (stderr, "skipping inconsistent entry\n");
     
    10001256    stars[i].measure.dMcal      = ps1data[i].dMcal;
    10011257    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1258    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    10021259                       
    10031260    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    10041261    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    1005                        
     1262
    10061263    // 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;
     1264    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1265    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    10091266    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    10101267    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1268    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1269    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
     1270
     1271    stars[i].measure.Sky        = ps1data[i].sky;
     1272    stars[i].measure.dSky       = ps1data[i].dSky;
     1273                       
     1274    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     1275    stars[i].measure.psfQF      = ps1data[i].psfQF;
     1276    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
     1277
     1278    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
     1279    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
     1280    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
     1281
     1282    stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
     1283    stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
     1284    stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
     1285
     1286    stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
     1287    stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     1288    stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
     1289                       
     1290    stars[i].measure.photFlags  = ps1data[i].flags;
     1291    stars[i].measure.photFlags2 = ps1data[i].flags2;
     1292
     1293    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1294    stars[i].measure.detID      = ps1data[i].detID;
     1295
     1296    // the Average fields and the following Measure fields are set in FilterStars after
     1297    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID,
     1298    // averef is set in find_matches, dbFlags is zero on ingest.
     1299
     1300    // the following fields are currently not being set anywhere: t_msec
     1301  }   
     1302  *nstars = Nstars;
     1303  return (stars);
     1304}
     1305
     1306Stars *Convert_PS1_DV3 (FTable *table, unsigned int *nstars) {
     1307
     1308  off_t Nstars;
     1309  unsigned int i;
     1310  double ZeroPt;
     1311  Stars *stars;
     1312  CMF_PS1_DV3 *ps1data;
     1313
     1314  ps1data = gfits_table_get_CMF_PS1_DV3 (table, &Nstars, NULL);
     1315  if (!ps1data) {
     1316    fprintf (stderr, "skipping inconsistent entry\n");
     1317    return (NULL);
     1318  }
     1319  ZeroPt = GetZeroPoint();
     1320
     1321  ALLOCATE (stars, Stars, Nstars);
     1322  for (i = 0; i < Nstars; i++) {
     1323    InitStar (&stars[i]);
     1324    stars[i].measure.Xccd       = ps1data[i].X;
     1325    stars[i].measure.Yccd       = ps1data[i].Y;
     1326    stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
     1327    stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
     1328
     1329    stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
     1330    stars[i].measure.pltscale   = ps1data[i].pltscale;
     1331
     1332    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
     1333      stars[i].measure.M      = NAN;
     1334    } else {
     1335      stars[i].measure.M      = ps1data[i].M + ZeroPt;
     1336    }
     1337    stars[i].measure.dM         = ps1data[i].dM;
     1338    stars[i].measure.dMcal      = ps1data[i].dMcal;
     1339    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1340    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1341                       
     1342    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1343    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1344                       
     1345    // these fluxes are converted from counts to counts/sec in FilterStars.c
     1346    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1347    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
     1348    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
     1349    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1350    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1351    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    10111352
    10121353    stars[i].measure.Sky        = ps1data[i].sky;
     
    10181359    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    10191360    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1020     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    10211361    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    10221362
     
    10301370                       
    10311371    stars[i].measure.photFlags  = ps1data[i].flags;
     1372    stars[i].measure.photFlags2 = ps1data[i].flags2;
    10321373
    10331374    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    10471388}
    10481389
    1049 
    1050 
     1390Stars *Convert_PS1_DV4 (FTable *table, unsigned int *nstars) {
     1391
     1392  off_t Nstars;
     1393  unsigned int i;
     1394  double ZeroPt;
     1395  Stars *stars;
     1396  CMF_PS1_DV4 *ps1data;
     1397
     1398  ps1data = gfits_table_get_CMF_PS1_DV4 (table, &Nstars, NULL);
     1399  if (!ps1data) {
     1400    fprintf (stderr, "skipping inconsistent entry\n");
     1401    return (NULL);
     1402  }
     1403  ZeroPt = GetZeroPoint();
     1404
     1405  fprintf (stderr, "WARNING: Convert_PS1_DV4 not yet updated to match real format\n");
     1406
     1407  ALLOCATE (stars, Stars, Nstars);
     1408  for (i = 0; i < Nstars; i++) {
     1409    InitStar (&stars[i]);
     1410    stars[i].measure.Xccd       = ps1data[i].X;
     1411    stars[i].measure.Yccd       = ps1data[i].Y;
     1412    stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
     1413    stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
     1414
     1415    stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
     1416    stars[i].measure.pltscale   = ps1data[i].pltscale;
     1417
     1418    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
     1419      stars[i].measure.M      = NAN;
     1420    } else {
     1421      stars[i].measure.M      = ps1data[i].M + ZeroPt;
     1422    }
     1423    stars[i].measure.dM         = ps1data[i].dM;
     1424    stars[i].measure.dMcal      = ps1data[i].dMcal;
     1425    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1426    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1427                       
     1428    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1429    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1430                       
     1431    // these fluxes are converted from counts to counts/sec in FilterStars.c
     1432    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1433    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
     1434    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
     1435    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1436    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1437    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
     1438
     1439    stars[i].measure.Sky        = ps1data[i].sky;
     1440    stars[i].measure.dSky       = ps1data[i].dSky;
     1441                       
     1442    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     1443    stars[i].measure.psfQF      = ps1data[i].psfQF;
     1444    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
     1445    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
     1446    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
     1447    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
     1448
     1449    stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
     1450    stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
     1451    stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
     1452
     1453    stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
     1454    stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     1455    stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
     1456                       
     1457    stars[i].measure.photFlags  = ps1data[i].flags;
     1458    stars[i].measure.photFlags2 = ps1data[i].flags2;
     1459
     1460    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1461    stars[i].measure.detID      = ps1data[i].detID;
     1462
     1463    // the Average fields and the following Measure fields are set in FilterStars after
     1464    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID.
     1465
     1466    // averef is set in find_matches
     1467
     1468    // dbFlags is zero on ingest.
     1469
     1470    // the following fields are currently not being set anywhere: t_msec
     1471  }   
     1472  *nstars = Nstars;
     1473  return (stars);
     1474}
     1475
     1476
     1477
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/SEDfit.c

    r34405 r37403  
    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/ps2-tc3-20130727/Ohana/src/addstar/src/StarOps.c

    r34260 r37403  
    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/ps2-tc3-20130727/Ohana/src/addstar/src/UpdateImageIDs.c

    r35579 r37403  
    5555  for (i = 0; i < Nstars; i++) {
    5656    stars[i].measure.imageID += imageID;
     57    if (stars[i].lensing) {
     58      stars[i].lensing->imageID += imageID;
     59    }
    5760  }
    5861
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/addstar.c

    r34405 r37403  
    11# include "addstar.h"
     2
     3# define RESETTIME { gettimeofday (&startTimer, (void *) NULL); }
    24
    35// LARGEFILES: this program currently limits Nstars (input file) to < 2^31
     
    79  int Nmatch, status, loadObjects;
    810  off_t i, Nimages;
    9   off_t Naverage, Nmeasure;
     11  off_t Naverage, Nmeasure, Nlensing;
    1012  Stars *stars, **subset;
    1113  Image *images;
     
    1820  SkyList *newlist = NULL;
    1921
    20   double dtime;
    21   struct timeval start, stop;
    22 
    23   gettimeofday (&start, NULL);
     22  struct timeval startAddstar, stopAddstar;
     23  gettimeofday (&startAddstar, (void *) NULL);
     24
     25  INITTIME;
    2426
    2527  SetSignals ();
     
    4042 
    4143  if (options.mode == ADDSTAR_MODE_RESORT) {
    42     if (NTHREADS == 0) {
    43       resort_unthreaded (&options, sky, 0, NULL);
    44     } else {
    45       resort_threaded (&options, sky);
    46     }
     44    resort_catalogs (&options, sky);
    4745    exit (0);
    4846  }
     47
     48  MARKTIME ("init and config: %f sec\n", dtime); RESETTIME;
    4949
    5050  stars = NULL;
     
    5454    case ADDSTAR_MODE_IMAGE:
    5555      stars = LoadStars (argv[1], &Nstars, &images, &Nimages, &options);
     56      MARKTIME ("load smf: %f sec\n", dtime); RESETTIME;
    5657
    5758      // set and update the imageID sequence
     
    7172      skylist = SkyListForStars (sky, -1, stars, Nstars);
    7273      break;
    73     case ADDSTAR_MODE_RESORT:
    7474    case ADDSTAR_MODE_REFCAT:
    7575      skylist = SkyListByPatch (sky, -1, &UserPatch);
     
    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
     
    132132      }
    133133    }
     134    MARKTIME ("load cpt: %f sec\n", dtime); RESETTIME;
    134135
    135136    // Naves_disk == 0 implies an empty catalog file
     
    161162        if (Nsubset) free (subset);
    162163        break;
    163       case ADDSTAR_MODE_RESORT:
    164         if (options.nosort == 3) catalog.sorted = FALSE;
    165 
    166         // no need to resort empty catalogs
    167         if (catalog.Naves_disk == 0) {
    168           dvo_catalog_unlock (&catalog);
    169           dvo_catalog_free (&catalog);
    170           continue;
    171         }
    172 
    173         if (OLD_RESORT) {
    174           resort_catalog_old (&catalog);
    175         } else {
    176           resort_catalog (&catalog);
    177         }
    178         Nsubset = 1;
    179         break;
    180     }
     164    }
     165    MARKTIME ("match stars: %f sec\n", dtime); RESETTIME;
     166
    181167    /* report total updated values */
    182168    Naverage += catalog.Naverage;
    183169    Nmeasure += catalog.Nmeasure;
     170    Nlensing += catalog.Nlensing;
    184171
    185172    // write out catalog, if appropriate
     
    187174      SetProtect (TRUE);
    188175      if (options.update) {
    189         catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     176        catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF | LOAD_LENSING;
    190177        dvo_catalog_update (&catalog, VERBOSE);
    191178      } else {
     
    196183    dvo_catalog_unlock (&catalog);
    197184    dvo_catalog_free (&catalog);
     185    MARKTIME ("save cpt: %f sec\n", dtime); RESETTIME;
    198186
    199187    if (options.mode == ADDSTAR_MODE_REFCAT) free (stars);
     
    229217  dvo_image_unlock (&db); /* unlock? */
    230218
    231   gettimeofday (&stop, NULL);
    232   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);
     219  gettimeofday (&stopAddstar, (void *) NULL);
     220  float dtime = DTIME (stopAddstar, startAddstar);
     221  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);
    234222
    235223  exit (0);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/addstar_client.c

    r33963 r37403  
    2525
    2626  if (options.mode == ADDSTAR_MODE_RESORT) {
    27     resort_unthreaded (&options, sky, HOST_ID, HOSTDIR);
     27    resort_catalogs (&options, sky);
    2828    exit (0);
    2929  }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/args.c

    r35760 r37403  
    3434    remove_argument (N, &argc, argv);
    3535  }
     36  OLD_RESORT = FALSE;
     37  if ((N = get_argument (argc, argv, "-old-resort"))) {
     38    remove_argument (N, &argc, argv);
     39    OLD_RESORT = TRUE;
     40  }
     41
    3642  if ((N = get_argument (argc, argv, "-create-id"))) {
    3743    options.mode = ADDSTAR_MODE_CREATE_ID;
     
    7581    PMM_CCD_TABLE = strcreate (argv[N]);
    7682    remove_argument (N, &argc, argv);
     83  }
     84
     85  READ_XRAD_DATA = FALSE;
     86  if ((N = get_argument (argc, argv, "-xrad"))) {
     87    remove_argument (N, &argc, argv);
     88    READ_XRAD_DATA = TRUE;
    7789  }
    7890
     
    350362  // XXX for the moment, make this selection manual.  it needs to be automatic
    351363  // based on the state of the SkyTable
     364  HOST_ID = 0;
     365  HOSTDIR = NULL;
    352366  PARALLEL = FALSE;
    353367  if ((N = get_argument (argc, argv, "-parallel"))) {
     
    466480}
    467481
     482int strextend (char *input, char *format,...) {
     483
     484  char tmpextra[1024], tmpline[1024];
     485  va_list argp;
     486
     487  va_start (argp, format);
     488  vsnprintf (tmpextra, 1024, format, argp);
     489  snprintf (tmpline, 1024, "%s %s", input, tmpextra);
     490  strcpy (input, tmpline);
     491
     492  return TRUE;
     493}
     494
    468495/** addstar modes:
    469496 
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/args_parallel_client.c

    r33963 r37403  
    8787  }
    8888
     89  OLD_RESORT = FALSE;
     90  if ((N = get_argument (argc, argv, "-old-resort"))) {
     91    remove_argument (N, &argc, argv);
     92    OLD_RESORT = TRUE;
     93  }
     94
    8995  /* extra error messages */
    9096  VERBOSE = FALSE;
     
    118124  exit (2);
    119125}
     126
     127int strextend (char *input, char *format,...) {
     128
     129  char tmpextra[1024], tmpline[1024];
     130  va_list argp;
     131
     132  va_start (argp, format);
     133  vsnprintf (tmpextra, 1024, format, argp);
     134  snprintf (tmpline, 1024, "%s %s", input, tmpextra);
     135  strcpy (input, tmpline);
     136
     137  return TRUE;
     138}
     139
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/build_links.c

    r27435 r37403  
    11# include "addstar.h"
     2
     3# define myAbortF(FORMAT,...) { fprintf (stderr, FORMAT, __VA_ARGS__); abort(); }
    24
    35/*
     
    4749
    4850    if (N >= Nmeasure) {
    49       fprintf (stderr, "overflow in init_measure_links\n");
    50       abort ();
     51      myAbort ("overflow in init_measure_links\n");
    5152    }
    5253  }
     
    102103
    103104/* average[].measureOffset, average[].Nmeasure are valid within an addstar run */
    104 off_t add_meas_link (Average *average, off_t *next_meas, off_t Nmeasure, off_t NMEASURE) {
     105int add_meas_link (Average *average, off_t *next_meas, off_t Nmeasure, off_t NMEASURE) {
    105106
    106107  off_t k, m;
     
    134135}
    135136
    136 /* Missing does not carry enough information to reconstruct the links
    137    we must always save the missing table, if it exists */
    138 
    139137Measure *sort_measure (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next_meas) {
    140138
    141   off_t i, k, n, N;
     139  int i, k, n, N;
    142140  Measure *tmpmeasure;
    143141
     
    149147    average[i].measureOffset = N;
    150148    for (k = 0; k < average[i].Nmeasure; k++, N++) {
    151       if (n == -1) abort();
     149      if (n == -1) myAbortF("invalid measureOffset for ave %d, measureOffset %d, measure %d\n", i, average[i].measureOffset, k);
    152150      tmpmeasure[N] = measure[n];
    153       if (measure[n].averef != i) abort();
     151      if (measure[n].averef != i) myAbortF("invalid averef for ave %d, measureOffset %d, measure %d, averef %d\n", i, average[i].measureOffset, k, measure[n].averef);
    154152      tmpmeasure[N].averef = i;
    155153      n = next_meas[n];
     
    159157  return (tmpmeasure);
    160158}
     159
     160/*******************************************************************************************/
    161161
    162162/* build the initial links assuming the table is sorted */
     
    176176      next_miss[N] = -1;
    177177      if (N >= Nmissing) {
    178         fprintf (stderr, "overflow in init_missing_links");
    179         abort ();
     178        myAbort ("overflow in init_missing_links");
    180179      }
    181180      N++;
     
    186185}
    187186
    188 off_t add_miss_link (Average *average, off_t *next_miss, off_t Nmissing) {
     187int add_miss_link (Average *average, off_t *next_miss, off_t Nmissing) {
    189188
    190189  off_t k, m;
     
    205204}
    206205
     206/* Missing does not carry enough information to reconstruct the links
     207   we must always save the missing table, if it exists */
     208
    207209Missing *sort_missing (Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss) {
    208210
     
    225227}
    226228
     229/*******************************************************************************************/
     230
     231/* build the initial links assuming the table is sorted,
     232   not partial, and has a correct set of average[].lensingOffset,Nlensing values */
     233off_t *init_lensing_links (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing) {
     234
     235  off_t i, j, N;
     236  off_t *next_lens;
     237
     238  N = 0;
     239
     240  ALLOCATE (next_lens, off_t, Nlensing);
     241  for (i = 0; i < Naverage; i++) {
     242    if (!average[i].Nlensing) continue;
     243    for (j = 0; j < average[i].Nlensing - 1; j++, N++) {
     244      next_lens[N] = N + 1;
     245      if (N >= Nlensing) {
     246        fprintf (stderr, "WARNING: N out of bounds (1)\n");
     247      }
     248    }
     249    next_lens[N] = -1;
     250    if (N >= Nlensing) {
     251      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     252    }
     253
     254    if (N >= Nlensing) {
     255      myAbort ("overflow in init_lensing_links\n");
     256    }
     257    N++;
     258  }
     259  return (next_lens);
     260}
     261
     262/* construct lensing links which are valid FOR THIS LOAD
     263 * - if we have a full load, we will get links which can
     264 *   be used by other programs (eg, relphot, etc)
     265 * - if we have a partial load, the links are only valid
     266 *   for that partial load
     267 */
     268
     269off_t *build_lensing_links (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing) {
     270
     271  off_t i, m, k, Nm, averef;
     272  off_t *next_lens;
     273
     274  ALLOCATE (next_lens, off_t, Nlensing);
     275
     276  /* reset the Nm, offset values for average */
     277  for (i = 0; i < Naverage; i++) {
     278    average[i].lensingOffset = -1;
     279    average[i].Nlensing     =  0;
     280  }
     281
     282  for (Nm = 0; Nm < Nlensing; Nm++) {
     283    averef = lensing[Nm].averef;
     284    m = average[averef].lensingOffset; 
     285    next_lens[Nm] = -1;
     286
     287    if (m == -1) { /* no links yet for source */
     288      average[averef].lensingOffset = Nm;
     289      average[averef].Nlensing     = 1;
     290      continue;
     291    }
     292
     293    for (k = 0; next_lens[m] != -1; k++) {
     294      m = next_lens[m];
     295      if (m >= Nlensing) {
     296        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     297      }
     298    }
     299
     300    average[averef].Nlensing = k + 2;
     301    next_lens[m] = Nm;
     302    if (m >= Nlensing) {
     303      fprintf (stderr, "WARNING: m out of bounds (2)\n");
     304    }
     305  }
     306  return (next_lens);
     307}
     308
     309/* average[].lensingOffset, average[].Nlensing are valid within an addstar run */
     310int add_lens_link (Average *average, off_t *next_lens, off_t Nlensing, off_t NLENSING) {
     311
     312  off_t k, m;
     313
     314  /* if we have trouble, check validity of next_lens[m] : m < Nlensing */
     315  m = average[0].lensingOffset; 
     316
     317  for (k = 0; k < average[0].Nlensing - 1; k++)  {
     318    m = next_lens[m];
     319    if (m >= NLENSING) {
     320      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     321    }
     322  }
     323
     324  /* set up references */
     325  next_lens[Nlensing] = -1;
     326  if (Nlensing >= NLENSING) {
     327    fprintf (stderr, "WARNING: Nlensing out of bounds (1)\n");
     328  }
     329
     330  if (m == -1) {
     331    average[0].lensingOffset = Nlensing;
     332  } else {
     333    next_lens[m] = Nlensing;
     334    if (m >= NLENSING) {
     335      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     336    }
     337  }
     338
     339  return (TRUE);
     340}
     341
     342Lensing *sort_lensing (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next_lens) {
     343
     344  int i, k, n, N;
     345  Lensing *tmplensing;
     346
     347  /* fix order of Lensing (memory intensive, but fast) */
     348  N = 0;
     349  ALLOCATE (tmplensing, Lensing, Nlensing);
     350  for (i = 0; i < Naverage; i++) {
     351    if (!average[i].Nlensing) continue;
     352    n = average[i].lensingOffset;
     353    average[i].lensingOffset = N;
     354    for (k = 0; k < average[i].Nlensing; k++, N++) {
     355      if (n == -1) myAbortF("invalid lensingOffset for ave %d, lensingOffset %d, lensing %d\n", i, average[i].lensingOffset, k);
     356      tmplensing[N] = lensing[n];
     357      if (lensing[n].averef != i) myAbortF("invalid averef for ave %d, lensingOffset %d, lensing %d, averef %d\n", i, average[i].lensingOffset, k, lensing[n].averef);
     358      tmplensing[N].averef = i;
     359      n = next_lens[n];
     360    }
     361  }
     362  free (lensing);
     363  return (tmplensing);
     364}
     365
     366
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/fakeimage.c

    r36680 r37403  
    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];
     
    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/ps2-tc3-20130727/Ohana/src/addstar/src/find_matches.c

    r36680 r37403  
    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
     
    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/ps2-tc3-20130727/Ohana/src/addstar/src/find_matches_closest.c

    r36680 r37403  
    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
     
    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/ps2-tc3-20130727/Ohana/src/addstar/src/find_matches_closest_refstars.c

    r36680 r37403  
    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
     
    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/ps2-tc3-20130727/Ohana/src/addstar/src/find_matches_refstars.c

    r36680 r37403  
    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);
     
    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/ps2-tc3-20130727/Ohana/src/addstar/src/findskycell.c

    r36680 r37403  
    2727int apply_tree (char *treefile, char *datafile);
    2828
    29 float SCALE = 1.0;
    30 int NX_SUB = 1;
    31 int NY_SUB = 1;
     29float SCALE  = 1.0;
     30float NX_SUB = 1.0;
     31float NY_SUB = 1.0;
    3232
    3333double R_MIN = 0.0;
     
    162162}
    163163
    164 # define MARKTIME(MSG,...) {                    \
    165     float dtime;                                \
    166     gettimeofday (&stop, (void *) NULL);        \
    167     dtime = DTIME (stop, start);                \
    168     fprintf (stderr, MSG, __VA_ARGS__); }
    169 
    170164int mktree (char *treefile, char *catdir) {
    171165
     
    223217  ALLOCATE (tree.Xo,   double *, tree.Nzone);
    224218  ALLOCATE (tree.Yo,   double *, tree.Nzone);
    225   ALLOCATE (tree.dX,      int *, tree.Nzone);
    226   ALLOCATE (tree.dY,      int *, tree.Nzone);
     219  ALLOCATE (tree.dX,    float *, tree.Nzone);
     220  ALLOCATE (tree.dY,    float *, tree.Nzone);
    227221  ALLOCATE (tree.cell,    int *, tree.Nzone);
    228222  ALLOCATE (tree.name,  char **, tree.Nzone);
     
    257251    ALLOCATE (tree.Xo[zone],   double, tree.NBAND[zone]);
    258252    ALLOCATE (tree.Yo[zone],   double, tree.NBAND[zone]);
    259     ALLOCATE (tree.dX[zone],      int, tree.NBAND[zone]);
    260     ALLOCATE (tree.dY[zone],      int, tree.NBAND[zone]);
     253    ALLOCATE (tree.dX[zone],    float, tree.NBAND[zone]);
     254    ALLOCATE (tree.dY[zone],    float, tree.NBAND[zone]);
    261255    ALLOCATE (tree.cell[zone], int,    tree.NBAND[zone]);
    262256    ALLOCATE (tree.name[zone], char *, tree.NBAND[zone]);
     
    266260      tree.Xo[zone][band] = NAN;
    267261      tree.Yo[zone][band] = NAN;
    268       tree.dX[zone][band] = -1;
    269       tree.dY[zone][band] = -1;
     262      tree.dX[zone][band] = NAN;
     263      tree.dY[zone][band] = NAN;
    270264      tree.cell[zone][band] = -1;
    271265      ALLOCATE (tree.name[zone][band], char, BOUNDARY_TREE_NAME_LENGTH);
     
    292286      REALLOCATE (tree.Xo[zone],   double, tree.NBAND[zone]);
    293287      REALLOCATE (tree.Yo[zone],   double, tree.NBAND[zone]);
    294       REALLOCATE (tree.dX[zone],      int, tree.NBAND[zone]);
    295       REALLOCATE (tree.dY[zone],      int, tree.NBAND[zone]);
     288      REALLOCATE (tree.dX[zone],    float, tree.NBAND[zone]);
     289      REALLOCATE (tree.dY[zone],    float, tree.NBAND[zone]);
    296290      REALLOCATE (tree.cell[zone],    int, tree.NBAND[zone]);
    297291      REALLOCATE (tree.name[zone], char *, tree.NBAND[zone]);
     
    301295        tree.Xo[zone][band] = NAN;
    302296        tree.Yo[zone][band] = NAN;
    303         tree.dX[zone][band] = -1;
    304         tree.dY[zone][band] = -1;
     297        tree.dX[zone][band] = NAN;
     298        tree.dY[zone][band] = NAN;
    305299        tree.cell[zone][j] = -1;
    306300        ALLOCATE (tree.name[zone][j], char, BOUNDARY_TREE_NAME_LENGTH);
     
    402396  }
    403397
    404   struct timeval start, stop;
    405   gettimeofday (&start, (void *) NULL);
     398  INITTIME;
    406399
    407400  int Npts = 10000000;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/load2mass_catalog.c

    r35416 r37403  
    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/ps2-tc3-20130727/Ohana/src/addstar/src/loadsupercos_ops.c

    r33653 r37403  
    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/ps2-tc3-20130727/Ohana/src/addstar/src/mkcmf.c

    r35760 r37403  
    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;
     32
     33static char reserved[] =  "Reserved space.  This line can be used to add a new FITS card.";
    2534
    2635int main (int argc, char **argv) {
     
    3847  Matrix matrix;
    3948  FTable ftable;
    40   Coords coords;
    4149
    4250  int APPEND = FALSE;
     
    105113  }
    106114
    107   float exptime = 1.0;
    108115  if ((N = get_argument (argc, argv, "-exptime"))) {
    109116    remove_argument (N, &argc, argv);
     
    288295    gfits_modify (&header, "UTC-OBS",  "%s", 1, time);
    289296  }
    290   gfits_modify (&header, "ZERO_PT", "%lf", 1, 25.0);
     297  gfits_modify (&header, "ZERO_PT", "%lf", 1, ZERO_POINT);
    291298  gfits_modify (&header, "EXPTIME", "%lf", 1, exptime);
    292299  gfits_modify (&header, "AIRMASS", "%lf", 1, airmass);
     
    300307  PutCoords (&coords, &header);
    301308  gfits_modify (&header, "EXTNAME",   "%s", 1, exthead);
     309
     310  int i;
     311  for (i = 1; i < 32; i++) {
     312    gfits_modify_alt (&header, "COMMENT", "%C", i, reserved);
     313  }
    302314
    303315  ftable.header = &theader;
     
    327339  if (!strcmp(type, "PS1_V4")) {
    328340    writeStars_PS1_V4 (&ftable, X, Y, M, Flag, Nstars);
     341    found = TRUE;
     342  }
     343  if (!strcmp(type, "PS1_V5")) {
     344    writeStars_PS1_V5 (&ftable, X, Y, M, Flag, Nstars);
     345    found = TRUE;
     346  }
     347  if (!strcmp(type, "PS1_V5_Lensing")) {
     348    writeStars_PS1_V5_Lensing (&ftable, X, Y, M, Flag, Nstars);
     349    found = TRUE;
     350  }
     351  if (!strcmp(type, "PS1_SV3")) {
     352    writeStars_PS1_SV3 (&ftable, X, Y, M, Flag, Nstars);
    329353    found = TRUE;
    330354  }
     
    764788}
    765789
     790void writeStars_PS1_V5 (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars) {
     791
     792  int i;
     793  CMF_PS1_V5 *stars;
     794  float flux, fSN;
     795
     796  // XXX add gaussian-distributed noise based on counts
     797  // this needs to make different output 'stars' entries depending on the desired type
     798  ALLOCATE (stars, CMF_PS1_V5, Nstars);
     799  for (i = 0; i < Nstars; i++) {
     800
     801    flux = pow (10.0, -0.4*M[i]);
     802    fSN = 1.0 / sqrt(flux);
     803
     804    stars[i].detID = i;
     805    stars[i].X = X[i];
     806    stars[i].Y = Y[i];
     807    stars[i].dX = FX * fSN;
     808    stars[i].dY = FY * fSN;
     809
     810    stars[i].posangle = 10.0;
     811    stars[i].pltscale = 0.25;
     812
     813    stars[i].M = M[i];
     814    stars[i].dM = fSN;
     815
     816    stars[i].Flux = flux;
     817    stars[i].dFlux = flux * fSN;
     818
     819    stars[i].Map = M[i] - 0.05;
     820    stars[i].MapRaw = M[i] - 0.10;
     821
     822    stars[i].apRadius = 8.0;
     823
     824    stars[i].apFlux = pow(10.0, -0.4*stars[i].Map);
     825    stars[i].apFluxErr = stars[i].apFlux * fSN;
     826
     827    stars[i].Mcalib = M[i] + ZERO_POINT + 2.5*log10(exptime);
     828    stars[i].dMcal = 0.05;
     829
     830    XY_to_RD (&stars[i].RA, &stars[i].DEC, X[i], Y[i], &coords);
     831    stars[i].apNpix = 3.14*8.0*8.0;
     832
     833    stars[i].Mpeak     = M[i] + 1.0;
     834    stars[i].sky       = SKY;
     835    stars[i].dSky      = DSKY;
     836    stars[i].psfChisq  = PSFCHI;
     837    stars[i].crNsigma  = CRN;
     838    stars[i].extNsigma = EXTN;
     839    stars[i].fx        = FX;
     840    stars[i].fy        = FY;
     841    stars[i].df        = DF;
     842
     843    stars[i].k         = 1.0;
     844    stars[i].fwhmMaj   = FX*2.8;
     845    stars[i].fwhmMin   = FY*2.8;
     846
     847    // randomly give poor PSFQF values
     848    if ((BAD_PSFQF_FRAC > 0.0) && (drand48() < BAD_PSFQF_FRAC)) {
     849      stars[i].psfQF     = 0.25;
     850      stars[i].psfQFperf = 0.24;
     851    } else {
     852      stars[i].psfQF     = PSFQUAL;
     853      stars[i].psfQFperf = MAX(PSFQUAL - 0.01, 0.0);
     854    }
     855
     856    stars[i].psfNdof   = 1;
     857    stars[i].psfNpix   = 2;
     858
     859    stars[i].Mxx       = FX;
     860    stars[i].Mxy       = 0.01;
     861    stars[i].Myy       = FX;
     862    stars[i].M3c       = FX;
     863    stars[i].M3s       = FX;
     864    stars[i].M4c       = FX;
     865    stars[i].M4s       = FX;
     866    stars[i].Mr1       = FX;
     867    stars[i].Mrh       = FX;
     868
     869    stars[i].kronFlux  = flux * 1.25;
     870    stars[i].kronFluxErr = fSN * flux * 1.25;
     871
     872    stars[i].kronInner = fSN * flux * 0.9;
     873    stars[i].kronOuter = fSN * flux * 1.5;
     874
     875    stars[i].skyLimitRad = 1;
     876    stars[i].skyLimitFlux = 2;
     877    stars[i].skyLimitSlope = 0.2;
     878
     879    stars[i].flags     = Flag[i];
     880    stars[i].flags2    = 0x80;
     881
     882    stars[i].nFrames   = 1;
     883
     884    if (ADDNOISE) {
     885      stars[i].X += FX * fSN * rnd_gauss(0.0, 1.0);
     886      stars[i].Y += FY * fSN * rnd_gauss(0.0, 1.0);
     887      float Moff = fSN*rnd_gauss(0.0, 1.0);
     888      stars[i].M += Moff;
     889      stars[i].Map += Moff;
     890      stars[i].MapRaw += Moff;
     891      stars[i].Mcalib += Moff;
     892    }
     893  }
     894
     895  gfits_table_set_CMF_PS1_V5 (ftable, stars, Nstars);
     896  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_V5");
     897}
     898
     899void writeStars_PS1_SV3 (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars) {
     900
     901  int i;
     902  CMF_PS1_SV3 *stars;
     903  float flux, fSN;
     904
     905  // XXX add gaussian-distributed noise based on counts
     906  // this needs to make different output 'stars' entries depending on the desired type
     907  ALLOCATE (stars, CMF_PS1_SV3, Nstars);
     908  for (i = 0; i < Nstars; i++) {
     909
     910    flux = pow (10.0, -0.4*M[i]);
     911    fSN = 1.0 / sqrt(flux);
     912
     913    stars[i].detID = i;
     914    stars[i].X = X[i];
     915    stars[i].Y = Y[i];
     916    stars[i].dX = FX * fSN;
     917    stars[i].dY = FY * fSN;
     918
     919    stars[i].posangle = 10.0;
     920    stars[i].pltscale = 0.25;
     921
     922    stars[i].M = M[i];
     923    stars[i].dM = fSN;
     924
     925    stars[i].Flux = flux;
     926    stars[i].dFlux = flux * fSN;
     927
     928    stars[i].Map = M[i] - 0.05;
     929    stars[i].MapRaw = M[i] - 0.10;
     930
     931    stars[i].apRadius = 8.0;
     932
     933    stars[i].apFlux = pow(10.0, -0.4*stars[i].Map);
     934    stars[i].apFluxErr = stars[i].apFlux * fSN;
     935
     936    stars[i].Mcalib = M[i] + ZERO_POINT + 2.5*log10(exptime);
     937    stars[i].dMcal = 0.05;
     938
     939    XY_to_RD (&stars[i].RA, &stars[i].DEC, X[i], Y[i], &coords);
     940    stars[i].apNpix = 3.14*8.0*8.0;
     941
     942    stars[i].Mpeak     = M[i] + 1.0;
     943    stars[i].sky       = SKY;
     944    stars[i].dSky      = DSKY;
     945    stars[i].psfChisq  = PSFCHI;
     946    stars[i].crNsigma  = CRN;
     947    stars[i].extNsigma = EXTN;
     948    stars[i].fx        = FX;
     949    stars[i].fy        = FY;
     950    stars[i].df        = DF;
     951
     952    stars[i].k         = 1.0;
     953    stars[i].fwhmMaj   = FX*2.8;
     954    stars[i].fwhmMin   = FY*2.8;
     955
     956    // randomly give poor PSFQF values
     957    if ((BAD_PSFQF_FRAC > 0.0) && (drand48() < BAD_PSFQF_FRAC)) {
     958      stars[i].psfQF     = 0.25;
     959      stars[i].psfQFperf = 0.24;
     960    } else {
     961      stars[i].psfQF     = PSFQUAL;
     962      stars[i].psfQFperf = MAX(PSFQUAL - 0.01, 0.0);
     963    }
     964
     965    stars[i].psfNdof   = 1;
     966    stars[i].psfNpix   = 2;
     967
     968    stars[i].Mxx       = FX;
     969    stars[i].Mxy       = 0.01;
     970    stars[i].Myy       = FX;
     971    stars[i].M3c       = FX;
     972    stars[i].M3s       = FX;
     973    stars[i].M4c       = FX;
     974    stars[i].M4s       = FX;
     975    stars[i].Mr1       = FX;
     976    stars[i].Mrh       = FX;
     977
     978    stars[i].kronFlux  = flux * 1.25;
     979    stars[i].kronFluxErr = fSN * flux * 1.25;
     980
     981    stars[i].kronInner = fSN * flux * 0.9;
     982    stars[i].kronOuter = fSN * flux * 1.5;
     983
     984    // stars[i].skyLimitRad = 1;
     985    // stars[i].skyLimitFlux = 2;
     986    // stars[i].skyLimitSlope = 0.2;
     987
     988    stars[i].flags     = Flag[i];
     989    stars[i].flags2    = 0x80;
     990
     991    stars[i].nFrames   = 1;
     992
     993    if (ADDNOISE) {
     994      stars[i].X += FX * fSN * rnd_gauss(0.0, 1.0);
     995      stars[i].Y += FY * fSN * rnd_gauss(0.0, 1.0);
     996      float Moff = fSN*rnd_gauss(0.0, 1.0);
     997      stars[i].M += Moff;
     998      stars[i].Map += Moff;
     999      stars[i].MapRaw += Moff;
     1000      stars[i].Mcalib += Moff;
     1001    }
     1002  }
     1003
     1004  gfits_table_set_CMF_PS1_SV3 (ftable, stars, Nstars);
     1005  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_SV3");
     1006}
     1007
     1008void writeStars_PS1_V5_Lensing (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars) {
     1009
     1010  int i;
     1011  CMF_PS1_V5_Lensing *stars;
     1012  float flux, fSN;
     1013
     1014  // XXX add gaussian-distributed noise based on counts
     1015  // this needs to make different output 'stars' entries depending on the desired type
     1016  ALLOCATE (stars, CMF_PS1_V5_Lensing, Nstars);
     1017  for (i = 0; i < Nstars; i++) {
     1018
     1019    flux = pow (10.0, -0.4*M[i]);
     1020    fSN = 1.0 / sqrt(flux);
     1021
     1022    stars[i].detID = i;
     1023    stars[i].X = X[i];
     1024    stars[i].Y = Y[i];
     1025    stars[i].dX = FX * fSN;
     1026    stars[i].dY = FY * fSN;
     1027
     1028    stars[i].posangle = 10.0;
     1029    stars[i].pltscale = 0.25;
     1030
     1031    stars[i].M = M[i];
     1032    stars[i].dM = fSN;
     1033
     1034    stars[i].Flux = flux;
     1035    stars[i].dFlux = flux * fSN;
     1036
     1037    stars[i].Map = M[i] - 0.05;
     1038    stars[i].MapRaw = M[i] - 0.10;
     1039
     1040    stars[i].apRadius = 8.0;
     1041
     1042    stars[i].apFlux = pow(10.0, -0.4*stars[i].Map);
     1043    stars[i].apFluxErr = stars[i].apFlux * fSN;
     1044
     1045    stars[i].Mcalib = M[i] + ZERO_POINT + 2.5*log10(exptime);
     1046    stars[i].dMcal = 0.05;
     1047
     1048    XY_to_RD (&stars[i].RA, &stars[i].DEC, X[i], Y[i], &coords);
     1049    stars[i].apNpix = 3.14*8.0*8.0;
     1050
     1051    stars[i].Mpeak     = M[i] + 1.0;
     1052    stars[i].sky       = SKY;
     1053    stars[i].dSky      = DSKY;
     1054    stars[i].psfChisq  = PSFCHI;
     1055    stars[i].crNsigma  = CRN;
     1056    stars[i].extNsigma = EXTN;
     1057    stars[i].fx        = FX;
     1058    stars[i].fy        = FY;
     1059    stars[i].df        = DF;
     1060
     1061    stars[i].k         = 1.0;
     1062    stars[i].fwhmMaj   = FX*2.8;
     1063    stars[i].fwhmMin   = FY*2.8;
     1064
     1065    // randomly give poor PSFQF values
     1066    if ((BAD_PSFQF_FRAC > 0.0) && (drand48() < BAD_PSFQF_FRAC)) {
     1067      stars[i].psfQF     = 0.25;
     1068      stars[i].psfQFperf = 0.24;
     1069    } else {
     1070      stars[i].psfQF     = PSFQUAL;
     1071      stars[i].psfQFperf = MAX(PSFQUAL - 0.01, 0.0);
     1072    }
     1073
     1074    stars[i].psfNdof   = 1;
     1075    stars[i].psfNpix   = 2;
     1076
     1077    stars[i].Mxx       = FX;
     1078    stars[i].Mxy       = 0.01;
     1079    stars[i].Myy       = FX;
     1080    stars[i].M3c       = FX;
     1081    stars[i].M3s       = FX;
     1082    stars[i].M4c       = FX;
     1083    stars[i].M4s       = FX;
     1084    stars[i].Mr1       = FX;
     1085    stars[i].Mrh       = FX;
     1086
     1087    stars[i].X11_sm_obj = FX;
     1088    stars[i].X12_sm_obj = FX;
     1089    stars[i].X22_sm_obj = FY;
     1090    stars[i].E1_sm_obj  = FX;
     1091    stars[i].E2_sm_obj  = FX;
     1092
     1093    stars[i].X11_sh_obj = FX;
     1094    stars[i].X12_sh_obj = 0.2;
     1095    stars[i].X22_sh_obj = FY;
     1096    stars[i].E1_sh_obj  = FX*0.9;
     1097    stars[i].E2_sh_obj  = FX*0.8;
     1098
     1099    stars[i].X11_sm_psf = FX;
     1100    stars[i].X12_sm_psf = FX;
     1101    stars[i].X22_sm_psf = FX;
     1102    stars[i].E1_sm_psf  = FX;
     1103    stars[i].E2_sm_psf  = FX;
     1104
     1105    stars[i].X11_sh_psf = FX;
     1106    stars[i].X12_sh_psf = FX;
     1107    stars[i].X22_sh_psf = FX;
     1108    stars[i].E1_sh_psf  = FX;
     1109    stars[i].E2_sh_psf  = FX;
     1110
     1111    stars[i].kronFlux  = flux * 1.25;
     1112    stars[i].kronFluxErr = fSN * flux * 1.25;
     1113
     1114    stars[i].kronInner = fSN * flux * 0.9;
     1115    stars[i].kronOuter = fSN * flux * 1.5;
     1116
     1117    stars[i].skyLimitRad = 1;
     1118    stars[i].skyLimitFlux = 2;
     1119    stars[i].skyLimitSlope = 0.2;
     1120
     1121    stars[i].flags     = Flag[i];
     1122    stars[i].flags2    = 0x80;
     1123
     1124    stars[i].nFrames   = 1;
     1125
     1126    if (ADDNOISE) {
     1127      stars[i].X += FX * fSN * rnd_gauss(0.0, 1.0);
     1128      stars[i].Y += FY * fSN * rnd_gauss(0.0, 1.0);
     1129      float Moff = fSN*rnd_gauss(0.0, 1.0);
     1130      stars[i].M += Moff;
     1131      stars[i].Map += Moff;
     1132      stars[i].MapRaw += Moff;
     1133      stars[i].Mcalib += Moff;
     1134    }
     1135  }
     1136
     1137  gfits_table_set_CMF_PS1_V5_Lensing (ftable, stars, Nstars);
     1138  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_V5");
     1139}
     1140
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/replace_match.c

    r26278 r37403  
    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/ps2-tc3-20130727/Ohana/src/addstar/src/resort_catalog.c

    r35760 r37403  
    11# include "addstar.h"
    22
     3void SortAveMatch (off_t *MEAS, off_t *AVE, off_t N);
     4void resort_catalog_measure (Catalog *catalog);
     5void resort_catalog_lensing (Catalog *catalog);
     6
    37void resort_catalog_old (Catalog *catalog) {
    48
    5   off_t *next_meas;
    6   off_t Naves, Nmeas;
    7   double dtime;
    8   struct timeval start, stop;
     9  off_t *next_meas, *next_lens;
     10  off_t Naves, Nmeas, Nlens;
    911
    1012  if (catalog[0].sorted == TRUE) return;
    1113
    12   gettimeofday (&start, NULL);
     14  INITTIME;
    1315
    1416  /* internal counters */
    1517  Nmeas = catalog[0].Nmeasure;
     18  Nlens = catalog[0].Nlensing;
    1619  Naves = catalog[0].Naverage;
    1720 
    1821  /* set up pointers for linked list of measure, missing */
    1922  next_meas = build_measure_links (catalog[0].average, Naves, catalog[0].measure, Nmeas);
     23  next_lens = build_lensing_links (catalog[0].average, Naves, catalog[0].lensing, Nlens);
    2024
    2125  catalog[0].sorted = TRUE;
    2226  catalog[0].measure = sort_measure (catalog[0].average, Naves, catalog[0].measure, Nmeas, next_meas);
    23 
    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);
     27  catalog[0].lensing = sort_lensing (catalog[0].average, Naves, catalog[0].lensing, Nlens, next_lens);
     28
     29  MARKTIME ("  match time %9.4f sec for %7lld measures, %6lld average\n", dtime, (long long) Nmeas, (long long) Naves);
    2730
    2831  return;
    2932}
    3033
    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 
    5334void resort_catalog (Catalog *catalog) {
     35
     36  if (catalog[0].sorted == TRUE) return;
     37
     38  resort_catalog_measure (catalog);
     39  resort_catalog_lensing (catalog);
     40}
     41
     42void resort_catalog_measure (Catalog *catalog) {
    5443
    5544  off_t Naverage, Nmeasure;
     
    6251  Measure *measureTMP = NULL;
    6352
    64   if (catalog[0].sorted == TRUE) return;
    65 
    6653  // struct timeval start, stop;
    6754  // gettimeofday (&start, NULL);
     
    7057  Nmeasure = catalog[0].Nmeasure;
    7158  Naverage = catalog[0].Naverage;
     59
     60  if (!Nmeasure) return;
    7261
    7362  measure = catalog[0].measure;
     
    9382      myAssert(average[averageSeq[i]].catID == measure[measureSeq[i]].catID, "object / detection mismatch");
    9483# if (1)
    95       myAssert(average[averageSeq[i]].objID == measure[measureSeq[i]].objID, "object / detection mismatch");
     84      // myAssert(average[averageSeq[i]].objID == measure[measureSeq[i]].objID, "object / detection mismatch");
     85      // check if the objID is correct. if not, check if it is byte-swapped (this has happened) and repair if so. 
     86      // otherwise, abort
     87      if (average[averageSeq[i]].objID != measure[measureSeq[i]].objID) {
     88        fprintf (stderr, "object / detection mismatch average.objID = %d, measure.objID = %d, catID: %d, detID: %d",
     89                 average[averageSeq[i]].objID, measure[measureSeq[i]].objID,
     90                 measure[measureSeq[i]].catID, measure[measureSeq[i]].detID);
     91        int objIDalt = measure[measureSeq[i]].objID;
     92        char *byte = (char *) &objIDalt;
     93        char tmp;
     94        tmp = byte[0]; byte[0] = byte[3]; byte[3] = tmp;
     95        tmp = byte[1]; byte[1] = byte[2]; byte[2] = tmp;
     96        if (average[averageSeq[i]].objID == objIDalt) {
     97          fprintf (stderr, "objID is byte-swapped, repairing\n");
     98          measure[measureSeq[i]].objID = average[averageSeq[i]].objID; // XXX I don't really like this...
     99        } else if (measure[measureSeq[i]].objID == 0) {
     100          fprintf (stderr, "objID is 0, repairing\n");
     101          measure[measureSeq[i]].objID = average[averageSeq[i]].objID; // XXX I don't really like this...
     102        } else {
     103          myAbort ("objID is NOT byte-swapped, aborting\n");
     104        }
     105      }
    96106# else
    97107      // for reasons I do not understand, the mini dvodbs generated on stsci1X had a handful of detections with an inconsistency between averef and objID. 
     
    113123  // fprintf (stderr, "\n");
    114124
    115   SortAveMeasMatch(measureSeq, averageSeq, Nmeasure);
     125  SortAveMatch(measureSeq, averageSeq, Nmeasure);
    116126  // MARKTIME("sort : %f sec\n", dtime);
    117127
     
    188198}
    189199
     200void resort_catalog_lensing (Catalog *catalog) {
     201
     202  off_t Naverage, Nlensing;
     203  Lensing *lensing;
     204  Average *average;
     205  off_t i, j, N, currentAve;
     206
     207  off_t *lensingSeq = NULL;
     208  off_t *averageSeq = NULL;
     209  Lensing *lensingTMP = NULL;
     210
     211  // struct timeval start, stop;
     212  // gettimeofday (&start, NULL);
     213
     214  /* internal counters */
     215  Nlensing = catalog[0].Nlensing;
     216  Naverage = catalog[0].Naverage;
     217
     218  if (!Nlensing) return;
     219
     220  lensing = catalog[0].lensing;
     221  average = catalog[0].average;
     222 
     223  // we have a table of average objects and an unsorted table of measurements.  each measurement
     224  // has a reference to the average object sequence (as well as an ID)
     225  // lensing[i].averef -> average[averef]
     226  // lensing[i].objID = average[averef].objID
     227  // lensing[i].catID = average[averef].catID
     228
     229  // we want a sorted lensing array with all averef entries in sequence
     230
     231  ALLOCATE (lensingSeq, off_t,   Nlensing);
     232  ALLOCATE (averageSeq, off_t,   Nlensing);
     233
     234  for (i = 0; i < Nlensing; i++) {
     235    lensingSeq[i] = i;
     236    averageSeq[i] = lensing[i].averef;
     237   
     238    if (catalog[0].catformat >= DVO_FORMAT_PS1_V1) {
     239      // earlier formats did not carry the objID or catID, so they are not available (we could assign on load, but we don't)
     240      myAssert(average[averageSeq[i]].catID == lensing[lensingSeq[i]].catID, "object / detection mismatch");
     241# if (1)
     242      myAssert(average[averageSeq[i]].objID == lensing[lensingSeq[i]].objID, "object / detection mismatch");
     243# else
     244      // for reasons I do not understand, the mini dvodbs generated on stsci1X had a handful of detections with an inconsistency between averef and objID. 
     245      // 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
     246      if (average[averageSeq[i]].objID != lensing[lensingSeq[i]].objID) {
     247        fprintf (stderr, "R");
     248        lensing[lensingSeq[i]].objID = average[averageSeq[i]].objID; // XXX I don't really like this...
     249      }
     250# endif
     251    }
     252  }
     253 
     254  // check that averageSeq is now in order
     255  // for (i = 1; i < Nlensing; i++) {
     256  //   if (averageSeq[i] < averageSeq[i-1]) {
     257  //     fprintf (stderr, "%d ", (int) i);
     258  //   }
     259  // }
     260  // fprintf (stderr, "\n");
     261
     262  SortAveMatch(lensingSeq, averageSeq, Nlensing);
     263  // MARKTIME("sort : %f sec\n", dtime);
     264
     265  // check that averageSeq is now in order
     266  // for (i = 1; i < Nlensing; i++) {
     267  //   if (averageSeq[i] < averageSeq[i-1]) {
     268  //     fprintf (stderr, "%d ", (int) i);
     269  //   }
     270  // }
     271  // fprintf (stderr, "\n");
     272
     273  // copy the lensing entries in the sorted order
     274  ALLOCATE (lensingTMP, Lensing, Nlensing);
     275  for (i = 0; i < Nlensing; i++) {
     276    j = lensingSeq[i];
     277    lensingTMP[i] = lensing[j];
     278  }
     279  // MARKTIME("assign lensing : %f sec\n", dtime);
     280
     281  // update the values of average.lensingOffset and average.Nlensing
     282  FREE(lensing);
     283  catalog[0].lensing = lensingTMP;
     284
     285  N = 0;
     286  currentAve = averageSeq[0];
     287  average[currentAve].lensingOffset = 0;
     288  for (i = 0; i < Nlensing; i++) {
     289    if (averageSeq[i] != currentAve) {
     290      // we have hit the next entry in the list
     291      average[currentAve].Nlensing = N;
     292      N = 0;
     293      currentAve = averageSeq[i];
     294      average[currentAve].lensingOffset = i;
     295    }
     296    N++;
     297  }
     298  // N++;
     299  average[currentAve].Nlensing = N;
     300  // MARKTIME("update Nlensing : %f sec\n", dtime);
     301
     302  int NlensingTotal = 0;
     303  int lensingOffsetOK = TRUE;
     304  for (i = 0; i < Naverage; i++) {
     305    NlensingTotal += catalog[0].average[i].Nlensing;
     306    if (VERBOSE && !(NlensingTotal <= catalog[0].Nlensing)) {
     307      fprintf (stderr, "too few lensing: %d %d %d\n", (int) i, NlensingTotal, (int) catalog[0].Nlensing);
     308    }
     309    lensingOffsetOK &= (catalog[0].average[i].lensingOffset < catalog[0].Nlensing);
     310    if (VERBOSE && !(catalog[0].average[i].lensingOffset < catalog[0].Nlensing)) {
     311      fprintf (stderr, "offset too large: %d %d %d\n", (int) i, catalog[0].average[i].Nlensing, (int) catalog[0].Nlensing);
     312    }
     313    lensingOffsetOK &= (catalog[0].average[i].lensingOffset + catalog[0].average[i].Nlensing <= catalog[0].Nlensing);
     314    if (VERBOSE && !(catalog[0].average[i].lensingOffset + catalog[0].average[i].Nlensing <= catalog[0].Nlensing)) {
     315      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);
     316    }
     317  }
     318
     319  if (!lensingOffsetOK) {
     320    fprintf (stderr, "ERROR: catalog %s has an invalid lensingOffset\n", catalog[0].filename);
     321  }
     322
     323  if (NlensingTotal != catalog[0].Nlensing) {
     324    fprintf (stderr, "ERROR: catalog %s has an invalid Nlensing\n", catalog[0].filename);
     325  }
     326
     327  // MARKTIME("  match time %9.4f sec for %7lld lensings, %6lld average\n", dtime, (long long) Nlensing, (long long) Naverage);
     328
     329  catalog[0].sorted = TRUE;
     330
     331  FREE (lensingSeq);
     332  FREE (averageSeq);
     333
     334  return;
     335}
     336
     337// sort the measure or lensing Sequence based on the average Sequence entries
     338void SortAveMatch (off_t *MEAS, off_t *AVE, off_t N) {
     339
     340# define SWAPFUNC(A,B){ off_t tmp_meas; off_t tmp_ave;          \
     341    tmp_meas = MEAS[A]; MEAS[A] = MEAS[B]; MEAS[B] = tmp_meas;  \
     342    tmp_ave  = AVE[A];  AVE[A]  = AVE[B];  AVE[B]  = tmp_ave;   \
     343  }
     344# define COMPARE(A,B)(AVE[A] < AVE[B])
     345  OHANA_SORT (N, COMPARE, SWAPFUNC);
     346# undef SWAPFUNC
     347# undef COMPARE
     348}
     349
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/resort_threaded.c

    r29938 r37403  
    1313  int iThread;
    1414  int state;
    15   int nosort;
     15  int forcesort;
    1616  char *filename;
    1717  SkyRegion *region;
     
    3737    }
    3838
     39    // chose the catalog file (local or remote?)
     40    char hostfile[1024];
     41    snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, threadData->region->name);
     42    catalog.filename  = HOST_ID ? hostfile : threadData->filename;
     43
    3944    // set the parameters which guide catalog open/load/create
    40     catalog.filename  = threadData->filename;
    4145    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    4246    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    43     catalog.catflags  = LOAD_AVES | LOAD_MEAS;
     47    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_LENSING;
    4448    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    4549 
     
    6468
    6569    // this is an overloaded value to mean 'force sort'
    66     if (threadData->nosort == 3) catalog.sorted = FALSE;
     70    if (threadData->forcesort) catalog.sorted = FALSE;
    6771
    6872    if (OLD_RESORT) {
     
    8892}
    8993
    90 int resort_threaded (AddstarClientOptions *options, SkyTable *sky) {
     94int resort_threaded (SkyList *skylist, int ForceSort) {
    9195
    9296  int j, launched, done, Nwait, Nrun;
     
    97101  ThreadData *threadData;
    98102  pthread_t *threads;
    99 
    100   double dtime;
    101   struct timeval start, stop;
    102   gettimeofday (&start, NULL);
    103 
    104   SkyList *skylist = SkyListByPatch (sky, -1, &UserPatch);
    105  
    106   // in these cases, limit the sky catalogs to an existing subset
    107   if (options->existing_regions) {
    108     SkyList *tmp;
    109     tmp = SkyListExistingSubset (skylist, CATDIR);
    110     SkyListFree (skylist);
    111     skylist = tmp;
    112   }
    113   if (VERBOSE) fprintf (stderr, "writing to "OFF_T_FMT" regions\n",  skylist[0].Nregions);
    114 
    115   if (options->only_images) {
    116     fprintf (stderr, "-image (only images) makes no sense with -resort\n");
    117     exit (2);
    118   }
    119   if (options->only_match) {
    120     fprintf (stderr, "-only-match makes no sense with -resort\n");
    121     exit (2);
    122   }
    123   if (options->nosort == 1) {
    124     fprintf (stderr, "-nosort makes no sense with -resort\n");
    125     exit (2);
    126   }
    127   if (options->update) {
    128     fprintf (stderr, "-update makes no sense with -resort\n");
    129     exit (2);
    130   }
    131   if (options->calibrate) {
    132     fprintf (stderr, "-cal (calibrate) makes no sense with -resort\n");
    133     exit (2);
    134   }
    135103
    136104  ALLOCATE(threads, pthread_t, NTHREADS);
     
    148116  Naverage = Nmeasure = 0;
    149117  for (i = 0; i < skylist[0].Nregions; i++) {
     118
     119    // does this host ID match the desired location for the table?
     120    if (!HostTableTestHost(skylist[0].regions[i], HOST_ID)) continue;
    150121
    151122    launched = FALSE;
     
    166137        if (threadData[j].state == TS_FAIL) goto failure;
    167138        if (threadData[j].state != TS_WAIT) continue;
    168         threadData[j].nosort = options->nosort;
     139        threadData[j].forcesort = ForceSort;
    169140        threadData[j].filename = skylist[0].filename[i];
    170141        threadData[j].region = skylist[0].regions[i];
     
    203174  }
    204175
    205   gettimeofday (&stop, NULL);
    206   dtime = DTIME (stop, start);
    207   fprintf (stderr, "SUCCESS: elapsed time %9.4f sec for, "OFF_T_FMT" average, "OFF_T_FMT" measure\n", dtime, Naverage, Nmeasure);
    208 
    209176  // for (i = 0; i < NTHREADS; i++) {
    210177  //   pthread_cancel(threads[i]);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/resort_unthreaded.c

    r35142 r37403  
    11# include "addstar.h"
    22
    3 int resort_unthreaded (AddstarClientOptions *options, SkyTable *sky, int hostID, char *hostpath) {
     3// pass in options and skylist?
     4int resort_unthreaded (SkyList *skylist, int ForceSort) {
    45
    5   double dtime;
    6   struct timeval start, stop;
     6  off_t i;
     7  off_t Naverage, Nmeasure;
     8  Catalog catalog;
    79
    8   gettimeofday (&start, NULL);
     10  /* match stars to existing catalog data (or otherwise manipulate catalog data) */
     11  Naverage = Nmeasure = 0;
     12  for (i = 0; i < skylist[0].Nregions; i++) {
    913
    10   SkyList *skylist = SkyListByPatch (sky, -1, &UserPatch);
    11  
    12   // in these cases, limit the sky catalogs to an existing subset
    13   if (options->existing_regions) {
    14     SkyList *tmp;
    15     tmp = SkyListExistingSubset (skylist, CATDIR);
    16     SkyListFree (skylist);
    17     skylist = tmp;
     14    // does this host ID match the desired location for the table?
     15    if (!HostTableTestHost(skylist[0].regions[i], HOST_ID)) continue;
     16
     17    // chose the catalog file (local or remote?)
     18    char hostfile[1024];
     19    snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
     20    catalog.filename  = HOST_ID ? hostfile : skylist[0].filename[i];
     21
     22    // set the parameters which guide catalog open/load/create
     23    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
     24    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
     25    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_LENSING;
     26    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
     27
     28    // an error exit status here is a significant error (disk I/O or file access)
     29    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
     30      fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
     31      exit (2);
     32    }
     33
     34    // Naves_disk == 0 implies an empty catalog file, skip empty catalogs
     35    if (catalog.Naves_disk == 0) {
     36      dvo_catalog_unlock (&catalog);
     37      dvo_catalog_free (&catalog);
     38      continue;
     39    }
     40
     41    // this is an overloaded value to mean 'force sort'
     42    if (ForceSort) catalog.sorted = FALSE;
     43
     44    if (OLD_RESORT) {
     45      resort_catalog_old (&catalog);
     46    } else {
     47      resort_catalog (&catalog);
     48    }
     49
     50    // report total updated values
     51    Naverage += catalog.Naverage;
     52    Nmeasure += catalog.Nmeasure;
     53
     54    // write out catalog, if appropriate
     55    SetProtect (TRUE);
     56    dvo_catalog_save (&catalog, VERBOSE);
     57    SetProtect (FALSE);
     58    dvo_catalog_unlock (&catalog);
     59    dvo_catalog_free (&catalog);
    1860  }
    19   if (VERBOSE) fprintf (stderr, "writing to "OFF_T_FMT" regions\n",  skylist[0].Nregions);
    20 
    21   if (options->only_images) {
    22     fprintf (stderr, "-image (only images) makes no sense with -resort\n");
    23     exit (2);
    24   }
    25   if (options->only_match) {
    26     fprintf (stderr, "-only-match makes no sense with -resort\n");
    27     exit (2);
    28   }
    29   if (options->nosort == 1) {
    30     fprintf (stderr, "-nosort makes no sense with -resort\n");
    31     exit (2);
    32   }
    33   if (options->update) {
    34     fprintf (stderr, "-update makes no sense with -resort\n");
    35     exit (2);
    36   }
    37   if (options->calibrate) {
    38     fprintf (stderr, "-cal (calibrate) makes no sense with -resort\n");
    39     exit (2);
    40   }
    41 
    42   resort_unthreaded_catalogs (options, skylist, hostID, hostpath);
    43 
    44   gettimeofday (&stop, NULL);
    45   dtime = DTIME (stop, start);
    46   fprintf (stderr, "SUCCESS: elapsed time %9.4f sec\n", dtime);
    47 
    4861  return TRUE;
    4962}
    5063
     64
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/update_coords.c

    r34405 r37403  
    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/ps2-tc3-20130727/Ohana/src/addstar/test/simple.dvo

    r35263 r37403  
    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/ps2-tc3-20130727/Ohana/src/delstar/include/delstar.h

    r35837 r37403  
    6767int    UPDATE;
    6868int    IMAGE_DETAILS;
     69int    IMAGE_DUPLICATES_BY_OBSTIME;
    6970int    IMAGE_ONLY;
    7071int    ORPHAN;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/delstar/src/ImageOpsFixLAP.c

    r35758 r37403  
    11# include "delstar.h"
    2 # define FT_BZERO_INT32 1.0*0x80000000
    32
    43off_t   Nimage = 0;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/delstar/src/ImageSubsetFixLAP.c

    r35758 r37403  
    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/ps2-tc3-20130727/Ohana/src/delstar/src/MeasureEdgeOps.c

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

    r35758 r37403  
    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/ps2-tc3-20130727/Ohana/src/delstar/src/delete_duplicate_images.c

    r35758 r37403  
    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/ps2-tc3-20130727/Ohana/src/delstar/src/delete_fix_LAP_edges.c

    r35805 r37403  
    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/ps2-tc3-20130727/Ohana/src/dvomerge/include/dvomerge.h

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    r36680 r37403  
    99
    1010typedef struct {
    11   int imageID;
    12   unsigned int ippDetectID;
     11  uint64_t objID;
    1312  uint64_t detectID;
    1413  uint64_t ippObjID;
    15   uint64_t objID;
    16   int      photcode;
    17   unsigned int flags;
    18   float zp;
    19   float zpErr;
    20   float airMass;
    21   float expTime;
     14  unsigned int ippDetectID;
     15  int imageID;
     16  int catID;
    2217  double ra;
    2318  double dec;
    2419  float raErr;
    2520  float decErr;
     21  float zp;
     22  float telluricExt;
     23  float airmass;
     24  float expTime;
     25
     26  float Mpsf;
     27  float dMpsf;
     28  float Mkron;
     29  float dMkron;
     30  float Map;
     31  float dMap;
     32
     33  unsigned int flags;
    2634} Detections;
    2735
     
    7886     
    7987int    insert_detections_mysql_commit     PROTO((IOBuffer *buffer, MYSQL *mysql));
    80 int    insert_detections_mysql_value      PROTO((IOBuffer *buffer, Average *average, Measure *measure));
     88// int    insert_detections_mysql_value      PROTO((IOBuffer *buffer, Average *average, Measure *measure));
    8189int    insert_detections_mysql_init       PROTO((IOBuffer *buffer));
    8290
    8391int    insert_detections_mysql_array      PROTO((MYSQL *mysql, Detections *detections, int Ndetections));
    8492int    insert_detections_mysql_detvalue   PROTO((IOBuffer *buffer, Detections *detection));
     93int    assign_detection_values            PROTO((Detections *detection, Measure *measure, Average *average));
    8594
    8695int    init_detections                    PROTO(());
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvopsps/src/DetectionOps.c

    r35578 r37403  
    11# include "dvopsps.h"
    2 # define BZERO_INT16 1.0*0x8000
    3 # define BZERO_INT32 1.0*0x80000000
    4 # define BZERO_INT64 1.0*0x8000000000000000
    52
    63# define GET_COLUMN(OUT,NAME,TYPE)                                      \
     
    4946 
    5047  // need to create and assign to flat-field correction
    51   GET_COLUMN(imageID     , "imageID",     int);
    52   GET_COLUMN(ippDetectID , "ippDetectID", int);
     48  GET_COLUMN(objID       , "objID",       int64_t);
    5349  GET_COLUMN(detectID    , "detectID",    int64_t);
    5450  GET_COLUMN(ippObjID    , "ippObjID",    int64_t);
    55   GET_COLUMN(objID       , "objID",       int64_t);
    56   GET_COLUMN(photcode    , "photcode",    int);
    57   GET_COLUMN(flags       , "flags",       int);
    58   GET_COLUMN(zp          , "zp",          float);
    59   GET_COLUMN(zpErr       , "zpErr",       float);
    60   GET_COLUMN(airMass     , "airMass",     float);
    61   GET_COLUMN(expTime     , "expTime",     float);
     51  GET_COLUMN(ippDetectID , "ippDetectID", int);
     52  GET_COLUMN(imageID     , "imageID",     int);
     53  GET_COLUMN(catID       , "catID",       int);
    6254  GET_COLUMN(ra          , "ra",          double); // XXX signed vs unsigned?
    6355  GET_COLUMN(dec         , "dec",         double);
    6456  GET_COLUMN(raErr       , "raErr",       float);
    6557  GET_COLUMN(decErr      , "decErr",      float);
     58  GET_COLUMN(zp          , "zp",          float);
     59  GET_COLUMN(telluricExt , "telluricExt", float);
     60  GET_COLUMN(airmass     , "airmass",     float);
     61  GET_COLUMN(expTime     , "expTime",     float);
     62  GET_COLUMN(Mpsf        , "Mpsf",        float);
     63  GET_COLUMN(dMpsf       , "dMpsf",       float);
     64  GET_COLUMN(Mkron       , "Mkron",       float);
     65  GET_COLUMN(dMkron      , "dMkron",      float);
     66  GET_COLUMN(Map         , "Map",         float);
     67  GET_COLUMN(dMap        , "dMap",        float);
     68  GET_COLUMN(flags       , "flags",       int);
    6669  gfits_free_header (&theader);
    6770  gfits_free_table  (&ftable);
     
    6972  ALLOCATE (detections, Detections, Nrow);
    7073  for (i = 0; i < Nrow; i++) {
    71     detections[i].imageID      = imageID[i];   
    72     detections[i].ippDetectID  = ippDetectID[i];
     74    detections[i].objID        = objID[i];     
    7375    detections[i].detectID     = detectID[i];   
    7476    detections[i].ippObjID     = ippObjID[i];   
    75     detections[i].objID        = objID[i];     
    76     detections[i].photcode     = photcode[i];     
    77     detections[i].flags        = flags[i];     
    78     detections[i].zp           = zp[i];         
    79     detections[i].zpErr        = zpErr[i];     
    80     detections[i].airMass      = airMass[i];   
    81     detections[i].expTime      = expTime[i];   
     77    detections[i].ippDetectID  = ippDetectID[i];
     78    detections[i].imageID      = imageID[i];   
     79    detections[i].catID        = catID[i];   
    8280    detections[i].ra           = ra[i];         
    8381    detections[i].dec          = dec[i];       
    8482    detections[i].raErr        = raErr[i];     
    8583    detections[i].decErr       = decErr[i];     
     84    detections[i].zp           = zp[i];         
     85    detections[i].telluricExt  = telluricExt[i];     
     86    detections[i].airmass      = airmass[i];   
     87    detections[i].expTime      = expTime[i];   
     88    detections[i].Mpsf         = Mpsf[i];   
     89    detections[i].dMpsf        = dMpsf[i];   
     90    detections[i].Mkron        = Mkron[i];   
     91    detections[i].dMkron       = dMkron[i];   
     92    detections[i].Map          = Map[i];   
     93    detections[i].dMap         = dMap[i];   
     94    detections[i].flags        = flags[i];     
    8695  }
    8796  fprintf (stderr, "loaded data for %lld detections\n", (long long) Nrow);
    8897
    89   free (imageID    );
    90   free (ippDetectID);
     98  free (objID      );
    9199  free (detectID   );
    92100  free (ippObjID   );
    93   free (objID      );
    94   free (photcode   );
    95   free (flags      );
    96   free (zp         );
    97   free (zpErr      );
    98   free (airMass    );
    99   free (expTime    );
     101  free (ippDetectID);
     102  free (imageID    );
     103  free (catID      );
    100104  free (ra         );
    101105  free (dec        );
    102106  free (raErr      );
    103107  free (decErr     );
     108  free (zp         );
     109  free (telluricExt);
     110  free (airmass    );
     111  free (expTime    );
     112  free (Mpsf       );
     113  free (dMpsf      );
     114  free (Mkron      );
     115  free (dMkron     );
     116  free (Map        );
     117  free (dMap       );
     118  free (flags      );
    104119
    105120  gfits_free_header (&header);
     
    149164
    150165  // XXX need to get the bzero values right
    151   gfits_define_bintable_column (&theader, "J", "imageID",     NULL, NULL, 1.0, BZERO_INT32);
    152   gfits_define_bintable_column (&theader, "J", "ippDetectID", NULL, NULL, 1.0, BZERO_INT32);
     166  gfits_define_bintable_column (&theader, "K", "objID",       NULL, NULL, 1.0, 0);
    153167  gfits_define_bintable_column (&theader, "K", "detectID",    NULL, NULL, 1.0, 0);
    154168  gfits_define_bintable_column (&theader, "K", "ippObjID",    NULL, NULL, 1.0, 0);
    155   gfits_define_bintable_column (&theader, "K", "objID",       NULL, NULL, 1.0, 0);
    156   // gfits_define_bintable_column (&theader, "K", "detectID",    NULL, NULL, 1.0, BZERO_INT64);
    157   // gfits_define_bintable_column (&theader, "K", "ippObjID",    NULL, NULL, 1.0, BZERO_INT64);
    158   // gfits_define_bintable_column (&theader, "K", "objID",       NULL, NULL, 1.0, BZERO_INT64);
    159   gfits_define_bintable_column (&theader, "J", "photcode",    NULL, NULL, 1.0, 0.0);
    160   gfits_define_bintable_column (&theader, "J", "flags",       NULL, NULL, 1.0, BZERO_INT32);
    161   gfits_define_bintable_column (&theader, "E", "zp",          NULL, NULL, 1.0, 0.0);
    162   gfits_define_bintable_column (&theader, "E", "zpErr",       NULL, NULL, 1.0, 0.0);
    163   gfits_define_bintable_column (&theader, "E", "airMass",     NULL, NULL, 1.0, 0.0);
    164   gfits_define_bintable_column (&theader, "E", "expTime",     NULL, NULL, 1.0, 0.0);
     169  gfits_define_bintable_column (&theader, "J", "ippDetectID", NULL, NULL, 1.0, FT_BZERO_INT32);
     170  gfits_define_bintable_column (&theader, "J", "imageID",     NULL, NULL, 1.0, FT_BZERO_INT32);
     171  gfits_define_bintable_column (&theader, "J", "catID",       NULL, NULL, 1.0, FT_BZERO_INT32);
    165172  gfits_define_bintable_column (&theader, "D", "ra",          NULL, NULL, 1.0, 0.0);
    166173  gfits_define_bintable_column (&theader, "D", "dec",         NULL, NULL, 1.0, 0.0);
    167174  gfits_define_bintable_column (&theader, "E", "raErr",       NULL, NULL, 1.0, 0.0);
    168175  gfits_define_bintable_column (&theader, "E", "decErr",      NULL, NULL, 1.0, 0.0);
     176  gfits_define_bintable_column (&theader, "E", "zp",          NULL, NULL, 1.0, 0.0);
     177  gfits_define_bintable_column (&theader, "E", "telluricExt", NULL, NULL, 1.0, 0.0);
     178  gfits_define_bintable_column (&theader, "E", "airmass",     NULL, NULL, 1.0, 0.0);
     179  gfits_define_bintable_column (&theader, "E", "expTime",     NULL, NULL, 1.0, 0.0);
     180  gfits_define_bintable_column (&theader, "E", "Mpsf",        NULL, NULL, 1.0, 0.0);
     181  gfits_define_bintable_column (&theader, "E", "dMpsf",       NULL, NULL, 1.0, 0.0);
     182  gfits_define_bintable_column (&theader, "E", "Mkron",       NULL, NULL, 1.0, 0.0);
     183  gfits_define_bintable_column (&theader, "E", "dMkron",      NULL, NULL, 1.0, 0.0);
     184  gfits_define_bintable_column (&theader, "E", "Map",         NULL, NULL, 1.0, 0.0);
     185  gfits_define_bintable_column (&theader, "E", "dMap",        NULL, NULL, 1.0, 0.0);
     186  gfits_define_bintable_column (&theader, "J", "flags",       NULL, NULL, 1.0, FT_BZERO_INT32);
    169187
    170188  // generate the output array that carries the data
     
    172190
    173191  // create intermediate storage arrays
    174    int32_t   *imageID     ; ALLOCATE (imageID     ,   int32_t, Ndetections);
    175   uint32_t   *ippDetectID ; ALLOCATE (ippDetectID ,  uint32_t, Ndetections);
     192  uint64_t   *objID       ; ALLOCATE (objID       ,  uint64_t, Ndetections);
    176193  uint64_t   *detectID    ; ALLOCATE (detectID    ,  uint64_t, Ndetections);
    177194  uint64_t   *ippObjID    ; ALLOCATE (ippObjID    ,  uint64_t, Ndetections);
    178   uint64_t   *objID       ; ALLOCATE (objID       ,  uint64_t, Ndetections);
    179   int        *photcode    ; ALLOCATE (photcode    ,  int,      Ndetections);
    180   uint32_t   *flags       ; ALLOCATE (flags       ,  uint32_t, Ndetections);
    181   float      *zp          ; ALLOCATE (zp          ,  float,    Ndetections);
    182   float      *zpErr       ; ALLOCATE (zpErr       ,  float,    Ndetections);
    183   float      *airMass     ; ALLOCATE (airMass     ,  float,    Ndetections);
    184   float      *expTime     ; ALLOCATE (expTime     ,  float,    Ndetections);
     195  uint32_t   *ippDetectID ; ALLOCATE (ippDetectID ,  uint32_t, Ndetections);
     196   int32_t   *imageID     ; ALLOCATE (imageID     ,   int32_t, Ndetections);
     197   int32_t   *catID       ; ALLOCATE (catID       ,   int32_t, Ndetections);
    185198  double     *ra          ; ALLOCATE (ra          ,  double,   Ndetections);
    186199  double     *dec         ; ALLOCATE (dec         ,  double,   Ndetections);
    187200  float      *raErr       ; ALLOCATE (raErr       ,  float,    Ndetections);
    188201  float      *decErr      ; ALLOCATE (decErr      ,  float,    Ndetections);
     202  float      *zp          ; ALLOCATE (zp          ,  float,    Ndetections);
     203  float      *telluricExt ; ALLOCATE (telluricExt ,  float,    Ndetections);
     204  float      *airmass     ; ALLOCATE (airmass     ,  float,    Ndetections);
     205  float      *expTime     ; ALLOCATE (expTime     ,  float,    Ndetections);
     206  float      *Mpsf        ; ALLOCATE (Mpsf        ,  float,    Ndetections);
     207  float      *dMpsf       ; ALLOCATE (dMpsf       ,  float,    Ndetections);
     208  float      *Mkron       ; ALLOCATE (Mkron       ,  float,    Ndetections);
     209  float      *dMkron      ; ALLOCATE (dMkron      ,  float,    Ndetections);
     210  float      *Map         ; ALLOCATE (Map         ,  float,    Ndetections);
     211  float      *dMap        ; ALLOCATE (dMap        ,  float,    Ndetections);
     212  uint32_t   *flags       ; ALLOCATE (flags       ,  uint32_t, Ndetections);
    189213
    190214  // assign the storage arrays
    191215  for (i = 0; i < Ndetections; i++) {
    192     imageID[i]     = detections[i].imageID     ;
    193     ippDetectID[i] = detections[i].ippDetectID ;
     216    objID[i]       = detections[i].objID       ;
    194217    detectID[i]    = detections[i].detectID    ;
    195218    ippObjID[i]    = detections[i].ippObjID    ;
    196     objID[i]       = detections[i].objID       ;
    197     photcode[i]    = detections[i].photcode    ;
    198     flags[i]       = detections[i].flags       ;
    199     zp[i]          = detections[i].zp          ;
    200     zpErr[i]       = detections[i].zpErr       ;
    201     airMass[i]     = detections[i].airMass     ;
    202     expTime[i]     = detections[i].expTime     ;
     219    ippDetectID[i] = detections[i].ippDetectID ;
     220    imageID[i]     = detections[i].imageID     ;
     221    catID[i]       = detections[i].catID       ;
    203222    ra[i]          = detections[i].ra          ;
    204223    dec[i]         = detections[i].dec         ;
    205224    raErr[i]       = detections[i].raErr       ;
    206225    decErr[i]      = detections[i].decErr      ;
     226    zp[i]          = detections[i].zp          ;
     227    telluricExt[i] = detections[i].telluricExt ;
     228    airmass[i]     = detections[i].airmass     ;
     229    expTime[i]     = detections[i].expTime     ;
     230    Mpsf[i]        = detections[i].Mpsf        ;
     231    dMpsf[i]       = detections[i].dMpsf       ;
     232    Mkron[i]       = detections[i].Mkron       ;
     233    dMkron[i]      = detections[i].dMkron      ;
     234    Map[i]         = detections[i].Map         ;
     235    dMap[i]        = detections[i].dMap        ;
     236    flags[i]       = detections[i].flags       ;
    207237  }
    208238
    209239  // add the columns to the output array
    210   gfits_set_bintable_column (&theader, &ftable, "imageID",     imageID     , Ndetections);
    211   gfits_set_bintable_column (&theader, &ftable, "ippDetectID", ippDetectID , Ndetections);
     240  gfits_set_bintable_column (&theader, &ftable, "objID",       objID       , Ndetections);
    212241  gfits_set_bintable_column (&theader, &ftable, "detectID",    detectID    , Ndetections);
    213242  gfits_set_bintable_column (&theader, &ftable, "ippObjID",    ippObjID    , Ndetections);
    214   gfits_set_bintable_column (&theader, &ftable, "objID",       objID       , Ndetections);
    215   gfits_set_bintable_column (&theader, &ftable, "photcode",    photcode    , Ndetections);
    216   gfits_set_bintable_column (&theader, &ftable, "flags",       flags       , Ndetections);
    217   gfits_set_bintable_column (&theader, &ftable, "zp",          zp          , Ndetections);
    218   gfits_set_bintable_column (&theader, &ftable, "zpErr",       zpErr       , Ndetections);
    219   gfits_set_bintable_column (&theader, &ftable, "airMass",     airMass     , Ndetections);
    220   gfits_set_bintable_column (&theader, &ftable, "expTime",     expTime     , Ndetections);
     243  gfits_set_bintable_column (&theader, &ftable, "ippDetectID", ippDetectID , Ndetections);
     244  gfits_set_bintable_column (&theader, &ftable, "imageID",     imageID     , Ndetections);
     245  gfits_set_bintable_column (&theader, &ftable, "catID",       catID       , Ndetections);
    221246  gfits_set_bintable_column (&theader, &ftable, "ra",          ra          , Ndetections);
    222247  gfits_set_bintable_column (&theader, &ftable, "dec",         dec         , Ndetections);
    223248  gfits_set_bintable_column (&theader, &ftable, "raErr",       raErr       , Ndetections);
    224249  gfits_set_bintable_column (&theader, &ftable, "decErr",      decErr      , Ndetections);
    225 
    226   free (imageID     );
    227   free (ippDetectID );
     250  gfits_set_bintable_column (&theader, &ftable, "zp",          zp          , Ndetections);
     251  gfits_set_bintable_column (&theader, &ftable, "telluricExt", telluricExt , Ndetections);
     252  gfits_set_bintable_column (&theader, &ftable, "airmass",     airmass     , Ndetections);
     253  gfits_set_bintable_column (&theader, &ftable, "expTime",     expTime     , Ndetections);
     254  gfits_set_bintable_column (&theader, &ftable, "Mpsf",        Mpsf        , Ndetections);
     255  gfits_set_bintable_column (&theader, &ftable, "dMpsf",       dMpsf       , Ndetections);
     256  gfits_set_bintable_column (&theader, &ftable, "Mkron",       Mkron       , Ndetections);
     257  gfits_set_bintable_column (&theader, &ftable, "dMkron",      dMkron      , Ndetections);
     258  gfits_set_bintable_column (&theader, &ftable, "Map",         Map         , Ndetections);
     259  gfits_set_bintable_column (&theader, &ftable, "dMap",        dMap        , Ndetections);
     260  gfits_set_bintable_column (&theader, &ftable, "flags",       flags       , Ndetections);
     261
     262  free (objID       );
    228263  free (detectID    );
    229264  free (ippObjID    );
    230   free (objID       );
    231   free (photcode    );
    232   free (flags       );
    233   free (zp          );
    234   free (zpErr       );
    235   free (airMass     );
    236   free (expTime     );
     265  free (ippDetectID );
     266  free (imageID     );
     267  free (catID       );
    237268  free (ra          );
    238269  free (dec         );
    239270  free (raErr       );
    240271  free (decErr      );
     272  free (zp          );
     273  free (telluricExt );
     274  free (airmass     );
     275  free (expTime     );
     276  free (Mpsf        );
     277  free (dMpsf       );
     278  free (Mkron       );
     279  free (dMkron      );
     280  free (Map         );
     281  free (dMap        );
     282  free (flags       );
    241283
    242284  gfits_fwrite_Theader (f, &theader);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvopsps/src/insert_detections_dvopsps.c

    r36680 r37403  
    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:
     
    7468    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    7569
    76     if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
     70    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "r")) {
    7771      fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename);
    7872      exit (1);
     
    10195    dvo_catalog_unlock (&catalog);
    10296    dvo_catalog_free (&catalog);
     97
     98    if (!status) {
     99      fprintf (stderr, "failure to insert data in mysql\n");
     100      exit (2);
     101    }
    103102  }
    104103
     
    245244  buffer.Nalloc = 0;
    246245
    247   struct timeval start, stop;
    248 
    249246  if (Ndetections == 0) return TRUE;
    250247
     
    254251  int Ninsert = 0;
    255252
    256   gettimeofday (&start, (void *) NULL);
     253  INITTIME;
    257254  for (i = 0; i < Ndetections; i++) {
    258255
     
    289286}
    290287
    291 # define PRINT_FLOAT(BUFFER,FIELD,FORMAT)                 \
    292   if (!isfinite(FIELD)) PrintIOBuffer (BUFFER, "NULL, "); \
    293   else PrintIOBuffer (BUFFER, FORMAT, FIELD);
    294 
    295 int insert_detections_mysql_detvalue (IOBuffer *buffer, Detections *detection) {
    296 
    297   PrintIOBuffer (buffer, "(%d, ", detection->imageID);    // imageID
    298   PrintIOBuffer (buffer, "%u, ", detection->ippDetectID); // ippDetectID
    299   PrintIOBuffer (buffer, "%lu, ", detection->detectID);   // detectID
    300   PrintIOBuffer (buffer, "%lu, ", detection->ippObjID);   // ippObjID
    301   PrintIOBuffer (buffer, "%lu, ", detection->objID);      // objID
    302   PrintIOBuffer (buffer, "%u, ", detection->flags);       // flags
    303   PRINT_FLOAT(buffer, detection->zp,      "%.6f, ");
    304   PRINT_FLOAT(buffer, detection->zpErr,   "%.6f, ");
    305   PRINT_FLOAT(buffer, detection->airMass, "%.6f, ");
    306   PRINT_FLOAT(buffer, detection->expTime, "%.6f, ");
    307   PRINT_FLOAT(buffer, detection->ra,      "%.8f, ");
    308   PRINT_FLOAT(buffer, detection->dec,     "%.8f, ");
    309   PRINT_FLOAT(buffer, detection->raErr,   "%.6f, ");
    310   PRINT_FLOAT(buffer, detection->decErr,  "%.6f),\n");
    311   return TRUE;
    312 }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c

    r36680 r37403  
    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;
     
    126Detections *detections = NULL;
    137
     8static float ZeroPoint = 25.0;
     9
    1410int init_detections () {
    1511  NDETECTIONS = 1000;
     
    2117
    2218  off_t i, j;
     19
     20  ZeroPoint = GetZeroPoint();
    2321
    2422  int missingID = 0;
     
    5351      if (measure->photcode >=  PHOTCODE_END) continue;
    5452
    55       PhotCode *code = GetPhotcodebyCode(measure->photcode);
    56 
    57       detections[Ndetections].imageID     = measure->imageID;    // imageID
    58       detections[Ndetections].ippDetectID = measure->detID;   // ippDetectID
    59       detections[Ndetections].detectID    = measure->extID;   // detectID
    60       detections[Ndetections].ippObjID    = ((uint64_t)average->catID * 1000000000) + (uint64_t)average->objID; // ippObjID
    61       // NOTE: this is better, but the above is the current ippToPsps value
    62       // detections[Ndetections]. ((uint64_t)average->catID << 32) + (uint64_t)average->objID; // ippObjID
    63       detections[Ndetections].objID        = average->extID;   // objID
    64       detections[Ndetections].photcode     = measure->photcode;   // photcode
    65       detections[Ndetections].flags        = measure->dbFlags;  // flags
    66       detections[Ndetections].zp           = code->C * 0.001 + code->K * (measure->airmass - 1) - measure->Mcal;   // zp
    67       detections[Ndetections].zpErr        = measure->dMcal;    // zpErr
    68       detections[Ndetections].airMass      = measure->airmass;
    69       detections[Ndetections].expTime      = pow(10.0, 0.4 * measure->dt);    // expTime
    70       detections[Ndetections].ra           = average->R - measure->dR / 3600.;    // ra
    71       detections[Ndetections].dec          = average->D - measure->dD / 3600.;    // dec
    72       detections[Ndetections].raErr        = measure->dXccd * 0.01 * fabs(measure->pltscale); // estimate of raErr
    73       detections[Ndetections].decErr       = measure->dYccd * 0.01 * fabs(measure->pltscale); // estimate of decErr
    74 
     53      assign_detection_values (&detections[Ndetections], measure, average);
    7554      Ndetections ++;
     55
    7656      myAssert (Ndetections <= NDETECTIONS, "programming error");
    7757    }
     
    10787  off_t i, j;
    10888  int missingID = 0;
    109   struct timeval start, stop;
    11089
    11190  IOBuffer buffer;
     
    11796  off_t found = 0;
    11897
    119   gettimeofday (&start, (void *) NULL);
     98  ZeroPoint = GetZeroPoint();
     99
     100  INITTIME;
    120101  insert_detections_mysql_init (&buffer);
    121102  int Ninsert = 0;
     
    150131
    151132      // XXX check return status
    152       if (!insert_detections_mysql_value (&buffer, &average[i], &measure[Nmeas])) {
     133      Detections detection;
     134      assign_detection_values (&detection, &measure[Nmeas], &average[i]);
     135
     136      if (!insert_detections_mysql_detvalue (&buffer, &detection)) {
    153137        fprintf (stderr, "failure to insert detections in mysql\n");
    154138        status = FALSE;
     
    201185  }
    202186
    203   // PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, photcode, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
    204   PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
    205 
    206   return TRUE;
    207 }
    208 
    209 # define PRINT_FLOAT(BUFFER,FIELD,FORMAT)                 \
    210   if (isinf(FIELD) || isnan(FIELD)) PrintIOBuffer (BUFFER, "NULL, ");   \
    211   else PrintIOBuffer (BUFFER, FORMAT, FIELD);
    212 
    213 int insert_detections_mysql_value (IOBuffer *buffer, Average *average, Measure *measure) {
    214 
    215   PhotCode *code = GetPhotcodebyCode(measure->photcode);
    216   PrintIOBuffer (buffer, "(%d, ", measure->imageID);      // imageID
    217   PrintIOBuffer (buffer, "%u, ", measure->detID); // ippDetectID
    218   PrintIOBuffer (buffer, "%lu, ", measure->extID);        // detectID
    219   PrintIOBuffer (buffer, "%lu, ", ((uint64_t)average->catID * 1000000000) + (uint64_t)average->objID);    // ippObjID
    220   // NOTE: the following is better, but the above is the current ippToPsps value
    221   // ((uint64_t)average->catID << 32) + (uint64_t)average->objID, // ippObjID
    222   PrintIOBuffer (buffer, "%lu, ", average->extID);        // objID
    223   // XXX PrintIOBuffer (buffer, "%d, ", measure->photcode);       // photcode
    224   PrintIOBuffer (buffer, "%u, ", measure->dbFlags);       // flags
    225 
    226   float zp = code->C * 0.001 + code->K * (measure->airmass - 1) - measure->Mcal;
    227   float exptime = pow(10.0, 0.4 * measure->dt);
    228   double ra  = average->R - measure->dR / 3600.0;
    229   double dec = average->D - measure->dD / 3600.0;
    230   double dR = measure->dXccd * 0.01 * fabs(measure->pltscale);
    231   double dD = measure->dYccd * 0.01 * fabs(measure->pltscale);
    232 
    233   PRINT_FLOAT(buffer, zp,               "%.6f, ");
    234   PRINT_FLOAT(buffer, measure->dMcal,   "%.6f, ");
    235   PRINT_FLOAT(buffer, measure->airmass, "%.6f, ");
    236   PRINT_FLOAT(buffer, exptime,          "%.6f, ");
    237   PRINT_FLOAT(buffer, ra,               "%.8f, ");
    238   PRINT_FLOAT(buffer, dec,              "%.8f, ");
    239   PRINT_FLOAT(buffer, dR,               "%.6f, ");
    240   PRINT_FLOAT(buffer, dD,               "%.6f),\n");
    241  
    242   return TRUE;
    243 }
    244    
     187  PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (objID, detectID, ippObjID, ippDetectID, imageID, catID, ");
     188  PrintIOBuffer (buffer, "ra, dec_, raErr, decErr, zp, telluricExt, airmass, expTime, ");
     189  PrintIOBuffer (buffer, "Mpsf, dMpsf, Mkron, dMkron, Map, dMap, flags) VALUES \n");
     190
     191  return TRUE;
     192}
     193
    245194int insert_detections_mysql_commit (IOBuffer *buffer, MYSQL *mysql) {
    246195
     
    261210  // XXX check return status
    262211  if (mysql) {
    263     if (DEBUG) fprintf (stderr, "%s\n", buffer->buffer);
    264212    int mysqlStatus = mysql_query(mysql, buffer->buffer);
    265213    if (mysqlStatus) {
     
    267215      fprintf (stderr, "%s\n", mysql_error(mysql));
    268216      fprintf (stderr, "Nbuffer: %d\n", buffer->Nbuffer);
     217      if (DEBUG) fprintf (stderr, "%s\n", buffer->buffer);
    269218      status = FALSE;
    270219    }
     
    277226  return status;
    278227}
     228
     229# define PRINT_FLOAT(BUFFER,FIELD,FORMAT)                 \
     230  if (!isfinite(FIELD)) PrintIOBuffer (BUFFER, "NULL, "); \
     231  else PrintIOBuffer (BUFFER, FORMAT, FIELD);
     232
     233int insert_detections_mysql_detvalue (IOBuffer *buffer, Detections *detection) {
     234
     235  if (detection->detectID == 164458937060000101) {
     236    fprintf (stderr, "isfinite: %d\n", isfinite(detection->dMpsf));
     237    fprintf (stderr, "isnan: %d\n", isnan(detection->dMpsf));
     238    fprintf (stderr, "isinf: %d\n", isinf(detection->dMpsf));
     239  }
     240
     241  PrintIOBuffer (buffer, "(%lu, ", detection->objID);       // objID
     242  PrintIOBuffer (buffer,  "%lu, ", detection->detectID);    // detectID
     243  PrintIOBuffer (buffer,  "%lu, ", detection->ippObjID);    // ippObjID
     244  PrintIOBuffer (buffer,  "%u,  ", detection->ippDetectID); // ippDetectID
     245  PrintIOBuffer (buffer,  "%d,  ", detection->imageID);     // imageID
     246  PrintIOBuffer (buffer,  "%d,  ", detection->catID);       // DVO Catalog ID
     247
     248  PRINT_FLOAT(buffer, detection->ra,          "%.8f, ");
     249  PRINT_FLOAT(buffer, detection->dec,         "%.8f, ");
     250  PRINT_FLOAT(buffer, detection->raErr,       "%.6f, ");
     251  PRINT_FLOAT(buffer, detection->decErr,      "%.6f, ");
     252  PRINT_FLOAT(buffer, detection->zp,          "%.6f, ");
     253  PRINT_FLOAT(buffer, detection->telluricExt, "%.6f, ");
     254  PRINT_FLOAT(buffer, detection->airmass,     "%.6f, ");
     255  PRINT_FLOAT(buffer, detection->expTime,     "%.6f, ");
     256
     257  PRINT_FLOAT(buffer, detection->Mpsf,        "%.6f, ");
     258  PRINT_FLOAT(buffer, detection->dMpsf,       "%.6f, ");
     259  PRINT_FLOAT(buffer, detection->Mkron,       "%.6f, ");
     260  PRINT_FLOAT(buffer, detection->dMkron,      "%.6f, ");
     261  PRINT_FLOAT(buffer, detection->Map,         "%.6f, ");
     262  PRINT_FLOAT(buffer, detection->dMap,        "%.6f, ");
     263
     264  PrintIOBuffer (buffer, "%u),\n", detection->flags);     // flags
     265  return TRUE;
     266}
     267
     268float getMagFromValueOrFlux (float flux, float mag, float zp) {
     269
     270  // first, if mag is finite, use mag:
     271  if (isfinite(mag)) {
     272    return (zp + mag - ZeroPoint);
     273  }
     274
     275  if (isfinite(flux) && (flux > 0.0)) {
     276    // fprintf (stderr, "funny flux: %f with mag %f\n", flux, mag);
     277    return (zp - 2.5*log10(flux));
     278  }
     279
     280  if (isfinite(flux) && (flux <= 0.0)) {
     281    return (NAN);
     282  }
     283  return (NAN);
     284}
     285
     286float getdMagFromValueOrFlux (float flux, float dflux, float dmag) {
     287
     288  // first, if mag is finite, use mag:
     289  if (isfinite(dmag)) {
     290    return (dmag);
     291  }
     292
     293  if (isfinite(flux) && isfinite(dflux)) {
     294    return (dflux / fabs(flux));
     295  }
     296  return (NAN);
     297}
     298
     299int assign_detection_values (Detections *detection, Measure *measure, Average *average) {
     300
     301  PhotCode *code = GetPhotcodebyCode(measure->photcode);
     302
     303  uint64_t ippObjID = ((uint64_t)average->catID << 32) + (uint64_t)average->objID; // ippObjID
     304
     305  float nominalZP   = code->C * 0.001 + code->K * (measure->airmass - 1);
     306  float zp          = nominalZP - measure->Mcal;
     307  float telluricExt = - measure->Mcal;
     308  float expTime     = pow(10.0, 0.4 * measure->dt);
     309  float airmass     = measure->airmass;
     310
     311  detection->objID        = average->extID;   // objID
     312  detection->detectID     = measure->extID;   // detectID
     313  detection->ippObjID     = ippObjID;         // ippObjID
     314  detection->ippDetectID  = measure->detID;   // ippDetectID
     315  detection->imageID      = measure->imageID; // imageID
     316  detection->catID        = measure->catID;   // catID
     317
     318  detection->ra           = measure->R;    // ra
     319  detection->dec          = measure->D;    // dec
     320  detection->raErr        = measure->dXccd * 0.01 * fabs(measure->pltscale); // estimate of raErr
     321  detection->decErr       = measure->dYccd * 0.01 * fabs(measure->pltscale); // estimate of decErr
     322
     323  detection->zp           = zp;
     324  detection->telluricExt  = telluricExt;
     325  detection->airmass      = airmass;
     326  detection->expTime      = expTime;
     327
     328  // XXX clean this up with dvo_photcode_ops calls:
     329  // if (isfinite(measure->FluxPSF) && (measure->FluxPSF < 0.0))
     330  detection->Mpsf  = getMagFromValueOrFlux (measure->FluxPSF,  measure->M,     zp);
     331  detection->Mkron = getMagFromValueOrFlux (measure->FluxKron, measure->Mkron, zp);
     332  detection->Map   = getMagFromValueOrFlux (measure->FluxAp,   measure->Map,   zp);
     333
     334  detection->dMpsf  = getdMagFromValueOrFlux (measure->FluxPSF,  measure->dFluxPSF,  measure->dM);
     335  detection->dMkron = getdMagFromValueOrFlux (measure->FluxKron, measure->dFluxKron, measure->dMkron);
     336  detection->dMap   = getdMagFromValueOrFlux (measure->FluxAp,   measure->dFluxAp,   measure->dMap);
     337
     338  detection->flags  = measure->dbFlags;  // flags
     339
     340  return TRUE;
     341}
     342
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvopsps/src/insert_objects_dvopsps.c

    r35098 r37403  
    5656    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    5757
    58     if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
     58    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "r")) {
    5959      fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename);
    6060      exit (1);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvopsps/src/insert_objects_dvopsps_catalog.c

    r35450 r37403  
    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;
     
    9588  bzero (buffer.buffer, buffer.Nalloc);
    9689
     90  // Only send the necessary fields (eg, do not sent parallax and pm)
    9791  PrintIOBuffer (&buffer, "CREATE TABLE %s_cpt ("
    98                  "RA DOUBLE,  "         
    99                  "DEC_ DOUBLE,  "         
    100                  "RA_ERR FLOAT,  "     
    101                  "DEC_ERR FLOAT,  "     
    102                  "U_RA FLOAT,  "       
    103                  "U_DEC FLOAT,  "       
    104                  "V_RA_ERR FLOAT,  "   
    105                  "V_DEC_ERR FLOAT,  "   
    106                  "PAR FLOAT,  "         
    107                  "PAR_ERR FLOAT,  "     
    108                  "CHISQ_POS FLOAT,  "   
    109                  "CHISQ_PM FLOAT,  "   
    110                  "CHISQ_PAP FLOAT,  "   
    111                  "MEAN_EPOCH INT,  " 
    112                  "TIME_RANGE INT,  " 
    113                  "PSF_QF FLOAT, "     
    114                  "PSF_QF_PERF FLOAT,  "
    115                  "STARGAL_SEP FLOAT,  "
    116                  "NUMBER_POS SMALLINT,  " 
    117                  "NMEASURE SMALLINT,  "   
    118                  "NMISSING SMALLINT,  "   
    119                  "NEXTEND SMALLINT,  "     
    120                  "OFF_MEASURE INT,  "
    121                  "OFF_MISSING INT,  "
    122                  "OFF_EXTEND INT,  " 
    123                  "FLAGS INT,  "       
    124                  "PHOTFLAGS_U INT,  "
    125                  "PHOTFLAGS_L INT,  "
    126                  "OBJ_ID INT,  "     
    127                  "CAT_ID INT,  "     
    128                  "EXT_ID BIGINT"
     92                 "EXT_ID        BIGINT,   "
     93                 "OBJ_ID        INT,      "     
     94                 "CAT_ID        INT,      "
     95                 "TESS_ID       TINYINT,  "
     96                 "PROJECTION_ID SMALLINT, "
     97                 "SKYCELL_ID    TINYINT,  "
     98                 "RA_STK        DOUBLE,   "         
     99                 "DEC_STK       DOUBLE,   "         
     100                 "RA_STK_ERR    FLOAT,    "     
     101                 "DEC_STK_ERR   FLOAT,    "     
     102                 "RA_MEAN       DOUBLE,   "         
     103                 "DEC_MEAN      DOUBLE,   "         
     104                 "RA_ERR        FLOAT,    "     
     105                 "DEC_ERR       FLOAT,    "     
     106                 "CHISQ_POS     FLOAT,    "   
     107                 "CHISQ_PM      FLOAT,    "   
     108                 "CHISQ_PAR     FLOAT,    "   
     109                 "FLAGS         INT       "       
    129110                 ")\n", basename);
     111
     112// skipping these cpt fields:
     113//               "U_RA        FLOAT,  "       
     114//               "U_DEC       FLOAT,  "       
     115//               "V_RA_ERR    FLOAT,  "   
     116//               "V_DEC_ERR   FLOAT,  "   
     117//               "PAR         FLOAT,  "         
     118//               "PAR_ERR     FLOAT,  "     
     119//               "OFF_MEASURE INT,  "
     120//               "OFF_MISSING INT,  "
     121//               "OFF_EXTEND  INT,  " 
     122//               "PSF_QF      FLOAT, "     
     123//               "PSF_QF_PERF FLOAT,  "
     124//               "STARGAL_SEP FLOAT,  "
     125//               "NUMBER_POS  SMALLINT,  " 
     126//               "NMEASURE    SMALLINT,  "   
     127//               "NMISSING    SMALLINT,  "   
     128//               "NEXTEND     SMALLINT,  "     
     129//               "PHOTFLAGS_U INT,  "
     130//               "PHOTFLAGS_L INT,  "
     131
     132
    130133
    131134  if (DEBUG) fprintf (stderr, "%s\n", buffer.buffer);
     
    152155
    153156  PrintIOBuffer (&buffer, "CREATE TABLE %s_cps ("
    154                  "MAG FLOAT,  "             
    155                  "MAG_AP FLOAT,  "             
    156                  "MAG_KRON FLOAT,  "       
    157                  "MAG_KRON_ERR FLOAT,  "   
    158                  "MAG_ERR FLOAT,  "         
    159                  "MAG_CHI FLOAT,  "         
    160                  "STACK_PSF_MAG FLOAT,  "       
    161                  "STACK_PSF_MAG_ERR FLOAT,  "   
    162                  "STACK_KRON_MAG FLOAT,  "      
    163                  "STACK_KRON_MAG_ERR FLOAT,  "   
    164                  "FLAGS INT,  "           
    165                  "NCODE SMALLINT,  "           
    166                  "NUSED SMALLINT,  "           
    167                  "MAG_20 SMALLINT,  "         
    168                  "MAG_80 SMALLINT,  "         
    169                  "UBERCAL_DIST SMALLINT,  "   
    170                  "MAG_STDEV SMALLINT,  "       
    171                  "STACK_DETECT_ID BIGINT"
     157                 "MAG            FLOAT,  "             
     158                 "MAG_ERR        FLOAT,  "         
     159                 "MAG_STDEV      FLOAT,  "        
     160                 "MAG_MIN        FLOAT,  "        
     161                 "MAG_MAX        FLOAT,  "         
     162                 "NUSED          SMALLINT,  "           
     163                 "MAG_KRON      FLOAT,  "       
     164                 "MAG_KRON_ERR  FLOAT,  "   
     165                 "MAG_KRON_STDEV FLOAT,  "   
     166                 "NUSED_KRON     SMALLINT,  "    
     167                 "MAG_AP         FLOAT,  "             
     168                 "MAG_AP_ERR     FLOAT,  "             
     169                 "MAG_AP_STDEV   FLOAT,  "             
     170                 "NUSED_AP       SMALLINT,  "   
     171                 "NCODE          SMALLINT,  "          
     172                 "NSTACK_DET     SMALLINT,  "          
     173                 "PSF_QF_PERF_MAX FLOAT, "           
     174                 "FLAGS          INT "         
    172175                 ")\n", basename);
    173 
    174  //              "FLUX_PSF FLOAT,  "       
    175  //              "FLUX_PSF_ERR FLOAT,  "   
    176  //              "FLUX_KRON FLOAT,  "       
    177  //              "FLUX_KRON_ERR FLOAT,  "   
    178176
    179177  if (DEBUG) fprintf (stderr, "%s\n", buffer.buffer);
     
    198196
    199197  PrintIOBuffer (ave_buffer, "INSERT INTO %s_cpt ("
    200                  "RA, "         
    201                  "DEC_, "         
    202                  "RA_ERR, "     
    203                  "DEC_ERR, "     
    204                  "U_RA, "       
    205                  "U_DEC, "       
    206                  "V_RA_ERR, "   
    207                  "V_DEC_ERR, "   
    208                  "PAR, "         
    209                  "PAR_ERR, "     
    210                  "CHISQ_POS, "   
    211                  "CHISQ_PM, "   
    212                  "CHISQ_PAP, "   
    213                  "MEAN_EPOCH, " 
    214                  "TIME_RANGE, " 
    215                  "PSF_QF, "     
    216                  "PSF_QF_PERF, "
    217                  "STARGAL_SEP, "
    218                  "NUMBER_POS, " 
    219                  "NMEASURE, "   
    220                  "NMISSING, "   
    221                  "NEXTEND, "     
    222                  "OFF_MEASURE, "
    223                  "OFF_MISSING, "
    224                  "OFF_EXTEND, " 
    225                  "FLAGS, "       
    226                  "PHOTFLAGS_U, "
    227                  "PHOTFLAGS_L, "
    228                  "OBJ_ID, "     
    229                  "CAT_ID, "     
    230                  "EXT_ID"
     198                 "EXT_ID,        "
     199                 "OBJ_ID,        "     
     200                 "CAT_ID,        "     
     201                 "TESS_ID,       "     
     202                 "PROJECTION_ID, "     
     203                 "SKYCELL_ID,    "     
     204                 "RA_STK,        "         
     205                 "DEC_STK,       "         
     206                 "RA_STK_ERR,    "     
     207                 "DEC_STK_ERR,   "     
     208                 "RA_MEAN,       "         
     209                 "DEC_MEAN,      "         
     210                 "RA_ERR,        "     
     211                 "DEC_ERR,       "     
     212                 "CHISQ_POS,     "   
     213                 "CHISQ_PM,      "   
     214                 "CHISQ_PAR,     "   
     215                 "FLAGS          "       
    231216                 ") VALUES \n", basename);
    232217
     
    237222  PrintIOBuffer (sec_buffer, "INSERT INTO %s_cps ("
    238223                 "MAG, "             
    239                  "MAG_AP, "             
     224                 "MAG_ERR, "         
     225                 "MAG_STDEV, "       
     226                 "MAG_MIN, "         
     227                 "MAG_MAX, "         
     228                 "NUSED, "           
     229
    240230                 "MAG_KRON, "       
    241231                 "MAG_KRON_ERR, "   
    242                  "MAG_ERR, "         
    243                  "MAG_CHI, "         
    244                  "STACK_PSF_MAG, "       
    245                  "STACK_PSF_MAG_ERR, "   
    246                  "STACK_KRON_MAG, "       
    247                  "STACK_KRON_MAG_ERR, "   
    248                  "FLAGS, "           
     232                 "MAG_KRON_STDEV, "   
     233                 "NUSED_KRON, "           
     234
     235                 "MAG_AP, "             
     236                 "MAG_AP_ERR, "             
     237                 "MAG_AP_STDEV, "             
     238                 "NUSED_AP, "           
     239
    249240                 "NCODE, "           
    250                  "NUSED, "           
    251                  "MAG_20, "         
    252                  "MAG_80, "         
    253                  "UBERCAL_DIST, "   
    254                  "MAG_STDEV, "       
    255                  "STACK_DETECT_ID "
     241                 "NSTACK_DET,  "           
     242                 "PSF_QF_PERF_MAX, "           
     243                 "FLAGS "           
    256244                 ") VALUES \n", basename);
    257245  return TRUE;
     
    268256// XXX this bit could/should be autocoded...
    269257  PrintIOBuffer (ave_buffer, " (");
     258  PrintIOBuffer (ave_buffer, "%lu, ", average->extID);         
     259  PrintIOBuffer (ave_buffer, "%u,  ", average->objID);         
     260  PrintIOBuffer (ave_buffer, "%u,  ", average->catID);         
     261
     262  PrintIOBuffer (ave_buffer, "%hhd, ", average->tessID);         
     263  PrintIOBuffer (ave_buffer, "%hd,  ", average->projectionID);         
     264  PrintIOBuffer (ave_buffer, "%hhd, ", average->skycellID);         
     265
     266  PRINT_FLOAT(ave_buffer, average->Rstk,     "%.8f, ");  // 0.036 mas precision
     267  PRINT_FLOAT(ave_buffer, average->Dstk,     "%.8f, ");  // 0.036 mas precision
     268  PRINT_FLOAT(ave_buffer, average->dRstk,    "%.5f, ");  // 0.010 mas precision
     269  PRINT_FLOAT(ave_buffer, average->dDstk,    "%.5f, ");  // 0.010 mas precision
     270
    270271  PRINT_FLOAT(ave_buffer, average->R,        "%.8f, ");  // 0.036 mas precision
    271272  PRINT_FLOAT(ave_buffer, average->D,        "%.8f, ");  // 0.036 mas precision
    272273  PRINT_FLOAT(ave_buffer, average->dR,       "%.5f, ");  // 0.010 mas precision
    273274  PRINT_FLOAT(ave_buffer, average->dD,       "%.5f, ");  // 0.010 mas precision
    274   PRINT_FLOAT(ave_buffer, average->uR,       "%.5f, ");  // 0.010 mas/yr precision
    275   PRINT_FLOAT(ave_buffer, average->uD,       "%.5f, ");
    276   PRINT_FLOAT(ave_buffer, average->duR,      "%.5f, ");
    277   PRINT_FLOAT(ave_buffer, average->duD,      "%.5f, ");
    278   PRINT_FLOAT(ave_buffer, average->P,        "%.5f, ");
    279   PRINT_FLOAT(ave_buffer, average->dP,       "%.5f, ");
     275
    280276  PRINT_FLOAT(ave_buffer, average->ChiSqAve, "%.4f, ");
    281277  PRINT_FLOAT(ave_buffer, average->ChiSqPM,  "%.4f, ");
    282278  PRINT_FLOAT(ave_buffer, average->ChiSqPar, "%.4f, ");
    283   PrintIOBuffer (ave_buffer, "%d, ",  average->Tmean);         
    284   PrintIOBuffer (ave_buffer, "%d, ",  average->Trange);         
    285   PRINT_FLOAT(ave_buffer, average->psfQF,     "%.3f, ");
    286   PRINT_FLOAT(ave_buffer, average->psfQFperf, "%.3f, ");
    287   PRINT_FLOAT(ave_buffer, average->stargal,   "%.3f, ");
    288   PrintIOBuffer (ave_buffer, "%hu, ", average->Npos);           
    289   PrintIOBuffer (ave_buffer, "%hu, ", average->Nmeasure);       
    290   PrintIOBuffer (ave_buffer, "%hu, ", average->Nmissing);       
    291   PrintIOBuffer (ave_buffer, "%hu, ", average->Nextend);       
    292   PrintIOBuffer (ave_buffer, "%d, ",  average->measureOffset); 
    293   PrintIOBuffer (ave_buffer, "%d, ",  average->missingOffset); 
    294   PrintIOBuffer (ave_buffer, "%d, ",  average->extendOffset);   
    295   PrintIOBuffer (ave_buffer, "%u, ",  average->flags);         
    296   PrintIOBuffer (ave_buffer, "%u, ",  average->photFlagsUpper);
    297   PrintIOBuffer (ave_buffer, "%u, ",  average->photFlagsLower);
    298   PrintIOBuffer (ave_buffer, "%u, ",  average->objID);         
    299   PrintIOBuffer (ave_buffer, "%u, ",  average->catID);         
    300   PrintIOBuffer (ave_buffer, "%lu",   average->extID);         
     279
     280  PrintIOBuffer (ave_buffer, "%u ",  average->flags);         
     281
    301282  PrintIOBuffer (ave_buffer, "),\n");
    302283
     284  // XXX what rules for keeping or NAN-ing various mags?
    303285  for (i = 0; i < Nsecfilt; i++) {
    304286    float meanPSFMag    = -999.0;
    305287    float meanPSFMagErr = -999.0;
     288    float meanPSFMagStd = -999.0;
     289    float meanPSFMagMin = -999.0;
     290    float meanPSFMagMax = -999.0;
    306291    if (isfinite(secfilt->dM) && isfinite(secfilt->M)) {
    307       meanPSFMag = secfilt->M;
     292      meanPSFMag    = secfilt->M;
    308293      meanPSFMagErr = secfilt->dM;
     294      meanPSFMagStd = secfilt->Mstdev;
     295      meanPSFMagMin = secfilt->Mmin;
     296      meanPSFMagMax = secfilt->Mmax;
    309297    }
    310298
    311299    float meanKronMag    = -999.0;
    312300    float meanKronMagErr = -999.0;
     301    float meanKronMagStd = -999.0;
    313302    if (isfinite(secfilt->dMkron) && isfinite(secfilt->Mkron) && (secfilt->dMkron < 0.333)) {
    314       meanKronMag = secfilt->Mkron;
     303      meanKronMag    = secfilt->Mkron;
    315304      meanKronMagErr = secfilt->dMkron;
     305      meanKronMagStd = secfilt->sMkron;
    316306    }
    317307
    318308    float meanApMag    = -999.0;
    319     if (isfinite(secfilt->Map)) {
    320       meanApMag = secfilt->Map;
    321     }
    322 
    323     float stackPSFMag    = -999.0;
    324     float stackPSFMagErr = -999.0;
    325     if (isfinite(secfilt->dFluxPSF) && isfinite(secfilt->FluxPSF) && (secfilt->dFluxPSF > 0.0)) {
    326       float SN = secfilt->FluxPSF / secfilt->dFluxPSF;
    327       if (SN > 3.0) {
    328         stackPSFMag = -2.5 * log10(secfilt->FluxPSF) + 8.9;
    329         stackPSFMagErr = secfilt->dFluxPSF / secfilt->FluxPSF;
    330       }
    331     }
    332 
    333     float stackKronMag    = -999.0;
    334     float stackKronMagErr = -999.0;
    335     if (isfinite(secfilt->dFluxKron) && isfinite(secfilt->FluxKron) && (secfilt->dFluxKron > 0.0)) {
    336       float SN = secfilt->FluxKron / secfilt->dFluxKron;
    337       if (SN > 3.0) {
    338         stackKronMag = -2.5 * log10(secfilt->FluxKron) + 8.9;
    339         stackKronMagErr = secfilt->dFluxKron / secfilt->FluxKron;
    340       }
     309    float meanApMagErr = -999.0;
     310    float meanApMagStd = -999.0;
     311    if (isfinite(secfilt->dMap) && isfinite(secfilt->Map)) {
     312      meanApMag    = secfilt->Map;
     313      meanApMagErr = secfilt->dMap;
     314      meanApMagStd = secfilt->sMap;
    341315    }
    342316
    343317    PrintIOBuffer (sec_buffer, " (");
    344318    PRINT_FLOAT(sec_buffer, meanPSFMag,      "%.6f, "); // umag precision
    345     PRINT_FLOAT(sec_buffer, meanApMag,       "%.6f, "); // umag precision
     319    PRINT_FLOAT(sec_buffer, meanPSFMagErr,   "%.6f, "); // umag precision
     320    PRINT_FLOAT(sec_buffer, meanPSFMagStd,   "%.6f, "); // umag precision
     321    PRINT_FLOAT(sec_buffer, meanPSFMagMin,   "%.6f, "); // umag precision
     322    PRINT_FLOAT(sec_buffer, meanPSFMagMax,   "%.6f, "); // umag precision
     323    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->Nused);       
     324
    346325    PRINT_FLOAT(sec_buffer, meanKronMag,     "%.6f, "); // umag precision
    347326    PRINT_FLOAT(sec_buffer, meanKronMagErr,  "%.6f, "); // umag precision
    348     PRINT_FLOAT(sec_buffer, meanPSFMagErr,   "%.6f, "); // umag precision
    349     PRINT_FLOAT(sec_buffer, secfilt->Xm,     "%.6f, ");
    350     PRINT_FLOAT(sec_buffer, stackPSFMag,     "%.6f, "); // umag precision
    351     PRINT_FLOAT(sec_buffer, stackPSFMagErr,  "%.6f, "); // umag precision
    352     PRINT_FLOAT(sec_buffer, stackKronMag,    "%.6f, "); // umag precision
    353     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);         
    359     PrintIOBuffer (sec_buffer, "%hd, ", secfilt->ubercalDist); 
    360     PrintIOBuffer (sec_buffer, "%hd, ", secfilt->Mstdev);       
    361     PrintIOBuffer (sec_buffer, "%lu  ", secfilt->stackDetectID);
     327    PRINT_FLOAT(sec_buffer, meanKronMagStd,  "%.6f, "); // umag precision
     328    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->NusedKron);       
     329
     330    PRINT_FLOAT(sec_buffer, meanApMag,     "%.6f, "); // umag precision
     331    PRINT_FLOAT(sec_buffer, meanApMagErr,  "%.6f, "); // umag precision
     332    PRINT_FLOAT(sec_buffer, meanApMagStd,  "%.6f, "); // umag precision
     333    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->NusedAp);       
     334    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->Ncode);       
     335    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->NstackDet);       
     336
     337    PRINT_FLOAT(sec_buffer, secfilt->psfQfPerfMax, "%.6f,");       
     338    PrintIOBuffer (sec_buffer, "%u ", secfilt->flags);       
    362339    PrintIOBuffer (sec_buffer, "),\n");
    363340    secfilt ++;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvopsps/src/insert_skytable.c

    r35098 r37403  
    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/ps2-tc3-20130727/Ohana/src/dvosplit/src/dvosplit.c

    r33963 r37403  
    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/ps2-tc3-20130727/Ohana/src/dvosplit/src/split_averages.c

    r33656 r37403  
    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/ps2-tc3-20130727/Ohana/src/dvosplit/src/split_measures.c

    r33656 r37403  
    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/ps2-tc3-20130727/Ohana/src/gastro2/src/gstars2.c

    r36680 r37403  
    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/ps2-tc3-20130727/Ohana/src/getstar

  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/getstar/src/GetFileMode.c

    r36680 r37403  
    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);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/getstar/src/ReadImageFiles.c

    r34088 r37403  
    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/ps2-tc3-20130727/Ohana/src/getstar/src/getstar.c

    r31669 r37403  
    1414  set_db (&db);
    1515
    16   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
     16  sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, FALSE, SKY_DEPTH, VERBOSE);
    1717  if (!sky) exit (1);
    1818   
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/getstar/src/select_by_region.c

    r35066 r37403  
    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/ps2-tc3-20130727/Ohana/src/getstar/src/write_getstar_ps1_dev_0.c

    r21508 r37403  
    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/ps2-tc3-20130727/Ohana/src/getstar/src/write_getstar_ps1_dev_1.c

    r21508 r37403  
    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/ps2-tc3-20130727/Ohana/src/getstar/src/write_getstar_ps1_dev_2.c

    r21508 r37403  
    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/ps2-tc3-20130727/Ohana/src/kapa2/src/CheckPipe.c

    r29938 r37403  
    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/ps2-tc3-20130727/Ohana/src/kapa2/src/DrawObjects.c

    r35416 r37403  
    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/ps2-tc3-20130727/Ohana/src/kapa2/src/EventLoop.c

    r21153 r37403  
    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/ps2-tc3-20130727/Ohana/src/kapa2/src/FlushDisplay.c

    r21153 r37403  
    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/ps2-tc3-20130727/Ohana/src/kapa2/src/Refresh.c

    r27790 r37403  
    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/ps2-tc3-20130727/Ohana/src/kapa2/src/bDrawObjects.c

    r36680 r37403  
    540540        FillCircle (buffer, sx, sy, D);
    541541        // 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
    542564      }
    543565    }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libautocode/Makefile.Targets

    r34405 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/average-ps1-dev-2.d

    r16810 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/average-ps1-v1.d

    r21508 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/average-ps1-v2.d

    r33647 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/average-ps1-v3.d

    r33647 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/average-ps1-v4.d

    r34405 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/average.d

    r34405 r37403  
    22EXTNAME      DVO_AVERAGE
    33TYPE         BINTABLE
    4 SIZE         128
     4SIZE         192
    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
     54
     55FIELD tessID,         TESS_ID,       char,          ID of tessellation for primary skycell
     56FIELD skycellID,      SKYCELL_ID,    char,          ID of skycell for primary skycell
     57FIELD projectionID,   PROJECTION_ID, short,         ID of projection for primary skycell
     58
     59FIELD dummy,          DUMMY,         int,           unassigned bytes
    4160
    4261# 'flags' was called 'code' prior to 2009.02.07
     
    4968FIELD catID,          CAT_ID,      unsigned int,    unique ID for table in which object was first realized
    5069FIELD extID,          EXT_ID,      uint64_t,        external ID for object (eg PSPS objID)
     70FIELD extIDgc,        EXT_ID_GC,   uint64_t,        external ID for object in galactic coords
    5171
    5272# this structure should only be used for internal representations
     
    5676
    5777# *** 20090206 : new fields : ChiSq, Npos, flags (was code, uint16_t), extID
    58 
    5978# *** 20100331 : new fields needed to assess astrometry analysis quality:
    60 
     79# *** 20140617 : new fields : Rstk, Dstk, dRstk,dDstk, Nlensing, Nlensobj, lensingOffset, lensobjOffset, refColor
    6180
    6281# photflagsUpper & photflagsLower: we have Nmeasures of a given source
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libautocode/def/common.h

    r34088 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/image-ps1-v2.d

    r30604 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/image-ps1-v3.d

    r33647 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/image-ps1-v4.d

    r34260 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/image.d

    r33963 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/measure.d

    r35099 r37403  
    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?
     
    5666FIELD psfNdof,        PSF_NDOF,      int,            psf degrees of freedom
    5767FIELD psfNpix,        PSF_NPIX,      int,            psf number of pixels
    58 FIELD crNsigma,       CR_NSIGMA,     float,          Nsigma deviation towards CR
     68FIELD photFlags2,     PHOT_FLAGS,    int,            flags supplied by photometry program
    5969FIELD extNsigma,      EXT_NSIGMA,    float,          Nsigma deviation towards EXT
    6070
     
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/photcode-ps1-v2.d

    r27579 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/photcode-ps1-v3.d

    r33647 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/photcode-ps1-v4.d

    r34260 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/photcode.d

    r33647 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/secfilt-ps1-v1.d

    r21508 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/secfilt-ps1-v2.d

    r27579 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/secfilt-ps1-v3.d

    r33963 r37403  
    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/ps2-tc3-20130727/Ohana/src/libautocode/def/secfilt-ps1-v4.d

    r34620 r37403  
    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
     
    2323FIELD  ubercalDist,   UBERCAL_DIST,    short,      number of images from an ubercal-image
    2424FIELD  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)
     25FIELD  stackPrmryOff, STACK_PRIMARY_OFF, int,      measure entry which is primary stack detection
     26FIELD  stackBestOff,  STACK_BEST_OFF,    int,      measure entry which is best stack detection
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libautocode/def/secfilt.d

    r35099 r37403  
    22EXTNAME      DVO_SECFILT
    33TYPE         BINTABLE
    4 SIZE         64
     4SIZE         176
    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
     15FIELD  sMkron,        MAG_KRON_STDEV,  float,      standard deviation of kron mags,       mags
     16
     17# XXX I could add these fields to secfilt or calculate in dvopsps?
     18FIELD  psfQfMax,      PSF_QF_MAX,      float,      best psfQf for this filter
     19FIELD  psfQfPerfMax,  PSF_QF_PERF_MAX, float,      best psfQfPerfect for this filter
     20
     21# these statistics are PSF-specific     
     22FIELD  Mstdev,        MAG_STDEV,       float,      standard deviation of measurements,    mags
     23FIELD  Mmin,          MAG_MIN,         float,      minimum accepted mag,                  mags
     24FIELD  Mmax,          MAG_MAX,         float,      maximum accepted mag,                  mags
     25FIELD  Mchisq,        MAG_CHI,         float,      chisq on average mag,                  value
     26
     27FIELD  Ncode,         NCODE,           short,      number of detections in band (gpc1 chip only)
     28FIELD  Nused,         NUSED,           short,      number of detections used to calculate secfilt.M
     29FIELD  NusedKron,     NUSED_KRON,      short,      number of detections used to calculate secfilt.Mkron
     30FIELD  NusedAp,       NUSED_AP,        short,      number of detections used to calculate secfilt.Map
     31
    1832FIELD  flags,         FLAGS,           uint32_t,   photometry flags
    19 FIELD  Ncode,         NCODE,           short,      number of detections in band
    20 FIELD  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
    23 FIELD  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)
     33
     34## *** this section is for stack values ***
     35
     36FIELD  MpsfStk,       MAG_PSF_STK,       float,    magnitude from stack (primary if available)
     37FIELD  FpsfStk,       FLUX_PSF_STK,      float,    flux from stack (primary if available)
     38FIELD  dFpsfStk,      FLUX_PSF_STK_ERR,  float,    mean flux psf error
     39
     40FIELD  MkronStk,      MAG_KRON_STK,      float,    magnitude from stack (primary if available)
     41FIELD  FkronStk,      FLUX_KRON_STK,     float,    flux from stack (primary if available)
     42FIELD  dFkronStk,     FLUX_KRON_STK_ERR, float,    mean flux kron error
     43
     44FIELD  MapStk,        MAG_AP_STK,        float,    magnitude from stack (primary if available)
     45FIELD  FapStk,        FLUX_AP_STK,       float,    flux from stack (primary if available)
     46FIELD  dFapStk,       FLUX_AP_STK_ERR,   float,    mean flux ap error
     47
     48FIELD  Nstack,        NSTACK,            short,    number of measurements in band (gpc1 stack only)
     49FIELD  NstackDet,     NSTACK_DET,        short,    number of stack detections in band (gpc1 stack only)
     50
     51FIELD  stackPrmryOff, STACK_PRIMARY_OFF, int,      measure entry which is primary stack detection
     52FIELD  stackBestOff,  STACK_BEST_OFF,    int,      measure entry which is best stack detection
     53
     54## *** this section is for forced-warp mean values ***
     55
     56FIELD  MpsfWrp,       MAG_PSF_WRP,       float,    psf magnitude from stack (primary if available)
     57FIELD  FpsfWrp,       FLUX_PSF_WRP,      float,    psf flux from stack (primary if available)
     58FIELD  dFpsfWrp,      FLUX_PSF_WRP_ERR,  float,    mean flux psf error
     59FIELD  sFpsfWrp,      FLUX_PSF_WRP_STD,  float,    mean flux psf stdev
     60
     61FIELD  MkronWrp,      MAG_KRON_WRP,      float,    kron magnitude from stack (primary if available)
     62FIELD  FkronWrp,      FLUX_KRON_WRP,     float,    kron flux from stack (primary if available)
     63FIELD  dFkronWrp,     FLUX_KRON_WRP_ERR, float,    mean flux kron error
     64FIELD  sFkronWrp,     FLUX_KRON_WRP_STD, float,    mean flux kron stdev
     65
     66FIELD  MapWrp,        MAG_AP_WRP,        float,    aper magnitude from stack (primary if available)
     67FIELD  FapWrp,        FLUX_AP_WRP,       float,    aper flux from stack (primary if available)
     68FIELD  dFapWrp,       FLUX_AP_WRP_ERR,   float,    mean flux ap error
     69FIELD  sFapWrp,       FLUX_AP_WRP_STD,   float,    mean flux ap stdev
     70
     71FIELD  NusedWrp,      NUSED_WRP,         short,    number of detections used in average
     72FIELD  NusedKronWrp,  NUSED_KRON_WRP,    short,    number of detections used in average
     73FIELD  NusedApWrp,    NUSED_AP_WRP,      short,    number of detections used in average
     74
     75FIELD  Nwarp,         NWARP,             short,    number of measurements in band (gpc1 warp only)
     76FIELD  NwarpGood,     NWARP_GOOD,        short,    number of meas with psf_qf > 0.85 in band (gpc1 warp only)
     77
     78FIELD  ubercalDist,   UBERCAL_DIST,      short,    number of images from an ubercal-image
    2679
    2780# *** 20090206 : new fields : M_20, M_80; dropped dummy
    2881# *** 20120302 : new fields : ubercalDist, Map, Mstdev
    2982# *** 20120710 : new fields : Mkron, dMkron, FluxPSF, dFluxPSF, FluxKron, dFluxKron, stackID
     83
     84# *** 20140617 : added   : dMap, NusedKron, NusedAp, MpsfStk, MkronStk, MapStk, *Wrp
     85               : changed : Mstdev, M_20 (to Mmin,short:float),M_80 (to Mmax,short:float),
     86               : rename : FpsfStk, dFpsfStk, FkronStk, dFronStk (were FluxPSF, dFluxPSF, FluxKron, dFluxKron)
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/Makefile

    r36680 r37403  
    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          \
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/include/dvo.h

    r36680 r37403  
    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 */
     
    125128  ID_MEAS_BLEND_MEAS     = 0x00000100,  // detection is within radius of multiple objects
    126129  ID_MEAS_BLEND_OBJ      = 0x00000200,  // multiple detections within radius of object
    127   ID_MEAS_UNDEF_3        = 0x00000400,  // unused
     130  ID_MEAS_WARP_USED      = 0x00000400,  // measurement used to find mean warp photometry
    128131  ID_MEAS_UNDEF_4        = 0x00000800,  // unused
    129132  ID_MEAS_BLEND_MEAS_X   = 0x00001000,  // detection is within radius of multiple objects across catalogs                   
     
    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)
     
    333337// another special case : does not match byte-boundaries
    334338# include "cmf-ps1-dv3.h"
     339# include "cmf-ps1-sv3.h"
     340# include "cmf-ps1-v5.h"
     341# include "cmf-ps1-v5-lensing.h"
    335342
    336343typedef struct {
     
    376383  char  ***name; // projection cell name
    377384 
    378   int NX_SUB;
    379   int NY_SUB;
     385  float NX_SUB;
     386  float NY_SUB;
    380387  double dPix;
    381388
    382389  double **Xo;
    383390  double **Yo;
    384   int **dX;
    385   int **dY;
     391  float **dX;
     392  float **dY;
    386393} BoundaryTree;
    387394
     
    404411  double Do;
    405412  double dPix;
    406   int dX;
    407   int dY;
    408 
    409   int NX_SUB;
    410   int NY_SUB;
     413  float dX;
     414  float dY;
     415
     416  float NX_SUB;
     417  float NY_SUB;
    411418
    412419  char *basename;
     
    433440// a reduced-subset structure for relphot & relastro
    434441typedef struct {
    435   float          dR;
    436   float          dD;
     442  double         R;
     443  double         D;
    437444  float          M;
    438445  float          Mcal;
     
    457464} MeasureTiny;
    458465
    459 /** STRUCT DEFINITION **/
     466// alternate version of PS1_V4 (old dev version)
    460467typedef struct {
    461468  double           R;                    // RA (decimal degrees )
     
    481488  uint32_t         measureOffset;        // offset to first psf measurement
    482489  uint32_t         missingOffset;        // offset to first missing obs
    483   uint32_t         extendOffset;         // offset to first extended measurement
     490  float            refColor;            // offset to first extended measurement
    484491  uint32_t         flags;                // average object flags (star; ghost; etc)
    485492  uint32_t         photFlagsUpper;       // upper bit of 2 bit summary of per-measure photflags
     
    493500Average *Average_PS1_V4alt_ToInternal (Average_PS1_V4alt *in, off_t Nvalues);
    494501
    495 /** STRUCT DEFINITION **/
     502// alternate version of PS1_V4 (old dev version)
    496503typedef struct {
    497504  float            dR;                   // RA offset (arcsec)
     
    547554
    548555Measure_PS1_V4alt *gfits_table_get_Measure_PS1_V4alt (FTable *table, off_t *Ndata, char *swapped);
    549 Measure *Measure_PS1_V4alt_ToInternal (Measure_PS1_V4alt *in, off_t Nvalues);
     556Measure *Measure_PS1_V4alt_ToInternal (Average *ave, Measure_PS1_V4alt *in, off_t Nvalues);
     557
     558// alternate version of PS1_V5 (old dev version)
     559typedef struct {
     560  float            M;                    // average mag in this band (mags)
     561  float            dM;                   // formal error on average mag (mags)
     562  float            Map;                  // ave aperture mag in this band (mags)
     563  float            dMap;                 // ave aperture mag in this band (mags)
     564  float            sMap;                 // standard deviation of ap mags (mags)
     565  float            Mkron;                // ave kron mag in this band (mags)
     566  float            dMkron;               // formal error on average kron mag (mags)
     567  float            sMkron;               // standard deviation of kron mags (mags)
     568  float            Mstdev;               // standard deviation of measurements (mags)
     569  float            Mmin;                 // min accepted mag (mags)
     570  float            Mmax;                 // max accepted mag (mags)
     571  float            Mchisq;               // chisq on average mag (value)
     572  short            Ncode;                // number of detections in band
     573  short            Nused;                // number of detections used in average
     574  short            NusedKron;            // number of detections used in average
     575  short            NusedAp;              // number of detections used in average
     576  uint32_t         flags;                // photometry flags
     577  float            MpsfStk;              // magnitude from stack (primary if available)
     578  float            FpsfStk;              // flux from stack (primary if available)
     579  float            dFpsfStk;             // mean flux psf error
     580  float            MkronStk;             // magnitude from stack (primary if available)
     581  float            FkronStk;             // flux from stack (primary if available)
     582  float            dFkronStk;            // mean flux kron error
     583  float            MapStk;               // magnitude from stack (primary if available)
     584  float            FapStk;               // flux from stack (primary if available)
     585  float            dFapStk;              // mean flux ap error
     586  int              stackPrmryOff;        // measure entry which is primary stack detection
     587  int              stackBestOff;         // measure entry which is best stack detection
     588  float            MpsfWrp;              // psf magnitude from stack (primary if available)
     589  float            FpsfWrp;              // psf flux from stack (primary if available)
     590  float            dFpsfWrp;             // mean flux psf error
     591  float            sFpsfWrp;             // mean flux psf stdev
     592  float            MkronWrp;             // kron magnitude from stack (primary if available)
     593  float            FkronWrp;             // kron flux from stack (primary if available)
     594  float            dFkronWrp;            // mean flux kron error
     595  float            sFkronWrp;            // mean flux kron stdev
     596  float            MapWrp;               // aper magnitude from stack (primary if available)
     597  float            FapWrp;               // aper flux from stack (primary if available)
     598  float            dFapWrp;              // mean flux ap error
     599  float            sFapWrp;              // mean flux ap stdev
     600  short            NusedWrp;             // number of detections used in average
     601  short            NusedKronWrp;         // number of detections used in average
     602  short            NusedApWrp;           // number of detections used in average
     603  short            ubercalDist;          // number of images from an ubercal-image
     604} SecFilt_PS1_V5alt;
     605
     606SecFilt_PS1_V5alt *gfits_table_get_SecFilt_PS1_V5alt (FTable *table, off_t *Ndata, char *swapped);
     607int      gfits_convert_SecFilt_PS1_V5alt (SecFilt_PS1_V5alt *data, off_t size, off_t nitems);
     608SecFilt *SecFilt_PS1_V5alt_ToInternal (SecFilt_PS1_V5alt *in, off_t Nvalues);
     609
     610// alternate version of PS1_V5alt (old dev version)
     611typedef struct {
     612  double           R;                    // RA (decimal degrees )
     613  double           D;                    // DEC (decimal degrees )
     614  float            dR;                   // RA error (arcsec)
     615  float            dD;                   // DEC error (arcsec)
     616  float            uR;                   // RA*cos(D) proper-motion (arcsec/year)
     617  float            uD;                   // DEC proper-motion (arcsec/year)
     618  float            duR;                  // RA*cos(D) p-m error (arcsec/year)
     619  float            duD;                  // DEC p-m error (arcsec/year)
     620  float            P;                    // parallax (arcsec)
     621  float            dP;                   // parallax error (arcsec)
     622  double           Rstk;                 // RA on stack (decimal degrees )
     623  double           Dstk;                 // DEC on stack (decimal degrees )
     624  float            dRstk;                // RA error on stack (arcsec)
     625  float            dDstk;                // DEC error on stack (arcsec)
     626  float            ChiSqAve;             // astrometry analysis chisq
     627  float            ChiSqPM;              // astrometry analysis chisq
     628  float            ChiSqPar;             // astrometry analysis chisq
     629  int              Tmean;                // mean epoch (PM,PAR ref) (unix time seconds)
     630  int              Trange;               // mean epoch (PM,PAR ref) (unix time seconds)
     631  float            psfQF;                // psf coverage (bad masks)
     632  float            psfQFperf;            // psf coverage (all masks)
     633  float            stargal;              // star / galaxy separator (1/100 arcsec)
     634  unsigned short   Npos;                 // number of detections used for astrometry
     635  unsigned short   Nmeasure;             // number of psf measurements
     636  unsigned short   Nmissing;             // number of missings
     637  unsigned short   Nlensing;             // number of lensing measurements
     638  unsigned short   Nlensobj;             // number of lensing measurements
     639  unsigned short   Nextend;              // number of extended measurements
     640  int              measureOffset;        // offset to first psf measurement
     641  int              missingOffset;        // offset to first missing obs
     642  int              lensingOffset;        // offset to first lensing obs
     643  int              lensobjOffset;        // offset to mean lensing data
     644  int              extendOffset;         // offset to extended object entry
     645  int              paramsOffset;         // offset to stellar parameter data
     646  float            refColorBlue;         // color of astrometry ref stars
     647  float            refColorRed;          // color of astrometry ref stars
     648  uint32_t         flags;                // average object flags (star; ghost; etc)
     649  uint32_t         photFlagsUpper;       // upper bit of 2 bit summary of per-measure photflags
     650  uint32_t         photFlagsLower;       // lower bit of 2 bit summary of per-measure photflags
     651  unsigned int     objID;                // unique ID for object in table
     652  unsigned int     catID;                // unique ID for table in which object was first realized
     653  uint64_t         extID;                // external ID for object (eg PSPS objID)
     654  uint64_t         extIDgc;              // external ID for object in galactic coords
     655} Average_PS1_V5alt;
     656
     657Average_PS1_V5alt *gfits_table_get_Average_PS1_V5alt (FTable *table, off_t *Ndata, char *swapped);
     658int      gfits_convert_Average_PS1_V5alt (Average_PS1_V5alt *data, off_t size, off_t nitems);
     659Average *Average_PS1_V5alt_ToInternal (Average_PS1_V5alt *in, off_t Nvalues);
     660
     661/* for some reason I have merged the set of tables and the file description,
     662   so I need to have an internal structure to point to the separate files */
    550663
    551664/* a catalog contains this data */
     
    561674  SecFilt *secfilt;
    562675
     676  // lensing data (optional?)
     677  Lensing *lensing;
     678  Lensobj *lensobj;
     679
    563680  int Nsecfilt;  /* number of secfilt entries for each average entry */
    564   off_t Naverage,   Nmeasure,   Nmissing,   Nsecf_mem;  /* current number of each component in memory */
    565   off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nsecf_disk; /* current number of each component on disk */
    566   off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nsecf_off;  /* index of first loaded data value */
     681  off_t Naverage,   Nmeasure,   Nmissing,   Nlensing,      Nlensobj,      Nsecf_mem;  /* current number of each component in memory */
     682  off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nlensing_disk, Nlensobj_disk, Nsecf_disk; /* current number of each component on disk */
     683  off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nlensing_off,  Nlensobj_off,  Nsecf_off;  /* index of first loaded data value */
    567684
    568685  // note that we use these for the full-sky relphot analysis
     
    583700  struct Catalog *missing_catalog;              /* missing catalog data (split) */
    584701  struct Catalog *secfilt_catalog;              /* secfilt catalog data (split) */
     702  struct Catalog *lensing_catalog;              /* lensing catalog data (split) */
     703  struct Catalog *lensobj_catalog;              /* lensobj catalog data (split) */
    585704
    586705  unsigned int objID;
     
    591710  char catmode;                         /* storage mode (raw, mef, split, mysql) */
    592711  char catformat;                       /* storage format (elixir, panstarrs, etc) */
    593   char catflags;                                /* choices to be loaded */
    594   char sorted;                          /* is measure table average-sorted? */
     712  int sorted;                           /* is measure table average-sorted? (NOTE this is an int only because gfits_scan %t requires it) */
    595713 
     714  short catflags; /* choices to be loaded */
     715
    596716  /* pointers for data manipulation */
    597   off_t *found;
    598   off_t *image;
    599   off_t *mosaic;
    600   float *X;
    601   float *Y;
    602   int   *nOwn; // relastro uses this to count owned detections per object
     717  off_t *found_t;
     718  off_t *foundWarp_t;
     719//  off_t *image_t;
     720//  off_t *mosaic_t;
     721//  float *X_t;
     722//  float *Y_t;
     723  int   *nOwn_t; // relastro uses this to count owned detections per object
    603724
    604725} Catalog;
     
    660781char     *GetPhotcodeNamebyCode (int code);
    661782
    662 float PhotInst (Measure *measure);
    663 float PhotCat (Measure *measure);
    664 float PhotSys (Measure *measure, Average *average, SecFilt *secfilt);
    665 float PhotRel (Measure *measure, Average *average, SecFilt *secfilt);
    666 float PhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
    667 float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt);
    668 float PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure);
    669 float PhotAveErr (PhotCode *code, Average *average, SecFilt *secfilt);
    670 
    671 float PhotAperInst (Measure *measure);
    672 float PhotAperCat (Measure *measure);
    673 float PhotAperSys (Measure *measure, Average *average, SecFilt *secfilt);
    674 float PhotAperRel (Measure *measure, Average *average, SecFilt *secfilt);
    675 float PhotAperCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
    676 float PhotAperAve (PhotCode *code, Average *average, SecFilt *secfilt);
    677 float PhotAperRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure);
    678 
    679 float PhotKronInst (Measure *measure);
    680 float PhotKronCat (Measure *measure);
    681 float PhotKronSys (Measure *measure, Average *average, SecFilt *secfilt);
    682 float PhotKronRel (Measure *measure, Average *average, SecFilt *secfilt);
    683 float PhotKronCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
    684 float PhotKronAve (PhotCode *code, Average *average, SecFilt *secfilt);
    685 float PhotKronRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure);
    686 float PhotKronAveErr (PhotCode *code, Average *average, SecFilt *secfilt);
     783float PhotInst (Measure *measure, dvoMagClassType class);
     784float PhotCat (Measure *measure, dvoMagClassType class);
     785float PhotSys (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class);
     786float PhotRel (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class);
     787float PhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code, dvoMagClassType class);
     788float PhotErr (Measure *measure, dvoMagClassType class);
     789float PhotCalErr (Measure *measure, dvoMagClassType class);
     790
     791float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
     792float PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure, dvoMagClassType class, dvoMagSourceType source);
     793float PhotAveErr (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
     794
     795float PhotInstTiny (MeasureTiny *measure, dvoMagClassType class);
     796float PhotCatTiny (MeasureTiny *measure, dvoMagClassType class);
     797float PhotSysTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt, dvoMagClassType class);
     798float PhotRelTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt, dvoMagClassType class);
     799float PhotCalTiny (MeasureTiny *thisone, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code, dvoMagClassType class);
     800
     801float PhotAveTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
     802float PhotRefTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, dvoMagClassType class, dvoMagSourceType source);
     803
     804float PhotFluxInst (Measure *measure, dvoMagClassType class);
     805float PhotFluxCat (Measure *measure, dvoMagClassType class);
     806float PhotFluxSys (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class);
     807float PhotFluxRel (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class);
     808float PhotFluxCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code, dvoMagClassType class);
     809
     810float PhotFluxAve (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
     811float PhotFluxRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure, dvoMagClassType class, dvoMagSourceType source);
     812
     813float PhotFluxInstErr (Measure *measure, dvoMagClassType class);
     814float PhotFluxCatErr (Measure *measure, dvoMagClassType class);
     815float PhotFluxAveErr (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
    687816
    688817float PhotXm (PhotCode *code, Average *average, SecFilt *secfilt);
    689 
    690818float PhotZeroPoint (Measure *measure, Average *average, SecFilt *secfilt);
    691 float PhotAveFluxPSF (PhotCode *code, Average *average, SecFilt *secfilt);
    692 float PhotAvedFluxPSF (PhotCode *code, Average *average, SecFilt *secfilt);
    693 float PhotAveFluxKron (PhotCode *code, Average *average, SecFilt *secfilt);
    694 float PhotAvedFluxKron (PhotCode *code, Average *average, SecFilt *secfilt);
    695 
    696 float PhotMstdev (PhotCode *code, Average *average, SecFilt *secfilt);
    697 float PhotM20 (PhotCode *code, Average *average, SecFilt *secfilt);
    698 float PhotM80 (PhotCode *code, Average *average, SecFilt *secfilt);
     819
     820int   PhotNphot (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
     821float PhotMstdev (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
     822float PhotMmin (PhotCode *code, Average *average, SecFilt *secfilt);
     823float PhotMmax (PhotCode *code, Average *average, SecFilt *secfilt);
    699824float PhotUCdist (PhotCode *code, Average *average, SecFilt *secfilt);
    700825unsigned int PhotStackID (PhotCode *code, Average *average, SecFilt *secfilt);
     
    703828int PhotColor (Average *average, SecFilt *secfilt, Measure *measure, int c1, int c2, double *color);
    704829
    705 float PhotInstTiny (MeasureTiny *measure);
    706 float PhotCatTiny (MeasureTiny *measure);
    707 float PhotAperTiny (MeasureTiny *measure);
    708 float PhotSysTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt);
    709 float PhotRelTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt);
    710 float PhotCalTiny (MeasureTiny *thisone, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code);
    711 float PhotAveTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt);
    712 float PhotRefTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure);
    713830float PhotXmTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt);
    714831float PhotdMTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt);
     
    781898/*** conversion functions / I/O conversions ***/
    782899Average *ReadRawAverage (FILE *f, off_t Naverage, char format, SecFilt **primary);
    783 Measure *ReadRawMeasure (FILE *f, off_t Nmeasure, char format);
     900Measure *ReadRawMeasure (FILE *f, Average *average, off_t Nmeasure, char format);
    784901SecFilt *ReadRawSecFilt (FILE *f, off_t Nsecfilt, char format);
    785902int WriteRawAverage (FILE *f, Average *average, off_t Naverage, char format, SecFilt *primary);
    786 int WriteRawMeasure (FILE *f, Measure *measure, off_t Nmeasure, char format);
     903int WriteRawMeasure (FILE *f, Average *average, Measure *measure, off_t Nmeasure, char format);
    787904int WriteRawSecFilt (FILE *f, SecFilt *secfilt, off_t Nsecfilt, char format);
    788905
     
    790907
    791908Average *FtableToAverage (FTable *ftable, off_t *Naverage, char *format, SecFilt **primary);
    792 Measure *FtableToMeasure (FTable *ftable, off_t *Nmeasure, char *format);
     909Measure *FtableToMeasure (FTable *ftable, Average *average, off_t *Nmeasure, char *format);
    793910SecFilt *FtableToSecFilt (FTable *ftable, off_t *Nsecfilt, char *format);
     911Lensing *FtableToLensing (FTable *ftable, off_t *Nlensing, char *format);
     912Lensobj *FtableToLensobj (FTable *ftable, off_t *Nlensobj, char *format);
    794913int      FtableToImage   (FTable *ftable, Header *theader, char *format);
    795914
    796915int AverageToFtable (FTable *ftable, Average *average, off_t Naverage, char format, SecFilt *primary);
    797 int MeasureToFtable (FTable *ftable, Measure *measure, off_t Nmeasure, char format);
     916int MeasureToFtable (FTable *ftable, Average *average, Measure *measure, off_t Nmeasure, char format);
    798917int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, off_t Nsecfilt, char format);
     918int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, char format);
     919int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, char format);
    799920int ImageToFtable (FTable *ftable, Header *theader, char format);
    800921int ImageToVtable (VTable *vtable, Header *theader, char format);
     
    811932# include "ps1_v3_defs.h"
    812933# include "ps1_v4_defs.h"
     934# include "ps1_v5_defs.h"
    813935# include "ps1_ref_defs.h"
    814936
     
    9051027void TessellationTableInit (TessellationTable *tess, int Ntess);
    9061028
     1029float dvoOffsetR (Measure *measure, Average *average);
     1030float dvoOffsetD (Measure *measure, Average *average);
     1031double dvoMeanR (float dR, Average *average);
     1032double dvoMeanD (float dD, Average *average);
     1033
    9071034void dvo_average_init (Average *average);
    9081035void dvo_averageT_init (AverageTiny *average);
     
    9101037void dvo_measure_init (Measure *measure);
    9111038void dvo_measureT_init (MeasureTiny *measure);
     1039
     1040void dvo_lensing_init (Lensing *lensing);
     1041void dvo_lensobj_init (Lensobj *lensobj, int toZero);
    9121042
    9131043void InitRegionHosts (RegionHostInfo *hosts, int Nhosts, int NHOSTS);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/include/dvodb.h

    r36680 r37403  
    2222
    2323/* magnitude types */
    24 enum {MAG_NONE,
    25 
    26       // these magnitude types are from the measurement table (or derived therein)
    27       // the following imply PSF magnitudes:
    28       MAG_INST, // -2.5*log(DN) [ie, not DN/sec]
    29       MAG_CAT,  // MAG_INST + 2.5*log(exptime) + C_lambda + K_lambda*(airmass - 1)
    30       MAG_SYS,  // MAG_CAT + \sum_i A_i * (color_i - color_o) [color correction for measure photcode]
    31       MAG_REL,  // MAG_SYS - Mcal [specific zero point for image]
    32       MAG_CAL,  // MAG_REL + \sum_i A_i * (color_i - color_o) [color correction for average photcode]
    33       MAG_ERR,  // error on PSF MAG
    34 
    35       // the following imply APERTURE magnitudes:
    36       MAG_APER_INST, // -2.5*log(DN) [ie, not DN/sec]
    37       MAG_APER_CAT,  // MAG_APER_INST + 2.5*log(exptime) + C_lambda + K_lambda*(airmass - 1)
    38       MAG_APER_SYS,  // MAG_APER_CAT + \sum_i A_i * (color_i - color_o) [color correction for measure photcode]
    39       MAG_APER_REL,  // MAG_APER_SYS - Mcal [specific zero point for image]
    40       MAG_APER_CAL,  // MAG_APER_REL + \sum_i A_i * (color_i - color_o) [color correction for average photcode]
    41       MAG_APER_ERR,  // error on APER MAG (if known, else psf error)
    42       MAG_APER,      // in mextract -> MAG_APER_REL, in avextract -> MAG_APER_AVE
    43 
    44       // the following imply KRON magnitudes:
    45       MAG_KRON_INST, // -2.5*log(DN) [ie, not DN/sec]
    46       MAG_KRON_CAT,  // MAG_KRON_INST + 2.5*log(exptime) + C_lambda + K_lambda*(airmass - 1)
    47       MAG_KRON_SYS,  // MAG_KRON_CAT + \sum_i A_i * (color_i - color_o) [color correction for measure photcode]
    48       MAG_KRON_REL,  // MAG_KRON_SYS - Mcal [specific zero point for image]
    49       MAG_KRON_CAL,  // MAG_KRON_REL + \sum_i A_i * (color_i - color_o) [color correction for average photcode]
    50       MAG_KRON_ERR,  // error on KRON MAG
    51       MAG_KRON,      // in mextract -> MAG_KRON_REL, in avextract -> MAG_KRON_AVE
    52 
    53       // these magnitude types are from the average (secfilt) table:
    54       // the following imply PSF magnitudes (or fluxes)
    55       MAG_AVE,
    56       MAG_REF,
    57       MAG_STDEV,
    58       MAG_AVE_ERR,
    59       MAG_CHISQ,
    60       MAG_20,
    61       MAG_80,
    62       MAG_FLUX_PSF,
    63       MAG_FLUX_PSF_ERR,
    64 
    65       // the following imply APERTURE magnitudes:
    66       MAG_APER_AVE,
    67       MAG_APER_REF,
    68 
    69       // the following imply KRON magnitudes or fluxes:
    70       MAG_KRON_AVE,
    71       MAG_KRON_REF,
    72       MAG_FLUX_KRON,
    73       MAG_FLUX_KRON_ERR,
    74 
    75       // other secfilt fields of interest
    76       MAG_PHOT_FLAGS,
    77       MAG_NCODE,
    78       MAG_NPHOT,
    79       MAG_UC_DIST,
    80       MAG_STACK_DET_ID,
    81 };
     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_FLAGS,
     57} dvoMagOptionType;
     58
     59//  MAG_OPTION_STACK_PRIMARY_OFF,
     60//  MAG_OPTION_STACK_BEST_OFF,
     61
     62typedef enum {
     63  MAG_CLASS_NONE,
     64  MAG_CLASS_PSF,
     65  MAG_CLASS_KRON,
     66  MAG_CLASS_APER,
     67} dvoMagClassType;
    8268
    8369/* measure fields */
     
    119105      MEAS_OBJ_FLAGS,
    120106      MEAS_SECFILT_FLAGS,
    121       MEAS_MAG,
     107      MEAS_PHOT, // photometry class of measurements
    122108      MEAS_MINST,
    123109      MEAS_MCAT,
     
    173159      MEAS_EXTERN_ID,
    174160      MEAS_EXPNAME_AS_INT,
    175       MEAS_MCAL_OFFSET,
     161      MEAS_MCAL_OFFSET, // make this a dvoMagOption?
    176162      MEAS_FLAT,
    177163      MEAS_CENTER_OFFSET,
    178       MEAS_FLUX_PSF,
    179       MEAS_FLUX_PSF_ERR,
    180       MEAS_FLUX_KRON,
    181       MEAS_FLUX_KRON_ERR,
     164      MEAS_REF_COLOR,
    182165};
    183166
     
    210193      AVE_NMISS,
    211194      AVE_NPOS,
    212       AVE_NPHOT,
    213       AVE_NCODE,
    214       AVE_MAG,
    215       AVE_dMAG,
    216       AVE_Xm,
    217195      AVE_OBJ_FLAGS,
    218196      AVE_TYPE,
     
    222200      AVE_EXTID_HI,
    223201      AVE_EXTID_LO,
     202      AVE_REF_COLOR,
     203      AVE_PHOT, // photometry class of values
    224204};
     205
     206//       AVE_NPHOT,
     207//       AVE_NCODE,
     208//       AVE_MAG,
     209//       AVE_dMAG,
     210//       AVE_Xm,
    225211
    226212enum {IMAGE_ZERO,
     
    289275      IMAGE_NFIT_ASTROM,
    290276      IMAGE_NLINK_PHOTOM,
    291       IMAGE_NLINK_ASTROM
     277      IMAGE_NLINK_ASTROM,
     278      IMAGE_REF_COLOR
    292279};
    293280
     
    309296  int table;
    310297  int ID;
    311   int magMode;
     298
     299  dvoMagSourceType magSource; // chip, (forced) warp, stack [only relevant for averages]
     300  dvoMagLevelType magLevel;  // inst, cat, sys, rel, ave, ref, err, min, max, stdev, nphot, chisq,
     301  dvoMagOptionType magOption;  // psf, kron, aper
     302  dvoMagClassType magClass;
     303
    312304  char type;
    313305  PhotCode *photcode;
     
    371363
    372364int          GetMagMode             PROTO((char *string));
    373 PhotCode    *ParsePhotcodeField     PROTO((char *field, int *mode, int def));
     365int          ParsePhotcodeField     PROTO((dbField *field, char *fieldName, int fieldID));
    374366int          ParseMeasureField      PROTO((dbField *field, char *fieldName));
    375367int          ParseAverageField      PROTO((dbField *field, char *fieldName));
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/include/elixir_defs.h

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/include/loneos_defs.h

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/include/panstarrs_dev_0_defs.h

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/include/panstarrs_dev_1_defs.h

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/include/ps1_dev_1_defs.h

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/include/ps1_dev_2_defs.h

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/include/ps1_ref_defs.h

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/include/ps1_v1_defs.h

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/include/ps1_v2_defs.h

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/include/ps1_v3_defs.h

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/include/ps1_v4_defs.h

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/BoundaryTree.c

    r36680 r37403  
    8484  gfits_scan (headerPHU, "DEC_ORI",  "%lf", 1, &tree->DEC_origin);
    8585  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);
     86  gfits_scan (headerPHU, "NX_SUB",   "%f",  1, &tree->NX_SUB);
     87  gfits_scan (headerPHU, "NY_SUB",   "%f",  1, &tree->NY_SUB);
    8888  gfits_scan (headerPHU, "PIXSCALE", "%lf", 1, &tree->dPix);
    8989
     
    111111  ALLOCATE (tree->Xo,   double *, tree->Nzone);
    112112  ALLOCATE (tree->Yo,   double *, tree->Nzone);
    113   ALLOCATE (tree->dX,      int *, tree->Nzone);
    114   ALLOCATE (tree->dY,      int *, tree->Nzone);
     113  ALLOCATE (tree->dX,    float *, tree->Nzone);
     114  ALLOCATE (tree->dY,    float *, tree->Nzone);
    115115  ALLOCATE (tree->cell,    int *, tree->Nzone);
    116116  ALLOCATE (tree->projID,  int *, tree->Nzone);
     
    121121    ALLOCATE (tree->Xo[i],   double, tree->Nband[i]);
    122122    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]);
     123    ALLOCATE (tree->dX[i],    float, tree->Nband[i]);
     124    ALLOCATE (tree->dY[i],    float, tree->Nband[i]);
    125125    ALLOCATE (tree->cell[i],    int, tree->Nband[i]);
    126126    ALLOCATE (tree->projID[i],  int, tree->Nband[i]);
     
    147147  GET_COLUMN_NEW(&headerCell, &ftableCell, Xo,    "X_CENT",      double);
    148148  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);
     149  GET_COLUMN_NEW(&headerCell, &ftableCell, dX,    "X_GRID",      float);
     150  GET_COLUMN_NEW(&headerCell, &ftableCell, dY,    "Y_GRID",      float);
    151151  GET_COLUMN_NEW(&headerCell, &ftableCell, name,  "NAME",        char); // XXX how is this done?
    152152  gfits_free_header (&headerCell);
     
    214214  gfits_modify (&header, "DEC_OFF", "%lf", 1, tree->DEC_offset);
    215215
    216   gfits_modify (&header, "NX_SUB", "%d", 1, tree->NX_SUB);
    217   gfits_modify (&header, "NY_SUB", "%d", 1, tree->NY_SUB);
     216  gfits_modify (&header, "NX_SUB", "%f", 1, tree->NX_SUB);
     217  gfits_modify (&header, "NY_SUB", "%f", 1, tree->NY_SUB);
    218218  gfits_modify (&header, "PIXSCALE", "%lf", 1, tree->dPix);
    219219
     
    289289    gfits_define_bintable_column (&theader, "D", "X_CENT", "projection cell center pixel", "none", 1.0, 0.0);
    290290    gfits_define_bintable_column (&theader, "D", "Y_CENT", "projection cell center pixel", "none", 1.0, 0.0);
    291     gfits_define_bintable_column (&theader, "J", "X_GRID", "skycell grid spacing", "none", 1.0, 0.0);
    292     gfits_define_bintable_column (&theader, "J", "Y_GRID", "skycell grid spacing", "none", 1.0, 0.0);
     291    gfits_define_bintable_column (&theader, "E", "X_GRID", "skycell grid spacing", "none", 1.0, 0.0);
     292    gfits_define_bintable_column (&theader, "E", "Y_GRID", "skycell grid spacing", "none", 1.0, 0.0);
    293293    gfits_define_bintable_column (&theader, fmt, "NAME", "cell name", "none", 1.0, 0.0);
    294294
     
    310310    double *Xo            ; ALLOCATE (Xo,    double, Ncell);
    311311    double *Yo            ; ALLOCATE (Yo,    double, Ncell);
    312     int    *dX            ; ALLOCATE (dX,    int,    Ncell);
    313     int    *dY            ; ALLOCATE (dY,    int,    Ncell);
     312    float  *dX            ; ALLOCATE (dX,    float,  Ncell);
     313    float  *dY            ; ALLOCATE (dY,    float,  Ncell);
    314314    char   *name          ; ALLOCATE (name,  char,   Ncell*BOUNDARY_TREE_NAME_LENGTH);
    315315
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/ImageMetadata.c

    r35416 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/LoadPhotcodesFITS.c

    r35755 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/LoadPhotcodesText.c

    r28833 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/SavePhotcodesFITS.c

    r34260 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/TessellationTable.c

    r36680 r37403  
    2828    tess[i].dPix = NAN;
    2929
    30     tess[i].dX = 0;
    31     tess[i].dY = 0;
    32 
    33     tess[i].NX_SUB = 0;
    34     tess[i].NY_SUB = 0;
     30    tess[i].dX = NAN;
     31    tess[i].dY = NAN;
     32
     33    tess[i].NX_SUB = NAN;
     34    tess[i].NY_SUB = NAN;
    3535
    3636    tess[i].basename = NULL;
     
    123123  GET_COLUMN_NEW(Xo,     "X_CENT", double);
    124124  GET_COLUMN_NEW(Yo,     "Y_CENT", double);
    125   GET_COLUMN_NEW(dX,     "X_GRID", int);
    126   GET_COLUMN_NEW(dY,     "Y_GRID", int);
     125  GET_COLUMN_NEW(dX,     "X_GRID", float);
     126  GET_COLUMN_NEW(dY,     "Y_GRID", float);
    127127  GET_COLUMN_NEW(Rmin,   "R_MIN",  double);
    128128  GET_COLUMN_NEW(Rmax,   "R_MAX",  double);
     
    130130  GET_COLUMN_NEW(Dmax,   "D_MAX",  double);
    131131  GET_COLUMN_NEW(dPix,   "SCALE",  double);
    132   GET_COLUMN_NEW(NX_SUB, "NX_SUB", int);
    133   GET_COLUMN_NEW(NY_SUB, "NY_SUB", int);
     132  GET_COLUMN_NEW(NX_SUB, "NX_SUB", float);
     133  GET_COLUMN_NEW(NY_SUB, "NY_SUB", float);
    134134  GET_COLUMN_NEW(TYPE,   "TYPE",   int);
    135135
     
    280280    gfits_modify (&header, "DEC_OFF", "%lf", 1, rings->DEC_offset);
    281281
    282     gfits_modify (&header, "NX_SUB", "%d", 1, rings->NX_SUB);
    283     gfits_modify (&header, "NY_SUB", "%d", 1, rings->NY_SUB);
     282    gfits_modify (&header, "NX_SUB", "%f", 1, rings->NX_SUB);
     283    gfits_modify (&header, "NY_SUB", "%f", 1, rings->NY_SUB);
    284284    gfits_modify (&header, "PIXSCALE", "%lf", 1, rings->dPix);
    285285  }
     
    300300  gfits_define_bintable_column (&theader, "D", "X_CENT", "projection cell center pixel", "none", 1.0, 0.0);
    301301  gfits_define_bintable_column (&theader, "D", "Y_CENT", "projection cell center pixel", "none", 1.0, 0.0);
    302   gfits_define_bintable_column (&theader, "J", "X_GRID", "skycell grid spacing", "none", 1.0, 0.0);
    303   gfits_define_bintable_column (&theader, "J", "Y_GRID", "skycell grid spacing", "none", 1.0, 0.0);
     302  gfits_define_bintable_column (&theader, "E", "X_GRID", "skycell grid spacing", "none", 1.0, 0.0);
     303  gfits_define_bintable_column (&theader, "E", "Y_GRID", "skycell grid spacing", "none", 1.0, 0.0);
    304304  gfits_define_bintable_column (&theader, "D", "R_MIN",  "RA limit (lower)", "none", 1.0, 0.0);
    305305  gfits_define_bintable_column (&theader, "D", "R_MAX",  "RA limit (upper)", "none", 1.0, 0.0);
     
    307307  gfits_define_bintable_column (&theader, "D", "D_MAX",  "DEC limit (upper)", "none", 1.0, 0.0);
    308308  gfits_define_bintable_column (&theader, "D", "SCALE",  "pixel scale for projection cell", "none", 1.0, 0.0);
    309   gfits_define_bintable_column (&theader, "J", "NX_SUB", "skycell subdivision in x", "none", 1.0, 0.0);
    310   gfits_define_bintable_column (&theader, "J", "NY_SUB", "skycell subdivision in y", "none", 1.0, 0.0);
     309  gfits_define_bintable_column (&theader, "E", "NX_SUB", "skycell subdivision in x", "none", 1.0, 0.0);
     310  gfits_define_bintable_column (&theader, "E", "NY_SUB", "skycell subdivision in y", "none", 1.0, 0.0);
    311311  gfits_define_bintable_column (&theader, "J", "TYPE",   "type of tessellation", "none", 1.0, 0.0);
    312312
     
    330330  double *Xo            ; ALLOCATE (Xo    ,    double, Nout);
    331331  double *Yo            ; ALLOCATE (Yo    ,    double, Nout);
    332   int    *dX            ; ALLOCATE (dX    ,    int,    Nout);
    333   int    *dY            ; ALLOCATE (dY    ,    int,    Nout);
     332  float  *dX            ; ALLOCATE (dX    ,    float,  Nout);
     333  float  *dY            ; ALLOCATE (dY    ,    float,  Nout);
    334334  double *Rmin          ; ALLOCATE (Rmin  ,    double, Nout);
    335335  double *Rmax          ; ALLOCATE (Rmax  ,    double, Nout);
     
    337337  double *Dmax          ; ALLOCATE (Dmax  ,    double, Nout);
    338338  double *dPix          ; ALLOCATE (dPix  ,    double, Nout);
    339   int    *NX_SUB        ; ALLOCATE (NX_SUB,    int,    Nout);
    340   int    *NY_SUB        ; ALLOCATE (NY_SUB,    int,    Nout);
     339  float  *NX_SUB        ; ALLOCATE (NX_SUB,    float,  Nout);
     340  float  *NY_SUB        ; ALLOCATE (NY_SUB,    float,  Nout);
    341341  int    *TYPE          ; ALLOCATE (TYPE,      int,    Nout);
    342342
     
    559559    int xi = x / tess[myTess].tree->dX[zone][band];
    560560    int yi = y / tess[myTess].tree->dY[zone][band];
     561
     562    xi = MAX(MIN(xi, tess[myTess].tree->NX_SUB - 1.0), 0);
     563    yi = MAX(MIN(yi, tess[myTess].tree->NY_SUB - 1.0), 0);
     564
    561565    int N = xi + tess[myTess].tree->NX_SUB * yi;
    562566 
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/cmf-ps1-dv3.c

    r35416 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dbExtractAverages.c

    r36680 r37403  
    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
     
    162161      value.Flt = average[0].stargal;
    163162      break;
     163    case AVE_REF_COLOR:
     164      value.Flt = average[0].refColorBlue;
     165      break;
    164166
    165167    case AVE_OBJ_FLAGS:
     
    179181      break;
    180182
    181     case AVE_MAG:
    182       switch (field->magMode) {
    183         case MAG_AVE:
    184           value.Flt = PhotAve  (field->photcode, average, secfilt);
    185           break;
    186         case MAG_REF:
    187           value.Flt = PhotRef  (field->photcode, average, secfilt, measure);
    188           break;
    189         case MAG_INST:
    190         case MAG_CAT:
    191         case MAG_SYS:
    192         case MAG_REL:
    193         case MAG_CAL:
    194           // XXX need to code this correctly: this returns just the first matching value
    195           value.Flt = NAN;
     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      /* in some cases below we need a measurement which matches the requested photcode.
     203         here is some sample code to find this.
     204
    196205          for (i = 0; i < average[0].Nmeasure; i++) {
    197206            if (field->photcode->code != measure[i].photcode) continue;
     
    199208            break;
    200209          }
    201           break;
    202         case MAG_CHISQ:
     210      */
     211
     212      switch (field->magOption) {
     213        case MAG_OPTION_MAG:
     214          switch (field->magLevel) {
     215            case MAG_LEVEL_AVE:
     216              value.Flt = PhotAve  (field->photcode, average, secfilt, field->magClass, field->magSource);
     217              break;
     218            case MAG_LEVEL_REF:
     219              // which measure is needed here?
     220              // PhotRef  (field->photcode, average, secfilt, measure, field->magClass, field->magSource);
     221              break;
     222            case MAG_LEVEL_INST:
     223            case MAG_LEVEL_CAT:
     224            case MAG_LEVEL_SYS:
     225            case MAG_LEVEL_REL:
     226            case MAG_LEVEL_CAL:
     227            case MAG_LEVEL_NONE:
     228              break;
     229          }
     230          break;
     231
     232        case MAG_OPTION_ERR:
     233          switch (field->magLevel) {
     234            case MAG_LEVEL_AVE:
     235            case MAG_LEVEL_REF:
     236              value.Flt = PhotAveErr (field->photcode, average, secfilt, field->magClass, field->magSource); 
     237              break;
     238            case MAG_LEVEL_INST:
     239            case MAG_LEVEL_CAT:
     240            case MAG_LEVEL_SYS:
     241            case MAG_LEVEL_REL:
     242            case MAG_LEVEL_CAL:
     243            case MAG_LEVEL_NONE:
     244              break;
     245          }
     246          break;
     247
     248        case MAG_OPTION_FLUX:
     249          switch (field->magLevel) {
     250            case MAG_LEVEL_AVE:
     251              value.Flt = PhotFluxAve  (field->photcode, average, secfilt, field->magClass, field->magSource);
     252              break;
     253            case MAG_LEVEL_REF:
     254              // XXX which measure is needed here?
     255              // value.Flt = PhotFluxRef  (field->photcode, average, secfilt, measure, field->magClass, field->magSource);
     256              break;
     257            case MAG_LEVEL_INST:
     258            case MAG_LEVEL_CAT:
     259            case MAG_LEVEL_SYS:
     260            case MAG_LEVEL_REL:
     261            case MAG_LEVEL_CAL:
     262            case MAG_LEVEL_NONE:
     263              break;
     264          }
     265          break;
     266
     267        case MAG_OPTION_FLUX_ERR:
     268          switch (field->magLevel) {
     269            case MAG_LEVEL_AVE:
     270            case MAG_LEVEL_REF:
     271              value.Flt = PhotFluxAveErr (field->photcode, average, secfilt, field->magClass, field->magSource); 
     272              break;
     273            case MAG_LEVEL_INST:
     274            case MAG_LEVEL_CAT:
     275            case MAG_LEVEL_SYS:
     276            case MAG_LEVEL_REL:
     277            case MAG_LEVEL_CAL:
     278            case MAG_LEVEL_NONE:
     279              break;
     280          }
     281          break;
     282
     283        case MAG_OPTION_STDEV:
     284          value.Flt = PhotMstdev (field->photcode, average, secfilt, field->magClass, field->magSource);
     285          break;
     286        case MAG_OPTION_CHISQ:
    203287          value.Flt = PhotXm (field->photcode, average, secfilt);
    204288          break;
    205         case MAG_ERR:
    206           if ((field->photcode->type == PHOT_REF) || (field->photcode->type == PHOT_DEP)) {
    207             for (i = 0; i < average[0].Nmeasure; i++) {
    208               if (field->photcode->code != measure[i].photcode) continue;
    209               value.Flt = measure[i].dM;
    210               break;
    211             }
    212           } else {
    213             value.Flt = PhotAveErr (field->photcode, average, secfilt);
    214           }
    215           break;
    216         case MAG_STDEV:
    217           value.Flt = PhotMstdev (field->photcode, average, secfilt);
    218           break;
    219         case MAG_PHOT_FLAGS:
    220           if ((field->photcode->type == PHOT_REF) || (field->photcode->type == PHOT_DEP)) {
    221             for (i = 0; i < average[0].Nmeasure; i++) {
    222               if (field->photcode->code != measure[i].photcode) continue;
    223               value.Int = measure[i].photFlags;
    224               break;
    225             }
    226           } else {
    227             Nsec = GetPhotcodeNsec (field->photcode->code);
    228             if (Nsec == -1) break;
    229             value.Int = secfilt[Nsec].flags;
    230           }
    231           break;
    232         case MAG_NCODE:
    233           // XXX push these into dvo_photcode_ops APIs
    234           // XXX do I need to allow for conversion to equiv?
    235           Nsec = GetPhotcodeNsec (field->photcode->code);
     289        case MAG_OPTION_MIN:
     290          value.Flt = PhotMmin (field->photcode, average, secfilt);
     291          break;
     292        case MAG_OPTION_MAX:
     293          value.Flt = PhotMmax (field->photcode, average, secfilt);
     294          break;
     295        case MAG_OPTION_NCODE: {
     296          int Nsec = GetPhotcodeNsec (field->photcode->code);
    236297          if (Nsec == -1) break;
    237298          value.Int = secfilt[Nsec].Ncode;
    238299          break;
    239         case MAG_NPHOT:
    240           Nsec = GetPhotcodeNsec (field->photcode->code);
     300        }
     301        case MAG_OPTION_NPHOT: {
     302          value.Int = PhotNphot (field->photcode, average, secfilt, field->magClass, field->magSource);
     303          break;
     304        }
     305        case MAG_OPTION_UC_DIST:
     306          value.Flt = PhotUCdist (field->photcode, average, secfilt);
     307          break;
     308        // XX case MAG_OPTION_STACK_DET_ID:
     309        // XX   value.Int = PhotStackID (field->photcode, average, secfilt);
     310        // XX   break;
     311        case MAG_OPTION_FLAGS: {
     312          int Nsec = GetPhotcodeNsec (field->photcode->code);
    241313          if (Nsec == -1) break;
    242           value.Int = secfilt[Nsec].Nused;
    243           break;
    244 
    245         case MAG_APER:
    246         case MAG_APER_AVE:
    247           value.Flt = PhotAperAve (field->photcode, average, secfilt);
    248           break;
    249 
    250         case MAG_APER_REF:
    251           value.Flt = PhotAperRef (field->photcode, average, secfilt, measure);
    252           break;
    253 
    254         case MAG_KRON:
    255         case MAG_KRON_AVE:
    256           value.Flt = PhotKronAve (field->photcode, average, secfilt);
    257           break;
    258 
    259         case MAG_KRON_REF:
    260           value.Flt = PhotKronRef (field->photcode, average, secfilt, measure);
    261           break;
    262 
    263         case MAG_KRON_ERR:
    264           value.Flt = PhotKronAveErr (field->photcode, average, secfilt);
    265           break;
    266 
    267         case MAG_20:
    268           value.Flt = PhotM20 (field->photcode, average, secfilt);
    269           break;
    270         case MAG_80:
    271           value.Flt = PhotM80 (field->photcode, average, secfilt);
    272           break;
    273         case MAG_UC_DIST:
    274           value.Flt = PhotUCdist (field->photcode, average, secfilt);
    275           break;
    276         case MAG_STACK_DET_ID:
    277           value.Int = PhotStackID (field->photcode, average, secfilt);
    278           break;
    279 
    280         case MAG_FLUX_PSF:
    281           value.Flt = PhotAveFluxPSF (field->photcode, average, secfilt);
    282           break;
    283         case MAG_FLUX_PSF_ERR:
    284           value.Flt = PhotAvedFluxPSF (field->photcode, average, secfilt);
    285           break;
    286         case MAG_FLUX_KRON:
    287           value.Flt = PhotAveFluxKron (field->photcode, average, secfilt);
    288           break;
    289         case MAG_FLUX_KRON_ERR:
    290           value.Flt = PhotAvedFluxKron (field->photcode, average, secfilt);
    291           break;
    292       }
    293       break;
    294     case AVE_dMAG:
    295       value.Flt = PhotAveErr (field->photcode, average, secfilt);
    296       break;
    297     case AVE_Xm:
    298       value.Flt = PhotXm (field->photcode, average, secfilt);
    299       break;
     314          value.Int = secfilt[Nsec].flags;
     315          break;
     316        }
     317        case MAG_OPTION_NONE:
     318          break;
     319      }
     320      break;
     321
    300322    case AVE_TYPE:
    301323      break;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dbExtractImages.c

    r35102 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dbExtractMeasures.c

    r36680 r37403  
    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_ERR:
    126 
    127           case MAG_APER_INST:
    128           case MAG_APER_CAT:
    129           case MAG_APER_SYS:
    130           case MAG_APER_REL:
    131           case MAG_APER_CAL:
    132           case MAG_APER_ERR:
    133 
    134           case MAG_KRON_INST:
    135           case MAG_KRON_CAT:
    136           case MAG_KRON_SYS:
    137           case MAG_KRON_REL:
    138           case MAG_KRON_CAL:
    139           case MAG_KRON_ERR:
    140 
    141           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:
    142126            equiv = myEquiv;
    143127            if (equiv && (equiv->code == field->photcode->code)) goto valid_photcode;
     
    145129
    146130            // mean-like : return value for the given photcode
    147           case MAG_AVE:
    148           case MAG_REF:
    149           case MAG_STDEV:
    150           case MAG_AVE_ERR:
    151           case MAG_CHISQ:
    152           case MAG_FLUX_PSF:
    153           case MAG_FLUX_PSF_ERR:
    154 
    155           case MAG_APER_AVE:
    156 
    157           case MAG_KRON_AVE:
    158           case MAG_FLUX_KRON:
    159           case MAG_FLUX_KRON_ERR:
    160 
    161           case MAG_20:
    162           case MAG_80:
    163           case MAG_UC_DIST:
    164           case MAG_STACK_DET_ID:
    165 
    166           case MAG_NCODE:
    167           case MAG_NPHOT:
     131          case MAG_LEVEL_AVE:
     132          case MAG_LEVEL_REF:
    168133            equiv = field->photcode;
    169134            goto valid_photcode;
     
    177142
    178143  valid_photcode:
    179       switch (field->magMode) {
    180         case MAG_INST:
    181           value.Flt = PhotInst (measure); 
    182           break;
    183         case MAG_CAT:
    184           value.Flt = PhotCat  (measure);
    185           break;
    186         case MAG_SYS:
    187           value.Flt = PhotSys  (measure, average, secfilt);
    188           break;
    189         case MAG_REL:
    190           value.Flt = PhotRel  (measure, average, secfilt);
    191           break;
    192         case MAG_CAL:
    193           value.Flt = PhotCal  (measure, average, secfilt, measure, equiv);
    194           break;
    195         case MAG_AVE:
    196           value.Flt = PhotAve  (equiv, average, secfilt);
    197           break;
    198         case MAG_REF:
    199           value.Flt = PhotRef  (equiv, average, secfilt, measure);
    200           break;
    201         case MAG_ERR:
    202           value.Flt = measure[0].dM;
    203           break;
    204         case MAG_AVE_ERR:
    205           value.Flt = PhotAveErr  (equiv, average, secfilt);
    206           break;
    207 
    208         case MAG_APER_INST:
    209           value.Flt = PhotAperInst (measure);
    210           break;
    211         case MAG_APER_CAT:
    212           value.Flt = PhotAperCat (measure);
    213           break;
    214         case MAG_APER_SYS:
    215           value.Flt = PhotAperSys (measure, average, secfilt);
    216           break;
    217         case MAG_APER:
    218         case MAG_APER_REL:
    219           value.Flt = PhotAperRel (measure, average, secfilt);
    220           break;
    221         case MAG_APER_CAL:
    222           value.Flt = PhotAperCal (measure, average, secfilt, measure, equiv);
    223           break;
    224         case MAG_APER_AVE:
    225           value.Flt = PhotAperAve (equiv, average, secfilt);
    226           break;
    227         case MAG_APER_REF:
    228           value.Flt = PhotAperRef (equiv, average, secfilt, measure);
    229           break;
    230         case MAG_APER_ERR:
    231           value.Flt = measure[0].dM;
    232           break;
    233 
    234         case MAG_KRON_INST:
    235           value.Flt = PhotKronInst (measure);
    236           break;
    237         case MAG_KRON_CAT:
    238           value.Flt = PhotKronCat (measure);
    239           break;
    240         case MAG_KRON_SYS:
    241           value.Flt = PhotKronSys (measure, average, secfilt);
    242           break;
    243         case MAG_KRON:
    244         case MAG_KRON_REL:
    245           value.Flt = PhotKronRel (measure, average, secfilt);
    246           break;
    247         case MAG_KRON_CAL:
    248           value.Flt = PhotKronCal (measure, average, secfilt, measure, equiv);
    249           break;
    250         case MAG_KRON_AVE:
    251           value.Flt = PhotKronAve (equiv, average, secfilt);
    252           break;
    253         case MAG_KRON_REF:
    254           value.Flt = PhotKronRef (equiv, average, secfilt, measure);
    255           break;
    256         case MAG_KRON_ERR:
    257           value.Flt = measure[0].dMkron;
    258           break;
    259 
    260         case MAG_PHOT_FLAGS:
    261           if ((field->photcode->type == PHOT_REF) || (field->photcode->type == PHOT_DEP)) {
    262             value.Int = measure[0].photFlags;
     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;
    263170          }
    264171          break;
    265172
    266         case MAG_NCODE:
    267           if (equiv == NULL) break;
    268           Nsec = GetPhotcodeNsec (equiv->code);
    269           if (Nsec == -1) break;
    270           value.Int = secfilt[Nsec].Ncode;
     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          }
    271191          break;
    272         case MAG_NPHOT:
    273           if (equiv == NULL) break;
    274           Nsec = GetPhotcodeNsec (equiv->code);
    275           if (Nsec == -1) break;
    276           value.Int = secfilt[Nsec].Nused;
     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;
     218          }
    277219          break;
    278220
    279         case MAG_CHISQ:
    280           value.Flt = PhotXm (equiv, average, secfilt);
     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;
     240          }
    281241          break;
    282         case MAG_STDEV:
    283           value.Flt = PhotMstdev (equiv, average, secfilt);
    284           break;
    285         case MAG_20:
    286           value.Flt = PhotM20 (equiv, average, secfilt);
    287           break;
    288         case MAG_80:
    289           value.Flt = PhotM80 (equiv, average, secfilt);
    290           break;
    291         case MAG_UC_DIST:
    292           value.Flt = PhotUCdist (equiv, average, secfilt);
    293           break;
    294 
    295         case MAG_FLUX_PSF:
    296           value.Flt = PhotAveFluxPSF (field->photcode, average, secfilt);
    297           break;
    298         case MAG_FLUX_PSF_ERR:
    299           value.Flt = PhotAvedFluxPSF (field->photcode, average, secfilt);
    300           break;
    301         case MAG_FLUX_KRON:
    302           value.Flt = PhotAveFluxKron (field->photcode, average, secfilt);
    303           break;
    304         case MAG_FLUX_KRON_ERR:
    305           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_FLAGS:
     251        case MAG_OPTION_NONE:
    306252          break;
    307253      }
     
    309255    }
    310256    case MEAS_RA: /* OK */
    311       value.Flt = average[0].R - measure[0].dR / 3600.0;
     257      value.Flt = measure[0].R;
    312258      break;
    313259    case MEAS_DEC: /* OK */
    314       value.Flt = average[0].D - measure[0].dD / 3600.0;
     260      value.Flt = measure[0].D;
    315261      break;
    316262    case MEAS_RA_AVE: /* OK */
     
    323269    case MEAS_GLON:
    324270      if (!haveGalacticMeas) {
    325         ApplyTransform (&GLON_MEAS, &GLAT_MEAS, average[0].R - measure[0].dR / 3600.0, average[0].D - measure[0].dD / 3600.0, celestial_to_galactic);
     271        ApplyTransform (&GLON_MEAS, &GLAT_MEAS, measure[0].R, measure[0].D, celestial_to_galactic);
    326272        haveGalacticMeas = TRUE;
    327273      }
     
    330276    case MEAS_GLAT:
    331277      if (!haveGalacticMeas) {
    332         ApplyTransform (&GLON_MEAS, &GLAT_MEAS, average[0].R - measure[0].dR / 3600.0, average[0].D - measure[0].dD / 3600.0, celestial_to_galactic);
     278        ApplyTransform (&GLON_MEAS, &GLAT_MEAS, measure[0].R, measure[0].D, celestial_to_galactic);
    333279        haveGalacticMeas = TRUE;
    334280      }
     
    337283    case MEAS_ELON:
    338284      if (!haveEclipticMeas) {
    339         ApplyTransform (&ELON_MEAS, &ELAT_MEAS, average[0].R - measure[0].dR / 3600.0, average[0].D - measure[0].dD / 3600.0, celestial_to_ecliptic);
     285        ApplyTransform (&ELON_MEAS, &ELAT_MEAS, measure[0].R, measure[0].D, celestial_to_ecliptic);
    340286        haveEclipticMeas = TRUE;
    341287      }
     
    344290    case MEAS_ELAT:
    345291      if (!haveEclipticMeas) {
    346         ApplyTransform (&ELON_MEAS, &ELAT_MEAS, average[0].R - measure[0].dR / 3600.0, average[0].D - measure[0].dD / 3600.0, celestial_to_ecliptic);
     292        ApplyTransform (&ELON_MEAS, &ELAT_MEAS, measure[0].R, measure[0].D, celestial_to_ecliptic);
    347293        haveEclipticMeas = TRUE;
    348294      }
     
    441387    // the error.
    442388    case MEAS_RA_OFFSET: /* OK */
    443       value.Flt = measure[0].dR;
     389      value.Flt = dvoOffsetR (measure, average);
    444390      break;
    445391    case MEAS_DEC_OFFSET: /* OK */
    446       value.Flt = measure[0].dD;
     392      value.Flt = dvoOffsetD (measure, average);
    447393      break;
    448394    case MEAS_RA_FIT_OFFSET: /* OK */
    449395      dT = (measure[0].t - average[0].Tmean) / (86400*365.25);
    450       value.Flt = average[0].uR * dT + measure[0].dR;
     396      dR = dvoOffsetR (measure, average);
     397      value.Flt = average[0].uR * dT + dR;
    451398      break;
    452399    case MEAS_DEC_FIT_OFFSET: /* OK */
    453400      dT = (measure[0].t - average[0].Tmean) / (86400*365.25);
    454       value.Flt = average[0].uD * dT + measure[0].dD;
     401      dD = dvoOffsetD (measure, average);
     402      value.Flt = average[0].uD * dT + dD;
    455403      break;
    456404    case MEAS_RA_OFFSET_ERR: /* OK */
     
    524472    case MEAS_PLATESCALE: /* OK */
    525473      value.Flt = measure[0].pltscale;
     474      break;
     475
     476    case MEAS_REF_COLOR:
     477      value.Flt = average[0].refColorBlue;
    526478      break;
    527479
     
    552504        // measure.xccd if we need it
    553505        Image *image;
    554         ra  = average[0].R - measure[0].dR / 3600.0;
    555         dec = average[0].D - measure[0].dD / 3600.0;
     506        ra  = measure[0].R;
     507        dec = measure[0].D;
    556508        image = MatchImageDVO (measure[0].t, measure[0].photcode, measure[0].imageID);
    557509        if (image == NULL) break;
     
    567519      {
    568520        Image *image;
    569         ra  = average[0].R - measure[0].dR / 3600.0;
    570         dec = average[0].D - measure[0].dD / 3600.0;
     521        ra  = measure[0].R;
     522        dec = measure[0].D;
    571523        image = MatchImageDVO (measure[0].t, measure[0].photcode, measure[0].imageID);
    572524        if (image == NULL) break;
     
    603555        }
    604556        if (fieldc == NULL) break;
    605         double Rm = average[0].R - measure[0].dR / 3600.0;
    606         double Dm = average[0].D - measure[0].dD / 3600.0;
     557        double Rm = measure[0].R;
     558        double Dm = measure[0].D;
    607559        RD_to_XY (&XFIELD_MEAS, &YFIELD_MEAS, Rm, Dm, fieldc);
    608560      }
     
    620572        }
    621573        if (fieldc == NULL) break;
    622         double Rm = average[0].R - measure[0].dR / 3600.0;
    623         double Dm = average[0].D - measure[0].dD / 3600.0;
     574        double Rm = measure[0].R;
     575        double Dm = measure[0].D;
    624576        RD_to_XY (&XFIELD_MEAS, &YFIELD_MEAS, Rm, Dm, fieldc);
    625577      }
     
    638590        }
    639591        if (mosaic == NULL) break;
    640         double Rm = average[0].R - measure[0].dR / 3600.0;
    641         double Dm = average[0].D - measure[0].dD / 3600.0;
     592        double Rm = measure[0].R;
     593        double Dm = measure[0].D;
    642594        RD_to_XY (&XMOS_MEAS, &YMOS_MEAS, Rm, Dm, mosaic);
    643595      }
     
    655607        }
    656608        if (mosaic == NULL) break;
    657         double Rm = average[0].R - measure[0].dR / 3600.0;
    658         double Dm = average[0].D - measure[0].dD / 3600.0;
     609        double Rm = measure[0].R;
     610        double Dm = measure[0].D;
    659611        RD_to_XY (&XMOS_MEAS, &YMOS_MEAS, Rm, Dm, mosaic);
    660612      }
     
    694646    case MEAS_PSF_NPIX: /* OK */
    695647      value.Int = measure[0].psfNpix;
    696       break;
    697     case MEAS_CR_NSIGMA: /* OK */
    698       value.Flt = measure[0].crNsigma;
    699648      break;
    700649    case MEAS_EXT_NSIGMA: /* OK */
     
    769718      break;
    770719
    771     case MEAS_FLUX_PSF: /* OK */
    772       value.Flt = measure[0].FluxPSF;
    773       break;
    774     case MEAS_FLUX_PSF_ERR: /* OK */
    775       value.Flt = measure[0].dFluxPSF;
    776       break;
    777     case MEAS_FLUX_KRON: /* OK */
    778       value.Flt = measure[0].FluxKron;
    779       break;
    780     case MEAS_FLUX_KRON_ERR: /* OK */
    781       value.Flt = measure[0].dFluxKron;
    782       break;
     720    // case MEAS_FLUX_PSF: /* OK */
     721    //   value.Flt = measure[0].FluxPSF;
     722    //   break;
     723    // case MEAS_FLUX_PSF_ERR: /* OK */
     724    //   value.Flt = measure[0].dFluxPSF;
     725    //   break;
     726    // case MEAS_FLUX_KRON: /* OK */
     727    //   value.Flt = measure[0].FluxKron;
     728    //   break;
     729    // case MEAS_FLUX_KRON_ERR: /* OK */
     730    //   value.Flt = measure[0].dFluxKron;
     731    //   break;
    783732  }
    784733  return (value);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dbFields.c

    r36680 r37403  
    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, "flags"))        return (MAG_OPTION_FLAGS);
     81
     82  return MAG_OPTION_NONE;
     83}
     84
     85# if (0)
    3086int GetMagMode (char *string) {
    3187
     
    85141  if (!strcasecmp (string, "nphot"))       return (MAG_NPHOT);
    86142  if (!strcasecmp (string, "stdev"))       return (MAG_STDEV);
    87   if (!strcasecmp (string, "20"))          return (MAG_20);
    88   if (!strcasecmp (string, "80"))          return (MAG_80);
     143  if (!strcasecmp (string, "min"))         return (MAG_MIN);
     144  if (!strcasecmp (string, "max"))         return (MAG_MAX);
    89145  if (!strcasecmp (string, "ucdist"))      return (MAG_UC_DIST);
    90   if (!strcasecmp (string, "stackDetectID")) return (MAG_STACK_DET_ID);
    91146  if (!strcasecmp (string, "fluxpsf"))     return (MAG_FLUX_PSF);
    92147  if (!strcasecmp (string, "fluxpsferr"))  return (MAG_FLUX_PSF_ERR);
     
    95150  return (MAG_NONE);
    96151}
    97 
    98 PhotCode *ParsePhotcodeField (char *field, int *mode, int defMode) {
    99 
    100   int useDefault;
    101   char *tmpstring, *p;
    102   PhotCode *code;
    103 
    104   *mode = defMode;
    105   useDefault = TRUE;
    106 
    107   p = strchr (field, ':');
    108   if (p != NULL) {
    109     *mode = GetMagMode (p + 1);
    110     useDefault = FALSE;
    111     if (*mode == MAG_NONE) return (NULL);
    112     tmpstring = strncreate (field, p - field);
    113   } else {
    114     tmpstring = strcreate (field);
    115   }
    116   if (!strcasecmp (tmpstring, "MAG")) {
    117     ALLOCATE (code, PhotCode, 1);
    118     code[0].code = 0;
    119     strcpy (code[0].name, "MAG");
    120     code[0].type = PHOT_MAG;
    121     // the field call 'mag' is only valid for mextract
    122     // it should default to REL, but other types should default to AVE
    123     if (useDefault) {
    124       *mode = MAG_REL;
     152# endif
     153
     154// field may be of the form mag:psf:inst:wrp.  except for the first subword,
     155// the words may be in any order
     156int ParsePhotcodeField (dbField *field, char *fieldName, int fieldID) {
     157
     158  int j;
     159
     160  // defaults:
     161  field->ID = fieldID; // change if not true in the end?
     162
     163  // check what options are provided.  do not allow duplicate types
     164  // except mag and flux may exist with err
     165  dvoMagSourceType mySource = MAG_SRC_NONE;
     166  dvoMagLevelType myLevel = MAG_LEVEL_NONE;
     167  dvoMagClassType myClass = MAG_CLASS_NONE;
     168  dvoMagOptionType myOption = MAG_OPTION_NONE;
     169
     170  field->magSource = MAG_SRC_CHP;
     171  field->magLevel  = MAG_LEVEL_AVE;
     172  field->magClass  = MAG_CLASS_PSF;
     173  field->magOption = MAG_OPTION_MAG;
     174
     175  // make a local working copy of fieldName and replace ':' with spaces
     176  char *fieldCopy = strcreate(fieldName);
     177  for (j = 0; fieldCopy[j]; j++) {
     178    if (fieldCopy[j] == ':') fieldCopy[j] = ' ';
     179  }
     180
     181  char *firstWord = getword(fieldCopy);
     182 
     183  // firstWord may be either flux, mag or photcode
     184  if (!strcasecmp (firstWord, "MAG")) {
     185    // default level for 'mag' is rel
     186    field->magLevel  = MAG_LEVEL_REL;
     187    myOption = MAG_OPTION_MAG;
     188  }
     189  if (!strcasecmp (firstWord, "FLUX")) {
     190    // default level for 'flux' is rel
     191    field->magLevel  = MAG_LEVEL_REL;
     192    myOption = MAG_OPTION_FLUX;
     193  }
     194  PhotCode *code = GetPhotcodebyName (firstWord);
     195  free (firstWord);
     196
     197  if (!code) return FALSE;
     198
     199  // defaults for photcode clases
     200  if (code->type == PHOT_DEP) {
     201    field->magLevel = MAG_LEVEL_REL;
     202  }
     203  if (code->type == PHOT_SEC) {
     204    field->magLevel = MAG_LEVEL_AVE;
     205  }
     206  if (code->type == PHOT_REF) {
     207    field->magLevel = MAG_LEVEL_CAT;
     208    // is this one required?
     209  }
     210 
     211  // look at the remaining words and assign properties as approrpiate
     212  char *ptr = skipword(fieldCopy);
     213  while (ptr) {
     214
     215    char *word = getword(ptr);
     216    if (!word) break;
     217   
     218    dvoMagSourceType source = GetMagSource (word);
     219    if (source != MAG_SRC_NONE) {
     220      if (mySource != MAG_SRC_NONE) { fprintf (stderr, "invalid selection %s in %s\n", word, fieldName); free (word); return FALSE; }
     221      mySource = source;
     222      ptr = skipword (ptr);
     223      continue;
    125224    }
    126     free (tmpstring);
    127     return (code);
    128   }
    129   code = GetPhotcodebyName (tmpstring);
    130   if (!code) {
    131       return NULL;
    132   }
    133 
    134   // enforce compatibility
    135   if (useDefault) {
    136     if (code[0].type == PHOT_REF) {
    137       *mode = MAG_CAT;
     225
     226    dvoMagLevelType level = GetMagLevel (word);
     227    if (level != MAG_LEVEL_NONE) {
     228      if (myLevel != MAG_LEVEL_NONE) { fprintf (stderr, "invalid selection %s in %s\n", word, fieldName); free (word); return FALSE; }
     229      myLevel = level;
     230      ptr = skipword (ptr);
     231      continue;
    138232    }
    139     if (code[0].type == PHOT_DEP) {
    140       *mode = MAG_REL;
     233
     234    dvoMagClassType class = GetMagClass (word);
     235    if (class != MAG_CLASS_NONE) {
     236      if (myClass != MAG_CLASS_NONE) { fprintf (stderr, "invalid selection %s in %s\n", word, fieldName); free (word); return FALSE; }
     237      myClass = class;
     238      ptr = skipword (ptr);
     239      continue;
    141240    }
    142   }
    143   free (tmpstring);
    144   return (code);
    145 }
    146 
    147 # define ESCAPE(F,M,T) { \
    148   field->ID = (F); \
    149   field->magMode = (M); \
    150   field->type = (T); \
    151   field->photcode = NULL; \
    152   return (TRUE); }
    153 
    154 int ParseMeasureField (dbField *field, char *fieldName) {
    155 
    156   int mode;
    157   PhotCode *code;
    158 
    159   field->table = DVO_TABLE_MEASURE;
    160   field->name  = strcreate (fieldName);
    161 
    162   if (!strcasecmp (fieldName, "GLON"))       {
    163     dbExtractMeasuresInitTransform (COORD_GALACTIC);
    164     ESCAPE (MEAS_GLON, MAG_NONE, OPIHI_FLT);
    165   }
    166   if (!strcasecmp (fieldName, "GLAT")) {
    167     dbExtractMeasuresInitTransform (COORD_GALACTIC);
    168     ESCAPE (MEAS_GLAT, MAG_NONE, OPIHI_FLT);
    169   }
    170   if (!strcasecmp (fieldName, "GLON:AVE")) {
    171     dbExtractMeasuresInitTransform (COORD_GALACTIC);
    172     ESCAPE (MEAS_GLON_AVE, MAG_NONE, OPIHI_FLT);
    173   }
    174   if (!strcasecmp (fieldName, "GLAT:AVE")) {
    175     dbExtractMeasuresInitTransform (COORD_GALACTIC);
    176     ESCAPE (MEAS_GLAT_AVE, MAG_NONE, OPIHI_FLT);
    177   }
    178 
    179   if (!strcasecmp (fieldName, "ELON"))       {
    180     dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
    181     ESCAPE (MEAS_ELON, MAG_NONE, OPIHI_FLT);
    182   }
    183   if (!strcasecmp (fieldName, "ELAT")) {
    184     dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
    185     ESCAPE (MEAS_ELAT, MAG_NONE, OPIHI_FLT);
    186   }
    187   if (!strcasecmp (fieldName, "ELON:AVE")) {
    188     dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
    189     ESCAPE (MEAS_ELON_AVE, MAG_NONE, OPIHI_FLT);
    190   }
    191   if (!strcasecmp (fieldName, "ELAT:AVE")) {
    192     dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
    193     ESCAPE (MEAS_ELAT_AVE, MAG_NONE, OPIHI_FLT);
    194   }
    195 
    196   if (!strcasecmp (fieldName, "RA"))             ESCAPE (MEAS_RA,             MAG_NONE, OPIHI_FLT);
    197   if (!strcasecmp (fieldName, "DEC"))            ESCAPE (MEAS_DEC,            MAG_NONE, OPIHI_FLT);
    198   if (!strcasecmp (fieldName, "RA:AVE"))         ESCAPE (MEAS_RA_AVE,         MAG_NONE, OPIHI_FLT);
    199   if (!strcasecmp (fieldName, "DEC:AVE"))        ESCAPE (MEAS_DEC_AVE,        MAG_NONE, OPIHI_FLT);
    200   if (!strcasecmp (fieldName, "RA:ERR"))         ESCAPE (MEAS_RA_AVE_ERR,     MAG_NONE, OPIHI_FLT);
    201   if (!strcasecmp (fieldName, "DEC:ERR"))        ESCAPE (MEAS_DEC_AVE_ERR,    MAG_NONE, OPIHI_FLT);
    202   if (!strcasecmp (fieldName, "uRA"))            ESCAPE (MEAS_U_RA,           MAG_NONE, OPIHI_FLT);
    203   if (!strcasecmp (fieldName, "uDEC"))           ESCAPE (MEAS_U_DEC,          MAG_NONE, OPIHI_FLT);
    204   if (!strcasecmp (fieldName, "duRA"))           ESCAPE (MEAS_U_RA_ERR,       MAG_NONE, OPIHI_FLT);
    205   if (!strcasecmp (fieldName, "duDEC"))          ESCAPE (MEAS_U_DEC_ERR,      MAG_NONE, OPIHI_FLT);
    206   if (!strcasecmp (fieldName, "PAR"))            ESCAPE (MEAS_PAR,            MAG_NONE, OPIHI_FLT);
    207   if (!strcasecmp (fieldName, "dPAR"))           ESCAPE (MEAS_PAR_ERR,        MAG_NONE, OPIHI_FLT);
    208   if (!strcasecmp (fieldName, "dR"))             ESCAPE (MEAS_RA_OFFSET,      MAG_NONE, OPIHI_FLT);
    209   if (!strcasecmp (fieldName, "dD"))             ESCAPE (MEAS_DEC_OFFSET,     MAG_NONE, OPIHI_FLT);
    210   if (!strcasecmp (fieldName, "dR:FIT"))         ESCAPE (MEAS_RA_FIT_OFFSET,  MAG_NONE, OPIHI_FLT);
    211   if (!strcasecmp (fieldName, "dD:FIT"))         ESCAPE (MEAS_DEC_FIT_OFFSET, MAG_NONE, OPIHI_FLT);
    212   if (!strcasecmp (fieldName, "dR:ERR"))         ESCAPE (MEAS_RA_OFFSET_ERR,  MAG_NONE, OPIHI_FLT);
    213   if (!strcasecmp (fieldName, "dD:ERR"))         ESCAPE (MEAS_DEC_OFFSET_ERR, MAG_NONE, OPIHI_FLT);
    214   if (!strcasecmp (fieldName, "ChiSqPos"))       ESCAPE (MEAS_CHISQ_POS,      MAG_NONE, OPIHI_FLT);
    215   if (!strcasecmp (fieldName, "ChiSqPM"))        ESCAPE (MEAS_CHISQ_PM,       MAG_NONE, OPIHI_FLT);
    216   if (!strcasecmp (fieldName, "ChiSqPar"))       ESCAPE (MEAS_CHISQ_PAR,      MAG_NONE, OPIHI_FLT);
    217   if (!strcasecmp (fieldName, "Tmean"))          ESCAPE (MEAS_TMEAN,          MAG_NONE, OPIHI_FLT);
    218   if (!strcasecmp (fieldName, "Trange"))         ESCAPE (MEAS_TRANGE,         MAG_NONE, OPIHI_FLT);
    219   if (!strcasecmp (fieldName, "nmeas"))          ESCAPE (MEAS_NMEAS,          MAG_NONE, OPIHI_INT);
    220   if (!strcasecmp (fieldName, "nmiss"))          ESCAPE (MEAS_NMISS,          MAG_NONE, OPIHI_INT);
    221   if (!strcasecmp (fieldName, "npos"))           ESCAPE (MEAS_NPOS,           MAG_NONE, OPIHI_INT);
    222   if (!strcasecmp (fieldName, "OBJFLAGS"))       ESCAPE (MEAS_OBJ_FLAGS,      MAG_NONE, OPIHI_INT);
    223   if (!strcasecmp (fieldName, "OBJ_FLAGS"))      ESCAPE (MEAS_OBJ_FLAGS,      MAG_NONE, OPIHI_INT);
    224   if (!strcasecmp (fieldName, "OBJ_PHOT_FLAGS")) ESCAPE (MEAS_SECFILT_FLAGS,      MAG_NONE, OPIHI_INT);
    225   if (!strcasecmp (fieldName, "SECFLAGS"))       ESCAPE (MEAS_SECFILT_FLAGS,      MAG_NONE, OPIHI_INT);
    226   if (!strcasecmp (fieldName, "SEC_FLAGS"))      ESCAPE (MEAS_SECFILT_FLAGS,      MAG_NONE, OPIHI_INT);
    227   if (!strcasecmp (fieldName, "SECFILT_FLAGS"))  ESCAPE (MEAS_SECFILT_FLAGS,      MAG_NONE, OPIHI_INT);
    228   if (!strcasecmp (fieldName, "DB_FLAGS"))       ESCAPE (MEAS_DB_FLAGS,       MAG_NONE, OPIHI_INT);
    229   if (!strcasecmp (fieldName, "PHOT_FLAGS"))     ESCAPE (MEAS_PHOT_FLAGS,     MAG_NONE, OPIHI_INT);
    230   if (!strcasecmp (fieldName, "DBFLAGS"))        ESCAPE (MEAS_DB_FLAGS,       MAG_NONE, OPIHI_INT);
    231   if (!strcasecmp (fieldName, "PHOTFLAGS"))      ESCAPE (MEAS_PHOT_FLAGS,     MAG_NONE, OPIHI_INT);
    232   if (!strcasecmp (fieldName, "AIRMASS"))        ESCAPE (MEAS_AIRMASS,        MAG_NONE, OPIHI_FLT);
    233   if (!strcasecmp (fieldName, "MEAN_AIRMASS"))   ESCAPE (MEAS_MEAN_AIRMASS,   MAG_NONE, OPIHI_FLT);
    234   if (!strcasecmp (fieldName, "ALT"))            ESCAPE (MEAS_ALT,            MAG_NONE, OPIHI_FLT);
    235   if (!strcasecmp (fieldName, "AZ"))             ESCAPE (MEAS_AZ,             MAG_NONE, OPIHI_FLT);
    236   if (!strcasecmp (fieldName, "EXPTIME"))        ESCAPE (MEAS_EXPTIME,        MAG_NONE, OPIHI_FLT);
    237   if (!strcasecmp (fieldName, "PHOTCODE"))       ESCAPE (MEAS_PHOTCODE,       MAG_NONE, OPIHI_INT);
    238   if (!strcasecmp (fieldName, "PHOTCODE:KLAM"))  ESCAPE (MEAS_PHOTCODE_KLAM,  MAG_NONE, OPIHI_FLT);
    239   if (!strcasecmp (fieldName, "PHOTCODE:C"))     ESCAPE (MEAS_PHOTCODE_C,     MAG_NONE, OPIHI_FLT);
    240   if (!strcasecmp (fieldName, "PHOTCODE:EQUIV")) ESCAPE (MEAS_PHOTCODE_EQUIV, MAG_NONE, OPIHI_INT);
    241   if (!strcasecmp (fieldName, "TIME"))           ESCAPE (MEAS_TIME,           MAG_NONE, OPIHI_FLT);
    242   if (!strcasecmp (fieldName, "FWHM"))           ESCAPE (MEAS_FWHM,           MAG_NONE, OPIHI_FLT);
    243   if (!strcasecmp (fieldName, "FWHM_MAJ"))       ESCAPE (MEAS_FWHM_MAJ,       MAG_NONE, OPIHI_FLT);
    244   if (!strcasecmp (fieldName, "FWHM_MIN"))       ESCAPE (MEAS_FWHM_MIN,       MAG_NONE, OPIHI_FLT);
    245   if (!strcasecmp (fieldName, "THETA"))          ESCAPE (MEAS_THETA,          MAG_NONE, OPIHI_FLT);
    246   if (!strcasecmp (fieldName, "POSANGLE"))       ESCAPE (MEAS_POSANGLE,       MAG_NONE, OPIHI_FLT);
    247   if (!strcasecmp (fieldName, "PLATESCALE"))     ESCAPE (MEAS_PLATESCALE,     MAG_NONE, OPIHI_FLT);
    248   if (!strcasecmp (fieldName, "MXX"))            ESCAPE (MEAS_MXX,            MAG_NONE, OPIHI_FLT);
    249   if (!strcasecmp (fieldName, "MYY"))            ESCAPE (MEAS_MYY,            MAG_NONE, OPIHI_FLT);
    250   if (!strcasecmp (fieldName, "MXY"))            ESCAPE (MEAS_MXY,            MAG_NONE, OPIHI_FLT);
    251   if (!strcasecmp (fieldName, "DOPHOT"))         ESCAPE (MEAS_DOPHOT,         MAG_NONE, OPIHI_INT);
    252   if (!strcasecmp (fieldName, "XCCD"))           ESCAPE (MEAS_XCCD,           MAG_NONE, OPIHI_FLT);
    253   if (!strcasecmp (fieldName, "YCCD"))           ESCAPE (MEAS_YCCD,           MAG_NONE, OPIHI_FLT);
    254   if (!strcasecmp (fieldName, "XCCD:ERR"))       ESCAPE (MEAS_XCCD_ERR,       MAG_NONE, OPIHI_FLT);
    255   if (!strcasecmp (fieldName, "YCCD:ERR"))       ESCAPE (MEAS_YCCD_ERR,       MAG_NONE, OPIHI_FLT);
    256   if (!strcasecmp (fieldName, "XFIX"))           ESCAPE (MEAS_XFIX,           MAG_NONE, OPIHI_FLT);
    257   if (!strcasecmp (fieldName, "YFIX"))           ESCAPE (MEAS_YFIX,           MAG_NONE, OPIHI_FLT);
    258   if (!strcasecmp (fieldName, "POS_SYS_ERR"))    ESCAPE (MEAS_POS_SYS_ERR,    MAG_NONE, OPIHI_FLT);
    259   if (!strcasecmp (fieldName, "XFIELD"))         ESCAPE (MEAS_XFIELD,         MAG_NONE, OPIHI_FLT);
    260   if (!strcasecmp (fieldName, "YFIELD"))         ESCAPE (MEAS_YFIELD,         MAG_NONE, OPIHI_FLT);
    261   if (!strcasecmp (fieldName, "XMOSAIC"))        ESCAPE (MEAS_XMOSAIC,        MAG_NONE, OPIHI_FLT);
    262   if (!strcasecmp (fieldName, "YMOSAIC"))        ESCAPE (MEAS_YMOSAIC,        MAG_NONE, OPIHI_FLT);
    263   if (!strcasecmp (fieldName, "XCHIP"))          ESCAPE (MEAS_XCCD,           MAG_NONE, OPIHI_FLT);
    264   if (!strcasecmp (fieldName, "YCHIP"))          ESCAPE (MEAS_YCCD,           MAG_NONE, OPIHI_FLT);
    265   if (!strcasecmp (fieldName, "XFPA"))           ESCAPE (MEAS_XMOSAIC,        MAG_NONE, OPIHI_FLT);
    266   if (!strcasecmp (fieldName, "YFPA"))           ESCAPE (MEAS_YMOSAIC,        MAG_NONE, OPIHI_FLT);
    267   if (!strcasecmp (fieldName, "DETID"))          ESCAPE (MEAS_DET_ID,         MAG_NONE, OPIHI_INT);
    268   if (!strcasecmp (fieldName, "OBJID"))          ESCAPE (MEAS_OBJ_ID,         MAG_NONE, OPIHI_INT);
    269   if (!strcasecmp (fieldName, "CATID"))          ESCAPE (MEAS_CAT_ID,         MAG_NONE, OPIHI_INT);
    270   if (!strcasecmp (fieldName, "IMAGEID"))        ESCAPE (MEAS_IMAGE_ID,       MAG_NONE, OPIHI_INT);
    271   if (!strcasecmp (fieldName, "EXTERNID"))       ESCAPE (MEAS_EXTERN_ID,      MAG_NONE, OPIHI_INT);
    272   if (!strcasecmp (fieldName, "EXPNAME"))        ESCAPE (MEAS_EXPNAME_AS_INT, MAG_NONE, OPIHI_INT);
    273   if (!strcasecmp (fieldName, "PSF_QF"))         ESCAPE (MEAS_PSF_QF,         MAG_NONE, OPIHI_FLT);
    274   if (!strcasecmp (fieldName, "PSF_QF_PERFECT")) ESCAPE (MEAS_PSF_QF_PERFECT, MAG_NONE, OPIHI_FLT);
    275   if (!strcasecmp (fieldName, "PSF_CHISQ"))      ESCAPE (MEAS_PSF_CHISQ,      MAG_NONE, OPIHI_FLT);
    276   if (!strcasecmp (fieldName, "PSF_NDOF"))       ESCAPE (MEAS_PSF_NDOF,       MAG_NONE, OPIHI_INT);
    277   if (!strcasecmp (fieldName, "PSF_NPIX"))       ESCAPE (MEAS_PSF_NPIX,       MAG_NONE, OPIHI_INT);
    278   if (!strcasecmp (fieldName, "CR_NSIGMA"))      ESCAPE (MEAS_CR_NSIGMA,      MAG_NONE, OPIHI_FLT);
    279   if (!strcasecmp (fieldName, "EXT_NSIGMA"))     ESCAPE (MEAS_EXT_NSIGMA,     MAG_NONE, OPIHI_FLT);
    280   if (!strcasecmp (fieldName, "SKY"))            ESCAPE (MEAS_SKY,            MAG_NONE, OPIHI_FLT);
    281   if (!strcasecmp (fieldName, "SKY_ERR"))        ESCAPE (MEAS_dSKY,           MAG_NONE, OPIHI_FLT);
    282   if (!strcasecmp (fieldName, "MCAL_OFFSET"))    ESCAPE (MEAS_MCAL_OFFSET,    MAG_NONE, OPIHI_FLT);
    283   if (!strcasecmp (fieldName, "FLAT"))           ESCAPE (MEAS_FLAT,           MAG_NONE, OPIHI_FLT);
    284   if (!strcasecmp (fieldName, "CENTER_OFFSET"))  ESCAPE (MEAS_CENTER_OFFSET,  MAG_NONE, OPIHI_FLT);
    285   if (!strcasecmp (fieldName, "FLUX"))           ESCAPE (MEAS_FLUX_PSF,       MAG_NONE, OPIHI_FLT);
    286   if (!strcasecmp (fieldName, "FLUX_ERR"))       ESCAPE (MEAS_FLUX_PSF_ERR,   MAG_NONE, OPIHI_FLT);
    287   if (!strcasecmp (fieldName, "FLUX_PSF"))       ESCAPE (MEAS_FLUX_PSF,       MAG_NONE, OPIHI_FLT);
    288   if (!strcasecmp (fieldName, "FLUX_PSF_ERR"))   ESCAPE (MEAS_FLUX_PSF_ERR,   MAG_NONE, OPIHI_FLT);
    289   if (!strcasecmp (fieldName, "FLUX_KRON"))      ESCAPE (MEAS_FLUX_KRON,      MAG_NONE, OPIHI_FLT);
    290   if (!strcasecmp (fieldName, "FLUX_KRON_ERR"))  ESCAPE (MEAS_FLUX_KRON_ERR,  MAG_NONE, OPIHI_FLT);
    291 
    292   // for words that don't parse, try a photcode
    293 
    294   // check for code:mode in photcode name
    295   code = ParsePhotcodeField (fieldName, &mode, MAG_AVE);
    296   if (code == NULL) {
    297     gprint (GP_ERR, "unknown field '%s' for measurement table in DVO database\n", fieldName);
    298     return (FALSE);
    299   }
    300 
    301   field->ID = MEAS_MAG;
    302   field->magMode = mode;
    303   switch (mode) {
    304     case MAG_STACK_DET_ID:
    305     case MAG_NCODE:
    306     case MAG_NPHOT:
    307     case MAG_PHOT_FLAGS:
     241
     242    dvoMagOptionType option = GetMagOption (word);
     243    if (option != MAG_OPTION_NONE) {
     244      // some combinations are OK: mag + err -> err
     245      if ((myOption == MAG_OPTION_MAG) && (option == MAG_OPTION_ERR)) {
     246        myOption = option;
     247        ptr = skipword (ptr);
     248        continue;
     249      }
     250      // some combinations are OK: err + mag -> err
     251      if ((myOption == MAG_OPTION_ERR) && (option == MAG_OPTION_MAG)) {
     252        ptr = skipword (ptr);
     253        continue;
     254      }
     255      // some combinations are OK: flux + err -> FLUX_ERR
     256      if ((myOption == MAG_OPTION_FLUX) && (option == MAG_OPTION_ERR)) {
     257        myOption = MAG_OPTION_FLUX_ERR;
     258        ptr = skipword (ptr);
     259        continue;
     260      }
     261      // some combinations are OK: err + flux -> FLUX_ERR
     262      if ((myOption == MAG_OPTION_ERR) && (option == MAG_OPTION_FLUX)) {
     263        myOption = MAG_OPTION_FLUX_ERR;
     264        ptr = skipword (ptr);
     265        continue;
     266      }
     267      // some combinations are OK: flux + fluxerr -> FLUX_ERR
     268      if ((myOption == MAG_OPTION_FLUX) && (option == MAG_OPTION_FLUX_ERR)) {
     269        myOption = MAG_OPTION_FLUX_ERR;
     270        ptr = skipword (ptr);
     271        continue;
     272      }
     273      // some combinations are OK: fluxerr + flux -> FLUX_ERR
     274      if ((myOption == MAG_OPTION_FLUX_ERR) && (option == MAG_OPTION_FLUX)) {
     275        myOption = MAG_OPTION_FLUX_ERR;
     276        ptr = skipword (ptr);
     277        continue;
     278      }
     279      if (myOption != MAG_OPTION_NONE) { fprintf (stderr, "invalid selection %s in %s\n", word, fieldName); free (word); return FALSE; }
     280      myOption = option;
     281      ptr = skipword (ptr);
     282      continue;
     283    }
     284
     285    fprintf (stderr, "ERROR: unknown mag/photocode argument %s\n", word);
     286    free (word);
     287  }
     288
     289  // if nothing is provided, use the defaults
     290  field->magSource = (mySource == MAG_SRC_NONE)    ? field->magSource : mySource;
     291  field->magLevel  = (myLevel  == MAG_LEVEL_NONE)  ? field->magLevel  : myLevel;
     292  field->magClass  = (myClass  == MAG_CLASS_NONE)  ? field->magClass  : myClass;
     293  field->magOption = (myOption == MAG_OPTION_NONE) ? field->magOption : myOption;
     294
     295  switch (field->magOption) {
     296    case MAG_OPTION_NCODE:
     297    case MAG_OPTION_NPHOT:
     298    case MAG_OPTION_FLAGS:
    308299      field->type = OPIHI_INT;
    309300      break;
     
    313304  }
    314305  field->photcode = code;
     306  return TRUE;
     307}
     308
     309// field needs to be initialized with dbInitField()
     310# define ESCAPE(F,T) { \
     311  field->ID = (F); \
     312  field->type = (T); \
     313  return (TRUE); }
     314
     315int ParseMeasureField (dbField *field, char *fieldName) {
     316
     317  field->table = DVO_TABLE_MEASURE;
     318  field->name  = strcreate (fieldName);
     319
     320  if (!strcasecmp (fieldName, "GLON"))       {
     321    dbExtractMeasuresInitTransform (COORD_GALACTIC);
     322    ESCAPE (MEAS_GLON, OPIHI_FLT);
     323  }
     324  if (!strcasecmp (fieldName, "GLAT")) {
     325    dbExtractMeasuresInitTransform (COORD_GALACTIC);
     326    ESCAPE (MEAS_GLAT, OPIHI_FLT);
     327  }
     328  if (!strcasecmp (fieldName, "GLON:AVE")) {
     329    dbExtractMeasuresInitTransform (COORD_GALACTIC);
     330    ESCAPE (MEAS_GLON_AVE, OPIHI_FLT);
     331  }
     332  if (!strcasecmp (fieldName, "GLAT:AVE")) {
     333    dbExtractMeasuresInitTransform (COORD_GALACTIC);
     334    ESCAPE (MEAS_GLAT_AVE, OPIHI_FLT);
     335  }
     336
     337  if (!strcasecmp (fieldName, "ELON"))       {
     338    dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
     339    ESCAPE (MEAS_ELON, OPIHI_FLT);
     340  }
     341  if (!strcasecmp (fieldName, "ELAT")) {
     342    dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
     343    ESCAPE (MEAS_ELAT, OPIHI_FLT);
     344  }
     345  if (!strcasecmp (fieldName, "ELON:AVE")) {
     346    dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
     347    ESCAPE (MEAS_ELON_AVE, OPIHI_FLT);
     348  }
     349  if (!strcasecmp (fieldName, "ELAT:AVE")) {
     350    dbExtractMeasuresInitTransform (COORD_ECLIPTIC);
     351    ESCAPE (MEAS_ELAT_AVE, OPIHI_FLT);
     352  }
     353
     354  if (!strcasecmp (fieldName, "RA"))             ESCAPE (MEAS_RA,             OPIHI_FLT);
     355  if (!strcasecmp (fieldName, "DEC"))            ESCAPE (MEAS_DEC,            OPIHI_FLT);
     356  if (!strcasecmp (fieldName, "RA:AVE"))         ESCAPE (MEAS_RA_AVE,         OPIHI_FLT);
     357  if (!strcasecmp (fieldName, "DEC:AVE"))        ESCAPE (MEAS_DEC_AVE,        OPIHI_FLT);
     358  if (!strcasecmp (fieldName, "RA:ERR"))         ESCAPE (MEAS_RA_AVE_ERR,     OPIHI_FLT);
     359  if (!strcasecmp (fieldName, "DEC:ERR"))        ESCAPE (MEAS_DEC_AVE_ERR,    OPIHI_FLT);
     360  if (!strcasecmp (fieldName, "uRA"))            ESCAPE (MEAS_U_RA,           OPIHI_FLT);
     361  if (!strcasecmp (fieldName, "uDEC"))           ESCAPE (MEAS_U_DEC,          OPIHI_FLT);
     362  if (!strcasecmp (fieldName, "duRA"))           ESCAPE (MEAS_U_RA_ERR,       OPIHI_FLT);
     363  if (!strcasecmp (fieldName, "duDEC"))          ESCAPE (MEAS_U_DEC_ERR,      OPIHI_FLT);
     364  if (!strcasecmp (fieldName, "PAR"))            ESCAPE (MEAS_PAR,            OPIHI_FLT);
     365  if (!strcasecmp (fieldName, "dPAR"))           ESCAPE (MEAS_PAR_ERR,        OPIHI_FLT);
     366  if (!strcasecmp (fieldName, "dR"))             ESCAPE (MEAS_RA_OFFSET,      OPIHI_FLT);
     367  if (!strcasecmp (fieldName, "dD"))             ESCAPE (MEAS_DEC_OFFSET,     OPIHI_FLT);
     368  if (!strcasecmp (fieldName, "dR:FIT"))         ESCAPE (MEAS_RA_FIT_OFFSET,  OPIHI_FLT);
     369  if (!strcasecmp (fieldName, "dD:FIT"))         ESCAPE (MEAS_DEC_FIT_OFFSET, OPIHI_FLT);
     370  if (!strcasecmp (fieldName, "dR:ERR"))         ESCAPE (MEAS_RA_OFFSET_ERR,  OPIHI_FLT);
     371  if (!strcasecmp (fieldName, "dD:ERR"))         ESCAPE (MEAS_DEC_OFFSET_ERR, OPIHI_FLT);
     372  if (!strcasecmp (fieldName, "ChiSqPos"))       ESCAPE (MEAS_CHISQ_POS,      OPIHI_FLT);
     373  if (!strcasecmp (fieldName, "ChiSqPM"))        ESCAPE (MEAS_CHISQ_PM,       OPIHI_FLT);
     374  if (!strcasecmp (fieldName, "ChiSqPar"))       ESCAPE (MEAS_CHISQ_PAR,      OPIHI_FLT);
     375  if (!strcasecmp (fieldName, "Tmean"))          ESCAPE (MEAS_TMEAN,          OPIHI_FLT);
     376  if (!strcasecmp (fieldName, "Trange"))         ESCAPE (MEAS_TRANGE,         OPIHI_FLT);
     377  if (!strcasecmp (fieldName, "nmeas"))          ESCAPE (MEAS_NMEAS,          OPIHI_INT);
     378  if (!strcasecmp (fieldName, "nmiss"))          ESCAPE (MEAS_NMISS,          OPIHI_INT);
     379  if (!strcasecmp (fieldName, "npos"))           ESCAPE (MEAS_NPOS,           OPIHI_INT);
     380  if (!strcasecmp (fieldName, "OBJFLAGS"))       ESCAPE (MEAS_OBJ_FLAGS,      OPIHI_INT);
     381  if (!strcasecmp (fieldName, "OBJ_FLAGS"))      ESCAPE (MEAS_OBJ_FLAGS,      OPIHI_INT);
     382  if (!strcasecmp (fieldName, "OBJ_PHOT_FLAGS")) ESCAPE (MEAS_SECFILT_FLAGS,      OPIHI_INT);
     383  if (!strcasecmp (fieldName, "SECFLAGS"))       ESCAPE (MEAS_SECFILT_FLAGS,      OPIHI_INT);
     384  if (!strcasecmp (fieldName, "SEC_FLAGS"))      ESCAPE (MEAS_SECFILT_FLAGS,      OPIHI_INT);
     385  if (!strcasecmp (fieldName, "SECFILT_FLAGS"))  ESCAPE (MEAS_SECFILT_FLAGS,      OPIHI_INT);
     386  if (!strcasecmp (fieldName, "DB_FLAGS"))       ESCAPE (MEAS_DB_FLAGS,       OPIHI_INT);
     387  if (!strcasecmp (fieldName, "PHOT_FLAGS"))     ESCAPE (MEAS_PHOT_FLAGS,     OPIHI_INT);
     388  if (!strcasecmp (fieldName, "DBFLAGS"))        ESCAPE (MEAS_DB_FLAGS,       OPIHI_INT);
     389  if (!strcasecmp (fieldName, "PHOTFLAGS"))      ESCAPE (MEAS_PHOT_FLAGS,     OPIHI_INT);
     390  if (!strcasecmp (fieldName, "AIRMASS"))        ESCAPE (MEAS_AIRMASS,        OPIHI_FLT);
     391  if (!strcasecmp (fieldName, "MEAN_AIRMASS"))   ESCAPE (MEAS_MEAN_AIRMASS,   OPIHI_FLT);
     392  if (!strcasecmp (fieldName, "ALT"))            ESCAPE (MEAS_ALT,            OPIHI_FLT);
     393  if (!strcasecmp (fieldName, "AZ"))             ESCAPE (MEAS_AZ,             OPIHI_FLT);
     394  if (!strcasecmp (fieldName, "EXPTIME"))        ESCAPE (MEAS_EXPTIME,        OPIHI_FLT);
     395  if (!strcasecmp (fieldName, "PHOTCODE"))       ESCAPE (MEAS_PHOTCODE,       OPIHI_INT);
     396  if (!strcasecmp (fieldName, "PHOTCODE:KLAM"))  ESCAPE (MEAS_PHOTCODE_KLAM,  OPIHI_FLT);
     397  if (!strcasecmp (fieldName, "PHOTCODE:C"))     ESCAPE (MEAS_PHOTCODE_C,     OPIHI_FLT);
     398  if (!strcasecmp (fieldName, "PHOTCODE:EQUIV")) ESCAPE (MEAS_PHOTCODE_EQUIV, OPIHI_INT);
     399  if (!strcasecmp (fieldName, "TIME"))           ESCAPE (MEAS_TIME,           OPIHI_FLT);
     400  if (!strcasecmp (fieldName, "FWHM"))           ESCAPE (MEAS_FWHM,           OPIHI_FLT);
     401  if (!strcasecmp (fieldName, "FWHM_MAJ"))       ESCAPE (MEAS_FWHM_MAJ,       OPIHI_FLT);
     402  if (!strcasecmp (fieldName, "FWHM_MIN"))       ESCAPE (MEAS_FWHM_MIN,       OPIHI_FLT);
     403  if (!strcasecmp (fieldName, "THETA"))          ESCAPE (MEAS_THETA,          OPIHI_FLT);
     404  if (!strcasecmp (fieldName, "POSANGLE"))       ESCAPE (MEAS_POSANGLE,       OPIHI_FLT);
     405  if (!strcasecmp (fieldName, "PLATESCALE"))     ESCAPE (MEAS_PLATESCALE,     OPIHI_FLT);
     406  if (!strcasecmp (fieldName, "MXX"))            ESCAPE (MEAS_MXX,            OPIHI_FLT);
     407  if (!strcasecmp (fieldName, "MYY"))            ESCAPE (MEAS_MYY,            OPIHI_FLT);
     408  if (!strcasecmp (fieldName, "MXY"))            ESCAPE (MEAS_MXY,            OPIHI_FLT);
     409  if (!strcasecmp (fieldName, "DOPHOT"))         ESCAPE (MEAS_DOPHOT,         OPIHI_INT);
     410  if (!strcasecmp (fieldName, "XCCD"))           ESCAPE (MEAS_XCCD,           OPIHI_FLT);
     411  if (!strcasecmp (fieldName, "YCCD"))           ESCAPE (MEAS_YCCD,           OPIHI_FLT);
     412  if (!strcasecmp (fieldName, "XCCD:ERR"))       ESCAPE (MEAS_XCCD_ERR,       OPIHI_FLT);
     413  if (!strcasecmp (fieldName, "YCCD:ERR"))       ESCAPE (MEAS_YCCD_ERR,       OPIHI_FLT);
     414  if (!strcasecmp (fieldName, "XFIX"))           ESCAPE (MEAS_XFIX,           OPIHI_FLT);
     415  if (!strcasecmp (fieldName, "YFIX"))           ESCAPE (MEAS_YFIX,           OPIHI_FLT);
     416  if (!strcasecmp (fieldName, "POS_SYS_ERR"))    ESCAPE (MEAS_POS_SYS_ERR,    OPIHI_FLT);
     417  if (!strcasecmp (fieldName, "XFIELD"))         ESCAPE (MEAS_XFIELD,         OPIHI_FLT);
     418  if (!strcasecmp (fieldName, "YFIELD"))         ESCAPE (MEAS_YFIELD,         OPIHI_FLT);
     419  if (!strcasecmp (fieldName, "XMOSAIC"))        ESCAPE (MEAS_XMOSAIC,        OPIHI_FLT);
     420  if (!strcasecmp (fieldName, "YMOSAIC"))        ESCAPE (MEAS_YMOSAIC,        OPIHI_FLT);
     421  if (!strcasecmp (fieldName, "XCHIP"))          ESCAPE (MEAS_XCCD,           OPIHI_FLT);
     422  if (!strcasecmp (fieldName, "YCHIP"))          ESCAPE (MEAS_YCCD,           OPIHI_FLT);
     423  if (!strcasecmp (fieldName, "XFPA"))           ESCAPE (MEAS_XMOSAIC,        OPIHI_FLT);
     424  if (!strcasecmp (fieldName, "YFPA"))           ESCAPE (MEAS_YMOSAIC,        OPIHI_FLT);
     425  if (!strcasecmp (fieldName, "DETID"))          ESCAPE (MEAS_DET_ID,         OPIHI_INT);
     426  if (!strcasecmp (fieldName, "OBJID"))          ESCAPE (MEAS_OBJ_ID,         OPIHI_INT);
     427  if (!strcasecmp (fieldName, "CATID"))          ESCAPE (MEAS_CAT_ID,         OPIHI_INT);
     428  if (!strcasecmp (fieldName, "IMAGEID"))        ESCAPE (MEAS_IMAGE_ID,       OPIHI_INT);
     429  if (!strcasecmp (fieldName, "EXTERNID"))       ESCAPE (MEAS_EXTERN_ID,      OPIHI_INT);
     430  if (!strcasecmp (fieldName, "EXPNAME"))        ESCAPE (MEAS_EXPNAME_AS_INT, OPIHI_INT);
     431  if (!strcasecmp (fieldName, "PSF_QF"))         ESCAPE (MEAS_PSF_QF,         OPIHI_FLT);
     432  if (!strcasecmp (fieldName, "PSF_QF_PERFECT")) ESCAPE (MEAS_PSF_QF_PERFECT, OPIHI_FLT);
     433  if (!strcasecmp (fieldName, "PSF_CHISQ"))      ESCAPE (MEAS_PSF_CHISQ,      OPIHI_FLT);
     434  if (!strcasecmp (fieldName, "PSF_NDOF"))       ESCAPE (MEAS_PSF_NDOF,       OPIHI_INT);
     435  if (!strcasecmp (fieldName, "PSF_NPIX"))       ESCAPE (MEAS_PSF_NPIX,       OPIHI_INT);
     436  if (!strcasecmp (fieldName, "CR_NSIGMA"))      ESCAPE (MEAS_CR_NSIGMA,      OPIHI_FLT);
     437  if (!strcasecmp (fieldName, "EXT_NSIGMA"))     ESCAPE (MEAS_EXT_NSIGMA,     OPIHI_FLT);
     438  if (!strcasecmp (fieldName, "SKY"))            ESCAPE (MEAS_SKY,            OPIHI_FLT);
     439  if (!strcasecmp (fieldName, "SKY_ERR"))        ESCAPE (MEAS_dSKY,           OPIHI_FLT);
     440  if (!strcasecmp (fieldName, "MCAL_OFFSET"))    ESCAPE (MEAS_MCAL_OFFSET,    OPIHI_FLT);
     441  if (!strcasecmp (fieldName, "FLAT"))           ESCAPE (MEAS_FLAT,           OPIHI_FLT);
     442  if (!strcasecmp (fieldName, "CENTER_OFFSET"))  ESCAPE (MEAS_CENTER_OFFSET,  OPIHI_FLT);
     443  // if (!strcasecmp (fieldName, "FLUX"))                ESCAPE (MEAS_FLUX_PSF,       OPIHI_FLT);
     444  // if (!strcasecmp (fieldName, "FLUX_ERR"))       ESCAPE (MEAS_FLUX_PSF_ERR,   OPIHI_FLT);
     445  // if (!strcasecmp (fieldName, "FLUX_PSF"))       ESCAPE (MEAS_FLUX_PSF,       OPIHI_FLT);
     446  // if (!strcasecmp (fieldName, "FLUX_PSF_ERR"))   ESCAPE (MEAS_FLUX_PSF_ERR,   OPIHI_FLT);
     447  // if (!strcasecmp (fieldName, "FLUX_KRON"))      ESCAPE (MEAS_FLUX_KRON,      OPIHI_FLT);
     448  // if (!strcasecmp (fieldName, "FLUX_KRON_ERR"))  ESCAPE (MEAS_FLUX_KRON_ERR,  OPIHI_FLT);
     449  if (!strcasecmp (fieldName, "REF_COLOR"))      ESCAPE (MEAS_REF_COLOR,      OPIHI_FLT);
     450
     451  // for words that don't parse, try a photcode
     452
     453  // check for code:mode in photcode name
     454  if (!ParsePhotcodeField (field, fieldName, MEAS_PHOT)) {
     455    gprint (GP_ERR, "unknown field '%s' for measurement table in DVO database\n", fieldName);
     456    return (FALSE);
     457  }
     458
    315459  return (TRUE);
    316460}
    317461
    318462int ParseAverageField (dbField *field, char *fieldName) {
    319 
    320   int mode;
    321   PhotCode *code;
    322463
    323464  field->table = DVO_TABLE_AVERAGE;
     
    328469  if (!strcasecmp (fieldName, "GLON"))  {
    329470    dbExtractAveragesInitTransform (COORD_GALACTIC);
    330     ESCAPE (AVE_GLON, MAG_NONE, OPIHI_FLT);
     471    ESCAPE (AVE_GLON, OPIHI_FLT);
    331472  }
    332473  if (!strcasecmp (fieldName, "GLAT"))  {
    333474    dbExtractAveragesInitTransform (COORD_GALACTIC);
    334     ESCAPE (AVE_GLAT, MAG_NONE, OPIHI_FLT);
     475    ESCAPE (AVE_GLAT, OPIHI_FLT);
    335476  }
    336477
     
    339480  if (!strcasecmp (fieldName, "ELON"))  {
    340481    dbExtractAveragesInitTransform (COORD_ECLIPTIC);
    341     ESCAPE (AVE_ELON, MAG_NONE, OPIHI_FLT);
     482    ESCAPE (AVE_ELON, OPIHI_FLT);
    342483  }
    343484  if (!strcasecmp (fieldName, "ELAT"))  {
    344485    dbExtractAveragesInitTransform (COORD_ECLIPTIC);
    345     ESCAPE (AVE_ELAT, MAG_NONE, OPIHI_FLT);
    346   }
    347 
    348   if (!strcasecmp (fieldName, "RA"))          ESCAPE (AVE_RA,          MAG_NONE, OPIHI_FLT);
    349   if (!strcasecmp (fieldName, "DEC"))         ESCAPE (AVE_DEC,         MAG_NONE, OPIHI_FLT);
    350   if (!strcasecmp (fieldName, "GLON"))        ESCAPE (AVE_GLON,        MAG_NONE, OPIHI_FLT);
    351   if (!strcasecmp (fieldName, "GLAT"))        ESCAPE (AVE_GLAT,        MAG_NONE, OPIHI_FLT);
    352   if (!strcasecmp (fieldName, "ELON"))        ESCAPE (AVE_ELON,        MAG_NONE, OPIHI_FLT);
    353   if (!strcasecmp (fieldName, "ELAT"))        ESCAPE (AVE_ELAT,        MAG_NONE, OPIHI_FLT);
    354   if (!strcasecmp (fieldName, "dRA"))         ESCAPE (AVE_RA_ERR,      MAG_NONE, OPIHI_FLT);
    355   if (!strcasecmp (fieldName, "dDEC"))        ESCAPE (AVE_DEC_ERR,     MAG_NONE, OPIHI_FLT);
    356   if (!strcasecmp (fieldName, "uRA"))         ESCAPE (AVE_U_RA,        MAG_NONE, OPIHI_FLT);
    357   if (!strcasecmp (fieldName, "uDEC"))        ESCAPE (AVE_U_DEC,       MAG_NONE, OPIHI_FLT);
    358   if (!strcasecmp (fieldName, "duRA"))        ESCAPE (AVE_U_RA_ERR,    MAG_NONE, OPIHI_FLT);
    359   if (!strcasecmp (fieldName, "duDEC"))       ESCAPE (AVE_U_DEC_ERR,   MAG_NONE, OPIHI_FLT);
    360   if (!strcasecmp (fieldName, "PAR"))         ESCAPE (AVE_PAR,         MAG_NONE, OPIHI_FLT);
    361   if (!strcasecmp (fieldName, "dPAR"))        ESCAPE (AVE_PAR_ERR,     MAG_NONE, OPIHI_FLT);
    362   if (!strcasecmp (fieldName, "ChiSqPos"))    ESCAPE (AVE_CHISQ_POS,   MAG_NONE, OPIHI_FLT);
    363   if (!strcasecmp (fieldName, "ChiSqPM"))     ESCAPE (AVE_CHISQ_PM,    MAG_NONE, OPIHI_FLT);
    364   if (!strcasecmp (fieldName, "ChiSqPar"))    ESCAPE (AVE_CHISQ_PAR,   MAG_NONE, OPIHI_FLT);
    365   if (!strcasecmp (fieldName, "Tmean"))       ESCAPE (AVE_TMEAN,       MAG_NONE, OPIHI_FLT);
    366   if (!strcasecmp (fieldName, "Trange"))      ESCAPE (AVE_TRANGE,      MAG_NONE, OPIHI_FLT);
    367   if (!strcasecmp (fieldName, "psfqf"))       ESCAPE (AVE_PSF_QF,      MAG_NONE, OPIHI_FLT);
    368   if (!strcasecmp (fieldName, "psfqfperf"))   ESCAPE (AVE_PSF_QF_PERF, MAG_NONE, OPIHI_FLT);
    369   if (!strcasecmp (fieldName, "psf_qf"))      ESCAPE (AVE_PSF_QF,      MAG_NONE, OPIHI_FLT);
    370   if (!strcasecmp (fieldName, "psf_qf_perf")) ESCAPE (AVE_PSF_QF_PERF, MAG_NONE, OPIHI_FLT);
    371   if (!strcasecmp (fieldName, "stargal"))     ESCAPE (AVE_STARGAL,     MAG_NONE, OPIHI_FLT);
    372   if (!strcasecmp (fieldName, "NMEAS"))       ESCAPE (AVE_NMEAS,       MAG_NONE, OPIHI_INT);
    373   if (!strcasecmp (fieldName, "NMISS"))       ESCAPE (AVE_NMISS,       MAG_NONE, OPIHI_INT);
    374   if (!strcasecmp (fieldName, "NPOS"))        ESCAPE (AVE_NPOS,        MAG_NONE, OPIHI_INT);
    375   if (!strcasecmp (fieldName, "NASTROM"))     ESCAPE (AVE_NPOS,        MAG_NONE, OPIHI_INT);
    376   if (!strcasecmp (fieldName, "FLAGS"))       ESCAPE (AVE_OBJ_FLAGS,   MAG_NONE, OPIHI_INT);
    377   if (!strcasecmp (fieldName, "OBJ_FLAGS"))   ESCAPE (AVE_OBJ_FLAGS,   MAG_NONE, OPIHI_INT);
    378   if (!strcasecmp (fieldName, "OBJFLAGS"))    ESCAPE (AVE_OBJ_FLAGS,   MAG_NONE, OPIHI_INT);
    379   if (!strcasecmp (fieldName, "OBJID"))       ESCAPE (AVE_OBJID,       MAG_NONE, OPIHI_INT);
    380   if (!strcasecmp (fieldName, "CATID"))       ESCAPE (AVE_CATID,       MAG_NONE, OPIHI_INT);
    381   if (!strcasecmp (fieldName, "EXTID_HI"))    ESCAPE (AVE_EXTID_HI,    MAG_NONE, OPIHI_INT);
    382   if (!strcasecmp (fieldName, "EXTID_LO"))    ESCAPE (AVE_EXTID_LO,    MAG_NONE, OPIHI_INT);
     486    ESCAPE (AVE_ELAT, OPIHI_FLT);
     487  }
     488
     489  if (!strcasecmp (fieldName, "RA"))          ESCAPE (AVE_RA,          OPIHI_FLT);
     490  if (!strcasecmp (fieldName, "DEC"))         ESCAPE (AVE_DEC,         OPIHI_FLT);
     491  if (!strcasecmp (fieldName, "GLON"))        ESCAPE (AVE_GLON,        OPIHI_FLT);
     492  if (!strcasecmp (fieldName, "GLAT"))        ESCAPE (AVE_GLAT,        OPIHI_FLT);
     493  if (!strcasecmp (fieldName, "ELON"))        ESCAPE (AVE_ELON,        OPIHI_FLT);
     494  if (!strcasecmp (fieldName, "ELAT"))        ESCAPE (AVE_ELAT,        OPIHI_FLT);
     495  if (!strcasecmp (fieldName, "dRA"))         ESCAPE (AVE_RA_ERR,      OPIHI_FLT);
     496  if (!strcasecmp (fieldName, "dDEC"))        ESCAPE (AVE_DEC_ERR,     OPIHI_FLT);
     497  if (!strcasecmp (fieldName, "uRA"))         ESCAPE (AVE_U_RA,        OPIHI_FLT);
     498  if (!strcasecmp (fieldName, "uDEC"))        ESCAPE (AVE_U_DEC,       OPIHI_FLT);
     499  if (!strcasecmp (fieldName, "duRA"))        ESCAPE (AVE_U_RA_ERR,    OPIHI_FLT);
     500  if (!strcasecmp (fieldName, "duDEC"))       ESCAPE (AVE_U_DEC_ERR,   OPIHI_FLT);
     501  if (!strcasecmp (fieldName, "PAR"))         ESCAPE (AVE_PAR,         OPIHI_FLT);
     502  if (!strcasecmp (fieldName, "dPAR"))        ESCAPE (AVE_PAR_ERR,     OPIHI_FLT);
     503  if (!strcasecmp (fieldName, "ChiSqPos"))    ESCAPE (AVE_CHISQ_POS,   OPIHI_FLT);
     504  if (!strcasecmp (fieldName, "ChiSqPM"))     ESCAPE (AVE_CHISQ_PM,    OPIHI_FLT);
     505  if (!strcasecmp (fieldName, "ChiSqPar"))    ESCAPE (AVE_CHISQ_PAR,   OPIHI_FLT);
     506  if (!strcasecmp (fieldName, "Tmean"))       ESCAPE (AVE_TMEAN,       OPIHI_FLT);
     507  if (!strcasecmp (fieldName, "Trange"))      ESCAPE (AVE_TRANGE,      OPIHI_FLT);
     508  if (!strcasecmp (fieldName, "psfqf"))       ESCAPE (AVE_PSF_QF,      OPIHI_FLT);
     509  if (!strcasecmp (fieldName, "psfqfperf"))   ESCAPE (AVE_PSF_QF_PERF, OPIHI_FLT);
     510  if (!strcasecmp (fieldName, "psf_qf"))      ESCAPE (AVE_PSF_QF,      OPIHI_FLT);
     511  if (!strcasecmp (fieldName, "psf_qf_perf")) ESCAPE (AVE_PSF_QF_PERF, OPIHI_FLT);
     512  if (!strcasecmp (fieldName, "stargal"))     ESCAPE (AVE_STARGAL,     OPIHI_FLT);
     513  if (!strcasecmp (fieldName, "NMEAS"))       ESCAPE (AVE_NMEAS,       OPIHI_INT);
     514  if (!strcasecmp (fieldName, "NMISS"))       ESCAPE (AVE_NMISS,       OPIHI_INT);
     515  if (!strcasecmp (fieldName, "NPOS"))        ESCAPE (AVE_NPOS,        OPIHI_INT);
     516  if (!strcasecmp (fieldName, "NASTROM"))     ESCAPE (AVE_NPOS,        OPIHI_INT);
     517  if (!strcasecmp (fieldName, "FLAGS"))       ESCAPE (AVE_OBJ_FLAGS,   OPIHI_INT);
     518  if (!strcasecmp (fieldName, "OBJ_FLAGS"))   ESCAPE (AVE_OBJ_FLAGS,   OPIHI_INT);
     519  if (!strcasecmp (fieldName, "OBJFLAGS"))    ESCAPE (AVE_OBJ_FLAGS,   OPIHI_INT);
     520  if (!strcasecmp (fieldName, "OBJID"))       ESCAPE (AVE_OBJID,       OPIHI_INT);
     521  if (!strcasecmp (fieldName, "CATID"))       ESCAPE (AVE_CATID,       OPIHI_INT);
     522  if (!strcasecmp (fieldName, "EXTID_HI"))    ESCAPE (AVE_EXTID_HI,    OPIHI_INT);
     523  if (!strcasecmp (fieldName, "EXTID_LO"))    ESCAPE (AVE_EXTID_LO,    OPIHI_INT);
     524  if (!strcasecmp (fieldName, "REF_COLOR"))   ESCAPE (AVE_REF_COLOR,   OPIHI_FLT);
    383525
    384526  // check for code:mode in photcode name
    385   code = ParsePhotcodeField (fieldName, &mode, MAG_AVE);
    386   if (code == NULL) {
     527  if (!ParsePhotcodeField (field, fieldName, AVE_PHOT)) {
    387528    gprint (GP_ERR, "unknown field '%s' for average table in DVO database\n", fieldName);
    388529    return (FALSE);
    389530  }
    390531
    391   if (code[0].type == PHOT_MAG) {
     532  if (field->photcode->type == PHOT_MAG) {
    392533    gprint (GP_ERR, "'mag' is ambiguous for avextract\n");
    393     free (code);
    394534    return (FALSE);
    395535  }
    396536
    397   field->ID = AVE_MAG;
    398   field->magMode = mode;
    399   switch (mode) {
    400     case MAG_STACK_DET_ID:
    401     case MAG_NCODE:
    402     case MAG_NPHOT:
    403     case MAG_PHOT_FLAGS:
    404       field->type = OPIHI_INT;
    405       break;
    406     default:
    407       field->type = OPIHI_FLT;
    408       break;
    409   }
    410   field->photcode = code;
    411537  return (TRUE);
    412538}
     
    422548  if (!strcasecmp (fieldName, "GLON"))  {
    423549    dbExtractImagesInitTransform (COORD_GALACTIC);
    424     ESCAPE (IMAGE_GLON, MAG_NONE, OPIHI_FLT);
     550    ESCAPE (IMAGE_GLON, OPIHI_FLT);
    425551  }
    426552  if (!strcasecmp (fieldName, "GLAT"))  {
    427553    dbExtractImagesInitTransform (COORD_GALACTIC);
    428     ESCAPE (IMAGE_GLAT, MAG_NONE, OPIHI_FLT);
     554    ESCAPE (IMAGE_GLAT, OPIHI_FLT);
    429555  }
    430556
     
    433559  if (!strcasecmp (fieldName, "ELON"))  {
    434560    dbExtractImagesInitTransform (COORD_ECLIPTIC);
    435     ESCAPE (IMAGE_ELON, MAG_NONE, OPIHI_FLT);
     561    ESCAPE (IMAGE_ELON, OPIHI_FLT);
    436562  }
    437563  if (!strcasecmp (fieldName, "ELAT"))  {
    438564    dbExtractImagesInitTransform (COORD_ECLIPTIC);
    439     ESCAPE (IMAGE_ELAT, MAG_NONE, OPIHI_FLT);
    440   }
    441 
    442   if (!strcasecmp (fieldName, "RA"       )) ESCAPE (IMAGE_RA,        MAG_NONE, OPIHI_FLT);
    443   if (!strcasecmp (fieldName, "DEC"      )) ESCAPE (IMAGE_DEC,       MAG_NONE, OPIHI_FLT);
    444   if (!strcasecmp (fieldName, "GLON"     )) ESCAPE (IMAGE_GLON,      MAG_NONE, OPIHI_FLT);
    445   if (!strcasecmp (fieldName, "GLAT"     )) ESCAPE (IMAGE_GLAT,      MAG_NONE, OPIHI_FLT);
    446   if (!strcasecmp (fieldName, "ELON"     )) ESCAPE (IMAGE_ELON,      MAG_NONE, OPIHI_FLT);
    447   if (!strcasecmp (fieldName, "ELAT"     )) ESCAPE (IMAGE_ELAT,      MAG_NONE, OPIHI_FLT);
    448 
    449   if (!strcasecmp (fieldName, "theta"    )) ESCAPE (IMAGE_THETA,     MAG_NONE, OPIHI_FLT);
    450   if (!strcasecmp (fieldName, "skew"     )) ESCAPE (IMAGE_SKEW,      MAG_NONE, OPIHI_FLT);
    451   if (!strcasecmp (fieldName, "scale"    )) ESCAPE (IMAGE_SCALE,     MAG_NONE, OPIHI_FLT);
    452   if (!strcasecmp (fieldName, "dscale"   )) ESCAPE (IMAGE_DSCALE,    MAG_NONE, OPIHI_FLT);
    453 
    454   if (!strcasecmp (fieldName, "time"     )) ESCAPE (IMAGE_TIME,      MAG_NONE, OPIHI_FLT);
    455   if (!strcasecmp (fieldName, "nstar"    )) ESCAPE (IMAGE_NSTAR,     MAG_NONE, OPIHI_INT);
    456   if (!strcasecmp (fieldName, "airmass"  )) ESCAPE (IMAGE_AIRMASS,   MAG_NONE, OPIHI_FLT);
    457   if (!strcasecmp (fieldName, "NX"       )) ESCAPE (IMAGE_NX_PIX,    MAG_NONE, OPIHI_INT);
    458   if (!strcasecmp (fieldName, "NY"       )) ESCAPE (IMAGE_NY_PIX,    MAG_NONE, OPIHI_INT);
    459   if (!strcasecmp (fieldName, "apresid"  )) ESCAPE (IMAGE_APRESID,   MAG_NONE, OPIHI_FLT);
    460   if (!strcasecmp (fieldName, "dapresid" )) ESCAPE (IMAGE_DAPRESID,  MAG_NONE, OPIHI_FLT);
    461 
    462   if (!strcasecmp (fieldName, "Mcal"     )) ESCAPE (IMAGE_MCAL,      MAG_NONE, OPIHI_FLT);
    463   if (!strcasecmp (fieldName, "dMcal"    )) ESCAPE (IMAGE_dMCAL,     MAG_NONE, OPIHI_FLT);
    464   if (!strcasecmp (fieldName, "Xm"       )) ESCAPE (IMAGE_XM,        MAG_NONE, OPIHI_FLT);
    465   if (!strcasecmp (fieldName, "photcode" )) ESCAPE (IMAGE_PHOTCODE,  MAG_NONE, OPIHI_INT);
    466   if (!strcasecmp (fieldName, "exptime"  )) ESCAPE (IMAGE_EXPTIME,   MAG_NONE, OPIHI_FLT);
    467   if (!strcasecmp (fieldName, "sidtime"  )) ESCAPE (IMAGE_SIDTIME,   MAG_NONE, OPIHI_FLT);
    468 
    469   if (!strcasecmp (fieldName, "latitude" )) ESCAPE (IMAGE_LATITUDE,  MAG_NONE, OPIHI_FLT);
    470 
    471   if (!strcasecmp (fieldName, "detlimit" )) ESCAPE (IMAGE_DET_LIMIT, MAG_NONE, OPIHI_FLT);
    472   if (!strcasecmp (fieldName, "satlimit" )) ESCAPE (IMAGE_SAT_LIMIT, MAG_NONE, OPIHI_FLT);
    473   if (!strcasecmp (fieldName, "cerror"   )) ESCAPE (IMAGE_CERROR,    MAG_NONE, OPIHI_FLT);
    474 
    475   if (!strcasecmp (fieldName, "FWHM"       )) ESCAPE (IMAGE_FWHM,      MAG_NONE, OPIHI_FLT);
    476   if (!strcasecmp (fieldName, "FWHM_MAJ"   )) ESCAPE (IMAGE_FWHM_MAJ,  MAG_NONE, OPIHI_FLT);
    477   if (!strcasecmp (fieldName, "FWHM_MIN"   )) ESCAPE (IMAGE_FWHM_MIN,  MAG_NONE, OPIHI_FLT);
    478   if (!strcasecmp (fieldName, "FWHM_MAJOR" )) ESCAPE (IMAGE_FWHM_MAJ,  MAG_NONE, OPIHI_FLT);
    479   if (!strcasecmp (fieldName, "FWHM_MINOR" )) ESCAPE (IMAGE_FWHM_MIN,  MAG_NONE, OPIHI_FLT);
    480 
    481   if (!strcasecmp (fieldName, "FWHM_MEDIAN"    ))   ESCAPE (IMAGE_FWHM_MEDIAN,      MAG_NONE, OPIHI_FLT);
    482   if (!strcasecmp (fieldName, "FWHM_MAJ_MEDIAN"))   ESCAPE (IMAGE_FWHM_MAJ_MEDIAN,  MAG_NONE, OPIHI_FLT);
    483   if (!strcasecmp (fieldName, "FWHM_MIN_MEDIAN"))   ESCAPE (IMAGE_FWHM_MIN_MEDIAN,  MAG_NONE, OPIHI_FLT);
    484   if (!strcasecmp (fieldName, "FWHM_MAJOR_MEDIAN")) ESCAPE (IMAGE_FWHM_MAJ_MEDIAN,  MAG_NONE, OPIHI_FLT);
    485   if (!strcasecmp (fieldName, "FWHM_MINOR_MEDIAN")) ESCAPE (IMAGE_FWHM_MIN_MEDIAN,  MAG_NONE, OPIHI_FLT);
    486 
    487   if (!strcasecmp (fieldName, "trate"    )) ESCAPE (IMAGE_TRATE,     MAG_NONE, OPIHI_FLT);
    488 
    489   if (!strcasecmp (fieldName, "ncal"     )) ESCAPE (IMAGE_NCAL,      MAG_NONE, OPIHI_INT);
    490   if (!strcasecmp (fieldName, "sky"      )) ESCAPE (IMAGE_SKY,       MAG_NONE, OPIHI_FLT); // deprecated for now
    491 
    492   if (!strcasecmp (fieldName, "imflags"  )) ESCAPE (IMAGE_FLAGS,     MAG_NONE, OPIHI_INT);
    493   if (!strcasecmp (fieldName, "flags"    )) ESCAPE (IMAGE_FLAGS,     MAG_NONE, OPIHI_INT);
    494   if (!strcasecmp (fieldName, "ccdnum"   )) ESCAPE (IMAGE_CCDNUM,    MAG_NONE, OPIHI_INT);
    495 
    496   if (!strcasecmp (fieldName, "imageID"  )) ESCAPE (IMAGE_IMAGE_ID,  MAG_NONE, OPIHI_INT);
    497   if (!strcasecmp (fieldName, "externID" )) ESCAPE (IMAGE_EXTERN_ID, MAG_NONE, OPIHI_INT);
    498   if (!strcasecmp (fieldName, "sourceID" )) ESCAPE (IMAGE_SOURCE_ID, MAG_NONE, OPIHI_INT);
    499 
    500   if (!strcasecmp (fieldName, "X_LL_CHIP")) ESCAPE (IMAGE_X_LL_CHIP, MAG_NONE, OPIHI_FLT);
    501   if (!strcasecmp (fieldName, "X_LR_CHIP")) ESCAPE (IMAGE_X_LR_CHIP, MAG_NONE, OPIHI_FLT);
    502   if (!strcasecmp (fieldName, "X_UL_CHIP")) ESCAPE (IMAGE_X_UL_CHIP, MAG_NONE, OPIHI_FLT);
    503   if (!strcasecmp (fieldName, "X_UR_CHIP")) ESCAPE (IMAGE_X_UR_CHIP, MAG_NONE, OPIHI_FLT);
    504   if (!strcasecmp (fieldName, "Y_LL_CHIP")) ESCAPE (IMAGE_Y_LL_CHIP, MAG_NONE, OPIHI_FLT);
    505   if (!strcasecmp (fieldName, "Y_LR_CHIP")) ESCAPE (IMAGE_Y_LR_CHIP, MAG_NONE, OPIHI_FLT);
    506   if (!strcasecmp (fieldName, "Y_UL_CHIP")) ESCAPE (IMAGE_Y_UL_CHIP, MAG_NONE, OPIHI_FLT);
    507   if (!strcasecmp (fieldName, "Y_UR_CHIP")) ESCAPE (IMAGE_Y_UR_CHIP, MAG_NONE, OPIHI_FLT);
    508   if (!strcasecmp (fieldName, "X_LL_FP"  )) ESCAPE (IMAGE_X_LL_FP,   MAG_NONE, OPIHI_FLT);
    509   if (!strcasecmp (fieldName, "X_LR_FP"  )) ESCAPE (IMAGE_X_LR_FP,   MAG_NONE, OPIHI_FLT);
    510   if (!strcasecmp (fieldName, "X_UL_FP"  )) ESCAPE (IMAGE_X_UL_FP,   MAG_NONE, OPIHI_FLT);
    511   if (!strcasecmp (fieldName, "X_UR_FP"  )) ESCAPE (IMAGE_X_UR_FP,   MAG_NONE, OPIHI_FLT);
    512   if (!strcasecmp (fieldName, "Y_LL_FP"  )) ESCAPE (IMAGE_Y_LL_FP,   MAG_NONE, OPIHI_FLT);
    513   if (!strcasecmp (fieldName, "Y_LR_FP"  )) ESCAPE (IMAGE_Y_LR_FP,   MAG_NONE, OPIHI_FLT);
    514   if (!strcasecmp (fieldName, "Y_UL_FP"  )) ESCAPE (IMAGE_Y_UL_FP,   MAG_NONE, OPIHI_FLT);
    515   if (!strcasecmp (fieldName, "Y_UR_FP"  )) ESCAPE (IMAGE_Y_UR_FP,   MAG_NONE, OPIHI_FLT);
    516 
    517   if (!strcasecmp (fieldName, "dX_SYS"  )) ESCAPE (IMAGE_X_ERR_SYS,  MAG_NONE, OPIHI_FLT);
    518   if (!strcasecmp (fieldName, "dY_SYS"  )) ESCAPE (IMAGE_Y_ERR_SYS,  MAG_NONE, OPIHI_FLT);
    519   if (!strcasecmp (fieldName, "dM_SYS"  )) ESCAPE (IMAGE_MAG_ERR_SYS,MAG_NONE, OPIHI_FLT);
    520 
    521   if (!strcasecmp (fieldName, "UBERCAL_DIST")) ESCAPE (IMAGE_UBERCAL_DIST,MAG_NONE, OPIHI_INT);
    522   if (!strcasecmp (fieldName, "UCDIST")) ESCAPE (IMAGE_UBERCAL_DIST,MAG_NONE, OPIHI_INT);
    523 
    524   if (!strcasecmp (fieldName, "NFIT_PHOTOM")) ESCAPE (IMAGE_NFIT_PHOTOM,MAG_NONE, OPIHI_INT);
    525   if (!strcasecmp (fieldName, "NFIT_ASTROM")) ESCAPE (IMAGE_NFIT_ASTROM,MAG_NONE, OPIHI_INT);
    526   if (!strcasecmp (fieldName, "NLINK_PHOTOM")) ESCAPE (IMAGE_NLINK_PHOTOM,MAG_NONE, OPIHI_INT);
    527   if (!strcasecmp (fieldName, "NLINK_ASTROM")) ESCAPE (IMAGE_NLINK_ASTROM,MAG_NONE, OPIHI_INT);
     565    ESCAPE (IMAGE_ELAT, OPIHI_FLT);
     566  }
     567
     568  if (!strcasecmp (fieldName, "RA"       )) ESCAPE (IMAGE_RA,        OPIHI_FLT);
     569  if (!strcasecmp (fieldName, "DEC"      )) ESCAPE (IMAGE_DEC,       OPIHI_FLT);
     570  if (!strcasecmp (fieldName, "GLON"     )) ESCAPE (IMAGE_GLON,      OPIHI_FLT);
     571  if (!strcasecmp (fieldName, "GLAT"     )) ESCAPE (IMAGE_GLAT,      OPIHI_FLT);
     572  if (!strcasecmp (fieldName, "ELON"     )) ESCAPE (IMAGE_ELON,      OPIHI_FLT);
     573  if (!strcasecmp (fieldName, "ELAT"     )) ESCAPE (IMAGE_ELAT,      OPIHI_FLT);
     574
     575  if (!strcasecmp (fieldName, "theta"    )) ESCAPE (IMAGE_THETA,     OPIHI_FLT);
     576  if (!strcasecmp (fieldName, "skew"     )) ESCAPE (IMAGE_SKEW,      OPIHI_FLT);
     577  if (!strcasecmp (fieldName, "scale"    )) ESCAPE (IMAGE_SCALE,     OPIHI_FLT);
     578  if (!strcasecmp (fieldName, "dscale"   )) ESCAPE (IMAGE_DSCALE,    OPIHI_FLT);
     579
     580  if (!strcasecmp (fieldName, "time"     )) ESCAPE (IMAGE_TIME,      OPIHI_FLT);
     581  if (!strcasecmp (fieldName, "nstar"    )) ESCAPE (IMAGE_NSTAR,     OPIHI_INT);
     582  if (!strcasecmp (fieldName, "airmass"  )) ESCAPE (IMAGE_AIRMASS,   OPIHI_FLT);
     583  if (!strcasecmp (fieldName, "NX"       )) ESCAPE (IMAGE_NX_PIX,    OPIHI_INT);
     584  if (!strcasecmp (fieldName, "NY"       )) ESCAPE (IMAGE_NY_PIX,    OPIHI_INT);
     585  if (!strcasecmp (fieldName, "apresid"  )) ESCAPE (IMAGE_APRESID,   OPIHI_FLT);
     586  if (!strcasecmp (fieldName, "dapresid" )) ESCAPE (IMAGE_DAPRESID,  OPIHI_FLT);
     587
     588  if (!strcasecmp (fieldName, "Mcal"     )) ESCAPE (IMAGE_MCAL,      OPIHI_FLT);
     589  if (!strcasecmp (fieldName, "dMcal"    )) ESCAPE (IMAGE_dMCAL,     OPIHI_FLT);
     590  if (!strcasecmp (fieldName, "Xm"       )) ESCAPE (IMAGE_XM,        OPIHI_FLT);
     591  if (!strcasecmp (fieldName, "photcode" )) ESCAPE (IMAGE_PHOTCODE,  OPIHI_INT);
     592  if (!strcasecmp (fieldName, "exptime"  )) ESCAPE (IMAGE_EXPTIME,   OPIHI_FLT);
     593  if (!strcasecmp (fieldName, "sidtime"  )) ESCAPE (IMAGE_SIDTIME,   OPIHI_FLT);
     594
     595  if (!strcasecmp (fieldName, "latitude" )) ESCAPE (IMAGE_LATITUDE,  OPIHI_FLT);
     596
     597  if (!strcasecmp (fieldName, "detlimit" )) ESCAPE (IMAGE_DET_LIMIT, OPIHI_FLT);
     598  if (!strcasecmp (fieldName, "satlimit" )) ESCAPE (IMAGE_SAT_LIMIT, OPIHI_FLT);
     599  if (!strcasecmp (fieldName, "cerror"   )) ESCAPE (IMAGE_CERROR,    OPIHI_FLT);
     600
     601  if (!strcasecmp (fieldName, "FWHM"       )) ESCAPE (IMAGE_FWHM,      OPIHI_FLT);
     602  if (!strcasecmp (fieldName, "FWHM_MAJ"   )) ESCAPE (IMAGE_FWHM_MAJ,  OPIHI_FLT);
     603  if (!strcasecmp (fieldName, "FWHM_MIN"   )) ESCAPE (IMAGE_FWHM_MIN,  OPIHI_FLT);
     604  if (!strcasecmp (fieldName, "FWHM_MAJOR" )) ESCAPE (IMAGE_FWHM_MAJ,  OPIHI_FLT);
     605  if (!strcasecmp (fieldName, "FWHM_MINOR" )) ESCAPE (IMAGE_FWHM_MIN,  OPIHI_FLT);
     606
     607  if (!strcasecmp (fieldName, "FWHM_MEDIAN"    ))   ESCAPE (IMAGE_FWHM_MEDIAN,      OPIHI_FLT);
     608  if (!strcasecmp (fieldName, "FWHM_MAJ_MEDIAN"))   ESCAPE (IMAGE_FWHM_MAJ_MEDIAN,  OPIHI_FLT);
     609  if (!strcasecmp (fieldName, "FWHM_MIN_MEDIAN"))   ESCAPE (IMAGE_FWHM_MIN_MEDIAN,  OPIHI_FLT);
     610  if (!strcasecmp (fieldName, "FWHM_MAJOR_MEDIAN")) ESCAPE (IMAGE_FWHM_MAJ_MEDIAN,  OPIHI_FLT);
     611  if (!strcasecmp (fieldName, "FWHM_MINOR_MEDIAN")) ESCAPE (IMAGE_FWHM_MIN_MEDIAN,  OPIHI_FLT);
     612
     613  if (!strcasecmp (fieldName, "trate"    )) ESCAPE (IMAGE_TRATE,     OPIHI_FLT);
     614
     615  if (!strcasecmp (fieldName, "ncal"     )) ESCAPE (IMAGE_NCAL,      OPIHI_INT);
     616  if (!strcasecmp (fieldName, "sky"      )) ESCAPE (IMAGE_SKY,       OPIHI_FLT); // deprecated for now
     617
     618  if (!strcasecmp (fieldName, "imflags"  )) ESCAPE (IMAGE_FLAGS,     OPIHI_INT);
     619  if (!strcasecmp (fieldName, "flags"    )) ESCAPE (IMAGE_FLAGS,     OPIHI_INT);
     620  if (!strcasecmp (fieldName, "ccdnum"   )) ESCAPE (IMAGE_CCDNUM,    OPIHI_INT);
     621
     622  if (!strcasecmp (fieldName, "imageID"  )) ESCAPE (IMAGE_IMAGE_ID,  OPIHI_INT);
     623  if (!strcasecmp (fieldName, "externID" )) ESCAPE (IMAGE_EXTERN_ID, OPIHI_INT);
     624  if (!strcasecmp (fieldName, "sourceID" )) ESCAPE (IMAGE_SOURCE_ID, OPIHI_INT);
     625
     626  if (!strcasecmp (fieldName, "X_LL_CHIP")) ESCAPE (IMAGE_X_LL_CHIP, OPIHI_FLT);
     627  if (!strcasecmp (fieldName, "X_LR_CHIP")) ESCAPE (IMAGE_X_LR_CHIP, OPIHI_FLT);
     628  if (!strcasecmp (fieldName, "X_UL_CHIP")) ESCAPE (IMAGE_X_UL_CHIP, OPIHI_FLT);
     629  if (!strcasecmp (fieldName, "X_UR_CHIP")) ESCAPE (IMAGE_X_UR_CHIP, OPIHI_FLT);
     630  if (!strcasecmp (fieldName, "Y_LL_CHIP")) ESCAPE (IMAGE_Y_LL_CHIP, OPIHI_FLT);
     631  if (!strcasecmp (fieldName, "Y_LR_CHIP")) ESCAPE (IMAGE_Y_LR_CHIP, OPIHI_FLT);
     632  if (!strcasecmp (fieldName, "Y_UL_CHIP")) ESCAPE (IMAGE_Y_UL_CHIP, OPIHI_FLT);
     633  if (!strcasecmp (fieldName, "Y_UR_CHIP")) ESCAPE (IMAGE_Y_UR_CHIP, OPIHI_FLT);
     634  if (!strcasecmp (fieldName, "X_LL_FP"  )) ESCAPE (IMAGE_X_LL_FP,   OPIHI_FLT);
     635  if (!strcasecmp (fieldName, "X_LR_FP"  )) ESCAPE (IMAGE_X_LR_FP,   OPIHI_FLT);
     636  if (!strcasecmp (fieldName, "X_UL_FP"  )) ESCAPE (IMAGE_X_UL_FP,   OPIHI_FLT);
     637  if (!strcasecmp (fieldName, "X_UR_FP"  )) ESCAPE (IMAGE_X_UR_FP,   OPIHI_FLT);
     638  if (!strcasecmp (fieldName, "Y_LL_FP"  )) ESCAPE (IMAGE_Y_LL_FP,   OPIHI_FLT);
     639  if (!strcasecmp (fieldName, "Y_LR_FP"  )) ESCAPE (IMAGE_Y_LR_FP,   OPIHI_FLT);
     640  if (!strcasecmp (fieldName, "Y_UL_FP"  )) ESCAPE (IMAGE_Y_UL_FP,   OPIHI_FLT);
     641  if (!strcasecmp (fieldName, "Y_UR_FP"  )) ESCAPE (IMAGE_Y_UR_FP,   OPIHI_FLT);
     642
     643  if (!strcasecmp (fieldName, "dX_SYS"  )) ESCAPE (IMAGE_X_ERR_SYS,  OPIHI_FLT);
     644  if (!strcasecmp (fieldName, "dY_SYS"  )) ESCAPE (IMAGE_Y_ERR_SYS,  OPIHI_FLT);
     645  if (!strcasecmp (fieldName, "dM_SYS"  )) ESCAPE (IMAGE_MAG_ERR_SYS,OPIHI_FLT);
     646
     647  if (!strcasecmp (fieldName, "UBERCAL_DIST")) ESCAPE (IMAGE_UBERCAL_DIST,OPIHI_INT);
     648  if (!strcasecmp (fieldName, "UCDIST")) ESCAPE (IMAGE_UBERCAL_DIST,OPIHI_INT);
     649
     650  if (!strcasecmp (fieldName, "NFIT_PHOTOM"))  ESCAPE (IMAGE_NFIT_PHOTOM,  OPIHI_INT);
     651  if (!strcasecmp (fieldName, "NFIT_ASTROM"))  ESCAPE (IMAGE_NFIT_ASTROM,  OPIHI_INT);
     652  if (!strcasecmp (fieldName, "NLINK_PHOTOM")) ESCAPE (IMAGE_NLINK_PHOTOM, OPIHI_INT);
     653  if (!strcasecmp (fieldName, "NLINK_ASTROM")) ESCAPE (IMAGE_NLINK_ASTROM, OPIHI_INT);
     654  if (!strcasecmp (fieldName, "REF_COLOR"))    ESCAPE (IMAGE_REF_COLOR,    OPIHI_FLT);
    528655
    529656  // for words that don't parse, try a photcode
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_catalog.c

    r36680 r37403  
    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;
     142
     143  average->tessID          = 0;
     144  average->skycellID       = 0;
     145  average->projectionID    = 0;
     146  average->dummy           = 0;
    103147
    104148  average->flags           = 0;
     
    109153  average->catID           = 0;
    110154  average->extID           = 0;
     155  average->extIDgc         = 0;
    111156}
    112157
     
    125170void dvo_secfilt_init (SecFilt *secfilt) {
    126171  secfilt->M           = NAN;
     172  secfilt->dM          = NAN;
    127173  secfilt->Map         = NAN;
     174  secfilt->dMap        = NAN;
     175  secfilt->sMap        = NAN;
    128176  secfilt->Mkron       = NAN;
    129177  secfilt->dMkron      = NAN;
    130   secfilt->dM          = NAN;
    131   secfilt->Xm          = NAN_S_SHORT;
    132 
    133   secfilt->FluxPSF     = NAN;
    134   secfilt->dFluxPSF    = NAN;
    135   secfilt->FluxKron    = NAN;
    136   secfilt->dFluxKron   = NAN;
    137 
    138   secfilt->flags       = 0;
     178  secfilt->sMkron      = NAN;
     179
     180  secfilt->psfQfMax     = NAN;
     181  secfilt->psfQfPerfMax = NAN;
     182
     183  secfilt->Mstdev      = NAN;
     184  secfilt->Mmin        = NAN;
     185  secfilt->Mmax        = NAN;
     186  secfilt->Mchisq      = NAN;
     187
    139188  secfilt->Ncode       = 0;
    140189  secfilt->Nused       = 0;
    141 
    142   secfilt->M_20        = NAN_S_SHORT;
    143   secfilt->M_80        = NAN_S_SHORT;
     190  secfilt->NusedKron   = 0;
     191  secfilt->NusedAp     = 0;
     192
     193  secfilt->flags       = 0;
     194
     195  secfilt->MpsfStk     = NAN;
     196  secfilt->FpsfStk     = NAN;
     197  secfilt->dFpsfStk    = NAN;
     198
     199  secfilt->MkronStk    = NAN;
     200  secfilt->FkronStk    = NAN;
     201  secfilt->dFkronStk   = NAN;
     202
     203  secfilt->MapStk      = NAN;
     204  secfilt->FapStk      = NAN;
     205  secfilt->dFapStk     = NAN;
     206
     207  secfilt->Nstack      = 0;
     208  secfilt->NstackDet   = 0;
     209
     210  secfilt->stackPrmryOff = -1;
     211  secfilt->stackBestOff  = -1;
     212
     213  secfilt->MpsfWrp     = NAN;
     214  secfilt->FpsfWrp     = NAN;
     215  secfilt->dFpsfWrp    = NAN;
     216  secfilt->sFpsfWrp    = NAN;
     217
     218  secfilt->MkronWrp    = NAN;
     219  secfilt->FkronWrp    = NAN;
     220  secfilt->dFkronWrp   = NAN;
     221  secfilt->sFkronWrp   = NAN;
     222
     223  secfilt->MapWrp      = NAN;
     224  secfilt->FapWrp      = NAN;
     225  secfilt->dFapWrp     = NAN;
     226  secfilt->sFapWrp     = NAN;
     227
     228  secfilt->NusedWrp     = 0;
     229  secfilt->NusedKronWrp = 0;
     230  secfilt->NusedApWrp   = 0;
     231
     232  secfilt->Nwarp        = 0;
     233  secfilt->NwarpGood    = 0;
    144234
    145235  secfilt->ubercalDist = 1000;
    146   secfilt->Mstdev      = NAN_S_SHORT;
    147   secfilt->stackDetectID     = 0;
    148236}
    149237
    150238// init all data, or just catalog data
    151239void dvo_measure_init (Measure *measure) {
     240 measure->R         = NAN;
     241 measure->D         = NAN;
     242
    152243 measure->M         = NAN;
    153  measure->dR        = NAN;
    154  measure->dD        = NAN;
    155  measure->Mcal      = NAN;
     244 measure->dM        = NAN;
    156245 measure->Map       = NAN;
     246 measure->dMap      = NAN;
    157247 measure->Mkron     = NAN;
    158248 measure->dMkron    = NAN;
    159  measure->dM        = NAN;
     249 measure->Mcal      = NAN;
    160250 measure->dMcal     = NAN;
    161251 measure->dt        = NAN;
     
    165255 measure->FluxKron  = NAN;
    166256 measure->dFluxKron = NAN;
     257 measure->FluxAp    = NAN;
     258 measure->dFluxAp   = NAN;
    167259
    168260 measure->airmass   = NAN;
     
    174266 measure->Yfix      = NAN;
    175267
     268 measure->XoffKH    = NAN;
     269 measure->YoffKH    = NAN;
     270 measure->XoffDCR   = NAN;
     271 measure->YoffDCR   = NAN;
     272 measure->RoffGAL   = NAN;
     273 measure->DoffGAL   = NAN;
     274
    176275 measure->Sky       = NAN;
    177276 measure->dSky      = NAN;
    178277
    179278 measure->t         = 0;
    180  measure->t_msec    = 0;
    181279 measure->averef    = 0;
    182280
    183281 measure->detID     = 0;
    184  measure->imageID   = 0;
    185282 measure->objID     = 0;
    186283 measure->catID     = 0;
     284
    187285 measure->extID     = 0;
     286
     287 measure->imageID   = 0;
    188288
    189289 measure->psfQF     = NAN;
    190290 measure->psfQFperf = NAN;
    191291 measure->psfChisq  = NAN;
     292
    192293 measure->psfNdof   = 0;
    193294 measure->psfNpix   = 0;
    194  measure->crNsigma  = NAN;
    195295 measure->extNsigma = NAN;
    196296
     
    203303 measure->Myy       = 0;
    204304
     305 measure->t_msec    = 0;
     306 measure->photcode  = 0;
     307
    205308 measure->dXccd     = 0;
    206309 measure->dYccd     = 0;
     
    210313 measure->pltscale  = NAN;
    211314
    212  measure->photcode  = 0;
    213315 measure->dbFlags   = 0;
    214316 measure->photFlags = 0;
     317 measure->photFlags2= 0;
    215318}
    216319
    217320void dvo_measureT_init (MeasureTiny *measure) {
    218  measure->dR        = NAN;
    219  measure->dD        = NAN;
     321 measure->R         = NAN;
     322 measure->D         = NAN;
    220323 measure->M         = NAN;
    221324 measure->Mcal      = NAN;
     
    244347 measure->dRsys     = 0;
    245348 measure->myDet     = FALSE;
     349}
     350
     351// init all data, or just catalog data
     352void dvo_lensing_init (Lensing *lensing) {
     353  lensing->X11_sm_obj = NAN;
     354  lensing->X12_sm_obj = NAN;
     355  lensing->X22_sm_obj = NAN;
     356  lensing->E1_sm_obj  = NAN;
     357  lensing->E2_sm_obj  = NAN;
     358
     359  lensing->X11_sh_obj = NAN;
     360  lensing->X12_sh_obj = NAN;
     361  lensing->X22_sh_obj = NAN;
     362  lensing->E1_sh_obj  = NAN;
     363  lensing->E2_sh_obj  = NAN;
     364
     365  lensing->X11_sm_psf = NAN;
     366  lensing->X12_sm_psf = NAN;
     367  lensing->X22_sm_psf = NAN;
     368  lensing->E1_sm_psf  = NAN;
     369  lensing->E2_sm_psf  = NAN;
     370
     371  lensing->X11_sh_psf = NAN;
     372  lensing->X12_sh_psf = NAN;
     373  lensing->X22_sh_psf = NAN;
     374  lensing->E1_sh_psf  = NAN;
     375  lensing->E2_sh_psf  = NAN;
     376
     377  lensing->F_ApR5     = NAN;
     378  lensing->dF_ApR5    = NAN;
     379  lensing->sF_ApR5    = NAN;
     380  lensing->fF_ApR5    = NAN;
     381
     382  lensing->F_ApR6     = NAN;
     383  lensing->dF_ApR6    = NAN;
     384  lensing->sF_ApR6    = NAN;
     385  lensing->fF_ApR6    = NAN;
     386
     387  lensing->detID = -1;
     388  lensing->objID = -1;
     389  lensing->catID = -1;
     390  lensing->averef = 0;
     391
     392  lensing->imageID = -1;
     393  lensing->padding = 0;
     394}
     395
     396// init all data, or just catalog data
     397void dvo_lensobj_init (Lensobj *lensobj, int toZero) {
     398  lensobj->X11_sm_obj = toZero ? 0 : NAN;
     399  lensobj->X12_sm_obj = toZero ? 0 : NAN;
     400  lensobj->X22_sm_obj = toZero ? 0 : NAN;
     401  lensobj->E1_sm_obj  = toZero ? 0 : NAN;
     402  lensobj->E2_sm_obj  = toZero ? 0 : NAN;
     403  lensobj->X11_sh_obj = toZero ? 0 : NAN;
     404  lensobj->X12_sh_obj = toZero ? 0 : NAN;
     405  lensobj->X22_sh_obj = toZero ? 0 : NAN;
     406  lensobj->E1_sh_obj  = toZero ? 0 : NAN;
     407  lensobj->E2_sh_obj  = toZero ? 0 : NAN;
     408  lensobj->X11_sm_psf = toZero ? 0 : NAN;
     409  lensobj->X12_sm_psf = toZero ? 0 : NAN;
     410  lensobj->X22_sm_psf = toZero ? 0 : NAN;
     411  lensobj->E1_sm_psf  = toZero ? 0 : NAN;
     412  lensobj->E2_sm_psf  = toZero ? 0 : NAN;
     413  lensobj->X11_sh_psf = toZero ? 0 : NAN;
     414  lensobj->X12_sh_psf = toZero ? 0 : NAN;
     415  lensobj->X22_sh_psf = toZero ? 0 : NAN;
     416  lensobj->E1_sh_psf  = toZero ? 0 : NAN;
     417  lensobj->E2_sh_psf  = toZero ? 0 : NAN;
     418  lensobj->F_ApR5     = toZero ? 0 : NAN;
     419  lensobj->dF_ApR5    = toZero ? 0 : NAN;
     420  lensobj->sF_ApR5    = toZero ? 0 : NAN;
     421  lensobj->fF_ApR5    = toZero ? 0 : NAN;
     422  lensobj->F_ApR6     = toZero ? 0 : NAN;
     423  lensobj->dF_ApR6    = toZero ? 0 : NAN;
     424  lensobj->sF_ApR6    = toZero ? 0 : NAN;
     425  lensobj->fF_ApR6    = toZero ? 0 : NAN;
     426
     427  lensobj->gamma = NAN;
     428  lensobj->E1 = NAN;
     429  lensobj->E2 = NAN;
     430
     431  lensobj->objID = -1;
     432  lensobj->catID = -1;
     433
     434  lensobj->photcode = 0;
     435  lensobj->Nmeas = 0;
    246436}
    247437
     
    269459  catalog[0].secfilt = NULL;
    270460 
     461  catalog[0].lensing = NULL;
     462  catalog[0].lensobj = NULL;
     463
    271464  catalog[0].averageT = NULL;
    272465  catalog[0].measureT = NULL;
     
    281474  catalog[0].Nsecf_mem = 0;
    282475
     476  catalog[0].Nlensing = 0;
     477  catalog[0].Nlensobj = 0;
     478
    283479  catalog[0].Naves_disk = 0;
    284480  catalog[0].Nmeas_disk = 0;
     
    286482  catalog[0].Nsecf_disk = 0;
    287483
     484  catalog[0].Nlensing_disk = 0;
     485  catalog[0].Nlensobj_disk = 0;
     486
    288487  catalog[0].Naves_off  = 0;
    289488  catalog[0].Nmeas_off  = 0;
     
    291490  catalog[0].Nsecf_off  = 0;
    292491
     492  catalog[0].Nlensing_off  = 0;
     493  catalog[0].Nlensobj_off  = 0;
     494
    293495  /* pointers to SPLIT data files */
    294496  catalog[0].measure_catalog = NULL;
    295497  catalog[0].missing_catalog = NULL;
    296498  catalog[0].secfilt_catalog = NULL;
     499  catalog[0].lensing_catalog = NULL;
     500  catalog[0].lensobj_catalog = NULL;
    297501
    298502  /* pointers for data manipulation */
    299   catalog[0].found = NULL;
    300   catalog[0].image = NULL;
    301   catalog[0].mosaic = NULL;
    302   catalog[0].X = NULL;
    303   catalog[0].Y = NULL;
     503  // catalog[0].X_t = NULL;
     504  // catalog[0].Y_t = NULL;
     505  catalog[0].nOwn_t = NULL;
     506  catalog[0].found_t = NULL;
     507  // catalog[0].image_t = NULL;
     508  // catalog[0].mosaic_t = NULL;
     509  catalog[0].foundWarp_t = NULL;
    304510}
    305511
     
    345551  }
    346552
     553  // closes f but does not set back to NULL
    347554  fclearlockfile (catalog[0].filename, catalog[0].f, catalog[0].lockmode, &dbstate);
    348555
    349556  if (catalog[0].catmode == DVO_MODE_SPLIT) {
    350     if (catalog[0].measure_catalog != NULL) dvo_catalog_unlock (catalog[0].measure_catalog);
    351     if (catalog[0].missing_catalog != NULL) dvo_catalog_unlock (catalog[0].missing_catalog);
    352     if (catalog[0].secfilt_catalog != NULL) dvo_catalog_unlock (catalog[0].secfilt_catalog);
     557    if (catalog[0].measure_catalog) dvo_catalog_unlock (catalog[0].measure_catalog);
     558    if (catalog[0].missing_catalog) dvo_catalog_unlock (catalog[0].missing_catalog);
     559    if (catalog[0].secfilt_catalog) dvo_catalog_unlock (catalog[0].secfilt_catalog);
     560    if (catalog[0].lensing_catalog) dvo_catalog_unlock (catalog[0].lensing_catalog);
     561    if (catalog[0].lensobj_catalog) dvo_catalog_unlock (catalog[0].lensobj_catalog);
    353562  }
    354563  return (1);
     
    579788    for (in = out = i = 0; i < catalog[0].Naverage; i++) {
    580789      for (j = 0; j < catalog[0].Nsecfilt; j++, in++, out++) {
    581         outsec[out].M  = insec[in].M;
    582         outsec[out].dM = insec[in].dM;
    583         outsec[out].Xm = insec[in].Xm;
     790        outsec[out].M      = insec[in].M;
     791        outsec[out].dM     = insec[in].dM;
     792        outsec[out].Mchisq = insec[in].Mchisq;
    584793      }
    585794      for (j = 0; j < Nextra; j++, out++) {
    586         outsec[out].M  = NAN;
    587         outsec[out].dM = NAN;
    588         outsec[out].Xm = NAN_S_SHORT;
     795        outsec[out].M      = NAN;
     796        outsec[out].dM     = NAN;
     797        outsec[out].Mchisq = NAN;
    589798      }
    590799    }
     
    616825      free (catalog[0].secfilt_catalog);
    617826    }
     827    if (catalog[0].lensing_catalog) {
     828      free (catalog[0].lensing_catalog[0].filename);
     829      dvo_catalog_free (catalog[0].lensing_catalog);
     830      free (catalog[0].lensing_catalog);
     831    }
     832    if (catalog[0].lensobj_catalog) {
     833      free (catalog[0].lensobj_catalog[0].filename);
     834      dvo_catalog_free (catalog[0].lensobj_catalog);
     835      free (catalog[0].lensobj_catalog);
     836    }
    618837  }
    619838  dvo_catalog_free_data (catalog);
     
    625844
    626845  /* free, initialize data structures */
    627   if (catalog[0].average != NULL) {
     846  if (catalog[0].average) {
    628847    free (catalog[0].average);
    629848    catalog[0].Naverage = 0;
    630849    catalog[0].average = NULL;
    631850  }
    632   if (catalog[0].measure != NULL) {
     851  if (catalog[0].measure) {
    633852    free (catalog[0].measure);
    634853    catalog[0].Nmeasure = 0;
    635854    catalog[0].measure = NULL;
    636855  }
    637   if (catalog[0].missing != NULL) {
     856  if (catalog[0].missing) {
    638857    free (catalog[0].missing);
    639858    catalog[0].Nmissing = 0;
    640859    catalog[0].missing = NULL;
    641860  }
    642   if (catalog[0].secfilt != NULL) {
     861  if (catalog[0].secfilt) {
    643862    free (catalog[0].secfilt);
    644863    catalog[0].Nsecf_mem = 0;
    645864    catalog[0].secfilt = NULL;
    646865  }
     866  if (catalog[0].lensing) {
     867    free (catalog[0].lensing);
     868    catalog[0].Nlensing = 0;
     869    catalog[0].lensing = NULL;
     870  }
     871  if (catalog[0].lensobj) {
     872    free (catalog[0].lensobj);
     873    catalog[0].Nlensobj = 0;
     874    catalog[0].lensobj = NULL;
     875  }
     876  if (catalog[0].nOwn_t)      { free (catalog[0].nOwn_t); catalog[0].nOwn_t = NULL; }
     877  if (catalog[0].found_t)     { free (catalog[0].found_t); catalog[0].found_t = NULL; }
     878  if (catalog[0].foundWarp_t) { free (catalog[0].foundWarp_t); catalog[0].foundWarp_t = NULL; }
    647879}
    648880
     
    733965      }
    734966    }
     967    if (catalog[0].lensing_catalog != NULL) {
     968      if (catalog[0].Nlensing_disk == 0) {
     969        // need to relock (and re-open) file for close elsewhere
     970        status = dvo_catalog_lock (catalog[0].lensing_catalog, lockmode);
     971      } else {
     972        if (!dvo_catalog_backup (catalog[0].lensing_catalog, FALSE)) {
     973          return FALSE;
     974        }
     975      }
     976    }
     977    if (catalog[0].lensobj_catalog != NULL) {
     978      if (catalog[0].Nlensobj_disk == 0) {
     979        // need to relock (and re-open) file for close elsewhere
     980        status = dvo_catalog_lock (catalog[0].lensobj_catalog, lockmode);
     981      } else {
     982        if (!dvo_catalog_backup (catalog[0].lensobj_catalog, FALSE)) {
     983          return FALSE;
     984        }
     985      }
     986    }
    735987  }
    736988  return TRUE;
     
    7541006  status = unlink (tmpfilename);
    7551007  if (status) {
    756     fprintf (stderr, "failed to unlink catalog %s\n", catalog->filename);
     1008    fprintf (stderr, "failed to unlink catalog %s~\n", catalog->filename);
    7571009    return FALSE;
    7581010  }
     
    7741026      }
    7751027    }
     1028    if ((catalog[0].lensing_catalog != NULL) && (catalog[0].Nlensing_disk > 0)) {
     1029      if (!dvo_catalog_unlink_backup (catalog[0].lensing_catalog, FALSE)) {
     1030        return FALSE;
     1031      }
     1032    }
     1033    if ((catalog[0].lensobj_catalog != NULL) && (catalog[0].Nlensobj_disk > 0)) {
     1034      if (!dvo_catalog_unlink_backup (catalog[0].lensobj_catalog, FALSE)) {
     1035        return FALSE;
     1036      }
     1037    }
    7761038  }
    7771039  return TRUE;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_catalog_chipcoords.c

    r16810 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_catalog_create.c

    r27435 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_catalog_mef.c

    r33649 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_catalog_raw.c

    r34260 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_catalog_split.c

    r34844 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert.c

    r36680 r37403  
    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
     
    7677    free (tmpAverage);
    7778    *format = DVO_FORMAT_PS1_V4;
     79    return (average);
     80  }
     81
     82  // block to convert old tables (PS1_V5 versions made during development)
     83  if (!strcmp (extname, "DVO_AVERAGE_PS1_V5") && (ftable[0].header[0].Naxis[0] == 184)) {
     84    Average_PS1_V5alt *tmpAverage;
     85    tmpAverage = gfits_table_get_Average_PS1_V5alt (ftable, Naverage, NULL);
     86    if (!tmpAverage) {
     87      fprintf (stderr, "ERROR: failed to read averages\n");
     88      exit (2);
     89    }
     90    average = Average_PS1_V5alt_ToInternal (tmpAverage, *Naverage);
     91    free (tmpAverage);
     92    *format = DVO_FORMAT_PS1_V5;
    7893    return (average);
    7994  }
     
    112127  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V3",          PS1_V3,          PS1_V3);
    113128  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V4",          PS1_V4,          PS1_V4);
     129  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5",          PS1_V5,          PS1_V5);
    114130  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF,         PS1_REF);
    115131# undef CONVERT_FORMAT
     
    147163      FORMAT_CASE (PS1_V3,          PS1_V3);
    148164      FORMAT_CASE (PS1_V4,          PS1_V4);
     165      FORMAT_CASE (PS1_V5,          PS1_V5);
    149166      FORMAT_CASE (PS1_REF,         PS1_REF);
    150167# undef FORMAT_CASE
     
    159176/*** Measure / FTable conversion functions ***/
    160177
    161 Measure *FtableToMeasure (FTable *ftable, off_t *Nmeasure, char *format) {
     178// FtableToMeasure needs the Average since old formats stored measure.dR,dD only
     179Measure *FtableToMeasure (FTable *ftable, Average *average, off_t *Nmeasure, char *format) {
    162180
    163181  Measure *measure;
     
    179197      exit (2);
    180198    }
    181     measure = Measure_PS1_V4alt_ToInternal (tmpMeasure, *Nmeasure);
     199    myAssert (average, "conversion to internal needs average table");
     200    measure = Measure_PS1_V4alt_ToInternal (average, tmpMeasure, *Nmeasure);
    182201    free (tmpMeasure);
    183202    *format = DVO_FORMAT_PS1_V4;
     
    185204  }
    186205
    187 # define CONVERT_FORMAT(NAME, FORMAT, TYPE) \
    188   if (!strcmp (extname, NAME)) { \
    189     Measure_##TYPE *tmpMeasure; \
     206# define CONVERT_FORMAT(NAME, FORMAT, TYPE, ABS_COORDS)         \
     207  if (!strcmp (extname, NAME)) {                                        \
     208    Measure_##TYPE *tmpMeasure;                                         \
    190209    tmpMeasure = gfits_table_get_Measure_##TYPE (ftable, Nmeasure, NULL); \
    191     if (!tmpMeasure) { \
    192       fprintf (stderr, "ERROR: failed to read measures\n"); \
    193       exit (2); \
    194     } \
    195     measure = Measure_##TYPE##_ToInternal (tmpMeasure, *Nmeasure); \
    196     free (tmpMeasure); \
    197     *format = DVO_FORMAT_##FORMAT; \
     210    if (!tmpMeasure) {                                                  \
     211      fprintf (stderr, "ERROR: failed to read measures\n");             \
     212      exit (2);                                                         \
     213    }                                                                   \
     214    myAssert (ABS_COORDS || average, "conversion to internal needs average table"); \
     215    measure = Measure_##TYPE##_ToInternal (average, tmpMeasure, *Nmeasure); \
     216    free (tmpMeasure);                                                  \
     217    *format = DVO_FORMAT_##FORMAT;                                      \
    198218    return (measure); }
    199219
     
    208228  }
    209229
    210   CONVERT_FORMAT ("DVO_MEASURE_ELIXIR",          ELIXIR,          Elixir);
    211   CONVERT_FORMAT ("DVO_MEASURE_LONEOS",          LONEOS,          Loneos);
    212   CONVERT_FORMAT ("DVO_MEASURE_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
    213   CONVERT_FORMAT ("DVO_MEASURE_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
    214   CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
    215   CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
    216   CONVERT_FORMAT ("DVO_MEASURE_PS1_V1",          PS1_V1,          PS1_V1);
    217   CONVERT_FORMAT ("DVO_MEASURE_PS1_V2",          PS1_V2,          PS1_V2);
    218   CONVERT_FORMAT ("DVO_MEASURE_PS1_V3",          PS1_V3,          PS1_V3);
    219   CONVERT_FORMAT ("DVO_MEASURE_PS1_V4",          PS1_V4,          PS1_V4);
    220   CONVERT_FORMAT ("DVO_MEASURE_PS1_REF",         PS1_REF,         PS1_REF);
     230  CONVERT_FORMAT ("DVO_MEASURE_ELIXIR",          ELIXIR,          Elixir,          FALSE);
     231  CONVERT_FORMAT ("DVO_MEASURE_LONEOS",          LONEOS,          Loneos,          FALSE);
     232  CONVERT_FORMAT ("DVO_MEASURE_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0, FALSE);
     233  CONVERT_FORMAT ("DVO_MEASURE_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1, FALSE);
     234  CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1,       FALSE);
     235  CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2,       FALSE);
     236  CONVERT_FORMAT ("DVO_MEASURE_PS1_V1",          PS1_V1,          PS1_V1,          FALSE);
     237  CONVERT_FORMAT ("DVO_MEASURE_PS1_V2",          PS1_V2,          PS1_V2,          FALSE);
     238  CONVERT_FORMAT ("DVO_MEASURE_PS1_V3",          PS1_V3,          PS1_V3,          FALSE);
     239  CONVERT_FORMAT ("DVO_MEASURE_PS1_V4",          PS1_V4,          PS1_V4,          FALSE);
     240  CONVERT_FORMAT ("DVO_MEASURE_PS1_V5",          PS1_V5,          PS1_V5,          TRUE);
     241  CONVERT_FORMAT ("DVO_MEASURE_PS1_REF",         PS1_REF,         PS1_REF,         FALSE);
    221242# undef CONVERT_FORMAT
    222243
     
    227248}
    228249
    229 int MeasureToFtable (FTable *ftable, Measure *measure, off_t Nmeasure, char format) {
    230 
    231 # define FORMAT_CASE(FORMAT, TYPE) \
     250// MeasureToFtable needs the Average since old formats stored measure.dR,dD only
     251int MeasureToFtable (FTable *ftable, Average *average, Measure *measure, off_t Nmeasure, char format) {
     252
     253# define FORMAT_CASE(FORMAT, TYPE, ABS_COORDS)          \
    232254    case DVO_FORMAT_##FORMAT: { \
    233255      Measure_##TYPE *tmpMeasure; \
    234       tmpMeasure = MeasureInternalTo_##TYPE (measure, Nmeasure); \
     256      myAssert (ABS_COORDS || average, "conversion to internal needs average table"); \
     257      tmpMeasure = MeasureInternalTo_##TYPE (average, measure, Nmeasure); \
    235258      gfits_table_set_Measure_##TYPE (ftable, tmpMeasure, Nmeasure); \
    236259      free (tmpMeasure); \
     
    243266      break; }
    244267
    245       FORMAT_CASE (ELIXIR,          Elixir);
    246       FORMAT_CASE (LONEOS,          Loneos);
    247       FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
    248       FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
    249       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
    250       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
    251       FORMAT_CASE (PS1_V1,          PS1_V1);
    252       FORMAT_CASE (PS1_V2,          PS1_V2);
    253       FORMAT_CASE (PS1_V3,          PS1_V3);
    254       FORMAT_CASE (PS1_V4,          PS1_V4);
    255       FORMAT_CASE (PS1_REF,         PS1_REF);
     268      FORMAT_CASE (ELIXIR,          Elixir,          FALSE);
     269      FORMAT_CASE (LONEOS,          Loneos,          FALSE);
     270      FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0, FALSE);
     271      FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1, FALSE);
     272      FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1,       FALSE);
     273      FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2,       FALSE);
     274      FORMAT_CASE (PS1_V1,          PS1_V1,          FALSE);
     275      FORMAT_CASE (PS1_V2,          PS1_V2,          FALSE);
     276      FORMAT_CASE (PS1_V3,          PS1_V3,          FALSE);
     277      FORMAT_CASE (PS1_V4,          PS1_V4,          FALSE);
     278      FORMAT_CASE (PS1_V5,          PS1_V5,          TRUE);
     279      FORMAT_CASE (PS1_REF,         PS1_REF,         FALSE);
    256280# undef FORMAT_CASE
    257281
     
    275299    return (FALSE);
    276300  }
     301
     302  // block to convert old tables (PS1_V5 versions made during development)
     303  if (!strcmp (extname, "DVO_SECFILT_PS1_V5") && (ftable[0].header[0].Naxis[0] == 160)) {
     304    SecFilt_PS1_V5alt *tmpSecFilt;
     305    tmpSecFilt = gfits_table_get_SecFilt_PS1_V5alt (ftable, Nsecfilt, NULL);
     306    if (!tmpSecFilt) {
     307      fprintf (stderr, "ERROR: failed to read secfilts\n");
     308      exit (2);
     309    }
     310    secfilt = SecFilt_PS1_V5alt_ToInternal (tmpSecFilt, *Nsecfilt);
     311    free (tmpSecFilt);
     312    *format = DVO_FORMAT_PS1_V5;
     313    return (secfilt);
     314  }
     315
    277316
    278317# define CONVERT_FORMAT(NAME, FORMAT, TYPE) \
     
    309348  CONVERT_FORMAT ("DVO_SECFILT_PS1_V3",          PS1_V3,          PS1_V3);
    310349  CONVERT_FORMAT ("DVO_SECFILT_PS1_V4",          PS1_V4,          PS1_V4);
     350  CONVERT_FORMAT ("DVO_SECFILT_PS1_V5",          PS1_V5,          PS1_V5);
    311351  CONVERT_FORMAT ("DVO_SECFILT_PS1_REF",         PS1_REF,         PS1_REF);
    312352# undef CONVERT_FORMAT
     
    344384      FORMAT_CASE (PS1_V3,          PS1_V3);
    345385      FORMAT_CASE (PS1_V4,          PS1_V4);
     386      FORMAT_CASE (PS1_V5,          PS1_V5);
    346387      FORMAT_CASE (PS1_REF,         PS1_REF);
    347388# undef FORMAT_CASE
     
    349390    default:
    350391      fprintf (stderr, "table format unknown (secfilt)\n");
     392      return (FALSE);
     393  }
     394  return (TRUE);
     395}
     396
     397/*** Lensing / FTable conversion functions ***/
     398
     399Lensing *FtableToLensing (FTable *ftable, off_t *Nlensing, char *format) {
     400
     401  Lensing *lensing;
     402  char extname[80];
     403
     404  /* convert to the internal format */
     405  if (!gfits_scan (ftable[0].header, "EXTNAME", "%s", 1, extname)) {
     406    fprintf (stderr, "EXTNAME missing for lensing table\n");
     407    return (FALSE);
     408  }
     409
     410# define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     411  if (!strcmp (extname, NAME)) {                                        \
     412    Lensing_##TYPE *tmpLensing;                                         \
     413    tmpLensing = gfits_table_get_Lensing_##TYPE (ftable, Nlensing, NULL); \
     414    if (!tmpLensing) {                                                  \
     415      fprintf (stderr, "ERROR: failed to read lensings\n");             \
     416      exit (2);                                                         \
     417    }                                                                   \
     418    lensing = Lensing_##TYPE##_ToInternal (tmpLensing, *Nlensing); \
     419    free (tmpLensing);                                                  \
     420    *format = DVO_FORMAT_##FORMAT;                                      \
     421    return (lensing); }
     422
     423# define SKIPPING_FORMAT(NAME, FORMAT, TYPE)            \
     424  if (!strcmp (extname, NAME)) {                                        \
     425    fprintf (stderr, "ERROR: format %s not defined for lensing, skipping\n", NAME); \
     426    *Nlensing = 0; \
     427    return NULL; \
     428  }
     429
     430  if (!strcmp (extname, "DVO_LENSING")) {
     431    lensing = gfits_table_get_Lensing (ftable, Nlensing, NULL);
     432    if (!lensing) {
     433      fprintf (stderr, "ERROR: failed to read lensings\n");
     434      exit (2);
     435    }
     436    *format = DVO_FORMAT_INTERNAL;
     437    return (lensing);
     438  }
     439
     440  SKIPPING_FORMAT ("DVO_LENSING_PS1_REF",         PS1_REF,         PS1_REF);
     441  SKIPPING_FORMAT ("DVO_LENSING_ELIXIR",          ELIXIR,          Elixir);
     442  SKIPPING_FORMAT ("DVO_LENSING_LONEOS",          LONEOS,          Loneos);
     443  SKIPPING_FORMAT ("DVO_LENSING_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
     444  SKIPPING_FORMAT ("DVO_LENSING_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
     445  SKIPPING_FORMAT ("DVO_LENSING_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
     446  SKIPPING_FORMAT ("DVO_LENSING_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     447  SKIPPING_FORMAT ("DVO_LENSING_PS1_V1",          PS1_V1,          PS1_V1);
     448  SKIPPING_FORMAT ("DVO_LENSING_PS1_V2",          PS1_V2,          PS1_V2);
     449  SKIPPING_FORMAT ("DVO_LENSING_PS1_V3",          PS1_V3,          PS1_V3);
     450  SKIPPING_FORMAT ("DVO_LENSING_PS1_V4",          PS1_V4,          PS1_V4);
     451  CONVERT_FORMAT  ("DVO_LENSING_PS1_V5",          PS1_V5,          PS1_V5);
     452# undef CONVERT_FORMAT
     453
     454  fprintf (stderr, "table format unknown: %s\n", extname);
     455
     456  *Nlensing = 0;
     457  return (NULL);
     458}
     459
     460// LensingToFtable needs the Average since old formats stored lensing.dR,dD only
     461int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, char format) {
     462
     463# define FORMAT_CASE(FORMAT, TYPE)              \
     464    case DVO_FORMAT_##FORMAT: { \
     465      Lensing_##TYPE *tmpLensing; \
     466      tmpLensing = LensingInternalTo_##TYPE (lensing, Nlensing); \
     467      gfits_table_set_Lensing_##TYPE (ftable, tmpLensing, Nlensing); \
     468      free (tmpLensing); \
     469      break; }
     470
     471  /* convert from the internal format */
     472  switch (format) {
     473    case DVO_FORMAT_INTERNAL: {
     474      gfits_table_set_Lensing (ftable, lensing, Nlensing);
     475      break; }
     476
     477//    FORMAT_CASE (PS1_REF,         PS1_REF);
     478//    FORMAT_CASE (ELIXIR,          Elixir);
     479//    FORMAT_CASE (LONEOS,          Loneos);
     480//    FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
     481//    FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
     482//    FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
     483//    FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     484//    FORMAT_CASE (PS1_V1,          PS1_V1);
     485//    FORMAT_CASE (PS1_V2,          PS1_V2);
     486//    FORMAT_CASE (PS1_V3,          PS1_V3);
     487//    FORMAT_CASE (PS1_V4,          PS1_V4);
     488      FORMAT_CASE (PS1_V5,          PS1_V5);
     489# undef FORMAT_CASE
     490
     491    default:
     492      fprintf (stderr, "table format unknown (lensing)\n");
     493      return (FALSE);
     494  }
     495  return (TRUE);
     496}
     497
     498/*** Lensobj / FTable conversion functions ***/
     499
     500Lensobj *FtableToLensobj (FTable *ftable, off_t *Nlensobj, char *format) {
     501
     502  Lensobj *lensobj;
     503  char extname[80];
     504
     505  /* convert to the internal format */
     506  if (!gfits_scan (ftable[0].header, "EXTNAME", "%s", 1, extname)) {
     507    fprintf (stderr, "EXTNAME missing for lensobj table\n");
     508    return (FALSE);
     509  }
     510
     511# define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     512  if (!strcmp (extname, NAME)) {                                        \
     513    Lensobj_##TYPE *tmpLensobj;                                         \
     514    tmpLensobj = gfits_table_get_Lensobj_##TYPE (ftable, Nlensobj, NULL); \
     515    if (!tmpLensobj) {                                                  \
     516      fprintf (stderr, "ERROR: failed to read lensobjs\n");             \
     517      exit (2);                                                         \
     518    }                                                                   \
     519    lensobj = Lensobj_##TYPE##_ToInternal (tmpLensobj, *Nlensobj); \
     520    free (tmpLensobj);                                                  \
     521    *format = DVO_FORMAT_##FORMAT;                                      \
     522    return (lensobj); }
     523
     524  if (!strcmp (extname, "DVO_LENSOBJ")) {
     525    lensobj = gfits_table_get_Lensobj (ftable, Nlensobj, NULL);
     526    if (!lensobj) {
     527      fprintf (stderr, "ERROR: failed to read lensobjs\n");
     528      exit (2);
     529    }
     530    *format = DVO_FORMAT_INTERNAL;
     531    return (lensobj);
     532  }
     533
     534// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_REF",         PS1_REF,         PS1_REF);
     535// CONVERT_FORMAT ("DVO_LENSOBJ_ELIXIR",          ELIXIR,          Elixir);
     536// CONVERT_FORMAT ("DVO_LENSOBJ_LONEOS",          LONEOS,          Loneos);
     537// CONVERT_FORMAT ("DVO_LENSOBJ_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
     538// CONVERT_FORMAT ("DVO_LENSOBJ_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
     539// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
     540// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     541// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V1",          PS1_V1,          PS1_V1);
     542// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V2",          PS1_V2,          PS1_V2);
     543// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V3",          PS1_V3,          PS1_V3);
     544// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V4",          PS1_V4,          PS1_V4);
     545  CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V5",          PS1_V5,          PS1_V5);
     546# undef CONVERT_FORMAT
     547
     548  fprintf (stderr, "table format unknown: %s\n", extname);
     549
     550  *Nlensobj = 0;
     551  return (NULL);
     552}
     553
     554// LensobjToFtable needs the Average since old formats stored lensobj.dR,dD only
     555int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, char format) {
     556
     557# define FORMAT_CASE(FORMAT, TYPE)              \
     558    case DVO_FORMAT_##FORMAT: { \
     559      Lensobj_##TYPE *tmpLensobj; \
     560      tmpLensobj = LensobjInternalTo_##TYPE (lensobj, Nlensobj); \
     561      gfits_table_set_Lensobj_##TYPE (ftable, tmpLensobj, Nlensobj); \
     562      free (tmpLensobj); \
     563      break; }
     564
     565  /* convert from the internal format */
     566  switch (format) {
     567    case DVO_FORMAT_INTERNAL: {
     568      gfits_table_set_Lensobj (ftable, lensobj, Nlensobj);
     569      break; }
     570
     571//    FORMAT_CASE (PS1_REF,         PS1_REF);
     572//    FORMAT_CASE (ELIXIR,          Elixir);
     573//    FORMAT_CASE (LONEOS,          Loneos);
     574//    FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
     575//    FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
     576//    FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
     577//    FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     578//    FORMAT_CASE (PS1_V1,          PS1_V1);
     579//    FORMAT_CASE (PS1_V2,          PS1_V2);
     580//    FORMAT_CASE (PS1_V3,          PS1_V3);
     581//    FORMAT_CASE (PS1_V4,          PS1_V4);
     582      FORMAT_CASE (PS1_V5,          PS1_V5);
     583# undef FORMAT_CASE
     584
     585    default:
     586      fprintf (stderr, "table format unknown (lensobj)\n");
    351587      return (FALSE);
    352588  }
     
    428664  CONVERT_FORMAT ("DVO_IMAGE_PS1_V3",          PS1_V3,          PS1_V3);
    429665  CONVERT_FORMAT ("DVO_IMAGE_PS1_V4",          PS1_V4,          PS1_V4);
     666  CONVERT_FORMAT ("DVO_IMAGE_PS1_V5",          PS1_V5,          PS1_V5);
    430667  CONVERT_FORMAT ("DVO_IMAGE_PS1_REF",         PS1_REF,         PS1_REF);
    431668
     
    467704      FORMAT_CASE (PS1_V3,          PS1_V3);
    468705      FORMAT_CASE (PS1_V4,          PS1_V4);
     706      FORMAT_CASE (PS1_V5,          PS1_V5);
    469707      FORMAT_CASE (PS1_REF,         PS1_REF);
    470708
     
    522760      FORMAT_CASE (PS1_V3,          PS1_V3);
    523761      FORMAT_CASE (PS1_V4,          PS1_V4);
     762      FORMAT_CASE (PS1_V5,          PS1_V5);
    524763      FORMAT_CASE (PS1_REF,         PS1_REF);
    525764
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c

    r35162 r37403  
    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;
     
    3032    out[i].psfQF      = in[i].psfQF;
    3133    out[i].psfChisq   = in[i].psfChisq;
    32     out[i].crNsigma   = in[i].crNsigma;
    3334    out[i].extNsigma  = in[i].extNsigma;
    3435    out[i].FWx        = in[i].FWx;
     
    5051}
    5152
    52 Measure_PS1_DEV_1 *MeasureInternalTo_PS1_DEV_1 (Measure *in, off_t Nvalues) {
     53Measure_PS1_DEV_1 *MeasureInternalTo_PS1_DEV_1 (Average *ave, Measure *in, off_t Nvalues) {
    5354
    5455  off_t i;
     
    5859
    5960  for (i = 0; i < Nvalues; i++) {
    60     out[i].dR         = in[i].dR;
    61     out[i].dD         = in[i].dD;
     61    int averef = in[i].averef;
     62
     63    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
     64    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    6265    out[i].M          = in[i].M;
    6366    out[i].Mcal       = in[i].Mcal;
     
    7679    out[i].psfQF      = in[i].psfQF;
    7780    out[i].psfChisq   = in[i].psfChisq;
    78     out[i].crNsigma   = in[i].crNsigma;
    7981    out[i].extNsigma  = in[i].extNsigma;
    8082    out[i].FWx        = in[i].FWx;
     
    180182    out[i].M     = in[i].M;     
    181183    out[i].dM    = in[i].dM;     
    182     out[i].Xm    = in[i].Xm;     
     184    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    183185    out[i].Ncode = in[i].Ncode;
    184186    out[i].Nused = in[i].Nused;
     
    197199    out[i].M     = in[i].M;     
    198200    out[i].dM    = in[i].dM;     
    199     out[i].Xm    = in[i].Xm;     
     201    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
    200202    out[i].Ncode = in[i].Ncode;
    201203    out[i].Nused = in[i].Nused;
     
    203205  return (out);
    204206}
     207
     208# define RAW_IMAGE_NAME_LEN 64
    205209
    206210Image *Image_PS1_DEV_1_ToInternal (Image_PS1_DEV_1 *in, off_t Nvalues, off_t Nalloc) {
     
    217221    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    218222
    219     strncpy (out[i].name, in[i].name, 63); // out[128], in[64]
    220     out[i].name[63] = 0; // force termination
     223    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     224    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     225    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    221226
    222227    out[i].tzero            = in[i].tzero;
     
    284289    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    285290
    286     strncpy (out[i].name, in[i].name, 63); // out[128], in[64]
    287     out[i].name[63] = 0; // force termination
     291    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     292    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     293    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    288294
    289295    out[i].tzero            = in[i].tzero;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c

    r35162 r37403  
    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;
     
    3234    out[i].psfQF      = in[i].psfQF;
    3335    out[i].psfChisq   = in[i].psfChisq;
    34     out[i].crNsigma   = in[i].crNsigma;
    3536    out[i].extNsigma  = in[i].extNsigma;
    3637    out[i].FWx        = in[i].FWx;
     
    4849}
    4950
    50 Measure_PS1_DEV_2 *MeasureInternalTo_PS1_DEV_2 (Measure *in, off_t Nvalues) {
     51Measure_PS1_DEV_2 *MeasureInternalTo_PS1_DEV_2 (Average *ave, Measure *in, off_t Nvalues) {
    5152
    5253  off_t i;
     
    5657
    5758  for (i = 0; i < Nvalues; i++) {
    58     out[i].dR         = in[i].dR;
    59     out[i].dD         = in[i].dD;
     59    int averef = in[i].averef;
     60
     61    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
     62    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    6063    out[i].M          = in[i].M;
    6164    out[i].Mcal       = in[i].Mcal;
     
    7679    out[i].psfQF      = in[i].psfQF;
    7780    out[i].psfChisq   = in[i].psfChisq;
    78     out[i].crNsigma   = in[i].crNsigma;
    7981    out[i].extNsigma  = in[i].extNsigma;
    8082    out[i].FWx        = in[i].FWx;
     
    119121    out[i].measureOffset = in[i].measureOffset;
    120122    out[i].missingOffset = in[i].missingOffset;
    121     out[i].extendOffset  = in[i].extendOffset;
     123    out[i].refColorBlue  = in[i].refColor;
    122124    out[i].objID         = in[i].objID;
    123125    out[i].catID         = in[i].catID;
     
    153155    out[i].measureOffset = in[i].measureOffset;
    154156    out[i].missingOffset = in[i].missingOffset;
    155     out[i].extendOffset  = in[i].extendOffset;
     157    out[i].refColor  = in[i].refColorBlue;
    156158    out[i].objID         = in[i].objID;
    157159    out[i].catID         = in[i].catID;
     
    175177    out[i].M     = in[i].M;     
    176178    out[i].dM    = in[i].dM;     
    177     out[i].Xm    = in[i].Xm;     
     179    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    178180    out[i].Ncode = in[i].Ncode;
    179181    out[i].Nused = in[i].Nused;
     
    192194    out[i].M     = in[i].M;     
    193195    out[i].dM    = in[i].dM;     
    194     out[i].Xm    = in[i].Xm;     
     196    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
    195197    out[i].Ncode = in[i].Ncode;
    196198    out[i].Nused = in[i].Nused;
     
    198200  return (out);
    199201}
     202
     203# define RAW_IMAGE_NAME_LEN 64
    200204
    201205Image *Image_PS1_DEV_2_ToInternal (Image_PS1_DEV_2 *in, off_t Nvalues, off_t Nalloc) {
     
    212216    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    213217
    214     strncpy (out[i].name, in[i].name, 63); // out[121], in[64]
    215     out[i].name[63] = 0; // force termination
     218    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     219    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     220    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    216221
    217222    out[i].tzero            = in[i].tzero;
     
    276281    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    277282
    278     strncpy (out[i].name, in[i].name, 63); // in[121], out[64]
    279     out[i].name[63] = 0; // force termination
     283    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     284    strncpy (out[i].name, in[i].name, RAW_IMAGE_NAME_LEN - 1);
     285    out[i].name[RAW_IMAGE_NAME_LEN - 1] = 0; // force termination
    280286
    281287    out[i].tzero            = in[i].tzero;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c

    r35162 r37403  
    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;
     
    3940    out[i].psfNdof    = in[i].psfNdof;
    4041    out[i].psfNpix    = in[i].psfNpix;
    41     out[i].crNsigma   = in[i].crNsigma;
    4242    out[i].extNsigma  = in[i].extNsigma;
    4343    out[i].FWx        = in[i].FWx;
     
    5858}
    5959
    60 Measure_PS1_V1 *MeasureInternalTo_PS1_V1 (Measure *in, off_t Nvalues) {
     60Measure_PS1_V1 *MeasureInternalTo_PS1_V1 (Average *ave, Measure *in, off_t Nvalues) {
    6161
    6262  off_t i;
     
    6666
    6767  for (i = 0; i < Nvalues; i++) {
    68     out[i].dR         = in[i].dR;
    69     out[i].dD         = in[i].dD;
     68    int averef = in[i].averef;
     69
     70    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
     71    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    7072    out[i].M          = in[i].M;
    7173    out[i].Mcal       = in[i].Mcal;
     
    9294    out[i].psfNdof    = in[i].psfNdof;
    9395    out[i].psfNpix    = in[i].psfNpix;
    94     out[i].crNsigma   = in[i].crNsigma;
    9596    out[i].extNsigma  = in[i].extNsigma;
    9697    out[i].FWx        = in[i].FWx;
     
    140141    out[i].measureOffset = in[i].measureOffset;
    141142    out[i].missingOffset = in[i].missingOffset;
    142     out[i].extendOffset  = in[i].extendOffset;
     143    out[i].refColorBlue  = in[i].refColor;
    143144    out[i].flags         = in[i].flags;   
    144145    out[i].objID         = in[i].objID;
     
    175176    out[i].measureOffset = in[i].measureOffset;
    176177    out[i].missingOffset = in[i].missingOffset;
    177     out[i].extendOffset  = in[i].extendOffset;
     178    out[i].refColor      = in[i].refColorBlue;
    178179    out[i].flags         = in[i].flags;   
    179180    out[i].objID         = in[i].objID;
     
    196197    out[i].M     = in[i].M;     
    197198    out[i].dM    = in[i].dM;     
    198     out[i].Xm    = in[i].Xm;     
     199    out[i].Mchisq= in[i].Mchisq;     
    199200    out[i].Ncode = in[i].Ncode;
    200201    out[i].Nused = in[i].Nused;
    201     out[i].M_20  = in[i].M_20;     
    202     out[i].M_80  = in[i].M_80;     
     202    out[i].Mmin  = in[i].M_20*0.001;     
     203    out[i].Mmax  = in[i].M_80*0.001;     
    203204 }
    204205  return (out);
     
    215216    out[i].M     = in[i].M;     
    216217    out[i].dM    = in[i].dM;     
    217     out[i].Xm    = in[i].Xm;     
     218    out[i].Mchisq= in[i].Mchisq;     
    218219    out[i].Ncode = in[i].Ncode;
    219220    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 }
     221    out[i].M_20  = in[i].Mmin*1000.0;     
     222    out[i].M_80  = in[i].Mmax*1000.0;     
     223  }
     224  return (out);
     225}
     226
     227# define RAW_IMAGE_NAME_LEN 121
    225228
    226229Image *Image_PS1_V1_ToInternal (Image_PS1_V1 *in, off_t Nvalues, off_t Nalloc) {
     
    237240    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    238241
    239     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    240     out[i].name[120] = 0; // force termination
     242    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     243    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     244    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    241245
    242246    out[i].tzero            = in[i].tzero;
     
    300304    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    301305
    302     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    303     out[i].name[120] = 0; // force termination
     306    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     307    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     308    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    304309
    305310    out[i].tzero            = in[i].tzero;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c

    r35162 r37403  
    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;
     
    3940    out[i].psfNdof    = in[i].psfNdof;
    4041    out[i].psfNpix    = in[i].psfNpix;
    41     out[i].crNsigma   = in[i].crNsigma;
    4242    out[i].extNsigma  = in[i].extNsigma;
    4343    out[i].FWx        = in[i].FWx;
     
    5959}
    6060
    61 Measure_PS1_V2 *MeasureInternalTo_PS1_V2 (Measure *in, off_t Nvalues) {
     61Measure_PS1_V2 *MeasureInternalTo_PS1_V2 (Average *ave, Measure *in, off_t Nvalues) {
    6262
    6363  off_t i;
     
    6767
    6868  for (i = 0; i < Nvalues; i++) {
    69     out[i].dR         = in[i].dR;
    70     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);
    7173    out[i].M          = in[i].M;
    7274    out[i].Mcal       = in[i].Mcal;
     
    9395    out[i].psfNdof    = in[i].psfNdof;
    9496    out[i].psfNpix    = in[i].psfNpix;
    95     out[i].crNsigma   = in[i].crNsigma;
    9697    out[i].extNsigma  = in[i].extNsigma;
    9798    out[i].FWx        = in[i].FWx;
     
    145146    out[i].measureOffset = in[i].measureOffset;
    146147    out[i].missingOffset = in[i].missingOffset;
    147     out[i].extendOffset  = in[i].extendOffset;
     148    out[i].refColorBlue  = in[i].refColor;
    148149    out[i].flags         = in[i].flags;   
    149150    out[i].objID         = in[i].objID;
     
    184185    out[i].measureOffset = in[i].measureOffset;
    185186    out[i].missingOffset = in[i].missingOffset;
    186     out[i].extendOffset  = in[i].extendOffset;
     187    out[i].refColor  = in[i].refColorBlue;
    187188    out[i].flags         = in[i].flags;   
    188189    out[i].objID         = in[i].objID;
     
    205206    out[i].M     = in[i].M;     
    206207    out[i].dM    = in[i].dM;     
    207     out[i].Xm    = in[i].Xm;     
     208    out[i].Mchisq= in[i].Mchisq;     
    208209    out[i].flags = in[i].flags;     
    209210    out[i].Ncode = in[i].Ncode;
    210211    out[i].Nused = in[i].Nused;
    211     out[i].M_20  = in[i].M_20;     
    212     out[i].M_80  = in[i].M_80;     
     212    out[i].Mmin  = in[i].M_20*0.001;     
     213    out[i].Mmax  = in[i].M_80*0.001;     
    213214 }
    214215  return (out);
     
    225226    out[i].M     = in[i].M;     
    226227    out[i].dM    = in[i].dM;     
    227     out[i].Xm    = in[i].Xm;     
     228    out[i].Mchisq= in[i].Mchisq;     
    228229    out[i].flags = in[i].flags;     
    229230    out[i].Ncode = in[i].Ncode;
    230231    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 }
     232    out[i].M_20  = in[i].Mmin*1000.0;     
     233    out[i].M_80  = in[i].Mmax*1000.0;     
     234  }
     235  return (out);
     236}
     237
     238# define RAW_IMAGE_NAME_LEN 121
    236239
    237240Image *Image_PS1_V2_ToInternal (Image_PS1_V2 *in, off_t Nvalues, off_t Nalloc) {
     
    248251    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    249252
    250     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    251     out[i].name[120] = 0; // force termination
     253    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     254    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     255    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    252256
    253257    out[i].tzero            = in[i].tzero;
     
    269273    out[i].DECo             = in[i].DECo;
    270274    out[i].Radius           = in[i].Radius;
     275    out[i].refColorBlue             = in[i].refColor;
    271276
    272277    out[i].detection_limit  = in[i].detection_limit;
     
    310315    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    311316
    312     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    313     out[i].name[120] = 0; // force termination
     317    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     318    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     319    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    314320
    315321    out[i].tzero            = in[i].tzero;
     
    331337    out[i].DECo             = in[i].DECo;
    332338    out[i].Radius           = in[i].Radius;
     339    out[i].refColor         = in[i].refColorBlue;
    333340
    334341    out[i].detection_limit  = in[i].detection_limit;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c

    r35162 r37403  
    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;
     
    3940    out[i].psfNdof    = in[i].psfNdof;
    4041    out[i].psfNpix    = in[i].psfNpix;
    41     out[i].crNsigma   = in[i].crNsigma;
    4242    out[i].extNsigma  = in[i].extNsigma;
    4343    out[i].FWx        = in[i].FWx;
     
    5959}
    6060
    61 Measure_PS1_V3 *MeasureInternalTo_PS1_V3 (Measure *in, off_t Nvalues) {
     61Measure_PS1_V3 *MeasureInternalTo_PS1_V3 (Average *ave, Measure *in, off_t Nvalues) {
    6262
    6363  off_t i;
     
    6767
    6868  for (i = 0; i < Nvalues; i++) {
    69     out[i].dR         = in[i].dR;
    70     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);
    7173    out[i].M          = in[i].M;
    7274    out[i].Mcal       = in[i].Mcal;
     
    9395    out[i].psfNdof    = in[i].psfNdof;
    9496    out[i].psfNpix    = in[i].psfNpix;
    95     out[i].crNsigma   = in[i].crNsigma;
    9697    out[i].extNsigma  = in[i].extNsigma;
    9798    out[i].FWx        = in[i].FWx;
     
    145146    out[i].measureOffset = in[i].measureOffset;
    146147    out[i].missingOffset = in[i].missingOffset;
    147     out[i].extendOffset  = in[i].extendOffset;
     148    out[i].refColorBlue  = in[i].refColor;
    148149    out[i].flags         = in[i].flags;   
    149150    out[i].photFlagsUpper = in[i].photFlagsUpper;   
     
    186187    out[i].measureOffset = in[i].measureOffset;
    187188    out[i].missingOffset = in[i].missingOffset;
    188     out[i].extendOffset  = in[i].extendOffset;
     189    out[i].refColor      = in[i].refColorBlue;
    189190    out[i].flags         = in[i].flags;   
    190191    out[i].photFlagsUpper = in[i].photFlagsUpper;   
     
    210211    out[i].Map         = in[i].Map;     
    211212    out[i].dM          = in[i].dM;     
    212     out[i].Xm          = in[i].Xm;     
     213    out[i].Mchisq      = in[i].Mchisq;     
    213214    out[i].flags       = in[i].flags;     
    214215    out[i].Ncode       = in[i].Ncode;
    215216    out[i].Nused       = in[i].Nused;
    216     out[i].M_20        = in[i].M_20;     
    217     out[i].M_80        = in[i].M_80;     
     217    out[i].Mmin        = in[i].M_20*0.001;     
     218    out[i].Mmax        = in[i].M_80*0.001;     
    218219    out[i].Mstdev      = in[i].Mstdev;     
    219220    out[i].ubercalDist = in[i].ubercalDist;     
     
    233234    out[i].Map         = in[i].Map;     
    234235    out[i].dM          = in[i].dM;     
    235     out[i].Xm          = in[i].Xm;     
     236    out[i].Mchisq      = in[i].Mchisq;     
    236237    out[i].flags       = in[i].flags;     
    237238    out[i].Ncode       = in[i].Ncode;
    238239    out[i].Nused       = in[i].Nused;
    239     out[i].M_20        = in[i].M_20;     
    240     out[i].M_80        = in[i].M_80;     
     240    out[i].M_20        = in[i].Mmin*1000.0;     
     241    out[i].M_80        = in[i].Mmax*1000.0;     
    241242    out[i].Mstdev      = in[i].Mstdev;     
    242243    out[i].ubercalDist = in[i].ubercalDist;     
     
    244245  return (out);
    245246}
     247
     248# define RAW_IMAGE_NAME_LEN 121
    246249
    247250Image *Image_PS1_V3_ToInternal (Image_PS1_V3 *in, off_t Nvalues, off_t Nalloc) {
     
    258261    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    259262
    260     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    261     out[i].name[120] = 0; // force termination
     263    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     264    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     265    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    262266
    263267    out[i].tzero            = in[i].tzero;
     
    279283    out[i].DECo             = in[i].DECo;
    280284    out[i].Radius           = in[i].Radius;
     285    out[i].refColorBlue     = in[i].refColor;
    281286
    282287    out[i].detection_limit  = in[i].detection_limit;
     
    320325    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    321326
    322     strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
    323     out[i].name[120] = 0; // force termination
     327    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     328    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
     329    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 0; // force termination
    324330
    325331    out[i].tzero            = in[i].tzero;
     
    341347    out[i].DECo             = in[i].DECo;
    342348    out[i].Radius           = in[i].Radius;
     349    out[i].refColor         = in[i].refColorBlue;
    343350
    344351    out[i].detection_limit  = in[i].detection_limit;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c

    r36680 r37403  
    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;
     
    4849    out[i].psfNdof    = in[i].psfNdof;
    4950    out[i].psfNpix    = in[i].psfNpix;
    50     out[i].crNsigma   = in[i].crNsigma;
    5151    out[i].extNsigma  = in[i].extNsigma;
    5252    out[i].FWx        = in[i].FWx;
     
    6868}
    6969
    70 Measure_PS1_V4 *MeasureInternalTo_PS1_V4 (Measure *in, off_t Nvalues) {
     70Measure_PS1_V4 *MeasureInternalTo_PS1_V4 (Average *ave, Measure *in, off_t Nvalues) {
    7171
    7272  off_t i;
     
    7676
    7777  for (i = 0; i < Nvalues; i++) {
    78     out[i].dR         = in[i].dR;
    79     out[i].dD         = in[i].dD;
     78    int averef = in[i].averef;
     79
     80    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
     81    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    8082    out[i].M          = in[i].M;
    8183    out[i].Mcal       = in[i].Mcal;
     
    111113    out[i].psfNdof    = in[i].psfNdof;
    112114    out[i].psfNpix    = in[i].psfNpix;
    113     out[i].crNsigma   = in[i].crNsigma;
    114115    out[i].extNsigma  = in[i].extNsigma;
    115116    out[i].FWx        = in[i].FWx;
     
    166167    out[i].measureOffset = in[i].measureOffset;
    167168    out[i].missingOffset = in[i].missingOffset;
    168     out[i].extendOffset  = in[i].extendOffset;
     169    out[i].refColorBlue  = in[i].refColor;
    169170    out[i].flags         = in[i].flags;   
    170171    out[i].photFlagsUpper = in[i].photFlagsUpper;   
     
    210211    out[i].measureOffset = in[i].measureOffset;
    211212    out[i].missingOffset = in[i].missingOffset;
    212     out[i].extendOffset  = in[i].extendOffset;
     213    out[i].refColor      = in[i].refColorBlue;
    213214    out[i].flags         = in[i].flags;   
    214215    out[i].photFlagsUpper = in[i].photFlagsUpper;   
     
    236237    out[i].dMkron        = in[i].dMkron;     
    237238    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;
     239    out[i].Mchisq        = in[i].Mchisq;     
     240    out[i].FpsfStk       = in[i].FluxPSF;
     241    out[i].dFpsfStk      = in[i].dFluxPSF;
     242    out[i].FkronStk      = in[i].FluxKron;
     243    out[i].dFkronStk     = in[i].dFluxKron;
    243244    out[i].flags         = in[i].flags;     
    244245    out[i].Ncode         = in[i].Ncode;
    245246    out[i].Nused         = in[i].Nused;
    246     out[i].M_20          = in[i].M_20;     
    247     out[i].M_80          = in[i].M_80;     
     247    out[i].Mmin          = in[i].M_20*0.001;     
     248    out[i].Mmax          = in[i].M_80*0.001;     
    248249    out[i].Mstdev        = in[i].Mstdev;     
    249250    out[i].ubercalDist   = in[i].ubercalDist;     
    250     out[i].stackDetectID = in[i].stackDetectID;     
     251    out[i].stackPrmryOff = in[i].stackPrmryOff;     
     252    out[i].stackBestOff  = in[i].stackBestOff;     
    251253 }
    252254  return (out);
     
    266268    out[i].dMkron        = in[i].dMkron;     
    267269    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;
     270    out[i].Mchisq        = in[i].Mchisq;
     271    out[i].FluxPSF       = in[i].FpsfStk;
     272    out[i].dFluxPSF      = in[i].dFpsfStk;
     273    out[i].FluxKron      = in[i].FkronStk;
     274    out[i].dFluxKron     = in[i].dFkronStk;
    273275    out[i].flags         = in[i].flags;     
    274276    out[i].Ncode         = in[i].Ncode;
    275277    out[i].Nused         = in[i].Nused;
    276     out[i].M_20          = in[i].M_20;     
    277     out[i].M_80          = in[i].M_80;     
     278    out[i].M_20          = in[i].Mmin*1000.0;     
     279    out[i].M_80          = in[i].Mmax*1000.0;     
    278280    out[i].Mstdev        = in[i].Mstdev;     
    279281    out[i].ubercalDist   = in[i].ubercalDist;     
    280     out[i].stackDetectID = in[i].stackDetectID;
    281   }
    282   return (out);
    283 }
     282    out[i].stackPrmryOff = in[i].stackPrmryOff;     
     283    out[i].stackBestOff  = in[i].stackBestOff;     
     284  }
     285  return (out);
     286}
     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;
     
    484493/*** there are some mini dvodbs with the wrong PS1_V4 format (missing Xoff,Yoff / Xfix,Yfix) ************/
    485494
    486 Measure *Measure_PS1_V4alt_ToInternal (Measure_PS1_V4alt *in, off_t Nvalues) {
     495Measure *Measure_PS1_V4alt_ToInternal (Average *ave, Measure_PS1_V4alt *in, off_t Nvalues) {
    487496
    488497  off_t i;
     
    494503    dvo_measure_init (&out[i]);
    495504
    496     out[i].dR         = in[i].dR;
    497     out[i].dD         = in[i].dD;
     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;
    498508    out[i].M          = in[i].M;
    499509    out[i].Mcal       = in[i].Mcal;
     
    529539    out[i].psfNdof    = in[i].psfNdof;
    530540    out[i].psfNpix    = in[i].psfNpix;
    531     out[i].crNsigma   = in[i].crNsigma;
    532541    out[i].extNsigma  = in[i].extNsigma;
    533542    out[i].FWx        = in[i].FWx;
     
    680689    out[i].measureOffset = in[i].measureOffset;
    681690    out[i].missingOffset = in[i].missingOffset;
    682     out[i].extendOffset  = in[i].extendOffset;
     691    out[i].refColorBlue  = in[i].refColor;
    683692    out[i].flags         = in[i].flags;   
    684693    out[i].photFlagsUpper = in[i].photFlagsUpper;   
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert_elixir.c

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert_loneos.c

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_image.c

    r35162 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_image_raw.c

    r34260 r37403  
    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/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_photcode_ops.c

    r36680 r37403  
    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++) {
     
    222255
    223256/******** photometry conversion functions *********/
    224 float PhotInst (Measure *measure) {
    225 
    226   int Np;
    227   float M;
    228 
    229   Np = photcodes[0].hashcode[measure[0].photcode];
     257float PhotInst (Measure *measure, dvoMagClassType class) {
     258
     259  int Np = photcodes[0].hashcode[measure[0].photcode];
    230260  if (Np == -1) return (NAN);
    231 
    232   if (photcodes[0].code[Np].type == PHOT_REF) {
    233     M = measure[0].M;
    234     return (M);
    235   }
    236 
    237   M = measure[0].M - measure[0].dt - ZERO_POINT;
    238          
    239   return (M);
    240 
    241 }
    242 
    243 float PhotCat (Measure *measure) {
    244 
    245   int Np;
    246   float Mcat;
    247   PhotCode *code;
    248 
    249   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];
    250288  if (Np == -1) return (NAN);
    251 
    252   if (photcodes[0].code[Np].type == PHOT_REF) {
    253     Mcat = measure[0].M;
    254     return (Mcat);
    255   }
    256   code = &photcodes[0].code[Np];
    257   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;
    258310 
    259311  return (Mcat);
    260312}
    261313
    262 float PhotSys (Measure *measure, Average *average, SecFilt *secfilt) {
    263 
    264   int i, Np;
    265   float Mcat, Mcol, Msys, mc, Mc;
    266   PhotCode *code;
    267 
    268   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];
    269317  if (Np == -1) return (NAN);
    270 
    271   if (photcodes[0].code[Np].type == PHOT_REF) {
    272     Msys = measure[0].M;
    273     return (Msys);
    274   }
    275   code = &photcodes[0].code[Np];
    276   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;
    277338
    278339  /* for DEP, color must be made of PRI/SEC */
    279   mc = PhotColorForCode (average, secfilt, NULL, code);
     340  float mc = PhotColorForCode (average, secfilt, NULL, code);
    280341  if (isnan(mc)) return (Mcat);
    281   mc = mc - SCALE*code[0].dX;
    282 
    283   Mc = mc;
    284   Mcol = 0;
     342  mc -= SCALE*code[0].dX;
     343
     344  int i = 0;
     345  double Mc = mc;
     346  float Mcol = 0;
    285347  for (i = 0; i < code[0].Nc; i++) {
    286348    Mcol += code[0].X[i]*Mc;
    287349    Mc *= mc;
    288350  }
    289   Msys = Mcat + Mcol;
     351  float Msys = Mcat + Mcol;
    290352  return (Msys);
    291353}
    292354
    293 float PhotRel (Measure *measure, Average *average, SecFilt *secfilt) {
    294 
    295   int i, Np;
    296   float Mcat, Mcol, Mrel, mc, Mc;
    297   PhotCode *code;
    298 
    299   Np = photcodes[0].hashcode[measure[0].photcode];
     355float PhotRel (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class) {
     356
     357  int Np = photcodes[0].hashcode[measure[0].photcode];
    300358  if (Np == -1) return (NAN);
    301 
    302   if (photcodes[0].code[Np].type == PHOT_REF) {
    303     Mcat = measure[0].M;
    304     return (Mcat);
    305   }
    306   code = &photcodes[0].code[Np];
    307   Mrel = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
     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;
    308379
    309380  /* for DEP, color must be made of PRI/SEC */
    310   mc = PhotColorForCode (average, secfilt, NULL, code);
    311   if (isnan(mc)) return (Mrel);
    312   mc = mc - SCALE*code[0].dX;
    313 
    314   Mc = mc;
    315   Mcol = 0;
     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;
    316524  for (i = 0; i < code[0].Nc; i++) {
    317525    Mcol += code[0].X[i]*Mc;
    318526    Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
    319527  }
    320   Mrel += Mcol;
    321   return (Mrel);
    322 }
    323 
    324 /* return calibrated magnitude from measure for given photcode */
    325 float PhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code) {
    326 
    327   int i, Np;
    328   float Mcal, Mrel, Mcol, mc, Mc;
    329 
    330   if (code == NULL) return NAN;
    331 
    332   /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
    333   Np = photcodes[0].hashcode[thisone[0].photcode];
    334   if (Np == -1) return (NAN);
    335 
    336   if (photcodes[0].code[Np].type == PHOT_REF) {
    337     Mrel = thisone[0].M;
    338     return (Mrel);
    339   }
    340   if (code[0].code != photcodes[0].code[Np].equiv) return (NAN);
    341 
    342   Mcal = PhotRel (thisone, average, secfilt) + SCALE*code[0].C;
    343 
    344   mc = PhotColorForCode (average, secfilt, measure, code);
    345   if (isnan(mc)) return (Mcal);
    346   mc = mc - SCALE*code[0].dX;
    347 
    348   Mc = mc;
    349   Mcol = 0;
    350   for (i = 0; i < code[0].Nc; i++) {
    351     Mcol += code[0].X[i]*Mc;
    352     Mc *= mc;
    353   }
    354   Mcal += Mcol;
    355   return (Mcal);
    356 }
    357 
    358 /***/
    359 float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt) {
    360 
    361   int Ns;
    362   float Mave;
    363 
    364   if (code == NULL) return NAN;
    365 
    366   Ns = photcodes[0].hashNsec[code[0].code];
    367   Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
    368   return (Mave);
    369 }
    370 
    371 /* return calibrated magnitude from average/secfilt for given photcode */
    372 float PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure) {
    373 
    374   int i, Ns;
    375   float Mave, Mref, Mcol, mc;
    376   double Mc;
    377 
    378   if (code == NULL) return NAN;
    379 
    380   Ns = photcodes[0].hashNsec[code[0].code];
    381   Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
    382   Mref = Mave + SCALE*code[0].C;
    383 
    384   mc = PhotColorForCode (average, secfilt, measure, code);
    385   if (isnan(mc)) return (Mref);
    386   mc = mc - SCALE*code[0].dX;
    387 
    388   Mc = mc;
    389   Mcol = 0;
    390   for (i = 0; i < code[0].Nc; i++) {
    391     Mcol += code[0].X[i]*Mc;
    392     Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
    393   }
    394528  Mref += Mcol;
    395529  return (Mref);
    396530}
    397531
    398 float PhotAveErr (PhotCode *code, Average *average, SecFilt *secfilt) {
    399 
    400   int Ns;
    401   float dM;
    402 
    403   if (code == NULL) return NAN;
    404 
    405   Ns = photcodes[0].hashNsec[code[0].code];
    406   dM  = (Ns == -1) ? NAN : secfilt[Ns].dM;
    407   return (dM);
    408 }
    409 
    410 /************************************** APERTURE-related Magnitudes ***********************************************/
    411 
    412 float PhotAperInst (Measure *measure) {
    413 
    414   int Np;
    415   float Minst;
    416 
    417   Np = photcodes[0].hashcode[measure[0].photcode];
    418   if (Np == -1) return (NAN);
    419 
    420   if (photcodes[0].code[Np].type == PHOT_REF) {
    421     Minst = measure[0].Map;
    422     return (Minst);
    423   }
    424   Minst = measure[0].Map - measure[0].dt - ZERO_POINT;
    425  
    426   return (Minst);
    427 }
    428 
    429 float PhotAperCat (Measure *measure) {
    430 
    431   int Np;
    432   float Mcat;
    433   PhotCode *code;
    434 
    435   Np = photcodes[0].hashcode[measure[0].photcode];
    436   if (Np == -1) return (NAN);
    437 
    438   if (photcodes[0].code[Np].type == PHOT_REF) {
    439     Mcat = measure[0].Map;
    440     return (Mcat);
    441   }
    442   code = &photcodes[0].code[Np];
    443   Mcat = measure[0].Map - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    444  
    445   return (Mcat);
    446 }
    447 
    448 float PhotAperSys (Measure *measure, Average *average, SecFilt *secfilt) {
    449 
    450   int i, Np;
    451   float Mcat, Mcol, Msys, mc, Mc;
    452   PhotCode *code;
    453 
    454   Np = photcodes[0].hashcode[measure[0].photcode];
    455   if (Np == -1) return (NAN);
    456 
    457   if (photcodes[0].code[Np].type == PHOT_REF) {
    458     Mcat = measure[0].Map;
    459     return (Mcat);
    460   }
    461   code = &photcodes[0].code[Np];
    462   Mcat = measure[0].Map - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    463  
    464   /* for DEP, color must be made of PRI/SEC */
    465   mc = PhotColorForCode (average, secfilt, NULL, code);
    466   if (isnan(mc)) return (Mcat);
    467   mc = mc - SCALE*code[0].dX;
    468 
    469   Mc = mc;
    470   Mcol = 0;
    471   for (i = 0; i < code[0].Nc; i++) {
    472     Mcol += code[0].X[i]*Mc;
    473     Mc *= mc;
    474   }
    475   Msys = Mcat + Mcol;
    476   return (Msys);
    477 }
    478 
    479 float PhotAperRel (Measure *measure, Average *average, SecFilt *secfilt) {
    480 
    481   int i, Np;
    482   float Mcat, Mcol, Mrel, mc, Mc;
    483   PhotCode *code;
    484 
    485   Np = photcodes[0].hashcode[measure[0].photcode];
    486   if (Np == -1) return (NAN);
    487 
    488   if (photcodes[0].code[Np].type == PHOT_REF) {
    489     Mcat = measure[0].Map;
    490     return (Mcat);
    491   }
    492   code = &photcodes[0].code[Np];
    493   Mrel = measure[0].Map - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
    494 
    495   /* for DEP, color must be made of PRI/SEC */
    496   mc = PhotColorForCode (average, secfilt, NULL, code);
    497   if (isnan(mc)) return (Mrel);
    498   mc = mc - SCALE*code[0].dX;
    499 
    500   Mc = mc;
    501   Mcol = 0;
    502   for (i = 0; i < code[0].Nc; i++) {
    503     Mcol += code[0].X[i]*Mc;
    504     Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
    505   }
    506   Mrel += Mcol;
    507   return (Mrel);
    508 }
    509 
    510 /* return calibrated magnitude from measure for given photcode */
    511 float PhotAperCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code) {
    512 
    513   int i, Np;
    514   float Mcal, Mrel, Mcol, mc, Mc;
    515 
    516   if (code == NULL) return NAN;
    517 
    518   /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
    519   Np = photcodes[0].hashcode[thisone[0].photcode];
    520   if (Np == -1) return (NAN);
    521 
    522   if (photcodes[0].code[Np].type == PHOT_REF) {
    523     Mrel = thisone[0].Map;
    524     return (Mrel);
    525   }
    526   if (code[0].code != photcodes[0].code[Np].equiv) return (NAN);
    527 
    528   Mcal = PhotAperRel (thisone, average, secfilt) + SCALE*code[0].C;
    529 
    530   mc = PhotColorForCode (average, secfilt, measure, code);
    531   if (isnan(mc)) return (Mcal);
    532   mc = mc - SCALE*code[0].dX;
    533 
    534   Mc = mc;
    535   Mcol = 0;
    536   for (i = 0; i < code[0].Nc; i++) {
    537     Mcol += code[0].X[i]*Mc;
    538     Mc *= mc;
    539   }
    540   Mcal += Mcol;
    541   return (Mcal);
    542 }
    543 
    544 float PhotAperAve (PhotCode *code, Average *average, SecFilt *secfilt) {
    545 
    546   int Ns;
    547   float Maper;
    548 
    549   if (code == NULL) return NAN;
    550 
    551   Ns = photcodes[0].hashNsec[code[0].code];
    552   Maper = (Ns == -1) ? NAN : secfilt[Ns].Map;
    553   return (Maper);
    554 }
    555 
    556 /* return calibrated magnitude from average/secfilt for given photcode */
    557 float PhotAperRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure) {
    558 
    559   int i, Ns;
    560   float Mave, Mref, Mcol, mc;
    561   double Mc;
    562 
    563   if (code == NULL) return NAN;
    564 
    565   Ns = photcodes[0].hashNsec[code[0].code];
    566   Mave = (Ns == -1) ? NAN : secfilt[Ns].Map;
    567   Mref = Mave + SCALE*code[0].C;
    568 
    569   mc = PhotColorForCode (average, secfilt, measure, code);
    570   if (isnan(mc)) return (Mref);
    571   mc = mc - SCALE*code[0].dX;
    572 
    573   Mc = mc;
    574   Mcol = 0;
    575   for (i = 0; i < code[0].Nc; i++) {
    576     Mcol += code[0].X[i]*Mc;
    577     Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
    578   }
    579   Mref += Mcol;
    580   return (Mref);
    581 }
    582 
    583 /************************************** KRON-related Magnitudes ***********************************************/
    584 
    585 float PhotKronInst (Measure *measure) {
    586 
    587   int Np;
    588   float Minst;
    589 
    590   Np = photcodes[0].hashcode[measure[0].photcode];
    591   if (Np == -1) return (NAN);
    592 
    593   if (photcodes[0].code[Np].type == PHOT_REF) {
    594     Minst = measure[0].Mkron;
    595     return (Minst);
    596   }
    597   Minst = measure[0].Mkron - measure[0].dt - ZERO_POINT;
    598  
    599   return (Minst);
    600 }
    601 
    602 float PhotKronCat (Measure *measure) {
    603 
    604   int Np;
    605   float Mcat;
    606   PhotCode *code;
    607 
    608   Np = photcodes[0].hashcode[measure[0].photcode];
    609   if (Np == -1) return (NAN);
    610 
    611   if (photcodes[0].code[Np].type == PHOT_REF) {
    612     Mcat = measure[0].Mkron;
    613     return (Mcat);
    614   }
    615   code = &photcodes[0].code[Np];
    616   Mcat = measure[0].Mkron - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    617  
    618   return (Mcat);
    619 }
    620 
    621 float PhotKronSys (Measure *measure, Average *average, SecFilt *secfilt) {
    622 
    623   int i, Np;
    624   float Mcat, Mcol, Msys, mc, Mc;
    625   PhotCode *code;
    626 
    627   Np = photcodes[0].hashcode[measure[0].photcode];
    628   if (Np == -1) return (NAN);
    629 
    630   if (photcodes[0].code[Np].type == PHOT_REF) {
    631     Msys = measure[0].Mkron;
    632     return (Msys);
    633   }
    634   code = &photcodes[0].code[Np];
    635   Mcat = measure[0].Mkron - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    636 
    637   /* for DEP, color must be made of PRI/SEC */
    638   mc = PhotColorForCode (average, secfilt, NULL, code);
    639   if (isnan(mc)) return (Mcat);
    640   mc = mc - SCALE*code[0].dX;
    641 
    642   Mc = mc;
    643   Mcol = 0;
    644   for (i = 0; i < code[0].Nc; i++) {
    645     Mcol += code[0].X[i]*Mc;
    646     Mc *= mc;
    647   }
    648   Msys = Mcat + Mcol;
    649   return (Msys);
    650 }
    651 
    652 float PhotKronRel (Measure *measure, Average *average, SecFilt *secfilt) {
    653 
    654   int i, Np;
    655   float Mcat, Mcol, Mrel, mc, Mc;
    656   PhotCode *code;
    657 
    658   Np = photcodes[0].hashcode[measure[0].photcode];
    659   if (Np == -1) return (NAN);
    660 
    661   if (photcodes[0].code[Np].type == PHOT_REF) {
    662     Mcat = measure[0].Mkron;
    663     return (Mcat);
    664   }
    665   code = &photcodes[0].code[Np];
    666   Mrel = measure[0].Mkron - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
    667 
    668   /* for DEP, color must be made of PRI/SEC */
    669   mc = PhotColorForCode (average, secfilt, NULL, code);
    670   if (isnan(mc)) return (Mrel);
    671   mc = mc - SCALE*code[0].dX;
    672 
    673   Mc = mc;
    674   Mcol = 0;
    675   for (i = 0; i < code[0].Nc; i++) {
    676     Mcol += code[0].X[i]*Mc;
    677     Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
    678   }
    679   Mrel += Mcol;
    680   return (Mrel);
    681 }
    682 
    683 /* return calibrated magnitude from measure for given photcode */
    684 float PhotKronCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code) {
    685 
    686   int i, Np;
    687   float Mcal, Mrel, Mcol, mc, Mc;
    688 
    689   if (code == NULL) return NAN;
    690 
    691   /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
    692   Np = photcodes[0].hashcode[thisone[0].photcode];
    693   if (Np == -1) return (NAN);
    694 
    695   if (photcodes[0].code[Np].type == PHOT_REF) {
    696     Mrel = thisone[0].Mkron;
    697     return (Mrel);
    698   }
    699   if (code[0].code != photcodes[0].code[Np].equiv) return (NAN);
    700 
    701   Mcal = PhotKronRel (thisone, average, secfilt) + SCALE*code[0].C;
    702 
    703   mc = PhotColorForCode (average, secfilt, measure, code);
    704   if (isnan(mc)) return (Mcal);
    705   mc = mc - SCALE*code[0].dX;
    706 
    707   Mc = mc;
    708   Mcol = 0;
    709   for (i = 0; i < code[0].Nc; i++) {
    710     Mcol += code[0].X[i]*Mc;
    711     Mc *= mc;
    712   }
    713   Mcal += Mcol;
    714   return (Mcal);
    715 }
    716 
    717 float PhotKronAve (PhotCode *code, Average *average, SecFilt *secfilt) {
    718 
    719   int Ns;
    720   float Mkron;
    721 
    722   if (code == NULL) return NAN;
    723 
    724   Ns = photcodes[0].hashNsec[code[0].code];
    725   Mkron = (Ns == -1) ? NAN : secfilt[Ns].Mkron;
    726   return (Mkron);
    727 }
    728 
    729 /* return calibrated magnitude from average/secfilt for given photcode */
    730 float PhotKronRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure) {
    731 
    732   int i, Ns;
    733   float Mave, Mref, Mcol, mc;
    734   double Mc;
    735 
    736   if (code == NULL) return NAN;
    737 
    738   Ns = photcodes[0].hashNsec[code[0].code];
    739   Mave = (Ns == -1) ? NAN : secfilt[Ns].Mkron;
    740   Mref = Mave + SCALE*code[0].C;
    741 
    742   mc = PhotColorForCode (average, secfilt, measure, code);
    743   if (isnan(mc)) return (Mref);
    744   mc = mc - SCALE*code[0].dX;
    745 
    746   Mc = mc;
    747   Mcol = 0;
    748   for (i = 0; i < code[0].Nc; i++) {
    749     Mcol += code[0].X[i]*Mc;
    750     Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
    751   }
    752   Mref += Mcol;
    753   return (Mref);
    754 }
    755 
    756 float PhotKronAveErr (PhotCode *code, Average *average, SecFilt *secfilt) {
    757 
    758   int Ns;
    759   float dMkron;
    760 
    761   if (code == NULL) return NAN;
    762 
    763   Ns = photcodes[0].hashNsec[code[0].code];
    764   dMkron = (Ns == -1) ? NAN : secfilt[Ns].dMkron;
    765   return (dMkron);
     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);
    766615}
    767616
     
    788637
    789638/* color term may not use DEP magnitude */
     639// currently only returns the PSF color
    790640float PhotColorForCode (Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code) {
    791641
     
    837687}
    838688
    839 float PhotMstdev (PhotCode *code, Average *average, SecFilt *secfilt) {
    840 
    841   int Ns;
    842   float Mstdev;
    843 
    844   if (code == NULL) return NAN;
    845 
    846   Ns = photcodes[0].hashNsec[code[0].code];
    847   Mstdev  = (Ns == -1) ? NAN : 0.001*secfilt[Ns].Mstdev;
     689float PhotMstdev (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source) {
     690
     691  if (code == NULL) return NAN;
     692
     693  int Ns = photcodes[0].hashNsec[code[0].code];
     694  if (Ns == -1) return (NAN);
     695
     696  float Mstdev = NAN;
     697  switch (source) {
     698    case MAG_SRC_CHP:
     699      switch (class) {
     700        case MAG_CLASS_PSF:
     701          Mstdev = secfilt[Ns].Mstdev;
     702          break;
     703        case MAG_CLASS_KRON:
     704          Mstdev = secfilt[Ns].sMkron;
     705          break;
     706        case MAG_CLASS_APER:
     707          Mstdev = secfilt[Ns].sMap;
     708          break;
     709        default:
     710          break;
     711      }
     712      break;
     713    case MAG_SRC_WRP:
     714      switch (class) {
     715        case MAG_CLASS_PSF:
     716          Mstdev = secfilt[Ns].sFpsfWrp;
     717          break;
     718        case MAG_CLASS_KRON:
     719          Mstdev = secfilt[Ns].sFkronWrp;
     720          break;
     721        case MAG_CLASS_APER:
     722          Mstdev = secfilt[Ns].sFapWrp;
     723          break;
     724        default:
     725          break;
     726      }
     727      break;
     728    case MAG_SRC_STK:
     729    default:
     730      break;
     731  }
    848732  return (Mstdev);
     733}
     734
     735int PhotNphot (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source) {
     736
     737  if (code == NULL) return 0;
     738
     739  int Ns = photcodes[0].hashNsec[code[0].code];
     740  if (Ns == -1) return 0;
     741
     742  int Nphot = 0;
     743  switch (source) {
     744    case MAG_SRC_CHP:
     745      switch (class) {
     746        case MAG_CLASS_PSF:
     747          Nphot = secfilt[Ns].Nused;
     748          break;
     749        case MAG_CLASS_KRON:
     750          Nphot = secfilt[Ns].NusedKron;
     751          break;
     752        case MAG_CLASS_APER:
     753          Nphot = secfilt[Ns].NusedAp;
     754          break;
     755        default:
     756          break;
     757      }
     758      break;
     759    case MAG_SRC_WRP:
     760      switch (class) {
     761        case MAG_CLASS_PSF:
     762          Nphot = secfilt[Ns].NusedWrp;
     763          break;
     764        case MAG_CLASS_KRON:
     765          Nphot = secfilt[Ns].NusedKronWrp;
     766          break;
     767        case MAG_CLASS_APER:
     768          Nphot = secfilt[Ns].NusedApWrp;
     769          break;
     770        default:
     771          break;
     772      }
     773      break;
     774    case MAG_SRC_STK:
     775    default:
     776      break;
     777  }
     778  return (Nphot);
    849779}
    850780
     
    857787
    858788  Ns = photcodes[0].hashNsec[code[0].code];
    859   Fpsf = (Ns == -1) ? NAN : secfilt[Ns].FluxPSF;
     789  Fpsf = (Ns == -1) ? NAN : secfilt[Ns].FpsfStk;
    860790  return (Fpsf);
    861791}
     
    869799
    870800  Ns = photcodes[0].hashNsec[code[0].code];
    871   dFpsf = (Ns == -1) ? NAN : secfilt[Ns].dFluxPSF;
     801  dFpsf = (Ns == -1) ? NAN : secfilt[Ns].dFpsfStk;
    872802  return (dFpsf);
    873803}
     
    881811
    882812  Ns = photcodes[0].hashNsec[code[0].code];
    883   Fkron = (Ns == -1) ? NAN : secfilt[Ns].FluxKron;
     813  Fkron = (Ns == -1) ? NAN : secfilt[Ns].FkronStk;
    884814  return (Fkron);
    885815}
     
    893823
    894824  Ns = photcodes[0].hashNsec[code[0].code];
    895   dFkron = (Ns == -1) ? NAN : secfilt[Ns].dFluxKron;
     825  dFkron = (Ns == -1) ? NAN : secfilt[Ns].dFkronStk;
    896826  return (dFkron);
    897827}
    898828
    899 float PhotM20 (PhotCode *code, Average *average, SecFilt *secfilt) {
     829float PhotMmin (PhotCode *code, Average *average, SecFilt *secfilt) {
    900830
    901831  int Ns;
    902   float M20;
     832  float Mmin;
    903833
    904834  if (code == NULL) return NAN;
    905835
    906836  Ns = photcodes[0].hashNsec[code[0].code];
    907   M20  = (Ns == -1) ? NAN : 0.001*secfilt[Ns].M_20;
    908   return (M20);
    909 }
    910 
    911 float PhotM80 (PhotCode *code, Average *average, SecFilt *secfilt) {
     837  Mmin  = (Ns == -1) ? NAN : secfilt[Ns].Mmin;
     838  return (Mmin);
     839}
     840
     841float PhotMmax (PhotCode *code, Average *average, SecFilt *secfilt) {
    912842
    913843  int Ns;
    914   float M80;
     844  float Mmax;
    915845
    916846  if (code == NULL) return NAN;
    917847
    918848  Ns = photcodes[0].hashNsec[code[0].code];
    919   M80  = (Ns == -1) ? NAN : 0.001*secfilt[Ns].M_80;
    920   return (M80);
     849  Mmax  = (Ns == -1) ? NAN : secfilt[Ns].Mmax;
     850  return (Mmax);
    921851}
    922852
     
    933863}
    934864
    935 unsigned int PhotStackID (PhotCode *code, Average *average, SecFilt *secfilt) {
     865// XX unsigned int PhotStackID (PhotCode *code, Average *average, SecFilt *secfilt) {
     866// XX
     867// XX   int Ns;
     868// XX   unsigned int ID;
     869// XX
     870// XX   if (code == NULL) return 0;
     871// XX
     872// XX   Ns = photcodes[0].hashNsec[code[0].code];
     873// XX   ID = (Ns == -1) ? 0 : secfilt[Ns].stackDetectID;
     874// XX   return (ID);
     875// XX }
     876
     877// Xm is now (2014.07.03) stored as the chisq except in dvo formats which use as short
     878float PhotXm (PhotCode *code, Average *average, SecFilt *secfilt) {
    936879
    937880  int Ns;
    938   unsigned int ID;
    939 
    940   if (code == NULL) return 0;
     881  float Xm;
     882
     883  if (code == NULL) return NAN;
    941884
    942885  Ns = photcodes[0].hashNsec[code[0].code];
    943   ID = (Ns == -1) ? 0 : secfilt[Ns].stackDetectID;
    944   return (ID);
    945 }
    946 
    947 // XXX return NAN or NAN_S_SHORT? (secfilt->Xm is short)
    948 float PhotXm (PhotCode *code, Average *average, SecFilt *secfilt) {
    949 
    950   int Ns;
    951   short Mi;
    952   float Xm;
    953 
    954   if (code == NULL) return NAN;
    955 
    956   Ns = photcodes[0].hashNsec[code[0].code];
    957   Mi = (Ns == -1) ? NAN : secfilt[Ns].Xm;
    958   Xm = (isnan(Mi)) ? -1.0 : pow (10.0, 0.01*Mi);
     886  Xm = (Ns == -1) ? NAN : secfilt[Ns].Mchisq;
    959887  return (Xm);
    960888}
     
    1006934}
    1007935
    1008 /******** alternate photometry conversion functions using MeasureTiny and AverageTiny *********/
    1009 float PhotInstTiny (MeasureTiny *measure) {
    1010 
    1011   int Np;
    1012   float M;
    1013 
    1014   Np = photcodes[0].hashcode[measure[0].photcode];
     936float MagToFlux (float Mag) {
     937  float Flux = pow(10.0, -0.4*(Mag));
     938  return (Flux);
     939}
     940
     941/** flux conversion *******************************************************************/
     942float PhotFluxInst (Measure *measure, dvoMagClassType class) {
     943
     944  float Moff = - measure[0].dt - ZERO_POINT;
     945  float Finst = NAN;
     946  switch (class) {
     947    case MAG_CLASS_PSF:
     948      Finst = isnan (measure[0].FluxPSF)  ? MagToFlux(measure[0].M + Moff)     : measure[0].FluxPSF;
     949      break;
     950    case MAG_CLASS_KRON:
     951      Finst = isnan (measure[0].FluxKron) ? MagToFlux(measure[0].Mkron + Moff) : measure[0].FluxKron;
     952      break;
     953    case MAG_CLASS_APER:
     954      Finst = isnan (measure[0].FluxAp)   ? MagToFlux(measure[0].Map + Moff)   : measure[0].FluxAp;
     955      break;
     956    default:
     957      break;
     958  }
     959  return (Finst);
     960}
     961
     962// returns Jy fluxes assuming mag in AB? (needs an extra AP factor, right?)
     963float PhotFluxCat (Measure *measure, dvoMagClassType class) {
     964
     965  int Np = photcodes[0].hashcode[measure[0].photcode];
    1015966  if (Np == -1) return (NAN);
    1016 
    1017   if (photcodes[0].code[Np].type == PHOT_REF) {
    1018     M = measure[0].M;
    1019     return (M);
    1020   }
    1021 
    1022   M = measure[0].M - measure[0].dt - ZERO_POINT;
    1023          
    1024   return (M);
    1025 
    1026 }
    1027 
    1028 float PhotCatTiny (MeasureTiny *measure) {
    1029 
    1030   int Np;
    1031   float Mcat;
    1032   PhotCode *code;
    1033 
    1034   Np = photcodes[0].hashcode[measure[0].photcode];
     967  PhotCode *code = &photcodes[0].code[Np];
     968
     969  // mag_AB = -2.5 log (flux_cgs) - 48.6 (by definition) [~Vega flux in V-band]
     970  // flux_Jy = flux_cgs * 10^23
     971  // -2.5 log (flux_cgs) = -2.5 log (flux_Jy * 10^-23) = -2.5 log (flux_Jy) + 2.5*23
     972
     973  // from these we get:
     974  // mag_AB = -2.5 log (flux_Jy) + 8.9
     975  // log (flux_Jy) = -0.4*mag_AB + 3.56
     976
     977  // mag_AB = mag_inst + ZP
     978
     979  // log(flux_Jy) = -0.4*mag_inst -0.4*ZP + 3.56
     980  // mag_inst = -2.5 log (flux_Jy) - ZP + 8.9
     981
     982  // log (flux_Jy) = -0.4*(mag_inst + ZP - 8.9)
     983
     984  // -2.5 log (flux_inst) = -2.5 log (flux_Jy) - ZP + 8.9
     985  // log (flux_inst) = log (flux_Jy) + 0.4 ZP - 3.56
     986  // flux_inst = flux_Jy * 10^(0.4*ZP - 3.56)
     987  // flux_Jy = flux_inst * 10^(3.56 - 0.4*ZP) = flux_inst * zpFactor
     988  // flux_Jy = flux_inst * 3630.8 * 10^(-0.4*ZP)
     989
     990  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
     991  float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     992  float Moff = Mcal - ZERO_POINT + 8.9;
     993  float Foff = 3630.8 * MagToFlux(Mcal);
     994  float Fcat = NAN;
     995  switch (class) {
     996    case MAG_CLASS_PSF:
     997      Fcat = isnan (measure[0].FluxPSF)  ? MagToFlux(measure[0].M + Moff)     : measure[0].FluxPSF * Foff;
     998      break;
     999    case MAG_CLASS_KRON:
     1000      Fcat = isnan (measure[0].FluxKron) ? MagToFlux(measure[0].Mkron + Moff) : measure[0].FluxKron * Foff;
     1001      break;
     1002    case MAG_CLASS_APER:
     1003      Fcat = isnan (measure[0].FluxAp)   ? MagToFlux(measure[0].Map + Moff)   : measure[0].FluxAp * Foff;
     1004      break;
     1005    default:
     1006      break;
     1007  }
     1008  return (Fcat);
     1009}
     1010
     1011// corrected for color trends
     1012float PhotFluxSys (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class) {
     1013
     1014  int Np = photcodes[0].hashcode[measure[0].photcode];
    10351015  if (Np == -1) return (NAN);
    1036 
    1037   if (photcodes[0].code[Np].type == PHOT_REF) {
    1038     Mcat = measure[0].M;
    1039     return (Mcat);
    1040   }
    1041   code = &photcodes[0].code[Np];
    1042   Mcat = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    1043  
    1044   return (Mcat);
    1045 }
    1046 
    1047 # if (0)
    1048 float PhotAperTiny (MeasureTiny *measure) {
    1049 
    1050   int Np;
    1051   float Mcat;
    1052   PhotCode *code;
    1053 
    1054   Np = photcodes[0].hashcode[measure[0].photcode];
    1055   if (Np == -1) return (NAN);
    1056 
    1057   if (photcodes[0].code[Np].type == PHOT_REF) {
    1058     Mcat = measure[0].Map;
    1059     return (Mcat);
    1060   }
    1061   code = &photcodes[0].code[Np];
    1062   Mcat = measure[0].Map - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    1063  
    1064   return (Mcat);
    1065 }
    1066 # endif
    1067 
    1068 float PhotSysTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt) {
    1069 
    1070   int i, Np;
    1071   float Mcat, Mcol, Msys, mc, Mc;
    1072   PhotCode *code;
    1073 
    1074   Np = photcodes[0].hashcode[measure[0].photcode];
    1075   if (Np == -1) return (NAN);
    1076 
    1077   if (photcodes[0].code[Np].type == PHOT_REF) {
    1078     Msys = measure[0].M;
    1079     return (Msys);
    1080   }
    1081   code = &photcodes[0].code[Np];
    1082   Mcat = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    1083 
    1084   /* for DEP, color must be made of PRI/SEC */
    1085   mc = PhotColorForCodeTiny (average, secfilt, NULL, code);
    1086   if (isnan(mc)) return (Mcat);
    1087   mc = mc - SCALE*code[0].dX;
    1088 
    1089   Mc = mc;
    1090   Mcol = 0;
     1016  PhotCode *code = &photcodes[0].code[Np];
     1017
     1018  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
     1019  float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     1020  float Moff = Mcal - ZERO_POINT + 8.9;
     1021  float Foff = 3630.8 * MagToFlux(Mcal);
     1022  float Fcat = NAN;
     1023  switch (class) {
     1024    case MAG_CLASS_PSF:
     1025      Fcat = isnan (measure[0].FluxPSF)  ? MagToFlux(measure[0].M + Moff)     : measure[0].FluxPSF * Foff;
     1026      break;
     1027    case MAG_CLASS_KRON:
     1028      Fcat = isnan (measure[0].FluxKron) ? MagToFlux(measure[0].Mkron + Moff) : measure[0].FluxKron * Foff;
     1029      break;
     1030    case MAG_CLASS_APER:
     1031      Fcat = isnan (measure[0].FluxAp)   ? MagToFlux(measure[0].Map + Moff)   : measure[0].FluxAp * Foff;
     1032      break;
     1033    default:
     1034      break;
     1035  }
     1036  if (isnan(Fcat)) return (NAN);
     1037
     1038  // find the relevant color
     1039  float mc = PhotColorForCode (average, secfilt, NULL, code);
     1040  if (isnan(mc)) return (Fcat);
     1041  mc -= SCALE*code[0].dX;
     1042
     1043  // find the color correction in mags
     1044  int i = 0;
     1045  double Mc = mc;
     1046  float Mcol = 0;
    10911047  for (i = 0; i < code[0].Nc; i++) {
    10921048    Mcol += code[0].X[i]*Mc;
    10931049    Mc *= mc;
    10941050  }
    1095   Msys = Mcat + Mcol;
    1096   return (Msys);
    1097 }
    1098 
    1099 float PhotRelTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt) {
    1100 
    1101   int i, Np;
    1102   float Mcat, Mcol, Mrel, mc, Mc;
    1103   PhotCode *code;
    1104 
    1105   Np = photcodes[0].hashcode[measure[0].photcode];
     1051  float Fcol = MagToFlux (Mcol);
     1052
     1053  float Fsys = Fcat * Fcol;
     1054  return (Fsys);
     1055}
     1056
     1057float PhotFluxRel (Measure *measure, Average *average, SecFilt *secfilt, dvoMagClassType class) {
     1058
     1059  int Np = photcodes[0].hashcode[measure[0].photcode];
    11061060  if (Np == -1) return (NAN);
    1107 
    1108   if (photcodes[0].code[Np].type == PHOT_REF) {
    1109     Mcat = measure[0].M;
    1110     return (Mcat);
    1111   }
    1112   code = &photcodes[0].code[Np];
    1113   Mrel = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
     1061  PhotCode *code = &photcodes[0].code[Np];
     1062
     1063  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
     1064  float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
     1065  float Moff = Mcal - ZERO_POINT + 8.9;
     1066  float Foff = 3630.8 * MagToFlux(Mcal);
     1067  float Fcat = NAN;
     1068  switch (class) {
     1069    case MAG_CLASS_PSF:
     1070      Fcat = isnan (measure[0].FluxPSF)  ? MagToFlux(measure[0].M + Moff)     : measure[0].FluxPSF * Foff;
     1071      break;
     1072    case MAG_CLASS_KRON:
     1073      Fcat = isnan (measure[0].FluxKron) ? MagToFlux(measure[0].Mkron + Moff) : measure[0].FluxKron * Foff;
     1074      break;
     1075    case MAG_CLASS_APER:
     1076      Fcat = isnan (measure[0].FluxAp)   ? MagToFlux(measure[0].Map + Moff)   : measure[0].FluxAp * Foff;
     1077      break;
     1078    default:
     1079      break;
     1080  }
     1081  if (isnan(Fcat)) return (NAN);
    11141082
    11151083  /* for DEP, color must be made of PRI/SEC */
    1116   mc = PhotColorForCodeTiny (average, secfilt, NULL, code);
    1117   if (isnan(mc)) return (Mrel);
    1118   mc = mc - SCALE*code[0].dX;
    1119 
    1120   Mc = mc;
    1121   Mcol = 0;
     1084  float mc = PhotColorForCode (average, secfilt, NULL, code);
     1085  if (isnan(mc)) return (Fcat);
     1086  mc -= SCALE*code[0].dX;
     1087
     1088  double Mc = mc;
     1089  float Mcol = 0;
     1090  int i = 0;
     1091  for (i = 0; i < code[0].Nc; i++) {
     1092    Mcol += code[0].X[i]*Mc;
     1093    Mc *= mc;
     1094  }
     1095  float Fcol = MagToFlux (Mcol);
     1096
     1097  float Frel = Fcat * Fcol;
     1098  return (Frel);
     1099}
     1100
     1101/* return calibrated magnitude from measure for given photcode */
     1102float PhotFluxCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code, dvoMagClassType class) {
     1103
     1104  int i;
     1105
     1106  if (code == NULL) return NAN;
     1107
     1108  /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
     1109  int Np = photcodes[0].hashcode[thisone[0].photcode];
     1110  if (Np == -1) return (NAN);
     1111  PhotCode *myCode = &photcodes[0].code[Np];
     1112
     1113  if (code->code != myCode->equiv) return (NAN);
     1114
     1115  float Frel = PhotFluxRel (thisone, average, secfilt, class) + SCALE*code[0].C;
     1116
     1117  // get the relevant color term
     1118  float mc = PhotColorForCode (average, secfilt, measure, code);
     1119  if (isnan(mc)) return (Frel);
     1120  mc -= SCALE*code[0].dX;
     1121
     1122  // get the corresponding color correction in mags, convert to flux
     1123  double Mc = mc;
     1124  float Mcol = 0;
     1125  for (i = 0; i < code[0].Nc; i++) {
     1126    Mcol += code[0].X[i]*Mc;
     1127    Mc *= mc;
     1128  }
     1129  float Fcol = MagToFlux (Mcol);
     1130
     1131  float Fcal = Frel * Fcol;
     1132  return (Fcal);
     1133}
     1134
     1135/***/
     1136float PhotFluxAve (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source) {
     1137
     1138  if (code == NULL) return NAN;
     1139
     1140  int Ns = photcodes[0].hashNsec[code[0].code];
     1141  if (Ns == -1) return (NAN);
     1142
     1143  float Fave = NAN;
     1144  switch (source) {
     1145    case MAG_SRC_CHP:
     1146      switch (class) {
     1147        case MAG_CLASS_PSF:
     1148          Fave = MagToFlux(secfilt[Ns].M);
     1149          break;
     1150        case MAG_CLASS_KRON:
     1151          Fave = MagToFlux(secfilt[Ns].Mkron);
     1152          break;
     1153        case MAG_CLASS_APER:
     1154          Fave = MagToFlux(secfilt[Ns].Map);
     1155          break;
     1156        default:
     1157          break;
     1158      }
     1159      break;
     1160    case MAG_SRC_WRP:
     1161      switch (class) {
     1162        case MAG_CLASS_PSF:
     1163          Fave = isnan (secfilt[Ns].FpsfWrp)  ? MagToFlux(secfilt[Ns].MpsfWrp)  : secfilt[Ns].FpsfWrp;
     1164          break;
     1165        case MAG_CLASS_KRON:
     1166          Fave = isnan (secfilt[Ns].FkronWrp) ? MagToFlux(secfilt[Ns].MkronWrp) : secfilt[Ns].FkronWrp;
     1167          break;
     1168        case MAG_CLASS_APER:
     1169          Fave = isnan (secfilt[Ns].FapWrp)   ? MagToFlux(secfilt[Ns].MapWrp)   : secfilt[Ns].FapWrp;
     1170          break;
     1171        default:
     1172          break;
     1173      }
     1174      break;
     1175    case MAG_SRC_STK:
     1176      switch (class) {
     1177        case MAG_CLASS_PSF:
     1178          Fave = isnan (secfilt[Ns].FpsfStk)  ? MagToFlux(secfilt[Ns].MpsfStk)  : secfilt[Ns].FpsfStk;
     1179          break;
     1180        case MAG_CLASS_KRON:
     1181          Fave = isnan (secfilt[Ns].FkronStk) ? MagToFlux(secfilt[Ns].MkronStk) : secfilt[Ns].FkronStk;
     1182          break;
     1183        case MAG_CLASS_APER:
     1184          Fave = isnan (secfilt[Ns].FapStk)   ? MagToFlux(secfilt[Ns].MapStk)   : secfilt[Ns].FapStk;
     1185          break;
     1186        default:
     1187          break;
     1188      }
     1189      break;
     1190    default:
     1191      break;
     1192  }
     1193  return (Fave);
     1194}
     1195
     1196float PhotFluxAveErr (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source) {
     1197
     1198  if (code == NULL) return NAN;
     1199
     1200  int Ns = photcodes[0].hashNsec[code[0].code];
     1201  if (Ns == -1) return (NAN);
     1202
     1203  float dFave = NAN;
     1204  switch (source) {
     1205    case MAG_SRC_CHP:
     1206      switch (class) {
     1207        case MAG_CLASS_PSF:
     1208          dFave = secfilt[Ns].dM * MagToFlux(secfilt[Ns].M);
     1209          break;
     1210        case MAG_CLASS_KRON:
     1211          dFave = secfilt[Ns].dMkron * MagToFlux(secfilt[Ns].Mkron);
     1212          break;
     1213        case MAG_CLASS_APER:
     1214          dFave = secfilt[Ns].dMap * MagToFlux(secfilt[Ns].Map);
     1215          break;
     1216        default:
     1217          break;
     1218      }
     1219      break;
     1220    case MAG_SRC_WRP:
     1221      switch (class) {
     1222        case MAG_CLASS_PSF:
     1223          dFave = secfilt[Ns].dFpsfWrp;
     1224          break;
     1225        case MAG_CLASS_KRON:
     1226          dFave = secfilt[Ns].dFkronWrp;
     1227          break;
     1228        case MAG_CLASS_APER:
     1229          dFave = secfilt[Ns].dFapWrp;
     1230          break;
     1231        default:
     1232          break;
     1233      }
     1234      break;
     1235    case MAG_SRC_STK:
     1236      switch (class) {
     1237        case MAG_CLASS_PSF:
     1238          dFave = secfilt[Ns].dFpsfStk;
     1239          break;
     1240        case MAG_CLASS_KRON:
     1241          dFave = secfilt[Ns].dFkronStk;
     1242          break;
     1243        case MAG_CLASS_APER:
     1244          dFave = secfilt[Ns].dFapStk;
     1245          break;
     1246        default:
     1247          break;
     1248      }
     1249      break;
     1250    default:
     1251      break;
     1252  }
     1253  return (dFave);
     1254}
     1255
     1256/* return calibrated magnitude from average/secfilt for given photcode */
     1257float PhotFluxRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure, dvoMagClassType class, dvoMagSourceType source) {
     1258
     1259  int i;
     1260
     1261  float Fave = PhotFluxAve (code, average, secfilt, class, source);
     1262  if (isnan(Fave)) return NAN;
     1263
     1264  // correct for relative zero-point
     1265  float Moff = SCALE*code[0].C;
     1266
     1267  float mc = PhotColorForCode (average, secfilt, measure, code);
     1268  if (isnan(mc)) return (Fave * MagToFlux(Moff));
     1269  mc -= SCALE*code[0].dX;
     1270
     1271  // correct for color terms
     1272  double Mc = mc;
     1273  float Mcol = 0;
    11221274  for (i = 0; i < code[0].Nc; i++) {
    11231275    Mcol += code[0].X[i]*Mc;
    11241276    Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
    11251277  }
    1126   Mrel += Mcol;
    1127   return (Mrel);
    1128 }
    1129 
    1130 /* return calibrated magnitude from measure for given photcode */
    1131 float PhotCalTiny (MeasureTiny *thisone, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code) {
    1132 
    1133   int i, Np;
    1134   float Mcal, Mrel, Mcol, mc, Mc;
    1135 
    1136   if (code == NULL) return NAN;
    1137 
    1138   /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
    1139   Np = photcodes[0].hashcode[thisone[0].photcode];
     1278  float Foff = MagToFlux(Mcol);
     1279  return (Fave * Foff);
     1280}
     1281
     1282float PhotFluxInstErr (Measure *measure, dvoMagClassType class) {
     1283
     1284  float Moff = - measure[0].dt - ZERO_POINT;
     1285
     1286  // use dFlux if we can, but use dMag if we must:
     1287  // dFlux = Flux * dMag
     1288
     1289  float dFinst = NAN;
     1290  switch (class) {
     1291    case MAG_CLASS_PSF:
     1292      if (isnan (measure[0].dFluxPSF)) {
     1293        float Finst = MagToFlux(measure[0].M + Moff);
     1294        dFinst = measure[0].dM * Finst;
     1295      } else {
     1296        dFinst = measure[0].dFluxPSF;
     1297      }
     1298      break;
     1299    case MAG_CLASS_KRON:
     1300      if (isnan (measure[0].dFluxKron)) {
     1301        float Finst = MagToFlux(measure[0].Mkron + Moff);
     1302        dFinst = measure[0].dMkron * Finst;
     1303      } else {
     1304        dFinst = measure[0].dFluxKron;
     1305      }
     1306      break;
     1307    case MAG_CLASS_APER:
     1308      if (isnan (measure[0].dFluxAp)) {
     1309        float Finst = MagToFlux(measure[0].Map + Moff);
     1310        dFinst = measure[0].dMap * Finst;
     1311      } else {
     1312        dFinst = measure[0].dFluxAp;
     1313      }
     1314      break;
     1315    default:
     1316      break;
     1317  }
     1318  return (dFinst);
     1319}
     1320
     1321float PhotFluxCatErr (Measure *measure, dvoMagClassType class) {
     1322
     1323  int Np = photcodes[0].hashcode[measure[0].photcode];
    11401324  if (Np == -1) return (NAN);
    1141 
    1142   if (photcodes[0].code[Np].type == PHOT_REF) {
    1143     Mrel = thisone[0].M;
    1144     return (Mrel);
    1145   }
    1146   if (code[0].code != photcodes[0].code[Np].equiv) return (NAN);
    1147 
    1148   Mcal = PhotRelTiny (thisone, average, secfilt) + SCALE*code[0].C;
    1149 
    1150   mc = PhotColorForCodeTiny (average, secfilt, measure, code);
    1151   if (isnan(mc)) return (Mcal);
    1152   mc = mc - SCALE*code[0].dX;
    1153 
    1154   Mc = mc;
    1155   Mcol = 0;
     1325  PhotCode *code = &photcodes[0].code[Np];
     1326
     1327  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
     1328  float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     1329  float Moff = Mcal - ZERO_POINT + 8.9;
     1330  float Foff = 3630.8 * MagToFlux(Mcal);
     1331
     1332  // use dFlux if we can, but use dMag if we must:
     1333  // dFlux = Flux * dMag
     1334
     1335  float dFcat = NAN;
     1336  switch (class) {
     1337    case MAG_CLASS_PSF:
     1338      if (isnan (measure[0].dFluxPSF)) {
     1339        float Finst = MagToFlux(measure[0].M + Moff);
     1340        dFcat = measure[0].dM * Finst;
     1341      } else {
     1342        dFcat = measure[0].dFluxPSF * Foff;
     1343      }
     1344      break;
     1345    case MAG_CLASS_KRON:
     1346      if (isnan (measure[0].dFluxKron)) {
     1347        float Finst = MagToFlux(measure[0].Mkron + Moff);
     1348        dFcat = measure[0].dMkron * Finst;
     1349      } else {
     1350        dFcat = measure[0].dFluxKron * Foff;
     1351      }
     1352      break;
     1353    case MAG_CLASS_APER:
     1354      if (isnan (measure[0].dFluxAp)) {
     1355        float Finst = MagToFlux(measure[0].Map + Moff);
     1356        dFcat = measure[0].dMap * Finst;
     1357      } else {
     1358        dFcat = measure[0].dFluxAp * Foff;
     1359      }
     1360      break;
     1361    default:
     1362      break;
     1363  }
     1364  return (dFcat);
     1365}
     1366
     1367/******** alternate photometry conversion functions using MeasureTiny and AverageTiny *********/
     1368float PhotInstTiny (MeasureTiny *measure, dvoMagClassType class) {
     1369
     1370  int Np = photcodes[0].hashcode[measure[0].photcode];
     1371  if (Np == -1) return (NAN);
     1372  PhotCode *code = &photcodes[0].code[Np];
     1373
     1374  float Mraw = NAN;
     1375  switch (class) {
     1376    case MAG_CLASS_PSF:
     1377      Mraw = measure[0].M;
     1378      break;
     1379    case MAG_CLASS_KRON:
     1380      // Mraw = measure[0].Mkron;
     1381      break;
     1382    case MAG_CLASS_APER:
     1383      // Mraw = measure[0].Map;
     1384      break;
     1385    default:
     1386      break;
     1387  }
     1388  if (code->type == PHOT_REF) {
     1389    return (Mraw);
     1390  }
     1391  float Minst = Mraw - measure[0].dt - ZERO_POINT;
     1392
     1393  return (Minst);
     1394}
     1395
     1396float PhotCatTiny (MeasureTiny *measure, dvoMagClassType class) {
     1397
     1398  int Np = photcodes[0].hashcode[measure[0].photcode];
     1399  if (Np == -1) return (NAN);
     1400  PhotCode *code = &photcodes[0].code[Np];
     1401
     1402  float Mraw = NAN;
     1403  switch (class) {
     1404    case MAG_CLASS_PSF:
     1405      Mraw = measure[0].M;
     1406      break;
     1407    case MAG_CLASS_KRON:
     1408      // Mraw = measure[0].Mkron;
     1409      break;
     1410    case MAG_CLASS_APER:
     1411      // Mraw = measure[0].Map;
     1412      break;
     1413    default:
     1414      break;
     1415  }
     1416  if (code->type == PHOT_REF) {
     1417    return (Mraw);
     1418  }
     1419
     1420  float Mcat = Mraw - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     1421 
     1422  return (Mcat);
     1423}
     1424
     1425float PhotSysTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt, dvoMagClassType class) {
     1426
     1427  int Np = photcodes[0].hashcode[measure[0].photcode];
     1428  if (Np == -1) return (NAN);
     1429  PhotCode *code = &photcodes[0].code[Np];
     1430
     1431  float Mraw = NAN;
     1432  switch (class) {
     1433    case MAG_CLASS_PSF:
     1434      Mraw = measure[0].M;
     1435      break;
     1436    case MAG_CLASS_KRON:
     1437      // Mraw = measure[0].Mkron;
     1438      break;
     1439    case MAG_CLASS_APER:
     1440      // Mraw = measure[0].Map;
     1441      break;
     1442    default:
     1443      break;
     1444  }
     1445  if (code->type == PHOT_REF) {
     1446    return (Mraw);
     1447  }
     1448  float Mcat = Mraw - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     1449
     1450  /* for DEP, color must be made of PRI/SEC */
     1451  float mc = PhotColorForCodeTiny (average, secfilt, NULL, code);
     1452  if (isnan(mc)) return (Mcat);
     1453  mc -= SCALE*code[0].dX;
     1454
     1455  int i = 0;
     1456  double Mc = mc;
     1457  float Mcol = 0;
    11561458  for (i = 0; i < code[0].Nc; i++) {
    11571459    Mcol += code[0].X[i]*Mc;
    11581460    Mc *= mc;
    11591461  }
     1462  float Msys = Mcat + Mcol;
     1463  return (Msys);
     1464}
     1465
     1466float PhotRelTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt, dvoMagClassType class) {
     1467
     1468  int Np = photcodes[0].hashcode[measure[0].photcode];
     1469  if (Np == -1) return (NAN);
     1470  PhotCode *code = &photcodes[0].code[Np];
     1471
     1472  float Mraw = NAN;
     1473  switch (class) {
     1474    case MAG_CLASS_PSF:
     1475      Mraw = measure[0].M;
     1476      break;
     1477    case MAG_CLASS_KRON:
     1478      // Mraw = measure[0].Mkron;
     1479      break;
     1480    case MAG_CLASS_APER:
     1481      // Mraw = measure[0].Map;
     1482      break;
     1483    default:
     1484      break;
     1485  }
     1486  if (code->type == PHOT_REF) {
     1487    return (Mraw);
     1488  }
     1489  float Mcat = Mraw - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
     1490
     1491  /* for DEP, color must be made of PRI/SEC */
     1492  float mc = PhotColorForCodeTiny (average, secfilt, NULL, code);
     1493  if (isnan(mc)) return (Mcat);
     1494  mc -= SCALE*code[0].dX;
     1495
     1496  double Mc = mc;
     1497  float Mcol = 0;
     1498  int i = 0;
     1499  for (i = 0; i < code[0].Nc; i++) {
     1500    Mcol += code[0].X[i]*Mc;
     1501    Mc *= mc;
     1502  }
     1503  float Mrel = Mcat + Mcol;
     1504  return (Mrel);
     1505}
     1506
     1507/* return calibrated magnitude from measure for given photcode */
     1508float PhotCalTiny (MeasureTiny *thisone, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code, dvoMagClassType class) {
     1509
     1510  int i;
     1511
     1512  if (code == NULL) return NAN;
     1513
     1514  /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
     1515  int Np = photcodes[0].hashcode[thisone[0].photcode];
     1516  if (Np == -1) return (NAN);
     1517  PhotCode *myCode = &photcodes[0].code[Np];
     1518
     1519  if (code->code != myCode->equiv) return (NAN);
     1520
     1521  // if we are REF type, just get the right version and return
     1522  if (myCode->type == PHOT_REF) {
     1523    float Mraw = NAN;
     1524    switch (class) {
     1525      case MAG_CLASS_PSF:
     1526        Mraw = thisone[0].M;
     1527        break;
     1528      case MAG_CLASS_KRON:
     1529        // Mraw = thisone[0].Mkron;
     1530        break;
     1531      case MAG_CLASS_APER:
     1532        // Mraw = thisone[0].Map;
     1533        break;
     1534      default:
     1535        break;
     1536    }
     1537    return (Mraw);
     1538  }
     1539
     1540  float Mcal = PhotRelTiny (thisone, average, secfilt, class) + SCALE*code[0].C;
     1541
     1542  float mc = PhotColorForCodeTiny (average, secfilt, measure, code);
     1543  if (isnan(mc)) return (Mcal);
     1544  mc -= SCALE*code[0].dX;
     1545
     1546  double Mc = mc;
     1547  float Mcol = 0;
     1548  for (i = 0; i < code[0].Nc; i++) {
     1549    Mcol += code[0].X[i]*Mc;
     1550    Mc *= mc;
     1551  }
    11601552  Mcal += Mcol;
    11611553  return (Mcal);
     1554}
     1555
     1556/***/
     1557float PhotAveTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source) {
     1558
     1559  if (code == NULL) return NAN;
     1560
     1561  int Ns = photcodes[0].hashNsec[code[0].code];
     1562  if (Ns == -1) return (NAN);
     1563
     1564  float Mave = NAN;
     1565  switch (source) {
     1566    case MAG_SRC_CHP:
     1567      switch (class) {
     1568        case MAG_CLASS_PSF:
     1569          Mave = secfilt[Ns].M;
     1570          break;
     1571        case MAG_CLASS_KRON:
     1572          Mave = secfilt[Ns].Mkron;
     1573          break;
     1574        case MAG_CLASS_APER:
     1575          Mave = secfilt[Ns].Map;
     1576          break;
     1577        default:
     1578          break;
     1579      }
     1580      break;
     1581    case MAG_SRC_WRP:
     1582      switch (class) {
     1583        case MAG_CLASS_PSF:
     1584          Mave = secfilt[Ns].MpsfWrp;
     1585          break;
     1586        case MAG_CLASS_KRON:
     1587          Mave = secfilt[Ns].MkronWrp;
     1588          break;
     1589        case MAG_CLASS_APER:
     1590          Mave = secfilt[Ns].MapWrp;
     1591          break;
     1592        default:
     1593          break;
     1594      }
     1595      break;
     1596    case MAG_SRC_STK:
     1597      switch (class) {
     1598        case MAG_CLASS_PSF:
     1599          Mave = secfilt[Ns].MpsfStk;
     1600          break;
     1601        case MAG_CLASS_KRON:
     1602          Mave = secfilt[Ns].MkronStk;
     1603          break;
     1604        case MAG_CLASS_APER:
     1605          Mave = secfilt[Ns].MapStk;
     1606          break;
     1607        default:
     1608          break;
     1609      }
     1610      break;
     1611    default:
     1612      break;
     1613  }
     1614  return (Mave);
     1615}
     1616
     1617/* return calibrated magnitude from average/secfilt for given photcode */
     1618float PhotRefTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, dvoMagClassType class, dvoMagSourceType source) {
     1619
     1620  int i;
     1621
     1622  float Mave = PhotAveTiny (code, average, secfilt, class, source);
     1623  if (isnan(Mave)) return NAN;
     1624
     1625  // correct for relative zero-point
     1626  float Mref = Mave + SCALE*code[0].C;
     1627
     1628  float mc = PhotColorForCodeTiny (average, secfilt, measure, code);
     1629  if (isnan(mc)) return (Mref);
     1630  mc -= SCALE*code[0].dX;
     1631
     1632  // correct for color terms
     1633  double Mc = mc;
     1634  float Mcol = 0;
     1635  for (i = 0; i < code[0].Nc; i++) {
     1636    Mcol += code[0].X[i]*Mc;
     1637    Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
     1638  }
     1639  Mref += Mcol;
     1640  return (Mref);
    11621641}
    11631642
     
    12121691}
    12131692
    1214 /* return calibrated magnitude from average/secfilt for given photcode */
    1215 float PhotRefTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure) {
    1216 
    1217   int i, Ns;
    1218   float Mave, Mref, Mcol, mc;
    1219   double Mc;
    1220 
    1221   if (code == NULL) return NAN;
    1222 
    1223   Ns = photcodes[0].hashNsec[code[0].code];
    1224   Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
    1225   Mref = Mave + SCALE*code[0].C;
    1226 
    1227   mc = PhotColorForCodeTiny (average, secfilt, measure, code);
    1228   if (isnan(mc)) return (Mref);
    1229   mc = mc - SCALE*code[0].dX;
    1230 
    1231   Mc = mc;
    1232   Mcol = 0;
    1233   for (i = 0; i < code[0].Nc; i++) {
    1234     Mcol += code[0].X[i]*Mc;
    1235     Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
    1236   }
    1237   Mref += Mcol;
    1238   return (Mref);
    1239 }
    1240 
    1241 /***/
    1242 float PhotAveTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt) {
    1243 
    1244   int Ns;
    1245   float Mave;
    1246 
    1247   if (code == NULL) return NAN;
    1248 
    1249   Ns = photcodes[0].hashNsec[code[0].code];
    1250   Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
    1251   return (Mave);
    1252 }
    1253 
    12541693float PhotdMTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt) {
    12551694
     
    12641703}
    12651704
    1266 // XXX return NAN or NAN_S_SHORT? (secfilt->Xm is short)
     1705// Xm is now (2014.07.03) stored as the chisq except in dvo formats which use as short
    12671706float PhotXmTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt) {
    12681707
    12691708  int Ns;
    1270   short Mi;
    12711709  float Xm;
    12721710
     
    12741712
    12751713  Ns = photcodes[0].hashNsec[code[0].code];
    1276   Mi = (Ns == -1) ? NAN : secfilt[Ns].Xm;
    1277   Xm = (isnan(Mi)) ? -1.0 : pow (10.0, 0.01*Mi);
     1714  Xm = (Ns == -1) ? NAN : secfilt[Ns].Mchisq;
    12781715  return (Xm);
    12791716}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_tiny_values.c

    r36680 r37403  
    1414
    1515void CopyMeasureToTiny (MeasureTiny *measureT, Measure *measure) {
    16   measureT[0].dR         = measure[0].dR;
    17   measureT[0].dD         = measure[0].dD;
     16  measureT[0].R          = measure[0].R;
     17  measureT[0].D          = measure[0].D;
    1818  measureT[0].M          = measure[0].M;
    1919  measureT[0].Mcal       = measure[0].Mcal;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/skyregion_io.c

    r33649 r37403  
    7878  gfits_free_matrix (&matrix);
    7979  gfits_free_header (&theader);
     80  fclose (f);
    8081
    8182  return (skytable);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libfits/include/gfitsio.h

    r35756 r37403  
    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/ps2-tc3-20130727/Ohana/src/libfits/matrix/F_compress_M.c

    r34088 r37403  
    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/ps2-tc3-20130727/Ohana/src/libfits/table/F_get_column.c

    r36680 r37403  
    7575  Pout = array;
    7676  if (!strcmp (type, "char")) {
     77    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
     78      *(char *)Pout = *(char *)Pin*Bscale + Bzero;
     79    }
     80  }
     81  if (!strcmp (type, "byte")) {
    7782    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    7883      *(char *)Pout = *(char *)Pin*Bscale + Bzero;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libfits/table/F_set_column.c

    r35101 r37403  
    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/ps2-tc3-20130727/Ohana/src/libfits/table/F_table_format.c

    r28241 r37403  
    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/ps2-tc3-20130727/Ohana/src/libkapa/src/KapaOpen.c

    r35761 r37403  
    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/ps2-tc3-20130727/Ohana/src/libohana/include/ohana.h

    r35754 r37403  
    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)))
     
    183192
    184193# ifndef isfinite
    185 # define isfinite(A) (!isnan(A))
     194# define isfinite(A) (!isnan(A) && !isinf(A))
    186195# endif
    187196
     
    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/ps2-tc3-20130727/Ohana/src/libohana/src

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libohana/src/string.c

    r34753 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/cmd.astro/cplot.c

    r34613 r37403  
    44 
    55  double ra_prev = 0;
    6   int i, kapa, Npts, status, leftside;
     6  int i, kapa, Npts, status, leftside, valid, size;
    77  opihi_flt *x, *y, *r, *d, Rmin, Rmax, Rmid;
    88  Vector Xvec, Yvec, *xvec, *yvec;
     
    1111  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    1212
    13   if (argc != 3) {
     13  valid  = (argc == 3);
     14  valid |= (argc > 4) && !strcmp (argv[3], "where");
     15  if (!valid) {
    1416    gprint (GP_ERR, "USAGE: cplot <ra> <dec> [style]\n");
     17    gprint (GP_ERR, "   OR: cplot <ra> <dec> [style] where (condition)\n");
    1518    return (FALSE);
    1619  }
     
    3235  }
    3336
     37  // tvec is used for logical test (truth vector)
     38  Vector *tvec = NULL;
     39  if (argc > 4) {
     40    char *out = dvomath (argc - 4, &argv[4], &size, 1);
     41    if (out == NULL) {
     42      print_error ();
     43      return FALSE;
     44    }
     45    if ((tvec = SelectVector (out, OLDVECTOR, TRUE)) == NULL) {
     46      gprint (GP_ERR, " invalid logic result\n");
     47      DeleteNamedVector (out);
     48      free (out);
     49      return (FALSE);
     50    }
     51  }
     52
     53  if (tvec && tvec[0].Nelements != yvec[0].Nelements) {
     54    gprint (GP_ERR, "logic test vector not the same length as data vectors\n");
     55    DeleteVector (tvec);
     56    return (FALSE);
     57  }
     58
    3459  SetVector (&Xvec, OPIHI_FLT, xvec[0].Nelements);
    3560  SetVector (&Yvec, OPIHI_FLT, xvec[0].Nelements);
     
    4267  Npts = 0;
    4368  for (i = 0; i < Xvec.Nelements; i++, r++, d++) {
     69    if (tvec) {
     70      int skip = (tvec->type == OPIHI_FLT) ? (tvec->elements.Flt[i] == 0.0) : (tvec->elements.Int[i] == 0.0);
     71      if (skip) continue;
     72    }
     73
    4474    double ra = ohana_normalize_angle (*r);
    4575    while (ra < Rmin) ra += 360.0;
     
    88118  free (Yvec.elements.Ptr);
    89119   
     120  if (tvec) DeleteVector (tvec);
     121
    90122  return (TRUE);
    91123}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.basic/Makefile

    r35237 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/cmd.basic/init.c

    r35237 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/cmd.basic/list.c

    r36680 r37403  
    22# define D_NLINES 100
    33static char prompt[] = ">> ";
    4 
    5 static int set_list_varname (char *line, char *base, int N, int excelStyle);
    64
    75int list (int argc, char **argv) {
     
    311309  return (TRUE);
    312310}
    313 
    314 static int set_list_varname (char *line, char *base, int N, int excelStyle) {
    315 
    316   int i;
    317    
    318   // A-Z correspond to 0 - 25
    319 
    320   if (excelStyle) {
    321     float f = log(26.0);
    322     float g = (N == 0) ? 0.0 : log(1.0*N);
    323     int Ndigit = (int) (g / f) + 1;
    324     if (Ndigit > 10) {
    325       sprintf (line, "%s:ZZZZZZZZZZ", base);
    326       return FALSE;
    327     }
    328     char name[12];
    329     memset (name, 0, 12);
    330     for (i = 0; i < Ndigit; i++) {
    331       float Npow = Ndigit - i - 1;
    332       float g = pow(26.0, Npow);
    333       int V = (int) (N / g);
    334       name[i] = (Npow == 0.0) ? 'A' + V : 'A' + V - 1;
    335       N -= V * g;
    336     }
    337     sprintf (line, "%s:%s", base, name);
    338   } else {
    339     sprintf (line, "%s:%d", base, N);
    340   }
    341   return TRUE;
    342 }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.data/Makefile

    r36680 r37403  
    9898$(SRC)/point.$(ARCH).o          \
    9999$(SRC)/ps.$(ARCH).o             \
     100$(SRC)/print_vectors.$(ARCH).o  \
    100101$(SRC)/queuedelete.$(ARCH).o    \
    101102$(SRC)/queuedrop.$(ARCH).o      \
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.data/init.c

    r36680 r37403  
    8787int point            PROTO((int, char **));
    8888int ps               PROTO((int, char **));
     89int print_vectors    PROTO((int, char **));
    8990int queuelist        PROTO((int, char **));
    9091int queueload        PROTO((int, char **));
     
    250251  {1, "ppm",          jpeg,             "convert display graphic to PPM"},
    251252  {1, "ps",           ps,               "convert display to PostScript"},
     253  {1, "print_vectors", print_vectors,   "print a set of vectors"},
    252254  {1, "queuedelete",  queuedelete,      "delete a queue"},
    253255  {1, "queuedrop",    queuedrop,        "drop values from queue matching a key"},
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.data/read_vectors.c

    r36680 r37403  
    33FILE *f = (FILE *) NULL;
    44char filename[2048];
     5
     6void read_vectors_cleanup ();
    57
    68int datafile (int argc, char **argv) {
     
    2325// vector types
    2426enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME, COLTYPE_CHAR};
    25 static int FITS_TRANSPOSE;
     27
     28static int      Nvec     = 0;
     29static Vector **vec      = NULL;
     30static char   **listname = NULL;
     31static int     *col      = NULL;
     32static int     *coltype  = NULL;
     33static char    *buffer   = NULL;
    2634
    2735int read_vectors (int argc, char **argv) {
     
    2937  int TimeFormat;
    3038  time_t TimeReference;
    31   int i, j, Nskip, Narg, Nvec, *col, IsCSV, VERBOSE;
    32   int Nbytes, Nstart, NELEM, Nelem, nread, *coltype;
     39  int i, j, Nskip, Narg, IsCSV, VERBOSE;
     40  int Nbytes, Nstart, NELEM, Nelem, nread;
    3341  char *colstr, *c0, *c1, *extname;
    34   Vector **vec;
    35 
    36   char *buffer = NULL;
    37 
    38   FITS_TRANSPOSE = FALSE;
    39   if ((Narg = get_argument (argc, argv, "-transpose"))) {
    40     remove_argument (Narg, &argc, argv);
    41     FITS_TRANSPOSE = TRUE;
    42   }
     42  char varname[1024];  // used as a buffer for the names of string fields
    4343
    4444  /* auto-sense table type */
     
    8888
    8989  Nvec = (argc - 1) / 2;
     90  ALLOCATE (listname, char *, Nvec);
    9091  ALLOCATE (vec, Vector *, Nvec);
    9192  ALLOCATE (col, int, Nvec);
    9293  ALLOCATE (coltype, int, Nvec);
     94  for (i = 0; i < Nvec; i++) {
     95    listname[i] = NULL;
     96    vec[i] = NULL;
     97  }
    9398
    9499  for (i = 0; i < Nvec; i++) {
     
    115120    }
    116121
    117     if ((vec[i] = SelectVector (argv[2*i + 1], ANYVECTOR, TRUE)) == NULL) {
    118       gprint (GP_ERR, "USAGE: read name N name N ...\n");
    119       free (vec);
    120       free (col);
    121       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      }
    122130    }
    123131
     
    144152    bad_colname:
    145153      gprint (GP_ERR, "USAGE: read name N name N ...\n");
    146       free (vec);
    147       free (col);
     154      read_vectors_cleanup();
    148155      return (FALSE);   
    149156    }
     
    153160  NELEM = 1000;
    154161  for (i = 0; i < Nvec; i++) {
    155     if ((coltype[i] == COLTYPE_INT) || (coltype[i] == COLTYPE_CHAR)) {
    156       ResetVector (vec[i], OPIHI_INT, NELEM);
    157     } else {
    158       // note that COLTYPE_TIME is a type of float
    159       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;
    160174    }
    161175  }
     
    166180    if (scan_line_maxlen (f, buffer, 0x10000) == EOF) {
    167181      gprint (GP_ERR, "problem reading file %s\n", filename);
    168       free (vec);
    169       free (col);
     182      read_vectors_cleanup();
    170183      return FALSE;
    171184    }
     
    213226      for (i = 0; i < Nvec; i++) {
    214227        int ivalue;
    215         char cvalue;
    216228        double dvalue;
    217229        time_t tvalue;
     
    224236            break;
    225237          case COLTYPE_CHAR:
    226             readStatus = IsCSV ? charparse_csv (&cvalue, col[i], c0) : charparse (&cvalue, col[i], c0);
    227             vec[i][0].elements.Int[Nelem] = readStatus ? cvalue : 0;
    228             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            }
    229255          case COLTYPE_FLT:
    230256            readStatus = IsCSV ? dparse_csv (&dvalue, col[i], c0) : dparse (&dvalue, col[i], c0);
     
    256282        NELEM += 1000;
    257283        for (i = 0; i < Nvec; i++) {
    258           if (coltype[i] == COLTYPE_INT) {
    259             REALLOCATE (vec[i][0].elements.Int, opihi_int, NELEM);
    260           } else {
    261             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;
    262295          }
    263296        }
     
    266299    }
    267300  }
     301  // set the final vector / list length
    268302  for (i = 0; i < Nvec; i++) {
    269     if (coltype[i] == COLTYPE_INT) {
    270       REALLOCATE (vec[i][0].elements.Int, opihi_int, MAX (Nelem,1));
    271     } else {
    272       REALLOCATE (vec[i][0].elements.Flt, opihi_flt, MAX (Nelem,1));
    273     }
    274     vec[i][0].Nelements = Nelem;
    275   }
    276  
    277   free (vec);
    278   free (col);
    279   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();
    280320  return (TRUE);
    281 
    282321}
    283322
    284 # define ESCAPE(MSG) { \
    285   gprint (GP_ERR, "%s\n", MSG); \
     323# define ESCAPE(...) {          \
     324  gprint (GP_ERR, __VA_ARGS__); \
    286325  if (CCDKeyword != NULL) free (CCDKeyword); \
    287326  gfits_free_table  (&table); \
     
    292331
    293332  off_t Nbytes;
    294   int i, j, k, N, Nextend, Ny, Binary, vecType, padIfShort;
     333  int i, j, N, Nextend, Ny, Binary, vecType, padIfShort;
    295334  char type[16], ID[80], *CCDKeyword;
    296335  FTable table;
    297336  Header header;
    298337  Vector **vec;
     338  int FITS_TRANSPOSE;
    299339
    300340  table.buffer = NULL;
    301341  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  }
    302348
    303349  CCDKeyword = NULL;
     
    328374  // }
    329375
    330   if (argc < 2) ESCAPE ("USAGE: read -fits extension [-extnum] [-keyword key] name name ...");
    331 
    332   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");
    333379  fseeko (f, 0LL, SEEK_SET);
    334380  table.header = &header;
     
    338384    // first extension is PHU, cannot be a table.
    339385    // Nextend counts from 0 for first extension
    340     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");
    341387    Nbytes = gfits_data_size (&header);
    342388    fseeko (f, Nbytes, SEEK_CUR);
     
    344390
    345391    for (i = 0; i < Nextend; i++) {
    346       if (!gfits_load_header (f, &header)) ESCAPE ("extension not found");
     392      if (!gfits_load_header (f, &header)) ESCAPE ("extension %d not found\n", i);
    347393      Nbytes = gfits_data_size (&header);
    348394      /* skip the prior data buffers */
     
    350396      gfits_free_header (&header);
    351397    }
    352     if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension");
    353     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);
    354400
    355401  } else {
     
    382428        continue;
    383429      }
    384       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");
    385431      break;
    386432    }
     
    391437  gfits_scan (&header, "XTENSION", "%s", 1, type);
    392438  if (strcmp (type, "BINTABLE") && strcmp (type, "TABLE")) {
    393     ESCAPE ("specified extension is not a table\n");
     439    ESCAPE ("specified extension %s is not a table\n", type);
    394440  }
    395441  Binary = !strcmp (type, "BINTABLE");
     
    418464       
    419465    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
    420488      // define the multifield vector names (Nval vectors x Ny elements)
    421489      ALLOCATE (vec, Vector *, Nval);
     
    429497      }
    430498
    431       if (!strcmp (type, "char")) {
    432         char *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, "short")) {
    440         short *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, "int")) {
    448         int *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, "int64_t")) {
    456         int64_t *Ptr = data;
    457         for (j = 0; j < Ny; j++) {
    458           for (k = 0; k < Nval; k++, Ptr++) {
    459             vec[k][0].elements.Int[j] = *Ptr;
    460           }
    461         }
    462       }
    463       if (!strcmp (type, "float")) {
    464         float *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         }
    470       }
    471       if (!strcmp (type, "double")) {
    472         double *Ptr = data;
    473         for (j = 0; j < Ny; j++) {
    474           for (k = 0; k < Nval; k++, Ptr++) {
    475             vec[k][0].elements.Flt[j] = *Ptr;
    476           }
    477         }
    478       }
     499      if (!VectorAssignData (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s", type);
     500
    479501    } else {
    480502      // define the multifield vector names (Ny vectors x Nval elements)
     
    489511      }
    490512
    491       if (!strcmp (type, "char")) {
    492         char *Ptr = data;
    493         for (j = 0; j < Ny; j++) {
    494           for (k = 0; k < Nval; k++, Ptr++) {
    495             vec[j][0].elements.Int[k] = *Ptr;
    496           }
    497         }
    498       }
    499       if (!strcmp (type, "short")) {
    500         short *Ptr = data;
    501         for (j = 0; j < Ny; j++) {
    502           for (k = 0; k < Nval; k++, Ptr++) {
    503             vec[j][0].elements.Int[k] = *Ptr;
    504           }
    505         }
    506       }
    507       if (!strcmp (type, "int")) {
    508         int *Ptr = data;
    509         for (j = 0; j < Ny; j++) {
    510           for (k = 0; k < Nval; k++, Ptr++) {
    511             vec[j][0].elements.Int[k] = *Ptr;
    512           }
    513         }
    514       }
    515       if (!strcmp (type, "int64_t")) {
    516         int64_t *Ptr = data;
    517         for (j = 0; j < Ny; j++) {
    518           for (k = 0; k < Nval; k++, Ptr++) {
    519             vec[j][0].elements.Int[k] = *Ptr;
    520           }
    521         }
    522       }
    523       if (!strcmp (type, "float")) {
    524         float *Ptr = data;
    525         for (j = 0; j < Ny; j++) {
    526           for (k = 0; k < Nval; k++, Ptr++) {
    527             vec[j][0].elements.Flt[k] = *Ptr;
    528           }
    529         }
    530       }
    531       if (!strcmp (type, "double")) {
    532         double *Ptr = data;
    533         for (j = 0; j < Ny; j++) {
    534           for (k = 0; k < Nval; k++, Ptr++) {
    535             vec[j][0].elements.Flt[k] = *Ptr;
    536           }
    537         }
    538       }
     513      if (!VectorAssignDataTranspose (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s", type);
    539514    }
    540515    free (data);
     
    546521  return (TRUE);
    547522}
     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/ps2-tc3-20130727/Ohana/src/opihi/dvo/Makefile

    r36680 r37403  
    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                \
    4251$(SRC)/coordimage.$(ARCH).o             \
    43 $(SRC)/ddmags.$(ARCH).o         \
     52$(SRC)/coordmosaic.$(ARCH).o            \
    4453$(SRC)/detrend.$(ARCH).o                \
    45 $(SRC)/dmagaves.$(ARCH).o               \
    46 $(SRC)/dmagmeas.$(ARCH).o               \
    47 $(SRC)/dmags.$(ARCH).o                  \
    4854$(SRC)/dmt.$(ARCH).o                    \
    4955$(SRC)/elixir.$(ARCH).o                \
    50 $(SRC)/fitcolors.$(ARCH).o             \
    5156$(SRC)/fitsed.$(ARCH).o                \
    5257$(SRC)/gcat.$(ARCH).o                   \
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/avextract.c

    r35416 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/dvo/avmatch.c

    r36680 r37403  
    152152  int needMeasures = FALSE;
    153153  for (i = 0; !needMeasures && (i < Nfields); i++) {
    154     if (fields[i].magMode == MAG_NONE) continue;
    155154    if (fields[i].photcode == NULL) continue; // assert this?
    156155    if (fields[i].photcode[0].type == PHOT_REF) needMeasures = TRUE;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/fitsed.c

    r34088 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/dvo/gstar.c

    r35109 r37403  
    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,
     
    2323  GSTAR_STACK_FLUX_KRON,
    2424  GSTAR_STACK_FLUX_KRON_ERR,
     25  GSTAR_STACK_FLUX_APER,
     26  GSTAR_STACK_FLUX_APER_ERR,
     27  GSTAR_WARP_FLUX_PSF,
     28  GSTAR_WARP_FLUX_PSF_ERR,
     29  GSTAR_WARP_FLUX_KRON,
     30  GSTAR_WARP_FLUX_KRON_ERR,
     31  GSTAR_WARP_FLUX_APER,
     32  GSTAR_WARP_FLUX_APER_ERR,
     33  GSTAR_STACK_MAG_PSF,
     34  GSTAR_STACK_MAG_PSF_ERR,
     35  GSTAR_STACK_MAG_KRON,
     36  GSTAR_STACK_MAG_KRON_ERR,
     37  GSTAR_STACK_MAG_APER,
     38  GSTAR_STACK_MAG_APER_ERR,
     39  GSTAR_WARP_MAG_PSF,
     40  GSTAR_WARP_MAG_PSF_ERR,
     41  GSTAR_WARP_MAG_KRON,
     42  GSTAR_WARP_MAG_KRON_ERR,
     43  GSTAR_WARP_MAG_APER,
     44  GSTAR_WARP_MAG_APER_ERR,
    2545} GSTAR_SECF_CODES;
    2646
     
    3151void sort_index_float (float *X, int *IDX, int N) {
    3252
    33 # define SWAPFUNC(A,B){ float tmp; int itmp;    \
    34   tmp = X[A]; X[A] = X[B]; X[B] = tmp; \
    35   itmp = IDX[A]; IDX[A] = IDX[B]; IDX[B] = itmp; \
    36 }
     53# define SWAPFUNC(A,B){ float tmp; int itmp;            \
     54    tmp = X[A]; X[A] = X[B]; X[B] = tmp;                \
     55    itmp = IDX[A]; IDX[A] = IDX[B]; IDX[B] = itmp;      \
     56  }
    3757# define COMPARE(A,B)(X[A] < X[B])
    3858
     
    5272  off_t i, Nstars, *N1;
    5373  off_t j, k, m, N, Nlo, Nhi;
    54   int Nsecfilt, NPTS, QUIET, FULL_OUTPUT, STACK_OUTPUT, INST, SHOW_MASKS;
     74  int Nsecfilt, NPTS, QUIET, INST, SHOW_MASKS;
    5575  int found, GetMeasures;
    5676  int SaveVectors;
     
    109129  }
    110130
    111   FULL_OUTPUT = FALSE;
     131  int FULL_OUTPUT = FALSE;
    112132  if ((N = get_argument (argc, argv, "-full"))) {
    113133    FULL_OUTPUT = TRUE;
     
    115135  }
    116136
    117   STACK_OUTPUT = FALSE;
    118   if ((N = get_argument (argc, argv, "-stack"))) {
     137  int STACK_OUTPUT = FALSE;
     138  if ((N = get_argument (argc, argv, "+stack"))) {
    119139    STACK_OUTPUT = TRUE;
     140    remove_argument (N, &argc, argv);
     141  }
     142
     143  int EXTRA_OUTPUT = FALSE;
     144  if ((N = get_argument (argc, argv, "+extras"))) {
     145    EXTRA_OUTPUT = TRUE;
     146    remove_argument (N, &argc, argv);
     147  }
     148
     149  int WARP_OUTPUT = FALSE;
     150  if ((N = get_argument (argc, argv, "+warp"))) {
     151    WARP_OUTPUT = TRUE;
     152    remove_argument (N, &argc, argv);
     153  }
     154
     155  int FLUX_OUTPUT = FALSE;
     156  if ((N = get_argument (argc, argv, "+flux"))) {
     157    FLUX_OUTPUT = TRUE;
     158    remove_argument (N, &argc, argv);
     159  }
     160
     161  int MAG_OUTPUT = TRUE;
     162  if ((N = get_argument (argc, argv, "-mag"))) {
     163    MAG_OUTPUT = FALSE;
     164    remove_argument (N, &argc, argv);
     165  }
     166
     167  int KRON_OUTPUT = FALSE;
     168  if ((N = get_argument (argc, argv, "+kron"))) {
     169    KRON_OUTPUT = TRUE;
     170    remove_argument (N, &argc, argv);
     171  }
     172
     173  int APER_OUTPUT = FALSE;
     174  if ((N = get_argument (argc, argv, "+aper"))) {
     175    APER_OUTPUT = TRUE;
    120176    remove_argument (N, &argc, argv);
    121177  }
     
    185241  // an error exit status here is a significant error
    186242  if (!dvo_catalog_open (&catalog, NULL, FALSE, "r")) {
    187       fprintf (stderr, "ERROR: failure to open catalog file %s\n", catalog.filename);
    188       exit (2);
     243    fprintf (stderr, "ERROR: failure to open catalog file %s\n", catalog.filename);
     244    exit (2);
    189245  }
    190246  dvo_catalog_unlock (&catalog);
     
    248304      k = N1[i];
    249305      if (!QUIET) {
    250         gprint (GP_LOG, "star: "OFF_T_FMT"\n",  i);
     306        gprint (GP_LOG, "star: "OFF_T_FMT"\n",  k);
    251307        gprint (GP_LOG, "%11.7f ", catalog.average[k].R);
    252308        gprint (GP_LOG, "%11.7f ", catalog.average[k].D);
     
    259315       
    260316        if (FULL_OUTPUT) {
    261             gprint (GP_LOG, "%f ",     catalog.average[k].dR);
    262             gprint (GP_LOG, "%f ",     catalog.average[k].dD);
    263             gprint (GP_LOG, "%f ",     catalog.average[k].uR);
    264             gprint (GP_LOG, "%f ",     catalog.average[k].uD);
    265             gprint (GP_LOG, "%f ",     catalog.average[k].duR);
    266             gprint (GP_LOG, "%f ",     catalog.average[k].duD);
    267             gprint (GP_LOG, "%f ",     catalog.average[k].P);
    268             gprint (GP_LOG, "%f   ",     catalog.average[k].dP);
    269 
    270             gprint (GP_LOG, "%f   ",     catalog.average[k].ChiSqPM);
    271             gprint (GP_LOG, "%f   ",     catalog.average[k].ChiSqPar);
    272 
    273             date = ohana_sec_to_date (catalog.average[k].Tmean);
    274             gprint (GP_LOG, "%20s ",     date);
    275             gprint (GP_LOG, "%f   ",     catalog.average[k].Trange / 86400.0);
     317          gprint (GP_LOG, "%f ",     catalog.average[k].dR);
     318          gprint (GP_LOG, "%f ",     catalog.average[k].dD);
     319          gprint (GP_LOG, "%f ",     catalog.average[k].uR);
     320          gprint (GP_LOG, "%f ",     catalog.average[k].uD);
     321          gprint (GP_LOG, "%f ",     catalog.average[k].duR);
     322          gprint (GP_LOG, "%f ",     catalog.average[k].duD);
     323          gprint (GP_LOG, "%f ",     catalog.average[k].P);
     324          gprint (GP_LOG, "%f   ",     catalog.average[k].dP);
     325
     326          gprint (GP_LOG, "%f   ",     catalog.average[k].ChiSqPM);
     327          gprint (GP_LOG, "%f   ",     catalog.average[k].ChiSqPar);
     328
     329          date = ohana_sec_to_date (catalog.average[k].Tmean);
     330          gprint (GP_LOG, "%20s ",     date);
     331          gprint (GP_LOG, "%f   ",     catalog.average[k].Trange / 86400.0);
    276332        }
    277333
    278         gprint (GP_LOG, "\n");
     334        gprint (GP_LOG, "\n\n");
    279335     
    280336        /* filter names */
     337        gprint (GP_LOG, "filter     : ");
    281338        for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_FILTER_NAMES);
    282339        gprint (GP_LOG, "\n");
    283340
    284341        /* average mags */
     342        gprint (GP_LOG, "chp_psf_ave: ");
    285343        for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_AVE_MAG);
    286344        gprint (GP_LOG, "\n");
    287345
    288346        /* average mag errors */
     347        gprint (GP_LOG, "chp_psf_err: ");
    289348        for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_AVE_MAG_ERR);
    290349        gprint (GP_LOG, "\n");
    291350
    292351        /* average mag chisq */
     352        gprint (GP_LOG, "chp_psf_chi: ");
    293353        for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_AVE_MAG_CHISQ);
    294354        gprint (GP_LOG, "\n");
    295355
    296         if (FULL_OUTPUT) {
     356       
     357        if (APER_OUTPUT) {
    297358          /* Map */
     359          gprint (GP_LOG, "chp_ap__ave: ");
    298360          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_AVE_AP_MAG);
    299361          gprint (GP_LOG, "\n");
    300 
     362        }
     363
     364        if (KRON_OUTPUT) {
    301365          /* Mkron */
     366          gprint (GP_LOG, "chp_krn_ave: ");
    302367          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_AVE_KRON_MAG);
    303368          gprint (GP_LOG, "\n");
    304369
    305370          /* dMkron */
     371          gprint (GP_LOG, "chp_krn_err: ");
    306372          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_AVE_KRON_MAG_ERR);
    307373          gprint (GP_LOG, "\n");
    308 
    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);;
     374        }
     375
     376        if (EXTRA_OUTPUT) {
     377          /* Mmin */
     378          gprint (GP_LOG, "chp_psf_min: ");
     379          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_AVE_MAG_MIN);
     380          gprint (GP_LOG, "\n");
     381
     382          /* Mmax */
     383          gprint (GP_LOG, "chp_psf_max: ");
     384          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_AVE_MAG_MAX);;
    315385          gprint (GP_LOG, "\n");
    316386
    317387          /* UCDIST */
     388          gprint (GP_LOG, "ubercal_dst: ");
    318389          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_UCDIST);;
    319390          gprint (GP_LOG, "\n");
    320391
    321392          /* secfilt flags */
     393          gprint (GP_LOG, "filtflags:   ");
    322394          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_SECF_FLAGS);
    323395          gprint (GP_LOG, "\n");
    324 
    325396        }
    326         if (STACK_OUTPUT) {
     397        if (STACK_OUTPUT && MAG_OUTPUT) {
    327398          /* FluxPSF */
     399          gprint (GP_LOG, "stk_psf_ave: ");
     400          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_MAG_PSF);
     401          gprint (GP_LOG, "\n");
     402 
     403          /* dFluxPSF */
     404          gprint (GP_LOG, "stk_psf_err: ");
     405          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_MAG_PSF_ERR);
     406          gprint (GP_LOG, "\n");
     407 
     408          if (KRON_OUTPUT) {
     409            /* MagKron */
     410            gprint (GP_LOG, "stk_krn_ave: ");
     411            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_MAG_KRON);
     412            gprint (GP_LOG, "\n");
     413 
     414            /* dMagKron */
     415            gprint (GP_LOG, "stk_krn_err: ");
     416            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_MAG_KRON_ERR);
     417            gprint (GP_LOG, "\n");
     418          }
     419
     420          if (APER_OUTPUT) {
     421            /* MagAper */
     422            gprint (GP_LOG, "stk_ap__ave: ");
     423            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_MAG_APER);
     424            gprint (GP_LOG, "\n");
     425 
     426            /* dMagAper */
     427            gprint (GP_LOG, "stk_ap__err: ");
     428            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_MAG_APER_ERR);
     429            gprint (GP_LOG, "\n");
     430          }
     431        }
     432        if (WARP_OUTPUT && MAG_OUTPUT) {
     433          /* FluxPSF */
     434          gprint (GP_LOG, "wrp_psf_ave: ");
     435          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_WARP_MAG_PSF);
     436          gprint (GP_LOG, "\n");
     437 
     438          /* dFluxPSF */
     439          gprint (GP_LOG, "wrp_psf_err: ");
     440          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_WARP_MAG_PSF_ERR);
     441          gprint (GP_LOG, "\n");
     442 
     443          if (KRON_OUTPUT) {
     444            /* MagKron */
     445            gprint (GP_LOG, "wrp_krn_ave: ");
     446            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_WARP_MAG_KRON);
     447            gprint (GP_LOG, "\n");
     448 
     449            /* dMagKron */
     450            gprint (GP_LOG, "wrp_krn_err: ");
     451            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_WARP_MAG_KRON_ERR);
     452            gprint (GP_LOG, "\n");
     453
     454          }
     455
     456          if (APER_OUTPUT) {
     457            /* MagAper */
     458            gprint (GP_LOG, "wrp_ap__ave: ");
     459            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_WARP_MAG_APER);
     460            gprint (GP_LOG, "\n");
     461 
     462            /* dMagAper */
     463            gprint (GP_LOG, "wrp_ap__err: ");
     464            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_WARP_MAG_APER_ERR);
     465            gprint (GP_LOG, "\n");
     466          }
     467        }
     468        if (STACK_OUTPUT && FLUX_OUTPUT) {
     469          /* FluxPSF */
     470          gprint (GP_LOG, "stk_psf_ave: ");
    328471          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_FLUX_PSF);
    329472          gprint (GP_LOG, "\n");
    330 
     473 
    331474          /* dFluxPSF */
     475          gprint (GP_LOG, "stk_psf_err: ");
    332476          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_FLUX_PSF_ERR);
    333477          gprint (GP_LOG, "\n");
    334 
    335           /* FluxKron */
    336           for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_FLUX_KRON);
    337           gprint (GP_LOG, "\n");
    338 
    339           /* dFluxKron */
    340           for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_FLUX_KRON_ERR);
    341           gprint (GP_LOG, "\n");
    342 
     478 
     479          if (KRON_OUTPUT) {
     480            /* FluxKron */
     481            gprint (GP_LOG, "stk_krn_ave: ");
     482            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_FLUX_KRON);
     483            gprint (GP_LOG, "\n");
     484 
     485            /* dFluxKron */
     486            gprint (GP_LOG, "stk_krn_err: ");
     487            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_FLUX_KRON_ERR);
     488            gprint (GP_LOG, "\n");
     489          }
     490
     491          if (APER_OUTPUT) {
     492            /* FluxAper */
     493            gprint (GP_LOG, "stk_ap_ave: ");
     494            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_FLUX_APER);
     495            gprint (GP_LOG, "\n");
     496 
     497            /* dFluxAper */
     498            gprint (GP_LOG, "stk_ap_err: ");
     499            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_STACK_FLUX_APER_ERR);
     500            gprint (GP_LOG, "\n");
     501          }
    343502        }
    344       }
     503        if (WARP_OUTPUT && FLUX_OUTPUT) {
     504          /* FluxPSF */
     505          gprint (GP_LOG, "wrp_psf_ave: ");
     506          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_WARP_FLUX_PSF);
     507          gprint (GP_LOG, "\n");
     508 
     509          /* dFluxPSF */
     510          gprint (GP_LOG, "wrp_psf_ave: ");
     511          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_WARP_FLUX_PSF_ERR);
     512          gprint (GP_LOG, "\n");
     513 
     514          if (KRON_OUTPUT) {
     515            /* FluxKron */
     516            gprint (GP_LOG, "wrp_krn_ave: ");
     517            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_WARP_FLUX_KRON);
     518            gprint (GP_LOG, "\n");
     519 
     520            /* dFluxKron */
     521            gprint (GP_LOG, "wrp_krn_err: ");
     522            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_WARP_FLUX_KRON_ERR);
     523            gprint (GP_LOG, "\n");
     524          }
     525
     526          if (APER_OUTPUT) {
     527            /* FluxAper */
     528            gprint (GP_LOG, "wrp_ap__ave: ");
     529            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_WARP_FLUX_APER);
     530            gprint (GP_LOG, "\n");
     531 
     532            /* dFluxAper */
     533            gprint (GP_LOG, "wrp_ap__err: ");
     534            for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_WARP_FLUX_APER_ERR);
     535            gprint (GP_LOG, "\n");
     536          }
     537        }
     538      }
     539      gprint (GP_LOG, "\n");
     540     
    345541      if (GetMeasures || SaveVectors) {
    346542
     
    374570          int Nv = index[j];
    375571
    376           Mcat = PhotCat (&catalog.measure[Nv]);
     572          Mcat = PhotCat (&catalog.measure[Nv], MAG_CLASS_PSF);
    377573          if (INST) {
    378             Mrel = PhotInst (&catalog.measure[Nv]);
     574            Mrel = PhotInst (&catalog.measure[Nv], MAG_CLASS_PSF);
    379575          } else {
    380             Mrel = PhotRel (&catalog.measure[Nv], &catalog.average[k], &catalog.secfilt[k*Nsecfilt]);
    381           }
     576            Mrel = PhotRel (&catalog.measure[Nv], &catalog.average[k], &catalog.secfilt[k*Nsecfilt], MAG_CLASS_PSF);
     577          }
     578
     579          float dRoff = dvoOffsetR(&catalog.measure[Nv], &catalog.average[k]);
     580          float dDoff = dvoOffsetD(&catalog.measure[Nv], &catalog.average[k]);
    382581
    383582          if (GetMeasures && !QUIET) {
     
    387586            gprint (GP_LOG, "%6.3f  ", catalog.measure[Nv].dM);
    388587            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);
     588           
     589            gprint (GP_LOG, "%7.4f ",  dRoff);
     590            gprint (GP_LOG, "%7.4f ",  dDoff);
    391591            gprint (GP_LOG, "0x%08x ", catalog.measure[Nv].photFlags);
    392592            gprint (GP_LOG, "0x%08x ", catalog.measure[Nv].dbFlags);
     
    409609
    410610            if (FULL_OUTPUT) {
    411                 gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Mcal);
    412                 gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Map);
    413                 gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Mkron);
    414                 gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].dMkron);
    415                 gprint (GP_LOG, "%5.1f ", pow(10.0, 0.4*catalog.measure[Nv].dt));
    416                 gprint (GP_LOG, "%5.3f ", catalog.measure[Nv].airmass);
    417                 gprint (GP_LOG, "%6.1f ", catalog.measure[Nv].az);
    418                 gprint (GP_LOG, "%6.1f ", catalog.measure[Nv].Xccd);
    419                 gprint (GP_LOG, "%6.1f ", catalog.measure[Nv].Yccd);
    420                 gprint (GP_LOG, "%3.1f ", FromShortPixels(catalog.measure[Nv].dXccd));
    421                 gprint (GP_LOG, "%3.1f ", FromShortPixels(catalog.measure[Nv].dYccd));
    422                 gprint (GP_LOG, "%6.1f ", catalog.measure[Nv].Sky);
    423                 gprint (GP_LOG, "%5.1f ", catalog.measure[Nv].dSky);
    424                 gprint (GP_LOG, "%8d ", catalog.measure[Nv].averef);
    425                 gprint (GP_LOG, "0x%08x ", catalog.measure[Nv].detID);
    426                 gprint (GP_LOG, "0x%08x ", catalog.measure[Nv].imageID);
    427                 gprint (GP_LOG, "%.3f ", catalog.measure[Nv].psfQF);
    428                 gprint (GP_LOG, "%.1f ", catalog.measure[Nv].psfChisq);
    429                 gprint (GP_LOG, "%.1f ", catalog.measure[Nv].crNsigma);
    430                 gprint (GP_LOG, "%.1f ", catalog.measure[Nv].extNsigma);
    431                 gprint (GP_LOG, "%.1f ", FromShortDegrees(catalog.measure[Nv].theta));
     611              gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Mcal);
     612              gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Map);
     613              gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Mkron);
     614              gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].dMkron);
     615              gprint (GP_LOG, "%5.1f ", pow(10.0, 0.4*catalog.measure[Nv].dt));
     616              gprint (GP_LOG, "%5.3f ", catalog.measure[Nv].airmass);
     617              gprint (GP_LOG, "%6.1f ", catalog.measure[Nv].az);
     618              gprint (GP_LOG, "%6.1f ", catalog.measure[Nv].Xccd);
     619              gprint (GP_LOG, "%6.1f ", catalog.measure[Nv].Yccd);
     620              gprint (GP_LOG, "%3.1f ", FromShortPixels(catalog.measure[Nv].dXccd));
     621              gprint (GP_LOG, "%3.1f ", FromShortPixels(catalog.measure[Nv].dYccd));
     622              gprint (GP_LOG, "%6.1f ", catalog.measure[Nv].Sky);
     623              gprint (GP_LOG, "%5.1f ", catalog.measure[Nv].dSky);
     624              gprint (GP_LOG, "%8d ", catalog.measure[Nv].averef);
     625              gprint (GP_LOG, "0x%08x ", catalog.measure[Nv].detID);
     626              gprint (GP_LOG, "0x%08x ", catalog.measure[Nv].imageID);
     627              gprint (GP_LOG, "%5.3f ", catalog.measure[Nv].psfQF);
     628              gprint (GP_LOG, "%7.1f ", catalog.measure[Nv].psfChisq);
     629              // gprint (GP_LOG, "%3.1f ", catalog.measure[Nv].crNsigma);
     630              gprint (GP_LOG, "%4.1f ", catalog.measure[Nv].extNsigma);
     631              gprint (GP_LOG, "%5.1f ", FromShortDegrees(catalog.measure[Nv].theta));
    432632            }
    433             if (STACK_OUTPUT) {
    434                 gprint (GP_LOG, "%10.3e ", catalog.measure[Nv].FluxPSF);
    435                 gprint (GP_LOG, "%10.3e ", catalog.measure[Nv].dFluxPSF);
    436                 gprint (GP_LOG, "%10.3e ", catalog.measure[Nv].FluxKron);
    437                 gprint (GP_LOG, "%10.3e ", catalog.measure[Nv].dFluxKron);
     633            if (FLUX_OUTPUT) {
     634              gprint (GP_LOG, "%10.3e ", catalog.measure[Nv].FluxPSF);
     635              gprint (GP_LOG, "%10.3e ", catalog.measure[Nv].dFluxPSF);
     636              gprint (GP_LOG, "%10.3e ", catalog.measure[Nv].FluxKron);
     637              gprint (GP_LOG, "%10.3e ", catalog.measure[Nv].dFluxKron);
    438638            }
    439639            gprint (GP_LOG, "\n");
     
    447647            vec3[0].elements.Flt[N] = catalog.measure[Nv].airmass;
    448648            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;
     649            vec5[0].elements.Flt[N] = dRoff;
     650            vec6[0].elements.Flt[N] = dDoff;
    451651            N ++;
    452652            if (N == NPTS - 1) {
     
    543743
    544744  switch (type) {
    545     case GSTAR_AVE_MAG: /* average mags */
    546       if (seq == -1) {
    547         print_double (NAN);
    548       } else {
    549         print_double (secfilt[seq].M);
    550       }
    551       break;
    552 
    553     case GSTAR_AVE_MAG_ERR: /* average mags errors */
    554       if (seq == -1) {
    555         print_double (NAN);
    556       } else {
    557         print_double (secfilt[seq].dM);
     745    case GSTAR_AVE_MAG_MIN: /* average ap mags */
     746      if (seq == -1) {
     747        print_double (NAN);
     748      } else {
     749        print_double (secfilt[seq].Mmin);
     750      }
     751      break;
     752
     753    case GSTAR_AVE_MAG_MAX: /* average ap mags */
     754      if (seq == -1) {
     755        print_double (NAN);
     756      } else {
     757        print_double (secfilt[seq].Mmax);
    558758      }
    559759      break;
     
    561761    case GSTAR_AVE_MAG_CHISQ: /* average mag chisq */
    562762      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);
     763        print_double (NAN);
     764      } else {
     765        print_double (secfilt[seq].Mchisq);
    566766      }
    567767      break;
     
    588788      break;
    589789
     790      /*** CHIP : MAG ***/
     791
     792    case GSTAR_AVE_MAG: /* average mags */
     793      if (seq == -1) {
     794        print_double (NAN);
     795      } else {
     796        print_double (secfilt[seq].M);
     797      }
     798      break;
     799
     800    case GSTAR_AVE_MAG_ERR: /* average mags errors */
     801      if (seq == -1) {
     802        print_double (NAN);
     803      } else {
     804        print_double (secfilt[seq].dM);
     805      }
     806      break;
     807
    590808    case GSTAR_AVE_AP_MAG: /* average ap mags */
    591809      if (seq == -1) {
     
    596814      break;
    597815
    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);
    611       }
    612       break;
    613 
    614816    case GSTAR_AVE_KRON_MAG: /* average ap mags */
    615817      if (seq == -1) {
     
    628830      break;
    629831
     832      /******************* STACK : FLUX **********************/
     833
    630834    case GSTAR_STACK_FLUX_PSF: /* average ap mags */
    631835      if (seq == -1) {
    632836        print_double (NAN);
    633837      } else {
    634         print_double_exp (secfilt[seq].FluxPSF);
     838        print_double_exp (secfilt[seq].FpsfStk);
    635839      }
    636840      break;
     
    640844        print_double (NAN);
    641845      } else {
    642         print_double_exp (secfilt[seq].dFluxPSF);
     846        print_double_exp (secfilt[seq].dFpsfStk);
    643847      }
    644848      break;
     
    648852        print_double (NAN);
    649853      } else {
    650         print_double_exp (secfilt[seq].FluxKron);
     854        print_double_exp (secfilt[seq].FkronStk);
    651855      }
    652856      break;
     
    656860        print_double (NAN);
    657861      } else {
    658         print_double_exp (secfilt[seq].dFluxKron);
     862        print_double_exp (secfilt[seq].dFkronStk);
     863      }
     864      break;
     865
     866    case GSTAR_STACK_FLUX_APER: /* average ap mags */
     867      if (seq == -1) {
     868        print_double (NAN);
     869      } else {
     870        print_double_exp (secfilt[seq].FapStk);
     871      }
     872      break;
     873
     874    case GSTAR_STACK_FLUX_APER_ERR: /* average ap mags */
     875      if (seq == -1) {
     876        print_double (NAN);
     877      } else {
     878        print_double_exp (secfilt[seq].dFapStk);
     879      }
     880      break;
     881
     882      /******************* STACK : MAG **********************/
     883
     884    case GSTAR_STACK_MAG_PSF: /* average ap mags */
     885      if (seq == -1) {
     886        print_double (NAN);
     887      } else {
     888        print_double (secfilt[seq].MpsfStk);
     889      }
     890      break;
     891
     892    case GSTAR_STACK_MAG_PSF_ERR: /* average ap mags */
     893      if (seq == -1) {
     894        print_double (NAN);
     895      } else {
     896        print_double (secfilt[seq].dFpsfStk / secfilt[seq].FpsfStk);
     897      }
     898      break;
     899
     900    case GSTAR_STACK_MAG_KRON: /* average ap mags */
     901      if (seq == -1) {
     902        print_double (NAN);
     903      } else {
     904        print_double (secfilt[seq].MkronStk);
     905      }
     906      break;
     907
     908    case GSTAR_STACK_MAG_KRON_ERR: /* average ap mags */
     909      if (seq == -1) {
     910        print_double (NAN);
     911      } else {
     912        print_double (secfilt[seq].dFkronStk / secfilt[seq].FkronStk);
     913      }
     914      break;
     915
     916    case GSTAR_STACK_MAG_APER: /* average ap mags */
     917      if (seq == -1) {
     918        print_double (NAN);
     919      } else {
     920        print_double (secfilt[seq].MapStk);
     921      }
     922      break;
     923
     924    case GSTAR_STACK_MAG_APER_ERR: /* average ap mags */
     925      if (seq == -1) {
     926        print_double (NAN);
     927      } else {
     928        print_double (secfilt[seq].dFapStk / secfilt[seq].FapStk);
     929      }
     930      break;
     931
     932      /******************* WARP : FLUX **********************/
     933
     934    case GSTAR_WARP_FLUX_PSF: /* average ap mags */
     935      if (seq == -1) {
     936        print_double (NAN);
     937      } else {
     938        print_double_exp (secfilt[seq].FpsfWrp);
     939      }
     940      break;
     941
     942    case GSTAR_WARP_FLUX_PSF_ERR: /* average ap mags */
     943      if (seq == -1) {
     944        print_double (NAN);
     945      } else {
     946        print_double_exp (secfilt[seq].dFpsfWrp);
     947      }
     948      break;
     949
     950    case GSTAR_WARP_FLUX_KRON: /* average ap mags */
     951      if (seq == -1) {
     952        print_double (NAN);
     953      } else {
     954        print_double_exp (secfilt[seq].FkronWrp);
     955      }
     956      break;
     957
     958    case GSTAR_WARP_FLUX_KRON_ERR: /* average ap mags */
     959      if (seq == -1) {
     960        print_double (NAN);
     961      } else {
     962        print_double_exp (secfilt[seq].dFkronWrp);
     963      }
     964      break;
     965
     966    case GSTAR_WARP_FLUX_APER: /* average ap mags */
     967      if (seq == -1) {
     968        print_double (NAN);
     969      } else {
     970        print_double_exp (secfilt[seq].FapWrp);
     971      }
     972      break;
     973
     974    case GSTAR_WARP_FLUX_APER_ERR: /* average ap mags */
     975      if (seq == -1) {
     976        print_double (NAN);
     977      } else {
     978        print_double_exp (secfilt[seq].dFapWrp);
     979      }
     980      break;
     981
     982      /******************* WARP : MAG **********************/
     983
     984    case GSTAR_WARP_MAG_PSF: /* average ap mags */
     985      if (seq == -1) {
     986        print_double (NAN);
     987      } else {
     988        print_double (secfilt[seq].MpsfWrp);
     989      }
     990      break;
     991
     992    case GSTAR_WARP_MAG_PSF_ERR: /* average ap mags */
     993      if (seq == -1) {
     994        print_double (NAN);
     995      } else {
     996        print_double (secfilt[seq].dFpsfWrp / secfilt[seq].FpsfWrp);
     997      }
     998      break;
     999
     1000    case GSTAR_WARP_MAG_KRON: /* average ap mags */
     1001      if (seq == -1) {
     1002        print_double (NAN);
     1003      } else {
     1004        print_double (secfilt[seq].MkronWrp);
     1005      }
     1006      break;
     1007
     1008    case GSTAR_WARP_MAG_KRON_ERR: /* average ap mags */
     1009      if (seq == -1) {
     1010        print_double (NAN);
     1011      } else {
     1012        print_double (secfilt[seq].dFkronWrp / secfilt[seq].FkronWrp);
     1013      }
     1014      break;
     1015
     1016    case GSTAR_WARP_MAG_APER: /* average ap mags */
     1017      if (seq == -1) {
     1018        print_double (NAN);
     1019      } else {
     1020        print_double (secfilt[seq].MapWrp);
     1021      }
     1022      break;
     1023
     1024    case GSTAR_WARP_MAG_APER_ERR: /* average ap mags */
     1025      if (seq == -1) {
     1026        print_double (NAN);
     1027      } else {
     1028        print_double (secfilt[seq].dFapWrp / secfilt[seq].FapWrp);
    6591029      }
    6601030      break;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/hosts.c

    r36680 r37403  
    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
     
    7174      if (!strcasecmp(argv[N], "dvo.results"))       TEMP_TYPE = TEMP_DVO_RESULTS;
    7275      if (!strcasecmp(argv[N], "dvo.log"))           TEMP_TYPE = TEMP_DVO_LOG;
    73       if (!strcasecmp(argv[N], "relastro.catalog"))   TEMP_TYPE = TEMP_RELASTRO_CATALOG;
     76      if (!strcasecmp(argv[N], "relastro.catalog"))  TEMP_TYPE = TEMP_RELASTRO_CATALOG;
    7477      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;
    7581      if (!strcasecmp(argv[N], "relphot.log"))       TEMP_TYPE = TEMP_RELPHOT_LOG;
    7682      if (!strcasecmp(argv[N], "dvopsps.det"))       TEMP_TYPE = TEMP_DVOPSPS_DET;
     
    7884      if (TEMP_TYPE == TEMP_NONE) {
    7985        gprint (GP_ERR, "USAGE: hosts purge-temp [-type (type)]\n");
    80         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");
    8187        return FALSE;
    8288      }
     
    118124        if (TEMP_TYPE == TEMP_RELPHOT_CATALOG)   snprintf (name, DVO_MAX_PATH, "%s/relphot.catalog.subset.dat", table->hosts[i].pathname);
    119125        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);
    120129        if (TEMP_TYPE == TEMP_DVOPSPS_DET)       snprintf (name, DVO_MAX_PATH, "%s/dvopsps.*.det.dat", table->hosts[i].pathname);
    121130        if (TEMP_TYPE == TEMP_FIXSTKIDS_RESULTS) snprintf (name, DVO_MAX_PATH, "%s/fixstkids.results.*.dat", table->hosts[i].pathname);
     
    126135        if (TEMP_TYPE == TEMP_RELPHOT_CATALOG)   snprintf (name, DVO_MAX_PATH, "%s/relphot.catalog.subset.dat", table->hosts[i].pathname);
    127136        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);
    128140        if (TEMP_TYPE == TEMP_DVOPSPS_DET)       snprintf (name, DVO_MAX_PATH, "%s/dvopsps.%05d.*.det.dat", table->hosts[i].pathname, PID);
    129141        if (TEMP_TYPE == TEMP_FIXSTKIDS_RESULTS) snprintf (name, DVO_MAX_PATH, "%s/fixstkids.results.%05d.*.dat", table->hosts[i].pathname, PID);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/imdata.c

    r34088 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/dvo/imextract.c

    r34088 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/dvo/init.c

    r36680 r37403  
    1414int cmpread         PROTO((int, char **));
    1515int coordimage      PROTO((int, char **));
     16int coordmosaic     PROTO((int, char **));
     17int psastro_model   PROTO((int, char **));
    1618int ddmags          PROTO((int, char **));
    1719int detrend         PROTO((int, char **));
     
    6466  {1, "avmatch",     avmatch,      "extract average data values matched to RA,DEC points"},
    6567  {1, "badimages",   badimages,    "look for images with anomalous astrometry"},
    66   {1, "calextract",  calextract,   "extract photometry calibration"},
    67   {1, "calmextract", calmextract,  "extract photometry calibration"},
     68//  {1, "calextract",  calextract,   "extract photometry calibration"},
     69//  {1, "calmextract", calmextract,  "extract photometry calibration"},
    6870  {1, "catdir",      catdir_define,"re-define CATDIR"},
    69   {1, "ccd",         ccd,          "plot color-color diagram"},
     71//  {1, "ccd",         ccd,          "plot color-color diagram"},
    7072  {1, "cmatch",      cmatch,       "match two catalogs"},
    71   {1, "cmd",         cmd,          "plot cmd of stars in current region"},
     73//  {1, "cmd",         cmd,          "plot cmd of stars in current region"},
    7274  {1, "cmpload",     cmpload,      "load cmp file into ?"},
    7375  {1, "cmpread",     cmpread,      "read data from cmp format files"},
    7476  {1, "coordimage",  coordimage,   "generate a map of the transformation residuals"},
    75   {1, "ddmags",      ddmags,       "plot magnitude differences"},
     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"},
    7680  {1, "detrend",     detrend,      "extract from detrend database?"},
    77   {1, "dmagaves",    dmagaves,     "foo"},
    78   {1, "dmagmeas",    dmagmeas,     "foo"},
    79   {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"},
    8084  {1, "dmt",         dmt,          "plot mag scatter"},
    8185  {1, "elixir",      elixir,       "talk to elixir"},
    82   {1, "fitcolors",   fitcolors,    "fit chip-to-chip color terms"},
     86//  {1, "fitcolors",   fitcolors,    "fit chip-to-chip color terms"},
    8387  {1, "fitsed",      fitsed,       "fit stellar SEDs to objects"},
    8488  {1, "gcat",        gcat,         "get catalog at location"},
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/lcurve.c

    r34584 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/dvo/lightcurve.c

    r27435 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/dvo/photometry.c

    r36680 r37403  
    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
     
    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/ps2-tc3-20130727/Ohana/src/opihi/dvo/pmeasure.c

    r34088 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/dvo/subpix.c

    r31635 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/include/dvomath.h

    r36680 r37403  
    170170Vector      **ReadVectorTableFITS   PROTO((char *filename, char *extname, int *Nvec));
    171171
     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
    172175/* buffer handling */
    173176Buffer       *InitBuffer            PROTO((void));
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/include/dvoshell.h

    r35416 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/include/shell.h

    r33662 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/lib.shell/VectorIO.c

    r35109 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/lib.shell/string.c

    r33662 r37403  
    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/ps2-tc3-20130727/Ohana/src/opihi/pcontrol/PclientCommand.c

    r27435 r37403  
    2525    return (PCLIENT_DOWN);
    2626  }
    27  
     27
    2828  // prepare host to accept response
    2929  host[0].response_state = response_state;
     
    3535  return (PCLIENT_GOOD);
    3636}
    37  
     37
    3838// check for response; message must end with specified string.
    3939// accumulate the response in the buffer
     
    4747  ASSERT (response != NULL, "response missing");
    4848  ASSERT (buffer != NULL, "buffer missing");
     49
     50  // INITTIME;
    4951
    5052  /* avoid blocking very long on read, test every 100 usec, up to 0.1 sec */
     
    6668    return (PCLIENT_DOWN);
    6769  }
    68   if (line == NULL) return (PCLIENT_HUNG);
    69   if (status == -1) return (PCLIENT_HUNG);
     70  if (line == NULL) {
     71      // MARKTIME ("-- client hung (line NULL): %s : %f sec\n", host[0].hostname, dtime);
     72      return (PCLIENT_HUNG);
     73  }
     74  if (status == -1) {
     75      // MARKTIME ("-- client hung (status -1): %s : %f sec\n", host[0].hostname, dtime);
     76      return (PCLIENT_HUNG);
     77  }
    7078
    7179  // fprintf (stderr, "response: %s\n", buffer[0].buffer);
     
    7583
    7684/* memstr returns a view, not an allocated string : don't free */
    77 /* ReadtoIOBuffer returns : 
     85/* ReadtoIOBuffer returns :
    7886    0 - pipe closed
    7987   -1 - no more data in pipe, data not ready
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/photdbc/Makefile

    r33655 r37403  
    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/ps2-tc3-20130727/Ohana/src/photdbc/include/photdbc.h

    r33963 r37403  
    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/ps2-tc3-20130727/Ohana/src/photdbc/src/args.c

    r33655 r37403  
    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/ps2-tc3-20130727/Ohana/src/photdbc/src/copy_images.c

    r33655 r37403  
    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/ps2-tc3-20130727/Ohana/src/photdbc/src/get_mags.c

    r15509 r37403  
    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/ps2-tc3-20130727/Ohana/src/photdbc/src/initialize.c

    r33655 r37403  
    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/ps2-tc3-20130727/Ohana/src/photdbc/src/join_stars.c

    r36680 r37403  
    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;
     
    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/ps2-tc3-20130727/Ohana/src/photdbc/src/make_subcatalog.c

    r31635 r37403  
    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/ps2-tc3-20130727/Ohana/src/photdbc/src/photdbc.c

    r33655 r37403  
    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/ps2-tc3-20130727/Ohana/src/photdbc/src/photdbc_catalogs.c

    r33963 r37403  
    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/ps2-tc3-20130727/Ohana/src/relastro/Makefile

    r36680 r37403  
    5959$(SRC)/save_catalogs.$(ARCH).o       \
    6060$(SRC)/CoordOps.$(ARCH).o            \
     61$(SRC)/extra.$(ARCH).o            \
    6162$(SRC)/FixProblemImages.$(ARCH).o    \
    6263$(SRC)/StarMaps.$(ARCH).o    \
     
    117118$(SRC)/save_catalogs.$(ARCH).o       \
    118119$(SRC)/CoordOps.$(ARCH).o            \
     120$(SRC)/extra.$(ARCH).o            \
    119121$(SRC)/high_speed_catalogs.$(ARCH).o  \
    120122$(SRC)/high_speed_objects.$(ARCH).o  \
     
    127129$(SRC)/plotstuff.$(ARCH).o           \
    128130$(SRC)/relastroVisual.$(ARCH).o \
     131$(SRC)/syncfile.$(ARCH).o \
    129132$(SRC)/BrightCatalog.$(ARCH).o
    130133
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/include/relastro.h

    r36680 r37403  
    55# include <assert.h>
    66# include <pthread.h>
    7 
    8 # define MARKTIME(MSG,...) {                    \
    9     gettimeofday (&stopTimer, (void *) NULL);   \
    10     float dtime = DTIME (stopTimer, startTimer);        \
    11     fprintf (stderr, MSG, __VA_ARGS__); }
    12 
    13 # define INITTIME \
    14   struct timeval startTimer, stopTimer; \
    15   gettimeofday (&startTimer, (void *) NULL);
    167
    178// choose off_t or int depending on full-scale relphot analysis resources
     
    8374  double L, M;  /* Focal Plane   - pixels  */
    8475  double X, Y;  /* Chip Coords   - pixels  */
    85   double Mag;
    86   double dMag;
    87   double dPos;
     76  float Mag;
     77  float ColorBlue;
     78  float ColorRed;
     79  float dMag;
     80  float dPos;
    8881  int mask;
    8982  int Nmeas;
     
    140133  int    Nmeas;
    141134} StatType;
     135
     136typedef struct {
     137  off_t Nave;
     138  off_t Npm;
     139  off_t Npar;
     140  off_t Nskip;
     141  off_t Noffset;
     142} FitStats;
    142143
    143144/* global variables set in parameter file */
     
    207208double MaxDensityValue;
    208209
    209 char          *PHOTCODE_KEEP_LIST, *PHOTCODE_SKIP_LIST;
    210 int           NphotcodesKeep,      NphotcodesSkip;
    211 PhotCode     **photcodesKeep,     **photcodesSkip;
     210char          *PHOTCODE_KEEP_LIST, *PHOTCODE_SKIP_LIST, *PHOTCODE_RESET_LIST;
     211int           NphotcodesKeep,      NphotcodesSkip,      NphotcodesReset;
     212PhotCode     **photcodesKeep,     **photcodesSkip,     **photcodesReset;
    212213
    213214char          *PHOTCODE_A_LIST,  *PHOTCODE_B_LIST;
     
    217218SkyRegionSelection SELECTION;
    218219
     220char         *DCR_BLUE_COLOR_POS,    *DCR_BLUE_COLOR_NEG;
     221PhotCode     *DCR_BLUE_PHOTCODE_POS, *DCR_BLUE_PHOTCODE_NEG;
     222int           DCR_BLUE_NSEC_POS,      DCR_BLUE_NSEC_NEG;
     223
     224char         *DCR_RED_COLOR_POS,    *DCR_RED_COLOR_NEG;
     225PhotCode     *DCR_RED_PHOTCODE_POS, *DCR_RED_PHOTCODE_NEG;
     226int           DCR_RED_NSEC_POS,      DCR_RED_NSEC_NEG;
     227
    219228int ImagSelect;
    220229double ImagMin, ImagMax;
     
    233242int    CLIP_THRESH;
    234243int USE_BASIC_CHECK;
     244
     245int ExcludeBogus;
     246double ExcludeBogusRadius;
    235247
    236248FitMode FIT_MODE;
     
    307319int           liststats           PROTO((double *value, double *dvalue, int N, StatType *stats));
    308320int           liststats_pos       PROTO((double *value, double *dvalue, int N, StatType *stats, int XVERB));
    309 Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath));
     321Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath, char *syncfile));
    310322int           load_images         PROTO((FITS_DB *db, SkyList *skylist, int UseFullOverlap));
    311323Image        *select_images       PROTO((SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage, int UseFullOverlap));
     
    417429int setMeanR (double ra_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt);
    418430int setMeanD (double dec_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt);
     431double getMeanR_Big (Measure *measure, Average *average, SecFilt *secfilt);
     432double getMeanD_Big (Measure *measure, Average *average, SecFilt *secfilt);
    419433int setMeanR_Big (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt);
    420434int setMeanD_Big (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt);
     
    521535int ImageTableSave (char *filename, Image *images, off_t Nimages);
    522536int select_mosaics_hostregion (RegionHostTable *regionHosts, Image *image, off_t Nimage);
     537
     538float getColorBlue (off_t meas, int cat);
     539float getColorRed (off_t meas, int cat);
     540
     541int strextend (char *input, char *format,...);
     542
     543int areImagesLoaded ();
     544int areImagesMatched ();
     545
     546int isGPC1chip (int photcode);
     547int isGPC1stack (int photcode);
     548int isGPC1warp (int photcode);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/BrightCatalog.c

    r35105 r37403  
    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/ps2-tc3-20130727/Ohana/src/relastro/src/FitChip.c

    r33652 r37403  
    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/ps2-tc3-20130727/Ohana/src/relastro/src/GetAstromError.c

    r33652 r37403  
    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/ps2-tc3-20130727/Ohana/src/relastro/src/ImageOps.c

    r36680 r37403  
    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) {
     
    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;
     
    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/ps2-tc3-20130727/Ohana/src/relastro/src/MeanPosIO.c

    r36680 r37403  
    111111  gfits_define_bintable_column (&theader, "D", "RA",        "mean position, ra",  "degrees", 1.0, 0.0);
    112112  gfits_define_bintable_column (&theader, "D", "DEC",       "mean position, dec", "degrees", 1.0, 0.0);
    113   gfits_define_bintable_column (&theader, "J", "OBJ_ID",    "object ID",          NULL,      1.0, 1.0*0x8000);
    114   gfits_define_bintable_column (&theader, "J", "CAT_ID",    "catalog ID",         NULL,      1.0, 1.0*0x8000);
     113  gfits_define_bintable_column (&theader, "J", "OBJ_ID",    "object ID",          NULL,      1.0, FT_BZERO_INT32);
     114  gfits_define_bintable_column (&theader, "J", "CAT_ID",    "catalog ID",         NULL,      1.0, FT_BZERO_INT32);
    115115
    116116  // generate the output array that carries the data
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/MosaicOps.c

    r36680 r37403  
    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;
    107107    mosaic[Nmosaic].myImage = i;
    108108
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/ParFactor.c

    r33652 r37403  
    6363  double jd, lambda, beta, epsilon, Radius;
    6464
    65   /* given a time T in UNIX seconds, determine the solar longitude S */
     65  /* given a Time relative to Tmean, Tmean in years since J2000, determine the solar
     66    longitude S */
    6667
    6768  // jd = ohana_sec_to_jd (365.25*86400.0*(Time + Tmean));
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/Shutdown.c

    r12332 r37403  
    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/ps2-tc3-20130727/Ohana/src/relastro/src/UpdateObjectOffsets.c

    r35763 r37403  
    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/ps2-tc3-20130727/Ohana/src/relastro/src/UpdateObjects.c

    r36680 r37403  
    11# include "relastro.h"
     2# define PAR_TOOFEW 5
     3
     4int UpdateObjects_Chips (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats, int i, off_t m);
     5int UpdateObjects_Stack (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats);
    26
    37static off_t Nmax;
     
    1014static double *T;
    1115static double *dT;
     16static double *C_blue;
     17static double *C_red;
     18
     19static Coords coords;
     20
     21static time_t T2000;
     22
     23void initFitStats (FitStats *fitStats) {
     24  fitStats->Nave = 0; 
     25  fitStats->Npm = 0;   
     26  fitStats->Npar = 0; 
     27  fitStats->Nskip = 0;
     28  fitStats->Noffset = 0;
     29  return;
     30}
     31
     32void sumFitStats (FitStats *srcFitStats, FitStats *tgtFitStats) {
     33  tgtFitStats->Nave    += srcFitStats->Nave    ; 
     34  tgtFitStats->Npm     += srcFitStats->Npm     ;   
     35  tgtFitStats->Npar    += srcFitStats->Npar    ; 
     36  tgtFitStats->Nskip   += srcFitStats->Nskip   ;
     37  tgtFitStats->Noffset += srcFitStats->Noffset ;
     38  return;
     39}
    1240
    1341void initObjectData (Catalog *catalog, int Ncatalog) {
     
    3664  ALLOCATE (pX, double, MAX (1, Nmax));
    3765  ALLOCATE (pY, double, MAX (1, Nmax));
    38 
    39 
    40 void freeObjectData () {
    41 
    42   free (R);
    43   free (D);
    44   free (T);
    45   free (X);
    46   free (Y);
    47 
    48   free (dR);
    49   free (dD);
    50   free (dT);
    51   free (dX);
    52   free (dY);
    53 
    54   free (pX);
    55   free (pY);
    56 
    57 
    58 // This function operates on both Measure and MeasureTiny.  In the big stages, this should
    59 // be called with just MeasureTiny set and Measure == NULL
    60 int UpdateObjects (Catalog *catalog, int Ncatalog) {
    61 
    62   off_t j, k, m;
    63   int i, N, Nsecfilt, mode, result, status, XVERB;
    64   StatType statsR, statsD;
    65   Coords coords;
    66   PMFit fitAve, fitPM, fitPAR, fit;
    67   time_t T2000;
    68   off_t Nave, Npm, Npar, Nskip, Noffset;
    69   off_t NaveSum, NpmSum, NparSum, NskipSum, NoffSum;
    70   double Tmin, Tmax, Tmean, Trange;
    71 
    72   memset (&fit,    0, sizeof(fit));
    73   memset (&fitAve, 0, sizeof(fitAve));
    74   memset (&fitPM,  0, sizeof(fitPM));
    75   memset (&fitPAR, 0, sizeof(fitPAR));
    76   initObjectData (catalog, Ncatalog);
     66
     67  ALLOCATE (C_blue, double, MAX (1, Nmax));
     68  ALLOCATE (C_red,  double, MAX (1, Nmax));
    7769
    7870  /* project coordinates to a plane centered on the object with units of arcsec */
     
    8779  strcpy (coords.ctype, "DEC--SIN");
    8880
    89   XVERB = FALSE;
    90 
    9181  // use J2000 as a reference time
    92   T2000 = ohana_date_to_sec ("2000/01/01");
     82  T2000 = ohana_date_to_sec ("2000/01/01,12:00:00");
     83
     84
     85void freeObjectData () {
     86
     87  free (R);
     88  free (D);
     89  free (T);
     90  free (X);
     91  free (Y);
     92
     93  free (dR);
     94  free (dD);
     95  free (dT);
     96  free (dX);
     97  free (dY);
     98
     99  free (pX);
     100  free (pY);
     101
     102  free (C_blue);
     103  free (C_red);
     104
     105
     106// This function operates on both Measure and MeasureTiny.  In the big stages, this should
     107// be called with just MeasureTiny set and Measure == NULL
     108int UpdateObjects (Catalog *catalog, int Ncatalog) {
     109
     110  initObjectData (catalog, Ncatalog);
     111
    93112  // XXX in the future, use catalog[0].Nsecfilt only?  allow catalogs to have variable Nsecfilt?
    94 
    95   Nsecfilt = GetPhotcodeNsecfilt ();
     113  int Nsecfilt = GetPhotcodeNsecfilt ();
    96114  if (Ncatalog) {
    97115    assert (catalog[0].Nsecfilt == Nsecfilt);
    98116  }
    99117
    100   NaveSum = NparSum = NpmSum = NoffSum = NskipSum = 0;
     118  FitStats sumStatsChips; initFitStats (&sumStatsChips);
     119  FitStats sumStatsStack; initFitStats (&sumStatsStack);
     120
     121  int i;
    101122  for (i = 0; i < Ncatalog; i++) {
    102123
    103124    if (VERBOSE2) fprintf (stderr, "astrometrize catalog %d : "OFF_T_FMT" ave, "OFF_T_FMT" meas\n", i,  catalog[i].Naverage,  catalog[i].Nmeasure);
    104125
    105     Nave = Npar = Npm = Nskip = Noffset = 0;
     126    FitStats fitStatsChips; initFitStats (&fitStatsChips);
     127    FitStats fitStatsStack; initFitStats (&fitStatsStack);
     128
     129    off_t j;
    106130    for (j = 0; j < catalog[i].Naverage; j++) {
    107131      /* calculate the average value of R,D for a single star */
    108 
    109       XVERB = FALSE;
    110       fitAve.chisq = NAN;
    111       fitPM.chisq = NAN;
    112       fitPAR.chisq = NAN;
    113 
    114       if (catalog[i].average[j].Nmeasure == 0) {
    115           continue;
    116       }
    117 
    118       N = 0;
    119       m = catalog[i].average[j].measureOffset;
     132      off_t m = catalog[i].average[j].measureOffset;
    120133      MeasureTiny *measure = &catalog[i].measureT[m];
    121134      Measure *measureBig = catalog[i].measure ? &catalog[i].measure[m] : NULL;
    122       // when we update the output measure values, we need to do it here
    123 
    124       mode = FIT_MODE;
    125 
    126       // XVERB |= (catalog[i].averge[j].objID == 0xc90) && (catalog[i].average[j].catID == 0x2a1e);
    127       XVERB |= (catalog[i].average[j].objID == OBJ_ID_SRC) && (catalog[i].average[j].catID == CAT_ID_SRC);
    128       XVERB |= (catalog[i].average[j].objID == OBJ_ID_DST) && (catalog[i].average[j].catID == CAT_ID_DST);
    129 
    130       // find the basic properties of the detections for this object (Tmin, Tmax, Tmean)
    131       for (k = 0; k < catalog[i].average[j].Nmeasure; k++) {
    132 
    133         if (XVERB) {
    134           char *date = ohana_sec_to_date (measure[k].t);
    135           int dbFlagsBig = measureBig ? measureBig[k].dbFlags : 0;
    136           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);
    137           free (date);
    138         }
    139 
    140         // does the measurement pass the supplied filtering constraints?
    141         // MeasFilterTestTiny does not test psfQF
    142         int keepMeasure = measureBig ? MeasFilterTest(&measureBig[k], FALSE) : MeasFilterTestTiny(&measure[k], FALSE);
    143         if (!keepMeasure) {
    144           measure[k].dbFlags &= ~ID_MEAS_USED_OBJ;
    145           if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; }
    146           continue;
    147         }
    148 
    149         // outlier rejection
    150         if (FlagOutlier && (measure[k].dbFlags & ID_MEAS_POOR_ASTROM)) {
    151           measure[k].dbFlags &= ~ID_MEAS_USED_OBJ;
    152           if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; }
    153           continue;
    154         }
    155 
    156         measure[k].dbFlags |= ID_MEAS_USED_OBJ;
    157         if (measureBig) { measureBig[k].dbFlags |= ID_MEAS_USED_OBJ; }
    158 
    159         R[N] = getMeanR (&measure[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
    160         D[N] = getMeanD (&measure[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
    161 
    162         // XXX I think this is a problem: T[] is time in years relative to J2000, but ParFactor expects
    163         // to get Time in years relative to UNIX Tzero (1970/01/01)
    164         T[N] = (measure[k].t - T2000) / (86400*365.25) ; // time relative to J2000 in years
    165 
    166         // dX, dY : error in arcsec --
    167         dX[N] = GetAstromErrorTiny (&measure[k], ERROR_MODE_RA);
    168         dY[N] = GetAstromErrorTiny (&measure[k], ERROR_MODE_DEC);
    169 
    170         // allow a given photcode or measurement to be
    171         // ignored if the error is NAN (for photcode, set astromErrSys to NaN)
    172         if (isnan(dX[N])) {
    173           measure[k].dbFlags &= ~ID_MEAS_USED_OBJ;
    174           if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; }
    175           continue;
    176         }
    177         if (isnan(dY[N])) {
    178           measure[k].dbFlags &= ~ID_MEAS_USED_OBJ;
    179           if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; }
    180           continue;
    181         }
    182 
    183         // add systematic error in quadrature, if desired
    184         // only do this after the fit has converged (or you will never improve the poor images)
    185         // if (INCLUDE_SYS_ERR) {
    186         // float dRsys = FromShortPixels(measure[k].dRsys);
    187         // dX[N] = hypot(dX[N], dRsys);
    188         // dY[N] = hypot(dY[N], dRsys);
    189         // }
    190 
    191         // dX[N] = 0.1;
    192         // dY[N] = 0.1;
    193 
    194         dT[N] = measure[k].dt;
    195 
    196         // XXX this is (slightly) inconsistent: dX,dY are the X and Y direction errors in
    197         // arcseconds.  dR, dD are the errors in those directions in degrees.  IF we have
    198         // non-circular errors (different values for X and Y), then dR and dD will be
    199         // incorrect: they would need to be rotated to take out the position angle
    200         dR[N] = dX[N] / 3600.0;
    201         dD[N] = dY[N] / 3600.0;
    202 
    203         N++;
    204       }
    205 
    206       // if we have too few good detections for the desired fit, or too limited a
    207       // baseline, use a fit with fewer parameters.  XXX if we have too few measurements
    208       // for even the average position, consider including the lower-quality detections?
    209 
    210       catalog[i].average[j].flags &= ~ID_STAR_NO_ASTROM;
    211 
    212       // find Tmin & Tmax from the list of accepted measurements
    213       Tmean = 0;
    214       Tmin = Tmax = T[0];
    215       for (k = 0; k < N; k++) {
    216         Tmin = MIN(Tmin, T[k]);
    217         Tmax = MAX(Tmax, T[k]);
    218         Tmean += T[k];
    219       }
    220       // XXX add the parallax factor range as a criterion as well
    221       Trange = Tmax - Tmin;
    222       if (Trange < PM_DT_MIN) mode = FIT_AVERAGE;
    223       if (((mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) && (N <= PM_TOOFEW)) mode = FIT_AVERAGE;
    224 
    225       if (RELASTRO_OP == OP_HIGH_SPEED) {
    226           Tmean = 0.5*(Tmax - Tmin);
    227       } else {
    228           Tmean /= (float) N;
    229       }
    230 
    231       // too few measurements for average position (require 2 values)
    232       if (N < SRC_MEAS_TOOFEW) {
    233         // XXX need to define PHOTOM and ASTROM object flags
    234         // XXX reset the average value fields?
    235         catalog[i].average[j].flags |= ID_STAR_NO_ASTROM;
    236         catalog[i].average[j].ChiSqAve  = NAN;
    237         catalog[i].average[j].ChiSqPM   = NAN;
    238         catalog[i].average[j].ChiSqPar  = NAN;
    239         if (N < 2) continue;
    240       }
    241 
    242       /* we need to do the fit in a locally linear space; choose a ref coordinate */
    243       coords.crval1 = R[0];
    244       coords.crval2 = D[0];
    245 
    246       // to judge the quality of the PM and PAR fits, we need to fit all three models and compare Chisq
    247 
    248       if ((mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) {
    249         // project all of the R,D coordinates to a plane centered on this coordinate. set
    250         // the times to be relative to Tmean (this is required for parallax as well)
    251         for (k = 0; k < N; k++) {
    252           RD_to_XY (&X[k], &Y[k], R[k], D[k], &coords);
    253           T[k] -= Tmean;
    254           if (XVERB) {
    255             fprintf (stderr, OFF_T_FMT" %f %f %f  %f %f +/- %f %f\n",  k, T[k], R[k], D[k], X[k], Y[k], dX[k], dY[k]);
    256           }
    257         }         
    258 
    259         FitPM (&fitPM, X, dX, Y, dY, T, N, XVERB);
    260 
    261         if (XVERB) fprintf (stderr, "fitted PM:  %f - %f : %f %f : %f %f : %f vs %f\n", Tmin, Tmax, fitPM.Ro, fitPM.Do, fitPM.uR, fitPM.uD, fitPM.chisq, fitAve.chisq);
    262 
    263         // project Ro, Do back to RA,DEC
    264         XY_to_RD (&fitPM.Ro, &fitPM.Do, fitPM.Ro, fitPM.Do, &coords);
    265         if (XVERB) fprintf (stderr, "project: %f %f : %f %f : %f\n", fitPM.Ro, fitPM.Do, fitPM.uR, fitPM.uD, fitPM.p);
    266 
    267         fitPM.p  = fitPM.dp  = 0.0;
    268         catalog[i].average[j].flags |= ID_STAR_FIT_PM;
    269         Npm ++;
    270       }
    271 
    272       if (mode == FIT_PM_AND_PAR) {
    273         // fprintf (stderr, "parallax fitting is still untested (%s, %d)\n", __FILE__, __LINE__);
    274 
    275         float pXmin = +2.0;
    276         float pXmax = -2.0;
    277         float pYmin = +2.0;
    278         float pYmax = -2.0;
    279         for (k = 0; k < N; k++) {
    280           ParFactor (&pX[k], &pY[k], R[k], D[k], T[k], Tmean);
    281           pXmin = MIN (pXmin, pX[k]);
    282           pXmax = MAX (pXmax, pX[k]);
    283           pYmin = MIN (pYmin, pY[k]);
    284           pYmax = MAX (pYmax, pY[k]);
    285         }
    286         float dXRange = pXmax - pXmin;
    287         float dYRange = pYmax - pYmin;
    288         float parRange = hypot (dXRange, dYRange);
    289        
    290 # define PAR_TOOFEW 5
    291         if ((parRange >= PAR_FACTOR_MIN) && (N > PAR_TOOFEW)) {
    292           FitPMandPar (&fitPAR, X, dX, Y, dY, T, pX, pY, N, XVERB);
    293           if (XVERB) fprintf (stderr, "fitted PM+PAR:  %f - %f : %f %f : %f %f : %f %f : %f vs %f vs %f\n", Tmin, Tmax, fitPAR.Ro, fitPAR.Do, fitPAR.uR, fitPAR.uD, fitPAR.p, fitPAR.dp, fitPAR.chisq, fitPM.chisq, fitAve.chisq);
    294 
    295           XY_to_RD (&fitPAR.Ro, &fitPAR.Do, fitPAR.Ro, fitPAR.Do, &coords);
    296           catalog[i].average[j].flags |= ID_STAR_FIT_PAR;
    297           Npar ++;
    298         } else {
    299           // need to set mode = FIT_PM_ONLY if we do not fit for parallax
    300           mode = FIT_PM_ONLY;
    301         }
    302       }   
    303 
    304       // fit the average model
    305       if ((mode == FIT_AVERAGE) || (mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) {
    306         liststats_pos (R, dR, N, &statsR, XVERB); // WARNING: this function modifies R (do not use after here)
    307         liststats_pos (D, dD, N, &statsD, XVERB); // WARNING: this function modifies D (do not use after here)
    308 
    309         fitAve.Ro = statsR.mean;
    310         fitAve.dRo = 3600.0*statsR.sigma;
    311 
    312         fitAve.Do = statsD.mean;
    313         fitAve.dDo = 3600.0*statsD.sigma;
    314 
    315         fitAve.chisq = 0.5 * (statsR.chisq + statsD.chisq);
    316         fitAve.Nfit = N;
    317 
    318         fitAve.uR = fitAve.duR = 0.0;
    319         fitAve.uD = fitAve.duD = 0.0;
    320         fitAve.p  = fitAve.dp  = 0.0;
    321         catalog[i].average[j].flags |= ID_STAR_FIT_AVE;
    322         Nave ++;
    323       }
    324 
    325       /* choose the result based on the chisq values */
    326       // XXXX for now, just use the mode as the result:
    327       result = mode;
    328 
    329       switch (result) {
    330       case FIT_AVERAGE:
    331         catalog[i].average[j].flags |= ID_STAR_USE_AVE;
    332         fit = fitAve;
    333         break;
    334       case FIT_PM_ONLY:
    335         catalog[i].average[j].flags |= ID_STAR_USE_PM;
    336         fit = fitPM;
    337         break;
    338       case FIT_PM_AND_PAR:
    339         catalog[i].average[j].flags |= ID_STAR_USE_PAR;
    340         fit = fitPAR;
    341         break;
    342       }
    343       if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f) pm=(%f %f) plx=(%f +/- %f)\n",
    344                           catalog[i].average[j].R,
    345                           catalog[i].average[j].D,
    346                           fit.Ro, fit.Do,
    347                           3600*(catalog[i].average[j].R - fit.Ro),
    348                           3600*(catalog[i].average[j].D - fit.Do),
    349                           fit.uR, fit.uD, fit.p, fit.dp);
    350 
    351       // make sure that the fit succeeded
    352       status = TRUE;
    353       status &= finite(fit.Ro);
    354       status &= finite(fit.Do);
    355       status &= finite(fit.dRo);
    356       status &= finite(fit.dDo);
    357       status &= finite(fit.uR);
    358       status &= finite(fit.uD);
    359       status &= finite(fit.duR);
    360       status &= finite(fit.duD);
    361       status &= finite(fit.p);
    362       status &= finite(fit.dp);
    363       if (!status) {
    364         Nskip ++;
     135      Average *average = &catalog[i].average[j];
     136      SecFilt *secfilt = &catalog[i].secfilt[j*Nsecfilt];
     137
     138      UpdateObjects_Stack(average, secfilt, measure, measureBig, Nsecfilt, &fitStatsStack);
     139      UpdateObjects_Chips(average, secfilt, measure, measureBig, Nsecfilt, &fitStatsChips, i, m);
     140    }
     141    if (VERBOSE) fprintf (stderr, "catalog %d : chips "OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par : Nskip "OFF_T_FMT", Noffset "OFF_T_FMT"\n",  i,  fitStatsChips.Nave,  fitStatsChips.Npm,  fitStatsChips.Npar,  fitStatsChips.Nskip, fitStatsChips.Noffset);
     142    if (VERBOSE) fprintf (stderr, "catalog %d : stack "OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par : Nskip "OFF_T_FMT", Noffset "OFF_T_FMT"\n",  i,  fitStatsStack.Nave,  fitStatsStack.Npm,  fitStatsStack.Npar,  fitStatsStack.Nskip, fitStatsStack.Noffset);
     143    sumFitStats (&fitStatsChips, &sumStatsChips);
     144    sumFitStats (&fitStatsStack, &sumStatsStack);
     145  }
     146  freeObjectData ();
     147
     148  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",  (sumStatsChips.Nave + sumStatsChips.Npm + sumStatsChips.Npar),  sumStatsChips.Nave,  sumStatsChips.Npm,  sumStatsChips.Npar,  sumStatsChips.Nskip, sumStatsChips.Noffset);
     149  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",  (sumStatsStack.Nave + sumStatsStack.Npm + sumStatsStack.Npar),  sumStatsStack.Nave,  sumStatsStack.Npm,  sumStatsStack.Npar,  sumStatsStack.Nskip, sumStatsStack.Noffset);
     150  return (TRUE);
     151}
     152
     153// This function operates on both Measure and MeasureTiny.  In the big stages, this should
     154// be called with just MeasureTiny set and Measure == NULL
     155int UpdateObjects_Chips (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats, int i, off_t m) {
     156
     157  int setRefColor = areImagesMatched();
     158
     159  /* calculate the average value of R,D for a single star */
     160
     161  PMFit fit;    memset (&fit,    0, sizeof(fit));
     162  PMFit fitAve; memset (&fitAve, 0, sizeof(fitAve)); fitAve.chisq = NAN;
     163  PMFit fitPM;  memset (&fitPM,  0, sizeof(fitPM));  fitPM.chisq = NAN;
     164  PMFit fitPAR; memset (&fitPAR, 0, sizeof(fitPAR)); fitPAR.chisq = NAN;
     165
     166  // if we fail to fit the astrometry for some reason, we need to set/reset these
     167  average[0].flags |= ID_STAR_NO_ASTROM;
     168  average[0].ChiSqAve  = NAN;
     169  average[0].ChiSqPM   = NAN;
     170  average[0].ChiSqPar  = NAN;
     171  average[0].Npos = 0;
     172
     173  // an object with no measurements is externally supplied
     174  if (average[0].Nmeasure == 0) return TRUE;
     175
     176  int NcBlue = 0;
     177  int NcRed = 0;
     178  int N = 0;
     179
     180  int mode = FIT_MODE; // start with the globally-defined fit mode
     181
     182  int XVERB = FALSE;
     183  XVERB |= (average[0].objID == OBJ_ID_SRC) && (average[0].catID == CAT_ID_SRC);
     184  XVERB |= (average[0].objID == OBJ_ID_DST) && (average[0].catID == CAT_ID_DST);
     185
     186  // find the basic properties of the detections for this object (Tmin, Tmax, Tmean)
     187  off_t k;
     188  for (k = 0; k < average[0].Nmeasure; k++) {
     189
     190    if (XVERB) {
     191      char *date = ohana_sec_to_date (measure[k].t);
     192      int dbFlagsBig = measureBig ? measureBig[k].dbFlags : 0;
     193      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);
     194      free (date);
     195    }
     196
     197    // SKIP gpc1 stack data
     198    if (isGPC1stack(measure[k].photcode)) continue;
     199
     200    // SKIP gpc1 forced-warp data
     201    if (isGPC1warp(measure[k].photcode)) continue;
     202
     203    // reset the bit to note that a detection was used (or not)
     204    measure[k].dbFlags &= ~ID_MEAS_USED_OBJ;
     205    if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; }
     206
     207    // does the measurement pass the supplied filtering constraints?
     208    // MeasFilterTestTiny does not test psfQF
     209    // exclude bad detections based on: photcodes, psfQF, time range, photflags & astromBadMask, mag_inst
     210    int keepMeasure = measureBig ? MeasFilterTest(&measureBig[k], FALSE) : MeasFilterTestTiny(&measure[k], FALSE);
     211    if (!keepMeasure) {
     212      continue;
     213    }
     214
     215    double Ri = getMeanR (&measure[k], average, secfilt);
     216    double Di = getMeanD (&measure[k], average, secfilt);
     217
     218    // mark (as POOR) any measurements which are deviant from the mean by > ExcludeBogusRadius
     219    if (ExcludeBogus) {
     220      coords.crval1 = average[0].R;
     221      coords.crval2 = average[0].D;
     222      double Xi, Yi;
     223      RD_to_XY (&Xi, &Yi, Ri, Di, &coords);
     224      double radius = hypot(Xi, Yi);
     225      if (radius > ExcludeBogusRadius) {
     226        measure[k].dbFlags |= ID_MEAS_POOR_ASTROM;
     227        if (measureBig) { measureBig[k].dbFlags |= ID_MEAS_POOR_ASTROM; }
    365228        continue;
    366229      }
    367 
    368       // what is the offset relative to the mean fit position?
    369       coords.crval1 = catalog[i].average[j].R;
    370       coords.crval2 = catalog[i].average[j].D;
    371 
    372       double dXoff, dYoff;
    373       RD_to_XY (&dXoff, &dYoff, fit.Ro, fit.Do, &coords);
    374       float dPos = hypot (dXoff, dYoff);
    375       if (dPos > MaxMeanOffset) {
    376         if (Noffset < 100) {
    377           fprintf (stderr, "(%f,%f) -> (%f,%f) (%f,%f)\n", coords.crval1, coords.crval2, fit.Ro, fit.Do, dXoff, dYoff);
    378         }
    379         Noffset ++;
    380         continue;
     230      measure[k].dbFlags &= ~ID_MEAS_POOR_ASTROM;
     231      if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_POOR_ASTROM; }
     232    }
     233
     234    // outlier rejection
     235    if (FALSE && FlagOutlier && (measure[k].dbFlags & ID_MEAS_POOR_ASTROM)) {
     236      continue;
     237    }
     238
     239    R[N] = Ri;
     240    D[N] = Di;
     241
     242    // measure[k].t is UNIX seconds, T2000 is UNIX seconds for J2000.
     243    // T[] is time in years since J2000 (jd = 2451545)
     244    T[N] = (measure[k].t - T2000) / (86400*365.25) ; // time relative to J2000 in years
     245
     246    // dX, dY : error in arcsec --
     247    dX[N] = GetAstromErrorTiny (&measure[k], ERROR_MODE_RA);
     248    dY[N] = GetAstromErrorTiny (&measure[k], ERROR_MODE_DEC);
     249
     250    // allow a given photcode or measurement to be
     251    // ignored if the error is NAN (for photcode, set astromErrSys to NaN)
     252    if (isnan(dX[N])) continue;
     253    if (isnan(dY[N])) continue;
     254
     255    // add systematic error in quadrature, if desired
     256    // only do this after the fit has converged (or you will never improve the poor images)
     257    // if (INCLUDE_SYS_ERR) {
     258    // float dRsys = FromShortPixels(measure[k].dRsys);
     259    // dX[N] = hypot(dX[N], dRsys);
     260    // dY[N] = hypot(dY[N], dRsys);
     261    // }
     262
     263    // dX[N] = 0.1;
     264    // dY[N] = 0.1;
     265
     266    dT[N] = measure[k].dt;
     267
     268    // XXX this is (slightly) inconsistent: dX,dY are the X and Y direction errors in
     269    // arcseconds.  dR, dD are the errors in those directions in degrees.  IF we have
     270    // non-circular errors (different values for X and Y), then dR and dD will be
     271    // incorrect: they would need to be rotated to take out the position angle
     272    dR[N] = dX[N] / 3600.0;
     273    dD[N] = dY[N] / 3600.0;
     274
     275    if (setRefColor) {
     276      float colorBlue = getColorBlue (m+k, i);
     277      if (!isnan(colorBlue)) {
     278        C_blue[NcBlue] = colorBlue;
     279        NcBlue++;
    381280      }
    382 
    383 
    384       // the measure fields must be updated before the average fields
    385       for (k = 0; k < catalog[i].average[j].Nmeasure; k++) {
    386         setMeanR (fit.Ro, &measure[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
    387         setMeanD (fit.Do, &measure[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
    388         if (measureBig) {
    389           setMeanR_Big (fit.Ro, &measureBig[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
    390           setMeanD_Big (fit.Do, &measureBig[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
    391         }
    392       }     
    393 
    394       catalog[i].average[j].R   = fit.Ro; // RA in degrees
    395       catalog[i].average[j].D   = fit.Do; // DEC in degrees
    396       catalog[i].average[j].dR  = fit.dRo; // RA scatter in arcsec
    397       catalog[i].average[j].dD  = fit.dDo; // DEC scatter in arcsec
    398 
    399       catalog[i].average[j].uR  = fit.uR; // RA proper motion in arcsec/year
    400       catalog[i].average[j].uD  = fit.uD; // DEC proper motion in arcsec/year
    401       catalog[i].average[j].duR = fit.duR; // RA proper motion error in arcsec/year
    402       catalog[i].average[j].duD = fit.duD; // DEC proper motion error in arcsec/year
    403 
    404       catalog[i].average[j].P   = fit.p; // parallax in arcsec
    405       catalog[i].average[j].dP  = fit.dp; // parallax error in arcsec
    406 
    407       catalog[i].average[j].ChiSqAve  = fitAve.chisq;
    408       catalog[i].average[j].ChiSqPM   = fitPM.chisq;
    409       catalog[i].average[j].ChiSqPar  = fitPAR.chisq;
    410       catalog[i].average[j].Tmean = (Tmean * 86400 * 365.25) + T2000;
    411       catalog[i].average[j].Trange = (Trange * 86400 * 365.25);
    412       catalog[i].average[j].Npos = fit.Nfit;
    413       if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f) pm=(%f %f) chisq=(%f, %f, %f)\n",
    414                           catalog[i].average[j].R,
    415                           catalog[i].average[j].D,
    416                           fit.Ro, fit.Do,
    417                           3600*(catalog[i].average[j].R - fit.Ro),
    418                           3600*(catalog[i].average[j].D - fit.Do),
    419                           catalog[i].average[j].uR,
    420                           catalog[i].average[j].uD,
    421                           fitAve.chisq, fitPM.chisq, fitPAR.chisq);
    422     }
    423 
    424     NaveSum += Nave;
    425     NpmSum += Npm;
    426     NparSum += Npar;
    427     NskipSum += Nskip;
    428     NoffSum += Noffset;
    429     if (VERBOSE) fprintf (stderr, "catalog %d : "OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par : Nskip "OFF_T_FMT", Noffset "OFF_T_FMT"\n",  i,  Nave,  Npm,  Npar,  Nskip, Noffset);
    430   }
    431 
    432   freeObjectData ();
    433 
    434   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);
     281      float colorRed = getColorRed (m+k, i);
     282      if (!isnan(colorRed)) {
     283        C_red[NcRed] = colorRed;
     284        NcRed++;
     285      }
     286    }
     287
     288    measure[k].dbFlags |= ID_MEAS_USED_OBJ;
     289    if (measureBig) { measureBig[k].dbFlags |= ID_MEAS_USED_OBJ; }
     290
     291    N++;
     292  } // loop over measurements : average[0].Nmeasure
     293
     294  if (N < 1) {
     295    if (isfinite(average[0].Rstk) && isfinite(average[0].Dstk)) {
     296      average[0].R  = average[0].Rstk;
     297      average[0].D  = average[0].Dstk;
     298      average[0].dR = average[0].dRstk;
     299      average[0].dD = average[0].dDstk;
     300    }
     301    return FALSE;
     302  }
     303
     304  // if we have too few good detections for the desired fit, or too limited a
     305  // baseline, use a fit with fewer parameters.  XXX if we have too few measurements
     306  // for even the average position, consider including the lower-quality detections?
     307
     308  // find Tmin & Tmax from the list of accepted measurements
     309  double Tmean = 0.0;
     310  double Tmin = T[0];
     311  double Tmax = T[0];
     312  for (k = 0; k < N; k++) {
     313    Tmin = MIN(Tmin, T[k]);
     314    Tmax = MAX(Tmax, T[k]);
     315    Tmean += T[k];
     316  }
     317  double Trange = Tmax - Tmin;
     318
     319  if (RELASTRO_OP == OP_HIGH_SPEED) {
     320    Tmean = 0.5*(Tmax - Tmin);
     321  } else {
     322    Tmean /= (float) N;
     323  }
     324
     325  /* we need to do the fit in a locally linear space; choose a ref coordinate */
     326  coords.crval1 = R[0];
     327  coords.crval2 = D[0];
     328
     329  // to judge the quality of the PM and PAR fits, we need to fit all three models and compare Chisq
     330
     331  // *** first fit for the proper motion (skip fit if Trange or Npts is too small) ***
     332  if ((mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) {
     333    if (Trange < PM_DT_MIN) {
     334      mode = FIT_AVERAGE;
     335      goto skipPM;
     336    }
     337    if (N <= PM_TOOFEW) {
     338      mode = FIT_AVERAGE;
     339      goto skipPM;
     340    }
     341
     342    // project all of the R,D coordinates to a plane centered on this coordinate. set
     343    // the times to be relative to Tmean (this is required for parallax as well)
     344    for (k = 0; k < N; k++) {
     345      RD_to_XY (&X[k], &Y[k], R[k], D[k], &coords);
     346      T[k] -= Tmean;
     347      if (XVERB) {
     348        fprintf (stderr, OFF_T_FMT" %f %f %f  %f %f +/- %f %f\n",  k, T[k], R[k], D[k], X[k], Y[k], dX[k], dY[k]);
     349      }
     350    }     
     351
     352    FitPM (&fitPM, X, dX, Y, dY, T, N, XVERB);
     353
     354    if (XVERB) fprintf (stderr, "fitted PM:  %f - %f : %f %f : %f %f : %f vs %f\n", Tmin, Tmax, fitPM.Ro, fitPM.Do, fitPM.uR, fitPM.uD, fitPM.chisq, fitAve.chisq);
     355
     356    // project Ro, Do back to RA,DEC
     357    XY_to_RD (&fitPM.Ro, &fitPM.Do, fitPM.Ro, fitPM.Do, &coords);
     358    if (XVERB) fprintf (stderr, "project: %f %f : %f %f : %f\n", fitPM.Ro, fitPM.Do, fitPM.uR, fitPM.uD, fitPM.p);
     359
     360    fitPM.p  = fitPM.dp  = 0.0;
     361    average[0].flags |= ID_STAR_FIT_PM;
     362    fitStats->Npm ++;
     363
     364    // XXX a hard-wired hack...
     365    if ((fabs(fitPM.uR) > 2.0) || (fabs(fitPM.uD) > 2.0)) {
     366      mode = FIT_AVERAGE;
     367      average[0].flags |= ID_STAR_BAD_PM;
     368    }
     369  }
     370 
     371skipPM:
     372  // fit the parallax + proper-motion model
     373  // NOTE : we only fit PAR if we have already fitted for proper motion. if we do not fit PM or we fail
     374  // to fit PM, we do not attempt PAR.  thus failure to fit PAR falls back to PM-only
     375  if (mode == FIT_PM_AND_PAR) {
     376    if (Trange < PM_DT_MIN) {
     377      mode = FIT_PM_ONLY;
     378      goto skipPAR;
     379    }
     380    if (N <= PAR_TOOFEW) {
     381      mode = FIT_PM_ONLY;
     382      goto skipPAR;
     383    }
     384    float pXmin = +2.0;
     385    float pXmax = -2.0;
     386    float pYmin = +2.0;
     387    float pYmax = -2.0;
     388    for (k = 0; k < N; k++) {
     389      ParFactor (&pX[k], &pY[k], R[k], D[k], T[k], Tmean);
     390      pXmin = MIN (pXmin, pX[k]);
     391      pXmax = MAX (pXmax, pX[k]);
     392      pYmin = MIN (pYmin, pY[k]);
     393      pYmax = MAX (pYmax, pY[k]);
     394    }
     395    float dXRange = pXmax - pXmin;
     396    float dYRange = pYmax - pYmin;
     397    float parRange = hypot (dXRange, dYRange);
     398       
     399    if (parRange < PAR_FACTOR_MIN) {
     400      mode = FIT_PM_ONLY;
     401      goto skipPAR;
     402    }
     403
     404    FitPMandPar (&fitPAR, X, dX, Y, dY, T, pX, pY, N, XVERB);
     405    if (XVERB) fprintf (stderr, "fitted PM+PAR:  %f - %f : %f %f : %f %f : %f %f : %f vs %f vs %f\n", Tmin, Tmax, fitPAR.Ro, fitPAR.Do, fitPAR.uR, fitPAR.uD, fitPAR.p, fitPAR.dp, fitPAR.chisq, fitPM.chisq, fitAve.chisq);
     406
     407    XY_to_RD (&fitPAR.Ro, &fitPAR.Do, fitPAR.Ro, fitPAR.Do, &coords);
     408    average[0].flags |= ID_STAR_FIT_PAR;
     409    fitStats->Npar ++;
     410
     411    // XXX a hard-wired hack...
     412    if ((fabs(fitPAR.uR) > 2.0) || (fabs(fitPAR.uD) > 2.0)) {
     413      mode = FIT_PM_ONLY;
     414    }
     415  }       
     416
     417skipPAR:
     418  {
     419    // ALWAYS fit the average model
     420    StatType statsR, statsD;
     421    liststats_pos (R, dR, N, &statsR, XVERB); // WARNING: this function modifies R (do not use after here)
     422    liststats_pos (D, dD, N, &statsD, XVERB); // WARNING: this function modifies D (do not use after here)
     423
     424    fitAve.Ro = statsR.mean;
     425    fitAve.dRo = 3600.0*statsR.sigma;
     426
     427    fitAve.Do = statsD.mean;
     428    fitAve.dDo = 3600.0*statsD.sigma;
     429
     430    fitAve.chisq = (N > 1) ? 0.5 * (statsR.chisq + statsD.chisq) : NAN;
     431    fitAve.Nfit = N;
     432
     433    fitAve.uR = fitAve.duR = 0.0;
     434    fitAve.uD = fitAve.duD = 0.0;
     435    fitAve.p  = fitAve.dp  = 0.0;
     436    average[0].flags |= ID_STAR_FIT_AVE;
     437    fitStats->Nave ++;
     438  }
     439
     440  if (setRefColor) {
     441    float colorMedian;
     442    dsort (C_blue, NcBlue);
     443    colorMedian = (NcBlue > 0) ? C_blue[(int)(0.5*NcBlue)] : NAN;
     444    average[0].refColorBlue = colorMedian;
     445    dsort (C_red, NcRed);
     446    colorMedian = (NcRed > 0) ? C_red[(int)(0.5*NcRed)] : NAN;
     447    average[0].refColorRed = colorMedian;
     448  }
     449
     450  /* choose the result based on the chisq values */
     451  // XXXX for now, just use the mode as the result:
     452  int result = mode;
     453
     454  switch (result) {
     455    case FIT_AVERAGE:
     456      average[0].flags |= ID_STAR_USE_AVE;
     457      fit = fitAve;
     458      break;
     459    case FIT_PM_ONLY:
     460      average[0].flags |= ID_STAR_USE_PM;
     461      fit = fitPM;
     462      break;
     463    case FIT_PM_AND_PAR:
     464      average[0].flags |= ID_STAR_USE_PAR;
     465      fit = fitPAR;
     466      break;
     467  }
     468  if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f) pm=(%f %f) plx=(%f +/- %f)\n",
     469                      average[0].R,
     470                      average[0].D,
     471                      fit.Ro, fit.Do,
     472                      3600*(average[0].R - fit.Ro),
     473                      3600*(average[0].D - fit.Do),
     474                      fit.uR, fit.uD, fit.p, fit.dp);
     475
     476  // make sure that the fit succeeded
     477  int status = TRUE;
     478  status &= finite(fit.Ro);
     479  status &= finite(fit.Do);
     480  status &= finite(fit.dRo);
     481  status &= finite(fit.dDo);
     482  status &= finite(fit.uR);
     483  status &= finite(fit.uD);
     484  status &= finite(fit.duR);
     485  status &= finite(fit.duD);
     486  status &= finite(fit.p);
     487  status &= finite(fit.dp);
     488  if (!status) {
     489    fitStats->Nskip ++;
     490    return FALSE; // XXX ??
     491  }
     492
     493  // what is the offset relative to the mean fit position?
     494  coords.crval1 = average[0].R;
     495  coords.crval2 = average[0].D;
     496
     497  double dXoff, dYoff;
     498  RD_to_XY (&dXoff, &dYoff, fit.Ro, fit.Do, &coords);
     499  float dPos = hypot (dXoff, dYoff);
     500  if (dPos > MaxMeanOffset) {
     501    if (fitStats->Noffset < 100) {
     502      fprintf (stderr, "(%f,%f) -> (%f,%f) (%f,%f)\n", coords.crval1, coords.crval2, fit.Ro, fit.Do, dXoff, dYoff);
     503    }
     504    fitStats->Noffset ++;
     505    return FALSE; // XXX ??
     506  }
     507
     508  average[0].R          = fit.Ro; // RA in degrees
     509  average[0].D          = fit.Do; // DEC in degrees
     510  average[0].dR         = fit.dRo; // RA scatter in arcsec
     511  average[0].dD         = fit.dDo; // DEC scatter in arcsec
     512
     513  average[0].uR         = fit.uR; // RA proper motion in arcsec/year
     514  average[0].uD         = fit.uD; // DEC proper motion in arcsec/year
     515  average[0].duR        = fit.duR; // RA proper motion error in arcsec/year
     516  average[0].duD        = fit.duD; // DEC proper motion error in arcsec/year
     517
     518  average[0].P          = fit.p; // parallax in arcsec
     519  average[0].dP         = fit.dp; // parallax error in arcsec
     520
     521  average[0].ChiSqAve   = fitAve.chisq;
     522  average[0].ChiSqPM    = fitPM.chisq;
     523  average[0].ChiSqPar   = fitPAR.chisq;
     524
     525  average[0].Tmean      = (Tmean * 86400 * 365.25) + T2000;
     526  average[0].Trange     = (Trange * 86400 * 365.25);
     527  average[0].Npos       = fit.Nfit;
     528
     529  // unset the NO_ASTROM bit (not(NO_ASTROM) == HAVE_ASTROM)
     530  average[0].flags &= ~ID_STAR_NO_ASTROM;
     531
     532  if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f) pm=(%f %f) chisq=(%f, %f, %f)\n",
     533                      average[0].R,
     534                      average[0].D,
     535                      fit.Ro, fit.Do,
     536                      3600*(average[0].R - fit.Ro),
     537                      3600*(average[0].D - fit.Do),
     538                      average[0].uR,
     539                      average[0].uD,
     540                      fitAve.chisq, fitPM.chisq, fitPAR.chisq);
     541
    435542  return (TRUE);
    436543}
     544
     545// This function operates on both Measure and MeasureTiny.  In the big stages, this should
     546// be called with just MeasureTiny set and Measure == NULL
     547int UpdateObjects_Stack (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats) {
     548
     549  off_t k;
     550
     551  // set the default values
     552  average[0].Rstk  = NAN; // RA in degrees
     553  average[0].Dstk  = NAN; // DEC in degrees
     554  average[0].dRstk = NAN; // RA scatter in arcsec
     555  average[0].dDstk = NAN; // DEC scatter in arcsec
     556
     557  /* calculate the average value of R,D for a single star */
     558  PMFit fitAve;
     559  memset (&fitAve, 0, sizeof(fitAve));
     560  fitAve.chisq = NAN;
     561
     562  if (average[0].Nmeasure == 0) return TRUE;
     563
     564  int N = 0;
     565
     566  int XVERB = FALSE;
     567  XVERB |= (average[0].objID == OBJ_ID_SRC) && (average[0].catID == CAT_ID_SRC);
     568  XVERB |= (average[0].objID == OBJ_ID_DST) && (average[0].catID == CAT_ID_DST);
     569
     570  // find the basic properties of the detections for this object (Tmin, Tmax, Tmean)
     571  for (k = 0; k < average[0].Nmeasure; k++) {
     572
     573    if (XVERB) {
     574      char *date = ohana_sec_to_date (measure[k].t);
     575      int dbFlagsBig = measureBig ? measureBig[k].dbFlags : 0;
     576      fprintf (stderr, "stack: "OFF_T_FMT" %f %f %s : 0x%08x : 0x%08x\n",  k, measure[k].R, measure[k].D, date, measure[k].dbFlags, dbFlagsBig);
     577      free (date);
     578    }
     579
     580    // SKIP everything except gpc1 stack data
     581    if (!isGPC1stack(measure[k].photcode)) continue;
     582
     583    // exclude bad detections based on: photcodes, psfQF, time range, photflags & astromBadMask, mag_inst
     584    int keepMeasure = measureBig ? MeasFilterTest(&measureBig[k], FALSE) : MeasFilterTestTiny(&measure[k], FALSE);
     585    if (!keepMeasure) {
     586      continue;
     587    }
     588
     589    R[N] = getMeanR (&measure[k], average, secfilt);
     590    D[N] = getMeanD (&measure[k], average, secfilt);
     591
     592    // dX, dY : error in arcsec --
     593    dX[N] = GetAstromErrorTiny (&measure[k], ERROR_MODE_RA);
     594    dY[N] = GetAstromErrorTiny (&measure[k], ERROR_MODE_DEC);
     595
     596    // allow a given photcode or measurement to be
     597    // ignored if the error is NAN (for photcode, set astromErrSys to NaN)
     598    if (isnan(dX[N])) continue;
     599    if (isnan(dY[N])) continue;
     600
     601    // XXX this is (slightly) inconsistent: dX,dY are the X and Y direction errors in
     602    // arcseconds.  dR, dD are the errors in those directions in degrees.  IF we have
     603    // non-circular errors (different values for X and Y), then dR and dD will be
     604    // incorrect: they would need to be rotated to take out the position angle
     605    dR[N] = dX[N] / 3600.0;
     606    dD[N] = dY[N] / 3600.0;
     607
     608    // XXX use a different flag for stack measurements?
     609    // measure[k].dbFlags |= ID_MEAS_USED_OBJ;
     610    // if (measureBig) { measureBig[k].dbFlags |= ID_MEAS_USED_OBJ; }
     611
     612    N++;
     613  } // loop over measurements : average[0].Nmeasure
     614
     615  // if we have too few good detections for the desired fit, or too limited a
     616  // baseline, use a fit with fewer parameters.  XXX if we have too few measurements
     617  // for even the average position, consider including the lower-quality detections?
     618
     619  // too few measurements for average position (require 2 values)
     620  if (N < 1) return FALSE; // XXX ??
     621
     622  // find the mean position
     623  StatType statsR, statsD;
     624  liststats_pos (R, dR, N, &statsR, XVERB); // WARNING: this function modifies R (do not use after here)
     625  liststats_pos (D, dD, N, &statsD, XVERB); // WARNING: this function modifies D (do not use after here)
     626
     627  fitAve.Ro = statsR.mean;
     628  fitAve.dRo = 3600.0*statsR.sigma;
     629
     630  fitAve.Do = statsD.mean;
     631  fitAve.dDo = 3600.0*statsD.sigma;
     632
     633  fitAve.chisq = 0.5 * (statsR.chisq + statsD.chisq);
     634  fitAve.Nfit = N;
     635
     636  // XXX choose stack flag? average[0].flags |= ID_STAR_FIT_AVE;
     637  fitStats->Nave ++;
     638
     639  if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f)\n",
     640                      average[0].R,
     641                      average[0].D,
     642                      fitAve.Ro, fitAve.Do,
     643                      3600*(average[0].R - fitAve.Ro),
     644                      3600*(average[0].D - fitAve.Do));
     645
     646  // make sure that the fit succeeded
     647  int status = TRUE;
     648  status &= finite(fitAve.Ro);
     649  status &= finite(fitAve.Do);
     650  status &= finite(fitAve.dRo);
     651  status &= finite(fitAve.dDo);
     652  if (!status) {
     653    fitStats->Nskip ++;
     654    return FALSE;
     655  }
     656
     657  // what is the offset relative to the mean fit position?
     658  coords.crval1 = average[0].R;
     659  coords.crval2 = average[0].D;
     660
     661  double dXoff, dYoff;
     662  RD_to_XY (&dXoff, &dYoff, fitAve.Ro, fitAve.Do, &coords);
     663  float dPos = hypot (dXoff, dYoff);
     664  if (dPos > MaxMeanOffset) {
     665    if (fitStats->Noffset < 100) {
     666      fprintf (stderr, "(%f,%f) -> (%f,%f) (%f,%f)\n", coords.crval1, coords.crval2, fitAve.Ro, fitAve.Do, dXoff, dYoff);
     667    }
     668    fitStats->Noffset ++;
     669    return FALSE;
     670  }
     671
     672  // set the stack position values
     673  average[0].Rstk  = fitAve.Ro; // RA in degrees
     674  average[0].Dstk  = fitAve.Do; // DEC in degrees
     675  average[0].dRstk = fitAve.dRo; // RA scatter in arcsec
     676  average[0].dDstk = fitAve.dDo; // DEC scatter in arcsec
     677
     678  return (TRUE);
     679}
     680
     681
    437682
    438683/* fitting proper-motion and parallax:
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/args.c

    r36680 r37403  
    179179  FlagOutlier = FALSE;
    180180  if ((N = get_argument (argc, argv, "-clip"))) {
     181    fprintf (stderr, "-clip is currently disabled\n");
    181182    remove_argument (N, &argc, argv);
    182183    CLIP_THRESH = atof (argv[N]);
    183184    remove_argument (N, &argc, argv);
    184185    FlagOutlier = TRUE;
     186  }
     187
     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;
    185195  }
    186196
     
    284294  }
    285295
     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
    286325  PHOTCODE_KEEP_LIST = NULL;
    287326  if ((N = get_argument (argc, argv, "+photcode"))) {
     
    291330  }
    292331
    293   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;
    294335  if ((N = get_argument (argc, argv, "-photcode"))) {
    295336    remove_argument (N, &argc, argv);
    296     char *tmp1 = strcreate(argv[N]);
    297 
    298     int Ntotal = strlen(tmp1) + strlen(PHOTCODE_SKIP_LIST) + 5;
    299 
    300     char *tmp2 = NULL;
    301     ALLOCATE (tmp2, char, Ntotal);
    302     snprintf (tmp2, Ntotal, "%s,%s", PHOTCODE_SKIP_LIST, tmp1);
    303 
    304     free (tmp1);
    305     free (PHOTCODE_SKIP_LIST);
    306 
    307     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    }
    308349    remove_argument (N, &argc, argv);
    309350  }
     
    582623  FlagOutlier = FALSE;
    583624  if ((N = get_argument (argc, argv, "-clip"))) {
     625    fprintf (stderr, "-clip is currently disabled\n");
    584626    remove_argument (N, &argc, argv);
    585627    CLIP_THRESH = atof (argv[N]);
    586628    remove_argument (N, &argc, argv);
    587629    FlagOutlier = TRUE;
     630  }
     631
     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;
    588639  }
    589640
     
    655706    remove_argument (N, &argc, argv);
    656707    TimeSelect = TRUE;
     708  }
     709
     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);
    657734  }
    658735
     
    861938  exit (2);
    862939}
     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/ps2-tc3-20130727/Ohana/src/relastro/src/bcatalog.c

    r34429 r37403  
    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/ps2-tc3-20130727/Ohana/src/relastro/src/dvo_astrom_ops.c

    r33652 r37403  
    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/ps2-tc3-20130727/Ohana/src/relastro/src/high_speed_objects.c

    r36680 r37403  
    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/ps2-tc3-20130727/Ohana/src/relastro/src/hpm_objects.c

    r36680 r37403  
    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/ps2-tc3-20130727/Ohana/src/relastro/src/initialize.c

    r36680 r37403  
    88  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/ps2-tc3-20130727/Ohana/src/relastro/src/launch_region_hosts.c

    r36680 r37403  
    11# include "relastro.h"
    22# define DEBUG 0
    3 
    4 int strextend (char *input, char *format,...) {
    5 
    6   char tmpextra[1024], tmpline[1024];
    7   va_list argp;
    8 
    9   va_start (argp, format);
    10   vsnprintf (tmpextra, 1024, format, argp);
    11   snprintf (tmpline, 1024, "%s %s", input, tmpextra);
    12   strcpy (input, tmpline);
    13 
    14   return TRUE;
    15 }
    163
    174int launch_region_hosts (RegionHostTable *regionHosts) {
     
    229  for (i = 0; i < regionHosts->Nhosts; i++) {
    2310    char *syncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanmags.sync");
    24     truncate (syncfile, 0);
     11    if (truncate (syncfile, 0)) fprintf (stderr, "trouble clearing syncfile %s\n", syncfile);
    2512    free (syncfile);
    2613
    2714    char *fitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanmags.fits");
    28     truncate (fitsfile, 0);
     15    if (truncate (fitsfile, 0)) fprintf (stderr, "trouble clearing fitsfile %s\n", fitsfile);
    2916    free (fitsfile);
    3017
    3118    char *imsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagemags.sync");
    32     truncate (imsyncfile, 0);
     19    if (truncate (imsyncfile, 0)) fprintf (stderr, "trouble clearing imsyncfile %s\n", imsyncfile);
    3320    free (imsyncfile);
    3421
    3522    char *imfitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagemags.fits");
    36     truncate (imfitsfile, 0);
     23    if (truncate (imfitsfile, 0)) fprintf (stderr, "trouble clearing imfitsfile %s\n", imfitsfile);
    3724    free (imfitsfile);
    3825
    3926    char *loopsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "loop.sync");
    40     truncate (loopsyncfile, 0);
     27    if (truncate (loopsyncfile, 0)) fprintf (stderr, "trouble clearing loopsyncfile %s\n", loopsyncfile);
    4128    free (loopsyncfile);
    4229  }
     
    8875    if (PHOTCODE_KEEP_LIST) strextend (command, "+photcode %s", PHOTCODE_KEEP_LIST);
    8976    if (PHOTCODE_SKIP_LIST) strextend (command, "-photcode %s", PHOTCODE_SKIP_LIST);
     77    if (PHOTCODE_RESET_LIST) strextend (command, "-reset-to-photcode %s", PHOTCODE_RESET_LIST);
    9078
    9179    if (MaxDensityUse)      strextend (command, "-max-density %f", MaxDensityValue);
    9280    if (ImagSelect)         strextend (command, "-instmag %f %f", ImagMin, ImagMax);
     81    if (ExcludeBogus)       strextend (command, "-exclude-bogus %f", ExcludeBogusRadius);
     82
     83    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
     84      strextend (command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     85    }
     86    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
     87      strextend (command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
     88    }
     89
    9390    if (PhotFlagSelect)     strextend (command, "+photflags");
    9491    if (PhotFlagBad)        strextend (command, "+photflagbad %d", PhotFlagBad);
     
    9794    if (MinBadQF > 0.0)        strextend (command, "-min-bad-psfqf %f", MinBadQF);
    9895    if (MaxMeanOffset != 10.0) strextend (command, "-max-mean-offset  %f", MaxMeanOffset);
     96
     97    strextend (command, "-D RELASTRO_SRC_MEAS_TOOFEW %d", SRC_MEAS_TOOFEW);
     98    strextend (command, "-D RELASTRO_SIGMA_LIM %f", SIGMA_LIM);
     99    strextend (command, "-D RELASTRO_DPOS_MAX %f", DPOS_MAX);
     100    strextend (command, "-D ADDSTAR_RADIUS %f", ADDSTAR_RADIUS);
     101
     102    if (USE_FIXED_PIXCOORDS) strextend (command, "-D USE_FIXED_PIXCOORDS 1");
    99103
    100104    if (TimeSelect) {
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/load_catalogs.c

    r36680 r37403  
    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) {
    116125
    117126  char uniquer[12];
     
    150159              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);
    151160
    152     char tmpline[1024];
    153     if (FIT_MODE == FIT_PM_ONLY)         { snprintf (tmpline, 1024, "%s -pm",    command);           strcpy (command, tmpline); }
    154     if (FIT_MODE == FIT_PAR_ONLY)        { snprintf (tmpline, 1024, "%s -par",   command);           strcpy (command, tmpline); }
    155     if (FIT_MODE == FIT_PM_AND_PAR)      { snprintf (tmpline, 1024, "%s -pmpar", command);           strcpy (command, tmpline); }
    156 
    157     if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",              command);                    strcpy (command, tmpline); }
    158     if (VERBOSE2)      { snprintf (tmpline, 1024, "%s -vv",             command);                    strcpy (command, tmpline); }
    159     if (RESET)         { snprintf (tmpline, 1024, "%s -reset",          command);                    strcpy (command, tmpline); }
    160     if (ImagSelect)    { snprintf (tmpline, 1024, "%s -instmag %f %f",  command, ImagMin, ImagMax);  strcpy (command, tmpline); }
    161     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);
    162172   
    163     if (FlagOutlier)   { snprintf (tmpline, 1024, "%s -clip %d",        command, CLIP_THRESH);       strcpy (command, tmpline); }
    164    
    165     if (USE_FIXED_PIXCOORDS) { snprintf (tmpline, 1024, "%s -D USE_FIXED_PIXCOORDS 1", command);     strcpy (command, tmpline); }
    166 
    167     if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, 1024, "%s +photcode %s", command, PHOTCODE_KEEP_LIST); strcpy (command, tmpline); }
    168     if (PHOTCODE_SKIP_LIST) { snprintf (tmpline, 1024, "%s -photcode %s", command, PHOTCODE_SKIP_LIST); strcpy (command, tmpline); }
    169     if (PhotFlagSelect)    { snprintf (tmpline, 1024, "%s +photflags",   command);                     strcpy (command, tmpline); }
    170     if (PhotFlagBad)       { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad);     strcpy (command, tmpline); }
    171     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);
    172186    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
    173187
     
    175189      char *tstart = ohana_sec_to_date (TSTART);
    176190      char *tstop  = ohana_sec_to_date (TSTOP);
    177       snprintf (tmpline, 1024, "%s -time %s %s", command, tstart, tstop);
     191      strextend (command, "-time %s %s", tstart, tstop);
    178192      free (tstart);
    179193      free (tstop);
    180       strcpy (command, tmpline);
    181194    }
    182195
     
    211224  }
    212225
     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
    213239  // each host generates a BrightCatalog structure, with the measure, average, etc value
    214240  // loaded into a single set of arrays (of MeasureTiny, AverageTiny, Secfilt).  I need to
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/markObjects.c

    r36680 r37403  
    88  // How strongly do I own this object?
    99  for (i = 0; i < Ncatalog; i++) {
    10     ALLOCATE (catalog[i].nOwn, int, catalog[i].Naverage);
    11     memset (catalog[i].nOwn, 0, catalog[i].Naverage*sizeof(int));
     10    ALLOCATE (catalog[i].nOwn_t, int, catalog[i].Naverage);
     11    memset (catalog[i].nOwn_t, 0, catalog[i].Naverage*sizeof(int));
    1212    for (j = 0; j < catalog[i].Naverage; j++) {
    1313      int nOwn = 0;
     
    1717        nOwn ++;
    1818      }
    19       catalog[i].nOwn[j] = nOwn;
     19      catalog[i].nOwn_t[j] = nOwn;
    2020    }
    2121  }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/relastroVisual.c

    r31635 r37403  
    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/ps2-tc3-20130727/Ohana/src/relastro/src/relastro_client.c

    r36680 r37403  
    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) {
    3737        fprintf (stderr, "ERROR loading catalogs from %s\n", CATDIR);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/relastro_images.c

    r36680 r37403  
    2828  // XXX pass in the image table
    2929  // XXX who carries the image grid?
    30   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);
    3134  MARKTIME("load catalog data: %f sec\n", dtime);
     35
     36  if (photcodesReset) {
     37    photcodesKeep  = photcodesReset;
     38    NphotcodesKeep = NphotcodesReset;
     39  }
    3240
    3341  if (Ncatalog == 0) {
     
    5058  // set test points based on the starmap
    5159  createStarMap (catalog, Ncatalog);
     60
     61  // XXX NOTE : for 2mass reset, photcodesKeep should now limit to 2MASS measurements
    5262
    5363  /* major modes */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/relastro_merge_source.c

    r34088 r37403  
    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/ps2-tc3-20130727/Ohana/src/relastro/src/relastro_objects.c

    r36680 r37403  
    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
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/relastro_parallel_images.c

    r36680 r37403  
    4545
    4646  /* load catalog data from region files (hostID is 0 since we are not a client */
    47   catalog = load_catalogs (skylist, &Ncatalog, TRUE, 0, NULL);
     47  char *syncfile = make_filename (CATDIR, regionHosts->hosts[myHost].hostname, REGION_HOST_ID, "loadcat.sync");
     48  catalog = load_catalogs (skylist, &Ncatalog, TRUE, 0, NULL, syncfile);
    4849  MARKTIME("-- load catalog data: %f sec\n", dtime);
     50  free (syncfile);
    4951 
    50   // NOTE: if I let all hosts load blindly, I saturate the data clients with too many
    51   // relastro_client requests.  I need to have the master mediate this.  the master
    52   // will not launch the next remote job until this one says it is done
    53   char *syncfile = make_filename (CATDIR, regionHosts->hosts[myHost].hostname, REGION_HOST_ID, "loadcat.sync");
    54   update_sync_file (syncfile, 1);
    55  
     52  if (photcodesReset) {
     53    photcodesKeep  = photcodesReset;
     54    NphotcodesKeep = NphotcodesReset;
     55  }
     56
    5657  // generate tables go from catID,objID -> catSeq,objSeq
    5758  indexCatalogs (catalog, Ncatalog);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/share_mean_pos.c

    r36680 r37403  
    3333      // XXX : sky objects without missing detections
    3434      // XXX watch out for detections which are not associated with an image (REF)
    35       if (catalog[i].nOwn[j] == catalog[i].average[j].Nmeasure) continue;
     35      if (catalog[i].nOwn_t[j] == catalog[i].average[j].Nmeasure) continue;
    3636
    3737      set_mean_pos (&meanpos[Nmeanpos], &catalog[i].average[j]);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/syncfile.c

    r36680 r37403  
    5050int clear_sync_file (char *filename) {
    5151  // delete file contents
    52   truncate (filename, 0);
     52  if (truncate (filename, 0)) fprintf (stderr, "trouble clearing file %s\n", filename);
    5353
    5454  return TRUE;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/Makefile

    r36680 r37403  
    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    \
     
    8283$(SRC)/args.$(ARCH).o            \
    8384$(SRC)/help.$(ARCH).o            \
     85$(SRC)/extra.$(ARCH).o           \
    8486$(SRC)/synthetic_mags.$(ARCH).o  \
    8587$(SRC)/plotstuff.$(ARCH).o       \
    8688$(SRC)/liststats.$(ARCH).o       \
    8789$(SRC)/initialize.$(ARCH).o      \
     90$(SRC)/syncfile.$(ARCH).o        \
    8891$(SRC)/load_catalogs.$(ARCH).o   \
    8992$(SRC)/reload_catalogs.$(ARCH).o \
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/doc/mosaic.txt

    r33963 r37403  
     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/ps2-tc3-20130727/Ohana/src/relphot/include/relphot.h

    r36680 r37403  
    44# include <signal.h>
    55# include <pthread.h>
    6 
    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);
    156
    167/* # define GRID_V1 */
     
    119110  float M;
    120111  float dM;
    121   float Xm;
     112  float Mchisq;
    122113  int Nsec;
    123114  unsigned int objID;
     
    130121  float dMcal;
    131122  float dMagSys;
    132   float Xm;
     123  short Xm;
    133124  int nFitPhotom;
    134125  int flags;
     
    317308int           findMosaics         PROTO((Catalog *catalog, int Ncatalog, int doMosaicList));
    318309
    319 void makeMosaics (Image *image, off_t Nimage);
     310void makeMosaics (Image *image, off_t Nimage, int mergeMcal);
    320311Mosaic *getMosaicForImage (off_t im);
    321312void setMosaicCenters (Image *image, off_t Nimage);
     
    360351void          liststats_setmode   PROTO((StatType *stats, char *strmode));
    361352int           liststats           PROTO((double *value, double *dvalue, double *wvalue, int N, StatType *stats));
    362 Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int hostID, char *hostpath));
    363 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));
    364355
    365356SkyList      *load_images         PROTO((FITS_DB *db, char *regionName, SkyRegion *region));
     
    449440int MatchImageName (off_t meas, int cat, char *name);
    450441int MatchImageSkycellID (off_t meas, int cat, int myTessID, int myProjectionID, int mySkycellID);
     442int FindImageSkycellID (off_t meas, int cat, int *myTessID, int *myProjectionID, int *mySkycellID);
    451443
    452444int load_tess (char *treefile);
     
    460452int setMrel_catalog_alt (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt);
    461453int setMrelAverageExposure (off_t meas, int cat, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, AverageTiny *averageT, SecFilt *secfilt, Measure *measure, MeasureTiny *measureT, off_t *found);
    462 int setMrelAverageStack (off_t meas, int cat, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, char *primaryCell);
     454int setMrelAverageStack (off_t meas, int cat, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure);
    463455int setGlobalObjStats (Average *average, Measure *measure);
    464456
     
    509501int relphot_parallel_images ();
    510502int relphot_parallel_regions ();
     503
     504// in extra.c
     505int isGPC1chip  (int photcode);
     506int isGPC1stack (int photcode);
     507int isGPC1warp  (int photcode);
     508
     509
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/BrightCatalog.c

    r36680 r37403  
    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];
     
    105105    fprintf (stderr, "loaded data for %lld measure\n", (long long) Nrow);
    106106
    107     free (dR      );
    108     free (dD      );
     107    free (R       );
     108    free (D       );
    109109    free (M       );
    110110    free (Mcal    );
     
    136136 
    137137    // need to create and assign to flat-field correction
    138     GET_COLUMN(R,             "RA",        double);
    139     GET_COLUMN(D,             "DEC",       double);
     138    GET_COLUMN(R,             "RA",          double);
     139    GET_COLUMN(D,             "DEC",         double);
    140140    GET_COLUMN(Nmeasure,      "NMEAS",       int);
    141141    GET_COLUMN(measureOffset, "MEASURE_OFF", int);
     
    182182 
    183183    // need to create and assign to flat-field correction
    184     GET_COLUMN(M,     "MAG",      float);
    185     GET_COLUMN(dM,    "MAG_ERR",  float);
    186     GET_COLUMN(Xm,    "MAG_CHI",  float);
    187     GET_COLUMN(flags, "FLAGS",    int);
    188     GET_COLUMN(Ncode, "NCODE",    short);
    189     GET_COLUMN(Nused, "NUSED",    short);
    190     GET_COLUMN(M_20,  "MAG_20",   short);
    191     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);
    192192    gfits_free_header (&theader);
    193193    gfits_free_table  (&ftable);
     
    196196    ALLOCATE (secfilt, SecFilt, Nrow);
    197197    for (i = 0; i < Nrow; i++) {
    198       secfilt[i].M     = M[i];         
    199       secfilt[i].dM    = dM[i];
    200       secfilt[i].Xm    = Xm[i];
    201       secfilt[i].flags = flags[i];
    202       secfilt[i].Ncode = Ncode[i];
    203       secfilt[i].Nused = Nused[i];
    204       secfilt[i].M_20  = M_20[i];
    205       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];
    206206    }
    207207    fprintf (stderr, "loaded data for %lld secfilt\n", (long long) Nrow);
    208208
    209     free (M    );
    210     free (dM   );
    211     free (Xm   );
    212     free (flags);
    213     free (Ncode);
    214     free (Nused);
    215     free (M_20 );
    216     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 );
    217217    catalog->secfilt = secfilt;
    218218    // assert Nsecfilt * Naverage = Nrow?
     
    265265    gfits_create_table_header (&theader, "BINTABLE", "MEASURE_TINY");
    266266
    267     gfits_define_bintable_column (&theader, "E", "RA_OFF",   "ra offset",                  "arcsec", 1.0, 0.0);
    268     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);
    269269    gfits_define_bintable_column (&theader, "E", "MAG_SYS",  "magnitude (sys)",             NULL,    1.0, 0.0);
    270270    gfits_define_bintable_column (&theader, "E", "MAG_CAL",  "magnitude (cal)",             NULL,    1.0, 0.0);
     
    274274    gfits_define_bintable_column (&theader, "E", "Y_CCD",    "ccd y coord",                "pix",    1.0, 0.0);
    275275    gfits_define_bintable_column (&theader, "E", "EXPTIME",  "-2.5 * log (exposure time)", "sec",    1.0, 0.0);
    276     gfits_define_bintable_column (&theader, "J", "TIME",     "time of exp",                "sec",    1.0, 1.0*0x8000);
    277     gfits_define_bintable_column (&theader, "J", "AVE_REF",  "pointer to average table",    NULL,    1.0, 1.0*0x8000);
    278     gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image",                       NULL,    1.0, 1.0*0x8000);
    279     gfits_define_bintable_column (&theader, "J", "DB_FLAGS", "flags",                       NULL,    1.0, 1.0*0x8000);
    280     gfits_define_bintable_column (&theader, "J", "PHOT_FLAGS", "photflags",                 NULL,    1.0, 1.0*0x8000);
    281     gfits_define_bintable_column (&theader, "J", "CAT_ID",   "catalog",                     NULL,    1.0, 1.0*0x8000);
    282     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);
    283283
    284284    // generate the output array that carries the data
     
    286286
    287287    // create intermediate storage arrays
    288     float *dR        ; ALLOCATE (dR       ,  float, catalog->Nmeasure);
    289     float *dD        ; ALLOCATE (dD       ,  float, 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);
     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);
    304304
    305305    // assign the storage arrays
    306306    MeasureTiny *measure = catalog->measure;
    307307    for (i = 0; i < catalog->Nmeasure; i++) {
    308       dR[i]       = measure[i].dR       ;
    309       dD[i]       = measure[i].dD       ;
     308      R[i]        = measure[i].R       ;
     309      D[i]        = measure[i].D       ;
    310310      M[i]        = measure[i].M        ;
    311311      Mcal[i]     = measure[i].Mcal     ;
     
    325325
    326326    // add the columns to the output array
    327     gfits_set_bintable_column (&theader, &ftable, "RA_OFF",     dR,        catalog->Nmeasure);
    328     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);
    329329    gfits_set_bintable_column (&theader, &ftable, "MAG_SYS",    M,         catalog->Nmeasure);
    330330    gfits_set_bintable_column (&theader, &ftable, "MAG_CAL",    Mcal,      catalog->Nmeasure);
     
    342342    gfits_set_bintable_column (&theader, &ftable, "PHOTCODE",   photcode,  catalog->Nmeasure);
    343343
    344     free (dR      );
    345     free (dD      );
     344    free (R       );
     345    free (D       );
    346346    free (M       );
    347347    free (Mcal    );
     
    428428    gfits_create_table_header (&theader, "BINTABLE", "SECFILT");
    429429
    430     gfits_define_bintable_column (&theader, "E", "MAG",      "ra offset",                "arcsec", 1.0, 0.0);
    431     gfits_define_bintable_column (&theader, "E", "MAG_ERR",  "dec offset",               "arcsec", 1.0, 0.0);
    432     gfits_define_bintable_column (&theader, "E", "MAG_CHI",  "magnitude (sys)",           NULL,    1.0, 0.0);
    433     gfits_define_bintable_column (&theader, "J", "FLAGS",    "magnitude (cal)",           NULL,    1.0, 0.0);
    434     gfits_define_bintable_column (&theader, "I", "NCODE",    "magnitude (err)",           NULL,    1.0, 0.0);
    435     gfits_define_bintable_column (&theader, "I", "NUSED",    "airmass",                   NULL,    1.0, 0.0);
    436     gfits_define_bintable_column (&theader, "I", "MAG_20",   "ccd x coord",              "pix",    1.0, 0.0);
    437     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);
    438438
    439439    // generate the output array that carries the data
     
    447447    float *M        ; ALLOCATE (M      ,  float, Nsec);
    448448    float *dM       ; ALLOCATE (dM     ,  float, Nsec);
    449     float *Xm       ; ALLOCATE (Xm    ,  float, Nsec);
     449    float *Mchisq   ; ALLOCATE (Mchisq ,  float, Nsec);
    450450    int   *flags    ; ALLOCATE (flags  ,  int,   Nsec);
    451451    short *Ncode    ; ALLOCATE (Ncode  ,  short, Nsec);
    452452    short *Nused    ; ALLOCATE (Nused  ,  short, Nsec);
    453     short *M_20     ; ALLOCATE (M_20   ,  short, Nsec);
    454     short *M_80     ; ALLOCATE (M_80   ,  short, Nsec);
     453    float *Mmin     ; ALLOCATE (Mmin   ,  float, Nsec);
     454    float *Mmax     ; ALLOCATE (Mmax   ,  float, Nsec);
    455455
    456456    // assign the storage arrays
    457457    SecFilt *secfilt = catalog->secfilt;
    458458    for (i = 0; i < Nsec; i++) {
    459       M     [i]       = secfilt[i]. M      ;
    460       dM    [i]       = secfilt[i]. dM     ;
    461       Xm    [i]       = secfilt[i]. Xm    ;
    462       flags [i]       = secfilt[i]. flags  ;
    463       Ncode [i]       = secfilt[i]. Ncode  ;
    464       Nused [i]       = secfilt[i]. Nused  ;
    465       M_20  [i]       = secfilt[i]. M_20   ;
    466       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   ;
    467467    }
    468468
    469469    // add the columns to the output array
    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",  Xm   , 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_20",   M_20 , Nsec);
    477     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);
    478478
    479479    free (M      );
    480480    free (dM     );
    481     free (Xm    );
     481    free (Mchisq );
    482482    free (flags  );
    483483    free (Ncode  );
    484484    free (Nused  );
    485     free (M_20   );
    486     free (M_80   );
     485    free (Mmin   );
     486    free (Mmax   );
    487487
    488488    gfits_fwrite_Theader (f, &theader);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/GridOps.c

    r34088 r37403  
    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/ps2-tc3-20130727/Ohana/src/relphot/src/ImageMagIO.c

    r36680 r37403  
    6161  GET_COLUMN (dMcal,             "MCAL_ERR",       float);
    6262  GET_COLUMN (dMagSys,           "MCAL_SYSERR",    float);
    63   GET_COLUMN (Xm,                "CHISQ",          float);
    6463  GET_COLUMN (nFitPhotom,        "NFIT",             int);
    6564  GET_COLUMN (flags,             "FLAGS",            int);
    6665  GET_COLUMN (ubercalDist,       "UDIST",            int);
    6766  GET_COLUMN (imageID,           "ID",               int);
     67  GET_COLUMN (Xm,                "CHISQ",          short);
    6868
    6969  // free the memory associated with the FITS files
     
    121121  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_MAGS");
    122122
    123   gfits_define_bintable_column (&theader, "E", "MCAL",           "cal offset", "magnitudes", 1.0, 0.0);
    124   gfits_define_bintable_column (&theader, "E", "MCAL_ERR",       "cal error", "magnitudes", 1.0, 0.0);
    125   gfits_define_bintable_column (&theader, "E", "MCAL_SYSERR",    "systematic error", "magnitudes", 1.0, 0.0);
    126   gfits_define_bintable_column (&theader, "E", "CHISQ",          "cal chisq", "unitless", 1.0, 0.0);
    127   gfits_define_bintable_column (&theader, "J", "NFIT",           "number of fitted stars", "unitless", 1.0, 0.0);
    128   gfits_define_bintable_column (&theader, "J", "FLAGS",          "analysis flags", "unitless", 1.0, 0.0);
    129   gfits_define_bintable_column (&theader, "J", "UDIST",          "distance to ubercal images", "images", 1.0, 0.0);
    130   gfits_define_bintable_column (&theader, "J", "ID",             "image ID", "unitless", 1.0, 0.0);
     123  gfits_define_bintable_column (&theader, "E", "MCAL",           "cal offset",                 "magnitudes", 1.0, 0.0);
     124  gfits_define_bintable_column (&theader, "E", "MCAL_ERR",       "cal error",                  "magnitudes", 1.0, 0.0);
     125  gfits_define_bintable_column (&theader, "E", "MCAL_SYSERR",    "systematic error",           "magnitudes", 1.0, 0.0);
     126  gfits_define_bintable_column (&theader, "J", "NFIT",           "number of fitted stars",     "unitless",  1.0, 0.0);
     127  gfits_define_bintable_column (&theader, "J", "FLAGS",          "analysis flags",             "unitless",  1.0, 0.0);
     128  gfits_define_bintable_column (&theader, "J", "UDIST",          "distance to ubercal images", "images",    1.0, 0.0);
     129  gfits_define_bintable_column (&theader, "J", "ID",             "image ID",                   "unitless",  1.0, 0.0);
     130  gfits_define_bintable_column (&theader, "I", "CHISQ",          "cal chisq",                  "unitless",   1.0, FT_BZERO_INT16);
    131131
    132132  // generate the output array that carries the data
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/ImageOps.c

    r36680 r37403  
    495495}
    496496
     497// returns image.Mcal - ff(x,y)
     498int FindImageSkycellID (off_t meas, int cat, int *myTessID, int *myProjectionID, int *mySkycellID) {
     499
     500  off_t i;
     501
     502  if (!MeasureToImage) return FALSE;
     503
     504  if (meas < 0) return FALSE;
     505
     506  i = MeasureToImage[cat][meas];
     507  if (i == -1) return FALSE;
     508
     509  if (tessID[i]    == -1) return FALSE;
     510  if (projectID[i] == -1) return FALSE;
     511  if (skycellID[i] == -1) return FALSE;
     512
     513  *myTessID = tessID[i];
     514  *myProjectionID = projectID[i];
     515  *mySkycellID =  skycellID[i];
     516 
     517  return TRUE;
     518}
     519
    497520float getMflat (off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog) {
    498521
     
    531554  liststats_setmode (&stats, STATMODE);
    532555
    533   if (FREEZE_IMAGES) return;
     556  // FREEZE_IMAGES only applies to mosaic data (eg, gpc1)
    534557
    535558  fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE);
     
    561584      if (!bad) continue;
    562585    }     
     586
     587    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    563588
    564589    // UBERCAL image: if this is an ubercal image, set minUbercalDist to 0:
     
    608633
    609634      n = catalog[c].measureT[m].averef;
    610       Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
     635      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
    611636      if (isnan(Msys)) {
    612637        Nsys++;
     
    695720  double MaxOffset, MaxScatter, MedOffset;
    696721
    697   if (FREEZE_IMAGES) return;
     722  // if (FREEZE_IMAGES) return;
    698723
    699724  if (VERBOSE) fprintf (stderr, "marking poor images\n");
     
    706731  for (i = N = 0; i < Nimage; i++) {
    707732    if (image[i].flags & IMAGE_BAD) continue;
     733
     734    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
     735
    708736    mlist[N] = image[i].Mcal;
    709737    slist[N] = image[i].dMcal;
     
    797825  Graphdata graphdata;
    798826
    799   if (FREEZE_IMAGES) return;
     827  // if (FREEZE_IMAGES) return;
    800828
    801829  ALLOCATE (xlist, double, Nimage);
     
    810838  float mindMcal    = +100.0;
    811839  float maxdMcal    = -100.0;
    812   for (i = 0; i < Nimage; i++) {
    813     Mlist[i] = image[i].Mcal;
    814     dlist[i] = image[i].dMcal;
    815     xlist[i] = image[i].secz;
     840
     841  int Nplot = 0;
     842
     843  for (i = 0; i < Nimage; i++) {
     844
     845    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
     846
     847    Mlist[Nplot] = image[i].Mcal;
     848    dlist[Nplot] = image[i].dMcal;
     849    xlist[Nplot] = image[i].secz;
    816850    minAirmass = MIN (image[i].secz, minAirmass);
    817851    maxAirmass = MAX (image[i].secz, maxAirmass);
     
    820854    mindMcal = MIN (image[i].dMcal, mindMcal);
    821855    maxdMcal = MAX (image[i].dMcal, maxdMcal);
     856   
     857    Nplot ++;
    822858  }
    823859
     
    852888  for (i = 0; i < NBIN; i++) xlist[i] = 0.00025*i;
    853889  bzero (Mlist, NBIN*sizeof(double));
    854   for (i = 0; i < Nimage; i++) {
     890
     891  for (i = 0; i < Nimage; i++) {
     892    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
     893
    855894    bin = image[i].dMcal / 0.00025;
    856895    bin = MAX (0, MIN (NBIN - 1, bin));
     
    877916  StatType stats;
    878917  bzero (&stats, sizeof (StatType));
    879   if (FREEZE_IMAGES) return (stats);
     918
     919  // we no longer blindly apply FREEZE_IMAGES to all images, only to mosaics
     920  // if (FREEZE_IMAGES) return (stats);
    880921
    881922  ALLOCATE (list, double, Nimage);
     
    885926  for (i = 0; i < Nimage; i++) {
    886927    if (image[i].flags & IMAGE_BAD)  continue;
     928
     929    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    887930
    888931    N = 0;
     
    920963
    921964  bzero (&stats, sizeof (StatType));
    922   if (FREEZE_IMAGES) return (stats);
     965  // if (FREEZE_IMAGES) return (stats);
    923966
    924967  ALLOCATE (list, double, Nimage);
     
    929972
    930973    if (image[i].flags & IMAGE_BAD)  continue;
     974
     975    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    931976
    932977    list[n] = pow (10.0, 0.01*image[i].Xm);
     
    950995
    951996  bzero (&stats, sizeof (StatType));
    952   if (FREEZE_IMAGES) return (stats);
     997  // if (FREEZE_IMAGES) return (stats);
    953998
    954999  ALLOCATE (list, double, Nimage);
     
    9591004
    9601005    if (image[i].flags & IMAGE_BAD)  continue;
     1006
     1007    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    9611008
    9621009    list[n] = image[i].Mcal;
     
    9801027
    9811028  bzero (&stats, sizeof (StatType));
    982   if (FREEZE_IMAGES) return (stats);
     1029  // if (FREEZE_IMAGES) return (stats);
    9831030
    9841031  ALLOCATE (list, double, Nimage);
     
    9891036
    9901037    if (image[i].flags & IMAGE_BAD)  continue;
     1038
     1039    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    9911040
    9921041    list[n] = image[i].dMcal;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/ImageSubset.c

    r36680 r37403  
    126126  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_SUBSET");
    127127
    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 
    131   gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image ID", NULL, 1.0, 1.0*0x8000);
    132   gfits_define_bintable_column (&theader, "J", "PHOTOM_MAP", "map", NULL, 1.0, 1.0*0x8000);
    133   gfits_define_bintable_column (&theader, "J", "FLAGS", "flags", NULL, 1.0, 1.0*0x8000);
    134 
    135   gfits_define_bintable_column (&theader, "J", "TESS_ID", "ID", NULL, 1.0, 0.0);
    136   gfits_define_bintable_column (&theader, "J", "PROJ_ID", "ID", NULL, 1.0, 0.0);
    137   gfits_define_bintable_column (&theader, "J", "SKYCELL_ID", "ID", NULL, 1.0, 0.0);
    138 
    139   gfits_define_bintable_column (&theader, "J", "TZERO", "exposure start", NULL, 1.0, 1.0*0x8000);
    140   gfits_define_bintable_column (&theader, "I", "TRATE", "tti rate", NULL, 1.0, 0.0);
    141 
    142   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);
    143139
    144140  // generate the output array that carries the data
     
    152148
    153149  // create intermediate storage arrays
    154   ALLOCATE (Mcal,      float,        Nimage);
    155   ALLOCATE (dMcal,     float,        Nimage);
     150  ALLOCATE (Mcal,      float,          Nimage);
     151  ALLOCATE (dMcal,     float,          Nimage);
    156152  ALLOCATE (imageID,   unsigned int,   Nimage);
    157153  ALLOCATE (map,       unsigned int,   Nimage);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/MeanMagIO.c

    r36680 r37403  
    6060  GET_COLUMN (M,         "MAG",          float);
    6161  GET_COLUMN (dM,        "MAG_ERR",      float);
    62   GET_COLUMN (Xm,        "MAG_CHISQ",    float);
     62  GET_COLUMN (Mchisq,    "MAG_CHISQ",    float);
    6363  GET_COLUMN (Nsec,      "NSEC",         int);
    6464  GET_COLUMN (objID,     "OBJ_ID",       int);
     
    7373  ALLOCATE (meanmags, MeanMag, Nrow);
    7474  for (i = 0; i < Nrow; i++) {
    75     meanmags[i].M              = M    [i];
    76     meanmags[i].dM             = dM   [i];
    77     meanmags[i].Xm             = Xm  [i];
    78     meanmags[i].Nsec           = Nsec [i];
    79     meanmags[i].objID          = objID[i];
    80     meanmags[i].catID          = catID[i];
     75    meanmags[i].M              = M      [i];
     76    meanmags[i].dM             = dM     [i];
     77    meanmags[i].Mchisq         = Mchisq [i];
     78    meanmags[i].Nsec           = Nsec   [i];
     79    meanmags[i].objID          = objID  [i];
     80    meanmags[i].catID          = catID  [i];
    8181  }
    8282  fprintf (stderr, "loaded data for %lld objects (* filters)\n", (long long) Nrow);
    8383
    84   free (M    );
    85   free (dM   );
    86   free (Xm   );
    87   free (Nsec );
    88   free (objID);
    89   free (catID);
     84  free (M     );
     85  free (dM    );
     86  free (Mchisq);
     87  free (Nsec  );
     88  free (objID );
     89  free (catID );
    9090
    9191  *nmeanmags = Nrow;
     
    118118  gfits_define_bintable_column (&theader, "E", "MAG_ERR",   "mean magnitude error", "magnitudes", 1.0, 0.0);
    119119  gfits_define_bintable_column (&theader, "E", "MAG_CHISQ", "mean magnitude chisq", "unitless", 1.0, 0.0);
    120   gfits_define_bintable_column (&theader, "J", "NSEC",      "secfilt sequence", NULL, 1.0, 1.0*0x8000);
    121   gfits_define_bintable_column (&theader, "J", "OBJ_ID",    "object ID",        NULL, 1.0, 1.0*0x8000);
    122   gfits_define_bintable_column (&theader, "J", "CAT_ID",    "catalog ID",       NULL, 1.0, 1.0*0x8000);
     120  gfits_define_bintable_column (&theader, "J", "NSEC",      "secfilt sequence", NULL, 1.0, FT_BZERO_INT32);
     121  gfits_define_bintable_column (&theader, "J", "OBJ_ID",    "object ID",        NULL, 1.0, FT_BZERO_INT32);
     122  gfits_define_bintable_column (&theader, "J", "CAT_ID",    "catalog ID",       NULL, 1.0, FT_BZERO_INT32);
    123123
    124124  // generate the output array that carries the data
    125125  gfits_create_table (&theader, &ftable);
    126126
    127   float *M, *dM, *Xm;
     127  float *M, *dM, *Mchisq;
    128128  int *Nsec;
    129129  unsigned int *objID, *catID;
     
    132132  ALLOCATE (M,         float,          Nmeanmags);
    133133  ALLOCATE (dM,        float,          Nmeanmags);
    134   ALLOCATE (Xm,        float,          Nmeanmags);
     134  ALLOCATE (Mchisq,    float,          Nmeanmags);
    135135  ALLOCATE (Nsec,      int,            Nmeanmags);
    136136  ALLOCATE (objID,     unsigned int,   Nmeanmags);
     
    139139  // assign the storage arrays
    140140  for (i = 0; i < Nmeanmags; i++) {
    141     M    [i]   = meanmags[i].M    ;
    142     dM   [i]   = meanmags[i].dM   ;
    143     Xm   [i]   = meanmags[i].Xm   ;
    144     Nsec [i]   = meanmags[i].Nsec ;
    145     objID[i]   = meanmags[i].objID;
    146     catID[i]   = meanmags[i].catID;
     141    M     [i]   = meanmags[i].M     ;
     142    dM    [i]   = meanmags[i].dM    ;
     143    Mchisq[i]   = meanmags[i].Mchisq;
     144    Nsec  [i]   = meanmags[i].Nsec ;
     145    objID [i]   = meanmags[i].objID ;
     146    catID [i]   = meanmags[i].catID ;
    147147  }
    148148
     
    150150  gfits_set_bintable_column (&theader, &ftable, "MAG",       M,         Nmeanmags);
    151151  gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",   dM,        Nmeanmags);
    152   gfits_set_bintable_column (&theader, &ftable, "MAG_CHISQ", Xm,        Nmeanmags);
     152  gfits_set_bintable_column (&theader, &ftable, "MAG_CHISQ", Mchisq,    Nmeanmags);
    153153  gfits_set_bintable_column (&theader, &ftable, "NSEC",      Nsec,      Nmeanmags);
    154154  gfits_set_bintable_column (&theader, &ftable, "OBJ_ID",    objID,     Nmeanmags);
    155155  gfits_set_bintable_column (&theader, &ftable, "CAT_ID",    catID,     Nmeanmags);
    156156
    157   free (M    );
    158   free (dM   );
    159   free (Xm   );
    160   free (Nsec );
    161   free (objID);
    162   free (catID);
     157  free (M     );
     158  free (dM    );
     159  free (Mchisq);
     160  free (Nsec  );
     161  free (objID );
     162  free (catID );
    163163
    164164  FILE *f = fopen (filename, "w");
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/MosaicOps.c

    r36680 r37403  
    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;
    320315}
    321316
    322 /* find mosaic frames (unique time periods) (NOTE : we do NOT require matching photcodes but we
    323    match images by MOSAICNAME.  this last point is weak: it forces a single camera at a time.
    324    we can extend the logic to multiple cameras if we make list of MOSAICNAMES (better to assign a camera ID)
     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
    325319 */
    326 void makeMosaics (Image *image, off_t Nimage) {
    327 
    328   off_t i, j, status, found, NMOSAIC, *MosaicN_IMAGE;
     320void makeMosaics (Image *image, off_t Nimage, int mergeMcal) {
     321
     322  off_t i, j, found, NMOSAIC, *MosaicN_IMAGE;
    329323  unsigned int start, stop, *startTimes, *startTimesMosaic;
    330   char *pname;
    331324
    332325  if (!MOSAIC_ZEROPT) return;
     
    341334  // generate a list of all image start times
    342335  ALLOCATE (startTimes, unsigned int, Nimage);
     336  int Nmoschip = 0;
    343337  for (i = 0; i < Nimage; i++) {
    344     startTimes[i] = image[i].tzero;
    345   }
    346   sort_times (startTimes, Nimage);
     338    if (!isGPC1chip(image[i].photcode)) continue;
     339    startTimes[Nmoschip] = image[i].tzero;
     340    Nmoschip ++;
     341  }
     342  sort_times (startTimes, Nmoschip);
    347343  MARKTIME("create array of all image obstimes: %f sec\n", dtime);
    348344 
     
    353349
    354350  // generate a list of the unique start times (these define the mosaics)
    355   for (i = 0; i < Nimage; i++) {
    356     if (startTimes[i] < startTimesMosaic[Nmosaic]) {
    357       fprintf (stderr, "error?\n");
    358       abort();
    359     }
     351  for (i = 0; i < Nmoschip; i++) {
     352    myAssert (startTimes[i] >= startTimesMosaic[Nmosaic], "times out of order?");
    360353    if (startTimes[i] == startTimesMosaic[Nmosaic]) continue;
    361354    Nmosaic ++;
     
    379372  // init the mosaic array values
    380373  for (i = 0; i < Nmosaic; i++) {
    381     mosaic[i].start = startTimesMosaic[i];
    382     mosaic[i].stop  = 0;
    383     mosaic[i].Mcal  = 0.0;
    384     mosaic[i].dMcal = 0.0;
    385     mosaic[i].dMsys = 0.0;
    386     mosaic[i].Xm    = 0.0;
    387     mosaic[i].flags = 0;
    388     mosaic[i].secz  = NAN;
     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;
    389382    mosaic[i].photcode = 0;
    390     mosaic[i].skipCal = FALSE;
     383    mosaic[i].skipCal  = FALSE;
    391384   
    392385    memset (&mosaic[i].coords, 0, sizeof(Coords));
     
    401394
    402395  // assign each image to a mosaic
     396  int Nsimple = 0;
    403397  for (i = 0; i < Nimage; i++) {
    404398    ImageToMosaic[i] = -1;
    405399
    406     /* select valid mosaic images by photcode */
    407     pname = GetPhotcodeNamebyCode (image[i].photcode);
    408     if (!pname) continue;
    409 
    410     status = strncmp (pname, MOSAICNAME, strlen (MOSAICNAME));
    411     if (status) continue;
     400    if (!isGPC1chip(image[i].photcode)) {
     401      Nsimple ++;
     402      continue;
     403    }
    412404
    413405    start = image[i].tzero;
     
    440432      abort();
    441433    }
    442     mosaic[j].stop  = stop;
    443     mosaic[j].Mcal  = 0.0;
    444     mosaic[j].dMcal = 0.0;
    445     mosaic[j].Xm    = 0.0;
    446     mosaic[j].dMsys = image[i].flags;
    447     mosaic[j].flags = image[i].flags;
    448     mosaic[j].secz  = image[i].secz;
     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;
    449441    mosaic[j].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode);
    450442  }
     
    456448  free (startTimesMosaic);
    457449
     450  if (mergeMcal) {
     451    initMosaicGrid (image, Nimage);
     452  }
     453
    458454  fprintf (stderr, "matched %d images to %d mosaics\n", (int) Nimage, (int) Nmosaic);
    459 
    460455  return;
    461456}
     
    513508  off_t i, j, m, NX, NY, NC, Nc;
    514509  double R, D, Rmid, Dmid;
    515   double Mcal, dMcal, Xm;
    516510  double *Rc, *Dc;
    517511
     
    523517    Nc = 0;
    524518    Rmid = Dmid = NAN;
    525     Mcal = dMcal = Xm = 0;
    526519    for (j = 0; j < MosaicN_Image[i]; j++) {
    527520      m = MosaicToImage[i][j];
     
    563556        REALLOCATE (Dc, double, NC);
    564557      }
    565 
    566       Mcal  += image[m].Mcal;
    567       dMcal += image[m].dMcal;
    568       Xm    += image[m].Xm;
    569 
    570       // for ubercal images, we (elsewhere) keep Mcal frozen
    571 
    572       /* we are using mosaic.Mcal, not image.Mcal. reset image.Mcal */
    573       image[m].Mcal  = 0.0;
    574       image[m].dMcal = NAN;
    575       image[m].Xm    = NAN_S_SHORT;
    576558    }
    577559
     
    617599    mosaic[i].coords.pc2_1  = 0.0;
    618600
    619     mosaic[i].Mcal  = Mcal / MosaicN_Image[i];
    620     mosaic[i].dMcal = dMcal / MosaicN_Image[i];
    621     mosaic[i].Xm    = Xm / MosaicN_Image[i];
     601    mosaic[i].Mcal   = 0.0;
     602    mosaic[i].dMcal  = 0.0;
     603    mosaic[i].Xm     = 0.0;
    622604  }
    623605  return;
     
    635617  double R, D, Rmin, Rmax, Dmin, Dmax;
    636618  double Mcal, dMcal, Xm;
     619
     620  fprintf (stderr, "*** moving Mcal from image.Mcal to mosaic.Mcal ***\n");
    637621
    638622  dXmax = dYmax = 0.0;
     
    667651      Dmin = MIN (Dmin, D);
    668652      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
    669661      Mcal  += image[m].Mcal;
    670662      dMcal += image[m].dMcal;
    671663      Xm    += image[m].Xm;
    672664
    673       // XXX: how does this work with UBERCAL?  We want to keep the Mcal values supplied by ubercal, but
    674       // solve for a single offset for each exposure (Mosaic.Mcal). 
    675 
    676       // we also want to keep the flat-field terms for each exposure (regardless of ubercal or not)
    677 
    678       // if it helps, note that ubercal uses a single zp per exposure, so the mean of those values is the same as the value
    679 
    680       /* we are using mosaic.Mcal, not image.Mcal. reset image.Mcal */
    681       image[m].Mcal  = 0.0;
    682       image[m].dMcal = NAN;
    683       image[m].Xm    = NAN_S_SHORT;
     665      image[m].Mcal   = 0.0;
     666      image[m].dMcal  = NAN;
     667      image[m].Xm     = NAN_S_SHORT;
    684668    }
    685669    dS /= MosaicN_Image[i];
     
    697681    RD_to_XY (&dX, &dY, Rmax, Dmax, &mosaic[i].coords);
    698682
    699     mosaic[i].Mcal  = Mcal / MosaicN_Image[i];
    700     mosaic[i].dMcal = dMcal / MosaicN_Image[i];
    701     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];
    702686  }
    703687  if (!USE_GRID) return;
     
    709693}
    710694
    711 // XXX : what about mosaics with skipCal == TRUE?
    712695void setMcalFinal () {
    713696
     
    719702  image = getimages (&Nimage, NULL);
    720703
    721   // XXX I think this is OK in the ubercal context, but probably need to skip UBERCAL
    722   // images? (no need to update them)
     704  fprintf (stderr, "*** return Mcal from mosaic.Mcal to image.Mcal ***\n");
    723705
    724706  // copy the mosaic results to the images.  set the mosaic Mcal to 0.0 since we have moved its
     
    840822  mosID = ImageToMosaic[idx];
    841823  if (mosID < 0) {
    842     Image *image = getimage(idx);
    843     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)
    844827    return;
    845828  }
     
    882865  if (!MOSAIC_ZEROPT) return (0);
    883866
     867  // unassigned measurements belong to simple chips
    884868  i = MeasureToMosaic[cat][meas];
    885   if (i == -1) return (NAN);
     869  if (i == -1) return (0.0);
    886870
    887871  if (mosaic[i].flags & IMAGE_BAD) return (NAN); 
     
    11271111
    11281112      off_t n = catalog[c].measureT[m].averef;
    1129       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);
    11301114
    11311115      float delta = Msys - Mrel - Mcal - Mgrid + Mflat;
     
    11641148
    11651149    off_t n = catalog[c].measureT[m].averef;
    1166     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);
    11671151    if (isnan(Msys)) {
    11681152      info->Nsys++;
     
    12391223
    12401224  if (testImage) {
    1241     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));
    12421226  }
    12431227
     
    15921576    if (mosaic[i].flags & IMAGE_BAD) continue;
    15931577    if (mosaic[i].skipCal) continue;
     1578    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
     1579
    15941580    list[n] = mosaic[i].Mcal;
    15951581    dlist[n] = 1;
     
    16221608    if (mosaic[i].flags & IMAGE_BAD) continue;
    16231609    if (mosaic[i].skipCal) continue;
     1610    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
     1611
    16241612    list[n] = mosaic[i].dMcal;
    16251613    dlist[n] = 1;
     
    16531641    if (mosaic[i].flags & IMAGE_BAD)  continue;
    16541642    if (mosaic[i].skipCal) continue;
     1643    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
    16551644
    16561645    N = 0;
     
    16991688    if (mosaic[i].flags & IMAGE_BAD) continue;
    17001689    if (mosaic[i].skipCal) continue;
    1701     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);
    17021693    dlist[n] = 1;
    17031694    n++;
     
    17821773void plot_mosaic_fields (Catalog *catalog) {
    17831774
    1784   off_t i, j, m, c, N, ave, Nimage;
     1775  off_t i, j, m, c, N, Nimage;
    17851776  double *xlist, *ylist;
    1786   // double Xmin, Xmax, Ymin, Ymax;
    17871777  char string[64];
    17881778  Graphdata graphdata;
     
    18031793  for (i = 0; i < Nmosaic; i++) {
    18041794    N = 0;
    1805     // Xmin = Ymin = +360.0;
    1806     // Xmax = Ymax = -360.0;
    18071795    for (j = 0; j < N_onMosaic[i]; j++) {
    18081796     
     
    18121800      if (catalog[c].measureT[m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;
    18131801
    1814       ave = catalog[c].measureT[m].averef;
    1815       xlist[N] = catalog[c].averageT[ave].R - catalog[c].measureT[m].dR / 3600.0;
    1816       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;
    18171805      N++;
    18181806    }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/Shutdown.c

    r33651 r37403  
    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/ps2-tc3-20130727/Ohana/src/relphot/src/StarOps.c

    r36680 r37403  
    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
     
    407410
    408411      /* star/photcodes already calibrated */
    409       if ( isSetMrelFinal && catalog[Nc].found[Nsecfilt*j+Nsec]) continue; 
     412      if ( isSetMrelFinal && catalog[Nc].found_t[Nsecfilt*j+Nsec]) continue; 
    410413     
    411414      // skip bad stars
     
    467470
    468471        // skip some absurd values NAN, < 0.0, > 30.0
    469         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);
    470473        if (isnan(Msys)) SKIP_THIS_MEAS(Nsys);
    471474        if (Msys <  0.0) SKIP_THIS_MEAS(Nsys);
     
    670673      liststats (list, dlist, wlist, N, &stats);
    671674
    672       catalog[Nc].secfilt[Nsecfilt*j+Nsec].M  = stats.mean;
    673       catalog[Nc].secfilt[Nsecfilt*j+Nsec].dM = stats.error;
    674       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;
    675678
    676679      // when running -averages, we have no information about the images, so we cannot set this
     
    680683
    681684      if (isSetMrelFinal) {
    682         catalog[Nc].found[Nsecfilt*j+Nsec] = TRUE;
     685        catalog[Nc].found_t[Nsecfilt*j+Nsec] = TRUE;
    683686
    684687        catalog[Nc].secfilt[Nsecfilt*j+Nsec].Mstdev = 1000.0*stats.sigma; // Mstdev is in millimags (not enough space for more precision)
     
    950953
    951954  int i, j, Ndel, Nave, Ntot, mark, Ns, Nscat, Nchi, Nnan;
    952   float dM, Xm;
    953   double Chisq, MaxScatter, MaxChisq;
     955  float dM;
     956  double MaxScatter, MaxChisq;
    954957  double *xlist, *slist, *dlist;
    955958
     
    978981      for (j = 0; j < catalog[i].Naverage; j++) {
    979982        if ( catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD ) continue;
    980         Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
    981         if (Xm == -1) continue;
    982         Chisq = pow (10.0, 0.01*Xm);
    983         xlist[Ntot] = Chisq;
     983        float Mchisq = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq;
     984        if (isnan(Mchisq)) continue;
     985        xlist[Ntot] = Mchisq;
    984986        slist[Ntot] = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
    985987        dlist[Ntot] = 1;
     
    9991001      for (j = 0; j < catalog[i].Naverage; j++) {
    10001002        dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
    1001         Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
    1002         Chisq = pow (10.0, 0.01*Xm);
    1003         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);
    10041005        if (mark) {
    10051006          catalog[i].secfilt[Nsecfilt*j+Nsec].flags |= ID_STAR_POOR;
    10061007          Ndel ++;
    1007           if (dM > MaxScatter) { Nscat ++; }
    1008           if (Xm == NAN_S_SHORT) { Nnan ++; }
    1009           if (Chisq > MaxChisq) { Nchi ++; }
     1008          if (dM > MaxScatter)   { Nscat ++; }
     1009          if (isnan(Mchisq))    { Nnan ++; }
     1010          if (Mchisq > MaxChisq) { Nchi ++; }
    10101011        } else {
    10111012          catalog[i].secfilt[Nsecfilt*j+Nsec].flags &= ~ID_STAR_POOR;
     
    10721073       
    10731074        /* on final processing, skip stars already measured */
    1074         if (final && catalog[i].found[Nsecfilt*j + Nsec]) continue; 
     1075        if (final && catalog[i].found_t[Nsecfilt*j + Nsec]) continue; 
    10751076
    10761077        /* skip bad stars to prevent them from becoming good (on inner sample) */
     
    10851086          if (ecode != thisCode) { continue; }
    10861087
     1088          // SKIP gpc1 stack data
     1089          if (isGPC1stack(catalog[i].measureT[m].photcode)) continue;
     1090         
     1091          // SKIP gpc1 forced-warp data
     1092          if (isGPC1warp(catalog[i].measureT[m].photcode)) continue;
     1093         
    10871094          // NOTE: we do not skip MEAS_BAD because this measurement is just an internal assessment of the outliers
    10881095          Mcal  = getMcal  (m, i, flatcorr, catalog);
     
    10931100          if (isnan(Mgrid)) { Ngrid ++; continue; }
    10941101
    1095           Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]);
     1102          Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF);
    10961103          list[N] = Msys - Mcal - Mmos - Mgrid;
    10971104          dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);
     
    11301137          if (ecode != thisCode) { continue; }
    11311138
     1139          // SKIP gpc1 stack data
     1140          if (isGPC1stack(catalog[i].measureT[m].photcode)) continue;
     1141         
     1142          // SKIP gpc1 forced-warp data
     1143          if (isGPC1warp(catalog[i].measureT[m].photcode)) continue;
     1144         
    11321145          // NOTE: we do not skip MEAS_BAD because this measurement is just an internal assessment of the outliers
    11331146          Mcal  = getMcal  (m, i, flatcorr, catalog);
     
    11381151          if (isnan(Mgrid)) continue;
    11391152
    1140           Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]);
     1153          Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt], MAG_CLASS_PSF);
    11411154          list[N] = Msys - Mcal - Mmos - Mgrid;
    11421155          dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);
     
    12331246
    12341247  off_t j, Ntot;
    1235   int i, n, Xm;
     1248  int i, n;
    12361249  double *list, *dlist;
    12371250  StatType stats;
     
    12541267      if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 
    12551268       
    1256       Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
    1257       if (Xm == NAN_S_SHORT) continue;
    1258       list[n] = pow (10.0, 0.01*Xm);
     1269      float Mchisq = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq;
     1270      if (isnan(Mchisq)) continue;
     1271      list[n] = Mchisq;
    12591272      dlist[n] = 1;
    12601273      n++;
     
    13771390        if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue;
    13781391        xlist[N] = catalog[i].secfilt[Nsecfilt*j+Nsec].M;
    1379         value    = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
    1380         if (value == NAN_S_SHORT) continue;
    1381         ylist[N] = 0.01*value;
     1392        value    = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq;
     1393        if (isnan(value)) continue;
     1394        ylist[N] = value;
    13821395        N++;
    13831396      }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/args.c

    r36680 r37403  
    227227  }
    228228
    229   SHOW_PARAMS = FALSE;
     229  SHOW_PARAMS = TRUE;
    230230  if ((N = get_argument (argc, argv, "-params"))) {
    231231    remove_argument (N, &argc, argv);
    232     SHOW_PARAMS = TRUE;
     232    SHOW_PARAMS = FALSE;
    233233  }
    234234
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/assign_images.c

    r36680 r37403  
    2525
    2626  if (MOSAIC_ZEROPT) {
    27     makeMosaics (image, Nimage);
    28 
    29     // center coords and Mcal, dMcal, Xm for the mosaics
     27    makeMosaics (image, Nimage, FALSE);
     28
     29    // center coords and Mcal, dMcal, Mchisq for the mosaics
    3030    setMosaicCenters (image, Nimage);
    3131    MARKTIME("set mosaic coordinates and Mcal values: %f sec\n", dtime);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/bcatalog.c

    r35416 r37403  
    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/ps2-tc3-20130727/Ohana/src/relphot/src/initialize.c

    r36680 r37403  
    3636
    3737  if (SHOW_PARAMS) {
    38     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    }
    3948    if (TimeSelect) {
    4049      fprintf (stderr, "TimeSelect: TRUE (%s - %s)\n", ohana_sec_to_date (TSTART), ohana_sec_to_date (TSTOP));
     
    4251      fprintf (stderr, "TimeSelect: FALSE\n");
    4352    }
     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
    4467    fprintf (stderr, "VERBOSE: %d, PLOTSTUFF: %d\n", VERBOSE, PLOTSTUFF);
    4568    fprintf (stderr, "GRID_X: %d, GRID_Y: %d, BINNING: %d == Nmx: %d, Nmy: %d\n",
     
    4972             (int)(RELPHOT_GRID_X/RELPHOT_GRID_BINNING), (int)(RELPHOT_GRID_Y/RELPHOT_GRID_BINNING));
    5073
    51     fprintf (stderr, "MAG_LIM                %lf\n", MAG_LIM);
    5274    fprintf (stderr, "STAR_SCATTER           %lf\n", STAR_SCATTER);
    5375    fprintf (stderr, "IMAGE_SCATTER          %lf\n", IMAGE_SCATTER);
     
    5678    fprintf (stderr, "GSCFILE                %s\n",  GSCFILE);
    5779    fprintf (stderr, "CATDIR                 %s\n",  CATDIR);
    58     exit (0);
    5980  }
    6081
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/launch_region_hosts.c

    r36680 r37403  
    2222  for (i = 0; i < regionHosts->Nhosts; i++) {
    2323    char *syncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanmags.sync");
    24     truncate (syncfile, 0);
     24    if (truncate (syncfile, 0)) fprintf (stderr, "trouble clearing syncfile %s\n", syncfile);
    2525    free (syncfile);
    2626
    2727    char *fitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanmags.fits");
    28     truncate (fitsfile, 0);
     28    if (truncate (fitsfile, 0)) fprintf (stderr, "trouble clearing fitsfile %s\n", fitsfile );
    2929    free (fitsfile);
    3030
    3131    char *imsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagemags.sync");
    32     truncate (imsyncfile, 0);
     32    if (truncate (imsyncfile, 0)) fprintf (stderr, "trouble clearing imsyncfile %s\n", imsyncfile);
    3333    free (imsyncfile);
    3434
    3535    char *imfitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagemags.fits");
    36     truncate (imfitsfile, 0);
     36    if (truncate (imfitsfile, 0)) fprintf (stderr, "trouble clearing imfitsfile %s\n", imfitsfile);
    3737    free (imfitsfile);
    3838
    3939    char *loopsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "loop.sync");
    40     truncate (loopsyncfile, 0);
     40    if (truncate (loopsyncfile, 0)) fprintf (stderr, "trouble clearing loopsyncfile %s\n", loopsyncfile);
    4141    free (loopsyncfile);
    4242  }
     
    5555
    5656    char command[1024];
    57     snprintf (command, 1024, "relphot %s -parallel-images %s -region-hosts %s -region-hostID %d -D CATDIR %s -region %f %f %f %f -statmode %s -D CAMERA %s -D STAR_TOOFEW %d -minerror %f",
    58               PhotcodeList, filename, REGION_FILE, host->hostID, CATDIR, host->RminCat, host->RmaxCat, host->DminCat, host->DmaxCat, STATMODE, CAMERA, STAR_TOOFEW, MIN_ERROR);
     57    snprintf (command, 1024, "relphot %s", PhotcodeList);
     58    strextend (command, "-parallel-images %s", filename);
     59    strextend (command, "-region-hosts %s", REGION_FILE);
     60    strextend (command, "-region-hostID %d", host->hostID);
     61    strextend (command, "-D CATDIR %s", CATDIR);
     62    strextend (command, "-region %f %f %f %f", host->RminCat, host->RmaxCat, host->DminCat, host->DmaxCat);
     63    strextend (command, "-statmode %s", STATMODE);
     64    strextend (command, "-D CAMERA %s", CAMERA);
     65    strextend (command, "-D STAR_TOOFEW %d", STAR_TOOFEW);
     66    strextend (command, "-minerror %f", MIN_ERROR);
     67    strextend (command, "-cloud-limit %f", CLOUD_TOLERANCE);
    5968
    6069    if (VERBOSE)             strextend (command, "-v");
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/load_catalogs.c

    r36680 r37403  
    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  }
     
    9292  // in regular relphot, we shutdown here; in relphot_client, we generate and return an empty table (for consistency)
    9393
     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  }
     99
    94100  // XXX consider only returning the populated catalogs
    95101  *Ncatalog = skylist[0].Nregions;
     
    105111// CATDIR is supplied globally
    106112# define DEBUG 1
    107 Catalog *load_catalogs_parallel (SkyList *sky, int *Ncatalog) {
     113Catalog *load_catalogs_parallel (SkyList *sky, int *Ncatalog, char *syncfile) {
    108114
    109115  char uniquer[12];
     
    206212  }
    207213
     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
    208227  // each host generates a BrightCatalog structure, with the measure, average, etc value
    209228  // loaded into a single set of arrays (of MeasureTiny, AverageTiny, Secfilt).  I need to
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/plot_scatter.c

    r35759 r37403  
    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/ps2-tc3-20130727/Ohana/src/relphot/src/relphot_client.c

    r36680 r37403  
    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/ps2-tc3-20130727/Ohana/src/relphot/src/relphot_images.c

    r36680 r37403  
    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 
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/relphot_parallel_images.c

    r36680 r37403  
    3838  // unlink (IMAGE_TABLE); // XXX a bit risky, add some protection?
    3939
    40   // XXX need to deal with mosaic vs image...
    41   makeMosaics (image, Nimage);
     40  makeMosaics (image, Nimage, TRUE);
    4241
    4342  initImages (image, NULL, Nimage);
     
    5655
    5756  /* load catalog data from region files (hostID is 0 since we are not a client */
    58   catalog = load_catalogs (skylist, &Ncatalog, 0, NULL);
     57  char *syncfile = make_filename (CATDIR, regionHosts->hosts[myHost].hostname, REGION_HOST_ID, "loadcat.sync");
     58  catalog = load_catalogs (skylist, &Ncatalog, 0, NULL, syncfile);
    5959  MARKTIME("-- load catalog data: %f sec\n", dtime);
     60  free (syncfile);
     61
    6062  client_logger_message ("loaded catalog data\n");
    6163
    62   // NOTE: if I let all hosts load blindly, I saturate the data clients with too many
    63   // relphot_client requests.  I need to have the master mediate this.  the master
    64   // will not launch the next remote job until this one says it is done
    65   char *syncfile = make_filename (CATDIR, regionHosts->hosts[myHost].hostname, REGION_HOST_ID, "loadcat.sync");
    66   update_sync_file (syncfile, 1);
    67  
    6864  // generate tables go from catID,objID -> catSeq,objSeq
    6965  indexCatalogs (catalog, Ncatalog);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/relphot_parallel_regions.c

    r36680 r37403  
    11# include "relphot.h"
     2int save_images_backup (FITS_DB *db);
    23
    34int relphot_parallel_regions () {
     
    6364  SkyList *skylist = SkyListByBounds (sky, -1, regionHosts->Rmin, regionHosts->Rmax, regionHosts->Dmin, regionHosts->Dmax);
    6465
     66  // I have to save a copy because dvo_image_save and _unlock swap and free the data
     67  save_images_backup (&db);
     68
    6569  /* update catalogs (in parallel) */
    6670  reload_catalogs (skylist, flatcorr, 0, NULL);
     
    7478}
    7579
     80int save_images_backup (FITS_DB *db) {
     81
     82  FITS_DB dbX;
     83  char filename[1024];
     84
     85  INITTIME;
     86
     87  gfits_db_init (&dbX);
     88  dbX.lockstate = LCK_XCLD;
     89  dbX.timeout   = 60.0;
     90  dbX.mode      = db->mode;
     91  dbX.format    = db->format;
     92
     93  snprintf (filename, 1024, "%s.bck", ImageCat);
     94  if (!gfits_db_lock (&dbX, filename)) {
     95    fprintf (stderr, "can't lock backup image image catalog\n");
     96    return (FALSE);
     97  }
     98   
     99  // copy Images.dat data (all or only the subset / vtable elements?)  I think I need to dump
     100  // the entire Image table, but with the updates in place I think this says: re-work the
     101  // ftable/vtable usage in this program to be more sensible...
     102  gfits_copy_header (&db->header,  &dbX.header);
     103  gfits_copy_matrix (&db->matrix,  &dbX.matrix);
     104  gfits_copy_header (&db->theader, &dbX.theader);
     105  gfits_copy_ftable (&db->ftable,  &dbX.ftable);
     106
     107  dbX.ftable.header = &dbX.theader;
     108
     109  dvo_image_save (&dbX, VERBOSE);
     110  dvo_image_unlock (&dbX);
     111  MARKTIME("-- save Image.dat.bck: %f sec\n", dtime);
     112
     113  return TRUE;
     114}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/setExclusions.c

    r33651 r37403  
    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/ps2-tc3-20130727/Ohana/src/relphot/src/setMrelCatalog.c

    r36680 r37403  
    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
     
    2935  return (TRUE);
    3036}
     37
     38int setMrelAverageForcedWarp (off_t measureOffset, int cat, int pass, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t *found);
    3139
    3240int setMrel_catalog_alt (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt) {
     
    4250  int isSetMrelFinal = (pass >= 0);
    4351
    44   char *primaryCell = NULL;
    45   if (isSetMrelFinal) {
    46     ALLOCATE (primaryCell, char, DVO_MAX_PATH);
    47   }
     52  // XX char *primaryCell = NULL;
     53  // XX if (isSetMrelFinal) {
     54  // XX   ALLOCATE (primaryCell, char, DVO_MAX_PATH);
     55  // XX }
    4856
    4957  for (j = 0; j < catalog[Nc].Naverage; j++) {
     
    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
    5765    if (isSetMrelFinal && (pass == 0)) {
    58       setMrelAverageStack (m, Nc, flatcorr, results, &catalog[Nc].average[j], &catalog[Nc].secfilt[j*Nsecfilt], &catalog[Nc].measure[m], primaryCell);
     66      setMrelAverageStack (m, Nc, flatcorr, results, &catalog[Nc].average[j], &catalog[Nc].secfilt[j*Nsecfilt], &catalog[Nc].measure[m]);
    5967      setGlobalObjStats (&catalog[Nc].average[j], &catalog[Nc].measure[m]);
    6068    }
    61   }
    62   if (primaryCell) free (primaryCell);
     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    }
     75  }
     76  // if (primaryCell) free (primaryCell);
    6377  return (TRUE);
    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
     
    132147    off_t meas = measureOffset;
    133148
     149    float psfQfMax = 0.0;
     150    float psfQfPerfMax = 0.0;
     151
    134152    int Nap = 0;
    135153    int Npsf = 0;
     
    144162
    145163      // are we a PS1 exposure photcode?
    146       if ((measureT[k].photcode >= 10000) && (measureT[k].photcode <= 10500)) {
    147         NexpPS1 ++;
     164      if (isGPC1chip(measureT[k].photcode)) NexpPS1 ++;
     165
     166      // SKIP gpc1 stack data
     167      if (isGPC1stack(measureT[k].photcode)) continue;
     168
     169      // SKIP gpc1 forced-warp data
     170      if (isGPC1warp(measureT[k].photcode)) continue;
     171
     172      if (isSetMrelFinal) {
     173        if (measure[k].psfQF     > psfQfMax)     psfQfMax     = measure[k].psfQF;
     174        if (measure[k].psfQFperf > psfQfPerfMax) psfQfPerfMax = measure[k].psfQFperf;
    148175      }
    149176
     
    166193
    167194      // skip some absurd values NAN, < 0.0, > 30.0
    168       Msys = PhotSysTiny (&measureT[k], &averageT[0], &secfilt[0]);
     195      Msys = PhotSysTiny (&measureT[k], &averageT[0], &secfilt[0], MAG_CLASS_PSF);
    169196      if (isnan(Msys)) SKIP_THIS_MEAS(Nsys);
    170197      if (Msys <  0.0) SKIP_THIS_MEAS(Nsys);
     
    197224          }
    198225          havePS1 = TRUE;
    199         }
    200 
    201         // gpc1 stack data
    202         if ((measure[k].photcode >= 11000) && (measure[k].photcode <= 11400)) {
    203           continue;
    204226        }
    205227
     
    255277
    256278        // Map (Maplist) and Mkron (Mkronlist,dkronlist) are used to calculate mean mags per filter
    257         float Map = PhotAperCat (&measure[k]);
     279        float Map = PhotCat (&measure[k], MAG_CLASS_APER);
    258280        if (!isnan(Map)) {
    259281            Maplist[Nap] = Map - Mcal - Mmos - Mgrid;
    260             daplist[Nap] = dMpsf;
    261             waplist[Nap] = isUbercal ? 10.0 : 1.0;
     282            daplist[Nap] = dMpsf;// XXX check on this...
     283            waplist[Nap] = isUbercal ? UBERCAL_WEIGHT : 1.0;
    262284            Nap ++;
    263285        }
    264286
    265         float Mkron = PhotKronCat (&measure[k]);
     287        float Mkron = PhotCat (&measure[k], MAG_CLASS_KRON);
    266288        if (!isnan(Mkron)) {
    267289          Mkronlist[Nkron] = Mkron - Mcal - Mmos - Mgrid;
    268290          dkronlist[Nkron] = measure[k].dMkron;
    269           wkronlist[Nkron] = isUbercal ? 10.0 : 1.0;
     291          wkronlist[Nkron] = isUbercal ? UBERCAL_WEIGHT : 1.0;
    270292          Nkron ++;
    271293        }
     
    280302      Mpsflist[Npsf] = Msys - Mcal - Mmos - Mgrid;
    281303      dpsflist[Npsf] = dMpsf;
    282       wpsflist[Npsf] = isUbercal ? 10.0 : 1.0;
     304      wpsflist[Npsf] = isUbercal ? UBERCAL_WEIGHT : 1.0;
    283305
    284306      // NOTE:
     
    293315      if (refPhotcode) {
    294316        if (code->code == refPhotcode->code) {
    295           wpsflist[Npsf] = 100.0;
     317          wpsflist[Npsf] = UBERCAL_WEIGHT;
    296318        }
    297319      }
     
    304326    if (isSetMrelFinal && (pass == 0)) {
    305327      if ((thisCode < 6) || (thisCode == 9)) {
    306         secfilt[Nsec].Ncode = NexpPS1;
     328        secfilt[Nsec].Ncode = NexpPS1; 
    307329      } else {
    308330        secfilt[Nsec].Ncode = Ncode; // 2MASS data if it exists
     
    334356    liststats (Mpsflist, dpsflist, wpsflist, Npsf, psfstats);
    335357
    336     secfilt[Nsec].M  = psfstats->mean;
    337     secfilt[Nsec].dM = psfstats->error;
    338     secfilt[Nsec].Xm = (psfstats->Nmeas > 1) ? 100.0*log10(psfstats->chisq + 1e-4) : NAN_S_SHORT;
     358    secfilt[Nsec].M      = psfstats->mean;
     359    secfilt[Nsec].dM     = psfstats->error;
     360    secfilt[Nsec].Mchisq = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN;
    339361
    340362    // when running -averages, we have no information about the images, so we cannot set this
     
    346368      found[Nsec] = TRUE;
    347369
    348       secfilt[Nsec].Mstdev = 1000.0*psfstats->sigma; // Mstdev is in millimags (not enough space for more precision)
     370      secfilt[Nsec].Mstdev = psfstats->sigma; // Mstdev is in millimags (not enough space for more precision)
    349371      // secfilt[Nsec].Ncode = Ncode;
    350372      secfilt[Nsec].Nused = psfstats->Nmeas;
    351373
    352       secfilt[Nsec].M_80 = 1000 * psfstats->Upper80;
    353       secfilt[Nsec].M_20 = 1000 * psfstats->Lower20;
     374      secfilt[Nsec].Mmax = psfstats->max;
     375      secfilt[Nsec].Mmin = psfstats->min;
     376
     377      secfilt[Nsec].psfQfMax     = psfQfMax;
     378      secfilt[Nsec].psfQfPerfMax = psfQfPerfMax;
    354379
    355380      // NOTE : use the modified weight for apmags as well as psf mags
    356381      liststats (Maplist, daplist, waplist, Nap, apstats);
    357382      secfilt[Nsec].Map  = Nap > 0 ? apstats->mean : NAN;
     383      secfilt[Nsec].dMap  = Nap > 0 ? apstats->error : NAN;
     384      secfilt[Nsec].sMap  = Nap > 0 ? apstats->sigma : NAN;
     385      secfilt[Nsec].NusedAp  = Nap;
    358386
    359387      liststats (Mkronlist, dkronlist, wkronlist, Nkron, kronstats);
    360388      secfilt[Nsec].Mkron  = Nkron > 0 ? kronstats->mean  : NAN;
    361389      secfilt[Nsec].dMkron = Nkron > 0 ? kronstats->error : NAN;
     390      secfilt[Nsec].sMkron = Nkron > 0 ? kronstats->sigma : NAN;
     391      secfilt[Nsec].NusedKron  = Nkron;
    362392
    363393      // NOTE: for 2MASS measurements, Next should be 1, as should N
     
    422452
    423453// only apply Stack operation on setMrelFinal in first pass
    424 int setMrelAverageStack (off_t measureOffset, int cat, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, char *primaryCell) {
    425 
    426   off_t k, ID;
    427 
    428   float Msys = 0, Mcal= 0, Mmos = 0, Mgrid = 0;
     454// this function has 3 goals, not to be confused:
     455// 1) find and mark the PRIMARY detections (regardless of the quality of the detection)
     456// 2) select the BEST detections per filter (regardless of PRIMARY)
     457// 3) apply the zero point and AB->Jy transformations
     458int setMrelAverageStack (off_t measureOffset, int cat, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure) {
     459
     460  off_t k;
     461
     462  float Mcal= 0, Mmos = 0, Mgrid = 0, Finst = 0;
    429463
    430464  // set the primary projection cell and skycell for this coordinate
     
    434468  get_tess_ids(&tessID, &projectID, &skycellID, average[0].R, average[0].D);
    435469
     470  average[0].tessID       = tessID;
     471  average[0].projectionID = projectID;
     472  average[0].skycellID    = skycellID;
     473
    436474  int NstackGood = 0;
    437475  int NstackSuspect = 0;
     
    448486    int haveStack = FALSE;
    449487
    450     // need to find the measurement closest to the center of its skycell, as well as the
    451     // closest for the subset of primary projection cells
    452 
    453     float stackCenterOffsetMin = 1e9;
    454     off_t stackCenterMeasureMin = -1;
    455 
    456     float stackPrimaryOffsetMin = 1e9;
    457     off_t stackPrimaryMeasureMin = -1;
     488    float psfQFbest = 0.0;
     489
     490    off_t stackBestMeasure = -1;
     491    off_t stackPrimaryMeasure = -1;
    458492
    459493    int isBad = FALSE;
    460494    int isSuspect = FALSE;
    461495
     496    int Nstack = 0; // number for this photcode
     497    int NstackDet = 0; // number for this photcode
     498
    462499    off_t meas = measureOffset;
    463500    for (k = 0; k < average[0].Nmeasure; k++, meas++) {
     501
     502      // only examine gpc1 stack data
     503      if (!isGPC1stack(measure[k].photcode)) continue;
    464504
    465505      // skip measurements that do not match the current photcode
     
    468508      if (code->equiv != thisCode) { continue; }
    469509
     510      Nstack ++;
     511      if ((measure[k].photFlags2 & 0x00000004) == 0) NstackDet ++;
     512
    470513      // clear this bit for all measurements
    471514      measure[k].dbFlags &= ~ID_MEAS_STACK_PRIMARY;
    472 
    473       // only examine gpc1 stack data
    474       // XXX this is absurdly hardwired (along with several photcode tests)
    475       if (measure[k].photcode < 11000) continue;
    476       if (measure[k].photcode > 11400) continue;
     515      measure[k].dbFlags &= ~ID_MEAS_STACK_PHOT_SRC;
    477516
    478517      haveStack = TRUE;
    479518      haveStackObject = TRUE;
    480519     
     520      // match measurement to its image (this is just a check, right?)
     521      if (getImageEntry (meas, cat) < 0) {
     522        fprintf (stderr, "*** warning : this should be impossible\n");
     523        abort();
     524        continue;
     525      }
     526
     527      // find the PRIMARY measurement
     528
     529      // if we request the primary (USE_TREE_FOR_PRIMARY), this is true if the measurement is from the
     530      // primary skycell for this position
     531      if (MatchImageSkycellID (meas, cat, tessID, projectID, skycellID)) {
     532        stackPrimaryMeasure = k;
     533        measure[k].dbFlags |= ID_MEAS_STACK_PRIMARY;
     534        secfilt[Nsec].stackPrmryOff = meas;
     535      }
     536
     537      // now choose the BEST measurements (may also be PRIMARY)
     538
    481539      if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS_STACK(Nbad);
    482540
    483       if (getImageEntry (meas, cat) < 0) continue;
    484541      // measurements without an image are either external reference photometry or
    485542      // data for which the associated image has not been loaded (probably because of
     
    493550      if (isnan(Mgrid)) SKIP_THIS_MEAS_STACK(Ngrid);
    494551
    495       Msys = PhotSys (&measure[k], &average[0], &secfilt[0]);
    496       if (isnan(Msys)) SKIP_THIS_MEAS_STACK(Nsys);
    497 
    498       unsigned int stackImageID;
    499 
    500       // which stack image should we use for the mean value?
    501       // if we request the primary (USE_TREE_FOR_PRIMARY), then find the min distances for data from the primary cell
    502       if (MatchImageSkycellID (meas, cat, tessID, projectID, skycellID)) {
    503         float stackPrimaryOffset = getCenterOffset (meas, cat, &measure[k], &stackImageID);
    504         if (stackPrimaryOffset < stackPrimaryOffsetMin) {
    505           stackPrimaryOffsetMin = stackPrimaryOffset;
    506           // stackPrimaryIDmin = stackImageID;
    507           stackPrimaryMeasureMin = k;
    508         }
    509       }
    510 
    511       // get the center distance for the generic case:
    512       float stackCenterOffset = getCenterOffset (meas, cat, &measure[k], &stackImageID);
    513       if (stackCenterOffset < stackCenterOffsetMin) {
    514         stackCenterOffsetMin = stackCenterOffset;
    515         // stackCenterIDmin = stackImageID;
    516         stackCenterMeasureMin = k;
     552      // NOTE: negative and insignificant vlues values are allowed, but not NAN flux values
     553      Finst = PhotFluxInst (&measure[k], MAG_CLASS_PSF);
     554      if (isnan(Finst)) SKIP_THIS_MEAS_STACK(Ninst);
     555
     556      if (measure[k].psfQFperf > psfQFbest) {
     557        psfQFbest = measure[k].psfQFperf;
     558        stackBestMeasure = k;
    517559      }
    518560
     
    537579
    538580    // measurements which are bad will not have a valid stack entry and are skipped
    539     k = (stackPrimaryMeasureMin >= 0) ? stackPrimaryMeasureMin : stackCenterMeasureMin;
     581    k = (stackBestMeasure >= 0) ? stackBestMeasure : stackPrimaryMeasure;
    540582    if (k < 0) continue;
    541 
    542583
    543584    // we are now populating stackDetectID not stack Image ID in secfilt
    544585    // ID = (stackPrimaryMeasureMin >= 0) ? stackPrimaryIDmin      : stackCenterIDmin;
    545     ID = measure[k].extID; // for the stack, this is the stackDetectID
     586    // ID = measure[k].extID; // for the stack, this is the stackDetectID
    546587
    547588    // get the zero point for the selected image
     
    581622
    582623    // need to put in AB mag factor to get to Janskies (or uJy?)
    583     secfilt[Nsec].FluxPSF   = zpFactor * measure[k].FluxPSF; 
    584     secfilt[Nsec].dFluxPSF  = zpFactor * measure[k].dFluxPSF;
    585     secfilt[Nsec].FluxKron  = zpFactor * measure[k].FluxKron;
    586     secfilt[Nsec].dFluxKron = zpFactor * measure[k].dFluxKron;
    587 
    588     secfilt[Nsec].stackDetectID = ID;
    589 
     624    secfilt[Nsec].FpsfStk   = zpFactor * measure[k].FluxPSF; 
     625    secfilt[Nsec].dFpsfStk  = zpFactor * measure[k].dFluxPSF;
     626    secfilt[Nsec].FkronStk  = zpFactor * measure[k].FluxKron;
     627    secfilt[Nsec].dFkronStk = zpFactor * measure[k].dFluxKron;
     628    secfilt[Nsec].FapStk    = zpFactor * measure[k].FluxAp;
     629    secfilt[Nsec].dFapStk   = zpFactor * measure[k].dFluxAp;
     630
     631    // Jy to AB mags
     632    secfilt[Nsec].MpsfStk   = (measure[k].FluxPSF  > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FpsfStk) : NAN;
     633    secfilt[Nsec].MkronStk  = (measure[k].FluxKron > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FkronStk) : NAN;
     634    secfilt[Nsec].MapStk    = (measure[k].FluxAp   > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FapStk) : NAN;
     635
     636    secfilt[Nsec].stackBestOff = k + measureOffset;
     637
     638    secfilt[Nsec].Nstack    = Nstack;
     639    secfilt[Nsec].NstackDet = NstackDet;
     640
     641    // this is the measurement used by secfilt[]
    590642    measure[k].dbFlags |= ID_MEAS_STACK_PHOT_SRC;
    591     if (stackPrimaryMeasureMin >= 0) {
    592       measure[k].dbFlags |= ID_MEAS_STACK_PRIMARY;
     643    if (k == stackPrimaryMeasure) {
    593644      secfilt[Nsec].flags |= ID_SECF_STACK_PRIMARY;
    594645    }
     
    607658}
    608659
     660# undef SKIP_THIS_MEAS
     661# define SKIP_THIS_MEAS(REASON) {                               \
     662    measure[k].dbFlags |= ID_MEAS_SKIP_PHOTOM;  \
     663    results->REASON ++;                                         \
     664    continue; }
     665
     666// set mean of forced-warp measurements (selected by photcode range for now):
     667// somewhat simplified relative to chip-photometry:
     668// * no grid, no mosaic, no 2MASS, no SYNTH, no Ubercal, no flatcorr
     669int setMrelAverageForcedWarp (off_t measureOffset, int cat, int pass, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t *found) {
     670
     671  off_t k;
     672  float Mcal= 0;
     673
     674  // we are measuring means for 3 types of FLUXes: psf, ap, kron.  I am using the psf mag
     675  // error for the ap mags, but krons have their own errors.  it is an open question if I
     676  // should be doing weighted or unweighted fits (this is a user option)
     677  double *Fpsflist  = results->Mpsflist;
     678  double *dpsflist  = results->dpsflist;
     679  double *wpsflist  = results->wpsflist;
     680
     681  double *Faplist   = results->Maplist;
     682  double *daplist   = results->daplist;
     683  double *waplist   = results->waplist;
     684
     685  double *Fkronlist = results->Mkronlist;
     686  double *dkronlist = results->dkronlist;
     687  double *wkronlist = results->wkronlist;
     688
     689  StatType *psfstats  = &results->psfstats;
     690  StatType *apstats   = &results->apstats;
     691  StatType *kronstats = &results->kronstats;
     692
     693  // option for a test print
     694  if ((average[0].objID == 0xd6e) && (average[0].catID == 0x4984)) {
     695    fprintf (stderr, "test obj\n");
     696    print_measure_set_alt (average, secfilt, measure);
     697  }
     698
     699  int Ns;
     700  for (Ns = 0; Ns < Nphotcodes; Ns++) {
     701
     702    int thisCode = photcodes[Ns][0].code;
     703    int Nsec = GetPhotcodeNsec(thisCode);
     704
     705    /* calculate the average mag in this SEC photcode for a single star */
     706
     707    /* star/photcodes already calibrated */
     708    if (found[Nsec]) continue; 
     709     
     710    // I need to restrict the measurements coming only from the same skycell as the secfilt values
     711    // if we cannot make that association, skip this set of warps
     712    int stkTessID, stkProjID, stkSkycellID;
     713    if (!FindImageSkycellID (secfilt[Nsec].stackBestOff, cat, &stkTessID, &stkProjID, &stkSkycellID)) continue;
     714
     715    off_t meas = measureOffset;
     716
     717    int Nap = 0;
     718    int Npsf = 0;
     719    int Nkron = 0;
     720
     721    int Nwarp = 0;
     722    int NwarpGood = 0;
     723    for (k = 0; k < average[0].Nmeasure; k++, meas++) {
     724
     725      // only examine gpc1 forced-warp data
     726      if (!isGPC1warp(measure[k].photcode)) continue;
     727
     728      // skip measurements that do not match the current photcode
     729      PhotCode *code = GetPhotcodebyCode (measure[k].photcode);
     730      if (!code) continue;
     731      if (code->equiv != thisCode) { continue; }
     732
     733      Nwarp ++;
     734      if (measure[k].psfQFperf > 0.85) NwarpGood ++;
     735
     736      measure[k].dbFlags &= ~ID_MEAS_WARP_USED;
     737
     738      if (!MatchImageSkycellID (meas, cat, stkTessID, stkProjID, stkSkycellID)) continue;
     739
     740      if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS(Nbad);
     741
     742      if (getImageEntry (meas, cat) < 0) {
     743        // measurements without an image are either external reference photometry or
     744        // data for which the associated image has not been loaded (probably because of
     745        // overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
     746        Mcal = measure[k].Mcal; // check that this is zero for loaded REF value
     747      } else {
     748        // use getMcal not getMcal_alt?
     749        Mcal  = getMcal_alt (meas, cat, NULL, measure[k].Xccd, measure[k].Yccd);
     750        // Mcal  = getMcal (meas, cat);
     751        if (isnan(Mcal))  SKIP_THIS_MEAS(Ncal);
     752      }
     753      float Fcal = MagToFlux(-Mcal);
     754
     755      // in the calculations below,
     756      // ...list gives the error per measurement, wlist gives the weight
     757      // we can modify the error and weight in a few ways:
     758      // 1) MIN_ERROR guarantees a floor
     759      // 2) photomErrSys is added in quadrature as a sytematic error, set per photcode
     760
     761      // skip some absurd values NAN
     762      // NOTE : I am using PhotCat not PhotSys for now since GPC1 chip-to-chip color terms
     763      // are small (and not measured)
     764      float Fpsf = PhotFluxCat (&measure[k], MAG_CLASS_PSF);
     765      if (isnan(Fpsf)) SKIP_THIS_MEAS(Nsys);
     766      // if (Msys <  0.0) SKIP_THIS_MEAS(Nsys);
     767      // if (Msys > 30.0) SKIP_THIS_MEAS(Nsys);
     768
     769      float dFpsf = PhotFluxCatErr (&measure[k], MAG_CLASS_PSF);
     770      if (isnan(dFpsf)) SKIP_THIS_MEAS (Nsys);
     771
     772      int isBad = (measure[k].psfQF < 0.85);
     773      isBad |= isnan(measure[k].psfQF);
     774      if (isBad) SKIP_THIS_MEAS (Nsys);
     775
     776      int isPoor = (measure[k].psfQFperf < 0.85);
     777      if ((pass == 0) && isPoor) SKIP_THIS_MEAS (Nsys);
     778
     779      dFpsf = MAX (dFpsf, MIN_ERROR*Fpsf); // MIN_ERROR is a fractional error
     780      Fpsflist[Npsf] = Fpsf * Fcal;
     781      dpsflist[Npsf] = dFpsf * Fcal;
     782      wpsflist[Npsf] = 1.0;
     783      Npsf ++;
     784
     785      measure[k].dbFlags |= ID_MEAS_WARP_USED;
     786
     787      float Fap = PhotFluxCat (&measure[k], MAG_CLASS_APER);
     788      float dFap = PhotFluxCatErr (&measure[k], MAG_CLASS_APER);
     789      if (!isnan(Fap)) {
     790        Faplist[Nap] = Fap * Fcal;
     791        daplist[Nap] = dFap * Fcal;
     792        waplist[Nap] = 1.0; // drop weight lists?
     793        Nap ++;
     794      }
     795
     796      float Fkron = PhotFluxCat (&measure[k], MAG_CLASS_KRON);
     797      float dFkron = PhotFluxCatErr (&measure[k], MAG_CLASS_KRON);
     798      if (!isnan(Fkron)) {
     799        Fkronlist[Nkron] = Fkron * Fcal;
     800        dkronlist[Nkron] = dFkron * Fcal;
     801        wkronlist[Nkron] = 1.0;
     802        Nkron ++;
     803      }
     804    }
     805    if (Npsf < 1) continue;
     806
     807    found[Nsec] = TRUE;
     808
     809    liststats (Fpsflist, dpsflist, wpsflist, Npsf, psfstats);
     810
     811    secfilt[Nsec].FpsfWrp  = psfstats->mean;
     812    secfilt[Nsec].dFpsfWrp = psfstats->error;
     813    secfilt[Nsec].sFpsfWrp = psfstats->sigma; // Mstdev is in millimags (not enough space for more precision)
     814    secfilt[Nsec].NusedWrp = psfstats->Nmeas;
     815    secfilt[Nsec].MpsfWrp  = isnan(secfilt[Nsec].FpsfWrp) ? NAN : 8.9 - 2.5*log10(secfilt[Nsec].FpsfWrp); // 8.9 since flux is in Jy
     816
     817    // NOTE : use the modified weight for apmags as well as psf mags
     818    liststats (Faplist, daplist, waplist, Nap, apstats);
     819    secfilt[Nsec].FapWrp     = Nap > 0 ? apstats->mean : NAN;
     820    secfilt[Nsec].dFapWrp    = Nap > 0 ? apstats->error : NAN;
     821    secfilt[Nsec].sFapWrp    = Nap > 0 ? apstats->sigma : NAN;
     822    secfilt[Nsec].NusedApWrp = Nap;
     823    secfilt[Nsec].MapWrp  = isnan(secfilt[Nsec].FapWrp) ? NAN : 8.9 - 2.5*log10(secfilt[Nsec].FapWrp); // 8.9 since flux is in Jy
     824
     825    liststats (Fkronlist, dkronlist, wkronlist, Nkron, kronstats);
     826    secfilt[Nsec].FkronWrp     = Nkron > 0 ? kronstats->mean  : NAN;
     827    secfilt[Nsec].dFkronWrp    = Nkron > 0 ? kronstats->error : NAN;
     828    secfilt[Nsec].sFkronWrp    = Nkron > 0 ? kronstats->sigma : NAN;
     829    secfilt[Nsec].NusedKronWrp = Nkron;
     830    secfilt[Nsec].MkronWrp  = isnan(secfilt[Nsec].FkronWrp) ? NAN : 8.9 - 2.5*log10(secfilt[Nsec].FkronWrp); // 8.9 since flux is in Jy
     831
     832    secfilt[Nsec].Nwarp     = Nwarp;
     833    secfilt[Nsec].NwarpGood = NwarpGood;
     834  }
     835  return (TRUE);
     836}
     837
    609838int setGlobalObjStats (Average *average, Measure *measure) {
    610839
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/setMrelFinal.c

    r35759 r37403  
    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/ps2-tc3-20130727/Ohana/src/relphot/src/share_mean_mags.c

    r36680 r37403  
    123123  meanmags->M  = secfilt->M;
    124124  meanmags->dM = secfilt->dM;
    125   meanmags->Xm = secfilt->Xm;
     125  meanmags->Mchisq = secfilt->Mchisq;
    126126  meanmags->Nsec = Nsec; // key to secfilt entry
    127127
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/syncfile.c

    r36680 r37403  
    5050int clear_sync_file (char *filename) {
    5151  // delete file contents
    52   truncate (filename, 0);
     52  if (truncate (filename, 0)) fprintf (stderr, "trouble clearing file %s\n", filename);
    5353
    5454  return TRUE;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/tools/Makefile

    r31496 r37403  
    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/ps2-tc3-20130727/Ohana/src/tools/src/ftable.c

    r34260 r37403  
    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/ps2-tc3-20130727/Ohana/src/uniphot/src/ImageSubset.c

    r33654 r37403  
    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/ps2-tc3-20130727/Ohana/src/uniphot/src/ImageSubsetFixImageIDs.c

    r35764 r37403  
    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/ps2-tc3-20130727/Ohana/src/uniphot/src/ImageSubsetFixStackIDs.c

    r35764 r37403  
    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/ps2-tc3-20130727/Ohana/src/uniphot/src/ImageSubsetSetPosangle.c

    r34749 r37403  
    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/ps2-tc3-20130727/Ohana/src/uniphot/src/load_images_fiximids.c

    r35764 r37403  
    11# include "fiximids.h"
    2 # define FT_BZERO_INT32 1.0*0x80000000
    32
    43off_t   Nimage = 0;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/uniphot/src/load_images_fixstkids.c

    r35764 r37403  
    11# include "fixstkids.h"
    2 # define FT_BZERO_INT32 1.0*0x80000000
    32
    43off_t Nimage = 0;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/uniphot/src/update_catalog_fiximids.c

    r35764 r37403  
    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/ps2-tc3-20130727/Ohana/src/uniphot/src/update_catalog_setastrom.c

    r35103 r37403  
    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
Note: See TracChangeset for help on using the changeset viewer.