IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37822


Ignore:
Timestamp:
Jan 12, 2015, 12:29:24 PM (12 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-pv3-20140717-merge/Ohana
Files:
1 deleted
345 edited
143 copied

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana

  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/Makefile.in

    r35110 r37822  
    3434dvopsps     \
    3535elixir      \
     36fakeastro   \
    3637gastro      \
    3738gastro2     \
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/configure.tcsh

    r34088 r37822  
    240240set needlibs   = "$needlibs X11"
    241241set needlibs   = "$needlibs pthread"
     242set needlibs   = "$needlibs gsl"
     243set needlibs   = "$needlibs gslcblas"
    242244set needlibs   = "$needlibs m"
    243245
     
    269271set needincs = "$needincs png.h"
    270272set needincs = "$needincs pthread.h"
     273set needincs = "$needincs gsl/gsl_sf_legendre.h"
    271274set needincs = "$needincs readline/history.h"
    272275set needincs = "$needincs readline/readline.h"
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/Makefile

    r37343 r37822  
    2424sedstar      : $(BIN)/sedstar.$(ARCH)
    2525load2mass    : $(BIN)/load2mass.$(ARCH)
     26loadstarpar  : $(BIN)/loadstarpar.$(ARCH)
     27loadstarpar_client : $(BIN)/loadstarpar_client.$(ARCH)
     28loadICRF  : $(BIN)/loadICRF.$(ARCH)
     29loadICRF_client : $(BIN)/loadICRF_client.$(ARCH)
    2630loadwise     : $(BIN)/loadwise.$(ARCH)
    2731dumpskycells : $(BIN)/dumpskycells.$(ARCH)
     
    3135mkcmf        : $(BIN)/mkcmf.$(ARCH)
    3236
    33 all: addstar addstar_client sedstar load2mass skycells mkcmf loadwise loadsupercos dumpskycells findskycell
    34 
    35 INSTALL = addstar addstar_client sedstar load2mass skycells mkcmf loadwise loadsupercos dumpskycells findskycell
     37all: addstar addstar_client sedstar load2mass loadstarpar loadstarpar_client loadICRF loadICRF_client skycells mkcmf loadwise loadsupercos dumpskycells findskycell
     38
     39INSTALL = addstar addstar_client sedstar load2mass loadstarpar loadstarpar_client loadICRF loadICRF_client skycells mkcmf loadwise loadsupercos dumpskycells findskycell
    3640
    3741# I need to fix the client/server version of addstar now that I have dropped Stars
     
    7882$(SRC)/parse_time.$(ARCH).o \
    7983$(SRC)/replace_match.$(ARCH).o \
    80 $(SRC)/resort_catalog.$(ARCH).o \
     84$(SRC)/resort_catalogs.$(ARCH).o \
    8185$(SRC)/resort_threaded.$(ARCH).o \
    8286$(SRC)/resort_unthreaded.$(ARCH).o \
    83 $(SRC)/resort_unthreaded_catalogs.$(ARCH).o \
     87$(SRC)/resort_catalog.$(ARCH).o \
    8488$(SRC)/StarOps.$(ARCH).o \
    8589$(SRC)/ReadStarsFITS.$(ARCH).o \
     
    106110$(SRC)/addstar_client.$(ARCH).o \
    107111$(SRC)/args_parallel_client.$(ARCH).o \
    108 $(SRC)/resort_catalog.$(ARCH).o \
     112$(SRC)/resort_catalogs.$(ARCH).o \
    109113$(SRC)/resort_threaded.$(ARCH).o \
    110114$(SRC)/resort_unthreaded.$(ARCH).o \
    111 $(SRC)/resort_unthreaded_catalogs.$(ARCH).o
     115$(SRC)/resort_catalog.$(ARCH).o
    112116
    113117ADDSTARD = \
     
    241245$(SRC)/psps_ids.$(ARCH).o
    242246
     247LOAD-STARPAR = \
     248$(SRC)/loadstarpar.$(ARCH).o \
     249$(SRC)/ConfigInit.$(ARCH).o \
     250$(SRC)/SetSignals.$(ARCH).o \
     251$(SRC)/Shutdown.$(ARCH).o \
     252$(SRC)/SkyRegionUtils.$(ARCH).o \
     253$(SRC)/args_loadstarpar.$(ARCH).o \
     254$(SRC)/find_matches_starpar.$(ARCH).o \
     255$(SRC)/loadstarpar_catalog.$(ARCH).o \
     256$(SRC)/loadstarpar_io.$(ARCH).o \
     257$(SRC)/loadstarpar_make_subset.$(ARCH).o \
     258$(SRC)/loadstarpar_readstars.$(ARCH).o \
     259$(SRC)/loadstarpar_remote_hosts.$(ARCH).o \
     260$(SRC)/loadstarpar_save_remote.$(ARCH).o \
     261$(SRC)/loadstarpar_table.$(ARCH).o \
     262$(SRC)/psps_ids.$(ARCH).o
     263
     264LOAD-STARPAR-CLIENT = \
     265$(SRC)/loadstarpar_client.$(ARCH).o \
     266$(SRC)/ConfigInit.$(ARCH).o \
     267$(SRC)/SetSignals.$(ARCH).o \
     268$(SRC)/Shutdown.$(ARCH).o \
     269$(SRC)/SkyRegionUtils.$(ARCH).o \
     270$(SRC)/args_loadstarpar.$(ARCH).o \
     271$(SRC)/find_matches_starpar.$(ARCH).o \
     272$(SRC)/loadstarpar_catalog.$(ARCH).o \
     273$(SRC)/loadstarpar_io.$(ARCH).o \
     274$(SRC)/loadstarpar_make_subset.$(ARCH).o \
     275$(SRC)/loadstarpar_readstars.$(ARCH).o \
     276$(SRC)/loadstarpar_remote_hosts.$(ARCH).o \
     277$(SRC)/loadstarpar_save_remote.$(ARCH).o \
     278$(SRC)/loadstarpar_table.$(ARCH).o \
     279$(SRC)/psps_ids.$(ARCH).o
     280
     281LOAD-ICRF = \
     282$(SRC)/loadICRF.$(ARCH).o \
     283$(SRC)/ConfigInit.$(ARCH).o \
     284$(SRC)/SetSignals.$(ARCH).o \
     285$(SRC)/Shutdown.$(ARCH).o \
     286$(SRC)/SkyRegionUtils.$(ARCH).o \
     287$(SRC)/args_loadICRF.$(ARCH).o \
     288$(SRC)/find_matches_ICRF.$(ARCH).o \
     289$(SRC)/loadICRF_catalog.$(ARCH).o \
     290$(SRC)/loadICRF_io.$(ARCH).o \
     291$(SRC)/loadICRF_make_subset.$(ARCH).o \
     292$(SRC)/loadICRF_readstars.$(ARCH).o \
     293$(SRC)/loadICRF_remote_hosts.$(ARCH).o \
     294$(SRC)/loadICRF_save_remote.$(ARCH).o \
     295$(SRC)/loadICRF_table.$(ARCH).o \
     296$(SRC)/psps_ids.$(ARCH).o
     297
     298LOAD-ICRF-CLIENT = \
     299$(SRC)/loadICRF_client.$(ARCH).o \
     300$(SRC)/ConfigInit.$(ARCH).o \
     301$(SRC)/SetSignals.$(ARCH).o \
     302$(SRC)/Shutdown.$(ARCH).o \
     303$(SRC)/SkyRegionUtils.$(ARCH).o \
     304$(SRC)/args_loadICRF.$(ARCH).o \
     305$(SRC)/find_matches_ICRF.$(ARCH).o \
     306$(SRC)/loadICRF_catalog.$(ARCH).o \
     307$(SRC)/loadICRF_io.$(ARCH).o \
     308$(SRC)/loadICRF_make_subset.$(ARCH).o \
     309$(SRC)/loadICRF_readstars.$(ARCH).o \
     310$(SRC)/loadICRF_remote_hosts.$(ARCH).o \
     311$(SRC)/loadICRF_save_remote.$(ARCH).o \
     312$(SRC)/loadICRF_table.$(ARCH).o \
     313$(SRC)/psps_ids.$(ARCH).o
     314
    243315LOAD-WISE = \
    244316$(SRC)/loadwise.$(ARCH).o \
     
    309381$(SRC)/Shutdown.$(ARCH).o
    310382
    311 $(ADDSTARC)       : $(INC)/addstar.h
    312 $(ADDSTARD)       : $(INC)/addstar.h
    313 $(ADDSTART)       : $(INC)/addstar.h
    314 $(ADDSTAR)        : $(INC)/addstar.h
    315 $(ADDSTAR_CLIENT) : $(INC)/addstar.h
    316 $(SKYCELLS)       : $(INC)/addstar.h
    317 $(DUMPSKYCELLS)   : $(INC)/addstar.h
    318 $(FINDSKYCELL)    : $(INC)/addstar.h
    319 $(LOAD-2MASS)     : $(INC)/addstar.h $(INC)/2mass.h
    320 $(LOAD-WISE)      : $(INC)/addstar.h $(INC)/WISE.h
    321 $(MKCMF)          : $(INC)/mkcmf.h
     383$(ADDSTARC)            : $(INC)/addstar.h
     384$(ADDSTARD)            : $(INC)/addstar.h
     385$(ADDSTART)            : $(INC)/addstar.h
     386$(ADDSTAR)             : $(INC)/addstar.h
     387$(ADDSTAR_CLIENT)      : $(INC)/addstar.h
     388$(SKYCELLS)            : $(INC)/addstar.h
     389$(DUMPSKYCELLS)        : $(INC)/addstar.h
     390$(FINDSKYCELL)         : $(INC)/addstar.h
     391$(LOAD-2MASS)          : $(INC)/addstar.h $(INC)/2mass.h
     392$(LOAD-STARPAR)        : $(INC)/addstar.h $(INC)/loadstarpar.h
     393$(LOAD-STARPAR-CLIENT) : $(INC)/addstar.h $(INC)/loadstarpar.h
     394$(LOAD-ICRF)           : $(INC)/addstar.h $(INC)/loadICRF.h
     395$(LOAD-ICRF-CLIENT)    : $(INC)/addstar.h $(INC)/loadICRF.h
     396$(LOAD-WISE)           : $(INC)/addstar.h $(INC)/WISE.h
     397$(MKCMF)               : $(INC)/mkcmf.h
    322398
    323399$(BIN)/addstar.$(ARCH)        : $(ADDSTAR)
     
    330406$(BIN)/load2mass.$(ARCH)      : $(LOAD-2MASS)
    331407$(BIN)/loadwise.$(ARCH)       : $(LOAD-WISE)
     408$(BIN)/loadstarpar.$(ARCH)    : $(LOAD-STARPAR)
     409$(BIN)/loadstarpar_client.$(ARCH) : $(LOAD-STARPAR-CLIENT)
     410$(BIN)/loadICRF.$(ARCH)       : $(LOAD-ICRF)
     411$(BIN)/loadICRF_client.$(ARCH): $(LOAD-ICRF-CLIENT)
    332412$(BIN)/loadsupercos.$(ARCH)   : $(LOAD-SUPERCOS)
    333413$(BIN)/skycells.$(ARCH)       : $(SKYCELLS)
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/include/WISE.h

    r33963 r37822  
    2121short WISE_W1, WISE_W2, WISE_W3, WISE_W4;
    2222
    23 int ALLSKY;
     23enum {MODE_NONE, MODE_ALLWISE, MODE_ALLSKY, MODE_PRELIM};
     24int MODE;
    2425
    2526AddstarClientOptions args_loadwise (int argc, char **argv, AddstarClientOptions options);
    2627
    27 int loadwise_rawdata (SkyList *skytable, char *filename, AddstarClientOptions options, int ALLSKY);
     28int loadwise_rawdata (SkyList *skytable, char *filename, AddstarClientOptions options);
    2829
    2930int getWISE_setup ();
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/include/addstar.h

    r37343 r37822  
    2020# define IN_REGION(R,D) ( \
    2121((D) >= region[0].Dmin) && ((D) < region[0].Dmax) && \
    22 ((R) >= region[0].Rmin)  && ((R) < region[0].Rmax))
     22((R) >= region[0].Rmin) && ((R) < region[0].Rmax))
    2323
    2424/* grab named photcode */
     
    3131# define dCOS(A)   ((double) cos ((double)RAD_DEG*A))
    3232# define dSIN(A)   ((double) sin ((double)RAD_DEG*A))
     33
     34# define myAbortF(FORMAT,...) { fprintf (stderr, FORMAT, __VA_ARGS__); abort(); }
    3335
    3436typedef struct {
     
    240242Stars     *rd_gsc                 PROTO((char *filename, unsigned int *nstars));
    241243int        replace_match          PROTO((Average *average, Measure *measure, Stars *star));
    242 int        resort_threaded        PROTO((AddstarClientOptions *options, SkyTable *sky));
    243 int        resort_unthreaded      PROTO((AddstarClientOptions *options, SkyTable *sky, int hostID, char *hostpath));
    244 int        resort_unthreaded_catalogs PROTO((AddstarClientOptions *options, SkyList *skylist, int hostID, char *hostpath));
     244int        resort_catalogs        PROTO((AddstarClientOptions *options, SkyTable *sky));
     245int        resort_catalogs_parallel PROTO((AddstarClientOptions *options, SkyList *sky));
     246int        resort_threaded        PROTO((SkyList *skylist, int ForceSort));
     247int        resort_unthreaded      PROTO((SkyList *skylist, int ForceSort));
    245248void       resort_catalog         PROTO((Catalog *catalog));
    246249void       resort_catalog_old     PROTO((Catalog *catalog));
     250
    247251Stars     *ReadStarsFITS          PROTO((FILE *f, Header *header, Header *in_theader, unsigned int *nstars));
    248252Stars     *ReadStarsTEXT          PROTO((FILE *f, unsigned int *nstars));
     
    259263off_t     *init_lensing_links     PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
    260264off_t     *init_missing_links     PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing));
    261 off_t      add_meas_link          PROTO((Average *average, off_t *next_meas, off_t Nmeasure, off_t NMEASURE));
    262 off_t      add_miss_link          PROTO((Average *average, off_t *next_miss, off_t Nmissing));
    263 off_t      add_lens_link          PROTO((Average *average, off_t *next_lens, off_t Nlensing, off_t NLENSING));
     265int        add_meas_link          PROTO((Average *average, off_t *next_meas, off_t Nmeasure, off_t NMEASURE));
     266int        add_miss_link          PROTO((Average *average, off_t *next_miss, off_t Nmissing));
     267int        add_lens_link          PROTO((Average *average, off_t *next_lens, off_t Nlensing, off_t NLENSING));
    264268off_t     *build_measure_links    PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
    265269off_t     *build_lensing_links    PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
     
    322326void *memrchr(const void *s, int c, size_t n);
    323327int addstar_create_ID ();
     328int strextend (char *input, char *format,...);
     329
     330void initMosaicCoords ();
     331void saveMosaicCoords (Coords *input);
     332
    324333
    325334/**
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/BoundaryTreeIO.c

    r34260 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/addstar/src/LoadData.c

    r37343 r37822  
    3333  // we need to perform that analysis here
    3434  GetZeroPointExposure (headers, headerSets, Nimages);
     35
     36  if (!options[0].mosaic) {
     37    // we are requiring a single set of N x WRPs + 1 DIS per file set.
     38    // NOTE: if the -mosaic was supplied, do not reset the mosaic coords here
     39    initMosaicCoords ();
     40  }
    3541
    3642  // now run through the images, interpret the headers and read the stars
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/LoadDataPMM.c

    r36485 r37822  
    193193
    194194    // XXX for now, we define a totally fake coordinate system centered on the plate center
    195     strcpy (image[0].coords.ctype, "DEC--TAN");
     195    InitCoords (&image[0].coords, "DEC--TAN");
    196196   
    197197    image[0].coords.crval1  = pmm_get_ra (RA);
     
    203203    image[0].coords.crpix2 = 0.5*PLATE_NY;
    204204    image[0].coords.cdelt1 = image[0].coords.cdelt2 = 0.9 / 3600.0;
    205 
    206     image[0].coords.pc1_1 = 0.0;
    207     image[0].coords.pc1_2 = 1.0;
    208     image[0].coords.pc2_1 = 1.0;
    209     image[0].coords.pc2_2 = 0.0;
    210 
    211     image[0].coords.Npolyterms = 0;
    212     memset (image[0].coords.polyterms, 0, 2*7*sizeof(float));
    213205
    214206    image[0].NX = PLATE_NX;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/LoadStars.c

    r28241 r37822  
    8888      exit (1);
    8989    }
     90    /* supplied photcode is incompatible with multi-chip images */
     91    if ((NheaderSets > 1) && options[0].mosaic) {
     92      fprintf (stderr, "ERROR: -mosaic cannot be supplied to multiple images\n");
     93      exit (1);
     94    }
    9095
    9196    // if these are SDSS data, load with SDSS-specific wrapper
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/MatchHeaders.c

    r37343 r37822  
    6464    if (!strcmp (exttype, "PS1_SV2")) goto keep;
    6565    if (!strcmp (exttype, "PS1_SV3")) goto keep;
     66    if (!strcmp (exttype, "PS1_SV4")) goto keep;
    6667
    6768    if (!strcmp (exttype, "PS1_DV1")) goto keep;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/NewImage.c

    r10939 r37822  
    3333      goto reject;
    3434    }
     35    saveMosaicCoords (mosaic);
    3536  }   
    3637
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/ReadImageHeader.c

    r37036 r37822  
    11# include "addstar.h"
     2
     3// for DIS/WRP sets, we need to save the DIS set and supply it to the WRP entries
     4static Coords *mosaic = NULL;
     5
     6void initMosaicCoords () {
     7  mosaic = NULL;
     8}
     9
     10void saveMosaicCoords (Coords *input) {
     11  ALLOCATE (mosaic, Coords, 1);
     12  memcpy (mosaic, input, sizeof(Coords));
     13}
    214
    315/* read an image header corresponding to a CMF / CMP data block */
     
    5466  /* only load astrometry, NAXIS1,2, and time if this is a MOSAIC_PHU (ctype is ....-DIS) */
    5567  if (!strcmp (&image[0].coords.ctype[4], "-DIS")) {
    56     RegisterMosaic (&image[0].coords);
     68    saveMosaicCoords (&image[0].coords);
    5769    return (TRUE);
    5870  }
     
    7991  }
    8092  if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
    81     if (!isRegisteredMosaic()) {
     93    if (!mosaic) {
    8294      fprintf (stderr, "no mosaic for WRP image (use -mosaic)\n");
    8395      return (FALSE);
    8496    }
     97    image[0].coords.mosaic = mosaic;
    8598  } else {
    8699    /* force image to lie in 0-360 range */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/ReadStarsFITS.c

    r37036 r37822  
    1414Stars     *Convert_PS1_V5         PROTO((FTable *table, unsigned int *nstars));
    1515Stars     *Convert_PS1_V5_Lensing PROTO((FTable *table, unsigned int *nstars));
     16Stars     *Convert_PS1_V5_Lensing_Alt PROTO((FTable *table, unsigned int *nstars));
    1617Stars     *Convert_PS1_SV1        PROTO((FTable *table, unsigned int *nstars));
    1718Stars     *Convert_PS1_SV1_Alt    PROTO((FTable *table, unsigned int *nstars));
    1819Stars     *Convert_PS1_SV2        PROTO((FTable *table, unsigned int *nstars));
    1920Stars     *Convert_PS1_SV3        PROTO((FTable *table, unsigned int *nstars));
     21Stars     *Convert_PS1_SV4        PROTO((FTable *table, unsigned int *nstars));
    2022Stars     *Convert_PS1_DV3        PROTO((FTable *table, unsigned int *nstars));
    2123Stars     *Convert_PS1_DV4        PROTO((FTable *table, unsigned int *nstars));
     
    7880  }
    7981  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);
     82    switch (table.header[0].Naxis[0]) {
     83      case 232:
     84        stars = Convert_PS1_V5 (&table, &Nstars);
     85        break;
     86      case 312:
     87        stars = Convert_PS1_V5_Lensing_Alt (&table, &Nstars);
     88        break;
     89      case 320:
     90        stars = Convert_PS1_V5_Lensing (&table, &Nstars);
     91        break;
     92      default:
     93        fprintf (stderr, "invalid PS1_V5 table size %d\n", (int) table.header[0].Naxis[0]);
     94        return NULL;
    8495    }
    8596  }
     
    92103  if (!strcmp (type, "PS1_SV3")) {
    93104    stars = Convert_PS1_SV3 (&table, &Nstars);
     105  }
     106  if (!strcmp (type, "PS1_SV4")) {
     107    stars = Convert_PS1_SV4 (&table, &Nstars);
    94108  }
    95109  if (!strcmp (type, "PS1_DV3")) {
     
    182196    stars[i].measure.psfNdof    = NAN_S_INT; // not provided by SMPDATA:
    183197    stars[i].measure.psfNpix    = NAN_S_INT; // not provided by SMPDATA:
    184     stars[i].measure.crNsigma   = NAN;       // not provided by SMPDATA:
    185198    stars[i].measure.extNsigma  = NAN;       // not provided by SMPDATA:
    186199
     
    251264    stars[i].measure.psfNdof    = NAN_S_INT; // not provided by PS1_DEV_0:
    252265    stars[i].measure.psfNpix    = NAN_S_INT; // not provided by PS1_DEV_0:
    253     stars[i].measure.crNsigma   = NAN;       // not provided by PS1_DEV_0:
    254266    stars[i].measure.extNsigma  = NAN;        // not provided by PS1_DEV_0:
    255267
     
    323335    stars[i].measure.psfNdof    = NAN_S_INT; // not provided by PS1_DEV_1:
    324336    stars[i].measure.psfNpix    = NAN_S_INT; // not provided by PS1_DEV_1:
    325     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    326337    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    327338
     
    408419    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    409420    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    410     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    411421    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    412422
     
    494504    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    495505    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    496     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    497506    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    498507
     
    572581    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    573582    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    574     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    575583    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    576584
     
    653661    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    654662    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    655     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    656663    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    657664
     
    665672                       
    666673    stars[i].measure.photFlags  = ps1data[i].flags;
     674    stars[i].measure.photFlags2 = ps1data[i].flags2;
    667675
    668676    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    738746    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    739747    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    740     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    741748    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    742749
     
    750757                       
    751758    stars[i].measure.photFlags  = ps1data[i].flags;
     759    stars[i].measure.photFlags2 = ps1data[i].flags2;
    752760
    753761    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    823831    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    824832    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    825     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    826833    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    827834
     
    835842                       
    836843    stars[i].measure.photFlags  = ps1data[i].flags;
     844    stars[i].measure.photFlags2 = ps1data[i].flags2;
    837845
    838846    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    908916    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    909917    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    910     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    911918    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    912919
     
    920927                       
    921928    stars[i].measure.photFlags  = ps1data[i].flags;
     929    stars[i].measure.photFlags2 = ps1data[i].flags2;
    922930
    923931    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    977985}
    978986
     987Stars *Convert_PS1_V5_Lensing_Alt (FTable *table, unsigned int *nstars) {
     988
     989  off_t Nstars;
     990  unsigned int i;
     991  double ZeroPt;
     992  Stars *stars;
     993  CMF_PS1_V5_Lensing_Alt *ps1data;
     994
     995  ps1data = gfits_table_get_CMF_PS1_V5_Lensing_Alt (table, &Nstars, NULL);
     996  if (!ps1data) {
     997    fprintf (stderr, "skipping inconsistent entry\n");
     998    return (NULL);
     999  }
     1000  ZeroPt = GetZeroPoint();
     1001
     1002  ALLOCATE (stars, Stars, Nstars);
     1003  for (i = 0; i < Nstars; i++) {
     1004    InitStar (&stars[i]);
     1005    stars[i].measure.Xccd       = ps1data[i].X;
     1006    stars[i].measure.Yccd       = ps1data[i].Y;
     1007    stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
     1008    stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
     1009
     1010    stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
     1011    stars[i].measure.pltscale   = ps1data[i].pltscale;
     1012
     1013    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
     1014      stars[i].measure.M      = NAN;
     1015    } else {
     1016      stars[i].measure.M      = ps1data[i].M + ZeroPt;
     1017    }
     1018    stars[i].measure.dM         = ps1data[i].dM;
     1019    stars[i].measure.dMcal      = ps1data[i].dMcal;
     1020    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1021    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1022                       
     1023    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1024    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1025                       
     1026    // these fluxes are converted from counts to counts/sec in FilterStars.c
     1027    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1028    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
     1029    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
     1030    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1031    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1032    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
     1033
     1034    stars[i].measure.Sky        = ps1data[i].sky;
     1035    stars[i].measure.dSky       = ps1data[i].dSky;
     1036                       
     1037    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     1038    stars[i].measure.psfQF      = ps1data[i].psfQF;
     1039    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
     1040
     1041    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
     1042    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
     1043    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
     1044
     1045    stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
     1046    stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
     1047    stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
     1048
     1049    stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
     1050    stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     1051    stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
     1052                       
     1053    stars[i].measure.photFlags  = ps1data[i].flags;
     1054    stars[i].measure.photFlags2 = ps1data[i].flags2;
     1055
     1056    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1057    stars[i].measure.detID      = ps1data[i].detID;
     1058
     1059    ALLOCATE (stars[i].lensing, Lensing, 1);
     1060    dvo_lensing_init (stars[i].lensing);
     1061
     1062    stars[i].lensing->X11_sm_obj  = ps1data[i].X11_sm_obj;
     1063    stars[i].lensing->X12_sm_obj  = ps1data[i].X12_sm_obj;
     1064    stars[i].lensing->X22_sm_obj  = ps1data[i].X22_sm_obj;
     1065    stars[i].lensing->E1_sm_obj   = ps1data[i].E1_sm_obj;
     1066    stars[i].lensing->E2_sm_obj   = ps1data[i].E2_sm_obj;
     1067
     1068    stars[i].lensing->X11_sh_obj  = ps1data[i].X11_sh_obj;
     1069    stars[i].lensing->X12_sh_obj  = ps1data[i].X12_sh_obj;
     1070    stars[i].lensing->X22_sh_obj  = ps1data[i].X22_sh_obj;
     1071    stars[i].lensing->E1_sh_obj   = ps1data[i].E1_sh_obj;
     1072    stars[i].lensing->E2_sh_obj   = ps1data[i].E2_sh_obj;
     1073
     1074    stars[i].lensing->X11_sm_psf  = ps1data[i].X11_sm_psf;
     1075    stars[i].lensing->X12_sm_psf  = ps1data[i].X12_sm_psf;
     1076    stars[i].lensing->X22_sm_psf  = ps1data[i].X22_sm_psf;
     1077    stars[i].lensing->E1_sm_psf   = ps1data[i].E1_sm_psf;
     1078    stars[i].lensing->E2_sm_psf   = ps1data[i].E2_sm_psf;
     1079
     1080    stars[i].lensing->X11_sh_psf  = ps1data[i].X11_sh_psf;
     1081    stars[i].lensing->X12_sh_psf  = ps1data[i].X12_sh_psf;
     1082    stars[i].lensing->X22_sh_psf  = ps1data[i].X22_sh_psf;
     1083    stars[i].lensing->E1_sh_psf   = ps1data[i].E1_sh_psf;
     1084    stars[i].lensing->E2_sh_psf   = ps1data[i].E2_sh_psf;
     1085
     1086    // stars[i].lensing->F_ApR5    = ps1data[i].F_ApR5;
     1087    // stars[i].lensing->dF_ApR5   = ps1data[i].dF_ApR5;
     1088    // stars[i].lensing->sF_ApR5   = ps1data[i].sF_ApR5;
     1089    // stars[i].lensing->fF_ApR5   = ps1data[i].fF_ApR5;
     1090    //
     1091    // stars[i].lensing->F_ApR6    = ps1data[i].F_ApR6;
     1092    // stars[i].lensing->dF_ApR6   = ps1data[i].dF_ApR6;
     1093    // stars[i].lensing->sF_ApR6   = ps1data[i].sF_ApR6;
     1094    // stars[i].lensing->fF_ApR6   = ps1data[i].fF_ApR6;
     1095
     1096    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1097    stars[i].lensing->detID      = ps1data[i].detID;
     1098
     1099    // the Average fields and the following Measure fields are set in FilterStars after
     1100    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID.
     1101
     1102    // averef is set in find_matches
     1103
     1104    // dbFlags is zero on ingest.
     1105
     1106    // the following fields are currently not being set anywhere: t_msec
     1107  }   
     1108  *nstars = Nstars;
     1109  return (stars);
     1110}
     1111
    9791112Stars *Convert_PS1_SV1 (FTable *table, unsigned int *nstars) {
    9801113
     
    10381171    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    10391172    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1040     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    10411173    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    10421174
     
    10501182                       
    10511183    stars[i].measure.photFlags  = ps1data[i].flags;
     1184    stars[i].measure.photFlags2 = ps1data[i].flags2;
    10521185
    10531186    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    11201253    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    11211254    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1122     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    11231255    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    11241256
     
    11321264                       
    11331265    stars[i].measure.photFlags  = ps1data[i].flags;
     1266    stars[i].measure.photFlags2 = ps1data[i].flags2;
    11341267
    11351268    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    12021335    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    12031336    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1204     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    12051337    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    12061338
     
    12141346                       
    12151347    stars[i].measure.photFlags  = ps1data[i].flags;
     1348    stars[i].measure.photFlags2 = ps1data[i].flags2;
    12161349
    12171350    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    12841417    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    12851418    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1286     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    12871419    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    12881420
     
    12961428                       
    12971429    stars[i].measure.photFlags  = ps1data[i].flags;
     1430    stars[i].measure.photFlags2 = ps1data[i].flags2;
    12981431
    12991432    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    13101443}
    13111444
    1312 Stars *Convert_PS1_DV3 (FTable *table, unsigned int *nstars) {
     1445Stars *Convert_PS1_SV4 (FTable *table, unsigned int *nstars) {
    13131446
    13141447  off_t Nstars;
     
    13161449  double ZeroPt;
    13171450  Stars *stars;
    1318   CMF_PS1_DV3 *ps1data;
    1319 
    1320   ps1data = gfits_table_get_CMF_PS1_DV3 (table, &Nstars, NULL);
     1451  CMF_PS1_SV4 *ps1data;
     1452
     1453  ps1data = gfits_table_get_CMF_PS1_SV4 (table, &Nstars, NULL);
    13211454  if (!ps1data) {
    13221455    fprintf (stderr, "skipping inconsistent entry\n");
     
    13481481    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    13491482    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    1350                        
     1483
    13511484    // these fluxes are converted from counts to counts/sec in FilterStars.c
    13521485    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     
    13631496    stars[i].measure.psfQF      = ps1data[i].psfQF;
    13641497    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
     1498
    13651499    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    13661500    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1367     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    13681501    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    13691502
     
    13771510                       
    13781511    stars[i].measure.photFlags  = ps1data[i].flags;
     1512    stars[i].measure.photFlags2 = ps1data[i].flags2;
    13791513
    13801514    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    13821516
    13831517    // the Average fields and the following Measure fields are set in FilterStars after
    1384     // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID.
    1385 
    1386     // averef is set in find_matches
    1387 
    1388     // dbFlags is zero on ingest.
     1518    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID,
     1519    // averef is set in find_matches, dbFlags is zero on ingest.
    13891520
    13901521    // the following fields are currently not being set anywhere: t_msec
     
    13941525}
    13951526
    1396 Stars *Convert_PS1_DV4 (FTable *table, unsigned int *nstars) {
     1527Stars *Convert_PS1_DV3 (FTable *table, unsigned int *nstars) {
    13971528
    13981529  off_t Nstars;
     
    14001531  double ZeroPt;
    14011532  Stars *stars;
    1402   CMF_PS1_DV4 *ps1data;
    1403 
    1404   ps1data = gfits_table_get_CMF_PS1_DV4 (table, &Nstars, NULL);
     1533  CMF_PS1_DV3 *ps1data;
     1534
     1535  ps1data = gfits_table_get_CMF_PS1_DV3 (table, &Nstars, NULL);
    14051536  if (!ps1data) {
    14061537    fprintf (stderr, "skipping inconsistent entry\n");
     
    14081539  }
    14091540  ZeroPt = GetZeroPoint();
    1410 
    1411   fprintf (stderr, "WARNING: Convert_PS1_DV4 not yet updated to match real format\n");
    14121541
    14131542  ALLOCATE (stars, Stars, Nstars);
     
    14511580    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    14521581    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1453     stars[i].measure.crNsigma   = ps1data[i].crNsigma;
    14541582    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    14551583
     
    14631591                       
    14641592    stars[i].measure.photFlags  = ps1data[i].flags;
     1593    stars[i].measure.photFlags2 = ps1data[i].flags2;
    14651594
    14661595    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     
    14801609}
    14811610
    1482 
    1483 
     1611Stars *Convert_PS1_DV4 (FTable *table, unsigned int *nstars) {
     1612
     1613  off_t Nstars;
     1614  unsigned int i;
     1615  double ZeroPt;
     1616  Stars *stars;
     1617  CMF_PS1_DV4 *ps1data;
     1618
     1619  ps1data = gfits_table_get_CMF_PS1_DV4 (table, &Nstars, NULL);
     1620  if (!ps1data) {
     1621    fprintf (stderr, "skipping inconsistent entry\n");
     1622    return (NULL);
     1623  }
     1624  ZeroPt = GetZeroPoint();
     1625
     1626  fprintf (stderr, "WARNING: Convert_PS1_DV4 not yet updated to match real format\n");
     1627
     1628  ALLOCATE (stars, Stars, Nstars);
     1629  for (i = 0; i < Nstars; i++) {
     1630    InitStar (&stars[i]);
     1631    stars[i].measure.Xccd       = ps1data[i].X;
     1632    stars[i].measure.Yccd       = ps1data[i].Y;
     1633    stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
     1634    stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
     1635
     1636    stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
     1637    stars[i].measure.pltscale   = ps1data[i].pltscale;
     1638
     1639    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
     1640      stars[i].measure.M      = NAN;
     1641    } else {
     1642      stars[i].measure.M      = ps1data[i].M + ZeroPt;
     1643    }
     1644    stars[i].measure.dM         = ps1data[i].dM;
     1645    stars[i].measure.dMcal      = ps1data[i].dMcal;
     1646    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     1647    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1648                       
     1649    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1650    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1651                       
     1652    // these fluxes are converted from counts to counts/sec in FilterStars.c
     1653    stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1654    stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
     1655    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
     1656    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
     1657    stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1658    stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
     1659
     1660    stars[i].measure.Sky        = ps1data[i].sky;
     1661    stars[i].measure.dSky       = ps1data[i].dSky;
     1662                       
     1663    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     1664    stars[i].measure.psfQF      = ps1data[i].psfQF;
     1665    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
     1666    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
     1667    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
     1668    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
     1669
     1670    stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
     1671    stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
     1672    stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
     1673
     1674    stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
     1675    stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     1676    stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
     1677                       
     1678    stars[i].measure.photFlags  = ps1data[i].flags;
     1679    stars[i].measure.photFlags2 = ps1data[i].flags2;
     1680
     1681    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1682    stars[i].measure.detID      = ps1data[i].detID;
     1683
     1684    // the Average fields and the following Measure fields are set in FilterStars after
     1685    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID.
     1686
     1687    // averef is set in find_matches
     1688
     1689    // dbFlags is zero on ingest.
     1690
     1691    // the following fields are currently not being set anywhere: t_msec
     1692  }   
     1693  *nstars = Nstars;
     1694  return (stars);
     1695}
     1696
     1697
     1698
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/ReadStarsSDSS.c

    r36485 r37822  
    201201   
    202202    // XXX for now, we define a totally fake coordinate system centered on the first listed star
    203     strcpy (images[N].coords.ctype, "DEC--TAN");
    204    
     203    InitCoords (&images[N].coords, "DEC--TAN");
    205204    images[N].coords.crval1 = stars[0].average.R;
    206205    images[N].coords.crval2 = stars[0].average.D;
    207    
    208206    images[N].coords.crpix1 = stars[0].measure.Xccd;
    209207    images[N].coords.crpix2 = stars[0].measure.Yccd;
    210208    images[N].coords.cdelt1 = images[N].coords.cdelt2 = 0.4 / 3600.0;
    211 
    212     images[N].coords.pc1_1 = 0.0;
    213     images[N].coords.pc1_2 = 1.0;
    214     images[N].coords.pc2_1 = 1.0;
    215     images[N].coords.pc2_2 = 0.0;
    216 
    217     images[N].coords.Npolyterms = 0;
    218     memset (images[N].coords.polyterms, 0, 2*7*sizeof(float));
    219209
    220210    images[N].NX = 2048;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/UpdateDatabase_Image.c

    r27435 r37822  
    2121
    2222  /* find correpsonding regions for image */
    23   RegisterMosaic (mosaic);
    2423  skylist = NULL;
    2524  newlist = NULL;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/addstar.c

    r37036 r37822  
    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
     
    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);
     
    132132      }
    133133    }
     134    if (VERBOSE) 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    if (VERBOSE) MARKTIME ("match stars: %f sec\n", dtime); RESETTIME;
     166
    181167    /* report total updated values */
    182168    Naverage += catalog.Naverage;
     
    197183    dvo_catalog_unlock (&catalog);
    198184    dvo_catalog_free (&catalog);
     185    if (VERBOSE) MARKTIME ("save cpt: %f sec\n", dtime); RESETTIME;
    199186
    200187    if (options.mode == ADDSTAR_MODE_REFCAT) free (stars);
     
    230217  dvo_image_unlock (&db); /* unlock? */
    231218
    232   gettimeofday (&stop, NULL);
    233   dtime = DTIME (stop, start);
     219  gettimeofday (&stopAddstar, (void *) NULL);
     220  float dtime = DTIME (stopAddstar, startAddstar);
    234221  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);
    235222
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/addstar_client.c

    r33963 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/addstar/src/args.c

    r37343 r37822  
    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;
     
    169175      exit (1);
    170176    }
    171     RegisterMosaic (&MOSAIC);
     177    saveMosaicCoords (&MOSAIC);
    172178    remove_argument (N, &argc, argv);
    173179    gfits_free_header (&header);
     
    356362  // XXX for the moment, make this selection manual.  it needs to be automatic
    357363  // based on the state of the SkyTable
     364  HOST_ID = 0;
     365  HOSTDIR = NULL;
    358366  PARALLEL = FALSE;
    359367  if ((N = get_argument (argc, argv, "-parallel"))) {
     
    472480}
    473481
     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
    474495/** addstar modes:
    475496 
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/args_client.c

    r33963 r37822  
    8383      exit (1);
    8484    }
    85     RegisterMosaic (&MOSAIC);
     85    saveMosaicCoords (&MOSAIC);
    8686    remove_argument (N, &argc, argv);
    8787    gfits_free_header (&header);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/args_loadwise.c

    r33963 r37822  
    5353  }
    5454
     55enum {MODE_NONE, MODE_ALLWISE, MODE_ALLSKY, MODE_PRELIM};
     56int MODE;
     57
    5558  /* load the prelim data dump */
    56   ALLSKY = TRUE;
    57   if ((N = get_argument (argc, argv, "-prelim"))) {
    58     ALLSKY = FALSE;
     59  MODE = MODE_ALLWISE;
     60  if ((N = get_argument (argc, argv, "-mode"))) {
     61    MODE = MODE_NONE;
     62    remove_argument (N, &argc, argv);
     63    if (!strcasecmp(argv[N], "allwise")) MODE = MODE_ALLWISE;
     64    if (!strcasecmp(argv[N], "allsky"))  MODE = MODE_ALLSKY;
     65    if (!strcasecmp(argv[N], "prelim"))  MODE = MODE_PRELIM;
     66    if (MODE == MODE_NONE) {
     67      fprintf (stderr, "invalid mode: %s\n", argv[N]);
     68      exit (2);
     69    }
    5970    remove_argument (N, &argc, argv);
    6071  }
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/args_parallel_client.c

    r33963 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/addstar/src/build_links.c

    r37036 r37822  
    4747
    4848    if (N >= Nmeasure) {
    49       fprintf (stderr, "overflow in init_measure_links\n");
    50       abort ();
     49      myAbort ("overflow in init_measure_links\n");
    5150    }
    5251  }
     
    102101
    103102/* 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) {
     103int add_meas_link (Average *average, off_t *next_meas, off_t Nmeasure, off_t NMEASURE) {
    105104
    106105  off_t k, m;
     
    134133}
    135134
    136 /* Missing does not carry enough information to reconstruct the links
    137    we must always save the missing table, if it exists */
    138 
    139135Measure *sort_measure (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next_meas) {
    140136
    141   off_t i, k, n, N;
     137  int i, k, n, N;
    142138  Measure *tmpmeasure;
    143139
     
    149145    average[i].measureOffset = N;
    150146    for (k = 0; k < average[i].Nmeasure; k++, N++) {
    151       if (n == -1) abort();
     147      if (n == -1) myAbortF("invalid measureOffset for ave %d, measureOffset %d, measure %d\n", i, average[i].measureOffset, k);
    152148      tmpmeasure[N] = measure[n];
    153       if (measure[n].averef != i) abort();
     149      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);
    154150      tmpmeasure[N].averef = i;
    155151      n = next_meas[n];
     
    159155  return (tmpmeasure);
    160156}
     157
     158/*******************************************************************************************/
    161159
    162160/* build the initial links assuming the table is sorted */
     
    176174      next_miss[N] = -1;
    177175      if (N >= Nmissing) {
    178         fprintf (stderr, "overflow in init_missing_links");
    179         abort ();
     176        myAbort ("overflow in init_missing_links");
    180177      }
    181178      N++;
     
    186183}
    187184
    188 off_t add_miss_link (Average *average, off_t *next_miss, off_t Nmissing) {
     185int add_miss_link (Average *average, off_t *next_miss, off_t Nmissing) {
    189186
    190187  off_t k, m;
     
    205202}
    206203
     204/* Missing does not carry enough information to reconstruct the links
     205   we must always save the missing table, if it exists */
     206
    207207Missing *sort_missing (Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss) {
    208208
     
    251251
    252252    if (N >= Nlensing) {
    253       fprintf (stderr, "overflow in init_lensing_links\n");
    254       abort ();
     253      myAbort ("overflow in init_lensing_links\n");
    255254    }
    256255    N++;
     
    307306
    308307/* average[].lensingOffset, average[].Nlensing are valid within an addstar run */
    309 off_t add_lens_link (Average *average, off_t *next_lens, off_t Nlensing, off_t NLENSING) {
     308int add_lens_link (Average *average, off_t *next_lens, off_t Nlensing, off_t NLENSING) {
    310309
    311310  off_t k, m;
     
    341340Lensing *sort_lensing (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next_lens) {
    342341
    343   off_t i, k, n, N;
     342  int i, k, n, N;
    344343  Lensing *tmplensing;
    345344
     
    352351    average[i].lensingOffset = N;
    353352    for (k = 0; k < average[i].Nlensing; k++, N++) {
    354       if (n == -1) abort();
     353      if (n == -1) myAbortF("invalid lensingOffset for ave %d, lensingOffset %d, lensing %d\n", i, average[i].lensingOffset, k);
    355354      tmplensing[N] = lensing[n];
    356       if (lensing[n].averef != i) abort();
     355      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);
    357356      tmplensing[N].averef = i;
    358357      n = next_lens[n];
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/fakeimage.c

    r37036 r37822  
    33Image *fakeimage (char *rootname, off_t *Nimage, int photcode) {
    44
    5   int i, j, Nx, Ny, Nchips;
     5  int i, Nx, Ny, Nchips;
    66  double pltscale, pixscale;
    77  double Rmin, Rmax, Dmin, Dmax;
     
    3333
    3434  /* create a mosaic distortion structure */
    35   strcpy (MOSAIC.ctype, "DEC--DIS");
     35  InitCoords (&MOSAIC, "DEC--DIS");
    3636  MOSAIC.crval1 = FAKE_RA;
    3737  MOSAIC.crval2 = FAKE_DEC;
    38  
    39   MOSAIC.crpix1 = MOSAIC.crpix2 = 0.0;
    4038 
    4139  /* mosaic 'pixels' are millimeters */
     
    4947
    5048  MOSAIC.Npolyterms = 3;
    51   for (i = 0; i < 7; i++) {
    52     MOSAIC.polyterms[i][0] = 0;
    53     MOSAIC.polyterms[i][1] = 0;
    54   }
    5549  ScanConfig (config, "DPLATE_X",   "%lf", 0, &pltscale);
    5650  MOSAIC.polyterms[3][0] = pltscale;  // L : X^3 Y^0
     
    5953  MOSAIC.polyterms[4][1] = pltscale;  // M : X^0 Y^0
    6054  MOSAIC.polyterms[6][1] = pltscale;  // M : X^2 Y^0
    61 
    62   RegisterMosaic (&MOSAIC);
    6355
    6456  /* some basic data about the chisp */
     
    8577    strcpy (image[i+1].name, name);
    8678
    87     strcpy (image[i+1].coords.ctype, "DEC--WRP");
     79    InitCoords (&image[i+1].coords, "DEC--WRP");
    8880   
    8981    image[i+1].coords.crval1 = dX*pixscale;
    9082    image[i+1].coords.crval2 = dY*pixscale;
    91    
    92     image[i+1].coords.crpix1 = image[i+1].coords.crpix2 = 0.0;
     83
    9384    image[i+1].coords.cdelt1 = image[i+1].coords.cdelt2 = pixscale;
    9485
    95     image[i+1].coords.pc1_1 = 1.0;
    96     image[i+1].coords.pc1_2 = 0.0;
    97     image[i+1].coords.pc2_1 = 0.0;
    98     image[i+1].coords.pc2_2 = 1.0;
    99 
    100     image[i+1].coords.Npolyterms = 0;
    101     for (j = 0; j < 7; j++) {
    102       image[i+1].coords.polyterms[j][0] = 0;
    103       image[i+1].coords.polyterms[j][1] = 0;
    104     }
     86    image[i+1].coords.mosaic = &MOSAIC;
    10587
    10688    image[i+1].sidtime  = 0.0;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/find_matches.c

    r37036 r37822  
    5353   * coordops.update.c).  We use the center of the region (catalog) for crval1,2.
    5454   */
     55  InitCoords (&tcoords, "DEC--ARC");
    5556  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    5657  if (region[0].Dmax < 90) {
     
    5960    tcoords.crval2 = 90.0;
    6061  }
    61   tcoords.crpix1 = 0;
    62   tcoords.crpix2 = 0;
    6362  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    64   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    65   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    66   tcoords.Npolyterms = 1;
    67   strcpy (tcoords.ctype, "DEC--ARC");
    6863
    6964  /* build spatial index (RA sort) referencing input array sequence */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/find_matches_closest.c

    r37036 r37822  
    5353   * far from the projection pole. We use the center of the region (catalog) for crval1,2.
    5454   */
     55  InitCoords (&tcoords, "DEC--ARC");
    5556  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    5657  if (region[0].Dmax < 90) {
     
    5960    tcoords.crval2 = 90.0;
    6061  }
    61   tcoords.crpix1 = 0;
    62   tcoords.crpix2 = 0;
    6362  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    64   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    65   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    66   tcoords.Npolyterms = 1;
    67   strcpy (tcoords.ctype, "DEC--ARC");
    6863
    6964  /* build spatial index (RA sort) referencing input array sequence */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/find_matches_closest_refstars.c

    r37036 r37822  
    4747   * far from the projection pole. We use the center of the region (catalog) for crval1,2.
    4848   */
     49  InitCoords (&tcoords, "DEC--ARC");
    4950  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    5051  if (region[0].Dmax < 90) {
     
    5354    tcoords.crval2 = 90.0;
    5455  }
    55   tcoords.crpix1 = 0.0;
    56   tcoords.crpix2 = 0.0;
    5756  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    58   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    59   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    60   tcoords.Npolyterms = 0;
    61   strcpy (tcoords.ctype, "DEC--ARC");
    6257 
    6358  /* build spatial index (RA sort) referencing input array sequence */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/find_matches_refstars.c

    r37036 r37822  
    5151  /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
    5252  /* reference for coords is catalog center */
     53  InitCoords (&tcoords, "DEC--ZEA");
    5354  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    5455  tcoords.crval2 = 0.5*(region[0].Dmin + region[0].Dmax);
    55   tcoords.crpix1 = tcoords.crpix2 = 0.0;
    5656  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    57   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    58   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    59   strcpy (tcoords.ctype, "DEC--ZEA");
    60   tcoords.Npolyterms = 0;
    6157 
    6258  for (i = 0; i < Nstars; i++) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/find_missing.c

    r10937 r37822  
    1414    REALLOCATE (catalog[0].missing, Missing, NMISS);
    1515  }
    16   if (!FindMosaicForImage (overlap, Noverlap, j)) continue;
    1716  if (!in_image (catalog[0].average[Nave].R, catalog[0].average[Nave].D, &overlap[j])) continue;
    1817  add_miss_link (&catalog[0].average[Nave], next_miss, Nmiss);
     
    2726/* add reference for undetected catalog stars */
    2827/* XXX allow this option only for single images? */
    29 if (!strcmp (&image[0].coords.ctype[4], "-WRP")) RegisterMosaic (mosaic);
     28if (!strcmp (&image[0].coords.ctype[4], "-WRP")) image[0].coords = mosaic;
    3029for (j = 0; (j < Nave) && !options.skip_missed; j++) {
    3130  n = N2[j];
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/findskycell.c

    r37036 r37822  
    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;
     
    217217  ALLOCATE (tree.Xo,   double *, tree.Nzone);
    218218  ALLOCATE (tree.Yo,   double *, tree.Nzone);
    219   ALLOCATE (tree.dX,      int *, tree.Nzone);
    220   ALLOCATE (tree.dY,      int *, tree.Nzone);
     219  ALLOCATE (tree.dX,    float *, tree.Nzone);
     220  ALLOCATE (tree.dY,    float *, tree.Nzone);
    221221  ALLOCATE (tree.cell,    int *, tree.Nzone);
    222222  ALLOCATE (tree.name,  char **, tree.Nzone);
     
    251251    ALLOCATE (tree.Xo[zone],   double, tree.NBAND[zone]);
    252252    ALLOCATE (tree.Yo[zone],   double, tree.NBAND[zone]);
    253     ALLOCATE (tree.dX[zone],      int, tree.NBAND[zone]);
    254     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]);
    255255    ALLOCATE (tree.cell[zone], int,    tree.NBAND[zone]);
    256256    ALLOCATE (tree.name[zone], char *, tree.NBAND[zone]);
     
    260260      tree.Xo[zone][band] = NAN;
    261261      tree.Yo[zone][band] = NAN;
    262       tree.dX[zone][band] = -1;
    263       tree.dY[zone][band] = -1;
     262      tree.dX[zone][band] = NAN;
     263      tree.dY[zone][band] = NAN;
    264264      tree.cell[zone][band] = -1;
    265265      ALLOCATE (tree.name[zone][band], char, BOUNDARY_TREE_NAME_LENGTH);
     
    286286      REALLOCATE (tree.Xo[zone],   double, tree.NBAND[zone]);
    287287      REALLOCATE (tree.Yo[zone],   double, tree.NBAND[zone]);
    288       REALLOCATE (tree.dX[zone],      int, tree.NBAND[zone]);
    289       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]);
    290290      REALLOCATE (tree.cell[zone],    int, tree.NBAND[zone]);
    291291      REALLOCATE (tree.name[zone], char *, tree.NBAND[zone]);
     
    295295        tree.Xo[zone][band] = NAN;
    296296        tree.Yo[zone][band] = NAN;
    297         tree.dX[zone][band] = -1;
    298         tree.dY[zone][band] = -1;
     297        tree.dX[zone][band] = NAN;
     298        tree.dY[zone][band] = NAN;
    299299        tree.cell[zone][j] = -1;
    300300        ALLOCATE (tree.name[zone][j], char, BOUNDARY_TREE_NAME_LENGTH);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/loadsupercos_plates.c

    r36485 r37822  
    9292    image[Nimage].Radius = NAN;
    9393   
    94     snprintf (image[Nimage].name, 121, "SCOS.%02d.%06d", survey_id, plate_id);
     94    snprintf (image[Nimage].name, DVO_IMAGE_NAME_LEN, "SCOS.%02d.%06d", survey_id, plate_id);
    9595    image[Nimage].imageID = Nimage + 1;
    9696    image[Nimage].externID = plate_id;
     
    118118
    119119    // for now, we define a fake coordinate system based on the boresite center
    120     strcpy (image[Nimage].coords.ctype, "DEC--TAN");
     120    InitCoords (&image[Nimage].coords, "DEC--TAN");
    121121   
    122122    image[Nimage].coords.crval1 = RAo;
     
    126126    image[Nimage].coords.crpix2 = 0.5*image[Nimage].NY;
    127127    image[Nimage].coords.cdelt1 = image[Nimage].coords.cdelt2 = scale;
    128 
    129     image[Nimage].coords.pc1_1 = 0.0;
    130     image[Nimage].coords.pc1_2 = 1.0;
    131     image[Nimage].coords.pc2_1 = 1.0;
    132     image[Nimage].coords.pc2_2 = 0.0;
    133 
    134     image[Nimage].coords.Npolyterms = 0;
    135     memset (image[Nimage].coords.polyterms, 0, 2*7*sizeof(float));
    136128
    137129    Nimage ++;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/loadwise.c

    r33963 r37822  
    4040  for (i = 1; i < argc; i++) {
    4141      fprintf (stderr, "loading %s\n", argv[i]);
    42       loadwise_rawdata (skylist, argv[i], options, ALLSKY);
     42      loadwise_rawdata (skylist, argv[i], options);
    4343  }
    4444  exit (0);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/loadwise_rawdata.c

    r34088 r37822  
    1010# define DEBUG 0
    1111
    12 int loadwise_rawdata (SkyList *skytable, char *filename, AddstarClientOptions options, int ALLSKY) {
     12int loadwise_rawdata (SkyList *skytable, char *filename, AddstarClientOptions options) {
    1313 
    1414  int i, j, verbose;
     
    159159        stars[Nstars+3][0].average.D = tstars[j].D;
    160160       
    161         if (ALLSKY) {
    162           loadwise_star_allsky (&stars[Nstars], &buffer[offset], Nbyte - offset);
    163         } else {
    164           loadwise_star_prelim (&stars[Nstars], &buffer[offset], Nbyte - offset);
     161        switch (MODE) {
     162          case MODE_PRELIM:
     163            loadwise_star_prelim (&stars[Nstars], &buffer[offset], Nbyte - offset);
     164            break;
     165          case MODE_ALLSKY:
     166            loadwise_star_allsky (&stars[Nstars], &buffer[offset], Nbyte - offset);
     167            break;
     168          case MODE_ALLWISE:
     169          default:
     170            // loadwise_star_allwise (&stars[Nstars], &buffer[offset], Nbyte - offset);
     171            break;
    165172        }
    166173
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/loadwise_star_full.c

    r33963 r37822  
    1010int setWISE_sat_flag (Stars *star, char *ptr);
    1111int setWISE_blend_flag (Stars **star, char *ptr);
     12
     13// fill in the data for a WISE quad star.  takes a pointer to the start of the line the
     14// RA and DEC have already been set
     15int loadwise_star_allwise (Stars **star, char *line, int Nmax) {
     16
     17  int i;
     18  char *ptr;
     19
     20  if (line == NULL) Shutdown ("format error in WISE");
     21
     22  ptr = line;
     23
     24  // I can assign dRA and dDEC to dX and dY if I can consistently set posangle and pltscale
     25  star[0][0].measure.posangle = 0.0;
     26  star[0][0].measure.pltscale = 1.0;
     27
     28  ptr = skipNbounds (ptr, '|', 3, Nmax); // skip: desig, ra, dec,
     29  star[0][0].measure.dXccd = ToShortPixels(strtod (ptr, NULL)); // sig_ra
     30  ptr = nextWISEfield (ptr);
     31  star[0][0].measure.dYccd = ToShortPixels(strtod (ptr, NULL)); // sig_dec
     32  ptr = nextWISEfield (ptr);
     33
     34  // we only know a single set of values for all 4 bands
     35  for (i = 1; i < 4; i++) {
     36      star[i][0].measure.dXccd    = star[0][0].measure.dXccd;
     37      star[i][0].measure.dYccd    = star[0][0].measure.dYccd;
     38      star[i][0].measure.posangle = star[0][0].measure.posangle;
     39      star[i][0].measure.pltscale = star[0][0].measure.pltscale;
     40  }
     41  ptr = skipNbounds (ptr, '|', 5, Nmax); // skip: sig_radec, glon, glat, elon, elat
     42
     43  star[0][0].measure.Xccd = strtod (ptr, NULL); // wx
     44  ptr = nextWISEfield (ptr); // skip wx
     45  star[0][0].measure.Yccd = strtod (ptr, NULL); // wy
     46  ptr = nextWISEfield (ptr); // skip wy
     47
     48  for (i = 1; i < 4; i++) {
     49      star[i][0].measure.Xccd    = star[0][0].measure.Xccd;
     50      star[i][0].measure.Yccd    = star[0][0].measure.Yccd;
     51  }
     52  ptr = skipNbounds (ptr, '|', 4, Nmax); // skip: cntr, source_id, coadd_id, src
     53
     54  // W1
     55  for (i = 0; i < 4; i++) {
     56    char *endpoint;
     57      star[i][0].measure.M  = strtod (ptr, &endpoint); // w?mpro
     58      if (endpoint == ptr) {
     59        star[i][0].measure.M  = NAN;
     60      }
     61      ptr = nextWISEfield (ptr);
     62      star[i][0].measure.dM = strtod (ptr, &endpoint); // w?sigmpro
     63      if (endpoint == ptr) {
     64        star[i][0].measure.dM  = NAN;
     65      }
     66      ptr = skipNbounds (ptr, '|', 2, Nmax); // skip: w?sigmpro, w?snr
     67      star[i][0].measure.psfChisq = strtod (ptr, NULL); // w?rchi2
     68      ptr = nextWISEfield (ptr); // skip : w1rchi2
     69
     70      // init the photFlags field
     71      star[i][0].measure.photFlags = 0;
     72  }
     73
     74  ptr = nextWISEfield (ptr); // skip: rchi2
     75
     76  // set blend flags for all 4 measures
     77  setWISE_blend_flag (star, ptr); // nb & na both used here
     78  ptr = skipNbounds (ptr, '|', 2, Nmax); // skip: nb, na
     79
     80  for (i = 0; i < 4; i++) {
     81      setWISE_sat_flag (star[i], ptr); // w1sat
     82      ptr = nextWISEfield (ptr);
     83  }
     84  ptr = nextWISEfield (ptr); // skip satnum
     85
     86  ptr = skipNbounds (ptr, '|', 15, Nmax); // skip pm info
     87
     88  for (i = 0; i < 4; i++) {
     89      setWISE_cc_flag (star[i], ptr[i]); // cc_flags
     90  }
     91  ptr = nextWISEfield (ptr); // skip cc_flags
     92  ptr = nextWISEfield (ptr); // skip rel
     93
     94  // set ext flags for all 4 measures
     95  setWISE_ext_flag_allsky (star, ptr[0]); // ext_flg
     96  ptr = nextWISEfield (ptr); // skip ext_flags
     97
     98  for (i = 0; i < 4; i++) {
     99      setWISE_var_flag_allsky (star[i], ptr[i]); // var_flg
     100  }
     101  ptr = nextWISEfield (ptr); // skip var_flags
     102
     103  for (i = 0; i < 4; i++) {
     104      setWISE_ph_qual (star[i], ptr[i]); // ph_qual
     105  }
     106
     107  ptr = skipNbounds (ptr, '|', 158, Nmax); // skip: det_bit, moon_lev, w?nm, w?m, w?cov, etc, etc.
     108  // w?frtr dropped, (-4), use_src, best_use_cntr, ngrp added (+3), w?dmag dropped, w?k added,
     109
     110  for (i = 0; i < 4; i++) {
     111    ptr = skipNbounds (ptr, '|', 8, Nmax); // skip: w?magp, w?sigp1,2, w?dmag, w?ndf, w?m1q, w?mjdmin, w?mjdmax
     112
     113    // double mjdmin = strtod (ptr, NULL); // mjd min
     114    // ptr = nextWISEfield (ptr); // skip
     115    // double mjdmax = strtod (ptr, NULL); // mjd max
     116    // ptr = nextWISEfield (ptr); // skip mjd max
     117    double mjdmean = strtod (ptr, NULL); // mjd mean
     118    ptr = nextWISEfield (ptr); // skip mjd mean
     119
     120    // fprintf (stderr, "w%d mjd: %f\n", i, mjdmean);
     121
     122    // the release is based on data taken in the period 14 January 2010 to 29 April 2010
     123    if (mjdmean == 0.0) {
     124      star[i][0].measure.t = 0;
     125    } else {
     126      star[i][0].measure.t = ohana_mjd_to_sec (mjdmean);
     127    }
     128  }
     129
     130  star[0][0].measure.photcode  = WISE_W1;
     131  star[0][0].measure.detID   = 0;
     132  star[0][0].measure.imageID = 0;
     133
     134  star[1][0].measure.photcode  = WISE_W2;
     135  star[1][0].measure.detID   = 0;
     136  star[1][0].measure.imageID = 0;
     137
     138  star[2][0].measure.photcode  = WISE_W3;
     139  star[2][0].measure.detID   = 0;
     140  star[2][0].measure.imageID = 0;
     141
     142  star[3][0].measure.photcode  = WISE_W4;
     143  star[3][0].measure.detID   = 0;
     144  star[3][0].measure.imageID = 0;
     145
     146  return TRUE;
     147}
    12148
    13149// there are slight format differences between the prelim data dump and the allsky data dump:
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/mkcmf.c

    r37036 r37822  
    3131static Coords coords;
    3232
     33static char reserved[] =  "Reserved space.  This line can be used to add a new FITS card.";
     34
    3335int main (int argc, char **argv) {
    3436
     
    198200   
    199201  /* bore site center guess */
    200   strcpy (coords.ctype, "DEC--TAN");
     202  InitCoords (&coords, "DEC--TAN");
    201203  coords.crval1 = RA;
    202204  coords.crval2 = DEC;
     
    206208  coords.cdelt1 = 0.25/3600.0;
    207209  coords.cdelt2 = 0.25/3600.0;
    208 
    209   coords.pc1_1  = 1;
    210   coords.pc2_2  = 1;
    211   coords.pc1_2  = 0;
    212   coords.pc2_1  = 0;
    213   coords.Npolyterms = 1;
    214210
    215211  // load stars and generate complete output fields
     
    298294  gfits_modify (&header, "NASTRO",   "%d", 1, 100);
    299295
    300   if (imageID == -1) imageID = 1000.0*drand48();
    301   if (sourceID == -1) sourceID = 100.0*drand48();
     296  if (imageID == -1) imageID = 100000.0*drand48();
     297  if (sourceID == -1) sourceID = 1000.0*drand48();
    302298  gfits_modify (&header, "IMAGEID",  "%d", 1, imageID);
    303299  gfits_modify (&header, "SOURCEID", "%d", 1, sourceID);
     
    305301  PutCoords (&coords, &header);
    306302  gfits_modify (&header, "EXTNAME",   "%s", 1, exthead);
     303
     304  int i;
     305  for (i = 1; i < 32; i++) {
     306    gfits_modify_alt (&header, "COMMENT", "%C", i, reserved);
     307  }
    307308
    308309  ftable.header = &theader;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/resort_catalog.c

    r37036 r37822  
    44void resort_catalog_measure (Catalog *catalog);
    55void resort_catalog_lensing (Catalog *catalog);
     6void resort_catalog_starpar (Catalog *catalog);
    67
    78void resort_catalog_old (Catalog *catalog) {
    89
    9   off_t *next_meas;
    10   off_t Naves, Nmeas;
     10  off_t *next_meas, *next_lens;
     11  off_t Naves, Nmeas, Nlens;
    1112
    1213  if (catalog[0].sorted == TRUE) return;
     
    1617  /* internal counters */
    1718  Nmeas = catalog[0].Nmeasure;
     19  Nlens = catalog[0].Nlensing;
    1820  Naves = catalog[0].Naverage;
    1921 
    2022  /* set up pointers for linked list of measure, missing */
    2123  next_meas = build_measure_links (catalog[0].average, Naves, catalog[0].measure, Nmeas);
     24  next_lens = build_lensing_links (catalog[0].average, Naves, catalog[0].lensing, Nlens);
    2225
    2326  catalog[0].sorted = TRUE;
    2427  catalog[0].measure = sort_measure (catalog[0].average, Naves, catalog[0].measure, Nmeas, next_meas);
     28  catalog[0].lensing = sort_lensing (catalog[0].average, Naves, catalog[0].lensing, Nlens, next_lens);
    2529
    2630  MARKTIME ("  match time %9.4f sec for %7lld measures, %6lld average\n", dtime, (long long) Nmeas, (long long) Naves);
     
    3539  resort_catalog_measure (catalog);
    3640  resort_catalog_lensing (catalog);
     41  resort_catalog_starpar (catalog);
    3742}
    3843
     
    7984      myAssert(average[averageSeq[i]].catID == measure[measureSeq[i]].catID, "object / detection mismatch");
    8085# if (1)
    81       myAssert(average[averageSeq[i]].objID == measure[measureSeq[i]].objID, "object / detection mismatch");
     86      // myAssert(average[averageSeq[i]].objID == measure[measureSeq[i]].objID, "object / detection mismatch");
     87      // check if the objID is correct. if not, check if it is byte-swapped (this has happened) and repair if so. 
     88      // otherwise, abort
     89      if (average[averageSeq[i]].objID != measure[measureSeq[i]].objID) {
     90        fprintf (stderr, "object / detection mismatch average.objID = %d, measure.objID = %d, catID: %d, detID: %d",
     91                 average[averageSeq[i]].objID, measure[measureSeq[i]].objID,
     92                 measure[measureSeq[i]].catID, measure[measureSeq[i]].detID);
     93        int objIDalt = measure[measureSeq[i]].objID;
     94        char *byte = (char *) &objIDalt;
     95        char tmp;
     96        tmp = byte[0]; byte[0] = byte[3]; byte[3] = tmp;
     97        tmp = byte[1]; byte[1] = byte[2]; byte[2] = tmp;
     98        if (average[averageSeq[i]].objID == objIDalt) {
     99          fprintf (stderr, "objID is byte-swapped, repairing\n");
     100          measure[measureSeq[i]].objID = average[averageSeq[i]].objID; // XXX I don't really like this...
     101        } else if (measure[measureSeq[i]].objID == 0) {
     102          fprintf (stderr, "objID is 0, repairing\n");
     103          measure[measureSeq[i]].objID = average[averageSeq[i]].objID; // XXX I don't really like this...
     104        } else {
     105          myAbort ("objID is NOT byte-swapped, aborting\n");
     106        }
     107      }
    82108# else
    83109      // for reasons I do not understand, the mini dvodbs generated on stsci1X had a handful of detections with an inconsistency between averef and objID. 
     
    311337}
    312338
     339void resort_catalog_starpar (Catalog *catalog) {
     340
     341  off_t Naverage, Nstarpar;
     342  StarPar *starpar;
     343  Average *average;
     344  off_t i, j, N, currentAve;
     345
     346  off_t *starparSeq = NULL;
     347  off_t *averageSeq = NULL;
     348  StarPar *starparTMP = NULL;
     349
     350  // struct timeval start, stop;
     351  // gettimeofday (&start, NULL);
     352
     353  /* internal counters */
     354  Nstarpar = catalog[0].Nstarpar;
     355  Naverage = catalog[0].Naverage;
     356
     357  if (!Nstarpar) return;
     358
     359  starpar = catalog[0].starpar;
     360  average = catalog[0].average;
     361 
     362  // we have a table of average objects and an unsorted table of measurements.  each measurement
     363  // has a reference to the average object sequence (as well as an ID)
     364  // starpar[i].averef -> average[averef]
     365  // starpar[i].objID = average[averef].objID
     366  // starpar[i].catID = average[averef].catID
     367
     368  // we want a sorted starpar array with all averef entries in sequence
     369
     370  ALLOCATE (starparSeq, off_t,   Nstarpar);
     371  ALLOCATE (averageSeq, off_t,   Nstarpar);
     372
     373  for (i = 0; i < Nstarpar; i++) {
     374    starparSeq[i] = i;
     375    averageSeq[i] = starpar[i].averef;
     376   
     377    if (catalog[0].catformat >= DVO_FORMAT_PS1_V1) {
     378      // earlier formats did not carry the objID or catID, so they are not available (we could assign on load, but we don't)
     379      myAssert(average[averageSeq[i]].catID == starpar[starparSeq[i]].catID, "object / detection mismatch");
     380# if (1)
     381      myAssert(average[averageSeq[i]].objID == starpar[starparSeq[i]].objID, "object / detection mismatch");
     382# else
     383      // for reasons I do not understand, the mini dvodbs generated on stsci1X had a handful of detections with an inconsistency between averef and objID. 
     384      // 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
     385      if (average[averageSeq[i]].objID != starpar[starparSeq[i]].objID) {
     386        fprintf (stderr, "R");
     387        starpar[starparSeq[i]].objID = average[averageSeq[i]].objID; // XXX I don't really like this...
     388      }
     389# endif
     390    }
     391  }
     392 
     393  // check that averageSeq is now in order
     394  // for (i = 1; i < Nstarpar; i++) {
     395  //   if (averageSeq[i] < averageSeq[i-1]) {
     396  //     fprintf (stderr, "%d ", (int) i);
     397  //   }
     398  // }
     399  // fprintf (stderr, "\n");
     400
     401  SortAveMatch(starparSeq, averageSeq, Nstarpar);
     402  // MARKTIME("sort : %f sec\n", dtime);
     403
     404  // check that averageSeq is now in order
     405  // for (i = 1; i < Nstarpar; i++) {
     406  //   if (averageSeq[i] < averageSeq[i-1]) {
     407  //     fprintf (stderr, "%d ", (int) i);
     408  //   }
     409  // }
     410  // fprintf (stderr, "\n");
     411
     412  // copy the starpar entries in the sorted order
     413  ALLOCATE (starparTMP, StarPar, Nstarpar);
     414  for (i = 0; i < Nstarpar; i++) {
     415    j = starparSeq[i];
     416    starparTMP[i] = starpar[j];
     417  }
     418  // MARKTIME("assign starpar : %f sec\n", dtime);
     419
     420  // update the values of average.starparOffset and average.Nstarpar
     421  FREE(starpar);
     422  catalog[0].starpar = starparTMP;
     423
     424  N = 0;
     425  currentAve = averageSeq[0];
     426  average[currentAve].starparOffset = 0;
     427  for (i = 0; i < Nstarpar; i++) {
     428    if (averageSeq[i] != currentAve) {
     429      // we have hit the next entry in the list
     430      average[currentAve].Nstarpar = N;
     431      N = 0;
     432      currentAve = averageSeq[i];
     433      average[currentAve].starparOffset = i;
     434    }
     435    N++;
     436  }
     437  // N++;
     438  average[currentAve].Nstarpar = N;
     439  // MARKTIME("update Nstarpar : %f sec\n", dtime);
     440
     441  int NstarparTotal = 0;
     442  int starparOffsetOK = TRUE;
     443  for (i = 0; i < Naverage; i++) {
     444    NstarparTotal += catalog[0].average[i].Nstarpar;
     445    if (VERBOSE && !(NstarparTotal <= catalog[0].Nstarpar)) {
     446      fprintf (stderr, "too few starpar: %d %d %d\n", (int) i, NstarparTotal, (int) catalog[0].Nstarpar);
     447    }
     448    starparOffsetOK &= (catalog[0].average[i].starparOffset < catalog[0].Nstarpar);
     449    if (VERBOSE && !(catalog[0].average[i].starparOffset < catalog[0].Nstarpar)) {
     450      fprintf (stderr, "offset too large: %d %d %d\n", (int) i, catalog[0].average[i].Nstarpar, (int) catalog[0].Nstarpar);
     451    }
     452    starparOffsetOK &= (catalog[0].average[i].starparOffset + catalog[0].average[i].Nstarpar <= catalog[0].Nstarpar);
     453    if (VERBOSE && !(catalog[0].average[i].starparOffset + catalog[0].average[i].Nstarpar <= catalog[0].Nstarpar)) {
     454      fprintf (stderr, "orrset + Nstarpar too large: %d + %d > %d %d\n", (int) i, catalog[0].average[i].starparOffset, catalog[0].average[i].Nstarpar, (int) catalog[0].Nstarpar);
     455    }
     456  }
     457
     458  if (!starparOffsetOK) {
     459    fprintf (stderr, "ERROR: catalog %s has an invalid starparOffset\n", catalog[0].filename);
     460  }
     461
     462  if (NstarparTotal != catalog[0].Nstarpar) {
     463    fprintf (stderr, "ERROR: catalog %s has an invalid Nstarpar\n", catalog[0].filename);
     464  }
     465
     466  // MARKTIME("  match time %9.4f sec for %7lld starpars, %6lld average\n", dtime, (long long) Nstarpar, (long long) Naverage);
     467
     468  catalog[0].sorted = TRUE;
     469
     470  FREE (starparSeq);
     471  FREE (averageSeq);
     472
     473  return;
     474}
     475
    313476// sort the measure or lensing Sequence based on the average Sequence entries
    314477void SortAveMatch (off_t *MEAS, off_t *AVE, off_t N) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/src/resort_threaded.c

    r37036 r37822  
    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
     
    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/ipp-pv3-20140717-merge/Ohana/src/addstar/src/resort_unthreaded.c

    r35142 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/addstar/src/sky_tessalation.c

    r36485 r37822  
    581581
    582582  memset (rectangle, 0, sizeof(SkyRectangle));
     583
     584  InitCoords (&rectangle[0].coords, "DEC--TAN");
     585
    583586  rectangle[0].coords.crval1 = CENTER_RA;
    584587  rectangle[0].coords.crval2 = CENTER_DEC;
     
    609612  rectangle[0].coords.cdelt2 = SCALE / 3600.0;
    610613
    611   strcpy (rectangle[0].coords.ctype, "DEC--TAN");
    612 
    613614  rectangle[0].NX = NX;
    614615  rectangle[0].NY = NY;
     
    699700  for (i = 0; i < nRA; i++) {
    700701    memset (&ring[i], 0, sizeof(SkyRectangle));
    701     memset (&ring[i].coords, 0, sizeof(Coords));
     702
     703    InitCoords (&ring[i].coords, "DEC--TAN");
    702704    ring[i].coords.crval1 = i*dRA;
    703705    ring[i].coords.crval2 = dec;
    704706
    705707    ring[i].coords.pc1_1 = +1.0 * X_PARITY;
    706     ring[i].coords.pc1_2 = +0.0;
    707     ring[i].coords.pc2_1 = -0.0;
    708     ring[i].coords.pc2_2 = +1.0;
    709708 
    710709    // range values are in projected degrees
     
    718717    ring[i].coords.cdelt1 = SCALE / 3600.0;
    719718    ring[i].coords.cdelt2 = SCALE / 3600.0;
    720 
    721     strcpy (ring[i].coords.ctype, "DEC--TAN");
    722719
    723720    ring[i].NX = NX*(1.0 + PADDING);
     
    771768
    772769      memset (&ring[N], 0, sizeof(SkyRectangle));
    773       memset (&ring[N].coords, 0, sizeof(Coords));
     770      InitCoords (&ring[N].coords, "DEC--TAN");
    774771
    775772      ring[N].coords.crval1 = ra / d2r;
     
    779776
    780777      ring[N].coords.pc1_1 = +1.0 * X_PARITY;
    781       ring[N].coords.pc1_2 = +0.0;
    782       ring[N].coords.pc2_1 = -0.0;
    783       ring[N].coords.pc2_2 = +1.0;
    784778 
    785779      // range values are in projected degrees
     
    793787      ring[N].coords.cdelt1 = SCALE / 3600.0;
    794788      ring[N].coords.cdelt2 = SCALE / 3600.0;
    795 
    796       strcpy (ring[N].coords.ctype, "DEC--TAN");
    797789
    798790      ring[N].NX = NX*(1.0 + PADDING);
     
    10991091
    11001092  ALLOCATE (refcoords, Coords, 1);
    1101   refcoords[0].crval1 = refcoords[0].crval2 = 0.0;
    1102   refcoords[0].crpix1 = refcoords[0].crpix2 = 0.0;
     1093  InitCoords (refcoords, "DEC--TAN");
    11031094  refcoords[0].cdelt1 = refcoords[0].cdelt2 = scale / 3600;
    1104   refcoords[0].pc1_1 = refcoords[0].pc2_2 = 1.0;
    1105   refcoords[0].pc1_2 = refcoords[0].pc2_1 = 0.0;
    1106   refcoords[0].Npolyterms = 0;
    1107   memset (refcoords[0].polyterms, 0, 14*sizeof(float));
    1108   strcpy (refcoords[0].ctype, "DEC--TAN");
    11091095  return (TRUE);
    11101096}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/addstar/test/relphot.parallel.dvo

    r33653 r37822  
    2525  if (not($?VERBOSE)) set VERBOSE = 0
    2626
    27   # images are loaded into dvo with GPC1 photcodes, so we need to get the nominal zps for those filters
    28   $zpt_nominal:g = 24.58
    29   $zpt_nominal:r = 24.80
    30   $zpt_nominal:i = 24.74
    31   $zpt_nominal:z = 24.26
    32   $zpt_nominal:y = 23.41
    33 
    34   # klam is negative, so klam*(airmass - 1) increase the zero point
    35   $klam_nominal:g = -0.15
    36   $klam_nominal:r = -0.10
    37   $klam_nominal:i = -0.04
    38   $klam_nominal:z = -0.03
    39   $klam_nominal:y = -0.03
     27# images are loaded into dvo with GPC1 photcodes, so we need to get the nominal zps for those filters
     28# $zpt_nominal:g = 24.58
     29# $zpt_nominal:r = 24.80
     30# $zpt_nominal:i = 24.74
     31# $zpt_nominal:z = 24.26
     32# $zpt_nominal:y = 23.41
     33
     34# klam is negative, so klam*(airmass - 1) increase the zero point
     35# $klam_nominal:g = -0.15
     36# $klam_nominal:r = -0.10
     37# $klam_nominal:i = -0.04
     38# $klam_nominal:z = -0.03
     39# $klam_nominal:y = -0.03
     40
     41  $zpt_nominal:g = 24.563; $klam_nominal:g = -0.147
     42  $zpt_nominal:r = 24.750; $klam_nominal:r = -0.085
     43  $zpt_nominal:i = 24.611; $klam_nominal:i = -0.044
     44  $zpt_nominal:z = 24.250; $klam_nominal:z = -0.033
     45  $zpt_nominal:y = 23.320; $klam_nominal:y = -0.073
    4046
    4147  # we have two sets of images: ubercaled and not-ubercaled
     
    111117  mksequence $fileroot $catdir
    112118  for i 0 mjd_nc[]
    113     ckexposure $catdir mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i raw
     119    ckexposure $catdir mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i raw 0
    114120  end
    115121
     
    121127
    122128  # run relphot on the serial db and check that the images now match the expected values
    123   exec relphot g,r,i -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -keep-ubercal -D IMAGE_OFFSET 0.5 -update >& log.relphot.s0
     129  exec relphot -images g,r,i -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -D IMAGE_OFFSET 0.5 -update >& log.relphot.s0
    124130
    125131  for i 0 mjd_nc[]
     
    128134    # matching the mean zp of photometric data, which we calculate in
    129135    # 'init'
    130     ckexposure $catdir mjd_nc[$i] $zpt_nc_$filt_nc:$i exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc
     136    ckexposure $catdir mjd_nc[$i] $zpt_nc_$filt_nc:$i exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc 0
    131137  end
    132138
    133139  # run relphot on the parallel db and check that the images now match the expected values
    134   exec relphot -parallel g,r,i -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir.p0 -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -keep-ubercal -D IMAGE_OFFSET 0.5 -update >& log.relphot.p0
    135 
    136   exec dvodist -in $catdir.p0 >& log.dvodist.in
     140  exec relphot -images -parallel g,r,i -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir.p0 -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -D IMAGE_OFFSET 0.5 -update >& log.relphot.p0
    137141
    138142  for i 0 mjd_nc[]
     
    141145    # matching the mean zp of photometric data, which we calculate in
    142146    # 'init'
    143     ckexposure $catdir.p0 mjd_nc[$i] $zpt_nc_$filt_nc:$i exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc
     147    ckexposure $catdir.p0 mjd_nc[$i] $zpt_nc_$filt_nc:$i exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc 1
    144148  end
    145149
     
    148152
    149153macro ckexposure
    150   if ($0 != 8)
    151     echo "ckexposure (catdir) (mjd) (zpt) (exptime) (airmass) (filter) (mode)"
     154  if ($0 != 9)
     155    echo "ckexposure (catdir) (mjd) (zpt) (exptime) (airmass) (filter) (mode) (isParallel)"
    152156    echo "  mode == raw or corr"
    153157    break
     
    163167  $FILTER      = $6
    164168  $MODE        = $7
     169  $PARALLEL    =
     170  if ($8)
     171    $PARALLEL = "-parallel"
     172  end
    165173
    166174  # XXX need a function to extract the nominal zpt for a given filter / photcode from the db
     
    182190
    183191  skyregion {$RA_CENTER - 0.2/dcos($DEC_CENTER)} {$RA_CENTER + 0.2/dcos($DEC_CENTER)} {$DEC_CENTER - 0.2} {$DEC_CENTER + 0.2}
    184   mextract ra dec mag xccd yccd where (abs(time - $MJD_IMAGE) < 0.0001)
     192  mextract $PARALLEL ra dec mag xccd yccd where (abs(time - $MJD_IMAGE) < 0.0001)
    185193  if (not(ra[]))
    186194    echo "no matching data for MJD = $MJD_IMAGE"
     
    344352    # the fake images have inconsistent ra,dec and airmass,sidtime values
    345353    if ($VERBOSE) echo addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass
    346     exec addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass >& /dev/null
     354    exec addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass >& log.addstar
    347355    # costs 10/36 sec / chip
    348356  end
     
    432440  $catdir = $tmp1/$tmp2
    433441
     442  if ($VERBOSE) echo rsync -auv $catdir/ $catdir.p0/
    434443  exec rsync -auv $catdir/ $catdir.p0/ >& log.rsync
    435444  mkdir $catdir.d1
     
    442451  exec echo "3 $hostname $catdir.d3" >> $catdir.p0/HostTable.dat
    443452
     453  if ($VERBOSE) echo dvodist -out $catdir.p0
    444454  exec dvodist -out $catdir.p0 >& log.dvodist.out
    445455end
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/checkastro/src/ImageOps.c

    r36833 r37822  
    130130  }
    131131
    132   BuildChipMatch (image, Nimage);
    133 
    134132  char output[128];
    135133  snprintf (output, 128, "checkastrom.%+3.0f.%+3.0f.%03.0f.%03.0f.dat", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
     
    148146    name = GetPhotcodeNamebyCode (image[i].photcode);
    149147
    150     off_t myMosaic = FindMosaicForImage (image, Nimage, i);
    151 
    152148    /* only check exposure center */
    153149    double Rexp = NAN, Dexp = NAN, Rccd = NAN, Dccd = NAN;
    154150
    155     if (myMosaic) {
    156       myMosaic --;
    157       XY_to_RD (&Rccd, &Dccd, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
    158       XY_to_RD (&Rexp, &Dexp, 0.0, 0.0, &image[myMosaic].coords);
    159     }
     151    XY_to_RD (&Rccd, &Dccd, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
     152    XY_to_RD (&Rexp, &Dexp, 0.0, 0.0, &image[i].parent->coords);
    160153
    161154    char *date = ohana_sec_to_date(image[i].tzero);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/checkastro/src/bcatalog.c

    r36833 r37822  
    191191  /* project coordinates to a plane centered on the object with units of arcsec */
    192192  Coords coords;
     193  InitCoords (&coords, "DEC--SIN");
    193194  coords.crval1 = Rc;
    194195  coords.crval2 = Dc;
    195   coords.crpix1 = 0;
    196   coords.crpix2 = 0;
    197196  coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
    198   coords.pc1_1  = coords.pc2_2 = 1.0;
    199   coords.pc1_2  = coords.pc2_1 = 0.0;
    200   coords.Npolyterms = 1;
    201   strcpy (coords.ctype, "DEC--SIN");
    202197
    203198  // convert all average R,D values to X,Y:
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/checkastro/src/load_images.c

    r36833 r37822  
    1717  MARKTIME("  convert image table: %f sec\n", dtime);
    1818
     19  BuildChipMatch (image, Nimage);
     20
    1921  // select the images which overlap the selected sky regions
    2022  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/checkastro/src/select_images.c

    r36833 r37822  
    4343
    4444  if (VERBOSE) fprintf (stderr, "finding images\n");
    45   BuildChipMatch (timage, Ntimage);
    46   MARKTIME("build chip match: %f sec\n", dtime);
    4745
    4846  nimage = 0;
     
    8381    }
    8482   
    85     // this adds 1.3 sec for 3M images
    86     off_t myMosaic = FindMosaicForImage (timage, Ntimage, i);
    87     if (!myMosaic) {
    88       fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    89       continue;
    90     }
    91     myMosaic --;
    92 
    9383    /* only check exposure center */
    9484    if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) {
    9585      XY_to_RD (&Rexp, &Dexp, 0.0, 0.0, &timage[i].coords);
    9686    } else {
    97       XY_to_RD (&Rexp, &Dexp, 0.0, 0.0, &timage[myMosaic].coords);
     87      XY_to_RD (&Rexp, &Dexp, 0.0, 0.0, &timage[i].parent->coords);
    9888    }
    9989    Rexp = ohana_normalize_angle_to_midpoint (Rexp, RmidSkyRegion);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/delstar/src/ImageOpsFixLAP.c

    r37040 r37822  
    320320    if ((Nimage_valid[i] + Nimage_invalid[i] == 0) || (found_ratio < 0.995)) {
    321321      double r, d;
    322       if (!FindMosaicForImage (image, Nimage, i)) {
    323         fprintf (stderr, "failed to get astrometry for %s\n", image[i].name);
     322      if (!strcmp(&image[i].coords.ctype[4], "-DIS")) {
     323        XY_to_RD (&r, &d, 0.0, 0.0, &image[i].coords);
    324324      } else {
    325         if (!strcmp(&image[i].coords.ctype[4], "-DIS")) {
    326           XY_to_RD (&r, &d, 0.0, 0.0, &image[i].coords);
    327         } else {
    328           XY_to_RD (&r, &d, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
    329         }
     325        XY_to_RD (&r, &d, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
    330326      }
    331327      char *date = ohana_sec_to_date (image[i].tzero);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/delstar/src/delete_duplicate_measures.c

    r35758 r37822  
    6161    }
    6262
    63     delete_duplicate_measures_catalog (&catalog);
    64 
    65     if (UPDATE) {
    66       // XXX skip if nothing was deleted
    67       dvo_catalog_save_complete (&catalog, VERBOSE2);
     63    if (delete_duplicate_measures_catalog (&catalog)) {
     64      // skip if nothing was deleted
     65      if (UPDATE) {
     66        if (!dvo_catalog_backup (&catalog, TRUE)) {
     67          fprintf (stderr, "ERROR: failed to make backup for catalog %s\n", catalog.filename);
     68          exit (1);
     69        }
     70        dvo_catalog_save_complete (&catalog, VERBOSE2);
     71      }
    6872    }
    6973
     
    234238    measureDrop[j] = TRUE;
    235239    off_t N = measure[j].averef;
    236     fprintf (stderr, "0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode);
     240    if (VERBOSE) fprintf (stderr, "0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode);
    237241  }
    238242
     
    385389  off_t NdelAves = Naverage - catalog[0].Naverage;
    386390  off_t NdelMeas = Nmeasure - catalog[0].Nmeasure;
     391
    387392  if (NdelAves || NdelMeas) {
    388393    fprintf (stderr, "deleting "OFF_T_FMT" measures and "OFF_T_FMT" averages : %s\n",  NdelMeas, NdelAves, catalog[0].filename);
     
    404409  FREE (measureAveOut);
    405410
    406   return TRUE;
     411  if (NdelAves || NdelMeas) return TRUE;
     412  return FALSE;
    407413}
    408414
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/delstar/src/delete_imagename.c

    r34749 r37822  
    2424  }
    2525
     26  BuildChipMatch (image, Nimage);
     27
    2628  /* find image in db by name */
    2729  imlist = find_images_name (db, IMAGENAME, &Nimlist);
     
    3335    if (VERBOSE) fprintf (stderr, "deleting %s\n", image[j].name);
    3436   
    35     // XXX EAM : need to handle failure
    36     FindMosaicForImage (image, Nimage, j);
    3737    skylist = SkyListByImage (sky, -1, &image[j]);
    3838
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/delstar/src/delete_times.c

    r29001 r37822  
    3131  }
    3232
     33  BuildChipMatch (image, Nimage);
     34
    3335  /* find images for time range, delete each image */
    3436  imlist = find_images_time (db, START, END, PHOTCODE, &Nimlist);
     
    3941    if (VERBOSE) fprintf (stderr, "finding regions for %s\n", image[j].name);
    4042
    41     // XXX EAM : need to handle failure
    42     FindMosaicForImage (image, Nimage, j);
    4343    skyset = SkyListByImage (sky, -1, &image[j]);
    4444
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/Makefile

    r35416 r37822  
    2323dvoverify_client : $(BIN)/dvoverify_client.$(ARCH)
    2424
    25 all: dvomerge dvomerge_client dvoconvert dvosecfilt dvosecfilt_client dvoverify dvoverify_client
     25dvoutils        : $(BIN)/dvoutils.$(ARCH)
     26
     27all: dvomerge dvomerge_client dvoconvert dvosecfilt dvosecfilt_client dvorepair dvoverify dvoverify_client dvoutils
    2628
    2729#  $(SRC)/dvomergeContinue.$(ARCH).o
     
    120122$(SRC)/dvorepairImagesVsMeasures.$(ARCH).o \
    121123$(SRC)/dvorepairDeleteImageList.$(ARCH).o \
     124$(SRC)/dvorepairDeleteImagesByExternID.$(ARCH).o \
     125$(SRC)/dvorepairDeleteImagesByExternID.$(ARCH).o \
    122126$(SRC)/dvorepairFixImages.$(ARCH).o \
    123127$(SRC)/psps_ids.$(ARCH).o \
    124128$(SRC)/LoadImages.$(ARCH).o \
    125129$(SRC)/ReadDeleteList.$(ARCH).o \
     130$(SRC)/ReadDeleteListExternID.$(ARCH).o \
     131$(SRC)/myIndex.$(ARCH).o \
    126132$(SRC)/match_image.$(ARCH).o \
    127133$(SRC)/help.$(ARCH).o \
     
    149155$(BIN)/dvoverify_client.$(ARCH) : $(DVOVERIFY_CLIENT)
    150156
    151 INSTALL = dvomerge dvomerge_client dvoconvert dvosecfilt dvosecfilt_client dvorepair dvoverify dvoverify_client
     157DVOUTILS = \
     158$(SRC)/dvoutils.$(ARCH).o \
     159$(SRC)/dvoutils_args.$(ARCH).o \
     160$(SRC)/dvoutils_uniq_images.$(ARCH).o \
     161$(SRC)/dvoutils_load_image_index.$(ARCH).o
     162
     163$(DVOUTILS)  : $(INC)/dvoutils.h
     164$(BIN)/dvoutils.$(ARCH) : $(DVOUTILS)
     165
     166INSTALL = dvomerge dvomerge_client dvoconvert dvosecfilt dvosecfilt_client dvorepair dvoverify dvoverify_client dvoverify
    152167
    153168# dependancy rules for binary code #########################
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/include/dvomerge.h

    r35765 r37822  
    4141int    REPLACE_BY_PHOTCODE;
    4242int    FORCE_MERGE;
     43char  *UPDATE_CATFORMAT;
     44
     45int    MATCHED_TABLES;
    4346
    4447char *SINGLE_CPT;
    4548SkyRegion UserPatch;  // used by MODE CAT
     49
     50# ifndef MAX_INT
     51# define MAX_INT 2147483647
     52# endif
     53
     54typedef struct {
     55  int minID;
     56  int maxID;
     57  int *index;
     58  int Nindex;
     59  int NINDEX;
     60} myIndexType;
    4661
    4762typedef struct {
     
    129144int        merge_catalogs_old     PROTO((SkyRegion *region, Catalog *output, Catalog *input, double RADIUS, int *secflitMap));
    130145
     146off_t     *build_measure_links    PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
    131147off_t     *init_measure_links     PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
     148int        add_meas_link          PROTO((Average *average, off_t *next, off_t Nmeasure, off_t NMEASURE));
     149Measure   *sort_measure           PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next));
     150
     151off_t     *build_lensing_links    PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
     152off_t     *init_lensing_links     PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
     153int        add_lens_link          PROTO((Average *average, off_t *next, off_t Nlensing, off_t NLENSING));
     154Lensing   *sort_lensing           PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next));
     155
     156off_t     *build_starpar_links    PROTO((Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar));
     157off_t     *init_starpar_links     PROTO((Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar));
     158int        add_star_link          PROTO((Average *average, off_t *next, off_t Nstarpar, off_t NSTARPAR));
     159StarPar   *sort_starpar           PROTO((Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar, off_t *next));
     160
    132161off_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));
    135162int        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));
    137163Missing   *sort_missing           PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss));
    138164
     
    194220int dvoCreateID (char *catdir);
    195221
     222myIndexType *myIndexInit ();
     223int myIndexFree (myIndexType *myIndex);
     224int myIndexUpdateLimits (myIndexType *myIndex, int value);
     225int myIndexSetRange (myIndexType *myIndex);
     226int myIndexSetEntry (myIndexType *myIndex, int value, int entry);
     227int myIndexGetEntry (myIndexType *myIndex, int value);
     228
     229int dvorepairDeleteImagesByExternID (int argc, char **argv);
     230int RepairTableCPT_V1(char *cptFilenameSrc, char *cptFilenameTgt, char *cpsFilenameSrc, char *cpsFilenameTgt, Measure *measure, off_t Nmeasure, Image *image, off_t Nimage, myIndexType *imageIDindex, char catformat);
     231int *ReadDeleteListExternID(char *filename, int *nindex);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/include/dvoverify.h

    r34405 r37822  
    5656int LoadImageIDs (char *catdir);
    5757int CheckImageID (Catalog *catalog);
     58
     59int SaveImageIDsSmall(char *filename);
     60int LoadImageIDsSmall (char *filename);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/ImageOps.c

    r29938 r37822  
    1818  }
    1919  if (m == -1) return (NULL);
    20   if (!FindMosaicForImage (image, Nimage, m)) return (NULL);
    2120  return (&image[m]);
    2221}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/LoadCatalog.c

    r29938 r37822  
    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 | LOAD_STARPAR;
    1111
    1212    catalog[0].catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/args.c

    r35765 r37822  
    3737  }
    3838
     39  /* extra error messages */
     40  MATCHED_TABLES = FALSE;
     41  if ((N = get_argument (*argc, argv, "-matched-tables"))) {
     42    MATCHED_TABLES = TRUE;
     43    remove_argument (N, argc, argv);
     44  }
     45
    3946  /* use a different photcode file to define mean values */
    4047  if ((N = get_argument (*argc, argv, "-photcode-file"))) {
     
    4855  if ((N = get_argument (*argc, argv, "-force-merge"))) {
    4956    FORCE_MERGE = TRUE;
     57    remove_argument (N, argc, argv);
     58  }
     59
     60  UPDATE_CATFORMAT = NULL;
     61  if ((N = get_argument (*argc, argv, "-update-catformat"))) {
     62    remove_argument (N, argc, argv);
     63    UPDATE_CATFORMAT = strcreate (argv[N]);
    5064    remove_argument (N, argc, argv);
    5165  }
     
    185199  }
    186200
     201  /* extra error messages */
     202  MATCHED_TABLES = FALSE;
     203  if ((N = get_argument (*argc, argv, "-matched-tables"))) {
     204    MATCHED_TABLES = TRUE;
     205    remove_argument (N, argc, argv);
     206  }
     207
    187208  /* replace measurement, don't duplicate */
    188209  REPLACE_BY_PHOTCODE = FALSE;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/build_links.c

    r27435 r37822  
    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    off_t m = average[i].lensingOffset;
     244    myAssert (lensing[m].averef == i, "not sorted");
     245    for (j = 0; j < average[i].Nlensing - 1; j++, N++) {
     246      myAssert (lensing[m+j+1].averef == i, "not sorted");
     247      next_lens[N] = N + 1;
     248      if (N >= Nlensing) {
     249        fprintf (stderr, "WARNING: N out of bounds (1)\n");
     250      }
     251    }
     252    next_lens[N] = -1;
     253    if (N >= Nlensing) {
     254      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     255    }
     256
     257    if (N >= Nlensing) {
     258      fprintf (stderr, "overflow in init_lensing_links\n");
     259      abort ();
     260    }
     261    N++;
     262  }
     263  return (next_lens);
     264}
     265
     266/* construct lensing links which are valid FOR THIS LOAD
     267 * - if we have a full load, we will get links which can
     268 *   be used by other programs (eg, relphot, etc)
     269 * - if we have a partial load, the links are only valid
     270 *   for that partial load
     271 */
     272
     273off_t *build_lensing_links (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing) {
     274
     275  off_t i, m, k, Nm, averef;
     276  off_t *next_lens;
     277
     278  ALLOCATE (next_lens, off_t, Nlensing);
     279
     280  /* reset the Nm, offset values for average */
     281  for (i = 0; i < Naverage; i++) {
     282    average[i].lensingOffset = -1;
     283    average[i].Nlensing     =  0;
     284  }
     285
     286  for (Nm = 0; Nm < Nlensing; Nm++) {
     287    averef = lensing[Nm].averef;
     288    m = average[averef].lensingOffset; 
     289    next_lens[Nm] = -1;
     290
     291    if (m == -1) { /* no links yet for source */
     292      average[averef].lensingOffset = Nm;
     293      average[averef].Nlensing     = 1;
     294      continue;
     295    }
     296
     297    for (k = 0; next_lens[m] != -1; k++) {
     298      m = next_lens[m];
     299      if (m >= Nlensing) {
     300        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     301      }
     302    }
     303
     304    average[averef].Nlensing = k + 2;
     305    next_lens[m] = Nm;
     306    if (m >= Nlensing) {
     307      fprintf (stderr, "WARNING: m out of bounds (2)\n");
     308    }
     309  }
     310  return (next_lens);
     311}
     312
     313/* average[].lensingOffset, average[].Nlensing are valid within an addstar run */
     314int add_lens_link (Average *average, off_t *next_lens, off_t Nlensing, off_t NLENSING) {
     315
     316  off_t k, m;
     317
     318  /* if we have trouble, check validity of next_lens[m] : m < Nlensing */
     319  m = average[0].lensingOffset; 
     320
     321  for (k = 0; k < average[0].Nlensing - 1; k++)  {
     322    m = next_lens[m];
     323    if (m >= NLENSING) {
     324      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     325    }
     326  }
     327
     328  /* set up references */
     329  next_lens[Nlensing] = -1;
     330  if (Nlensing >= NLENSING) {
     331    fprintf (stderr, "WARNING: Nlensing out of bounds (1)\n");
     332  }
     333
     334  // if Nlensing is 0, m may have been mis-set; add to the end
     335  if ((average[0].Nlensing == 0) || (m == -1)) {
     336    average[0].lensingOffset = Nlensing;
     337  } else {
     338    next_lens[m] = Nlensing;
     339    if (m >= NLENSING) {
     340      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     341    }
     342  }
     343
     344  return (TRUE);
     345}
     346
     347Lensing *sort_lensing (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next_lens) {
     348
     349  off_t i, k, n, np, N;
     350  Lensing *tmplensing;
     351
     352  /*
     353  for (i = 0; i < Naverage; i++) {
     354    if (average[i].Nlensing != 4) {
     355      fprintf (stderr, "check %d %d %d\n", (int) i, (int) average[i].Nlensing, (int) average[i].lensingOffset);
     356    }
     357  }
     358  */
     359
     360  /* fix order of Lensing (memory intensive, but fast) */
     361  np = -1;
     362  N = 0;
     363  ALLOCATE (tmplensing, Lensing, Nlensing);
     364  for (i = 0; i < Naverage; i++) {
     365    if (!average[i].Nlensing) continue;
     366    n = average[i].lensingOffset;
     367    average[i].lensingOffset = N;
     368    for (k = 0; k < average[i].Nlensing; k++, N++) {
     369      if (n == -1) {
     370        fprintf (stderr, "entry after %d has a problem\n", (int) np);
     371        abort();
     372      }
     373      tmplensing[N] = lensing[n];
     374      if (lensing[n].averef != i) abort();
     375      tmplensing[N].averef = i;
     376      np = n;
     377      n = next_lens[n];
     378    }
     379  }
     380  free (lensing);
     381  return (tmplensing);
     382}
     383
     384/********  StarPar ********************************************************************************/
     385
     386/* build the initial links assuming the table is sorted,
     387   not partial, and has a correct set of average[].starparOffset,Nstarpar values */
     388off_t *init_starpar_links (Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar) {
     389
     390  off_t i, j, N;
     391  off_t *next_star;
     392
     393  N = 0;
     394
     395  ALLOCATE (next_star, off_t, Nstarpar);
     396  for (i = 0; i < Naverage; i++) {
     397    if (!average[i].Nstarpar) continue;
     398    for (j = 0; j < average[i].Nstarpar - 1; j++, N++) {
     399      next_star[N] = N + 1;
     400      if (N >= Nstarpar) {
     401        fprintf (stderr, "WARNING: N out of bounds (1)\n");
     402      }
     403    }
     404    next_star[N] = -1;
     405    if (N >= Nstarpar) {
     406      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     407    }
     408
     409    if (N >= Nstarpar) {
     410      fprintf (stderr, "overflow in init_starpar_links\n");
     411      abort ();
     412    }
     413    N++;
     414  }
     415  return (next_star);
     416}
     417
     418/* construct starpar links which are valid FOR THIS LOAD
     419 * - if we have a full load, we will get links which can
     420 *   be used by other programs (eg, relphot, etc)
     421 * - if we have a partial load, the links are only valid
     422 *   for that partial load
     423 */
     424
     425off_t *build_starpar_links (Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar) {
     426
     427  off_t i, m, k, Nm, averef;
     428  off_t *next_star;
     429
     430  ALLOCATE (next_star, off_t, Nstarpar);
     431
     432  /* reset the Nm, offset values for average */
     433  for (i = 0; i < Naverage; i++) {
     434    average[i].starparOffset = -1;
     435    average[i].Nstarpar     =  0;
     436  }
     437
     438  for (Nm = 0; Nm < Nstarpar; Nm++) {
     439    averef = starpar[Nm].averef;
     440    m = average[averef].starparOffset; 
     441    next_star[Nm] = -1;
     442
     443    if (m == -1) { /* no links yet for source */
     444      average[averef].starparOffset = Nm;
     445      average[averef].Nstarpar     = 1;
     446      continue;
     447    }
     448
     449    for (k = 0; next_star[m] != -1; k++) {
     450      m = next_star[m];
     451      if (m >= Nstarpar) {
     452        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     453      }
     454    }
     455
     456    average[averef].Nstarpar = k + 2;
     457    next_star[m] = Nm;
     458    if (m >= Nstarpar) {
     459      fprintf (stderr, "WARNING: m out of bounds (2)\n");
     460    }
     461  }
     462  return (next_star);
     463}
     464
     465/* average[].starparOffset, average[].Nstarpar are valid within an addstar run */
     466int add_star_link (Average *average, off_t *next_star, off_t Nstarpar, off_t NSTARPAR) {
     467
     468  off_t k, m;
     469
     470  /* if we have trouble, check validity of next_star[m] : m < Nstarpar */
     471  m = average[0].starparOffset; 
     472
     473  for (k = 0; k < average[0].Nstarpar - 1; k++)  {
     474    m = next_star[m];
     475    if (m >= NSTARPAR) {
     476      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     477    }
     478  }
     479
     480  /* set up references */
     481  next_star[Nstarpar] = -1;
     482  if (Nstarpar >= NSTARPAR) {
     483    fprintf (stderr, "WARNING: Nstarpar out of bounds (1)\n");
     484  }
     485
     486  if (m == -1) {
     487    average[0].starparOffset = Nstarpar;
     488  } else {
     489    next_star[m] = Nstarpar;
     490    if (m >= NSTARPAR) {
     491      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     492    }
     493  }
     494
     495  return (TRUE);
     496}
     497
     498StarPar *sort_starpar (Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar, off_t *next_star) {
     499
     500  off_t i, k, n, np, N;
     501  StarPar *tmpstarpar;
     502
     503  /*
     504  for (i = 0; i < Naverage; i++) {
     505    if (average[i].Nstarpar != 4) {
     506      fprintf (stderr, "check %d %d %d\n", (int) i, (int) average[i].Nstarpar, (int) average[i].starparOffset);
     507    }
     508  }
     509  */
     510
     511  /* fix order of StarPar (memory intensive, but fast) */
     512  np = -1;
     513  N = 0;
     514  ALLOCATE (tmpstarpar, StarPar, Nstarpar);
     515  for (i = 0; i < Naverage; i++) {
     516    if (!average[i].Nstarpar) continue;
     517    n = average[i].starparOffset;
     518    average[i].starparOffset = N;
     519    for (k = 0; k < average[i].Nstarpar; k++, N++) {
     520      if (n == -1) {
     521        fprintf (stderr, "entry after %d has a problem\n", (int) np);
     522        abort();
     523      }
     524      tmpstarpar[N] = starpar[n];
     525      if (starpar[n].averef != i) abort();
     526      tmpstarpar[N].averef = i;
     527      np = n;
     528      n = next_star[n];
     529    }
     530  }
     531  free (starpar);
     532  return (tmpstarpar);
     533}
     534
     535
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c

    r36833 r37822  
    113113  create_IDmap_lookup (IDmap);
    114114
    115   if (!out[0].swapped) {
    116     gfits_convert_Image ((Image *) out[0].ftable.buffer, sizeof(Image), Nout);
    117     out[0].swapped = TRUE;
    118   }
    119 
    120115  Nout += Nimages;
    121116  IDstart += Nimages;
     
    179174  off_t lastID = IDmap->old[IDmap->Nmap-1];
    180175
     176  // update measure.imageID
    181177  for (i = 0; i < catalog[0].Nmeasure; i++) {
    182178    oldID = catalog[0].measure[i].imageID;
     
    199195    }
    200196    catalog[0].measure[i].imageID = newID;
     197  }
     198
     199  // also update lensing.imageID if lensing exists
     200  for (i = 0; i < catalog[0].Nlensing; i++) {
     201    oldID = catalog[0].lensing[i].imageID;
     202    if (oldID == 0) continue;
     203
     204    newID = dvo_map_image_ID (IDmap, oldID);
     205    if (newID == 0) {
     206      if (oldID > lastID) {
     207        fprintf (stderr, "problem with image IDs : input out of range\n");
     208        fprintf (stderr, "old ID: "OFF_T_FMT", last ID: "OFF_T_FMT"\n", oldID, lastID);
     209        exit (2);
     210      }
     211      if (!IDmap->notFound[oldID]) {
     212        fprintf (stderr, "cannot find image ID "OFF_T_FMT"\n",  oldID);
     213        IDmap->notFound[oldID] = TRUE;
     214        // once we discover an imageID is not found, record that fact so we do not complain for every detection
     215      }
     216      // optionally exit here? or wait until end to report an error?
     217      // exit (2);
     218    }
     219    catalog[0].lensing[i].imageID = newID;
    201220  }
    202221  return TRUE;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvomergeContinue.c

    r34260 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvomergeContinue_threaded.c

    r34260 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvomergeCreate.c

    r33963 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvomergeFromList.c

    r35590 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvomergeUpdate.c

    r36528 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c

    r37046 r37822  
    5858    }
    5959
     60# ifdef OLD_CODE
     61    // NOTE: i was having trouble dropping objects on edges with the option below.  Since an object can move outside the catalog grab the neighbors.
    6062    // SkyListByBounds will return neighbor catalogs if the boundaries exactly match (due to rounding).  Since the regions are not infinitely small,
    6163    // compare to a slightly reduced footprint
    6264    float dPos = 2.0/3600.0;
    6365    outlist = SkyListByBounds (outsky, -1, inlist[0].regions[i][0].Rmin + dPos, inlist[0].regions[i][0].Rmax - dPos, inlist[0].regions[i][0].Dmin + dPos, inlist[0].regions[i][0].Dmax - dPos);
     66# endif
     67
     68    if (MATCHED_TABLES) {
     69      // if we know the output will have the same depth / layout as the input, just choose the matched table
     70      outlist = SkyRegionByIndex (outsky, inlist[0].regions[i][0].index);
     71    } else {
     72      // Since an object can move outside the catalog grab the neighbors.
     73      float dPos = 2.0/3600.0;
     74      outlist = SkyListByBounds (outsky, -1, inlist[0].regions[i][0].Rmin - dPos, inlist[0].regions[i][0].Rmax + dPos, inlist[0].regions[i][0].Dmin - dPos, inlist[0].regions[i][0].Dmax + dPos);
     75    }
    6476
    6577    OutputStatus *outstat = OutputStatusInit (outlist->Nregions);
     
    163175      LoadCatalog (&outcatalog, outlist[0].regions[j], outcatalog.filename, "w", NsecfiltOutput);
    164176
     177      // if no catalog already exists, use the input catalog to define the format or the specified format
     178      if (outcatalog.Naves_disk == 0) {
     179        if (UPDATE_CATFORMAT) {
     180          outcatalog.catformat = dvo_catalog_catformat (UPDATE_CATFORMAT);
     181        } else {
     182          outcatalog.catformat = incatalog.catformat;
     183        }
     184      }
     185
    165186      merge_catalogs_old (outlist[0].regions[j], &outcatalog, &incatalog, RADIUS, secfiltMap);
    166 
    167       outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    168187
    169188      if (outstat[j].missed) {
     
    184203      SetProtect (FALSE);
    185204
     205      if (!dvo_catalog_unlock (&outcatalog)) {
     206        fprintf (stderr, "ERROR: failed to unlock catalog %s\n", outlist[0].filename[j]);
     207        exit (1);
     208      }
     209
    186210      if (!dvo_catalog_unlink_backup (&outcatalog, TRUE)) {
    187211        fprintf (stderr, "WARNING: failed to remove backup for catalog %s\n", outlist[0].filename[j]);
    188212      }
    189213
    190       dvo_catalog_unlock (&outcatalog);
    191214      dvo_catalog_free (&outcatalog);
    192215
     
    253276    if (PARALLEL_INPUT)      { snprintf (tmpline, DVO_MAX_PATH, "%s -parallel-input",  command); strcpy (command, tmpline); }
    254277    if (FORCE_MERGE)         { snprintf (tmpline, DVO_MAX_PATH, "%s -force-merge",     command); strcpy (command, tmpline); }
     278    if (MATCHED_TABLES)      { snprintf (tmpline, DVO_MAX_PATH, "%s -matched-tables",  command); strcpy (command, tmpline); }
    255279
    256280    // add some config variables:
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvomergeUpdate_threaded.c

    r35765 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvorepair.c

    r37046 r37822  
    33int main (int argc, char **argv) {
    44
    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);
     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);
    88
    99  dvorepair_help(argc, argv);
     
    1313  if (!strcmp(argv[1], "-images-vs-measures")) dvorepairImagesVsMeasures(argc, argv);
    1414  if (!strcmp(argv[1], "-delete-image-list")) dvorepairDeleteImageList(argc, argv);
     15  if (!strcmp(argv[1], "-delete-images-by-extern-id")) dvorepairDeleteImagesByExternID(argc, argv);
    1516  if (!strcmp(argv[1], "-fix-images")) dvorepairFixImages(argc, argv);
    1617  dvorepair_help(0, NULL);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvorepairCPT.c

    r37046 r37822  
    119119    thisImage = MatchImage (image, Nimage, measure[i].t, measure[i].photcode, measure[i].imageID);
    120120    XY_to_RD (&average[Nave].R, &average[Nave].D, measure[i].Xccd, measure[i].Yccd, &thisImage[0].coords);
     121    average[Nave].R = ohana_normalize_angle (average[Nave].R);
    121122
    122123    average[Nave].Nmeasure = 1;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvorepairDeleteImageList.c

    r37046 r37822  
    114114    index = deleteIDs[i];
    115115    seq = imageIdx[index];
    116     if (!FindMosaicForImage (image, Nimage, seq)) {
    117       fprintf (stderr, "cannot find mosaic for %s, skipping\n", image[seq].name);
    118       continue;
    119     }
    120116
    121117    XY_to_RD(&Rthis, &Dthis, 0, 0, &image[seq].coords);
     
    404400    thisImage = MatchImage (image, Nimage, measure[i].t, measure[i].photcode, measure[i].imageID);
    405401    XY_to_RD (&average[Nave].R, &average[Nave].D, measure[i].Xccd, measure[i].Yccd, &thisImage[0].coords);
     402    average[Nave].R = ohana_normalize_angle (average[Nave].R);
    406403
    407404    average[Nave].Nmeasure = 1;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvorepairFixImages.c

    r29938 r37822  
    130130int MarkMosaicsToDelete(Image *image, off_t Nimage, int *deleteIndex) {
    131131
     132  myAbort ("this function needs to be redone with a concept to match the old BuildChipMatch");
     133
     134# if (0) 
     135
    132136  off_t i;
    133137 
     
    140144     marked.  Now find all WRP images for which none/some/all images are to be deleted.
    141145  */
     146
     147 
    142148
    143149  // make a copy of the ChipMatch table (generated by BuildChipMatch, see libdvo/src/mosaic_astrom.c)
     
    237243  free (ChipByMosaicID);
    238244
     245# endif
     246
    239247  return TRUE;
    240248}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvorepairFixTables.c

    r37046 r37822  
    259259    thisImage = MatchImage (image, Nimage, measure[i].t, measure[i].photcode, measure[i].imageID);
    260260    XY_to_RD (&average[Nave].R, &average[Nave].D, measure[i].Xccd, measure[i].Yccd, &thisImage[0].coords);
     261    average[Nave].R = ohana_normalize_angle (average[Nave].R);
    261262
    262263    average[Nave].Nmeasure = 1;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvoverify_args.c

    r36101 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvoverify_catalogs.c

    r36084 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvoverify_client.c

    r34405 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/dvoverify_utils.c

    r36101 r37822  
    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.Nlensing || (catalog.average[i].lensingOffset < catalog.Nlensing));
     241    if (VERBOSE && catalog.Nlensing && !(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/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/merge_catalogs_new.c

    r28855 r37822  
    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, NSTARPAR, Naverage, Nmeasure, Nlensing, Nstarpar, NsecfiltIn, NsecfiltOut, Nm;
    1614
    1715  Naverage = output[0].Naverage;
    1816  Nmeasure = output[0].Nmeasure;
     17  Nlensing = output[0].Nlensing;
     18  Nstarpar = output[0].Nstarpar;
    1919
    2020  NsecfiltOut = output[0].Nsecfilt;
     
    2323  NAVERAGE = Naverage + 100;
    2424  NMEASURE = Nmeasure + 1000;
     25  NLENSING = Nlensing + 1000;
     26  NSTARPAR = Nstarpar + 1000;
    2527
    2628  REALLOCATE (output[0].average, Average, NAVERAGE);
    2729  REALLOCATE (output[0].secfilt, SecFilt, NAVERAGE*NsecfiltOut);
    2830  REALLOCATE (output[0].measure, Measure, NMEASURE);
     31  REALLOCATE (output[0].lensing, Lensing, NLENSING);
     32  REALLOCATE (output[0].starpar, StarPar, NSTARPAR);
    2933
    3034  // add all of these entries to the existing catalog
     
    6367      }
    6468      output[0].average[Naverage].Nmeasure = Nm;
     69
     70      Nm = 0;
     71      for (j = 0; j < input[0].average[i].Nlensing; j++) {
     72          offset = input[0].average[i].lensingOffset + j;
     73
     74          output[0].lensing[Nlensing] = input[0].lensing[offset];
     75          output[0].lensing[Nlensing].averef = Naverage;
     76
     77          Nlensing ++;
     78          Nm ++;
     79          if (Nlensing == NLENSING) {
     80              NLENSING += 1000;
     81              REALLOCATE (output[0].lensing, Lensing, NLENSING);
     82          }
     83      }
     84      output[0].average[Naverage].Nlensing = Nm;
     85
     86      Nm = 0;
     87      for (j = 0; j < input[0].average[i].Nstarpar; j++) {
     88          offset = input[0].average[i].starparOffset + j;
     89
     90          output[0].starpar[Nstarpar] = input[0].starpar[offset];
     91          output[0].starpar[Nstarpar].averef = Naverage;
     92
     93          Nstarpar ++;
     94          Nm ++;
     95          if (Nstarpar == NSTARPAR) {
     96              NSTARPAR += 1000;
     97              REALLOCATE (output[0].starpar, StarPar, NSTARPAR);
     98          }
     99      }
     100      output[0].average[Naverage].Nstarpar = Nm;
     101
    65102      Naverage ++;
    66103      if (Naverage == NAVERAGE) {
     
    72109  REALLOCATE (output[0].average, Average, MAX (Naverage, 1));
    73110  REALLOCATE (output[0].measure, Measure, MAX (Nmeasure, 1));
     111  REALLOCATE (output[0].lensing, Lensing, MAX (Nlensing, 1));
     112  REALLOCATE (output[0].starpar, StarPar, MAX (Nstarpar, 1));
    74113  REALLOCATE (output[0].secfilt, SecFilt, NsecfiltOut*MAX (Naverage, 1));
    75114  output[0].Naverage = Naverage;
    76   output[0].Nmeasure = Nmeasure;
     115  output[0].Nlensing = Nlensing;
     116  output[0].Nstarpar = Nstarpar;
    77117  output[0].Nsecf_mem = Naverage * NsecfiltOut;
    78118
     
    84124 
    85125  if (VERBOSE) {
    86       fprintf (stderr, OFF_T_FMT": using "OFF_T_FMT" stars ("OFF_T_FMT" measures) for catalog\n",
     126      fprintf (stderr, OFF_T_FMT": using "OFF_T_FMT" stars ("OFF_T_FMT" measures, "OFF_T_FMT" lensing) for catalog\n",
    87127                i,
    88128                output[0].Naverage,
    89                 output[0].Nmeasure);
     129                output[0].Nmeasure,
     130                output[0].Nlensing);
    90131  }
    91132  return (TRUE);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r37046 r37822  
    44# define IN_REGION(R,D) (                                       \
    55    ((D) >= region[0].Dmin) && ((D) < region[0].Dmax) &&        \
    6     ((R) >= region[0].Rmin)  && ((R) < region[0].Rmax))
     6    ((R) >= region[0].Rmin) && ((R) < region[0].Rmax))
    77
    88// merge the input data into the output catalog
     
    1414  double *X1, *Y1, *X2, *Y2;
    1515  double dX, dY, dR;
    16   off_t *N1, *N2,  *next_meas;
    17   off_t Nave, NAVE, Nmeas, NMEAS, Nmatch;
     16  off_t *N1, *N2, *next_meas, *next_lens, *next_star;
     17  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch, Nlens, NLENS, Nstar, NSTAR;
    1818  int NsecfiltIn;
    1919  int NsecfiltOut;
     
    5252  Nmatch = 0;
    5353  NMEAS = Nmeas = output[0].Nmeasure;
     54  NLENS = Nlens = output[0].Nlensing;
     55  NSTAR = Nstar = output[0].Nstarpar;
    5456
    5557  // current max obj ID for this catalog
     
    6365   * coordops.update.c).  We use the center of the region (catalog) for crval1,2.
    6466   */
     67
     68  InitCoords (&tcoords, "DEC--ARC");
    6569  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    6670  if (region[0].Dmax < 90) {
     
    6973    tcoords.crval2 = 90.0;
    7074  }
    71   tcoords.crpix1 = 0;
    72   tcoords.crpix2 = 0;
    7375  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    74   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    75   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    76   tcoords.Npolyterms = 1;
    77   strcpy (tcoords.ctype, "DEC--ARC");
    7876
    7977  if (VERBOSE) fprintf (stderr, "merging %s into %s\n", input[0].filename, output[0].filename);
     
    113111  }
    114112
    115 
    116113  /* set up pointers for linked list of measure */
    117114  if (output[0].sorted && (output[0].Nmeasure >= output[0].Nmeas_disk)) {
     
    119116    // is sorted while processed
    120117    next_meas = init_measure_links (output[0].average, Nave, output[0].measure, Nmeas);
     118    next_lens = init_lensing_links (output[0].average, Nave, output[0].lensing, Nlens);
     119    next_star = init_starpar_links (output[0].average, Nave, output[0].starpar, Nstar);
    121120  } else {
    122121    next_meas = build_measure_links (output[0].average, Nave, output[0].measure, Nmeas);
     122    next_lens = build_lensing_links (output[0].average, Nave, output[0].lensing, Nlens);
     123    next_star = build_starpar_links (output[0].average, Nave, output[0].starpar, Nstar);
    123124  }   
    124125
     
    182183      REALLOCATE (output[0].measure, Measure, NMEAS);
    183184    }
     185    if (Nlens + input[0].average[N].Nlensing >= NLENS) {
     186      NLENS = Nlens + input[0].average[N].Nlensing + 1000;
     187      REALLOCATE (next_lens, off_t, NLENS);
     188      REALLOCATE (output[0].lensing, Lensing, NLENS);
     189    }
     190    if (Nstar + input[0].average[N].Nstarpar >= NSTAR) {
     191      NSTAR = Nstar + input[0].average[N].Nstarpar + 1000;
     192      REALLOCATE (next_star, off_t, NSTAR);
     193      REALLOCATE (output[0].starpar, StarPar, NSTAR);
     194    }
    184195
    185196    // 4) average properties from the input and the output db need to be properly merged.
     
    191202      if (REPLACE_BY_PHOTCODE) {
    192203        // index to first measure for this object
     204        // XXX this does not support lensing measurements
    193205        int Mout = output[0].average[n].measureOffset; 
    194206        if (replace_match(&output[0].average[n], &output[0].measure[Mout], &input[0].average[N], &input[0].measure[offset])) {
     
    248260    }
    249261
     262    // if lensing measurements exist, add them too
     263    if (output[0].lensing) {
     264      for (Nin = 0; Nin < input[0].average[N].Nlensing; Nin++) {
     265        /* add to end of lensing list */
     266        add_lens_link (&output[0].average[n], next_lens, Nlens, NLENS);
     267       
     268        // set the new lensing
     269        off_t lensoff = input[0].average[N].lensingOffset + Nin;
     270        output[0].lensing[Nlens] = input[0].lensing[lensoff];
     271
     272        output[0].lensing[Nlens].averef   = n;
     273        output[0].lensing[Nlens].objID    = output[0].average[n].objID;
     274        output[0].lensing[Nlens].catID    = output[0].catID;
     275        output[0].average[n].Nlensing ++;
     276        Nlens ++;
     277      }
     278    }
     279
     280    // if lensing measurements exist, add them too
     281    if (output[0].starpar) {
     282      for (Nin = 0; Nin < input[0].average[N].Nstarpar; Nin++) {
     283        /* add to end of lensing list */
     284        add_star_link (&output[0].average[n], next_star, Nstar, NSTAR);
     285       
     286        // set the new starpar
     287        off_t staroff = input[0].average[N].starparOffset + Nin;
     288        output[0].starpar[Nstar] = input[0].starpar[staroff];
     289
     290        output[0].starpar[Nstar].averef   = n;
     291        output[0].starpar[Nstar].objID    = output[0].average[n].objID;
     292        output[0].starpar[Nstar].catID    = output[0].catID;
     293        output[0].average[n].Nstarpar ++;
     294        Nstar ++;
     295      }
     296    }
     297
    250298    // update the average properties to reflect the incoming entries:
    251299    // if the original value is NAN but the input value is not, accept the input:
     
    288336      REALLOCATE (output[0].measure, Measure, NMEAS);
    289337    }
     338    if (Nlens + input[0].average[N].Nlensing >= NLENS) {
     339      NLENS = Nlens + input[0].average[N].Nlensing + 1000;
     340      REALLOCATE (next_lens, off_t, NLENS);
     341      REALLOCATE (output[0].lensing, Lensing, NLENS);
     342    }
     343    if (Nstar + input[0].average[N].Nstarpar >= NSTAR) {
     344      NSTAR = Nstar + input[0].average[N].Nstarpar + 1000;
     345      REALLOCATE (next_star, off_t, NSTAR);
     346      REALLOCATE (output[0].starpar, StarPar, NSTAR);
     347    }
    290348    if (Nave >= NAVE) {
    291349      NAVE = Nave + 1000;
     
    295353
    296354    if (input[0].found_t[N] >= 0) continue;
    297     if (!IN_REGION (input[0].average[N].R, input[0].average[N].D)) continue;
     355
     356    // if we are using MATCHED_TABLES, we are going to leave the edge cases in their
     357    // source catalog, even if they have leaked beyond the edge
     358    if (!MATCHED_TABLES && !IN_REGION (input[0].average[N].R, input[0].average[N].D)) continue;
    298359
    299360    // XXX should we accept the input measurements for these fields?
     
    355416      next_meas[Nmeas - Ngroup + j] = Nmeas - Ngroup + j + 1;
    356417    }
     418
     419    /** add lensing for this input average object **/
     420    if (output[0].lensing) {
     421      output[0].average[Nave].lensingOffset  = Nlens;
     422      for (Nin = 0; Nin < input[0].average[N].Nlensing; Nin ++) {
     423        // supply the lensing values from this detection
     424        off_t lensoff = input[0].average[N].lensingOffset + Nin;
     425        output[0].lensing[Nlens]           = input[0].lensing[lensoff];
     426
     427        // the following lensing elements cannot be set until here:
     428        output[0].lensing[Nlens].averef   = Nave;
     429        output[0].lensing[Nlens].objID    = output[0].average[Nave].objID;
     430        output[0].lensing[Nlens].catID    = output[0].catID;
     431
     432        // as we add lensing, update Nlensing to match
     433        output[0].average[Nave].Nlensing ++;
     434
     435        /* we set next[Nlens] to -1 here, and update correctly below */
     436        next_lens[Nlens] = -1;
     437        Nlens ++;
     438      }
     439      int Ngroup = input[0].average[N].Nlensing;
     440      for (j = 0; j < Ngroup - 1; j++) {
     441        next_lens[Nlens - Ngroup + j] = Nlens - Ngroup + j + 1;
     442      }
     443    }
     444
     445    /** add starpar for this input average object **/
     446    if (output[0].starpar) {
     447      output[0].average[Nave].starparOffset  = Nstar;
     448      for (Nin = 0; Nin < input[0].average[N].Nstarpar; Nin ++) {
     449        // supply the starpar values from this detection
     450        off_t staroff = input[0].average[N].starparOffset + Nin;
     451        output[0].starpar[Nstar]           = input[0].starpar[staroff];
     452
     453        // the following starpar elements cannot be set until here:
     454        output[0].starpar[Nstar].averef   = Nave;
     455        output[0].starpar[Nstar].objID    = output[0].average[Nave].objID;
     456        output[0].starpar[Nstar].catID    = output[0].catID;
     457
     458        // as we add starpar, update Nstarpar to match
     459        output[0].average[Nave].Nstarpar ++;
     460
     461        /* we set next[Nstar] to -1 here, and update correctly below */
     462        next_star[Nstar] = -1;
     463        Nstar ++;
     464      }
     465      int Ngroup = input[0].average[N].Nstarpar;
     466      for (j = 0; j < Ngroup - 1; j++) {
     467        next_star[Nstar - Ngroup + j] = Nstar - Ngroup + j + 1;
     468      }
     469    }
     470
    357471    Nave ++;
    358472  }
     
    362476  REALLOCATE (output[0].average, Average, Nave);
    363477  REALLOCATE (output[0].measure, Measure, Nmeas);
     478  REALLOCATE (output[0].lensing, Lensing, Nlens);
     479  REALLOCATE (output[0].starpar, StarPar, Nstar);
    364480 
    365481# define NOSORT 0
     
    369485    output[0].sorted = TRUE;
    370486    output[0].measure = sort_measure (output[0].average, Nave, output[0].measure, Nmeas, next_meas);
     487    output[0].lensing = sort_lensing (output[0].average, Nave, output[0].lensing, Nlens, next_lens);
     488    output[0].starpar = sort_starpar (output[0].average, Nave, output[0].starpar, Nstar, next_star);
    371489  }
    372490
     
    384502  output[0].Naverage = Nave;
    385503  output[0].Nmeasure = Nmeas;
     504  output[0].Nlensing = Nlens;
     505  output[0].Nstarpar = Nstar;
    386506  output[0].Nsecf_mem = Nave*NsecfiltOut;
    387   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);
     507  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);
    388508
    389509  free (next_meas);
     510  free (next_lens);
     511  free (next_star);
    390512
    391513  free (X2);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvopsps/Makefile

    r35098 r37822  
    3030$(SRC)/insert_objects_dvopsps.$(ARCH).o \
    3131$(SRC)/insert_objects_dvopsps_catalog.$(ARCH).o \
     32$(SRC)/insert_FWobjects_dvopsps.$(ARCH).o \
     33$(SRC)/insert_FWobjects_dvopsps_catalog.$(ARCH).o \
    3234$(SRC)/insert_detections_dvopsps.$(ARCH).o \
    3335$(SRC)/insert_detections_dvopsps_catalog.$(ARCH).o
     
    4648$(SRC)/insert_objects_dvopsps.$(ARCH).o \
    4749$(SRC)/insert_objects_dvopsps_catalog.$(ARCH).o \
     50$(SRC)/insert_FWobjects_dvopsps.$(ARCH).o \
     51$(SRC)/insert_FWobjects_dvopsps_catalog.$(ARCH).o \
    4852$(SRC)/insert_detections_dvopsps.$(ARCH).o \
    4953$(SRC)/insert_detections_dvopsps_catalog.$(ARCH).o
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvopsps/include/dvopsps.h

    r36188 r37822  
    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(());
     
    93102                                         
    94103int    insert_objects_mysql_create_tables PROTO((char *basename, MYSQL *mysql));
    95 
    96104int    insert_objects_mysql_commit        PROTO((IOBuffer *ave_buffer, IOBuffer *sec_buffer, MYSQL *mysql));
    97105int    insert_objects_mysql_value         PROTO((IOBuffer *ave_buffer, IOBuffer *sec_buffer, Average *average, SecFilt *secfilt, int Nsecfilt));
    98106int    insert_objects_mysql_init          PROTO((IOBuffer *ave_buffer, IOBuffer *sec_buffer, char *basename));
     107
     108int    insert_FWobjects_dvopsps             PROTO(());
     109int    insert_FWobjects_dvopsps_parallel    PROTO((SkyList *sky));
     110int    insert_FWobjects_dvopsps_catalog     PROTO((Catalog *catalog, char *basename, MYSQL *mysql));
     111                                         
     112int    insert_FWobjects_mysql_create_tables PROTO((char *basename, MYSQL *mysql));
     113int    insert_FWobjects_mysql_init          PROTO((IOBuffer *ave_buffer, IOBuffer *sec_buffer, IOBuffer *cpy_buffer, char *basename));
     114int    insert_FWobjects_mysql_value         PROTO((IOBuffer *ave_buffer, IOBuffer *sec_buffer, IOBuffer *cpy_buffer, Average *average, SecFilt *secfilt, int Nsecfilt, Lensobj *lensobj, int Nlensobj));
     115int    insert_FWobjects_mysql_commit        PROTO((IOBuffer *ave_buffer, IOBuffer *sec_buffer, IOBuffer *cpy_buffer, MYSQL *mysql));
    99116
    100117int    insert_skytable                    PROTO(());
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvopsps/src/DetectionOps.c

    r35578 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/dvopsps/src/dvopsps.c

    r35098 r37822  
    1414  if (!strcasecmp (argv[1], "objects")) {
    1515    status = insert_objects_dvopsps ();
     16  }
     17  if (!strcasecmp (argv[1], "forced_warp_objects")) {
     18    status = insert_FWobjects_dvopsps ();
    1619  }
    1720  if (!strcasecmp (argv[1], "skytable")) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvopsps/src/dvopsps_client.c

    r35111 r37822  
    2222    status = insert_objects_dvopsps ();
    2323  }
     24  if (!strcasecmp (argv[1], "forced_warp_objects")) {
     25    status = insert_FWobjects_dvopsps ();
     26  }
    2427  if (status == -1) {
    2528    fprintf (stderr, "invalid mode, should be : detections, skytable\n");
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvopsps/src/initialize_dvopsps.c

    r36188 r37822  
    2121  fprintf (stderr, "\n");
    2222
    23   fprintf (stderr, " (mode) is one of detections, objects, skytable\n");
     23  fprintf (stderr, " (mode) is one of detections, objects, forced_warp_objects, skytable\n");
    2424
    2525  fprintf (stderr, "\n");
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvopsps/src/insert_detections_dvopsps.c

    r37304 r37822  
    9595    dvo_catalog_unlock (&catalog);
    9696    dvo_catalog_free (&catalog);
     97
     98    if (!status) {
     99      fprintf (stderr, "failure to insert data in mysql\n");
     100      exit (2);
     101    }
    97102  }
    98103
     
    281286}
    282287
    283 # define PRINT_FLOAT(BUFFER,FIELD,FORMAT)                 \
    284   if (!isfinite(FIELD)) PrintIOBuffer (BUFFER, "NULL, "); \
    285   else PrintIOBuffer (BUFFER, FORMAT, FIELD);
    286 
    287 int insert_detections_mysql_detvalue (IOBuffer *buffer, Detections *detection) {
    288 
    289   PrintIOBuffer (buffer, "(%d, ", detection->imageID);    // imageID
    290   PrintIOBuffer (buffer, "%u, ", detection->ippDetectID); // ippDetectID
    291   PrintIOBuffer (buffer, "%lu, ", detection->detectID);   // detectID
    292   PrintIOBuffer (buffer, "%lu, ", detection->ippObjID);   // ippObjID
    293   PrintIOBuffer (buffer, "%lu, ", detection->objID);      // objID
    294   PrintIOBuffer (buffer, "%u, ", detection->flags);       // flags
    295   PRINT_FLOAT(buffer, detection->zp,      "%.6f, ");
    296   PRINT_FLOAT(buffer, detection->zpErr,   "%.6f, ");
    297   PRINT_FLOAT(buffer, detection->airMass, "%.6f, ");
    298   PRINT_FLOAT(buffer, detection->expTime, "%.6f, ");
    299   PRINT_FLOAT(buffer, detection->ra,      "%.8f, ");
    300   PRINT_FLOAT(buffer, detection->dec,     "%.8f, ");
    301   PRINT_FLOAT(buffer, detection->raErr,   "%.6f, ");
    302   PRINT_FLOAT(buffer, detection->decErr,  "%.6f),\n");
    303   return TRUE;
    304 }
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c

    r37048 r37822  
    66Detections *detections = NULL;
    77
     8static float ZeroPoint = 25.0;
     9
    810int init_detections () {
    911  NDETECTIONS = 1000;
     
    1517
    1618  off_t i, j;
     19
     20  ZeroPoint = GetZeroPoint();
    1721
    1822  int missingID = 0;
     
    4751      if (measure->photcode >=  PHOTCODE_END) continue;
    4852
    49       PhotCode *code = GetPhotcodebyCode(measure->photcode);
    50 
    51       detections[Ndetections].imageID     = measure->imageID;    // imageID
    52       detections[Ndetections].ippDetectID = measure->detID;   // ippDetectID
    53       detections[Ndetections].detectID    = measure->extID;   // detectID
    54       detections[Ndetections].ippObjID    = ((uint64_t)average->catID * 1000000000) + (uint64_t)average->objID; // ippObjID
    55       // NOTE: this is better, but the above is the current ippToPsps value
    56       // detections[Ndetections]. ((uint64_t)average->catID << 32) + (uint64_t)average->objID; // ippObjID
    57       detections[Ndetections].objID        = average->extID;   // objID
    58       detections[Ndetections].photcode     = measure->photcode;   // photcode
    59       detections[Ndetections].flags        = measure->dbFlags;  // flags
    60       detections[Ndetections].zp           = code->C * 0.001 + code->K * (measure->airmass - 1) - measure->Mcal;   // zp
    61       detections[Ndetections].zpErr        = measure->dMcal;    // zpErr
    62       detections[Ndetections].airMass      = measure->airmass;
    63       detections[Ndetections].expTime      = pow(10.0, 0.4 * measure->dt);    // expTime
    64       detections[Ndetections].ra           = measure->R;    // ra
    65       detections[Ndetections].dec          = measure->D;    // dec
    66       detections[Ndetections].raErr        = measure->dXccd * 0.01 * fabs(measure->pltscale); // estimate of raErr
    67       detections[Ndetections].decErr       = measure->dYccd * 0.01 * fabs(measure->pltscale); // estimate of decErr
    68 
     53      assign_detection_values (&detections[Ndetections], measure, average);
    6954      Ndetections ++;
     55
    7056      myAssert (Ndetections <= NDETECTIONS, "programming error");
    7157    }
     
    10995
    11096  off_t found = 0;
     97
     98  ZeroPoint = GetZeroPoint();
    11199
    112100  INITTIME;
     
    143131
    144132      // XXX check return status
    145       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)) {
    146137        fprintf (stderr, "failure to insert detections in mysql\n");
    147138        status = FALSE;
     
    194185  }
    195186
    196   // PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, photcode, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
    197   PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
    198 
    199   return TRUE;
    200 }
    201 
    202 # define PRINT_FLOAT(BUFFER,FIELD,FORMAT)                 \
    203   if (isinf(FIELD) || isnan(FIELD)) PrintIOBuffer (BUFFER, "NULL, ");   \
    204   else PrintIOBuffer (BUFFER, FORMAT, FIELD);
    205 
    206 int insert_detections_mysql_value (IOBuffer *buffer, Average *average, Measure *measure) {
    207 
    208   PhotCode *code = GetPhotcodebyCode(measure->photcode);
    209   PrintIOBuffer (buffer, "(%d, ", measure->imageID);      // imageID
    210   PrintIOBuffer (buffer, "%u, ", measure->detID); // ippDetectID
    211   PrintIOBuffer (buffer, "%lu, ", measure->extID);        // detectID
    212   PrintIOBuffer (buffer, "%lu, ", ((uint64_t)average->catID * 1000000000) + (uint64_t)average->objID);    // ippObjID
    213   // NOTE: the following is better, but the above is the current ippToPsps value
    214   // ((uint64_t)average->catID << 32) + (uint64_t)average->objID, // ippObjID
    215   PrintIOBuffer (buffer, "%lu, ", average->extID);        // objID
    216   // XXX PrintIOBuffer (buffer, "%d, ", measure->photcode);       // photcode
    217   PrintIOBuffer (buffer, "%u, ", measure->dbFlags);       // flags
    218 
    219   float zp = code->C * 0.001 + code->K * (measure->airmass - 1) - measure->Mcal;
    220   float exptime = pow(10.0, 0.4 * measure->dt);
    221   double ra  = measure->R;
    222   double dec = measure->D;
    223   double dR = measure->dXccd * 0.01 * fabs(measure->pltscale);
    224   double dD = measure->dYccd * 0.01 * fabs(measure->pltscale);
    225 
    226   PRINT_FLOAT(buffer, zp,               "%.6f, ");
    227   PRINT_FLOAT(buffer, measure->dMcal,   "%.6f, ");
    228   PRINT_FLOAT(buffer, measure->airmass, "%.6f, ");
    229   PRINT_FLOAT(buffer, exptime,          "%.6f, ");
    230   PRINT_FLOAT(buffer, ra,               "%.8f, ");
    231   PRINT_FLOAT(buffer, dec,              "%.8f, ");
    232   PRINT_FLOAT(buffer, dR,               "%.6f, ");
    233   PRINT_FLOAT(buffer, dD,               "%.6f),\n");
    234  
    235   return TRUE;
    236 }
    237    
     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
    238194int insert_detections_mysql_commit (IOBuffer *buffer, MYSQL *mysql) {
    239195
     
    254210  // XXX check return status
    255211  if (mysql) {
    256     if (DEBUG) fprintf (stderr, "%s\n", buffer->buffer);
    257212    int mysqlStatus = mysql_query(mysql, buffer->buffer);
    258213    if (mysqlStatus) {
     
    260215      fprintf (stderr, "%s\n", mysql_error(mysql));
    261216      fprintf (stderr, "Nbuffer: %d\n", buffer->Nbuffer);
     217      if (DEBUG) fprintf (stderr, "%s\n", buffer->buffer);
    262218      status = FALSE;
    263219    }
     
    270226  return status;
    271227}
     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  // XXX I needed OFF_T_FMT on my 32bit ubuntu laptop; ok on 64bit?
     242  PrintIOBuffer (buffer, "("OFF_T_FMT", ", detection->objID);       // objID
     243  PrintIOBuffer (buffer,  OFF_T_FMT", ", detection->detectID);    // detectID
     244  PrintIOBuffer (buffer,  OFF_T_FMT", ", detection->ippObjID);    // ippObjID
     245  PrintIOBuffer (buffer,  "%u,  ", detection->ippDetectID); // ippDetectID
     246  PrintIOBuffer (buffer,  "%d,  ", detection->imageID);     // imageID
     247  PrintIOBuffer (buffer,  "%d,  ", detection->catID);       // DVO Catalog ID
     248
     249  PRINT_FLOAT(buffer, detection->ra,          "%.8f, ");
     250  PRINT_FLOAT(buffer, detection->dec,         "%.8f, ");
     251  PRINT_FLOAT(buffer, detection->raErr,       "%.6f, ");
     252  PRINT_FLOAT(buffer, detection->decErr,      "%.6f, ");
     253  PRINT_FLOAT(buffer, detection->zp,          "%.6f, ");
     254  PRINT_FLOAT(buffer, detection->telluricExt, "%.6f, ");
     255  PRINT_FLOAT(buffer, detection->airmass,     "%.6f, ");
     256  PRINT_FLOAT(buffer, detection->expTime,     "%.6f, ");
     257
     258  PRINT_FLOAT(buffer, detection->Mpsf,        "%.6f, ");
     259  PRINT_FLOAT(buffer, detection->dMpsf,       "%.6f, ");
     260  PRINT_FLOAT(buffer, detection->Mkron,       "%.6f, ");
     261  PRINT_FLOAT(buffer, detection->dMkron,      "%.6f, ");
     262  PRINT_FLOAT(buffer, detection->Map,         "%.6f, ");
     263  PRINT_FLOAT(buffer, detection->dMap,        "%.6f, ");
     264
     265  PrintIOBuffer (buffer, "%u),\n", detection->flags);     // flags
     266  return TRUE;
     267}
     268
     269float getMagFromValueOrFlux (float flux, float mag, float zp) {
     270
     271  // first, if mag is finite, use mag:
     272  if (isfinite(mag)) {
     273    return (zp + mag - ZeroPoint);
     274  }
     275
     276  if (isfinite(flux) && (flux > 0.0)) {
     277    // fprintf (stderr, "funny flux: %f with mag %f\n", flux, mag);
     278    return (zp - 2.5*log10(flux));
     279  }
     280
     281  if (isfinite(flux) && (flux <= 0.0)) {
     282    return (NAN);
     283  }
     284  return (NAN);
     285}
     286
     287float getdMagFromValueOrFlux (float flux, float dflux, float dmag) {
     288
     289  // first, if mag is finite, use mag:
     290  if (isfinite(dmag)) {
     291    return (dmag);
     292  }
     293
     294  if (isfinite(flux) && isfinite(dflux)) {
     295    return (dflux / fabs(flux));
     296  }
     297  return (NAN);
     298}
     299
     300int assign_detection_values (Detections *detection, Measure *measure, Average *average) {
     301
     302  PhotCode *code = GetPhotcodebyCode(measure->photcode);
     303
     304  uint64_t ippObjID = ((uint64_t)average->catID << 32) + (uint64_t)average->objID; // ippObjID
     305
     306  float nominalZP   = code->C * 0.001 + code->K * (measure->airmass - 1);
     307  float zp          = nominalZP - measure->Mcal;
     308  float telluricExt = - measure->Mcal;
     309  float expTime     = pow(10.0, 0.4 * measure->dt);
     310  float airmass     = measure->airmass;
     311
     312  detection->objID        = average->extID;   // objID
     313  detection->detectID     = measure->extID;   // detectID
     314  detection->ippObjID     = ippObjID;         // ippObjID
     315  detection->ippDetectID  = measure->detID;   // ippDetectID
     316  detection->imageID      = measure->imageID; // imageID
     317  detection->catID        = measure->catID;   // catID
     318
     319  detection->ra           = measure->R;    // ra
     320  detection->dec          = measure->D;    // dec
     321  detection->raErr        = measure->dXccd * 0.01 * fabs(measure->pltscale); // estimate of raErr
     322  detection->decErr       = measure->dYccd * 0.01 * fabs(measure->pltscale); // estimate of decErr
     323
     324  detection->zp           = zp;
     325  detection->telluricExt  = telluricExt;
     326  detection->airmass      = airmass;
     327  detection->expTime      = expTime;
     328
     329  // XXX clean this up with dvo_photcode_ops calls:
     330  // if (isfinite(measure->FluxPSF) && (measure->FluxPSF < 0.0))
     331  detection->Mpsf  = getMagFromValueOrFlux (measure->FluxPSF,  measure->M,     zp);
     332  detection->Mkron = getMagFromValueOrFlux (measure->FluxKron, measure->Mkron, zp);
     333  detection->Map   = getMagFromValueOrFlux (measure->FluxAp,   measure->Map,   zp);
     334
     335  detection->dMpsf  = getdMagFromValueOrFlux (measure->FluxPSF,  measure->dFluxPSF,  measure->dM);
     336  detection->dMkron = getdMagFromValueOrFlux (measure->FluxKron, measure->dFluxKron, measure->dMkron);
     337  detection->dMap   = getdMagFromValueOrFlux (measure->FluxAp,   measure->dFluxAp,   measure->dMap);
     338
     339  detection->flags  = measure->dbFlags;  // flags
     340
     341  return TRUE;
     342}
     343
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvopsps/src/insert_objects_dvopsps_catalog.c

    r37048 r37822  
    8888  bzero (buffer.buffer, buffer.Nalloc);
    8989
     90  // Only send the necessary fields (eg, do not sent parallax and pm)
    9091  PrintIOBuffer (&buffer, "CREATE TABLE %s_cpt ("
    91                  "RA DOUBLE,  "         
    92                  "DEC_ DOUBLE,  "         
    93                  "RA_ERR FLOAT,  "     
    94                  "DEC_ERR FLOAT,  "     
    95                  "U_RA FLOAT,  "       
    96                  "U_DEC FLOAT,  "       
    97                  "V_RA_ERR FLOAT,  "   
    98                  "V_DEC_ERR FLOAT,  "   
    99                  "PAR FLOAT,  "         
    100                  "PAR_ERR FLOAT,  "     
    101                  "CHISQ_POS FLOAT,  "   
    102                  "CHISQ_PM FLOAT,  "   
    103                  "CHISQ_PAP FLOAT,  "   
    104                  "MEAN_EPOCH INT,  " 
    105                  "TIME_RANGE INT,  " 
    106                  "PSF_QF FLOAT, "     
    107                  "PSF_QF_PERF FLOAT,  "
    108                  "STARGAL_SEP FLOAT,  "
    109                  "NUMBER_POS SMALLINT,  " 
    110                  "NMEASURE SMALLINT,  "   
    111                  "NMISSING SMALLINT,  "   
    112                  "NEXTEND SMALLINT,  "     
    113                  "OFF_MEASURE INT,  "
    114                  "OFF_MISSING INT,  "
    115                  "OFF_EXTEND INT,  " 
    116                  "FLAGS INT,  "       
    117                  "PHOTFLAGS_U INT,  "
    118                  "PHOTFLAGS_L INT,  "
    119                  "OBJ_ID INT,  "     
    120                  "CAT_ID INT,  "     
    121                  "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       "       
    122110                 ")\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
    123133
    124134  if (DEBUG) fprintf (stderr, "%s\n", buffer.buffer);
     
    145155
    146156  PrintIOBuffer (&buffer, "CREATE TABLE %s_cps ("
    147                  "MAG FLOAT,  "             
    148                  "MAG_AP FLOAT,  "             
    149                  "MAG_KRON FLOAT,  "       
    150                  "MAG_KRON_ERR FLOAT,  "   
    151                  "MAG_ERR FLOAT,  "         
    152                  "MAG_CHI FLOAT,  "         
    153                  "STACK_PSF_MAG FLOAT,  "       
    154                  "STACK_PSF_MAG_ERR FLOAT,  "   
    155                  "STACK_KRON_MAG FLOAT,  "      
    156                  "STACK_KRON_MAG_ERR FLOAT,  "   
    157                  "FLAGS INT,  "           
    158                  "NCODE SMALLINT,  "           
    159                  "NUSED SMALLINT,  "           
    160                  "MAG_20 SMALLINT,  "         
    161                  "MAG_80 SMALLINT,  "         
    162                  "UBERCAL_DIST SMALLINT,  "   
    163                  "MAG_STDEV SMALLINT,  "       
    164                  "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 "         
    165175                 ")\n", basename);
    166 
    167  //              "FLUX_PSF FLOAT,  "       
    168  //              "FLUX_PSF_ERR FLOAT,  "   
    169  //              "FLUX_KRON FLOAT,  "       
    170  //              "FLUX_KRON_ERR FLOAT,  "   
    171176
    172177  if (DEBUG) fprintf (stderr, "%s\n", buffer.buffer);
     
    191196
    192197  PrintIOBuffer (ave_buffer, "INSERT INTO %s_cpt ("
    193                  "RA, "         
    194                  "DEC_, "         
    195                  "RA_ERR, "     
    196                  "DEC_ERR, "     
    197                  "U_RA, "       
    198                  "U_DEC, "       
    199                  "V_RA_ERR, "   
    200                  "V_DEC_ERR, "   
    201                  "PAR, "         
    202                  "PAR_ERR, "     
    203                  "CHISQ_POS, "   
    204                  "CHISQ_PM, "   
    205                  "CHISQ_PAP, "   
    206                  "MEAN_EPOCH, " 
    207                  "TIME_RANGE, " 
    208                  "PSF_QF, "     
    209                  "PSF_QF_PERF, "
    210                  "STARGAL_SEP, "
    211                  "NUMBER_POS, " 
    212                  "NMEASURE, "   
    213                  "NMISSING, "   
    214                  "NEXTEND, "     
    215                  "OFF_MEASURE, "
    216                  "OFF_MISSING, "
    217                  "OFF_EXTEND, " 
    218                  "FLAGS, "       
    219                  "PHOTFLAGS_U, "
    220                  "PHOTFLAGS_L, "
    221                  "OBJ_ID, "     
    222                  "CAT_ID, "     
    223                  "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          "       
    224216                 ") VALUES \n", basename);
    225217
     
    230222  PrintIOBuffer (sec_buffer, "INSERT INTO %s_cps ("
    231223                 "MAG, "             
    232                  "MAG_AP, "             
     224                 "MAG_ERR, "         
     225                 "MAG_STDEV, "       
     226                 "MAG_MIN, "         
     227                 "MAG_MAX, "         
     228                 "NUSED, "           
     229
    233230                 "MAG_KRON, "       
    234231                 "MAG_KRON_ERR, "   
    235                  "MAG_ERR, "         
    236                  "MAG_CHI, "         
    237                  "STACK_PSF_MAG, "       
    238                  "STACK_PSF_MAG_ERR, "   
    239                  "STACK_KRON_MAG, "       
    240                  "STACK_KRON_MAG_ERR, "   
    241                  "FLAGS, "           
     232                 "MAG_KRON_STDEV, "   
     233                 "NUSED_KRON, "           
     234
     235                 "MAG_AP, "             
     236                 "MAG_AP_ERR, "             
     237                 "MAG_AP_STDEV, "             
     238                 "NUSED_AP, "           
     239
    242240                 "NCODE, "           
    243                  "NUSED, "           
    244                  "MAG_20, "         
    245                  "MAG_80, "         
    246                  "UBERCAL_DIST, "   
    247                  "MAG_STDEV, "       
    248                  "STACK_DETECT_ID "
     241                 "NSTACK_DET,  "           
     242                 "PSF_QF_PERF_MAX, "           
     243                 "FLAGS "           
    249244                 ") VALUES \n", basename);
    250245  return TRUE;
     
    261256// XXX this bit could/should be autocoded...
    262257  PrintIOBuffer (ave_buffer, " (");
     258  PrintIOBuffer (ave_buffer, OFF_T_FMT", ", 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
    263271  PRINT_FLOAT(ave_buffer, average->R,        "%.8f, ");  // 0.036 mas precision
    264272  PRINT_FLOAT(ave_buffer, average->D,        "%.8f, ");  // 0.036 mas precision
    265273  PRINT_FLOAT(ave_buffer, average->dR,       "%.5f, ");  // 0.010 mas precision
    266274  PRINT_FLOAT(ave_buffer, average->dD,       "%.5f, ");  // 0.010 mas precision
    267   PRINT_FLOAT(ave_buffer, average->uR,       "%.5f, ");  // 0.010 mas/yr precision
    268   PRINT_FLOAT(ave_buffer, average->uD,       "%.5f, ");
    269   PRINT_FLOAT(ave_buffer, average->duR,      "%.5f, ");
    270   PRINT_FLOAT(ave_buffer, average->duD,      "%.5f, ");
    271   PRINT_FLOAT(ave_buffer, average->P,        "%.5f, ");
    272   PRINT_FLOAT(ave_buffer, average->dP,       "%.5f, ");
     275
    273276  PRINT_FLOAT(ave_buffer, average->ChiSqAve, "%.4f, ");
    274277  PRINT_FLOAT(ave_buffer, average->ChiSqPM,  "%.4f, ");
    275278  PRINT_FLOAT(ave_buffer, average->ChiSqPar, "%.4f, ");
    276   PrintIOBuffer (ave_buffer, "%d, ",  average->Tmean);         
    277   PrintIOBuffer (ave_buffer, "%d, ",  average->Trange);         
    278   PRINT_FLOAT(ave_buffer, average->psfQF,     "%.3f, ");
    279   PRINT_FLOAT(ave_buffer, average->psfQFperf, "%.3f, ");
    280   PRINT_FLOAT(ave_buffer, average->stargal,   "%.3f, ");
    281   PrintIOBuffer (ave_buffer, "%hu, ", average->Npos);           
    282   PrintIOBuffer (ave_buffer, "%hu, ", average->Nmeasure);       
    283   PrintIOBuffer (ave_buffer, "%hu, ", average->Nmissing);       
    284   PrintIOBuffer (ave_buffer, "%hu, ", average->Nextend);       
    285   PrintIOBuffer (ave_buffer, "%d, ",  average->measureOffset); 
    286   PrintIOBuffer (ave_buffer, "%d, ",  average->missingOffset); 
    287   PrintIOBuffer (ave_buffer, "%d, ",  0); // was : average->extendOffset);   
    288   PrintIOBuffer (ave_buffer, "%u, ",  average->flags);         
    289   PrintIOBuffer (ave_buffer, "%u, ",  average->photFlagsUpper);
    290   PrintIOBuffer (ave_buffer, "%u, ",  average->photFlagsLower);
    291   PrintIOBuffer (ave_buffer, "%u, ",  average->objID);         
    292   PrintIOBuffer (ave_buffer, "%u, ",  average->catID);         
    293   PrintIOBuffer (ave_buffer, "%lu",   average->extID);         
     279
     280  PrintIOBuffer (ave_buffer, "%u ",  average->flags);         
     281
    294282  PrintIOBuffer (ave_buffer, "),\n");
    295283
     284  // XXX what rules for keeping or NAN-ing various mags?
    296285  for (i = 0; i < Nsecfilt; i++) {
    297286    float meanPSFMag    = -999.0;
    298287    float meanPSFMagErr = -999.0;
     288    float meanPSFMagStd = -999.0;
     289    float meanPSFMagMin = -999.0;
     290    float meanPSFMagMax = -999.0;
    299291    if (isfinite(secfilt->dM) && isfinite(secfilt->M)) {
    300       meanPSFMag = secfilt->M;
     292      meanPSFMag    = secfilt->M;
    301293      meanPSFMagErr = secfilt->dM;
     294      meanPSFMagStd = secfilt->Mstdev;
     295      meanPSFMagMin = secfilt->Mmin;
     296      meanPSFMagMax = secfilt->Mmax;
    302297    }
    303298
    304299    float meanKronMag    = -999.0;
    305300    float meanKronMagErr = -999.0;
     301    float meanKronMagStd = -999.0;
    306302    if (isfinite(secfilt->dMkron) && isfinite(secfilt->Mkron) && (secfilt->dMkron < 0.333)) {
    307       meanKronMag = secfilt->Mkron;
     303      meanKronMag    = secfilt->Mkron;
    308304      meanKronMagErr = secfilt->dMkron;
     305      meanKronMagStd = secfilt->sMkron;
    309306    }
    310307
    311308    float meanApMag    = -999.0;
    312     if (isfinite(secfilt->Map)) {
    313       meanApMag = secfilt->Map;
    314     }
    315 
    316     float stackPSFMag    = -999.0;
    317     float stackPSFMagErr = -999.0;
    318     if (isfinite(secfilt->dFpsfStk) && isfinite(secfilt->FpsfStk) && (secfilt->dFpsfStk > 0.0)) {
    319       float SN = secfilt->FpsfStk / secfilt->dFpsfStk;
    320       if (SN > 3.0) {
    321         stackPSFMag = -2.5 * log10(secfilt->FpsfStk) + 8.9;
    322         stackPSFMagErr = secfilt->dFpsfStk / secfilt->FpsfStk;
    323       }
    324     }
    325 
    326     float stackKronMag    = -999.0;
    327     float stackKronMagErr = -999.0;
    328     if (isfinite(secfilt->dFkronStk) && isfinite(secfilt->FkronStk) && (secfilt->dFkronStk > 0.0)) {
    329       float SN = secfilt->FkronStk / secfilt->dFkronStk;
    330       if (SN > 3.0) {
    331         stackKronMag = -2.5 * log10(secfilt->FkronStk) + 8.9;
    332         stackKronMagErr = secfilt->dFkronStk / secfilt->FkronStk;
    333       }
     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;
    334315    }
    335316
    336317    PrintIOBuffer (sec_buffer, " (");
    337318    PRINT_FLOAT(sec_buffer, meanPSFMag,      "%.6f, "); // umag precision
    338     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
    339325    PRINT_FLOAT(sec_buffer, meanKronMag,     "%.6f, "); // umag precision
    340326    PRINT_FLOAT(sec_buffer, meanKronMagErr,  "%.6f, "); // umag precision
    341     PRINT_FLOAT(sec_buffer, meanPSFMagErr,   "%.6f, "); // umag precision
    342     PRINT_FLOAT(sec_buffer, secfilt->Mchisq, "%.6f, ");
    343     PRINT_FLOAT(sec_buffer, stackPSFMag,     "%.6f, "); // umag precision
    344     PRINT_FLOAT(sec_buffer, stackPSFMagErr,  "%.6f, "); // umag precision
    345     PRINT_FLOAT(sec_buffer, stackKronMag,    "%.6f, "); // umag precision
    346     PRINT_FLOAT(sec_buffer, stackKronMagErr, "%.6f, "); // 0.36 umag precision
    347     PrintIOBuffer (sec_buffer, "%u,   ", secfilt->flags);       
     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);        
    348334    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->Ncode);       
    349     PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->Nused);       
    350     PrintIOBuffer (sec_buffer, "%.6f, ", secfilt->Mmin);         
    351     PrintIOBuffer (sec_buffer, "%.6f, ", secfilt->Mmax);         
    352     PrintIOBuffer (sec_buffer, "%hd, ", secfilt->ubercalDist); 
    353     PrintIOBuffer (sec_buffer, "%.6f, ", secfilt->Mstdev);       
    354     PrintIOBuffer (sec_buffer, "%lu  ", secfilt->stackDetectID);
     335    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->NstackDet);       
     336
     337    PRINT_FLOAT(sec_buffer, secfilt->psfQfPerfMax, "%.6f,");       
     338    PrintIOBuffer (sec_buffer, "%u ", secfilt->flags);       
    355339    PrintIOBuffer (sec_buffer, "),\n");
    356340    secfilt ++;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvosplit/include/dvosplit.h

    r33656 r37822  
    2222} AveLinks;
    2323
     24int    FULL_TABLE;
    2425int    VERBOSE;
    2526char  *OUTDIR;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvosplit/src/args.c

    r33656 r37822  
    5757  }
    5858
     59  // override input catalog format (PS1_V1, PS1_REF, etc)
     60  FULL_TABLE = FALSE;
     61  if ((N = get_argument (argc, argv, "-full-table"))) {
     62    remove_argument (N, &argc, argv);
     63    FULL_TABLE = TRUE;
     64  }
     65
    5966  /* extra error messages */
    6067  VERBOSE = FALSE;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvosplit/src/split_averages.c

    r37043 r37822  
    2727  incatalog[0].catflags = LOAD_AVES | LOAD_SECF;
    2828
    29   if (incatalog[0].catmode == DVO_MODE_SPLIT) {
     29  if ((incatalog[0].catmode == DVO_MODE_SPLIT) && !FULL_TABLE) {
    3030    Nblocks = incatalog[0].Naves_disk / NROWS;
    3131    if (incatalog[0].Naves_disk % NROWS) Nblocks ++;
     
    3636  for (block = 0; block < Nblocks; block++) {
    3737
    38     if (incatalog[0].catmode == DVO_MODE_SPLIT) {
     38    if ((incatalog[0].catmode == DVO_MODE_SPLIT) && !FULL_TABLE) {
    3939      // read up to NROWS at a time
    4040      dvo_catalog_load_segment (incatalog, VERBOSE, block*NROWS, NROWS);
    4141      fprintf (stderr, "splitting %s (averages) .. %d of %d\n", incatalog[0].filename, block, Nblocks);
     42      assert (block*NROWS == incatalog[0].Naves_off);
    4243    } else {
    4344      dvo_catalog_load (incatalog, VERBOSE);
    4445      fprintf (stderr, "splitting %s (averages)\n", incatalog[0].filename);
    4546    }
    46 
    47     assert (block*NROWS == incatalog[0].Naves_off);
    4847
    4948    // distribute data to the output catalogs
     
    5453      inD = incatalog[0].average[ave].D;
    5554
     55      if (incatalog[0].average[ave].Nmeasure == 0) {
     56        fprintf (stderr, "WARNING: object with no measurements, skipping %d (%f, %f)\n", averef, inR, inD);
     57        continue;
     58      }
    5659      // which of the outcatalogs contains this coordinate?
    5760
     
    98101
    99102    // write out the new values
    100     for (cat = 0; cat < outlist[0].Nregions; cat++) {
    101       outcatalogs[cat].catflags = LOAD_AVES | LOAD_SECF;
     103    if (!FULL_TABLE) {
     104      for (cat = 0; cat < outlist[0].Nregions; cat++) {
     105        outcatalogs[cat].catflags = LOAD_AVES | LOAD_SECF;
    102106
    103       dvo_catalog_save (&outcatalogs[cat], VERBOSE);
    104       // fprintf (stderr, "secfilt: %d %d %d %d\n", outcatalogs[cat].Nsecf_mem, outcatalogs[cat].Nsecf_disk, outcatalogs[cat].Nsecf_off, outcatalogs[cat].Naverage, outcatalogs[cat].Nsecfilt);
     107        dvo_catalog_save (&outcatalogs[cat], VERBOSE);
     108        // fprintf (stderr, "secfilt: %d %d %d %d\n", outcatalogs[cat].Nsecf_mem, outcatalogs[cat].Nsecf_disk, outcatalogs[cat].Nsecf_off, outcatalogs[cat].Naverage, outcatalogs[cat].Nsecfilt);
    105109
    106       // advance the pointers and free the current data
    107       // XXX these should be done within save segment:
    108       outcatalogs[cat].Naves_disk += outcatalogs[cat].Naverage;
    109       outcatalogs[cat].Naves_off  += outcatalogs[cat].Naverage;
    110       outcatalogs[cat].Nsecf_disk += outcatalogs[cat].Nsecfilt * outcatalogs[cat].Naverage;
    111       outcatalogs[cat].Nsecf_off  += outcatalogs[cat].Nsecfilt * outcatalogs[cat].Naverage;
    112       outcatalogs[cat].Nsecfilt    = Nsecfilt;
     110        // advance the pointers and free the current data
     111        // XXX these should be done within save segment:
     112        outcatalogs[cat].Naves_disk += outcatalogs[cat].Naverage;
     113        outcatalogs[cat].Naves_off  += outcatalogs[cat].Naverage;
     114        outcatalogs[cat].Nsecf_disk += outcatalogs[cat].Nsecfilt * outcatalogs[cat].Naverage;
     115        outcatalogs[cat].Nsecf_off  += outcatalogs[cat].Nsecfilt * outcatalogs[cat].Naverage;
     116        outcatalogs[cat].Nsecfilt    = Nsecfilt;
    113117
    114       outcatalogs[cat].Naverage    = 0;
    115       outcatalogs[cat].Nsecf_mem   = 0;
     118        outcatalogs[cat].Naverage    = 0;
     119        outcatalogs[cat].Nsecf_mem   = 0;
     120      }
    116121    }
    117122  }
    118123
    119   for (cat = 0; cat < outlist[0].Nregions; cat++) {
    120     dvo_catalog_free_data (&outcatalogs[cat]);
     124  if (!FULL_TABLE) {
     125    for (cat = 0; cat < outlist[0].Nregions; cat++) {
     126      dvo_catalog_free_data (&outcatalogs[cat]);
     127    }
    121128  }
    122129
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/dvosplit/src/split_measures.c

    r37043 r37822  
    2727  // }
    2828
    29   if (incatalog[0].catmode == DVO_MODE_SPLIT) {
     29  if ((incatalog[0].catmode == DVO_MODE_SPLIT) && !FULL_TABLE) {
    3030    Nblocks = incatalog[0].Nmeas_disk / NROWS;
    3131    if (incatalog[0].Nmeas_disk % NROWS) Nblocks ++;
     
    3737
    3838    // read up to NROWS at a time
    39     if (incatalog[0].catmode == DVO_MODE_SPLIT) {
     39    if ((incatalog[0].catmode == DVO_MODE_SPLIT) && !FULL_TABLE) {
    4040      dvo_catalog_load_segment (incatalog, VERBOSE, block*NROWS, NROWS);
    4141      fprintf (stderr, "splitting %s (measures) .. %d of %d\n", incatalog[0].filename, block, Nblocks);
     42      assert (block*NROWS == incatalog[0].Nmeas_off);
    4243    } else {
    4344      dvo_catalog_load (incatalog, VERBOSE);
    4445      fprintf (stderr, "splitting %s (measures)\n", incatalog[0].filename);
    4546    }
    46 
    47     assert (block*NROWS == incatalog[0].Nmeas_off);
    4847
    4948    for (meas = 0; meas < incatalog[0].Nmeasure; meas++) {
     
    5251      Ncat = outcat[averef];
    5352
     53      int averef_out = outref[averef];
     54      if (averef_out >= outcatalogs[Ncat].Naverage) {
     55        fprintf (stderr, "mismatch 1\n");
     56        abort();
     57      }
     58
    5459      Nout = outcatalogs[Ncat].Nmeasure;
    5560      outcatalogs[Ncat].measure[Nout] = incatalog[0].measure[meas];
    5661      outcatalogs[Ncat].measure[Nout].averef = outref[averef];
     62
    5763      outcatalogs[Ncat].Nmeasure++;
    5864
     
    6470    dvo_catalog_free_data (incatalog);
    6571
     72    if (!FULL_TABLE) {
     73      for (cat = 0; cat < outlist[0].Nregions; cat++) {
     74        outcatalogs[cat].catflags = LOAD_MEAS;
     75        dvo_catalog_save (&outcatalogs[cat], VERBOSE);
     76
     77        outcatalogs[cat].Nmeas_disk += outcatalogs[cat].Nmeasure;
     78        outcatalogs[cat].Nmeas_off  += outcatalogs[cat].Nmeasure;
     79        outcatalogs[cat].Nmeasure    = 0;
     80      }
     81    }
     82  }
     83
     84  if (FULL_TABLE) {
    6685    for (cat = 0; cat < outlist[0].Nregions; cat++) {
    67       outcatalogs[cat].catflags = LOAD_MEAS;
     86      outcatalogs[cat].catflags = LOAD_AVES | LOAD_SECF | LOAD_MEAS;
    6887      dvo_catalog_save (&outcatalogs[cat], VERBOSE);
    69 
    70       outcatalogs[cat].Nmeas_disk += outcatalogs[cat].Nmeasure;
    71       outcatalogs[cat].Nmeas_off  += outcatalogs[cat].Nmeasure;
    72       outcatalogs[cat].Nmeasure    = 0;
    73 
    7488    }
    7589  }
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/fixcat/src/gcatstats.c

    r36481 r37822  
    4646  /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
    4747  /* reference for coords is center of field  */
     48  InitCoords (&catstats[0].coords, "DEC--TAN");
    4849  catstats[0].coords.crval1 = RaCenter;
    4950  catstats[0].coords.crval2 = DecCenter;
    50   catstats[0].coords.crpix1 = catstats[0].coords.crpix2 = 0.0;
    5151  catstats[0].coords.cdelt1 = catstats[0].coords.cdelt2 = 1.0 / 3600.0;
    52   catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
    53   catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
    54   strcpy (catstats[0].coords.ctype, "DEC--TAN");
    5552
    5653  X1 = catstats[0].X;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/gastro/src/gfitpoly.c

    r27435 r37822  
    261261    det = 1.0 / (a1*b2 - a2*b1);
    262262
     263    InitCoords (coords, "DEC--PLY");
     264
    263265    coords[0].pc1_1 = p11*a1 + p12*b1*(S2/S1);
    264266    coords[0].pc2_1 = p21*a1 + p22*b1*(S2/S1);
     
    273275
    274276    coords[0].Npolyterms = NORDER;
    275     strcpy (coords[0].ctype, "DEC--PLY");
    276277
    277278    /* generate higher order terms from vector */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/gastro/src/gstars.c

    r36481 r37822  
    7979  if (!strcasecmp (ROUGH_ASTROMETRY, "config")) {
    8080    /* default values for coords */
    81     strcpy (coords[0].ctype, "DEC--TAN");
     81    InitCoords (coords, "DEC--TAN");
    8282    coords[0].pc1_1 = CCD_PC1_1; coords[0].pc1_2 = CCD_PC1_2;
    8383    coords[0].pc2_1 = CCD_PC2_1; coords[0].pc2_2 = CCD_PC2_2;
    8484    coords[0].cdelt1 = coords[0].cdelt2 = ASEC_PIX / 3600.0;
    85     coords[0].Npolyterms = 0;
    8685    coords[0].crpix1 = 0.5*(*NX);
    8786    coords[0].crpix2 = 0.5*(*NY);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/gastro2/src/gproject2.c

    r12332 r37822  
    1919
    2020  /* create Tangent Plane to Sky transformation from input coords */
    21   strcpy (TPtoSky.ctype, coords[0].ctype);
     21  InitCoords (&TPtoSky, coords[0].ctype);
    2222  TPtoSky.crval1 = coords[0].crval1;
    2323  TPtoSky.crval2 = coords[0].crval2;
    2424
    25   TPtoSky.cdelt1 = TPtoSky.cdelt2 = 1;
    26   TPtoSky.crpix1 = TPtoSky.crpix2 = 0;
    27   TPtoSky.pc1_1 = TPtoSky.pc2_2 = 1;
    28   TPtoSky.pc1_2 = TPtoSky.pc2_1 = 0;
    29   TPtoSky.Npolyterms = 0;
    30   for (i = 0; i < 7; i++) {
    31     TPtoSky.polyterms[i][0] = 0;
    32     TPtoSky.polyterms[i][1] = 0;
    33   }
    34 
    3525  /* create Focal Plane to Tangent Plane transformation from input coords */
    36   strcpy (FPtoTP.ctype, "FP---PLY");
    37   FPtoTP.crval1 = FPtoTP.crval2 = 0;
    38 
     26  InitCoords (&FPtoTP, "FP---PLY");
    3927  FPtoTP.cdelt1 = coords[0].cdelt1;
    4028  FPtoTP.cdelt2 = coords[0].cdelt2;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/gastro2/src/gstars2.c

    r37054 r37822  
    2828
    2929  /* default values for coords */
    30   strcpy (Target[0].coords.ctype, "DEC--TAN");
     30  InitCoords (&Target[0].coords, "DEC--TAN");
    3131  Target[0].coords.pc1_1 = CCD_PC1_1; Target[0].coords.pc1_2 = CCD_PC1_2;
    3232  Target[0].coords.pc2_1 = CCD_PC2_1; Target[0].coords.pc2_2 = CCD_PC2_2;
    3333  Target[0].coords.cdelt1 = Target[0].coords.cdelt2 = ASEC_PIX / 3600.0;
    34   Target[0].coords.Npolyterms = 0;
    3534  Target[0].coords.crpix1 = 0.5*NX;
    3635  Target[0].coords.crpix2 = 0.5*NY;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/getstar

  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/getstar/include/dvoImageOverlaps.h

    r27435 r37822  
    3737int edge_check (double *x1, double *y1, double *x2, double *y2);
    3838double opening_angle (double x1, double y1, double x2, double y2, double x3, double y3);
     39
     40void initMosaicCoords ();
     41void saveMosaicCoords (Coords *input);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/getstar/src/MatchCoords.c

    r31238 r37822  
    2929    if (!WITH_PHU && !strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
    3030    if ( SOLO_PHU &&  strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
    31 
    32     /* if any of these images are WRP images, need to find matching DIS */
    33     if (!FindMosaicForImage (dbImages, NdbImages, i)) continue;
    3431
    3532    /* define image corners */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/getstar/src/MatchImages.c

    r36481 r37822  
    2323  /* we keep the original crpix1,2 and crref1,2 */
    2424  /* for mosaic astrometry, the grid should be w.r.t. the tangent-plane, not chip coords */
     25  InitCoords (&tcoords, "DEC--TAN");
    2526  if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
    26     // if the input image is a mosaic, we need to register that mosaic for the calculations below
    27     if (MOSAIC == NULL) {
    28       fprintf (stderr, "no mosaic for WRP image (use -mosaic)\n");
    29       return NULL;
    30     }
    31     RegisterMosaic (MOSAIC);
    32 
    33     tcoords = MOSAIC[0];
     27    myAssert (image[0].coords.mosaic, "should already have tested this");
     28    tcoords = image[0].coords.mosaic[0];
    3429    tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    35     tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    36     tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    37     tcoords.Npolyterms = 1;
    38     strcpy (tcoords.ctype, "DEC--TAN");
    3930    /* register so image->sky conversions below have correct mosaic */
    4031  } else {
    4132    tcoords = image[0].coords;
    4233    tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    43     tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    44     tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    45     tcoords.Npolyterms = 1;
    46     strcpy (tcoords.ctype, "DEC--TAN");
    4734  }
    4835
     
    7764    if (!WITH_PHU && !strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
    7865    if ( SOLO_PHU &&  strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
    79 
    80     /* if any of these images are WRP images, need to find matching DIS */
    81     if (!FindMosaicForImage (dbImages, NdbImages, i)) continue;
    8266
    8367    /* define image corners */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/getstar/src/ReadImageFiles.c

    r36874 r37822  
    4242
    4343  mode = GetFileMode (header);
     44
     45  initMosaicCoords ();
    4446
    4547  /*** load data from a single PHU or a collection of PHU files ***/
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/getstar/src/ReadImageHeader.c

    r21508 r37822  
    11# include "dvoImageOverlaps.h"
     2
     3// for DIS/WRP sets, we need to save the DIS set and supply it to the WRP entries
     4static Coords *mosaic = NULL;
     5
     6void initMosaicCoords () {
     7  mosaic = NULL;
     8}
     9
     10void saveMosaicCoords (Coords *input) {
     11  mosaic = input;
     12}
    213
    314/* read an image header corresponding to a CMF / CMP data block */
     
    4455  /* only load astrometry, NAXIS1,2, and time if this is a MOSAIC_PHU (ctype is ....-DIS) */
    4556  if (!strcmp (&image[0].coords.ctype[4], "-DIS")) {
    46     MOSAIC = &image[0].coords;
     57    saveMosaicCoords (&image[0].coords);
    4758    return (TRUE);
    4859  }
     
    5667  }
    5768  if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
    58     if (MOSAIC == NULL) {
     69    if (mosaic == NULL) {
    5970      fprintf (stderr, "no mosaic for WRP image (use -mosaic)\n");
    6071      return (FALSE);
    6172    }
    62     RegisterMosaic (MOSAIC);
     73    image[0].coords.mosaic = mosaic;
    6374  } else {
    6475    /* force image to lie in 0-360 range */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/getstar/src/WriteImages.c

    r27435 r37822  
    55 
    66  int i, N;
    7   int nWRP, newWRP, isWRP;
     7  int isWRP;
    88  FILE *f;
    99
     
    1616  }
    1717
    18   nWRP = -1;
     18  Image *mosaic = NULL;
    1919  isWRP = FALSE;
    2020  for (i = 0; i < Nmatches; i++) {
    21     if (!strcmp (&images[0].coords.ctype[4], "-WRP")) {
    22       if (!FindMosaicForImage (images, Nimages, i)) {
    23         fprintf (stderr, "failed to find matching mosaic\n");
    24         exit (1);
    25       }
     21    N = matches[i];
     22    if (!strcmp (&images[N].coords.ctype[4], "-WRP")) {
    2623      if (isWRP) {
    27         newWRP = GetRegisteredMosaic();
    28         if (newWRP != nWRP) {
     24        if (mosaic != images[N].parent) {
    2925          fprintf (stderr, "only one mosaic allowed in an output file\n");
    3026          exit (1);
    3127        }
    3228      } else {
    33         nWRP = GetRegisteredMosaic();
    34         isWRP = TRUE;
     29        mosaic = images[N].parent;
    3530      }
    3631    }     
     
    3833
    3934  if (isWRP) {
    40     WriteImageFITS (f, &images[nWRP]);
     35    WriteImageFITS (f, mosaic);
    4136  } else {
    4237    // write a blank
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/imregister/imphot/dumpfits.c

    r30617 r37822  
    3434
    3535  ftable.header = &theader;
    36   gfits_table_set_Image (&ftable, subset, Nmatch);
     36  // gfits_table_set_Image (&ftable, subset, Nmatch);
    3737
    3838  gfits_fwrite_header  (f, &header);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/imregister/imphot/modify.c

    r27435 r37822  
    3030  gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, match, Nmatch);
    3131  for (i = 0; i < Nmatch; i++) {
    32     gfits_convert_Image ((Image *) db[0].vtable.buffer[i], sizeof (Image), 1);
     32    fprintf (stderr, "need to work with real output format\n");
     33    exit (2);
     34    // gfits_convert_Image ((Image *) db[0].vtable.buffer[i], sizeof (Image), 1);
    3335  }
    3436  gfits_db_update (db);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/kapa2/include/constants.h

    r36084 r37822  
    1010 | PointerMotionMask)
    1111
    12 # define NCHANNELS 3
     12# define NCHANNELS 10
    1313# define NPIXELS_DYNAMIC 128
    1414
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/kapa2/include/structures.h

    r32695 r37822  
    217217  KapaImageChannel *image;
    218218  KapaImageChannel channel[NCHANNELS];
     219  int currentChannel;
    219220} KapaImageWidget;
    220221
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/kapa2/src/CreatePicture.c

    r16270 r37822  
    4040
    4141  case 24:
     42   
     43    extra = 4 - (image[0].wide.dx * 3) % 4;
     44    REALLOCATE (image[0].wide.data, char, image[0].wide.dy*(3*image[0].wide.dx+extra));
     45
     46    extra = 4 - (image[0].zoom.dx * 3) % 4;
     47    REALLOCATE (image[0].zoom.data, char, image[0].zoom.dy*(3*image[0].zoom.dx+extra));
     48
    4249    extra = 4 - (image[0].picture.dx * 3) % 4;
    43     REALLOCATE (image[0].wide.data, char, image[0].wide.dy*(3*image[0].wide.dx+extra));
    44     REALLOCATE (image[0].zoom.data, char, image[0].zoom.dy*(3*image[0].zoom.dx+extra));
    4550    REALLOCATE (image[0].picture.data, char, image[0].picture.dy*(3*image[0].picture.dx+extra));
    4651    c = (unsigned char *) image[0].picture.data;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/kapa2/src/CursorOps.c

    r25757 r37822  
    100100  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
    101101  Image_to_Picture (&Sx, &Sy, Ix, Iy, picture);
     102 
     103  // Sx,Sy should be forced into the pixel
     104  int Sxi = Sx + 0.5;
     105  int Syi = Sy + 0.5;
    102106
    103107  // i_start, j_start are now limited to valid screen coordinates
    104   *i_start = MIN (MAX (Sx, 0), picture[0].dx);
    105   *j_start = MIN (MAX (Sy, 0), picture[0].dy);
     108  *i_start = MIN (MAX (Sxi, 0), picture[0].dx);
     109  *j_start = MIN (MAX (Syi, 0), picture[0].dy);
    106110}
    107111 
     
    127131  Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]);
    128132
    129   // I_end, J_end are the last displayed image pixel
    130   // *I_end = Ix;
    131   // *J_end = Iy;
    132 
    133133  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
    134134  Image_to_Picture (&Sx, &Sy, Ix, Iy, picture);
    135135
     136  // Sx,Sy should be forced into the pixel
     137  int Sxi = Sx + 0.5;
     138  int Syi = Sy + 0.5;
     139
     140  // double IxTest, IyTest;
     141  // Picture_to_Image (&IxTest, &IyTest, Sx, Sy, picture);
     142  // fprintf (stderr, "dx,dy: %d,%d : %f,%f : %f,%f : %f:%f\n", picture[0].dx, picture[0].dy, Ix, Iy, Sx, Sy, IxTest, IyTest);
     143
    136144  // i_start, j_start are now limited to valid screen coordinates
    137   *i_end = MIN (MAX (Sx, 0), picture[0].dx);
    138   *j_end = MIN (MAX (Sy, 0), picture[0].dy);
     145  // XXX: i_end, j_end *should* be the last valid screen pixel plus 1
     146  *i_end = MIN (MAX (Sxi, 0), picture[0].dx);
     147  *j_end = MIN (MAX (Syi, 0), picture[0].dy);
    139148
    140149  // round off error can leave us with a small number of extra pixels here.
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/kapa2/src/Graphs.c

    r36487 r37822  
    5757  graph[0].data.flipnorth = FALSE;      // +North = +Y by default
    5858
    59   graph[0].data.coords.pc1_1 = graph[0].data.coords.pc2_2 = 1.0;
    60   graph[0].data.coords.pc1_2 = graph[0].data.coords.pc2_1 = 0.0;
    61   graph[0].data.coords.crval1 = 0.0;
    62   graph[0].data.coords.crval2 = 0.0;
    63   graph[0].data.coords.crpix1 = 0.0;
    64   graph[0].data.coords.crpix2 = 0.0;
    65   graph[0].data.coords.cdelt1 = graph[0].data.coords.cdelt2 = 1.0;
    66   strcpy (graph[0].data.coords.ctype, "DEC--LIN");
     59  InitCoords (&graph[0].data.coords, "DEC--LIN");
    6760  strcpy (graph[0].data.axis, "2222");
    6861  strcpy (graph[0].data.ticks, "2222");
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/kapa2/src/Image.c

    r36487 r37822  
    1111  channel->slope = 1;
    1212
    13   channel->coords.pc1_1 = channel->coords.pc2_2 = 1.0;
    14   channel->coords.pc1_2 = channel->coords.pc2_1 = 0.0;
    15   channel->coords.crval1 = 0.0;
    16   channel->coords.crval2 = 0.0;
    17   channel->coords.crpix1 = 0.0;
    18   channel->coords.crpix2 = 0.0;
    19   channel->coords.cdelt1 = channel->coords.cdelt2 = 1.0;
    20   strcpy (channel->coords.ctype, "DEC--LIN");
    21   channel->coords.Npolyterms = 0;
     13  InitCoords (&channel->coords, "DEC--LIN");
    2214
    2315  channel->matrix.datasize = 0; /* a flag to show there is no data in the matrix */
     
    4234    InitImageChannel (&image[0].channel[i]);
    4335  }
    44   image[0].image = &image[0].channel[0];
     36
     37  image[0].currentChannel = 0;
     38  image[0].image = &image[0].channel[image[0].currentChannel];
    4539
    4640  image[0].nPixels = 0;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/kapa2/src/InterpretKeys.c

    r25757 r37822  
    5050    Z = -1;
    5151
    52     if (graph) {
     52    int haveGraph = graph && graph->haveGraph;
     53    if (haveGraph) {
    5354      X = (event[0].x - graph[0].axis[0].fx)*(graph[0].axis[0].max - graph[0].axis[0].min)/graph[0].axis[0].dfx + graph[0].axis[0].min;
    5455      Y = (event[0].y - graph[0].axis[1].fy)*(graph[0].axis[1].max - graph[0].axis[1].min)/graph[0].axis[1].dfy + graph[0].axis[1].min;
    5556      XY_to_RD (&R, &D, X, Y, &graph[0].data.coords);
    5657    }
    57     if (image && !graph) {
     58    if (image && !haveGraph) {
    5859      if (event[0].x < image[0].picture.x) goto skip_cursor;
    5960      if (event[0].y < image[0].picture.y) goto skip_cursor;
     
    8990  switch (keysym) {
    9091
    91     case XK_F1:
    92       image[0].image = &image[0].channel[0];
    93       SetColorScale (graphic, image);
    94       Remap (graphic, image);
    95       Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0);
     92# define SET_CHANNEL_CASE(NCHAN) \
     93    case XK_F##NCHAN: \
     94      image[0].currentChannel = NCHAN-1; \
     95      image[0].image = &image[0].channel[NCHAN-1]; \
     96      SetColorScale (graphic, image); \
     97      Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0); \
     98      Screen_to_Image (&X, &Y, (double)(event[0].x + 0.5), (double)(event[0].y + 0.5), &image[0].picture); \
     99      UpdateStatusBox (graphic, image, X, Y, 0.0, 1); \
    96100      break;
    97101
    98     case XK_F2:
    99       image[0].image = &image[0].channel[1];
    100       SetColorScale (graphic, image);
    101       Remap (graphic, image);
    102       Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0);
    103       break;
     102//    Remap (graphic, image);
    104103
    105     case XK_F3:
    106       image[0].image = &image[0].channel[2];
    107       SetColorScale (graphic, image);
    108       Remap (graphic, image);
    109       Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0);
    110       break;
     104    // the number of entries here must match the value of NCHANNELS in contants.h
     105    SET_CHANNEL_CASE(1);
     106    SET_CHANNEL_CASE(2);
     107    SET_CHANNEL_CASE(3);
     108    SET_CHANNEL_CASE(4);
     109    SET_CHANNEL_CASE(5);
     110    SET_CHANNEL_CASE(6);
     111    SET_CHANNEL_CASE(7);
     112    SET_CHANNEL_CASE(8);
     113    SET_CHANNEL_CASE(9);
     114    SET_CHANNEL_CASE(10);
    111115
    112116    case XK_KP_Home:
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/kapa2/src/LoadPicture.c

    r28241 r37822  
    5555  // choose expand for wide to guarantee we fit:
    5656  wx = MAX ((header.Naxis[0] / (float) image[0].wide.dx), (header.Naxis[1] / (float) image[0].wide.dy));
    57   if (wx > 1.0) {
    58     image[0].wide.expand = -wx;
    59   } else {
    60     image[0].wide.expand = 1.0 / wx;
    61   }   
     57
     58  // -4.002 -> -5
     59  // image[0].wide.expand = (wx > 1.0) ? ceil (-wx) : floor (1.0 / wx);
     60  image[0].wide.expand = (wx > 1.0) ? floor (-wx) : ceil (1.0 / wx);
     61  // fprintf (stderr, "%d : %f\n", image[0].wide.expand, wx);
     62  image[0].wide.expand = (wx > 1.0) ? ceil (-wx) : floor (1.0 / wx);
     63
    6264  image[0].wide.Xc = 0.5*header.Naxis[0];
    6365  image[0].wide.Yc = 0.5*header.Naxis[1];
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/kapa2/src/Reconfig.c

    r21153 r37822  
    1515
    1616  // if the new size is the same as the old size, do nothing.
    17   if ((graphic->dx == NX) && (graphic->dy == NY)) return (TRUE);
     17  if ((graphic->dx == NX) && (graphic->dy == NY)) {
     18    if (USE_XWINDOW) XClearWindow (graphic->display, graphic->window);
     19    Refresh ();
     20    return (TRUE);
     21  }
    1822
    1923  // set the new window size
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/kapa2/src/Remap32.c

    r34088 r37822  
    3737  swap_client = 0;
    3838# endif 
    39 
    4039  swap_server = ImageByteOrder (graphic[0].display);
    4140  swap_bytes = !(swap_client ^ swap_server);
     
    9190  in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    9291
     92  unsigned short *in_base = image[0].pixmap;
     93  OUT_TYPE *out_base = (OUT_TYPE *) picture[0].data;
     94
     95  int Ninmax = matrix[0].Naxis[0] * matrix[0].Naxis[1];
     96  int Noutmax = picture[0].dx * picture[0].dy;
     97
    9398  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
    9499
    95100  /**** fill in bottom area ****/
    96101  for (j = 0; j < dx*j_start; j++, out_pix++) {
     102    myAssert (out_pix - out_base < Noutmax, "too far out");
    97103    *out_pix = back;
    98104  }
     
    105111      out_pix2 = out_pix + jj*dx;
    106112      for (i = 0; i < i_start; i++, out_pix2++) {
     113        myAssert (out_pix2 - out_base < Noutmax, "too far out");
    107114        *out_pix2 = back;
    108115      }
     
    114121    if (expand_out == 1) {
    115122      for (i = i_start; i < i_end; i++, in_pix2 += inDX*expand_in, out_pix++) {
     123        myAssert (out_pix - out_base < Noutmax, "too far out");
     124        myAssert (in_pix2 - in_base < Ninmax, "too far in");
    116125        *out_pix = pixel[*in_pix2];
    117126      }
    118127    } else {
    119128      for (i = i_start; i < i_end; i+= expand_out, in_pix2 += inDX, out_pix+= expand_out) {
     129        myAssert (in_pix2 - in_base < Ninmax, "too far in");
    120130        pixvalue = pixel[*in_pix2];
    121131        out_pix2 = out_pix;
    122132        for (jj = 0; (jj < expand_out) && (j + jj < dy); jj++, out_pix2+=(dx-expand_out)) {
    123133          for (ii = 0; ii < expand_out; ii++, out_pix2++) {
     134            myAssert (out_pix2 - out_base < Noutmax, "too far out");
    124135            *out_pix2 = pixvalue;
    125136          }
     
    133144      out_pix2 = out_pix + jj*dx;
    134145      for (i = i_end; i < dx; i++, out_pix2++) {
     146        myAssert (out_pix2 - out_base < Noutmax, "too far out");
    135147        *out_pix2 = back;
    136148      }
     
    142154  for (j = 0; j < dy - j_end; j++) {
    143155    for (i = 0; i < dx; i++, out_pix ++) {
     156      myAssert (out_pix - out_base < Noutmax, "too far out");
    144157      *out_pix = back;
    145158    }
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/kapa2/src/SetChannel.c

    r31665 r37822  
    2121  if (Nchannel >= NCHANNELS) return (TRUE);
    2222 
    23   image[0].image = &image[0].channel[Nchannel];
     23  image[0].currentChannel = Nchannel;
     24  image[0].image = &image[0].channel[image[0].currentChannel];
    2425  SetColorScale (graphic, image);
    2526
     
    6162
    6263  Refresh ();
    63   XFlush (graphic[0].display);
     64  if (USE_XWINDOW) XFlush (graphic[0].display);
    6465
    6566  return (TRUE);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/kapa2/src/UpdateStatusBox.c

    r30606 r37822  
    2020 
    2121    bzero (line, 100);
    22     snprintf (line, 100, "(%d x %d) @ %d                                         ",
    23              image[0].picture.dx, image[0].picture.dy, image[0].picture.expand);
     22    snprintf (line, 100, "(%d x %d) @ %d   ch: %d                                     ",
     23              image[0].picture.dx, image[0].picture.dy, image[0].picture.expand, image[0].currentChannel+1);
    2424    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    2525                 image[0].text_x + PAD1, image[0].text_y + 4*textpad + 4*PAD1, line, 25);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/Makefile.Targets

    r37034 r37822  
    11AOBJS = \
    2 $(ASRC)/coords.$(ARCH).o \
     2$(ASRC)/coords-disk.$(ARCH).o \
     3$(ASRC)/AstromOffsetMap_Disk.$(ARCH).o \
    34$(ASRC)/average.$(ARCH).o \
    45$(ASRC)/average-loneos.$(ARCH).o \
     
    1314$(ASRC)/average-ps1-v4.$(ARCH).o \
    1415$(ASRC)/average-ps1-v5.$(ARCH).o \
     16$(ASRC)/average-ps1-sim.$(ARCH).o \
    1517$(ASRC)/average-ps1-ref.$(ARCH).o \
    1618$(ASRC)/secfilt.$(ARCH).o \
     
    2628$(ASRC)/secfilt-ps1-v4.$(ARCH).o \
    2729$(ASRC)/secfilt-ps1-v5.$(ARCH).o \
     30$(ASRC)/secfilt-ps1-sim.$(ARCH).o \
    2831$(ASRC)/secfilt-ps1-ref.$(ARCH).o \
    2932$(ASRC)/measure.$(ARCH).o \
     
    3942$(ASRC)/measure-ps1-v4.$(ARCH).o \
    4043$(ASRC)/measure-ps1-v5.$(ARCH).o \
     44$(ASRC)/measure-ps1-sim.$(ARCH).o \
    4145$(ASRC)/measure-ps1-ref.$(ARCH).o \
    4246$(ASRC)/lensing.$(ARCH).o \
    4347$(ASRC)/lensing-ps1-v5.$(ARCH).o \
     48$(ASRC)/lensing-ps1-v5-alt.$(ARCH).o \
    4449$(ASRC)/lensobj.$(ARCH).o \
    4550$(ASRC)/lensobj-ps1-v5.$(ARCH).o \
     51$(ASRC)/starpar.$(ARCH).o \
     52$(ASRC)/starpar-ps1-v5.$(ARCH).o \
     53$(ASRC)/starpar-ps1-sim.$(ARCH).o \
    4654$(ASRC)/missing.$(ARCH).o \
    4755$(ASRC)/photcode.$(ARCH).o \
     
    5664$(ASRC)/photcode-ps1-v5.$(ARCH).o \
    5765$(ASRC)/photcode-ps1-ref.$(ARCH).o \
    58 $(ASRC)/image.$(ARCH).o \
    5966$(ASRC)/image-loneos.$(ARCH).o \
    6067$(ASRC)/image-elixir.$(ARCH).o \
     
    6976$(ASRC)/image-ps1-v4.$(ARCH).o \
    7077$(ASRC)/image-ps1-v5.$(ARCH).o \
     78$(ASRC)/image-ps1-sim.$(ARCH).o \
    7179$(ASRC)/image-ps1-ref.$(ARCH).o \
    7280$(ASRC)/regimage.$(ARCH).o \
     
    98106
    99107AINCS = \
    100 $(AINC)/coords.h \
     108$(AINC)/coords-disk.h \
     109$(AINC)/AstromOffsetMap_Disk.h \
    101110$(AINC)/average.h \
    102111$(AINC)/average-loneos.h \
     
    111120$(AINC)/average-ps1-v4.h \
    112121$(AINC)/average-ps1-v5.h \
     122$(AINC)/average-ps1-sim.h \
    113123$(AINC)/average-ps1-ref.h \
    114124$(AINC)/secfilt.h \
     
    124134$(AINC)/secfilt-ps1-v4.h \
    125135$(AINC)/secfilt-ps1-v5.h \
     136$(AINC)/secfilt-ps1-sim.h \
    126137$(AINC)/secfilt-ps1-ref.h \
    127138$(AINC)/measure.h \
     
    137148$(AINC)/measure-ps1-v4.h \
    138149$(AINC)/measure-ps1-v5.h \
     150$(AINC)/measure-ps1-sim.h \
    139151$(AINC)/measure-ps1-ref.h \
    140152$(AINC)/lensing.h \
    141153$(AINC)/lensing-ps1-v5.h \
     154$(AINC)/lensing-ps1-v5-alt.h \
    142155$(AINC)/lensobj.h \
    143156$(AINC)/lensobj-ps1-v5.h \
     157$(AINC)/starpar.h \
     158$(AINC)/starpar-ps1-v5.h \
     159$(AINC)/starpar-ps1-sim.h \
    144160$(AINC)/missing.h \
    145161$(AINC)/photcode.h \
     
    154170$(AINC)/photcode-ps1-v5.h \
    155171$(AINC)/photcode-ps1-ref.h \
    156 $(AINC)/image.h \
    157172$(AINC)/image-loneos.h \
    158173$(AINC)/image-elixir.h \
     
    167182$(AINC)/image-ps1-v4.h \
    168183$(AINC)/image-ps1-v5.h \
     184$(AINC)/image-ps1-sim.h \
    169185$(AINC)/image-ps1-ref.h \
    170186$(AINC)/regimage.h \
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/average-ps1-v5.d

    r37034 r37822  
    22EXTNAME      DVO_AVERAGE_PS1_V5
    33TYPE         BINTABLE
    4 SIZE         184
     4SIZE         192
    55DESCRIPTION  DVO Average Object Table
    66
     
    4747FIELD lensingOffset,  OFF_LENSING, int,             offset to first lensing obs
    4848FIELD lensobjOffset,  OFF_LENSOBJ, int,             offset to mean lensing data
     49FIELD starparOffset,  OFF_STARPAR, int,             offset to stellar parameter data
    4950FIELD extendOffset,   OFF_EXTEND,  int,             offset to extended object entry
    50 FIELD paramsOffset,   OFF_PARAMS,  int,             offset to stellar parameter data
    5151
    5252FIELD refColorBlue,   REF_COLOR_BLUE, float,        color of astrometry ref stars
    5353FIELD 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 Nstarpar,       DUMMY,         short,         number of stellar parameter entries
     60FIELD dummy,          DUMMY,         short,         unassigned bytes
    5461
    5562# 'flags' was called 'code' prior to 2009.02.07
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/average.d

    r37034 r37822  
    22EXTNAME      DVO_AVERAGE
    33TYPE         BINTABLE
    4 SIZE         184
     4SIZE         192
    55DESCRIPTION  DVO Average Object Table
    66
     
    4747FIELD lensingOffset,  OFF_LENSING, int,             offset to first lensing obs
    4848FIELD lensobjOffset,  OFF_LENSOBJ, int,             offset to mean lensing data
     49FIELD starparOffset,  OFF_STARPAR, int,             offset to stellar parameter data
    4950FIELD extendOffset,   OFF_EXTEND,  int,             offset to extended object entry
    50 FIELD paramsOffset,   OFF_PARAMS,  int,             offset to stellar parameter data
    5151
    5252FIELD refColorBlue,   REF_COLOR_BLUE, float,        color of astrometry ref stars
    5353FIELD 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 Nstarpar,       DUMMY,         short,         number of stellar parameter entries
     60FIELD dummy,          DUMMY,         short,         unassigned bytes
    5461
    5562# 'flags' was called 'code' prior to 2009.02.07
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/cmf-ps1-v5-lensing.d

    r37034 r37822  
    33EXTNAME CMF_PS1_V5
    44TYPE    BINTABLE
    5 SIZE    312
     5SIZE    320
    66
    77# elements of data structure / FITS table
     
    8181FIELD E2_sh_psf,      E2_SH_PSF,         float,    lensing shear
    8282
     83FIELD srcChipNum,     SRC_CHIP_NUM,      short,    source chip in warp
     84FIELD srcChipX,       SRC_CHIP_X,        short,    source chip x coordinate
     85FIELD srcChipY,       SRC_CHIP_Y,        short,    source chip y coordinate
     86FIELD padding3,       SRC_CHIP_PAD,      short,    source chip in warp
     87
    8388FIELD Mr1,            MOMENTS_R1,        float,    first radial moment,   pixels
    8489FIELD Mrh,            MOMENTS_RH,        float,    half radial moment,    pixels^1/2
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/coords.d

    r6454 r37822  
    1717FIELD  pc2_2,            PC2_2,                float,            rotation matrix
    1818FIELD  polyterms,        POLYTERMS,            float[7][2],      higher order warping terms
    19 FIELD  ctype,            CTYPE,                char[15],      coordinate type
     19FIELD  ctype,            CTYPE,                char[15],         coordinate type
    2020FIELD  Npolyterms,       NPOLYTERMS,           char,             order of polynomial
     21FIELD  astrom_map_id,    ASTROM_MAP_ID,        unsigned int,   reference to 2D astrometry map
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image-elixir.d

    r30604 r37822  
    66# elements of the image structure
    77
    8 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     8SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    99SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1010SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image-loneos.d

    r30604 r37822  
    66# elements of the image structure
    77
    8 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     8SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    99SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1010SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image-panstarrs-dev-0.d

    r30604 r37822  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image-panstarrs-dev-1.d

    r30604 r37822  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image-ps1-dev-1.d

    r30604 r37822  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image-ps1-dev-2.d

    r30604 r37822  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image-ps1-dev-3.d

    r30604 r37822  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image-ps1-ref.d

    r30604 r37822  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image-ps1-v1.d

    r30604 r37822  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image-ps1-v2.d

    r36833 r37822  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image-ps1-v3.d

    r36833 r37822  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image-ps1-v4.d

    r36833 r37822  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image-ps1-v5.d

    r37034 r37822  
    88# careful of 8-byte boundaries
    99
    10 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     10SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1111SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1212SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/image.d

    r37034 r37822  
    22EXTNAME      DVO_IMAGE
    33TYPE         BINTABLE
    4 SIZE         360
     4SIZE         384
    55DESCRIPTION  DVO Image Table
    66
     
    88# careful of 8-byte boundaries
    99
     10# Coords is an internal structure defined in def/common.h
    1011SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
    1112SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
     
    2223SUBFIELD  ctype,            CTYPE,                char[15],      coordinate type
    2324SUBFIELD  Npolyterms,       NPOLYTERMS,           char,          order of polynomial
    24 # 120 bytes
     25SUBFIELD  mosaic,           MOSAIC,               e_void,        pointer to parent mosaic
     26SUBFIELD  imageMap,         IMAGE_MAP,            e_void,        pointer to image map
     27# 136 bytes
    2528
    2629# change this to a double?
     
    7679FIELD     photom_map_id,    PHOTOM_MAP_ID,        unsigned int,   reference to 2D zero point map
    7780FIELD     astrom_map_id,    ASTROM_MAP_ID,        unsigned int,   reference to 2D astrometry map
     81
     82FIELD    *parent,           PARENT,               e_void,         pointer to parent mosaic (not save to disk)
    7883# nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases
    7984
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/lensing-ps1-v5.d

    r37329 r37822  
    3030
    3131FIELD F_ApR5,        FLUX_AP_R5,     float,          Flux inside r = 5
    32 FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          Flux inside r = 5
    33 FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          Flux inside r = 5
    34 FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          Flux inside r = 5
     32FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          error on Flux inside r = 5
     33FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          stdev of Flux inside r = 5
     34FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          fill factor for Flux inside r = 5
    3535
    3636FIELD F_ApR6,        FLUX_AP_R6,     float,          Flux inside r = 5
    37 FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          Flux inside r = 5
    38 FIELD sF_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 5
    39 FIELD fF_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 5
     37FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          error on Flux inside r = 5
     38FIELD sF_ApR6,       FLUX_STD_AP_R6, float,          stdev of Flux inside r = 5
     39FIELD fF_ApR6,       FLUX_FIL_AP_R6, float,          fill factor for Flux inside r = 5
    4040
    4141FIELD  detID,          DET_ID,       unsigned int,   detection ID
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/lensing.d

    r37329 r37822  
    2929FIELD  E2_sh_psf,      E2_SH_PSF,    float,          lensing shear psf stars E2
    3030
    31 FIELD  F_ApR5,       FLUX_AP_R5,     float,          Flux inside r = 5
    32 FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          Flux inside r = 5
    33 FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          Flux inside r = 5
    34 FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          Flux inside r = 5
     31FIELD F_ApR5,        FLUX_AP_R5,     float,          Flux inside r = 5
     32FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          error on Flux inside r = 5
     33FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          stdev of Flux inside r = 5
     34FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          fill factor for Flux inside r = 5
    3535
    36 FIELD  F_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 6
    37 FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          Flux inside r = 6
    38 FIELD sF_ApR6,       FLUX_STD_R6,    float,          Flux inside r = 6
    39 FIELD fF_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 6
     36FIELD F_ApR6,        FLUX_AP_R6,     float,          Flux inside r = 5
     37FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          error on Flux inside r = 5
     38FIELD sF_ApR6,       FLUX_STD_AP_R6, float,          stdev of Flux inside r = 5
     39FIELD fF_ApR6,       FLUX_FIL_AP_R6, float,          fill factor for Flux inside r = 5
    4040
    4141FIELD   detID,          DET_ID,      int,            detection ID
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/lensobj-ps1-v5.d

    r37329 r37822  
    3030
    3131FIELD F_ApR5,        FLUX_AP_R5,     float,          Flux inside r = 5
    32 FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          Flux inside r = 5
    33 FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          Flux inside r = 5
    34 FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          Flux inside r = 5
     32FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          error on Flux inside r = 5
     33FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          stdev of Flux inside r = 5
     34FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          fill factor for Flux inside r = 5
    3535
    3636FIELD F_ApR6,        FLUX_AP_R6,     float,          Flux inside r = 5
    37 FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          Flux inside r = 5
    38 FIELD sF_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 5
    39 FIELD fF_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 5
     37FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          error on Flux inside r = 5
     38FIELD sF_ApR6,       FLUX_STD_AP_R6, float,          stdev of Flux inside r = 5
     39FIELD fF_ApR6,       FLUX_FIL_AP_R6, float,          fill factor for Flux inside r = 5
    4040
    4141FIELD  gamma,            GAMMA,      float
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/lensobj.d

    r37329 r37822  
    2929FIELD  E2_sh_psf,      E2_SH_PSF,    float,          mean lensing shear psf stars E2
    3030
    31 FIELD     F_ApR5,    FLUX_AP_R5,     float,          Flux inside r = 5
    32 FIELD    dF_ApR5,    FLUX_ERR_AP_R5, float,          Flux inside r = 5
    33 FIELD    sF_ApR5,    FLUX_STD_AP_R5, float,          Flux inside r = 5
    34 FIELD    fF_ApR5,    FLUX_FIL_AP_R5, float,          Flux inside r = 5
     31FIELD F_ApR5,        FLUX_AP_R5,     float,          Flux inside r = 5
     32FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          error on Flux inside r = 5
     33FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          stdev of Flux inside r = 5
     34FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          fill factor for Flux inside r = 5
    3535
    36 FIELD     F_ApR6,    FLUX_AP_R6,     float,          Flux inside r = 5
    37 FIELD    dF_ApR6,    FLUX_ERR_AP_R6, float,          Flux inside r = 5
    38 FIELD    sF_ApR6,    FLUX_AP_R6,     float,          Flux inside r = 5
    39 FIELD    fF_ApR6,    FLUX_AP_R6,     float,          Flux inside r = 5
     36FIELD F_ApR6,        FLUX_AP_R6,     float,          Flux inside r = 5
     37FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          error on Flux inside r = 5
     38FIELD sF_ApR6,       FLUX_STD_AP_R6, float,          stdev of Flux inside r = 5
     39FIELD fF_ApR6,       FLUX_FIL_AP_R6, float,          fill factor for Flux inside r = 5
    4040
    4141FIELD      gamma,        GAMMA,      float
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/measure-ps1-v5.d

    r37034 r37822  
    6868FIELD psfNdof,        PSF_NDOF,      int,            psf degrees of freedom
    6969FIELD psfNpix,        PSF_NPIX,      int,            psf number of pixels
    70 FIELD crNsigma,       CR_NSIGMA,     float,          Nsigma deviation towards CR
     70FIELD photFlags2,     PHOT_FLAGS,    int,            flags supplied by photometry program
    7171FIELD extNsigma,      EXT_NSIGMA,    float,          Nsigma deviation towards EXT
    7272
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/measure.d

    r37034 r37822  
    6666FIELD psfNdof,        PSF_NDOF,      int,            psf degrees of freedom
    6767FIELD psfNpix,        PSF_NPIX,      int,            psf number of pixels
    68 FIELD crNsigma,       CR_NSIGMA,     float,          Nsigma deviation towards CR
     68FIELD photFlags2,     PHOT_FLAGS,    int,            flags supplied by photometry program
    6969FIELD extNsigma,      EXT_NSIGMA,    float,          Nsigma deviation towards EXT
    7070
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/secfilt-ps1-v4.d

    r37034 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/secfilt-ps1-v5.d

    r37034 r37822  
    22EXTNAME      DVO_SECFILT_PS1_V5
    33TYPE         BINTABLE
    4 SIZE         160
     4SIZE         176
    55DESCRIPTION  DVO SecFilt : Secondary Filter Data
    66
     
    1515FIELD  sMkron,        MAG_KRON_STDEV,  float,      standard deviation of kron mags,       mags
    1616                                         
     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
    1721# these statistics are PSF-specific     
    1822FIELD  Mstdev,        MAG_STDEV,         float,    standard deviation of measurements,    mags
     
    4246FIELD  dFapStk,       FLUX_AP_STK_ERR,   float,    mean flux ap error
    4347
    44 ## need an 8-byte boundary here ##
    45 FIELD  stackDetectID, STACK_DETECT_ID,   uint64_t, detection ID on stack used for fluxes (if any)
     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
    4653
    4754## *** this section is for forced-warp mean values ***
     
    6673FIELD  NusedApWrp,    NUSED_AP_WRP,      short,    number of detections used in average
    6774
     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
    6878FIELD  ubercalDist,   UBERCAL_DIST,      short,    number of images from an ubercal-image
    6979
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/def/secfilt.d

    r37034 r37822  
    22EXTNAME      DVO_SECFILT
    33TYPE         BINTABLE
    4 SIZE         160
     4SIZE         176
    55DESCRIPTION  DVO SecFilt : Secondary Filter Data
    66
     
    1515FIELD  sMkron,        MAG_KRON_STDEV,  float,      standard deviation of kron mags,       mags
    1616
     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
    1721# these statistics are PSF-specific     
    1822FIELD  Mstdev,        MAG_STDEV,       float,      standard deviation of measurements,    mags
     
    2125FIELD  Mchisq,        MAG_CHI,         float,      chisq on average mag,                  value
    2226
    23 FIELD  Ncode,         NCODE,           short,      number of detections in band
    24 FIELD  Nused,         NUSED,           short,      number of detections used in average
    25 FIELD  NusedKron,     NUSED_KRON,      short,      number of detections used in average
    26 FIELD  NusedAp,       NUSED_AP,        short,      number of detections used in average
     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
    2731
    2832FIELD  flags,         FLAGS,           uint32_t,   photometry flags
     
    4246FIELD  dFapStk,       FLUX_AP_STK_ERR,   float,    mean flux ap error
    4347
    44 ## need an 8-byte boundary here ##
    45 FIELD  stackDetectID, STACK_DETECT_ID, uint64_t,   detection ID on stack used for fluxes (if any)
     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
    4653
    4754## *** this section is for forced-warp mean values ***
     
    6673FIELD  NusedApWrp,    NUSED_AP_WRP,      short,    number of detections used in average
    6774
    68 FIELD  ubercalDist,   UBERCAL_DIST,    short,      number of images from an ubercal-image
     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
    6979
    7080# *** 20090206 : new fields : M_20, M_80; dropped dummy
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/doc/autocode.txt

    r21508 r37822  
    3535
    3636- the element name
     37- the element FITS field (in FITS table)
    3738- the element data type
    3839- the element description
    3940- the element physical unit
     41
     42SUBFIELD / SUBSTRUCT keywords allows the user to define elements of a
     43structure which are themselves structures.  These fields are used as
     44follow:
     45
     46Binary / ASCII FITS tables write out the SUBFIELD entries as if they
     47were regular table rows (substructure distinction not visible in FITS
     48table).  SUBSTRUCT rows are NOT added to the FITS table.
     49
     50In a C-structure, the SUBFIELD rows are skipped and only the SUBSTRUCT
     51row is saved.  The definition of the substructure is assumed to be
     52defined elsewhere in the C code.
    4053
    4154Template File
     
    4356The template file is a source code in whatever language is desired.
    4457Within the template, the defined keywords may be used as desired,
    45 wherever needed.  In addition, there are special directives which
    46 invoke additional special behavior.  All special directives have the
    47 form of comments within their target language.  They are replaced with
    48 a block of code in that target language, normally one which iterates
    49 over the FIELD elements of the schema file.  As such, the directive
    50 appropriate for one language should not be used within code for a
    51 different language.  Here is a list of existing special directives:
     58wherever needed. 
     59
     60In addition, there are special directives which invoke additional
     61special behavior.  All special directives have the form of comments
     62within their target language.  They are replaced with a block of code
     63in that target language, normally one which iterates over the FIELD
     64elements of the schema file.  As such, the directive appropriate for
     65one language should not be used within code for a different language.
     66Here is a list of existing special directives:
    5267
    5368/** STRUCT DEFINITION **/
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libautocode/generate

    r26384 r37822  
    144144        if ($type eq "e_time")        { $pt1 = "J"; }
    145145        if ($type eq "e_void")        { $pt1 = "B"; $Np = 8*$Np; }
     146        # if ($type eq "Image")               { $pt1 = "B"; $Np = 8*$Np; }
    146147        # e_void is a 64 bit pointer, cast to size_t.  its value is not loaded
    147148        # from the table.
     
    248249        if ($type eq "e_time")        { $pt1 = sprintf "I%s", $length; }
    249250        if ($type eq "e_void")        { $pt1 = sprintf "I%s", $length; }
     251        # if ($type eq "Image")               { $pt1 = sprintf "I%s", $length; }
    250252
    251253        if (!$pt1) { die "unknown type $type"; }
     
    331333        if ($type eq "e_time")        { $T = "WORD"; $n = 4; }
    332334        if ($type eq "e_void")        { $T = "DBLE"; $n = 8; }
     335        # if ($type eq "Image")               { $T = "DBLE"; $n = 8; }
    333336
    334337        if (!$n) { die "unknown type $type"; }
     
    375378        if ($type eq "e_time")         { $Nbytes += 4*$Np; $valid = 1; }
    376379        if ($type eq "e_void")         { $Nbytes += 8*$Np; $valid = 1; }
     380        # if ($type eq "Image")                { $Nbytes += 8*$Np; $valid = 1; }
    377381        if (!$valid) { die "unknown type $type"; }
    378382    }
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/Makefile

    r37035 r37822  
    3838$(DESTINC)/ps1_v5_defs.h \
    3939$(DESTINC)/ps1_ref_defs.h \
     40$(DESTINC)/ps1_sim_defs.h \
    4041$(DESTINC)/cmf-ps1-dv3.h \
    4142$(DESTINC)/cmf-ps1-v5.h \
    4243$(DESTINC)/cmf-ps1-sv3.h \
    43 $(DESTINC)/cmf-ps1-v5-lensing.h
     44$(DESTINC)/cmf-ps1-sv4.h \
     45$(DESTINC)/cmf-ps1-v5-lensing.h \
     46$(DESTINC)/cmf-ps1-v5-lensing-alt.h
    4447
    4548INCS = $(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
     
    4851$(SRC)/version.$(ARCH).o         \
    4952$(SRC)/coordops.$(ARCH).o        \
     53$(SRC)/galaxy_model.$(ARCH).o    \
    5054$(SRC)/dvosorts.$(ARCH).o        \
    5155$(SRC)/dvo_photcode_ops.$(ARCH).o \
     
    8286$(SRC)/dvo_convert_PS1_V5.$(ARCH).o \
    8387$(SRC)/dvo_convert_PS1_REF.$(ARCH).o \
     88$(SRC)/dvo_convert_PS1_SIM.$(ARCH).o \
    8489$(SRC)/flatcorr_io.$(ARCH).o    \
    8590$(SRC)/skyregion_io.$(ARCH).o    \
    8691$(SRC)/skyregion_gsc.$(ARCH).o    \
    8792$(SRC)/skyregion_ops.$(ARCH).o \
     93$(SRC)/AstromOffsetMapIO.$(ARCH).o    \
     94$(SRC)/AstromOffsetMapOps.$(ARCH).o \
     95$(SRC)/AstromOffsetMapUtils.$(ARCH).o \
    8896$(SRC)/dvo_set_skyregion.$(ARCH).o \
    8997$(SRC)/dvo_set_catdir.$(ARCH).o \
     
    92100$(SRC)/cmf-ps1-dv3.$(ARCH).o \
    93101$(SRC)/cmf-ps1-sv3.$(ARCH).o \
     102$(SRC)/cmf-ps1-sv4.$(ARCH).o \
    94103$(SRC)/cmf-ps1-v5.$(ARCH).o \
    95104$(SRC)/cmf-ps1-v5-lensing.$(ARCH).o \
     105$(SRC)/cmf-ps1-v5-lensing-alt.$(ARCH).o \
    96106$(SRC)/dvo_util.$(ARCH).o \
    97107$(SRC)/dbBooleanCond.$(ARCH).o          \
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/include/cmf-ps1-v5-lensing.h

    r37035 r37822  
    7171  float            E2_sh_psf;            // lensing shear
    7272
     73  short            srcChipNum;
     74  short            srcChipX;
     75  short            srcChipY;
     76
    7377  float            Mr1;                  // first radial moment (pixels)
    7478  float            Mrh;                  // half radial moment (pixels^1/2)
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/include/dvo.h

    r37331 r37822  
    2424  DVO_FORMAT_PS1_DEV_3,
    2525  DVO_FORMAT_PS1_REF,
     26  DVO_FORMAT_PS1_SIM,
    2627  DVO_FORMAT_PS1_V1,
    2728  DVO_FORMAT_PS1_V2,
     
    3637
    3738typedef enum {DVO_CAT_OPEN_FAIL, DVO_CAT_OPEN_OK, DVO_CAT_OPEN_EMPTY} DVOCatalogOpenModes;
    38 
    39 typedef enum {
    40   PROJ_NONE, // undefined
    41   PROJ_ZEA, // zenithal
    42   PROJ_ZPL, // zenithal
    43   PROJ_ARC, // zenithal
    44   PROJ_STG, // zenithal
    45   PROJ_SIN, // zenithal
    46   PROJ_TAN, // zenithal
    47   PROJ_TNX, // zenithal
    48   PROJ_DIS, // zenithal (TAN + polyterms)
    49   PROJ_LIN, // cartesian
    50   PROJ_PLY, // cartesian
    51   PROJ_WRP, // cartesian
    52   PROJ_AIT, // pseudocyl
    53   PROJ_GLS, // pseudocyl
    54   PROJ_PAR, // pseudocyl
    55 } OhanaProjection;
    56 
    57 typedef enum {
    58   PROJ_MODE_NONE,
    59   PROJ_MODE_CARTESIAN,
    60   PROJ_MODE_ZENITHAL,
    61   PROJ_MODE_PSEUDOCYL,
    62 } OhanaProjectionMode;
    6339
    6440// these are used as NAN for types of int values
     
    7955
    8056/* catalog values to be loaded */
    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
     57# define LOAD_NONE      0x0000
     58# define LOAD_AVES      0x0001
     59# define LOAD_MEAS      0x0002
     60# define LOAD_MISS      0x0004
     61# define LOAD_SECF      0x0008
     62# define SKIP_AVES      0x0010
     63# define SKIP_MEAS      0x0020
     64# define SKIP_MISS      0x0040
     65# define SKIP_SECF      0x0080
     66# define LOAD_LENSING   0x0100
     67# define LOAD_LENSOBJ   0x0200
     68# define SKIP_LENSING   0x0400
     69# define SKIP_LENSOBJ   0x0800
     70# define LOAD_STARPAR   0x1000
     71# define SKIP_STARPAR   0x2000
    9472
    9573/* photometry code types */
     
    11492  ID_IMAGE_ASTROM_FEW     = 0x00000100,  /* currently too few measurements for astrometry */
    11593  ID_IMAGE_PHOTOM_UBERCAL = 0x00000200,  /* externally-supplied photometry zero point from ubercal analysis */
     94  ID_IMAGE_ASTROM_GMM     = 0x00000400,  /* image was fitted to positions corrected by the galaxy motion model */
    11695} DVOImageFlags;
    11796
     
    128107  ID_MEAS_BLEND_MEAS     = 0x00000100,  // detection is within radius of multiple objects
    129108  ID_MEAS_BLEND_OBJ      = 0x00000200,  // multiple detections within radius of object
    130   ID_MEAS_UNDEF_3        = 0x00000400,  // unused
     109  ID_MEAS_WARP_USED      = 0x00000400,  // measurement used to find mean warp photometry
    131110  ID_MEAS_UNDEF_4        = 0x00000800,  // unused
    132111  ID_MEAS_BLEND_MEAS_X   = 0x00001000,  // detection is within radius of multiple objects across catalogs                   
     
    136115  ID_MEAS_STACK_PRIMARY  = 0x00010000,  // this stack measurement is in the primary skycell
    137116  ID_MEAS_STACK_PHOT_SRC = 0x00020000,  // this measurement supplied the stack photometry
     117  ID_MEAS_ICRF_QSO       = 0x00040000,  // this measurement is an ICRF reference position
     118  ID_MEAS_IMAGE_EPOCH    = 0x00080000,  // this measurement is registered to the image epoch (not tied to ref catalog epoch)
    138119} DVOMeasureFlags;
    139120
     
    152133*/
    153134
     135/** these names were previously used for Average flags in old (LONEOS-era) dvo versions
     136  ID_BAD_OBJECT        = 0x00004000, // if all measurements are bad, set this bit
     137  ID_MOVING            = 0x00008000, // is a moving object
     138  ID_ROCK              = 0x0000a000, // 0x8000 + 0x2000
     139  ID_GHOST             = 0x0000c001, // 0x8000 + 0x4000 + 0x0001
     140  ID_TRAIL             = 0x0000c002, // 0x8000 + 0x4000 + 0x0002
     141  ID_BLEED             = 0x0000c003, // 0x8000 + 0x4000 + 0x0003
     142  ID_COSMIC            = 0x0000c004, // 0x8000 + 0x4000 + 0x0004
     143**/
     144
    154145/* Average.flags values -- these values are 32 bit (as of PS1_V1) */
    155146typedef enum {
    156   ID_STAR_FEW       = 0x00000001, // used within relphot: skip star
    157   ID_STAR_POOR      = 0x00000002, // used within relphot: skip star
    158   ID_PROPER         = 0x00000400, // star with large proper motion
    159   ID_TRANSIENT      = 0x00001000, // is this mutually exclusive with USNO?
    160   ID_VARIABLE       = 0x00002000, // not currently set?
    161   ID_ASTEROID       = 0x00002000, // identified with an asteroid
    162   ID_BAD_OBJECT     = 0x00004000, // if all measurements are bad, set this bit
    163   ID_MOVING         = 0x00008000, // is a moving object
    164   ID_ROCK           = 0x0000a000, // 0x8000 + 0x2000
    165   ID_GHOST          = 0x0000c001, // 0x8000 + 0x4000 + 0x0001
    166   ID_TRAIL          = 0x0000c002, // 0x8000 + 0x4000 + 0x0002
    167   ID_BLEED          = 0x0000c003, // 0x8000 + 0x4000 + 0x0003
    168   ID_COSMIC         = 0x0000c004, // 0x8000 + 0x4000 + 0x0004
    169   ID_STAR_FIT_AVE   = 0x00010000, // average position fitted
    170   ID_STAR_FIT_PM    = 0x00020000, // proper motion fitted
    171   ID_STAR_FIT_PAR   = 0x00040000, // parallax fitted
    172   ID_STAR_USE_AVE   = 0x00080000, // average position used (not PM or PAR)
    173   ID_STAR_USE_PM    = 0x00100000, // proper motion used (not AVE or PAR)
    174   ID_STAR_USE_PAR   = 0x00200000, // parallax used (not AVE or PM)
    175   ID_STAR_NO_ASTROM = 0x00400000, // mean astrometry could not be measured
    176   ID_STAR_BAD_PM    = 0x00800000, // mean astrometry could not be measured
    177   ID_OBJ_EXT        = 0x01000000, // extended in our data (eg, PS)
    178   ID_OBJ_EXT_ALT    = 0x02000000, // extended in external data (eg, 2MASS)
    179   ID_OBJ_GOOD       = 0x04000000, // good-quality measurement in our data (eg,PS)
    180   ID_OBJ_GOOD_ALT   = 0x08000000, // good-quality measurement in  external data (eg, 2MASS)
    181   ID_OBJ_GOOD_STACK = 0x10000000, // good-quality object in the stack (> 1 good stack)
     147  ID_STAR_FEW          = 0x00000001, // used within relphot: skip star
     148  ID_STAR_POOR         = 0x00000002, // used within relphot: skip star
     149  ID_ICRF_QSO          = 0x00000004, // object IDed with known ICRF quasar (may have ICRF position measurement)
     150  ID_OTHEF_QSO         = 0x00000008, // object IDed with known or suspected quasar, without ICRF reference data
     151  ID_PROPER            = 0x00000010, // star with large proper motion
     152  ID_TRANSIENT         = 0x00000020, // identified as a non-periodic (stationary) transient
     153  ID_VARIABLE          = 0x00000040, // identified as a period variable
     154  ID_ASTEROID          = 0x00000080, // identified with a known solar-system object (asteroid or other)
     155  // bits 0x00000100 - 0x00008000 are currently unused
     156  ID_STAR_FIT_AVE      = 0x00010000, // average position fitted
     157  ID_STAR_FIT_PM       = 0x00020000, // proper motion fitted
     158  ID_STAR_FIT_PAR      = 0x00040000, // parallax fitted
     159  ID_STAR_USE_AVE      = 0x00080000, // average position used (not PM or PAR)
     160  ID_STAR_USE_PM       = 0x00100000, // proper motion used (not AVE or PAR)
     161  ID_STAR_USE_PAR      = 0x00200000, // parallax used (not AVE or PM)
     162  ID_STAR_NO_ASTROM    = 0x00400000, // mean astrometry could not be measured
     163  ID_STAR_BAD_PM       = 0x00800000, // mean astrometry could not be measured
     164  ID_OBJ_EXT           = 0x01000000, // extended in our data (eg, PS)
     165  ID_OBJ_EXT_ALT       = 0x02000000, // extended in external data (eg, 2MASS)
     166  ID_OBJ_GOOD          = 0x04000000, // good-quality measurement in our data (eg,PS)
     167  ID_OBJ_GOOD_ALT      = 0x08000000, // good-quality measurement in  external data (eg, 2MASS)
     168  ID_OBJ_GOOD_STACK    = 0x10000000, // good-quality object in the stack (> 1 good stack)
    182169  ID_OBJ_SUSPECT_STACK = 0x20000000, // suspect object in the stack (> 1 good or suspect stack, < 2 good)
    183   ID_OBJ_BAD_STACK  = 0x40000000, // good-quality object in the stack (> 1 good stack)
     170  ID_OBJ_BAD_STACK     = 0x40000000, // good-quality object in the stack (> 1 good stack)
    184171} DVOAverageFlags;
    185172
     
    202189} DVOSecfiltFlags;
    203190
     191/* definitions for parallel dvo host information
     192   XXX : need better names (safer namespace)
     193*/
     194
     195typedef enum {
     196  DATA_ON_TGT  = 0x01,
     197  DATA_ON_BCK  = 0x02,
     198  DATA_USE_BCK = 0x04,
     199
     200  DATA_COPY_FAILURE = 0x80,
     201} SkyTableDataFlags;
     202
     203typedef enum {
     204  HOST_STDIN = 0,
     205  HOST_STDOUT = 1,
     206  HOST_STDERR = 2,
     207} HostInfoIOfd;
     208
    204209/*** general dvo structures (internal use only / not IO) ***/
    205210
     
    253258} FlatCorrectionTable;
    254259
    255 /* definitions for parallel dvo host information
    256    XXX : need better names (safer namespace)
    257 */
    258 
    259 typedef enum {
    260   DATA_ON_TGT  = 0x01,
    261   DATA_ON_BCK  = 0x02,
    262   DATA_USE_BCK = 0x04,
    263 
    264   DATA_COPY_FAILURE = 0x80,
    265 } SkyTableDataFlags;
    266 
    267 typedef enum {
    268   HOST_STDIN = 0,
    269   HOST_STDOUT = 1,
    270   HOST_STDERR = 2,
    271 } HostInfoIOfd;
    272 
    273260typedef struct {
    274261  char *hostname;             // name of remote machine
     
    289276} HostTable;
    290277
     278typedef struct {
     279  int Nhosts;
     280  HostInfo **hosts;
     281} HostTableGroup;
     282
    291283// A RegionHost processes data for some region in parallel with other regions
    292284typedef struct RegionHostInfo {
     
    315307  off_t *imseq;
    316308
     309  AstromOffsetTable *astromTable;
     310
    317311  int *neighbors;             // list of neighbor index values
    318312  int Nneighbors;             // number of neighbors
     
    338332# include "cmf-ps1-dv3.h"
    339333# include "cmf-ps1-sv3.h"
     334# include "cmf-ps1-sv4.h"
    340335# include "cmf-ps1-v5.h"
    341336# include "cmf-ps1-v5-lensing.h"
     337# include "cmf-ps1-v5-lensing-alt.h"
    342338
    343339typedef struct {
     
    383379  char  ***name; // projection cell name
    384380 
    385   int NX_SUB;
    386   int NY_SUB;
     381  float NX_SUB;
     382  float NY_SUB;
    387383  double dPix;
    388384
    389385  double **Xo;
    390386  double **Yo;
    391   int **dX;
    392   int **dY;
     387  float **dX;
     388  float **dY;
    393389} BoundaryTree;
    394390
     
    411407  double Do;
    412408  double dPix;
    413   int dX;
    414   int dY;
    415 
    416   int NX_SUB;
    417   int NY_SUB;
     409  float dX;
     410  float dY;
     411
     412  float NX_SUB;
     413  float NY_SUB;
    418414
    419415  char *basename;
     
    442438  double         R;
    443439  double         D;
     440  float          RoffGAL;
     441  float          DoffGAL;
    444442  float          M;
    445443  float          Mcal;
     
    464462} MeasureTiny;
    465463
    466 /** STRUCT DEFINITION **/
     464// alternate version of PS1_V4 (old dev version)
    467465typedef struct {
    468466  double           R;                    // RA (decimal degrees )
     
    500498Average *Average_PS1_V4alt_ToInternal (Average_PS1_V4alt *in, off_t Nvalues);
    501499
    502 /** STRUCT DEFINITION **/
     500// alternate version of PS1_V4 (old dev version)
    503501typedef struct {
    504502  float            dR;                   // RA offset (arcsec)
     
    556554Measure *Measure_PS1_V4alt_ToInternal (Average *ave, Measure_PS1_V4alt *in, off_t Nvalues);
    557555
     556// alternate version of PS1_V5 (old dev version)
     557typedef struct {
     558  float            M;                    // average mag in this band (mags)
     559  float            dM;                   // formal error on average mag (mags)
     560  float            Map;                  // ave aperture mag in this band (mags)
     561  float            dMap;                 // ave aperture mag in this band (mags)
     562  float            sMap;                 // standard deviation of ap mags (mags)
     563  float            Mkron;                // ave kron mag in this band (mags)
     564  float            dMkron;               // formal error on average kron mag (mags)
     565  float            sMkron;               // standard deviation of kron mags (mags)
     566  float            Mstdev;               // standard deviation of measurements (mags)
     567  float            Mmin;                 // min accepted mag (mags)
     568  float            Mmax;                 // max accepted mag (mags)
     569  float            Mchisq;               // chisq on average mag (value)
     570  short            Ncode;                // number of detections in band
     571  short            Nused;                // number of detections used in average
     572  short            NusedKron;            // number of detections used in average
     573  short            NusedAp;              // number of detections used in average
     574  uint32_t         flags;                // photometry flags
     575  float            MpsfStk;              // magnitude from stack (primary if available)
     576  float            FpsfStk;              // flux from stack (primary if available)
     577  float            dFpsfStk;             // mean flux psf error
     578  float            MkronStk;             // magnitude from stack (primary if available)
     579  float            FkronStk;             // flux from stack (primary if available)
     580  float            dFkronStk;            // mean flux kron error
     581  float            MapStk;               // magnitude from stack (primary if available)
     582  float            FapStk;               // flux from stack (primary if available)
     583  float            dFapStk;              // mean flux ap error
     584  int              stackPrmryOff;        // measure entry which is primary stack detection
     585  int              stackBestOff;         // measure entry which is best stack detection
     586  float            MpsfWrp;              // psf magnitude from stack (primary if available)
     587  float            FpsfWrp;              // psf flux from stack (primary if available)
     588  float            dFpsfWrp;             // mean flux psf error
     589  float            sFpsfWrp;             // mean flux psf stdev
     590  float            MkronWrp;             // kron magnitude from stack (primary if available)
     591  float            FkronWrp;             // kron flux from stack (primary if available)
     592  float            dFkronWrp;            // mean flux kron error
     593  float            sFkronWrp;            // mean flux kron stdev
     594  float            MapWrp;               // aper magnitude from stack (primary if available)
     595  float            FapWrp;               // aper flux from stack (primary if available)
     596  float            dFapWrp;              // mean flux ap error
     597  float            sFapWrp;              // mean flux ap stdev
     598  short            NusedWrp;             // number of detections used in average
     599  short            NusedKronWrp;         // number of detections used in average
     600  short            NusedApWrp;           // number of detections used in average
     601  short            ubercalDist;          // number of images from an ubercal-image
     602} SecFilt_PS1_V5alt;
     603
     604SecFilt_PS1_V5alt *gfits_table_get_SecFilt_PS1_V5alt (FTable *table, off_t *Ndata, char *swapped);
     605int      gfits_convert_SecFilt_PS1_V5alt (SecFilt_PS1_V5alt *data, off_t size, off_t nitems);
     606SecFilt *SecFilt_PS1_V5alt_ToInternal (SecFilt_PS1_V5alt *in, off_t Nvalues);
     607
     608// alternate version of PS1_V5alt (old dev version)
     609typedef struct {
     610  double           R;                    // RA (decimal degrees )
     611  double           D;                    // DEC (decimal degrees )
     612  float            dR;                   // RA error (arcsec)
     613  float            dD;                   // DEC error (arcsec)
     614  float            uR;                   // RA*cos(D) proper-motion (arcsec/year)
     615  float            uD;                   // DEC proper-motion (arcsec/year)
     616  float            duR;                  // RA*cos(D) p-m error (arcsec/year)
     617  float            duD;                  // DEC p-m error (arcsec/year)
     618  float            P;                    // parallax (arcsec)
     619  float            dP;                   // parallax error (arcsec)
     620  double           Rstk;                 // RA on stack (decimal degrees )
     621  double           Dstk;                 // DEC on stack (decimal degrees )
     622  float            dRstk;                // RA error on stack (arcsec)
     623  float            dDstk;                // DEC error on stack (arcsec)
     624  float            ChiSqAve;             // astrometry analysis chisq
     625  float            ChiSqPM;              // astrometry analysis chisq
     626  float            ChiSqPar;             // astrometry analysis chisq
     627  int              Tmean;                // mean epoch (PM,PAR ref) (unix time seconds)
     628  int              Trange;               // mean epoch (PM,PAR ref) (unix time seconds)
     629  float            psfQF;                // psf coverage (bad masks)
     630  float            psfQFperf;            // psf coverage (all masks)
     631  float            stargal;              // star / galaxy separator (1/100 arcsec)
     632  unsigned short   Npos;                 // number of detections used for astrometry
     633  unsigned short   Nmeasure;             // number of psf measurements
     634  unsigned short   Nmissing;             // number of missings
     635  unsigned short   Nlensing;             // number of lensing measurements
     636  unsigned short   Nlensobj;             // number of lensing measurements
     637  unsigned short   Nextend;              // number of extended measurements
     638  int              measureOffset;        // offset to first psf measurement
     639  int              missingOffset;        // offset to first missing obs
     640  int              lensingOffset;        // offset to first lensing obs
     641  int              lensobjOffset;        // offset to mean lensing data
     642  int              extendOffset;         // offset to extended object entry
     643  int              starparOffset;        // offset to stellar parameter data
     644  float            refColorBlue;         // color of astrometry ref stars
     645  float            refColorRed;          // color of astrometry ref stars
     646  uint32_t         flags;                // average object flags (star; ghost; etc)
     647  uint32_t         photFlagsUpper;       // upper bit of 2 bit summary of per-measure photflags
     648  uint32_t         photFlagsLower;       // lower bit of 2 bit summary of per-measure photflags
     649  unsigned int     objID;                // unique ID for object in table
     650  unsigned int     catID;                // unique ID for table in which object was first realized
     651  uint64_t         extID;                // external ID for object (eg PSPS objID)
     652  uint64_t         extIDgc;              // external ID for object in galactic coords
     653} Average_PS1_V5alt;
     654
     655Average_PS1_V5alt *gfits_table_get_Average_PS1_V5alt (FTable *table, off_t *Ndata, char *swapped);
     656int      gfits_convert_Average_PS1_V5alt (Average_PS1_V5alt *data, off_t size, off_t nitems);
     657Average *Average_PS1_V5alt_ToInternal (Average_PS1_V5alt *in, off_t Nvalues);
     658
    558659/* for some reason I have merged the set of tables and the file description,
    559660   so I need to have an internal structure to point to the separate files */
     
    574675  Lensing *lensing;
    575676  Lensobj *lensobj;
     677  StarPar *starpar;
    576678
    577679  int Nsecfilt;  /* number of secfilt entries for each average entry */
    578   off_t Naverage,   Nmeasure,   Nmissing,   Nlensing,      Nlensobj,      Nsecf_mem;  /* current number of each component in memory */
    579   off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nlensing_disk, Nlensobj_disk, Nsecf_disk; /* current number of each component on disk */
    580   off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nlensing_off,  Nlensobj_off,  Nsecf_off;  /* index of first loaded data value */
     680  off_t Naverage,   Nmeasure,   Nmissing,   Nlensing,      Nlensobj,      Nstarpar,      Nsecf_mem;  /* current number of each component in memory */
     681  off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nlensing_disk, Nlensobj_disk, Nstarpar_disk, Nsecf_disk; /* current number of each component on disk */
     682  off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nlensing_off,  Nlensobj_off,  Nstarpar_off,  Nsecf_off;  /* index of first loaded data value */
    581683
    582684  // note that we use these for the full-sky relphot analysis
     
    599701  struct Catalog *lensing_catalog;              /* lensing catalog data (split) */
    600702  struct Catalog *lensobj_catalog;              /* lensobj catalog data (split) */
     703  struct Catalog *starpar_catalog;              /* starpar catalog data (split) */
    601704
    602705  unsigned int objID;
     
    635738int   gfits_db_free                PROTO((FITS_DB *db));
    636739
    637 /* in coords.c, using libautocode/def/coords.d */
    638 int  XY_to_LM (double *L, double *M, double x,  double y,   Coords *coords);
    639 int  LM_to_XY (double *x,  double *y,   double L, double M, Coords *coords);
    640 int  RD_to_LM (double *L, double *M, double ra,  double dec,   Coords *coords);
    641 int  LM_to_RD (double *ra, double *dec,   double L, double M, Coords *coords);
    642 int  XY_to_RD (double *ra, double *dec, double x,  double y,   Coords *coords);
    643 int  RD_to_XY (double *x,  double *y,   double ra, double dec, Coords *coords);
    644 int  fXY_to_RD (float *ra, float *dec, double x,  double y,   Coords *coords);
    645 int  fRD_to_XY (float *x,  float *y,   double ra, double dec, Coords *coords);
    646 int  GetCoords (Coords *coords, Header *header);
    647 int  PutCoords (Coords *coords, Header *header);
    648 void RegisterMosaic (Coords *coords);
    649 void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
    650 OhanaProjection GetProjection (char *ctype);
    651 int SetProjection (char *ctype, OhanaProjection proj);
    652 OhanaProjectionMode GetProjectionMode (OhanaProjection proj);
    653 
    654740char *libdvo_version (void);
    655741
     
    710796float PhotFluxInstErr (Measure *measure, dvoMagClassType class);
    711797float PhotFluxCatErr (Measure *measure, dvoMagClassType class);
     798float PhotFluxAveErr (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
    712799
    713800float PhotXm (PhotCode *code, Average *average, SecFilt *secfilt);
    714801float PhotZeroPoint (Measure *measure, Average *average, SecFilt *secfilt);
    715802
    716 float PhotMstdev (PhotCode *code, Average *average, SecFilt *secfilt);
     803int   PhotNphot (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
     804float PhotMstdev (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
    717805float PhotMmin (PhotCode *code, Average *average, SecFilt *secfilt);
    718806float PhotMmax (PhotCode *code, Average *average, SecFilt *secfilt);
     
    806894Lensing *FtableToLensing (FTable *ftable, off_t *Nlensing, char *format);
    807895Lensobj *FtableToLensobj (FTable *ftable, off_t *Nlensobj, char *format);
     896StarPar *FtableToStarPar (FTable *ftable, off_t *Nstarpar, char *format);
    808897int      FtableToImage   (FTable *ftable, Header *theader, char *format);
    809898
     
    813902int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, char format);
    814903int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, char format);
     904int StarParToFtable (FTable *ftable, StarPar *starpar, off_t Nstarpar, char format);
    815905int ImageToFtable (FTable *ftable, Header *theader, char format);
    816906int ImageToVtable (VTable *vtable, Header *theader, char format);
     
    829919# include "ps1_v5_defs.h"
    830920# include "ps1_ref_defs.h"
     921# include "ps1_sim_defs.h"
    831922
    832923/*** DVO image db I/O Functions ***/
     
    843934void dvo_image_create (FITS_DB *db, double ZeroPoint);
    844935
     936int gfits_table_set_Image (FTable *ftable);
     937int gfits_table_mkheader_Image (Header *header);
     938Image *gfits_table_get_Image (FTable *ftable, off_t *Ndata, char *swapped);
     939
    845940/* flatcorr APIs */
    846941FlatCorrectionTable *FlatCorrectionLoad (char *filename, int VERBOSE);
     
    856951SkyTable  *SkyTableLoadOptimal     PROTO((char *catdir, char *SKYFILE, char *GSCFILE, int readwrite, int depth, int VERBOSE));
    857952int        SkyTableSetDepth        PROTO((SkyTable *sky, int depth));
     953SkyList   *SkyRegionByIndex        PROTO((SkyTable *table, int index));
    858954SkyList   *SkyRegionByCPT          PROTO((SkyTable *table, char *filename));
    859955SkyList   *SkyRegionByPoint        PROTO((SkyTable *table, int depth, double ra, double dec));
     
    902998int HostTableTestHost (SkyRegion *region, int hostID);
    903999
     1000void InitHost (HostInfo *host);
     1001
     1002HostTableGroup *HostTableGroups (HostTable *table, int *ngroups);
     1003int HostTableGroupWaitJobsGetIO (HostTableGroup *table, char *file, int lineno, int VERBOSE);
     1004
    9041005// functions to support tiny versions of Average and Measure
    9051006void CopyAverageToTiny (AverageTiny *averageT, Average *average);
     
    9351036void dvo_lensing_init (Lensing *lensing);
    9361037void dvo_lensobj_init (Lensobj *lensobj, int toZero);
     1038void dvo_starpar_init (StarPar *starpar);
    9371039
    9381040void InitRegionHosts (RegionHostInfo *hosts, int Nhosts, int NHOSTS);
     
    9441046int RegionHostFindNeighbors (RegionHostTable *table, int Nhost);
    9451047
     1048// galaxy_model:
     1049int TransformProperMotion_radians (double *uR, double *uD, double uL, double uB, double Rrad, double Drad, CoordTransform *transform);
     1050int TransformProperMotion (double *uR, double *uD, double uL, double uB, double R, double D, CoordTransform *transform);
     1051int SolarMotionModel_radians (double *uL_sol, double *uB_sol, double Lrad, double Brad, double distance);
     1052int SolarMotionModel (double *uL_sol, double *uB_sol, double L, double B, double distance);
     1053int GalaxyMotionModel_radians (double *uL_gal, double *uB_gal, double Lrad, double Brad);
     1054int GalaxyMotionModel (double *uL_gal, double *uB_gal, double L, double B);
     1055int InitGalaxyModel (char *version);
     1056
     1057# define LENSFIELD(NAME) float LensValue_##NAME (PhotCode *code, Lensobj *lensobj);
     1058
     1059LENSFIELD(X11_sm_obj)
     1060LENSFIELD(X12_sm_obj)
     1061LENSFIELD(X22_sm_obj)
     1062LENSFIELD(E1_sm_obj)
     1063LENSFIELD(E2_sm_obj)
     1064
     1065LENSFIELD(X11_sh_obj)
     1066LENSFIELD(X12_sh_obj)
     1067LENSFIELD(X22_sh_obj)
     1068LENSFIELD(E1_sh_obj)
     1069LENSFIELD(E2_sh_obj)
     1070
     1071LENSFIELD(X11_sm_psf)
     1072LENSFIELD(X12_sm_psf)
     1073LENSFIELD(X22_sm_psf)
     1074LENSFIELD(E1_sm_psf)
     1075LENSFIELD(E2_sm_psf)
     1076
     1077LENSFIELD(X11_sh_psf)
     1078LENSFIELD(X12_sh_psf)
     1079LENSFIELD(X22_sh_psf)
     1080LENSFIELD(E1_sh_psf)
     1081LENSFIELD(E2_sh_psf)
     1082
     1083# undef LENSFIELD
     1084
    9461085# endif // DVO_H
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/include/dvodb.h

    r37035 r37822  
    5454  MAG_OPTION_NPHOT, // Nused
    5555  MAG_OPTION_UC_DIST,
    56   MAG_OPTION_STACK_DET_ID,
    5756  MAG_OPTION_FLAGS,
     57
     58  MAG_OPTION_X11_SM_OBJ,
     59  MAG_OPTION_X12_SM_OBJ,
     60  MAG_OPTION_X22_SM_OBJ,
     61  MAG_OPTION_E1_SM_OBJ,
     62  MAG_OPTION_E2_SM_OBJ,
     63
     64  MAG_OPTION_X11_SH_OBJ,
     65  MAG_OPTION_X12_SH_OBJ,
     66  MAG_OPTION_X22_SH_OBJ,
     67  MAG_OPTION_E1_SH_OBJ,
     68  MAG_OPTION_E2_SH_OBJ,
     69
     70  MAG_OPTION_X11_SM_PSF,
     71  MAG_OPTION_X12_SM_PSF,
     72  MAG_OPTION_X22_SM_PSF,
     73  MAG_OPTION_E1_SM_PSF,
     74  MAG_OPTION_E2_SM_PSF,
     75
     76  MAG_OPTION_X11_SH_PSF,
     77  MAG_OPTION_X12_SH_PSF,
     78  MAG_OPTION_X22_SH_PSF,
     79  MAG_OPTION_E1_SH_PSF,
     80  MAG_OPTION_E2_SH_PSF,
     81
     82  MAG_OPTION_F_AP_R5,
     83  MAG_OPTION_F_ERR_AP_R5,
     84  MAG_OPTION_F_STDEV_AP_R5,
     85  MAG_OPTION_F_FILL_AP_R5,
     86
     87  MAG_OPTION_F_AP_R6,
     88  MAG_OPTION_F_ERR_AP_R6,
     89  MAG_OPTION_F_STDEV_AP_R6,
     90  MAG_OPTION_F_FILL_AP_R6,
    5891} dvoMagOptionType;
     92
     93//  MAG_OPTION_STACK_PRIMARY_OFF,
     94//  MAG_OPTION_STACK_BEST_OFF,
    5995
    6096typedef enum {
     
    137173      MEAS_XFIX,
    138174      MEAS_YFIX,
     175      MEAS_XOFF_KH,
     176      MEAS_YOFF_KH,
     177      MEAS_XOFF_DCR,
     178      MEAS_YOFF_DCR,
     179      MEAS_ROFF_GAL,
     180      MEAS_DOFF_GAL,
    139181      MEAS_POS_SYS_ERR,
    140182      MEAS_XFIELD,
     
    160202      MEAS_FLAT,
    161203      MEAS_CENTER_OFFSET,
    162       MEAS_REF_COLOR,
     204      MEAS_REF_COLOR_BLUE,
     205      MEAS_REF_COLOR_RED,
     206      MEAS_X11_SM_OBJ,
     207      MEAS_X12_SM_OBJ,
     208      MEAS_X22_SM_OBJ,
     209      MEAS_E1_SM_OBJ,
     210      MEAS_E2_SM_OBJ,
     211      MEAS_X11_SH_OBJ,
     212      MEAS_X12_SH_OBJ,
     213      MEAS_X22_SH_OBJ,
     214      MEAS_E1_SH_OBJ,
     215      MEAS_E2_SH_OBJ,
     216      MEAS_X11_SM_PSF,
     217      MEAS_X12_SM_PSF,
     218      MEAS_X22_SM_PSF,
     219      MEAS_E1_SM_PSF,
     220      MEAS_E2_SM_PSF,
     221      MEAS_X11_SH_PSF,
     222      MEAS_X12_SH_PSF,
     223      MEAS_X22_SH_PSF,
     224      MEAS_E1_SH_PSF,
     225      MEAS_E2_SH_PSF,
     226      MEAS_E_BV,                      // extinction (mags)
     227      MEAS_E_BV_ERR,
     228      MEAS_DISTANCE_MOD, // distance modulus (mags)
     229      MEAS_DISTANCE_MOD_ERR,
     230      MEAS_M_R,               // absolute mag in r-band
     231      MEAS_M_R_ERR,
     232      MEAS_FEH,               // metallicity
     233      MEAS_FEH_ERR,
     234      MEAS_URA_GALMODEL,      // model pm prediction
     235      MEAS_UDEC_GALMODEL,     // model pm prediction
     236      MEAS_RA_GALMODEL,      // model pm prediction
     237      MEAS_DEC_GALMODEL,     // model pm prediction
    163238};
    164239
     
    198273      AVE_EXTID_HI,
    199274      AVE_EXTID_LO,
    200       AVE_REF_COLOR,
     275      AVE_REF_COLOR_BLUE,
     276      AVE_REF_COLOR_RED,
    201277      AVE_PHOT, // photometry class of values
     278      AVE_E_BV,               // extinction (mags)
     279      AVE_E_BV_ERR,
     280      AVE_DISTANCE_MOD, // distance modulus (mags)
     281      AVE_DISTANCE_MOD_ERR,
     282      AVE_M_R,                // absolute mag in r-band
     283      AVE_M_R_ERR,
     284      AVE_FEH,                // metallicity
     285      AVE_FEH_ERR,
     286      AVE_URA_GALMODEL,      // model pm prediction
     287      AVE_UDEC_GALMODEL,     // model pm prediction
     288      AVE_RA_GALMODEL,      // model pm prediction
     289      AVE_DEC_GALMODEL,     // model pm prediction
    202290};
    203291
     
    274362      IMAGE_NLINK_PHOTOM,
    275363      IMAGE_NLINK_ASTROM,
    276       IMAGE_REF_COLOR
     364      IMAGE_REF_COLOR_BLUE,
     365      IMAGE_REF_COLOR_RED
    277366};
    278367
     
    366455int          ParseImageField        PROTO((dbField *field, char *fieldName));
    367456
    368 dbValue      dbExtractAverages      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
    369 dbValue      dbExtractMeasures      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
     457dbValue      dbExtractAverages      PROTO((Average *average, SecFilt *secfilt, Measure *measure, Lensobj *lensobj, StarPar *starpar, dbField *field));
     458dbValue      dbExtractMeasures      PROTO((Average *average, SecFilt *secfilt, Measure *measure, Lensing *lensing, StarPar *starpar, dbField *field));
    370459dbValue      dbExtractImages        PROTO((Image *image, off_t Nimage, off_t N, dbField *field));
    371460
     
    374463int          dbAstroRegionLimits    PROTO((dbStack **stack, int *nstack, SkyRegionSelection *selection, int table));
    375464char        *strfloat               PROTO((float value));
     465
     466int dbFieldNeedMeasure (dbField *fields, int Nfields);
     467int dbFieldNeedLensobj (dbField *fields, int Nfields);
     468int dbFieldNeedLensing (dbField *fields, int Nfields);
     469int dbFieldNeedStarpar (dbField *fields, int Nfields, int isAverage);
    376470
    377471void FreeImageSelection (void);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/include/libdvo_astro.h

    r31635 r37822  
    1 #ifdef notdef
    2 # include "external.h"
    3 # include "shell.h"
    4 # include "dvomath.h"
    5 # include "convert.h"
    6 # include "display.h"
    7 # include "data.h"
    8 #endif
     1# ifndef LIBDVO_ASTRO_H
     2# define LIBDVO_ASTRO_H
    93
    10 # ifndef ASTRO_H
    11 # define ASTRO_H
     4typedef enum {
     5  COORD_NONE,
     6  COORD_CELESTIAL,
     7  COORD_GALACTIC, // based on Liu et al 2011
     8  COORD_ECLIPTIC,
     9  COORD_GALACTIC_REID_2004, // an older definition of the galactic plane
     10} CoordTransformSystem;
    1211
    13 void InitAstro (void);
    14 void FreeAstro (void);
     12typedef enum {
     13  PROJ_NONE, // undefined
     14  PROJ_ZEA, // zenithal
     15  PROJ_ZPL, // zenithal
     16  PROJ_ARC, // zenithal
     17  PROJ_STG, // zenithal
     18  PROJ_SIN, // zenithal
     19  PROJ_TAN, // zenithal
     20  PROJ_TNX, // zenithal
     21  PROJ_DIS, // zenithal (TAN + polyterms)
     22  PROJ_LIN, // cartesian
     23  PROJ_PLY, // cartesian (allow polyterms)
     24  PROJ_WRP, // cartesian (allow polyterms, require mosaic)
     25  PROJ_AIT, // pseudocyl
     26  PROJ_GLS, // pseudocyl
     27  PROJ_PAR, // pseudocyl
     28} OhanaProjection;
     29
     30typedef enum {
     31  PROJ_MODE_NONE,
     32  PROJ_MODE_CARTESIAN,
     33  PROJ_MODE_ZENITHAL,
     34  PROJ_MODE_PSEUDOCYL,
     35} OhanaProjectionMode;
    1536
    1637typedef struct {
     
    2950} CoordTransform;
    3051
    31 typedef enum {COORD_NONE, COORD_CELESTIAL, COORD_GALACTIC, COORD_ECLIPTIC} CoordTransformSystem;
     52typedef struct {
     53  int Nx;
     54  int Ny;
     55  float dX;
     56  float dY;
     57  float **dXv;
     58  float **dYv;
     59  unsigned int tableID;
     60  unsigned int imageID;
     61  int keep;
     62} AstromOffsetMap;
     63
     64typedef struct {
     65  int Nmap;
     66  AstromOffsetMap **map;
     67   int *imageIDtoTableSeq;
     68  int MaxImageID;
     69  int MaxTableID;
     70} AstromOffsetTable;
     71
     72/* Internal version of Coords (see CoordsDisk in libautocode/def/coords-disk.d) */
     73typedef struct Coords {
     74  double           crval1;               // coordinate at reference pixel
     75  double           crval2;               // coordinate at reference pixel
     76  float            crpix1;               // coordinate of reference pixel
     77  float            crpix2;               // coordinate of reference pixel
     78  float            cdelt1;               // degrees per pixel
     79  float            cdelt2;               // degrees per pixel
     80  float            pc1_1;                // rotation matrix
     81  float            pc1_2;                // rotation matrix
     82  float            pc2_1;                // rotation matrix
     83  float            pc2_2;                // rotation matrix
     84  float            polyterms[7][2];      // higher order warping terms
     85  char             ctype[15];            // coordinate type
     86  char             Npolyterms;           // order of polynomial
     87  struct Coords   *mosaic;               // pointer to parent mosaic
     88  AstromOffsetMap *offsetMap;            // pointer to offset map transformation
     89} Coords;
     90
     91typedef struct Image {
     92  Coords           coords;               // astrometric data
     93  e_time           tzero;                // readout time (row 0)
     94  unsigned int     nstar;                // number of stars on image
     95  float            secz;                 // airmass (mag)
     96  unsigned short   NX;                   // image width
     97  unsigned short   NY;                   // image height
     98  float            apmifit;              // aperture correction (mag)
     99  float            dapmifit;             // apmifit error (mag)
     100  float            Mcal;                 // calibration mag (mag)
     101  float            dMcal;                // error on Mcal (mag)
     102  short            Xm;                   // image chisq (10*log(value))
     103  short            photcode;             // identifier for CCD,
     104  float            exptime;              // exposure time (seconds)
     105  float            sidtime;              // sidereal time of exposure
     106  float            latitude;             // observatory latitude (degrees)
     107  float            RAo;                  // image center (degrees)
     108  float            DECo;                 // image center (degrees)
     109  float            Radius;               // image radius (degrees)
     110  float            refColorBlue;         // median astrometry ref color
     111  float            refColorRed;          // median astrometry ref color
     112  char             name[117];            // name of original image
     113  unsigned char    detection_limit;      // detection limit (10*mag)
     114  unsigned char    saturation_limit;     // saturation limit (10*mag)
     115  unsigned char    cerror;               // astrometric error (50*arcsec)
     116  unsigned char    fwhm_x;               // PSF x width (25*arcsec)
     117  unsigned char    fwhm_y;               // PSF y width (25*arcsec)
     118  unsigned char    trate;                // scan rate (100 usec/pixel)
     119  unsigned char    ccdnum;               // CCD ID number
     120  unsigned int     flags;                // image quality flags
     121  unsigned int     imageID;              // internal image ID
     122  unsigned int     parentID;             // associated ref image
     123  unsigned int     externID;             // external image ID
     124  unsigned short   sourceID;             // analysis source ID
     125  short            nLinkAstrom;          // mean number of matched measurements for astrometry
     126  short            nLinkPhotom;          // mean number of matched measurements for astrometry
     127  short            ubercalDist;          // distance to nearest ubercal image
     128  float            dXpixSys;             // systematic astrometry error in X
     129  float            dYpixSys;             // systematic astrometry error in Y
     130  float            dMagSys;              // systematic photometry error
     131  unsigned short   nFitAstrom;           // number of stars used for astrometry cal
     132  unsigned short   nFitPhotom;           // number of stars used for photometry cal
     133  unsigned int     photom_map_id;        // reference to 2D zero point map
     134  unsigned int     astrom_map_id;        // reference to 2D astrometry map
     135  struct Image    *parent;               // pointer to parent mosaic (not save to disk)
     136} Image;
    32137
    33138CoordTransform *InitTransform (CoordTransformSystem input, CoordTransformSystem output);
    34139int ApplyTransform (double *x, double *y, double X, double Y, CoordTransform *transform);
    35140
     141/* in coords.c */
     142void InitCoords (Coords *coords, char *projection);
     143void CopyCoords (Coords *tgt, Coords *src);
     144
     145int  XY_to_LM (double *L, double *M, double x,  double y,   Coords *coords);
     146int  LM_to_XY (double *x,  double *y,   double L, double M, Coords *coords);
     147int  RD_to_LM (double *L, double *M, double ra,  double dec,   Coords *coords);
     148int  LM_to_RD (double *ra, double *dec,   double L, double M, Coords *coords);
     149int  XY_to_RD (double *ra, double *dec, double x,  double y,   Coords *coords);
     150int  RD_to_XY (double *x,  double *y,   double ra, double dec, Coords *coords);
     151int  fXY_to_RD (float *ra, float *dec, double x,  double y,   Coords *coords);
     152int  fRD_to_XY (float *x,  float *y,   double ra, double dec, Coords *coords);
     153int  GetCoords (Coords *coords, Header *header);
     154int  PutCoords (Coords *coords, Header *header);
     155void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
     156OhanaProjection GetProjection (char *ctype);
     157int SetProjection (char *ctype, OhanaProjection proj);
     158OhanaProjectionMode GetProjectionMode (OhanaProjection proj);
     159
     160/* in AstromOffsetMapIO.c */
     161AstromOffsetTable *AstromOffsetMapLoad (char *filename, int VERBOSE);
     162int AstromOffsetMapSave (AstromOffsetTable *table, char *filename);
     163AstromOffsetTable *AstromOffsetMapToTable(AstromOffsetMap_Disk_6x6 *map_disk, off_t Nmap);
     164AstromOffsetMap_Disk_6x6 *AstromOffsetTableToMap(AstromOffsetTable *table, off_t *Nmap);
     165
     166/* in AstromOffsetMapOps.c */
     167float AstromOffsetMapValue (AstromOffsetMap *map, float x, float y, int xdir);
     168int AstromOffsetMapFit (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir);
     169
     170/* in AstromOffsetMapUtils.c */
     171AstromOffsetMap *AstromOffsetMapInit (int Nx, int Ny);
     172void AstromOffsetMapFree (AstromOffsetMap *map);
     173
     174int AstromOffsetTableNewMap (AstromOffsetTable *table, int Nx, int Ny, Image *image);
     175int AstromOffsetTableMatchChips (Image *images, off_t Nimages, AstromOffsetTable *table);
     176AstromOffsetTable *AstromOffsetTableInit();
     177void AstromOffsetTableFree(AstromOffsetTable *table);
     178int AstromOffsetTableAddMapFromImage (AstromOffsetTable *table, Image *image);
     179void AstromOffsetMapPrint (AstromOffsetMap *map, char *filename);
     180int AstromOffsetMapRepair (AstromOffsetMap *map, int xdir);
     181AstromOffsetMap *AstromOffsetMapCopy (AstromOffsetMap *map);
     182void AstromOffsetMapCopyData (AstromOffsetMap *tgt, AstromOffsetMap *src);
     183void AstromOffsetMapSetOrder (AstromOffsetMap *map, int Nx, int Ny, Image *image);
     184
    36185# endif
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/include/ps1_v5_defs.h

    r37035 r37822  
    99
    1010Lensing                 *Lensing_PS1_V5_ToInternal (Lensing_PS1_V5 *in, off_t Nvalues);
     11Lensing                 *Lensing_PS1_V5_ALT_ToInternal (Lensing_PS1_V5_ALT *in, off_t Nvalues);
    1112Lensing_PS1_V5          *LensingInternalTo_PS1_V5 (Lensing *in, off_t Nvalues);
    1213Lensobj                 *Lensobj_PS1_V5_ToInternal (Lensobj_PS1_V5 *in, off_t Nvalues);
    1314Lensobj_PS1_V5          *LensobjInternalTo_PS1_V5 (Lensobj *in, off_t Nvalues);
    1415
     16StarPar                 *StarPar_PS1_V5_ToInternal (StarPar_PS1_V5 *in, off_t Nvalues);
     17StarPar_PS1_V5          *StarParInternalTo_PS1_V5 (StarPar *in, off_t Nvalues);
     18
    1519PhotCode                *PhotCode_PS1_V5_To_Internal (PhotCode_PS1_V5 *in, off_t Nvalues);
    1620PhotCode_PS1_V5         *PhotCode_Internal_To_PS1_V5 (PhotCode *in, off_t Nvalues);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/BoundaryTree.c

    r36490 r37822  
    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
     
    371371int BoundaryTreeCellCoords (BoundaryTree *tree, int *zone, int *band, double ra, double dec) {
    372372
     373  ra = ohana_normalize_angle (ra);
     374
    373375  // first, find the containing zone
    374376
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/HostTable.c

    r35848 r37822  
    33# include <sys/wait.h>
    44
     5void InitHost (HostInfo *host) {
     6  host->hostname = NULL;
     7  host->pathname = NULL;
     8  host->results = NULL;
     9  host->stdio[HOST_STDIN] = -1;
     10  host->stdio[HOST_STDOUT] = -1;
     11  host->stdio[HOST_STDERR] = -1;
     12  host->pid = 0;
     13  return;
     14}
     15
    516void InitHosts (HostInfo *hosts, int Nhosts, int NHOSTS) {
    617
    718  int i;
    819  for (i = Nhosts; i < NHOSTS; i++) {
    9     hosts[i].hostname = NULL;
    10     hosts[i].pathname = NULL;
    11     hosts[i].results = NULL;
    12     hosts[i].stdio[HOST_STDIN] = -1;
    13     hosts[i].stdio[HOST_STDOUT] = -1;
    14     hosts[i].stdio[HOST_STDERR] = -1;
    15     hosts[i].pid = 0;
     20    InitHost (&hosts[i]);
    1621  }
    1722  return;
     
    3641  }
    3742  if (table->index) free (table->index);
     43  free (table);
     44  return;
     45}
     46
     47// a HostTableGroup is a pointer set to one or more HostTable entries
     48void FreeTableGroup (HostTableGroup *table) {
     49
     50  if (!table) return;
     51  if (table->hosts) {
     52    free (table->hosts);
     53  }
    3854  free (table);
    3955  return;
     
    136152  fclose (f);
    137153  return table;
     154}
     155
     156// split a host table into Ngroups, each with a unique set of hosts
     157HostTableGroup *HostTableGroups (HostTable *table, int *ngroups) {
     158
     159  // identify the unique host names and the number of times they each exist
     160  // (Host tables are not very large; I can afford to do this in an inefficient way)
     161  int i, j, k;
     162
     163  int Nunique = 0;
     164  char **unique_hosts = NULL; // an array of pointers to a set of the names
     165  int  *Nunique_hosts = NULL; // an array of pointers to the count of each
     166  ALLOCATE ( unique_hosts, char *, table->Nhosts);
     167  ALLOCATE (Nunique_hosts, int, table->Nhosts);
     168  for (i = 0; i < table->Nhosts; i++) Nunique_hosts[i] = 0;
     169
     170  for (i = 0; i < table->Nhosts; i++) {
     171    int found = FALSE;
     172    for (j = 0; !found && (j < Nunique); j++) {
     173      if (!strcmp(table->hosts[i].hostname, unique_hosts[j])) {
     174        Nunique_hosts[j] ++;
     175        found = TRUE;
     176      }
     177    }
     178    if (!found) {
     179      unique_hosts[Nunique] = table->hosts[i].hostname;
     180      Nunique_hosts[Nunique] = 1;
     181      Nunique ++;
     182    }
     183  }
     184
     185  int Ngroups = 0;
     186  for (i = 0; i < Nunique; i++) {
     187    Ngroups = MAX (Nunique_hosts[i], Ngroups);
     188  }
     189
     190  HostTableGroup *groups = NULL;
     191  int *foundHost = NULL;
     192 
     193  ALLOCATE (foundHost, int, table->Nhosts);
     194  ALLOCATE (groups, HostTableGroup, Ngroups);
     195
     196  for (i = 0; i < table->Nhosts; i++) foundHost[i] = FALSE;
     197
     198  // in each group, attempt to add one of each unique host
     199  for (i = 0; i < Ngroups; i++) {
     200    groups[i].Nhosts = 0;
     201    ALLOCATE (groups[i].hosts, HostInfo *, Nunique);
     202    for (j = 0; j < Nunique; j++) {
     203      int found = FALSE;
     204      for (k = 0; !found && (k < table->Nhosts); k++) {
     205        if (foundHost[k]) continue;
     206        if (strcmp(unique_hosts[j], table->hosts[k].hostname)) continue;
     207        groups[i].hosts[groups[i].Nhosts] = &table->hosts[k];
     208        groups[i].Nhosts ++;
     209        found = TRUE;
     210        foundHost[k] = TRUE;
     211      }
     212    }
     213  }
     214  *ngroups = Ngroups;
     215  return groups;
    138216}
    139217
     
    255333
    256334  // this loop has 2 chunks: (a) check for I/O + (b) check for jobs done
    257   while (1) {
     335  while (Nfound < Nrunning) {
    258336
    259337    // Wait up to 0.5 second for host to provide I/O
     
    284362        // if (table->hosts[i].stdout.Nbuffer > 0x10000) {
    285363        if (table->hosts[i].stdout.Nbuffer > 0x1000) {
    286           int printHead = VERBOSE || (table->hosts[i].stdout.Nbuffer > 0);
     364          int printHead = VERBOSE && (table->hosts[i].stdout.Nbuffer > 0);
    287365          if (printHead) fprintf (stdout, "--- stdout from %s --- (%d bytes, v1)\n", table->hosts[i].hostname, table->hosts[i].stdout.Nbuffer);
    288366          int Nout = write (STDOUT_FILENO, table->hosts[i].stdout.buffer, table->hosts[i].stdout.Nbuffer);
     
    298376        // if (table->hosts[i].stderr.Nbuffer > 0x10000) {
    299377        if (table->hosts[i].stderr.Nbuffer > 0x1000) {
    300           int printHead = VERBOSE || (table->hosts[i].stderr.Nbuffer > 0);
     378          int printHead = VERBOSE && (table->hosts[i].stderr.Nbuffer > 0);
    301379          if (printHead) fprintf (stdout, "--- stderr from %s --- (%d bytes, v1)\n", table->hosts[i].hostname, table->hosts[i].stderr.Nbuffer);
    302380          int Nout = write (STDOUT_FILENO, table->hosts[i].stderr.buffer, table->hosts[i].stderr.Nbuffer);
     
    314392      if (!pid) {
    315393        // fprintf (stderr, "no hosts to harvest\n");
    316         usleep (500000);
     394        usleep (200000);
    317395        break; // no outstanding jobs have finished
    318396      }
     
    367445        }
    368446      }
    369       if (!found) {
    370         fprintf (stderr, "Programming error: failed to matched finished job to known host!\n");
    371         exit (2);
    372       }
    373       Nfound ++;
     447      if (found) Nfound ++;
     448      // we sometimes harvest children not in the list (eg, closed kapa window).  just ignore
    374449      if (Nfound == Nrunning) goto escape; // we've harvested all jobs
    375450    }
     
    389464}
    390465
     466// wait for all children to complete, report output to stdout
     467int HostTableGroupWaitJobsGetIO (HostTableGroup *table, char *file, int lineno, int VERBOSE) {
     468
     469  // we have launched table->Nhosts jobs; wait for all of them to complete...
     470  // if one (N) failed to launch, we will get an ECHILD error from the last (N) calls
     471
     472  // we need to read any data waiting on stderr or stdout from these jobs, or the overfull
     473  // buffers can cause a problem.  we alternate between 'select' and 'waitpid' calls with
     474  // timeouts for both
     475
     476  // add all hosts' sockets to the fd_sets
     477  fd_set rdSet, wtSet;
     478  FD_ZERO (&rdSet);
     479  FD_ZERO (&wtSet);
     480
     481  // XXX can I set the fd_sets once, since I am not actually closing the fd's?
     482
     483  int globalStatus = TRUE;
     484
     485  int i;
     486  int Nmax = 0;
     487  for (i = 0; i < table->Nhosts; i++) {
     488    if (!table->hosts[i][0].pid) continue; // any unconnected hosts should be skipped
     489    FD_SET (table->hosts[i][0].stdio[HOST_STDIN], &wtSet);
     490    Nmax = MAX (Nmax, table->hosts[i][0].stdio[HOST_STDIN]);
     491    FD_SET (table->hosts[i][0].stdio[HOST_STDOUT], &rdSet);
     492    Nmax = MAX (Nmax, table->hosts[i][0].stdio[HOST_STDOUT]);
     493    FD_SET (table->hosts[i][0].stdio[HOST_STDERR], &rdSet);
     494    Nmax = MAX (Nmax, table->hosts[i][0].stdio[HOST_STDERR]);
     495  }   
     496  Nmax ++;
     497
     498  // need the list of connected hosts for exit test below
     499  int Nrunning = 0;
     500  for (i = 0; i < table->Nhosts; i++) {
     501    if (!table->hosts[i][0].pid) continue; // any unconnected hosts should be skipped
     502    Nrunning ++;
     503  }
     504
     505  int Nfound = 0;
     506
     507  // this loop has 2 chunks: (a) check for I/O + (b) check for jobs done
     508  while (1) {
     509
     510    // Wait up to 0.5 second for host to provide I/O
     511    // timeout gets mucked: need to reset before each select
     512    struct timeval timeout;
     513    timeout.tv_sec = 10;
     514    timeout.tv_usec = 500000;
     515
     516    int status = select (Nmax, NULL, &wtSet, NULL, &timeout);
     517    if (status == -1) {
     518      perror("select()");
     519      exit (2);
     520    }
     521
     522    // we have some sockets to check, check sockets for all hosts
     523    for (i = 0; (status > 0) && (i < table->Nhosts); i++) {
     524      if (!table->hosts[i][0].pid) continue; // any unconnected hosts should be skipped
     525
     526      if (FALSE && FD_ISSET (table->hosts[i][0].stdio[HOST_STDIN], &wtSet)) {
     527        // this host is waiting for input : this is an error, so exit
     528        fprintf (stderr, "host %s is waiting for input\n", table->hosts[i][0].hostname);
     529        abort();
     530      }
     531     
     532      if ((table->hosts[i][0].stdio[HOST_STDOUT] > 0) && FD_ISSET (table->hosts[i][0].stdio[HOST_STDOUT], &rdSet)) {
     533        // this host has waiting output : read to buffer, and dump if necessary
     534        ReadtoIOBuffer (&table->hosts[i][0].stdout, table->hosts[i][0].stdio[HOST_STDOUT]);
     535        // if (table->hosts[i][0].stdout.Nbuffer > 0x10000) {
     536        if (table->hosts[i][0].stdout.Nbuffer > 0x1000) {
     537          int printHead = VERBOSE || (table->hosts[i][0].stdout.Nbuffer > 0);
     538          if (printHead) fprintf (stdout, "--- stdout from %s --- (%d bytes, v1)\n", table->hosts[i][0].hostname, table->hosts[i][0].stdout.Nbuffer);
     539          int Nout = write (STDOUT_FILENO, table->hosts[i][0].stdout.buffer, table->hosts[i][0].stdout.Nbuffer);
     540          if (Nout != table->hosts[i][0].stdout.Nbuffer) { fprintf (stderr, "(error writing log?)\n"); }
     541          FlushIOBuffer (&table->hosts[i][0].stdout);
     542          if (printHead) fprintf (stdout, "\n");
     543        }
     544      }
     545
     546      if ((table->hosts[i][0].stdio[HOST_STDERR] > 0) && FD_ISSET (table->hosts[i][0].stdio[HOST_STDERR], &rdSet)) {
     547        // this host has waiting output : read to buffer, and dump if necessary
     548        ReadtoIOBuffer (&table->hosts[i][0].stderr, table->hosts[i][0].stdio[HOST_STDERR]);
     549        // if (table->hosts[i][0].stderr.Nbuffer > 0x10000) {
     550        if (table->hosts[i][0].stderr.Nbuffer > 0x1000) {
     551          int printHead = VERBOSE || (table->hosts[i][0].stderr.Nbuffer > 0);
     552          if (printHead) fprintf (stdout, "--- stderr from %s --- (%d bytes, v1)\n", table->hosts[i][0].hostname, table->hosts[i][0].stderr.Nbuffer);
     553          int Nout = write (STDOUT_FILENO, table->hosts[i][0].stderr.buffer, table->hosts[i][0].stderr.Nbuffer);
     554          if (Nout != table->hosts[i][0].stderr.Nbuffer) { fprintf (stderr, "(error writing log?)\n"); }
     555          FlushIOBuffer (&table->hosts[i][0].stderr);
     556          if (printHead) fprintf (stdout, "\n");
     557        }
     558      }
     559    }
     560
     561    // now check if any children have finished...
     562    while (TRUE) {
     563      int status = 0;
     564      int pid = waitpid (-1, &status, WNOHANG);
     565      if (!pid) {
     566        // fprintf (stderr, "no hosts to harvest\n");
     567        usleep (500000);
     568        break; // no outstanding jobs have finished
     569      }
     570      if ((pid == -1) && (errno == ECHILD)) goto escape; // no more jobs on which to wait
     571      if ((pid == -1) && (errno != ECHILD)) {
     572        fprintf (stderr, "programming error (2)? %s %d", file, lineno);
     573        exit (2);
     574      }
     575
     576      // find the host which has finished
     577      int found = FALSE;
     578      for (i = 0; (i < table->Nhosts) && !found; i++) {
     579        if (table->hosts[i][0].pid != pid) continue;
     580        found = TRUE;
     581
     582        HostInfo *host = table->hosts[i];
     583
     584        // check on the status of this and report any output?
     585        if (VERBOSE) fprintf (stdout, "job finished for %s (%d)\n", host->hostname, pid);
     586
     587        // read stdout
     588        int printHead;
     589        printHead = VERBOSE || (host->stdout.Nbuffer > 0);
     590        EmptyIOBuffer (&host->stdout, 100, host->stdio[HOST_STDOUT]);
     591        if (printHead) fprintf (stdout, "--- stdout from %s --- (%d bytes, v2)\n", host->hostname, host->stdout.Nbuffer);
     592        int Nout = write (STDOUT_FILENO, host->stdout.buffer, host->stdout.Nbuffer);
     593        if (Nout != host->stdout.Nbuffer) { fprintf (stderr, "(error writing log?)\n"); }
     594        FlushIOBuffer (&host->stdout);
     595        if (printHead) fprintf (stdout, "\n");
     596           
     597        // read stderr
     598        printHead = VERBOSE || (host->stderr.Nbuffer > 0);
     599        EmptyIOBuffer (&host->stderr, 100, host->stdio[HOST_STDERR]);
     600        if (printHead) fprintf (stdout, "--- stderr from %s --- (%d bytes, v2)\n", host->hostname, host->stderr.Nbuffer);
     601        Nout = write (STDOUT_FILENO, host->stderr.buffer, host->stderr.Nbuffer);
     602        if (Nout != host->stderr.Nbuffer) { fprintf (stderr, "(error writing log?)\n"); }
     603        FlushIOBuffer (&host->stderr);
     604        if (printHead) fprintf (stdout, "\n");
     605
     606        if (WIFEXITED(status)) {
     607          if (VERBOSE) fprintf (stdout, "normal completion, exit status is %d\n", WEXITSTATUS(status));
     608          host->status = WEXITSTATUS(status);
     609          if (host->status) {
     610            fprintf (stdout, "job failed on %s\n", host->hostname);
     611            globalStatus = FALSE;
     612          }
     613        } else {
     614          host->status = -1;
     615          fprintf (stdout, "job exited abnormally on %s\n", host->hostname);
     616          globalStatus = FALSE;
     617          continue;
     618        }
     619      }
     620      if (!found) {
     621        fprintf (stderr, "Programming error: failed to matched finished job to known host!\n");
     622        exit (2);
     623      }
     624      Nfound ++;
     625      if (Nfound == Nrunning) goto escape; // we've harvested all jobs
     626    }
     627  }
     628
     629escape:
     630
     631  // close all opened connections
     632  for (i = 0; i < table->Nhosts; i++) {
     633    if (!table->hosts[i][0].pid) continue; // any unconnected hosts should be skipped
     634    close (table->hosts[i][0].stdio[HOST_STDIN]);
     635    close (table->hosts[i][0].stdio[HOST_STDOUT]);
     636    close (table->hosts[i][0].stdio[HOST_STDERR]);
     637  }
     638
     639  return globalStatus;
     640}
     641
    391642int HostTableTestHost (SkyRegion *region, int hostID) {
    392643
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/ImageMetadata.c

    r37035 r37822  
    156156  // assign the storage arrays
    157157  for (i = 0; i < Nimage; i++) {
    158     int Nmosaic = FindMosaicForImage (image, Nimage, i);
    159     if (!Nmosaic) continue;
    160     Nmosaic --;
     158    if (!image[i].coords.mosaic) continue;
    161159    imageID[i]  = image[i].imageID;
    162160    externID[i] = image[i].externID;
    163     crval1[i]   = image[Nmosaic].coords.crval1;
    164     crval2[i]   = image[Nmosaic].coords.crval2;
    165 
    166     theta[i]    = DEG_RAD*atan2(image[Nmosaic].coords.pc1_2, image[Nmosaic].coords.pc1_1);
     161    Coords *mosaic = image[i].coords.mosaic;
     162
     163    crval1[i]   = mosaic->crval1;
     164    crval2[i]   = mosaic->crval2;
     165
     166    theta[i]    = DEG_RAD*atan2(mosaic->pc1_2, mosaic->pc1_1);
    167167
    168168    Mcal[i]     = image[i].Mcal;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/ImageMetadataSelection.c

    r36490 r37822  
    1313 
    1414  /* field defines a frame with 0,0 at the field center, and 1 arcsec / pixel */
    15   field.crpix1 = field.crpix2 = 0.0;
     15  InitCoords (&field, "DEC--SIN");
    1616  field.cdelt1 = field.cdelt2 = 1.0 / 3600;
    17   field.pc1_1  = field.pc2_2  = 1.0;
    18   field.pc1_2  = field.pc2_1  = 0.0;
    19   field.Npolyterms = 0;
    20   strcpy (field.ctype, "DEC--SIN");
    2117
    2218  /* mosaic defines a frame with 0,0 at the mosaic center, and 1 arcsec / pixel */
    23   mosaic.crpix1 = mosaic.crpix2 = 0.0;
     19  InitCoords (&mosaic, "DEC--SIN");
    2420  mosaic.cdelt1 = mosaic.cdelt2 = 1.0 / 3600;
    25   mosaic.pc1_1  = mosaic.pc2_2  = 1.0;
    26   mosaic.pc1_2  = mosaic.pc2_1  = 0.0;
    27   mosaic.Npolyterms = 0;
    28   strcpy (mosaic.ctype, "DEC--SIN");
    2921
    3022  if ((image = ImageMetadataLoad (filename, &Nimage)) == NULL) return (FALSE);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/ImageOps.c

    r34088 r37822  
    5555    if (TimeSelect && ((image[i].tzero < tzero) || (image[i].tzero+image[i].trate*image[i].NY > tzero + trange))) continue;
    5656    if (selection->useDisplay) {
    57       if (!FindMosaicForImage (image, Nimage, i)) continue;
    5857      // first check if region center is in image
    5958      status = RD_to_XY (&X, &Y, Rmid, graph.coords.crval2, &image[i].coords);
     
    8988    }
    9089    if (selection->useSkyregion) {
    91       if (!FindMosaicForImage (image, Nimage, i)) continue;
    9290      /* project this image to screen display coords */
    9391      x[0] = 0;           y[0] = 0;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/ImageSelection.c

    r36490 r37822  
    2222
    2323  if (mosaicMode) {
    24       /* mosaic defines a frame with 0,0 at the mosaic center, and 1 arcsec / pixel */
    25       mosaic.crpix1 = mosaic.crpix2 = 0.0;
    26       mosaic.cdelt1 = mosaic.cdelt2 = 1.0 / 3600;
    27       mosaic.pc1_1  = mosaic.pc2_2  = 1.0;
    28       mosaic.pc1_2  = mosaic.pc2_1  = 0.0;
    29       mosaic.Npolyterms = 0;
    30       strcpy (mosaic.ctype, "DEC--SIN");
     24    /* mosaic defines a frame with 0,0 at the mosaic center, and 1 arcsec / pixel */
     25    InitCoords (&mosaic, "DEC--SIN");
     26    mosaic.cdelt1 = mosaic.cdelt2 = 1.0 / 3600;
    3127  }
    3228
     
    6460  }
    6561  if (m == -1) return (NULL);
    66   if (!FindMosaicForImage (image, Nimage, m)) return (NULL);
    6762  return (&image[m]);
    6863}
     
    8580  }
    8681  if (m == -1) return (NULL);
    87   if (!FindMosaicForImage (image, Nimage, m)) return (NULL);
    8882  return (&image[m]);
    8983}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/LoadImages.c

    r33649 r37822  
    99static Image *imageCache = NULL;
    1010static off_t cacheNimage = 0;
     11AstromOffsetTable *table = NULL;
    1112
    1213static time_t getLastModified(char *filename);
     
    3940    lastModified = 0;
    4041  }
    41 
    4242
    4343  gfits_db_init (&db);
     
    7777  }
    7878
     79  // assign image->parent and image->coords.mosaic
     80  BuildChipMatch (image, *Nimage);
     81  // MARKTIME("build chip match: %f sec\n", dtime);
     82
     83  char mapfile[DVO_MAX_PATH];
     84  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", catdir);
     85
     86  if (table) AstromOffsetTableFree(table);
     87  table = AstromOffsetMapLoad (mapfile, FALSE);
     88
     89  // assign images.coords.offsetMap -> table->map[i]
     90  if (table) {
     91    AstromOffsetTableMatchChips (image, *Nimage, table);
     92  }
     93
    7994  return (image);
    8095}
     
    92107  if (!dvoUseImageCache && (images != NULL)) {
    93108    free(images);
     109    AstromOffsetTableFree (table);
    94110  } else {
    95111    // defer free until next LoadImages with a different or modified Images.dat
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/RegionHostTable.c

    r36630 r37822  
    3131    hosts[i].Nneighbors = 0;
    3232    hosts[i].isNeighbor = FALSE;
     33
     34    hosts[i].astromTable = NULL;
    3335  }
    3436  return;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/TessellationTable.c

    r36490 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/cmf-ps1-v5-lensing.c

    r37035 r37822  
    11# include "dvo.h"
    2 # define ST_SIZE 312
     2# define ST_SIZE 320
    33
    44// this function is based on the one generated by the autocode of cmf-ps1-v5.d
     
    100100    SWAP_WORD (256); // E1_SH_PSF
    101101    SWAP_WORD (260); // E2_SH_PSF
    102     SWAP_WORD (264); // MOMENTS_R1
    103     SWAP_WORD (268); // MOMENTS_RH
    104     SWAP_WORD (272); // KRON_FLUX
    105     SWAP_WORD (276); // KRON_FLUX_ERR
    106     SWAP_WORD (280); // KRON_FLUX_INNER
    107     SWAP_WORD (284); // KRON_FLUX_OUTER
    108     SWAP_WORD (288); // SKY_LIMIT_RAD
    109     SWAP_WORD (292); // SKY_LIMIT_FLUX
    110     SWAP_WORD (296); // SKY_LIMIT_SLOPE
    111     SWAP_WORD (300); // FLAGS
    112     SWAP_WORD (304); // FLAGS2
    113     SWAP_BYTE (308); // N_FRAMES
    114     SWAP_BYTE (310); // PADDING                       
     102
     103    SWAP_BYTE (264); // SRC_CHIP_NUM
     104    SWAP_BYTE (266); // SRC_CHIP_X
     105    SWAP_BYTE (268); // SRC_CHIP_Y
     106
     107    SWAP_WORD (272); // MOMENTS_R1
     108    SWAP_WORD (276); // MOMENTS_RH
     109    SWAP_WORD (280); // KRON_FLUX
     110    SWAP_WORD (284); // KRON_FLUX_ERR
     111    SWAP_WORD (288); // KRON_FLUX_INNER
     112    SWAP_WORD (292); // KRON_FLUX_OUTER
     113    SWAP_WORD (296); // SKY_LIMIT_RAD
     114    SWAP_WORD (300); // SKY_LIMIT_FLUX
     115    SWAP_WORD (304); // SKY_LIMIT_SLOPE
     116    SWAP_WORD (308); // FLAGS
     117    SWAP_WORD (312); // FLAGS2
     118    SWAP_BYTE (316); // N_FRAMES
     119    SWAP_BYTE (318); // PADDING                       
    115120  }
    116121# endif 
     
    289294  gfits_define_bintable_column (header, "E",    "E1_SH_PSF",        "lensing shear",                   "",                  1.0, 0.0);
    290295  gfits_define_bintable_column (header, "E",    "E2_SH_PSF",        "lensing shear",                   "",                  1.0, 0.0);
     296
     297  gfits_define_bintable_column (header, "I",    "SRC_CHIP_NUM",     "number of source chip for warp",  "",                  1.0, 0.0);
     298  gfits_define_bintable_column (header, "I",    "SRC_CHIP_X",       "x-coord in source chip",          "",                  1.0, 0.0);
     299  gfits_define_bintable_column (header, "I",    "SRC_CHIP_Y",       "y-coord in source chip",          "",                  1.0, 0.0);
     300  gfits_define_bintable_column (header, "I",    "PADDING3",         "padding for 8byte records",       "",                  1.0, 0.0);
     301
    291302  gfits_define_bintable_column (header, "E",    "MOMENTS_R1",       "first radial moment",             "pixels",            1.0, 0.0);
    292303  gfits_define_bintable_column (header, "E",    "MOMENTS_RH",       "half radial moment",              "pixels^1/2",        1.0, 0.0);
     
    385396  gfits_define_bintable_column (header, "E",    "E1_SH_PSF",        "lensing shear",                   "",                  1.0, 0.0);
    386397  gfits_define_bintable_column (header, "E",    "E2_SH_PSF",        "lensing shear",                   "",                  1.0, 0.0);
     398
     399  gfits_define_bintable_column (header, "I",    "SRC_CHIP_NUM",     "number of source chip for warp",  "",                  1.0, 0.0);
     400  gfits_define_bintable_column (header, "I",    "SRC_CHIP_X",       "x-coord in source chip",          "",                  1.0, 0.0);
     401  gfits_define_bintable_column (header, "I",    "SRC_CHIP_Y",       "y-coord in source chip",          "",                  1.0, 0.0);
     402  gfits_define_bintable_column (header, "I",    "PADDING3",         "padding for 8byte records",       "",                  1.0, 0.0);
     403
    387404  gfits_define_bintable_column (header, "E",    "MOMENTS_R1",       "first radial moment",             "pixels",            1.0, 0.0);
    388405  gfits_define_bintable_column (header, "E",    "MOMENTS_RH",       "half radial moment",              "pixels^1/2",        1.0, 0.0);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/cmf-ps1-v5.c

    r37035 r37822  
    11# include "dvo.h"
     2# define ST_SIZE 232
    23
    34// this function is based on the one generated by the autocode of cmf-ps1-v5.d
     
    78  unsigned char tmp;
    89
    9   if (size != 232) {
    10     fprintf (stderr, "WARNING: mismatch in data types CMF_PS1_V5: "OFF_T_FMT" vs %d\n",  size,  232);
     10  if (size != ST_SIZE) {
     11    fprintf (stderr, "WARNING: mismatch in data types CMF_PS1_V5: "OFF_T_FMT" vs %d\n",  size,  ST_SIZE);
    1112    return (FALSE);
    1213  }
     
    3334# ifdef BYTE_SWAP
    3435  byte = (unsigned char *) data;
    35   for (i = 0; i < nitems; i++, byte += 232) {
     36  for (i = 0; i < nitems; i++, byte += ST_SIZE) {
    3637    /** BYTE SWAP **/
    3738    SWAP_WORD (0); // IPP_IDET                     
     
    176177
    177178  Ncols = ftable[0].header[0].Naxis[0];
    178   if (Ncols != 232) {
    179     fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, 232);
     179  if (Ncols != ST_SIZE) {
     180    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, ST_SIZE);
    180181    return NULL;
    181182  }
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/coord_systems.c

    r31635 r37822  
    11# include "dvo.h"
    2 # include "libdvo_astro.h"
    32   
    43CoordTransform *InitTransform (CoordTransformSystem input, CoordTransformSystem output) {
     
    4039          // \delta^p_J = +27d 07' 41.7087"
    4140          // \theta_J   = 122.93192526 deg
     41
    4242          // these differ from the above at the several milliarcsec level
    43 
    4443
    4544          // These values were used in the past, but transform to/from B1950.0
     
    4746          // transform->Xo  = 282.25*RAD_DEG;
    4847          // transform->xo  =  33.00;
     48
     49          break;
     50        case COORD_GALACTIC_REID_2004:
     51
     52          // J2000 FK5 transformation from Reid et al 2004, ApJ 616, 872
     53          transform->phi = (27.128336111 - 90.0)*RAD_DEG; // +27d 07' 42.01" (J2000)
     54          transform->Xo  = (192.859508333 + 90.0)*RAD_DEG; // 12h 51m 26.282s (J2000)
     55          transform->xo  =  32.932;
     56
     57          // comments from LSD code (lsd/builtins/misc.py, Mario Juric)
     58          // # Appendix of Reid et al. (http://adsabs.harvard.edu/cgi-bin/bib_query?2004ApJ...616..872R)
     59          // # This convention is also used by LAMBDA/WMAP (http://lambda.gsfc.nasa.gov/toolbox/tb_coordconv.cfm)
     60
     61          // _angp = np.radians(192.859508333) #  12h 51m 26.282s (J2000)
     62          // _dngp = np.radians(27.128336111)  # +27d 07' 42.01" (J2000)
     63          // _l0   = np.radians(32.932)
    4964
    5065          break;
     
    87102      switch (output) {
    88103        case COORD_CELESTIAL:
    89           // J2000 transformation from Liu et al 2011 ()
     104          // J2000 transformation from Liu et al 2011 (A&A 526, A16)
    90105          transform->phi =  62.8717488056*RAD_DEG;
    91106          transform->Xo  =  32.9319185700*RAD_DEG;
    92107          transform->xo  = 282.8594812080;
     108
     109          // These values were used in the past, but transform to/from B1950.0
     110          // transform->phi =  62.60*RAD_DEG;
     111          // transform->Xo  =  33.00*RAD_DEG;
     112          // transform->xo  = 282.25;
     113          break;
     114        case COORD_GALACTIC:
     115          transform->phi = 0.0;
     116          transform->Xo  = 0.0;
     117          transform->xo  = 0.0;
     118          transform->isIdentity = TRUE;
     119          break;
     120        case COORD_ECLIPTIC:
     121          return NULL;
     122        default:
     123          abort();
     124      }
     125      break;
     126    case COORD_GALACTIC_REID_2004:
     127      switch (output) {
     128        case COORD_CELESTIAL:
     129          // J2000 FK5 transformation from Reid et al 2004, ApJ 616, 872
     130          transform->phi = (90.0 - 27.128336111)*RAD_DEG; // +27d 07' 42.01" (J2000)
     131          transform->Xo  =  32.932*RAD_DEG;
     132          transform->xo  = (192.859508333 + 90.0); // 12h 51m 26.282s (J2000)
    93133
    94134          // These values were used in the past, but transform to/from B1950.0
     
    144184  Y *= RAD_DEG;
    145185
     186  double cosY = cos(Y);
     187  double sinY = sin(Y);
     188 
     189  double cosX = cos(X);
     190  double sinX = sin(X);
     191
    146192  // recast with constants extracted:
    147   sin_y = cos(Y)*sin(X)*transform->sin_phi_cos_Xo - cos(Y)*cos(X)*transform->sin_phi_sin_Xo + sin(Y)*transform->cos_phi;
     193  sin_y = cosY*sinX*transform->sin_phi_cos_Xo - cosY*cosX*transform->sin_phi_sin_Xo + sinY*transform->cos_phi;
    148194  cos_y = sqrt (1 - sin_y*sin_y);
    149195
    150   sin_x = cos(Y)*sin(X)*transform->cos_phi_cos_Xo - cos(Y)*cos(X)*transform->cos_phi_sin_Xo - sin(Y)*transform->sin_phi;
    151   cos_x = cos(Y)*cos(X)*transform->cos_Xo + cos(Y)*sin(X)*transform->sin_Xo;
     196  sin_x = cosY*sinX*transform->cos_phi_cos_Xo - cosY*cosX*transform->cos_phi_sin_Xo - sinY*transform->sin_phi;
     197  cos_x = cosY*cosX*transform->cos_Xo + cosY*sinX*transform->sin_Xo;
    152198     
    153199  // atan2 returns -pi : +pi
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/coordops.c

    r36490 r37822  
    33/* note that Coords.ctype carries the DEC (ctype2) value */
    44
    5 static Coords mosaic;
    6 static int gotMosaic = FALSE;
    7 
    8 void RegisterMosaic (Coords *coords) {
    9   mosaic = *coords;
    10   gotMosaic = TRUE;
    11 }
    12 
    13 int isRegisteredMosaic () {
    14   return (gotMosaic);
    15 }
    16 
    17 int GetMosaicCoords (Coords *coords) {
    18   *coords = mosaic;
    19   return (TRUE);
    20 }
     5// default coordinates have unit scale and no rotation
     6void InitCoords (Coords *coords, char *projection) {
     7  coords->crval1 = 0.0;
     8  coords->crval2 = 0.0;
     9  coords->crpix1 = 0.0;
     10  coords->crpix2 = 0.0;
     11
     12  coords->cdelt1 = 1.0;
     13  coords->cdelt2 = 1.0;
     14
     15  coords->pc1_1 = 1.0; // EW is flipped relative to sky parity (dRA/dX > 0)
     16  coords->pc2_2 = 1.0;
     17  coords->pc2_1 = 0.0;
     18  coords->pc1_2 = 0.0;
     19
     20  coords->Npolyterms = 1;
     21  coords->mosaic = NULL;
     22  coords->offsetMap = NULL;
     23
     24  memset (coords->polyterms, 0, 7*2*sizeof(float));
     25
     26  if (projection) {
     27    strcpy (coords->ctype, projection);
     28  } else {
     29    strcpy (coords->ctype, "NONE");
     30  }
     31}
     32
     33// default coordinates have unit scale and no rotation
     34void CopyCoords (Coords *tgt, Coords *src) {
     35  tgt->crval1     = src->crval1;
     36  tgt->crval2     = src->crval2;
     37  tgt->crpix1     = src->crpix1;
     38  tgt->crpix2     = src->crpix2;
     39  tgt->cdelt1     = src->cdelt1;
     40  tgt->cdelt2     = src->cdelt2;
     41  tgt->pc1_1      = src->pc1_1;
     42  tgt->pc2_2      = src->pc2_2;
     43  tgt->pc2_1      = src->pc2_1;
     44  tgt->pc1_2      = src->pc1_2;
     45  tgt->Npolyterms = src->Npolyterms;
     46  tgt->mosaic     = src->mosaic;      // pointer to another structure
     47  tgt->offsetMap  = src->offsetMap;   // pointer to another structure
     48
     49  memcpy (tgt->polyterms, src->polyterms, 7*2*sizeof(float));
     50  strcpy (tgt->ctype,     src->ctype);
     51}
    2152
    2253int XY_to_LM (double *L, double *M, double x, double y, Coords *coords) {
     
    2859  proj = GetProjection (coords[0].ctype);
    2960  mode = GetProjectionMode (proj);
     61
     62  // if we have an image map, it should be applied to the pixel coordinates
     63  // before anything else is done.  It is easier to invert the map if it is
     64  // of the form (dX,dY) = f(X,Y), then if (dL,dM) = f(X,Y).
     65  if (coords[0].Npolyterms == -1) {
     66    myAssert (coords[0].offsetMap, "offsetMap is requested by not defined");
     67    float dX = AstromOffsetMapValue (coords->offsetMap, x, y, TRUE);
     68    float dY = AstromOffsetMapValue (coords->offsetMap, x, y, FALSE);
     69    if (isnan(dX)) dX = 0.0;
     70    if (isnan(dY)) dY = 0.0;
     71    x += dX;
     72    y += dY;
     73  }
    3074
    3175  /** convert pixel coordinates to cartesian system **/
     
    78122    /* mosaic astrometry : WRP is chip astrometry; apply mosaic (DIS) term */
    79123    if (proj == PROJ_WRP) {
    80       if (!gotMosaic) return (FALSE);
    81       XY_to_RD (ra, dec, L, M, &mosaic);
     124      if (!coords->mosaic) {
     125        myAbort ("missing mosaic element");
     126        return (FALSE);
     127      }
     128      XY_to_RD (ra, dec, L, M, coords->mosaic);
    82129    }
    83130    return (TRUE);
     
    149196    *dec = DEG_RAD*delta;
    150197
    151     *ra = ohana_normalize_angle (*ra);
     198    // *ra = ohana_normalize_angle (*ra);
    152199
    153200    return (TRUE);
     
    182229    *dec = delta + coords[0].crval2;
    183230
    184     *ra = ohana_normalize_angle (*ra);
     231    // *ra = ohana_normalize_angle (*ra);
    185232
    186233    return (TRUE);
     
    208255  if (mode == PROJ_MODE_CARTESIAN) {
    209256    if (proj == PROJ_WRP) {
    210       if (!gotMosaic) return (FALSE);
    211       RD_to_XY (L, M, ra, dec, &mosaic);
     257      if (!coords->mosaic) {
     258        myAbort ("missing mosaic element");
     259        return (FALSE);
     260      }
     261      RD_to_XY (L, M, ra, dec, coords->mosaic);
    212262      return (TRUE);
    213263    }
     
    381431  *y = Yo / coords[0].cdelt2 + coords[0].crpix2;
    382432
     433  // if we have an image map, it should be applied to the pixel coordinates
     434  // after anything else is done.  It is easier to invert the map if it is
     435  // of the form (dX,dY) = f(X,Y), then if (dL,dM) = f(X,Y).
     436  if (coords[0].Npolyterms == -1) {
     437    myAssert (coords[0].offsetMap, "offsetMap is requested by not defined");
     438
     439    double xraw = *x;
     440    double yraw = *y;
     441
     442    double dXo = 0.0;
     443    double dYo = 0.0;
     444
     445    int i;
     446    for (i = 0; i < 4; i++) {
     447      double dX = AstromOffsetMapValue (coords->offsetMap, xraw, yraw, TRUE);
     448      double dY = AstromOffsetMapValue (coords->offsetMap, xraw, yraw, FALSE);
     449
     450      if (isnan(dX)) dX = 0.0;
     451      if (isnan(dY)) dY = 0.0;
     452
     453      dX -= dXo;
     454      dY -= dYo;
     455
     456      xraw -= dX;
     457      yraw -= dY;
     458
     459      dXo += dX;
     460      dYo += dY;
     461    }
     462
     463    *x = xraw;
     464    *y = yraw;
     465
     466    // I need to iterate since the position at which I have first made the correction is
     467    // not the true position.  but if dX,dY is small and the gradient of dX,dY is also
     468    // small, then even a single pass gets us close.
     469
     470    // XXX test this and use a while (hypot(dX,dY) > XXX) condition
     471  }
    383472  return (TRUE);
    384473}
     
    449538 
    450539  rotate = 0.0;
    451   coords[0].crval1 = coords[0].crpix1 = coords[0].cdelt1 = 0.0;
    452   coords[0].crval2 = coords[0].crpix2 = coords[0].cdelt2 = 0.0;
    453   coords[0].pc1_1 = coords[0].pc2_2 = 1.0;
    454   coords[0].pc2_1 = coords[0].pc1_2 = 0.0;
    455   coords[0].Npolyterms = 1;
    456   strcpy (coords[0].ctype, "NONE");
     540
     541  InitCoords (coords, NULL);
    457542 
    458543  mode = COORD_TYPE_NONE;
     
    595680
    596681  if (status) {
    597     if (!gfits_scan (header, "EQUINOX", "%lf", 1, &equinox)) {
    598       if (!gfits_scan (header, "EPOCH", "%lf", 1, &equinox)) {
    599         equinox = 2000.0;
     682    char equinoxString[80];
     683    int haveEquinox = gfits_scan (header, "EQUINOX", "%s", 1, equinoxString);
     684    if (haveEquinox) {
     685      // is the string a valid number (it is bad to interpret an error message as year 0.0)
     686      char *endptr;
     687      equinox = strtod (equinoxString, &endptr);
     688      if (endptr == equinoxString) haveEquinox = FALSE;
     689    }
     690    if (!haveEquinox) {
     691      haveEquinox = gfits_scan (header, "EPOCH", "%s", 1, equinoxString);
     692      if (haveEquinox) {
     693        // is the string a valid number (it is bad to interpret an error message as year 0.0)
     694        char *endptr;
     695        equinox = strtod (equinoxString, &endptr);
     696        if (endptr == equinoxString) haveEquinox = FALSE;
    600697      }
     698    }
     699    if (!haveEquinox) {
     700      equinox = 2000.0;
    601701    }
    602702    if (fabs (equinox - 2000.0) > 0.1) {
     
    604704    }
    605705  }
    606 
     706 
    607707  if (!status) {
    608708    // fprintf (stderr, "error getting all elements for coordinate mode %s\n", coords[0].ctype);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dbExtractAverages.c

    r37035 r37822  
    5050
    5151/* return average.field based on the selection */
    52 dbValue dbExtractAverages (Average *average, SecFilt *secfilt, Measure *measure, dbField *field) {
     52dbValue dbExtractAverages (Average *average, SecFilt *secfilt, Measure *measure, Lensobj *lensobj, StarPar *starpar, dbField *field) {
    5353
    5454  // off_t i;
     
    161161      value.Flt = average[0].stargal;
    162162      break;
    163     case AVE_REF_COLOR:
     163    case AVE_REF_COLOR_BLUE:
    164164      value.Flt = average[0].refColorBlue;
     165      break;
     166    case AVE_REF_COLOR_RED:
     167      value.Flt = average[0].refColorRed;
    165168      break;
    166169
     
    200203      }
    201204
     205      /* in some cases below we need a measurement which matches the requested photcode.
     206         here is some sample code to find this.
     207
     208          for (i = 0; i < average[0].Nmeasure; i++) {
     209            if (field->photcode->code != measure[i].photcode) continue;
     210            value.Flt = measure[i].M;
     211            break;
     212          }
     213      */
     214
    202215      switch (field->magOption) {
    203216        case MAG_OPTION_MAG:
     
    207220              break;
    208221            case MAG_LEVEL_REF:
    209               // why is measure needed here?
     222              // which measure is needed here?
    210223              // PhotRef  (field->photcode, average, secfilt, measure, field->magClass, field->magSource);
    211224              break;
     
    242255              break;
    243256            case MAG_LEVEL_REF:
    244               // value.Flt = PhotFluxRef  (equiv, average, secfilt, measure, field->magClass, field->magSource);
     257              // XXX which measure is needed here?
     258              // value.Flt = PhotFluxRef  (field->photcode, average, secfilt, measure, field->magClass, field->magSource);
    245259              break;
    246260            case MAG_LEVEL_INST:
     
    258272            case MAG_LEVEL_AVE:
    259273            case MAG_LEVEL_REF:
    260               // value.Flt = PhotFluxAveErr (equiv, average, secfilt, field->magClass, field->magSource); 
     274              value.Flt = PhotFluxAveErr (field->photcode, average, secfilt, field->magClass, field->magSource); 
    261275              break;
    262276            case MAG_LEVEL_INST:
     
    271285
    272286        case MAG_OPTION_STDEV:
     287          value.Flt = PhotMstdev (field->photcode, average, secfilt, field->magClass, field->magSource);
     288          break;
    273289        case MAG_OPTION_CHISQ:
     290          value.Flt = PhotXm (field->photcode, average, secfilt);
     291          break;
    274292        case MAG_OPTION_MIN:
     293          value.Flt = PhotMmin (field->photcode, average, secfilt);
     294          break;
    275295        case MAG_OPTION_MAX:
     296          value.Flt = PhotMmax (field->photcode, average, secfilt);
     297          break;
    276298        case MAG_OPTION_NCODE: {
    277299          int Nsec = GetPhotcodeNsec (field->photcode->code);
     
    281303        }
    282304        case MAG_OPTION_NPHOT: {
    283           int Nsec = GetPhotcodeNsec (field->photcode->code);
    284           if (Nsec == -1) break;
    285           value.Int = secfilt[Nsec].Nused;
     305          value.Int = PhotNphot (field->photcode, average, secfilt, field->magClass, field->magSource);
    286306          break;
    287307        }
    288308        case MAG_OPTION_UC_DIST:
    289         case MAG_OPTION_STACK_DET_ID:
    290           value.Int = PhotStackID (field->photcode, average, secfilt);
     309          value.Flt = PhotUCdist (field->photcode, average, secfilt);
    291310          break;
    292311        case MAG_OPTION_FLAGS: {
     
    296315          break;
    297316        }
     317
     318          // g:X11_SM_OBJ, etc, are only valid for average
     319        case MAG_OPTION_X11_SM_OBJ: { value.Flt = LensValue_X11_sm_obj (field->photcode, lensobj); break; }
     320        case MAG_OPTION_X12_SM_OBJ: { value.Flt = LensValue_X12_sm_obj (field->photcode, lensobj); break; }
     321        case MAG_OPTION_X22_SM_OBJ: { value.Flt = LensValue_X22_sm_obj (field->photcode, lensobj); break; }
     322        case MAG_OPTION_E1_SM_OBJ:  { value.Flt = LensValue_E1_sm_obj  (field->photcode, lensobj); break; }
     323        case MAG_OPTION_E2_SM_OBJ:  { value.Flt = LensValue_E2_sm_obj  (field->photcode, lensobj); break; }
     324
     325        case MAG_OPTION_X11_SH_OBJ: { value.Flt = LensValue_X11_sh_obj (field->photcode, lensobj); break; }
     326        case MAG_OPTION_X12_SH_OBJ: { value.Flt = LensValue_X12_sh_obj (field->photcode, lensobj); break; }
     327        case MAG_OPTION_X22_SH_OBJ: { value.Flt = LensValue_X22_sh_obj (field->photcode, lensobj); break; }
     328        case MAG_OPTION_E1_SH_OBJ:  { value.Flt = LensValue_E1_sh_obj  (field->photcode, lensobj); break; }
     329        case MAG_OPTION_E2_SH_OBJ:  { value.Flt = LensValue_E2_sh_obj  (field->photcode, lensobj); break; }
     330
     331        case MAG_OPTION_X11_SM_PSF: { value.Flt = LensValue_X11_sm_psf (field->photcode, lensobj); break; }
     332        case MAG_OPTION_X12_SM_PSF: { value.Flt = LensValue_X12_sm_psf (field->photcode, lensobj); break; }
     333        case MAG_OPTION_X22_SM_PSF: { value.Flt = LensValue_X22_sm_psf (field->photcode, lensobj); break; }
     334        case MAG_OPTION_E1_SM_PSF:  { value.Flt = LensValue_E1_sm_psf  (field->photcode, lensobj); break; }
     335        case MAG_OPTION_E2_SM_PSF:  { value.Flt = LensValue_E2_sm_psf  (field->photcode, lensobj); break; }
     336
     337        case MAG_OPTION_X11_SH_PSF: { value.Flt = LensValue_X11_sh_psf (field->photcode, lensobj); break; }
     338        case MAG_OPTION_X12_SH_PSF: { value.Flt = LensValue_X12_sh_psf (field->photcode, lensobj); break; }
     339        case MAG_OPTION_X22_SH_PSF: { value.Flt = LensValue_X22_sh_psf (field->photcode, lensobj); break; }
     340        case MAG_OPTION_E1_SH_PSF:  { value.Flt = LensValue_E1_sh_psf  (field->photcode, lensobj); break; }
     341        case MAG_OPTION_E2_SH_PSF:  { value.Flt = LensValue_E2_sh_psf  (field->photcode, lensobj); break; }
     342
    298343        case MAG_OPTION_NONE:
    299344          break;
    300       }
    301       break;
    302 
    303 # if (0)
    304       switch (field->magMode) {
    305         case MAG_AVE:
    306           value.Flt = PhotAve  (field->photcode, average, secfilt);
    307           break;
    308         case MAG_REF:
    309           value.Flt = PhotRef  (field->photcode, average, secfilt, measure);
    310           break;
    311         case MAG_INST:
    312         case MAG_CAT:
    313         case MAG_SYS:
    314         case MAG_REL:
    315         case MAG_CAL:
    316           // XXX need to code this correctly: this returns just the first matching value
    317           value.Flt = NAN;
    318           for (i = 0; i < average[0].Nmeasure; i++) {
    319             if (field->photcode->code != measure[i].photcode) continue;
    320             value.Flt = measure[i].M;
    321             break;
    322           }
    323           break;
    324         case MAG_CHISQ:
    325           value.Flt = PhotXm (field->photcode, average, secfilt);
    326           break;
    327         case MAG_ERR:
    328           if ((field->photcode->type == PHOT_REF) || (field->photcode->type == PHOT_DEP)) {
    329             for (i = 0; i < average[0].Nmeasure; i++) {
    330               if (field->photcode->code != measure[i].photcode) continue;
    331               value.Flt = measure[i].dM;
    332               break;
    333             }
    334           } else {
    335             value.Flt = PhotAveErr (field->photcode, average, secfilt);
    336           }
    337           break;
    338         case MAG_STDEV:
    339           value.Flt = PhotMstdev (field->photcode, average, secfilt);
    340           break;
    341         case MAG_PHOT_FLAGS:
    342           if ((field->photcode->type == PHOT_REF) || (field->photcode->type == PHOT_DEP)) {
    343             for (i = 0; i < average[0].Nmeasure; i++) {
    344               if (field->photcode->code != measure[i].photcode) continue;
    345               value.Int = measure[i].photFlags;
    346               break;
    347             }
    348           } else {
    349             int Nsec = GetPhotcodeNsec (field->photcode->code);
    350             if (Nsec == -1) break;
    351             value.Int = secfilt[Nsec].flags;
    352           }
    353           break;
    354         case MAG_NCODE:
    355           // XXX push these into dvo_photcode_ops APIs
    356           // XXX do I need to allow for conversion to equiv?
    357           int Nsec = GetPhotcodeNsec (field->photcode->code);
    358           if (Nsec == -1) break;
    359           value.Int = secfilt[Nsec].Ncode;
    360           break;
    361         case MAG_NPHOT:
    362           int Nsec = GetPhotcodeNsec (field->photcode->code);
    363           if (Nsec == -1) break;
    364           value.Int = secfilt[Nsec].Nused;
    365           break;
    366 
    367         case MAG_APER:
    368         case MAG_APER_AVE:
    369           value.Flt = PhotAperAve (field->photcode, average, secfilt);
    370           break;
    371 
    372         case MAG_APER_REF:
    373           value.Flt = PhotAperRef (field->photcode, average, secfilt, measure);
    374           break;
    375 
    376         case MAG_KRON:
    377         case MAG_KRON_AVE:
    378           value.Flt = PhotKronAve (field->photcode, average, secfilt);
    379           break;
    380 
    381         case MAG_KRON_REF:
    382           value.Flt = PhotKronRef (field->photcode, average, secfilt, measure);
    383           break;
    384 
    385         case MAG_KRON_ERR:
    386           value.Flt = PhotKronAveErr (field->photcode, average, secfilt);
    387           break;
    388 
    389         case MAG_MIN:
    390           value.Flt = PhotMmin (field->photcode, average, secfilt);
    391           break;
    392         case MAG_MAX:
    393           value.Flt = PhotMmax (field->photcode, average, secfilt);
    394           break;
    395         case MAG_UC_DIST:
    396           value.Flt = PhotUCdist (field->photcode, average, secfilt);
    397           break;
    398         case MAG_STACK_DET_ID:
    399           value.Int = PhotStackID (field->photcode, average, secfilt);
    400           break;
    401 
    402         case MAG_FLUX_PSF:
    403           value.Flt = PhotAveFluxPSF (field->photcode, average, secfilt);
    404           break;
    405         case MAG_FLUX_PSF_ERR:
    406           value.Flt = PhotAvedFluxPSF (field->photcode, average, secfilt);
    407           break;
    408         case MAG_FLUX_KRON:
    409           value.Flt = PhotAveFluxKron (field->photcode, average, secfilt);
    410           break;
    411         case MAG_FLUX_KRON_ERR:
    412           value.Flt = PhotAvedFluxKron (field->photcode, average, secfilt);
    413           break;
    414       }
    415       break;
    416     case AVE_dMAG:
    417       value.Flt = PhotAveErr (field->photcode, average, secfilt);
    418       break;
    419     case AVE_Xm:
    420       value.Flt = PhotXm (field->photcode, average, secfilt);
    421       break;
    422 # endif
     345
     346        default:
     347          break;
     348      }
     349      break;
     350
     351    case AVE_E_BV:             { value.Flt = starpar->Ebv;      break; }
     352    case AVE_E_BV_ERR:         { value.Flt = starpar->dEbv;     break; }
     353    case AVE_DISTANCE_MOD:     { value.Flt = starpar->DistMag;  break; }
     354    case AVE_DISTANCE_MOD_ERR: { value.Flt = starpar->dDistMag; break; }
     355    case AVE_M_R:              { value.Flt = starpar->M_r;      break; }
     356    case AVE_M_R_ERR:          { value.Flt = starpar->dM_r;     break; }
     357    case AVE_FEH:              { value.Flt = starpar->FeH;      break; }
     358    case AVE_FEH_ERR:          { value.Flt = starpar->dFeH;     break; }
     359    case AVE_URA_GALMODEL:     { value.Flt = starpar->uRA;      break; }
     360    case AVE_UDEC_GALMODEL:    { value.Flt = starpar->uDEC;     break; }
     361    case AVE_RA_GALMODEL:      { value.Flt = starpar->R;        break; }
     362    case AVE_DEC_GALMODEL:     { value.Flt = starpar->D;        break; }
     363
    423364    case AVE_TYPE:
    424365      break;
    425366    case AVE_TYPEFRAC:
    426367      break;
     368
     369
    427370  }
    428371  return (value);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dbExtractImages.c

    r37035 r37822  
    5959  time_t t;
    6060  dbValue value;
    61   off_t Nmosaic;
    6261
    6362  value.Flt = NAN;
     
    6867    case IMAGE_RA:
    6968      if (!haveCelestial) {
    70         if (!FindMosaicForImage (image, Nimage, N)) return value;
    7169        if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
    7270          x = 0.0;
     
    8381    case IMAGE_DEC:
    8482      if (!haveCelestial) {
    85         if (!FindMosaicForImage (image, Nimage, N)) return value;
    8683        if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
    8784          x = 0.0;
     
    9996      if (!haveGalactic) {
    10097        if (!haveCelestial) {
    101           if (!FindMosaicForImage (image, Nimage, N)) return value;
    10298          if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
    10399            x = 0.0;
     
    118114      if (!haveGalactic) {
    119115        if (!haveCelestial) {
    120           if (!FindMosaicForImage (image, Nimage, N)) return value;
    121116          if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
    122117            x = 0.0;
     
    137132      if (!haveEcliptic) {
    138133        if (!haveCelestial) {
    139           if (!FindMosaicForImage (image, Nimage, N)) return value;
    140134          if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
    141135            x = 0.0;
     
    156150      if (!haveEcliptic) {
    157151        if (!haveCelestial) {
    158           if (!FindMosaicForImage (image, Nimage, N)) return value;
    159152          if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
    160153            x = 0.0;
     
    269262
    270263    case IMAGE_FWHM_MEDIAN:
    271       if (!(Nmosaic = FindMosaicForImage (image, Nimage, N))) return value;
    272       Nmosaic --; // XXX kind of a hack: FindMosaicForImage returns 0 or the mosaic seq number + 1
    273       value.Flt = (image[Nmosaic].fwhm_x + image[Nmosaic].fwhm_y) / 50.0;
     264      if (!image[N].parent) return value;
     265      value.Flt = (image[N].parent->fwhm_x + image[N].parent->fwhm_y) / 50.0;
    274266      break;
    275267    case IMAGE_FWHM_MAJ_MEDIAN:
    276       if (!(Nmosaic = FindMosaicForImage (image, Nimage, N))) return value;
    277       Nmosaic --; // XXX kind of a hack: FindMosaicForImage returns 0 or the mosaic seq number + 1
    278       value.Flt = image[Nmosaic].fwhm_x / 25.0;
     268      if (!image[N].parent) return value;
     269      value.Flt = image[N].parent->fwhm_x / 25.0;
    279270      break;
    280271    case IMAGE_FWHM_MIN_MEDIAN:
    281       if (!(Nmosaic = FindMosaicForImage (image, Nimage, N))) return value;
    282       Nmosaic --; // XXX kind of a hack: FindMosaicForImage returns 0 or the mosaic seq number + 1
    283       value.Flt = image[Nmosaic].fwhm_y / 25.0;
     272      if (!image[N].parent) return value;
     273      value.Flt = image[N].parent->fwhm_y / 25.0;
    284274      break;
    285275
     
    375365      break;
    376366
    377     case IMAGE_REF_COLOR:
     367    case IMAGE_REF_COLOR_BLUE:
    378368      value.Flt = image[N].refColorBlue;
     369      break;
     370    case IMAGE_REF_COLOR_RED:
     371      value.Flt = image[N].refColorRed;
    379372      break;
    380373  }
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dbExtractMeasures.c

    r37035 r37822  
    8585
    8686/* return measure.field based on the selection */
    87 dbValue dbExtractMeasures (Average *average, SecFilt *secfilt, Measure *measure, dbField *field) {
     87dbValue dbExtractMeasures (Average *average, SecFilt *secfilt, Measure *measure, Lensing *lensing, StarPar *starpar, dbField *field) {
    8888
    8989  int Nsec;
     
    248248        case MAG_OPTION_NPHOT:
    249249        case MAG_OPTION_UC_DIST:
    250         case MAG_OPTION_STACK_DET_ID:
    251250        case MAG_OPTION_FLAGS:
     251        case MAG_OPTION_X11_SM_OBJ:
     252        case MAG_OPTION_X12_SM_OBJ:
     253        case MAG_OPTION_X22_SM_OBJ:
     254        case MAG_OPTION_E1_SM_OBJ:
     255        case MAG_OPTION_E2_SM_OBJ:
     256        case MAG_OPTION_X11_SH_OBJ:
     257        case MAG_OPTION_X12_SH_OBJ:
     258        case MAG_OPTION_X22_SH_OBJ:
     259        case MAG_OPTION_E1_SH_OBJ:
     260        case MAG_OPTION_E2_SH_OBJ:
     261        case MAG_OPTION_X11_SM_PSF:
     262        case MAG_OPTION_X12_SM_PSF:
     263        case MAG_OPTION_X22_SM_PSF:
     264        case MAG_OPTION_E1_SM_PSF:
     265        case MAG_OPTION_E2_SM_PSF:
     266        case MAG_OPTION_X11_SH_PSF:
     267        case MAG_OPTION_X12_SH_PSF:
     268        case MAG_OPTION_X22_SH_PSF:
     269        case MAG_OPTION_E1_SH_PSF:
     270        case MAG_OPTION_E2_SH_PSF:
     271        case MAG_OPTION_F_AP_R5:
     272        case MAG_OPTION_F_ERR_AP_R5:
     273        case MAG_OPTION_F_STDEV_AP_R5:
     274        case MAG_OPTION_F_FILL_AP_R5:
     275        case MAG_OPTION_F_AP_R6:
     276        case MAG_OPTION_F_ERR_AP_R6:
     277        case MAG_OPTION_F_STDEV_AP_R6:
     278        case MAG_OPTION_F_FILL_AP_R6:
     279
    252280        case MAG_OPTION_NONE:
    253281          break;
     
    475503      break;
    476504
    477     case MEAS_REF_COLOR:
     505    case MEAS_REF_COLOR_BLUE:
    478506      value.Flt = average[0].refColorBlue;
     507      break;
     508    case MEAS_REF_COLOR_RED:
     509      value.Flt = average[0].refColorRed;
    479510      break;
    480511
     
    529560# endif
    530561      break;
    531     case MEAS_XFIX: /* OK */
    532       value.Flt = measure[0].Xfix;
    533       break;
    534     case MEAS_YFIX: /* OK */
    535       value.Flt = measure[0].Yfix;
    536       break;
    537     case MEAS_XCCD_ERR: /* OK */
    538       value.Flt = FromShortPixels(measure[0].dXccd);
    539       break;
    540     case MEAS_YCCD_ERR: /* OK */
    541       value.Flt = FromShortPixels(measure[0].dYccd);
    542       break;
    543     case MEAS_POS_SYS_ERR: /* OK */
    544       value.Flt = FromShortPixels(measure[0].dRsys);
    545       break;
     562    case MEAS_XFIX: { value.Flt = measure[0].Xfix; break; }
     563    case MEAS_YFIX: { value.Flt = measure[0].Yfix; break; }
     564    case MEAS_XCCD_ERR: { value.Flt = FromShortPixels(measure[0].dXccd); break; }
     565    case MEAS_YCCD_ERR: { value.Flt = FromShortPixels(measure[0].dYccd); break; }
     566    case MEAS_POS_SYS_ERR: { value.Flt = FromShortPixels(measure[0].dRsys); }
     567
     568    case MEAS_XOFF_KH:  { value.Flt = measure[0].XoffKH;  break; }
     569    case MEAS_YOFF_KH:  { value.Flt = measure[0].YoffKH;  break; }
     570    case MEAS_XOFF_DCR: { value.Flt = measure[0].XoffDCR; break; }
     571    case MEAS_YOFF_DCR: { value.Flt = measure[0].YoffDCR; break; }
     572    case MEAS_ROFF_GAL: { value.Flt = measure[0].RoffGAL; break; }
     573    case MEAS_DOFF_GAL: { value.Flt = measure[0].DoffGAL; break; }
    546574
    547575    case MEAS_XFIELD: /* offset relative to exposure center in ra,dec space */
     
    582610    case MEAS_XMOSAIC: /* offset relative to exposure center in camera coords */
    583611      if (!haveMosaicMeas) {
    584         if (REMOTE_CLIENT) {
    585           mosaic = MatchMosaicMetadata (measure[0].imageID);
    586         } else {
    587           // fprintf (stderr, "non-parallel Xmos broken\n");
    588           // abort();
    589           // mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
    590           mosaic = MatchMosaicMetadata (measure[0].imageID);
    591         }
     612        mosaic = MatchMosaicMetadata (measure[0].imageID);
    592613        if (mosaic == NULL) break;
    593614        double Rm = measure[0].R;
     
    599620    case MEAS_YMOSAIC: /* OK */
    600621      if (!haveMosaicMeas) {
    601         if (REMOTE_CLIENT) {
    602           mosaic = MatchMosaicMetadata (measure[0].imageID);
    603         } else {
    604           // fprintf (stderr, "non-parallel Xmos broken\n");
    605           // abort();
    606           // mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
    607           mosaic = MatchMosaicMetadata (measure[0].imageID);
    608         }
     622        mosaic = MatchMosaicMetadata (measure[0].imageID);
    609623        if (mosaic == NULL) break;
    610624        double Rm = measure[0].R;
     
    647661    case MEAS_PSF_NPIX: /* OK */
    648662      value.Int = measure[0].psfNpix;
    649       break;
    650     case MEAS_CR_NSIGMA: /* OK */
    651       value.Flt = measure[0].crNsigma;
    652663      break;
    653664    case MEAS_EXT_NSIGMA: /* OK */
     
    684695      break;
    685696
    686     case MEAS_MCAL_OFFSET: /* OK */
    687       value.Flt = measure[0].Mcal;
    688       break;
     697    case MEAS_MCAL_OFFSET: { value.Flt = measure[0].Mcal; break; }
    689698
    690699    case MEAS_FLAT: /* OK */
     
    721730      }
    722731      break;
     732
     733    case MEAS_E_BV:             { value.Flt = starpar->Ebv;      break; }
     734    case MEAS_E_BV_ERR:         { value.Flt = starpar->dEbv;     break; }
     735    case MEAS_DISTANCE_MOD:     { value.Flt = starpar->DistMag;  break; }
     736    case MEAS_DISTANCE_MOD_ERR: { value.Flt = starpar->dDistMag; break; }
     737    case MEAS_M_R:              { value.Flt = starpar->M_r;      break; }
     738    case MEAS_M_R_ERR:          { value.Flt = starpar->dM_r;     break; }
     739    case MEAS_FEH:              { value.Flt = starpar->FeH;      break; }
     740    case MEAS_FEH_ERR:          { value.Flt = starpar->dFeH;     break; }
     741    case MEAS_URA_GALMODEL:     { value.Flt = starpar->uRA;      break; }
     742    case MEAS_UDEC_GALMODEL:    { value.Flt = starpar->uDEC;     break; }
     743    case MEAS_RA_GALMODEL:      { value.Flt = starpar->R;        break; }
     744    case MEAS_DEC_GALMODEL:     { value.Flt = starpar->D;        break; }
    723745
    724746    // case MEAS_FLUX_PSF: /* OK */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dbFields.c

    r37035 r37822  
    2828}
    2929
     30int dbFieldNeedMeasure (dbField *fields, int Nfields) {
     31  int i;
     32  for (i = 0; i < Nfields; i++) {
     33    if (fields[i].photcode == NULL) continue; // non-measure fields do not have a photcode
     34    if (fields[i].photcode[0].type == PHOT_REF) return TRUE;
     35    if (fields[i].photcode[0].type == PHOT_DEP) return TRUE;
     36  }
     37  return FALSE;
     38}
     39
     40int dbFieldNeedLensing (dbField *fields, int Nfields) {
     41  int i;
     42  for (i = 0; i < Nfields; i++) {
     43    if (fields[i].ID == MEAS_X11_SM_OBJ) return TRUE;
     44    if (fields[i].ID == MEAS_X12_SM_OBJ) return TRUE;
     45    if (fields[i].ID == MEAS_X22_SM_OBJ) return TRUE;
     46    if (fields[i].ID == MEAS_E1_SM_OBJ)  return TRUE;
     47    if (fields[i].ID == MEAS_E2_SM_OBJ)  return TRUE;
     48    if (fields[i].ID == MEAS_X11_SH_OBJ) return TRUE;
     49    if (fields[i].ID == MEAS_X12_SH_OBJ) return TRUE;
     50    if (fields[i].ID == MEAS_X22_SH_OBJ) return TRUE;
     51    if (fields[i].ID == MEAS_E1_SH_OBJ)  return TRUE;
     52    if (fields[i].ID == MEAS_E2_SH_OBJ)  return TRUE;
     53    if (fields[i].ID == MEAS_X11_SM_PSF) return TRUE;
     54    if (fields[i].ID == MEAS_X12_SM_PSF) return TRUE;
     55    if (fields[i].ID == MEAS_X22_SM_PSF) return TRUE;
     56    if (fields[i].ID == MEAS_E1_SM_PSF)  return TRUE;
     57    if (fields[i].ID == MEAS_E2_SM_PSF)  return TRUE;
     58    if (fields[i].ID == MEAS_X11_SH_PSF) return TRUE;
     59    if (fields[i].ID == MEAS_X12_SH_PSF) return TRUE;
     60    if (fields[i].ID == MEAS_X22_SH_PSF) return TRUE;
     61    if (fields[i].ID == MEAS_E1_SH_PSF)  return TRUE;
     62    if (fields[i].ID == MEAS_E2_SH_PSF)  return TRUE;
     63  }
     64  return FALSE;
     65}
     66
     67int dbFieldNeedLensobj (dbField *fields, int Nfields) {
     68  int i;
     69  for (i = 0; i < Nfields; i++) {
     70    if (fields[i].magOption == MAG_OPTION_NONE) continue; // non-measure fields do not have a photcode
     71
     72    if (fields[i].magOption == MAG_OPTION_X11_SM_OBJ) return TRUE;
     73    if (fields[i].magOption == MAG_OPTION_X12_SM_OBJ) return TRUE;
     74    if (fields[i].magOption == MAG_OPTION_X22_SM_OBJ) return TRUE;
     75    if (fields[i].magOption == MAG_OPTION_E1_SM_OBJ)  return TRUE;
     76    if (fields[i].magOption == MAG_OPTION_E2_SM_OBJ)  return TRUE;
     77    if (fields[i].magOption == MAG_OPTION_X11_SH_OBJ) return TRUE;
     78    if (fields[i].magOption == MAG_OPTION_X12_SH_OBJ) return TRUE;
     79    if (fields[i].magOption == MAG_OPTION_X22_SH_OBJ) return TRUE;
     80    if (fields[i].magOption == MAG_OPTION_E1_SH_OBJ)  return TRUE;
     81    if (fields[i].magOption == MAG_OPTION_E2_SH_OBJ)  return TRUE;
     82    if (fields[i].magOption == MAG_OPTION_X11_SM_PSF) return TRUE;
     83    if (fields[i].magOption == MAG_OPTION_X12_SM_PSF) return TRUE;
     84    if (fields[i].magOption == MAG_OPTION_X22_SM_PSF) return TRUE;
     85    if (fields[i].magOption == MAG_OPTION_E1_SM_PSF)  return TRUE;
     86    if (fields[i].magOption == MAG_OPTION_E2_SM_PSF)  return TRUE;
     87    if (fields[i].magOption == MAG_OPTION_X11_SH_PSF) return TRUE;
     88    if (fields[i].magOption == MAG_OPTION_X12_SH_PSF) return TRUE;
     89    if (fields[i].magOption == MAG_OPTION_X22_SH_PSF) return TRUE;
     90    if (fields[i].magOption == MAG_OPTION_E1_SH_PSF)  return TRUE;
     91    if (fields[i].magOption == MAG_OPTION_E2_SH_PSF)  return TRUE;
     92  }
     93  return FALSE;
     94}
     95
     96int dbFieldNeedStarpar (dbField *fields, int Nfields, int isAverage) {
     97  int i;
     98  for (i = 0; i < Nfields; i++) {
     99    if (isAverage) {
     100      if (fields[i].ID == AVE_E_BV)             return TRUE;
     101      if (fields[i].ID == AVE_E_BV_ERR)         return TRUE;
     102      if (fields[i].ID == AVE_DISTANCE_MOD)     return TRUE;
     103      if (fields[i].ID == AVE_DISTANCE_MOD_ERR) return TRUE;
     104      if (fields[i].ID == AVE_M_R)              return TRUE;
     105      if (fields[i].ID == AVE_M_R_ERR)          return TRUE;
     106      if (fields[i].ID == AVE_FEH)              return TRUE;
     107      if (fields[i].ID == AVE_FEH_ERR)          return TRUE;
     108      if (fields[i].ID == AVE_URA_GALMODEL)     return TRUE;
     109      if (fields[i].ID == AVE_UDEC_GALMODEL)    return TRUE;
     110      if (fields[i].ID == AVE_RA_GALMODEL)      return TRUE;
     111      if (fields[i].ID == AVE_DEC_GALMODEL)     return TRUE;
     112    } else {
     113      if (fields[i].ID == MEAS_E_BV)             return TRUE;
     114      if (fields[i].ID == MEAS_E_BV_ERR)         return TRUE;
     115      if (fields[i].ID == MEAS_DISTANCE_MOD)     return TRUE;
     116      if (fields[i].ID == MEAS_DISTANCE_MOD_ERR) return TRUE;
     117      if (fields[i].ID == MEAS_M_R)              return TRUE;
     118      if (fields[i].ID == MEAS_M_R_ERR)          return TRUE;
     119      if (fields[i].ID == MEAS_FEH)              return TRUE;
     120      if (fields[i].ID == MEAS_FEH_ERR)          return TRUE;
     121      if (fields[i].ID == MEAS_URA_GALMODEL)     return TRUE;
     122      if (fields[i].ID == MEAS_UDEC_GALMODEL)    return TRUE;
     123      if (fields[i].ID == MEAS_RA_GALMODEL)      return TRUE;
     124      if (fields[i].ID == MEAS_DEC_GALMODEL)     return TRUE;
     125    }
     126  }
     127  return FALSE;
     128}
     129
    30130dvoMagSourceType GetMagSource (char *string) {
    31131
    32   if (!strcasecmp (string, "chip")) return (MAG_SRC_CHP);
    33   if (!strcasecmp (string, "warp")) return (MAG_SRC_WRP);
     132  if (!strcasecmp (string, "chip"))  return (MAG_SRC_CHP);
     133  if (!strcasecmp (string, "warp"))  return (MAG_SRC_WRP);
    34134  if (!strcasecmp (string, "stack")) return (MAG_SRC_STK);
    35135
     
    66166dvoMagOptionType GetMagOption (char *string) {
    67167
    68   if (!strcasecmp (string, "mag"))          return (MAG_OPTION_MAG);
    69   if (!strcasecmp (string, "err"))          return (MAG_OPTION_ERR);
    70   if (!strcasecmp (string, "magerr"))       return (MAG_OPTION_ERR);
    71   if (!strcasecmp (string, "flux"))         return (MAG_OPTION_FLUX);
    72   if (!strcasecmp (string, "fluxerr"))      return (MAG_OPTION_FLUX_ERR);
    73   if (!strcasecmp (string, "stdev"))        return (MAG_OPTION_STDEV);
    74   if (!strcasecmp (string, "chisq"))        return (MAG_OPTION_CHISQ);
    75   if (!strcasecmp (string, "min"))          return (MAG_OPTION_MIN);
    76   if (!strcasecmp (string, "max"))          return (MAG_OPTION_MAX);
    77   if (!strcasecmp (string, "ncode"))        return (MAG_OPTION_NCODE);
    78   if (!strcasecmp (string, "nphot"))        return (MAG_OPTION_NPHOT);
    79   if (!strcasecmp (string, "uc_dist"))      return (MAG_OPTION_UC_DIST);
    80   if (!strcasecmp (string, "stack_det_id")) return (MAG_OPTION_STACK_DET_ID);
    81   if (!strcasecmp (string, "flags"))        return (MAG_OPTION_FLAGS);
     168  if (!strcasecmp (string, "mag"))           return MAG_OPTION_MAG;
     169  if (!strcasecmp (string, "err"))           return MAG_OPTION_ERR;
     170  if (!strcasecmp (string, "magerr"))        return MAG_OPTION_ERR;
     171  if (!strcasecmp (string, "flux"))          return MAG_OPTION_FLUX;
     172  if (!strcasecmp (string, "fluxerr"))       return MAG_OPTION_FLUX_ERR;
     173  if (!strcasecmp (string, "stdev"))         return MAG_OPTION_STDEV;
     174  if (!strcasecmp (string, "chisq"))         return MAG_OPTION_CHISQ;
     175  if (!strcasecmp (string, "min"))           return MAG_OPTION_MIN;
     176  if (!strcasecmp (string, "max"))           return MAG_OPTION_MAX;
     177  if (!strcasecmp (string, "ncode"))         return MAG_OPTION_NCODE;
     178  if (!strcasecmp (string, "nphot"))         return MAG_OPTION_NPHOT;
     179  if (!strcasecmp (string, "uc_dist"))       return MAG_OPTION_UC_DIST;
     180  if (!strcasecmp (string, "flags"))         return MAG_OPTION_FLAGS;
     181  if (!strcasecmp (string, "X11_SM_OBJ"))    return MAG_OPTION_X11_SM_OBJ;
     182  if (!strcasecmp (string, "X12_SM_OBJ"))    return MAG_OPTION_X12_SM_OBJ;
     183  if (!strcasecmp (string, "X22_SM_OBJ"))    return MAG_OPTION_X22_SM_OBJ;
     184  if (!strcasecmp (string, "E1_SM_OBJ"))     return MAG_OPTION_E1_SM_OBJ;
     185  if (!strcasecmp (string, "E2_SM_OBJ"))     return MAG_OPTION_E2_SM_OBJ;
     186  if (!strcasecmp (string, "X11_SH_OBJ"))    return MAG_OPTION_X11_SH_OBJ;
     187  if (!strcasecmp (string, "X12_SH_OBJ"))    return MAG_OPTION_X12_SH_OBJ;
     188  if (!strcasecmp (string, "X22_SH_OBJ"))    return MAG_OPTION_X22_SH_OBJ;
     189  if (!strcasecmp (string, "E1_SH_OBJ"))     return MAG_OPTION_E1_SH_OBJ;
     190  if (!strcasecmp (string, "E2_SH_OBJ"))     return MAG_OPTION_E2_SH_OBJ;
     191  if (!strcasecmp (string, "X11_SM_PSF"))    return MAG_OPTION_X11_SM_PSF;
     192  if (!strcasecmp (string, "X12_SM_PSF"))    return MAG_OPTION_X12_SM_PSF;
     193  if (!strcasecmp (string, "X22_SM_PSF"))    return MAG_OPTION_X22_SM_PSF;
     194  if (!strcasecmp (string, "E1_SM_PSF"))     return MAG_OPTION_E1_SM_PSF;
     195  if (!strcasecmp (string, "E2_SM_PSF"))     return MAG_OPTION_E2_SM_PSF;
     196  if (!strcasecmp (string, "X11_SH_PSF"))    return MAG_OPTION_X11_SH_PSF;
     197  if (!strcasecmp (string, "X12_SH_PSF"))    return MAG_OPTION_X12_SH_PSF;
     198  if (!strcasecmp (string, "X22_SH_PSF"))    return MAG_OPTION_X22_SH_PSF;
     199  if (!strcasecmp (string, "E1_SH_PSF"))     return MAG_OPTION_E1_SH_PSF;
     200  if (!strcasecmp (string, "E2_SH_PSF"))     return MAG_OPTION_E2_SH_PSF;
     201  // if (!strcasecmp (string, "F_AP_R5"))       return MAG_OPTION_F_AP_R5;
     202  // if (!strcasecmp (string, "F_ERR_AP_R5"))   return MAG_OPTION_F_ERR_AP_R5;
     203  // if (!strcasecmp (string, "F_STDEV_AP_R5")) return MAG_OPTION_F_STDEV_AP_R5;
     204  // if (!strcasecmp (string, "F_FILL_AP_R5"))  return MAG_OPTION_F_FILL_AP_R5;
     205  // if (!strcasecmp (string, "F_AP_R6"))       return MAG_OPTION_F_AP_R6;
     206  // if (!strcasecmp (string, "F_ERR_AP_R6"))   return MAG_OPTION_F_ERR_AP_R6;
     207  // if (!strcasecmp (string, "F_STDEV_AP_R6")) return MAG_OPTION_F_STDEV_AP_R6;
     208  // if (!strcasecmp (string, "F_FILL_AP_R6"))  return MAG_OPTION_F_FILL_AP_R6;
    82209
    83210  return MAG_OPTION_NONE;
    84211}
    85 
    86 # if (0)
    87 int GetMagMode (char *string) {
    88 
    89   // these all imply PSF mags:
    90   if (!strcasecmp (string, "inst"))        return (MAG_INST);
    91   if (!strcasecmp (string, "cat"))         return (MAG_CAT);
    92   if (!strcasecmp (string, "sys"))         return (MAG_SYS);
    93   if (!strcasecmp (string, "rel"))         return (MAG_REL);
    94   if (!strcasecmp (string, "cal"))         return (MAG_CAL);
    95   if (!strcasecmp (string, "ave"))         return (MAG_AVE);
    96   if (!strcasecmp (string, "ref"))         return (MAG_REF);
    97   if (!strcasecmp (string, "err"))         return (MAG_ERR);
    98   if (!strcasecmp (string, "aveerr"))      return (MAG_AVE_ERR);
    99 
    100   // these are explicit PSF mags:
    101   if (!strcasecmp (string, "psf_inst"))    return (MAG_INST);
    102   if (!strcasecmp (string, "psf_cat"))     return (MAG_CAT);
    103   if (!strcasecmp (string, "psf_sys"))     return (MAG_SYS);
    104   if (!strcasecmp (string, "psf_rel"))     return (MAG_REL);
    105   if (!strcasecmp (string, "psf_cal"))     return (MAG_CAL);
    106   if (!strcasecmp (string, "psf_ave"))     return (MAG_AVE);
    107   if (!strcasecmp (string, "psf_ref"))     return (MAG_REF);
    108   if (!strcasecmp (string, "psf_err"))     return (MAG_ERR);
    109   if (!strcasecmp (string, "psf_aveerr"))  return (MAG_AVE_ERR);
    110 
    111   // these are aper mags:
    112   if (!strcasecmp (string, "ap"))          return (MAG_APER);
    113   if (!strcasecmp (string, "aper"))        return (MAG_APER);
    114   if (!strcasecmp (string, "aperinst"))    return (MAG_APER_INST);
    115   if (!strcasecmp (string, "aper_inst"))   return (MAG_APER_INST);
    116   if (!strcasecmp (string, "aper_cat"))    return (MAG_APER_CAT);
    117   if (!strcasecmp (string, "aper_sys"))    return (MAG_APER_SYS);
    118   if (!strcasecmp (string, "aper_rel"))    return (MAG_APER_REL);
    119   if (!strcasecmp (string, "aper_cal"))    return (MAG_APER_CAL);
    120   if (!strcasecmp (string, "aper_ave"))    return (MAG_APER_AVE);
    121   if (!strcasecmp (string, "aper_ref"))    return (MAG_APER_REF);
    122   if (!strcasecmp (string, "aper_err"))    return (MAG_APER_ERR);
    123 
    124   // these are kron mags:
    125   if (!strcasecmp (string, "kron"))        return (MAG_KRON);
    126   if (!strcasecmp (string, "kron_inst"))   return (MAG_KRON_INST);
    127   if (!strcasecmp (string, "kron_cat"))    return (MAG_KRON_CAT);
    128   if (!strcasecmp (string, "kron_sys"))    return (MAG_KRON_SYS);
    129   if (!strcasecmp (string, "kron_rel"))    return (MAG_KRON_REL);
    130   if (!strcasecmp (string, "kron_cal"))    return (MAG_KRON_CAL);
    131   if (!strcasecmp (string, "kron_ave"))    return (MAG_KRON_AVE);
    132   if (!strcasecmp (string, "kron_ref"))    return (MAG_KRON_REF);
    133   if (!strcasecmp (string, "kron_err"))    return (MAG_KRON_ERR);
    134   if (!strcasecmp (string, "kroninst"))    return (MAG_KRON_INST);
    135   if (!strcasecmp (string, "kronerr"))     return (MAG_KRON_ERR);
    136 
    137   // other fields:
    138   if (!strcasecmp (string, "photflags"))   return (MAG_PHOT_FLAGS);
    139   if (!strcasecmp (string, "flags"))       return (MAG_PHOT_FLAGS);
    140   if (!strcasecmp (string, "chisq"))       return (MAG_CHISQ);
    141   if (!strcasecmp (string, "ncode"))       return (MAG_NCODE);
    142   if (!strcasecmp (string, "nphot"))       return (MAG_NPHOT);
    143   if (!strcasecmp (string, "stdev"))       return (MAG_STDEV);
    144   if (!strcasecmp (string, "min"))         return (MAG_MIN);
    145   if (!strcasecmp (string, "max"))         return (MAG_MAX);
    146   if (!strcasecmp (string, "ucdist"))      return (MAG_UC_DIST);
    147   if (!strcasecmp (string, "stackDetectID")) return (MAG_STACK_DET_ID);
    148   if (!strcasecmp (string, "fluxpsf"))     return (MAG_FLUX_PSF);
    149   if (!strcasecmp (string, "fluxpsferr"))  return (MAG_FLUX_PSF_ERR);
    150   if (!strcasecmp (string, "fluxkron"))    return (MAG_FLUX_KRON);
    151   if (!strcasecmp (string, "fluxkronerr")) return (MAG_FLUX_KRON_ERR);
    152   return (MAG_NONE);
    153 }
    154 # endif
    155212
    156213// field may be of the form mag:psf:inst:wrp.  except for the first subword,
     
    287344    fprintf (stderr, "ERROR: unknown mag/photocode argument %s\n", word);
    288345    free (word);
     346    return FALSE;
    289347  }
    290348
     
    296354
    297355  switch (field->magOption) {
    298     case MAG_OPTION_STACK_DET_ID:
    299356    case MAG_OPTION_NCODE:
    300357    case MAG_OPTION_NPHOT:
     
    417474  if (!strcasecmp (fieldName, "XFIX"))           ESCAPE (MEAS_XFIX,           OPIHI_FLT);
    418475  if (!strcasecmp (fieldName, "YFIX"))           ESCAPE (MEAS_YFIX,           OPIHI_FLT);
     476  if (!strcasecmp (fieldName, "XOFF_KH"))        ESCAPE (MEAS_XOFF_KH,        OPIHI_FLT);
     477  if (!strcasecmp (fieldName, "YOFF_KH"))        ESCAPE (MEAS_YOFF_KH,        OPIHI_FLT);
     478  if (!strcasecmp (fieldName, "XOFF_DCR"))       ESCAPE (MEAS_XOFF_DCR,       OPIHI_FLT);
     479  if (!strcasecmp (fieldName, "YOFF_DCR"))       ESCAPE (MEAS_YOFF_DCR,       OPIHI_FLT);
     480  if (!strcasecmp (fieldName, "ROFF_GAL"))       ESCAPE (MEAS_ROFF_GAL,       OPIHI_FLT);
     481  if (!strcasecmp (fieldName, "DOFF_GAL"))       ESCAPE (MEAS_DOFF_GAL,       OPIHI_FLT);
    419482  if (!strcasecmp (fieldName, "POS_SYS_ERR"))    ESCAPE (MEAS_POS_SYS_ERR,    OPIHI_FLT);
    420483  if (!strcasecmp (fieldName, "XFIELD"))         ESCAPE (MEAS_XFIELD,         OPIHI_FLT);
     
    444507  if (!strcasecmp (fieldName, "FLAT"))           ESCAPE (MEAS_FLAT,           OPIHI_FLT);
    445508  if (!strcasecmp (fieldName, "CENTER_OFFSET"))  ESCAPE (MEAS_CENTER_OFFSET,  OPIHI_FLT);
    446   // if (!strcasecmp (fieldName, "FLUX"))                ESCAPE (MEAS_FLUX_PSF,       OPIHI_FLT);
     509
     510  // individual lensing measurements are not grouped by photcode:
     511  if (!strcasecmp (fieldName, "X11_SM_OBJ"))     ESCAPE (MEAS_X11_SM_OBJ,  OPIHI_FLT);
     512  if (!strcasecmp (fieldName, "X12_SM_OBJ"))     ESCAPE (MEAS_X12_SM_OBJ,  OPIHI_FLT);
     513  if (!strcasecmp (fieldName, "X22_SM_OBJ"))     ESCAPE (MEAS_X22_SM_OBJ,  OPIHI_FLT);
     514  if (!strcasecmp (fieldName, "E1_SM_OBJ"))      ESCAPE (MEAS_E1_SM_OBJ,  OPIHI_FLT);
     515  if (!strcasecmp (fieldName, "E2_SM_OBJ"))      ESCAPE (MEAS_E2_SM_OBJ,  OPIHI_FLT);
     516  if (!strcasecmp (fieldName, "X11_SH_OBJ"))     ESCAPE (MEAS_X11_SH_OBJ,  OPIHI_FLT);
     517  if (!strcasecmp (fieldName, "X12_SH_OBJ"))     ESCAPE (MEAS_X12_SH_OBJ,  OPIHI_FLT);
     518  if (!strcasecmp (fieldName, "X22_SH_OBJ"))     ESCAPE (MEAS_X22_SH_OBJ,  OPIHI_FLT);
     519  if (!strcasecmp (fieldName, "E1_SH_OBJ"))      ESCAPE (MEAS_E1_SH_OBJ,  OPIHI_FLT);
     520  if (!strcasecmp (fieldName, "E2_SH_OBJ"))      ESCAPE (MEAS_E2_SH_OBJ,  OPIHI_FLT);
     521  if (!strcasecmp (fieldName, "X11_SM_PSF"))     ESCAPE (MEAS_X11_SM_PSF,  OPIHI_FLT);
     522  if (!strcasecmp (fieldName, "X12_SM_PSF"))     ESCAPE (MEAS_X12_SM_PSF,  OPIHI_FLT);
     523  if (!strcasecmp (fieldName, "X22_SM_PSF"))     ESCAPE (MEAS_X22_SM_PSF,  OPIHI_FLT);
     524  if (!strcasecmp (fieldName, "E1_SM_PSF"))      ESCAPE (MEAS_E1_SM_PSF,  OPIHI_FLT);
     525  if (!strcasecmp (fieldName, "E2_SM_PSF"))      ESCAPE (MEAS_E2_SM_PSF,  OPIHI_FLT);
     526  if (!strcasecmp (fieldName, "X11_SH_PSF"))     ESCAPE (MEAS_X11_SH_PSF,  OPIHI_FLT);
     527  if (!strcasecmp (fieldName, "X12_SH_PSF"))     ESCAPE (MEAS_X12_SH_PSF,  OPIHI_FLT);
     528  if (!strcasecmp (fieldName, "X22_SH_PSF"))     ESCAPE (MEAS_X22_SH_PSF,  OPIHI_FLT);
     529  if (!strcasecmp (fieldName, "E1_SH_PSF"))      ESCAPE (MEAS_E1_SH_PSF,  OPIHI_FLT);
     530  if (!strcasecmp (fieldName, "E2_SH_PSF"))      ESCAPE (MEAS_E2_SH_PSF,  OPIHI_FLT);
     531
     532  if (!strcasecmp (fieldName, "E_BV"))             ESCAPE (MEAS_E_BV          ,   OPIHI_FLT);
     533  if (!strcasecmp (fieldName, "E_BV_ERR"))         ESCAPE (MEAS_E_BV_ERR      ,   OPIHI_FLT);
     534  if (!strcasecmp (fieldName, "DISTANCE_MOD"))     ESCAPE (MEAS_DISTANCE_MOD  ,   OPIHI_FLT);
     535  if (!strcasecmp (fieldName, "DISTANCE_MOD_ERR")) ESCAPE (MEAS_DISTANCE_MOD_ERR, OPIHI_FLT);
     536  if (!strcasecmp (fieldName, "D_M"))              ESCAPE (MEAS_DISTANCE_MOD  ,   OPIHI_FLT);
     537  if (!strcasecmp (fieldName, "D_M_ERR"))          ESCAPE (MEAS_DISTANCE_MOD_ERR, OPIHI_FLT);
     538  if (!strcasecmp (fieldName, "M_R"))              ESCAPE (MEAS_M_R           ,   OPIHI_FLT);
     539  if (!strcasecmp (fieldName, "M_R_ERR"))          ESCAPE (MEAS_M_R_ERR       ,   OPIHI_FLT);
     540  if (!strcasecmp (fieldName, "FEH"))              ESCAPE (MEAS_FEH           ,   OPIHI_FLT);
     541  if (!strcasecmp (fieldName, "FEH_ERR"))          ESCAPE (MEAS_FEH_ERR       ,   OPIHI_FLT);
     542  if (!strcasecmp (fieldName, "URA_GALMODEL"))     ESCAPE (MEAS_URA_GALMODEL  ,   OPIHI_FLT);
     543  if (!strcasecmp (fieldName, "UDEC_GALMODEL"))    ESCAPE (MEAS_UDEC_GALMODEL ,   OPIHI_FLT);
     544  if (!strcasecmp (fieldName, "RA_GALMODEL"))      ESCAPE (MEAS_RA_GALMODEL   ,   OPIHI_FLT);
     545  if (!strcasecmp (fieldName, "DEC_GALMODEL"))     ESCAPE (MEAS_DEC_GALMODEL  ,   OPIHI_FLT);
     546  if (!strcasecmp (fieldName, "URA_GAL"))          ESCAPE (MEAS_URA_GALMODEL  ,   OPIHI_FLT);
     547  if (!strcasecmp (fieldName, "UDEC_GAL"))         ESCAPE (MEAS_UDEC_GALMODEL ,   OPIHI_FLT);
     548  if (!strcasecmp (fieldName, "RA_GAL"))           ESCAPE (MEAS_RA_GALMODEL   ,   OPIHI_FLT);
     549  if (!strcasecmp (fieldName, "DEC_GAL"))          ESCAPE (MEAS_DEC_GALMODEL  ,   OPIHI_FLT);
     550
     551  // if (!strcasecmp (fieldName, "FLUX"))           ESCAPE (MEAS_FLUX_PSF,       OPIHI_FLT);
    447552  // if (!strcasecmp (fieldName, "FLUX_ERR"))       ESCAPE (MEAS_FLUX_PSF_ERR,   OPIHI_FLT);
    448553  // if (!strcasecmp (fieldName, "FLUX_PSF"))       ESCAPE (MEAS_FLUX_PSF,       OPIHI_FLT);
     
    450555  // if (!strcasecmp (fieldName, "FLUX_KRON"))      ESCAPE (MEAS_FLUX_KRON,      OPIHI_FLT);
    451556  // if (!strcasecmp (fieldName, "FLUX_KRON_ERR"))  ESCAPE (MEAS_FLUX_KRON_ERR,  OPIHI_FLT);
    452   if (!strcasecmp (fieldName, "REF_COLOR"))      ESCAPE (MEAS_REF_COLOR,      OPIHI_FLT);
     557  if (!strcasecmp (fieldName, "REF_COLOR_BLUE"))    ESCAPE (MEAS_REF_COLOR_BLUE, OPIHI_FLT);
     558  if (!strcasecmp (fieldName, "REF_COLOR_RED"))     ESCAPE (MEAS_REF_COLOR_RED,  OPIHI_FLT);
    453559
    454560  // for words that don't parse, try a photcode
     
    525631  if (!strcasecmp (fieldName, "EXTID_HI"))    ESCAPE (AVE_EXTID_HI,    OPIHI_INT);
    526632  if (!strcasecmp (fieldName, "EXTID_LO"))    ESCAPE (AVE_EXTID_LO,    OPIHI_INT);
    527   if (!strcasecmp (fieldName, "REF_COLOR"))   ESCAPE (AVE_REF_COLOR,   OPIHI_FLT);
     633  if (!strcasecmp (fieldName, "REF_COLOR_BLUE")) ESCAPE (AVE_REF_COLOR_BLUE, OPIHI_FLT);
     634  if (!strcasecmp (fieldName, "REF_COLOR_RED"))  ESCAPE (AVE_REF_COLOR_RED,  OPIHI_FLT);
     635
     636  if (!strcasecmp (fieldName, "E_BV"))             ESCAPE (AVE_E_BV          ,   OPIHI_FLT);
     637  if (!strcasecmp (fieldName, "E_BV_ERR"))         ESCAPE (AVE_E_BV_ERR      ,   OPIHI_FLT);
     638  if (!strcasecmp (fieldName, "DISTANCE_MOD"))     ESCAPE (AVE_DISTANCE_MOD  ,   OPIHI_FLT);
     639  if (!strcasecmp (fieldName, "DISTANCE_MOD_ERR")) ESCAPE (AVE_DISTANCE_MOD_ERR, OPIHI_FLT);
     640  if (!strcasecmp (fieldName, "M_R"))              ESCAPE (AVE_M_R           ,   OPIHI_FLT);
     641  if (!strcasecmp (fieldName, "M_R_ERR"))          ESCAPE (AVE_M_R_ERR       ,   OPIHI_FLT);
     642  if (!strcasecmp (fieldName, "FEH"))              ESCAPE (AVE_FEH           ,   OPIHI_FLT);
     643  if (!strcasecmp (fieldName, "FEH_ERR"))          ESCAPE (AVE_FEH_ERR       ,   OPIHI_FLT);
     644  if (!strcasecmp (fieldName, "URA_GALMODEL"))     ESCAPE (AVE_URA_GALMODEL  ,   OPIHI_FLT);
     645  if (!strcasecmp (fieldName, "UDEC_GALMODEL"))    ESCAPE (AVE_UDEC_GALMODEL ,   OPIHI_FLT);
     646  if (!strcasecmp (fieldName, "RA_GALMODEL"))      ESCAPE (AVE_RA_GALMODEL   ,   OPIHI_FLT);
     647  if (!strcasecmp (fieldName, "DEC_GALMODEL"))     ESCAPE (AVE_DEC_GALMODEL  ,   OPIHI_FLT);
     648
    528649
    529650  // check for code:mode in photcode name
     
    655776  if (!strcasecmp (fieldName, "NLINK_PHOTOM")) ESCAPE (IMAGE_NLINK_PHOTOM, OPIHI_INT);
    656777  if (!strcasecmp (fieldName, "NLINK_ASTROM")) ESCAPE (IMAGE_NLINK_ASTROM, OPIHI_INT);
    657   if (!strcasecmp (fieldName, "REF_COLOR"))    ESCAPE (IMAGE_REF_COLOR,    OPIHI_FLT);
     778  if (!strcasecmp (fieldName, "REF_COLOR_BLUE")) ESCAPE (IMAGE_REF_COLOR_BLUE, OPIHI_FLT);
     779  if (!strcasecmp (fieldName, "REF_COLOR_RED"))  ESCAPE (IMAGE_REF_COLOR_RED,  OPIHI_FLT);
    658780
    659781  // for words that don't parse, try a photcode
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_catalog.c

    r37331 r37822  
    5858  if (!strcasecmp (catformat, "PS1_V5"))          return (DVO_FORMAT_PS1_V5);
    5959  if (!strcasecmp (catformat, "PS1_REF"))         return (DVO_FORMAT_PS1_REF);
     60  if (!strcasecmp (catformat, "PS1_SIM"))         return (DVO_FORMAT_PS1_SIM);
    6061  return (DVO_FORMAT_UNDEF);
    6162}
     
    129130  average->Nlensing        = 0;
    130131  average->Nlensobj        = 0;
     132  average->Nstarpar        = 0;
    131133  average->Nextend         = 0;
    132134
     
    135137  average->lensingOffset   = -1;
    136138  average->lensobjOffset   = -1;
     139  average->starparOffset   = -1;
    137140  average->extendOffset    = -1;
    138   average->paramsOffset    = -1;
    139141
    140142  average->refColorBlue    = NAN;
    141143  average->refColorRed     = NAN;
     144
     145  average->tessID          = 0;
     146  average->skycellID       = 0;
     147  average->projectionID    = 0;
     148
     149  average->dummy           = 0;
    142150
    143151  average->flags           = 0;
     
    173181  secfilt->sMkron      = NAN;
    174182
     183  secfilt->psfQfMax     = NAN;
     184  secfilt->psfQfPerfMax = NAN;
     185
    175186  secfilt->Mstdev      = NAN;
    176187  secfilt->Mmin        = NAN;
     
    197208  secfilt->dFapStk     = NAN;
    198209
    199   secfilt->stackDetectID = 0;
     210  secfilt->Nstack      = 0;
     211  secfilt->NstackDet   = 0;
     212
     213  secfilt->stackPrmryOff = -1;
     214  secfilt->stackBestOff  = -1;
    200215
    201216  secfilt->MpsfWrp     = NAN;
     
    217232  secfilt->NusedKronWrp = 0;
    218233  secfilt->NusedApWrp   = 0;
     234
     235  secfilt->Nwarp        = 0;
     236  secfilt->NwarpGood    = 0;
    219237
    220238  secfilt->ubercalDist = 1000;
     
    278296 measure->psfNdof   = 0;
    279297 measure->psfNpix   = 0;
    280  measure->crNsigma  = NAN;
    281298 measure->extNsigma = NAN;
    282299
     
    301318 measure->dbFlags   = 0;
    302319 measure->photFlags = 0;
     320 measure->photFlags2= 0;
    303321}
    304322
     
    422440
    423441// init all data, or just catalog data
     442void dvo_starpar_init (StarPar *starpar) {
     443  starpar->R        = NAN;
     444  starpar->D        = NAN;
     445  starpar->galLat   = NAN;
     446  starpar->galLon   = NAN;
     447  starpar->Ebv      = NAN;
     448  starpar->dEbv     = NAN;
     449  starpar->DistMag  = NAN;
     450  starpar->dDistMag = NAN;
     451  starpar->M_r      = NAN;
     452  starpar->dM_r     = NAN;
     453  starpar->FeH      = NAN;
     454  starpar->dFeH     = NAN;
     455  starpar->uRA      = NAN;
     456  starpar->uDEC     = NAN;
     457  starpar->averef   = -1;
     458  starpar->objID    = -1;
     459  starpar->catID    = -1;
     460}
     461
     462// init all data, or just catalog data
    424463void dvo_catalog_init (Catalog *catalog, int complete) {
    425464
     
    447486  catalog[0].lensobj = NULL;
    448487
     488  catalog[0].starpar = NULL;
     489
    449490  catalog[0].averageT = NULL;
    450491  catalog[0].measureT = NULL;
     
    462503  catalog[0].Nlensobj = 0;
    463504
     505  catalog[0].Nstarpar = 0;
     506
    464507  catalog[0].Naves_disk = 0;
    465508  catalog[0].Nmeas_disk = 0;
     
    470513  catalog[0].Nlensobj_disk = 0;
    471514
     515  catalog[0].Nstarpar_disk = 0;
     516
    472517  catalog[0].Naves_off  = 0;
    473518  catalog[0].Nmeas_off  = 0;
     
    477522  catalog[0].Nlensing_off  = 0;
    478523  catalog[0].Nlensobj_off  = 0;
     524
     525  catalog[0].Nstarpar_off  = 0;
    479526
    480527  /* pointers to SPLIT data files */
     
    484531  catalog[0].lensing_catalog = NULL;
    485532  catalog[0].lensobj_catalog = NULL;
     533  catalog[0].starpar_catalog = NULL;
    486534
    487535  /* pointers for data manipulation */
     
    525573
    526574  if (catalog[0].f == (FILE *) NULL) return (2);
    527   fflush (catalog[0].f);
     575
     576  if (fflush (catalog[0].f)) {
     577    fprintf (stderr, "failed to flush file\n");
     578    return FALSE;
     579  }
     580
    528581  // fprintf (stderr, "unlocking: %s\n", catalog[0].filename);
    529582
     
    537590
    538591  // closes f but does not set back to NULL
    539   fclearlockfile (catalog[0].filename, catalog[0].f, catalog[0].lockmode, &dbstate);
     592  if (!fclearlockfile (catalog[0].filename, catalog[0].f, catalog[0].lockmode, &dbstate)) {
     593    fprintf (stderr, "failed to unlock or close file\n");
     594    return (0);
     595  }
    540596
    541597  if (catalog[0].catmode == DVO_MODE_SPLIT) {
    542     if (catalog[0].measure_catalog) dvo_catalog_unlock (catalog[0].measure_catalog);
    543     if (catalog[0].missing_catalog) dvo_catalog_unlock (catalog[0].missing_catalog);
    544     if (catalog[0].secfilt_catalog) dvo_catalog_unlock (catalog[0].secfilt_catalog);
    545     if (catalog[0].lensing_catalog) dvo_catalog_unlock (catalog[0].lensing_catalog);
    546     if (catalog[0].lensobj_catalog) dvo_catalog_unlock (catalog[0].lensobj_catalog);
     598    if (catalog[0].measure_catalog) { if (!dvo_catalog_unlock (catalog[0].measure_catalog)) { fprintf (stderr, "failed to unlock measures\n"); return (0); }}
     599    if (catalog[0].missing_catalog) { if (!dvo_catalog_unlock (catalog[0].missing_catalog)) { fprintf (stderr, "failed to unlock missing\n"); return (0); }}
     600    if (catalog[0].secfilt_catalog) { if (!dvo_catalog_unlock (catalog[0].secfilt_catalog)) { fprintf (stderr, "failed to unlock secfilt\n"); return (0); }}
     601    if (catalog[0].lensing_catalog) { if (!dvo_catalog_unlock (catalog[0].lensing_catalog)) { fprintf (stderr, "failed to unlock lensing\n"); return (0); }}
     602    if (catalog[0].lensobj_catalog) { if (!dvo_catalog_unlock (catalog[0].lensobj_catalog)) { fprintf (stderr, "failed to unlock lensobj\n"); return (0); }}
     603    if (catalog[0].starpar_catalog) { if (!dvo_catalog_unlock (catalog[0].starpar_catalog)) { fprintf (stderr, "failed to unlock starpar\n"); return (0); }}
    547604  }
    548605  return (1);
     
    582639  }
    583640 
     641  // NOTE: this only check if we can write a backup; it does not actually write the backup
    584642  if (!check_file_access (catalog[0].filename, BACKUP, READWRITE, VERBOSE)) {
    585643    fprintf (stderr, "no permission to access %s\n", catalog[0].filename);
     
    820878      free (catalog[0].lensobj_catalog);
    821879    }
     880    if (catalog[0].starpar_catalog) {
     881      free (catalog[0].starpar_catalog[0].filename);
     882      dvo_catalog_free (catalog[0].starpar_catalog);
     883      free (catalog[0].starpar_catalog);
     884    }
    822885  }
    823886  dvo_catalog_free_data (catalog);
     
    859922    catalog[0].lensobj = NULL;
    860923  }
    861   // if (catalog[0].X_t)      free (catalog[0].X_t);
    862   // if (catalog[0].Y_t)      free (catalog[0].Y_t);
    863   if (catalog[0].nOwn_t)      free (catalog[0].nOwn_t);
    864   if (catalog[0].found_t)     free (catalog[0].found_t);
    865   // if (catalog[0].image_t)  free (catalog[0].image_t);
    866   // if (catalog[0].mosaic_t) free (catalog[0].mosaic_t);
    867   if (catalog[0].foundWarp_t) free (catalog[0].foundWarp_t);
     924  if (catalog[0].starpar) {
     925    free (catalog[0].starpar);
     926    catalog[0].Nstarpar = 0;
     927    catalog[0].starpar = NULL;
     928  }
     929  if (catalog[0].nOwn_t)      { free (catalog[0].nOwn_t); catalog[0].nOwn_t = NULL; }
     930  if (catalog[0].found_t)     { free (catalog[0].found_t); catalog[0].found_t = NULL; }
     931  if (catalog[0].foundWarp_t) { free (catalog[0].foundWarp_t); catalog[0].foundWarp_t = NULL; }
    868932}
    869933
     
    9741038      }
    9751039    }
     1040    if (catalog[0].starpar_catalog != NULL) {
     1041      if (catalog[0].Nstarpar_disk == 0) {
     1042        // need to relock (and re-open) file for close elsewhere
     1043        status = dvo_catalog_lock (catalog[0].starpar_catalog, lockmode);
     1044      } else {
     1045        if (!dvo_catalog_backup (catalog[0].starpar_catalog, FALSE)) {
     1046          return FALSE;
     1047        }
     1048      }
     1049    }
    9761050  }
    9771051  return TRUE;
     
    10251099      }
    10261100    }
     1101    if ((catalog[0].starpar_catalog != NULL) && (catalog[0].Nstarpar_disk > 0)) {
     1102      if (!dvo_catalog_unlink_backup (catalog[0].starpar_catalog, FALSE)) {
     1103        return FALSE;
     1104      }
     1105    }
    10271106  }
    10281107  return TRUE;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_catalog_create.c

    r37035 r37822  
    9595    free (file);
    9696
     97    /* define starpar catalog file */
     98    ALLOCATE (catalog[0].starpar_catalog, Catalog, 1);
     99    dvo_catalog_init (catalog[0].starpar_catalog, TRUE);
     100
     101    /* create basic data for starpar catalog file */
     102    gfits_create_header (&catalog[0].starpar_catalog[0].header);
     103    ALLOCATE (catalog[0].starpar_catalog[0].filename, char, length);
     104    sprintf (catalog[0].starpar_catalog[0].filename, "%s/%s.cpz", path, root);
     105    file = filebasename (catalog[0].starpar_catalog[0].filename);
     106    gfits_modify (&catalog[0].header, "STARPAR", "%s", 1, file);
     107    free (file);
     108
    97109    free (path);
    98110    free (root);
     
    117129    }
    118130    if (dvo_catalog_lock (catalog[0].lensobj_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
     131      fprintf (stderr, "error with file lock\n");
     132      exit (2);
     133    }
     134    if (dvo_catalog_lock (catalog[0].starpar_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
    119135      fprintf (stderr, "error with file lock\n");
    120136      exit (2);
     
    146162  ALLOCATE (catalog[0].lensing, Lensing, 1);
    147163  ALLOCATE (catalog[0].lensobj, Lensobj, 1);
     164  ALLOCATE (catalog[0].starpar, StarPar, 1);
    148165
    149166  /* setup secondary filters to match photcodes:
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_catalog_mef.c

    r37035 r37822  
    44 
    55  off_t Nbytes;
    6   off_t Naverage;
    7   off_t Nmeasure;
    8   off_t Nmissing;
    9   off_t Nlensing;
    10   off_t Nlensobj;
    116  off_t Nitems, Nexpect;
    127  int Nsecfilt;
     
    1813
    1914  ftable.header = &header;
    20 
    21   /* get the components from the header */
    22   if (!gfits_scan (&catalog[0].header, "NSTARS",   OFF_T_FMT, 1,  &Naverage)) return (FALSE);
    23   if (!gfits_scan (&catalog[0].header, "NMEAS",    OFF_T_FMT, 1,  &Nmeasure)) return (FALSE);
    24   if (!gfits_scan (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  &Nmissing)) return (FALSE);
    25   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);
    2815
    2916  /* the OBJID is a counter that uniquely defines an average entry and never changes.  if
     
    3825    catalog[0].catID = 0;
    3926  }
     27
     28  // NSTARS, average, Naves_disk
     29
     30# define GET_TABLE_SIZES(HFIELD, CFIELD, DFIELD, REQUIRED)              \
     31  off_t N##CFIELD;                                                      \
     32  if (REQUIRED) {                                                       \
     33    if (!gfits_scan (&catalog[0].header, HFIELD, OFF_T_FMT, 1, &N##CFIELD)) return (FALSE); \
     34  } else {                                                              \
     35    if (!gfits_scan (&catalog[0].header, HFIELD, OFF_T_FMT, 1, &N##CFIELD)) N##CFIELD = 0; \
     36  }                                                                     \
     37  /* save the current number so we can do partial updates */            \
     38  catalog[0].DFIELD = N##CFIELD;                                        \
     39  /* default values, but we will assign these a valid value before we exit (even if empty) */ \
     40  catalog[0].CFIELD = NULL;
    4041 
    41   /* save the current number so we can do partial updates */
    42   catalog[0].Naves_disk = Naverage;
    43   catalog[0].Nmeas_disk = Nmeasure;
    44   catalog[0].Nmiss_disk = Nmissing;
    45   catalog[0].Nsecf_disk = Naverage * Nsecfilt;
    46   catalog[0].Nlensing_disk = Nlensing;
    47   catalog[0].Nlensobj_disk = Nlensobj;
     42  /* get the components and sizes from the header */
     43  GET_TABLE_SIZES ("NSTARS",   average, Naves_disk,    TRUE);
     44  GET_TABLE_SIZES ("NMEAS",    measure, Nmeas_disk,    TRUE);
     45  GET_TABLE_SIZES ("NMISS",    missing, Nmiss_disk,    FALSE);
     46  GET_TABLE_SIZES ("NLENSING", lensing, Nlensing_disk, FALSE);
     47  GET_TABLE_SIZES ("NLENSOBJ", lensobj, Nlensobj_disk, FALSE);
     48  GET_TABLE_SIZES ("NSTARPAR", starpar, Nstarpar_disk, FALSE);
    4849
    4950  /**  Nsecfilt is unusual: it does not list the number of data items in the table
    5051       instead, the number of items is Nsecfilt * Naverage.  **/
     52
     53  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d", 1, &Nsecfilt)) Nsecfilt = 0;
    5154  catalog[0].Nsecfilt = Nsecfilt;
    52 
    53   /* default values, but we will assign these a valid value before we exit (even if empty) */
    54   catalog[0].average = NULL;
    55   catalog[0].measure = NULL;
    56   catalog[0].missing = NULL;
     55  catalog[0].Nsecf_disk = Naverage * Nsecfilt;
    5756  catalog[0].secfilt = NULL;
    58   catalog[0].lensing = NULL;
    59   catalog[0].lensobj = NULL;
    60 
    61   /* validate table mode ?*/
    6257
    6358  /*** Average Table ***/
     
    259254  }
    260255
     256  /* read StarPar table header */
     257  if (!gfits_fread_header (catalog[0].f, &header)) {
     258    if (VERBOSE) fprintf (stderr, "can't read table starpar header");
     259    return (FALSE);
     260  }
     261  /* read StarPar table data */
     262  if (catalog[0].catflags & LOAD_STARPAR) {
     263    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
     264      if (VERBOSE) fprintf (stderr, "can't read table starpar data");
     265      return (FALSE);
     266    }
     267    catalog[0].starpar = FtableToStarPar (&ftable, &catalog[0].Nstarpar, &catalog[0].catformat);
     268    if (Nstarpar != catalog[0].Nstarpar_disk) {
     269      fprintf (stderr, "Warning: mismatch between Nstarpar in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nstarpar,  catalog[0].Nstarpar_disk);
     270    }
     271    catalog[0].Nstarpar = catalog[0].Nstarpar_disk;
     272    catalog[0].Nstarpar_off = 0;
     273  } else {
     274    Nbytes = gfits_data_size (&header);
     275    fseeko (catalog[0].f, Nbytes, SEEK_CUR);
     276    ALLOCATE (catalog[0].starpar, StarPar, 1);
     277    catalog[0].Nstarpar = 0;
     278    catalog[0].Nstarpar_off = catalog[0].Nstarpar_disk;
     279  }
     280
    261281  return (TRUE);
    262282}
     
    309329  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  catalog[0].Nlensing);
    310330  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  catalog[0].Nlensobj);
     331  gfits_modify (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  catalog[0].Nstarpar);
    311332  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    312333  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    403424  /* write out Lensobj table (convert to FITS table format) */
    404425  LensobjToFtable (&ftable, catalog[0].lensobj, catalog[0].Nlensobj, catalog[0].catformat);
     426  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
     427    fprintf (stderr, "can't write table header");
     428    goto failure;
     429  }
     430  if (!gfits_fwrite_table (catalog[0].f, &ftable)) {
     431    fprintf (stderr, "can't write table data");
     432    goto failure;
     433  }
     434  gfits_free_table (&ftable);
     435  gfits_free_header (&header);
     436
     437  /* free temp storage */
     438  if (primary != NULL) {
     439    free (primary);
     440    free (secfilt);
     441  }
     442  return (TRUE);
     443
     444  /* write out StarPar table (convert to FITS table format) */
     445  StarParToFtable (&ftable, catalog[0].starpar, catalog[0].Nstarpar, catalog[0].catformat);
    405446  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    406447    fprintf (stderr, "can't write table header");
     
    446487  lensobj header
    447488  lensobj table
     489  starpar header
     490  starpar table
    448491*/
    449492   
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_catalog_raw.c

    r37035 r37822  
    9292      FORMAT_CASE (PS1_V5,    PS1_V5);
    9393      FORMAT_CASE (PS1_REF,   PS1_REF);
     94      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    9495
    9596    default:
     
    287288  if (catalog[0].catformat == DVO_FORMAT_PS1_V5)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V5");
    288289  if (catalog[0].catformat == DVO_FORMAT_PS1_REF)         gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_REF");
     290  if (catalog[0].catformat == DVO_FORMAT_PS1_SIM)         gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_SIM");
    289291
    290292  /* rewind file pointers and truncate file */
     
    391393      FORMAT_CASE (PS1_V5,    PS1_V5);
    392394      FORMAT_CASE (PS1_REF,   PS1_REF);
     395      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    393396
    394397    default:
     
    443446      FORMAT_CASE (PS1_V5,    PS1_V5);
    444447      FORMAT_CASE (PS1_REF,   PS1_REF);
     448      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    445449
    446450    default:
     
    498502      FORMAT_CASE (PS1_V5,    PS1_V5);
    499503      FORMAT_CASE (PS1_REF,   PS1_REF);
     504      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    500505
    501506    default:
     
    550555      FORMAT_CASE (PS1_V5,    PS1_V5);
    551556      FORMAT_CASE (PS1_REF,   PS1_REF);
     557      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    552558
    553559    default:
     
    606612      FORMAT_CASE (PS1_V5,    PS1_V5);
    607613      FORMAT_CASE (PS1_REF,   PS1_REF);
     614      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    608615
    609616    default:
     
    658665      FORMAT_CASE (PS1_V5,    PS1_V5);
    659666      FORMAT_CASE (PS1_REF,   PS1_REF);
     667      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    660668
    661669    default:
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_catalog_split.c

    r37035 r37822  
    7575  Matrix matrix;
    7676
     77  // ohana_memcheck_func (TRUE);
     78 
     79
     80  if (0) {
     81    // XXX a TEST : is the data corrupted or the file?
     82    char name[1024];
     83    snprintf (name, 1024, "%s.phu.v2", catalog->filename);
     84    FILE *f = fopen (name, "w");
     85    fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
     86    // fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
     87    // fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n",
     88    //       catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3],
     89    //       catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
     90    fclose (f);
     91  }
     92  if (0) {
     93    // XXX a TEST : is the data corrupted or the file?
     94    char name[1024];
     95    snprintf (name, 1024, "%s.phu", catalog->filename);
     96    FILE *f = fopen (name, "w");
     97    fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
     98    // fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
     99    // fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n",
     100    //       catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3],
     101    //       catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
     102    fclose (f);
     103  }
     104# if (0)
     105  {
     106    // XXX a TEST : is the data corrupted or the file?
     107    char name[1024];
     108    snprintf (name, 1024, "%s.phu.v2", catalog->filename);
     109    FILE *f = fopen (name, "w");
     110    fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
     111    fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
     112    fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n",
     113             catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3],
     114             catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
     115    fclose (f);
     116  }
     117  {
     118    // XXX a TEST : is the data corrupted or the file?
     119    char name[1024];
     120    snprintf (name, 1024, "%s.phu.v3", catalog->filename);
     121    FILE *f = fopen (name, "w");
     122    fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
     123    fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
     124    fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n",
     125             catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3],
     126             catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
     127    fclose (f);
     128  }
     129# endif
    77130  /* rewind file pointers and truncate (file is still open) */
    78   fseeko (catalog->f, 0LL, SEEK_SET);
     131  if (fseeko (catalog->f, 0LL, SEEK_SET)) {
     132    perror ("dvo_catalog_save_subset: ");
     133    fprintf (stderr, "failed to seek to beginning\n");
     134  }
    79135
    80136  // write PHU header
     
    134190  if (!gfits_scan (&catalog[0].header, name,  "%s", 1, string)) {
    135191    free (path);
    136     // databases created prior to ~2014.07.01 did not have the LENSING or LENSOBJ paths in their headers.
     192    // databases created prior to ~2014.07.01 did not have the LENSING, LENSOBJ, STARPAR paths in their headers.
    137193    // in these cases, we do not try to lock or open the relevant file
    138194    if (!strcmp (name, "LENSING")) return (DVO_CAT_OPEN_EMPTY);
    139195    if (!strcmp (name, "LENSOBJ")) return (DVO_CAT_OPEN_EMPTY);
     196    if (!strcmp (name, "STARPAR")) return (DVO_CAT_OPEN_EMPTY);
    140197    return (DVO_CAT_OPEN_FAIL);
    141198  }
     
    182239  off_t Nlensing;
    183240  off_t Nlensobj;
     241  off_t Nstarpar;
    184242  off_t Nitems;
    185243  int status, Nsecfilt;
     
    196254
    197255  /* 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)
     256  // NSTARS, NMEAS, NMISS are required; NLENSING, NLENSOBJ, NSTARPAR are not (0 if not found)
    199257  if (!gfits_scan (&catalog[0].header, "NSTARS",   OFF_T_FMT, 1,  &Naverage)) return (FALSE);
    200258  if (!gfits_scan (&catalog[0].header, "NMEAS",    OFF_T_FMT, 1,  &Nmeasure)) return (FALSE);
     
    203261  if (!gfits_scan (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  &Nlensing)) Nlensing = 0;
    204262  if (!gfits_scan (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  &Nlensobj)) Nlensobj = 0;
     263  if (!gfits_scan (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  &Nstarpar)) Nstarpar = 0;
    205264
    206265  /* the OBJID is a counter that uniquely defines an average entry and never changes.  if
     
    223282  catalog[0].Nlensing_disk = Nlensing;
    224283  catalog[0].Nlensobj_disk = Nlensobj;
     284  catalog[0].Nstarpar_disk = Nstarpar;
    225285
    226286  /**  Nsecfilt is unusual: it does not list the number of data items in the table
     
    235295  catalog[0].lensing = NULL;
    236296  catalog[0].lensobj = NULL;
     297  catalog[0].starpar = NULL;
    237298
    238299  /*** Average Table ***/
     
    348409  /*** Secfilt Table ***/
    349410  status = dvo_catalog_open_subcat (catalog, &catalog[0].secfilt_catalog, ftable.header, "SECFILT", VERBOSE);
     411  // fprintf (stderr, "secfilt header %s : %zx\n", catalog[0].secfilt_catalog[0].filename, (size_t) catalog[0].secfilt_catalog[0].header.buffer);
    350412  if (status == DVO_CAT_OPEN_FAIL) {
    351413    return (FALSE);
     
    465527  gfits_free_header (&header);
    466528
     529  /*** StarPar Table ***/
     530  if (!(catalog[0].catflags & SKIP_STARPAR)) {
     531    // unless we specify 'skip', we still need to load the
     532    status = dvo_catalog_open_subcat (catalog, &catalog[0].starpar_catalog, ftable.header, "STARPAR", VERBOSE);
     533    if (status == DVO_CAT_OPEN_FAIL) {
     534      return (FALSE);
     535    }
     536    // the StarPar file need not exist, unless we expect data to exist
     537    if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nstarpar_disk > 0)) {
     538      return (FALSE);
     539    }
     540  }
     541  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_STARPAR)) {
     542    // only read the StarPar table if the file actually exists
     543    /* read StarPar table data */
     544    if (!gfits_fread_ftable_data (catalog[0].starpar_catalog[0].f, &ftable, FALSE)) {
     545      if (VERBOSE) fprintf (stderr, "can't read table starpar data\n");
     546      return (FALSE);
     547    }
     548    /* convert data format to internal : returns number of row read in Nstarpar */
     549    catalog[0].starpar = FtableToStarPar (&ftable, &Nstarpar, &catalog[0].catformat);
     550    if (Nstarpar != catalog[0].Nstarpar_disk) {
     551      fprintf (stderr, "Warning: mismatch between Nstarpar in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nstarpar,  catalog[0].Nstarpar_disk);
     552    }
     553    catalog[0].Nstarpar = catalog[0].Nstarpar_disk;
     554    catalog[0].Nstarpar_off = 0;
     555  } else {
     556    if (catalog[0].starpar_catalog) {
     557      gfits_free_header (&catalog[0].starpar_catalog[0].header);
     558    } else {
     559      ALLOCATE (catalog[0].starpar_catalog, Catalog, 1);
     560      dvo_catalog_init (catalog[0].starpar_catalog, TRUE);
     561    }
     562    gfits_create_header (&catalog[0].starpar_catalog[0].header);
     563    ALLOCATE (catalog[0].starpar, StarPar, 1);
     564    catalog[0].Nstarpar = 0;
     565    catalog[0].Nstarpar_off = catalog[0].Nstarpar_disk;
     566  }
     567  gfits_free_header (&header);
     568
    467569  return (TRUE);
    468570}
     
    473575
    474576  off_t Nbytes;
    475   off_t Naverage, Nexpect, Nitems, Nmeasure, Nmissing, Nlensing, Nlensobj;
     577  off_t Naverage, Nexpect, Nitems, Nmeasure, Nmissing, Nlensing, Nlensobj, Nstarpar;
    476578  Header header;
    477579  FTable ftable;
     
    497599    }
    498600    /* read Average table data : format is irrelevant here */
    499     if (!gfits_fread_ftable_range (catalog[0].f, &ftable, start, Nrows)) {
     601    if (!gfits_fread_ftable_range (catalog[0].f, FALSE, &ftable, start, Nrows)) {
    500602      if (VERBOSE) fprintf (stderr, "can't read table average data");
    501603      return (FALSE);
     
    527629    }
    528630    /* read Secfilt table data : format is irrelevant here */
    529     if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start*catalog[0].Nsecfilt, catalog[0].Naverage*catalog[0].Nsecfilt)) {
     631    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start*catalog[0].Nsecfilt, catalog[0].Naverage*catalog[0].Nsecfilt)) {
    530632      if (VERBOSE) fprintf (stderr, "can't read table measure data");
    531633      return (FALSE);
     
    563665    }
    564666    /* read Measure table data : format is irrelevant here */
    565     if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     667    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
    566668      if (VERBOSE) fprintf (stderr, "can't read table measure data");
    567669      return (FALSE);
     
    594696    }
    595697    /* read Missing table data : format is irrelevant here */
    596     if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     698    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
    597699      if (VERBOSE) fprintf (stderr, "can't read table missing data");
    598700      return (FALSE);
     
    628730    }
    629731    /* read Lensing table data : format is irrelevant here */
    630     if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     732    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
    631733      if (VERBOSE) fprintf (stderr, "can't read table lensing data");
    632734      return (FALSE);
     
    659761    }
    660762    /* read Lensobj table data : format is irrelevant here */
    661     if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     763    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
    662764      if (VERBOSE) fprintf (stderr, "can't read table lensobj data");
    663765      return (FALSE);
     
    675777  }
    676778
     779  // XXX check the open status of the catalog
     780  if (catalog[0].catflags & LOAD_STARPAR) {
     781
     782    Catalog *subcat = catalog[0].starpar_catalog;
     783
     784    /* move pointer past header -- must be already read (load_catalog) */
     785    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
     786    fseeko (subcat[0].f, Nbytes, SEEK_SET);
     787
     788    /* read StarPar table header */
     789    if (!gfits_fread_header (subcat[0].f, &header)) {
     790      if (VERBOSE) fprintf (stderr, "can't read table starpar header");
     791      return (FALSE);
     792    }
     793    /* read StarPar table data : format is irrelevant here */
     794    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
     795      if (VERBOSE) fprintf (stderr, "can't read table starpar data");
     796      return (FALSE);
     797    }
     798
     799    /* convert data format to internal : returns number of row read in Nstarpar */
     800    catalog[0].starpar = FtableToStarPar (&ftable, &Nstarpar, &catalog[0].catformat);
     801    if (Nstarpar != Nrows) {
     802      // XXX this condition denotes the eof has been reached; not an error or a warning
     803      // fprintf (stderr, "Warning: mismatch between Nstarpar in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nstarpar,  Nrows);
     804    }
     805    gfits_free_header (&header);
     806    catalog[0].Nstarpar = Nstarpar;
     807    catalog[0].Nstarpar_off = start;
     808  }
     809
    677810  return (TRUE);
    678811}
     
    686819  SecFilt *primary, *secfilt;
    687820  int Nsecfilt;
    688   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new;
     821  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new, Nstarpar_disk_new;
    689822  off_t first, start, Nrows;
    690823
     
    719852  Nlensing_disk_new = MAX (catalog[0].Nlensing_disk, catalog[0].Nlensing + catalog[0].Nlensing_off);
    720853  Nlensobj_disk_new = MAX (catalog[0].Nlensobj_disk, catalog[0].Nlensobj + catalog[0].Nlensobj_off);
     854  Nstarpar_disk_new = MAX (catalog[0].Nstarpar_disk, catalog[0].Nstarpar + catalog[0].Nstarpar_off);
    721855
    722856  /* make sure header is consistent with data */
     
    727861  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
    728862  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
     863  gfits_modify (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  Nstarpar_disk_new);
    729864  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    730865  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    845980  }
    846981
    847   /*** Lensing Table ***/
    848   if ((catalog[0].catflags & LOAD_LENSING) && (catalog[0].lensing != NULL)) {
     982  /*** Lensing Table (optional, do not save if not loaded) ***/
     983  if ((catalog[0].catflags & LOAD_LENSING) && catalog[0].lensing_catalog->f && catalog[0].lensing) {
    849984
    850985    first  = 0;                    // first row in memory to write
     
    8721007  }
    8731008
    874   /*** Lensobj Table ***/
    875   if ((catalog[0].catflags & LOAD_LENSOBJ) && (catalog[0].lensobj != NULL)) {
     1009  /*** Lensobj Table (optional, do not save if not loaded) ***/
     1010  if ((catalog[0].catflags & LOAD_LENSOBJ) && catalog[0].lensobj_catalog->f && catalog[0].lensobj) {
    8761011
    8771012    first  = 0;                    // first row in memory to write
     
    8931028    if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
    8941029      fprintf (stderr, "trouble writing Lensobj table\n");
     1030      goto failure;
     1031    }
     1032    gfits_free_header (&header);
     1033    gfits_free_table (&ftable);
     1034  }
     1035
     1036  /*** StarPar Table (optional, do not save if not loaded) ***/
     1037    if ((catalog[0].catflags & LOAD_STARPAR) && catalog[0].starpar_catalog->f && catalog[0].starpar) {
     1038
     1039    first  = 0;                    // first row in memory to write
     1040    start  = catalog[0].Nstarpar_off; // first disk row to write
     1041    Nrows  = catalog[0].Nstarpar - first;
     1042
     1043    assert (Nrows >= 0);
     1044    assert (first >= 0);
     1045    assert (first <= catalog[0].Nstarpar);
     1046    assert (catalog[0].Nstarpar_disk >= catalog[0].Nstarpar_off);
     1047
     1048    // convert to external table format (note that the block above does not damage or free catalog.average)
     1049    if (!StarParToFtable (&ftable, &catalog[0].starpar[first], Nrows, catalog[0].catformat)) {
     1050      fprintf (stderr, "trouble converting format\n");
     1051      goto failure;
     1052    }
     1053
     1054    // write out StarPar table
     1055    if (!dvo_catalog_save_subcat (catalog[0].starpar_catalog, &ftable, start, Nrows, catalog[0].Nstarpar_disk, Nstarpar_disk_new)) {
     1056      fprintf (stderr, "trouble writing StarPar table\n");
    8951057      goto failure;
    8961058    }
     
    9251087  SecFilt *primary, *secfilt;
    9261088  int Nsecfilt;
    927   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new;
     1089  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new, Nstarpar_disk_new;
    9281090  off_t first, start, Nrows;
    9291091
     
    9561118  if (catalog[0].Nlensobj_off > 0) {
    9571119    fprintf (stderr, "ERROR: only partial catalog (Lensobj) was loaded\n");
     1120    goto failure;
     1121  }
     1122  if (catalog[0].Nstarpar_off > 0) {
     1123    fprintf (stderr, "ERROR: only partial catalog (StarPar) was loaded\n");
    9581124    goto failure;
    9591125  }
     
    9841150  Nlensing_disk_new = catalog[0].Nlensing;
    9851151  Nlensobj_disk_new = catalog[0].Nlensobj;
     1152  Nstarpar_disk_new = catalog[0].Nstarpar;
    9861153
    9871154  /* make sure header is consistent with data */
     
    9921159  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
    9931160  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
     1161  gfits_modify (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  Nstarpar_disk_new);
    9941162  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    9951163  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    11581326    if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
    11591327      fprintf (stderr, "trouble writing Lensobj table\n");
     1328      goto failure;
     1329    }
     1330    gfits_free_header (&header);
     1331    gfits_free_table (&ftable);
     1332  }
     1333
     1334  /*** StarPar Table ***/
     1335  if ((catalog[0].catflags & LOAD_STARPAR) && (catalog[0].starpar != NULL)) {
     1336
     1337    first  = 0;                    // first row in memory to write
     1338    start  = catalog[0].Nstarpar_off; // first disk row to write
     1339    Nrows  = catalog[0].Nstarpar - first;
     1340
     1341    assert (Nrows >= 0);
     1342    assert (first >= 0);
     1343    assert (first <= catalog[0].Nstarpar);
     1344    assert (catalog[0].Nstarpar_disk >= catalog[0].Nstarpar_off);
     1345
     1346    // convert to external table format
     1347    if (!StarParToFtable (&ftable, &catalog[0].starpar[first], Nrows, catalog[0].catformat)) {
     1348      fprintf (stderr, "trouble converting format\n");
     1349      goto failure;
     1350    }
     1351
     1352    // write out StarPar table
     1353    if (!dvo_catalog_save_subcat (catalog[0].starpar_catalog, &ftable, start, Nrows, catalog[0].Nstarpar_disk, Nstarpar_disk_new)) {
     1354      fprintf (stderr, "trouble writing StarPar table\n");
    11601355      goto failure;
    11611356    }
     
    11891384  SecFilt *primary, *secfilt;
    11901385  int Nsecfilt;
    1191   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new;
     1386  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new, Nstarpar_disk_new;
    11921387  off_t first, start, Nrows;
    11931388
     
    12211416  Nlensing_disk_new = MAX (catalog[0].Nlensing_disk, catalog[0].Nlensing + catalog[0].Nlensing_off);
    12221417  Nlensobj_disk_new = MAX (catalog[0].Nlensobj_disk, catalog[0].Nlensobj + catalog[0].Nlensobj_off);
     1418  Nstarpar_disk_new = MAX (catalog[0].Nstarpar_disk, catalog[0].Nstarpar + catalog[0].Nstarpar_off);
    12231419
    12241420  /* make sure header is consistent with data */
     
    12291425  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
    12301426  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
     1427  gfits_modify (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  Nstarpar_disk_new);
    12311428  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    12321429  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    13991596    if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
    14001597      fprintf (stderr, "trouble writing Lensobj table\n");
     1598      goto failure;
     1599    }
     1600    gfits_free_header (&header);
     1601    gfits_free_table (&ftable);
     1602  }
     1603
     1604  /*** StarPar Table ***/
     1605  if (catalog[0].starpar != NULL) {
     1606
     1607    first  = catalog[0].Nstarpar_disk - catalog[0].Nstarpar_off;  // first row in memory to write
     1608    start  = catalog[0].Nstarpar_disk; // first disk row to write
     1609    Nrows  = catalog[0].Nstarpar - first;
     1610
     1611    assert (Nrows >= 0);
     1612    assert (first >= 0);
     1613    assert (first <= catalog[0].Nstarpar);
     1614    assert (catalog[0].Nstarpar_disk >= catalog[0].Nstarpar_off);
     1615
     1616    // convert to external table format
     1617    // XXX does catalog.starpar have averef correctly set up?
     1618    if (!StarParToFtable (&ftable, &catalog[0].starpar[first], Nrows, catalog[0].catformat)) {
     1619      fprintf (stderr, "trouble converting format\n");
     1620      goto failure;
     1621    }
     1622
     1623    // write out StarPar table
     1624    if (!dvo_catalog_save_subcat (catalog[0].starpar_catalog, &ftable, start, Nrows, catalog[0].Nstarpar_disk, Nstarpar_disk_new)) {
     1625      fprintf (stderr, "trouble writing StarPar table\n");
    14011626      goto failure;
    14021627    }
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert.c

    r37035 r37822  
    4343  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5",          PS1_V5);
    4444  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF);
     45  CONVERT_FORMAT ("DVO_AVERAGE_PS1_SIM",         PS1_SIM);
    4546# undef CONVERT_FORMAT
    4647
     
    7778    free (tmpAverage);
    7879    *format = DVO_FORMAT_PS1_V4;
     80    return (average);
     81  }
     82
     83  // block to convert old tables (PS1_V5 versions made during development)
     84  if (!strcmp (extname, "DVO_AVERAGE_PS1_V5") && (ftable[0].header[0].Naxis[0] == 184)) {
     85    Average_PS1_V5alt *tmpAverage;
     86    tmpAverage = gfits_table_get_Average_PS1_V5alt (ftable, Naverage, NULL);
     87    if (!tmpAverage) {
     88      fprintf (stderr, "ERROR: failed to read averages\n");
     89      exit (2);
     90    }
     91    average = Average_PS1_V5alt_ToInternal (tmpAverage, *Naverage);
     92    free (tmpAverage);
     93    *format = DVO_FORMAT_PS1_V5;
    7994    return (average);
    8095  }
     
    115130  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5",          PS1_V5,          PS1_V5);
    116131  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF,         PS1_REF);
     132  CONVERT_FORMAT ("DVO_AVERAGE_PS1_SIM",         PS1_SIM,         PS1_SIM);
    117133# undef CONVERT_FORMAT
    118134
     
    151167      FORMAT_CASE (PS1_V5,          PS1_V5);
    152168      FORMAT_CASE (PS1_REF,         PS1_REF);
     169      FORMAT_CASE (PS1_SIM,         PS1_SIM);
    153170# undef FORMAT_CASE
    154171
     
    226243  CONVERT_FORMAT ("DVO_MEASURE_PS1_V5",          PS1_V5,          PS1_V5,          TRUE);
    227244  CONVERT_FORMAT ("DVO_MEASURE_PS1_REF",         PS1_REF,         PS1_REF,         FALSE);
     245  CONVERT_FORMAT ("DVO_MEASURE_PS1_SIM",         PS1_SIM,         PS1_SIM,         TRUE);
    228246# undef CONVERT_FORMAT
    229247
     
    240258    case DVO_FORMAT_##FORMAT: { \
    241259      Measure_##TYPE *tmpMeasure; \
    242       myAssert (ABS_COORDS || average, "conversion to internal needs average table"); \
     260      myAssert (ABS_COORDS || average, "conversion from internal needs average table"); \
    243261      tmpMeasure = MeasureInternalTo_##TYPE (average, measure, Nmeasure); \
    244262      gfits_table_set_Measure_##TYPE (ftable, tmpMeasure, Nmeasure); \
     
    264282      FORMAT_CASE (PS1_V5,          PS1_V5,          TRUE);
    265283      FORMAT_CASE (PS1_REF,         PS1_REF,         FALSE);
     284      FORMAT_CASE (PS1_SIM,         PS1_SIM,         TRUE);
    266285# undef FORMAT_CASE
    267286
     
    285304    return (FALSE);
    286305  }
     306
     307  // block to convert old tables (PS1_V5 versions made during development)
     308  if (!strcmp (extname, "DVO_SECFILT_PS1_V5") && (ftable[0].header[0].Naxis[0] == 160)) {
     309    SecFilt_PS1_V5alt *tmpSecFilt;
     310    tmpSecFilt = gfits_table_get_SecFilt_PS1_V5alt (ftable, Nsecfilt, NULL);
     311    if (!tmpSecFilt) {
     312      fprintf (stderr, "ERROR: failed to read secfilts\n");
     313      exit (2);
     314    }
     315    secfilt = SecFilt_PS1_V5alt_ToInternal (tmpSecFilt, *Nsecfilt);
     316    free (tmpSecFilt);
     317    *format = DVO_FORMAT_PS1_V5;
     318    return (secfilt);
     319  }
     320
    287321
    288322# define CONVERT_FORMAT(NAME, FORMAT, TYPE) \
     
    321355  CONVERT_FORMAT ("DVO_SECFILT_PS1_V5",          PS1_V5,          PS1_V5);
    322356  CONVERT_FORMAT ("DVO_SECFILT_PS1_REF",         PS1_REF,         PS1_REF);
     357  CONVERT_FORMAT ("DVO_SECFILT_PS1_SIM",         PS1_SIM,         PS1_SIM);
    323358# undef CONVERT_FORMAT
    324359
     
    357392      FORMAT_CASE (PS1_V5,          PS1_V5);
    358393      FORMAT_CASE (PS1_REF,         PS1_REF);
     394      FORMAT_CASE (PS1_SIM,         PS1_SIM);
    359395# undef FORMAT_CASE
    360396
     
    378414    return (FALSE);
    379415  }
     416
     417  if (!strcmp (extname, "DVO_LENSING_PS1_V5") && (ftable[0].header[0].Naxis[0] == 128)) {
     418    Lensing_PS1_V5_ALT *tmpLensing;                                             
     419    tmpLensing = gfits_table_get_Lensing_PS1_V5_ALT (ftable, Nlensing, NULL);
     420    if (!tmpLensing) {                                                 
     421      fprintf (stderr, "ERROR: failed to read lensings\n");             
     422      exit (2);                                                         
     423    }                                                                   
     424    lensing = Lensing_PS1_V5_ALT_ToInternal (tmpLensing, *Nlensing);
     425    free (tmpLensing);                                                 
     426    *format = DVO_FORMAT_PS1_V5;                                       
     427    return (lensing); }
    380428
    381429# define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     
    392440    return (lensing); }
    393441
     442# define SKIPPING_FORMAT(NAME, FORMAT, TYPE)            \
     443  if (!strcmp (extname, NAME)) {                                        \
     444    fprintf (stderr, "ERROR: format %s not defined for lensing, skipping\n", NAME); \
     445    *Nlensing = 0; \
     446    return NULL; \
     447  }
     448
    394449  if (!strcmp (extname, "DVO_LENSING")) {
    395450    lensing = gfits_table_get_Lensing (ftable, Nlensing, NULL);
     
    402457  }
    403458
    404 // CONVERT_FORMAT ("DVO_LENSING_PS1_REF",         PS1_REF,         PS1_REF);
    405 // CONVERT_FORMAT ("DVO_LENSING_ELIXIR",          ELIXIR,          Elixir);
    406 // CONVERT_FORMAT ("DVO_LENSING_LONEOS",          LONEOS,          Loneos);
    407 // CONVERT_FORMAT ("DVO_LENSING_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
    408 // CONVERT_FORMAT ("DVO_LENSING_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
    409 // CONVERT_FORMAT ("DVO_LENSING_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
    410 // CONVERT_FORMAT ("DVO_LENSING_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
    411 // CONVERT_FORMAT ("DVO_LENSING_PS1_V1",          PS1_V1,          PS1_V1);
    412 // CONVERT_FORMAT ("DVO_LENSING_PS1_V2",          PS1_V2,          PS1_V2);
    413 // CONVERT_FORMAT ("DVO_LENSING_PS1_V3",          PS1_V3,          PS1_V3);
    414 // CONVERT_FORMAT ("DVO_LENSING_PS1_V4",          PS1_V4,          PS1_V4);
    415   CONVERT_FORMAT ("DVO_LENSING_PS1_V5",          PS1_V5,          PS1_V5);
     459  SKIPPING_FORMAT ("DVO_LENSING_PS1_REF",         PS1_REF,         PS1_REF);
     460  SKIPPING_FORMAT ("DVO_LENSING_ELIXIR",          ELIXIR,          Elixir);
     461  SKIPPING_FORMAT ("DVO_LENSING_LONEOS",          LONEOS,          Loneos);
     462  SKIPPING_FORMAT ("DVO_LENSING_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
     463  SKIPPING_FORMAT ("DVO_LENSING_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
     464  SKIPPING_FORMAT ("DVO_LENSING_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
     465  SKIPPING_FORMAT ("DVO_LENSING_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     466  SKIPPING_FORMAT ("DVO_LENSING_PS1_V1",          PS1_V1,          PS1_V1);
     467  SKIPPING_FORMAT ("DVO_LENSING_PS1_V2",          PS1_V2,          PS1_V2);
     468  SKIPPING_FORMAT ("DVO_LENSING_PS1_V3",          PS1_V3,          PS1_V3);
     469  SKIPPING_FORMAT ("DVO_LENSING_PS1_V4",          PS1_V4,          PS1_V4);
     470  CONVERT_FORMAT  ("DVO_LENSING_PS1_V5",          PS1_V5,          PS1_V5);
    416471# undef CONVERT_FORMAT
    417472
     
    549604    default:
    550605      fprintf (stderr, "table format unknown (lensobj)\n");
     606      return (FALSE);
     607  }
     608  return (TRUE);
     609}
     610
     611/*** StarPar / FTable conversion functions ***/
     612
     613StarPar *FtableToStarPar (FTable *ftable, off_t *Nstarpar, char *format) {
     614
     615  StarPar *starpar;
     616  char extname[80];
     617
     618  /* convert to the internal format */
     619  if (!gfits_scan (ftable[0].header, "EXTNAME", "%s", 1, extname)) {
     620    fprintf (stderr, "EXTNAME missing for starpar table\n");
     621    return (FALSE);
     622  }
     623
     624# define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     625  if (!strcmp (extname, NAME)) {                                        \
     626    StarPar_##TYPE *tmpStarPar;                                         \
     627    tmpStarPar = gfits_table_get_StarPar_##TYPE (ftable, Nstarpar, NULL); \
     628    if (!tmpStarPar) {                                                  \
     629      fprintf (stderr, "ERROR: failed to read starpar\n");              \
     630      exit (2);                                                         \
     631    }                                                                   \
     632    starpar = StarPar_##TYPE##_ToInternal (tmpStarPar, *Nstarpar); \
     633    free (tmpStarPar);                                                  \
     634    *format = DVO_FORMAT_##FORMAT;                                      \
     635    return (starpar); }
     636
     637  if (!strcmp (extname, "DVO_STARPAR")) {
     638    starpar = gfits_table_get_StarPar (ftable, Nstarpar, NULL);
     639    if (!starpar) {
     640      fprintf (stderr, "ERROR: failed to read starpar\n");
     641      exit (2);
     642    }
     643    *format = DVO_FORMAT_INTERNAL;
     644    return (starpar);
     645  }
     646
     647   CONVERT_FORMAT ("DVO_STARPAR_PS1_SIM",         PS1_SIM,         PS1_SIM);
     648// CONVERT_FORMAT ("DVO_STARPAR_PS1_REF",         PS1_REF,         PS1_REF);
     649// CONVERT_FORMAT ("DVO_STARPAR_ELIXIR",          ELIXIR,          Elixir);
     650// CONVERT_FORMAT ("DVO_STARPAR_LONEOS",          LONEOS,          Loneos);
     651// CONVERT_FORMAT ("DVO_STARPAR_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
     652// CONVERT_FORMAT ("DVO_STARPAR_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
     653// CONVERT_FORMAT ("DVO_STARPAR_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
     654// CONVERT_FORMAT ("DVO_STARPAR_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     655// CONVERT_FORMAT ("DVO_STARPAR_PS1_V1",          PS1_V1,          PS1_V1);
     656// CONVERT_FORMAT ("DVO_STARPAR_PS1_V2",          PS1_V2,          PS1_V2);
     657// CONVERT_FORMAT ("DVO_STARPAR_PS1_V3",          PS1_V3,          PS1_V3);
     658// CONVERT_FORMAT ("DVO_STARPAR_PS1_V4",          PS1_V4,          PS1_V4);
     659  CONVERT_FORMAT ("DVO_STARPAR_PS1_V5",          PS1_V5,          PS1_V5);
     660//  CONVERT_FORMAT ("DVO_STELLAR_PARAMS_PS1_V5",          PS1_V5,          PS1_V5);
     661  // XXX fix in libauto: STELLAR_PARAMS to STARPAR
     662# undef CONVERT_FORMAT
     663
     664  fprintf (stderr, "table format unknown: %s\n", extname);
     665
     666  *Nstarpar = 0;
     667  return (NULL);
     668}
     669
     670// StarParToFtable needs the Average since old formats stored starpar.dR,dD only
     671int StarParToFtable (FTable *ftable, StarPar *starpar, off_t Nstarpar, char format) {
     672
     673# define FORMAT_CASE(FORMAT, TYPE)              \
     674    case DVO_FORMAT_##FORMAT: { \
     675      StarPar_##TYPE *tmpStarPar; \
     676      tmpStarPar = StarParInternalTo_##TYPE (starpar, Nstarpar); \
     677      gfits_table_set_StarPar_##TYPE (ftable, tmpStarPar, Nstarpar); \
     678      free (tmpStarPar); \
     679      break; }
     680
     681  /* convert from the internal format */
     682  switch (format) {
     683    case DVO_FORMAT_INTERNAL: {
     684      gfits_table_set_StarPar (ftable, starpar, Nstarpar);
     685      break; }
     686
     687      FORMAT_CASE (PS1_SIM,         PS1_SIM);
     688//    FORMAT_CASE (PS1_REF,         PS1_REF);
     689//    FORMAT_CASE (ELIXIR,          Elixir);
     690//    FORMAT_CASE (LONEOS,          Loneos);
     691//    FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
     692//    FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
     693//    FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
     694//    FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     695//    FORMAT_CASE (PS1_V1,          PS1_V1);
     696//    FORMAT_CASE (PS1_V2,          PS1_V2);
     697//    FORMAT_CASE (PS1_V3,          PS1_V3);
     698//    FORMAT_CASE (PS1_V4,          PS1_V4);
     699      FORMAT_CASE (PS1_V5,          PS1_V5);
     700# undef FORMAT_CASE
     701
     702    default:
     703      fprintf (stderr, "table format unknown (starpar)\n");
    551704      return (FALSE);
    552705  }
     
    607760    return (TRUE); }
    608761
    609   if (!strcmp (extname, "DVO_IMAGE")) {
    610     Image *image;
    611     image = gfits_table_get_Image (ftable, &Nimage, NULL);
    612     if (!image) {
    613       fprintf (stderr, "ERROR: failed to read images\n");
    614       exit (2);
    615     }
    616     *format = DVO_FORMAT_INTERNAL;
    617     return (TRUE);
    618   }
    619 
    620762  CONVERT_FORMAT ("DVO_IMAGE_ELIXIR",          ELIXIR,          Elixir);
    621763  CONVERT_FORMAT ("DVO_IMAGE_LONEOS",          LONEOS,          Loneos);
     
    630772  CONVERT_FORMAT ("DVO_IMAGE_PS1_V5",          PS1_V5,          PS1_V5);
    631773  CONVERT_FORMAT ("DVO_IMAGE_PS1_REF",         PS1_REF,         PS1_REF);
     774  CONVERT_FORMAT ("DVO_IMAGE_PS1_SIM",         PS1_SIM,         PS1_SIM);
    632775
    633776# undef CONVERT_FORMAT
     
    654797  /* convert from the internal format */
    655798  switch (format) {
    656     case DVO_FORMAT_INTERNAL: {
    657       gfits_convert_Image ((Image *) ftable[0].buffer, sizeof(Image), Nimage);
    658       break; }
    659 
    660799      FORMAT_CASE (ELIXIR,          Elixir);
    661800      FORMAT_CASE (LONEOS,          Loneos);
     
    670809      FORMAT_CASE (PS1_V5,          PS1_V5);
    671810      FORMAT_CASE (PS1_REF,         PS1_REF);
     811      FORMAT_CASE (PS1_SIM,         PS1_SIM);
    672812
    673813# undef FORMAT_CASE
     
    708848  /* convert from the internal format */
    709849  switch (format) {
    710     case DVO_FORMAT_INTERNAL: {
    711       for (i = 0; i < Nrow; i++) {
    712         gfits_convert_Image ((Image *) vtable[0].buffer[i], sizeof(Image), 1);
    713       }
    714       return (TRUE); }
    715 
    716850      FORMAT_CASE (ELIXIR,          Elixir);
    717851      FORMAT_CASE (LONEOS,          Loneos);
     
    726860      FORMAT_CASE (PS1_V5,          PS1_V5);
    727861      FORMAT_CASE (PS1_REF,         PS1_REF);
     862      FORMAT_CASE (PS1_SIM,         PS1_SIM);
    728863
    729864# undef FORMAT_CASE
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c

    r37035 r37822  
    3232    out[i].psfQF      = in[i].psfQF;
    3333    out[i].psfChisq   = in[i].psfChisq;
    34     out[i].crNsigma   = in[i].crNsigma;
    3534    out[i].extNsigma  = in[i].extNsigma;
    3635    out[i].FWx        = in[i].FWx;
     
    8079    out[i].psfQF      = in[i].psfQF;
    8180    out[i].psfChisq   = in[i].psfChisq;
    82     out[i].crNsigma   = in[i].crNsigma;
    8381    out[i].extNsigma  = in[i].extNsigma;
    8482    out[i].FWx        = in[i].FWx;
     
    221219
    222220  for (i = 0; i < Nvalues; i++) {
    223     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     221    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     222    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     223    out[i].coords.mosaic   = NULL;
     224    out[i].coords.offsetMap = NULL;
    224225
    225226    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    289290
    290291  for (i = 0; i < Nvalues; i++) {
    291     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     292    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     293    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    292294
    293295    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c

    r37035 r37822  
    3434    out[i].psfQF      = in[i].psfQF;
    3535    out[i].psfChisq   = in[i].psfChisq;
    36     out[i].crNsigma   = in[i].crNsigma;
    3736    out[i].extNsigma  = in[i].extNsigma;
    3837    out[i].FWx        = in[i].FWx;
     
    8079    out[i].psfQF      = in[i].psfQF;
    8180    out[i].psfChisq   = in[i].psfChisq;
    82     out[i].crNsigma   = in[i].crNsigma;
    8381    out[i].extNsigma  = in[i].extNsigma;
    8482    out[i].FWx        = in[i].FWx;
     
    216214
    217215  for (i = 0; i < Nvalues; i++) {
    218     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     216    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     217    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     218    out[i].coords.mosaic   = NULL;
     219    out[i].coords.offsetMap = NULL;
    219220
    220221    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    281282
    282283  for (i = 0; i < Nvalues; i++) {
    283     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     284    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     285    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    284286
    285287    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c

    r37055 r37822  
    1818
    1919  for (i = 0; i < Nvalues; i++) {
    20     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     20    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     21    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     22    out[i].coords.mosaic   = NULL;
     23    out[i].coords.offsetMap = NULL;
    2124
    2225    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    7881
    7982  for (i = 0; i < Nvalues; i++) {
    80     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     83    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     84    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    8185
    8286    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c

    r37035 r37822  
    145145
    146146  for (i = 0; i < Nvalues; i++) {
    147     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     147    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     148    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     149    out[i].coords.mosaic   = NULL;
     150    out[i].coords.offsetMap = NULL;
    148151
    149152    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    208211
    209212  for (i = 0; i < Nvalues; i++) {
    210     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     213    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     214    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    211215
    212216    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c

    r37035 r37822  
    4040    out[i].psfNdof    = in[i].psfNdof;
    4141    out[i].psfNpix    = in[i].psfNpix;
    42     out[i].crNsigma   = in[i].crNsigma;
    4342    out[i].extNsigma  = in[i].extNsigma;
    4443    out[i].FWx        = in[i].FWx;
     
    9594    out[i].psfNdof    = in[i].psfNdof;
    9695    out[i].psfNpix    = in[i].psfNpix;
    97     out[i].crNsigma   = in[i].crNsigma;
    9896    out[i].extNsigma  = in[i].extNsigma;
    9997    out[i].FWx        = in[i].FWx;
     
    240238
    241239  for (i = 0; i < Nvalues; i++) {
    242     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     240    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     241    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     242    out[i].coords.mosaic   = NULL;
     243    out[i].coords.offsetMap = NULL;
    243244
    244245    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    304305
    305306  for (i = 0; i < Nvalues; i++) {
    306     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     307    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     308    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    307309
    308310    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c

    r37035 r37822  
    4040    out[i].psfNdof    = in[i].psfNdof;
    4141    out[i].psfNpix    = in[i].psfNpix;
    42     out[i].crNsigma   = in[i].crNsigma;
    4342    out[i].extNsigma  = in[i].extNsigma;
    4443    out[i].FWx        = in[i].FWx;
     
    9695    out[i].psfNdof    = in[i].psfNdof;
    9796    out[i].psfNpix    = in[i].psfNpix;
    98     out[i].crNsigma   = in[i].crNsigma;
    9997    out[i].extNsigma  = in[i].extNsigma;
    10098    out[i].FWx        = in[i].FWx;
     
    251249
    252250  for (i = 0; i < Nvalues; i++) {
    253     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     251    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     252    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     253    out[i].coords.mosaic   = NULL;
     254    out[i].coords.offsetMap = NULL;
    254255
    255256    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    315316
    316317  for (i = 0; i < Nvalues; i++) {
    317     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     318    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     319    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    318320
    319321    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c

    r37035 r37822  
    4040    out[i].psfNdof    = in[i].psfNdof;
    4141    out[i].psfNpix    = in[i].psfNpix;
    42     out[i].crNsigma   = in[i].crNsigma;
    4342    out[i].extNsigma  = in[i].extNsigma;
    4443    out[i].FWx        = in[i].FWx;
     
    9695    out[i].psfNdof    = in[i].psfNdof;
    9796    out[i].psfNpix    = in[i].psfNpix;
    98     out[i].crNsigma   = in[i].crNsigma;
    9997    out[i].extNsigma  = in[i].extNsigma;
    10098    out[i].FWx        = in[i].FWx;
     
    261259
    262260  for (i = 0; i < Nvalues; i++) {
    263     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     261    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     262    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     263    out[i].coords.mosaic   = NULL;
     264    out[i].coords.offsetMap = NULL;
    264265
    265266    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    325326
    326327  for (i = 0; i < Nvalues; i++) {
    327     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     328    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     329    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    328330
    329331    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c

    r37035 r37822  
    4949    out[i].psfNdof    = in[i].psfNdof;
    5050    out[i].psfNpix    = in[i].psfNpix;
    51     out[i].crNsigma   = in[i].crNsigma;
    5251    out[i].extNsigma  = in[i].extNsigma;
    5352    out[i].FWx        = in[i].FWx;
     
    114113    out[i].psfNdof    = in[i].psfNdof;
    115114    out[i].psfNpix    = in[i].psfNpix;
    116     out[i].crNsigma   = in[i].crNsigma;
    117115    out[i].extNsigma  = in[i].extNsigma;
    118116    out[i].FWx        = in[i].FWx;
     
    251249    out[i].Mstdev        = in[i].Mstdev;     
    252250    out[i].ubercalDist   = in[i].ubercalDist;     
    253     out[i].stackDetectID = in[i].stackDetectID;     
     251    out[i].stackPrmryOff = in[i].stackPrmryOff;     
     252    out[i].stackBestOff  = in[i].stackBestOff;     
    254253 }
    255254  return (out);
     
    281280    out[i].Mstdev        = in[i].Mstdev;     
    282281    out[i].ubercalDist   = in[i].ubercalDist;     
    283     out[i].stackDetectID = in[i].stackDetectID;
     282    out[i].stackPrmryOff = in[i].stackPrmryOff;     
     283    out[i].stackBestOff  = in[i].stackBestOff;     
    284284  }
    285285  return (out);
     
    299299
    300300  for (i = 0; i < Nvalues; i++) {
    301     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     301    // this is only save because the initial 120 bytes in Coords match CoordsDisk
     302    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     303    out[i].coords.mosaic    = NULL;
     304    out[i].coords.offsetMap = NULL;
    302305
    303306    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    363366
    364367  for (i = 0; i < Nvalues; i++) {
    365     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     368    // this is only save because the initial 120 bytes in Coords match CoordsDisk
     369    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    366370
    367371    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    539543    out[i].psfNdof    = in[i].psfNdof;
    540544    out[i].psfNpix    = in[i].psfNpix;
    541     out[i].crNsigma   = in[i].crNsigma;
    542545    out[i].extNsigma  = in[i].extNsigma;
    543546    out[i].FWx        = in[i].FWx;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c

    r37331 r37822  
    5656    out[i].psfNdof    = in[i].psfNdof;
    5757    out[i].psfNpix    = in[i].psfNpix;
    58     out[i].crNsigma   = in[i].crNsigma;
    5958    out[i].extNsigma  = in[i].extNsigma;
    6059    out[i].FWx        = in[i].FWx;
     
    7372    out[i].dbFlags    = in[i].dbFlags;
    7473    out[i].photFlags  = in[i].photFlags;
     74    out[i].photFlags2 = in[i].photFlags2;
    7575  }
    7676  return (out);
     
    128128    out[i].psfNdof    = in[i].psfNdof;
    129129    out[i].psfNpix    = in[i].psfNpix;
    130     out[i].crNsigma   = in[i].crNsigma;
    131130    out[i].extNsigma  = in[i].extNsigma;
    132131    out[i].FWx        = in[i].FWx;
     
    145144    out[i].dbFlags    = in[i].dbFlags;
    146145    out[i].photFlags  = in[i].photFlags;
     146    out[i].photFlags2 = in[i].photFlags2;
    147147  }
    148148  return (out);
     
    191191    out[i].Nlensing      = in[i].Nlensing;     
    192192    out[i].Nlensobj      = in[i].Nlensobj;     
     193    out[i].Nstarpar      = in[i].Nstarpar;     
    193194    out[i].Nextend       = in[i].Nextend;     
    194195
     
    197198    out[i].lensingOffset = in[i].lensingOffset;
    198199    out[i].lensobjOffset = in[i].lensobjOffset;
     200    out[i].starparOffset = in[i].starparOffset;
    199201    out[i].extendOffset  = in[i].extendOffset;
    200     out[i].paramsOffset  = in[i].paramsOffset;
    201202
    202203    out[i].refColorBlue  = in[i].refColorBlue;
    203204    out[i].refColorRed   = in[i].refColorRed;
     205
     206    out[i].tessID        = in[i].tessID;
     207    out[i].skycellID     = in[i].skycellID;
     208    out[i].projectionID  = in[i].projectionID;
    204209
    205210    out[i].flags         = in[i].flags;   
     
    223228
    224229  for (i = 0; i < Nvalues; i++) {
    225     out[i].R             = in[i].R;     
    226     out[i].D             = in[i].D;     
    227     out[i].dR            = in[i].dR;
    228     out[i].dD            = in[i].dD;
    229     out[i].uR            = in[i].uR;
    230     out[i].uD            = in[i].uD;
    231     out[i].duR           = in[i].duR;
    232     out[i].duD           = in[i].duD;
    233     out[i].P             = in[i].P;
    234     out[i].dP            = in[i].dP;
    235 
    236     out[i].Rstk          = in[i].Rstk;     
    237     out[i].Dstk          = in[i].Dstk;     
    238     out[i].dRstk         = in[i].dRstk;
    239     out[i].dDstk         = in[i].dDstk;
    240 
    241     out[i].ChiSqAve      = in[i].ChiSqAve;     
    242     out[i].ChiSqPM       = in[i].ChiSqPM;     
    243     out[i].ChiSqPar      = in[i].ChiSqPar;     
    244     out[i].Tmean         = in[i].Tmean;     
    245     out[i].Trange        = in[i].Trange;     
    246 
    247     out[i].psfQF         = in[i].psfQF;
    248     out[i].psfQFperf     = in[i].psfQFperf;
    249     out[i].stargal       = in[i].stargal;     
    250     out[i].Npos          = in[i].Npos;     
    251 
    252     out[i].Nmeasure      = in[i].Nmeasure;     
    253     out[i].Nmissing      = in[i].Nmissing;     
    254     out[i].Nlensing      = in[i].Nlensing;     
    255     out[i].Nlensobj      = in[i].Nlensobj;     
    256     out[i].Nextend       = in[i].Nextend;     
    257 
    258     out[i].measureOffset = in[i].measureOffset;
    259     out[i].missingOffset = in[i].missingOffset;
    260     out[i].lensingOffset = in[i].lensingOffset;
    261     out[i].lensobjOffset = in[i].lensobjOffset;
    262     out[i].extendOffset  = in[i].extendOffset;
    263     out[i].paramsOffset  = in[i].paramsOffset;
    264 
    265     out[i].refColorBlue  = in[i].refColorBlue;
    266     out[i].refColorRed   = in[i].refColorRed;
    267 
    268     out[i].flags         = in[i].flags;   
     230    out[i].R              = in[i].R;     
     231    out[i].D              = in[i].D;     
     232    out[i].dR             = in[i].dR;
     233    out[i].dD             = in[i].dD;
     234    out[i].uR             = in[i].uR;
     235    out[i].uD             = in[i].uD;
     236    out[i].duR            = in[i].duR;
     237    out[i].duD            = in[i].duD;
     238    out[i].P              = in[i].P;
     239    out[i].dP             = in[i].dP;
     240                         
     241    out[i].Rstk           = in[i].Rstk;     
     242    out[i].Dstk           = in[i].Dstk;     
     243    out[i].dRstk          = in[i].dRstk;
     244    out[i].dDstk          = in[i].dDstk;
     245                         
     246    out[i].ChiSqAve       = in[i].ChiSqAve;     
     247    out[i].ChiSqPM        = in[i].ChiSqPM;     
     248    out[i].ChiSqPar       = in[i].ChiSqPar;     
     249    out[i].Tmean          = in[i].Tmean;     
     250    out[i].Trange         = in[i].Trange;     
     251                         
     252    out[i].psfQF          = in[i].psfQF;
     253    out[i].psfQFperf      = in[i].psfQFperf;
     254    out[i].stargal        = in[i].stargal;     
     255    out[i].Npos           = in[i].Npos;     
     256                         
     257    out[i].Nmeasure       = in[i].Nmeasure;     
     258    out[i].Nmissing       = in[i].Nmissing;     
     259    out[i].Nlensing       = in[i].Nlensing;     
     260    out[i].Nlensobj       = in[i].Nlensobj;     
     261    out[i].Nstarpar       = in[i].Nstarpar;     
     262    out[i].Nextend        = in[i].Nextend;     
     263                         
     264    out[i].measureOffset  = in[i].measureOffset;
     265    out[i].missingOffset  = in[i].missingOffset;
     266    out[i].lensingOffset  = in[i].lensingOffset;
     267    out[i].lensobjOffset  = in[i].lensobjOffset;
     268    out[i].starparOffset  = in[i].starparOffset;
     269    out[i].extendOffset   = in[i].extendOffset;
     270                         
     271    out[i].refColorBlue   = in[i].refColorBlue;
     272    out[i].refColorRed    = in[i].refColorRed;
     273                         
     274    out[i].tessID         = in[i].tessID;
     275    out[i].skycellID      = in[i].skycellID;
     276    out[i].projectionID   = in[i].projectionID;
     277                         
     278    out[i].flags          = in[i].flags;   
    269279    out[i].photFlagsUpper = in[i].photFlagsUpper;   
    270280    out[i].photFlagsLower = in[i].photFlagsLower;   
    271     out[i].objID         = in[i].objID;
    272     out[i].catID         = in[i].catID;
    273     out[i].extID         = in[i].extID;
    274     out[i].extIDgc       = in[i].extIDgc;
     281    out[i].objID          = in[i].objID;
     282    out[i].catID          = in[i].catID;
     283    out[i].extID          = in[i].extID;
     284    out[i].extIDgc        = in[i].extIDgc;
    275285  }
    276286  return (out);
     
    286296  for (i = 0; i < Nvalues; i++) {
    287297    dvo_secfilt_init (&out[i]);
    288 
    289     out[i].M             = in[i].M;     
    290     out[i].dM            = in[i].dM;     
    291     out[i].Map           = in[i].Map;     
    292     out[i].dMap          = in[i].dMap;     
    293     out[i].sMap          = in[i].sMap;     
    294     out[i].Mkron         = in[i].Mkron;     
    295     out[i].dMkron        = in[i].dMkron;     
    296 
    297     out[i].Mstdev        = in[i].Mstdev;     
    298     out[i].Mmin          = in[i].Mmin;     
    299     out[i].Mmax          = in[i].Mmax;     
    300     out[i].Mchisq        = in[i].Mchisq;     
    301 
    302     out[i].Ncode         = in[i].Ncode;
    303     out[i].Nused         = in[i].Nused;
    304     out[i].NusedKron     = in[i].NusedKron;
    305     out[i].NusedAp       = in[i].NusedAp;
    306 
    307     out[i].flags         = in[i].flags;     
    308 
    309     out[i].MpsfStk       = in[i].MpsfStk;
    310     out[i].FpsfStk       = in[i].FpsfStk;
    311     out[i].dFpsfStk      = in[i].dFpsfStk;
    312 
    313     out[i].MkronStk      = in[i].MkronStk;
    314     out[i].FkronStk      = in[i].FkronStk;
    315     out[i].dFkronStk     = in[i].dFkronStk;
    316 
    317     out[i].MapStk        = in[i].MapStk;
    318     out[i].FapStk        = in[i].FapStk;
    319     out[i].dFapStk       = in[i].dFapStk;
    320 
    321     out[i].stackDetectID = in[i].stackDetectID;     
    322 
    323     out[i].MpsfWrp       = in[i].MpsfWrp;
    324     out[i].FpsfWrp       = in[i].FpsfWrp;
    325     out[i].dFpsfWrp      = in[i].dFpsfWrp;
    326     out[i].sFpsfWrp      = in[i].sFpsfWrp;
    327 
    328     out[i].MkronWrp      = in[i].MkronWrp;
    329     out[i].FkronWrp      = in[i].FkronWrp;
    330     out[i].dFkronWrp     = in[i].dFkronWrp;
    331     out[i].sFkronWrp     = in[i].sFkronWrp;
    332 
    333     out[i].MapWrp        = in[i].MapWrp;
    334     out[i].FapWrp        = in[i].FapWrp;
    335     out[i].dFapWrp       = in[i].dFapWrp;
    336     out[i].sFapWrp       = in[i].sFapWrp;
    337 
    338     out[i].NusedWrp      = in[i].NusedWrp;
    339     out[i].NusedKronWrp  = in[i].NusedKronWrp;
    340     out[i].NusedApWrp    = in[i].NusedApWrp;
    341 
    342     out[i].ubercalDist   = in[i].ubercalDist;     
    343   }
    344   return (out);
    345 }
    346 
    347 SecFilt_PS1_V5 *SecFiltInternalTo_PS1_V5 (SecFilt *in, off_t Nvalues) {
    348 
    349   off_t i;
    350   SecFilt_PS1_V5 *out;
    351 
    352   ALLOCATE_ZERO (out, SecFilt_PS1_V5, Nvalues);
    353 
    354   for (i = 0; i < Nvalues; i++) {
    355298
    356299    out[i].M             = in[i].M;     
     
    363306    out[i].sMkron        = in[i].sMkron;     
    364307
     308    out[i].psfQfMax      = in[i].psfQfMax;     
     309    out[i].psfQfPerfMax  = in[i].psfQfPerfMax;     
     310
    365311    out[i].Mstdev        = in[i].Mstdev;     
    366312    out[i].Mmin          = in[i].Mmin;     
     
    387333    out[i].dFapStk       = in[i].dFapStk;
    388334
    389     out[i].stackDetectID = in[i].stackDetectID;     
     335    out[i].Nstack        = in[i].Nstack;     
     336    out[i].NstackDet     = in[i].NstackDet;     
     337
     338    out[i].stackPrmryOff = in[i].stackPrmryOff;     
     339    out[i].stackBestOff  = in[i].stackBestOff;     
    390340
    391341    out[i].MpsfWrp       = in[i].MpsfWrp;
     
    407357    out[i].NusedKronWrp  = in[i].NusedKronWrp;
    408358    out[i].NusedApWrp    = in[i].NusedApWrp;
     359
     360    out[i].Nwarp         = in[i].Nwarp;     
     361    out[i].NwarpGood     = in[i].NwarpGood;     
     362
     363    out[i].ubercalDist   = in[i].ubercalDist;     
     364  }
     365  return (out);
     366}
     367
     368SecFilt_PS1_V5 *SecFiltInternalTo_PS1_V5 (SecFilt *in, off_t Nvalues) {
     369
     370  off_t i;
     371  SecFilt_PS1_V5 *out;
     372
     373  ALLOCATE_ZERO (out, SecFilt_PS1_V5, Nvalues);
     374
     375  for (i = 0; i < Nvalues; i++) {
     376
     377    out[i].M             = in[i].M;     
     378    out[i].dM            = in[i].dM;     
     379    out[i].Map           = in[i].Map;     
     380    out[i].dMap          = in[i].dMap;     
     381    out[i].sMap          = in[i].sMap;     
     382    out[i].Mkron         = in[i].Mkron;     
     383    out[i].dMkron        = in[i].dMkron;     
     384    out[i].sMkron        = in[i].sMkron;     
     385
     386    out[i].psfQfMax      = in[i].psfQfMax;     
     387    out[i].psfQfPerfMax  = in[i].psfQfPerfMax;     
     388
     389    out[i].Mstdev        = in[i].Mstdev;     
     390    out[i].Mmin          = in[i].Mmin;     
     391    out[i].Mmax          = in[i].Mmax;     
     392    out[i].Mchisq        = in[i].Mchisq;     
     393
     394    out[i].Ncode         = in[i].Ncode;
     395    out[i].Nused         = in[i].Nused;
     396    out[i].NusedKron     = in[i].NusedKron;
     397    out[i].NusedAp       = in[i].NusedAp;
     398
     399    out[i].flags         = in[i].flags;     
     400
     401    out[i].MpsfStk       = in[i].MpsfStk;
     402    out[i].FpsfStk       = in[i].FpsfStk;
     403    out[i].dFpsfStk      = in[i].dFpsfStk;
     404
     405    out[i].MkronStk      = in[i].MkronStk;
     406    out[i].FkronStk      = in[i].FkronStk;
     407    out[i].dFkronStk     = in[i].dFkronStk;
     408
     409    out[i].MapStk        = in[i].MapStk;
     410    out[i].FapStk        = in[i].FapStk;
     411    out[i].dFapStk       = in[i].dFapStk;
     412
     413    out[i].Nstack        = in[i].Nstack;     
     414    out[i].NstackDet     = in[i].NstackDet;     
     415
     416    out[i].stackPrmryOff = in[i].stackPrmryOff;     
     417    out[i].stackBestOff  = in[i].stackBestOff;     
     418
     419    out[i].MpsfWrp       = in[i].MpsfWrp;
     420    out[i].FpsfWrp       = in[i].FpsfWrp;
     421    out[i].dFpsfWrp      = in[i].dFpsfWrp;
     422    out[i].sFpsfWrp      = in[i].sFpsfWrp;
     423
     424    out[i].MkronWrp      = in[i].MkronWrp;
     425    out[i].FkronWrp      = in[i].FkronWrp;
     426    out[i].dFkronWrp     = in[i].dFkronWrp;
     427    out[i].sFkronWrp     = in[i].sFkronWrp;
     428
     429    out[i].MapWrp        = in[i].MapWrp;
     430    out[i].FapWrp        = in[i].FapWrp;
     431    out[i].dFapWrp       = in[i].dFapWrp;
     432    out[i].sFapWrp       = in[i].sFapWrp;
     433
     434    out[i].NusedWrp      = in[i].NusedWrp;
     435    out[i].NusedKronWrp  = in[i].NusedKronWrp;
     436    out[i].NusedApWrp    = in[i].NusedApWrp;
     437
     438    out[i].Nwarp         = in[i].Nwarp;     
     439    out[i].NwarpGood     = in[i].NwarpGood;     
    409440
    410441    out[i].ubercalDist   = in[i].ubercalDist;     
     
    634665}
    635666
     667StarPar *StarPar_PS1_V5_ToInternal (StarPar_PS1_V5 *in, off_t Nvalues) {
     668
     669  off_t i;
     670  StarPar *out;
     671
     672  ALLOCATE_ZERO (out, StarPar, Nvalues);
     673
     674  for (i = 0; i < Nvalues; i++) {
     675    dvo_starpar_init (&out[i]);
     676
     677    out[i].R         = in[i].R;     
     678    out[i].D         = in[i].D;     
     679    out[i].galLat    = in[i].galLat;     
     680    out[i].galLon    = in[i].galLon;     
     681
     682    out[i].Ebv       = in[i].Ebv     ;     
     683    out[i].dEbv      = in[i].dEbv    ;     
     684    out[i].DistMag   = in[i].DistMag ;     
     685    out[i].dDistMag  = in[i].dDistMag;     
     686    out[i].M_r       = in[i].M_r     ;     
     687    out[i].dM_r      = in[i].dM_r    ;     
     688    out[i].FeH       = in[i].FeH     ;     
     689    out[i].dFeH      = in[i].dFeH    ;     
     690    out[i].uRA       = in[i].uRA     ;     
     691    out[i].uDEC      = in[i].uDEC    ;     
     692
     693    out[i].averef  = in[i].averef;
     694    out[i].objID   = in[i].objID ;
     695    out[i].catID   = in[i].catID ;
     696  }
     697  return (out);
     698}
     699
     700StarPar_PS1_V5 *StarParInternalTo_PS1_V5 (StarPar *in, off_t Nvalues) {
     701
     702  off_t i;
     703  StarPar_PS1_V5 *out;
     704
     705  ALLOCATE_ZERO (out, StarPar_PS1_V5, Nvalues);
     706
     707  for (i = 0; i < Nvalues; i++) {
     708
     709    out[i].R         = in[i].R;     
     710    out[i].D         = in[i].D;     
     711    out[i].galLat    = in[i].galLat;     
     712    out[i].galLon    = in[i].galLon;     
     713
     714    out[i].Ebv       = in[i].Ebv     ;     
     715    out[i].dEbv      = in[i].dEbv    ;     
     716    out[i].DistMag   = in[i].DistMag ;     
     717    out[i].dDistMag  = in[i].dDistMag;     
     718    out[i].M_r       = in[i].M_r     ;     
     719    out[i].dM_r      = in[i].dM_r    ;     
     720    out[i].FeH       = in[i].FeH     ;     
     721    out[i].dFeH      = in[i].dFeH    ;     
     722    out[i].uRA       = in[i].uRA     ;     
     723    out[i].uDEC      = in[i].uDEC    ;     
     724
     725    out[i].averef  = in[i].averef;
     726    out[i].objID   = in[i].objID ;
     727    out[i].catID   = in[i].catID ;
     728  }
     729  return (out);
     730}
     731
    636732# define RAW_IMAGE_NAME_LEN 117
    637733
     
    647743
    648744  for (i = 0; i < Nvalues; i++) {
    649     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     745    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     746    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     747    out[i].coords.mosaic   = NULL;
     748    out[i].coords.offsetMap = NULL;
    650749
    651750    // RAW_IMAGE_NAME_LEN == DVO_IMAGE_NAME_LEN
     
    712811
    713812  for (i = 0; i < Nvalues; i++) {
    714     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     813    // this is only save because the initial 120 bytes in Coords match CoordsDisk
     814    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    715815
    716816    // RAW_IMAGE_NAME_LEN == DVO_IMAGE_NAME_LEN
     
    840940  return (out);
    841941}
     942
     943/*********************** old / alternate version **********************/
     944
     945// 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
     946Average *Average_PS1_V5alt_ToInternal (Average_PS1_V5alt *in, off_t Nvalues) {
     947
     948  off_t i;
     949  Average *out;
     950
     951  ALLOCATE_ZERO (out, Average, Nvalues);
     952
     953  for (i = 0; i < Nvalues; i++) {
     954    dvo_average_init (&out[i]);
     955
     956    out[i].R              = in[i].R;     
     957    out[i].D              = in[i].D;     
     958    out[i].dR             = in[i].dR;
     959    out[i].dD             = in[i].dD;
     960    out[i].uR             = in[i].uR;
     961    out[i].uD             = in[i].uD;
     962    out[i].duR            = in[i].duR;
     963    out[i].duD            = in[i].duD;
     964    out[i].P              = in[i].P;
     965    out[i].dP             = in[i].dP;
     966                         
     967    out[i].Rstk           = in[i].Rstk;     
     968    out[i].Dstk           = in[i].Dstk;     
     969    out[i].dRstk          = in[i].dRstk;
     970    out[i].dDstk          = in[i].dDstk;
     971                         
     972    out[i].ChiSqAve       = in[i].ChiSqAve;     
     973    out[i].ChiSqPM        = in[i].ChiSqPM;     
     974    out[i].ChiSqPar       = in[i].ChiSqPar;     
     975    out[i].Tmean          = in[i].Tmean;     
     976    out[i].Trange         = in[i].Trange;     
     977                         
     978    out[i].psfQF          = in[i].psfQF;
     979    out[i].psfQFperf      = in[i].psfQFperf;
     980    out[i].stargal        = in[i].stargal;     
     981    out[i].Npos           = in[i].Npos;     
     982                         
     983    out[i].Nmeasure       = in[i].Nmeasure;     
     984    out[i].Nmissing       = in[i].Nmissing;     
     985    out[i].Nlensing       = in[i].Nlensing;     
     986    out[i].Nlensobj       = in[i].Nlensobj;     
     987    out[i].Nextend        = in[i].Nextend;     
     988                         
     989    out[i].measureOffset  = in[i].measureOffset;
     990    out[i].missingOffset  = in[i].missingOffset;
     991    out[i].lensingOffset  = in[i].lensingOffset;
     992    out[i].lensobjOffset  = in[i].lensobjOffset;
     993    out[i].starparOffset  = in[i].starparOffset;
     994    out[i].extendOffset   = in[i].extendOffset;
     995                         
     996    out[i].refColorBlue   = in[i].refColorBlue;
     997    out[i].refColorRed    = in[i].refColorRed;
     998                         
     999    out[i].flags          = in[i].flags;   
     1000    out[i].photFlagsUpper = in[i].photFlagsUpper;   
     1001    out[i].photFlagsLower = in[i].photFlagsLower;   
     1002    out[i].objID          = in[i].objID;
     1003    out[i].catID          = in[i].catID;
     1004    out[i].extID          = in[i].extID;
     1005    out[i].extIDgc        = in[i].extIDgc;
     1006  }
     1007  return (out);
     1008}
     1009
     1010int gfits_convert_Average_PS1_V5alt (Average_PS1_V5alt *data, off_t size, off_t nitems) {
     1011
     1012  off_t i;
     1013  unsigned char *byte, tmp;
     1014
     1015  if (size != 184) {
     1016    fprintf (stderr, "WARNING: mismatch in data types Average_PS1_V5alt: "OFF_T_FMT" vs %d\n",  size,  184);
     1017    return (FALSE);
     1018  }
     1019
     1020  /* provide initial values to avoid compiler warnings for non-BYTE_SWAP arch */
     1021  i = tmp = 0;
     1022  byte = NULL;
     1023
     1024# ifdef BYTE_SWAP
     1025  byte = (unsigned char *) data;
     1026  for (i = 0; i < nitems; i++, byte += 184) {
     1027    /** BYTE SWAP **/
     1028    SWAP_DBLE (0); // RA
     1029    SWAP_DBLE (8); // DEC
     1030    SWAP_WORD (16); // RA_ERR
     1031    SWAP_WORD (20); // DEC_ERR
     1032    SWAP_WORD (24); // U_RA
     1033    SWAP_WORD (28); // U_DEC
     1034    SWAP_WORD (32); // V_RA_ERR
     1035    SWAP_WORD (36); // V_DEC_ERR
     1036    SWAP_WORD (40); // PAR
     1037    SWAP_WORD (44); // PAR_ERR
     1038    SWAP_DBLE (48); // RA_STK
     1039    SWAP_DBLE (56); // DEC_STK
     1040    SWAP_WORD (64); // RA_STK_ERR
     1041    SWAP_WORD (68); // DEC_STK_ERR
     1042    SWAP_WORD (72); // CHISQ_POS
     1043    SWAP_WORD (76); // CHISQ_PM
     1044    SWAP_WORD (80); // CHISQ_PAP
     1045    SWAP_WORD (84); // MEAN_EPOCH
     1046    SWAP_WORD (88); // TIME_RANGE
     1047    SWAP_WORD (92); // PSF_QF
     1048    SWAP_WORD (96); // PSF_QF_PERF
     1049    SWAP_WORD (100); // STARGAL_SEP
     1050    SWAP_BYTE (104); // NUMBER_POS
     1051    SWAP_BYTE (106); // NMEASURE
     1052    SWAP_BYTE (108); // NMISSING
     1053    SWAP_BYTE (110); // NLENSING
     1054    SWAP_BYTE (112); // NLENSOBJ
     1055    SWAP_BYTE (114); // NEXTEND
     1056    SWAP_WORD (116); // OFF_MEASURE
     1057    SWAP_WORD (120); // OFF_MISSING
     1058    SWAP_WORD (124); // OFF_LENSING
     1059    SWAP_WORD (128); // OFF_LENSOBJ
     1060    SWAP_WORD (132); // OFF_EXTEND
     1061    SWAP_WORD (136); // OFF_PARAMS
     1062    SWAP_WORD (140); // REF_COLOR_BLUE
     1063    SWAP_WORD (144); // REF_COLOR_RED
     1064    SWAP_WORD (148); // FLAGS
     1065    SWAP_WORD (152); // PHOTFLAGS_U
     1066    SWAP_WORD (156); // PHOTFLAGS_L
     1067    SWAP_WORD (160); // OBJ_ID
     1068    SWAP_WORD (164); // CAT_ID
     1069    SWAP_DBLE (168); // EXT_ID
     1070    SWAP_DBLE (176); // EXT_ID_GC
     1071  }
     1072# endif 
     1073
     1074  return (TRUE);
     1075}
     1076
     1077/*** add test of EXTNAME and header-defined columns? ***/
     1078/* return internal structure representation */
     1079Average_PS1_V5alt *gfits_table_get_Average_PS1_V5alt (FTable *ftable, off_t *Ndata, char *swapped) {
     1080
     1081  int Ncols;
     1082  Average_PS1_V5alt *data;
     1083
     1084  Ncols = ftable[0].header[0].Naxis[0];
     1085  if (Ncols != 184) {
     1086    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, 184);
     1087    return NULL;
     1088  }
     1089
     1090  *Ndata = ftable[0].header[0].Naxis[1];
     1091  data = (Average_PS1_V5alt *) ftable[0].buffer;
     1092  if ((swapped == NULL) || (*swapped == FALSE)) {
     1093    if (!gfits_convert_Average_PS1_V5alt (data, sizeof (Average_PS1_V5alt), *Ndata)) {
     1094      return NULL;
     1095    }
     1096    gfits_table_scale_data (ftable);
     1097    if (swapped != NULL) *swapped = TRUE;
     1098  }
     1099  return (data);
     1100}
     1101
     1102/****** alt secfilt **********/
     1103
     1104SecFilt *SecFilt_PS1_V5alt_ToInternal (SecFilt_PS1_V5alt *in, off_t Nvalues) {
     1105
     1106  off_t i;
     1107  SecFilt *out;
     1108
     1109  ALLOCATE_ZERO (out, SecFilt, Nvalues);
     1110
     1111  for (i = 0; i < Nvalues; i++) {
     1112    dvo_secfilt_init (&out[i]);
     1113
     1114    out[i].M             = in[i].M;     
     1115    out[i].dM            = in[i].dM;     
     1116    out[i].Map           = in[i].Map;     
     1117    out[i].dMap          = in[i].dMap;     
     1118    out[i].sMap          = in[i].sMap;     
     1119    out[i].Mkron         = in[i].Mkron;     
     1120    out[i].dMkron        = in[i].dMkron;     
     1121
     1122    out[i].Mstdev        = in[i].Mstdev;     
     1123    out[i].Mmin          = in[i].Mmin;     
     1124    out[i].Mmax          = in[i].Mmax;     
     1125    out[i].Mchisq        = in[i].Mchisq;     
     1126
     1127    out[i].Ncode         = in[i].Ncode;
     1128    out[i].Nused         = in[i].Nused;
     1129    out[i].NusedKron     = in[i].NusedKron;
     1130    out[i].NusedAp       = in[i].NusedAp;
     1131
     1132    out[i].flags         = in[i].flags;     
     1133
     1134    out[i].MpsfStk       = in[i].MpsfStk;
     1135    out[i].FpsfStk       = in[i].FpsfStk;
     1136    out[i].dFpsfStk      = in[i].dFpsfStk;
     1137
     1138    out[i].MkronStk      = in[i].MkronStk;
     1139    out[i].FkronStk      = in[i].FkronStk;
     1140    out[i].dFkronStk     = in[i].dFkronStk;
     1141
     1142    out[i].MapStk        = in[i].MapStk;
     1143    out[i].FapStk        = in[i].FapStk;
     1144    out[i].dFapStk       = in[i].dFapStk;
     1145
     1146    out[i].stackPrmryOff = in[i].stackPrmryOff;     
     1147    out[i].stackBestOff  = in[i].stackBestOff;     
     1148
     1149    out[i].MpsfWrp       = in[i].MpsfWrp;
     1150    out[i].FpsfWrp       = in[i].FpsfWrp;
     1151    out[i].dFpsfWrp      = in[i].dFpsfWrp;
     1152    out[i].sFpsfWrp      = in[i].sFpsfWrp;
     1153
     1154    out[i].MkronWrp      = in[i].MkronWrp;
     1155    out[i].FkronWrp      = in[i].FkronWrp;
     1156    out[i].dFkronWrp     = in[i].dFkronWrp;
     1157    out[i].sFkronWrp     = in[i].sFkronWrp;
     1158
     1159    out[i].MapWrp        = in[i].MapWrp;
     1160    out[i].FapWrp        = in[i].FapWrp;
     1161    out[i].dFapWrp       = in[i].dFapWrp;
     1162    out[i].sFapWrp       = in[i].sFapWrp;
     1163
     1164    out[i].NusedWrp      = in[i].NusedWrp;
     1165    out[i].NusedKronWrp  = in[i].NusedKronWrp;
     1166    out[i].NusedApWrp    = in[i].NusedApWrp;
     1167
     1168    out[i].ubercalDist   = in[i].ubercalDist;     
     1169  }
     1170  return (out);
     1171}
     1172
     1173int gfits_convert_SecFilt_PS1_V5alt (SecFilt_PS1_V5alt *data, off_t size, off_t nitems) {
     1174
     1175  off_t i;
     1176  unsigned char *byte, tmp;
     1177
     1178  if (size != 160) {
     1179    fprintf (stderr, "WARNING: mismatch in data types SecFilt_PS1_V5alt: "OFF_T_FMT" vs %d\n",  size,  160);
     1180    return (FALSE);
     1181  }
     1182
     1183  /* provide initial values to avoid compiler warnings for non-BYTE_SWAP arch */
     1184  i = tmp = 0;
     1185  byte = NULL;
     1186
     1187# ifdef BYTE_SWAP
     1188  byte = (unsigned char *) data;
     1189  for (i = 0; i < nitems; i++, byte += 160) {
     1190    /** BYTE SWAP **/
     1191    SWAP_WORD (0); // MAG
     1192    SWAP_WORD (4); // MAG_ERR
     1193    SWAP_WORD (8); // MAG_AP
     1194    SWAP_WORD (12); // MAG_AP_ERR
     1195    SWAP_WORD (16); // MAG_AP_STDEV
     1196    SWAP_WORD (20); // MAG_KRON
     1197    SWAP_WORD (24); // MAG_KRON_ERR
     1198    SWAP_WORD (28); // MAG_KRON_STDEV
     1199    SWAP_WORD (32); // MAG_STDEV
     1200    SWAP_WORD (36); // MAG_MIN
     1201    SWAP_WORD (40); // MAG_MAX
     1202    SWAP_WORD (44); // MAG_CHI
     1203    SWAP_BYTE (48); // NCODE
     1204    SWAP_BYTE (50); // NUSED
     1205    SWAP_BYTE (52); // NUSED_KRON
     1206    SWAP_BYTE (54); // NUSED_AP
     1207    SWAP_WORD (56); // FLAGS
     1208    SWAP_WORD (60); // MAG_PSF_STK
     1209    SWAP_WORD (64); // FLUX_PSF_STK
     1210    SWAP_WORD (68); // FLUX_PSF_STK_ERR
     1211    SWAP_WORD (72); // MAG_KRON_STK
     1212    SWAP_WORD (76); // FLUX_KRON_STK
     1213    SWAP_WORD (80); // FLUX_KRON_STK_ERR
     1214    SWAP_WORD (84); // MAG_AP_STK
     1215    SWAP_WORD (88); // FLUX_AP_STK
     1216    SWAP_WORD (92); // FLUX_AP_STK_ERR
     1217    SWAP_WORD (96); // STACK_PRIMARY_OFF
     1218    SWAP_WORD (100); // STACK_BEST_OFF
     1219    SWAP_WORD (104); // MAG_PSF_WRP
     1220    SWAP_WORD (108); // FLUX_PSF_WRP
     1221    SWAP_WORD (112); // FLUX_PSF_WRP_ERR
     1222    SWAP_WORD (116); // FLUX_PSF_WRP_STD
     1223    SWAP_WORD (120); // MAG_KRON_WRP
     1224    SWAP_WORD (124); // FLUX_KRON_WRP
     1225    SWAP_WORD (128); // FLUX_KRON_WRP_ERR
     1226    SWAP_WORD (132); // FLUX_KRON_WRP_STD
     1227    SWAP_WORD (136); // MAG_AP_WRP
     1228    SWAP_WORD (140); // FLUX_AP_WRP
     1229    SWAP_WORD (144); // FLUX_AP_WRP_ERR
     1230    SWAP_WORD (148); // FLUX_AP_WRP_STD
     1231    SWAP_BYTE (152); // NUSED_WRP
     1232    SWAP_BYTE (154); // NUSED_KRON_WRP
     1233    SWAP_BYTE (156); // NUSED_AP_WRP
     1234    SWAP_BYTE (158); // UBERCAL_DIST
     1235  }
     1236# endif 
     1237
     1238  return (TRUE);
     1239}
     1240
     1241/*** add test of EXTNAME and header-defined columns? ***/
     1242/* return internal structure representation */
     1243SecFilt_PS1_V5alt *gfits_table_get_SecFilt_PS1_V5alt (FTable *ftable, off_t *Ndata, char *swapped) {
     1244
     1245  int Ncols;
     1246  SecFilt_PS1_V5alt *data;
     1247
     1248  Ncols = ftable[0].header[0].Naxis[0];
     1249  if (Ncols != 160) {
     1250    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, 160);
     1251    return NULL;
     1252  }
     1253
     1254  *Ndata = ftable[0].header[0].Naxis[1];
     1255  data = (SecFilt_PS1_V5alt *) ftable[0].buffer;
     1256  if ((swapped == NULL) || (*swapped == FALSE)) {
     1257    if (!gfits_convert_SecFilt_PS1_V5alt (data, sizeof (SecFilt_PS1_V5alt), *Ndata)) {
     1258      return NULL;
     1259    }
     1260    gfits_table_scale_data (ftable);
     1261    if (swapped != NULL) *swapped = TRUE;
     1262  }
     1263  return (data);
     1264}
     1265
     1266
     1267Lensing *Lensing_PS1_V5_ALT_ToInternal (Lensing_PS1_V5_ALT *in, off_t Nvalues) {
     1268
     1269  off_t i;
     1270  Lensing *out;
     1271
     1272  ALLOCATE_ZERO (out, Lensing, Nvalues);
     1273
     1274  for (i = 0; i < Nvalues; i++) {
     1275    dvo_lensing_init (&out[i]);
     1276
     1277    out[i].X11_sm_obj  = in[i].X11_sm_obj;     
     1278    out[i].X12_sm_obj  = in[i].X12_sm_obj;     
     1279    out[i].X22_sm_obj  = in[i].X22_sm_obj;     
     1280    out[i].E1_sm_obj   = in[i].E1_sm_obj;     
     1281    out[i].E2_sm_obj   = in[i].E2_sm_obj;     
     1282                                         
     1283    out[i].X11_sh_obj  = in[i].X11_sh_obj;     
     1284    out[i].X12_sh_obj  = in[i].X12_sh_obj;     
     1285    out[i].X22_sh_obj  = in[i].X22_sh_obj;     
     1286    out[i].E1_sh_obj   = in[i].E1_sh_obj;     
     1287    out[i].E2_sh_obj   = in[i].E2_sh_obj;     
     1288                                         
     1289    out[i].X11_sm_psf  = in[i].X11_sm_psf;
     1290    out[i].X12_sm_psf  = in[i].X12_sm_psf;
     1291    out[i].X22_sm_psf  = in[i].X22_sm_psf;
     1292    out[i].E1_sm_psf   = in[i].E1_sm_psf;
     1293    out[i].E2_sm_psf   = in[i].E2_sm_psf;     
     1294                                         
     1295    out[i].X11_sh_psf  = in[i].X11_sh_psf;
     1296    out[i].X12_sh_psf  = in[i].X12_sh_psf;
     1297    out[i].X22_sh_psf  = in[i].X22_sh_psf;
     1298    out[i].E1_sh_psf   = in[i].E1_sh_psf;
     1299    out[i].E2_sh_psf   = in[i].E2_sh_psf;
     1300
     1301    out[i].F_ApR5      = in[i].F_ApR5;
     1302    out[i].dF_ApR5     = in[i].dF_ApR5;
     1303    out[i].sF_ApR5     = in[i].sF_ApR5;
     1304    out[i].fF_ApR5     = in[i].fF_ApR5;
     1305                                   
     1306    out[i].F_ApR6      = in[i].F_ApR6;
     1307    out[i].dF_ApR6     = in[i].dF_ApR6;
     1308    out[i].sF_ApR6     = in[i].sF_ApR6;
     1309    out[i].fF_ApR6     = in[i].fF_ApR6;
     1310                                   
     1311    out[i].detID       = in[i].detID;
     1312    out[i].objID       = in[i].objID;
     1313    out[i].catID       = in[i].catID;
     1314
     1315    out[i].averef      = in[i].averef;
     1316  }
     1317  return (out);
     1318}
     1319
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert_elixir.c

    r37035 r37822  
    210210
    211211  for (i = 0; i < Nvalues; i++) {
    212     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     212    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     213    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     214    out[i].coords.mosaic   = NULL;
     215    out[i].coords.offsetMap = NULL;
    213216
    214217    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    280283
    281284  for (i = 0; i < Nvalues; i++) {
    282     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     285    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     286    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    283287
    284288    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert_loneos.c

    r37035 r37822  
    188188
    189189  for (i = 0; i < Nvalues; i++) {
    190     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     190    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     191    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     192    out[i].coords.mosaic   = NULL;
     193    out[i].coords.offsetMap = NULL;
    191194
    192195    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    259262
    260263  for (i = 0; i < Nvalues; i++) {
    261     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     264    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     265    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    262266
    263267    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c

    r37035 r37822  
    227227
    228228  for (i = 0; i < Nvalues; i++) {
    229     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     229    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     230    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     231    out[i].coords.mosaic   = NULL;
     232    out[i].coords.offsetMap = NULL;
    230233
    231234    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    297300
    298301  for (i = 0; i < Nvalues; i++) {
    299     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     302    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     303    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    300304
    301305    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c

    r37035 r37822  
    227227
    228228  for (i = 0; i < Nvalues; i++) {
    229     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     229    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     230    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     231    out[i].coords.mosaic   = NULL;
     232    out[i].coords.offsetMap = NULL;
    230233
    231234    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    297300
    298301  for (i = 0; i < Nvalues; i++) {
    299     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     302    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     303    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    300304
    301305    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_image.c

    r37035 r37822  
    200200
    201201  gfits_create_matrix (&db[0].header, &db[0].matrix);
    202   gfits_table_set_Image (&db[0].ftable, NULL, 0);
     202  gfits_table_set_Image (&db[0].ftable);
    203203
    204204  gfits_modify (&db[0].header, "NIMAGES", "%d", 1, 0);
     
    207207  dvo_image_createID (&db[0].header);
    208208
    209   if (db[0].format == DVO_FORMAT_INTERNAL)        gfits_modify (&db[0].header, "FORMAT", "%s", 1, "INTERNAL");
     209  // if (db[0].format == DVO_FORMAT_INTERNAL)     gfits_modify (&db[0].header, "FORMAT", "%s", 1, "INTERNAL");
    210210  if (db[0].format == DVO_FORMAT_LONEOS)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "LONEOS");
    211211  if (db[0].format == DVO_FORMAT_ELIXIR)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "ELIXIR");
     
    221221  if (db[0].format == DVO_FORMAT_PS1_V5)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V5");
    222222  if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_REF");
     223  if (db[0].format == DVO_FORMAT_PS1_SIM)         gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_SIM");
    223224 
    224225  return;
     
    267268}
    268269
     270int gfits_table_set_Image (FTable *ftable) {
     271
     272  Header *header;
     273
     274  header = ftable[0].header;
     275
     276  gfits_table_mkheader_Image (header);
     277 
     278  /* create table */
     279  if (!gfits_create_table (header, ftable)) return (FALSE);
     280
     281  return (TRUE);
     282}
     283
     284int gfits_table_mkheader_Image (Header *header) {
     285
     286  /* create table header */
     287  if (!gfits_create_table_header (header, "BINTABLE", "DVO_IMAGE")) return (FALSE);
     288
     289  /* define table layout */
     290  /** TABLE DEFINITION **/
     291  gfits_define_bintable_column (header, "D",    "CRVAL1",           "coordinate at reference pixel",   "",                  1.0, 0.0);
     292  gfits_define_bintable_column (header, "D",    "CRVAL2",           "coordinate at reference pixel",   "",                  1.0, 0.0);
     293  gfits_define_bintable_column (header, "E",    "CRPIX1",           "coordinate of reference pixel",   "",                  1.0, 0.0);
     294  gfits_define_bintable_column (header, "E",    "CRPIX2",           "coordinate of reference pixel",   "",                  1.0, 0.0);
     295  gfits_define_bintable_column (header, "E",    "CDELT1",           "degrees per pixel",               "",                  1.0, 0.0);
     296  gfits_define_bintable_column (header, "E",    "CDELT2",           "degrees per pixel",               "",                  1.0, 0.0);
     297  gfits_define_bintable_column (header, "E",    "PC1_1",            "rotation matrix",                 "",                  1.0, 0.0);
     298  gfits_define_bintable_column (header, "E",    "PC1_2",            "rotation matrix",                 "",                  1.0, 0.0);
     299  gfits_define_bintable_column (header, "E",    "PC2_1",            "rotation matrix",                 "",                  1.0, 0.0);
     300  gfits_define_bintable_column (header, "E",    "PC2_2",            "rotation matrix",                 "",                  1.0, 0.0);
     301  gfits_define_bintable_column (header, "14E",  "POLYTERMS",        "higher order warping terms",      "",                  1.0, 0.0);
     302  if (sizeof(void *) == 4) {
     303    gfits_define_bintable_column (header, "J",    "POINTER1",       "",  "",                  1.0, 0.0);
     304    gfits_define_bintable_column (header, "J",    "POINTER2",       "",  "",                  1.0, 0.0);
     305  }
     306  if (sizeof(void *) == 8) {
     307    gfits_define_bintable_column (header, "K",    "POINTER1",       "",  "",                  1.0, 0.0);
     308    gfits_define_bintable_column (header, "K",    "POINTER2",       "",  "",                  1.0, 0.0);
     309  }
     310  gfits_define_bintable_column (header, "15A",  "CTYPE",            "coordinate type",                 "",                  1.0, 0.0);
     311  gfits_define_bintable_column (header, "A",    "NPOLYTERMS",       "order of polynomial",             "",                  1.0, 0.0);
     312  gfits_define_bintable_column (header, "J",    "TZERO",            "readout time (row 0)",            "",                  1.0, 0.0);
     313  gfits_define_bintable_column (header, "J",    "NSTAR",            "number of stars on image",        "",                  1.0, 0.0);
     314  gfits_define_bintable_column (header, "E",    "SECZ",             "airmass",                         "mag",               1.0, 0.0);
     315  gfits_define_bintable_column (header, "I",    "NX",               "image width",                     "",                  1.0, 0.0);
     316  gfits_define_bintable_column (header, "I",    "NY",               "image height",                    "",                  1.0, 0.0);
     317  gfits_define_bintable_column (header, "E",    "APMIFIT",          "aperture correction",             "mag",               1.0, 0.0);
     318  gfits_define_bintable_column (header, "E",    "DAPMIFIT",         "apmifit error",                   "mag",               1.0, 0.0);
     319  gfits_define_bintable_column (header, "E",    "MCAL",             "calibration mag",                 "mag",               1.0, 0.0);
     320  gfits_define_bintable_column (header, "E",    "DMCAL",            "error on Mcal",                   "mag",               1.0, 0.0);
     321  gfits_define_bintable_column (header, "I",    "XM",               "image chisq",                     "10*log(value)",     1.0, 0.0);
     322  gfits_define_bintable_column (header, "I",    "PHOTCODE",         "identifier for CCD,",             "",                  1.0, 0.0);
     323  gfits_define_bintable_column (header, "E",    "EXPTIME",          "exposure time",                   "seconds",           1.0, 0.0);
     324  gfits_define_bintable_column (header, "E",    "ST",               "sidereal time of exposure",       "",                  1.0, 0.0);
     325  gfits_define_bintable_column (header, "E",    "LAT",              "observatory latitude",            "degrees",           1.0, 0.0);
     326  gfits_define_bintable_column (header, "E",    "RA_CENTER",        "image center",                    "degrees",           1.0, 0.0);
     327  gfits_define_bintable_column (header, "E",    "DEC_CENTER",       "image center",                    "degrees",           1.0, 0.0);
     328  gfits_define_bintable_column (header, "E",    "RADIUS",           "image radius",                    "degrees",           1.0, 0.0);
     329  gfits_define_bintable_column (header, "E",    "REF_COLOR_BLUE",   "median astrometry ref color",     "",                  1.0, 0.0);
     330  gfits_define_bintable_column (header, "E",    "REF_COLOR_RED",    "median astrometry ref color",     "",                  1.0, 0.0);
     331  gfits_define_bintable_column (header, "117A", "NAME",             "name of original image ",         "",                  1.0, 0.0);
     332  gfits_define_bintable_column (header, "B",    "DETECTION_LIMIT",  "detection limit",                 "10*mag",            1.0, 0.0);
     333  gfits_define_bintable_column (header, "B",    "SATURATION_LIMIT", "saturation limit",                "10*mag",            1.0, 0.0);
     334  gfits_define_bintable_column (header, "B",    "CERROR",           "astrometric error",               "50*arcsec",         1.0, 0.0);
     335  gfits_define_bintable_column (header, "B",    "FWHM_X",           "PSF x width",                     "25*arcsec",         1.0, 0.0);
     336  gfits_define_bintable_column (header, "B",    "FWHM_Y",           "PSF y width",                     "25*arcsec",         1.0, 0.0);
     337  gfits_define_bintable_column (header, "B",    "TRATE",            "scan rate",                       "100 usec/pixel",    1.0, 0.0);
     338  gfits_define_bintable_column (header, "B",    "CCDNUM",           "CCD ID number",                   "",                  1.0, 0.0);
     339  gfits_define_bintable_column (header, "J",    "FLAGS",            "image quality flags",             "",                  1.0, 0.0);
     340  gfits_define_bintable_column (header, "J",    "IMAGE_ID",         "internal image ID",               "",                  1.0, 0.0);
     341  gfits_define_bintable_column (header, "J",    "PARENT_ID",        "associated ref image",            "",                  1.0, 0.0);
     342  gfits_define_bintable_column (header, "J",    "EXTERN_ID",        "external image ID",               "",                  1.0, 0.0);
     343  gfits_define_bintable_column (header, "I",    "SOURCE_ID",        "analysis source ID",              "",                  1.0, 0.0);
     344  gfits_define_bintable_column (header, "I",    "NLINK_ASTROM",     "mean number of matched measurements for astrometry", "",                  1.0, 0.0);
     345  gfits_define_bintable_column (header, "I",    "NLINK_PHOTOM",     "mean number of matched measurements for astrometry", "",                  1.0, 0.0);
     346  gfits_define_bintable_column (header, "I",    "UBERCAL_DIST",     "distance to nearest ubercal image", "",                  1.0, 0.0);
     347  gfits_define_bintable_column (header, "E",    "XPIX_SYS_ERR",     "systematic astrometry error in X", "",                  1.0, 0.0);
     348  gfits_define_bintable_column (header, "E",    "YPIX_SYS_ERR",     "systematic astrometry error in Y", "",                  1.0, 0.0);
     349  gfits_define_bintable_column (header, "E",    "MAG_SYS_ERR",      "systematic photometry error",     "",                  1.0, 0.0);
     350  gfits_define_bintable_column (header, "I",    "N_FIT_ASTROM",     "number of stars used for astrometry cal", "",                  1.0, 0.0);
     351  gfits_define_bintable_column (header, "I",    "N_FIT_PHOTOM",     "number of stars used for photometry cal", "",                  1.0, 0.0);
     352  gfits_define_bintable_column (header, "J",    "PHOTOM_MAP_ID",    "reference to 2D zero point map",  "",                  1.0, 0.0);
     353  gfits_define_bintable_column (header, "J",    "ASTROM_MAP_ID",    "reference to 2D astrometry map",  "",                  1.0, 0.0);
     354  if (sizeof(void *) == 4) {
     355    gfits_define_bintable_column (header, "J",    "POINTER3",       "",  "",                  1.0, 0.0);
     356  }
     357  if (sizeof(void *) == 8) {
     358    gfits_define_bintable_column (header, "K",    "POINTER3",       "",  "",                  1.0, 0.0);
     359  }
     360
     361  return (TRUE);
     362}
     363
     364/* return internal structure representation */
     365Image *gfits_table_get_Image (FTable *ftable, off_t *Ndata, char *swapped) {
     366
     367  int Ncols;
     368  Image *data;
     369
     370  Ncols = ftable[0].header[0].Naxis[0];
     371  if (Ncols != sizeof(Image)) {
     372    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, (int) sizeof(Image));
     373    return NULL;
     374  }
     375
     376  *Ndata = ftable[0].header[0].Naxis[1];
     377  data = (Image *) ftable[0].buffer;
     378
     379  if (!swapped) {
     380    myAbort ("invalid to call this without suppying 'swapped'");
     381  }
     382  if (*swapped == FALSE) {
     383    myAbort ("invalid for table to be swapped");
     384  }
     385   
     386  return (data);
     387}
     388
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_image_raw.c

    r37035 r37822  
    6161  if (db[0].format == DVO_FORMAT_PS1_V5)          ImageSize = sizeof(Image_PS1_V5);
    6262  if (db[0].format == DVO_FORMAT_PS1_REF)         ImageSize = sizeof(Image_PS1_REF);
     63  if (db[0].format == DVO_FORMAT_PS1_SIM)         ImageSize = sizeof(Image_PS1_SIM);
    6364
    6465  /* check that filesize makes sense */
     
    9293  if (db[0].format == DVO_FORMAT_PS1_V5)          gfits_table_mkheader_Image_PS1_V5 (&db[0].theader);
    9394  if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_table_mkheader_Image_PS1_REF (&db[0].theader);
     95  if (db[0].format == DVO_FORMAT_PS1_SIM)         gfits_table_mkheader_Image_PS1_SIM (&db[0].theader);
    9496   
    9597  /* read data from file */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_photcode_ops.c

    r37035 r37822  
    687687}
    688688
    689 float PhotMstdev (PhotCode *code, Average *average, SecFilt *secfilt) {
    690 
    691   int Ns;
    692   float Mstdev;
     689float PhotMstdev (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source) {
    693690
    694691  if (code == NULL) return NAN;
    695692
    696   Ns = photcodes[0].hashNsec[code[0].code];
    697   Mstdev  = (Ns == -1) ? NAN : 0.001*secfilt[Ns].Mstdev;
     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  }
    698732  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);
    699779}
    700780
     
    783863}
    784864
    785 unsigned int PhotStackID (PhotCode *code, Average *average, SecFilt *secfilt) {
    786 
    787   int Ns;
    788   unsigned int ID;
    789 
    790   if (code == NULL) return 0;
    791 
    792   Ns = photcodes[0].hashNsec[code[0].code];
    793   ID = (Ns == -1) ? 0 : secfilt[Ns].stackDetectID;
    794   return (ID);
    795 }
     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 }
    796876
    797877// Xm is now (2014.07.03) stored as the chisq except in dvo formats which use as short
     
    11121192  }
    11131193  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);
    11141254}
    11151255
     
    16481788  m2 = (Ns2 == -1) ? average[0].M : secfilt[Ns2].M;
    16491789*/
     1790
     1791/*** lensing *********************************************************************************/
     1792
     1793# define LENSFIELD(NAME) \
     1794  float LensValue_##NAME (PhotCode *code, Lensobj *lensobj) { \
     1795  if (code == NULL) return NAN; \
     1796  int Ns = photcodes->hashNsec[code->code]; \
     1797  float value = (Ns == -1) ? NAN : lensobj[Ns].NAME; \
     1798  return (value); \
     1799}
     1800
     1801LENSFIELD(X11_sm_obj);
     1802LENSFIELD(X12_sm_obj);
     1803LENSFIELD(X22_sm_obj);
     1804LENSFIELD(E1_sm_obj);
     1805LENSFIELD(E2_sm_obj);
     1806
     1807LENSFIELD(X11_sh_obj);
     1808LENSFIELD(X12_sh_obj);
     1809LENSFIELD(X22_sh_obj);
     1810LENSFIELD(E1_sh_obj);
     1811LENSFIELD(E2_sh_obj);
     1812
     1813LENSFIELD(X11_sm_psf);
     1814LENSFIELD(X12_sm_psf);
     1815LENSFIELD(X22_sm_psf);
     1816LENSFIELD(E1_sm_psf);
     1817LENSFIELD(E2_sm_psf);
     1818
     1819LENSFIELD(X11_sh_psf);
     1820LENSFIELD(X12_sh_psf);
     1821LENSFIELD(X22_sh_psf);
     1822LENSFIELD(E1_sh_psf);
     1823LENSFIELD(E2_sh_psf);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_tiny_values.c

    r37035 r37822  
    2020  measureT[0].dM         = measure[0].dM;
    2121  measureT[0].airmass    = measure[0].airmass;
     22  measureT[0].RoffGAL    = measure[0].RoffGAL;
     23  measureT[0].DoffGAL    = measure[0].DoffGAL;
    2224  measureT[0].Xccd       = measure[0].Xccd;
    2325  measureT[0].Yccd       = measure[0].Yccd;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/dvo_util.c

    r33030 r37822  
    145145        if ((image->externID == externID) && (image->sourceID == sourceID)) {
    146146            BuildChipMatch(dvoConfig->images, dvoConfig->nImages);
    147             if (FindMosaicForImage(dvoConfig->images, dvoConfig->nImages, i)) {
    148                 return image;
    149             } else {
    150                 fprintf(stderr, "FindMosaicForImage failed\n");
    151                 return NULL;
    152             }
     147            return image;
    153148        }
    154149    }
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/flatcorr_io.c

    r33963 r37822  
    183183}
    184184
     185// eddie uses cell_x = (int) (X + X_PAD) / (base + X_PAD)
     186// where base = 600, X_PAD = 8, Y_PAD = 10.  denominator is thus (608,610), whic is (4880/8),(4864/8)
     187// these match Eddie's NCELL_X,Y / CHIP_DX,DY, so I think we are good with this:
     188
     189# define X_PAD 8
     190# define Y_PAD 10
     191
    185192float FlatCorrectionOffset (FlatCorrectionTable *flatcorr, int ID, int X, int Y) {
    186193
     
    191198
    192199  // convert X,Y to Xbin, Ybin:
    193   int Xbin = MAX(MIN(X * flatcorr->image[seq].Nx / flatcorr->image[seq].DX, flatcorr->image[seq].Nx - 1), 0);
    194   int Ybin = MAX(MIN(Y * flatcorr->image[seq].Ny / flatcorr->image[seq].DY, flatcorr->image[seq].Ny - 1), 0);
     200  int Xbin = MAX(MIN((X + X_PAD) * flatcorr->image[seq].Nx / flatcorr->image[seq].DX, flatcorr->image[seq].Nx - 1), 0);
     201  int Ybin = MAX(MIN((Y + Y_PAD) * flatcorr->image[seq].Ny / flatcorr->image[seq].DY, flatcorr->image[seq].Ny - 1), 0);
    195202
    196203  // XXX warn if X,Y are out of range? not super important unless *way* out of range
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/mosaic_astrom.c

    r29938 r37822  
    11# include <dvo.h>
     2
     3//  the block of code below was used to define the chip->mosaic relationship before this
     4//  was assigned to the coords value
    25
    36off_t getDISentry (e_time start, e_time stop, e_time *startMos, off_t *indexMos, off_t Nmosaic);
    47void SortDISindex (e_time *S, off_t *I, off_t N);
     8
     9# if (0)
    510
    611/* chip-match table: j = ChipMatch[i], images[j] is DIS for images[i] WRP */
     
    9398}
    9499
    95 int BuildChipMatch_old (Image *images, off_t Nimages) {
     100// this is a very old version of BuildChipMatch which does not use bisection
     101int BuildChipMatch_nosort (Image *images, off_t Nimages) {
    96102
    97103  off_t i, j, NDIS;
     
    140146}
    141147
    142 int BuildChipMatch (Image *images, off_t Nimages) {
     148// this is an old version of BuildChipMatch which stores the results here in a local static variable
     149int BuildChipMatch_static (Image *images, off_t Nimages) {
    143150
    144151  off_t i, j, NDIS;
     
    198205  return (TRUE);
    199206}
    200 
     207# endif
     208
     209// XXX Note that this links (images[i].coords.mosaic, images[i].parent) will break
     210// if we reallocate the Image array in the middle of program
     211int BuildChipMatch (Image *images, off_t Nimages) {
     212
     213  off_t i, j, NDIS;
     214
     215  off_t  Ndis = 0;
     216  off_t  *DISentry = NULL;
     217  e_time *DIStzero = NULL;
     218
     219  if (DISentry != NULL) free (DISentry);
     220  if (DIStzero != NULL) free (DIStzero);
     221
     222  // allocate containers for DIS indexing
     223  Ndis = 0;
     224  NDIS = 100;
     225  ALLOCATE (DISentry, off_t, NDIS);
     226  ALLOCATE (DIStzero, e_time, NDIS);
     227
     228  // find all DIS images, save tzero (& photcode?)
     229  for (i = 0; i < Nimages; i++) {
     230    if (strcmp(&images[i].coords.ctype[4], "-DIS")) continue;
     231    DISentry[Ndis] = i;
     232    DIStzero[Ndis] = images[i].tzero;
     233    Ndis ++;
     234    if (Ndis >= NDIS) {
     235      NDIS += 100;
     236      REALLOCATE (DISentry, off_t, NDIS);
     237      REALLOCATE (DIStzero, e_time, NDIS);
     238    }
     239  }
     240
     241  // sort the index, start, and stop by the start times:
     242  SortDISindex (DIStzero, DISentry, Ndis);
     243
     244  /* find all matched WRP images */
     245  for (i = 0; i < Nimages; i++) {
     246    images[i].parent        = NULL; // reset to NULL
     247    images[i].coords.mosaic = NULL; // reset to NULL
     248    if (strcmp(&images[i].coords.ctype[4], "-WRP")) continue; // only define link for WRP coords
     249
     250    j = getDISentry (images[i].tzero, images[i].tzero + (int) images[i].exptime, DIStzero, DISentry, Ndis);
     251    if (j == -1) {
     252      fprintf (stderr, "WARNING: can't find matching mosaic \n");
     253      continue;
     254    }
     255    if (j >= Nimages) myAbort("invalid DIS entry");
     256    images[i].parent = &images[j];
     257    images[i].coords.mosaic = &images[j].coords;
     258  }
     259  return (TRUE);
     260}
     261
     262// use bisection to find the overlapping mosaic
    201263off_t getDISentry (e_time start, e_time stop, e_time *startMos, off_t *indexMos, off_t Nmosaic) {
    202 
    203   // use bisection to find the overlapping mosaic
    204264
    205265  off_t Nlo, Nhi, N;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/skyregion_gsc.c

    r34088 r37822  
    204204  for (i = 0; i < Nregions; i++) {
    205205    strncpy (temp, &buffer[i*48], 48);
    206     temp[49] = 0;
     206    temp[48] = 0;
    207207    hstgsc_hms_to_deg (&Rmin, &Rmax, &Dmin, &Dmax, &temp[7]);
    208208    if (Dmax < Dmin) SWAP (Dmin, Dmax);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libdvo/src/skyregion_ops.c

    r35102 r37822  
    1616  if (c) return (c+1);
    1717  return name;
     18}
     19
     20/* find region which corresponds to the given index */
     21SkyList *SkyRegionByIndex (SkyTable *table, int index) {
     22 
     23  SkyList *list;
     24
     25  ALLOCATE (list, SkyList, 1);
     26  ALLOCATE (list[0].regions,  SkyRegion *, 1);
     27  ALLOCATE (list[0].filename,  char *, 1);
     28  list[0].Nregions = 0;
     29  list[0].ownElements = FALSE; // this list is only holding a view to the elements
     30  strcpy (list[0].hosts, table[0].hosts);
     31
     32  list[0].regions[0] = &table[0].regions[index];
     33  list[0].filename[0] = table[0].filename[index];
     34  list[0].Nregions = 1;
     35  return (list);
    1836}
    1937
     
    250268  }
    251269
    252   if( Rmax > (Rmin+180.)) {
    253    
    254       double temp = Rmax;
    255       Rmax = Rmin;
    256       Rmin = temp;
    257   }
    258 
    259270  list = SkyListByBounds (table, depth, Rmin, Rmax, Dmin, Dmax);
    260   return (list);
    261 }
    262 
     271
     272  // fprintf (stderr, "%s : %f - %f, %f - %f : %d\n",
     273  // image->name, Rmin, Rmax, Dmin, Dmax, (int) list->Nregions);
     274
     275  return (list);
     276}
     277
     278// a region like -10 10 0 20 will become 350 10 0 20 and return all regions on both sides of 0,360
    263279SkyList *SkyListByBounds (SkyTable *table, int depth, double Rmin, double Rmax, double Dmin, double Dmax) {
    264280
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libfits/Makefile

    r34088 r37822  
    3232$(HEAD)/F_scan.$(ARCH).o                        $(HEAD)/F_print.$(ARCH).o     \
    3333$(HEAD)/F_copy_H.$(ARCH).o                      $(HEAD)/F_delete.$(ARCH).o    \
    34 $(HEAD)/F_read_XH.$(ARCH).o                     $(HEAD)/F_init_H.$(ARCH).o    \
    35 $(HEAD)/F_convert_H.$(ARCH).o                   $(HEAD)/version.$(ARCH).o
     34$(HEAD)/F_find_H.$(ARCH).o                      $(HEAD)/F_init_H.$(ARCH).o    \
     35$(HEAD)/F_convert_H.$(ARCH).o                   $(HEAD)/F_read_XH.$(ARCH).o   \
     36$(HEAD)/version.$(ARCH).o
    3637
    3738MATRIX_OBJ = \
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libfits/header/F_free_H.c

    r7054 r37822  
    44/*********************** fits free header ***********************************/
    55void gfits_free_header (Header *header) {
     6
     7  // fprintf (stderr, "free data for %zx\n", (size_t) header->buffer);
    68
    79  if (header[0].buffer == (char *) NULL) return;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libfits/include/gfitsio.h

    r37039 r37822  
    1717# define NEWLINE                 10  /* UNIX RETURN character */
    1818# endif /* NEWLINE */
     19
     20/* gfits_bintable_format returns 'byte' as the type associated with one-byte logical (non-char) values */
     21typedef char byte;
    1922
    2023/********** FITS Constants *********/
     
    116119int     gfits_modify_alt               PROTO((Header *header, char *field, char *mode, int N,...));
    117120int     gfits_print_alt                PROTO((Header *header, char *field, char *mode, int N,...));
     121int     gfits_find_Xheader             PROTO((FILE *f, Header *header, char *extname));
    118122int     gfits_read_Xheader             PROTO((char *filename, Header *header, int N));
    119123int     gfits_read_header              PROTO((char *filename, Header *header));
     
    184188int     gfits_fread_ftable             PROTO((FILE *f, FTable *ftable, char *extname));
    185189int     gfits_fread_ftable_data        PROTO((FILE *f, FTable *ftable, int padIfShort));
    186 int     gfits_fread_ftable_range       PROTO((FILE *f, FTable *ftable, off_t start, off_t Nrows));
     190int     gfits_fread_ftable_range       PROTO((FILE *f, int padIfShort, FTable *ftable, off_t start, off_t Nrows));
    187191int     gfits_fread_vtable             PROTO((FILE *f, VTable *vtable, char *extname, off_t Nrow, off_t *row));
    188192int     gfits_fread_vtable_range       PROTO((FILE *f, VTable *vtable, off_t start, off_t Nrows));
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libfits/table/F_read_T.c

    r29938 r37822  
    1919int gfits_fread_ftable (FILE *f, FTable *table, char *extname) {
    2020
    21   int j, found;
    22   off_t Nbytes;
    2321  Header *header;
    24   char tname[80];
    2522
    2623  header = table[0].header;
    27   fseeko (f, 0, SEEK_SET);
    28 
    29   found = FALSE;
    30   for (j = -1; !found; j++) {
    31     /* load data for this header */
    32     if (!gfits_load_header (f, header)) return (FALSE);
    33 
    34     /* check if this is the correct extension or not */
    35     bzero (tname, 80);
    36     gfits_scan (header, "EXTNAME", "%s", 1, tname);
    37     if (!strcmp (tname, extname)) {
    38       if (gfits_fread_ftable_data (f, table, FALSE)) return (TRUE);
    39       gfits_free_header (header);
    40       return (FALSE);
    41     }
    42 
    43     /* skip to next header */
    44     Nbytes = gfits_data_size (header);
    45     fseeko (f, Nbytes, SEEK_CUR);
    46     gfits_free_header (header);
    47   }
    48   return (TRUE);
    49 }       
     24  if (!gfits_find_Xheader (f, header, extname)) return FALSE;
     25
     26  if (gfits_fread_ftable_data (f, table, FALSE)) return (TRUE);
     27  gfits_free_header (header);
     28  return (FALSE);
     29}
    5030
    5131/*********************** fits read ftable data ***********************************/
     
    8464
    8565/*********************** fits read ftable data ***********************************/
    86 int gfits_fread_ftable_range (FILE *f, FTable *table, off_t start, off_t Nrows) {
     66int gfits_fread_ftable_range (FILE *f, int padIfShort, FTable *table, off_t start, off_t Nrows) {
    8767
    8868  off_t Nbytes, Nread, Nskip, Nx, Ny;
     
    10989    if (ferror (f)) {
    11090      perror ("fits read error");
     91      free (table[0].buffer);
     92      return (FALSE);
     93    }
     94    fprintf (stderr, "error: fits read error in %s, read "OFF_T_FMT", need "OFF_T_FMT"\n", __func__,  Nread,  Nbytes);
     95    if (padIfShort) {
     96      memset (&table[0].buffer[Nread], 0, Nbytes - Nread);
     97      fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n");
     98      table[0].validsize = Nread;
     99      table[0].datasize = Nbytes;
    111100    } else {
    112       fprintf (stderr, "unexpected eof\n");
    113     }     
    114     free (table[0].buffer);
    115     return (FALSE);
     101      free (table[0].buffer);
     102      return (FALSE);
     103    }
    116104  }
    117105
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libfits/table/F_write_T.c

    r28241 r37822  
    9595
    9696  // cursor must be at start of the table (after table header)
    97   fseeko (f, Nskip, SEEK_CUR);
     97  if (fseeko (f, Nskip, SEEK_CUR)) {
     98    fprintf (stderr, "can't seek table start\n");
     99    return (FALSE);
     100  }
     101
    98102  Nwrite = fwrite (ftable[0].buffer, sizeof (char), Nbytes, f);
    99103  if (Nwrite != Nbytes) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libkapa/src/KapaWindow.c

    r36488 r37822  
    9898  graphdata[0].lweight = graphdata[0].size = 1.0;
    9999   
    100   graphdata[0].coords.pc1_1 = graphdata[0].coords.pc2_2 = 1.0;
    101   graphdata[0].coords.pc1_2 = graphdata[0].coords.pc2_1 = 0.0;
    102   strcpy (graphdata[0].coords.ctype, "DEC--LIN");
    103   graphdata[0].coords.crval1 = 0.0;
    104   graphdata[0].coords.crval2 = 0.0;
    105   graphdata[0].coords.crpix1 = 0.0;
    106   graphdata[0].coords.crpix2 = 0.0;
    107   graphdata[0].coords.cdelt1 = graphdata[0].coords.cdelt2 = 1.0;
    108   graphdata[0].flipeast = TRUE;
     100  InitCoords (&graphdata[0].coords, "DEC--LIN");
     101  graphdata[0].flipeast = TRUE; // default coords has EW flipped relative to sky
    109102  graphdata[0].flipnorth = FALSE;
    110103
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libohana/Makefile

    r33646 r37822  
    3535$(SRC)/time.$(ARCH).o            \
    3636$(SRC)/gaussj.$(ARCH).o          \
     37$(SRC)/spherical.$(ARCH).o       \
     38$(SRC)/vstats.$(ARCH).o          \
    3739$(SRC)/config.$(ARCH).o          \
    3840$(SRC)/Fread.$(ARCH).o           \
     
    4547$(SRC)/gprint.$(ARCH).o  \
    4648$(SRC)/version.$(ARCH).o
     49
     50# $(SRC)/legendre.$(ARCH).o      \
     51# $(SRC)/gsl_utils.$(ARCH).o     \
    4752
    4853TYPETEST = \
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libohana/include/ohana.h

    r37033 r37822  
    192192
    193193# ifndef isfinite
    194 # define isfinite(A) (!isnan(A))
     194# define isfinite(A) (!isnan(A) && !isinf(A))
    195195# endif
    196196
     
    242242// sorting is now defined as a macro call
    243243# include <ohana_sort.h>
     244
     245// vector statistics options
     246typedef enum {
     247  VSTATS_NONE,
     248  VSTATS_MEAN,
     249  VSTATS_MEDIAN,
     250  VSTATS_WT_MEAN,
     251  VSTATS_INNER_MEAN,
     252  VSTATS_INNER_WTMEAN,
     253  VSTATS_CHI_INNER_MEAN,
     254  VSTATS_CHI_INNER_WTMEAN
     255} VStatsMode;
     256
     257typedef struct {
     258  double median;
     259  double mean;
     260  double sigma;
     261  double error;
     262  double chisq;
     263  double min;
     264  double max;
     265  double Upper80;
     266  double Lower20;
     267  double total;
     268  int    Nmeas;
     269  VStatsMode statmode;
     270} VStatsType;
    244271
    245272/* socket / pipe communication buffer */
     
    314341char   *ohana_version          PROTO((void));
    315342
     343int     dgaussjordan_pivot     PROTO((double **A, double **B, int N, int M, double minPivot));
    316344int     dgaussjordan           PROTO((double **A, double **B, int N, int M));
    317345int     fgaussjordan           PROTO((float **A, float **B, int n, int m));
     
    388416int rconnect (char *command, char *hostname, char *shell, int *stdio, int *errorInfo, int doHandshake);
    389417
     418int vstats_setmode (VStatsType *stats, char *mode);
     419int vstats_getstats (double *value, double *dvalue, double *weight, int N, VStatsType *stats);
     420int vstats_getstats_f (float *value, float *dvalue, float *weight, int N, VStatsType *stats);
     421
    390422/*
    391423#   define F_SETFL         4   
     
    404436*/
    405437
    406 # endif
     438
     439/** gsl-based functions for legendre and related polynomials **/
     440
     441double ohana_gsl_sf_log_1plusx (double x, double *err);
     442double ohana_gsl_sf_lnpoch(const double a, const double x, double *err);
     443double ohana_gsl_lnpoch_pos (const double a, const double x, double *err);
     444double ohana_gsl_pochrel_smallx(const double a, const double x, double *err);
     445
     446double legendre_Pl (int l, double x, double *err);
     447double legendre_Plm (int l, int m, double x, double *err);
     448double legendre_Plm_sphere(int l, int m, double x, double *err);
     449
     450typedef struct {
     451  double *Fr;
     452  double *Fi;
     453  int    *l;
     454  int    *m;
     455  int lmax;
     456  int Nterms;
     457} SHterms;
     458
     459SHterms *SHtermsInit (int lmax);
     460void SHtermsFree (SHterms *terms);
     461void SHtermsForRD (SHterms *terms, double R, double D);
     462void SHtermsForLM (SHterms *terms, double R, double D, int l, int m);
     463
     464typedef struct {
     465  double *dR_B;
     466  double *dR_E;
     467  double *dD_B;
     468  double *dD_E;
     469  int    *l;
     470  int    *m;
     471  int lmax;
     472  int Nterms;
     473} VSHterms;
     474
     475VSHterms *VSHtermsInit (int lmax);
     476void VSHtermsFree (VSHterms *terms);
     477void VSHtermsForRD (VSHterms *terms, double R, double D);
     478void VSHtermsForLM (VSHterms *terms, double R, double D, int l, int m);
     479
     480# endif
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libohana/src/gaussj.c

    r36084 r37822  
    11# include <ohana.h>
    22# define GROWTHTEST 0
    3 # define MAX_RANGE 1.0e9
     3# define VERY_VERBOSE 0
     4# define MAX_RANGE 1.0e16
    45
    56// Gauss-Jordan elimination using full pivots based on Press et al's description.  Substantially
     
    89// than their implementation.  (largely based on version by William Kahan)
    910
     11int dgaussjordan (double **A, double **B, int N, int M) {
     12
     13# define myMIN_PIVOT 1.0e-7
     14  int status = dgaussjordan_pivot (A, B, N, M, myMIN_PIVOT);
     15  return status;
     16}
     17
    1018// MAX_RANGE is used to test for ill-conditioned input matrices.  For an ill-conditioned
    1119// matrix, one or more of the pivots trends towards zero.  Rather than allow this to go to the
    1220// numerical precision, I am raising an error if |growth| > 1e8
    13 int dgaussjordan (double **A, double **B, int N, int M) {
     21int dgaussjordan_pivot (double **A, double **B, int N, int M, double MIN_PIVOT) {
    1422
    1523  int *colIndex;
     
    4856    // search for the next pivot
    4957    for (row = 0; row < N; row++) {
    50       if (!finite(A[row][diag])) goto escape;
     58      if (!finite(A[row][diag])) {
     59        fprintf (stderr, "infinity\n");
     60        goto escape;
     61      }
    5162
    5263      // if we have already operated on this row (pivot[row] is true), skip it
     
    6576# if (GROWTHTEST)
    6677    fprintf (stderr, "maxcol: %d\n", maxcol);
     78# if (VERY_VERBOSE)
    6779    fprintf (stderr, "full A matrix:\n");
    6880    for (row = 0; row < N; row++) {
    69         for (col = 0; col < N; col++) {
    70             fprintf (stderr, "%10.3e ", A[row][col]);
    71         }
    72         fprintf (stderr, "\n");
     81      for (col = 0; col < N; col++) {
     82        fprintf (stderr, "%10.3e ", A[row][col]);
     83      }
     84      fprintf (stderr, "\n");
    7385    }
    7486    fprintf (stderr, "\n");
    7587# endif
     88# endif
    7689
    7790    // if pivot[maxcol] is set, we have already done this row: this implies a singular matrix
    78     if (pivot[maxcol]) goto escape;
     91    if (pivot[maxcol]) {
     92      fprintf (stderr, "singular\n");
     93      goto escape;
     94    }
    7995    pivot[maxcol] = TRUE;
    8096
     
    86102    rowIndex[diag] = maxrow;
    87103    colIndex[diag] = maxcol;
    88     if (A[maxcol][maxcol] == 0.0) goto escape;
     104    if (A[maxcol][maxcol] == 0.0) {
     105      fprintf (stderr, "zero pivot\n");
     106      goto escape;
     107    }
     108
    89109    // XXX Kahan replaces the 0.0 pivot with epsilon*(largest element in column) + underFlow
    90110
    91111    /* rescale by pivot reciprocal */
    92112    double tmpval = 1.0 / A[maxcol][maxcol];
     113
     114# if (0)
     115    if (fabs(A[maxcol][maxcol]) < MIN_PIVOT) {
     116      // we are ill-conditioned.  set this row & col to 0.0, 1.0 on pivot
     117      // fprintf (stderr, "WARNING: eliminating degenerate pivot %lf @ A[%d][%d]\n", A[maxcol][maxcol], maxcol, maxcol);
     118      for (col = 0; col < N; col++) A[maxcol][col] = 0.0;
     119      for (col = 0; col < M; col++) B[maxcol][col] = 0.0;
     120      for (row = 0; row < N; row++) A[row][maxcol] = 0.0;
     121      A[maxcol][maxcol] = 1.0;
     122      continue;
     123    }
     124# endif
     125
    93126    // XXX why is this here (don't I double count this element?) A[maxcol][maxcol] = 1.0;
    94127    A[maxcol][maxcol] = 1.0;
     
    102135#   if (GROWTHTEST)
    103136    fprintf (stderr, "column: %d, maxval : %f, growth: %e, epsilon: %e\n", maxcol, tmpval, growth, epsilon);
     137# if (VERY_VERBOSE)
    104138    fprintf (stderr, "A diagonal: ");
    105139    for (col = 0; col < N; col++) fprintf (stderr, "%f ", A[col][col]);
    106140    fprintf (stderr, "\n");
    107141# endif
    108 
    109     if (fabs(growth) > MAX_RANGE) goto escape;
     142# endif
     143
     144    if (fabs(growth) > MAX_RANGE) {
     145      fprintf (stderr, "max range\n");
     146      goto escape;
     147    }
    110148
    111149    /* adjust the elements above the pivot */
     
    119157  }
    120158
    121 # if (GROWTHTEST)
    122     fprintf (stderr, "final A matrix:\n");
    123     for (row = 0; row < N; row++) {
    124         for (col = 0; col < N; col++) {
    125             fprintf (stderr, "%10.3e ", A[row][col]);
    126         }
    127         fprintf (stderr, "\n");
     159# if (GROWTHTEST && VERY_VERBOSE)
     160  fprintf (stderr, "final A matrix:\n");
     161  for (row = 0; row < N; row++) {
     162    for (col = 0; col < N; col++) {
     163      fprintf (stderr, "%10.3e ", A[row][col]);
    128164    }
    129165    fprintf (stderr, "\n");
     166  }
     167  fprintf (stderr, "\n");
    130168# endif
    131169
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libohana/src/glockfile.c

    r35754 r37822  
    288288
    289289    /* set value to IDLE */
    290     fseeko (flock, 0LL, SEEK_SET);
     290    if (fseeko (flock, 0LL, SEEK_SET)) {
     291      *state = LCK_HARDCLOSE;
     292      goto failure;
     293    }
     294
    291295    nbytes = fprintf (flock, "IDLE\n");
    292296    if (nbytes != 5) {
     
    303307 
    304308  /* now unlock the file */
    305   fclose (f);
     309  if (fclose (f)) {
     310    *state = LCK_UNKNOWN;
     311    goto failure;
     312  }
    306313
    307314  *state = LCK_UNLOCK;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/libohana/src/ohana_allocate.c

    r32632 r37822  
    178178  if (!in) return;
    179179
     180  // fprintf (stderr, "free %zx\n", (size_t) in);
     181
    180182  ref = (Memblock *) in - 1;
     183
     184  // fprintf (stderr, "  file: %s, line: %d, func: %s, size: %zd, addr: %zx\n",
     185  // ref->file, ref->line, ref->func, ref->size, (size_t) ref);
    181186
    182187  pthread_mutex_lock(&memBlockListMutex);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/markrock/src/gcatstats.c

    r36481 r37822  
    3434  /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
    3535  /* reference for coords is center of field  */
     36  InitCoords (&catstats[0].coords, "DEC--TAN");
    3637  catstats[0].coords.crval1 = RaCenter;
    3738  catstats[0].coords.crval2 = DecCenter;
    38   catstats[0].coords.crpix1 = catstats[0].coords.crpix2 = 0.0;
    3939  catstats[0].coords.cdelt1 = catstats[0].coords.cdelt2 = 1.0 / 3600.0;
    40   catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
    41   catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
    42   strcpy (catstats[0].coords.ctype, "DEC--TAN");
    43 
     40 
    4441  X1 = catstats[0].X;
    4542  Y1 = catstats[0].Y;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/markstar/src/gcatstats.c

    r36483 r37822  
    4444  /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
    4545  /* reference for coords is center of field  */
     46  InitCoords (&catstats[0].coords, "DEC--TAN");
    4647  catstats[0].coords.crval1 = RaCenter;
    4748  catstats[0].coords.crval2 = DecCenter;
    48   catstats[0].coords.crpix1 = catstats[0].coords.crpix2 = 0.0;
    4949  catstats[0].coords.cdelt1 = catstats[0].coords.cdelt2 = 1.0 / 3600.0;
    50   catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
    51   catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
    52   strcpy (catstats[0].coords.ctype, "DEC--TAN");
    5350
    5451  X1 = catstats[0].X;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/mosastro/src/chips.c

    r7401 r37822  
    2121
    2222    /* bore site center guess */
    23     strcpy (chip[i].map.ctype, "DEC--PLY");
    24     chip[i].map.crpix1 = 0.0;
    25     chip[i].map.crpix2 = 0.0;
    26     chip[i].map.cdelt1 = 1.0;
    27     chip[i].map.cdelt2 = 1.0;
     23    InitCoords (&chip[i].map, "DEC--PLY");
    2824
    2925    /* find (L,M) coords of reference pixel (0,0) */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/mosastro/src/fakefield.c

    r3401 r37822  
    2222
    2323  /* bore site center guess */
    24   strcpy (field.project.ctype, "DEC--TAN");
    25   field.project.crpix1 = 0;
    26   field.project.crpix2 = 0;
     24  InitCoords (&field.project, "DEC--TAN");
    2725 
    2826  /* set TP plate scale */
     
    3028  field.project.cdelt2 = 1.0/3600.0;
    3129
    32   /** allow guess at field rotation?? **/
    33   field.project.pc1_1  = 1;
    34   field.project.pc2_2  = 1;
    35   field.project.pc1_2  = 0;
    36   field.project.pc2_1  = 0;
    37   field.project.Npolyterms = 1;
    38 
    3930  /** distort only has power in polyterms **/
    40   strcpy (field.distort.ctype, "DEC--PLY");
    41   field.distort.crval1 = 0.0;
    42   field.distort.crval2 = 0.0;
    43   field.distort.crpix1 = 0.0;
    44   field.distort.crpix2 = 0.0;
    45   field.distort.cdelt1 = 1.0;
    46   field.distort.cdelt2 = 1.0;
    47  
    48   field.distort.pc1_1  = 1;
    49   field.distort.pc2_2  = 1;
    50   field.distort.pc1_2  = 0;
    51   field.distort.pc2_1  = 0;
    52 
    53   /* how do we handle renormalization? (fixed at 1000 pixels??) */
    54   field.distort.Npolyterms = 3;
    55   for (i = 0; i < 7; i++) {
    56     field.distort.polyterms[i][0] = 0;
    57     field.distort.polyterms[i][1] = 0;
    58   }
     31  InitCoords (&field.distort, "DEC--PLY");
    5932
    6033  return (1);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/mosastro/src/field.c

    r7401 r37822  
    1212
    1313  /* bore site center guess */
    14   strcpy (field.project.ctype, "DEC--TAN");
     14  InitCoords (&field.project, "DEC--TAN");
    1515
    1616  # if (PSASTRO_MODE)
     
    2323  # endif
    2424
    25   field.project.crpix1 = 0;
    26   field.project.crpix2 = 0;
    27  
    2825  /* measure average plate scale - would be better using parabolic min... */
    2926  field.project.cdelt1 = 0;
     
    4744           3600*field.project.cdelt1, 3600*field.project.cdelt2);
    4845
    49   /** allow guess at field rotation?? **/
    50   field.project.pc1_1  = 1;
    51   field.project.pc2_2  = 1;
    52   field.project.pc1_2  = 0;
    53   field.project.pc2_1  = 0;
    54   field.project.Npolyterms = 1;
    55 
    5646  /* bore site center guess */
    57   strcpy (field.distort.ctype, "DEC--PLY");
    58   field.distort.crval1 = 0.0;
    59   field.distort.crval2 = 0.0;
    60   field.distort.crpix1 = 0.0;
    61   field.distort.crpix2 = 0.0;
    62   field.distort.cdelt1 = 1.0;
    63   field.distort.cdelt2 = 1.0;
    64  
    65   /** allow guess at field rotation?? **/
    66   field.distort.pc1_1  = 1;
    67   field.distort.pc2_2  = 1;
    68   field.distort.pc1_2  = 0;
    69   field.distort.pc2_1  = 0;
    70 
    71   /* allow 2nd and 3rd order? */
    72   /* how do we handle renormalization? (fixed at 1000 pixels??) */
    73   field.distort.Npolyterms = 1;
    74   for (i = 0; i < 7; i++) {
    75     field.distort.polyterms[i][0] = 0;
    76     field.distort.polyterms[i][1] = 0;
    77   }
     47  InitCoords (&field.distort, "DEC--PLY");
    7848  return (TRUE);
    7949}
     
    138108int load_field (char *filename) {
    139109
    140   int i;
    141110  Coords coords;
    142111  Header header;
     
    156125
    157126  /* bore site center guess */
    158   strcpy (field.project.ctype, "DEC--TAN");
     127  InitCoords (&field.project, "DEC--TAN");
    159128  field.project.crval1 = 0.5*(field.Rmin + field.Rmax);
    160129  field.project.crval2 = 0.5*(field.Dmin + field.Dmax);
    161   field.project.crpix1 = 0;
    162   field.project.crpix2 = 0;
    163130 
    164131  /* measure average plate scale - would be better using parabolic min... */
     
    174141
    175142  /* bore site center guess */
    176   strcpy (field.distort.ctype, "DEC--PLY");
    177   field.distort.crval1 = 0.0;
    178   field.distort.crval2 = 0.0;
    179   field.distort.crpix1 = 0.0;
    180   field.distort.crpix2 = 0.0;
    181   field.distort.cdelt1 = 1.0;
    182   field.distort.cdelt2 = 1.0;
    183  
    184   /** allow guess at field rotation?? **/
    185   field.distort.pc1_1  = 1;
    186   field.distort.pc2_2  = 1;
    187   field.distort.pc1_2  = 0;
    188   field.distort.pc2_1  = 0;
     143  InitCoords (&field.distort, "DEC--PLY");
    189144
    190   /* allow 2nd and 3rd order? */
    191   /* how do we handle renormalization? (fixed at 1000 pixels??) */
    192   field.distort.Npolyterms = coords.Npolyterms;
    193   for (i = 0; i < 7; i++) {
    194     field.distort.polyterms[i][0] = coords.polyterms[i][0];
    195     field.distort.polyterms[i][1] = coords.polyterms[i][1];
    196   }
    197145  return (TRUE);
    198146}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/mosastro/src/fitpoly.c

    r16058 r37822  
    130130  double R;
    131131
     132  InitCoords (coords, "DEC--PLY");
     133
    132134  /* update the higher order terms */
    133135  if (NORDER > 1) {
     
    166168
    167169  coords[0].Npolyterms = NORDER;
    168   strcpy (coords[0].ctype, "DEC--PLY");
    169170}
    170171
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/mosastro/src/mkobs.c

    r7080 r37822  
    104104
    105105      /* Chip-Sky terms */
    106       strcpy (coords.ctype, "DEC--WRP");
     106      InitCoords (&coords, "DEC--WRP");
    107107      coords.crval1 = Ro;
    108108      coords.crval2 = Do;
     
    124124      }
    125125
    126       coords.pc1_1  = 1;
    127       coords.pc2_2  = 1;
    128       coords.pc1_2  = 0;
    129       coords.pc2_1  = 0;
    130       coords.Npolyterms = 1;
    131 
    132126      header = mkheader (2*dX, 2*dY, Nstars, &coords);
    133127
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/mosastro/src/mkstandards.c

    r7080 r37822  
    3232
    3333  /* bore site center guess */
    34   strcpy (coords.ctype, "DEC--TAN");
     34  InitCoords (&coords, "DEC--TAN");
    3535  coords.crval1 = atof(argv[1]);
    3636  coords.crval2 = atof(argv[2]);
    3737  coords.crpix1 = dX;
    3838  coords.crpix2 = dX;
    39  
    4039  coords.cdelt1 = 1/3600.0;
    4140  coords.cdelt2 = 1/3600.0;
    42 
    43   coords.pc1_1  = 1;
    44   coords.pc2_2  = 1;
    45   coords.pc1_2  = 0;
    46   coords.pc2_1  = 0;
    47   coords.Npolyterms = 1;
    4841
    4942  if (Random) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/mosastro/src/testcoords.c

    r3404 r37822  
    5353    exit (1);
    5454  }
    55   RegisterMosaic (&field.project);
     55
     56  chip[0].map.mosaic = &field.project;
    5657  strcpy (chip[0].map.ctype, "DEC--WRP");
    5758  for (i = 0; i < chip[0].Nmatch; i++) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.astro/Makefile

    r36489 r37822  
    7171$(SRC)/star.$(ARCH).o              \
    7272$(SRC)/transform.$(ARCH).o         \
     73$(SRC)/vshimage.$(ARCH).o         \
     74$(SRC)/shimage.$(ARCH).o         \
    7375$(SRC)/imsub.$(ARCH).o             \
    7476$(SRC)/imfit.$(ARCH).o             \
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.astro/cdensify.c

    r36489 r37822  
    9797  // generate the PSF in a local tangent plane
    9898  Coords coords;
    99   coords.crpix1 = coords.crpix2 = 0.0;
    100   coords.crval1 = coords.crval2 = 0.0;
    101   coords.cdelt1 = coords.cdelt2 = 1.0;
    102   coords.pc1_1  = coords.pc2_2  = 1.0;
    103   coords.pc1_2  = coords.pc2_1  = 0.0;
    104   coords.Npolyterms = 0;
    105   strcpy (coords.ctype, "DEC--TAN");
     99  InitCoords (&coords, "DEC--TAN");
    106100
    107101  r = vr[0].elements.Flt;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.astro/coords.c

    r33662 r37822  
    7171    if ((mosbuffer = SelectBuffer (MOSAIC, OLDBUFFER, TRUE)) == NULL) goto escape;
    7272    GetCoords (&moscoords, &mosbuffer[0].header);
    73     RegisterMosaic (&moscoords);
     73    coords.mosaic = &moscoords;
    7474  }
    7575 
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.astro/cplot.c

    r34613 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.astro/csystem.c

    r34342 r37822  
    1313  if (argc != 5) goto syntax;
    1414
    15   switch (argv[1][0]) {
    16     case 'C': input = COORD_CELESTIAL; break;
    17     case 'G': input = COORD_GALACTIC; break;
    18     case 'E': input = COORD_ECLIPTIC; break;
    19     default: goto syntax;
     15  if (!strcmp(argv[1], "G2004")) {
     16    input = COORD_GALACTIC_REID_2004;
     17  } else {
     18    switch (argv[1][0]) {
     19      case 'C': input = COORD_CELESTIAL; break;
     20      case 'G': input = COORD_GALACTIC; break;
     21      case 'E': input = COORD_ECLIPTIC; break;
     22      default: goto syntax;
     23    }
    2024  }
    2125
    22   switch (argv[2][0]) {
    23     case 'C': output = COORD_CELESTIAL; break;
    24     case 'G': output = COORD_GALACTIC; break;
    25     case 'E': output = COORD_ECLIPTIC; break;
    26     default: goto syntax;
     26  if (!strcmp(argv[2], "G2004")) {
     27    output = COORD_GALACTIC_REID_2004;
     28  } else {
     29    switch (argv[2][0]) {
     30      case 'C': output = COORD_CELESTIAL; break;
     31      case 'G': output = COORD_GALACTIC; break;
     32      case 'E': output = COORD_ECLIPTIC; break;
     33      default: goto syntax;
     34    }
    2735  }
    2836
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.astro/fitplx.c

    r36489 r37822  
    104104  /* project coordinates to a plane centered on the object with units of arcsec */
    105105  Coords coords;
     106  InitCoords (&coords, "DEC--SIN");
    106107  coords.crval1 = Rmean;
    107108  coords.crval2 = Dmean;
    108   coords.crpix1 = 0;
    109   coords.crpix2 = 0;
    110109  coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
    111   coords.pc1_1  = coords.pc2_2 = 1.0;
    112   coords.pc1_2  = coords.pc2_1 = 0.0;
    113   coords.Npolyterms = 1;
    114   strcpy (coords.ctype, "DEC--SIN");
    115110
    116111  double *X, *Y, *t, *pX, *pY, *dX, *dY;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.astro/fitpm.c

    r36489 r37822  
    100100  /* project coordinates to a plane centered on the object with units of arcsec */
    101101  Coords coords;
     102  InitCoords (&coords, "DEC--SIN");
    102103  coords.crval1 = Rmean;
    103104  coords.crval2 = Dmean;
    104   coords.crpix1 = 0;
    105   coords.crpix2 = 0;
    106105  coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
    107   coords.pc1_1  = coords.pc2_2 = 1.0;
    108   coords.pc1_2  = coords.pc2_1 = 0.0;
    109   coords.Npolyterms = 1;
    110   strcpy (coords.ctype, "DEC--SIN");
    111106
    112107  double *X, *Y, *t, *dX, *dY;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.astro/gauss.c

    r36679 r37822  
    3030  if (!GetImageData (&data, &kapa, name)) return (FALSE);
    3131  FREE (name);
     32
     33  int channel = 0;
     34  if ((N = get_argument (argc, argv, "-ch"))) {
     35    channel = GetKapaChannelFromString (argv[N]);
     36    if (!channel) return FALSE;
     37    KiiSetChannel (kapa, channel - 1);
     38  }
    3239
    3340  Nborder = 3;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.astro/getcoords.c

    r34345 r37822  
    5454  if (!strcmp(&coords.ctype[4], "-WRP")) {
    5555    if (MOSAIC == NULL) {
    56       gprint (GP_ERR, "must supply mosaic for WRP coords\n");
     56      gprint (GP_ERR, "must supply mosaic for WRP coords with -mosaic [buffer]\n");
    5757      return (FALSE);
    5858    }
     
    6565    }
    6666    GetCoords (&moscoords, &mosbuffer[0].header);
    67     RegisterMosaic (&moscoords);
     67    coords.mosaic = &moscoords;
    6868  }
    6969 
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.astro/init.c

    r36489 r37822  
    6161int times                   PROTO((int, char **));
    6262int transform               PROTO((int, char **));
     63int vshimage                PROTO((int, char **));
     64int shimage                 PROTO((int, char **));
    6365
    6466static Command cmds[] = { 
     
    121123  {1, "star",        star,         "star stats at rough coords"},
    122124  {1, "transform",   transform,    "geometric transformation of image"},
     125  {1, "vshimage",    vshimage,     "generate images for vector spherical harmonic terms"},
     126  {1, "shimage",     shimage,      "generate images for spherical harmonic terms"},
    123127};
    124128
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.astro/objload.c

    r34088 r37822  
    1919  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    2020  FREE (name);
     21
     22  int channel = 0;
     23  if ((N = get_argument (argc, argv, "-ch"))) {
     24    channel = GetKapaChannelFromString (argv[N]);
     25    if (!channel) return FALSE;
     26    KiiSetChannel (kapa, channel - 1);
     27  }
    2128
    2229  Objtype = 0;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.astro/region.c

    r36489 r37822  
    1717  if (!GetGraph (&graphmode, &kapa, name)) return (FALSE);
    1818  FREE (name);
     19
     20  int channel = 0;
     21  if ((N = get_argument (argc, argv, "-ch"))) {
     22    channel = GetKapaChannelFromString (argv[N]);
     23    if (!channel) return FALSE;
     24    KiiSetChannel (kapa, channel - 1);
     25  }
    1926
    2027  NoClear = FALSE;
     
    8087  if (!ohana_str_to_radec (&Ra, &Dec, argv[1], argv[2])) return (FALSE);
    8188  Radius = atof (argv[3]);
    82   strcpy (graphmode.coords.ctype, "DEC--TAN");
     89  InitCoords (&graphmode.coords, "DEC--TAN");
     90
    8391  if (argc == 5) {
    8492    if (!strcasecmp (argv[4], "TAN"))
     
    99107      strcpy (graphmode.coords.ctype, "DEC--PAR");
    100108  }
     109 
     110  graphmode.coords.crval1 = Ra;
     111  graphmode.coords.crval2 = Dec;
    101112
    102  
     113  graphmode.coords.pc1_1 = (graphmode.flipeast) ? -1 : 1;
     114  graphmode.coords.pc2_2 = (graphmode.flipnorth) ? -1 : 1;
     115
    103116  /* ask kapa for coordinate limits, to get the right aspect ratio */
    104117  KapaGetLimits (kapa, &dx, &dy);
     
    132145  set_int_variable ("NORTH_UP", !graphmode.flipnorth);
    133146
    134   graphmode.coords.pc1_1 = (graphmode.flipeast) ? -1 : 1;
    135   graphmode.coords.pc2_2 = (graphmode.flipnorth) ? -1 : 1;
    136 
    137   graphmode.coords.pc1_2 = graphmode.coords.pc2_1 = 0.0;
    138   graphmode.coords.crval1 = Ra;
    139   graphmode.coords.crval2 = Dec;
    140   graphmode.coords.crpix1 = 0.0;
    141   graphmode.coords.crpix2 = 0.0;
    142   graphmode.coords.cdelt1 = graphmode.coords.cdelt2 = 1.0;
    143 
    144147  if (!NoClear) KapaClearSections (kapa);
    145148  KapaSetLimits (kapa, &graphmode);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/Makefile

    r37049 r37822  
    3939$(SRC)/densify.$(ARCH).o        \
    4040$(SRC)/device.$(ARCH).o \
     41$(SRC)/dft2d.$(ARCH).o  \
    4142$(SRC)/dimendown.$(ARCH).o      \
    4243$(SRC)/dimenup.$(ARCH).o        \
     
    160161$(SRC)/vstats.$(ARCH).o            \
    161162$(SRC)/xsection.$(ARCH).o          \
     163$(SRC)/vsh.$(ARCH).o       \
     164$(SRC)/vshfit.$(ARCH).o    \
     165$(SRC)/shterms.$(ARCH).o           \
     166$(SRC)/shfit.$(ARCH).o     \
     167$(SRC)/shdot.$(ARCH).o     \
     168$(SRC)/shapply.$(ARCH).o           \
    162169$(SRC)/wd.$(ARCH).o                \
    163170$(SRC)/write_vectors.$(ARCH).o     \
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/center.c

    r29540 r37822  
    1616  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    1717  FREE (name);
     18
     19  int channel = 0;
     20  if ((N = get_argument (argc, argv, "-ch"))) {
     21    channel = GetKapaChannelFromString (argv[N]);
     22    if (!channel) return FALSE;
     23    KiiSetChannel (kapa, channel - 1);
     24  }
    1825
    1926  // XXX need an option to center the image based on the current plot limits
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/dimenup.c

    r20936 r37822  
    2323    return (FALSE);
    2424  }
    25 
    26   gfits_free_matrix (&buf[0].matrix);
    27   gfits_free_header (&buf[0].header);
    28   CreateBuffer (buf, Nx, Ny, -32, 0.0, 1.0);
     25  ResetBuffer (buf, Nx, Ny, -32, 0.0, 1.0);
    2926
    3027  out = (float *) buf[0].matrix.buffer;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/erase.c

    r13479 r37822  
    1515  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    1616  FREE (name);
     17
     18  int channel = 0;
     19  if ((N = get_argument (argc, argv, "-ch"))) {
     20    channel = GetKapaChannelFromString (argv[N]);
     21    if (!channel) return FALSE;
     22    KiiSetChannel (kapa, channel - 1);
     23  }
    1724
    1825  if (argc < 2) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/fit2d.c

    r31160 r37822  
    138138    y = yvec[0].elements.Flt;
    139139    z = zvec[0].elements.Flt;
     140    if (Weight) dz = dzvec[0].elements.Flt;
     141
    140142    for (i = 0; i < xvec[0].Nelements; i++, x++, y++, z++) {
    141143      if (mask[i]) continue;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/init.c

    r37049 r37822  
    11# include "data.h"
     2// XXX adding a comment
    23
    34int accum            PROTO((int, char **));
     
    3132int densify          PROTO((int, char **));
    3233int device           PROTO((int, char **));
     34int dft2d            PROTO((int, char **));
    3335int dimendown        PROTO((int, char **));
    3436int dimenup          PROTO((int, char **));
     
    147149int vpop             PROTO((int, char **));
    148150int vsmooth          PROTO((int, char **));
     151int vsh              PROTO((int, char **));
     152int vshfit           PROTO((int, char **));
     153int shterms          PROTO((int, char **));
     154int shfit            PROTO((int, char **));
     155int shdot            PROTO((int, char **));
     156int shapply          PROTO((int, char **));
    149157int wd               PROTO((int, char **));
    150158int write_vectors    PROTO((int, char **));
     
    189197  {1, "densify",      densify,          "create an image histogram from a set of vectors"},
    190198  {1, "device",       device,           "set / get current graphics device"},
     199  {1, "dft2d",        dft2d,            "2D discrete fourier transform"},
    191200  {1, "dimendown",    dimendown,        "convert image to vector"},
    192201  {1, "dimenup",      dimenup,          "convert vector to image"},
     
    314323  {1, "vstats",       vstats,           "statistics on a vector"},
    315324  {1, "vzload",       vzload,           "load vectors as overlay on image display (scaled points)"},
     325  {1, "vsh",          vsh,              "Vector Spherical Harmonics"},
     326  {1, "vshfit",       vshfit,           "Vector Spherical Harmonics fits"},
     327  {1, "shterms",      shterms,          "Spherical Harmonics terms"},
     328  {1, "shfit",        shfit,            "Spherical Harmonics fits"},
     329  {1, "shdot",        shdot,            "Spherical Harmonics dot product"},
     330  {1, "shapply",      shapply,          "Spherical Harmonics fit application"},
    316331  {1, "wd",           wd,               "write an image to a file"},
    317332  {1, "write",        write_vectors,    "write vectors to datafile"},
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/load.c

    r34088 r37822  
    2323  if (!GetImageData (&data, &kapa, name)) return (FALSE);
    2424  FREE (name);
     25
     26  int channel = 0;
     27  if ((N = get_argument (argc, argv, "-ch"))) {
     28    channel = GetKapaChannelFromString (argv[N]);
     29    if (!channel) return FALSE;
     30    KiiSetChannel (kapa, channel - 1);
     31  }
    2532
    2633  ISCEL = FALSE;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/point.c

    r15620 r37822  
    2121  if (!GetImageData (&data, &kapa, name)) return (FALSE);
    2222  FREE (name);
     23
     24  int channel = 0;
     25  if ((N = get_argument (argc, argv, "-ch"))) {
     26    channel = GetKapaChannelFromString (argv[N]);
     27    if (!channel) return FALSE;
     28    KiiSetChannel (kapa, channel - 1);
     29  }
    2330
    2431  celestial = FALSE;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/read_vectors.c

    r37049 r37822  
    55
    66void read_vectors_cleanup ();
     7int read_table_sizes (Header *header);
    78
    89int datafile (int argc, char **argv) {
     
    331332
    332333  off_t Nbytes;
    333   int i, j, N, Nextend, Ny, Binary, vecType, padIfShort;
    334   char type[16], ID[80], *CCDKeyword;
     334  int i, j, N, Ny, Binary, vecType;
     335  char type[16], ID[80];
    335336  FTable table;
    336337  Header header;
    337338  Vector **vec;
    338   int FITS_TRANSPOSE;
    339339
    340340  table.buffer = NULL;
    341341  header.buffer = NULL;
    342342
    343   FITS_TRANSPOSE = FALSE;
     343  int FITS_TRANSPOSE = FALSE;
    344344  if ((N = get_argument (argc, argv, "-transpose"))) {
    345345    remove_argument (N, &argc, argv);
     
    347347  }
    348348
    349   CCDKeyword = NULL;
     349  char *CCDKeyword = NULL;
    350350  if ((N = get_argument (argc, argv, "-keyword"))) {
    351351    remove_argument (N, &argc, argv);
     
    354354  }
    355355
    356   padIfShort = FALSE;
     356  int padIfShort = FALSE;
    357357  if ((N = get_argument (argc, argv, "-pad-if-short"))) {
    358358    remove_argument (N, &argc, argv);
     
    360360  }
    361361
    362   Nextend = -1;
     362  int getSizes = FALSE;
     363  if ((N = get_argument (argc, argv, "-sizes"))) {
     364    remove_argument (N, &argc, argv);
     365    getSizes = TRUE;
     366  }
     367
     368  int Nextend = -1;
    363369  if ((N = get_argument (argc, argv, "-extnum"))) {
    364370    remove_argument (N, &argc, argv);
    365371    Nextend = atoi (extname);
     372  }
     373
     374  int start = 0;
     375  int Nrows = -1; // -1 : read entire table
     376  if ((N = get_argument (argc, argv, "-range"))) {
     377    remove_argument (N, &argc, argv);
     378    start = atoi (argv[N]);
     379    remove_argument (N, &argc, argv);
     380    Nrows = atoi (argv[N]);
     381    remove_argument (N, &argc, argv);
     382  }
     383
     384  // if CharAsVectors, char fields will be saved as vectors NAME:0 -- NAME:n for n characters
     385  // else char fields will be saved as $NAME:0 - $NAME:m for m rows
     386  // if (Ny > 10000), force CharAsVectors
     387  int CharAsVectors = FALSE;
     388  if ((N = get_argument (argc, argv, "-char-vectors"))) {
     389    remove_argument (N, &argc, argv);
     390    CharAsVectors = TRUE;
    366391  }
    367392
     
    397422    }
    398423    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);
    400 
     424
     425    if (getSizes) {
     426      read_table_sizes (&header);
     427      if (CCDKeyword != NULL) free (CCDKeyword);
     428      gfits_free_header (&header);
     429      return TRUE;
     430    }
     431
     432    if (Nrows == -1) {
     433      Nrows = header.Naxis[1] - start;
     434    }
     435    if (start < 0) ESCAPE ("invalid range: start < 0\n");
     436    if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]);
     437    if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
     438    if (start + Nrows > header.Naxis[1]) ESCAPE ("invalid range: start + Nrows > Ny (%d)\n", header.Naxis[1]);
     439
     440    // Ny = 100, start = 0, Nrows = -1 -> Nrows => 100
     441    // Ny = 100, start = 10, Nrows = 90
     442
     443    if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);
    401444  } else {
    402445    if (CCDKeyword == NULL) {
     
    428471        continue;
    429472      }
    430       if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension\n");
     473
     474      if (Nrows == -1) {
     475        Nrows = header.Naxis[1] - start;
     476      }
     477      if (start < 0) ESCAPE ("invalid range: start < 0\n");
     478      if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]);
     479      if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
     480      if (start + Nrows > header.Naxis[1]) ESCAPE ("invalid range: start + Nrows > Ny (%d)\n", header.Naxis[1]);
     481
     482      if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);
     483
     484      // if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension\n");
     485
    431486      break;
    432487    }
     
    465520    if (!FITS_TRANSPOSE) {
    466521      // read string column into a list rather than a vector
    467       if (!strcmp (type, "char")) {
     522      if (!strcmp (type, "char") && !CharAsVectors && (Ny < 3000)) {
    468523        char *fieldName = argv[i];
    469524        char *Ptr = data;
     
    537592  if (vec) free (vec);
    538593}
     594
     595// read -fits foo -sizes -- Nx, Ny, Nfields -> $table:Nx, $table:Ny, $table:$Nfields
     596// read -fits foo -fields
     597
     598int read_table_sizes (Header *header) {
     599 
     600  int Nfields;
     601
     602  gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
     603
     604  set_int_variable ("table:Nx", header->Naxis[0]);
     605  set_int_variable ("table:Nx", header->Naxis[0]);
     606  set_int_variable ("table:Nfields", Nfields);
     607
     608  return TRUE;
     609}
     610
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/relocate.c

    r27435 r37822  
    1717  FREE (name);
    1818
     19  int channel = 0;
     20  if ((N = get_argument (argc, argv, "-ch"))) {
     21    channel = GetKapaChannelFromString (argv[N]);
     22    if (!channel) return FALSE;
     23    KiiSetChannel (kapa, channel - 1);
     24  }
     25
    1926  if (argc != 3) {
    2027    gprint (GP_ERR, "USAGE: relocate x y [-n]\n");
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/resize.c

    r29938 r37822  
    1717  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    1818  FREE (name);
     19
     20  int channel = 0;
     21  if ((N = get_argument (argc, argv, "-ch"))) {
     22    channel = GetKapaChannelFromString (argv[N]);
     23    if (!channel) return FALSE;
     24    KiiSetChannel (kapa, channel - 1);
     25  }
    1926
    2027  if ((N = get_argument (argc, argv, "-by-image"))) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/save.c

    r13479 r37822  
    1616  FREE (name);
    1717
     18  int channel = 0;
     19  if ((N = get_argument (argc, argv, "-ch"))) {
     20    channel = GetKapaChannelFromString (argv[N]);
     21    if (!channel) return FALSE;
     22    KiiSetChannel (kapa, channel - 1);
     23  }
     24
    1825  celestial = FALSE;
    1926  if ((N = get_argument (argc, argv, "-c"))) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/tv.c

    r35757 r37822  
    1818  if (!GetImage (&data, &kapa, name)) return (FALSE);
    1919  FREE (name);
     20
     21  int channel = 0;
     22  if ((N = get_argument (argc, argv, "-ch"))) {
     23    remove_argument (N, &argc, argv);
     24    channel = GetKapaChannelFromString (argv[N]);
     25    remove_argument (N, &argc, argv);
     26    if (!channel) return FALSE;
     27    KiiSetChannel (kapa, channel - 1);
     28  }
    2029
    2130  /* shell exits on pipe close, FIX */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/tvchannel.c

    r16038 r37822  
    2222  }
    2323
    24   Nchannel = atoi (argv[1]);
     24  Nchannel = GetKapaChannelFromString (argv[1]);
     25  if (!Nchannel) return FALSE;
     26
     27  KiiSetChannel (kapa, Nchannel - 1);
     28  return (TRUE);
     29}
     30
     31int GetKapaChannelFromString (char *string) {
     32
     33  int Nchannel = atoi (string);
    2534  if (Nchannel == 0) {
    2635    // try the string values R/Red, G/Green, B/Blue
    27     if (!strcasecmp (argv[1], "R") || !strcasecmp (argv[1], "RED")) {
     36    if (!strcasecmp (string, "R") || !strcasecmp (string, "RED")) {
    2837      Nchannel = 1;
    2938    }
    30     if (!strcasecmp (argv[1], "G") || !strcasecmp (argv[1], "GREEN")) {
     39    if (!strcasecmp (string, "G") || !strcasecmp (string, "GREEN")) {
    3140      Nchannel = 2;
    3241    }
    33     if (!strcasecmp (argv[1], "B") || !strcasecmp (argv[1], "BLUE")) {
     42    if (!strcasecmp (string, "B") || !strcasecmp (string, "BLUE")) {
    3443      Nchannel = 3;
    3544    }
    3645  }
    37   if ((Nchannel < 1) || (Nchannel > 3)) {
    38     gprint (GP_ERR, "invalid channel : use 1 - 3 or (R)ed, (G)reen, (B)lue\n");
    39     return (FALSE);
     46  if ((Nchannel < 1) || (Nchannel > 10)) {
     47    gprint (GP_ERR, "invalid channel : use 1 - 10 or (R)ed, (G)reen, (B)lue\n");
     48    gprint (GP_ERR, "   (R)ed, (G)reen, (B)lue == (1,2,3)\n");
     49    return (0);
    4050  }
    41    
    42   KiiSetChannel (kapa, Nchannel - 1);
    43   return (TRUE);
     51  return Nchannel;
    4452}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/tvcontour.c

    r13479 r37822  
    7171  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    7272  FREE (name);
     73
     74  int channel = 0;
     75  if ((N = get_argument (argc, argv, "-ch"))) {
     76    channel = GetKapaChannelFromString (argv[N]);
     77    if (!channel) return FALSE;
     78    KiiSetChannel (kapa, channel - 1);
     79  }
    7380
    7481  if ((argc != 4) && (argc != 5)) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/tvgrid.c

    r13479 r37822  
    2424  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    2525  FREE (name);
     26
     27  int channel = 0;
     28  if ((N = get_argument (argc, argv, "-ch"))) {
     29    channel = GetKapaChannelFromString (argv[N]);
     30    if (!channel) return FALSE;
     31    KiiSetChannel (kapa, channel - 1);
     32  }
    2633
    2734  if (argc != 3) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/vload.c

    r20936 r37822  
    1818  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    1919  FREE (name);
     20
     21  int channel = 0;
     22  if ((N = get_argument (argc, argv, "-ch"))) {
     23    channel = GetKapaChannelFromString (argv[N]);
     24    if (!channel) return FALSE;
     25    KiiSetChannel (kapa, channel - 1);
     26  }
    2027
    2128  type = KII_OVERLAY_BOX;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/cmd.data/vzload.c

    r20936 r37822  
    1818  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    1919  FREE (name);
     20
     21  int channel = 0;
     22  if ((N = get_argument (argc, argv, "-ch"))) {
     23    channel = GetKapaChannelFromString (argv[N]);
     24    if (!channel) return FALSE;
     25    KiiSetChannel (kapa, channel - 1);
     26  }
    2027
    2128  MAX_OUTPUT_SIZE = 10.0;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/Makefile

    r37049 r37822  
    4646$(SRC)/badimages.$(ARCH).o              \
    4747$(SRC)/catdir.$(ARCH).o                 \
     48$(SRC)/catname.$(ARCH).o                \
    4849$(SRC)/cmatch.$(ARCH).o         \
    4950$(SRC)/cmpload.$(ARCH).o                \
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/avextract.c

    r37049 r37822  
    55  off_t i, j, n, m;
    66  int N, Npts, NPTS, last, next, state, Nfields, Nreturn, Ncstack, Nstack;
    7   int Nsecfilt, VERBOSE, needMeasures;
     7  int Nsecfilt, VERBOSE;
    88  char **cstack, name[1024];
    99  void *Signal;
     
    137137  // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
    138138  if (PARALLEL && !HOST_ID) {
    139       int status = HostTableParallelOps (skylist, argc, argv, RESULT_FILE, TRUE, 0, VERBOSE);
     139    int status = HostTableParallelOps (skylist, argc, argv, RESULT_FILE, TRUE, 0, VERBOSE);
    140140
    141141    dbFreeFields (fields, Nfields);
     
    163163  }
    164164
    165   // check the requested fields : are all average/secfilt entries, or do we need measures?
    166   needMeasures = FALSE;
    167   for (i = 0; !needMeasures && (i < Nfields); i++) {
    168     if (fields[i].photcode == NULL) continue; // non-measure fields do not have a photcode
    169     if (fields[i].photcode[0].type == PHOT_REF) needMeasures = TRUE;
    170     if (fields[i].photcode[0].type == PHOT_DEP) needMeasures = TRUE;
    171   }
     165  // check the requested fields
     166  int needMeasure = dbFieldNeedMeasure (fields, Nfields);
     167  int needLensobj = dbFieldNeedLensobj (fields, Nfields);
     168  int needStarpar = dbFieldNeedStarpar (fields, Nfields, TRUE);
    172169
    173170  // grab data from all selected sky regions
     
    189186    catalog.filename = (HOST_ID || PARALLEL_LOCAL) ? hostfile : skylist[0].filename[i];
    190187    catalog.catflags = LOAD_AVES | LOAD_SECF;
    191     catalog.catflags |= needMeasures ? LOAD_MEAS : SKIP_MEAS;
     188    catalog.catflags |= needMeasure ? LOAD_MEAS : SKIP_MEAS;
     189    catalog.catflags |= needLensobj ? LOAD_LENSOBJ : SKIP_LENSOBJ;
     190    catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
    192191    catalog.Nsecfilt = 0;
    193192
     
    205204      // XXX for measure values, this could be optimized for one loop over measures...
    206205
    207       m = catalog.average[j].measureOffset;
    208 
    209206      dbExtractAveragesInitAve ();  // reset counters for saved fields (costs very little)
    210207
     208      Average *average = &catalog.average[j];
     209
     210      m = average->measureOffset;
     211      Measure *measure = needMeasure ? &catalog.measure[m] : NULL;
     212
     213      m = average->lensobjOffset;
     214      Lensobj *lensobj = needLensobj ? &catalog.lensobj[m] : NULL;
     215
     216      m = average->starparOffset;
     217      StarPar *starpar = needStarpar ? &catalog.starpar[m] : NULL;
     218
     219      m = j*Nsecfilt;
     220      SecFilt *secfilt = &catalog.secfilt[m];
     221
    211222      for (n = 0; n < Nfields; n++) {
    212         values[n] = dbExtractAverages (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]);
     223        values[n] = dbExtractAverages (average, secfilt, measure, lensobj, starpar, &fields[n]);
    213224      }
    214225
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/avmatch.c

    r37049 r37822  
    149149  }
    150150
    151   // check the requested fields : are all average/secfilt entries, or do we need measures?
    152   int needMeasures = FALSE;
    153   for (i = 0; !needMeasures && (i < Nfields); i++) {
    154     if (fields[i].photcode == NULL) continue; // assert this?
    155     if (fields[i].photcode[0].type == PHOT_REF) needMeasures = TRUE;
    156     if (fields[i].photcode[0].type == PHOT_DEP) needMeasures = TRUE;
    157   }
     151  // check the requested fields
     152  int needMeasure = dbFieldNeedMeasure (fields, Nfields);
     153  int needLensobj = dbFieldNeedLensobj (fields, Nfields);
     154  int needStarpar = dbFieldNeedStarpar (fields, Nfields, TRUE);
    158155
    159156  /* create output storage vectors */
     
    194191    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
    195192    catalog.catflags = LOAD_AVES | LOAD_SECF;
    196     catalog.catflags |= needMeasures ? LOAD_MEAS : SKIP_MEAS;
     193    catalog.catflags |= needMeasure ? LOAD_MEAS    : SKIP_MEAS;
     194    catalog.catflags |= needLensobj ? LOAD_LENSOBJ : SKIP_LENSOBJ;
     195    catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
    197196    catalog.Nsecfilt = 0;
    198197
     
    219218      if (Ncat == -2) continue; // no matches to this point
    220219
    221       m = catalog.average[Ncat].measureOffset;
     220      m = Ncat;
     221      Average *average = &catalog.average[m];
     222
     223      m = average->measureOffset;
     224      Measure *measure = needMeasure ? &catalog.measure[m] : NULL;
     225
     226      m = average->lensobjOffset;
     227      Lensobj *lensobj = needLensobj ? &catalog.lensobj[m] : NULL;
     228
     229      m = average->starparOffset;
     230      StarPar *starpar = needStarpar ? &catalog.starpar[m] : NULL;
     231
     232      m = Ncat*Nsecfilt;
     233      SecFilt *secfilt = &catalog.secfilt[m];
    222234
    223235      // reset counters for saved fields, extract fields
    224236      dbExtractAveragesInitAve ();
    225237      for (n = 0; n < Nfields; n++) {
    226         values[n] = dbExtractAverages (&catalog.average[Ncat], &catalog.secfilt[Ncat*Nsecfilt], &catalog.measure[m], &fields[n]);
     238        values[n] = dbExtractAverages (average, secfilt, measure, lensobj, starpar, &fields[n]);
    227239      }
    228240
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/cmpload.c

    r34088 r37822  
    2424  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    2525  FREE (name);
     26
     27  int channel = 0;
     28  if ((N = get_argument (argc, argv, "-ch"))) {
     29    channel = GetKapaChannelFromString (argv[N]);
     30    if (!channel) return FALSE;
     31    KiiSetChannel (kapa, channel - 1);
     32  }
    2633
    2734  Objtype = 0;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/dvo_host_utils.c

    r35416 r37822  
    137137
    138138  // determine the sky region
     139  // XXX EAM 20141230 : this needs to respect the -region selection
    139140  double Rmin, Rmax, Dmin, Dmax;
    140141  get_skyregion (&Rmin, &Rmax, &Dmin, &Dmax);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/find_matches.c

    r36489 r37822  
    3838   * far from the projection pole. We use the center of the region (catalog) for crval1,2.
    3939   */
     40  InitCoords (&tcoords, "DEC--ARC");
    4041  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    4142  if (region[0].Dmax < 90) {
     
    4445    tcoords.crval2 = 90.0;
    4546  }
    46   tcoords.crpix1 = 0;
    47   tcoords.crpix2 = 0;
    4847  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    49   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    50   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    51   tcoords.Npolyterms = 1;
    52   strcpy (tcoords.ctype, "DEC--ARC");
    5348
    5449  // this region includes a boundary layer of size RADIUS
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/gimages.c

    r36489 r37822  
    8585  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (FALSE);
    8686  image_subset (image, Nimage, &subset, &Nsubset, selection, tzero, trange, TimeSelect);
    87   BuildChipMatch (image, Nimage);
     87  // BuildChipMatch (image, Nimage);
    8888
    8989  int DistortImage = wordhash ("-DIS");
     
    102102      }
    103103    }     
    104     if (!FindMosaicForImage (image, Nimage, i)) continue;
    105104
    106105    typehash = wordhash (&image[i].coords.ctype[4]);
     
    129128      if (fabs(Ro - Ra) > 120.0) continue;
    130129
     130      InitCoords (&local, "DEC--TAN");
    131131      local.crval1 = Ro;
    132132      local.crval2 = Do;
    133       local.crpix1 = local.crpix2 = 0.0;
    134133      local.cdelt1 = local.cdelt2 = 1.0/3600.0;
    135       local.pc1_1 = local.pc2_2 = 1.0;
    136       local.pc2_1 = local.pc1_2 = 0.0;
    137       local.Npolyterms = 1;
    138       strcpy (local.ctype, "DEC--TAN");
    139134
    140135      if (typehash == DistortImage) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/gstar.c

    r37049 r37822  
    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 
     374        }
     375
     376        if (EXTRA_OUTPUT) {
    309377          /* Mmin */
     378          gprint (GP_LOG, "chp_psf_min: ");
    310379          for (j = 0; j < Nsecfilt; j++) printPhotcodeSequence (&catalog.average[k], &catalog.secfilt[Nsecfilt*k], j, GSTAR_AVE_MAG_MIN);
    311380          gprint (GP_LOG, "\n");
    312381
    313382          /* Mmax */
     383          gprint (GP_LOG, "chp_psf_max: ");
    314384          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
     
    413609
    414610            if (FULL_OUTPUT) {
    415                 gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Mcal);
    416                 gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Map);
    417                 gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Mkron);
    418                 gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].dMkron);
    419                 gprint (GP_LOG, "%5.1f ", pow(10.0, 0.4*catalog.measure[Nv].dt));
    420                 gprint (GP_LOG, "%5.3f ", catalog.measure[Nv].airmass);
    421                 gprint (GP_LOG, "%6.1f ", catalog.measure[Nv].az);
    422                 gprint (GP_LOG, "%6.1f ", catalog.measure[Nv].Xccd);
    423                 gprint (GP_LOG, "%6.1f ", catalog.measure[Nv].Yccd);
    424                 gprint (GP_LOG, "%3.1f ", FromShortPixels(catalog.measure[Nv].dXccd));
    425                 gprint (GP_LOG, "%3.1f ", FromShortPixels(catalog.measure[Nv].dYccd));
    426                 gprint (GP_LOG, "%6.1f ", catalog.measure[Nv].Sky);
    427                 gprint (GP_LOG, "%5.1f ", catalog.measure[Nv].dSky);
    428                 gprint (GP_LOG, "%8d ", catalog.measure[Nv].averef);
    429                 gprint (GP_LOG, "0x%08x ", catalog.measure[Nv].detID);
    430                 gprint (GP_LOG, "0x%08x ", catalog.measure[Nv].imageID);
    431                 gprint (GP_LOG, "%.3f ", catalog.measure[Nv].psfQF);
    432                 gprint (GP_LOG, "%.1f ", catalog.measure[Nv].psfChisq);
    433                 gprint (GP_LOG, "%.1f ", catalog.measure[Nv].crNsigma);
    434                 gprint (GP_LOG, "%.1f ", catalog.measure[Nv].extNsigma);
    435                 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));
    436632            }
    437             if (STACK_OUTPUT) {
    438                 gprint (GP_LOG, "%10.3e ", catalog.measure[Nv].FluxPSF);
    439                 gprint (GP_LOG, "%10.3e ", catalog.measure[Nv].dFluxPSF);
    440                 gprint (GP_LOG, "%10.3e ", catalog.measure[Nv].FluxKron);
    441                 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);
    442638            }
    443639            gprint (GP_LOG, "\n");
     
    547743
    548744  switch (type) {
    549     case GSTAR_AVE_MAG: /* average mags */
    550       if (seq == -1) {
    551         print_double (NAN);
    552       } else {
    553         print_double (secfilt[seq].M);
    554       }
    555       break;
    556 
    557     case GSTAR_AVE_MAG_ERR: /* average mags errors */
    558       if (seq == -1) {
    559         print_double (NAN);
    560       } else {
    561         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);
    562758      }
    563759      break;
     
    592788      break;
    593789
     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
    594808    case GSTAR_AVE_AP_MAG: /* average ap mags */
    595809      if (seq == -1) {
     
    600814      break;
    601815
    602     case GSTAR_AVE_MAG_MIN: /* average ap mags */
    603       if (seq == -1) {
    604         print_double (NAN);
    605       } else {
    606         print_double (secfilt[seq].Mmin);
    607       }
    608       break;
    609 
    610     case GSTAR_AVE_MAG_MAX: /* average ap mags */
    611       if (seq == -1) {
    612         print_double (NAN);
    613       } else {
    614         print_double (secfilt[seq].Mmax);
    615       }
    616       break;
    617 
    618816    case GSTAR_AVE_KRON_MAG: /* average ap mags */
    619817      if (seq == -1) {
     
    632830      break;
    633831
     832      /******************* STACK : FLUX **********************/
     833
    634834    case GSTAR_STACK_FLUX_PSF: /* average ap mags */
    635835      if (seq == -1) {
     
    664864      break;
    665865
     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);
     1029      }
     1030      break;
     1031
    6661032  }
    6671033}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/images.c

    r34584 r37822  
    131131  /* it is not an error for the database not to have any images */
    132132  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (TRUE);
    133   BuildChipMatch (image, Nimage);
     133  // BuildChipMatch (image, Nimage);
    134134
    135135  if (SOLO_MOSAIC && photcode) {
     
    152152  SetVector (&Yvec, OPIHI_FLT, NPTS);
    153153
     154  Image *mosaic = NULL;
     155
    154156  ALLOCATE (plist, int, NPTS);
    155157  n = N = 0;
     
    157159    if (ByName && strncmp (image[i].name, name, strlen(name))) continue;
    158160    if (TimeSelect && ((image[i].tzero < tzero) || (image[i].tzero+image[i].trate*image[i].NY > tzero + trange))) continue;
    159     if (!(Nmosaic = FindMosaicForImage (image, Nimage, i))) continue;
    160     Nmosaic --; // XXX kind of a hack: FindMosaicForImage returns 0 or the mosaic seq number + 1
     161
     162    mosaic = image[i].parent;
     163    Nmosaic = (SOLO_MOSAIC && mosaic) ? mosaic - image : -1;
     164
    161165    if (photcode) {
    162166      if ( photcodeEquiv && (photcode[0].code != GetPhotcodeEquivCodebyCode(image[i].photcode))) continue;
     
    170174    typehash = wordhash (&image[i].coords.ctype[4]);
    171175
    172     if (photcode && SOLO_MOSAIC) {
     176    if (photcode && SOLO_MOSAIC && (Nmosaic >= 0)) {
    173177      // mosaic (DIS) images are not currently given a photcode : plot these via the WRP entries
    174178      /* DIS images represent a field, not a chip */
    175179      if (typehash != ChipImage) continue;
    176180      if (foundMosaic[Nmosaic]) continue;
    177       x[0] = -0.5*image[Nmosaic].NX; y[0] = -0.5*image[Nmosaic].NY;
    178       x[1] = +0.5*image[Nmosaic].NX; y[1] = -0.5*image[Nmosaic].NY;
    179       x[2] = +0.5*image[Nmosaic].NX; y[2] = +0.5*image[Nmosaic].NY;
    180       x[3] = -0.5*image[Nmosaic].NX; y[3] = +0.5*image[Nmosaic].NY;
     181      x[0] = -0.5*mosaic->NX; y[0] = -0.5*mosaic->NY;
     182      x[1] = +0.5*mosaic->NX; y[1] = -0.5*mosaic->NY;
     183      x[2] = +0.5*mosaic->NX; y[2] = +0.5*mosaic->NY;
     184      x[3] = -0.5*mosaic->NX; y[3] = +0.5*mosaic->NY;
    181185      for (j = 0; j < Npts; j++) {
    182         status = XY_to_RD (&r[j], &d[j], x[j], y[j], &image[Nmosaic].coords);
     186        status = XY_to_RD (&r[j], &d[j], x[j], y[j], &mosaic->coords);
    183187        if (!status) break;
    184188        r[j] = ohana_normalize_angle (r[j]);
     
    198202
    199203    /* DIS images represent a field, not a chip */
    200     if ((typehash == DistortImage) && !WITH_MOSAIC) continue;
    201     if ((typehash != DistortImage) &&  SOLO_MOSAIC) continue;
     204    if ((typehash == DistortImage) && !WITH_MOSAIC) continue; // do not plot the mosaic images
     205    if ((typehash != DistortImage) &&  SOLO_MOSAIC) continue; // plot only the mosaic images
     206
    202207    if (typehash == DistortImage) {
    203208      x[0] = -0.5*image[i].NX; y[0] = -0.5*image[i].NY;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/imbox.c

    r34584 r37822  
    4343  SetVector (&Yvec, OPIHI_FLT, NPTS);
    4444
     45  mosaic.ctype[0] = 0; 
     46
    4547  while (gfits_fread_header (f, &header)) {
    4648    if (!GetCoords (&coords, &header)) goto skip;
    4749    if (!SOLO_PHU && !strcmp (&coords.ctype[4], "-DIS")) {
    4850      mosaic = coords;
    49       RegisterMosaic (&mosaic);
    5051      goto skip;
     52    }
     53    if (!strcmp (&coords.ctype[4], "-WRP")) {
     54      if (!mosaic.ctype[0]) {
     55        fprintf (stderr, "PHU mosaic not found\n");
     56        return FALSE;
     57      }
     58      coords.mosaic = &mosaic;
    5159    }
    5260
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/imdata.c

    r37049 r37822  
    8787  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (FALSE);
    8888  image_subset (image, Nimage, &subset, &Nsubset, selection, tzero, trange, TimeSelect);
    89   BuildChipMatch (image, Nimage);
     89  // BuildChipMatch (image, Nimage);
    9090  GetTimeFormat (&TimeReference, &TimeFormat);
    9191
     
    103103    I = subset[i];
    104104
    105     if (!FindMosaicForImage (image, Nimage, I)) continue;
    106105    skyset = SkyListByImage (sky, -1, &image[I]);
    107106
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/imdense.c

    r34584 r37822  
    2222
    2323  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (FALSE);
    24   BuildChipMatch (image, Nimage);
     24  // BuildChipMatch (image, Nimage);
    2525
    2626  Rmin = graphmode.coords.crval1 - 182.0;
     
    4242    /* project this image to screen display coords */
    4343    status = FALSE;
    44     if (!FindMosaicForImage (image, Nimage, i)) continue;
    4544    XY_to_RD (&r, &d, x, y, &image[i].coords);
    4645    r = ohana_normalize_angle (r);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/imextract.c

    r37049 r37822  
    9090
    9191  if ((image = LoadImagesDVO (&Nimage)) == NULL) goto escape;
    92   BuildChipMatch (image, Nimage);
     92  // BuildChipMatch (image, Nimage);
    9393  dbExtractImagesInit ();
    9494
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/imlist.c

    r34088 r37822  
    3838  }
    3939
    40   // int RegionSelect = FALSE;
    41   // if ((N = get_argument (argc, argv, "-region"))) {
    42   //   remove_argument (N, &argc, argv);
    43   //   RegionSelect = TRUE;
    44   // }
    45 
    4640  PhotcodeValue = NULL;
    4741  PhotcodeSelect = FALSE;
     
    7670  }
    7771
     72  int MAX_LIST = -1;
     73  if ((N = get_argument (argc, argv, "-max-list"))) {
     74    remove_argument (N, &argc, argv);
     75    MAX_LIST = atoi (argv[N]);
     76    remove_argument (N, &argc, argv);
     77  }
     78
    7879  if (argc != 1) {
    79     gprint (GP_ERR, "USAGE: image [-time start range] [-region] [-name string]\n");
     80    gprint (GP_ERR, "USAGE: image [-time start range] [-region] [-name string] [-photcode code] [-Nphotcode N] [-max-list N]\n");
    8081    return (FALSE);
    8182  }
     
    8384  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (FALSE);
    8485  image_subset (image, Nimage, &subset, &Nsubset, selection, tzero, trange, TimeSelect);
    85   BuildChipMatch (image, Nimage);
     86  MAX_LIST = MAX_LIST < 0 ? Nsubset : MIN(MAX_LIST, Nsubset);
    8687
    8788  GetTimeFormat (&TimeReference, &TimeFormat);
    8889
    89   for (j = 0; j < Nsubset; j++) {
     90  for (j = 0; j < MAX_LIST; j++) {
    9091    i = subset[j];
    9192    if (NameSelect && (strstr (image[i].name, name) == (char *) NULL)) continue;
     
    9798      }
    9899    }
    99     if (!FindMosaicForImage (image, Nimage, i)) continue;
    100100    t = TimeValue (image[i].tzero, TimeReference, TimeFormat);
    101101    if (!strcmp(&image[i].coords.ctype[4], "-DIS")) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/imstats.c

    r34584 r37822  
    3131
    3232  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (FALSE);
    33   BuildChipMatch (image, Nimage);
     33  // BuildChipMatch (image, Nimage);
    3434
    3535  /* assign vector values */
     
    4444    else
    4545      Yvec.elements.Flt[i] = image[i].dMcal;
    46     if (!FindMosaicForImage (image, Nimage, i)) continue;
    4746    XY_to_RD (&r, &d, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
    4847    gprint (GP_ERR, "%d %8.4f %8.4f %10d %6d  %5.3f %6.3f %6.3f\n",
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/init.c

    r37049 r37822  
    77int calmextract     PROTO((int, char **));
    88int catlog          PROTO((int, char **));
     9int catname         PROTO((int, char **));
    910int catdir_define   PROTO((int, char **));
    1011int ccd             PROTO((int, char **));
     
    6869//  {1, "calextract",  calextract,   "extract photometry calibration"},
    6970//  {1, "calmextract", calmextract,  "extract photometry calibration"},
     71  {1, "catname",     catname,      "list catalog files by name"},
    7072  {1, "catdir",      catdir_define,"re-define CATDIR"},
    7173//  {1, "ccd",         ccd,          "plot color-color diagram"},
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/mextract.c

    r35416 r37822  
    211211  }
    212212
     213  // int needLensing = dbFieldNeedLensing (fields, Nfields);
     214  int needStarpar = dbFieldNeedStarpar (fields, Nfields, FALSE);
     215
    213216  // grab data from all selected sky regions
    214217  Signal = signal (SIGINT, handle_interrupt);
     
    227230    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
    228231    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     232    // catalog.catflags |= needLensing ? LOAD_LENSING : SKIP_LENSING;
     233    catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
    229234    catalog.Nsecfilt = Nsecfilt;
    230235
     
    259264        // extract the relevant values for this measurement
    260265        dbExtractMeasuresInitMeas (); // reset counters for saved fields  (costs very little
     266
     267        Average *average = &catalog.average[j];
     268
     269        int Nstarpar = average->starparOffset;
     270        StarPar *starpar = needStarpar ? &catalog.starpar[Nstarpar] : NULL;
     271
     272        // int Nlensing = average->lensobjOffset;
     273        // Lensobj *lensobj = needLensobj ? &catalog.lensobj[m] : NULL;
     274
     275        int Nsec = j*Nsecfilt;
     276        SecFilt *secfilt = &catalog.secfilt[Nsec];
     277
    261278        for (n = 0; n < Nfields; n++) {
    262           values[n] = dbExtractMeasures (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]);
     279          values[n] = dbExtractMeasures (average, secfilt, &catalog.measure[m], NULL, starpar, &fields[n]);
    263280        }
    264281        // fprintf (stderr, "object: ave: %f, cat: %f, averef %d\n", fields[n].name, values[2], values[3], catalog.measure[m].averef);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/mmatch.c

    r35416 r37822  
    233233  ALLOCATE (index, off_t, Nelem);
    234234
     235  // int needLensing = dbFieldNeedLensing (fields, Nfields);
     236  int needStarpar = dbFieldNeedStarpar (fields, Nfields, FALSE);
     237
    235238  // grab data from all selected sky regions
    236239  Signal = signal (SIGINT, handle_interrupt);
     
    246249    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
    247250    catalog.catflags = LOAD_AVES | LOAD_SECF | LOAD_MEAS;
     251    catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
    248252    catalog.Nsecfilt = Nsecfilt;
    249253
     
    282286        // extract the relevant values for this measurement
    283287        dbExtractMeasuresInitMeas (); // reset counters for saved fields  (costs very little
     288
     289        Average *average = &catalog.average[Ncat];
     290
     291        int Nstarpar = average->starparOffset;
     292        StarPar *starpar = needStarpar ? &catalog.starpar[Nstarpar] : NULL;
     293
     294        // int Nlensing = average->lensobjOffset;
     295        // Lensobj *lensobj = needLensobj ? &catalog.lensobj[m] : NULL;
     296
     297        int Nsec = Ncat*Nsecfilt;
     298        SecFilt *secfilt = &catalog.secfilt[Nsec];
     299
    284300        for (n = 0; n < Nfields; n++) {
    285           values[n] = dbExtractMeasures (&catalog.average[Ncat], &catalog.secfilt[Ncat*Nsecfilt], &catalog.measure[m], &fields[n]);
     301          values[n] = dbExtractMeasures (average, secfilt, &catalog.measure[m], NULL, starpar, &fields[n]);
    286302        }
    287303
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/mmextract.c

    r35263 r37822  
    174174  }
    175175
     176  // int needLensing = dbFieldNeedLensing (fields, Nfields);
     177  int needStarpar = dbFieldNeedStarpar (fields, Nfields, FALSE);
     178
    176179  // grab data from all selected sky regions
    177180  Signal = signal (SIGINT, handle_interrupt);
     
    213216        // extract the relevant values for this measurement
    214217        dbExtractMeasuresInitMeas (); // reset counters for saved fields
     218
     219        Average *average = &catalog.average[j];
     220
     221        int Nstarpar = average->starparOffset;
     222        StarPar *starpar = needStarpar ? &catalog.starpar[Nstarpar] : NULL;
     223
     224        // int Nlensing = average->lensobjOffset;
     225        // Lensobj *lensobj = needLensobj ? &catalog.lensobj[m] : NULL;
     226
     227        int Nsec = j*Nsecfilt;
     228        SecFilt *secfilt = &catalog.secfilt[Nsec];
     229
    215230        for (n = 0; n < Nfields; n++) {
    216231          // values needs to be a pointer to a type with FLT and INT (with a union, we would save a bit of memory...)
    217           values[n] = dbExtractMeasures (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]);
     232          values[n] = dbExtractMeasures (average, secfilt, &catalog.measure[m], NULL, starpar, &fields[n]);
    218233        }
    219234        // fprintf (stderr, "object: ave: %f, cat: %f, averef %d\n", fields[n].name, values[2], values[3], catalog.measure[m].averef);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/objectcoverage.c

    r34088 r37822  
    147147  strcpy (buf[0].file, "(empty)");
    148148
     149  InitCoords (&coords, projection);
    149150  coords.crval1 = RaCenter;
    150151  coords.crval2 = DecCenter;
    151152  coords.crpix1 = 0.5*Nx;
    152153  coords.crpix2 = 0.5*Ny;
    153   strcpy (coords.ctype, projection);
    154   coords.pc1_1 = -1.0;
     154  coords.pc1_1 = -1.0; // sky parity
    155155  coords.pc2_2 = +1.0;
    156   coords.pc1_2 =  0.0;
    157   coords.pc2_1 =  0.0;
    158156  coords.cdelt1 = coords.cdelt2 = pixscale;
    159   coords.Npolyterms = 0;
    160157
    161158  PutCoords (&coords, &buf[0].header);
     
    166163    for (xs = 0; xs < Nx; xs++) {
    167164      status = XY_to_RD (&r, &d, (double)(xs), (double)(ys), &coords);
    168       status &= (r >= 0);
    169       status &= (r <= 360);
     165      r = ohana_normalize_angle (r);
    170166      if (status) {
    171167        V[ys*Nx + xs] = ShowDensity ?  0 : 2;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/showtile.c

    r36489 r37822  
    2828
    2929  /* reference for coords is this image */
    30   coords.crpix1 = coords.crpix2 = 0.0;
    31   coords.crval1 = coords.crval2 = 0.0;
    32   coords.cdelt1 = coords.cdelt2 = 1.0;
    33   coords.pc1_1  = coords.pc2_2  = 1.0;
    34   coords.pc1_2  = coords.pc2_1  = 0.0;
    35   coords.Npolyterms = 0;
    36   strcpy (coords.ctype, "DEC--TAN");
     30  InitCoords (&coords, "DEC--TAN");
    3731 
    3832  /* fill in top-left region */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/simage.c

    r36489 r37822  
    4242  }
    4343  /* get astrometry information */
    44   strcpy (coords.ctype, "NONE");
    45   gfits_scan (&header, "CTYPE2",   "%s",  1, coords.ctype);
    46   if (strcmp (coords.ctype, "DEC--PLY")) {
    47     gprint (GP_ERR, "ERROR: wrong astrometric info in header\n");
     44  if (!GetCoords (&coords, &header)) {
     45    gprint (GP_ERR, "ERROR: can't get coord info from header\n");
    4846    return (FALSE);
    4947  }
    50   gfits_scan (&header, "CDELT1",   "%f", 1, &coords.cdelt1);
    51   gfits_scan (&header, "CDELT2",   "%f", 1, &coords.cdelt2);
    52   gfits_scan (&header, "CRVAL1",   "%lf", 1, &coords.crval1);
    53   gfits_scan (&header, "CRVAL2",   "%lf", 1, &coords.crval2); 
    54   gfits_scan (&header, "CRPIX1",   "%f", 1, &coords.crpix1);
    55   gfits_scan (&header, "CRPIX2",   "%f", 1, &coords.crpix2);
    56   gfits_scan (&header, "PC001001", "%f", 1, &coords.pc1_1);
    57   gfits_scan (&header, "PC001002", "%f", 1, &coords.pc1_2);
    58   gfits_scan (&header, "PC002001", "%f", 1, &coords.pc2_1);
    59   gfits_scan (&header, "PC002002", "%f", 1, &coords.pc2_2);
    60   /* RA Terms */
    61   gfits_scan (&header, "PCA1X2Y0", "%f", 1, &coords.polyterms[0][0]);
    62   gfits_scan (&header, "PCA1X1Y1", "%f", 1, &coords.polyterms[1][0]);
    63   gfits_scan (&header, "PCA1X0Y2", "%f", 1, &coords.polyterms[2][0]);
    64   gfits_scan (&header, "PCA1X3Y0", "%f", 1, &coords.polyterms[3][0]);
    65   gfits_scan (&header, "PCA1X2Y1", "%f", 1, &coords.polyterms[4][0]);
    66   gfits_scan (&header, "PCA1X1Y2", "%f", 1, &coords.polyterms[5][0]);
    67   gfits_scan (&header, "PCA1X0Y3", "%f", 1, &coords.polyterms[6][0]);
    68   /* Dec Terms */                           
    69   gfits_scan (&header, "PCA2X2Y0", "%f", 1, &coords.polyterms[0][1]);
    70   gfits_scan (&header, "PCA2X1Y1", "%f", 1, &coords.polyterms[1][1]);
    71   gfits_scan (&header, "PCA2X0Y2", "%f", 1, &coords.polyterms[2][1]);
    72   gfits_scan (&header, "PCA2X3Y0", "%f", 1, &coords.polyterms[3][1]);
    73   gfits_scan (&header, "PCA2X2Y1", "%f", 1, &coords.polyterms[4][1]);
    74   gfits_scan (&header, "PCA2X1Y2", "%f", 1, &coords.polyterms[5][1]);
    75   gfits_scan (&header, "PCA2X0Y3", "%f", 1, &coords.polyterms[6][1]);
    76   coords.Npolyterms = 2; /* how many do we use? */
    7748
    7849  /* find number of stars */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/skycoverage.c

    r33963 r37822  
    204204  strcpy (buf[0].file, "(empty)");
    205205
     206  InitCoords (&coords, projection);
    206207  coords.crval1 = RaCenter;
    207208  coords.crval2 = DecCenter;
    208209  coords.crpix1 = 0.5*Nx;
    209210  coords.crpix2 = 0.5*Ny;
    210   strcpy (coords.ctype, projection);
    211   coords.pc1_1 = -1.0;
     211  coords.pc1_1 = -1.0; // sky parity
    212212  coords.pc2_2 = +1.0;
    213   coords.pc1_2 =  0.0;
    214   coords.pc2_1 =  0.0;
    215213  coords.cdelt1 = coords.cdelt2 = pixscale;
    216   coords.Npolyterms = 0;
    217214
    218215  PutCoords (&coords, &buf[0].header);
     
    222219      return (FALSE);
    223220  }
    224   BuildChipMatch (image, Nimage);
     221  // BuildChipMatch (image, Nimage);
    225222
    226223  V = (float *)buf[0].matrix.buffer;
     
    230227    for (xs = 0; xs < Nx; xs++) {
    231228      status = XY_to_RD (&r, &d, (double)(xs), (double)(ys), &coords);
    232       status &= (r >= 0);
    233       status &= (r <= 360);
     229      r = ohana_normalize_angle (r);
     230
    234231      // are we in a part of the projection covering the sky or not?
    235232      if (status) {
     
    284281      }
    285282    }
    286 
    287     if (!FindMosaicForImage (image, Nimage, i)) continue;
    288283
    289284    typehash = wordhash (&image[i].coords.ctype[4]);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/dvo/subpix.c

    r37049 r37822  
    115115  /* load all images, extract those touching Ra, Dec */
    116116  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (FALSE);
    117   BuildChipMatch (image, Nimage);
     117  // BuildChipMatch (image, Nimage);
    118118
    119119  for (i = 0; i < Nimage; i++) {
    120     if (!FindMosaicForImage (image, Nimage, i)) continue;
    121120    status = RD_to_XY (&X, &Y, Ra, Dec, &image[i].coords);
    122121    if (!status || (X < 0) || (X > image[i].NX) || (Y < 0) || (Y > image[i].NY)) continue;
     
    134133  for (i = 0; i < Nsub; i++) {
    135134    I = index[i];
    136     if (!FindMosaicForImage (image, Nimage, I)) continue;
    137135    Timage = image[I].tzero;
    138136    for (j = 0; j < Nmeasure; j++) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/include/astro.h

    r31635 r37822  
    1212void FreeAstro (void);
    1313
    14 typedef struct {
    15   int    isIdentity;          // identity transformation
    16   double phi;                 // saved in radians
    17   double Xo;                  // saved in radians
    18   double xo;                  // saved in degrees
    19   double sin_phi_cos_Xo;      // pre-computed values
    20   double sin_phi_sin_Xo;      // pre-computed values
    21   double cos_phi_cos_Xo;      // pre-computed values
    22   double cos_phi_sin_Xo;      // pre-computed values
    23   double cos_phi;             // pre-computed values
    24   double sin_phi;             // pre-computed values
    25   double cos_Xo;              // pre-computed values
    26   double sin_Xo;              // pre-computed values
    27 } CoordTransform;
    28 
    29 #ifndef MOVED_TO_LIBDVO
    30 typedef enum {COORD_NONE, COORD_CELESTIAL, COORD_GALACTIC, COORD_ECLIPTIC} CoordTransformSystem;
    31 #endif
    32 
    33 CoordTransform *InitTransform (CoordTransformSystem input, CoordTransformSystem output);
    34 int ApplyTransform (double *x, double *y, double X, double Y, CoordTransform *transform);
    35 
    3614# endif
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/include/data.h

    r36679 r37822  
    224224void ListMedImages ();
    225225
     226// in tvchannel.c
     227int GetKapaChannelFromString (char *string);
     228
    226229# endif
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/include/dvomath.h

    r37049 r37822  
    187187int           ListBuffersToList     PROTO((char *name));
    188188int           CreateBuffer          PROTO((Buffer *buf, int Nx, int Ny, int bitpix, float bzero, float bscale));
     189int           ResetBuffer           PROTO((Buffer *buf, int Nx, int Ny, int bitpix, float bzero, float bscale));
    189190Buffer       *SelectBuffer          PROTO((char *name, int mode, int verbose));
    190191void          dump_buffers          PROTO((int n));  /* deprecated? */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/lib.shell/BufferOps.c

    r33662 r37822  
    8888}
    8989
     90int ResetBuffer (Buffer *buf, int Nx, int Ny, int bitpix, float bzero, float bscale) {
     91
     92  gfits_free_matrix (&buf[0].matrix);
     93  gfits_free_header (&buf[0].header);
     94  CreateBuffer (buf, Nx, Ny, bitpix, bzero, bscale);
     95  return TRUE;
     96}
     97
    9098int CreateBuffer (Buffer *buf, int Nx, int Ny, int bitpix, float bzero, float bscale) {
    9199
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/pantasks/controller_status.c

    r23530 r37822  
    33int controller_status (int argc, char **argv) {
    44
    5   int status;
    6   char command[1024];
     5  int i, status;
     6  char command[1024], tmpline[1024];
    77  IOBuffer buffer;
    88
    9   if (argc != 1) {
    10     gprint (GP_ERR, "USAGE: controller status\n");
     9  if ((argc > 1) && (!strcasecmp(argv[1], "help")))  {
     10    gprint (GP_ERR, "USAGE: controller status [options]\n");
     11    gprint (GP_ERR, "  OPTIONS:\n");
     12    gprint (GP_ERR, "  -cmd command\n");
     13    gprint (GP_ERR, "  -host hostname\n");
     14    gprint (GP_ERR, "  -state state\n");
     15    gprint (GP_ERR, "  -age seconds\n");
     16    gprint (GP_ERR, "  +jobs [-nohost]\n");
     17    gprint (GP_ERR, "  +host [-nojobs]\n");
    1118    return (FALSE);
    1219  }
     
    1926  }
    2027
     28  snprintf (command, 1024, "status");
     29  for (i = 1; i < argc; i++) {
     30    snprintf (tmpline, 1024, "%s %s", command, argv[i]);
     31    strcpy (command, tmpline);
     32  }
    2133
    22   sprintf (command, "status");
    2334  InitIOBuffer (&buffer, 0x100);
    2435
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/pcontrol/Makefile

    r34088 r37822  
    1111
    1212# programs may add their own internal requirements here
    13 LIBS1         = -lkapa -lFITS -lohana
     13LIBS1         = -ldvo -lkapa -lFITS -lohana
    1414LIBS2         = -lbasiccmd -lshell -ldata
    1515FULL_CFLAGS   = $(BASE_CFLAGS)
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/opihi/pcontrol/status.c

    r36623 r37822  
    8585
    8686usage:
    87   gprint (GP_ERR, "USAGE: status [-cmd command] [-host hostname] [-state state] [-age seconds] [+jobs,-nohost] [+host,-nojobs]\n");
     87  gprint (GP_LOG, "USAGE: status [-cmd command] [-host hostname] [-state state] [-age seconds] [+jobs,-nohost] [+host,-nojobs]\n");
    8888  return FALSE;
    8989}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/photdbc/include/photdbc.h

    r37045 r37822  
    3131int    PARALLEL_MANUAL;
    3232int    PARALLEL_SERIAL;
     33char  *PARALLEL_OUTHOSTS;
    3334
    3435int          HOST_ID;
    3536char        *HOSTDIR;
     37char        *HOSTDIR_OUTPUT;
    3638
    3739// need to get RADIUS from Config
     
    4042
    4143/* global variables */
     44int    SKIP_IMAGES;
     45int    ONLY_IMAGES;
    4246int    SHOW_PARAMS;
    4347int    VERBOSE;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/photdbc/src/CopyToHostLocation.c

    r33655 r37822  
    5454    }
    5555
    56     char extname[4][16] = {"cpm", "cpt", "cps", "cpn"};
    57     for (j = 0; success && (j < 4); j++) {
     56    # define NEXTNAME 7
     57    char extname[NEXTNAME][16] = {"cpm", "cpt", "cps", "cpn", "cpx", "cpy", "cpz"};
     58    for (j = 0; success && (j < NEXTNAME); j++) {
    5859
    5960      // set the in and out table names
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/photdbc/src/args.c

    r36833 r37822  
    1515    remove_argument (N, &argc, argv);
    1616    SHOW_PARAMS = TRUE;
     17  }
     18
     19  SKIP_IMAGES = FALSE;
     20  if ((N = get_argument (argc, argv, "-skip-images"))) {
     21    SKIP_IMAGES = TRUE;
     22    remove_argument (N, &argc, argv);
     23  }
     24
     25  ONLY_IMAGES = FALSE;
     26  if ((N = get_argument (argc, argv, "-only-images"))) {
     27    if (SKIP_IMAGES) {
     28      fprintf (stderr, "-skip-images and -only-images cannot be used together\n");
     29    }
     30    ONLY_IMAGES = TRUE;
     31    remove_argument (N, &argc, argv);
    1732  }
    1833
     
    131146  }
    132147
     148  // XXX for the moment, make this selection manual.  it needs to be automatic
     149  // based on the state of the SkyTable
     150  HOSTDIR_OUTPUT = NULL;
     151  PARALLEL_OUTHOSTS = NULL;
     152  if ((N = get_argument (argc, argv, "-parallel-output"))) {
     153    remove_argument (N, &argc, argv);
     154    PARALLEL_OUTHOSTS = strcreate (argv[N]);
     155    remove_argument (N, &argc, argv);
     156  }
     157
    133158  if (argc != 2) usage();
    134159
     
    171196  if (!HOSTDIR) usage();
    172197
     198  HOSTDIR_OUTPUT = NULL;
     199  if ((N = get_argument (argc, argv, "-hostdir-output"))) {
     200    remove_argument (N, &argc, argv);
     201    HOSTDIR_OUTPUT = strcreate (argv[N]);
     202    remove_argument (N, &argc, argv);
     203  }
     204
    173205  VERBOSE = FALSE;
    174206  if ((N = get_argument (argc, argv, "-v"))) {
     
    289321  fprintf (stderr, " photdbc (output)\n\n");
    290322
     323  fprintf (stderr, " parallel options:\n");
     324  fprintf (stderr, "  -parallel:\n");
     325  fprintf (stderr, "  -parallel-output HostTable : HostTable should be relative path in OUTPUT directory\n");
     326  fprintf (stderr, "  -parallel-manual\n");
     327  fprintf (stderr, "  -parallel-serial\n\n");
     328
    291329  fprintf (stderr, " allowed filters / restrictions include:\n\n");
    292330
     
    303341  fprintf (stderr, " option options:\n");
    304342  fprintf (stderr, " -v : verbose mode\n");
    305   fprintf (stderr, " -params : list the current parameters\n\n");
     343  fprintf (stderr, " -params : list the current parameters\n");
     344  fprintf (stderr, " -skip-images\n");
     345  fprintf (stderr, " -only-images\n");
     346  fprintf (stderr, " -set-format (catformat)\n");
     347  fprintf (stderr, " -set-mode (catmode)\n");
    306348
    307349  fprintf (stderr, "ptolemy.rc config values used by this program:\n");
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/photdbc/src/copy_images.c

    r36833 r37822  
    5252  }
    5353
     54  BuildChipMatch (image, Nimage);
     55  // MARKTIME("build chip match: %f sec\n", dtime);
     56
     57  char mapfile[DVO_MAX_PATH];
     58  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", CATDIR);
     59  AstromOffsetTable *table_src = AstromOffsetMapLoad (mapfile, VERBOSE);
     60
     61  // assign images.coords.offsetMap -> table->map[i]
     62  if (table_src) {
     63    AstromOffsetTableMatchChips (image, Nimage, table_src);
     64  }
     65
    5466  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset, FALSE);
     67
     68  if (table_src) {
     69    AstromOffsetTable *table_tgt = AstromOffsetTableInit ();
     70   
     71    off_t i;
     72    for (i = 0; i < Nsubset; i++) {
     73      if (!subset[i].coords.offsetMap) continue;
     74      if (subset[i].coords.Npolyterms != -1) continue; // assert on this?
     75      AstromOffsetTableAddMapFromImage (table_tgt, &subset[i]);
     76    }
     77    snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", outdir);
     78    AstromOffsetMapSave (table_tgt, mapfile);
     79    free (table_tgt->imageIDtoTableSeq);
     80    free (table_tgt->map);
     81    free (table_tgt);
     82  }
    5583
    5684  dvo_image_addrows (&out, subset, Nsubset);
     
    73101  SavePhotcodesFITS (filename);
    74102
     103  // free the astrom offset tables
     104  AstromOffsetTableFree (table_src);
     105
    75106  return (TRUE);
    76107}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/photdbc/src/find_images.c

    r36481 r37822  
    1919
    2020  /* we make positional comparisons in the projection of catalog */
     21  InitCoords (&tcoords, "DEC--TAN");
    2122  tcoords.crval1 = 0.5*(region[0].RA[0]  + region[0].RA[1]);
    2223  tcoords.crval2 = 0.5*(region[0].DEC[0] + region[0].DEC[1]);
    23   tcoords.crpix1 = tcoords.crpix2 = 0.0;
    2424  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    25   tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    26   tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    27   strcpy (tcoords.ctype, "DEC--TAN");
    2825
    2926  timage = gfits_table_get_Image (&db[0].ftable, &Ntimage, &db[0].swapped);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/photdbc/src/join_stars.c

    r37045 r37822  
    5050
    5151  /* coordinate system for projection */
     52  InitCoords (&tcoords, "DEC--TAN");
    5253  tcoords.crval1 = Rmid;
    5354  tcoords.crval2 = Dmid;
    54   tcoords.crpix1 = tcoords.crpix2 = 0.0;
    5555  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    56   tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    57   tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    58   tcoords.Npolyterms = 0;
    59   strcpy (tcoords.ctype, "DEC--TAN");
    6056 
    6157  /* project & sort coordinates in local linear frame */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/photdbc/src/photdbc.c

    r36833 r37822  
    1515
    1616  // load and copy the image table
    17   copy_images (argv[1], skylist);
     17  if (!SKIP_IMAGES) {
     18    copy_images (argv[1], skylist);
     19  }
    1820
    1921  // hostID is 0 for master program
    20   photdbc_catalogs (argv[1], skylist, 0);
     22  if (!ONLY_IMAGES) {
     23    photdbc_catalogs (argv[1], skylist, 0);
     24  }
    2125
    2226  char *skyfile = SkyTableFilename (argv[1]);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/photdbc/src/photdbc_catalogs.c

    r36833 r37822  
    4242    snprintf (outfile, DVO_MAX_PATH, "%s/%s.cpt", outroot, skylist[0].regions[i]->name);
    4343    outcatalog.filename = outfile;
     44
     45    if (HOSTDIR_OUTPUT) {
     46      // parallel-ouput puts the output in a per-host directory (keeps the source sky partition)
     47      snprintf (outfile, DVO_MAX_PATH, "%s/%s.cpt", HOSTDIR_OUTPUT, skylist[0].regions[i]->name);
     48    }
     49
    4450    if (outcatalog.filename == NULL) Shutdown ("error with input catalog name");
    4551
     
    95101  }   
    96102
     103  HostTable *table_output = NULL;
     104  if (PARALLEL_OUTHOSTS) {
     105    table_output = HostTableLoad (outroot, PARALLEL_OUTHOSTS);
     106    if (!table_output) {
     107      fprintf (stderr, "%s not found in %s, please create\n", PARALLEL_OUTHOSTS, outroot);
     108    }
     109  }
     110
    97111  int i;
    98112  for (i = 0; i < table->Nhosts; i++) {
     
    123137    if (CATFORMAT)          { snprintf (tmpline, DVO_MAX_PATH, "%s -set-format %s",    command, CATFORMAT);                     strcpy (command, tmpline); }
    124138    if (CATMODE)            { snprintf (tmpline, DVO_MAX_PATH, "%s -set-mode %s",      command, CATMODE);                       strcpy (command, tmpline); }
     139
     140    if (PARALLEL_OUTHOSTS) {
     141      tmppath = abspath (table_output->hosts[i].pathname, DVO_MAX_PATH);
     142      free  (table_output->hosts[i].pathname);
     143      table_output->hosts[i].pathname = tmppath;
     144      snprintf (tmpline, DVO_MAX_PATH, "%s -hostdir-output %s", command, table_output->hosts[i].pathname); strcpy (command, tmpline);
     145    }
    125146
    126147    fprintf (stderr, "command: %s\n", command);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/photdbc/src/select_images.c

    r36833 r37822  
    3434
    3535  // the comparison is made in the catalog local projection. below we set crval1,2
    36   tcoords.crpix1 = tcoords.crpix2 = 0.0;
     36  InitCoords (&tcoords, "DEC--TAN");
    3737  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    38   tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    39   tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    40   strcpy (tcoords.ctype, "DEC--TAN");
    4138
    4239  ALLOCATE (skycoords, SkyRegionCoords, skylist[0].Nregions);
     
    9289
    9390  if (VERBOSE) fprintf (stderr, "finding images\n");
    94   BuildChipMatch (timage, Ntimage);
    95   MARKTIME("build chip match: %f sec\n", dtime);
    9691
    9792  nimage = 0;
     
    115110keep_image:
    116111
    117     // this adds 1.3 sec for 3M images
    118     if (!FindMosaicForImage (timage, Ntimage, i)) {
    119       fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    120       continue;
    121     }
    122 
    123112    /* define image corners - note the DIS images (mosaic phu) are special */
    124113    if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/Makefile

    r36833 r37822  
    5959$(SRC)/save_catalogs.$(ARCH).o       \
    6060$(SRC)/CoordOps.$(ARCH).o            \
    61 $(SRC)/FixProblemImages.$(ARCH).o    \
     61$(SRC)/extra.$(ARCH).o            \
    6262$(SRC)/StarMaps.$(ARCH).o    \
    6363$(SRC)/high_speed_catalogs.$(ARCH).o  \
     
    7474$(SRC)/relastro_parallel_regions.$(ARCH).o \
    7575$(SRC)/MeanPosIO.$(ARCH).o \
     76$(SRC)/MeasPosIO.$(ARCH).o \
    7677$(SRC)/share_mean_pos.$(ARCH).o \
     78$(SRC)/share_meas_pos.$(ARCH).o \
    7779$(SRC)/share_images_pos.$(ARCH).o \
     80$(SRC)/share_icrf_obj.$(ARCH).o \
     81$(SRC)/ICRF.$(ARCH).o \
     82$(SRC)/ICRFobjIO.$(ARCH).o \
     83$(SRC)/FrameCorrection.$(ARCH).o \
     84$(SRC)/FrameCorrectionIO.$(ARCH).o \
     85$(SRC)/FrameCorrectionUtils.$(ARCH).o \
    7886$(SRC)/ImagePosIO.$(ARCH).o \
    7987$(SRC)/ImageTable.$(ARCH).o \
     
    8189$(SRC)/indexCatalogs.$(ARCH).o \
    8290$(SRC)/syncfile.$(ARCH).o \
     91$(SRC)/client_logger.$(ARCH).o \
    8392$(SRC)/relastroVisual.$(ARCH).o
    8493
     
    116125$(SRC)/relastro_objects.$(ARCH).o    \
    117126$(SRC)/save_catalogs.$(ARCH).o       \
    118 $(SRC)/CoordOps.$(ARCH).o            \
     127$(SRC)/extra.$(ARCH).o            \
    119128$(SRC)/high_speed_catalogs.$(ARCH).o  \
    120129$(SRC)/high_speed_objects.$(ARCH).o  \
     
    126135$(SRC)/plot_scatter.$(ARCH).o        \
    127136$(SRC)/plotstuff.$(ARCH).o           \
     137$(SRC)/ICRF.$(ARCH).o \
    128138$(SRC)/relastroVisual.$(ARCH).o \
    129139$(SRC)/syncfile.$(ARCH).o \
    130140$(SRC)/BrightCatalog.$(ARCH).o
    131 
    132 #$(SRC)/FitChip.$(ARCH).o             \
    133 #$(SRC)/FitMosaic.$(ARCH).o           \
    134 #$(SRC)/UpdateChips.$(ARCH).o         \
    135 #$(SRC)/UpdateMosaic.$(ARCH).o        \
    136 #$(SRC)/UpdateSimple.$(ARCH).o        \
    137 #$(SRC)/write_coords.$(ARCH).o        \
    138 #$(SRC)/FixProblemImages.$(ARCH).o    \
    139 #$(SRC)/StarMaps.$(ARCH).o    \
    140141
    141142$(RELASTRO_CLIENT): $(INC)/relastro.h
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/doc/pv2.txt

    r37038 r37822  
     1
     22014.10.28
     3
     4Going over the sequence of steps in relastro.  I'm concerned that the
     5iteration is not modifying the measure.R,D values, preventing any
     6actual iterative improvements.
     7
     8* UpdateObjects : takes measure.R,D to calculate average.R,D and
     9  motion terms
     10
     11* ImageOps :
     12  * getImageRaw : takes measure.X,Y, applies image.coords to get (L,M),
     13                  (P,Q), etc, calculates
     14  * getImageRef : takes average.R,D, applies image.coords to get
     15                  (P,Q), (L,M), etc
     16  * FitChip : fit raw.X,Y to ref.L,M, plus residual map (dX,dY)
     17 
     18  *** modified raw.L,M values are then dropped and not used to update measure.R.D
    119
    2202014.07.03
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/include/relastro.h

    r37038 r37822  
    3434
    3535typedef struct {
    36   float R;
    37   float D;
     36  double R;
     37  double D;
    3838  unsigned int objID;
    3939  unsigned int catID;
    4040} MeanPos;
     41
     42typedef struct {
     43  double R;
     44  double D;
     45  unsigned int objID;
     46  unsigned int catID;
     47  unsigned int imageID;
     48} MeasPos;
    4149
    4250typedef struct {
     
    4755  int nFitAstrom;
    4856  int flags;
     57  float refColorBlue;
     58  float refColorRed;
    4959} ImagePos;
    5060
     
    134144} StatType;
    135145
     146typedef struct {
     147  off_t Nave;
     148  off_t Npm;
     149  off_t Npar;
     150  off_t Nskip;
     151  off_t Noffset;
     152} FitStats;
     153
     154typedef struct {
     155  double scale;
     156  double **Roff;
     157  double **Doff;
     158  double  *dR;
     159  int *Nra;
     160  int Ndec;
     161} FrameCorrectionType;
     162
     163typedef struct {
     164  // AstromOffsetMap *map;
     165  Coords *coords; // carries a pointer to the AstromOffsetMap
     166  FrameCorrectionType *frame;
     167} FrameCorrectionSet;
     168
     169
     170typedef struct {
     171  double *Rave;
     172  double *Dave;
     173  double *dRoff;
     174  double *dDoff;
     175  int Nicrfobj;
     176} ICRFobj;
     177
    136178/* global variables set in parameter file */
    137179# define DVO_MAX_PATH 1024
     
    164206double MIN_ERROR;
    165207
     208int    IMFIT_TOO_FEW; // need more than this number of stars to fit an image
    166209int    IMFIT_CLIP_NITER; // number of clipping iterations to perform in FitChip
    167210double IMFIT_CLIP_NSIGMA; // number of sigma to clip in FitChip
     
    180223
    181224int    USE_FIXED_PIXCOORDS;
     225int    USE_GALAXY_MODEL;
     226int    USE_ICRF_CORRECT;
     227
     228int    USE_ICRF_LOCAL;
     229int    USE_ICRF_SHFIT;
     230int    USE_ICRF_POLE;
    182231
    183232int    RESET;
     233int    RESET_IMAGES;
    184234int    RESET_BAD_IMAGES;
    185235int    NLOOP;
     
    196246int    PLOTDELAY;
    197247int    CHIPORDER;
     248int    CHIPMAP;
    198249
    199250int MaxDensityUse;
     
    234285int    CLIP_THRESH;
    235286int USE_BASIC_CHECK;
     287int APPLY_OFFSETS; // in parallel-regions mode, do not launch UpdateObjectOffsets unless -apply-offsets is called
    236288
    237289int ExcludeBogus;
     
    389441void FitSimple (StarData *raw, StarData *ref, int Nmatch, Coords *coords);
    390442void initObjectData (Catalog *catalog, int Ncatalog);
    391 int UpdateObjects (Catalog *catalog, int Ncatalog);
     443int UpdateObjects (Catalog *catalog, int Ncatalog, int Nloop);
    392444int UpdateSimple (Catalog *catalog, int Ncatalog);
    393445int UpdateChips (Catalog *catalog, int Ncatalog);
     
    409461StarData *getImageRef (Catalog *catalog, int Ncatalog, off_t im, off_t *Nstars, CoordMode mode);
    410462StarData *getImageRaw (Catalog *catalog, int Ncatalog, off_t im, off_t *Nstars, CoordMode mode);
     463int setImageRaw (Catalog *catalog, int Ncatalog, off_t im, StarData *raw, off_t Nraw, CoordMode mode);
    411464off_t getImageByID (off_t ID);
     465int updateImageRaw (Catalog *catalog, int Ncatalog, off_t im);
    412466
    413467Mosaic *getmosaics (off_t *N);
     
    439493int relastroGetVisual(void);
    440494
    441 int FixProblemImages (SkyList *skylist);
    442495int *getCatlist (int *N, off_t im);
    443496
    444 void initCoords (void);
    445 void getOffsets (double *dPos, off_t *nPos, off_t N);
    446 void saveOffsets (double dPos, off_t nPos, off_t N);
    447 void setBadCoords (off_t N);
    448 int badCoords (off_t N);
    449 Coords *getCoords (off_t N);
    450 int saveCoords (Coords *coords, off_t N);
    451 void resetImageRaw (Catalog *catalog, int Ncatalog, off_t im);
     497void SaveCoords (Coords *tgt, Coords *src);
     498void RestoreCoords (Coords *tgt, Coords *src, Image *image);
    452499
    453500int high_speed_catalogs (SkyTable *sky, SkyList *skylist, int hostID, char *hostpath);
     
    460507int checkStarMap(int N);
    461508int createStarMap (Catalog *catalog, int Ncatalog);
     509int printStarMap(int N, char *filename);
    462510
    463511int GetScatterRawRef(float *dLsig, float *dMsig, float *dRsig, int *nKeep, StarData *raw, StarData *ref, int Nstars, float SigmaLimit);
     
    511559MeanPos *MeanPosLoad(char *filename, off_t *nmeanpos);
    512560
     561int share_meas_pos (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     562int slurp_meas_pos (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     563int set_meas_pos (MeasPos *measpos, Average *average, MeasureTiny *measure);
     564MeasPos *merge_meas_pos (MeasPos *target, int *ntarget, MeasPos *source, int Nsource);
     565
     566int MeasPosSave(char *filename, MeasPos *measpos, off_t Nmeaspos);
     567MeasPos *MeasPosLoad(char *filename, off_t *nmeaspos);
     568
    513569int indexCatalogs (Catalog *catalog, int Ncatalog);
    514570int catID_and_objID_to_seq (int catID, int objID, int *catSeq, off_t *objSeq);
     
    520576
    521577int share_image_pos (RegionHostTable *regionHosts, int nloop);
    522 int slurp_image_pos (RegionHostTable *regionHosts, int nloop);
     578int slurp_image_pos (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
    523579ImagePos *merge_image_pos (ImagePos *target, int *ntarget, ImagePos *source, int Nsource);
    524580int set_image_pos (ImagePos *image_pos, Image *image);
     
    535591int areImagesLoaded ();
    536592int areImagesMatched ();
     593
     594int isGPC1chip (int photcode);
     595int isGPC1stack (int photcode);
     596int isGPC1warp (int photcode);
     597
     598int save_astrom_table ();
     599AstromOffsetTable *get_astrom_table ();
     600void put_astrom_table (AstromOffsetTable *myTable);
     601
     602int fit_map (AstromOffsetMap *map, StarData *raw, StarData *ref, int Npts);
     603
     604// ICRF QSOs : these must be marked in the database (flag on average, flag on measure)
     605
     606void ICRFinit ();
     607int ICRFsave (int cat, int ave, int meas);
     608int ICRFdata (int n, int *cat, int *ave, int *meas);
     609int ICRFmax ();
     610int select_catalog_ICRF (Catalog *catalog, int Ncatalog);
     611
     612void ICRFobjFree (ICRFobj *icrfobj);
     613ICRFobj *get_ICRF_data (Catalog *catalog, int Ncatalog);
     614ICRFobj *merge_icrf_obj (ICRFobj *target, ICRFobj *source);
     615ICRFobj *slurp_icrf_obj (RegionHostTable *regionHosts, int nloop);
     616int share_icrf_obj (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     617
     618int ICRFobjSave(char *filename, ICRFobj *icrfobj);
     619ICRFobj *ICRFobjLoad(char *filename);
     620
     621int SHfitWithMask (double *R, double *D, double *value, int *mask, int Npts, SHterms *fit);
     622
     623FrameCorrectionType *FrameCorrectionInit (double scale);
     624void FrameCorrectionFree (FrameCorrectionType *frame);
     625
     626int FrameCorrectionParallelMaster (RegionHostTable *regionHosts);
     627int FrameCorrectionParallelSlave (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     628int FrameCorrectionSerial (Catalog *catalog, int Ncatalog);
     629
     630FrameCorrectionSet *FrameCorrectionMeasure (ICRFobj *icrfobj);
     631
     632int FrameCorrectionFromSH (FrameCorrectionType *frame, SHterms *dR, SHterms *dD);
     633
     634Coords *FrameCorrectionImageToMap (Header *header, Matrix *matrix, Coords *coords, int raDirection);
     635int FrameCorrectionMapToImage (Header *header, Matrix *matrix, Coords *coords, int raDirection);
     636int FrameCorrectionSHtoImage (Header *header, Matrix *matrix, FrameCorrectionType *frame, int raDirection);
     637FrameCorrectionType *FrameCorrectionImageToSH (Header *header, Matrix *matrix, FrameCorrectionType *frame, int raDirection);
     638int FrameCorrectionFromSH (FrameCorrectionType *frame, SHterms *dR, SHterms *dD);
     639void FrameCorrectionFree (FrameCorrectionType *frame);
     640FrameCorrectionType *FrameCorrectionInit (double scale);
     641void FrameCorrectionSetFree (FrameCorrectionSet *set);
     642FrameCorrectionSet *FrameCorrectionSetInit ();
     643
     644int FrameCorrectionSetSave(char *filename, FrameCorrectionSet *set);
     645FrameCorrectionSet *FrameCorrectionSetLoad(char *filename);
     646
     647int FrameCorrectionFitSH (ICRFobj *icrfobj, SHterms *dRc, SHterms *dDc);
     648int FrameCorrectionFitLocal (ICRFobj *icrfobj, Coords *coords);
     649int FrameCorrectionApply (Catalog *catalog, int Ncatalog, FrameCorrectionType *frame, Coords *coords);
     650
     651int dump_stardata_pts (StarData *raw, int Npts, char *filename);
     652void printNcatTotal ();
     653
     654int HarvestRegionHosts (RegionHostTable *regionHosts);
     655
     656void lockUpdateChips ();
     657void unlockUpdateChips ();
     658
     659int client_logger_init (char *dirname);
     660int client_logger_message (char *format,...);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/BrightCatalog.c

    r37038 r37822  
    4343  if (!gfits_fread_header (f, &header)) {
    4444    if (VERBOSE) fprintf (stderr, "can't read image subset header\n");
    45     fclose (f);
    4645    goto escape;
    4746  }
    4847  if (!gfits_fread_matrix (f, &matrix, &header)) {
    4948    if (VERBOSE) fprintf (stderr, "can't read image subset matrix\n");
    50     gfits_free_header (&header);
    51     fclose (f);
    5249    goto escape;
    5350  }
     
    7067    GET_COLUMN(R,         "RA",         double);
    7168    GET_COLUMN(D,         "DEC",        double);
     69    GET_COLUMN(RoffGAL,   "ROFF_GAL",   float);
     70    GET_COLUMN(DoffGAL,   "DOFF_GAL",   float);
    7271    GET_COLUMN(M,         "MAG_SYS",    float);
    7372    GET_COLUMN(Mcal,      "MAG_CAL",    float);
     
    9493      measure[i].R         = R[i];
    9594      measure[i].D         = D[i];
     95      measure[i].RoffGAL   = RoffGAL[i];
     96      measure[i].DoffGAL   = DoffGAL[i];
    9697      measure[i].M         = M[i];
    9798      measure[i].Mcal      = Mcal[i];
     
    115116    free (R       );
    116117    free (D       );
     118    free (RoffGAL );
     119    free (DoffGAL );
    117120    free (M       );
    118121    free (Mcal    );
     
    310313  if (catalog) free (catalog);
    311314
    312   fclose (f);
     315  if (f) fclose (f);
    313316  return NULL;
    314317}
     
    343346    gfits_create_table_header (&theader, "BINTABLE", "MEASURE_TINY");
    344347
    345     gfits_define_bintable_column (&theader, "E", "RA_OFF",   "ra offset",                  "arcsec", 1.0, 0.0);
    346     gfits_define_bintable_column (&theader, "E", "DEC_OFF",  "dec offset",                 "arcsec", 1.0, 0.0);
     348    gfits_define_bintable_column (&theader, "D", "RA",       "ra",                         "degrees", 1.0, 0.0);
     349    gfits_define_bintable_column (&theader, "D", "DEC",      "dec",                        "degrees", 1.0, 0.0);
     350    gfits_define_bintable_column (&theader, "E", "ROFF_GAL", "ra offset",                  "arcsec", 1.0, 0.0);
     351    gfits_define_bintable_column (&theader, "E", "DOFF_GAL", "dec offset",                 "arcsec", 1.0, 0.0);
    347352    gfits_define_bintable_column (&theader, "E", "MAG_SYS",  "magnitude (sys)",             NULL,    1.0, 0.0);
    348353    gfits_define_bintable_column (&theader, "E", "MAG_CAL",  "magnitude (cal)",             NULL,    1.0, 0.0);
     
    368373    double *R         ; ALLOCATE (R        ,  double, catalog->Nmeasure);
    369374    double *D         ; ALLOCATE (D        ,  double, catalog->Nmeasure);
     375    float  *RoffGAL   ; ALLOCATE (RoffGAL  ,  float,  catalog->Nmeasure);
     376    float  *DoffGAL   ; ALLOCATE (DoffGAL  ,  float,  catalog->Nmeasure);
    370377    float  *M         ; ALLOCATE (M        ,  float,  catalog->Nmeasure);
    371378    float  *Mcal      ; ALLOCATE (Mcal     ,  float,  catalog->Nmeasure);
     
    390397      R[i]        = measure[i].R        ;
    391398      D[i]        = measure[i].D        ;
     399      RoffGAL[i]  = measure[i].RoffGAL  ;
     400      DoffGAL[i]  = measure[i].DoffGAL  ;
    392401      M[i]        = measure[i].M        ;
    393402      Mcal[i]     = measure[i].Mcal     ;
     
    411420    gfits_set_bintable_column (&theader, &ftable, "RA",         R,         catalog->Nmeasure);
    412421    gfits_set_bintable_column (&theader, &ftable, "DEC",        D,         catalog->Nmeasure);
     422    gfits_set_bintable_column (&theader, &ftable, "ROFF_GAL",   RoffGAL,   catalog->Nmeasure);
     423    gfits_set_bintable_column (&theader, &ftable, "DOFF_GAL",   DoffGAL,   catalog->Nmeasure);
    413424    gfits_set_bintable_column (&theader, &ftable, "MAG_SYS",    M,         catalog->Nmeasure);
    414425    gfits_set_bintable_column (&theader, &ftable, "MAG_CAL",    Mcal,      catalog->Nmeasure);
     
    430441    free (R       );
    431442    free (D       );
     443    free (RoffGAL );
     444    free (DoffGAL );
    432445    free (M       );
    433446    free (Mcal    );
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/ConfigInit.c

    r36630 r37822  
    2525  if (!ScanConfig (config, "RELASTRO_IMFIT_CLIP_NSIGMA",   "%lf", 0, &IMFIT_CLIP_NSIGMA))   IMFIT_CLIP_NSIGMA = 3.0;
    2626  if (!ScanConfig (config, "RELASTRO_IMFIT_SYS_SIGMA_LIM", "%lf", 0, &IMFIT_SYS_SIGMA_LIM)) IMFIT_SYS_SIGMA_LIM = 0.01;
     27  if (!ScanConfig (config, "RELASTRO_IMFIT_TOO_FEW",       "%d",  0, &IMFIT_TOO_FEW))       IMFIT_TOO_FEW = 5;
    2728
    2829  if (!ScanConfig (config, "PM_DT_MIN",              "%lf", 0, &PM_DT_MIN))        PM_DT_MIN = 0.25;   
     
    3637
    3738  if (!ScanConfig (config, "USE_FIXED_PIXCOORDS", "%d", 0, &USE_FIXED_PIXCOORDS))  USE_FIXED_PIXCOORDS = FALSE;
     39  if (!ScanConfig (config, "USE_GALAXY_MODEL",    "%d", 0, &USE_GALAXY_MODEL))     USE_GALAXY_MODEL = FALSE;
     40  if (!ScanConfig (config, "USE_ICRF_CORRECT",    "%d", 0, &USE_ICRF_CORRECT))     USE_ICRF_CORRECT = FALSE;
     41  if (!ScanConfig (config, "USE_ICRF_LOCAL",      "%d", 0, &USE_ICRF_LOCAL))       USE_ICRF_LOCAL = FALSE;
     42  if (!ScanConfig (config, "USE_ICRF_SHFIT",      "%d", 0, &USE_ICRF_SHFIT))       USE_ICRF_SHFIT = FALSE;
     43  if (!ScanConfig (config, "USE_ICRF_POLE",       "%d", 0, &USE_ICRF_POLE))        USE_ICRF_POLE = FALSE;
    3844
    3945  // force CATDIR to be absolute (so parallel mode will work)
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/FitChip.c

    r37038 r37822  
    1414
    1515  for (Niter = 0; Niter < IMFIT_CLIP_NITER; Niter ++) {
    16    
     16
    1717    // measure the scatter for the unmarked (good) measurements with dM < limit
    1818    // SIGMA_LIM here is redundant with ImageOps.c:915
     
    4949    // use that count to set order_use below
    5050
     51    // 20140925 : the same logic below is used to constrain the dimensions of the image map
     52
    5153    // figures to assess the fitting process:
    5254    // x vs dx, x vs dy, y vs dx, y vs dy :
    5355    // residual vector field
    5456    // dx vs mag, dy vs mag
     57    if (relastroGetVisual()) {
     58      fprintf (stderr, "fitting chip %s, %d matched stars\n", image->name, Nmatch);
     59    }
    5560    relastroVisualPlotChipFit(raw, ref, dRmax, Nmatch);
     61
     62    // for polynomial fits, I used (5,30,60) = (5,6,7) stars per term
    5663
    5764    // set the maximum order for the polynomial (based on number of stars kept above)
    5865    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)
     66    if (Nkeep >   5) order_use = 1; //  5 stars per cell
     67    if (Nkeep >  24) order_use = 2; //  6 stars per cell
     68    if (Nkeep >  63) order_use = 3; //  7 stars per cell
     69    if (Nkeep > 128) order_use = 4; //  8 stars per cell
     70    if (Nkeep > 225) order_use = 5; //  9 stars per cell
     71    if (Nkeep > 360) order_use = 6; // 10 stars per cell
    6272    if (order_use < 1) {
    6373      if (VERBOSE2) fprintf (stderr, "insufficient measurements (%d) for linear fit\n", Nkeep);
     
    6575      return FALSE;
    6676    }
    67     image[0].coords.Npolyterms = order_use;
     77    if (CHIPMAP) {
     78      order_use = MIN(MIN(order_use, CHIPMAP), 6); // can only go up to 6th order map (can be user limited)
     79    } else {
     80      order_use = MIN(order_use, 3); // can only go up to 3rd order for polynomials
     81    }
     82
     83    if (VERBOSE2) fprintf (stderr, "using %d for %s\n", order_use, image[0].name);
     84
     85    // when fitting the map, first fit a linear model (below? change Npolyterms to -1)
     86    image[0].coords.Npolyterms = CHIPMAP ? 1 : order_use;
    6887
    6988    if (fit) fit_free (fit);
     
    91110    }
    92111
     112    // apply fit to get the fitted X,Y coordinates.  we need these to fit the residual map below
    93113    for (i = 0; i < Nmatch; i++) {
     114      // we have not yet fitted the map, so Npolyterms needs to be 1 here:
     115      LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, &image[0].coords);
     116    }
     117
     118    if (CHIPMAP) {
     119      if (image[0].coords.offsetMap == NULL) {
     120        // allocate a new table and assign to this image
     121        // need to lock threads here because 'table' is a static with
     122        // modifiable elements
     123        lockUpdateChips ();
     124        AstromOffsetTable *table = get_astrom_table ();
     125        AstromOffsetTableNewMap(table, order_use, order_use, image);
     126        unlockUpdateChips ();
     127      }
     128      // XXX Need to check / update the order of the map here.  if we already have a map, it might have been
     129      // allocated with too small arrays
     130      AstromOffsetMapSetOrder (image[0].coords.offsetMap, order_use, order_use, image);
     131      image[0].coords.offsetMap->keep = TRUE; // if we are trying or re-trying this map, we should keep it unless it fails
     132      fit_map (image[0].coords.offsetMap, raw, ref, Nmatch);
     133      image[0].coords.Npolyterms = -1;
     134    }
     135
     136    if (!strcmp(image[0].name, "o5745g0403o.356777.cm.982487.smf[XY17.hdr]")) {
     137      fprintf (stderr, "test image\n");
     138    }
     139
     140    for (i = 0; i < Nmatch; i++) {
     141      // if we have fitted the map above, Npolyterms needs to be -1 here:
    94142      XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[0].coords);
    95143    }
    96 
    97144  }
    98145
     
    223270   L,M -> X,Y (polynomial transformation : WRP)
    224271
    225 Some details about this function:
    226 
    227 - the initial value of the clipping radius is set based on the distribution of the dR
    228   values for the bright sources.
    229 
    230 - NITER clipping passes are performed
    231 
    232 - the per-star astrometric errors are included in the fit.  The photcode table controls
    233   whether only the reported positional errors are used, or if the magnitudes errors are
    234   scaled to determine the error, and if there is a systematic floor for all sources.
    235 
    236 - input detections are pre-filtered on the basis of the photFlags, etc, in bcatalog
    237 
    238 - outlying detections are clipped in the iterative passes, but the clipped detections are
    239   not recorded
     272   Some details about this function:
     273
     274   - the initial value of the clipping radius is set based on the distribution of the dR
     275   values for the bright sources.
     276
     277   - NITER clipping passes are performed
     278
     279   - the per-star astrometric errors are included in the fit.  The photcode table controls
     280   whether only the reported positional errors are used, or if the magnitudes errors are
     281   scaled to determine the error, and if there is a systematic floor for all sources.
     282
     283   - input detections are pre-filtered on the basis of the photFlags, etc, in bcatalog
     284
     285   - outlying detections are clipped in the iterative passes, but the clipped detections are
     286   not recorded
    240287
    241288*/
     
    243290/* example using fit_apply() :
    244291
    245   f = fopen ("test3.dat", "w");
    246 
    247   // apply new coords to raw (X,Y -> L,M)
    248   for (i = 0; i < Nmatch; i++) {
    249     fprintf (f, "%f %f  %f %f  ", raw[i].X, raw[i].Y, raw[i].L, raw[i].M);
    250     fit_apply (newfit, &L1, &M1, raw[i].X - coords[0].crpix1, raw[i].Y - coords[0].crpix2);
    251     fprintf (f, "%f %f\n", L1, M1);
     292   f = fopen ("test3.dat", "w");
     293
     294   // apply new coords to raw (X,Y -> L,M)
     295   for (i = 0; i < Nmatch; i++) {
     296   fprintf (f, "%f %f  %f %f  ", raw[i].X, raw[i].Y, raw[i].L, raw[i].M);
     297   fit_apply (newfit, &L1, &M1, raw[i].X - coords[0].crpix1, raw[i].Y - coords[0].crpix2);
     298   fprintf (f, "%f %f\n", L1, M1);
     299   }
     300   fclose (f);
     301*/
     302
     303int fit_map (AstromOffsetMap *map, StarData *raw, StarData *ref, int Npts) {
     304
     305  // we are actually fitting the residual after the linear fit has been taken off
     306 
     307  // fit the linear terms as above
     308  // calculate dX (raw.X - ref.X) and dY
     309
     310  int i, N;
     311
     312  float *x, *y, *dX, *dY;
     313  ALLOCATE (x,  float, Npts);
     314  ALLOCATE (y,  float, Npts);
     315  ALLOCATE (dX, float, Npts);
     316  ALLOCATE (dY, float, Npts);
     317
     318  N = 0;
     319  for (i = 0; i < Npts; i++) {
     320    if (raw[i].mask) continue;
     321    x[N] = raw[i].X;
     322    y[N] = raw[i].Y;
     323    dX[N] = ref[i].X - raw[i].X;
     324    dY[N] = ref[i].Y - raw[i].Y;
     325    N++;
     326  }
     327
     328  // in coordsops.c:XY_to_LM, the map is defined to carry dX,dY so that:
     329  // (L,M) = f(X',Y') : (X',Y') = (X,Y) + (dX,dY)
     330
     331  AstromOffsetMapFit (map, x, y, dX, N, TRUE);
     332  AstromOffsetMapFit (map, x, y, dY, N, FALSE);
     333
     334  AstromOffsetMapRepair (map, TRUE);
     335  AstromOffsetMapRepair (map, FALSE);
     336
     337  free (x);
     338  free (y);
     339  free (dX);
     340  free (dY);
     341
     342  return TRUE;
     343}
     344
     345int dump_stardata_pts (StarData *raw, int Npts, char *filename) {
     346
     347  FILE *f = fopen (filename, "w");
     348  if (!f) {
     349    fprintf (stderr, "failed to open file %s\n", filename);
     350    return FALSE;
     351  }
     352
     353  int i;
     354  for (i = 0; i < Npts; i++) {
     355    fprintf (f, "%4d %10.6f %10.6f  %10.6f %10.6f  %9.2f %9.2f  %9.2f %9.2f  %9.4f %3d\n",
     356             i, raw[i].R, raw[i].D, raw[i].P, raw[i].Q, raw[i].L, raw[i].M, raw[i].X, raw[i].Y, raw[i].dPos, raw[i].mask);
    252357  }
    253358  fclose (f);
    254 */
    255 
     359
     360  return TRUE;
     361}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/ImageOps.c

    r37038 r37822  
    2828static off_t        *imageIDs; // list of all image IDs
    2929static off_t        *imageIdx; // list of index for image IDs
    30 # else
     30
     31// as an alternative, we generate imageSeq, which directly maps imageID -> seq
     32static off_t        *imageSeq; // list of index for image IDs
     33
     34// MAX_ID requires 512M to store the image index
     35# define MAX_ID      0x8000000
     36static off_t         minImageID = MAX_ID;
     37static off_t         maxImageID = 0;
     38
     39# else /* not using IMAGE_ID */
    3140static unsigned int *start;
    3241static unsigned int *stop;
     
    8493    imageIdx[i] = i;
    8594    imageIDs[i] = image[i].imageID;
     95    minImageID = MIN(minImageID, image[i].imageID);
     96    maxImageID = MAX(maxImageID, image[i].imageID);
     97    myAssert (image[i].imageID < MAX_ID, "image IDs too large for index memory");
    8698  }
    8799  llsortpair (imageIDs, imageIdx, Nimage);
     100
     101  ALLOCATE (imageSeq, off_t, maxImageID + 1);
     102  for (i = 0; i < maxImageID + 1; i++)  {
     103    imageSeq[i] = -1; // not yet assigned
     104  }
     105
     106  for (i = 0; i < Nimage; i++) {
     107    off_t N = image[i].imageID;
     108    myAssert (imageSeq[N] == -1, "previously assigned");
     109    imageSeq[N] = i;
     110  }
     111
    88112# else
    89113  ALLOCATE (start, unsigned, Nimage);
     
    98122
    99123off_t getImageByID (off_t ID) {
     124# if USE_IMAGE_ID
     125
     126  if (imageSeq) {
     127    if (ID < minImageID) return (-1);
     128    if (ID > maxImageID) return (-1);
     129    off_t N = imageSeq[ID];
     130    return N;
     131  }
    100132
    101133  // we have a pair of vectors (imageIDs, imageIdx) sorted by imageIDs
    102134  // use bisection to find the specified image ID
    103135
    104 # if USE_IMAGE_ID
    105136  off_t Nlo, Nhi, N;
    106137
     
    207238    if (VERBOSE2 || (MATCHCAT && (N_onImage[i] < 20))) {
    208239      name = GetPhotcodeNamebyCode (image[i].photcode);
    209       fprintf (stderr, "image "OFF_T_FMT" (%d, %s) has "OFF_T_FMT" of %d measures (%s, %s)",  i,  image[i].imageID, image[i].name, N_onImage[i], image[i].nstar,
     240      int showExample = (Nfew < 30);
     241      if (showExample) fprintf (stderr, "image "OFF_T_FMT" (%d, %s) has "OFF_T_FMT" of %d measures (%s, %s) ",  i,  image[i].imageID, image[i].name, N_onImage[i], image[i].nstar,
    210242               ohana_sec_to_date(image[i].tzero), name);
    211243      if (N_onImage[i] < 20) {
    212         fprintf (stderr, "*");
     244        if (showExample) fprintf (stderr, "*");
    213245        Nfew ++;
    214246      }
    215247      if (N_onImage[i] < 15) {
    216         fprintf (stderr, "*** warning ***");
     248        if (showExample) fprintf (stderr, "*** warning ***");
    217249        Nbad ++;
    218250      }
    219       fprintf (stderr, "\n");
    220     }
    221   }
    222   fprintf (stderr, OFF_T_FMT" total images, %d with < 20 measurements, %d with < 15\n", Nimage, Nfew, Nbad);
     251      if (showExample) fprintf (stderr, "\n");
     252    }
     253  }
     254  if (MATCHCAT) fprintf (stderr, OFF_T_FMT" total images, %d with < 20 measurements, %d with < 15\n", Nimage, Nfew, Nbad);
    223255}
    224256
     
    245277  }
    246278
     279  if (!ID) return; // detection not associated with an image
     280
    247281  idx = getImageByID (ID);
    248282  if (idx == -1) {
     
    250284    return;
    251285  }
     286  measure->myDet = TRUE; // I 'own' this detection (I am calibrating its image)
    252287
    253288  // index for (catalog, measure) -> image
     
    334369# endif
    335370
    336 /*
    337 Coords *getCoords (off_t meas, int cat) {
    338 
    339   off_t i;
    340 
    341   i = MeasureToImage[cat][meas];
    342   if (i == -1) return (NULL);
    343   return (&image[i].coords);
    344 }
    345 */
    346 
    347371float getColorBlue (off_t meas, int cat) {
    348372
     
    433457  Coords *moscoords, *imcoords;
    434458
    435   // check if this image is bad and should be skipped
    436   if (badCoords(im)) return;
    437 
    438459  // WRP images need to have an associated mosaic
    439460  moscoords = NULL;
     
    491512
    492513    int TESTPT = FALSE;
    493 
    494     TESTPT |= CAT_ID_SRC && OBJ_ID_SRC && (measure->imageID == CAT_ID_SRC) && (measure->detID == OBJ_ID_SRC);
    495     TESTPT |= CAT_ID_DST && OBJ_ID_DST && (measure->imageID == CAT_ID_DST) && (measure->detID == OBJ_ID_DST);
     514    TESTPT |= CAT_ID_SRC && OBJ_ID_SRC && (measure->catID == CAT_ID_SRC) && (measure->objID == OBJ_ID_SRC);
     515    TESTPT |= CAT_ID_DST && OBJ_ID_DST && (measure->catID == CAT_ID_DST) && (measure->objID == OBJ_ID_DST);
    496516    if (TESTPT) {
    497517      fprintf (stderr, "got test det\n");
     
    597617  int Noff = NoffRAave + NoffDECave + NoffRAori + NoffDECori;
    598618  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);
    599   saveOffsets (dPos, nPos, im);
    600619
    601620  return;
     
    604623void printNcatTotal () {
    605624  fprintf (stderr, "NcatTotal: %d\n", NcatTotal);
    606 }
    607 
    608 // return StarData values for detections in the specified image, converting coordinates from the
    609 // chip positions: X,Y -> L,M -> P,Q -> R,D
    610 void resetImageRaw (Catalog *catalog, int Ncatalog, off_t im) {
    611 
    612   off_t i, m, c, n;
    613   double X, Y, L, M, P, Q, R, D;
    614 
    615   Mosaic *mosaic;
    616   Coords *moscoords, *imcoords, *oldcoords;
    617 
    618   fprintf (stderr, "fix resetImageRaw wrt MeasureTiny\n");
    619   abort();
    620 
    621   // check if this image is bad and should be skipped
    622   if (!badCoords(im)) {
    623     fprintf (stderr, "ERROR: inconsistent result?");
    624     abort();
    625   }
    626 
    627   // replace the current coords with the old coords:
    628   oldcoords = getCoords (im);
    629   memcpy (&image[im].coords, oldcoords, sizeof(Coords));
    630 
    631   // WRP images need to have an associated mosaic
    632   moscoords = NULL;
    633   if (!strcmp(&image[im].coords.ctype[4], "-WRP")) {
    634     mosaic = getMosaicForImage (im);
    635     if (mosaic == NULL) return;  // if we cannot find the associated image, skip it
    636     moscoords = &mosaic[0].coords;
    637   }
    638   imcoords = &image[im].coords;
    639 
    640   for (i = 0; i < N_onImage[im]; i++) {
    641     m = ImageToMeasure[im][i];
    642     c = ImageToCatalog[im][i];
    643 
    644     // XXX unclear if this should use Measure or MeasureTiny; it is only called by FixProblemImages, which has not been updated
    645     Measure *measure = &catalog[c].measure[m];
    646 
    647     X = measure[0].Xccd;
    648     Y = measure[0].Yccd;
    649     if (USE_FIXED_PIXCOORDS) {
    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       }
    658     }
    659     n = measure[0].averef;
    660 
    661     if (moscoords == NULL) {
    662       // this is a Simple image (not a mosaic)
    663       // note that for a Simple image, L,M = P,Q
    664       XY_to_LM (&L, &M, X, Y, imcoords);
    665       LM_to_RD (&R, &D, L, M, imcoords);
    666     } else {
    667       XY_to_LM (&L, &M, X, Y, imcoords);
    668       XY_to_LM (&P, &Q, L, M, moscoords);
    669       LM_to_RD (&R, &D, P, Q, moscoords);
    670     }
    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) {
    677       // average on high end of boundary, move star up
    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;
    684     }
    685   }
    686 
    687   return;
    688625}
    689626
     
    736673
    737674    n = measure[0].averef;
     675
     676    int TESTPT = FALSE;
     677    TESTPT |= CAT_ID_SRC && OBJ_ID_SRC && (catalog[c].average[n].catID == CAT_ID_SRC) && (catalog[c].average[n].objID == OBJ_ID_SRC);
     678    TESTPT |= CAT_ID_DST && OBJ_ID_DST && (catalog[c].average[n].catID == CAT_ID_DST) && (catalog[c].average[n].objID == OBJ_ID_DST);
     679    if (TESTPT) {
     680      fprintf (stderr, "got test det\n");
     681    }
    738682
    739683    // an object with only one detection provides no information about the image calibration
     
    808752    ref[i].D = catalog[c].average[n].D;
    809753
     754    // if we are correcting for the Galaxy Motion Model, we assume the mean R,D is at the J2000 epoch position
     755    if (USE_GALAXY_MODEL) {
     756      myAssert (!isnan(measure[0].RoffGAL), "oops");
     757      myAssert (!isnan(measure[0].DoffGAL), "oops");
     758      ref[i].R += measure[0].RoffGAL / 3600.0;
     759      ref[i].D += measure[0].DoffGAL / 3600.0;
     760    }
     761
    810762    ref[i].Mag  = measure[0].M;
    811763    ref[i].dMag = measure[0].dM;
     
    842794  *Nstars = N_onImage[im];
    843795  return (ref);
     796}
     797
     798// return StarData values for detections in the specified image, converting coordinates from the
     799// chip positions: X,Y -> L,M -> P,Q -> R,D.  This function is used by the image fitting steps, for
     800// which the detections have already been filtered when they were loaded (bcatalog)
     801int setImageRaw (Catalog *catalog, int Ncatalog, off_t im, StarData *raw, off_t Nraw, CoordMode mode) {
     802
     803  off_t i, m, c;
     804
     805  Coords *moscoords;
     806
     807  moscoords = NULL;
     808  if (mode == MODE_MOSAIC) {
     809    moscoords = image[im].coords.mosaic;
     810    myAssert (moscoords, "coords.mosaic not defined for image %s (%d)", image[im].name, (int) im);
     811  }
     812
     813  myAssert (Nraw == N_onImage[im], "impossible!");
     814
     815  for (i = 0; i < N_onImage[im]; i++) {
     816    m = ImageToMeasure[im][i];
     817    c = ImageToCatalog[im][i];
     818
     819    // XXX should I use the raw coords or just measure.X,Y -> R,D?
     820
     821    switch (mode) {
     822      case MODE_SIMPLE:
     823        /* note that for a Simple image, L,M = P,Q */
     824        XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[im].coords);
     825        raw[i].P = raw[i].L;
     826        raw[i].Q = raw[i].M;
     827        LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, &image[im].coords);
     828        break;
     829      case MODE_MOSAIC:
     830        XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[im].coords);
     831        XY_to_LM (&raw[i].P, &raw[i].Q, raw[i].L, raw[i].M, moscoords);
     832        LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, moscoords);
     833        break;
     834      default:
     835        fprintf (stderr, "error: invalid mode in getImageRaw");
     836        abort ();
     837    }
     838
     839    MeasureTiny *measure = &catalog[c].measureT[m];
     840    measure->R = raw[i].R;
     841    measure->D = raw[i].D;
     842    if (catalog[c].measure) {
     843      catalog[c].measure[m].R = raw[i].R;
     844      catalog[c].measure[m].D = raw[i].D;
     845    }     
     846  }
     847  return TRUE;
     848}
     849
     850// return StarData values for detections in the specified image, converting coordinates from the
     851// chip positions: X,Y -> L,M -> P,Q -> R,D.  This function is used by the image fitting steps, for
     852// which the detections have already been filtered when they were loaded (bcatalog)
     853int updateImageRaw (Catalog *catalog, int Ncatalog, off_t im) {
     854
     855  off_t i, m, c;
     856
     857  for (i = 0; i < N_onImage[im]; i++) {
     858    m = ImageToMeasure[im][i];
     859    c = ImageToCatalog[im][i];
     860
     861    MeasureTiny *measure = &catalog[c].measureT[m];
     862
     863    /* apply the current image transformation or use the current value of R+dR, D+dD? */
     864    double X = measure[0].Xccd;
     865    double Y = measure[0].Yccd;
     866    if (USE_FIXED_PIXCOORDS) {
     867      if (isfinite(measure[0].Xfix) && isfinite(measure[0].Yfix)) {
     868        float dX = measure[0].Xfix - measure[0].Xccd;
     869        float dY = measure[0].Yfix - measure[0].Yccd;
     870        if (hypot(dX,dY) < 2.0) {
     871          X = measure[0].Xfix;
     872          Y = measure[0].Yfix;
     873        }
     874      }
     875    }
     876
     877    double R, D;
     878    XY_to_RD (&R, &D, X, Y, &image[im].coords);
     879    measure->R = R;
     880    measure->D = D;
     881    if (catalog[c].measure) {
     882      catalog[c].measure[m].R = R;
     883      catalog[c].measure[m].D = D;
     884    }     
     885  }
     886  return TRUE;
    844887}
    845888
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/ImagePosIO.c

    r36630 r37822  
    7070  GET_COLUMN (polyterms,        "POLYTERMS",         float); // verify that we got 14 columns?
    7171  GET_COLUMN (ctype,            "CTYPE",             char);  // verify that we got 15 columns?
    72   GET_COLUMN (Npolyterms,       "NPOLYTERMS",        char);
     72  GET_COLUMN (Npolyterms,       "NPOLYTERMS",        byte);
    7373  GET_COLUMN (dXpixSys,         "XPIX_SYS_ERR",      float);
    7474  GET_COLUMN (dYpixSys,         "YPIX_SYS_ERR",      float);
     75  GET_COLUMN (refColorBlue,     "REF_COLOR_BLUE",    float);
     76  GET_COLUMN (refColorRed,      "REF_COLOR_RED",     float);
    7577  GET_COLUMN (imageID,          "ID",                int);
    7678  GET_COLUMN (nFitAstrom,       "NFIT",              int);
     
    8587  ALLOCATE (image_pos, ImagePos, Nrow);
    8688  for (i = 0; i < Nrow; i++) {
    87     image_pos[i].coords.crval1             = crval1    [i];
    88     image_pos[i].coords.crval2             = crval2    [i];
    89     image_pos[i].coords.crpix1             = crpix1    [i];
    90     image_pos[i].coords.crpix2             = crpix2    [i];
    91     image_pos[i].coords.cdelt1             = cdelt1    [i];
    92     image_pos[i].coords.cdelt2             = cdelt2    [i];
    93     image_pos[i].coords.pc1_1              = pc1_1     [i];
    94     image_pos[i].coords.pc1_2              = pc1_2     [i];
    95     image_pos[i].coords.pc2_1              = pc2_1     [i];
    96     image_pos[i].coords.pc2_2              = pc2_2     [i];
    97     image_pos[i].coords.Npolyterms         = Npolyterms[i];
    98     image_pos[i].dXpixSys                  = dXpixSys  [i];
    99     image_pos[i].dYpixSys                  = dYpixSys  [i];
    100     image_pos[i].imageID                   = imageID   [i];
    101     image_pos[i].nFitAstrom                = nFitAstrom[i];
    102     image_pos[i].flags                     = flags     [i];
     89    InitCoords(&image_pos[i].coords, NULL);
     90    image_pos[i].coords.crval1             = crval1      [i];
     91    image_pos[i].coords.crval2             = crval2      [i];
     92    image_pos[i].coords.crpix1             = crpix1      [i];
     93    image_pos[i].coords.crpix2             = crpix2      [i];
     94    image_pos[i].coords.cdelt1             = cdelt1      [i];
     95    image_pos[i].coords.cdelt2             = cdelt2      [i];
     96    image_pos[i].coords.pc1_1              = pc1_1       [i];
     97    image_pos[i].coords.pc1_2              = pc1_2       [i];
     98    image_pos[i].coords.pc2_1              = pc2_1       [i];
     99    image_pos[i].coords.pc2_2              = pc2_2       [i];
     100    image_pos[i].coords.Npolyterms         = Npolyterms  [i];
     101    image_pos[i].dXpixSys                  = dXpixSys    [i];
     102    image_pos[i].dYpixSys                  = dYpixSys    [i];
     103    image_pos[i].refColorBlue              = refColorBlue[i];
     104    image_pos[i].refColorRed               = refColorRed [i];
     105    image_pos[i].imageID                   = imageID     [i];
     106    image_pos[i].nFitAstrom                = nFitAstrom  [i];
     107    image_pos[i].flags                     = flags       [i];
    103108
    104109    // polyterms and ctype are a bit different
     
    108113  fprintf (stderr, "loaded data for %lld images\n", (long long) Nrow);
    109114
    110   free (crval1    );
    111   free (crval2    );
    112   free (crpix1    );
    113   free (crpix2    );
    114   free (cdelt1    );
    115   free (cdelt2    );
    116   free (pc1_1     );
    117   free (pc1_2     );
    118   free (pc2_1     );
    119   free (pc2_2     );
    120   free (polyterms );
    121   free (ctype     );
    122   free (Npolyterms);
    123   free (dXpixSys  );
    124   free (dYpixSys  );
    125   free (imageID   );
    126   free (nFitAstrom);
    127   free (flags     );
     115  free (crval1      );
     116  free (crval2      );
     117  free (crpix1      );
     118  free (crpix2      );
     119  free (cdelt1      );
     120  free (cdelt2      );
     121  free (pc1_1       );
     122  free (pc1_2       );
     123  free (pc2_1       );
     124  free (pc2_2       );
     125  free (polyterms   );
     126  free (ctype       );
     127  free (Npolyterms  );
     128  free (dXpixSys    );
     129  free (dYpixSys    );
     130  free (refColorBlue);
     131  free (refColorRed );
     132  free (imageID     );
     133  free (nFitAstrom  );
     134  free (flags       );
    128135
    129136  *nimage_pos = Nrow;
     
    153160  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_POS");
    154161
    155   gfits_define_bintable_column (&theader, "D",   "CRVAL1",       "word", "unit", 1.0, 0.0);
    156   gfits_define_bintable_column (&theader, "D",   "CRVAL2",       "word", "unit", 1.0, 0.0);
    157   gfits_define_bintable_column (&theader, "E",   "CRPIX1",       "word", "unit", 1.0, 0.0);
    158   gfits_define_bintable_column (&theader, "E",   "CRPIX2",       "word", "unit", 1.0, 0.0);
    159   gfits_define_bintable_column (&theader, "E",   "CDELT1",       "word", "unit", 1.0, 0.0);
    160   gfits_define_bintable_column (&theader, "E",   "CDELT2",       "word", "unit", 1.0, 0.0);
    161   gfits_define_bintable_column (&theader, "E",   "PC1_1",        "word", "unit", 1.0, 0.0);
    162   gfits_define_bintable_column (&theader, "E",   "PC1_2",        "word", "unit", 1.0, 0.0);
    163   gfits_define_bintable_column (&theader, "E",   "PC2_1",        "word", "unit", 1.0, 0.0);
    164   gfits_define_bintable_column (&theader, "E",   "PC2_2",        "word", "unit", 1.0, 0.0);
    165   gfits_define_bintable_column (&theader, "14E", "POLYTERMS",    "word", "unit", 1.0, 0.0);
    166   gfits_define_bintable_column (&theader, "15A", "CTYPE",        "word", "unit", 1.0, 0.0);
    167   gfits_define_bintable_column (&theader, "L",   "NPOLYTERMS",   "word", "unit", 1.0, 0.0);
    168   gfits_define_bintable_column (&theader, "E",   "XPIX_SYS_ERR", "word", "unit", 1.0, 0.0);
    169   gfits_define_bintable_column (&theader, "E",   "YPIX_SYS_ERR", "word", "unit", 1.0, 0.0);
    170   gfits_define_bintable_column (&theader, "J",   "ID",           "image ID",               "unitless", 1.0, 0.0);
    171   gfits_define_bintable_column (&theader, "J",   "NFIT",         "number of fitted stars", "unitless", 1.0, 0.0);
    172   gfits_define_bintable_column (&theader, "J",   "FLAGS",        "analysis flags",         "unitless", 1.0, 0.0);
     162  gfits_define_bintable_column (&theader, "D",   "CRVAL1",         "word", "unit", 1.0, 0.0);
     163  gfits_define_bintable_column (&theader, "D",   "CRVAL2",         "word", "unit", 1.0, 0.0);
     164  gfits_define_bintable_column (&theader, "E",   "CRPIX1",         "word", "unit", 1.0, 0.0);
     165  gfits_define_bintable_column (&theader, "E",   "CRPIX2",         "word", "unit", 1.0, 0.0);
     166  gfits_define_bintable_column (&theader, "E",   "CDELT1",         "word", "unit", 1.0, 0.0);
     167  gfits_define_bintable_column (&theader, "E",   "CDELT2",         "word", "unit", 1.0, 0.0);
     168  gfits_define_bintable_column (&theader, "E",   "PC1_1",          "word", "unit", 1.0, 0.0);
     169  gfits_define_bintable_column (&theader, "E",   "PC1_2",          "word", "unit", 1.0, 0.0);
     170  gfits_define_bintable_column (&theader, "E",   "PC2_1",          "word", "unit", 1.0, 0.0);
     171  gfits_define_bintable_column (&theader, "E",   "PC2_2",          "word", "unit", 1.0, 0.0);
     172  gfits_define_bintable_column (&theader, "14E", "POLYTERMS",      "word", "unit", 1.0, 0.0);
     173  gfits_define_bintable_column (&theader, "15A", "CTYPE",          "word", "unit", 1.0, 0.0);
     174  gfits_define_bintable_column (&theader, "L",   "NPOLYTERMS",     "word", "unit", 1.0, 0.0);
     175  gfits_define_bintable_column (&theader, "E",   "XPIX_SYS_ERR",   "word", "unit", 1.0, 0.0);
     176  gfits_define_bintable_column (&theader, "E",   "YPIX_SYS_ERR",   "word", "unit", 1.0, 0.0);
     177  gfits_define_bintable_column (&theader, "E",   "REF_COLOR_BLUE", "word", "unit", 1.0, 0.0);
     178  gfits_define_bintable_column (&theader, "E",   "REF_COLOR_RED",  "word", "unit", 1.0, 0.0);
     179  gfits_define_bintable_column (&theader, "J",   "ID",             "image ID",               "unitless", 1.0, 0.0);
     180  gfits_define_bintable_column (&theader, "J",   "NFIT",           "number of fitted stars", "unitless", 1.0, 0.0);
     181  gfits_define_bintable_column (&theader, "J",   "FLAGS",          "analysis flags",         "unitless", 1.0, 0.0);
    173182
    174183  // generate the output array that carries the data
    175184  gfits_create_table (&theader, &ftable);
    176185
    177   double *crval1    ;
    178   double *crval2    ;
    179   float  *crpix1    ;
    180   float  *crpix2    ;
    181   float  *cdelt1    ;
    182   float  *cdelt2    ;
    183   float  *pc1_1     ;
    184   float  *pc1_2     ;
    185   float  *pc2_1     ;
    186   float  *pc2_2     ;
    187   float  *polyterms ;
    188   char   *ctype     ;
    189   char   *Npolyterms;
    190   float  *dXpixSys  ;
    191   float  *dYpixSys  ;
    192   int    *imageID   ;
    193   int    *nFitAstrom;
    194   int    *flags     ;
     186  double *crval1      ;
     187  double *crval2      ;
     188  float  *crpix1      ;
     189  float  *crpix2      ;
     190  float  *cdelt1      ;
     191  float  *cdelt2      ;
     192  float  *pc1_1       ;
     193  float  *pc1_2       ;
     194  float  *pc2_1       ;
     195  float  *pc2_2       ;
     196  float  *polyterms   ;
     197  char   *ctype       ;
     198  char   *Npolyterms  ;
     199  float  *dXpixSys    ;
     200  float  *dYpixSys    ;
     201  float  *refColorBlue;
     202  float  *refColorRed ;
     203  int    *imageID     ;
     204  int    *nFitAstrom  ;
     205  int    *flags       ;
    195206
    196207  // create intermediate storage arrays
     
    210221  ALLOCATE (dXpixSys  ,         float ,          Nimage_pos);
    211222  ALLOCATE (dYpixSys  ,         float ,          Nimage_pos);
     223  ALLOCATE (refColorBlue,       float ,          Nimage_pos);
     224  ALLOCATE (refColorRed ,       float ,          Nimage_pos);
    212225  ALLOCATE (imageID   ,         int   ,          Nimage_pos);
    213226  ALLOCATE (nFitAstrom,         int   ,          Nimage_pos);
     
    216229  // assign the storage arrays
    217230  for (i = 0; i < Nimage_pos; i++) {
    218     crval1    [i] = image_pos[i].coords.crval1    ;
    219     crval2    [i] = image_pos[i].coords.crval2    ;
    220     crpix1    [i] = image_pos[i].coords.crpix1    ;
    221     crpix2    [i] = image_pos[i].coords.crpix2    ;
    222     cdelt1    [i] = image_pos[i].coords.cdelt1    ;
    223     cdelt2    [i] = image_pos[i].coords.cdelt2    ;
    224     pc1_1     [i] = image_pos[i].coords.pc1_1     ;
    225     pc1_2     [i] = image_pos[i].coords.pc1_2     ;
    226     pc2_1     [i] = image_pos[i].coords.pc2_1     ;
    227     pc2_2     [i] = image_pos[i].coords.pc2_2     ;
    228     Npolyterms[i] = image_pos[i].coords.Npolyterms;
    229     dXpixSys  [i] = image_pos[i].dXpixSys         ;
    230     dYpixSys  [i] = image_pos[i].dYpixSys         ;
    231     imageID   [i] = image_pos[i].imageID          ;
    232     nFitAstrom[i] = image_pos[i].nFitAstrom       ;
    233     flags     [i] = image_pos[i].flags            ;
     231    crval1      [i] = image_pos[i].coords.crval1    ;
     232    crval2      [i] = image_pos[i].coords.crval2    ;
     233    crpix1      [i] = image_pos[i].coords.crpix1    ;
     234    crpix2      [i] = image_pos[i].coords.crpix2    ;
     235    cdelt1      [i] = image_pos[i].coords.cdelt1    ;
     236    cdelt2      [i] = image_pos[i].coords.cdelt2    ;
     237    pc1_1       [i] = image_pos[i].coords.pc1_1     ;
     238    pc1_2       [i] = image_pos[i].coords.pc1_2     ;
     239    pc2_1       [i] = image_pos[i].coords.pc2_1     ;
     240    pc2_2       [i] = image_pos[i].coords.pc2_2     ;
     241    Npolyterms  [i] = image_pos[i].coords.Npolyterms;
     242    dXpixSys    [i] = image_pos[i].dXpixSys         ;
     243    dYpixSys    [i] = image_pos[i].dYpixSys         ;
     244    refColorBlue[i] = image_pos[i].refColorBlue     ;
     245    refColorRed [i] = image_pos[i].refColorRed      ;
     246    imageID     [i] = image_pos[i].imageID          ;
     247    nFitAstrom  [i] = image_pos[i].nFitAstrom       ;
     248    flags       [i] = image_pos[i].flags            ;
    234249
    235250    // polyterms and ctype are a bit different
     
    239254
    240255  // add the columns to the output array
    241   gfits_set_bintable_column (&theader, &ftable, "CRVAL1",      crval1    ,         Nimage_pos);
    242   gfits_set_bintable_column (&theader, &ftable, "CRVAL2",      crval2    ,         Nimage_pos);
    243   gfits_set_bintable_column (&theader, &ftable, "CRPIX1",      crpix1    ,         Nimage_pos);
    244   gfits_set_bintable_column (&theader, &ftable, "CRPIX2",      crpix2    ,         Nimage_pos);
    245   gfits_set_bintable_column (&theader, &ftable, "CDELT1",      cdelt1    ,         Nimage_pos);
    246   gfits_set_bintable_column (&theader, &ftable, "CDELT2",      cdelt2    ,         Nimage_pos);
    247   gfits_set_bintable_column (&theader, &ftable, "PC1_1",       pc1_1     ,         Nimage_pos);
    248   gfits_set_bintable_column (&theader, &ftable, "PC1_2",       pc1_2     ,         Nimage_pos);
    249   gfits_set_bintable_column (&theader, &ftable, "PC2_1",       pc2_1     ,         Nimage_pos);
    250   gfits_set_bintable_column (&theader, &ftable, "PC2_2",       pc2_2     ,         Nimage_pos);
    251   gfits_set_bintable_column (&theader, &ftable, "POLYTERMS",   polyterms ,         Nimage_pos);
    252   gfits_set_bintable_column (&theader, &ftable, "CTYPE",       ctype     ,         Nimage_pos);
    253   gfits_set_bintable_column (&theader, &ftable, "NPOLYTERMS",  Npolyterms,         Nimage_pos);
    254   gfits_set_bintable_column (&theader, &ftable, "XPIX_SYS_ERR",dXpixSys  ,         Nimage_pos);
    255   gfits_set_bintable_column (&theader, &ftable, "YPIX_SYS_ERR",dYpixSys  ,         Nimage_pos);
    256   gfits_set_bintable_column (&theader, &ftable, "ID",          imageID   ,         Nimage_pos);
    257   gfits_set_bintable_column (&theader, &ftable, "NFIT",        nFitAstrom,         Nimage_pos);
    258   gfits_set_bintable_column (&theader, &ftable, "FLAGS",       flags     ,         Nimage_pos);
    259 
    260   free (crval1    );
    261   free (crval2    );
    262   free (crpix1    );
    263   free (crpix2    );
    264   free (cdelt1    );
    265   free (cdelt2    );
    266   free (pc1_1     );
    267   free (pc1_2     );
    268   free (pc2_1     );
    269   free (pc2_2     );
    270   free (polyterms );
    271   free (ctype     );
    272   free (Npolyterms);
    273   free (dXpixSys  );
    274   free (dYpixSys  );
    275   free (imageID   );
    276   free (nFitAstrom);
    277   free (flags     );
     256  gfits_set_bintable_column (&theader, &ftable, "CRVAL1",         crval1    ,         Nimage_pos);
     257  gfits_set_bintable_column (&theader, &ftable, "CRVAL2",         crval2    ,         Nimage_pos);
     258  gfits_set_bintable_column (&theader, &ftable, "CRPIX1",         crpix1    ,         Nimage_pos);
     259  gfits_set_bintable_column (&theader, &ftable, "CRPIX2",         crpix2    ,         Nimage_pos);
     260  gfits_set_bintable_column (&theader, &ftable, "CDELT1",         cdelt1    ,         Nimage_pos);
     261  gfits_set_bintable_column (&theader, &ftable, "CDELT2",         cdelt2    ,         Nimage_pos);
     262  gfits_set_bintable_column (&theader, &ftable, "PC1_1",          pc1_1     ,         Nimage_pos);
     263  gfits_set_bintable_column (&theader, &ftable, "PC1_2",          pc1_2     ,         Nimage_pos);
     264  gfits_set_bintable_column (&theader, &ftable, "PC2_1",          pc2_1     ,         Nimage_pos);
     265  gfits_set_bintable_column (&theader, &ftable, "PC2_2",          pc2_2     ,         Nimage_pos);
     266  gfits_set_bintable_column (&theader, &ftable, "POLYTERMS",      polyterms ,         Nimage_pos);
     267  gfits_set_bintable_column (&theader, &ftable, "CTYPE",          ctype     ,         Nimage_pos);
     268  gfits_set_bintable_column (&theader, &ftable, "NPOLYTERMS",     Npolyterms,         Nimage_pos);
     269  gfits_set_bintable_column (&theader, &ftable, "XPIX_SYS_ERR",   dXpixSys  ,         Nimage_pos);
     270  gfits_set_bintable_column (&theader, &ftable, "YPIX_SYS_ERR",   dYpixSys  ,         Nimage_pos);
     271  gfits_set_bintable_column (&theader, &ftable, "REF_COLOR_BLUE", refColorBlue,       Nimage_pos);
     272  gfits_set_bintable_column (&theader, &ftable, "REF_COLOR_RED",  refColorRed ,       Nimage_pos);
     273  gfits_set_bintable_column (&theader, &ftable, "ID",             imageID   ,         Nimage_pos);
     274  gfits_set_bintable_column (&theader, &ftable, "NFIT",           nFitAstrom,         Nimage_pos);
     275  gfits_set_bintable_column (&theader, &ftable, "FLAGS",          flags     ,         Nimage_pos);
     276
     277  free (crval1      );
     278  free (crval2      );
     279  free (crpix1      );
     280  free (crpix2      );
     281  free (cdelt1      );
     282  free (cdelt2      );
     283  free (pc1_1       );
     284  free (pc1_2       );
     285  free (pc2_1       );
     286  free (pc2_2       );
     287  free (polyterms   );
     288  free (ctype       );
     289  free (Npolyterms  );
     290  free (dXpixSys    );
     291  free (dYpixSys    );
     292  free (refColorBlue);
     293  free (refColorRed );
     294  free (imageID     );
     295  free (nFitAstrom  );
     296  free (flags       );
    278297 
    279298  FILE *f = fopen (filename, "w");
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/ParFactor.c

    r33652 r37822  
    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/ipp-pv3-20140717-merge/Ohana/src/relastro/src/StarMaps.c

    r36630 r37822  
    176176}
    177177
     178int printStarMap(int N, char *filename) {
     179
     180  off_t i, Nimages;
     181  Image *images = getimages(&Nimages, NULL);
     182  double L, M;
     183
     184  FILE *f = fopen (filename, "w");
     185
     186  for (i = 0; i < starmap[N].Npoints; i++) {
     187    // set the transformed coordinates
     188    XY_to_LM (&L, &M, starmap[N].points[i].X, starmap[N].points[i].Y, &images[N].coords);
     189
     190    fprintf (f, "%d %7.2f %f : %7.2f %7.2f : %7.2f %7.2f : %7.2f %7.2f\n", (int) i, starmap[N].points[i].X, starmap[N].points[i].Y, starmap[N].points[i].L, starmap[N].points[i].M, L, M, starmap[N].points[i].L - L, starmap[N].points[i].M - M);
     191  }
     192  fclose (f);
     193  return (TRUE);
     194}
     195
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/UpdateChips.c

    r33652 r37822  
    3636  off_t i, Nraw, Nref, nFitAstr;
    3737  StarData *raw, *ref;
    38   Coords *oldCoords;
    3938  float dXpixSys, dYpixSys;
    4039  double *Ro, *Do;
     
    7473      Nskip ++;
    7574      mode[i] = 0;
     75      continue;
     76    }
     77    if (Nraw <= IMFIT_TOO_FEW) {
     78      Nskip ++;
     79      mode[i] = 0;
     80      free (raw);
    7681      continue;
    7782    }
     
    9095
    9196    // save these in case of failure
    92     saveCoords (&image[i].coords, i);
     97    Coords oldCoords;
     98    SaveCoords (&oldCoords, &image[i].coords);
     99
    93100    dXpixSys = image[i].dXpixSys;
    94101    dYpixSys = image[i].dYpixSys;
     
    100107      if (VERBOSE) fprintf (stderr, "reject fit for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT" of %d\n", image[i].name,  i,  Nraw, image[i].nstar);
    101108
    102       // restore status quo ante
    103       oldCoords = getCoords (i);
    104       memcpy (&image[i].coords, oldCoords, sizeof(Coords));
    105       image[i].dXpixSys = dXpixSys;
    106       image[i].dYpixSys = dYpixSys;
    107       image[i].nFitAstrom = nFitAstr;
    108 
    109       saveCenter (image, &Ro[i], &Do[i], i);
    110       mode[i] = 1;
    111       NoldFit ++;
    112       free (raw);
    113       free (ref);
    114       continue;
     109      if (1) {
     110        // restore status quo ante (replace truMap with tmpMap)
     111        RestoreCoords (&image[i].coords, &oldCoords, &image[i]);
     112        image[i].dXpixSys = dXpixSys;
     113        image[i].dYpixSys = dYpixSys;
     114        image[i].nFitAstrom = nFitAstr;
     115
     116        saveCenter (image, &Ro[i], &Do[i], i);
     117        mode[i] = 1;
     118        NoldFit ++;
     119        free (raw);
     120        free (ref);
     121        continue;
     122      }
    115123    }
    116124
    117125    if (!checkStarMap (i)) {
    118126      if (VERBOSE) fprintf (stderr, "fit diverges too much for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name,  i,  Nraw);
    119       // restore status quo ante
    120       oldCoords = getCoords (i);
    121       memcpy (&image[i].coords, oldCoords, sizeof(Coords));
    122       image[i].dXpixSys = dXpixSys;
    123       image[i].dYpixSys = dYpixSys;
    124       image[i].nFitAstrom = nFitAstr;
    125 
    126       saveCenter (image, &Ro[i], &Do[i], i);
    127       mode[i] = 2;
    128       image[i].flags |= ID_IMAGE_ASTROM_POOR;
    129       NoldFit ++;
    130       free (raw);
    131       free (ref);
    132       continue;
     127
     128      if (1) {
     129        // restore status quo ante (replace truMap with tmpMap)
     130        RestoreCoords (&image[i].coords, &oldCoords, &image[i]);
     131        image[i].dXpixSys = dXpixSys;
     132        image[i].dYpixSys = dYpixSys;
     133        image[i].nFitAstrom = nFitAstr;
     134
     135        saveCenter (image, &Ro[i], &Do[i], i);
     136        mode[i] = 2;
     137        image[i].flags |= ID_IMAGE_ASTROM_POOR;
     138        NoldFit ++;
     139        free (raw);
     140        free (ref);
     141        continue;
     142      }
    133143    }
     144
     145    // Apply the modified coords back to the measure.R,D.  Note that raw.R,D, ref.L,M, etc
     146    // are all automatically updated in this block because they are re-generated from
     147    // image.coords on each pass.
     148    setImageRaw (catalog, Ncatalog, i, raw, Nraw, MODE_MOSAIC);
     149    if (USE_GALAXY_MODEL) {
     150      image[i].flags |= ID_IMAGE_ASTROM_GMM;
     151    }
    134152
    135153    saveCenter (image, &Ro[i], &Do[i], i);
     
    235253  off_t Nraw, Nref, nFitAstr;
    236254  StarData *raw, *ref;
    237   Coords *oldCoords;
    238255  float dXpixSys, dYpixSys;
    239256
     
    260277      threadinfo->Nskip ++;
    261278      threadinfo->mode[i] = 0;
     279      continue;
     280    }
     281    if (Nraw <= IMFIT_TOO_FEW) {
     282      threadinfo->Nskip ++;
     283      threadinfo->mode[i] = 0;
     284      free (raw);
    262285      continue;
    263286    }
     
    276299
    277300    // save these in case of failure
    278     saveCoords (&image[i].coords, i);
     301    Coords oldCoords;
     302    SaveCoords (&oldCoords, &image[i].coords);
    279303    dXpixSys = image[i].dXpixSys;
    280304    dYpixSys = image[i].dYpixSys;
     
    286310      if (VERBOSE) fprintf (stderr, "reject fit for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT" of %d\n", image[i].name,  i,  Nraw, image[i].nstar);
    287311
    288       // restore status quo ante
    289       oldCoords = getCoords (i);
    290       memcpy (&image[i].coords, oldCoords, sizeof(Coords));
     312      // restore status quo ante (replace truMap with tmpMap)
     313      RestoreCoords (&image[i].coords, &oldCoords, &image[i]);
    291314      image[i].dXpixSys = dXpixSys;
    292315      image[i].dYpixSys = dYpixSys;
     
    303326    if (!checkStarMap (i)) {
    304327      if (VERBOSE) fprintf (stderr, "fit diverges too much for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name,  i,  Nraw);
    305       // restore status quo ante
    306       oldCoords = getCoords (i);
    307       memcpy (&image[i].coords, oldCoords, sizeof(Coords));
     328
     329      // restore status quo ante (replace truMap with tmpMap)
     330      RestoreCoords (&image[i].coords, &oldCoords, &image[i]);
    308331      image[i].dXpixSys = dXpixSys;
    309332      image[i].dYpixSys = dYpixSys;
     
    319342    }
    320343
     344    // apply the modified R,D back to the measures
     345    setImageRaw (threadinfo->catalog, threadinfo->Ncatalog, i, raw, Nraw, MODE_MOSAIC);
     346
    321347    saveCenter (image, &threadinfo->Ro[i], &threadinfo->Do[i], i);
    322348    threadinfo->mode[i] = 3;
     
    333359static pthread_mutex_t UpdateChips_mutex = PTHREAD_MUTEX_INITIALIZER;
    334360
     361void lockUpdateChips () {
     362  pthread_mutex_lock (&UpdateChips_mutex);
     363}
     364void unlockUpdateChips () {
     365  pthread_mutex_unlock (&UpdateChips_mutex);
     366}
     367
    335368// we have an array of chips (image, Nimage).  we need to hand out images one at a time to
    336369// the worker threads as they need
    337370off_t getNextImageForThread () {
    338371
    339   pthread_mutex_lock (&UpdateChips_mutex);
     372  lockUpdateChips ();
    340373  if (nextImage >= Nimage) {
    341     pthread_mutex_unlock (&UpdateChips_mutex);
     374    unlockUpdateChips ();
    342375    return (-1);
    343376  }
     
    345378  nextImage ++;
    346379
    347   pthread_mutex_unlock (&UpdateChips_mutex);
     380  unlockUpdateChips ();
    348381  return (thisImage);
    349382}
     
    494527}
    495528
    496 // XXX if (!FindMosaicForImage (image, Nimage, i)) { }
     529// save the coords and offset map in src at tgt
     530void SaveCoords (Coords *tgt, Coords *src) {
     531  myAssert (tgt, "oops");
     532  myAssert (src, "oops");
     533  CopyCoords (tgt, src); // src retains a pointer to the AstromOffsetMap table, to be saved
     534  tgt->offsetMap = AstromOffsetMapCopy(src->offsetMap); // oldCoords now saves the old values in a new structure
     535}
     536
     537// restore the coords and offset map at tgt from src
     538void RestoreCoords (Coords *tgt, Coords *src, Image *image) {
     539
     540  AstromOffsetMap *truMap = tgt->offsetMap;
     541  AstromOffsetMap *tmpMap = src->offsetMap;
     542
     543  // copy the coords structure data first, then fix the offsetMap pointers
     544  // this modifies tgt.coords, but we need to keep the original pointer
     545  CopyCoords (tgt, src);
     546  tgt->offsetMap = truMap;
     547
     548  // we want to keep the old solution, which is (maybe) a pointer to a stand-alone
     549  // map.  the image has a bad solution, but it is a pointer to the map in the I/O
     550  // table.  those values will be saved on exit.
     551
     552  if (!tmpMap && !truMap) return;
     553
     554  if (tmpMap && truMap) {
     555    AstromOffsetMapSetOrder (truMap, tmpMap->Nx, tmpMap->Ny, image);
     556    AstromOffsetMapCopyData (truMap, tmpMap);
     557    return;
     558  }
     559
     560  if (tmpMap && !truMap) {
     561    // is this even possible?
     562    lockUpdateChips ();
     563    AstromOffsetTable *table = get_astrom_table ();
     564    AstromOffsetTableNewMap(table, tmpMap->Nx, tmpMap->Ny, image);  // registers the map with the image
     565    unlockUpdateChips ();
     566    AstromOffsetMapCopyData (image->coords.offsetMap, tmpMap);
     567    return;
     568  }
     569  if (!tmpMap && truMap) {
     570    truMap->keep = FALSE;
     571    return;
     572  }
     573  myAbort ("oops");
     574}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/UpdateMeasures.c

    r35763 r37822  
    11# include "relastro.h"
     2void dump_measures (Average *average, Measure *measure); // in ImageOps.c
    23
    3 void printNcatTotal ();
     4// this function is called by UpdateObjectOffsets or relastro_images.c for reset
     5int UpdateMeasures (Catalog *catalog, int Ncatalog) {
     6
     7  off_t i, j, Nimage;
     8  Image *image;
     9  double DPOS_MAX_ASEC;
     10
     11  int badImage =
     12    ID_IMAGE_ASTROM_NOCAL |
     13    ID_IMAGE_ASTROM_POOR |
     14    ID_IMAGE_ASTROM_FAIL |
     15    ID_IMAGE_ASTROM_SKIP |
     16    ID_IMAGE_ASTROM_FEW;
     17
     18  if (RESET_BAD_IMAGES) badImage = 0;
     19
     20  image = getimages (&Nimage, NULL);
     21
     22  // track measurements which are far from their original position (poor at pole)
     23  int NoffRAave = 0;  int NoffRAori = 0;
     24  int NoffDECave = 0; int NoffDECori = 0;
     25
     26  for (i = 0; i < Ncatalog; i++) {
     27    myAssert (!catalog[i].Nmeasure || catalog[i].measureT, "programming error");
     28    for (j = 0; j < catalog[i].Nmeasure; j++) {
     29      MeasureTiny *measureT = &catalog[i].measureT[j];
     30      Measure     *measureB = catalog[i].measure ? &catalog[i].measure[j] : NULL;
     31
     32      off_t im = getImageByID (measureT->imageID);
     33      if (im < 0) continue; // detections without imageIDs are not associated with a known image (eg, refs)
     34
     35      // check that we have the right image:
     36      myAssert (measureT->photcode == image[im].photcode, "image photcode mismatch");
     37      myAssert (measureT->t >= image[im].tzero, "image time mismatch (1)");
     38      myAssert (measureT->t <= image[im].tzero + image[im].NX*image[im].trate/5000.0, "image time mismatch (2)");
     39      // I'm allowing the trate*NX to be a factor of 2x too small
     40
     41      // skip measurements on images that have failed solutions (divergent or otherwise)
     42      // XXX apply this or not??
     43      if (FALSE && (image[im].flags & badImage)) continue;
     44
     45      Coords *moscoords = image[im].coords.mosaic;
     46      Coords *imcoords = &image[im].coords;
     47
     48      if (moscoords) {
     49        DPOS_MAX_ASEC = 3600.0*DPOS_MAX*hypot(moscoords->cdelt1, moscoords->cdelt2);
     50      } else {
     51        DPOS_MAX_ASEC = 3600.0*DPOS_MAX*hypot(imcoords->cdelt1, imcoords->cdelt2);
     52      }
     53
     54      double X = measureT->Xccd;
     55      double Y = measureT->Yccd;
     56      if (USE_FIXED_PIXCOORDS) {
     57        if (isfinite(measureT->Xfix) && isfinite(measureT->Yfix)) {
     58          float dX = measureT->Xfix - measureT->Xccd;
     59          float dY = measureT->Yfix - measureT->Yccd;
     60          if (hypot(dX,dY) < 2.0) {
     61            X = measureT->Xfix;
     62            Y = measureT->Yfix;
     63          }
     64        }
     65      }
     66
     67      double R, D;
     68      XY_to_RD (&R, &D, X, Y, imcoords);
     69
     70      int n = measureT[0].averef;
     71      Average *average = &catalog[i].average[n];
     72
     73      double dR = 3600.0*(average[0].R - R);
     74      double dD = 3600.0*(average[0].D - D);
     75
     76      // make sure detection is on the same side of the 0,360 boundary as the average
     77      // this will give some funny results withing ~1 arcsec of the pol
     78      if (dR > +180.0*3600.0) {
     79        // average on high end of boundary, move star up
     80        R += 360.0;
     81        dR = 3600.0*(average[0].R - R);
     82      }
     83      if (dR < -180.0*3600.0) {
     84        // average on low end of boundary, move star down
     85        R -= 360.0;
     86        dR = 3600.0*(average[0].R - R);
     87      }
     88
     89      float csdec = cos(average[0].D * RAD_DEG);
     90
     91      // complain if the new location is far from the average location
     92      // NOTE: This should never happen, or our StarMap tests are not working
     93      if (fabs(dR*csdec) > 3.0*ADDSTAR_RADIUS) {
     94        NoffRAave ++;
     95        if (VERBOSE2 && catalog[i].measure) {
     96          fprintf (stderr, "measurement is far from average location (R): %f %f (%f %f %f)\n", average[0].R, average[0].D, dR, dR*csdec, dD);
     97          dump_measures (&average[0], catalog[i].measure);
     98        }
     99      }
     100      if (fabs(dD) > 3.0*ADDSTAR_RADIUS) {
     101        NoffDECave ++;
     102        if (VERBOSE2 && catalog[i].measure) {
     103          fprintf (stderr, "measurement is far from average location (D): %f %f (%f %f)\n", average[0].R, average[0].D, dR, dD);
     104          dump_measures (&average[0], catalog[i].measure);
     105        }
     106      }
     107
     108      // complain if the new location is far from the old location
     109      if (fabs(csdec*(measureT[0].R - R)) > DPOS_MAX_ASEC) {
     110        NoffRAori ++;
     111        if (VERBOSE2 && catalog[i].measure) {
     112          fprintf (stderr, "measurement moves far from original location (R): %f %f (%f %f %f %f)\n", average[0].R, average[0].D, measureT[0].R, dR, csdec*(measureT[0].R - R), dD);
     113          dump_measures (&average[0], catalog[i].measure);
     114        }
     115      }
     116      if (fabs(measureT[0].D - D) > DPOS_MAX_ASEC) {
     117        NoffDECori ++;
     118        if (VERBOSE2 && catalog[i].measure) {
     119          fprintf (stderr, "measurement moves far from original location (D): %f %f (%f %f %f)\n", average[0].R, average[0].D, dR, measureT[0].D, dD);
     120          dump_measures (&average[0], catalog[i].measure);
     121        }
     122      }
     123      measureT->R = R;
     124      measureT->D = D;
     125      if (measureB) {
     126        measureB->R = R;
     127        measureB->D = D;
     128      }
     129    }
     130  }
     131  // printNcatTotal ();
     132
     133  int Noff = NoffRAave + NoffDECave + NoffRAori + NoffDECori;
     134  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);
     135
     136  return (TRUE);
     137}
    4138
    5139// this function operates on Measure, not MeasureTiny
    6 int UpdateMeasures (Catalog *catalog, int Ncatalog) {
     140int UpdateMeasuresOld (Catalog *catalog, int Ncatalog) {
    7141
    8142  off_t i, Nimage;
     
    32166  }
    33167
    34   printNcatTotal ();
     168  // printNcatTotal ();
    35169
    36170  return (TRUE);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/UpdateObjectOffsets.c

    r37038 r37822  
    5959
    6060    // uses MeasureTiny values, but will also update Measure values when populated
    61     UpdateObjects (&catalog, 1);
     61    // if Galaxy Motion Model correction is active, do not apply at this last stage
     62    UpdateObjects (&catalog, 1, FALSE);
    6263
    6364    free_tiny_values(&catalog);
     
    7475    save_catalogs (&catalog, 1);
    7576  }
    76  
     77  printNcatTotal();
    7778  return (TRUE);
    7879}
     80
     81int UpdateObjectOffsets_parallel_group (HostTableGroup *group, SkyList *sky);
     82int UpdateObjectOffsets_parallel_table (HostTable *table, SkyList *sky);
    7983
    8084// CATDIR is supplied globally
     
    9094    exit (1);
    9195  }   
     96
     97# if (0)
     98 
     99  UpdateObjectOffsets_parallel_table (table, sky);
     100
     101# else
     102
     103  int Ngroups;
     104  HostTableGroup *groups = HostTableGroups (table, &Ngroups);
     105  // split the table into Ngroups, each with a unique set of machines (this avoids overloading the remote host machines)
     106
     107  int i;
     108  for (i = 0; i < Ngroups; i++) {
     109    // update only a group of unique machines at a time
     110    UpdateObjectOffsets_parallel_group (&groups[i], sky);
     111  }
     112# endif
     113
     114  return TRUE;
     115}     
     116
     117// CATDIR is supplied globally
     118# define DEBUG 1
     119int UpdateObjectOffsets_parallel_group (HostTableGroup *group, SkyList *sky) {
     120
     121  // launch the relastro_client jobs to the parallel hosts
     122
     123  int i, j;
     124  for (i = 0; i < group->Nhosts; i++) {
     125
     126    if (sky->Nregions < group->Nhosts) {
     127      // do any of the regions want this host?
     128      int wantThisHost = FALSE;
     129      for (j = 0; j < sky->Nregions; j++) {
     130        if (HostTableTestHost (sky->regions[j], group->hosts[i][0].hostID)) {
     131          wantThisHost = TRUE;
     132          break;
     133        }
     134      }
     135      if (!wantThisHost) {
     136        // fprintf (stderr, "skip host %s\n", group->hosts[i][0].hostname);
     137        continue;
     138      }
     139    }
     140
     141    // ensure that the paths are absolute path names
     142    char *tmppath = abspath (group->hosts[i][0].pathname, DVO_MAX_PATH);
     143    free (group->hosts[i][0].pathname);
     144    group->hosts[i][0].pathname = tmppath;
     145
     146    // options / arguments that can affect relastro_client -load:
     147    // VERBOSE, VERBOSE2
     148    // RESET (-reset)
     149    // TimeSelect -time
     150    // (note that psfQF is applied rigidly at 0.85, as is the galaxy test)
     151    // ImagSelect, ImagMin, ImagMax
     152    // MaxDensityUse, MaxDensityValue
     153
     154    char command[1024];
     155    snprintf (command, 1024, "relastro_client -update-offsets -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -minerror %f",
     156              group->hosts[i][0].hostID, CATDIR, group->hosts[i][0].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, MIN_ERROR);
     157
     158    if (FIT_MODE == FIT_PM_ONLY)         strextend (command, "-pm");
     159    if (FIT_MODE == FIT_PAR_ONLY)        strextend (command, "-par");
     160    if (FIT_MODE == FIT_PM_AND_PAR)      strextend (command, "-pmpar");
     161
     162    if (VERBOSE)       strextend (command, "-v");
     163    if (VERBOSE2)      strextend (command, "-vv");
     164    if (RESET)         strextend (command, "-reset");
     165    if (UPDATE)        strextend (command, "-update");
     166
     167    if (RESET_BAD_IMAGES) strextend (command, "-reset-bad-images");
     168
     169    if (ImagSelect)    strextend (command, "-instmag %f %f", ImagMin, ImagMax);
     170    if (MaxDensityUse) strextend (command, "-max-density %f", MaxDensityValue);
     171   
     172    if (USE_BASIC_CHECK) strextend (command, "-basic-image-search");
     173    if (FlagOutlier)     strextend (command, "-clip %d", CLIP_THRESH);
     174    if (ExcludeBogus)    strextend (command, "-exclude-bogus %f", ExcludeBogusRadius);
     175   
     176    if (USE_FIXED_PIXCOORDS) strextend (command, "-D USE_FIXED_PIXCOORDS 1");
     177
     178    if (PHOTCODE_KEEP_LIST) strextend (command, "+photcode %s", PHOTCODE_KEEP_LIST);
     179    if (PHOTCODE_SKIP_LIST) strextend (command, "-photcode %s", PHOTCODE_SKIP_LIST);
     180    if (PhotFlagSelect)     strextend (command, "+photflags");
     181    if (PhotFlagBad)        strextend (command, "+photflagbad %d", PhotFlagBad);
     182    if (PhotFlagPoor)       strextend (command, "+photflagpoor %d", PhotFlagPoor);
     183    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
     184
     185    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
     186      strextend (command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     187    }
     188    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
     189      strextend (command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
     190    }
     191
     192    if (MinBadQF > 0.0)        strextend (command, "-min-bad-psfqf %f", MinBadQF);
     193    if (MaxMeanOffset != 10.0) strextend (command, "-max-mean-offset  %f", MaxMeanOffset);
     194
     195    if (TimeSelect) {
     196      char *tstart = ohana_sec_to_date (TSTART);
     197      char *tstop  = ohana_sec_to_date (TSTOP);
     198      strextend (command, "-time %s %s", tstart, tstop);
     199      free (tstart);
     200      free (tstop);
     201    }
     202    fprintf (stderr, "command: %s\n", command);
     203
     204    if (PARALLEL_MANUAL) continue;
     205
     206    if (PARALLEL_SERIAL) {
     207      int status = system (command);
     208      if (status) {
     209        fprintf (stderr, "ERROR running relastro_client\n");
     210        exit (2);
     211      }
     212    } else {
     213      // launch the job on the remote machine (no handshake)
     214      int errorInfo = 0;
     215      int pid = rconnect ("ssh", group->hosts[i][0].hostname, command, group->hosts[i][0].stdio, &errorInfo, FALSE);
     216      if (!pid) {
     217        if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", group->hosts[i][0].hostname, errorInfo);
     218        exit (1);
     219      }
     220      group->hosts[i][0].pid = pid; // save for future reference
     221    }
     222  }
     223
     224  if (PARALLEL_MANUAL) {
     225    fprintf (stderr, "run the relastro_client commands above.  when these are done, hit return\n");
     226    getchar();
     227  }
     228  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
     229    HostTableGroupWaitJobsGetIO (group, __FILE__, __LINE__, VERBOSE);
     230  }
     231
     232  return TRUE;
     233}     
     234
     235// CATDIR is supplied globally
     236# define DEBUG 1
     237int UpdateObjectOffsets_parallel_table (HostTable *table, SkyList *sky) {
     238
     239  // launch the relastro_client jobs to the parallel hosts
    92240
    93241  int i, j;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/UpdateObjects.c

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

    r37038 r37822  
    265265    remove_argument (N, &argc, argv);
    266266    MaxDensityUse = TRUE;
     267  }
     268
     269  APPLY_OFFSETS = FALSE;
     270  if ((N = get_argument (argc, argv, "-apply-offsets"))) {
     271    remove_argument (N, &argc, argv);
     272    APPLY_OFFSETS = TRUE;
    267273  }
    268274
     
    372378  }
    373379
     380  CHIPMAP = 0;
     381  if ((N = get_argument (argc, argv, "-chipmap"))) {
     382    remove_argument (N, &argc, argv);
     383    CHIPMAP = atoi(argv[N]);
     384    remove_argument (N, &argc, argv);
     385
     386  }
     387
    374388  SAVEPLOT = FALSE;
    375389  PLOTSTUFF = FALSE;
     
    399413    RESET = TRUE;
    400414  }
    401 
    402415  RESET_BAD_IMAGES = FALSE;
    403416  if ((N = get_argument (argc, argv, "-reset-bad-images"))) {
    404417    remove_argument (N, &argc, argv);
    405418    RESET_BAD_IMAGES = TRUE;
     419  }
     420  RESET_IMAGES = FALSE;
     421  if ((N = get_argument (argc, argv, "-reset-images"))) {
     422    remove_argument (N, &argc, argv);
     423    RESET_IMAGES = TRUE;
    406424  }
    407425
     
    868886  fprintf (stderr, "  -high-speed (code[,code,code]) (code[,code,code]) (radius) (output catdir)\n");
    869887  fprintf (stderr, "  -hpm (radius) (output catdir)\n");
     888  fprintf (stderr, "  -chipmap (MaxOrder)\n");
    870889  fprintf (stderr, "  -merge-source (objID) (catID) into (objID) (catID)\n\n");
    871890
     
    880899  fprintf (stderr, "  -statmode (mode)\n");
    881900  fprintf (stderr, "  -reset\n");
     901  fprintf (stderr, "  -reset-images\n");
    882902  fprintf (stderr, "  -nloop (N) : number of image-fit iterations\n");
    883903  fprintf (stderr, "  -update : apply new fit to database\n");
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/assign_images.c

    r36630 r37822  
    2323  BuildChipMatch (image, Nimage);
    2424  MARKTIME("build chip match for %d images: %f sec\n", (int) Nimage, dtime);
     25
     26  char mapfile[DVO_MAX_PATH];
     27  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", CATDIR);
     28  AstromOffsetTable *table = AstromOffsetMapLoad (mapfile, VERBOSE);
     29
     30  // assign images.coords.offsetMap -> table->map[i]
     31  if (table) {
     32    AstromOffsetTableMatchChips (image, Nimage, table);
     33  } else {
     34    table = AstromOffsetTableInit ();
     35  }
     36  put_astrom_table (table);
    2537
    2638  initMosaics (image, Nimage);
     
    89101    if (!strcmp(&image[j].coords.ctype[4], "-DIS")) continue;
    90102
    91     // match the image to its corresponding ASTROMETRIC mosaic (not the same as the Mosaic above)
    92     if (!FindMosaicForImage (image, Nimage, j)) {
    93       if (VERBOSE2) fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    94       continue;
    95     }
    96    
    97103    // Exclude images with crazy astrometry
    98104    // XXX NOTE : this is gpc1-specific
     
    150156
    151157    // this is a bit memory expensive : I am making a complete copy of the image table here
    152     off_t Nsubset = regionHosts->hosts[i].Nimage;
    153     regionHosts->hosts[i].image[Nsubset] = image[j];
    154     regionHosts->hosts[i].imseq[Nsubset] = j;
    155 
    156     regionHosts->hosts[i].Nimage ++;
    157     if (regionHosts->hosts[i].Nimage == regionHosts->hosts[i].NIMAGE) {
    158       regionHosts->hosts[i].NIMAGE += D_NIMAGE;
    159       REALLOCATE (regionHosts->hosts[i].image, Image, regionHosts->hosts[i].NIMAGE);
    160       REALLOCATE (regionHosts->hosts[i].imseq, off_t, regionHosts->hosts[i].NIMAGE);
     158    off_t Nsubset = host->Nimage;
     159    host->image[Nsubset] = image[j];
     160    host->imseq[Nsubset] = j;
     161
     162    host->Nimage ++;
     163    if (host->Nimage == host->NIMAGE) {
     164      host->NIMAGE += D_NIMAGE;
     165      REALLOCATE (host->image, Image, host->NIMAGE);
     166      REALLOCATE (host->imseq, off_t, host->NIMAGE);
     167    }
     168
     169    // save the astrometry maps, where they exist
     170    if (image[j].coords.offsetMap) {
     171      if (!host->astromTable) {
     172        host->astromTable = AstromOffsetTableInit();
     173      }
     174      AstromOffsetTableAddMapFromImage(host->astromTable, &image[j]);
    161175    }
    162176  }
     
    199213}
    200214
    201 int calculate_host_image_bounds (RegionHostTable *regionHosts) {
    202 
    203   int i, n;
    204   off_t j;
    205 
    206   for (i = 0; i < regionHosts->Nhosts; i++) {
    207 
    208     RegionHostInfo *host = &regionHosts->hosts[i];
    209 
    210     // XXX clear the chip match?
    211 
    212     BuildChipMatch (host->image, host->Nimage);
    213 
    214     double Rmin = 360.0;
    215     double Rmax =   0.0;
    216     double Dmin = +90.0;
    217     double Dmax = -90.0;
    218 
    219     for (j = 0; j < host->Nimage; j++) {
    220 
    221       Image *image = &host->image[j];
    222 
    223       if (!FindMosaicForImage (host->image, host->Nimage, j)) {
    224         fprintf (stderr, "missing astrometry? programming error?\n");
    225         abort ();
    226       }
    227      
    228       // define image corners
    229       for (n = 0; n < 4; n++) {
    230         double Xc, Yc, Rc, Dc;
    231         Xc = Xf[n]*image->NX;
    232         Yc = Yf[n]*image->NY;
    233         XY_to_RD (&Rc, &Dc, Xc, Yc, &image->coords);
    234         Rc = ohana_normalize_angle_to_midpoint (Rc, 180.0);
    235      
    236         Rmin = MIN (Rmin, Rc);
    237         Dmin = MIN (Dmin, Rc);
    238        
    239         Rmax = MAX (Rmax, Rc);
    240         Dmax = MAX (Dmax, Rc);
    241       }
    242 
    243     }
    244 
    245     host->RminCat = Rmin;
    246     host->DminCat = Dmin;
    247     host->RmaxCat = Rmax;
    248     host->DmaxCat = Dmax;
    249 
    250     // regionHosts needs to have the full outer boundary
    251     // (so reload_catalogs covers the correct region)
    252     regionHosts->Rmin = MIN(Rmin, regionHosts->Rmin);
    253     regionHosts->Rmax = MAX(Rmax, regionHosts->Rmax);
    254     regionHosts->Dmin = MIN(Dmin, regionHosts->Dmin);
    255     regionHosts->Dmax = MAX(Dmax, regionHosts->Dmax);
    256   }
    257   return TRUE;
    258 }
    259 
    260 
    261215// XXX add a search tree to speed this up?
    262216int find_host_for_coords (RegionHostTable *regionHosts, double Rc, double Dc) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/bcatalog.c

    r36833 r37822  
    2727
    2828  /* 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;
     29  InitCoords (&coords, "DEC--SIN");
    3330  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");
    3831
    3932  // XXX in the future, use catalog[0].Nsecfilt only?  allow catalogs to have variable Nsecfilt?
     
    7265    if (catalog[0].average[i].Nmeasure <= SRC_MEAS_TOOFEW) {
    7366      continue;
    74       // XXX can't (easily) count this for a given chip
    7567    }
    7668   
     
    8476    if (RESET) {
    8577      subcatalog[0].average[Naverage].flags &= ~averageBits;
     78    }
     79
     80    // if we want to do static correction to ICRF, keep the ICRF QSOs (regardless of other data quality)
     81    if (USE_ICRF_CORRECT && (subcatalog[0].average[Naverage].flags & ID_ICRF_QSO)) {
     82      Nm = 0;
     83      for (j = 0; j < catalog[0].average[i].Nmeasure; j++) {
     84         
     85        offset = catalog[0].average[i].measureOffset + j;
     86         
     87        CopyMeasureToTiny (&subcatalog[0].measureT[Nmeasure], &catalog[0].measure[offset]);
     88        subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_SKIP_ASTROM;
     89        subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_NOCAL;
     90        subcatalog[0].measureT[Nmeasure].averef   = Naverage;
     91        if (RESET) {
     92          subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_POOR_ASTROM;
     93          subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
     94        }
     95         
     96        Nmeasure ++;
     97        Nm ++;
     98        if (Nmeasure == NMEASURE) {
     99          NMEASURE += 1000;
     100          REALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE);
     101        }
     102      }
     103      subcatalog[0].average[Naverage].Nmeasure = Nm;
     104      Naverage ++;
     105      if (Naverage == NAVERAGE) {
     106        NAVERAGE += 50;
     107        REALLOCATE (subcatalog[0].average, Average, NAVERAGE);
     108        REALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*Nsecfilt);
     109      }
     110      continue;
     111    }
     112
     113    // if we want to correct to the galay model, we need to use objects with distances determined by Green & Schlafly
     114    if (USE_GALAXY_MODEL && !catalog[0].average[i].Nstarpar) {
     115      // we may want to add some starpar quality filters...
     116      continue;
    86117    }
    87118
     
    116147      // exclude bogus
    117148      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;
     149        double Ri = getMeanR_Big (&catalog[0].measure[offset], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt]);
     150        double Di = getMeanD_Big (&catalog[0].measure[offset], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt]);
     151        coords.crval1 = catalog[0].average[i].R;
     152        coords.crval2 = catalog[0].average[i].D;
     153        double Xi, Yi;
     154        RD_to_XY (&Xi, &Yi, Ri, Di, &coords);
     155        double radius = hypot(Xi, Yi);
     156        if (radius > ExcludeBogusRadius) {
     157          NskipBogus ++;
     158          if (VERBOSE2) {
     159            FILE *foutput = fbogus ? fbogus : stderr;
     160            char *date = ohana_sec_to_date(catalog[0].measure[offset].t);
     161            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);
     162            free (date);
    134163          }
     164          continue;
     165        }
    135166      }
    136167
     
    157188      subcatalog[0].measureT[Nmeasure].averef   = Naverage;
    158189      if (RESET) {
    159         subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_POOR_ASTROM;
    160         subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
     190        subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_POOR_ASTROM;
     191        subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
    161192      }
    162193
     
    164195      Nm ++;
    165196      if (Nmeasure == NMEASURE) {
    166         NMEASURE += 1000;
    167         REALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE);
    168       }
     197        NMEASURE += 1000;
     198        REALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE);
     199      }
     200    }
     201    // we have filtered this object.  do not keep it if we now have too few meas
     202    if (Nm <= SRC_MEAS_TOOFEW) {
     203      Nmeasure -= Nm;
     204      continue;
    169205    }
    170206    subcatalog[0].average[Naverage].Nmeasure = Nm;
     
    186222  assert (Nsecfilt == catalog[0].Nsecfilt);
    187223
    188   // limit the total number of stars in the catalog
     224// limit the total number of stars in the catalog
    189225  if (MaxDensityUse) {
    190226    LimitDensityCatalog_ByNmeasureGrid (subcatalog, catalog);
     
    217253
    218254# define SWAPFUNC(A,B){ int tmpI; off_t tmpT;   \
    219   tmpI = X[A]; X[A] = X[B]; X[B] = tmpI; \
    220   tmpT = Y[A]; Y[A] = Y[B]; Y[B] = tmpT; \
    221 }
     255    tmpI = X[A]; X[A] = X[B]; X[B] = tmpI;      \
     256    tmpT = Y[A]; Y[A] = Y[B]; Y[B] = tmpT;      \
     257  }
    222258# define COMPARE(A,B)(X[A] > X[B])
    223259
     
    231267/* generate a grid in a locally-projected coordinate system, try to select average entries
    232268   from each grid cell in decending Nmeasure order.
    233  */
     269*/
    234270int LimitDensityCatalog_ByNmeasureGrid (Catalog *subcatalog, Catalog *oldcatalog) {
    235271
     
    269305  /* project coordinates to a plane centered on the object with units of arcsec */
    270306  Coords coords;
     307  InitCoords (&coords, "DEC--SIN");
    271308  coords.crval1 = Rc;
    272309  coords.crval2 = Dc;
    273   coords.crpix1 = 0;
    274   coords.crpix2 = 0;
    275310  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");
    280311
    281312  // convert all average R,D values to X,Y:
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/fitpoly.c

    r33652 r37822  
    7878}
    7979 
     80int array_print (double **matrix, int Nx, int Ny) {
     81
     82  int i, j;
     83  for (i = 0; i < Nx; i++) {
     84    for (j = 0; j < Ny; j++) {
     85      fprintf (stderr, "%10.3e ", matrix[i][j]);
     86    }
     87    fprintf (stderr, "\n");
     88  }
     89  return TRUE;
     90}
     91
     92int fit_print (CoordFit *fit) {
     93
     94  fprintf (stderr, "Npts: %d, Norder: %d, Nterms: %d, Nsums: %d, Nelems: %d\n",
     95           fit[0].Npts, fit[0].Norder, fit[0].Nterms, fit[0].Nsums, fit[0].Nelems);
     96
     97  fprintf (stderr, "sums: \n");
     98  array_print (fit[0].sum, fit[0].Nsums, fit[0].Nsums);
     99
     100  fprintf (stderr, "xsums: \n");
     101  array_print (fit[0].xsum, fit[0].Nterms, fit[0].Nterms);
     102
     103  fprintf (stderr, "ysums: \n");
     104  array_print (fit[0].ysum, fit[0].Nterms, fit[0].Nterms);
     105
     106  fprintf (stderr, "xfits: \n");
     107  array_print (fit[0].xfit, fit[0].Nterms, fit[0].Nterms);
     108
     109  fprintf (stderr, "yfits: \n");
     110  array_print (fit[0].yfit, fit[0].Nterms, fit[0].Nterms);
     111 
     112  return TRUE;
     113}
     114
    80115// XXX use implicit masks as below or explicit masks (with function to set?)
    81116// XXX eg, add a global mask to this file and
     
    134169      for (j = 0; j < fit[0].Nelems; j++) {
    135170        matrix[i][j] = 0.0;
     171        matrix[j][i] = 0.0;
    136172      }
    137173      vector[i][0] = 0.0;
     
    148184  }     
    149185 
    150   if (!dgaussjordan (matrix, vector, fit[0].Nelems, 2)) {
     186  if (!dgaussjordan_pivot (matrix, vector, fit[0].Nelems, 2, 1e-16)) {
    151187    array_free (matrix, fit[0].Nelems);
    152188    array_free (vector, fit[0].Nelems);
     
    277313/* this should only apply to the polynomial, not the projection terms */
    278314/* compare with psastro supporting code */
     315// this code will work for linear (Npolyterm == 0 or 1) and linear + map fits
    279316int fit_apply_coords (CoordFit *fit, Coords *coords, int keepRef) {
    280317
     
    352389  /* keep the order and type from initial values */
    353390 
     391  if (isnan(coords[0].crval1)) {
     392    return FALSE;
     393  }
     394  if (isnan(coords[0].crval2)) {
     395    return FALSE;
     396  }
     397  if (isnan(coords[0].crpix1)) {
     398    return FALSE;
     399  }
     400  if (isnan(coords[0].crpix2)) {
     401    return FALSE;
     402  }
     403
    354404  return (TRUE);
    355405}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/high_speed_objects.c

    r37038 r37822  
    149149
    150150  // define a local projection
     151  InitCoords (&tcoords, "DEC--ARC");
    151152  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    152153  if (region[0].Dmax < 90) {
     
    155156    tcoords.crval2 = 90.0;
    156157  }
    157   tcoords.crpix1 = 0;
    158   tcoords.crpix2 = 0;
    159158  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    160   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    161   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    162   tcoords.Npolyterms = 1;
    163   strcpy (tcoords.ctype, "DEC--ARC");
    164159
    165160  /* build spatial index (RA sort) referencing input array sequence */
     
    271266
    272267  populate_tiny_values (&catalogOut, DVO_TV_MEASURE);
    273   UpdateObjects (&catalogOut, 1);
     268  UpdateObjects (&catalogOut, 1, 0);
    274269  free_tiny_values(&catalogOut);
    275270
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/high_speed_utils.c

    r33652 r37822  
    141141    off_t n;
    142142    for (n = 0; n < NfieldsA; n++) {
    143         valuesA[n] = dbExtractAverages (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], &catalog[0].measure[m], &fieldsA[n]);
     143      valuesA[n] = dbExtractAverages (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], &catalog[0].measure[m], NULL, NULL, &fieldsA[n]);
    144144    }
    145145    return dbBooleanCond(stackA, NstackA, valuesA);
     
    155155    off_t n;
    156156    for (n = 0; n < NfieldsB; n++) {
    157         valuesB[n] = dbExtractAverages (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], &catalog[0].measure[m], &fieldsB[n]);
     157        valuesB[n] = dbExtractAverages (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], &catalog[0].measure[m], NULL, NULL, &fieldsB[n]);
    158158    }
    159159    return dbBooleanCond(stackB, NstackB, valuesB);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/hpm_objects.c

    r37038 r37822  
    126126
    127127  // define a local projection
     128  InitCoords (&tcoords, "DEC--ARC");
    128129  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    129130  if (region[0].Dmax < 90) {
     
    132133    tcoords.crval2 = 90.0;
    133134  }
    134   tcoords.crpix1 = 0;
    135   tcoords.crpix2 = 0;
    136135  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    137   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    138   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    139   tcoords.Npolyterms = 1;
    140136  strcpy (tcoords.ctype, "DEC--ARC");
    141137
     
    256252    // distinguishing a bad fit from a fit with 1 or 2 bad points
    257253    FIT_MODE = FIT_PM_ONLY;
    258     UpdateObjects (&testcat, 1);
     254    UpdateObjects (&testcat, 1, 0);
    259255
    260256    free_tiny_values(&testcat);
     
    286282
    287283  populate_tiny_values (&catalogOut, DVO_TV_MEASURE);
    288   UpdateObjects (&catalogOut, 1);
     284  UpdateObjects (&catalogOut, 1, 0);
    289285  free_tiny_values(&catalogOut);
    290286
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/initialize.c

    r37038 r37822  
    99
    1010  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);
     11  if (DCR_RED_COLOR_POS)   fprintf (stderr, "DCR_RED_COLOR_POS:   %s - %s\n", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
    1212
    1313  if (PHOTCODE_KEEP_LIST)  fprintf (stderr, "PHOTCODE_KEEP_LIST:  %s\n", PHOTCODE_KEEP_LIST);
     
    6363  initstats (STATMODE);
    6464
     65  if (USE_ICRF_CORRECT) {
     66    if (!USE_ICRF_LOCAL && !USE_ICRF_SHFIT) {
     67      fprintf (stderr, "no ICRF correction method chosen\n");
     68      exit (2);
     69    }
     70  }
     71  if (USE_ICRF_CORRECT) ICRFinit();
     72
    6573  /* XXX drop irrelevant entries */
    6674  if (SHOW_PARAMS) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/launch_region_hosts.c

    r37038 r37822  
    66  int i;
    77
    8   // clear the I/O files
    9   for (i = 0; i < regionHosts->Nhosts; i++) {
    10     char *syncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanmags.sync");
    11     if (truncate (syncfile, 0)) fprintf (stderr, "trouble clearing syncfile %s\n", syncfile);
    12     free (syncfile);
     8  // do not remote the sync and fits files if we do a manual run -- user must clear if needed
     9  if (!PARALLEL_REGIONS_MANUAL) {
     10    // clear the I/O files
     11    for (i = 0; i < regionHosts->Nhosts; i++) {
     12      char *meansync = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanpos.sync");
     13      if (truncate (meansync, 0)) fprintf (stderr, "trouble clearing meansync %s\n", meansync);
     14      free (meansync);
    1315
    14     char *fitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanmags.fits");
    15     if (truncate (fitsfile, 0)) fprintf (stderr, "trouble clearing fitsfile %s\n", fitsfile);
    16     free (fitsfile);
     16      char *meanfits = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanpos.fits");
     17      if (truncate (meanfits, 0)) fprintf (stderr, "trouble clearing meanfits %s\n", meanfits);
     18      free (meanfits);
    1719
    18     char *imsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagemags.sync");
    19     if (truncate (imsyncfile, 0)) fprintf (stderr, "trouble clearing imsyncfile %s\n", imsyncfile);
    20     free (imsyncfile);
     20      char *meassync = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "measpos.sync");
     21      if (truncate (meassync, 0)) fprintf (stderr, "trouble clearing meassync %s\n", meassync);
     22      free (meassync);
    2123
    22     char *imfitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagemags.fits");
    23     if (truncate (imfitsfile, 0)) fprintf (stderr, "trouble clearing imfitsfile %s\n", imfitsfile);
    24     free (imfitsfile);
     24      char *measfits = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "measpos.fits");
     25      if (truncate (measfits, 0)) fprintf (stderr, "trouble clearing measfits %s\n", measfits);
     26      free (measfits);
    2527
    26     char *loopsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "loop.sync");
    27     if (truncate (loopsyncfile, 0)) fprintf (stderr, "trouble clearing loopsyncfile %s\n", loopsyncfile);
    28     free (loopsyncfile);
     28      char *icrfsync = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "icrfobj.sync");
     29      if (truncate (icrfsync, 0)) fprintf (stderr, "trouble clearing icrfsync %s\n", icrfsync);
     30      free (icrfsync);
     31
     32      char *icrffits = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "icrfobj.fits");
     33      if (truncate (icrffits, 0)) fprintf (stderr, "trouble clearing icrffits %s\n", icrffits);
     34      free (icrffits);
     35
     36      char *imsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagepos.sync");
     37      if (truncate (imsyncfile, 0)) fprintf (stderr, "trouble clearing imsyncfile %s\n", imsyncfile);
     38      free (imsyncfile);
     39
     40      char *imfitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagepos.fits");
     41      if (truncate (imfitsfile, 0)) fprintf (stderr, "trouble clearing imfitsfile %s\n", imfitsfile);
     42      free (imfitsfile);
     43
     44      char *loopsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "loop.sync");
     45      if (truncate (loopsyncfile, 0)) fprintf (stderr, "trouble clearing loopsyncfile %s\n", loopsyncfile);
     46      free (loopsyncfile);
     47    }
     48
     49    char *framesync = make_filename (CATDIR, "master", 0, "frame.corr.sync");
     50    if (truncate (framesync, 0)) fprintf (stderr, "trouble clearing framesync %s\n", framesync);
     51    free (framesync);
     52 
     53    char *framefits = make_filename (CATDIR, "master", 0, "frame.corr.fits");
     54    if (truncate (framefits, 0)) fprintf (stderr, "trouble clearing framefits %s\n", framefits);
     55    free (framefits);
    2956  }
    3057
     
    3764    char filename[1024];
    3865    snprintf (filename, 1024, "%s/Image.%d.fits", CATDIR, host->hostID);
     66    if (unlink (filename)) fprintf (stderr, "trouble clearing image %s\n", filename);
    3967
    4068    // write the image subset for this host
    4169    ImageTableSave (filename, host->image, host->Nimage);
     70
     71    if (host->astromTable) {
     72      char mapname[1024];
     73      snprintf (mapname, 1024, "%s/AstroMap.%d.fits", CATDIR, host->hostID);
     74
     75      // write the image subset for this host
     76      AstromOffsetMapSave (host->astromTable, mapname);
     77    }
    4278
    4379    char command[1024];
     
    92128    if (PhotFlagPoor)       strextend (command, "+photflagpoor %d", PhotFlagPoor);
    93129
     130    if (CHIPMAP)            strextend (command, "-chipmap %d", CHIPMAP);
     131    if (RESET_IMAGES)       strextend (command, "-reset-images");
     132
    94133    if (MinBadQF > 0.0)        strextend (command, "-min-bad-psfqf %f", MinBadQF);
    95134    if (MaxMeanOffset != 10.0) strextend (command, "-max-mean-offset  %f", MaxMeanOffset);
     
    99138    strextend (command, "-D RELASTRO_DPOS_MAX %f", DPOS_MAX);
    100139    strextend (command, "-D ADDSTAR_RADIUS %f", ADDSTAR_RADIUS);
     140
     141    strextend (command, "-D USE_GALAXY_MODEL %d", USE_GALAXY_MODEL);
     142
     143    strextend (command, "-D USE_ICRF_CORRECT %d", USE_ICRF_CORRECT);
     144    strextend (command, "-D USE_ICRF_LOCAL %d",   USE_ICRF_LOCAL);
     145    strextend (command, "-D USE_ICRF_SHFIT %d",   USE_ICRF_SHFIT);
     146    strextend (command, "-D USE_ICRF_POLE %d",    USE_ICRF_POLE);
    101147
    102148    if (USE_FIXED_PIXCOORDS) strextend (command, "-D USE_FIXED_PIXCOORDS 1");
     
    133179  }
    134180
     181  if (USE_ICRF_CORRECT) return TRUE;
     182
     183  int status = HarvestRegionHosts (regionHosts);
     184  return status;
     185}
     186
     187int HarvestRegionHosts (RegionHostTable *regionHosts) {
     188
     189  int status = TRUE;
     190
    135191  if (PARALLEL_REGIONS_MANUAL) {
    136192    fprintf (stderr, "run the relastro_client commands above.  when these are done, hit return\n");
    137193    getchar();
    138194  } else {
    139     RegionHostTableWaitJobsGetIO (regionHosts, __FILE__, __LINE__, VERBOSE);
     195    status = RegionHostTableWaitJobsGetIO (regionHosts, __FILE__, __LINE__, VERBOSE);
    140196  }
    141  
    142   int status = TRUE;
    143   for (i = 0; i < regionHosts->Nhosts; i++) {
    144     status = status && (regionHosts->hosts[i].status == 0);
    145   }
    146 
    147197  return status;
    148198}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/liststats.c

    r34576 r37822  
    252252    X2 += M / dM;
    253253    dS += M;
    254     if (XVERB) fprintf (stderr, "chisq contrib : %f : %f : %f : %f : %f\n", Mo, 3600.0*(value[i] - Mo), 3600.0*dvalue[i], (value[i] - Mo) / dvalue[i], X2);
     254    if (XVERB) fprintf (stderr, "chisq contrib : %f : %f : %f : %f : %f\n", Mo, (value[i] - Mo), dvalue[i], (value[i] - Mo) / dvalue[i], X2);
    255255  }
    256256  X2 = X2 / (Nm - 1);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/load_catalogs.c

    r37038 r37822  
    66Catalog *load_catalogs (SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath, char *syncfile) {
    77
    8   int i, j, Nstar;
     8  int i, j;
    99  // int k, m;
    1010  Catalog *catalog, *pcatalog, tcatalog;
     
    8888
    8989  bcatalog_show_skips();
    90 
    91   Nstar = 0;
     90  fprintf (stderr, "included %d ICRF QSOs\n", ICRFmax());
     91
     92  int Nstar = 0;
     93  int Nmeas = 0;
    9294  for (i = 0; i < Ncat; i++) {
    9395    Nstar += catalog[i].Naverage;
     96    Nmeas += catalog[i].Nmeasure;
    9497    if ((sizeof(IDX_T) == 8) && (catalog[i].Nmeasure > 0xffffffff)) {
    9598      fprintf (stderr, "ERROR: using small-sized IDX_T on data with more than 2G detections per table will cause errors\n");
     
    101104    fprintf (stderr, "warning: insufficient stars %d\n", Nstar);
    102105  }
     106  fprintf (stderr, "using %d stars, %d measurements to calibrate\n", Nstar, Nmeas);
    103107
    104108  // if we are running with parallel_images but not a parallel database, we need to
     
    170174    if (FlagOutlier)   strextend (command, "-clip %d", CLIP_THRESH);
    171175    if (ExcludeBogus)  strextend (command, "-exclude-bogus %f", ExcludeBogusRadius);
     176
     177    if (USE_ICRF_CORRECT) strextend (command, "-D USE_ICRF_CORRECT %d", USE_ICRF_CORRECT);
     178    if (USE_GALAXY_MODEL) strextend (command, "-D USE_GALAXY_MODEL %d", USE_GALAXY_MODEL);
    172179   
    173180    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/load_images.c

    r36630 r37822  
    11# include "relastro.h"
     2
     3static AstromOffsetTable *table = NULL;
     4
     5/* AstromOffsetMap is the map of Astrometry Offsets for non-polynomial astrometric
     6 * corrections for each chip. 
     7 */
    28
    39int load_images (FITS_DB *db, SkyList *skylist, int UseFullOverlap) {
     
    1723  MARKTIME("  convert image table: %f sec\n", dtime);
    1824
     25  // assign image->parent and image->coords.mosaic
     26  BuildChipMatch (image, Nimage);
     27  MARKTIME("build chip match: %f sec\n", dtime);
     28
     29  char mapfile[DVO_MAX_PATH];
     30  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", CATDIR);
     31  table = AstromOffsetMapLoad (mapfile, VERBOSE);
     32
     33  // assign images.coords.offsetMap -> table->map[i]
     34  if (table) {
     35    AstromOffsetTableMatchChips (image, Nimage, table);
     36  } else {
     37    table = AstromOffsetTableInit ();
     38  }
     39
    1940  // select the images which overlap the selected sky regions
    2041  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset, UseFullOverlap);
    2142  MARKTIME("  select images: %f sec\n", dtime);
     43
     44  if (Nsubset == Nimage) {
     45    free (subset);
     46    subset = image;
     47  }
    2248
    2349  initImages (subset, LineNumber, Nsubset);
     
    5177  return TRUE;
    5278}
     79
     80int save_astrom_table () {
     81
     82  char mapfile[DVO_MAX_PATH];
     83  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", CATDIR);
     84  AstromOffsetMapSave (table, mapfile);
     85
     86  return TRUE;
     87}
     88
     89AstromOffsetTable *get_astrom_table () {
     90  return table;
     91}
     92
     93void put_astrom_table (AstromOffsetTable *myTable) {
     94  table = myTable;
     95}
     96
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/markObjects.c

    r37038 r37822  
    1414      int m = catalog[i].average[j].measureOffset;
    1515      for (n = 0; n < catalog[i].average[j].Nmeasure; n++) {
    16         if (!catalog[i].measureT[m+n].myDet) continue;
    17         nOwn ++;
     16        // this is a detection I own (it is on one of my images)
     17        if (catalog[i].measureT[m+n].myDet) {
     18          nOwn ++;
     19          continue;
     20        }
     21        // 2MASS detections are counted as 'owned' (I completely control this object is nOwn_t == Nmeasure; no sharing needed)
     22        if ((catalog[i].measureT[m+n].photcode == 2011) ||
     23            (catalog[i].measureT[m+n].photcode == 2012) ||
     24            (catalog[i].measureT[m+n].photcode == 2013)) {
     25          nOwn ++;
     26          continue;
     27        }
    1828      }
    1929      catalog[i].nOwn_t[j] = nOwn;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/relastroVisual.c

    r37038 r37822  
    2424/** Spawn a kapa window */
    2525static int initWindow(int *kapid) {
     26  if (NTHREADS) {
     27    fprintf (stderr, "-visual and -threads are incompatible, quitting\n");
     28    exit (2);
     29  }
    2630  if (*kapid == -1) {
    2731    *kapid = KapaOpenNamedSocket("kapa", "relastro_plots");
     
    348352
    349353  int i;
    350   for(i = 0; i < numObj; i++) {
     354  for (i = 0; i < numObj; i++) {
    351355    if (raw[i].mask) continue; // XXX
    352356
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/relastro_client.c

    r36833 r37822  
    7979      load_images (&db, skylist, FALSE);
    8080     
     81      // I can free the database after I have loaded the images...
     82
    8183      // // load the image subset table from the specified location
    8284      // off_t Nimage;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/relastro_images.c

    r36833 r37822  
    2323  MARKTIME("load images: %f sec\n", dtime);
    2424
    25   initCoords();
    26 
    2725  /* load catalog data from region files : subselect high-quality measurements */
    28   // XXX pass in the image table
    29   // XXX who carries the image grid?
    3026
    3127  // photcodesKeep is used here to allow measurements from the images being calibrated
     
    3329  catalog = load_catalogs (skylist, &Ncatalog, TRUE, 0, NULL, NULL);
    3430  MARKTIME("load catalog data: %f sec\n", dtime);
     31
     32  // find ICRF QSOs for reference downstream (only if USE_ICRF_CORRECT)
     33  select_catalog_ICRF (catalog, Ncatalog);
    3534
    3635  if (photcodesReset) {
     
    6564    case TARGET_SIMPLE:
    6665      for (i = 0; i < NLOOP; i++) {
    67         UpdateObjects (catalog, Ncatalog);
     66        UpdateObjects (catalog, Ncatalog, i);
    6867        UpdateSimple (catalog, Ncatalog);
    6968      }
     
    7170
    7271    case TARGET_CHIPS:
     72      if (RESET_IMAGES) UpdateMeasures (catalog, Ncatalog);
    7373      for (i = 0; i < NLOOP; i++) {
    74         UpdateObjects (catalog, Ncatalog);
    75         UpdateChips (catalog, Ncatalog);
     74        UpdateObjects (catalog, Ncatalog, (i > 0)); // calculate <R>,<D>; if (i > 0), apply Galaxy Motion Model (if desired)
     75        if ((i > 1) || !USE_GALAXY_MODEL) {
     76          // if GALAXY_MODEL is selected, we want to delay the frame correction until we have
     77          // applied the galaxy model a couple of times.
     78          FrameCorrectionSerial (catalog, Ncatalog);
     79        }
     80        UpdateChips (catalog, Ncatalog);   // measure.X,Y -> R,D, fit image.coords
    7681        MARKTIME("update chips: %f sec\n", dtime);
    7782      }
     
    8287    case TARGET_MOSAICS:
    8388      for (i = 0; i < NLOOP; i++) {
    84         UpdateObjects (catalog, Ncatalog);
     89        UpdateObjects (catalog, Ncatalog, i);
    8590        UpdateMosaic (catalog, Ncatalog);
    8691      }
     
    102107  if (PARALLEL) {
    103108    // save the updated image parameters
     109    // need to also save the image map table...
     110    save_astrom_table ();
    104111    dvo_image_update (&db, VERBOSE);
    105112    dvo_image_unlock (&db);
     
    109116  UpdateObjectOffsets (skylist, 0, NULL);
    110117
    111   // iterate over catalogs to make detection coordinates consistant
    112   // FixProblemImages (skylist);
    113 
    114118  if (!PARALLEL) {
    115119    // save the updated image parameters
     120    save_astrom_table ();
    116121    dvo_image_update (&db, VERBOSE);
    117122    dvo_image_unlock (&db);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/relastro_objects.c

    r36833 r37822  
    7777    populate_tiny_values(&catalog, DVO_TV_MEASURE);
    7878
    79     UpdateObjects (&catalog, 1);
     79    UpdateObjects (&catalog, 1, 0);
    8080
    8181    free_tiny_values(&catalog);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/relastro_parallel_images.c

    r36833 r37822  
    1717  INITTIME;
    1818
     19  client_logger_init (CATDIR);
     20
    1921  // load the RegionTable (UserRegion should not be used at this level)
    2022  RegionHostTable *regionHosts = RegionHostTableLoad (CATDIR, REGION_FILE);
    2123  int myHost = regionHosts->index[REGION_HOST_ID];
    2224  RegionHostFindNeighbors (regionHosts, myHost);
     25  client_logger_message ("started parallel images on %s\n", regionHosts->hosts[myHost].hostname);
    2326
    2427  // load the subset images belonging to this host
     
    2932    exit (2);
    3033  }
     34
     35  // assign image->parent and image->coords.mosaic
     36  BuildChipMatch (image, Nimage);
     37
     38  char mapfile[DVO_MAX_PATH];
     39  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.%d.fits", CATDIR, REGION_HOST_ID);
     40  AstromOffsetTable *table = AstromOffsetMapLoad (mapfile, VERBOSE);
     41
     42  // assign images.coords.offsetMap -> table->map[i]
     43  if (table) {
     44    AstromOffsetTableMatchChips (image, Nimage, table);
     45  } else {
     46    table = AstromOffsetTableInit ();
     47  }
     48  put_astrom_table (table);
     49  client_logger_message ("loaded images on %s\n", regionHosts->hosts[myHost].hostname);
    3150
    3251  // once we have read this table, we should remove it for repeat runs
     
    4261  SkyList *skylist = SkyListByBounds (sky, -1, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    4362
    44   initCoords();
    45 
    4663  /* load catalog data from region files (hostID is 0 since we are not a client */
    4764  char *syncfile = make_filename (CATDIR, regionHosts->hosts[myHost].hostname, REGION_HOST_ID, "loadcat.sync");
    4865  catalog = load_catalogs (skylist, &Ncatalog, TRUE, 0, NULL, syncfile);
    49   MARKTIME("-- load catalog data: %f sec\n", dtime);
     66  MARKTIME("-- load catalog data, host %d: %f sec\n", REGION_HOST_ID, dtime);
    5067  free (syncfile);
    5168 
     69  client_logger_message ("loaded catalog data %s\n", regionHosts->hosts[myHost].hostname);
     70
     71  // find ICRF QSOs for reference downstream (only if USE_ICRF_CORRECT)
     72  select_catalog_ICRF (catalog, Ncatalog);
     73
    5274  if (photcodesReset) {
    5375    photcodesKeep  = photcodesReset;
     
    6082  /* match measurements with images, mosaics */
    6183  initImageBins  (catalog, Ncatalog, TRUE);
    62   MARKTIME("-- make image bins: %f sec\n", dtime);
     84  MARKTIME("-- make image bins, host %d: %f sec\n", REGION_HOST_ID, dtime);
    6385
    6486  findImages (catalog, Ncatalog, TRUE);
    65   MARKTIME("-- set up image indexes: %f sec\n", dtime);
     87  MARKTIME("-- set up image indexes, host %d: %f sec\n", REGION_HOST_ID, dtime);
    6688
    6789  // set test points based on the starmap
    6890  createStarMap (catalog, Ncatalog);
     91
     92  client_logger_message ("set up image indexes on %s\n", regionHosts->hosts[myHost].hostname);
    6993
    7094  markObjects (catalog, Ncatalog);
     
    7296  SAVEPLOT = FALSE;
    7397
     98  client_logger_message ("starting the loops: %s\n", regionHosts->hosts[myHost].hostname);
     99
    74100  /* major modes */
    75101  switch (FIT_TARGET) {
    76102    case TARGET_SIMPLE:
    77103      for (i = 0; i < NLOOP; i++) {
    78         UpdateObjects (catalog, Ncatalog);
     104        UpdateObjects (catalog, Ncatalog, i);
    79105        share_mean_pos (catalog, Ncatalog, regionHosts, i);
    80106        slurp_mean_pos (catalog, Ncatalog, regionHosts, i);
    81107        UpdateSimple (catalog, Ncatalog);
    82108        share_image_pos (regionHosts, i);
    83         slurp_image_pos (regionHosts, i);
     109        slurp_image_pos (catalog, Ncatalog, regionHosts, i);
    84110      }
    85111      break;
    86112
    87113    case TARGET_CHIPS:
     114      if (RESET_IMAGES) {
     115        UpdateMeasures (catalog, Ncatalog);
     116        MARKTIME("reset measures, host %d: %f sec\n", REGION_HOST_ID, dtime);
     117        client_logger_message ("reset measures: %s\n", regionHosts->hosts[myHost].hostname);
     118      }
    88119      for (i = 0; i < NLOOP; i++) {
    89         UpdateObjects (catalog, Ncatalog);
     120        UpdateObjects (catalog, Ncatalog, (i > 0));
     121        MARKTIME("update objects loop %d, host %d: %f sec\n", i, REGION_HOST_ID, dtime);
     122        client_logger_message ("update objects loop %d: %s\n", i, regionHosts->hosts[myHost].hostname);
     123        if ((i > 1) || !USE_GALAXY_MODEL) {
     124          // if GALAXY_MODEL is selected, we want to delay the frame correction until we have
     125          // applied the galaxy model a couple of times.
     126          FrameCorrectionParallelSlave (catalog, Ncatalog, regionHosts, i);
     127          MARKTIME("frame correction loop %d, host %d: %f sec\n", i, REGION_HOST_ID, dtime);
     128          client_logger_message ("frame correction loop %d: %s\n", i, regionHosts->hosts[myHost].hostname);
     129        }
    90130        share_mean_pos (catalog, Ncatalog, regionHosts, i);
    91131        slurp_mean_pos (catalog, Ncatalog, regionHosts, i);
     132        client_logger_message ("slurp mags loop %d: %s\n", i, regionHosts->hosts[myHost].hostname);
     133
    92134        UpdateChips (catalog, Ncatalog);
     135        MARKTIME("update chips loop %d, host %d: %f sec\n", i, REGION_HOST_ID, dtime);
     136        client_logger_message ("update chips loop %d: %s\n", i, regionHosts->hosts[myHost].hostname);
     137
    93138        share_image_pos (regionHosts, i);
    94         slurp_image_pos (regionHosts, i);
    95         MARKTIME("update chips: %f sec\n", dtime);
     139        slurp_image_pos (catalog, Ncatalog, regionHosts, i);
     140        client_logger_message ("slurp image pos loop %d: %s\n", i, regionHosts->hosts[myHost].hostname);
     141
     142        share_meas_pos (catalog, Ncatalog, regionHosts, i);
     143        slurp_meas_pos (catalog, Ncatalog, regionHosts, i);
     144        MARKTIME("done exchange loop %d, host %d: %f sec\n", i, REGION_HOST_ID, dtime);
     145        client_logger_message ("slurp meas loop %d: %s\n", i, regionHosts->hosts[myHost].hostname);
    96146      }
    97147      // create summary plots of the process
     
    101151    case TARGET_MOSAICS:
    102152      for (i = 0; i < NLOOP; i++) {
    103         UpdateObjects (catalog, Ncatalog);
     153        UpdateObjects (catalog, Ncatalog, i);
    104154        share_mean_pos (catalog, Ncatalog, regionHosts, i);
    105155        slurp_mean_pos (catalog, Ncatalog, regionHosts, i);
    106156        UpdateMosaic (catalog, Ncatalog);
    107157        share_image_pos (regionHosts, i);
    108         slurp_image_pos (regionHosts, i);
     158        slurp_image_pos (catalog, Ncatalog, regionHosts, i);
    109159      }
    110160      break;
     
    128178
    129179  share_image_pos (regionHosts, -1);
     180  client_logger_message ("share image pos loop %d: %s\n", -1, regionHosts->hosts[myHost].hostname);
    130181
    131182  exit (0);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/relastro_parallel_regions.c

    r36630 r37822  
    4444  if (!launch_region_hosts (regionHosts)) Shutdown ("error launching region hosts");
    4545
     46  // If we are doing FrameCorrection, we have to loop here waiting for ICRF objects from the region
     47  // hosts.  we then measure the frame correction and send back the result
     48  if (!FrameCorrectionParallelMaster (regionHosts)) Shutdown ("error running parallel frame correction");
     49
    4650  // retrieve updated image parameters from the remote hosts (also set Image.mcal)
    47   if (!slurp_image_pos (regionHosts, -1)) Shutdown ("error loading image updates");
     51  if (!slurp_image_pos (NULL, 0, regionHosts, -1)) Shutdown ("error loading image updates");
    4852
    4953  if (!UPDATE) {
     
    5963
    6064  if (PARALLEL) {
    61     // save the updated image parameters
     65    // save the updated image parameters.  if we are NOT PARALLEL, we have to wait
     66    // until after UpdateObjectOffsets, or the image parameters are swapped and/or freed
     67    save_astrom_table ();
    6268    dvo_image_save (&db, VERBOSE);
    6369    dvo_image_unlock (&db);
     
    6571
    6672  // iterate over catalogs to make detection coordinates consistant
    67   UpdateObjectOffsets (skylist, 0, NULL);
     73  if (APPLY_OFFSETS) {
     74    UpdateObjectOffsets (skylist, 0, NULL);
     75  }
    6876
    6977  if (!PARALLEL) {
    7078    // save the changes to the image parameters
     79    save_astrom_table ();
    7180    dvo_image_save (&db, VERBOSE);
    7281    dvo_image_unlock (&db);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/select_images.c

    r36630 r37822  
    2323  int InRange, found;
    2424  double Ri[5], Di[5], Xi[5], Yi[5], dx, dy;
    25   Coords tcoords;
    2625  SkyRegionCoords *skycoords;
    2726 
     
    4645
    4746  // the comparison is made in the catalog local projection. below we set crval1,2
    48   tcoords.crpix1 = tcoords.crpix2 = 0.0;
     47  Coords tcoords;
     48  InitCoords (&tcoords, "DEC--TAN");
    4949  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    50   tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    51   tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    52   strcpy (tcoords.ctype, "DEC--TAN");
    5350
    5451  ALLOCATE (skycoords, SkyRegionCoords, skylist[0].Nregions);
     
    104101
    105102  if (VERBOSE) fprintf (stderr, "finding images\n");
    106   BuildChipMatch (timage, Ntimage);
    107   MARKTIME("build chip match: %f sec\n", dtime);
    108103
    109104  nimage = 0;
     
    148143    }
    149144   
    150     // this adds 1.3 sec for 3M images
    151     if (!FindMosaicForImage (timage, Ntimage, i)) {
    152       fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    153       continue;
    154     }
    155 
    156145    /* define image corners - note the DIS images (mosaic phu) are special */
    157146    if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/share_images_pos.c

    r36630 r37822  
    3434  free (iposfile);
    3535
     36  // save the per-chip residual table
     37  AstromOffsetTable *table = get_astrom_table ();
     38  if (table) {
     39    char mapname[1024];
     40    snprintf (mapname, 1024, "%s/AstroMapUpdate.%d.fits", CATDIR, REGION_HOST_ID);
     41   
     42    // write the image subset for this host
     43    AstromOffsetMapSave (table, mapname);
     44  }
     45
    3646  char *syncfile = make_filename (CATDIR, hostname, REGION_HOST_ID, "imagepos.sync");
    3747  update_sync_file (syncfile, nloop);
     
    4151}
    4252
    43 int slurp_image_pos (RegionHostTable *regionHosts, int nloop) {
     53int slurp_image_pos (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop) {
    4454
    45   off_t Nimage, i;
     55  off_t Nimage, i, j;
    4656  Image *images = getimages (&Nimage, NULL);
    4757
     
    7484      continue;
    7585    }
     86    Coords *moscoords = images[seq].coords.mosaic;
    7687    images[seq].coords     = image_pos[i].coords    ;
    77     images[seq].dXpixSys   = image_pos[i].dXpixSys  ;
    78     images[seq].dYpixSys   = image_pos[i].dYpixSys  ;
    79     images[seq].imageID    = image_pos[i].imageID   ;
    80     images[seq].nFitAstrom = image_pos[i].nFitAstrom;
    81     images[seq].flags      = image_pos[i].flags     ;
     88    images[seq].coords.mosaic = moscoords;
     89
     90    images[seq].dXpixSys     = image_pos[i].dXpixSys  ;
     91    images[seq].dYpixSys     = image_pos[i].dYpixSys  ;
     92    images[seq].refColorBlue = image_pos[i].refColorBlue;
     93    images[seq].refColorRed  = image_pos[i].refColorRed;
     94    images[seq].imageID      = image_pos[i].imageID   ;
     95    images[seq].nFitAstrom   = image_pos[i].nFitAstrom;
     96    images[seq].flags        = image_pos[i].flags     ;
     97  }
     98
     99  // load the astrometry offset maps, if they exist, and apply
     100  for (i = 0; i < regionHosts->Nhosts; i++) {
     101    if (regionHosts->hosts[i].hostID == REGION_HOST_ID) continue;
     102    if (REGION_HOST_ID && !regionHosts->hosts[i].isNeighbor) continue;
     103
     104    char mapname[1024];
     105    snprintf (mapname, 1024, "%s/AstroMapUpdate.%d.fits", CATDIR, regionHosts->hosts[i].hostID);
     106   
     107    AstromOffsetTable *table = AstromOffsetMapLoad (mapname, VERBOSE);
     108 
     109    // apply table entries here to existing images
     110    for (j = 0; j < table->Nmap; j++) {
     111      off_t seq = getImageByID (table->map[j][0].imageID);
     112      // I do not necessarily own all images listed in the table.  skip if not found
     113      if (seq < 0) continue;
     114
     115      AstromOffsetMap *oldMap = images[seq].coords.offsetMap;
     116      AstromOffsetMap *newMap = table->map[j];
     117
     118      if (oldMap) {
     119        AstromOffsetMapSetOrder (oldMap, newMap->Nx, newMap->Ny, &images[seq]);
     120        AstromOffsetMapCopyData (oldMap, newMap);
     121      } else {
     122        lockUpdateChips ();
     123        AstromOffsetTable *FullTable = get_astrom_table ();
     124        AstromOffsetTableNewMap(FullTable, newMap->Nx, newMap->Ny, &images[seq]);  // registers the map with the image
     125        unlockUpdateChips ();
     126        AstromOffsetMapCopyData (images[seq].coords.offsetMap, newMap); // oldMap is now not valid
     127      }
     128    }
     129    AstromOffsetTableFree(table);
     130  }
     131
     132  // apply the modified image parameters to my detections
     133  for (i = 0; FALSE && (Ncatalog > 0) && (i < Nimage_pos); i++) {
     134    off_t seq = getImageByID (image_pos[i].imageID);
     135    if (seq < 0) continue;
     136    updateImageRaw (catalog, Ncatalog, seq);
    82137  }
    83138  free (image_pos);
     
    93148  image_pos->dXpixSys     = image->dXpixSys;
    94149  image_pos->dYpixSys     = image->dYpixSys;
     150  image_pos->refColorBlue = image->refColorBlue;
     151  image_pos->refColorRed  = image->refColorRed;
    95152  image_pos->imageID      = image->imageID;
    96153  image_pos->nFitAstrom   = image->nFitAstrom;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relastro/src/testparallax.c

    r36482 r37822  
    4949
    5050  /* project coordinates to a plane centered on the object with units of arcsec */
    51   coords.crval1 = 0;
    52   coords.crval2 = 0;
    53   coords.crpix1 = 0;
    54   coords.crpix2 = 0;
     51  InitCoords (&coords, "DEC--SIN");
    5552  coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
    56   coords.pc1_1  = coords.pc2_2 = 1.0;
    57   coords.pc1_2  = coords.pc2_1 = 0.0;
    58   coords.Npolyterms = 1;
    59   strcpy (coords.ctype, "DEC--SIN");
    6053
    6154  // use one point as a local reference
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/include/relphot.h

    r37037 r37822  
    440440int MatchImageName (off_t meas, int cat, char *name);
    441441int 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);
    442443
    443444int load_tess (char *treefile);
     
    451452int setMrel_catalog_alt (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt);
    452453int 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);
    453 int setMrelAverageStack (off_t meas, int cat, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, char *primaryCell);
     454int setMrelAverageStack (off_t measureOffset, int cat, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t Nmeasure);
     455int setMrelAverageForcedWarp (off_t measureOffset, int cat, int pass, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t *found, off_t Nmeasure);
     456
    454457int setGlobalObjStats (Average *average, Measure *measure);
    455458
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/BoundaryTreeOps.c

    r36491 r37822  
    5151  if (!tess) return FALSE;
    5252
    53   status = TessellationPrimaryCellIDs(tess, Ntess, tessID, projID, skycellID, ra, dec);
     53  double R = ohana_normalize_angle(ra);
     54  status = TessellationPrimaryCellIDs(tess, Ntess, tessID, projID, skycellID, R, dec);
    5455  return status;
    5556}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/ImageOps.c

    r37037 r37822  
    3535static off_t        *imageIdx; // list of index for image IDs
    3636
     37// QQ // as an alternative, we generate imageSeq, which directly maps imageID -> seq
     38// QQ static off_t        *imageSeq; // list of index for image IDs
     39// QQ
     40// QQ // MAX_ID requires 512M to store the image index
     41// QQ # define MAX_ID 0x8000000
     42// QQ static off_t         minImageID = MAX_ID;
     43// QQ static off_t         maxImageID = 0;
     44
    3745// elsewhere, we have loaded a set of catalogs with measures (catalog[cat].measure[meas])
    3846// each image has N_onImage[ImageIndex] measurements
     
    95103
    96104    TessellationIDsByImageName (&tessID[i], &projectID[i], &skycellID[i], image[i].name);
     105
     106    // QQ minImageID = MIN(minImageID, image[i].imageID);
     107    // QQ maxImageID = MAX(maxImageID, image[i].imageID);
     108    // QQ myAssert (image[i].imageID < MAX_ID, "image IDs too large for index memory");
    97109  }
    98110
     
    100112  // XXX does this break the imageID <-> projectID, etc match?
    101113  llsortpair (imageIDs, imageIdx, Nimage);
     114
     115  // QQ ALLOCATE (imageSeq, off_t, maxImageID + 1);
     116  // QQ for (i = 0; i < maxImageID + 1; i++)  {
     117  // QQ   imageSeq[i] = -1; // not yet assigned
     118  // QQ }
     119  // QQ
     120  // QQ for (i = 0; i < Nimage; i++) {
     121  // QQ   off_t N = image[i].imageID;
     122  // QQ   myAssert (imageSeq[N] == -1, "previously assigned");
     123  // QQ   imageSeq[N] = i;
     124  // QQ }
    102125}
    103126
     
    168191off_t getImageByID (off_t ID) {
    169192
     193  // QQ  if (imageSeq) {
     194  // QQ    myAssert (ID >= minImageID, "oops");
     195  // QQ    myAssert (ID <= maxImageID, "oops");
     196  // QQ    off_t N = imageSeq[ID];
     197  // QQ    return N;
     198  // QQ  }
     199
    170200  // we have a pair of vectors (imageIDs, imageIdx) sorted by imageIDs
    171201  // use bisection to find the specified image ID
     
    491521  if (projectID[i] != myProjectionID) return FALSE;
    492522  if (skycellID[i] != mySkycellID) return FALSE;
     523 
     524  return TRUE;
     525}
     526
     527// returns image.Mcal - ff(x,y)
     528int FindImageSkycellID (off_t meas, int cat, int *myTessID, int *myProjectionID, int *mySkycellID) {
     529
     530  off_t i;
     531
     532  if (!MeasureToImage) return FALSE;
     533
     534  if (meas < 0) return FALSE;
     535
     536  i = MeasureToImage[cat][meas];
     537  if (i == -1) return FALSE;
     538
     539  if (tessID[i]    == -1) return FALSE;
     540  if (projectID[i] == -1) return FALSE;
     541  if (skycellID[i] == -1) return FALSE;
     542
     543  *myTessID = tessID[i];
     544  *myProjectionID = projectID[i];
     545  *mySkycellID =  skycellID[i];
    493546 
    494547  return TRUE;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/ImageTable.c

    r36630 r37822  
    3232  }
    3333
     34  // XXX do not make the chip match -- we have not loaded the PHU entries (and do not need them here)
     35  // BuildChipMatch (image, Nimage);
     36
    3437  *nimage = Nimage;
    3538  return image;
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/MosaicOps.c

    r37037 r37822  
    520520      m = MosaicToImage[i][j];
    521521
    522       if (!FindMosaicForImage (image, Nimage, m)) {
    523         if (VERBOSE2) fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    524         continue;
    525       }
    526 
    527522      NX = image[m].NX;
    528523      NY = image[m].NY;
    529       XY_to_RD (&R, &D, 0.5*NX, 0.5*NY, &image[m].coords);
     524      if (!XY_to_RD (&R, &D, 0.5*NX, 0.5*NY, &image[m].coords)) continue;
    530525      R = ohana_normalize_angle_to_midpoint (R, 180.0);
    531526
     
    587582    }
    588583
    589     strcpy (mosaic[i].coords.ctype, "DEC--TAN");
     584    InitCoords (&mosaic[i].coords, "DEC--TAN");
    590585    mosaic[i].coords.crval1 = Rmid;
    591586    mosaic[i].coords.crval2 = Dmid;
    592     mosaic[i].coords.crpix1 = 0.0;
    593     mosaic[i].coords.crpix2 = 0.0;
    594587    mosaic[i].coords.cdelt1 = 1.0 / 3600.0;
    595588    mosaic[i].coords.cdelt2 = 1.0 / 3600.0;
    596     mosaic[i].coords.pc1_1  = 1.0;
    597     mosaic[i].coords.pc2_2  = 1.0;
    598     mosaic[i].coords.pc1_2  = 0.0;
    599     mosaic[i].coords.pc2_1  = 0.0;
    600589
    601590    mosaic[i].Mcal   = 0.0;
     
    631620      NY = image[m].NY;
    632621      dS += hypot (image[m].coords.cdelt1*image[m].coords.pc1_1, image[m].coords.cdelt1*image[m].coords.pc2_1);
    633       XY_to_RD (&R, &D, 0.0, 0.0, &image[m].coords);
     622
     623      OhanaProjection proj = GetProjection (image[m].coords.ctype);
     624      if ((proj == PROJ_WRP) && !image[m].coords.mosaic) {
     625        XY_to_LM (&R, &D, 0.0, 0.0, &image[m].coords);
     626      } else {
     627        XY_to_RD (&R, &D, 0.0, 0.0, &image[m].coords);
     628      }
    634629      Rmin = MIN (Rmin, R);
    635630      Rmax = MAX (Rmax, R);
    636631      Dmin = MIN (Dmin, D);
    637632      Dmax = MAX (Dmax, D);
    638       XY_to_RD (&R, &D, (double) NX, 0.0, &image[m].coords);
     633
     634      if ((proj == PROJ_WRP) && !image[m].coords.mosaic) {
     635        XY_to_LM (&R, &D, (double) NX, 0.0, &image[m].coords);
     636      } else {
     637        XY_to_RD (&R, &D, (double) NX, 0.0, &image[m].coords);
     638      }
    639639      Rmin = MIN (Rmin, R);
    640640      Rmax = MAX (Rmax, R);
    641641      Dmin = MIN (Dmin, D);
    642642      Dmax = MAX (Dmax, D);
    643       XY_to_RD (&R, &D, (double) NX, (double) NY, &image[m].coords);
     643
     644      if ((proj == PROJ_WRP) && !image[m].coords.mosaic) {
     645        XY_to_LM (&R, &D, (double) NX, (double) NY, &image[m].coords);
     646      } else {
     647        XY_to_RD (&R, &D, (double) NX, (double) NY, &image[m].coords);
     648      }
    644649      Rmin = MIN (Rmin, R);
    645650      Rmax = MAX (Rmax, R);
    646651      Dmin = MIN (Dmin, D);
    647652      Dmax = MAX (Dmax, D);
    648       XY_to_RD (&R, &D, 0.0, (double) NY, &image[m].coords);
     653
     654      if ((proj == PROJ_WRP) && !image[m].coords.mosaic) {
     655        XY_to_LM (&R, &D, 0.0, (double) NY, &image[m].coords);
     656      } else {
     657        XY_to_RD (&R, &D, 0.0, (double) NY, &image[m].coords);
     658      }
    649659      Rmin = MIN (Rmin, R);
    650660      Rmax = MAX (Rmax, R);
     
    652662      Dmax = MAX (Dmax, D);
    653663
     664      // XXX : this probably does not handle mosaics at RA = 0,360 well
     665
    654666      /* we are using mosaic.Mcal, not image.Mcal. reset image.Mcal */
    655667
     
    668680    }
    669681    dS /= MosaicN_Image[i];
    670     strcpy (mosaic[i].coords.ctype, "DEC--TAN");
     682
     683    InitCoords (&mosaic[i].coords, "DEC--TAN");
    671684    mosaic[i].coords.crval1 = Rmin;
    672685    mosaic[i].coords.crval2 = Dmin;
    673     mosaic[i].coords.crpix1 = 0.0;
    674     mosaic[i].coords.crpix2 = 0.0;
    675686    mosaic[i].coords.cdelt1 = dS;
    676687    mosaic[i].coords.cdelt2 = dS;
    677     mosaic[i].coords.pc1_1  = 1.0;
    678     mosaic[i].coords.pc2_2  = 1.0;
    679     mosaic[i].coords.pc1_2  = 0.0;
    680     mosaic[i].coords.pc2_1  = 0.0;
     688
    681689    RD_to_XY (&dX, &dY, Rmax, Dmax, &mosaic[i].coords);
    682690
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/StarOps.c

    r37037 r37822  
    10861086          if (ecode != thisCode) { continue; }
    10871087
     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         
    10881094          // NOTE: we do not skip MEAS_BAD because this measurement is just an internal assessment of the outliers
    10891095          Mcal  = getMcal  (m, i, flatcorr, catalog);
     
    11311137          if (ecode != thisCode) { continue; }
    11321138
     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         
    11331145          // NOTE: we do not skip MEAS_BAD because this measurement is just an internal assessment of the outliers
    11341146          Mcal  = getMcal  (m, i, flatcorr, catalog);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/assign_images.c

    r37037 r37822  
    8080    if (!strcmp(&image[j].coords.ctype[4], "-DIS")) continue;
    8181
    82     // match the image to its corresponding ASTROMETRIC mosaic (not the same as the Mosaic above)
    83     if (!FindMosaicForImage (image, Nimage, j)) {
    84       if (VERBOSE2) fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    85       continue;
    86     }
    87    
    8882    // Exclude images with crazy astrometry
    8983    // XXX NOTE : this is gpc1-specific
     
    123117
    124118    if (MOSAIC_ZEROPT) {
    125       // use the coords of the associated mosaic to select
     119      // use the coords of the associated mosaic to select (only for chips; stacks use their own center)
    126120      Mosaic *mosaic = getMosaicForImage (j);
    127       Rc = mosaic->coords.crval1;
    128       Dc = mosaic->coords.crval2;
    129       // NOTE : have defined mosaic Rc,Dc to choose the side of 0,360 on which most of the
    130       // chips are located.  but, for host assignment, we rationalize to 0.0 - 360.0
    131       Rc = ohana_normalize_angle_to_midpoint (Rc, 180.0);
     121      if (mosaic) {
     122        Rc = mosaic->coords.crval1;
     123        Dc = mosaic->coords.crval2;
     124        // NOTE : have defined mosaic Rc,Dc to choose the side of 0,360 on which most of the
     125        // chips are located.  but, for host assignment, we rationalize to 0.0 - 360.0
     126        Rc = ohana_normalize_angle_to_midpoint (Rc, 180.0);
     127      }
    132128    }
    133129
     
    206202}
    207203
    208 int calculate_host_image_bounds (RegionHostTable *regionHosts, double Rmid) {
    209 
    210   int i, n;
    211   off_t j;
    212 
    213   for (i = 0; i < regionHosts->Nhosts; i++) {
    214 
    215     RegionHostInfo *host = &regionHosts->hosts[i];
    216 
    217     // XXX clear the chip match?
    218 
    219     BuildChipMatch (host->image, host->Nimage);
    220 
    221     double Rmin =  720.0;
    222     double Rmax = -360.0;
    223     double Dmin =  +90.0;
    224     double Dmax = -90.0;
    225 
    226     for (j = 0; j < host->Nimage; j++) {
    227 
    228       Image *image = &host->image[j];
    229 
    230       if (!FindMosaicForImage (host->image, host->Nimage, j)) {
    231         fprintf (stderr, "missing astrometry? programming error?\n");
    232         abort ();
    233       }
    234      
    235       // define image corners
    236       for (n = 0; n < 4; n++) {
    237         double Xc, Yc, Rc, Dc;
    238         Xc = Xf[n]*image->NX;
    239         Yc = Yf[n]*image->NY;
    240         XY_to_RD (&Rc, &Dc, Xc, Yc, &image->coords);
    241         Rc = ohana_normalize_angle_to_midpoint (Rc, Rmid);
    242      
    243         Rmin = MIN (Rmin, Rc);
    244         Dmin = MIN (Dmin, Rc);
    245        
    246         Rmax = MAX (Rmax, Rc);
    247         Dmax = MAX (Dmax, Rc);
    248       }
    249 
    250     }
    251 
    252     // RminCat, RmaxCat may extended beyond 0.0 - 360.0
    253     host->RminCat = Rmin;
    254     host->DminCat = Dmin;
    255     host->RmaxCat = Rmax;
    256     host->DmaxCat = Dmax;
    257 
    258     // regionHosts needs to have the full outer boundary
    259     // (so reload_catalogs covers the correct region)
    260     regionHosts->Rmin = MIN(Rmin, regionHosts->Rmin);
    261     regionHosts->Rmax = MAX(Rmax, regionHosts->Rmax);
    262     regionHosts->Dmin = MIN(Dmin, regionHosts->Dmin);
    263     regionHosts->Dmax = MAX(Dmax, regionHosts->Dmax);
    264   }
    265   return TRUE;
    266 }
    267 
    268 
    269204// Rc is in range 0.0 - 360.0, hosts Rmin,Rmax in range 0.0 - 360.0
    270205int find_host_for_coords (RegionHostTable *regionHosts, double Rc, double Dc) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/bcatalog.c

    r37037 r37822  
    7878        int Nsec = GetPhotcodeNsec(thisCode);
    7979
    80         fprintf (stderr, "really use dvo_secfilt_init?");
     80        // fprintf (stderr, "really use dvo_secfilt_init?");
    8181        dvo_secfilt_init (&subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec]);
    8282
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/load_images.c

    r35759 r37822  
    2727  }
    2828  MARKTIME("read image table: %f sec\n", dtime);
     29
     30  BuildChipMatch (image, Nimage);
     31  MARKTIME("build chip match for %d images: %f sec\n", (int) Nimage, dtime);
     32
     33  char mapfile[DVO_MAX_PATH];
     34  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", CATDIR);
     35  AstromOffsetTable *table = AstromOffsetMapLoad (mapfile, VERBOSE);
     36
     37  // assign images.coords.offsetMap -> table->map[i]
     38  if (table) {
     39    AstromOffsetTableMatchChips (image, Nimage, table);
     40  }
    2941
    3042  // allocate and init an array to identify the images included in the subset
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/reload_catalogs.c

    r36630 r37822  
    128128}
    129129
     130int reload_catalog_parallel_group (HostTableGroup *group, SkyList *sky, char *imageFile);
     131
    130132// XXX Image to Image Subset
    131133int reload_catalogs_parallel (SkyList *sky) {
     
    165167    free (BOUNDARY_TREE);
    166168    BOUNDARY_TREE = tmppath;
    167    
    168   }
     169  }
     170
     171  int Ngroups;
     172  HostTableGroup *groups = HostTableGroups (table, &Ngroups);
     173  // split the table into Ngroups, each with a unique set of machines (this avoids overloading the remote host machines)
     174
     175  int i;
     176  for (i = 0; i < Ngroups; i++) {
     177    // update only a group of unique machines at a time
     178    reload_catalog_parallel_group (&groups[i], sky, imageFile);
     179  }
     180  return TRUE;
     181}
     182
     183int reload_catalog_parallel_group (HostTableGroup *group, SkyList *sky, char *imageFile) {
    169184
    170185  int i, j;
    171   for (i = 0; i < table->Nhosts; i++) {
    172 
    173     if (sky->Nregions < table->Nhosts) {
     186  for (i = 0; i < group->Nhosts; i++) {
     187
     188    if (sky->Nregions < group->Nhosts) {
    174189      // do any of the regions want this host?
    175190      int wantThisHost = FALSE;
    176191      for (j = 0; j < sky->Nregions; j++) {
    177         if (HostTableTestHost (sky->regions[j], table->hosts[i].hostID)) {
     192        if (HostTableTestHost (sky->regions[j], group->hosts[i][0].hostID)) {
    178193          wantThisHost = TRUE;
    179194          break;
     
    181196      }
    182197      if (!wantThisHost) {
    183         // fprintf (stderr, "skip host %s\n", table->hosts[i].hostname);
     198        // fprintf (stderr, "skip host %s\n", group->hosts[i][0].hostname);
    184199        continue;
    185200      }
     
    187202
    188203    // ensure that the paths are absolute path names
    189     char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH);
    190     free (table->hosts[i].pathname);
    191     table->hosts[i].pathname = tmppath;
     204    char *tmppath = abspath (group->hosts[i][0].pathname, DVO_MAX_PATH);
     205    free (group->hosts[i][0].pathname);
     206    group->hosts[i][0].pathname = tmppath;
    192207
    193208    char command[1024];
    194209    snprintf (command, 1024, "relphot_client %s -update-catalogs %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -D CAMERA %s -D STAR_TOOFEW %d -minerror %f",
    195               PhotcodeList, imageFile, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, CAMERA, STAR_TOOFEW, MIN_ERROR);
     210              PhotcodeList, imageFile, group->hosts[i][0].hostID, CATDIR, group->hosts[i][0].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, CAMERA, STAR_TOOFEW, MIN_ERROR);
    196211
    197212    // options & configs which affect relphot_client -update-catalogs
     
    238253      // launch the job on the remote machine (no handshake)
    239254      int errorInfo = 0;
    240       int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE);
     255      int pid = rconnect ("ssh", group->hosts[i][0].hostname, command, group->hosts[i][0].stdio, &errorInfo, FALSE);
    241256      if (!pid) {
    242         if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo);
     257        if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", group->hosts[i][0].hostname, errorInfo);
    243258        exit (1);
    244259      }
    245       table->hosts[i].pid = pid; // save for future reference
     260      group->hosts[i][0].pid = pid; // save for future reference
    246261    }
    247262  }
     
    252267  }
    253268  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
    254     int status = HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE);
     269    int status = HostTableGroupWaitJobsGetIO (group, __FILE__, __LINE__, VERBOSE);
    255270    if (!status) {
    256271      fprintf (stderr, "at least one remote client job failed to load data, exiting\n");
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/relphot.c

    r36630 r37822  
    99  switch (mode) {
    1010    case UPDATE_IMAGES:
     11      // IF CALLED WITH NLOOP == 0, DOES NOT LOAD bcatalog, just loads image table and generates ImageSubset.dat
    1112      relphot_images ();
    1213      exit (0);
     
    1415    case UPDATE_AVERAGES:
    1516      // take the current set of detections and set the mean magnitudes
     17      // DOES NOT LOAD THE IMAGE TABLE
    1618      relphot_objects (0, NULL);
    1719      exit (0);
     
    4345  exit (1);
    4446}
     47
     48/***
     49
     50    I would like to merge the functionality of relphot_images (Nloop == 0), relphot_objects, and apply_offsets
     51   
     52***/
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/relphot_objects.c

    r35104 r37822  
    3636    if (!HostTableTestHost(skylist[0].regions[i], hostID)) continue;
    3737
    38     // set up the basic catalog info
    3938    // set up the basic catalog info
    4039    char hostfile[1024];
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/relphot_parallel_regions.c

    r37037 r37822  
    4343  MARKTIME("-- load image data: %f sec\n", dtime);
    4444
     45  // save Images.dat using the copied structure
     46  if (UPDATE_CATFORMAT) {
     47    // ensure the db format is updated
     48    db.format = dvo_catalog_catformat (UPDATE_CATFORMAT);
     49  }
     50
    4551  /* assign the images to the different region hosts */
    4652  if (!assign_images (&db, regionHosts)) Shutdown ("error assigning images to region hosts");
     
    4955  /* launch processing on the parallel region hosts */
    5056  if (!launch_region_hosts (regionHosts)) Shutdown ("error launching region hosts");
     57  MARKTIME ("finished relphot -parallel-regions: %f sec total\n", dtime);
    5158
    5259  // retrieve updated image parameters from the remote hosts (also set Image.mcal)
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/select_images.c

    r36491 r37822  
    3636
    3737  // the comparison is made in the catalog local projection. below we set crval1,2
    38   tcoords.crpix1 = tcoords.crpix2 = 0.0;
     38  InitCoords (&tcoords, "DEC--TAN");
    3939  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    40   tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    41   tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    42   strcpy (tcoords.ctype, "DEC--TAN");
    4340
    4441  double RminSkyRegion = region[0].Rmin;
     
    9390
    9491  if (VERBOSE) fprintf (stderr, "finding images\n");
    95   BuildChipMatch (timage, Ntimage);
    96   MARKTIME("build chip match for %d images: %f sec\n", (int) Ntimage, dtime);
    9792
    9893  D_NIMAGE = 6000;
     
    107102     
    108103    if (!(i % 300000)) fprintf (stderr, ".");
     104
     105    // XXX I am just going for force this for the moment:
     106    goto found_it;
    109107
    110108    /* exclude images by photcode */
     
    123121    }
    124122   
    125     // this adds 1.3 sec for 3M images
    126     if (!FindMosaicForImage (timage, Ntimage, i)) {
    127       if (VERBOSE2) fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    128       continue;
    129     }
    130 
    131123    /* define image corners - note the DIS images (mosaic phu) are special */
    132124    if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) {
     
    405397
    406398  // the comparison is made in the catalog local projection. below we set crval1,2
    407   tcoords.crpix1 = tcoords.crpix2 = 0.0;
     399  InitCoords (&tcoords, "DEC--TAN");
    408400  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    409   tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    410   tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    411 
    412   tcoords.Npolyterms = 0;
    413   memset (tcoords.polyterms, 0, 14*sizeof(float));
    414   strcpy (tcoords.ctype, "DEC--TAN");
    415401
    416402  /* compare with each region file */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/relphot/src/setMrelCatalog.c

    r37037 r37822  
    3636}
    3737
    38 int setMrelAverageForcedWarp (off_t measureOffset, int cat, int pass, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t *found);
    39 
    4038int setMrel_catalog_alt (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt) {
    4139
     
    5048  int isSetMrelFinal = (pass >= 0);
    5149
    52   char *primaryCell = NULL;
    53   if (isSetMrelFinal) {
    54     ALLOCATE (primaryCell, char, DVO_MAX_PATH);
    55   }
     50  // XX char *primaryCell = NULL;
     51  // XX if (isSetMrelFinal) {
     52  // XX   ALLOCATE (primaryCell, char, DVO_MAX_PATH);
     53  // XX }
    5654
    5755  for (j = 0; j < catalog[Nc].Naverage; j++) {
     
    6058    Average *average = catalog[Nc].average ? &catalog[Nc].average[j] : NULL;
    6159    Measure *measure = catalog[Nc].measure ? &catalog[Nc].measure[m] : NULL;
    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]);
     60    SecFilt *secfilt = catalog[Nc].secfilt ? &catalog[Nc].secfilt[j*Nsecfilt] : NULL;
     61    setMrelAverageExposure (m, Nc, pass, flatcorr, results, average, &catalog[Nc].averageT[j], secfilt, measure, &catalog[Nc].measureT[m], &catalog[Nc].found_t[Nsecfilt*j]);
    6362
    6463    // only apply Stack operation on setMrelFinal in first pass
    6564    if (isSetMrelFinal && (pass == 0)) {
    66       setMrelAverageStack (m, Nc, flatcorr, results, &catalog[Nc].average[j], &catalog[Nc].secfilt[j*Nsecfilt], &catalog[Nc].measure[m], primaryCell);
     65      setMrelAverageStack (m, Nc, flatcorr, results, average, secfilt, &catalog[Nc].measure[m], catalog[Nc].Nmeasure);
    6766      setGlobalObjStats (&catalog[Nc].average[j], &catalog[Nc].measure[m]);
    6867    }
     
    7069    // only measure force-warp mean values if issetMrelFinal (make it optional?)
    7170    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);
     71      setMrelAverageForcedWarp (m, Nc, pass, results, average, secfilt, measure, &catalog[Nc].foundWarp_t[Nsecfilt*j], catalog[Nc].Nmeasure);
     72      setGlobalObjStats (average, measure);
     73    }
     74  }
     75  // if (primaryCell) free (primaryCell);
    7776  return (TRUE);
    7877}
     
    147146    off_t meas = measureOffset;
    148147
     148    float psfQfMax = 0.0;
     149    float psfQfPerfMax = 0.0;
     150
    149151    int Nap = 0;
    150152    int Npsf = 0;
     
    166168      // SKIP gpc1 forced-warp data
    167169      if (isGPC1warp(measureT[k].photcode)) continue;
     170
     171      if (isSetMrelFinal) {
     172        if (measure[k].psfQF     > psfQfMax)     psfQfMax     = measure[k].psfQF;
     173        if (measure[k].psfQFperf > psfQfPerfMax) psfQfPerfMax = measure[k].psfQFperf;
     174      }
    168175
    169176      if (measureT[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS(Nbad);
     
    367374      secfilt[Nsec].Mmin = psfstats->min;
    368375
     376      secfilt[Nsec].psfQfMax     = psfQfMax;
     377      secfilt[Nsec].psfQfPerfMax = psfQfPerfMax;
     378
    369379      // NOTE : use the modified weight for apmags as well as psf mags
    370380      liststats (Maplist, daplist, waplist, Nap, apstats);
     
    441451
    442452// only apply Stack operation on setMrelFinal in first pass
    443 int setMrelAverageStack (off_t measureOffset, int cat, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, char *primaryCell) {
    444 
    445   off_t k, ID;
    446 
    447   float Msys = 0, Mcal= 0, Mmos = 0, Mgrid = 0;
     453// this function has 3 goals, not to be confused:
     454// 1) find and mark the PRIMARY detections (regardless of the quality of the detection)
     455// 2) select the BEST detections per filter (regardless of PRIMARY)
     456// 3) apply the zero point and AB->Jy transformations
     457int setMrelAverageStack (off_t measureOffset, int cat, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t Nmeasure) {
     458
     459  off_t k;
     460
     461  float Mcal= 0, Mmos = 0, Mgrid = 0, Finst = 0;
    448462
    449463  // set the primary projection cell and skycell for this coordinate
     
    453467  get_tess_ids(&tessID, &projectID, &skycellID, average[0].R, average[0].D);
    454468
     469  average[0].tessID       = tessID;
     470  average[0].projectionID = projectID;
     471  average[0].skycellID    = skycellID;
     472
    455473  int NstackGood = 0;
    456474  int NstackSuspect = 0;
     
    467485    int haveStack = FALSE;
    468486
    469     // need to find the measurement closest to the center of its skycell, as well as the
    470     // closest for the subset of primary projection cells
    471 
    472     float stackCenterOffsetMin = 1e9;
    473     off_t stackCenterMeasureMin = -1;
    474 
    475     float stackPrimaryOffsetMin = 1e9;
    476     off_t stackPrimaryMeasureMin = -1;
     487    float psfQFbest = 0.0;
     488
     489    off_t stackBestMeasure = -1;
     490    off_t stackPrimaryMeasure = -1;
    477491
    478492    int isBad = FALSE;
    479493    int isSuspect = FALSE;
    480494
     495    int Nstack = 0; // number for this photcode
     496    int NstackDet = 0; // number for this photcode
     497
     498    secfilt[Nsec].stackBestOff = -1;
     499    secfilt[Nsec].stackPrmryOff = -1;
     500
    481501    off_t meas = measureOffset;
    482502    for (k = 0; k < average[0].Nmeasure; k++, meas++) {
     503
     504      // only examine gpc1 stack data
     505      if (!isGPC1stack(measure[k].photcode)) continue;
    483506
    484507      // skip measurements that do not match the current photcode
     
    487510      if (code->equiv != thisCode) { continue; }
    488511
     512      Nstack ++;
     513      if ((measure[k].photFlags2 & 0x00000004) == 0) NstackDet ++;
     514
    489515      // clear this bit for all measurements
    490516      measure[k].dbFlags &= ~ID_MEAS_STACK_PRIMARY;
    491 
    492       // only examine gpc1 stack data
    493       if (!isGPC1stack(measure[k].photcode)) continue;
     517      measure[k].dbFlags &= ~ID_MEAS_STACK_PHOT_SRC;
    494518
    495519      haveStack = TRUE;
    496520      haveStackObject = TRUE;
    497521     
     522      // find the PRIMARY measurement
     523
     524      // if we request the primary (USE_TREE_FOR_PRIMARY), this is true if the measurement is from the
     525      // primary skycell for this position
     526      if (MatchImageSkycellID (meas, cat, tessID, projectID, skycellID)) {
     527        stackPrimaryMeasure = k;
     528        measure[k].dbFlags |= ID_MEAS_STACK_PRIMARY;
     529        secfilt[Nsec].stackPrmryOff = meas;
     530        myAssert (secfilt[Nsec].stackPrmryOff <= Nmeasure, "stackPrmryOff out of range");
     531      }
     532
     533      // now choose the BEST measurements (may also be PRIMARY)
     534
    498535      if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS_STACK(Nbad);
    499536
    500       if (getImageEntry (meas, cat) < 0) continue;
    501537      // measurements without an image are either external reference photometry or
    502538      // data for which the associated image has not been loaded (probably because of
    503539      // overlaps).  we only want measurements associated with stack images in this loop
    504540
    505       Mcal  = getMcal_alt  (meas, cat, flatcorr, measure[k].Xccd, measure[k].Yccd);
    506       if (isnan(Mcal))  SKIP_THIS_MEAS_STACK(Ncal);
    507       Mmos  = getMmos  (meas, cat);
    508       if (isnan(Mmos))  SKIP_THIS_MEAS_STACK(Nmos);
    509       Mgrid = getMgrid (meas, cat);
    510       if (isnan(Mgrid)) SKIP_THIS_MEAS_STACK(Ngrid);
    511 
    512       Msys = PhotSys (&measure[k], &average[0], &secfilt[0], MAG_CLASS_PSF);
    513       if (isnan(Msys)) SKIP_THIS_MEAS_STACK(Nsys);
    514 
    515       unsigned int stackImageID;
    516 
    517       // which stack image should we use for the mean value?
    518       // if we request the primary (USE_TREE_FOR_PRIMARY), then find the min distances for data from the primary cell
    519       if (MatchImageSkycellID (meas, cat, tessID, projectID, skycellID)) {
    520         float stackPrimaryOffset = getCenterOffset (meas, cat, &measure[k], &stackImageID);
    521         if (stackPrimaryOffset < stackPrimaryOffsetMin) {
    522           stackPrimaryOffsetMin = stackPrimaryOffset;
    523           // stackPrimaryIDmin = stackImageID;
    524           stackPrimaryMeasureMin = k;
    525         }
    526       }
    527 
    528       // get the center distance for the generic case:
    529       float stackCenterOffset = getCenterOffset (meas, cat, &measure[k], &stackImageID);
    530       if (stackCenterOffset < stackCenterOffsetMin) {
    531         stackCenterOffsetMin = stackCenterOffset;
    532         // stackCenterIDmin = stackImageID;
    533         stackCenterMeasureMin = k;
     541      // match measurement to its image (this is just a check, right?)
     542      if (getImageEntry (meas, cat) < 0) {
     543        // measurements without an image are either external reference photometry or
     544        // data for which the associated image has not been loaded (probably because of
     545        // overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
     546        Mmos = Mgrid = 0;
     547        Mcal = measure[k].Mcal; // check that this is zero for loaded REF value
     548      } else {
     549        Mcal  = getMcal_alt  (meas, cat, flatcorr, measure[k].Xccd, measure[k].Yccd);
     550        if (isnan(Mcal))  SKIP_THIS_MEAS_STACK(Ncal);
     551        Mmos  = getMmos  (meas, cat);
     552        if (isnan(Mmos))  SKIP_THIS_MEAS_STACK(Nmos);
     553        Mgrid = getMgrid (meas, cat);
     554        if (isnan(Mgrid)) SKIP_THIS_MEAS_STACK(Ngrid);
     555      }
     556
     557      // NOTE: negative and insignificant vlues values are allowed, but not NAN flux values
     558      Finst = PhotFluxInst (&measure[k], MAG_CLASS_PSF);
     559      if (isnan(Finst)) SKIP_THIS_MEAS_STACK(Ninst);
     560
     561      if (measure[k].psfQFperf > psfQFbest) {
     562        psfQFbest = measure[k].psfQFperf;
     563        stackBestMeasure = k;
    534564      }
    535565
     
    554584
    555585    // measurements which are bad will not have a valid stack entry and are skipped
    556     k = (stackPrimaryMeasureMin >= 0) ? stackPrimaryMeasureMin : stackCenterMeasureMin;
     586    k = (stackBestMeasure >= 0) ? stackBestMeasure : stackPrimaryMeasure;
    557587    if (k < 0) continue;
    558 
    559588
    560589    // we are now populating stackDetectID not stack Image ID in secfilt
    561590    // ID = (stackPrimaryMeasureMin >= 0) ? stackPrimaryIDmin      : stackCenterIDmin;
    562     ID = measure[k].extID; // for the stack, this is the stackDetectID
     591    // ID = measure[k].extID; // for the stack, this is the stackDetectID
    563592
    564593    // get the zero point for the selected image
     
    605634    secfilt[Nsec].dFapStk   = zpFactor * measure[k].dFluxAp;
    606635
     636    // Jy to AB mags
    607637    secfilt[Nsec].MpsfStk   = (measure[k].FluxPSF  > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FpsfStk) : NAN;
    608638    secfilt[Nsec].MkronStk  = (measure[k].FluxKron > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FkronStk) : NAN;
    609639    secfilt[Nsec].MapStk    = (measure[k].FluxAp   > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FapStk) : NAN;
    610640
    611     secfilt[Nsec].stackDetectID = ID;
    612 
     641    secfilt[Nsec].stackBestOff = k + measureOffset;
     642    myAssert (secfilt[Nsec].stackBestOff <= Nmeasure, "stackBestOff out of range");
     643
     644    secfilt[Nsec].Nstack    = Nstack;
     645    secfilt[Nsec].NstackDet = NstackDet;
     646
     647    // this is the measurement used by secfilt[]
    613648    measure[k].dbFlags |= ID_MEAS_STACK_PHOT_SRC;
    614     if (stackPrimaryMeasureMin >= 0) {
    615       measure[k].dbFlags |= ID_MEAS_STACK_PRIMARY;
     649    if (k == stackPrimaryMeasure) {
    616650      secfilt[Nsec].flags |= ID_SECF_STACK_PRIMARY;
    617651    }
     
    639673// somewhat simplified relative to chip-photometry:
    640674// * no grid, no mosaic, no 2MASS, no SYNTH, no Ubercal, no flatcorr
    641 int setMrelAverageForcedWarp (off_t measureOffset, int cat, int pass, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t *found) {
     675int setMrelAverageForcedWarp (off_t measureOffset, int cat, int pass, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t *found, off_t Nmeasure) {
    642676
    643677  off_t k;
    644   float Fsys = 0, Mcal= 0;
     678  float Mcal= 0;
    645679
    646680  // we are measuring means for 3 types of FLUXes: psf, ap, kron.  I am using the psf mag
     
    664698
    665699  // option for a test print
    666   if (FALSE && (average[0].objID == 0x7146) && (average[0].catID == 0x49d8)) {
     700  if ((average[0].objID == 0xd6e) && (average[0].catID == 0x4984)) {
    667701    fprintf (stderr, "test obj\n");
    668702    print_measure_set_alt (average, secfilt, measure);
     
    680714    if (found[Nsec]) continue; 
    681715     
     716    // I need to restrict the measurements coming only from the same skycell as the secfilt values
     717    // if we cannot make that association, skip this set of warps
     718    int stkTessID, stkProjID, stkSkycellID;
     719
     720    myAssert (secfilt[Nsec].stackBestOff <= Nmeasure, "stackBestOff out of range");
     721    if (!FindImageSkycellID (secfilt[Nsec].stackBestOff, cat, &stkTessID, &stkProjID, &stkSkycellID)) continue;
     722
    682723    off_t meas = measureOffset;
    683724
     
    685726    int Npsf = 0;
    686727    int Nkron = 0;
     728
     729    int Nwarp = 0;
     730    int NwarpGood = 0;
    687731    for (k = 0; k < average[0].Nmeasure; k++, meas++) {
    688732
     
    694738      if (!code) continue;
    695739      if (code->equiv != thisCode) { continue; }
     740
     741      Nwarp ++;
     742      if (measure[k].psfQFperf > 0.85) NwarpGood ++;
     743
     744      measure[k].dbFlags &= ~ID_MEAS_WARP_USED;
     745
     746      if (!MatchImageSkycellID (meas, cat, stkTessID, stkProjID, stkSkycellID)) continue;
    696747
    697748      if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS(Nbad);
     
    720771      // are small (and not measured)
    721772      float Fpsf = PhotFluxCat (&measure[k], MAG_CLASS_PSF);
    722       if (isnan(Fsys)) SKIP_THIS_MEAS(Nsys);
     773      if (isnan(Fpsf)) SKIP_THIS_MEAS(Nsys);
    723774      // if (Msys <  0.0) SKIP_THIS_MEAS(Nsys);
    724775      // if (Msys > 30.0) SKIP_THIS_MEAS(Nsys);
    725776
    726777      float dFpsf = PhotFluxCatErr (&measure[k], MAG_CLASS_PSF);
     778      if (isnan(dFpsf)) SKIP_THIS_MEAS (Nsys);
     779
     780      int isBad = (measure[k].psfQF < 0.85);
     781      isBad |= isnan(measure[k].psfQF);
     782      if (isBad) SKIP_THIS_MEAS (Nsys);
     783
     784      int isPoor = (measure[k].psfQFperf < 0.85);
     785      if ((pass == 0) && isPoor) SKIP_THIS_MEAS (Nsys);
     786
    727787      dFpsf = MAX (dFpsf, MIN_ERROR*Fpsf); // MIN_ERROR is a fractional error
    728788      Fpsflist[Npsf] = Fpsf * Fcal;
     
    730790      wpsflist[Npsf] = 1.0;
    731791      Npsf ++;
     792
     793      measure[k].dbFlags |= ID_MEAS_WARP_USED;
    732794
    733795      float Fap = PhotFluxCat (&measure[k], MAG_CLASS_APER);
     
    775837    secfilt[Nsec].NusedKronWrp = Nkron;
    776838    secfilt[Nsec].MkronWrp  = isnan(secfilt[Nsec].FkronWrp) ? NAN : 8.9 - 2.5*log10(secfilt[Nsec].FkronWrp); // 8.9 since flux is in Jy
     839
     840    secfilt[Nsec].Nwarp     = Nwarp;
     841    secfilt[Nsec].NwarpGood = NwarpGood;
    777842  }
    778843  return (TRUE);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/uniphot/Makefile

    r35764 r37822  
    1 default: uniphot setphot setphot_client setfwhm setposangle setposangle_client setastrom setastrom_client fiximids fiximids_client fixstkids fixstkids_client ckids ckids_client
     1default: uniphot setphot setphot_client setfwhm setposangle setposangle_client setastrom setastrom_client setgalmodel setgalmodel_client fiximids fiximids_client fixstkids fixstkids_client ckids ckids_client
    22help:
    33@echo "make options: uniphot setphot setfwhm default help install default (uniphot setphot setfwhm)"
     
    2525setastrom: $(BIN)/setastrom.$(ARCH)
    2626setastrom_client: $(BIN)/setastrom_client.$(ARCH)
     27setgalmodel: $(BIN)/setgalmodel.$(ARCH)
     28setgalmodel_client: $(BIN)/setgalmodel_client.$(ARCH)
    2729fiximids: $(BIN)/fiximids.$(ARCH)
    2830fiximids_client: $(BIN)/fiximids_client.$(ARCH)
     
    3234ckids_client: $(BIN)/ckids_client.$(ARCH)
    3335
    34 install: $(DESTBIN)/uniphot $(DESTBIN)/setfwhm $(DESTBIN)/setphot $(DESTBIN)/setphot_client $(DESTBIN)/setposangle $(DESTBIN)/setposangle_client $(DESTBIN)/setastrom $(DESTBIN)/setastrom_client $(DESTBIN)/fiximids $(DESTBIN)/fiximids_client $(DESTBIN)/fixstkids $(DESTBIN)/fixstkids_client $(DESTBIN)/ckids $(DESTBIN)/ckids_client
     36install: $(DESTBIN)/uniphot $(DESTBIN)/setfwhm $(DESTBIN)/setphot $(DESTBIN)/setphot_client $(DESTBIN)/setposangle $(DESTBIN)/setposangle_client $(DESTBIN)/setastrom $(DESTBIN)/setastrom_client $(DESTBIN)/setgalmodel $(DESTBIN)/setgalmodel_client $(DESTBIN)/fiximids $(DESTBIN)/fiximids_client $(DESTBIN)/fixstkids $(DESTBIN)/fixstkids_client $(DESTBIN)/ckids $(DESTBIN)/ckids_client
    3537
    3638UNIPHOT = \
     
    110112$(SRC)/setastrom.$(ARCH).o          \
    111113$(SRC)/initialize_setastrom.$(ARCH).o \
     114$(SRC)/dcr_correction.$(ARCH).o \
     115$(SRC)/kh_correction.$(ARCH).o \
    112116$(SRC)/astrom_correction.$(ARCH).o \
    113117$(SRC)/update_dvo_setastrom.$(ARCH).o \
     
    123127$(SRC)/update_dvo_setastrom.$(ARCH).o \
    124128$(SRC)/update_catalog_setastrom.$(ARCH).o \
     129$(SRC)/dcr_correction.$(ARCH).o \
     130$(SRC)/kh_correction.$(ARCH).o \
    125131$(SRC)/astrom_correction.$(ARCH).o \
    126132$(SRC)/initialize_setastrom.$(ARCH).o
     
    128134$(SETASTROM_CLIENT): $(INC)/setastrom.h
    129135$(BIN)/setastrom_client.$(ARCH): $(SETASTROM_CLIENT)
     136
     137SETGALMODEL = \
     138$(SRC)/setgalmodel.$(ARCH).o        \
     139$(SRC)/initialize_setgalmodel.$(ARCH).o \
     140$(SRC)/galmodel_correction.$(ARCH).o \
     141$(SRC)/update_dvo_setgalmodel.$(ARCH).o \
     142$(SRC)/update_catalog_setgalmodel.$(ARCH).o \
     143$(SRC)/SetSignals.$(ARCH).o         \
     144$(SRC)/Shutdown.$(ARCH).o           
     145
     146$(SETGALMODEL): $(INC)/setgalmodel.h
     147$(BIN)/setgalmodel.$(ARCH): $(SETGALMODEL)
     148
     149SETGALMODEL_CLIENT = \
     150$(SRC)/setgalmodel_client.$(ARCH).o         \
     151$(SRC)/update_dvo_setgalmodel.$(ARCH).o \
     152$(SRC)/update_catalog_setgalmodel.$(ARCH).o \
     153$(SRC)/galmodel_correction.$(ARCH).o \
     154$(SRC)/initialize_setgalmodel.$(ARCH).o
     155
     156$(SETGALMODEL_CLIENT): $(INC)/setgalmodel.h
     157$(BIN)/setgalmodel_client.$(ARCH): $(SETGALMODEL_CLIENT)
    130158
    131159SETFWHM =                           \
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/uniphot/include/setastrom.h

    r35103 r37822  
    2525char        *SINGLE_CPT;
    2626
     27char        *KH_FILE;
     28char        *DCR_FILE;
     29
     30int          KH_RESET;
     31int          DCR_RESET;
     32
    2733SkyRegion    UserPatch;
    2834
     
    4652// int           SetSignals                      PROTO((void));
    4753
    48 int           update_dvo_setastrom            PROTO((char *corrfile));
    49 int           update_dvo_setastrom_parallel   PROTO((SkyTable *sky, char *corrfile));
     54int           update_dvo_setastrom            PROTO(());
     55int           update_dvo_setastrom_parallel   PROTO((SkyTable *sky));
    5056
    5157int           update_catalog_setastrom        PROTO((Catalog *catalog));
    5258
    5359// spline correction functions
    54 int load_astrom_correction (char *filename);
    55 int get_astrom_correction (int sub, int chip, double *dX, double *dY, float Minst);
    5660double spline_apply_dbl (double *x, double *y, double *y2, int N, double X);
     61
     62int load_kh_correction (char *filename);
     63int get_kh_correction (int sub, int chip, double *dX, double *dY, float Minst);
     64
     65int load_dcr_correction (char *filename);
     66int get_dcr_correction (int filter, double *dX, double *dY, float Color);
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/uniphot/src/astrom_correction.c

    r35103 r37822  
    22
    33// astrometry correction functions:
    4 // load the correction set from a file
    5 
    6 // the correction is saved as a set of splines, one per file extension
    7 // extensions have names of the form XYnn.Dx.Td
    8 
    9 // where nn = 00 - 77, the chip number
    10 // x is X or Y, the correction direction (dir)
    11 // d is 0 or 1, pre or post camera correction (sub)
    12 
    13 // these are stored in an N-D array of (Spline *) splineset[sub][dir][chip]
    14 
    15 # define N_SUB 2
    16 # define N_DIR 2
    17 # define N_CHIP 78
    18 // note that we are allocating pointers for XY00 - XY77, but only the octal elements are set (and not the 00,07,70,77 ones)
    19 
    20 Spline ****splineset;
    21 
    22 int load_astrom_correction (char *filename) {
    23 
    24   int Ncol;
    25   off_t Nrow;
    26 
    27   char type[16];
    28   char extname[80];
    29 
    30   Header header;
    31   Header theader;
    32   FTable ftable;
    33 
    34   /* open file for input */
    35   FILE *f = fopen (filename, "r");
    36   if (f == (FILE *) NULL) {
    37     gprint (GP_ERR, "can't open file for read : %s\n", filename);
    38     return FALSE;
    39   }
    40 
    41   // read the PHU header
    42   if (!gfits_load_header (f, &header)) return (FALSE);
    43  
    44   int Nbytes = gfits_data_size (&header);
    45   fseeko (f, Nbytes, SEEK_CUR);
    46   // XXX gfits_free_header (&header);
    47 
    48   ftable.header = &theader;
    49 
    50   int sub, dir, chip;
    51 
    52   // we have a N-D array of splines:
    53   // splineset[sub][dir][chip]
    54 
    55   ALLOCATE (splineset, Spline ***, N_SUB);
    56   for (sub = 0; sub < N_SUB; sub++) {
    57     ALLOCATE (splineset[sub], Spline **, N_DIR);
    58     for (dir = 0; dir < N_DIR; dir++) {
    59       ALLOCATE (splineset[sub][dir], Spline *, N_CHIP);
    60       for (chip = 0; chip < N_CHIP; chip ++) {
    61         splineset[sub][dir][chip] = NULL;
    62       }
    63     }
    64   }
    65 
    66   while (TRUE) {
    67     // load data for this header : if not found, assume we hit the end of the file
    68     if (!gfits_load_header (f, &theader)) break;
    69    
    70     if (!gfits_fread_ftable_data (f, &ftable, FALSE)) return (FALSE);
    71    
    72     if (!gfits_scan (&theader, "EXTNAME", "%s", 1, extname)) return (FALSE);
    73 
    74     // figure out the chip ID, diretion, and sequence from the EXTNAME
    75 
    76     // EXTNAME is of the form XY%d%d.D%s.T%s where
    77     char chipname[3];
    78     chipname[0] = extname[2];
    79     chipname[1] = extname[3];
    80     chipname[2] = 0;
    81     int chip = atoi(chipname);
    82     myAssert (chip >   0, "error in extname %s not(chip >   0)\n", extname);
    83     myAssert (chip <  77, "error in extname %s not(chip <  77)\n", extname);
    84     myAssert (chip !=  7, "error in extname %s not(chip !=  7)\n", extname);
    85     myAssert (chip != 70, "error in extname %s not(chip != 70)\n", extname);
    86 
    87     int dir = -1;
    88     if (extname[6] == 'X') {
    89       dir = 0;
    90     }
    91     if (extname[6] == 'Y') {
    92       dir = 1;
    93     }
    94     myAssert (dir != -1, "error in extname %s (dir)\n", extname);
    95 
    96     int sub = -1;
    97     if (extname[9] == '0') {
    98       sub = 0;
    99     }
    100     if (extname[9] == '1') {
    101       sub = 1;
    102     }
    103     myAssert (sub != -1, "error in extname %s (sub)\n", extname);
    104 
    105     // need to create and assign to flat-field correction
    106     double *xk = gfits_get_bintable_column_data (&theader, &ftable, "X_KNOT", type, &Nrow, &Ncol);
    107     myAssert (!strcmp(type, "double"), "error reading X_KNOT");
    108    
    109     // need to create and assign to flat-field correction
    110     double *yk = gfits_get_bintable_column_data (&theader, &ftable, "Y_KNOT", type, &Nrow, &Ncol);
    111     myAssert (!strcmp(type, "double"), "error reading X_KNOT");
    112    
    113     // need to create and assign to flat-field correction
    114     double *y2 = gfits_get_bintable_column_data (&theader, &ftable, "DY2_DX", type, &Nrow, &Ncol);
    115     myAssert (!strcmp(type, "double"), "error reading X_KNOT");
    116    
    117     ALLOCATE (splineset[sub][dir][chip], Spline, 1);
    118     splineset[sub][dir][chip]->xk = xk;
    119     splineset[sub][dir][chip]->yk = yk;
    120     splineset[sub][dir][chip]->y2 = y2;
    121     splineset[sub][dir][chip]->Nknots = Nrow;
    122   }
    123   return (TRUE);
    124 }
    125 
    126 int get_astrom_correction (int sub, int chip, double *dX, double *dY, float Minst) {
    127 
    128   Spline *spline = NULL;
    129 
    130   *dX = 0.0;
    131   *dY = 0.0;
    132 
    133   // XXX need to include some limits on Minst?
    134 
    135   spline = splineset[sub][0][chip];
    136   if (spline) {
    137     *dX = spline_apply_dbl (spline->xk, spline->yk, spline->y2, spline->Nknots, Minst);
    138   }
    139 
    140   spline = splineset[sub][1][chip];
    141   if (spline) {
    142     *dY = spline_apply_dbl (spline->xk, spline->yk, spline->y2, spline->Nknots, Minst);
    143   }
    144   return (TRUE);
    145 }
     4// KH correction
     5// DCR correction
    1466
    1477/* evaluate spline for x, y, y2 at X */
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/uniphot/src/find_image_sgroups.c

    r36481 r37822  
    1818  }
    1919
    20   coords.crpix1 = coords.crpix2 = 0.0;
    21   coords.cdelt1 = coords.cdelt2 = 1.0; /* scale is degrees, radius in degrees */
    22   coords.pc1_1 = coords.pc2_2 = 1.0;
    23   coords.pc1_2 = coords.pc2_1 = 0.0;
    24   strcpy (coords.ctype, "DEC--TAN");
     20  InitCoords (&coords, "DEC--TAN");
    2521 
    2622  Ngroup = 0;
     
    4137    // NOCAL above is used to mark images which do not match the photcode (including the DIS)
    4238    // if (!strcmp(&image[i].coords.ctype[4], "-DIS")) continue;
    43 
    44     // this adds 1.3 sec for 3M images
    45     if (!FindMosaicForImage (image, Nimage, i)) {
    46       fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    47       continue;
    48     }
    4939
    5040    /* define image center - note the DIS images (mosaic phu) are special */
     
    8373      // if (!strcmp(&image[j].coords.ctype[4], "-DIS")) continue;
    8474
    85       // this adds 1.3 sec for 3M images
    86       if (!FindMosaicForImage (image, Nimage, j)) {
    87           fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", j);
    88           continue;
    89       }
    90 
    9175      /* project image center to local coords, check radius */
    9276      if (!strcmp(&image[j].coords.ctype[4], "-DIS")) {
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/uniphot/src/initialize_setastrom.c

    r35103 r37822  
    22
    33void usage_setastrom () {
    4     fprintf (stderr, "USAGE: setastrom (corrections) [options]\n");
     4    fprintf (stderr, "USAGE: setastrom [options]\n");
    55    fprintf (stderr, "  options:\n");
     6    fprintf (stderr, "    -DCR (file) : supply DCR correction splines\n");
     7    fprintf (stderr, "    -KH (file) : supply Koppenhoefer correction splines\n");
    68    fprintf (stderr, "    -v : verbose mode\n");
    79    fprintf (stderr, "    -region Rmin Rmax Dmin Dmax\n");
     
    4951  int N;
    5052
     53  KH_FILE = NULL;
     54  if ((N = get_argument (argc, argv, "-KH"))) {
     55    remove_argument (N, &argc, argv);
     56    char *tmpfile = strcreate (argv[N]);
     57    KH_FILE = abspath (tmpfile, DVO_MAX_PATH);
     58    remove_argument (N, &argc, argv);
     59  }
     60  KH_RESET = FALSE;
     61  if ((N = get_argument (argc, argv, "-KH-reset"))) {
     62    remove_argument (N, &argc, argv);
     63    KH_RESET = TRUE;
     64  }
     65
     66  DCR_FILE = NULL;
     67  if ((N = get_argument (argc, argv, "-DCR"))) {
     68    remove_argument (N, &argc, argv);
     69    char *tmpfile = strcreate (argv[N]);
     70    DCR_FILE = abspath (tmpfile, DVO_MAX_PATH);
     71    remove_argument (N, &argc, argv);
     72  }
     73  DCR_RESET = FALSE;
     74  if ((N = get_argument (argc, argv, "-DCR-reset"))) {
     75    remove_argument (N, &argc, argv);
     76    DCR_RESET = TRUE;
     77  }
     78
    5179  SINGLE_CPT = NULL;
    5280  if ((N = get_argument (argc, argv, "-cpt"))) {
     
    118146  }
    119147
    120   if (argc != 2) usage_setastrom();
     148  if (!KH_FILE && !DCR_FILE) {
     149    fprintf (stderr, "at least one of -KH and -DCR must be supplied\n");
     150    exit (1);
     151  }
     152
     153  if (argc != 1) usage_setastrom();
    121154
    122155  return (TRUE);
     
    124157
    125158void usage_setastrom_client () {
    126   fprintf (stderr, "USAGE: setastrom_client (correction) -hostID (hostID) -catdir (catdir) -hostdir (hostdir) [options]\n");
     159  fprintf (stderr, "USAGE: setastrom_client -hostID (hostID) -catdir (catdir) -hostdir (hostdir) [options]\n");
    127160  fprintf (stderr, "  options:\n");
     161  fprintf (stderr, "    -DCR (file) : supply DCR correction splines\n");
     162  fprintf (stderr, "    -KH (file) : supply Koppenhoefer correction splines\n");
    128163  fprintf (stderr, "    -region Rmin Rmax Dmin Dmax\n");
    129164  fprintf (stderr, "    -update-catformat (format) : change database schema on output\n");
     
    163198
    164199  int N;
     200
     201  KH_FILE = NULL;
     202  if ((N = get_argument (argc, argv, "-KH"))) {
     203    remove_argument (N, &argc, argv);
     204    KH_FILE = strcreate (argv[N]);
     205    remove_argument (N, &argc, argv);
     206  }
     207  KH_RESET = FALSE;
     208  if ((N = get_argument (argc, argv, "-KH-reset"))) {
     209    remove_argument (N, &argc, argv);
     210    KH_RESET = TRUE;
     211  }
     212
     213  DCR_FILE = NULL;
     214  if ((N = get_argument (argc, argv, "-DCR"))) {
     215    remove_argument (N, &argc, argv);
     216    DCR_FILE = strcreate (argv[N]);
     217    remove_argument (N, &argc, argv);
     218  }
     219  DCR_RESET = FALSE;
     220  if ((N = get_argument (argc, argv, "-DCR-reset"))) {
     221    remove_argument (N, &argc, argv);
     222    DCR_RESET = TRUE;
     223  }
    165224
    166225  /* specify portion of the sky : allow default of all sky? */
     
    223282  if (!CATDIR) usage_setastrom_client();
    224283
    225   if (argc != 2) usage_setastrom_client();
     284  if (!KH_FILE && !DCR_FILE) {
     285    fprintf (stderr, "at least one of -KH and -DCR must be supplied\n");
     286    exit (1);
     287  }
     288
     289  if (argc != 1) usage_setastrom_client();
    226290  return (TRUE);
    227291}
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/uniphot/src/load_zpt_table.c

    r33654 r37822  
    173173      mjdstart = tstart_uc[i];
    174174      mjdstop  = tstop_uc[i];
    175   } else {
     175    } else {
    176176      char name[9];
    177       snprintf (name, 9, "TS0_%04d", i);
     177      // snprintf (name, 9, "TS0_%04d", i);
     178      snprintf (name, 9, "S0_MJD%d", i);
    178179      if (!gfits_scan (&header, name, "%lf", 1, &mjdstart)) {
    179180        fprintf (stderr, "cannot find %s in header of %s\n", name, filename);
     
    182183      }
    183184
    184       snprintf (name, 9, "TS1_%04d", i);
     185      // snprintf (name, 9, "TS1_%04d", i);
     186      snprintf (name, 9, "S1_MJD%d", i);
    185187      if (!gfits_scan (&header, name, "%lf", 1, &mjdstop)) {
    186188        fprintf (stderr, "cannot find %s in header of %s\n", name, filename);
     
    189191      }
    190192    }
    191     flatcorrTable->tstart[i] = ohana_mjd_to_sec(mjdstart);
    192     flatcorrTable->tstop[i]  = ohana_mjd_to_sec(mjdstop);
     193    flatcorrTable->tstart[i] = (mjdstart > 0) ? ohana_mjd_to_sec(mjdstart) : ohana_mjd_to_sec(50000.0); // 1995/10/10 (ancient history)
     194    flatcorrTable->tstop[i]  = (mjdstop  > 0) ? ohana_mjd_to_sec(mjdstop)  : ohana_mjd_to_sec(60000.0); // 2023/02/25 (infinite future)
    193195  }
    194196
     
    247249    } else {
    248250      if (!gfits_scan (&header, "FILTER", "%s", 1, filter)) {
    249         fprintf (stderr, "cannot find FILTER in header of %s\n", filename);
    250         fclose (f);
    251         return NULL;
     251        fprintf (stderr, "cannot find FILTER in header of %s, using %s\n", filename, filters_uc[nfilter]);
     252        strcpy (filter, filters_uc[nfilter]);
     253        // fclose (f);
     254        // return NULL;
    252255      }
    253256    }
     
    278281      REALLOCATE (offset64, double, matrix.Naxis[0]);
    279282      matrix.buffer = (char *) offset64;
     283    }
     284    if (matrix.Naxes == 1) {
     285      int Ntotal = NSEASON*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y;
     286      if (matrix.Naxis[0] != Ntotal) {
     287        int Nextra = Ntotal - matrix.Naxis[0];
     288        assert (Nextra >= 0);
     289        fprintf (stderr, "warning: images are not fully populated, extending by %d\n", Nextra);
     290       
     291        REALLOCATE (offset64, double, Ntotal);
     292        int npix;
     293        for (npix = matrix.Naxis[0]; npix < Ntotal; npix ++) offset64[npix] = 0.0;
     294
     295        matrix.Naxis[0] = Ntotal;
     296        matrix.buffer = (char *) offset64;
     297      }
    280298    }
    281299
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/uniphot/src/match_zpts_to_images.c

    r35764 r37822  
    9797    }
    9898
     99    // if secz is crazy, do not trust ubercal; skip and move along
     100    if (image[Ni].secz < 0.1) {
     101      i++;
     102      continue;
     103    }
     104
    99105    // we have a match: set zpt and record the match
    100106    // is the zero point supplied nominally corrected or not?
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/uniphot/src/update_catalog_setastrom.c

    r37043 r37822  
    11# include "setastrom.h"
     2
     3// this code does both DCR and KH corrections, if both are specified. 
    24
    35// XXX this function is dependent in two ways on the specific numerical values of the photcodes
     
    79int update_catalog_setastrom (Catalog *catalog) {
    810
    9   off_t i, found;
     11  off_t i;
    1012
    1113  time_t timeRef = ohana_date_to_sec("2011/05/11,00:00:00");
    1214
    13   found = 0;
     15  int Nsecfilt = GetPhotcodeNsecfilt ();
     16  PhotCode *code_g = GetPhotcodebyName ("g");
     17  PhotCode *code_i = GetPhotcodebyName ("i");
     18  PhotCode *code_z = GetPhotcodebyName ("z");
     19  PhotCode *code_y = GetPhotcodebyName ("y");
     20
     21  int Nsec_g = GetPhotcodeNsec(code_g->code);
     22  int Nsec_i = GetPhotcodeNsec(code_i->code);
     23  int Nsec_z = GetPhotcodeNsec(code_z->code);
     24  int Nsec_y = GetPhotcodeNsec(code_y->code);
     25
     26  off_t found = 0;
    1427
    1528  for (i = 0; i < catalog[0].Nmeasure; i++) {
     
    1730    Measure *measure = &catalog[0].measure[i];
    1831
    19     // XXX only do GPC1 data for now
     32    // only do GPC1 data for now (true for both DCR and KH)
    2033    if (measure[0].photcode < 10000) continue;
    2134    if (measure[0].photcode > 10600) continue;
    2235     
    23     // XXX hardwire the list of chips to correct
     36    int averef = measure->averef;
     37    Average *average = &catalog[0].average[averef];
     38    SecFilt *secfilt = &catalog[0].secfilt[averef*Nsecfilt];
     39
     40    int chipID = measure[0].photcode % 100;
     41
     42    // XXX hardwire the list of chips to KH correct
    2443    // some notes:
    25     // XY24 surpisingly does not need correction
     44    // XY24 surprisingly does not need correction
    2645    // XY27 has poor astrometry with a weird correction for all mags
    27     // XY36 surpisingly does not need correction
     46    // XY36 surprisingly does not need correction
    2847    // XY67 has poor astrometry with a weird correction for all mags
    2948
    30     int chipID = measure[0].photcode % 100;
     49    int doKH = FALSE;
    3150    switch (chipID) {
    3251      case 4:
     
    5776      case 72:
    5877      case 73:
     78        doKH = TRUE;
    5979        break;
    6080      default:
    61         measure[0].Xfix = measure[0].Xccd;
    62         measure[0].Yfix = measure[0].Yccd;
    63         continue;
    64     }
    65 
    66     double Xccd = measure[0].Xccd;
    67     double Yccd = measure[0].Yccd;
     81        break;
     82    }
     83
    6884    double pltScale = fabs(measure[0].pltscale);
    69 
    70     // this is not needed, is it?
    71     // double posAngle = FromShortDegrees(measure[0].posangle);
    72 
    73     // I need to know which chip we have.  use photcode assuming range
    74     int chip = measure[0].photcode % 100;
    75 
    76     // correction may be Minst or Minst + 5.0*log(fwhm
    77     float fwhm_maj = FromShortPixels(measure[0].FWx);
    78     float Minst = PhotInst (measure, MAG_CLASS_PSF);
    79     float MinstSB = Minst + 5.0*log10(fwhm_maj);
    80 
    81     // I should validate that the spline I'm using is SB corrected not Minst...
    82 
    83     // XXX this is very ad hoc.  the splines are measured based on an extraction from dvo
    84     // the dvo values of fwhm_maj are sigmas (NOT FWHM!) in pixels. 
     85    double posAngle = FromShortDegrees(measure[0].posangle);
     86
     87    /**** KH section ****/
     88
     89    double dX_KH = 0.0;
     90    double dY_KH = 0.0;
     91    if (KH_FILE && doKH && (measure[0].t < timeRef)) {
     92
     93      // correction may be Minst or Minst + 5.0*log(fwhm
     94      float fwhm_maj = FromShortPixels(measure[0].FWx);
     95      float Minst = PhotInst (measure, MAG_CLASS_PSF);
     96      // float MinstSB = Minst + 5.0*log10(fwhm_maj);
     97
     98      // NOTE: the spline correction was measured on the nightly-science database using measurements
     99      // from the period in which fwhm_maj & fwhm_min were a factor of sqrt(2) too small.  I am making
     100      // this correction here (but ideally I would re-measure the KH trend from PV2 data and re-generate
     101      // the splines
     102      float MinstSB = Minst + 5.0*log10(M_SQRT2*fwhm_maj);
     103
     104      // I should validate that the spline I'm using is SB corrected not Minst..
     105      // NOTE: it is SB, not raw Minst
     106
     107      // XXX this is very ad hoc.  the splines are measured based on an extraction from dvo
     108      // the dvo values of fwhm_maj are sigmas (NOT FWHM!) in pixels. 
    85109   
    86     // saturate fwhm_maj in the range 1.0 < fwhm_maj < 5.0
    87     // (images with really odd psf probably have poor astrometry anyway...)
    88     fwhm_maj = MIN(fwhm_maj,5.0);
    89     fwhm_maj = MAX(fwhm_maj,1.0);
    90 
    91     double dX;
    92     double dY;
    93 
    94     // correction is in arcseconds
    95     if (measure[0].t < timeRef) {
    96       get_astrom_correction (0, chip, &dX, &dY, MinstSB);
    97     } else {
    98       // XXX do not correct new data
    99       // get_astrom_correction (1, chip, &dX, &dY, MinstSB);
    100       dX = 0.0;
    101       dY = 0.0;
    102     }
     110      // saturate fwhm_maj in the range 1.0 < fwhm_maj < 5.0
     111      // (images with really odd psf probably have poor astrometry anyway...)
     112      fwhm_maj = MIN(fwhm_maj,5.0);
     113      fwhm_maj = MAX(fwhm_maj,1.0);
     114
     115      // correction is in arcseconds
     116      get_kh_correction (0, chipID, &dX_KH, &dY_KH, MinstSB);
     117    }
     118
     119    /**** DCR section ****/
     120
     121    double dX_DCR = 0.0;
     122    double dY_DCR = 0.0;
     123    if (DCR_FILE) {
     124
     125      // check if the color*airmass term is not-nan (Skip otherwise)
     126
     127      // XXX hard-wire gpc1 photcodes for now:
     128      // I should use photcode ops: PhotCode *code = PhotCodeByCode(measure->photcode)
     129      // int equiv = code->equiv
     130      // Nsec = GetNsec(equiv)
     131
     132      float dColor = 0.0;
     133      int filtCode = (int)(measure->photcode / 100); // eg, 101 = r
     134      switch (filtCode) {
     135        case 100:
     136        case 101:
     137        case 102: {
     138          float gmag = secfilt[Nsec_g].M;
     139          float imag = secfilt[Nsec_i].M;
     140          dColor = average->refColorBlue - (gmag - imag);
     141          break;
     142        }
     143        case 103:
     144        case 104: {
     145          float zmag = secfilt[Nsec_z].M;
     146          float ymag = secfilt[Nsec_y].M;
     147          dColor = average->refColorRed - (zmag - ymag);
     148          break;
     149        }
     150      }
     151      int filtSeq = filtCode % 100;
     152      if (!isfinite(dColor)) goto skip_DCR;
     153
     154      // I need to get the parallactic angle, but I only have alt & az, s:o
     155   
     156      // airmass = 1.0 / cos(90 - alt)
     157      // cos(90 - alt) = cos(zd) = sin(alt) = 1.0 / airmass
     158      // airmass = 1.0 / sin(alt)
     159
     160      // airmass = 1.0 / cos(zd)
     161      // cos(zd) = 1.0 / airmass == sn_alt
     162      // sin(zd) = sqrt(1.0 - cos(zd)^2) == cs_alt
     163      // tan(zd) = sin(zd) / cos(zd) = cs_alt / sn_alt
     164
     165      double sn_alt = 1.0 / measure->airmass;
     166      double cs_alt = sqrt(1.0 - SQ(sn_alt));
     167      double tan_zd = cs_alt / sn_alt;
     168
     169      double cs_az  = cos(RAD_DEG*measure->az);
     170      double sn_az  = sin(RAD_DEG*measure->az);
     171
     172# define LATITUDE (20.7070999146*RAD_DEG)
     173      double sn_lat = sin(LATITUDE);
     174      double cs_lat = cos(LATITUDE);
     175
     176      // double sind = sn_alt * sn_lat + cs_alt * cs_az * cs_lat;
     177      // *dec  = DEG_RAD * asin (sind);
     178
     179      // WARNING: these are NOT sin(ha),cos(ha) but are scaled
     180      // double ha = DEG_RAD * atan2 (sinh, cosh);
     181      double sinh = -cs_alt * sn_az;
     182      double cosh =  sn_alt * cs_lat - cs_alt * cs_az * sn_lat;
     183      double r_ha = hypot(sinh, cosh);
     184      double sn_ha = sinh / r_ha;
     185      double cs_ha = cosh / r_ha;
     186
     187      sinh = -cs_az * sn_alt * sn_ha * sn_lat + sn_az * sn_alt * cs_ha - sn_ha * cs_alt * cs_lat;
     188      cosh = -sn_az          * sn_ha * sn_lat - cs_az          * cs_ha;
     189      double r_rot = hypot(sinh, cosh);
     190
     191      double sn_rot = -sinh / r_rot;
     192      double cs_rot = +cosh / r_rot;
     193
     194      double dPx = 0.0;
     195      double dPy = 0.0;
     196
     197      float colorOffset = dColor * tan_zd;
     198      get_dcr_correction (filtSeq, &dPx, &dPy, colorOffset);
     199
     200      // if we had x-terms, we would have:
     201      // double dPx = dRx *cs_rot + dD_s*sn_rot;
     202      // double dPy = dD_s*cs_rot - dRx *sn_rot;
     203      // double dR = dPx*cs_rot - dPy*sn_rot;
     204      // double dD = dPx*sn_rot + dPy*cs_rot;
     205
     206      // since dPx = 0.0, instead we have: dPx, dPy as measured in dvo.dcr.sh
     207      double dR = -dPy*sn_rot;
     208      double dD = +dPy*cs_rot;
     209
     210      // dR = (measure->R - average->R) * 3600 * dcos(dec) [ie, in the projected plane]
     211      // dD = (measure->D - average->D) * 3600
     212      // average->D = measure->D - dD/3600
     213
     214      // now we need to rotate dR,dD into the chip frame and correction Xccd,Yccd
     215
     216      // are the plate-scale and posangle correctly set in the db?
     217
     218      // XXX the koppenhoefer code implies pos if angle from y -> D, (ie negative of the
     219      // below).  if so, apply sin(pos) -> -sin(pos)
     220
     221      // if parity = sky:
     222      // double dR =  dX*cos(pos) + dY*sin(pos);
     223      // double dD = -dX*sin(pos) + dY*cos(pos);
     224
     225      // XXX signs set here to reflect pos = -pos
     226      float posAngRad = posAngle * RAD_DEG;
     227      dX_DCR =  dR*cos(posAngRad) + dD*sin(posAngRad);
     228      dY_DCR = -dR*sin(posAngRad) + dD*cos(posAngRad);
     229    }
     230
     231  skip_DCR:
    103232
    104233    // do not modify the original Xccd,Yccd values
    105     measure[0].Xfix = Xccd + dX / pltScale;
    106     measure[0].Yfix = Yccd + dY / pltScale;
    107 
     234    if (KH_FILE) {
     235      measure[0].XoffKH = dX_KH / pltScale;
     236      measure[0].YoffKH = dY_KH / pltScale;
     237    }
     238    if (KH_RESET) {
     239      measure[0].XoffKH = 0.0;
     240      measure[0].YoffKH = 0.0;
     241    }
     242    if (DCR_FILE) {
     243      measure[0].XoffDCR = -dX_DCR / pltScale;
     244      measure[0].YoffDCR = -dY_DCR / pltScale;
     245    }
     246    if (DCR_RESET) {
     247      measure[0].XoffDCR = -dX_DCR / pltScale;
     248      measure[0].YoffDCR = -dY_DCR / pltScale;
     249    }
     250
     251    measure[0].Xfix = measure[0].Xccd;
     252    measure[0].Yfix = measure[0].Yccd;
     253    if (isfinite(measure[0].XoffKH) && isfinite(measure[0].YoffKH)) {
     254      measure[0].Xfix += measure[0].XoffKH;
     255      measure[0].Yfix += measure[0].YoffKH;
     256    }
     257    if (isfinite(measure[0].XoffDCR) && isfinite(measure[0].YoffDCR)) {
     258      measure[0].Xfix += measure[0].XoffDCR;
     259      measure[0].Yfix += measure[0].YoffDCR;
     260    }
    108261    found ++;
    109262  }
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/uniphot/src/update_dvo_setastrom.c

    r35103 r37822  
    11# include "setastrom.h"
    22
    3 int update_dvo_setastrom (char *corrfile) {
     3int update_dvo_setastrom () {
    44
    55  SkyTable *sky = NULL;
     
    1313 
    1414  if (PARALLEL && !HOST_ID) {
    15     int status = update_dvo_setastrom_parallel (sky, corrfile);
     15    int status = update_dvo_setastrom_parallel (sky);
    1616    return status;
    1717  }
    1818
    19   load_astrom_correction (corrfile);
     19  if (KH_FILE)  load_kh_correction (KH_FILE);
     20  if (DCR_FILE) load_dcr_correction (DCR_FILE);
    2021
    2122  // determine the populated SkyRegions overlapping the requested area (default depth)
     
    7879# define DEBUG 1
    7980
    80 int update_dvo_setastrom_parallel (SkyTable *sky, char *corrfile) {
     81int update_dvo_setastrom_parallel (SkyTable *sky) {
    8182
    8283  // now launch the setastrom_client jobs to the parallel hosts
    83 
    84   char *abscorrfile = abspath (corrfile, DVO_MAX_PATH);
    8584
    8685  // load the list of hosts
     
    9695
    9796    char command[1024];
    98     snprintf (command, 1024, "setastrom_client %s -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
    99               abscorrfile, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname,
     97    snprintf (command, 1024, "setastrom_client -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
     98              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname,
    10099              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    101 
    102     fprintf (stderr, "command: %s\n", command);
    103100
    104101    char tmpline[1024];
    105102    if (VERBOSE)          { snprintf (tmpline, 1024, "%s -v",                   command);                   strcpy (command, tmpline); }
    106103    if (UPDATE)           { snprintf (tmpline, 1024, "%s -update",              command);                   strcpy (command, tmpline); }
     104    if (KH_FILE)          { snprintf (tmpline, 1024, "%s -KH %s",               command, KH_FILE);          strcpy (command, tmpline); }
     105    if (DCR_FILE)         { snprintf (tmpline, 1024, "%s -DCR %s",              command, DCR_FILE);         strcpy (command, tmpline); }
    107106    if (UPDATE_CATFORMAT) { snprintf (tmpline, 1024, "%s -update-catformat %s", command, UPDATE_CATFORMAT); strcpy (command, tmpline); }
     107
     108    if (KH_RESET)         { snprintf (tmpline, 1024, "%s -KH-reset",            command);                   strcpy (command, tmpline); }
     109    if (DCR_RESET)        { snprintf (tmpline, 1024, "%s -DCR-reset",           command);                   strcpy (command, tmpline); }
     110
     111    fprintf (stderr, "command: %s\n", command);
    108112
    109113    if (PARALLEL_MANUAL) continue;
     
    126130    }
    127131  }
    128   free (abscorrfile);
    129132
    130133  // wait for the remote jobs to be completed
  • branches/eam_branches/ipp-pv3-20140717-merge/Ohana/src/uniphot/src/update_dvo_uniphot.c

    r36481 r37822  
    5757  glob (line, 0, NULL, &pglob);
    5858
    59   coords.crpix1 = coords.crpix2 = 0.0;
    60   coords.cdelt1 = coords.cdelt2 = 1.0; /* scale is degrees, radius in degrees */
    61   coords.pc1_1 = coords.pc2_2 = 1.0;
    62   coords.pc1_2 = coords.pc2_1 = 0.0;
    63   strcpy (coords.ctype, "DEC--TAN");
     59  InitCoords (&coords, "DEC--TAN");
    6460 
    6561  for (i = 0; i < pglob.gl_pathc; i++) {
Note: See TracChangeset for help on using the changeset viewer.