IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 11, 2015, 2:14:39 PM (12 years ago)
Author:
eugene
Message:

merge changes from eam branch ipp-20140904

Location:
trunk/Ohana
Files:
48 edited
7 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/libdvo/Makefile

    r37729 r37807  
    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 \
     
    5051$(SRC)/version.$(ARCH).o         \
    5152$(SRC)/coordops.$(ARCH).o        \
     53$(SRC)/galaxy_model.$(ARCH).o    \
    5254$(SRC)/dvosorts.$(ARCH).o        \
    5355$(SRC)/dvo_photcode_ops.$(ARCH).o \
     
    8486$(SRC)/dvo_convert_PS1_V5.$(ARCH).o \
    8587$(SRC)/dvo_convert_PS1_REF.$(ARCH).o \
     88$(SRC)/dvo_convert_PS1_SIM.$(ARCH).o \
    8689$(SRC)/flatcorr_io.$(ARCH).o    \
    8790$(SRC)/skyregion_io.$(ARCH).o    \
    8891$(SRC)/skyregion_gsc.$(ARCH).o    \
    8992$(SRC)/skyregion_ops.$(ARCH).o \
     93$(SRC)/AstromOffsetMapIO.$(ARCH).o    \
     94$(SRC)/AstromOffsetMapOps.$(ARCH).o \
     95$(SRC)/AstromOffsetMapUtils.$(ARCH).o \
    9096$(SRC)/dvo_set_skyregion.$(ARCH).o \
    9197$(SRC)/dvo_set_catdir.$(ARCH).o \
  • trunk/Ohana/src/libdvo/include/dvo.h

    r37729 r37807  
    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
     
    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 {
     
    314306  Image *image;
    315307  off_t *imseq;
     308
     309  AstromOffsetTable *astromTable;
    316310
    317311  int *neighbors;             // list of neighbor index values
     
    444438  double         R;
    445439  double         D;
     440  float          RoffGAL;
     441  float          DoffGAL;
    446442  float          M;
    447443  float          Mcal;
     
    645641  int              lensobjOffset;        // offset to mean lensing data
    646642  int              extendOffset;         // offset to extended object entry
    647   int              paramsOffset;         // offset to stellar parameter data
     643  int              starparOffset;        // offset to stellar parameter data
    648644  float            refColorBlue;         // color of astrometry ref stars
    649645  float            refColorRed;          // color of astrometry ref stars
     
    679675  Lensing *lensing;
    680676  Lensobj *lensobj;
     677  StarPar *starpar;
    681678
    682679  int Nsecfilt;  /* number of secfilt entries for each average entry */
    683   off_t Naverage,   Nmeasure,   Nmissing,   Nlensing,      Nlensobj,      Nsecf_mem;  /* current number of each component in memory */
    684   off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nlensing_disk, Nlensobj_disk, Nsecf_disk; /* current number of each component on disk */
    685   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 */
    686683
    687684  // note that we use these for the full-sky relphot analysis
     
    704701  struct Catalog *lensing_catalog;              /* lensing catalog data (split) */
    705702  struct Catalog *lensobj_catalog;              /* lensobj catalog data (split) */
     703  struct Catalog *starpar_catalog;              /* starpar catalog data (split) */
    706704
    707705  unsigned int objID;
     
    739737int   gfits_db_close               PROTO((FITS_DB *db));
    740738int   gfits_db_free                PROTO((FITS_DB *db));
    741 
    742 /* in coords.c, using libautocode/def/coords.d */
    743 int  XY_to_LM (double *L, double *M, double x,  double y,   Coords *coords);
    744 int  LM_to_XY (double *x,  double *y,   double L, double M, Coords *coords);
    745 int  RD_to_LM (double *L, double *M, double ra,  double dec,   Coords *coords);
    746 int  LM_to_RD (double *ra, double *dec,   double L, double M, Coords *coords);
    747 int  XY_to_RD (double *ra, double *dec, double x,  double y,   Coords *coords);
    748 int  RD_to_XY (double *x,  double *y,   double ra, double dec, Coords *coords);
    749 int  fXY_to_RD (float *ra, float *dec, double x,  double y,   Coords *coords);
    750 int  fRD_to_XY (float *x,  float *y,   double ra, double dec, Coords *coords);
    751 int  GetCoords (Coords *coords, Header *header);
    752 int  PutCoords (Coords *coords, Header *header);
    753 void RegisterMosaic (Coords *coords);
    754 void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
    755 OhanaProjection GetProjection (char *ctype);
    756 int SetProjection (char *ctype, OhanaProjection proj);
    757 OhanaProjectionMode GetProjectionMode (OhanaProjection proj);
    758739
    759740char *libdvo_version (void);
     
    913894Lensing *FtableToLensing (FTable *ftable, off_t *Nlensing, char *format);
    914895Lensobj *FtableToLensobj (FTable *ftable, off_t *Nlensobj, char *format);
     896StarPar *FtableToStarPar (FTable *ftable, off_t *Nstarpar, char *format);
    915897int      FtableToImage   (FTable *ftable, Header *theader, char *format);
    916898
     
    920902int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, char format);
    921903int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, char format);
     904int StarParToFtable (FTable *ftable, StarPar *starpar, off_t Nstarpar, char format);
    922905int ImageToFtable (FTable *ftable, Header *theader, char format);
    923906int ImageToVtable (VTable *vtable, Header *theader, char format);
     
    936919# include "ps1_v5_defs.h"
    937920# include "ps1_ref_defs.h"
     921# include "ps1_sim_defs.h"
    938922
    939923/*** DVO image db I/O Functions ***/
     
    950934void dvo_image_create (FITS_DB *db, double ZeroPoint);
    951935
     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
    952940/* flatcorr APIs */
    953941FlatCorrectionTable *FlatCorrectionLoad (char *filename, int VERBOSE);
     
    963951SkyTable  *SkyTableLoadOptimal     PROTO((char *catdir, char *SKYFILE, char *GSCFILE, int readwrite, int depth, int VERBOSE));
    964952int        SkyTableSetDepth        PROTO((SkyTable *sky, int depth));
     953SkyList   *SkyRegionByIndex        PROTO((SkyTable *table, int index));
    965954SkyList   *SkyRegionByCPT          PROTO((SkyTable *table, char *filename));
    966955SkyList   *SkyRegionByPoint        PROTO((SkyTable *table, int depth, double ra, double dec));
     
    1009998int HostTableTestHost (SkyRegion *region, int hostID);
    1010999
     1000void InitHost (HostInfo *host);
     1001
     1002HostTableGroup *HostTableGroups (HostTable *table, int *ngroups);
     1003int HostTableGroupWaitJobsGetIO (HostTableGroup *table, char *file, int lineno, int VERBOSE);
     1004
    10111005// functions to support tiny versions of Average and Measure
    10121006void CopyAverageToTiny (AverageTiny *averageT, Average *average);
     
    10421036void dvo_lensing_init (Lensing *lensing);
    10431037void dvo_lensobj_init (Lensobj *lensobj, int toZero);
     1038void dvo_starpar_init (StarPar *starpar);
    10441039
    10451040void InitRegionHosts (RegionHostInfo *hosts, int Nhosts, int NHOSTS);
     
    10511046int RegionHostFindNeighbors (RegionHostTable *table, int Nhost);
    10521047
     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
    10531085# endif // DVO_H
  • trunk/Ohana/src/libdvo/include/dvodb.h

    r37116 r37807  
    5555  MAG_OPTION_UC_DIST,
    5656  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,
    5791} dvoMagOptionType;
    5892
     
    139173      MEAS_XFIX,
    140174      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,
    141181      MEAS_POS_SYS_ERR,
    142182      MEAS_XFIELD,
     
    162202      MEAS_FLAT,
    163203      MEAS_CENTER_OFFSET,
    164       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
    165238};
    166239
     
    200273      AVE_EXTID_HI,
    201274      AVE_EXTID_LO,
    202       AVE_REF_COLOR,
     275      AVE_REF_COLOR_BLUE,
     276      AVE_REF_COLOR_RED,
    203277      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
    204290};
    205291
     
    276362      IMAGE_NLINK_PHOTOM,
    277363      IMAGE_NLINK_ASTROM,
    278       IMAGE_REF_COLOR
     364      IMAGE_REF_COLOR_BLUE,
     365      IMAGE_REF_COLOR_RED
    279366};
    280367
     
    368455int          ParseImageField        PROTO((dbField *field, char *fieldName));
    369456
    370 dbValue      dbExtractAverages      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
    371 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));
    372459dbValue      dbExtractImages        PROTO((Image *image, off_t Nimage, off_t N, dbField *field));
    373460
     
    376463int          dbAstroRegionLimits    PROTO((dbStack **stack, int *nstack, SkyRegionSelection *selection, int table));
    377464char        *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);
    378470
    379471void FreeImageSelection (void);
  • trunk/Ohana/src/libdvo/include/libdvo_astro.h

    r31635 r37807  
    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
  • trunk/Ohana/src/libdvo/include/ps1_v5_defs.h

    r37035 r37807  
    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);
  • trunk/Ohana/src/libdvo/src/BoundaryTree.c

    r37116 r37807  
    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
  • trunk/Ohana/src/libdvo/src/HostTable.c

    r35848 r37807  
    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
  • trunk/Ohana/src/libdvo/src/ImageMetadata.c

    r37035 r37807  
    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;
  • trunk/Ohana/src/libdvo/src/ImageMetadataSelection.c

    r36490 r37807  
    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);
  • trunk/Ohana/src/libdvo/src/ImageOps.c

    r34088 r37807  
    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;
  • trunk/Ohana/src/libdvo/src/ImageSelection.c

    r36490 r37807  
    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}
  • trunk/Ohana/src/libdvo/src/LoadImages.c

    r33649 r37807  
    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
  • trunk/Ohana/src/libdvo/src/RegionHostTable.c

    r36630 r37807  
    3131    hosts[i].Nneighbors = 0;
    3232    hosts[i].isNeighbor = FALSE;
     33
     34    hosts[i].astromTable = NULL;
    3335  }
    3436  return;
  • trunk/Ohana/src/libdvo/src/coord_systems.c

    r31635 r37807  
    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
  • trunk/Ohana/src/libdvo/src/coordops.c

    r37412 r37807  
    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;
     
    619704    }
    620705  }
    621 
     706 
    622707  if (!status) {
    623708    // fprintf (stderr, "error getting all elements for coordinate mode %s\n", coords[0].ctype);
  • trunk/Ohana/src/libdvo/src/dbExtractAverages.c

    r37116 r37807  
    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
     
    306309          value.Flt = PhotUCdist (field->photcode, average, secfilt);
    307310          break;
    308         // XX case MAG_OPTION_STACK_DET_ID:
    309         // XX   value.Int = PhotStackID (field->photcode, average, secfilt);
    310         // XX   break;
    311311        case MAG_OPTION_FLAGS: {
    312312          int Nsec = GetPhotcodeNsec (field->photcode->code);
     
    315315          break;
    316316        }
     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
    317343        case MAG_OPTION_NONE:
    318344          break;
    319       }
    320       break;
     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; }
    321363
    322364    case AVE_TYPE:
     
    324366    case AVE_TYPEFRAC:
    325367      break;
     368
     369
    326370  }
    327371  return (value);
  • trunk/Ohana/src/libdvo/src/dbExtractImages.c

    r37035 r37807  
    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  }
  • trunk/Ohana/src/libdvo/src/dbExtractMeasures.c

    r37246 r37807  
    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;
     
    249249        case MAG_OPTION_UC_DIST:
    250250        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
    251280        case MAG_OPTION_NONE:
    252281          break;
     
    474503      break;
    475504
    476     case MEAS_REF_COLOR:
     505    case MEAS_REF_COLOR_BLUE:
    477506      value.Flt = average[0].refColorBlue;
     507      break;
     508    case MEAS_REF_COLOR_RED:
     509      value.Flt = average[0].refColorRed;
    478510      break;
    479511
     
    528560# endif
    529561      break;
    530     case MEAS_XFIX: /* OK */
    531       value.Flt = measure[0].Xfix;
    532       break;
    533     case MEAS_YFIX: /* OK */
    534       value.Flt = measure[0].Yfix;
    535       break;
    536     case MEAS_XCCD_ERR: /* OK */
    537       value.Flt = FromShortPixels(measure[0].dXccd);
    538       break;
    539     case MEAS_YCCD_ERR: /* OK */
    540       value.Flt = FromShortPixels(measure[0].dYccd);
    541       break;
    542     case MEAS_POS_SYS_ERR: /* OK */
    543       value.Flt = FromShortPixels(measure[0].dRsys);
    544       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; }
    545574
    546575    case MEAS_XFIELD: /* offset relative to exposure center in ra,dec space */
     
    581610    case MEAS_XMOSAIC: /* offset relative to exposure center in camera coords */
    582611      if (!haveMosaicMeas) {
    583         if (REMOTE_CLIENT) {
    584           mosaic = MatchMosaicMetadata (measure[0].imageID);
    585         } else {
    586           // fprintf (stderr, "non-parallel Xmos broken\n");
    587           // abort();
    588           // mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
    589           mosaic = MatchMosaicMetadata (measure[0].imageID);
    590         }
     612        mosaic = MatchMosaicMetadata (measure[0].imageID);
    591613        if (mosaic == NULL) break;
    592614        double Rm = measure[0].R;
     
    598620    case MEAS_YMOSAIC: /* OK */
    599621      if (!haveMosaicMeas) {
    600         if (REMOTE_CLIENT) {
    601           mosaic = MatchMosaicMetadata (measure[0].imageID);
    602         } else {
    603           // fprintf (stderr, "non-parallel Xmos broken\n");
    604           // abort();
    605           // mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
    606           mosaic = MatchMosaicMetadata (measure[0].imageID);
    607         }
     622        mosaic = MatchMosaicMetadata (measure[0].imageID);
    608623        if (mosaic == NULL) break;
    609624        double Rm = measure[0].R;
     
    680695      break;
    681696
    682     case MEAS_MCAL_OFFSET: /* OK */
    683       value.Flt = measure[0].Mcal;
    684       break;
     697    case MEAS_MCAL_OFFSET: { value.Flt = measure[0].Mcal; break; }
    685698
    686699    case MEAS_FLAT: /* OK */
     
    717730      }
    718731      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; }
    719745
    720746    // case MEAS_FLUX_PSF: /* OK */
  • trunk/Ohana/src/libdvo/src/dbFields.c

    r37116 r37807  
    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, "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;
    81209
    82210  return MAG_OPTION_NONE;
    83211}
    84 
    85 # if (0)
    86 int GetMagMode (char *string) {
    87 
    88   // these all imply PSF mags:
    89   if (!strcasecmp (string, "inst"))        return (MAG_INST);
    90   if (!strcasecmp (string, "cat"))         return (MAG_CAT);
    91   if (!strcasecmp (string, "sys"))         return (MAG_SYS);
    92   if (!strcasecmp (string, "rel"))         return (MAG_REL);
    93   if (!strcasecmp (string, "cal"))         return (MAG_CAL);
    94   if (!strcasecmp (string, "ave"))         return (MAG_AVE);
    95   if (!strcasecmp (string, "ref"))         return (MAG_REF);
    96   if (!strcasecmp (string, "err"))         return (MAG_ERR);
    97   if (!strcasecmp (string, "aveerr"))      return (MAG_AVE_ERR);
    98 
    99   // these are explicit PSF mags:
    100   if (!strcasecmp (string, "psf_inst"))    return (MAG_INST);
    101   if (!strcasecmp (string, "psf_cat"))     return (MAG_CAT);
    102   if (!strcasecmp (string, "psf_sys"))     return (MAG_SYS);
    103   if (!strcasecmp (string, "psf_rel"))     return (MAG_REL);
    104   if (!strcasecmp (string, "psf_cal"))     return (MAG_CAL);
    105   if (!strcasecmp (string, "psf_ave"))     return (MAG_AVE);
    106   if (!strcasecmp (string, "psf_ref"))     return (MAG_REF);
    107   if (!strcasecmp (string, "psf_err"))     return (MAG_ERR);
    108   if (!strcasecmp (string, "psf_aveerr"))  return (MAG_AVE_ERR);
    109 
    110   // these are aper mags:
    111   if (!strcasecmp (string, "ap"))          return (MAG_APER);
    112   if (!strcasecmp (string, "aper"))        return (MAG_APER);
    113   if (!strcasecmp (string, "aperinst"))    return (MAG_APER_INST);
    114   if (!strcasecmp (string, "aper_inst"))   return (MAG_APER_INST);
    115   if (!strcasecmp (string, "aper_cat"))    return (MAG_APER_CAT);
    116   if (!strcasecmp (string, "aper_sys"))    return (MAG_APER_SYS);
    117   if (!strcasecmp (string, "aper_rel"))    return (MAG_APER_REL);
    118   if (!strcasecmp (string, "aper_cal"))    return (MAG_APER_CAL);
    119   if (!strcasecmp (string, "aper_ave"))    return (MAG_APER_AVE);
    120   if (!strcasecmp (string, "aper_ref"))    return (MAG_APER_REF);
    121   if (!strcasecmp (string, "aper_err"))    return (MAG_APER_ERR);
    122 
    123   // these are kron mags:
    124   if (!strcasecmp (string, "kron"))        return (MAG_KRON);
    125   if (!strcasecmp (string, "kron_inst"))   return (MAG_KRON_INST);
    126   if (!strcasecmp (string, "kron_cat"))    return (MAG_KRON_CAT);
    127   if (!strcasecmp (string, "kron_sys"))    return (MAG_KRON_SYS);
    128   if (!strcasecmp (string, "kron_rel"))    return (MAG_KRON_REL);
    129   if (!strcasecmp (string, "kron_cal"))    return (MAG_KRON_CAL);
    130   if (!strcasecmp (string, "kron_ave"))    return (MAG_KRON_AVE);
    131   if (!strcasecmp (string, "kron_ref"))    return (MAG_KRON_REF);
    132   if (!strcasecmp (string, "kron_err"))    return (MAG_KRON_ERR);
    133   if (!strcasecmp (string, "kroninst"))    return (MAG_KRON_INST);
    134   if (!strcasecmp (string, "kronerr"))     return (MAG_KRON_ERR);
    135 
    136   // other fields:
    137   if (!strcasecmp (string, "photflags"))   return (MAG_PHOT_FLAGS);
    138   if (!strcasecmp (string, "flags"))       return (MAG_PHOT_FLAGS);
    139   if (!strcasecmp (string, "chisq"))       return (MAG_CHISQ);
    140   if (!strcasecmp (string, "ncode"))       return (MAG_NCODE);
    141   if (!strcasecmp (string, "nphot"))       return (MAG_NPHOT);
    142   if (!strcasecmp (string, "stdev"))       return (MAG_STDEV);
    143   if (!strcasecmp (string, "min"))         return (MAG_MIN);
    144   if (!strcasecmp (string, "max"))         return (MAG_MAX);
    145   if (!strcasecmp (string, "ucdist"))      return (MAG_UC_DIST);
    146   if (!strcasecmp (string, "fluxpsf"))     return (MAG_FLUX_PSF);
    147   if (!strcasecmp (string, "fluxpsferr"))  return (MAG_FLUX_PSF_ERR);
    148   if (!strcasecmp (string, "fluxkron"))    return (MAG_FLUX_KRON);
    149   if (!strcasecmp (string, "fluxkronerr")) return (MAG_FLUX_KRON_ERR);
    150   return (MAG_NONE);
    151 }
    152 # endif
    153212
    154213// field may be of the form mag:psf:inst:wrp.  except for the first subword,
     
    285344    fprintf (stderr, "ERROR: unknown mag/photocode argument %s\n", word);
    286345    free (word);
     346    return FALSE;
    287347  }
    288348
     
    414474  if (!strcasecmp (fieldName, "XFIX"))           ESCAPE (MEAS_XFIX,           OPIHI_FLT);
    415475  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);
    416482  if (!strcasecmp (fieldName, "POS_SYS_ERR"))    ESCAPE (MEAS_POS_SYS_ERR,    OPIHI_FLT);
    417483  if (!strcasecmp (fieldName, "XFIELD"))         ESCAPE (MEAS_XFIELD,         OPIHI_FLT);
     
    441507  if (!strcasecmp (fieldName, "FLAT"))           ESCAPE (MEAS_FLAT,           OPIHI_FLT);
    442508  if (!strcasecmp (fieldName, "CENTER_OFFSET"))  ESCAPE (MEAS_CENTER_OFFSET,  OPIHI_FLT);
    443   // 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);
    444552  // if (!strcasecmp (fieldName, "FLUX_ERR"))       ESCAPE (MEAS_FLUX_PSF_ERR,   OPIHI_FLT);
    445553  // if (!strcasecmp (fieldName, "FLUX_PSF"))       ESCAPE (MEAS_FLUX_PSF,       OPIHI_FLT);
     
    447555  // if (!strcasecmp (fieldName, "FLUX_KRON"))      ESCAPE (MEAS_FLUX_KRON,      OPIHI_FLT);
    448556  // if (!strcasecmp (fieldName, "FLUX_KRON_ERR"))  ESCAPE (MEAS_FLUX_KRON_ERR,  OPIHI_FLT);
    449   if (!strcasecmp (fieldName, "REF_COLOR"))      ESCAPE (MEAS_REF_COLOR,      OPIHI_FLT);
     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);
    450559
    451560  // for words that don't parse, try a photcode
     
    522631  if (!strcasecmp (fieldName, "EXTID_HI"))    ESCAPE (AVE_EXTID_HI,    OPIHI_INT);
    523632  if (!strcasecmp (fieldName, "EXTID_LO"))    ESCAPE (AVE_EXTID_LO,    OPIHI_INT);
    524   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
    525649
    526650  // check for code:mode in photcode name
     
    652776  if (!strcasecmp (fieldName, "NLINK_PHOTOM")) ESCAPE (IMAGE_NLINK_PHOTOM, OPIHI_INT);
    653777  if (!strcasecmp (fieldName, "NLINK_ASTROM")) ESCAPE (IMAGE_NLINK_ASTROM, OPIHI_INT);
    654   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);
    655780
    656781  // for words that don't parse, try a photcode
  • trunk/Ohana/src/libdvo/src/dvo_catalog.c

    r37356 r37807  
    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;
     
    144146  average->skycellID       = 0;
    145147  average->projectionID    = 0;
     148
    146149  average->dummy           = 0;
    147150
     
    437440
    438441// 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
    439463void dvo_catalog_init (Catalog *catalog, int complete) {
    440464
     
    462486  catalog[0].lensobj = NULL;
    463487
     488  catalog[0].starpar = NULL;
     489
    464490  catalog[0].averageT = NULL;
    465491  catalog[0].measureT = NULL;
     
    477503  catalog[0].Nlensobj = 0;
    478504
     505  catalog[0].Nstarpar = 0;
     506
    479507  catalog[0].Naves_disk = 0;
    480508  catalog[0].Nmeas_disk = 0;
     
    485513  catalog[0].Nlensobj_disk = 0;
    486514
     515  catalog[0].Nstarpar_disk = 0;
     516
    487517  catalog[0].Naves_off  = 0;
    488518  catalog[0].Nmeas_off  = 0;
     
    492522  catalog[0].Nlensing_off  = 0;
    493523  catalog[0].Nlensobj_off  = 0;
     524
     525  catalog[0].Nstarpar_off  = 0;
    494526
    495527  /* pointers to SPLIT data files */
     
    499531  catalog[0].lensing_catalog = NULL;
    500532  catalog[0].lensobj_catalog = NULL;
     533  catalog[0].starpar_catalog = NULL;
    501534
    502535  /* pointers for data manipulation */
     
    540573
    541574  if (catalog[0].f == (FILE *) NULL) return (2);
    542   fflush (catalog[0].f);
     575
     576  if (fflush (catalog[0].f)) {
     577    fprintf (stderr, "failed to flush file\n");
     578    return FALSE;
     579  }
     580
    543581  // fprintf (stderr, "unlocking: %s\n", catalog[0].filename);
    544582
     
    552590
    553591  // closes f but does not set back to NULL
    554   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  }
    555596
    556597  if (catalog[0].catmode == DVO_MODE_SPLIT) {
    557     if (catalog[0].measure_catalog) dvo_catalog_unlock (catalog[0].measure_catalog);
    558     if (catalog[0].missing_catalog) dvo_catalog_unlock (catalog[0].missing_catalog);
    559     if (catalog[0].secfilt_catalog) dvo_catalog_unlock (catalog[0].secfilt_catalog);
    560     if (catalog[0].lensing_catalog) dvo_catalog_unlock (catalog[0].lensing_catalog);
    561     if (catalog[0].lensobj_catalog) dvo_catalog_unlock (catalog[0].lensobj_catalog);
     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); }}
    562604  }
    563605  return (1);
     
    597639  }
    598640 
     641  // NOTE: this only check if we can write a backup; it does not actually write the backup
    599642  if (!check_file_access (catalog[0].filename, BACKUP, READWRITE, VERBOSE)) {
    600643    fprintf (stderr, "no permission to access %s\n", catalog[0].filename);
     
    835878      free (catalog[0].lensobj_catalog);
    836879    }
     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    }
    837885  }
    838886  dvo_catalog_free_data (catalog);
     
    873921    catalog[0].Nlensobj = 0;
    874922    catalog[0].lensobj = NULL;
     923  }
     924  if (catalog[0].starpar) {
     925    free (catalog[0].starpar);
     926    catalog[0].Nstarpar = 0;
     927    catalog[0].starpar = NULL;
    875928  }
    876929  if (catalog[0].nOwn_t)      { free (catalog[0].nOwn_t); catalog[0].nOwn_t = NULL; }
     
    9851038      }
    9861039    }
     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    }
    9871050  }
    9881051  return TRUE;
     
    10361099      }
    10371100    }
     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    }
    10381106  }
    10391107  return TRUE;
  • trunk/Ohana/src/libdvo/src/dvo_catalog_create.c

    r37035 r37807  
    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:
  • trunk/Ohana/src/libdvo/src/dvo_catalog_mef.c

    r37035 r37807  
    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   
  • trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c

    r37035 r37807  
    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:
  • trunk/Ohana/src/libdvo/src/dvo_catalog_split.c

    r37035 r37807  
    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    }
  • trunk/Ohana/src/libdvo/src/dvo_convert.c

    r37246 r37807  
    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
     
    129130  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5",          PS1_V5,          PS1_V5);
    130131  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF,         PS1_REF);
     132  CONVERT_FORMAT ("DVO_AVERAGE_PS1_SIM",         PS1_SIM,         PS1_SIM);
    131133# undef CONVERT_FORMAT
    132134
     
    165167      FORMAT_CASE (PS1_V5,          PS1_V5);
    166168      FORMAT_CASE (PS1_REF,         PS1_REF);
     169      FORMAT_CASE (PS1_SIM,         PS1_SIM);
    167170# undef FORMAT_CASE
    168171
     
    240243  CONVERT_FORMAT ("DVO_MEASURE_PS1_V5",          PS1_V5,          PS1_V5,          TRUE);
    241244  CONVERT_FORMAT ("DVO_MEASURE_PS1_REF",         PS1_REF,         PS1_REF,         FALSE);
     245  CONVERT_FORMAT ("DVO_MEASURE_PS1_SIM",         PS1_SIM,         PS1_SIM,         TRUE);
    242246# undef CONVERT_FORMAT
    243247
     
    254258    case DVO_FORMAT_##FORMAT: { \
    255259      Measure_##TYPE *tmpMeasure; \
    256       myAssert (ABS_COORDS || average, "conversion to internal needs average table"); \
     260      myAssert (ABS_COORDS || average, "conversion from internal needs average table"); \
    257261      tmpMeasure = MeasureInternalTo_##TYPE (average, measure, Nmeasure); \
    258262      gfits_table_set_Measure_##TYPE (ftable, tmpMeasure, Nmeasure); \
     
    278282      FORMAT_CASE (PS1_V5,          PS1_V5,          TRUE);
    279283      FORMAT_CASE (PS1_REF,         PS1_REF,         FALSE);
     284      FORMAT_CASE (PS1_SIM,         PS1_SIM,         TRUE);
    280285# undef FORMAT_CASE
    281286
     
    350355  CONVERT_FORMAT ("DVO_SECFILT_PS1_V5",          PS1_V5,          PS1_V5);
    351356  CONVERT_FORMAT ("DVO_SECFILT_PS1_REF",         PS1_REF,         PS1_REF);
     357  CONVERT_FORMAT ("DVO_SECFILT_PS1_SIM",         PS1_SIM,         PS1_SIM);
    352358# undef CONVERT_FORMAT
    353359
     
    386392      FORMAT_CASE (PS1_V5,          PS1_V5);
    387393      FORMAT_CASE (PS1_REF,         PS1_REF);
     394      FORMAT_CASE (PS1_SIM,         PS1_SIM);
    388395# undef FORMAT_CASE
    389396
     
    407414    return (FALSE);
    408415  }
     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); }
    409428
    410429# define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     
    585604    default:
    586605      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");
    587704      return (FALSE);
    588705  }
     
    643760    return (TRUE); }
    644761
    645   if (!strcmp (extname, "DVO_IMAGE")) {
    646     Image *image;
    647     image = gfits_table_get_Image (ftable, &Nimage, NULL);
    648     if (!image) {
    649       fprintf (stderr, "ERROR: failed to read images\n");
    650       exit (2);
    651     }
    652     *format = DVO_FORMAT_INTERNAL;
    653     return (TRUE);
    654   }
    655 
    656762  CONVERT_FORMAT ("DVO_IMAGE_ELIXIR",          ELIXIR,          Elixir);
    657763  CONVERT_FORMAT ("DVO_IMAGE_LONEOS",          LONEOS,          Loneos);
     
    666772  CONVERT_FORMAT ("DVO_IMAGE_PS1_V5",          PS1_V5,          PS1_V5);
    667773  CONVERT_FORMAT ("DVO_IMAGE_PS1_REF",         PS1_REF,         PS1_REF);
     774  CONVERT_FORMAT ("DVO_IMAGE_PS1_SIM",         PS1_SIM,         PS1_SIM);
    668775
    669776# undef CONVERT_FORMAT
     
    690797  /* convert from the internal format */
    691798  switch (format) {
    692     case DVO_FORMAT_INTERNAL: {
    693       gfits_convert_Image ((Image *) ftable[0].buffer, sizeof(Image), Nimage);
    694       break; }
    695 
    696799      FORMAT_CASE (ELIXIR,          Elixir);
    697800      FORMAT_CASE (LONEOS,          Loneos);
     
    706809      FORMAT_CASE (PS1_V5,          PS1_V5);
    707810      FORMAT_CASE (PS1_REF,         PS1_REF);
     811      FORMAT_CASE (PS1_SIM,         PS1_SIM);
    708812
    709813# undef FORMAT_CASE
     
    744848  /* convert from the internal format */
    745849  switch (format) {
    746     case DVO_FORMAT_INTERNAL: {
    747       for (i = 0; i < Nrow; i++) {
    748         gfits_convert_Image ((Image *) vtable[0].buffer[i], sizeof(Image), 1);
    749       }
    750       return (TRUE); }
    751 
    752850      FORMAT_CASE (ELIXIR,          Elixir);
    753851      FORMAT_CASE (LONEOS,          Loneos);
     
    762860      FORMAT_CASE (PS1_V5,          PS1_V5);
    763861      FORMAT_CASE (PS1_REF,         PS1_REF);
     862      FORMAT_CASE (PS1_SIM,         PS1_SIM);
    764863
    765864# undef FORMAT_CASE
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c

    r37246 r37807  
    219219
    220220  for (i = 0; i < Nvalues; i++) {
    221     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;
    222225
    223226    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    287290
    288291  for (i = 0; i < Nvalues; i++) {
    289     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));
    290294
    291295    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c

    r37246 r37807  
    214214
    215215  for (i = 0; i < Nvalues; i++) {
    216     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;
    217220
    218221    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    279282
    280283  for (i = 0; i < Nvalues; i++) {
    281     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));
    282286
    283287    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c

    r37055 r37807  
    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
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c

    r37035 r37807  
    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
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c

    r37246 r37807  
    238238
    239239  for (i = 0; i < Nvalues; i++) {
    240     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;
    241244
    242245    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    302305
    303306  for (i = 0; i < Nvalues; i++) {
    304     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));
    305309
    306310    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c

    r37246 r37807  
    249249
    250250  for (i = 0; i < Nvalues; i++) {
    251     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;
    252255
    253256    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    313316
    314317  for (i = 0; i < Nvalues; i++) {
    315     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));
    316320
    317321    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c

    r37246 r37807  
    259259
    260260  for (i = 0; i < Nvalues; i++) {
    261     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;
    262265
    263266    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    323326
    324327  for (i = 0; i < Nvalues; i++) {
    325     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));
    326330
    327331    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c

    r37246 r37807  
    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
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c

    r37356 r37807  
    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;
     
    258259    out[i].Nlensing       = in[i].Nlensing;     
    259260    out[i].Nlensobj       = in[i].Nlensobj;     
     261    out[i].Nstarpar       = in[i].Nstarpar;     
    260262    out[i].Nextend        = in[i].Nextend;     
    261263                         
     
    264266    out[i].lensingOffset  = in[i].lensingOffset;
    265267    out[i].lensobjOffset  = in[i].lensobjOffset;
     268    out[i].starparOffset  = in[i].starparOffset;
    266269    out[i].extendOffset   = in[i].extendOffset;
    267     out[i].paramsOffset   = in[i].paramsOffset;
    268270                         
    269271    out[i].refColorBlue   = in[i].refColorBlue;
     
    663665}
    664666
     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
    665732# define RAW_IMAGE_NAME_LEN 117
    666733
     
    676743
    677744  for (i = 0; i < Nvalues; i++) {
    678     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;
    679749
    680750    // RAW_IMAGE_NAME_LEN == DVO_IMAGE_NAME_LEN
     
    741811
    742812  for (i = 0; i < Nvalues; i++) {
    743     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));
    744815
    745816    // RAW_IMAGE_NAME_LEN == DVO_IMAGE_NAME_LEN
     
    920991    out[i].lensingOffset  = in[i].lensingOffset;
    921992    out[i].lensobjOffset  = in[i].lensobjOffset;
     993    out[i].starparOffset  = in[i].starparOffset;
    922994    out[i].extendOffset   = in[i].extendOffset;
    923     out[i].paramsOffset   = in[i].paramsOffset;
    924995                         
    925996    out[i].refColorBlue   = in[i].refColorBlue;
     
    11941265
    11951266
     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
  • trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c

    r37035 r37807  
    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
  • trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c

    r37035 r37807  
    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
  • trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c

    r37035 r37807  
    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
  • trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c

    r37035 r37807  
    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
  • trunk/Ohana/src/libdvo/src/dvo_image.c

    r37035 r37807  
    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
  • trunk/Ohana/src/libdvo/src/dvo_image_raw.c

    r37035 r37807  
    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 */
  • trunk/Ohana/src/libdvo/src/dvo_photcode_ops.c

    r37116 r37807  
    17881788  m2 = (Ns2 == -1) ? average[0].M : secfilt[Ns2].M;
    17891789*/
     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);
  • trunk/Ohana/src/libdvo/src/dvo_tiny_values.c

    r37035 r37807  
    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;
  • trunk/Ohana/src/libdvo/src/dvo_util.c

    r33030 r37807  
    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    }
  • trunk/Ohana/src/libdvo/src/flatcorr_io.c

    r33963 r37807  
    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
  • trunk/Ohana/src/libdvo/src/mosaic_astrom.c

    r29938 r37807  
    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;
  • trunk/Ohana/src/libdvo/src/skyregion_gsc.c

    r34088 r37807  
    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);
  • trunk/Ohana/src/libdvo/src/skyregion_ops.c

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