Index: /branches/eam_branch_20090208/Ohana/src/libautocode/Makefile.Targets
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/Makefile.Targets	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/Makefile.Targets	(revision 21418)
@@ -1,3 +1,2 @@
-
 AOBJS = \
 $(ASRC)/coords.$(ARCH).o \
@@ -9,4 +8,5 @@
 $(ASRC)/average-ps1-dev-1.$(ARCH).o \
 $(ASRC)/average-ps1-dev-2.$(ARCH).o \
+$(ASRC)/average-ps1-v1.$(ARCH).o \
 $(ASRC)/secfilt.$(ARCH).o \
 $(ASRC)/secfilt-loneos.$(ARCH).o \
@@ -16,4 +16,5 @@
 $(ASRC)/secfilt-ps1-dev-1.$(ARCH).o \
 $(ASRC)/secfilt-ps1-dev-2.$(ARCH).o \
+$(ASRC)/secfilt-ps1-v1.$(ARCH).o \
 $(ASRC)/measure.$(ARCH).o \
 $(ASRC)/measure-loneos.$(ARCH).o \
@@ -23,4 +24,5 @@
 $(ASRC)/measure-ps1-dev-1.$(ARCH).o \
 $(ASRC)/measure-ps1-dev-2.$(ARCH).o \
+$(ASRC)/measure-ps1-v1.$(ARCH).o \
 $(ASRC)/missing.$(ARCH).o \
 $(ASRC)/photcode.$(ARCH).o \
@@ -29,4 +31,5 @@
 $(ASRC)/photcode-ps1-dev-2.$(ARCH).o \
 $(ASRC)/photcode-ps1-dev-3.$(ARCH).o \
+$(ASRC)/photcode-ps1-v1.$(ARCH).o \
 $(ASRC)/image.$(ARCH).o \
 $(ASRC)/image-loneos.$(ARCH).o \
@@ -37,4 +40,5 @@
 $(ASRC)/image-ps1-dev-2.$(ARCH).o \
 $(ASRC)/image-ps1-dev-3.$(ARCH).o \
+$(ASRC)/image-ps1-v1.$(ARCH).o \
 $(ASRC)/regimage.$(ARCH).o \
 $(ASRC)/detreg.$(ARCH).o \
@@ -63,4 +67,5 @@
 $(AINC)/average-ps1-dev-1.h \
 $(AINC)/average-ps1-dev-2.h \
+$(AINC)/average-ps1-v1.h \
 $(AINC)/secfilt.h \
 $(AINC)/secfilt-loneos.h \
@@ -70,4 +75,5 @@
 $(AINC)/secfilt-ps1-dev-1.h \
 $(AINC)/secfilt-ps1-dev-2.h \
+$(AINC)/secfilt-ps1-v1.h \
 $(AINC)/measure.h \
 $(AINC)/measure-loneos.h \
@@ -77,4 +83,5 @@
 $(AINC)/measure-ps1-dev-1.h \
 $(AINC)/measure-ps1-dev-2.h \
+$(AINC)/measure-ps1-v1.h \
 $(AINC)/missing.h \
 $(AINC)/photcode.h \
@@ -83,4 +90,5 @@
 $(AINC)/photcode-ps1-dev-2.h \
 $(AINC)/photcode-ps1-dev-3.h \
+$(AINC)/photcode-ps1-v1.h \
 $(AINC)/image.h \
 $(AINC)/image-loneos.h \
@@ -91,4 +99,5 @@
 $(AINC)/image-ps1-dev-2.h \
 $(AINC)/image-ps1-dev-3.h \
+$(AINC)/image-ps1-v1.h \
 $(AINC)/regimage.h \
 $(AINC)/detreg.h \
Index: /branches/eam_branch_20090208/Ohana/src/libautocode/def/average-ps1-v1.d
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/def/average-ps1-v1.d	(revision 21418)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/def/average-ps1-v1.d	(revision 21418)
@@ -0,0 +1,40 @@
+STRUCT       Average_PS1_V1
+EXTNAME      DVO_AVERAGE_PS1_V1
+TYPE         BINTABLE
+SIZE         96
+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 Xp,             SIGMA_POS,   float, 	    position scatter,   	  1/100 arcsec
+FIELD ChiSq,          CHISQ_POS,   float, 	    astrometry analysis chisq
+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)
+
+# 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)
Index: /branches/eam_branch_20090208/Ohana/src/libautocode/def/average.d
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/def/average.d	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/def/average.d	(revision 21418)
@@ -2,43 +2,41 @@
 EXTNAME      DVO_AVERAGE
 TYPE         BINTABLE
-SIZE         80
+SIZE         94
 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 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 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 Xp,             SIGMA_POS,   short,           position scatter,             1/100 arcsec
+FIELD ChiSq,          CHISQ_POS,   float,           astrometry analysis chisq
+FIELD Npos,           NUMBER_POS,  unsigned short,  number of detections used for astrometry
 
-FIELD Xp,             SIGMA_POS,   short, 	    position scatter,   	  1/100 arcsec
+# 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, int,     	    offset to first psf measurement
-FIELD missingOffset,  OFF_MISSING, int,     	    offset to first missing obs
-FIELD extendOffset,   OFF_EXTEND,  int,     	    offset to first extended measurement
 
-FIELD code,           code,       unsigned short,   ID code (star; ghost; etc)
-FIELD dummy,          DUMMY,      char[2],          padding
+FIELD measureOffset,  OFF_MEASURE, int,             offset to first psf measurement
+FIELD missingOffset,  OFF_MISSING, int,             offset to first missing obs
+FIELD extendOffset,   OFF_EXTEND,  int,             offset to first extended measurement
 
-# Pan-STARRS uses a 64-bit detection ID.  keep this in two 32 bit ints
-# for C89 compatibility.  The objID is constructed based on the
-# position of first instatiation.  this is actually quite expensive
-# because we need to include the uniqueness test to construct this,
-# which requires a select for each new object.  Therefore, I will use
-# a table based ID (table ID + object ID), and we will have to
-# re-number the object IDs if we change the table density, OR treat
-# all subdivisions as entries which are from a foreign table.
+# 'flags' was called 'code' prior to 2009.02.07
+FIELD flags,          FLAGS,       uint32_t,        average object flags (star; ghost; etc)
 
-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
+# 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)
 
 # this structure should only be used for internal representations
@@ -47,6 +45,3 @@
 # the index for the secfilt table is just Nsecfilt times the index for the average table.
 
-# the DVO object IDs are generated internally and are not equivalent to the PSPS object IDs
-# probably need to add position chisq
-
-# XXX include the number of measurements used to determine the positional information?
+# *** 20090206 : new fields : ChiSq, Npos, flags (was code, uint16_t), extID
Index: /branches/eam_branch_20090208/Ohana/src/libautocode/def/cmf-ps1-v1.d
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/def/cmf-ps1-v1.d	(revision 21418)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/def/cmf-ps1-v1.d	(revision 21418)
@@ -0,0 +1,26 @@
+# name of structure type
+STRUCT  CMF_PS1_V1
+EXTNAME CMF_PS1_V1
+TYPE    BINTABLE
+SIZE    72
+
+# elements of data structure / FITS table
+FIELD detID,     IPP_IDET,     	   unsigned int, detection ID
+FIELD X,      	 X_PSF,    	   float,    x coord,              pixels
+FIELD Y,      	 Y_PSF,    	   float,    y coord,              pixels
+FIELD dX,      	 X_PSF_SIG,    	   float,    x coord error,        pixels
+FIELD dY,      	 Y_PSF_SIG,    	   float,    y coord error,        pixels
+FIELD M,      	 PSF_INST_MAG,     float,    inst mags,            mags
+FIELD dM,     	 PSF_INST_MAG_SIG, float,    inst mag error,       mags
+FIELD Mpeak,     PEAK_FLUX_AS_MAG, float,    inst mag error,       mags
+FIELD sky,    	 SKY,              float,    sky flux,             cnts/sec
+FIELD dSky,    	 SKY_SIG,          float,    sky flux errorf       cnts/sec
+FIELD psfChisq,  PSF_CHISQ,        float,    psf fit chisq
+FIELD crNsigma,  CR_NSIGMA,        float,    Nsigma deviations from PSF to CF
+FIELD extNsigma, EXT_NSIGMA,       float,    Nsigma deviations from PSF to EXT
+FIELD fx,     	 PSF_WIDTH_X,      float,    semi-major,           pixels
+FIELD fy,     	 PSF_WIDTH_Y,      float,    semi-minor,           pixels
+FIELD df,     	 PSF_THETA,        float,    ellipse angle,        degrees
+FIELD psfQual, 	 PSF_QF,           float,    quality factor
+FIELD nFrames, 	 N_FRAMES,         short,    images overlapping peak
+FIELD flags,  	 FLAGS,            short,    padding
Index: /branches/eam_branch_20090208/Ohana/src/libautocode/def/getstar-ps1-v1.d
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/def/getstar-ps1-v1.d	(revision 21418)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/def/getstar-ps1-v1.d	(revision 21418)
@@ -0,0 +1,17 @@
+STRUCT       Getstar_PS1_V1
+EXTNAME      GETSTAR_PS1_V1
+TYPE         BINTABLE
+SIZE         32
+DESCRIPTION  Getstar output file
+
+# elements of data structure / FITS table
+
+# average R,D are epoch & equinox J2000.0
+FIELD R,              RA,         double,           RA,                	       	  decimal degrees 
+FIELD D,              DEC,        double,           DEC,               	       	  decimal degrees 
+FIELD mag,            MAG,        float,            average magnitude in requested photcode
+FIELD c1,             MAG_C1,     float,            average magnitude in color term 1
+FIELD c2,             MAG_C2,     float,            average magnitude in color term 2
+
+FIELD photcode,       PHOTCODE,   unsigned short,   photcode for this mag
+FIELD code,           CODE,       unsigned short,   ID code (star; ghost; etc)
Index: /branches/eam_branch_20090208/Ohana/src/libautocode/def/image-ps1-v1.d
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/def/image-ps1-v1.d	(revision 21418)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/def/image-ps1-v1.d	(revision 21418)
@@ -0,0 +1,72 @@
+STRUCT       Image_PS1_V1
+EXTNAME      DVO_IMAGE_PS1_V1
+TYPE         BINTABLE
+SIZE         344
+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
+
+# 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 	  order,            ORDER,                short,      	  Mrel 2D polynomical order 
+FIELD 	  Mx,               MX,                   short,      	  Mrel polyterm
+FIELD 	  My,               MY,                   short,      	  Mrel polyterm
+FIELD 	  Mxx,              MXX,                  short,      	  Mrel polyterm
+FIELD 	  Mxy,              MXY,                  short,      	  Mrel polyterm
+FIELD 	  Myy,              MYY,                  short,      	  Mrel polyterm
+FIELD 	  Mxxx,             MXXX,                 short,      	  Mrel polyterm
+FIELD 	  Mxxy,             MXXY,                 short,      	  Mrel polyterm
+FIELD 	  Mxyy,             MXYY,                 short,      	  Mrel polyterm
+FIELD 	  Myyy,             MYYY,                 short,      	  Mrel polyterm
+FIELD 	  Mxxxx,            MXXXX,                short,      	  Mrel polyterm
+FIELD 	  Mxxxy,            MXXXY,                short,      	  Mrel polyterm
+FIELD 	  Mxxyy,            MXXYY,                short,      	  Mrel polyterm
+FIELD 	  Mxyyy,            MXYYY,                short,      	  Mrel polyterm
+FIELD 	  Myyyy,            MYYYY,                short,      	  Mrel polyterm
+# 40 bytes
Index: /branches/eam_branch_20090208/Ohana/src/libautocode/def/image.d
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/def/image.d	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/def/image.d	(revision 21418)
@@ -40,5 +40,5 @@
 # 40 bytes
 
-FIELD 	  name,             NAME,                 char[128],      name of original image 
+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
@@ -47,10 +47,8 @@
 FIELD 	  fwhm_y,           FWHM_Y,               unsigned char,  PSF y width,               25*arcsec
 FIELD 	  trate,            TRATE,                unsigned char,  scan rate,                 100 usec/pixel
-FIELD 	  code,             CODE,                 char,           image quality flag
 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
-
-# XXX do we want to use this to handle mosaics?
-# FIELD 	  parentID,         PARENT_ID,            unsigned int,   associated ref image
+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
@@ -73,2 +71,4 @@
 FIELD 	  Myyyy,            MYYYY,                short,      	  Mrel polyterm
 # 40 bytes
+
+# *** 20090206 : new fields : parentID, flags (was code char), changed name to 121 bytes.
Index: /branches/eam_branch_20090208/Ohana/src/libautocode/def/measure-ps1-v1.d
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/def/measure-ps1-v1.d	(revision 21418)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/def/measure-ps1-v1.d	(revision 21418)
@@ -0,0 +1,66 @@
+STRUCT       Measure_PS1_V1
+EXTNAME      DVO_MEASURE_PS1_V1
+TYPE         BINTABLE
+SIZE         139
+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 Map_small,      M_APER_SMALL, float,          small 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 t_msec,         TIME_MSEC,    unsigned short, time fraction of second,       milliseconds
+FIELD averef,         AVE_REF,      unsigned int,   reference to average entry      
+
+# Pan-STARRS uses a 64-bit detection ID.  keep this in two 32 bit ints for backwards compatibility?
+FIELD detID,          DET_ID,       unsigned int,   detection ID
+FIELD imageID,        IMAGE_ID,     unsigned int,   reference to DVO image 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 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 arcsec 
+FIELD FWy,            FWHM_MINOR,   short,          object fwhm minor axis,       1/100 of arcsec 
+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 arcsec 
+FIELD Mxy,            MXY,          short,          second moments in pixel coords, 1/100 of arcsec
+FIELD Myy,            MYY,          short,          second moments in pixel coords, 1/100 of arcsec
+
+# position errors
+FIELD dXccd,          X_CCD_ERR,    short,          X coord error on chip,         pixels
+FIELD dYccd,          Y_CCD_ERR,    short,          Y coord error on chip,         pixels
+FIELD dTccd,          T_CCD_ERR,    short,          position angle chip to sky,    (0xffff/360) deg
+
+FIELD photcode,       PHOTCODE,     unsigned short, photcode
+
+FIELD dbFlags,        DB_FLAGS,     uint64_t,       flags supplied by analysis in database
+FIELD photFlags,      PHOT_FLAGS,   uint64_t,       flags supplied by photometry program
+
+FIELD stargal,        STAR_GAL,     char,           star-galaxy separator
+
+# FIELD dummy,          DUMMY,        char[6],        padding
Index: /branches/eam_branch_20090208/Ohana/src/libautocode/def/measure.d
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/def/measure.d	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/def/measure.d	(revision 21418)
@@ -2,5 +2,5 @@
 EXTNAME      DVO_MEASURE
 TYPE         BINTABLE
-SIZE         112
+SIZE         139
 DESCRIPTION  DVO Detection Measurement Table 
 
@@ -10,7 +10,9 @@
 FIELD Mcal,           M_CAL,        float,          image cal mag,	          mag
 FIELD Map,            M_APER,       float,          aperture mag,		  mag
+FIELD Map_small,      M_APER_SMALL, float,          small 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
@@ -26,5 +28,6 @@
 FIELD dSky,           SKY_FLUX_ERR, float,          local estimate of sky flux,    counts/sec
 
-FIELD t,              TIME,         unsigned int,   time in seconds (UNIX)
+FIELD t,              TIME,         int,   	    time in seconds (UNIX)
+FIELD t_msec,         TIME_MSEC,    unsigned short, time fraction of second,       milliseconds
 FIELD averef,         AVE_REF,      unsigned int,   reference to average entry      
 
@@ -32,7 +35,8 @@
 FIELD detID,          DET_ID,       unsigned int,   detection ID
 FIELD imageID,        IMAGE_ID,     unsigned int,   reference to DVO image 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 qPSF,           PSF_QF,       float,          psf coverage/quality factor
+FIELD psfQual,        PSF_QF,       float,          psf coverage/quality factor
 FIELD psfChisq,       PSF_CHISQ,    float,          psf fit chisq
 FIELD crNsigma,       CR_NSIGMA,    float,          Nsigma deviation towards CR
@@ -42,17 +46,23 @@
 FIELD FWy,            FWHM_MINOR,   short,          object fwhm minor axis,       1/100 of arcsec 
 FIELD theta,          PSF_THETA,    short,          angle wrt ccd X dir,          (0xffff/360) deg
-FIELD photcode,       PHOTCODE,     unsigned short, photcode
+
+# moments
+FIELD Mxx,            MXX,          short,          second moments in pixel coords, 1/100 of arcsec 
+FIELD Mxy,            MXY,          short,          second moments in pixel coords, 1/100 of arcsec
+FIELD Myy,            MYY,          short,          second moments in pixel coords, 1/100 of arcsec
 
 # convert this to error in arcsec on load?
 FIELD dXccd,          X_CCD_ERR,    short,          X coord error on chip,         pixels
 FIELD dYccd,          Y_CCD_ERR,    short,          Y coord error on chip,         pixels
+FIELD dTccd,          T_CCD_ERR,    short,          position angle chip to sky,    (0xffff/360) deg
 
-FIELD dbFlags,        DB_FLAGS,     unsigned short, flags for various uses  
-FIELD photFlags,      PHOT_FLAGS,   unsigned short, flags supplied by photometry program
+FIELD photcode,       PHOTCODE,     unsigned short, photcode
+FIELD dbFlags,        DB_FLAGS,     uint64_t,       flags supplied by analysis in database
+FIELD photFlags,      PHOT_FLAGS,   uint64_t,       flags supplied by photometry program
 
 FIELD stargal,        STAR_GAL,     char,           star-galaxy separator
 
-# absorb these into photFlags?
-FIELD dophot,         DOPHOT,       char,           dophot type
+# *** 20090206 : new fields : t_msec, extID, Mxx, Mxy, Myy, dTccd; deprecated dophot
+#                dbFlags, photFlags : uint16_t to uint64_t
 
-FIELD dummy,          DUMMY,        char[6],        padding
+# XXX unsigned int values are probably not being saved in the FITS file correctly: no BZERO, BSCALE
Index: /branches/eam_branch_20090208/Ohana/src/libautocode/def/photcode-ps1-v1.d
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/def/photcode-ps1-v1.d	(revision 21418)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/def/photcode-ps1-v1.d	(revision 21418)
@@ -0,0 +1,33 @@
+STRUCT       PhotCode_PS1_V1
+EXTNAME      DVO_PHOTCODE_PS1_V1
+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_branch_20090208/Ohana/src/libautocode/def/secfilt-ps1-v1.d
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/def/secfilt-ps1-v1.d	(revision 21418)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/def/secfilt-ps1-v1.d	(revision 21418)
@@ -0,0 +1,14 @@
+STRUCT       SecFilt_PS1_V1
+EXTNAME      DVO_SECFILT_PS1_V1
+TYPE         BINTABLE
+SIZE         20
+DESCRIPTION  DVO SecFilt : Secondary Filter Data 
+
+# elements of data structure / FITS table
+FIELD  M,     MAG,      float,                average mag in this band, mags
+FIELD  dM,    MAG_ERR,  float,                error on average mag,     mags
+FIELD  Xm,    MAG_CHI,  float,                chisq on average mag,     [100*log(value)]
+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
Index: /branches/eam_branch_20090208/Ohana/src/libautocode/def/secfilt.d
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/def/secfilt.d	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/def/secfilt.d	(revision 21418)
@@ -2,5 +2,5 @@
 EXTNAME      DVO_SECFILT
 TYPE         BINTABLE
-SIZE         16
+SIZE         18
 DESCRIPTION  DVO SecFilt : Secondary Filter Data 
 
@@ -11,3 +11,6 @@
 FIELD  Ncode, NCODE,    short,                number of detections in band
 FIELD  Nused, NUSED,    short,                number of detections used in average
-FIELD  dummy, JUNK,     short,                place holder
+FIELD  M_20,  MAG_20,   short,                lower 20percent mag,      millimags
+FIELD  M_80,  MAG_80,   short,                upper 20percent mag,      millimags
+
+# *** 20090206 : new fields : M_20, M_80; dropped dummy
Index: /branches/eam_branch_20090208/Ohana/src/libautocode/doc/autocode.txt
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/doc/autocode.txt	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/doc/autocode.txt	(revision 21418)
@@ -1,2 +1,12 @@
+
+2009.02.07
+
+The autocode tables currently use type names which are ambiguous in
+terms of their actual sizes in bits.  I've added the intNN_t and
+uintNN_t types -- this requires --use-gnu99 with configure
+
+see libdvo/doc/notes.txt for instructions on adding new dvo catalog formats
+
+2007.00.00
 
 This directory contains a collection of autocoded FITS I/O routines
Index: /branches/eam_branch_20090208/Ohana/src/libautocode/generate
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libautocode/generate	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libautocode/generate	(revision 21418)
@@ -114,4 +114,5 @@
 	
 	# rawshort is a short without byteswapping
+	# rawshort is a patch for old photreg tables
 
 	$pt1 = 0;
@@ -124,8 +125,22 @@
 	if ($type eq "int")    	      { $pt1 = "J"; }
 	if ($type eq "unsigned int")  { $pt1 = "J"; }
-	if ($type eq "e_time") 	      { $pt1 = "J"; }
+
+	if ($type eq "int8_t") 	      { $pt1 = "B"; }
+	if ($type eq "uint8_t")       { $pt1 = "B"; }
+	if ($type eq "int16_t")       { $pt1 = "I"; }
+	if ($type eq "uint16_t")      { $pt1 = "I"; }
+	if ($type eq "int32_t")       { $pt1 = "J"; }
+	if ($type eq "uint32_t")      { $pt1 = "J"; }
+
+	# FITS tables do not allow for 64bit integers.  we need to
+	# write these by splitting the value into high and low 32 bit values
+	if ($type eq "int64_t")       { $pt1 = "J"; $Np = 2*$Np; }
+	if ($type eq "uint64_t")      { $pt1 = "J"; $Np = 2*$Np; }
+
 	if ($type eq "float")  	      { $pt1 = "E"; }
 	if ($type eq "double") 	      { $pt1 = "D"; }
 
+	# special 'elixir' types:
+	if ($type eq "e_time") 	      { $pt1 = "J"; }
 	if ($type eq "e_void") 	      { $pt1 = "B"; $Np = 8*$Np; }
 	# e_void is a 64 bit pointer, cast to size_t.  its value is not loaded
@@ -146,5 +161,4 @@
 	printf FILE "%-20s 1.0, 0.0);\n", "\"$unit[$i]\", ";
     }
-
 }
 
@@ -217,8 +231,22 @@
 	if ($type eq "int")    	      { $pt1 = sprintf "I%s", $length; }
 	if ($type eq "unsigned int")  { $pt1 = sprintf "I%s", $length; }
-	if ($type eq "e_time") 	      { $pt1 = sprintf "I%s", $length; }
+
+	if ($type eq "int8_t") 	      { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "uint8_t")       { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "int16_t")       { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "uint16_t")      { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "int32_t")       { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "uint32_t")      { $pt1 = sprintf "I%s", $length; }
+
+	# FITS tables do not allow for 64bit integers.  we need to
+	# write these by splitting the value into high and low 32 bit values
+	if ($type eq "int64_t")       { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "uint64_t")      { $pt1 = sprintf "I%s", $length; }
+
 	if ($type eq "float")  	      { $pt1 = sprintf "F%s", $length; }
 	if ($type eq "double") 	      { $pt1 = sprintf "F%s", $length; }
 
+	# special 'elixir' types:
+	if ($type eq "e_time") 	      { $pt1 = sprintf "I%s", $length; }
 	if ($type eq "e_void") 	      { $pt1 = sprintf "I%s", $length; }
 
@@ -283,12 +311,29 @@
 	if ($type eq "unsigned char") { $N +=   $Np; next; }
 	if ($type eq "rawshort")      { $N += 2*$Np; next; }
+
 	if ($type eq "short")  	      { $T = "BYTE"; $n = 2; }
 	if ($type eq "unsigned short"){ $T = "BYTE"; $n = 2; }
 	if ($type eq "int")    	      { $T = "WORD"; $n = 4; }
 	if ($type eq "unsigned int")  { $T = "WORD"; $n = 4; }
+
+	if ($type eq "int8_t") 	      { $N +=   $Np; next; }
+	if ($type eq "uint8_t")       { $N +=   $Np; next; }
+	if ($type eq "int16_t")       { $T = "BYTE"; $n = 2; }
+	if ($type eq "uint16_t")      { $T = "BYTE"; $n = 2; }
+	if ($type eq "int32_t")       { $T = "WORD"; $n = 4; }
+	if ($type eq "uint32_t")      { $T = "WORD"; $n = 4; }
+
+	# FITS tables do not allow for 64bit integers.  we need to
+	# write these by splitting the value into high and low 32 bit values
+	if ($type eq "int64_t")       { $T = "WORD"; $n = 4; $Np = 2*$Np; }
+	if ($type eq "uint64_t")      { $T = "WORD"; $n = 4; $Np = 2*$Np; }
+
+	if ($type eq "float")  	      { $T = "WORD"; $n = 4; }
+	if ($type eq "double") 	      { $T = "DBLE"; $n = 8; }
+
+	# special 'elixir' types:
 	if ($type eq "e_time") 	      { $T = "WORD"; $n = 4; }
 	if ($type eq "e_void") 	      { $T = "DBLE"; $n = 8; }
-	if ($type eq "float")  	      { $T = "WORD"; $n = 4; }
-	if ($type eq "double") 	      { $T = "DBLE"; $n = 8; }
+
 	if (!$n) { die "unknown type $type"; }
 	for ($j = 0; $j < $Np; $j++) {
@@ -318,8 +363,23 @@
 	if ($type eq "int")    	       { $Nbytes += 4*$Np; $valid = 1; }
 	if ($type eq "unsigned int")   { $Nbytes += 4*$Np; $valid = 1; }
+
+	if ($type eq "int8_t") 	       { $Nbytes += 1*$Np; $valid = 1; }
+	if ($type eq "uint8_t")        { $Nbytes += 1*$Np; $valid = 1; }
+	if ($type eq "int16_t")        { $Nbytes += 2*$Np; $valid = 1; }
+	if ($type eq "uint16_t")       { $Nbytes += 2*$Np; $valid = 1; }
+	if ($type eq "int32_t")        { $Nbytes += 4*$Np; $valid = 1; }
+	if ($type eq "uint32_t")       { $Nbytes += 4*$Np; $valid = 1; }
+
+	# FITS tables do not allow for 64bit integers.  we need to
+	# write these by splitting the value into high and low 32 bit values
+	if ($type eq "int64_t")        { $Nbytes += 8*$Np; $valid = 1; }
+	if ($type eq "uint64_t")       { $Nbytes += 8*$Np; $valid = 1; }
+
+	if ($type eq "float")  	       { $Nbytes += 4*$Np; $valid = 1; }
+	if ($type eq "double") 	       { $Nbytes += 8*$Np; $valid = 1; }
+
+	# special 'elixir' types:
 	if ($type eq "e_time") 	       { $Nbytes += 4*$Np; $valid = 1; }
 	if ($type eq "e_void") 	       { $Nbytes += 8*$Np; $valid = 1; }
-	if ($type eq "float")  	       { $Nbytes += 4*$Np; $valid = 1; }
-	if ($type eq "double") 	       { $Nbytes += 8*$Np; $valid = 1; }
 	if (!$valid) { die "unknown type $type"; }
     }
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/Makefile
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/Makefile	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/Makefile	(revision 21418)
@@ -31,5 +31,6 @@
 $(DESTINC)/ps1_dev_1_defs.h \
 $(DESTINC)/ps1_dev_2_defs.h \
-$(DESTINC)/ps1_dev_3_defs.h
+$(DESTINC)/ps1_dev_3_defs.h \
+$(DESTINC)/ps1_v1_defs.h
 
 INCS = $(DEFS) $(DESTINC)/dvo.h $(DESTINC)/autocode.h
@@ -65,4 +66,5 @@
 $(SRC)/dvo_convert_PS1_DEV_2.$(ARCH).o \
 $(SRC)/dvo_convert_PS1_DEV_3.$(ARCH).o \
+$(SRC)/dvo_convert_PS1_V1.$(ARCH).o \
 $(SRC)/skyregion_io.$(ARCH).o    \
 $(SRC)/skyregion_gsc.$(ARCH).o    \
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/doc/notes.txt
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/doc/notes.txt	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/doc/notes.txt	(revision 21418)
@@ -2,9 +2,9 @@
 Adding a new dvo catalog format.  Assume the new format name is 'foo'.
 
-1) create the autocode definition files for average, measure, secfilt, image
-   these files must be a subset of the internal versions of these same
-   tables.  if you intend to add fields which don't exist in the
-   internal tables, you must update the internal tables as well.  the
-   naming convention is: average-foo.d, etc.
+1) create the autocode definition files for average, measure, secfilt,
+   image, and photcode.  these files must be a subset of the internal
+   versions of these same tables.  if you intend to add fields which
+   don't exist in the internal tables, you must update the internal
+   tables as well.  the naming convention is: average-foo.d, etc.
 
 2) add the new definition files to libautocode/Makefile.Targets (both
@@ -22,19 +22,26 @@
  (libdvo/src/dvo_catalog.c).  The name should be "FOO".
 
-6) add entry for structure size in dvo_catalog_load_raw
-   (libdvo/src/dvo_catalog_raw.c), since this is not available from
-   the header.
+6) in libdvo/src/dvo_catalog_raw.c, update the FORMAT_CASE lists to
+   include the new STRUCT name.
 
-7) add entries in ReadRawAverage, WriteRawAverage, ReadRawMeasure,
-   WriteRawMeasure, ReadRawSecFilt, WriteRawSecFilt.  Make sure to use
-   the new STRUCT names. the conversion function gfit_convert_Foo will
-   be automatically generated.
+7) create a new conversion file dvo_convert_foo.c and define the
+   internal to Foo conversions.
 
-8) add entry in WriteRawAverage, making sure to use the new STRUCT
-   name. the conversion function gfit_convert_Foo will be
-   automatically generated.  
+8) add the new format to the list of FORMAT conversion in dvo_convert.c.
 
-9) create a new conversion file dvo_convert_foo.c and define the
-   internal to Foo conversions.
+9) any changes to the internal format need to be reflected in the
+   functions in the dvo_convert_*.c files.  These files are defined so
+   that changed fields are sequential in the functions.  This should
+   make is easy to identify the new changes needed.
+
+10) add the new format to the section at the end of dvo_image.c
+
+11) add the new format to the dvo_image_raw.c
+
+12) add the photcode format conversions to libdvo/src/LoadPhotcodesFITS.c
+
+12) switch the output photcode format conversion ina libdvo/src/SavePhotcodesFITS.c
+
+13) Add the conversion functions to the header file libdvo/include/foo_defs.h
 
 * Note some esoteric format issues:  
@@ -54,2 +61,26 @@
     keywords.
 
+----
+
+20090207 : adding PS1_V1
+
+measure: 
+ new fields : t_msec, extID, Mxx, Mxy, Myy, dTccd; deprecated dophot
+ dbFlags, photFlags : uint16_t to uint64_t
+
+average:
+ new fields : ChiSq, Npos, flags (was code, uint16_t), extID
+
+secfilt:
+ new fields : M_20, M_80; dropped dummy
+
+image:
+ new fields : parentID, flags (was code char), changed name to 121 bytes.
+
+photcode:
+ new fields : NONE
+
+** parentID was added to enable easy lookups from chip->fpa for mosaic
+   astrometry.  In old databases, this conversion was done by making
+   the match via the time and photcode.  This conversion needs to be
+   done on load...
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/include/dvo.h	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/include/dvo.h	(revision 21418)
@@ -18,5 +18,6 @@
 	      DVO_FORMAT_PS1_DEV_1,
 	      DVO_FORMAT_PS1_DEV_2,
-	      DVO_FORMAT_PS1_DEV_3
+	      DVO_FORMAT_PS1_DEV_3,
+	      DVO_FORMAT_PS1_V1
 } DVOTableFormat;
 
@@ -407,4 +408,5 @@
 # include "ps1_dev_2_defs.h"
 # include "ps1_dev_3_defs.h"
+# include "ps1_v1_defs.h"
 
 /*** DVO image db I/O Functions ***/
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/include/ps1_v1_defs.h
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/include/ps1_v1_defs.h	(revision 21418)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/include/ps1_v1_defs.h	(revision 21418)
@@ -0,0 +1,11 @@
+Image 		       	*Image_PS1_V1_ToInternal (Image_PS1_V1 *in, int Nvalues);
+Image_PS1_V1    	*ImageInternalTo_PS1_V1 (Image *in, int Nvalues);
+Average 	       	*Average_PS1_V1_ToInternal (Average_PS1_V1 *in, int Nvalues, SecFilt **primary);
+Average_PS1_V1          *AverageInternalTo_PS1_V1 (Average *in, int Nvalues, SecFilt *primary);
+Measure 	       	*Measure_PS1_V1_ToInternal (Measure_PS1_V1 *in, int Nvalues);
+Measure_PS1_V1          *MeasureInternalTo_PS1_V1 (Measure *in, int Nvalues);
+SecFilt 	       	*SecFilt_PS1_V1_ToInternal (SecFilt_PS1_V1 *in, int Nvalues);
+SecFilt_PS1_V1          *SecFiltInternalTo_PS1_V1 (SecFilt *in, int Nvalues);
+
+PhotCode                *PhotCode_PS1_V1_To_Internal (PhotCode_PS1_V1 *in, int Nvalues);
+PhotCode_PS1_V1         *PhotCode_Internal_To_PS1_V1 (PhotCode *in, int Nvalues);
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/LoadPhotcodesFITS.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 21418)
@@ -40,5 +40,11 @@
   gfits_scan (&db.theader, "EXTNAME", "%s", 1, extname);
 
-  if (!strcmp (extname, "DVO_PHOTCODE") || !strcmp (extname, "DVO_PHOTCODE_ELIXIR")) {
+  if (!strcmp (extname, "DVO_PHOTCODE")) {
+    PhotCode_Elixir *photcode_elixir = gfits_table_get_PhotCode_Elixir (&db.ftable, &Ncode, &db.swapped);
+    photcode = PhotCode_Elixir_To_Internal (photcode_elixir, Ncode);
+    free (photcode_elixir);
+  } 
+
+  if (!strcmp (extname, "DVO_PHOTCODE_ELIXIR")) {
     PhotCode_Elixir *photcode_elixir = gfits_table_get_PhotCode_Elixir (&db.ftable, &Ncode, &db.swapped);
     photcode = PhotCode_Elixir_To_Internal (photcode_elixir, Ncode);
@@ -62,4 +68,10 @@
     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);
+    photcode = PhotCode_PS1_V1_To_Internal (photcode_ps1_v1, Ncode);
+    free (photcode_ps1_v1);
   } 
 
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/SavePhotcodesFITS.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/SavePhotcodesFITS.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/SavePhotcodesFITS.c	(revision 21418)
@@ -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_DEV_3 *photcode_output = PhotCode_Internal_To_PS1_DEV_3 (table[0].code, table[0].Ncode);
+  PhotCode_PS1_V1 *photcode_output = PhotCode_Internal_To_PS1_V1 (table[0].code, table[0].Ncode);
 
   /* convert FITS format data to internal format (byteswaps & EXTNAME) */
   gfits_db_create (&db);
-  gfits_table_set_PhotCode_PS1_DEV_3 (&db.ftable, photcode_output, table[0].Ncode);
+  gfits_table_set_PhotCode_PS1_V1 (&db.ftable, photcode_output, table[0].Ncode);
   gfits_db_save (&db);
   gfits_db_close (&db);
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_catalog.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_catalog.c	(revision 21418)
@@ -52,4 +52,5 @@
   if (!strcasecmp (catformat, "PS1_DEV_1"))       return (DVO_FORMAT_PS1_DEV_1);
   if (!strcasecmp (catformat, "PS1_DEV_2"))       return (DVO_FORMAT_PS1_DEV_2);
+  if (!strcasecmp (catformat, "PS1_V1"))          return (DVO_FORMAT_PS1_V1);
   return (DVO_FORMAT_UNDEF);
 }
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_catalog_raw.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 21418)
@@ -86,4 +86,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
@@ -271,4 +272,5 @@
   if (catalog[0].catformat == DVO_FORMAT_PS1_DEV_1)       gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_DEV_1");
   if (catalog[0].catformat == DVO_FORMAT_PS1_DEV_2)       gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_DEV_2");
+  if (catalog[0].catformat == DVO_FORMAT_PS1_V1)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V1");
 
   /* rewind file pointers and truncate file */
@@ -366,4 +368,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
@@ -412,4 +415,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
@@ -462,4 +466,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
@@ -508,4 +513,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
@@ -558,4 +564,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
@@ -604,4 +611,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert.c	(revision 21418)
@@ -49,4 +49,5 @@
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
+  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V1",          PS1_V1,          PS1_V1);
 # undef CONVERT_FORMAT
 
@@ -79,4 +80,5 @@
       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,          PS1_V1);
 # undef FORMAT_CASE
 
@@ -122,4 +124,5 @@
   CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
   CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
+  CONVERT_FORMAT ("DVO_MEASURE_PS1_V1",          PS1_V1,          PS1_V1);
 # undef CONVERT_FORMAT
 
@@ -152,4 +155,5 @@
       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,          PS1_V1);
 # undef FORMAT_CASE
 
@@ -195,4 +199,5 @@
   CONVERT_FORMAT ("DVO_SECFILT_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
   CONVERT_FORMAT ("DVO_SECFILT_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
+  CONVERT_FORMAT ("DVO_SECFILT_PS1_V1",          PS1_V1,          PS1_V1);
 # undef CONVERT_FORMAT
 
@@ -225,4 +230,5 @@
       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,          PS1_V1);
 # undef FORMAT_CASE
 
@@ -288,5 +294,9 @@
   CONVERT_FORMAT ("DVO_IMAGE_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
   CONVERT_FORMAT ("DVO_IMAGE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
-  CONVERT_FORMAT ("DVO_IMAGE_PS1_DEV_3",       PS1_DEV_3,       PS1_DEV_3);
+  CONVERT_FORMAT ("DVO_IMAGE_PS1_V1",          PS1_V1,          PS1_V1);
+
+  // XXX Not sure this was ever actually used -- it was not complete...
+  // CONVERT_FORMAT ("DVO_IMAGE_PS1_DEV_3",       PS1_DEV_3,       PS1_DEV_3);
+
 # undef CONVERT_FORMAT
 
@@ -322,5 +332,8 @@
       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
-      FORMAT_CASE (PS1_DEV_3,       PS1_DEV_3);
+      FORMAT_CASE (PS1_V1,          PS1_V1);
+
+      // XXX not sure this was actually used: it was incomplete
+      // FORMAT_CASE (PS1_DEV_3,       PS1_DEV_3);
 # undef FORMAT_CASE
 
@@ -372,5 +385,9 @@
       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
-      FORMAT_CASE (PS1_DEV_3,       PS1_DEV_3);
+      FORMAT_CASE (PS1_V1,          PS1_V1);
+
+      // XXX not sure this was used, it was incomplete
+      // FORMAT_CASE (PS1_DEV_3,       PS1_DEV_3);
+
 # undef FORMAT_CASE
 
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 21418)
@@ -15,5 +15,4 @@
     out[i].M          = in[i].M;
     out[i].Mcal       = in[i].Mcal;
-    out[i].Map        = in[i].Mgal;
     out[i].dM         = in[i].dM;
     out[i].dt         = in[i].dt;
@@ -28,5 +27,5 @@
     out[i].detID      = in[i].detID;
     out[i].imageID    = in[i].imageID;
-    out[i].qPSF       = in[i].qPSF;
+    out[i].psfQual    = in[i].psfQual;
     out[i].psfChisq   = in[i].psfChisq;
     out[i].crNsigma   = in[i].crNsigma;
@@ -41,5 +40,18 @@
     out[i].photFlags  = in[i].photFlags;
     out[i].stargal    = in[i].stargal;
-    out[i].dophot     = in[i].dophot;
+
+    // changed or added for PS1_DEV_2
+    out[i].Map        = in[i].Mgal;
+    out[i].dMcal      = 0; 
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].photFlags | (in[i].dophot << 16);
+    out[i].t_msec     = 0;
+    out[i].extID      = 0;
+    out[i].Mxx 	      = 0.0;
+    out[i].Mxy 	      = 0.0;
+    out[i].Myy        = 0.0;
+    out[i].dTccd      = 0;
+    out[i].Map_small  = 0;
   }
   return (out);
@@ -58,5 +70,4 @@
     out[i].M          = in[i].M;
     out[i].Mcal       = in[i].Mcal;
-    out[i].Mgal       = in[i].Map;
     out[i].dM         = in[i].dM;
     out[i].dt         = in[i].dt;
@@ -71,5 +82,5 @@
     out[i].detID      = in[i].detID;
     out[i].imageID    = in[i].imageID;
-    out[i].qPSF       = in[i].qPSF;
+    out[i].psfQual    = in[i].psfQual;
     out[i].psfChisq   = in[i].psfChisq;
     out[i].crNsigma   = in[i].crNsigma;
@@ -82,7 +93,12 @@
     out[i].dYccd      = in[i].dYccd;
     out[i].dbFlags    = in[i].dbFlags;
-    out[i].photFlags  = in[i].photFlags;
     out[i].stargal    = in[i].stargal;
-    out[i].dophot     = in[i].dophot;
+
+    // changed or added for PS1_DEV_2
+    out[i].Mgal       = in[i].Map;
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].photFlags & 0x0000ffff;
+    out[i].dophot     = in[i].photFlags >> 16;
   }
   return (out);
@@ -101,9 +117,4 @@
     out[i].D        	 = in[i].D;      
     out[i].Xp       	 = in[i].Xp;     
-    out[i].Nmeasure      = in[i].Nm;     
-    out[i].Nmissing      = in[i].Nn;     
-    out[i].code     	 = in[i].code;   
-    out[i].measureOffset = in[i].offset; 
-    out[i].missingOffset = in[i].missing;
     out[i].dR       	 = in[i].dR;
     out[i].dD       	 = in[i].dD;
@@ -116,4 +127,18 @@
     out[i].objID 	 = in[i].objID;
     out[i].catID 	 = in[i].catID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Nmeasure      = in[i].Nm;     
+    out[i].Nmissing      = in[i].Nn;     
+    out[i].measureOffset = in[i].offset; 
+    out[i].missingOffset = in[i].missing;
+    out[i].Nextend       = 0;
+    out[i].extendOffset  = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags    	 = in[i].code;   
+    out[i].ChiSq       	 = 0.0;
+    out[i].Npos       	 = 0.0;
+    out[i].extID 	 = 0;
   }
   return (out);
@@ -129,22 +154,26 @@
 
   for (i = 0; i < Nvalues; i++) {
-    out[i].R        = in[i].R;      
-    out[i].D        = in[i].D;      
-    out[i].Xp       = in[i].Xp;     
-    out[i].Nm       = in[i].Nmeasure;     
-    out[i].Nn       = in[i].Nmissing;     
-    out[i].code     = in[i].code;   
-    out[i].offset   = in[i].measureOffset; 
-    out[i].missing  = in[i].missingOffset;
-    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].objID    = in[i].objID;
-    out[i].catID    = in[i].catID;
+    out[i].R        	 = in[i].R;      
+    out[i].D        	 = in[i].D;      
+    out[i].Xp       	 = in[i].Xp;     
+    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].objID    	 = in[i].objID;
+    out[i].catID    	 = in[i].catID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Nm       	 = in[i].Nmeasure;     
+    out[i].Nn       	 = in[i].Nmissing;     
+    out[i].offset   	 = in[i].measureOffset; 
+    out[i].missing  	 = in[i].missingOffset;
+
+    // changed or added for PS1_V1
+    out[i].code          = in[i].flags;   
   }
   return (out);
@@ -164,4 +193,8 @@
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
+
+    // changed or added for PS1_V1
+    out[i].M_20  = 0;      
+    out[i].M_80  = 0;      
  }
   return (out);
@@ -218,5 +251,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
     out[i].imageID	    = in[i].imageID;
@@ -237,4 +269,12 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_DEV_2
+    out[i].externID	    = 0;
+    out[i].sourceID	    = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -275,5 +315,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
     out[i].imageID	    = in[i].imageID;
@@ -294,4 +333,46 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
+
+PhotCode *PhotCode_PS1_DEV_1_To_Internal (PhotCode_PS1_DEV_1 *in, int Nvalues) {
+
+  int i;
+  PhotCode *out;
+
+  ALLOCATE (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].astromErrMagScale = in[i].astromErrMagScale;
+    out[i].photomErrSys      = in[i].photomErrSys;
+
+    // changed or added for PS1_DEV_2
+    out[i].astromErrSys      = 0.0;
+    out[i].astromErrScale    = 0.0;
+
+    // changed or added for PS1_V1 (also PS1_DEV_3, deprecated)
+    out[i].photomPoorMask      = 0;
+    out[i].photomBadMask       = 0;
+    out[i].astromPoorMask      = 0;
+    out[i].astromBadMask       = 0;
   }
   return (out);
@@ -323,44 +404,5 @@
     out[i].astromErrMagScale = out[i].astromErrMagScale;
     out[i].photomErrSys      = out[i].photomErrSys;
-
-  }
-  return (out);
-}
-
-PhotCode *PhotCode_PS1_DEV_1_To_Internal (PhotCode_PS1_DEV_1 *in, int Nvalues) {
-
-  int i;
-  PhotCode *out;
-
-  ALLOCATE (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;           
-
-    // not defined in PS1_DEV_1
-    out[i].astromErrSys      = 0.0;
-    out[i].astromErrScale    = 0.0;
-    out[i].astromErrMagScale = in[i].astromErrMagScale;
-    out[i].photomErrSys      = in[i].photomErrSys;
-
-    memcpy (out[i].X, in[i].X, 4*sizeof(float));            
-
-    out[i].photomPoorMask      = 0;
-    out[i].photomBadMask       = 0;
-    out[i].astromPoorMask      = 0;
-    out[i].astromBadMask       = 0;
-  }
-  return (out);
-}
+  }
+  return (out);
+}
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 21418)
@@ -29,5 +29,5 @@
     out[i].detID      = in[i].detID;
     out[i].imageID    = in[i].imageID;
-    out[i].qPSF       = in[i].qPSF;
+    out[i].psfQual    = in[i].psfQual;
     out[i].psfChisq   = in[i].psfChisq;
     out[i].crNsigma   = in[i].crNsigma;
@@ -40,7 +40,15 @@
     out[i].dYccd      = in[i].dYccd;
     out[i].dbFlags    = in[i].dbFlags;
-    out[i].photFlags  = in[i].photFlags;
     out[i].stargal    = in[i].stargal;
-    out[i].dophot     = in[i].dophot;
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].photFlags | (in[i].dophot << 16);
+    out[i].t_msec     = 0;
+    out[i].extID      = 0;
+    out[i].Mxx 	      = 0.0;
+    out[i].Mxy 	      = 0.0;
+    out[i].Myy        = 0.0;
+    out[i].dTccd      = 0;
+    out[i].Map_small  = 0;
   }
   return (out);
@@ -73,5 +81,5 @@
     out[i].detID      = in[i].detID;
     out[i].imageID    = in[i].imageID;
-    out[i].qPSF       = in[i].qPSF;
+    out[i].psfQual    = in[i].psfQual;
     out[i].psfChisq   = in[i].psfChisq;
     out[i].crNsigma   = in[i].crNsigma;
@@ -84,7 +92,9 @@
     out[i].dYccd      = in[i].dYccd;
     out[i].dbFlags    = in[i].dbFlags;
-    out[i].photFlags  = in[i].photFlags;
     out[i].stargal    = in[i].stargal;
-    out[i].dophot     = in[i].dophot;
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].photFlags & 0x0000ffff;
+    out[i].dophot     = in[i].photFlags >> 16;
   }
   return (out);
@@ -114,5 +124,4 @@
     out[i].Nmissing      = in[i].Nmissing;     
     out[i].Nextend       = in[i].Nextend;     
-    out[i].code     	 = in[i].code;   
     out[i].measureOffset = in[i].measureOffset; 
     out[i].missingOffset = in[i].missingOffset;
@@ -120,4 +129,10 @@
     out[i].objID 	 = in[i].objID;
     out[i].catID 	 = in[i].catID;
+
+    // changed or added for PS1_V1
+    out[i].flags    	 = in[i].code;   
+    out[i].ChiSq       	 = 0.0;
+    out[i].Npos       	 = 0.0;
+    out[i].extID 	 = 0;
   }
   return (out);
@@ -147,5 +162,4 @@
     out[i].Nmissing      = in[i].Nmissing;     
     out[i].Nextend       = in[i].Nextend;     
-    out[i].code     	 = in[i].code;   
     out[i].measureOffset = in[i].measureOffset; 
     out[i].missingOffset = in[i].missingOffset;
@@ -153,4 +167,7 @@
     out[i].objID 	 = in[i].objID;
     out[i].catID 	 = in[i].catID;
+
+    // changed or added for PS1_V1
+    out[i].code     	 = in[i].flags;   
   }
   return (out);
@@ -170,4 +187,8 @@
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
+
+    // changed or added for PS1_V1
+    out[i].M_20  = 0;      
+    out[i].M_80  = 0;      
  }
   return (out);
@@ -201,5 +222,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
 
-    strncpy (out[i].name, in[i].name, 63); // out[128], int[64]
+    strncpy (out[i].name, in[i].name, 63); // out[121], int[64]
     out[i].name[63] = 0; // force termination
 
@@ -224,5 +245,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
     out[i].imageID	    = in[i].imageID;
@@ -245,4 +265,8 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -259,5 +283,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
 
-    strncpy (out[i].name, in[i].name, 63); // in[128], out[64]
+    strncpy (out[i].name, in[i].name, 63); // in[121], out[64]
     out[i].name[63] = 0; // force termination
 
@@ -282,5 +306,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
     out[i].imageID	    = in[i].imageID;
@@ -303,14 +326,17 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
-  }
-  return (out);
-}
-
-PhotCode_PS1_DEV_2 *PhotCode_Internal_To_PS1_DEV_2 (PhotCode *in, int Nvalues) {
-
-  int i;
-  PhotCode_PS1_DEV_2 *out;
-
-  ALLOCATE (out, PhotCode_PS1_DEV_2, Nvalues);
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
+
+PhotCode *PhotCode_PS1_DEV_2_To_Internal (PhotCode_PS1_DEV_2 *in, int Nvalues) {
+
+  int i;
+  PhotCode *out;
+
+  ALLOCATE (out, PhotCode, Nvalues);
 
   for (i = 0; i < Nvalues; i++) {
@@ -334,14 +360,20 @@
     out[i].astromErrMagScale = in[i].astromErrMagScale;
     out[i].photomErrSys      = in[i].photomErrSys;
-  }
-  return (out);
-}
-
-PhotCode *PhotCode_PS1_DEV_2_To_Internal (PhotCode_PS1_DEV_2 *in, int Nvalues) {
-
-  int i;
-  PhotCode *out;
-
-  ALLOCATE (out, PhotCode, Nvalues);
+
+    // changed or added for PS1_V1 (also PS1_DEV_3, deprecated)
+    out[i].photomPoorMask      = 0;
+    out[i].photomBadMask       = 0;
+    out[i].astromPoorMask      = 0;
+    out[i].astromBadMask       = 0;
+  }
+  return (out);
+}
+
+PhotCode_PS1_DEV_2 *PhotCode_Internal_To_PS1_DEV_2 (PhotCode *in, int Nvalues) {
+
+  int i;
+  PhotCode_PS1_DEV_2 *out;
+
+  ALLOCATE (out, PhotCode_PS1_DEV_2, Nvalues);
 
   for (i = 0; i < Nvalues; i++) {
@@ -365,10 +397,5 @@
     out[i].astromErrMagScale = in[i].astromErrMagScale;
     out[i].photomErrSys      = in[i].photomErrSys;
-
-    out[i].photomPoorMask      = 0;
-    out[i].photomBadMask       = 0;
-    out[i].astromPoorMask      = 0;
-    out[i].astromBadMask       = 0;
-  }
-  return (out);
-}
+  }
+  return (out);
+}
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c	(revision 21418)
@@ -3,5 +3,5 @@
 /* convert PS1_DEV_3 formats to internal formats */
 
-// XXX EAM I am not yet ready to commit to a full PS1_DEV_3 release, but I am providing image and photcode conversion
+// We only provide image and photcode conversion
 
 Image *Image_PS1_DEV_3_ToInternal (Image_PS1_DEV_3 *in, int Nvalues) {
@@ -38,5 +38,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
     out[i].imageID	    = in[i].imageID;
@@ -59,4 +58,8 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -96,5 +99,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
     out[i].imageID	    = in[i].imageID;
@@ -117,4 +119,43 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
+
+PhotCode *PhotCode_PS1_DEV_3_To_Internal (PhotCode_PS1_DEV_3 *in, int Nvalues) {
+
+  int i;
+  PhotCode *out;
+
+  ALLOCATE (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);
@@ -157,37 +198,2 @@
 }
 
-PhotCode *PhotCode_PS1_DEV_3_To_Internal (PhotCode_PS1_DEV_3 *in, int Nvalues) {
-
-  int i;
-  PhotCode *out;
-
-  ALLOCATE (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);
-}
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 21418)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 21418)
@@ -0,0 +1,403 @@
+# include <dvo.h>
+
+/* convert PS1_V1 formats to internal formats */
+
+Measure *Measure_PS1_V1_ToInternal (Measure_PS1_V1 *in, int Nvalues) {
+
+  int i;
+  Measure *out;
+
+  ALLOCATE (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].Map_small  = in[i].Map_small;
+    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].extID      = in[i].extID;
+    out[i].psfQual    = in[i].psfQual;
+    out[i].psfChisq   = in[i].psfChisq;
+    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].dTccd      = in[i].dTccd;
+    out[i].photcode   = in[i].photcode;
+    out[i].dbFlags    = in[i].dbFlags;
+    out[i].photFlags  = in[i].photFlags;
+    out[i].stargal    = in[i].stargal;
+  }
+  return (out);
+}
+
+Measure_PS1_V1 *MeasureInternalTo_PS1_V1 (Measure *in, int Nvalues) {
+
+  int i;
+  Measure_PS1_V1 *out;
+
+  ALLOCATE (out, Measure_PS1_V1, 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].Map_small  = in[i].Map_small;
+    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].extID      = in[i].extID;
+    out[i].psfQual    = in[i].psfQual;
+    out[i].psfChisq   = in[i].psfChisq;
+    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].dTccd      = in[i].dTccd;
+    out[i].photcode   = in[i].photcode;
+    out[i].dbFlags    = in[i].dbFlags;
+    out[i].photFlags  = in[i].photFlags;
+    out[i].stargal    = in[i].stargal;
+  }
+  return (out);
+}
+
+// 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
+Average *Average_PS1_V1_ToInternal (Average_PS1_V1 *in, int Nvalues, SecFilt **primary) {
+
+  int i;
+  Average *out;
+
+  ALLOCATE (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].ChiSq       	 = in[i].ChiSq;     
+    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].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_V1 *AverageInternalTo_PS1_V1 (Average *in, int Nvalues, SecFilt *primary) {
+
+  int i;
+  Average_PS1_V1 *out;
+
+  ALLOCATE (out, Average_PS1_V1, 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].ChiSq       	 = in[i].ChiSq;     
+    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].objID 	 = in[i].objID;
+    out[i].catID 	 = in[i].catID;
+    out[i].extID 	 = in[i].extID;
+  }
+  return (out);
+}
+
+SecFilt *SecFilt_PS1_V1_ToInternal (SecFilt_PS1_V1 *in, int Nvalues) {
+
+  int i;
+  SecFilt *out;
+
+  ALLOCATE (out, SecFilt, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].M     = in[i].M;      
+    out[i].dM    = in[i].dM;      
+    out[i].Xm    = in[i].Xm;     
+    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;      
+ }
+  return (out);
+}
+
+SecFilt_PS1_V1 *SecFiltInternalTo_PS1_V1 (SecFilt *in, int Nvalues) {
+
+  int i;
+  SecFilt_PS1_V1 *out;
+
+  ALLOCATE (out, SecFilt_PS1_V1, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].M     = in[i].M;      
+    out[i].dM    = in[i].dM;      
+    out[i].Xm    = in[i].Xm;     
+    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;      
+  }
+  return (out);
+}
+
+Image *Image_PS1_V1_ToInternal (Image_PS1_V1 *in, int Nvalues) {
+
+  int i;
+  Image *out;
+
+  ALLOCATE (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].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;
+
+    out[i].order	    = in[i].order;
+    out[i].Mx		    = in[i].Mx;
+    out[i].My		    = in[i].My;
+    out[i].Mxx		    = in[i].Mxx;
+    out[i].Mxy		    = in[i].Mxy;
+    out[i].Myy		    = in[i].Myy;
+    out[i].Mxxx		    = in[i].Mxxx;
+    out[i].Mxxy		    = in[i].Mxxy;
+    out[i].Mxyy		    = in[i].Mxyy;
+    out[i].Myyy		    = in[i].Myyy;
+    out[i].Mxxxx	    = in[i].Mxxxx;
+    out[i].Mxxxy	    = in[i].Mxxxy;
+    out[i].Mxxyy	    = in[i].Mxxyy;
+    out[i].Mxyyy	    = in[i].Mxyyy;
+    out[i].Myyyy	    = in[i].Myyyy;
+  }
+  return (out);
+}
+
+Image_PS1_V1 *ImageInternalTo_PS1_V1 (Image *in, int Nvalues) {
+
+  int i;
+  Image_PS1_V1 *out;
+
+  ALLOCATE (out, Image_PS1_V1, 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].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;
+
+    out[i].order	    = in[i].order;
+    out[i].Mx		    = in[i].Mx;
+    out[i].My		    = in[i].My;
+    out[i].Mxx		    = in[i].Mxx;
+    out[i].Mxy		    = in[i].Mxy;
+    out[i].Myy		    = in[i].Myy;
+    out[i].Mxxx		    = in[i].Mxxx;
+    out[i].Mxxy		    = in[i].Mxxy;
+    out[i].Mxyy		    = in[i].Mxyy;
+    out[i].Myyy		    = in[i].Myyy;
+    out[i].Mxxxx	    = in[i].Mxxxx;
+    out[i].Mxxxy	    = in[i].Mxxxy;
+    out[i].Mxxyy	    = in[i].Mxxyy;
+    out[i].Mxyyy	    = in[i].Mxyyy;
+    out[i].Myyyy	    = in[i].Myyyy;
+  }
+  return (out);
+}
+
+PhotCode *PhotCode_PS1_V1_To_Internal (PhotCode_PS1_V1 *in, int Nvalues) {
+
+  int i;
+  PhotCode *out;
+
+  ALLOCATE (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_V1 *PhotCode_Internal_To_PS1_V1 (PhotCode *in, int Nvalues) {
+
+  int i;
+  PhotCode_PS1_V1 *out;
+
+  ALLOCATE (out, PhotCode_PS1_V1, 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_branch_20090208/Ohana/src/libdvo/src/dvo_convert_elixir.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 21418)
@@ -10,4 +10,9 @@
 
   for (i = 0; i < Nvalues; i++) {
+    out[i].FWx 	    = in[i].FWx;
+    out[i].t        = in[i].t;
+    out[i].averef   = in[i].averef;
+
+    // changed for PANSTARRS_DEV_0
     out[i].dR       = (in[i].dR      == NAN_S_SHORT) ? NAN : in[i].dR     * 0.01;
     out[i].dD       = (in[i].dD      == NAN_S_SHORT) ? NAN : in[i].dD     * 0.01;
@@ -16,38 +21,44 @@
     out[i].dt       = (in[i].dt      == NAN_S_SHORT) ? NAN : in[i].dt     * 0.001;
     out[i].Mcal     = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
-
-    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
-    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
     out[i].Map      = (in[i].Mgal    == NAN_S_SHORT) ? NAN : in[i].Mgal   * 0.001;
     out[i].airmass  = (in[i].airmass == NAN_S_SHORT) ? NAN : in[i].airmass* 0.001;
-    out[i].FWx 	    = in[i].FWx;
     out[i].FWy 	    = in[i].fwy * in[i].FWx * 0.01;
     out[i].theta    = in[i].theta*(0x10000 / 0x100);
-    out[i].dophot   = in[i].dophot;
     out[i].photcode = in[i].source;
-    out[i].t        = in[i].t;
-    out[i].averef   = in[i].averef;
-    out[i].dbFlags  = in[i].flags;
     
-    /* these can be determined if needed / desired */
-    out[i].Xccd     = 0;
-    out[i].Yccd     = 0;
-    out[i].dXccd    = 0;
-    out[i].dYccd    = 0;
-
-    /* these do not have a corresponding value */
+    // added for PANSTARRS_DEV_0
+    out[i].Xccd      = 0;  // determine on-the-fly
+    out[i].Yccd      = 0;  // determine on-the-fly
+    out[i].dXccd     = 0;
+    out[i].dYccd     = 0;
     out[i].az        = 0;
     out[i].stargal   = 0;
     out[i].Sky       = 0;
     out[i].dSky      = 0;
-    out[i].qPSF      = 0;
+    out[i].psfQual   = 0;
     out[i].psfChisq  = 0;
     out[i].crNsigma  = 0;
     out[i].extNsigma = 0;
-    out[i].photFlags = 0;
-
-    /* XXX add these later */
-    out[i].detID = 0;
-    out[i].imageID = 0;
+    out[i].detID     = 0;  // determine on-the-fly
+    out[i].imageID   = 0;  // determine on-the-fly
+
+    // changed or added for PS1_DEV_1 (2008.02.26)
+    out[i].dbFlags    = in[i].flags;
+    out[i].detID      = 0;
+    out[i].imageID    = 0;
+
+    // changed or added for PS1_DEV_2
+    out[i].Map        = in[i].Mgal;
+    out[i].dMcal      = 0; 
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].dophot << 16;
+    out[i].t_msec     = 0;
+    out[i].extID      = 0;
+    out[i].Mxx 	      = 0.0;
+    out[i].Mxy 	      = 0.0;
+    out[i].Myy        = 0.0;
+    out[i].dTccd      = 0;
+    out[i].Map_small  = 0;
   }
   return (out);
@@ -63,4 +74,9 @@
 
   for (i = 0; i < Nvalues; i++) {
+    out[i].FWx 	   = in[i].FWx;
+    out[i].t       = in[i].t;
+    out[i].averef  = in[i].averef;
+
+    // changed for PANSTARRS_DEV_0
     out[i].dR       = isnan(in[i].dR     ) ? NAN_S_SHORT : in[i].dR      *  100.0;
     out[i].dD       = isnan(in[i].dD     ) ? NAN_S_SHORT : in[i].dD      *  100.0;
@@ -71,4 +87,7 @@
     out[i].Mgal     = isnan(in[i].Map    ) ? NAN_S_SHORT : in[i].Map     * 1000.0;
     out[i].airmass  = isnan(in[i].airmass) ? NAN_S_SHORT : in[i].airmass * 1000.0;
+    out[i].fwy 	    = in[i].FWy * 100.0 / in[i].FWx;
+    out[i].theta    = in[i].theta*(0x100/ 0x10000);
+    out[i].source   = in[i].photcode;
 
     if (out[i].M < 0) {
@@ -76,12 +95,9 @@
     }
 
-    out[i].FWx 	   = in[i].FWx;
-    out[i].fwy 	   = in[i].FWy * 100.0 / in[i].FWx;
-    out[i].theta   = in[i].theta*(0x100/ 0x10000);
-    out[i].dophot  = in[i].dophot;
-    out[i].source  = in[i].photcode;
-    out[i].t       = in[i].t;
-    out[i].averef  = in[i].averef;
+    // changed or added for PS1_DEV_1 (2008.02.26)
     out[i].flags   = in[i].dbFlags;
+
+    // changed or added for PS1_V1
+    out[i].dophot  = in[i].photFlags >> 16;
   }
   return (out);
@@ -101,11 +117,14 @@
     out[i].D       	 = in[i].D;      
     out[i].Xp      	 = in[i].Xp;     
-    out[i].Nmeasure 	 = in[i].Nm;     
-    out[i].Nmissing 	 = in[i].Nn;     
-    out[i].code     	 = in[i].code;   
-    out[i].measureOffset = in[i].offset; 
-    out[i].missingOffset = in[i].missing;
-
-    /* these don't exist in Elixir */
+
+    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
+    primary[0][i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;      
+    primary[0][i].dM    = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM * 0.001;      
+    primary[0][i].Xm    = in[i].Xm;     
+
+    primary[0][i].Ncode = 0;     
+    primary[0][i].Nused = 0;
+
+    // added for PANSTARRS_DEV_0
     out[i].dR      = 0;
     out[i].dD      = 0;
@@ -116,14 +135,20 @@
     out[i].P       = 0;
     out[i].dP      = 0;
-
-    /* XXX add these later */
-    out[i].objID   = 0;
-    out[i].catID   = 0;
-
-    primary[0][i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;      
-    primary[0][i].dM    = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM * 0.001;      
-    primary[0][i].Xm    = in[i].Xm;     
-    primary[0][i].Ncode = 0;     
-    primary[0][i].Nused = 0;
+    out[i].objID   = 0; // determine on-the-fly
+    out[i].catID   = 0; // determine on-the-fly
+
+    // changed or added for PS1_DEV_2
+    out[i].Nmeasure 	 = in[i].Nm;     
+    out[i].Nmissing 	 = in[i].Nn;     
+    out[i].measureOffset = in[i].offset; 
+    out[i].missingOffset = in[i].missing;
+    out[i].Nextend       = 0;
+    out[i].extendOffset  = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags    	 = in[i].code;   
+    out[i].ChiSq       	 = 0.0;
+    out[i].Npos       	 = 0.0;
+    out[i].extID 	 = 0;
   }
   return (out);
@@ -142,13 +167,18 @@
     out[i].D       = in[i].D;      
     out[i].Xp      = in[i].Xp;     
-    out[i].Nm      = in[i].Nmeasure;     
-    out[i].Nn      = in[i].Nmissing;     
-    out[i].code    = in[i].code;   
-    out[i].offset  = in[i].measureOffset; 
-    out[i].missing = in[i].missingOffset;
-
+
+    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
     out[i].M       = isnan(primary[i].M)  ? NAN_S_SHORT : primary[i].M   * 1000.0;
     out[i].dM      = isnan(primary[i].dM) ? NAN_S_SHORT : primary[i].dM  * 1000.0;
     out[i].Xm      = primary[i].Xm;     
+
+    // changed or added for PS1_DEV_2
+    out[i].Nm      = in[i].Nmeasure;     
+    out[i].Nn      = in[i].Nmissing;     
+    out[i].offset  = in[i].measureOffset; 
+    out[i].missing = in[i].missingOffset;
+
+    // changed or added for PS1_V1
+    out[i].code    = in[i].flags;   
   }
   return (out);
@@ -164,9 +194,15 @@
 
   for (i = 0; i < Nvalues; i++) {
+    out[i].Xm    = in[i].Xm;     
+
+    // added or changed for PANSTARRS_DEV_0
     out[i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M   * 0.001;
     out[i].dM    = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM  * 0.001;
-    out[i].Xm    = in[i].Xm;     
     out[i].Ncode = 0;
     out[i].Nused = 0;
+
+    // changed or added for PS1_V1
+    out[i].M_20  = 0;      
+    out[i].M_80  = 0;      
   }
   return (out);
@@ -182,7 +218,9 @@
 
   for (i = 0; i < Nvalues; i++) {
+    out[i].Xm    = in[i].Xm;     
+
+    // added or changed for PANSTARRS_DEV_0
     out[i].M     = isnan(in[i].M)  ? NAN_S_SHORT : in[i].M   * 1000.0;
     out[i].dM    = isnan(in[i].dM) ? NAN_S_SHORT : in[i].dM  * 1000.0;
-    out[i].Xm    = in[i].Xm;     
   }
   return (out);
@@ -207,9 +245,4 @@
     out[i].NX	    	    = in[i].NX;
     out[i].NY	    	    = in[i].NY;
-    out[i].secz    	    = (in[i].secz     == NAN_S_SHORT) ? NAN : in[i].secz     * 0.001;
-    out[i].apmifit  	    = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
-    out[i].dapmifit  	    = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
-    out[i].Mcal   	    = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
-    out[i].dMcal   	    = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
     out[i].Xm	    	    = in[i].Xm;
     out[i].photcode   	    = in[i].source;
@@ -221,5 +254,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
 
@@ -240,10 +272,21 @@
     out[i].Myyyy	    = in[i].Myyyy;
 
-    /* XXX add these later */
-    out[i].imageID = 0;
-
-    // not available in ELIXIR
+    // added or changed for PANSTARRS_DEV_0
+    out[i].secz    	    = (in[i].secz     == NAN_S_SHORT) ? NAN : in[i].secz     * 0.001;
+    out[i].apmifit  	    = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
+    out[i].dapmifit  	    = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
+    out[i].Mcal   	    = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
+    out[i].dMcal   	    = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
     out[i].sidtime  	    = NAN;
     out[i].latitude  	    = NAN;
+    out[i].imageID          = 0; // determine on-the-fly
+
+    // changed or added for PS1_DEV_2
+    out[i].externID	    = 0;
+    out[i].sourceID	    = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -268,9 +311,5 @@
     out[i].NX	    	    = in[i].NX;
     out[i].NY	    	    = in[i].NY;
-    out[i].secz    	    = isnan(in[i].secz    ) ? NAN_S_SHORT : in[i].secz     * 1000.0;
-    out[i].apmifit    	    = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
-    out[i].dapmifit    	    = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
-    out[i].Mcal    	    = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
-    out[i].dMcal    	    = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
+
     out[i].Xm	    	    = in[i].Xm;
     out[i].source   	    = in[i].photcode;
@@ -282,5 +321,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
 
@@ -300,14 +338,24 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
-  }
-  return (out);
-}
-
-PhotCode_Elixir *PhotCode_Internal_To_Elixir (PhotCode *in, int Nvalues) {
-
-  int i;
-  PhotCode_Elixir *out;
-
-  ALLOCATE (out, PhotCode_Elixir, Nvalues);
+
+    // added or changed for PANSTARRS_DEV_0
+    out[i].secz    	    = isnan(in[i].secz    ) ? NAN_S_SHORT : in[i].secz     * 1000.0;
+    out[i].apmifit    	    = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
+    out[i].dapmifit    	    = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
+    out[i].Mcal    	    = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
+    out[i].dMcal    	    = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
+
+PhotCode *PhotCode_Elixir_To_Internal (PhotCode_Elixir *in, int Nvalues) {
+
+  int i;
+  PhotCode *out;
+
+  ALLOCATE (out, PhotCode, Nvalues);
 
   for (i = 0; i < Nvalues; i++) {
@@ -326,14 +374,28 @@
     out[i].Nc    = in[i].Nc;           
     memcpy (out[i].X, in[i].X, 4*sizeof(float));            
-  }
-  return (out);
-}
-
-PhotCode *PhotCode_Elixir_To_Internal (PhotCode_Elixir *in, int Nvalues) {
-
-  int i;
-  PhotCode *out;
-
-  ALLOCATE (out, PhotCode, Nvalues);
+
+    // changed or added for PS1_DEV_1
+    out[i].astromErrMagScale = 0.0;
+    out[i].photomErrSys      = 0.0;
+
+    // changed or added for PS1_DEV_2
+    out[i].astromErrSys      = 0.0;
+    out[i].astromErrScale    = 0.0;
+
+    // changed or added for PS1_V1 (also PS1_DEV_3, deprecated)
+    out[i].photomPoorMask      = 0;
+    out[i].photomBadMask       = 0;
+    out[i].astromPoorMask      = 0;
+    out[i].astromBadMask       = 0;
+  }
+  return (out);
+}
+
+PhotCode_Elixir *PhotCode_Internal_To_Elixir (PhotCode *in, int Nvalues) {
+
+  int i;
+  PhotCode_Elixir *out;
+
+  ALLOCATE (out, PhotCode_Elixir, Nvalues);
 
   for (i = 0; i < Nvalues; i++) {
@@ -352,16 +414,5 @@
     out[i].Nc    = in[i].Nc;           
     memcpy (out[i].X, in[i].X, 4*sizeof(float));            
-
-    // not defined in Elixir:
-    out[i].astromErrSys      = 0.0;
-    out[i].astromErrScale    = 0.0;
-    out[i].astromErrMagScale = 0.0;
-    out[i].photomErrSys      = 0.0;
-
-    out[i].photomPoorMask      = 0;
-    out[i].photomBadMask       = 0;
-    out[i].astromPoorMask      = 0;
-    out[i].astromBadMask       = 0;
-  }
-  return (out);
-}
+  }
+  return (out);
+}
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_loneos.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 21418)
@@ -10,46 +10,57 @@
 
   for (i = 0; i < Nvalues; i++) {
-    out[i].dR        = (in[i].dR      == NAN_S_SHORT) ? NAN : in[i].dR     * 0.01;
-    out[i].dD        = (in[i].dD      == NAN_S_SHORT) ? NAN : in[i].dD     * 0.01;
-    out[i].M         = (in[i].M       == NAN_S_SHORT) ? NAN : in[i].M      * 0.001;
-    out[i].dM        = (in[i].dM      == NAN_U_CHAR)  ? NAN : in[i].dM     * 0.001;
-    out[i].Mcal      = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
-    out[i].dophot    = in[i].dophot;
-    out[i].photcode  = in[i].source;
-    out[i].t         = in[i].t;
-
-    /* flags and averef are now split */
+    out[i].t        = in[i].t;
+
+    // added or changed for ELIXIR
     out[i].averef    =  in[i].averef & 0x00ffffff;
     out[i].dbFlags   = (in[i].averef & 0xff000000) >> 24;
-
-    /* these values don't exist in the Loneos format */
-
-    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
-    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
-    out[i].Map       = out[i].M;
+    out[i].t         = in[i].t;
     out[i].dt        = 0;
     out[i].airmass   = 0;
+    out[i].FWy 	     = 0;
+    out[i].FWx       = 0;
+    out[i].theta     = 0;
+
+    // changed for PANSTARRS_DEV_0
+    out[i].dR       = (in[i].dR      == NAN_S_SHORT) ? NAN : in[i].dR     * 0.01;
+    out[i].dD       = (in[i].dD      == NAN_S_SHORT) ? NAN : in[i].dD     * 0.01;
+    out[i].M        = (in[i].M       == NAN_S_SHORT) ? NAN : in[i].M      * 0.001;
+    out[i].dM       = (in[i].dM      == NAN_U_CHAR)  ? NAN : in[i].dM     * 0.001;
+    out[i].Mcal     = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
+    out[i].Map      = (in[i].M       == NAN_S_SHORT) ? NAN : in[i].M      * 0.001;
+    out[i].photcode = in[i].source;
+    
+    // added for PANSTARRS_DEV_0
+    out[i].Xccd      = 0;  // determine on-the-fly
+    out[i].Yccd      = 0;  // determine on-the-fly
+    out[i].dXccd     = 0;
+    out[i].dYccd     = 0;
     out[i].az        = 0;
-    out[i].FWx 	     = 0;
-    out[i].FWy 	     = 0;
-    out[i].theta     = 0;
     out[i].stargal   = 0;
     out[i].Sky       = 0;
     out[i].dSky      = 0;
-    out[i].qPSF      = 0;
+    out[i].psfQual   = 0;
     out[i].psfChisq  = 0;
     out[i].crNsigma  = 0;
     out[i].extNsigma = 0;
-    out[i].photFlags = 0;
-
-    /* these can be determined if needed / desired */
-    out[i].Xccd     = 0;
-    out[i].Yccd     = 0;
-    out[i].dXccd    = 0;
-    out[i].dYccd    = 0;
-
-    /* XXX add these later */
-    out[i].detID = 0;
-    out[i].imageID = 0;
+    out[i].detID     = 0;  // determine on-the-fly
+    out[i].imageID   = 0;  // determine on-the-fly
+
+    // changed or added for PS1_DEV_1 (2008.02.26)
+    out[i].detID      = 0;
+    out[i].imageID    = 0;
+
+    // changed or added for PS1_DEV_2
+    out[i].dMcal      = 0; 
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].dophot << 16;
+    out[i].t_msec     = 0;
+    out[i].extID      = 0;
+    out[i].Mxx 	      = 0.0;
+    out[i].Mxy 	      = 0.0;
+    out[i].Myy        = 0.0;
+    out[i].dTccd      = 0;
+    out[i].Map_small  = 0;
   }
   return (out);
@@ -65,4 +76,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+
+    // changed for PANSTARRS_DEV_0
     out[i].dR     = isnan(in[i].dR     ) ? NAN_S_SHORT : in[i].dR      *  100.0;
     out[i].dD     = isnan(in[i].dD     ) ? NAN_S_SHORT : in[i].dD      *  100.0;
@@ -70,5 +83,4 @@
     out[i].dM     = isnan(in[i].dM     ) ? NAN_U_CHAR  : in[i].dM      * 1000.0;
     out[i].Mcal   = isnan(in[i].Mcal   ) ? NAN_S_SHORT : in[i].Mcal    * 1000.0;
-    out[i].dophot = in[i].dophot;
     out[i].source = in[i].photcode;
     out[i].t      = in[i].t;
@@ -76,4 +88,7 @@
     /* flags and averef are merged in Loneos */
     out[i].averef =  (in[i].averef & 0x00ffffff) | (in[i].dbFlags << 24);
+
+    // changed or added for PS1_V1
+    out[i].dophot  = in[i].photFlags >> 16;
   }
   return (out);
@@ -93,11 +108,15 @@
     out[i].D       	 = in[i].D;      
     out[i].Xp      	 = in[i].Xp;     
-    out[i].Nmeasure      = in[i].Nm;     
-    out[i].Nmissing      = in[i].Nn;     
-    out[i].code    	 = in[i].code;   
-    out[i].measureOffset = in[i].offset; 
-    out[i].missingOffset = in[i].missing;
-
-    /* these don't exist in Loneos */
+
+    // added for ELIXIR
+    primary[0][i].dM    = NAN;
+
+    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
+    primary[0][i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;      
+    primary[0][i].Xm    = in[i].Xm;     
+    primary[0][i].Ncode = 0;     
+    primary[0][i].Nused = 0;
+
+    // added for PANSTARRS_DEV_0
     out[i].dR      = 0;
     out[i].dD      = 0;
@@ -108,14 +127,20 @@
     out[i].P       = 0;
     out[i].dP      = 0;
-
-    /* XXX add these later */
-    out[i].objID   = 0;
-    out[i].catID   = 0;
-
-    primary[0][i].M  = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;      
-    primary[0][i].Xm = in[i].Xm;     
-    primary[0][i].dM = NAN;
-    primary[0][i].Ncode = 0;     
-    primary[0][i].Nused = 0;
+    out[i].objID   = 0; // determine on-the-fly
+    out[i].catID   = 0; // determine on-the-fly
+
+    // changed or added for PS1_DEV_2
+    out[i].Nmeasure 	 = in[i].Nm;     
+    out[i].Nmissing 	 = in[i].Nn;     
+    out[i].measureOffset = in[i].offset; 
+    out[i].missingOffset = in[i].missing;
+    out[i].Nextend       = 0;
+    out[i].extendOffset  = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags    	 = in[i].code;   
+    out[i].ChiSq       	 = 0.0;
+    out[i].Npos       	 = 0.0;
+    out[i].extID 	 = 0;
   }
   return (out);
@@ -134,12 +159,17 @@
     out[i].D       = in[i].D;      
     out[i].Xp      = in[i].Xp;     
+
+    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
+    out[i].M       = isnan(primary[i].M)  ? NAN_S_SHORT : primary[i].M   * 1000.0;
+    out[i].Xm      = primary[i].Xm;     
+
+    // changed or added for PS1_DEV_2
     out[i].Nm      = in[i].Nmeasure;     
     out[i].Nn      = in[i].Nmissing;     
-    out[i].code    = in[i].code;   
     out[i].offset  = in[i].measureOffset; 
     out[i].missing = in[i].missingOffset;
 
-    out[i].M       = isnan(primary[i].M)  ? NAN_S_SHORT : primary[i].M   * 1000.0;
-    out[i].Xm      = primary[i].Xm;     
+    // changed or added for PS1_V1
+    out[i].code    = in[i].flags;   
   }
   return (out);
@@ -155,9 +185,17 @@
 
   for (i = 0; i < Nvalues; i++) {
+    out[i].Xm    = in[i].Xm;      
+
+    // added for ELIXIR
+    out[i].dM    = NAN;
+
+    // added or changed for PANSTARRS_DEV_0
     out[i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M * 0.001;
-    out[i].Xm    = in[i].Xm;      
-    out[i].dM    = NAN;
     out[i].Ncode = 0;
     out[i].Nused = 0;
+
+    // changed or added for PS1_V1
+    out[i].M_20  = 0;      
+    out[i].M_80  = 0;      
   }
   return (out);
@@ -173,6 +211,8 @@
 
   for (i = 0; i < Nvalues; i++) {
+    out[i].Xm   = in[i].Xm;      
+
+    // added or changed for PANSTARRS_DEV_0
     out[i].M    = isnan(in[i].M)  ? NAN_S_SHORT : in[i].M * 1000.0;
-    out[i].Xm   = in[i].Xm;      
   }
   return (out);
@@ -197,10 +237,4 @@
     out[i].NX	    	    = in[i].NX;
     out[i].NY	    	    = in[i].NY;
-
-    out[i].secz    	    = (in[i].secz     == NAN_S_SHORT) ? NAN : in[i].secz     * 0.001;
-    out[i].apmifit  	    = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
-    out[i].dapmifit  	    = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
-    out[i].Mcal   	    = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
-    out[i].dMcal   	    = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
 
     out[i].Xm	    	    = in[i].Xm;
@@ -213,6 +247,6 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
+
     out[i].order	    = in[i].order;
     out[i].Mx		    = in[i].Mx;
@@ -231,6 +265,21 @@
     out[i].Myyyy	    = in[i].Myyyy;
 
-    /* XXX add these later */
-    out[i].imageID = 0;
+    // added or changed for PANSTARRS_DEV_0
+    out[i].secz    	    = (in[i].secz     == NAN_S_SHORT) ? NAN : in[i].secz     * 0.001;
+    out[i].apmifit  	    = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
+    out[i].dapmifit  	    = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
+    out[i].Mcal   	    = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
+    out[i].dMcal   	    = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
+    out[i].sidtime  	    = NAN;
+    out[i].latitude  	    = NAN;
+    out[i].imageID          = 0; // determine on-the-fly
+
+    // changed or added for PS1_DEV_2
+    out[i].externID	    = 0;
+    out[i].sourceID	    = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -255,10 +304,4 @@
     out[i].NX	    	    = in[i].NX;
     out[i].NY	    	    = in[i].NY;
-
-    out[i].secz    	    = isnan(in[i].secz    ) ? NAN_S_SHORT : in[i].secz     * 1000.0;
-    out[i].apmifit    	    = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
-    out[i].dapmifit    	    = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
-    out[i].Mcal    	    = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
-    out[i].dMcal    	    = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
 
     out[i].Xm	    	    = in[i].Xm;
@@ -271,6 +314,6 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
+
     out[i].order	    = in[i].order;
     out[i].Mx		    = in[i].Mx;
@@ -288,5 +331,15 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
-  }
-  return (out);
-}
+
+    // added or changed for PANSTARRS_DEV_0
+    out[i].secz    	    = isnan(in[i].secz    ) ? NAN_S_SHORT : in[i].secz     * 1000.0;
+    out[i].apmifit    	    = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
+    out[i].dapmifit    	    = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
+    out[i].Mcal    	    = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
+    out[i].dMcal    	    = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 21418)
@@ -16,7 +16,4 @@
     out[i].Mcal       = in[i].Mcal;
 
-    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
-    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
-    out[i].Map        = in[i].Mgal;
     out[i].airmass    = in[i].airmass;
     out[i].az         = in[i].az;
@@ -25,9 +22,7 @@
     out[i].FWy 	      = in[i].FWy;
     out[i].theta      = in[i].theta;
-    out[i].dophot     = in[i].dophot;
     out[i].photcode   = in[i].photcode;
     out[i].t          = in[i].t;
     out[i].averef     = in[i].averef;
-    out[i].dbFlags    = in[i].flags;
     out[i].Xccd       = in[i].Xccd;
     out[i].Yccd       = in[i].Yccd;
@@ -37,13 +32,30 @@
     out[i].Sky        = in[i].Sky;
     out[i].dSky       = in[i].dSky;
-    out[i].qPSF       = (in[i].qPSF == NAN_S_SHORT) ? NAN : in[i].qPSF;
+
+    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
+    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
+
+    // changed or added for PS1_DEV_1 (2008.02.26)
+    out[i].psfQual    = (in[i].psfQual == NAN_S_SHORT) ? NAN : in[i].psfQual;
+    out[i].dbFlags    = in[i].flags;
     out[i].detID      = in[i].detID_lo;
     out[i].imageID    = in[i].imageID_lo;
-
-    // these don't have a correspondence
-    out[i].psfChisq  = 0;
-    out[i].crNsigma  = 0;
-    out[i].extNsigma = 0;
-    out[i].photFlags = 0;
+    out[i].psfChisq   = 0;
+    out[i].crNsigma   = 0;
+    out[i].extNsigma  = 0;
+
+    // changed or added for PS1_DEV_2
+    out[i].Map        = in[i].Mgal;
+    out[i].dMcal      = 0; 
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].dophot << 16;
+    out[i].t_msec     = 0;
+    out[i].extID      = 0;
+    out[i].Mxx 	      = 0.0;
+    out[i].Mxy 	      = 0.0;
+    out[i].Myy        = 0.0;
+    out[i].dTccd      = 0;
+    out[i].Map_small  = 0;
   }
   return (out);
@@ -64,5 +76,4 @@
     out[i].dM         = in[i].dM;
     out[i].Mcal       = in[i].Mcal;
-    out[i].Mgal       = in[i].Map;
     out[i].airmass    = in[i].airmass;
     out[i].az         = in[i].az;
@@ -71,9 +82,7 @@
     out[i].FWy 	      = in[i].FWy;
     out[i].theta      = in[i].theta;
-    out[i].dophot     = in[i].dophot;
     out[i].photcode   = in[i].photcode;
     out[i].t          = in[i].t;
     out[i].averef     = in[i].averef;
-    out[i].flags      = in[i].dbFlags;
     out[i].Xccd       = in[i].Xccd;
     out[i].Yccd       = in[i].Yccd;
@@ -83,9 +92,19 @@
     out[i].Sky        = in[i].Sky;
     out[i].dSky       = in[i].dSky;
-    out[i].qPSF       = isnan(in[i].qPSF) ? NAN_S_SHORT : in[i].qPSF;
+
+    // changed or added for PS1_DEV_1 (2008.02.26)
+    out[i].flags      = in[i].dbFlags;
+    out[i].psfQual    = isnan(in[i].psfQual) ? NAN_S_SHORT : in[i].psfQual;
     out[i].detID_hi   = 0;
     out[i].detID_lo   = in[i].detID;
     out[i].imageID_hi = 0;
     out[i].imageID_lo = in[i].imageID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Mgal       = in[i].Map;
+
+    // changed or added for PS1_V1
+    // out[i].photFlags  = in[i].photFlags & 0x0000ffff; (only dophot pre PS1_DEV_1)
+    out[i].dophot     = in[i].photFlags >> 16;
   }
   return (out);
@@ -105,9 +124,4 @@
     out[i].D        	 = in[i].D;      
     out[i].Xp       	 = in[i].Xp;     
-    out[i].Nmeasure      = in[i].Nm;     
-    out[i].Nmissing      = in[i].Nn;     
-    out[i].code          = in[i].code;   
-    out[i].measureOffset = in[i].offset; 
-    out[i].missingOffset = in[i].missing;
     out[i].dR       	 = in[i].dR;
     out[i].dD       	 = in[i].dD;
@@ -120,4 +134,18 @@
     out[i].objID 	 = in[i].objID;
     out[i].catID 	 = in[i].catID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Nmeasure      = in[i].Nm;     
+    out[i].Nmissing      = in[i].Nn;     
+    out[i].measureOffset = in[i].offset; 
+    out[i].missingOffset = in[i].missing;
+    out[i].Nextend       = 0;
+    out[i].extendOffset  = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags    	 = in[i].code;   
+    out[i].ChiSq       	 = 0.0;
+    out[i].Npos       	 = 0.0;
+    out[i].extID 	 = 0;
   }
   return (out);
@@ -137,9 +165,4 @@
     out[i].D        = in[i].D;      
     out[i].Xp       = in[i].Xp;     
-    out[i].Nm       = in[i].Nmeasure;     
-    out[i].Nn       = in[i].Nmissing;     
-    out[i].code     = in[i].code;   
-    out[i].offset   = in[i].measureOffset; 
-    out[i].missing  = in[i].missingOffset;
     out[i].dR       = in[i].dR;
     out[i].dD       = in[i].dD;
@@ -152,4 +175,13 @@
     out[i].objID    = in[i].objID;
     out[i].catID    = in[i].catID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Nm       = in[i].Nmeasure;     
+    out[i].Nn       = in[i].Nmissing;     
+    out[i].offset   = in[i].measureOffset; 
+    out[i].missing  = in[i].missingOffset;
+
+    // changed or added for PS1_V1
+    out[i].code          = in[i].flags;   
   }
   return (out);
@@ -170,4 +202,8 @@
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
+
+    // changed or added for PS1_V1
+    out[i].M_20  = 0;      
+    out[i].M_80  = 0;      
  }
   return (out);
@@ -226,7 +262,5 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID	    = in[i].imageID_lo;
 
     out[i].order	    = in[i].order;
@@ -245,4 +279,15 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_DEV_1
+    out[i].imageID	    = in[i].imageID_lo;
+
+    // changed or added for PS1_DEV_2
+    out[i].externID	    = 0;
+    out[i].sourceID	    = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -283,8 +328,5 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID_hi	    = 0;
-    out[i].imageID_lo	    = in[i].imageID;
 
     out[i].order	    = in[i].order;
@@ -303,5 +345,12 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
-  }
-  return (out);
-}
+
+    // changed or added for PS1_DEV_1
+    out[i].imageID_hi	    = 0;
+    out[i].imageID_lo	    = in[i].imageID;
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 21418)
@@ -16,7 +16,4 @@
     out[i].Mcal       = in[i].Mcal;
 
-    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
-    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
-    out[i].Map        = in[i].Mgal;
     out[i].airmass    = in[i].airmass;
     out[i].az         = in[i].az;
@@ -25,9 +22,7 @@
     out[i].FWy 	      = in[i].FWy;
     out[i].theta      = in[i].theta;
-    out[i].dophot     = in[i].dophot;
     out[i].photcode   = in[i].photcode;
     out[i].t          = in[i].t;
     out[i].averef     = in[i].averef;
-    out[i].dbFlags    = in[i].flags;
     out[i].Xccd       = in[i].Xccd;
     out[i].Yccd       = in[i].Yccd;
@@ -37,13 +32,30 @@
     out[i].Sky        = in[i].Sky;
     out[i].dSky       = in[i].dSky;
-    out[i].qPSF       = (in[i].qPSF == NAN_S_SHORT) ? NAN : in[i].qPSF;
+
+    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
+    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
+
+    // changed or added for PS1_DEV_1 (2008.02.26)
+    out[i].psfQual    = (in[i].psfQual == NAN_S_SHORT) ? NAN : in[i].psfQual;
+    out[i].dbFlags    = in[i].flags;
     out[i].detID      = in[i].detID_lo;
     out[i].imageID    = in[i].imageID_lo;
-
-    // these don't have a correspondence
-    out[i].psfChisq  = 0;
-    out[i].crNsigma  = 0;
-    out[i].extNsigma = 0;
-    out[i].photFlags = 0;
+    out[i].psfChisq   = 0;
+    out[i].crNsigma   = 0;
+    out[i].extNsigma  = 0;
+
+    // changed or added for PS1_DEV_2
+    out[i].Map        = in[i].Mgal;
+    out[i].dMcal      = 0; 
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].dophot << 16;
+    out[i].t_msec     = 0;
+    out[i].extID      = 0;
+    out[i].Mxx 	      = 0.0;
+    out[i].Mxy 	      = 0.0;
+    out[i].Myy        = 0.0;
+    out[i].dTccd      = 0;
+    out[i].Map_small  = 0;
   }
   return (out);
@@ -64,5 +76,4 @@
     out[i].dM         = in[i].dM;
     out[i].Mcal       = in[i].Mcal;
-    out[i].Mgal       = in[i].Map;
     out[i].airmass    = in[i].airmass;
     out[i].az         = in[i].az;
@@ -71,9 +82,7 @@
     out[i].FWy 	      = in[i].FWy;
     out[i].theta      = in[i].theta;
-    out[i].dophot     = in[i].dophot;
     out[i].photcode   = in[i].photcode;
     out[i].t          = in[i].t;
     out[i].averef     = in[i].averef;
-    out[i].flags      = in[i].dbFlags;
     out[i].Xccd       = in[i].Xccd;
     out[i].Yccd       = in[i].Yccd;
@@ -83,9 +92,19 @@
     out[i].Sky        = in[i].Sky;
     out[i].dSky       = in[i].dSky;
-    out[i].qPSF       = isnan(in[i].qPSF) ? NAN_S_SHORT : in[i].qPSF;
+
+    // changed or added for PS1_DEV_1 (2008.02.26)
+    out[i].flags      = in[i].dbFlags;
+    out[i].psfQual    = isnan(in[i].psfQual) ? NAN_S_SHORT : in[i].psfQual;
     out[i].detID_hi   = 0;
     out[i].detID_lo   = in[i].detID;
     out[i].imageID_hi = 0;
     out[i].imageID_lo = in[i].imageID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Mgal       = in[i].Map;
+
+    // changed or added for PS1_V1
+    // out[i].photFlags  = in[i].photFlags & 0x0000ffff; (only dophot pre PS1_DEV_1)
+    out[i].dophot     = in[i].photFlags >> 16;
   }
   return (out);
@@ -105,9 +124,4 @@
     out[i].D        	 = in[i].D;      
     out[i].Xp       	 = in[i].Xp;     
-    out[i].Nmeasure      = in[i].Nm;     
-    out[i].Nmissing      = in[i].Nn;     
-    out[i].code     	 = in[i].code;   
-    out[i].measureOffset = in[i].offset; 
-    out[i].missingOffset = in[i].missing;
     out[i].dR       	 = in[i].dR;
     out[i].dD       	 = in[i].dD;
@@ -120,4 +134,18 @@
     out[i].objID 	 = in[i].objID;
     out[i].catID 	 = in[i].catID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Nmeasure      = in[i].Nm;     
+    out[i].Nmissing      = in[i].Nn;     
+    out[i].measureOffset = in[i].offset; 
+    out[i].missingOffset = in[i].missing;
+    out[i].Nextend       = 0;
+    out[i].extendOffset  = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags    	 = in[i].code;   
+    out[i].ChiSq       	 = 0.0;
+    out[i].Npos       	 = 0.0;
+    out[i].extID 	 = 0;
   }
   return (out);
@@ -137,9 +165,4 @@
     out[i].D        = in[i].D;      
     out[i].Xp       = in[i].Xp;     
-    out[i].Nm       = in[i].Nmeasure;     
-    out[i].Nn       = in[i].Nmissing;     
-    out[i].code     = in[i].code;   
-    out[i].offset   = in[i].measureOffset; 
-    out[i].missing  = in[i].missingOffset;
     out[i].dR       = in[i].dR;
     out[i].dD       = in[i].dD;
@@ -152,4 +175,13 @@
     out[i].objID    = in[i].objID;
     out[i].catID    = in[i].catID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Nm       = in[i].Nmeasure;     
+    out[i].Nn       = in[i].Nmissing;     
+    out[i].offset   = in[i].measureOffset; 
+    out[i].missing  = in[i].missingOffset;
+
+    // changed or added for PS1_V1
+    out[i].code          = in[i].flags;   
   }
   return (out);
@@ -170,4 +202,8 @@
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
+
+    // changed or added for PS1_V1
+    out[i].M_20  = 0;      
+    out[i].M_80  = 0;      
  }
   return (out);
@@ -226,7 +262,5 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID	    = in[i].imageID_lo;
 
     out[i].order	    = in[i].order;
@@ -245,4 +279,15 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_DEV_1
+    out[i].imageID	    = in[i].imageID_lo;
+
+    // changed or added for PS1_DEV_2
+    out[i].externID	    = 0;
+    out[i].sourceID	    = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -283,8 +328,5 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID_hi	    = 0;
-    out[i].imageID_lo	    = in[i].imageID;
 
     out[i].order	    = in[i].order;
@@ -303,5 +345,15 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
-  }
-  return (out);
-}
+
+    // changed or added for PS1_DEV_1
+    out[i].imageID_hi	    = 0;
+    out[i].imageID_lo	    = in[i].imageID;
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
+
+// XXX no photcode conversions?  this may be from before we had a photcode FITS table...
+
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_image.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_image.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_image.c	(revision 21418)
@@ -196,4 +196,5 @@
   if (db[0].format == DVO_FORMAT_PS1_DEV_2)       gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_DEV_2");
   if (db[0].format == DVO_FORMAT_PS1_DEV_3)       gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_DEV_3");
+  if (db[0].format == DVO_FORMAT_PS1_V1)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V1");
   
   return;
Index: /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_image_raw.c
===================================================================
--- /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 21417)
+++ /branches/eam_branch_20090208/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 21418)
@@ -54,4 +54,6 @@
   if (db[0].format == DVO_FORMAT_PS1_DEV_1)       ImageSize = sizeof(Image_PS1_DEV_1);
   if (db[0].format == DVO_FORMAT_PS1_DEV_2)       ImageSize = sizeof(Image_PS1_DEV_2);
+  if (db[0].format == DVO_FORMAT_PS1_DEV_3)       ImageSize = sizeof(Image_PS1_DEV_3);
+  if (db[0].format == DVO_FORMAT_PS1_V1)          ImageSize = sizeof(Image_PS1_V1);
 
   /* check that filesize makes sense */
@@ -78,4 +80,6 @@
   if (db[0].format == DVO_FORMAT_PS1_DEV_1)       gfits_table_mkheader_Image_PS1_DEV_1 (&db[0].theader);
   if (db[0].format == DVO_FORMAT_PS1_DEV_2)       gfits_table_mkheader_Image_PS1_DEV_2 (&db[0].theader);
+  if (db[0].format == DVO_FORMAT_PS1_DEV_3)       gfits_table_mkheader_Image_PS1_DEV_3 (&db[0].theader);
+  if (db[0].format == DVO_FORMAT_PS1_V1)          gfits_table_mkheader_Image_PS1_V1 (&db[0].theader);
     
   /* read data from file */
