Index: /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/Makefile.Targets
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/Makefile.Targets	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/Makefile.Targets	(revision 33397)
@@ -10,4 +10,5 @@
 $(ASRC)/average-ps1-v1.$(ARCH).o \
 $(ASRC)/average-ps1-v2.$(ARCH).o \
+$(ASRC)/average-ps1-v3.$(ARCH).o \
 $(ASRC)/average-ps1-ref.$(ARCH).o \
 $(ASRC)/secfilt.$(ARCH).o \
@@ -20,4 +21,5 @@
 $(ASRC)/secfilt-ps1-v1.$(ARCH).o \
 $(ASRC)/secfilt-ps1-v2.$(ARCH).o \
+$(ASRC)/secfilt-ps1-v3.$(ARCH).o \
 $(ASRC)/secfilt-ps1-ref.$(ARCH).o \
 $(ASRC)/measure.$(ARCH).o \
@@ -30,4 +32,5 @@
 $(ASRC)/measure-ps1-v1.$(ARCH).o \
 $(ASRC)/measure-ps1-v2.$(ARCH).o \
+$(ASRC)/measure-ps1-v3.$(ARCH).o \
 $(ASRC)/measure-ps1-ref.$(ARCH).o \
 $(ASRC)/missing.$(ARCH).o \
@@ -39,4 +42,5 @@
 $(ASRC)/photcode-ps1-v1.$(ARCH).o \
 $(ASRC)/photcode-ps1-v2.$(ARCH).o \
+$(ASRC)/photcode-ps1-v3.$(ARCH).o \
 $(ASRC)/photcode-ps1-ref.$(ARCH).o \
 $(ASRC)/image.$(ARCH).o \
@@ -50,4 +54,5 @@
 $(ASRC)/image-ps1-v1.$(ARCH).o \
 $(ASRC)/image-ps1-v2.$(ARCH).o \
+$(ASRC)/image-ps1-v3.$(ARCH).o \
 $(ASRC)/image-ps1-ref.$(ARCH).o \
 $(ASRC)/regimage.$(ARCH).o \
@@ -84,4 +89,5 @@
 $(AINC)/average-ps1-v1.h \
 $(AINC)/average-ps1-v2.h \
+$(AINC)/average-ps1-v3.h \
 $(AINC)/average-ps1-ref.h \
 $(AINC)/secfilt.h \
@@ -94,4 +100,5 @@
 $(AINC)/secfilt-ps1-v1.h \
 $(AINC)/secfilt-ps1-v2.h \
+$(AINC)/secfilt-ps1-v3.h \
 $(AINC)/secfilt-ps1-ref.h \
 $(AINC)/measure.h \
@@ -104,4 +111,5 @@
 $(AINC)/measure-ps1-v1.h \
 $(AINC)/measure-ps1-v2.h \
+$(AINC)/measure-ps1-v3.h \
 $(AINC)/measure-ps1-ref.h \
 $(AINC)/missing.h \
@@ -113,4 +121,5 @@
 $(AINC)/photcode-ps1-v1.h \
 $(AINC)/photcode-ps1-v2.h \
+$(AINC)/photcode-ps1-v3.h \
 $(AINC)/photcode-ps1-ref.h \
 $(AINC)/image.h \
@@ -124,4 +133,5 @@
 $(AINC)/image-ps1-v1.h \
 $(AINC)/image-ps1-v2.h \
+$(AINC)/image-ps1-v3.h \
 $(AINC)/image-ps1-ref.h \
 $(AINC)/regimage.h \
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/average-ps1-v2.d
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/average-ps1-v2.d	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/average-ps1-v2.d	(revision 33397)
@@ -9,6 +9,6 @@
 FIELD R,              RA,          double,          RA,                	       	  decimal degrees 
 FIELD D,              DEC,         double,          DEC,               	       	  decimal degrees 
-FIELD dR,             RA_ERR,      float,           RA error                      arcsec
-FIELD dD,             DEC_ERR,     float,           DEC error                     arcsec
+FIELD dR,             RA_ERR,      float,           RA error,                     arcsec
+FIELD dD,             DEC_ERR,     float,           DEC error,                    arcsec
 
 FIELD uR,             U_RA,        float,           RA*cos(D) proper-motion,      arcsec/year
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/average-ps1-v3.d
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/average-ps1-v3.d	(revision 33397)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/average-ps1-v3.d	(revision 33397)
@@ -0,0 +1,62 @@
+STRUCT       Average_PS1_V3
+EXTNAME      DVO_AVERAGE_PS1_V3
+TYPE         BINTABLE
+SIZE         120
+DESCRIPTION  DVO Average Object Table
+
+# elements of data structure / FITS table
+
+FIELD R,              RA,          double,          RA,                	       	  decimal degrees 
+FIELD D,              DEC,         double,          DEC,               	       	  decimal degrees 
+FIELD dR,             RA_ERR,      float,           RA error,                     arcsec
+FIELD dD,             DEC_ERR,     float,           DEC error,                    arcsec
+
+FIELD uR,             U_RA,        float,           RA*cos(D) proper-motion,      arcsec/year
+FIELD uD,             U_DEC,       float,           DEC proper-motion,            arcsec/year
+FIELD duR,            V_RA_ERR,    float,           RA*cos(D) p-m error,          arcsec/year
+FIELD duD,            V_DEC_ERR,   float,           DEC p-m error,                arcsec/year
+FIELD P,              PAR,         float,           parallax,			  arcsec
+FIELD dP,             PAR_ERR,     float,           parallax error,               arcsec
+
+FIELD ChiSqAve,       CHISQ_POS,   float,           astrometry analysis chisq
+FIELD ChiSqPM,        CHISQ_PM,    float,           astrometry analysis chisq
+FIELD ChiSqPar,       CHISQ_PAP,   float,           astrometry analysis chisq
+FIELD Tmean,          MEAN_EPOCH,  int,   	    mean epoch (PM,PAR ref),       unix time seconds
+FIELD Trange,         TIME_RANGE,  int,   	    mean epoch (PM,PAR ref),       unix time seconds
+
+FIELD Xp,             SIGMA_POS,   float, 	    position scatter,   	  1/100 arcsec
+FIELD Npos,           NUMBER_POS,  unsigned short,  number of detections used for astrometry
+
+# this limits us to a max of 64k measurements per object
+FIELD Nmeasure,       NMEASURE,    unsigned short,  number of psf measurements
+FIELD Nmissing,       NMISSING,    unsigned short,  number of missings
+FIELD Nextend,        NEXTEND,     unsigned short,  number of extended measurements
+
+FIELD measureOffset,  OFF_MEASURE, uint32_t,   	    offset to first psf measurement
+FIELD missingOffset,  OFF_MISSING, uint32_t,   	    offset to first missing obs
+FIELD extendOffset,   OFF_EXTEND,  uint32_t,   	    offset to first extended measurement
+
+# 'flags' was called 'code' prior to 2009.02.07
+FIELD flags,          FLAGS,       uint32_t,        average object flags (star; ghost; etc)
+FIELD photFlagsUpper, PHOTFLAGS_U, uint32_t,        upper bit of 2 bit summary of per-measure photflags
+FIELD photFlagsLower, PHOTFLAGS_L, uint32_t,        lower bit of 2 bit summary of per-measure photflags
+
+# objID + catID gives a unique ID for all objects in the database
+FIELD objID,          OBJ_ID,      unsigned int,    unique ID for object in table
+FIELD catID,          CAT_ID,      unsigned int,    unique ID for table in which object was first realized
+FIELD extID,          EXT_ID,      uint64_t,        external ID for object (eg PSPS objID)
+
+# 2*8 + 1*8 + 12*4 + 7*4 + 4*2
+
+# photflagsUpper & photflagsLower: we have Nmeasures of a given source
+# using psphot. each of these as a photFlag field, with bits
+# describing the detection quality.  photflagsUpper and photFlagsLower
+# represent a 2 bit value (0-3) which defines the frequency of a given
+# bit in the measurements:
+# for a given bit, if that bit is raised for these percentile ranges,
+# the following bits are set:
+# min |  max | L | U
+#  0% |  25% | 0 | 0 
+# 25% |  50% | 1 | 0 
+# 50% |  75% | 0 | 1 
+# 75% | 100% | 1 | 1 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/average.d
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/average.d	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/average.d	(revision 33397)
@@ -2,5 +2,5 @@
 EXTNAME      DVO_AVERAGE
 TYPE         BINTABLE
-SIZE         112
+SIZE         120
 DESCRIPTION  DVO Average Object Table
 
@@ -39,4 +39,6 @@
 # 'flags' was called 'code' prior to 2009.02.07
 FIELD flags,          FLAGS,       uint32_t,        average object flags (star; ghost; etc)
+FIELD photFlagsUpper, PHOTFLAGS_U, uint32_t,        upper bit of 2 bit summary of per-measure photflags
+FIELD photFlagsLower, PHOTFLAGS_L, uint32_t,        lower bit of 2 bit summary of per-measure photflags
 
 # objID + catID gives a unique ID for all objects in the database
@@ -54,2 +56,15 @@
 # *** 20100331 : new fields needed to assess astrometry analysis quality:
 
+
+# photflagsUpper & photflagsLower: we have Nmeasures of a given source
+# using psphot. each of these as a photFlag field, with bits
+# describing the detection quality.  photflagsUpper and photFlagsLower
+# represent a 2 bit value (0-3) which defines the frequency of a given
+# bit in the measurements:
+# for a given bit, if that bit is raised for these percentile ranges,
+# the following bits are set:
+# min |  max | L | U
+#  0% |  25% | 0 | 0 
+# 25% |  50% | 1 | 0 
+# 50% |  75% | 0 | 1 
+# 75% | 100% | 1 | 1 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/image-ps1-v3.d
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/image-ps1-v3.d	(revision 33397)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/image-ps1-v3.d	(revision 33397)
@@ -0,0 +1,75 @@
+STRUCT       Image_PS1_V3
+EXTNAME      DVO_IMAGE_PS1_V3
+TYPE         BINTABLE
+SIZE         360
+DESCRIPTION  DVO Image Table 
+
+# elements of the image structure
+
+SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
+SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
+SUBFIELD  crpix1,           CRPIX1,               float,   	 coordinate of reference pixel
+SUBFIELD  crpix2,           CRPIX2,               float,   	 coordinate of reference pixel
+SUBFIELD  cdelt1,           CDELT1,               float,   	 degrees per pixel
+SUBFIELD  cdelt2,           CDELT2,               float,    	 degrees per pixel
+SUBFIELD  pc1_1,            PC1_1,                float,    	 rotation matrix
+SUBFIELD  pc1_2,            PC1_2,                float,    	 rotation matrix
+SUBFIELD  pc2_1,            PC2_1,                float,    	 rotation matrix
+SUBFIELD  pc2_2,            PC2_2,                float,    	 rotation matrix
+SUBFIELD  polyterms,        POLYTERMS,            float[7][2],	 higher order warping terms
+SUBFIELD  ctype,            CTYPE,                char[15],      coordinate type
+SUBFIELD  Npolyterms,       NPOLYTERMS,           char,     	 order of polynomial
+# 120 bytes
+
+FIELD 	  tzero,            TZERO,                e_time,         readout time (row 0)
+FIELD 	  nstar,            NSTAR,                unsigned int,   number of stars on image
+FIELD 	  secz,             SECZ,                 float,      	  airmass,                   mag
+FIELD 	  NX,               NX,                   unsigned short, image width
+FIELD 	  NY,               NY,                   unsigned short, image height
+FIELD 	  apmifit,          APMIFIT,              float,      	  aperture correction,       mag
+FIELD 	  dapmifit,         DAPMIFIT,             float,      	  apmifit error,             mag
+FIELD 	  Mcal,             MCAL,                 float,      	  calibration mag,           mag
+FIELD 	  dMcal,            DMCAL,                float,      	  error on Mcal,             mag
+FIELD 	  Xm,               XM,                   short,      	  image chisq,               10*log(value)
+FIELD 	  photcode,         PHOTCODE,             short,      	  identifier for CCD,
+FIELD 	  exptime,          EXPTIME,              float,          exposure time,             seconds
+FIELD     sidtime,          ST,			  float,          sidereal time of exposure
+FIELD     latitude,         LAT,		  float,          observatory latitude,      degrees
+# 40 bytes
+
+FIELD     RAo,              RA_CENTER,            float,          image center,              degrees
+FIELD     DECo,             DEC_CENTER,           float,          image center,              degrees
+FIELD     Radius,           RADIUS,               float,          image radius,              degrees
+FIELD     DUMMY,            DUMMY,                float,          dummy
+
+# should we define the max length of name as a macro?
+FIELD 	  name,             NAME,                 char[121],      name of original image 
+FIELD 	  detection_limit,  DETECTION_LIMIT,      unsigned char,  detection limit,           10*mag
+FIELD 	  saturation_limit, SATURATION_LIMIT,     unsigned char,  saturation limit,          10*mag
+FIELD 	  cerror,           CERROR,               unsigned char,  astrometric error,         50*arcsec
+FIELD 	  fwhm_x,           FWHM_X,               unsigned char,  PSF x width,               25*arcsec
+FIELD 	  fwhm_y,           FWHM_Y,               unsigned char,  PSF y width,               25*arcsec
+FIELD 	  trate,            TRATE,                unsigned char,  scan rate,                 100 usec/pixel
+FIELD 	  ccdnum,           CCDNUM,               unsigned char,  CCD ID number
+FIELD 	  flags,            FLAGS,                unsigned int,   image quality flags
+FIELD 	  imageID,          IMAGE_ID,             unsigned int,   internal image ID
+FIELD 	  parentID,         PARENT_ID,            unsigned int,   associated ref image
+FIELD 	  externID,         EXTERN_ID,            unsigned int,   external image ID
+FIELD 	  sourceID,         SOURCE_ID,            unsigned short, analysis source ID
+# 48 bytes 
+
+FIELD 	  nLinkAstrom,      NLINK_ASTROM,         short,      	  mean number of matched measurements for astrometry
+FIELD 	  nLinkPhotom,      NLINK_PHOTOM,         short,      	  mean number of matched measurements for astrometry
+FIELD 	  ubercalDist,      UBERCAL_DIST,         short,      	  distance to nearest ubercal image
+
+FIELD 	  dXpixSys,         XPIX_SYS_ERR,         float,      	  systematic astrometry error in X
+FIELD 	  dYpixSys,         YPIX_SYS_ERR,         float,      	  systematic astrometry error in Y
+
+FIELD 	  dMagSys,          MAG_SYS_ERR,          float,      	  systematic photometry error
+FIELD 	  nFitAstrom,       N_FIT_ASTROM,         short,      	  number of stars used for astrometry cal
+FIELD 	  nFitPhotom,       N_FIT_PHOTOM,         short,      	  number of stars used for photometry cal
+
+FIELD 	  photom_map_id,    PHOTOM_MAP_ID,        unsigned int,   reference to 2D zero point map
+FIELD 	  astrom_map_id,    ASTROM_MAP_ID,        unsigned int,   reference to 2D astrometry map
+# nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/image.d
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/image.d	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/image.d	(revision 33397)
@@ -63,5 +63,5 @@
 FIELD 	  nLinkAstrom,      NLINK_ASTROM,         short,      	  mean number of matched measurements for astrometry
 FIELD 	  nLinkPhotom,      NLINK_PHOTOM,         short,      	  mean number of matched measurements for astrometry
-FIELD 	  dummy3,           DUMMY3,               short,      	  place holder for byte boundaries
+FIELD 	  ubercalDist,      UBERCAL_DIST,         short,      	  distance to nearest ubercal image
 
 FIELD 	  dXpixSys,         XPIX_SYS_ERR,         float,      	  systematic astrometry error in X
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/measure-ps1-v3.d
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/measure-ps1-v3.d	(revision 33397)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/measure-ps1-v3.d	(revision 33397)
@@ -0,0 +1,82 @@
+STRUCT       Measure_PS1_V3
+EXTNAME      DVO_MEASURE_PS1_V3
+TYPE         BINTABLE
+SIZE         152
+DESCRIPTION  DVO Detection Measurement Table 
+
+FIELD dR,             D_RA,         float,          RA offset,                	  arcsec
+FIELD dD,             D_DEC,        float,          DEC offset,               	  arcsec
+FIELD M,              MAG,          float,          catalog mag,       	       	  mag
+FIELD Mcal,           M_CAL,        float,          image cal mag,	          mag
+FIELD Map,            M_APER,       float,          aperture mag,		  mag
+FIELD dM,             MAG_ERR,      float,          mag error,                    mag
+FIELD dMcal,          MAG_CAL_ERR,  float,          systematic calibration error, mag
+FIELD dt,             M_TIME,       float,          exposure time,                2.5*log(exptime)
+
+# note that with airmass = 1.0 / cos(90 - alt), we have full alt/az representation
+FIELD airmass,        AIRMASS,      float,          (airmass - 1),		  airmass
+FIELD az,             AZ,           float,          telescope azimuth
+
+# new field elements needed for Pan-STARRS:
+FIELD Xccd,           X_CCD,        float,          X coord on chip,               pixels
+FIELD Yccd,           Y_CCD,        float,          Y coord on chip,               pixels
+
+# could these be packed into fewer bits?
+FIELD Sky,            SKY_FLUX,     float,          local estimate of sky flux,    counts/sec
+FIELD dSky,           SKY_FLUX_ERR, float,          local estimate of sky flux,    counts/sec
+
+FIELD t,              TIME,         int,   	    time in seconds (UNIX)
+FIELD averef,         AVE_REF,      unsigned int,   reference to average entry      
+
+# internally, this is an unsigned int; however, we do NOT convert with TZERO/TSCAL on output
+FIELD detID,          DET_ID,       unsigned int,   detection ID
+FIELD imageID,        IMAGE_ID,     unsigned int,   reference to DVO image ID
+FIELD objID,          OBJ_ID,       unsigned int,   unique ID for object in table
+FIELD catID,          CAT_ID,       unsigned int,   unique ID for table in which object was first realized
+
+# PSPS uses a 64-bit detection ID
+FIELD extID,          EXT_ID,       uint64_t,       external ID (eg PSPS detID)
+
+# do we need more resolution than a short? should this be a log?
+FIELD psfQual,        PSF_QF,       float,          psf coverage/quality factor
+FIELD psfChisq,       PSF_CHISQ,    float,          psf fit chisq
+FIELD psfNdof,        PSF_NDOF,     int,            psf degrees of freedom
+FIELD psfNpix,        PSF_NPIX,     int,            psf number of pixels
+FIELD crNsigma,       CR_NSIGMA,    float,          Nsigma deviation towards CR
+FIELD extNsigma,      EXT_NSIGMA,   float,          Nsigma deviation towards EXT
+
+# model shape parameters
+FIELD FWx,            FWHM_MAJOR,   short,          object fwhm major axis,         1/100 of pixels
+FIELD FWy,            FWHM_MINOR,   short,          object fwhm minor axis,         1/100 of pixels 
+FIELD theta,          PSF_THETA,    short,          angle wrt ccd X dir,            (0xffff/360) deg
+
+# moments
+FIELD Mxx,            MXX,          short,          second moments in pixel coords, 1/100 of pixels
+FIELD Mxy,            MXY,          short,          second moments in pixel coords, 1/100 of pixels
+FIELD Myy,            MYY,          short,          second moments in pixel coords, 1/100 of pixels
+
+# fractional exposure time
+FIELD t_msec,         TIME_MSEC,    unsigned short, time fraction of second,       milliseconds
+FIELD photcode,       PHOTCODE,     unsigned short, photcode
+
+# position errors
+FIELD dXccd,          X_CCD_ERR,    short,          X coord error on chip,          1/100 of pixels
+FIELD dYccd,          Y_CCD_ERR,    short,          Y coord error on chip,          1/100 of pixels
+FIELD dRsys,          POS_SYS_ERR,  short,          systematic error from astrom,   1/100 of pixels
+
+FIELD pad,            PAD,          char[4],        padding
+
+# local astrometry scales
+FIELD posangle,       POSANGLE,     short,          position angle sky to chip,     (0xffff/360) deg
+FIELD pltscale,       PLTSCALE,     float,          plate scale,                    arcsec/pixel
+
+FIELD dbFlags,        DB_FLAGS,     unsigned int,   flags supplied by analysis in database
+FIELD photFlags,      PHOT_FLAGS,   unsigned int,   flags supplied by photometry program
+
+
+# 19 x float
+# 6 x int or unsigned int
+# 11 x short or unsigned short
+# 3 x uint64_t
+
+# = 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/photcode-ps1-v3.d
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/photcode-ps1-v3.d	(revision 33397)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/photcode-ps1-v3.d	(revision 33397)
@@ -0,0 +1,33 @@
+STRUCT       PhotCode_PS1_V3
+EXTNAME      DVO_PHOTCODE_PS1_V3
+TYPE         BINTABLE
+SIZE         104
+DESCRIPTION  DVO Photcode Description Table 
+
+# elements of data structure / FITS table
+FIELD  code,         	  CODE,          	 unsigned short, code number (stored in Measure.source) 
+FIELD  name,         	  NAME,          	 char[32],       name for filter combination 
+FIELD  type,         	  TYPE,          	 char,           PRI/SEC/DEP/REF 
+FIELD  dummy,        	  DUMMY,         	 char[3],        padding
+FIELD  C,            	  C_LAM,         	 short,          primary phot calibration terms (millimags) 
+FIELD  dC,           	  C_LAM_ERR,     	 short,          primary phot calibration terms (millimags) 
+FIELD  dX,           	  X_ERR,         	 short,          primary phot calibration terms (millimags) 
+FIELD  K,            	  K,             	 float,          secondary phot calibration terms (millimags) 
+FIELD  c1,           	  C1,            	 int,            color is average.M[c1] - average.M[c2] 
+FIELD  c2,           	  C2,            	 int,            color is average.M[c1] - average.M[c2] 
+FIELD  equiv,        	  EQUIV,         	 int,            this dependent filter is equivalent to equiv PRI/SEC
+FIELD  Nc,           	  NC,            	 int,            number of color terms 
+FIELD  X,            	  X,             	 float[4],       color terms $X[0]*mc + X[1]*mc^2 + X[2]*mc^3$, etc 
+FIELD  astromErrSys,      ASTROM_ERR_SYS,  	 float,          systematic astrometry error (arcsec)
+FIELD  astromErrScale,    ASTROM_ERR_SCALE,  	 float,          astrometric error scale
+FIELD  astromErrMagScale, ASTROM_ERR_MAG_SCALE,  float,          astrometric error / mag error scale
+FIELD  astromPoorMask,    ASTROM_POOR_MASK,      short,          detections matching this mask should only be used in emergencies
+FIELD  astromBadMask,     ASTROM_BAD_MASK,       short,          detections matching this mask should not be used
+FIELD  photomErrSys,   	  PHOTOM_ERR_SYS,  	 float,          systematic photometric error
+FIELD  photomPoorMask, 	  PHOTOM_POOR_MASK,  	 short,          detections matching this mask should only be used in emergencies
+FIELD  photomBadMask,  	  PHOTOM_BAD_MASK,  	 short,          detections matching this mask should not be used
+
+#   dR_total^2 =  dR_sys^2 + AS * dR_obs^2 + MS * dM_obs^2
+#   dR_sys : systematicAstrometryError
+#   AS     : astrometryErrorScale
+#   MS     : astrometryErrorMagScale
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/secfilt-ps1-v3.d
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/secfilt-ps1-v3.d	(revision 33397)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/secfilt-ps1-v3.d	(revision 33397)
@@ -0,0 +1,18 @@
+STRUCT       SecFilt_PS1_V3
+EXTNAME      DVO_SECFILT_PS1_V3
+TYPE         BINTABLE
+SIZE         32
+DESCRIPTION  DVO SecFilt : Secondary Filter Data 
+
+# elements of data structure / FITS table
+FIELD  M,     	    MAG,      	  float,      average mag in this band,              mags
+FIELD  Map,    	    MAG,      	  float,      average mag in this band,              mags
+FIELD  dM,    	    MAG_ERR,  	  float,      formal error on average mag,           mags
+FIELD  Xm,    	    MAG_CHI,  	  float,      chisq on average mag,                  [100*log(value)]
+FIELD  flags, 	    FLAGS,    	  uint32_t,   photometry flags
+FIELD  Ncode, 	    NCODE,    	  short,      number of detections in band
+FIELD  Nused, 	    NUSED,    	  short,      number of detections used in average
+FIELD  M_20,  	    MAG_20,   	  short,      lower 20percent mag,                   millimags
+FIELD  M_80,  	    MAG_80,   	  short,      upper 20percent mag,                   millimags
+FIELD  ubercalDist, UBERCAL_DIST, short,      number of images from an ubercal-image
+FIELD  dummy,       DUMMY,        char[2],    padding
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/secfilt.d
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/secfilt.d	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/secfilt.d	(revision 33397)
@@ -2,20 +2,20 @@
 EXTNAME      DVO_SECFILT
 TYPE         BINTABLE
-SIZE         24
-#SIZE         28
+SIZE         32
 DESCRIPTION  DVO SecFilt : Secondary Filter Data 
 
 # elements of data structure / FITS table
-FIELD  M,     MAG,      float,                other mags,       mags
-FIELD  dM,    MAG_ERR,  float,                scatter on mag,   mags
-FIELD  Xm,    MAG_CHI,  float,                chisq on average mag,     [100*log(value)]
-FIELD  flags, FLAGS,    uint32_t,             photometry flags
-FIELD  Ncode, NCODE,    short,                number of detections in band
-FIELD  Nused, NUSED,    short,                number of detections used in average
-FIELD  M_20,  MAG_20,   short,                lower 20percent mag,      millimags
-FIELD  M_80,  MAG_80,   short,                upper 20percent mag,      millimags
-#FIELD  ubercalDist, UBERCAL_DIST, short,      number of images from an ubercal-image
-#FIELD  dummy,       DUMMY,        short,      padding
+FIELD  M,     	    MAG,      	  float,      average mag in this band,              mags
+FIELD  Map,    	    MAG,      	  float,      average mag in this band,              mags
+FIELD  dM,    	    MAG_ERR,  	  float,      formal error on average mag,           mags
+FIELD  Xm,    	    MAG_CHI,  	  float,      chisq on average mag,                  [100*log(value)]
+FIELD  flags, 	    FLAGS,    	  uint32_t,   photometry flags
+FIELD  Ncode, 	    NCODE,    	  short,      number of detections in band
+FIELD  Nused, 	    NUSED,    	  short,      number of detections used in average
+FIELD  M_20,  	    MAG_20,   	  short,      lower 20percent mag,                   millimags
+FIELD  M_80,  	    MAG_80,   	  short,      upper 20percent mag,                   millimags
+FIELD  ubercalDist, UBERCAL_DIST, short,      number of images from an ubercal-image
+FIELD  dummy,       DUMMY,        char[2],    padding
 
 # *** 20090206 : new fields : M_20, M_80; dropped dummy
-# *** 20120302 : new fields : ubercalDist, dummy; dropped dummy
+# *** 20120302 : new fields : ubercalDist, Map, dummy[2byte]
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/Makefile
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/Makefile	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/Makefile	(revision 33397)
@@ -34,4 +34,5 @@
 $(DESTINC)/ps1_v1_defs.h \
 $(DESTINC)/ps1_v2_defs.h \
+$(DESTINC)/ps1_v3_defs.h \
 $(DESTINC)/ps1_ref_defs.h
 
@@ -69,4 +70,5 @@
 $(SRC)/dvo_convert_PS1_V1.$(ARCH).o \
 $(SRC)/dvo_convert_PS1_V2.$(ARCH).o \
+$(SRC)/dvo_convert_PS1_V3.$(ARCH).o \
 $(SRC)/dvo_convert_PS1_REF.$(ARCH).o \
 $(SRC)/flatcorr_io.$(ARCH).o    \
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/include/dvo.h	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/include/dvo.h	(revision 33397)
@@ -26,4 +26,5 @@
   DVO_FORMAT_PS1_V1,
   DVO_FORMAT_PS1_V2,
+  DVO_FORMAT_PS1_V3,
 } DVOTableFormat;
 
@@ -535,4 +536,5 @@
 # include "ps1_v1_defs.h"
 # include "ps1_v2_defs.h"
+# include "ps1_v3_defs.h"
 # include "ps1_ref_defs.h"
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/include/ps1_v3_defs.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/include/ps1_v3_defs.h	(revision 33397)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/include/ps1_v3_defs.h	(revision 33397)
@@ -0,0 +1,11 @@
+Image 		       	*Image_PS1_V3_ToInternal (Image_PS1_V3 *in, off_t Nvalues);
+Image_PS1_V3    	*ImageInternalTo_PS1_V3 (Image *in, off_t Nvalues);
+Average 	       	*Average_PS1_V3_ToInternal (Average_PS1_V3 *in, off_t Nvalues, SecFilt **primary);
+Average_PS1_V3          *AverageInternalTo_PS1_V3 (Average *in, off_t Nvalues, SecFilt *primary);
+Measure 	       	*Measure_PS1_V3_ToInternal (Measure_PS1_V3 *in, off_t Nvalues);
+Measure_PS1_V3          *MeasureInternalTo_PS1_V3 (Measure *in, off_t Nvalues);
+SecFilt 	       	*SecFilt_PS1_V3_ToInternal (SecFilt_PS1_V3 *in, off_t Nvalues);
+SecFilt_PS1_V3          *SecFiltInternalTo_PS1_V3 (SecFilt *in, off_t Nvalues);
+
+PhotCode                *PhotCode_PS1_V3_To_Internal (PhotCode_PS1_V3 *in, off_t Nvalues);
+PhotCode_PS1_V3         *PhotCode_Internal_To_PS1_V3 (PhotCode *in, off_t Nvalues);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/LoadPhotcodesFITS.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 33397)
@@ -41,83 +41,26 @@
   gfits_scan (&db.theader, "EXTNAME", "%s", 1, extname);
 
-  if (!strcmp (extname, "DVO_PHOTCODE")) {
-    PhotCode_Elixir *photcode_elixir = gfits_table_get_PhotCode_Elixir (&db.ftable, &Ncode, &db.swapped);
-    if (!photcode_elixir) {
-      fprintf (stderr, "ERROR: failed to read photcodes\n");
-      exit (2);
-    }
-    photcode = PhotCode_Elixir_To_Internal (photcode_elixir, Ncode);
-    free (photcode_elixir);
-  } 
+# define CONVERT_FORMAT(NAME, FORMAT)					\
+  if (!strcmp (extname, NAME)) {					\
+    PhotCode_##FORMAT *photcode_input = gfits_table_get_PhotCode_##FORMAT (&db.ftable, &Ncode, &db.swapped); \
+    if (!photcode_input) {							\
+      fprintf (stderr, "ERROR: failed to read photcodes in LoadPhotcodesFITS.c\n");		\
+      fprintf (stderr, "file is either corrupted or this is a programming error\n");		\
+      fprintf (stderr, "exiting to avoid damaging dvo db\n");		\
+      exit (2);								\
+    }									\
+    photcode = PhotCode_##FORMAT##_To_Internal (photcode_input, Ncode); \
+    free (photcode_input);						\
+  }
 
-  if (!strcmp (extname, "DVO_PHOTCODE_ELIXIR")) {
-    PhotCode_Elixir *photcode_elixir = gfits_table_get_PhotCode_Elixir (&db.ftable, &Ncode, &db.swapped);
-    if (!photcode_elixir) {
-      fprintf (stderr, "ERROR: failed to read photcodes\n");
-      exit (2);
-    }
-    photcode = PhotCode_Elixir_To_Internal (photcode_elixir, Ncode);
-    free (photcode_elixir);
-  } 
-
-  if (!strcmp (extname, "DVO_PHOTCODE_PS1_DEV_1")) {
-    PhotCode_PS1_DEV_1 *photcode_ps1_dev_1 = gfits_table_get_PhotCode_PS1_DEV_1 (&db.ftable, &Ncode, &db.swapped);
-    if (!photcode_ps1_dev_1) {
-      fprintf (stderr, "ERROR: failed to read photcodes\n");
-      exit (2);
-    }
-    photcode = PhotCode_PS1_DEV_1_To_Internal (photcode_ps1_dev_1, Ncode);
-    free (photcode_ps1_dev_1);
-  } 
-
-  if (!strcmp (extname, "DVO_PHOTCODE_PS1_DEV_2")) {
-    PhotCode_PS1_DEV_2 *photcode_ps1_dev_2 = gfits_table_get_PhotCode_PS1_DEV_2 (&db.ftable, &Ncode, &db.swapped);
-    if (!photcode_ps1_dev_2) {
-      fprintf (stderr, "ERROR: failed to read photcodes\n");
-      exit (2);
-    }
-    photcode = PhotCode_PS1_DEV_2_To_Internal (photcode_ps1_dev_2, Ncode);
-    free (photcode_ps1_dev_2);
-  } 
-
-  if (!strcmp (extname, "DVO_PHOTCODE_PS1_DEV_3")) {
-    PhotCode_PS1_DEV_3 *photcode_ps1_dev_3 = gfits_table_get_PhotCode_PS1_DEV_3 (&db.ftable, &Ncode, &db.swapped);
-    if (!photcode_ps1_dev_3) {
-      fprintf (stderr, "ERROR: failed to read photcodes\n");
-      exit (2);
-    }
-    photcode = PhotCode_PS1_DEV_3_To_Internal (photcode_ps1_dev_3, Ncode);
-    free (photcode_ps1_dev_3);
-  } 
-
-  if (!strcmp (extname, "DVO_PHOTCODE_PS1_V1")) {
-    PhotCode_PS1_V1 *photcode_ps1_v1 = gfits_table_get_PhotCode_PS1_V1 (&db.ftable, &Ncode, &db.swapped);
-    if (!photcode_ps1_v1) {
-      fprintf (stderr, "ERROR: failed to read photcodes\n");
-      exit (2);
-    }
-    photcode = PhotCode_PS1_V1_To_Internal (photcode_ps1_v1, Ncode);
-    free (photcode_ps1_v1);
-  } 
-
-  if (!strcmp (extname, "DVO_PHOTCODE_PS1_V2")) {
-    PhotCode_PS1_V2 *photcode_ps1_v2 = gfits_table_get_PhotCode_PS1_V2 (&db.ftable, &Ncode, &db.swapped);
-    if (!photcode_ps1_v2) {
-      fprintf (stderr, "ERROR: failed to read photcodes\n");
-      exit (2);
-    }
-    photcode = PhotCode_PS1_V2_To_Internal (photcode_ps1_v2, Ncode);
-    free (photcode_ps1_v2);
-  } 
-
-  if (!strcmp (extname, "DVO_PHOTCODE_PS1_REF")) {
-    PhotCode_PS1_REF *photcode_ps1_ref = gfits_table_get_PhotCode_PS1_REF (&db.ftable, &Ncode, &db.swapped);
-    if (!photcode_ps1_ref) {
-      fprintf (stderr, "ERROR: failed to read photcodes\n");
-      exit (2);
-    }
-    photcode = PhotCode_PS1_REF_To_Internal (photcode_ps1_ref, Ncode);
-    free (photcode_ps1_ref);
-  } 
+  CONVERT_FORMAT("DVO_PHOTCODE",           Elixir);
+  CONVERT_FORMAT("DVO_PHOTCODE_ELIXIR",    Elixir);
+  CONVERT_FORMAT("DVO_PHOTCODE_PS1_DEV_1", PS1_DEV_1);
+  CONVERT_FORMAT("DVO_PHOTCODE_PS1_DEV_2", PS1_DEV_2);
+  CONVERT_FORMAT("DVO_PHOTCODE_PS1_DEV_3", PS1_DEV_3);
+  CONVERT_FORMAT("DVO_PHOTCODE_PS1_REF",   PS1_REF);
+  CONVERT_FORMAT("DVO_PHOTCODE_PS1_V1",    PS1_V1);
+  CONVERT_FORMAT("DVO_PHOTCODE_PS1_V2",    PS1_V2);
+  CONVERT_FORMAT("DVO_PHOTCODE_PS1_V3",    PS1_V3);
 
   table = GetPhotcodeTable ();
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/SavePhotcodesFITS.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/SavePhotcodesFITS.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/SavePhotcodesFITS.c	(revision 33397)
@@ -29,9 +29,9 @@
   // for the moment, we simply support the latest photcode format for output
   // XXX update this as needed as new formats are defined
-  PhotCode_PS1_V2 *photcode_output = PhotCode_Internal_To_PS1_V2 (table[0].code, table[0].Ncode);
+  PhotCode_PS1_V3 *photcode_output = PhotCode_Internal_To_PS1_V3 (table[0].code, table[0].Ncode);
 
   /* convert FITS format data to internal format (byteswaps & EXTNAME) */
   if (!gfits_db_create (&db)) return (FALSE);
-  if (!gfits_table_set_PhotCode_PS1_V2 (&db.ftable, photcode_output, table[0].Ncode)) return (FALSE);
+  if (!gfits_table_set_PhotCode_PS1_V3 (&db.ftable, photcode_output, table[0].Ncode)) return (FALSE);
   if (!gfits_db_save (&db)) return (FALSE);
   if (!gfits_db_close (&db)) return (FALSE);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog.c	(revision 33397)
@@ -54,4 +54,5 @@
   if (!strcasecmp (catformat, "PS1_V1"))          return (DVO_FORMAT_PS1_V1);
   if (!strcasecmp (catformat, "PS1_V2"))          return (DVO_FORMAT_PS1_V2);
+  if (!strcasecmp (catformat, "PS1_V3"))          return (DVO_FORMAT_PS1_V3);
   if (!strcasecmp (catformat, "PS1_REF"))         return (DVO_FORMAT_PS1_REF);
   return (DVO_FORMAT_UNDEF);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog_raw.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 33397)
@@ -88,4 +88,5 @@
       FORMAT_CASE (PS1_V1,    PS1_V1);
       FORMAT_CASE (PS1_V2,    PS1_V2);
+      FORMAT_CASE (PS1_V3,    PS1_V3);
       FORMAT_CASE (PS1_REF,   PS1_REF);
 
@@ -280,4 +281,5 @@
   if (catalog[0].catformat == DVO_FORMAT_PS1_V1)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V1");
   if (catalog[0].catformat == DVO_FORMAT_PS1_V2)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V2");
+  if (catalog[0].catformat == DVO_FORMAT_PS1_V3)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V3");
   if (catalog[0].catformat == DVO_FORMAT_PS1_REF)         gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_REF");
 
@@ -381,4 +383,5 @@
       FORMAT_CASE (PS1_V1,    PS1_V1);
       FORMAT_CASE (PS1_V2,    PS1_V2);
+      FORMAT_CASE (PS1_V3,    PS1_V3);
       FORMAT_CASE (PS1_REF,   PS1_REF);
 
@@ -430,4 +433,5 @@
       FORMAT_CASE (PS1_V1,    PS1_V1);
       FORMAT_CASE (PS1_V2,    PS1_V2);
+      FORMAT_CASE (PS1_V3,    PS1_V3);
       FORMAT_CASE (PS1_REF,   PS1_REF);
 
@@ -483,4 +487,5 @@
       FORMAT_CASE (PS1_V1,    PS1_V1);
       FORMAT_CASE (PS1_V2,    PS1_V2);
+      FORMAT_CASE (PS1_V3,    PS1_V3);
       FORMAT_CASE (PS1_REF,   PS1_REF);
 
@@ -532,4 +537,5 @@
       FORMAT_CASE (PS1_V1,    PS1_V1);
       FORMAT_CASE (PS1_V2,    PS1_V2);
+      FORMAT_CASE (PS1_V3,    PS1_V3);
       FORMAT_CASE (PS1_REF,   PS1_REF);
 
@@ -585,4 +591,5 @@
       FORMAT_CASE (PS1_V1,    PS1_V1);
       FORMAT_CASE (PS1_V2,    PS1_V2);
+      FORMAT_CASE (PS1_V3,    PS1_V3);
       FORMAT_CASE (PS1_REF,   PS1_REF);
 
@@ -634,4 +641,5 @@
       FORMAT_CASE (PS1_V1,    PS1_V1);
       FORMAT_CASE (PS1_V2,    PS1_V2);
+      FORMAT_CASE (PS1_V3,    PS1_V3);
       FORMAT_CASE (PS1_REF,   PS1_REF);
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert.c	(revision 33397)
@@ -39,4 +39,5 @@
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_V1",          PS1_V1);
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_V2",          PS1_V2);
+  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V3",          PS1_V3);
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF);
 # undef CONVERT_FORMAT
@@ -94,4 +95,5 @@
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_V1",          PS1_V1,          PS1_V1);
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_V2",          PS1_V2,          PS1_V2);
+  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V3",          PS1_V3,          PS1_V3);
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF,         PS1_REF);
 # undef CONVERT_FORMAT
@@ -127,4 +129,5 @@
       FORMAT_CASE (PS1_V1,          PS1_V1);
       FORMAT_CASE (PS1_V2,          PS1_V2);
+      FORMAT_CASE (PS1_V3,          PS1_V3);
       FORMAT_CASE (PS1_REF,         PS1_REF);
 # undef FORMAT_CASE
@@ -181,4 +184,5 @@
   CONVERT_FORMAT ("DVO_MEASURE_PS1_V1",          PS1_V1,          PS1_V1);
   CONVERT_FORMAT ("DVO_MEASURE_PS1_V2",          PS1_V2,          PS1_V2);
+  CONVERT_FORMAT ("DVO_MEASURE_PS1_V3",          PS1_V3,          PS1_V3);
   CONVERT_FORMAT ("DVO_MEASURE_PS1_REF",         PS1_REF,         PS1_REF);
 # undef CONVERT_FORMAT
@@ -214,4 +218,5 @@
       FORMAT_CASE (PS1_V1,          PS1_V1);
       FORMAT_CASE (PS1_V2,          PS1_V2);
+      FORMAT_CASE (PS1_V3,          PS1_V3);
       FORMAT_CASE (PS1_REF,         PS1_REF);
 # undef FORMAT_CASE
@@ -268,4 +273,5 @@
   CONVERT_FORMAT ("DVO_SECFILT_PS1_V1",          PS1_V1,          PS1_V1);
   CONVERT_FORMAT ("DVO_SECFILT_PS1_V2",          PS1_V2,          PS1_V2);
+  CONVERT_FORMAT ("DVO_SECFILT_PS1_V3",          PS1_V3,          PS1_V3);
   CONVERT_FORMAT ("DVO_SECFILT_PS1_REF",         PS1_REF,         PS1_REF);
 # undef CONVERT_FORMAT
@@ -301,4 +307,5 @@
       FORMAT_CASE (PS1_V1,          PS1_V1);
       FORMAT_CASE (PS1_V2,          PS1_V2);
+      FORMAT_CASE (PS1_V3,          PS1_V3);
       FORMAT_CASE (PS1_REF,         PS1_REF);
 # undef FORMAT_CASE
@@ -379,4 +386,5 @@
   CONVERT_FORMAT ("DVO_IMAGE_PS1_V1",          PS1_V1,          PS1_V1);
   CONVERT_FORMAT ("DVO_IMAGE_PS1_V2",          PS1_V2,          PS1_V2);
+  CONVERT_FORMAT ("DVO_IMAGE_PS1_V3",          PS1_V3,          PS1_V3);
   CONVERT_FORMAT ("DVO_IMAGE_PS1_REF",         PS1_REF,         PS1_REF);
 
@@ -416,4 +424,5 @@
       FORMAT_CASE (PS1_V1,          PS1_V1);
       FORMAT_CASE (PS1_V2,          PS1_V2);
+      FORMAT_CASE (PS1_V3,          PS1_V3);
       FORMAT_CASE (PS1_REF,         PS1_REF);
 
@@ -469,4 +478,5 @@
       FORMAT_CASE (PS1_V1,          PS1_V1);
       FORMAT_CASE (PS1_V2,          PS1_V2);
+      FORMAT_CASE (PS1_V3,          PS1_V3);
       FORMAT_CASE (PS1_REF,         PS1_REF);
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 33397)
@@ -147,4 +147,8 @@
     out[i].Npos       	 = 0.0;
     out[i].extID 	 = 0;
+
+    // added in PS1_V3
+    out[i].photFlagsUpper = 0;
+    out[i].photFlagsLower = 0;
   }
   return (out);
@@ -206,4 +210,8 @@
     // changed or added for PS1_V2
     out[i].flags = 0;
+
+    // added in PS1_V3
+    out[i].Map         = 0;
+    out[i].ubercalDist = 0;
  }
   return (out);
@@ -268,5 +276,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].ubercalDist	    = in[i].dummy3; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
@@ -335,5 +343,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].dummy3	    = in[i].ubercalDist; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 33397)
@@ -141,4 +141,8 @@
     out[i].Npos       	 = 0.0;
     out[i].extID 	 = 0;
+
+    // added in PS1_V3
+    out[i].photFlagsUpper = 0;
+    out[i].photFlagsLower = 0;
   }
   return (out);
@@ -200,4 +204,8 @@
     // changed or added for PS1_V2
     out[i].flags = 0;
+
+    // added in PS1_V3
+    out[i].Map         = 0;
+    out[i].ubercalDist = 0;
  }
   return (out);
@@ -264,5 +272,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].ubercalDist	    = in[i].dummy3; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
@@ -329,5 +337,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].dummy3	    = in[i].ubercalDist; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c	(revision 33397)
@@ -48,5 +48,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].ubercalDist	    = in[i].dummy3; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
@@ -107,5 +107,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].dummy3	    = in[i].ubercalDist; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c	(revision 33397)
@@ -114,4 +114,8 @@
     out[i].catID 	 = in[i].catID;
     out[i].extID 	 = 0;
+
+    // added in PS1_V3
+    out[i].photFlagsUpper = 0;
+    out[i].photFlagsLower = 0;
   }
   return (out);
@@ -160,4 +164,8 @@
     // changed or added for PS1_V2
     out[i].flags = 0;
+
+    // added in PS1_V3
+    out[i].Map         = 0;
+    out[i].ubercalDist = 0;
  }
   return (out);
@@ -223,5 +231,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].ubercalDist	    = in[i].dummy3; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
@@ -285,5 +293,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].dummy3	    = in[i].ubercalDist; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 33397)
@@ -146,4 +146,8 @@
     out[i].catID 	 = in[i].catID;
     out[i].extID 	 = in[i].extID;
+
+    // added in PS1_V3
+    out[i].photFlagsUpper = 0;
+    out[i].photFlagsLower = 0;
   }
   return (out);
@@ -204,4 +208,8 @@
     // changed or added for PS1_V2
     out[i].flags = 0;
+
+    // added in PS1_V3
+    out[i].Map         = 0;
+    out[i].ubercalDist = 0;
  }
   return (out);
@@ -272,5 +280,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].ubercalDist	    = in[i].dummy3;
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
@@ -336,5 +344,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].dummy3	    = in[i].ubercalDist; 
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c	(revision 33397)
@@ -147,4 +147,8 @@
     out[i].catID 	 = in[i].catID;
     out[i].extID 	 = in[i].extID;
+
+    // added in PS1_V3
+    out[i].photFlagsUpper = 0;
+    out[i].photFlagsLower = 0;
   }
   return (out);
@@ -207,4 +211,8 @@
     out[i].M_20  = in[i].M_20;      
     out[i].M_80  = in[i].M_80;      
+
+    // added in PS1_V3
+    out[i].Map         = 0;
+    out[i].ubercalDist = 0;
  }
   return (out);
@@ -281,5 +289,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].ubercalDist	    = in[i].dummy3; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
@@ -343,5 +351,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].dummy3	    = in[i].ubercalDist; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c	(revision 33397)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c	(revision 33397)
@@ -0,0 +1,435 @@
+# include <dvo.h>
+
+/* convert PS1_V3 formats to internal formats */
+
+Measure *Measure_PS1_V3_ToInternal (Measure_PS1_V3 *in, off_t Nvalues) {
+
+  off_t i;
+  Measure *out;
+
+  ALLOCATE_ZERO (out, Measure, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].dR         = in[i].dR;
+    out[i].dD         = in[i].dD;
+    out[i].M          = in[i].M;
+    out[i].Mcal       = in[i].Mcal;
+    out[i].Map        = in[i].Map;
+    out[i].dM         = in[i].dM;
+    out[i].dMcal      = in[i].dMcal;
+    out[i].dt         = in[i].dt;
+    out[i].airmass    = in[i].airmass;
+    out[i].az         = in[i].az;
+    out[i].Xccd       = in[i].Xccd;
+    out[i].Yccd       = in[i].Yccd;
+    out[i].Sky        = in[i].Sky;
+    out[i].dSky       = in[i].dSky;
+    out[i].t          = in[i].t;
+    out[i].t_msec     = in[i].t_msec;
+    out[i].averef     = in[i].averef;
+    out[i].detID      = in[i].detID;
+    out[i].imageID    = in[i].imageID;
+    out[i].objID      = in[i].objID;
+    out[i].catID      = in[i].catID;
+    out[i].extID      = in[i].extID;
+    out[i].psfQual    = in[i].psfQual;
+    out[i].psfChisq   = in[i].psfChisq;
+    out[i].psfNdof    = in[i].psfNdof;
+    out[i].psfNpix    = in[i].psfNpix;
+    out[i].crNsigma   = in[i].crNsigma;
+    out[i].extNsigma  = in[i].extNsigma;
+    out[i].FWx 	      = in[i].FWx;
+    out[i].FWy 	      = in[i].FWy;
+    out[i].theta      = in[i].theta;
+    out[i].Mxx 	      = in[i].Mxx;
+    out[i].Mxy 	      = in[i].Mxy;
+    out[i].Myy 	      = in[i].Myy;
+    out[i].dXccd      = in[i].dXccd;
+    out[i].dYccd      = in[i].dYccd;
+    out[i].dRsys      = in[i].dRsys;
+    out[i].posangle   = in[i].posangle;
+    out[i].pltscale   = in[i].pltscale;
+    out[i].photcode   = in[i].photcode;
+    out[i].dbFlags    = in[i].dbFlags;
+    out[i].photFlags  = in[i].photFlags;
+  }
+  return (out);
+}
+
+Measure_PS1_V3 *MeasureInternalTo_PS1_V3 (Measure *in, off_t Nvalues) {
+
+  off_t i;
+  Measure_PS1_V3 *out;
+
+  ALLOCATE_ZERO (out, Measure_PS1_V3, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].dR         = in[i].dR;
+    out[i].dD         = in[i].dD;
+    out[i].M          = in[i].M;
+    out[i].Mcal       = in[i].Mcal;
+    out[i].Map        = in[i].Map;
+    out[i].dM         = in[i].dM;
+    out[i].dMcal      = in[i].dMcal;
+    out[i].dt         = in[i].dt;
+    out[i].airmass    = in[i].airmass;
+    out[i].az         = in[i].az;
+    out[i].Xccd       = in[i].Xccd;
+    out[i].Yccd       = in[i].Yccd;
+    out[i].Sky        = in[i].Sky;
+    out[i].dSky       = in[i].dSky;
+    out[i].t          = in[i].t;
+    out[i].t_msec     = in[i].t_msec;
+    out[i].averef     = in[i].averef;
+    out[i].detID      = in[i].detID;
+    out[i].imageID    = in[i].imageID;
+    out[i].objID      = in[i].objID;
+    out[i].catID      = in[i].catID;
+    out[i].extID      = in[i].extID;
+    out[i].psfQual    = in[i].psfQual;
+    out[i].psfChisq   = in[i].psfChisq;
+    out[i].psfNdof    = in[i].psfNdof;
+    out[i].psfNpix    = in[i].psfNpix;
+    out[i].crNsigma   = in[i].crNsigma;
+    out[i].extNsigma  = in[i].extNsigma;
+    out[i].FWx 	      = in[i].FWx;
+    out[i].FWy 	      = in[i].FWy;
+    out[i].theta      = in[i].theta;
+    out[i].Mxx 	      = in[i].Mxx;
+    out[i].Mxy 	      = in[i].Mxy;
+    out[i].Myy 	      = in[i].Myy;
+    out[i].dXccd      = in[i].dXccd;
+    out[i].dYccd      = in[i].dYccd;
+    out[i].dRsys      = in[i].dRsys;
+    out[i].posangle   = in[i].posangle;
+    out[i].pltscale   = in[i].pltscale;
+    out[i].photcode   = in[i].photcode;
+    out[i].dbFlags    = in[i].dbFlags;
+    out[i].photFlags  = in[i].photFlags;
+  }
+  return (out);
+}
+
+// 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
+Average *Average_PS1_V3_ToInternal (Average_PS1_V3 *in, off_t Nvalues, SecFilt **primary) {
+
+  off_t i;
+  Average *out;
+
+  ALLOCATE_ZERO (out, Average, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].R        	 = in[i].R;      
+    out[i].D        	 = in[i].D;      
+    out[i].dR       	 = in[i].dR;
+    out[i].dD       	 = in[i].dD;
+    out[i].uR       	 = in[i].uR;
+    out[i].uD       	 = in[i].uD;
+    out[i].duR      	 = in[i].duR;
+    out[i].duD      	 = in[i].duD;
+    out[i].P        	 = in[i].P;
+    out[i].dP       	 = in[i].dP;
+    out[i].Xp       	 = in[i].Xp;     
+    out[i].ChiSqAve    	 = in[i].ChiSqAve;     
+    out[i].ChiSqPM    	 = in[i].ChiSqPM;     
+    out[i].ChiSqPar    	 = in[i].ChiSqPar;     
+    out[i].Tmean    	 = in[i].Tmean;     
+    out[i].Trange   	 = in[i].Trange;     
+    out[i].Npos       	 = in[i].Npos;     
+    out[i].Nmeasure      = in[i].Nmeasure;     
+    out[i].Nmissing      = in[i].Nmissing;     
+    out[i].Nextend       = in[i].Nextend;     
+    out[i].measureOffset = in[i].measureOffset; 
+    out[i].missingOffset = in[i].missingOffset;
+    out[i].extendOffset  = in[i].extendOffset;
+    out[i].flags     	 = in[i].flags;   
+    out[i].photFlagsUpper = in[i].photFlagsUpper;   
+    out[i].photFlagsLower = in[i].photFlagsLower;   
+    out[i].objID 	 = in[i].objID;
+    out[i].catID 	 = in[i].catID;
+    out[i].extID 	 = in[i].extID;
+  }
+  return (out);
+}
+
+// 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
+Average_PS1_V3 *AverageInternalTo_PS1_V3 (Average *in, off_t Nvalues, SecFilt *primary) {
+
+  off_t i;
+  Average_PS1_V3 *out;
+
+  ALLOCATE_ZERO (out, Average_PS1_V3, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].R        	 = in[i].R;      
+    out[i].D        	 = in[i].D;      
+    out[i].dR       	 = in[i].dR;
+    out[i].dD       	 = in[i].dD;
+    out[i].uR       	 = in[i].uR;
+    out[i].uD       	 = in[i].uD;
+    out[i].duR      	 = in[i].duR;
+    out[i].duD      	 = in[i].duD;
+    out[i].P        	 = in[i].P;
+    out[i].dP       	 = in[i].dP;
+    out[i].Xp       	 = in[i].Xp;     
+    out[i].ChiSqAve    	 = in[i].ChiSqAve;     
+    out[i].ChiSqPM     	 = in[i].ChiSqPM;     
+    out[i].ChiSqPar   	 = in[i].ChiSqPar;     
+    out[i].Tmean    	 = in[i].Tmean;     
+    out[i].Trange   	 = in[i].Trange;     
+    out[i].Npos       	 = in[i].Npos;     
+    out[i].Nmeasure      = in[i].Nmeasure;     
+    out[i].Nmissing      = in[i].Nmissing;     
+    out[i].Nextend       = in[i].Nextend;     
+    out[i].measureOffset = in[i].measureOffset; 
+    out[i].missingOffset = in[i].missingOffset;
+    out[i].extendOffset  = in[i].extendOffset;
+    out[i].flags     	 = in[i].flags;   
+    out[i].photFlagsUpper = in[i].photFlagsUpper;   
+    out[i].photFlagsLower = in[i].photFlagsLower;   
+    out[i].objID 	 = in[i].objID;
+    out[i].catID 	 = in[i].catID;
+    out[i].extID 	 = in[i].extID;
+  }
+  return (out);
+}
+
+SecFilt *SecFilt_PS1_V3_ToInternal (SecFilt_PS1_V3 *in, off_t Nvalues) {
+
+  off_t i;
+  SecFilt *out;
+
+  ALLOCATE_ZERO (out, SecFilt, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].M           = in[i].M;      
+    out[i].Map         = in[i].Map;      
+    out[i].dM          = in[i].dM;      
+    out[i].Xm          = in[i].Xm;     
+    out[i].flags       = in[i].flags;     
+    out[i].Ncode       = in[i].Ncode;
+    out[i].Nused       = in[i].Nused;
+    out[i].M_20        = in[i].M_20;      
+    out[i].M_80        = in[i].M_80;      
+    out[i].ubercalDist = in[i].ubercalDist;      
+ }
+  return (out);
+}
+
+SecFilt_PS1_V3 *SecFiltInternalTo_PS1_V3 (SecFilt *in, off_t Nvalues) {
+
+  off_t i;
+  SecFilt_PS1_V3 *out;
+
+  ALLOCATE_ZERO (out, SecFilt_PS1_V3, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].M           = in[i].M;      
+    out[i].Map         = in[i].Map;      
+    out[i].dM          = in[i].dM;      
+    out[i].Xm          = in[i].Xm;     
+    out[i].flags       = in[i].flags;     
+    out[i].Ncode       = in[i].Ncode;
+    out[i].Nused       = in[i].Nused;
+    out[i].M_20        = in[i].M_20;      
+    out[i].M_80        = in[i].M_80;      
+    out[i].ubercalDist = in[i].ubercalDist;      
+  }
+  return (out);
+}
+
+Image *Image_PS1_V3_ToInternal (Image_PS1_V3 *in, off_t Nvalues) {
+
+  off_t i;
+  Image *out;
+
+  ALLOCATE_ZERO (out, Image, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
+
+    strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
+    out[i].name[120] = 0; // force termination
+
+    out[i].tzero    	    = in[i].tzero;
+    out[i].nstar    	    = in[i].nstar;
+    out[i].secz	    	    = in[i].secz;
+    out[i].NX	    	    = in[i].NX;
+    out[i].NY	    	    = in[i].NY;
+    out[i].apmifit  	    = in[i].apmifit;
+    out[i].dapmifit 	    = in[i].dapmifit;
+    out[i].Mcal	    	    = in[i].Mcal;
+    out[i].dMcal    	    = in[i].dMcal;
+    out[i].Xm	    	    = in[i].Xm;
+    out[i].photcode   	    = in[i].photcode;
+    out[i].exptime  	    = in[i].exptime;
+    out[i].sidtime  	    = in[i].sidtime;
+    out[i].latitude  	    = in[i].latitude;
+
+    out[i].RAo  	    = in[i].RAo;
+    out[i].DECo  	    = in[i].DECo;
+    out[i].Radius  	    = in[i].Radius;
+
+    out[i].detection_limit  = in[i].detection_limit;
+    out[i].saturation_limit = in[i].saturation_limit;
+    out[i].cerror	    = in[i].cerror;
+    out[i].fwhm_x	    = in[i].fwhm_x;
+    out[i].fwhm_y	    = in[i].fwhm_y;
+    out[i].trate	    = in[i].trate;
+    out[i].ccdnum	    = in[i].ccdnum;
+    out[i].flags	    = in[i].flags;
+    out[i].imageID	    = in[i].imageID;
+    out[i].parentID	    = in[i].parentID;
+    out[i].externID	    = in[i].externID;
+    out[i].sourceID	    = in[i].sourceID;
+
+    // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced
+    // with the following.  (no real databases used those values -- see
+    // libdvo/doc/dvo-images.txt)
+    out[i].nLinkAstrom	    = in[i].nLinkAstrom;
+    out[i].nLinkPhotom	    = in[i].nLinkPhotom;
+    out[i].ubercalDist	    = in[i].ubercalDist;
+    out[i].dXpixSys	    = in[i].dXpixSys;
+    out[i].dYpixSys	    = in[i].dYpixSys;
+    out[i].dMagSys	    = in[i].dMagSys;
+    out[i].nFitAstrom       = in[i].nFitAstrom;
+    out[i].nFitPhotom       = in[i].nFitPhotom;
+    out[i].photom_map_id    = in[i].photom_map_id;
+    out[i].astrom_map_id    = in[i].astrom_map_id;
+  }
+  return (out);
+}
+
+Image_PS1_V3 *ImageInternalTo_PS1_V3 (Image *in, off_t Nvalues) {
+
+  off_t i;
+  Image_PS1_V3 *out;
+
+  ALLOCATE_ZERO (out, Image_PS1_V3, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
+
+    strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
+    out[i].name[120] = 0; // force termination
+
+    out[i].tzero    	    = in[i].tzero;
+    out[i].nstar    	    = in[i].nstar;
+    out[i].secz	    	    = in[i].secz;
+    out[i].NX	    	    = in[i].NX;
+    out[i].NY	    	    = in[i].NY;
+    out[i].apmifit  	    = in[i].apmifit;
+    out[i].dapmifit 	    = in[i].dapmifit;
+    out[i].Mcal	    	    = in[i].Mcal;
+    out[i].dMcal    	    = in[i].dMcal;
+    out[i].Xm	    	    = in[i].Xm;
+    out[i].photcode   	    = in[i].photcode;
+    out[i].exptime  	    = in[i].exptime;
+    out[i].sidtime  	    = in[i].sidtime;
+    out[i].latitude  	    = in[i].latitude;
+
+    out[i].RAo  	    = in[i].RAo;
+    out[i].DECo  	    = in[i].DECo;
+    out[i].Radius  	    = in[i].Radius;
+
+    out[i].detection_limit  = in[i].detection_limit;
+    out[i].saturation_limit = in[i].saturation_limit;
+    out[i].cerror	    = in[i].cerror;
+    out[i].fwhm_x	    = in[i].fwhm_x;
+    out[i].fwhm_y	    = in[i].fwhm_y;
+    out[i].trate	    = in[i].trate;
+    out[i].ccdnum	    = in[i].ccdnum;
+    out[i].flags	    = in[i].flags;
+    out[i].imageID	    = in[i].imageID;
+    out[i].parentID	    = in[i].parentID;
+    out[i].externID	    = in[i].externID;
+    out[i].sourceID	    = in[i].sourceID;
+
+    // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced
+    // with the following.  (no real databases used those values -- see
+    // libdvo/doc/dvo-images.txt)
+    out[i].nLinkAstrom	    = in[i].nLinkAstrom;
+    out[i].nLinkPhotom	    = in[i].nLinkPhotom;
+    out[i].ubercalDist	    = in[i].ubercalDist;
+    out[i].dXpixSys	    = in[i].dXpixSys;
+    out[i].dYpixSys	    = in[i].dYpixSys;
+    out[i].dMagSys	    = in[i].dMagSys;
+    out[i].nFitAstrom       = in[i].nFitAstrom;
+    out[i].nFitPhotom       = in[i].nFitPhotom;
+    out[i].photom_map_id    = in[i].photom_map_id;
+    out[i].astrom_map_id    = in[i].astrom_map_id;
+  }
+  return (out);
+}
+
+PhotCode *PhotCode_PS1_V3_To_Internal (PhotCode_PS1_V3 *in, off_t Nvalues) {
+
+  off_t i;
+  PhotCode *out;
+
+  ALLOCATE_ZERO (out, PhotCode, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
+    out[i].name[31] = 0; // force termination
+
+    out[i].code  = in[i].code;         
+    out[i].type  = in[i].type;         
+    out[i].C     = in[i].C;            
+    out[i].dC 	 = in[i].dC;           
+    out[i].dX 	 = in[i].dX;           
+    out[i].K  	 = in[i].K;            
+    out[i].c1 	 = in[i].c1;           
+    out[i].c2 	 = in[i].c2;           
+    out[i].equiv = in[i].equiv;        
+    out[i].Nc    = in[i].Nc;           
+    memcpy (out[i].X, in[i].X, 4*sizeof(float));            
+
+    out[i].astromErrSys      = in[i].astromErrSys;
+    out[i].astromErrScale    = in[i].astromErrScale;
+    out[i].astromErrMagScale = in[i].astromErrMagScale;
+    out[i].photomErrSys      = in[i].photomErrSys;
+
+    out[i].photomPoorMask      = in[i].photomPoorMask;
+    out[i].photomBadMask       = in[i].photomBadMask;
+    out[i].astromPoorMask      = in[i].astromPoorMask;
+    out[i].astromBadMask       = in[i].astromBadMask;
+  }
+  return (out);
+}
+
+PhotCode_PS1_V3 *PhotCode_Internal_To_PS1_V3 (PhotCode *in, off_t Nvalues) {
+
+  off_t i;
+  PhotCode_PS1_V3 *out;
+
+  ALLOCATE_ZERO (out, PhotCode_PS1_V3, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
+    out[i].name[31] = 0; // force termination
+
+    out[i].code  = in[i].code;         
+    out[i].type  = in[i].type;         
+    out[i].C     = in[i].C;            
+    out[i].dC 	 = in[i].dC;           
+    out[i].dX 	 = in[i].dX;           
+    out[i].K  	 = in[i].K;            
+    out[i].c1 	 = in[i].c1;           
+    out[i].c2 	 = in[i].c2;           
+    out[i].equiv = in[i].equiv;        
+    out[i].Nc    = in[i].Nc;           
+    memcpy (out[i].X, in[i].X, 4*sizeof(float));            
+
+    out[i].astromErrSys      = in[i].astromErrSys;
+    out[i].astromErrScale    = in[i].astromErrScale;
+    out[i].astromErrMagScale = in[i].astromErrMagScale;
+    out[i].photomErrSys      = in[i].photomErrSys;
+
+    out[i].photomPoorMask      = in[i].photomPoorMask;
+    out[i].photomBadMask       = in[i].photomBadMask;
+    out[i].astromPoorMask      = in[i].astromPoorMask;
+    out[i].astromBadMask       = in[i].astromBadMask;
+  }
+  return (out);
+}
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_elixir.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 33397)
@@ -158,4 +158,8 @@
     out[i].Npos       	 = 0.0;
     out[i].extID 	 = 0;
+
+    // added in PS1_V3
+    out[i].photFlagsUpper = 0;
+    out[i].photFlagsLower = 0;
   }
   return (out);
@@ -215,4 +219,8 @@
     // changed or added for PS1_V2
     out[i].flags = 0;
+
+    // added in PS1_V3
+    out[i].Map         = 0;
+    out[i].ubercalDist = 0;
   }
   return (out);
@@ -271,5 +279,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].ubercalDist	    = in[i].dummy3; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
@@ -341,5 +349,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].dummy3	    = in[i].ubercalDist; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_loneos.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 33397)
@@ -150,4 +150,8 @@
     out[i].Npos       	 = 0.0;
     out[i].extID 	 = 0;
+
+    // added in PS1_V3
+    out[i].photFlagsUpper = 0;
+    out[i].photFlagsLower = 0;
   }
   return (out);
@@ -208,4 +212,8 @@
     // changed or added for PS1_V2
     out[i].flags = 0;
+
+    // added in PS1_V3
+    out[i].Map         = 0;
+    out[i].ubercalDist = 0;
   }
   return (out);
@@ -264,5 +272,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].ubercalDist	    = in[i].dummy3; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
@@ -334,5 +342,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].dummy3	    = in[i].ubercalDist; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 33397)
@@ -154,4 +154,8 @@
     out[i].Npos       	 = 0.0;
     out[i].extID 	 = 0;
+
+    // added in PS1_V3
+    out[i].photFlagsUpper = 0;
+    out[i].photFlagsLower = 0;
   }
   return (out);
@@ -215,4 +219,8 @@
     // changed or added for PS1_V2
     out[i].flags = 0;
+
+    // added in PS1_V3
+    out[i].Map         = 0;
+    out[i].ubercalDist = 0;
  }
   return (out);
@@ -278,5 +286,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].ubercalDist	    = in[i].dummy3; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
@@ -347,5 +355,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].dummy3	    = in[i].ubercalDist; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 33397)
@@ -154,4 +154,8 @@
     out[i].Npos       	 = 0.0;
     out[i].extID 	 = 0;
+
+    // added in PS1_V3
+    out[i].photFlagsUpper = 0;
+    out[i].photFlagsLower = 0;
   }
   return (out);
@@ -215,4 +219,8 @@
     // changed or added for PS1_V2
     out[i].flags = 0;
+
+    // added in PS1_V3
+    out[i].Map         = 0;
+    out[i].ubercalDist = 0;
  }
   return (out);
@@ -278,5 +286,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].ubercalDist	    = in[i].dummy3; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
@@ -347,5 +355,5 @@
     out[i].nLinkAstrom	    = in[i].nLinkAstrom;
     out[i].nLinkPhotom	    = in[i].nLinkPhotom;
-    out[i].dummy3	    = in[i].dummy3;
+    out[i].dummy3	    = in[i].ubercalDist; // new name PS1_V3
     out[i].dXpixSys	    = in[i].dXpixSys;
     out[i].dYpixSys	    = in[i].dYpixSys;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_image.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_image.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_image.c	(revision 33397)
@@ -211,4 +211,5 @@
   if (db[0].format == DVO_FORMAT_PS1_V1)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V1");
   if (db[0].format == DVO_FORMAT_PS1_V2)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V2");
+  if (db[0].format == DVO_FORMAT_PS1_V3)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V3");
   if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_REF");
   
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_image_raw.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 33396)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 33397)
@@ -57,4 +57,5 @@
   if (db[0].format == DVO_FORMAT_PS1_V1)          ImageSize = sizeof(Image_PS1_V1);
   if (db[0].format == DVO_FORMAT_PS1_V2)          ImageSize = sizeof(Image_PS1_V2);
+  if (db[0].format == DVO_FORMAT_PS1_V3)          ImageSize = sizeof(Image_PS1_V3);
   if (db[0].format == DVO_FORMAT_PS1_REF)         ImageSize = sizeof(Image_PS1_REF);
 
@@ -85,4 +86,5 @@
   if (db[0].format == DVO_FORMAT_PS1_V1)          gfits_table_mkheader_Image_PS1_V1 (&db[0].theader);
   if (db[0].format == DVO_FORMAT_PS1_V2)          gfits_table_mkheader_Image_PS1_V2 (&db[0].theader);
+  if (db[0].format == DVO_FORMAT_PS1_V3)          gfits_table_mkheader_Image_PS1_V3 (&db[0].theader);
   if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_table_mkheader_Image_PS1_REF (&db[0].theader);
     
