Index: /tags/ipp-ops-20220906/Ohana/src/addstar/src/grefstars.c
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/addstar/src/grefstars.c	(revision 42430)
+++ /tags/ipp-ops-20220906/Ohana/src/addstar/src/grefstars.c	(revision 42431)
@@ -41,4 +41,8 @@
     catalog->average[N].R = ohana_normalize_angle (catalog->average[N].R);
 
+    catalog->measure[N].McalPSF  = 0.0;
+    catalog->measure[N].McalAPER = 0.0;
+    catalog->measure[N].dMcal    = 0.0;
+       
     catalog->measure[N].R = catalog->average[N].R;
     catalog->measure[N].D = catalog->average[N].D;
Index: /tags/ipp-ops-20220906/Ohana/src/libautocode/Makefile.Targets
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libautocode/Makefile.Targets	(revision 42430)
+++ /tags/ipp-ops-20220906/Ohana/src/libautocode/Makefile.Targets	(revision 42431)
@@ -19,4 +19,5 @@
 $(ASRC)/average-ps1-ref.$(ARCH).o \
 $(ASRC)/average-ps1-ref-v2.$(ARCH).o \
+$(ASRC)/average-ps1-ref-v3.$(ARCH).o \
 $(ASRC)/secfilt.$(ARCH).o \
 $(ASRC)/secfilt-loneos.$(ARCH).o \
@@ -36,4 +37,5 @@
 $(ASRC)/secfilt-ps1-ref.$(ARCH).o \
 $(ASRC)/secfilt-ps1-ref-v2.$(ARCH).o \
+$(ASRC)/secfilt-ps1-ref-v3.$(ARCH).o \
 $(ASRC)/measure.$(ARCH).o \
 $(ASRC)/measure-loneos.$(ARCH).o \
@@ -53,4 +55,5 @@
 $(ASRC)/measure-ps1-ref.$(ARCH).o \
 $(ASRC)/measure-ps1-ref-v2.$(ARCH).o \
+$(ASRC)/measure-ps1-ref-v3.$(ARCH).o \
 $(ASRC)/lensing.$(ARCH).o \
 $(ASRC)/lensing-ps1-v5-r0.$(ARCH).o \
@@ -90,4 +93,5 @@
 $(ASRC)/photcode-ps1-ref.$(ARCH).o \
 $(ASRC)/photcode-ps1-ref-v2.$(ARCH).o \
+$(ASRC)/photcode-ps1-ref-v3.$(ARCH).o \
 $(ASRC)/image-loneos.$(ARCH).o \
 $(ASRC)/image-elixir.$(ARCH).o \
@@ -107,4 +111,5 @@
 $(ASRC)/image-ps1-ref.$(ARCH).o \
 $(ASRC)/image-ps1-ref-v2.$(ARCH).o \
+$(ASRC)/image-ps1-ref-v3.$(ARCH).o \
 $(ASRC)/regimage.$(ARCH).o \
 $(ASRC)/detreg.$(ARCH).o \
@@ -155,4 +160,5 @@
 $(AINC)/average-ps1-ref.h \
 $(AINC)/average-ps1-ref-v2.h \
+$(AINC)/average-ps1-ref-v3.h \
 $(AINC)/secfilt.h \
 $(AINC)/secfilt-loneos.h \
@@ -172,4 +178,5 @@
 $(AINC)/secfilt-ps1-ref.h \
 $(AINC)/secfilt-ps1-ref-v2.h \
+$(AINC)/secfilt-ps1-ref-v3.h \
 $(AINC)/measure.h \
 $(AINC)/measure-loneos.h \
@@ -189,4 +196,5 @@
 $(AINC)/measure-ps1-ref.h \
 $(AINC)/measure-ps1-ref-v2.h \
+$(AINC)/measure-ps1-ref-v3.h \
 $(AINC)/lensing.h \
 $(AINC)/lensing-ps1-v5-r0.h \
@@ -226,4 +234,5 @@
 $(AINC)/photcode-ps1-ref.h \
 $(AINC)/photcode-ps1-ref-v2.h \
+$(AINC)/photcode-ps1-ref-v3.h \
 $(AINC)/image-loneos.h \
 $(AINC)/image-elixir.h \
@@ -243,4 +252,5 @@
 $(AINC)/image-ps1-ref.h \
 $(AINC)/image-ps1-ref-v2.h \
+$(AINC)/image-ps1-ref-v3.h \
 $(AINC)/regimage.h \
 $(AINC)/detreg.h \
Index: /tags/ipp-ops-20220906/Ohana/src/libautocode/def/average-ps1-ref-v3.d
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libautocode/def/average-ps1-ref-v3.d	(revision 42431)
+++ /tags/ipp-ops-20220906/Ohana/src/libautocode/def/average-ps1-ref-v3.d	(revision 42431)
@@ -0,0 +1,37 @@
+STRUCT       Average_PS1_REF_V3
+EXTNAME      DVO_AVERAGE_PS1_REF_V3
+TYPE         BINTABLE
+SIZE         80
+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 measureOffset,  OFF_MEASURE, uint32_t,   	    offset to first psf measurement
+FIELD missingOffset,  OFF_MISSING, uint32_t,   	    offset to first missing obs
+FIELD lensingOffset,  OFF_LENSING, uint32_t,   	    offset to first lensing obs
+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
+
+# 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 pad,            PAD,         char[4],         padding
+
+# 2 double, 8 float, 2 int, 2 short, 4 char, 2 unit32_t
+# 2*8 +     8*4 +    2*4 +  2*2 +    4*1 +   2*4       = 72
+
Index: /tags/ipp-ops-20220906/Ohana/src/libautocode/def/image-ps1-ref-v3.d
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libautocode/def/image-ps1-ref-v3.d	(revision 42431)
+++ /tags/ipp-ops-20220906/Ohana/src/libautocode/def/image-ps1-ref-v3.d	(revision 42431)
@@ -0,0 +1,77 @@
+STRUCT       Image_PS1_REF_V3
+EXTNAME      DVO_IMAGE_PS1_REF_V3
+TYPE         BINTABLE
+SIZE         344
+DESCRIPTION  DVO Image Table 
+
+# elements of the image structure
+
+SUBSTRUCT coords,           COORDS,               CoordsDisk,    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
+# 2 double, 8 float, 15 char, 1 char
+# 2*8 +     8*4 +    15*1 +   1*1       = 72
+
+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
+# 1 int, 8 float, 4 short
+# 1*4 +  8*4 +    4*2    = 44
+
+# 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 
+
+# 40 bytes
+FIELD 	  nLinkAstrom,      NLINK_ASTROM,         short,      	  mean number of matched measurements for astrometry
+FIELD 	  nLinkPhotom,      NLINK_PHOTOM,         short,      	  mean number of matched measurements for astrometry
+FIELD 	  dummy3,           DUMMY3,               short,      	  place holder for byte boundaries
+
+FIELD 	  dXpixSys,         XPIX_SYS_ERR,         float,      	  systematic astrometry error in X
+FIELD 	  dYpixSys,         YPIX_SYS_ERR,         float,      	  systematic astrometry error in Y
+
+FIELD 	  dMagSys,          MAG_SYS_ERR,          float,      	  systematic photometry error
+FIELD 	  nFitAstrom,       N_FIT_ASTROM,         short,      	  number of stars used for astrometry cal
+FIELD 	  nFitPhotom,       N_FIT_PHOTOM,         short,      	  number of stars used for photometry cal
+
+FIELD 	  photom_map_id,    PHOTOM_MAP_ID,        unsigned int,   reference to 2D zero point map
+FIELD 	  astrom_map_id,    ASTROM_MAP_ID,        unsigned int,   reference to 2D astrometry map
+# nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases
+
+
Index: /tags/ipp-ops-20220906/Ohana/src/libautocode/def/measure-ps1-ref-v3.d
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libautocode/def/measure-ps1-ref-v3.d	(revision 42431)
+++ /tags/ipp-ops-20220906/Ohana/src/libautocode/def/measure-ps1-ref-v3.d	(revision 42431)
@@ -0,0 +1,40 @@
+STRUCT       Measure_PS1_REF_V3
+EXTNAME      DVO_MEASURE_PS1_REF_V3
+TYPE         BINTABLE
+SIZE         56
+DESCRIPTION  DVO Detection Measurement Table 
+
+# this format is a stripped-down version of ps1-v1, appropriate to a static reference database
+# we make the trade-off towards small data volume vs detailed metadata
+
+FIELD dR,             D_RA,         float,          RA offset,                	  arcsec
+FIELD dD,             D_DEC,        float,          DEC offset,               	  arcsec
+FIELD M,              MAG,          float,          catalog mag,       	       	  mag
+FIELD dM,             MAG_ERR,      float,          mag error,                    mag
+FIELD Mcal,           M_CAL,        float,          image cal mag,                mag
+FIELD dMcal,          MAG_CAL_ERR,  float,          systematic calibration error, mag
+FIELD dt,             M_TIME,       float,          exposure time,                2.5*log(exptime)
+
+FIELD t,              TIME,         int,   	    time in seconds (UNIX)
+FIELD averef,         AVE_REF,      unsigned int,   reference to average entry      
+
+# might be able to drop these:
+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 dbFlags,        DB_FLAGS,     unsigned int,   flags supplied by analysis in database
+FIELD photFlags,      PHOT_FLAGS,   unsigned int,   flags supplied by photometry program
+
+
+FIELD photcode,       PHOTCODE,     unsigned short, photcode
+
+FIELD pad,            PAD,          char[2],        padding
+
+# 7 x float 
+# 4 x int
+# 2 + 2
+# = 48 bytes
+
+# 7 float, 4 int, 1 short, 2 char
+# 7*4 +    4*4 +  1*2 +    2*1   = 48
+
+
Index: /tags/ipp-ops-20220906/Ohana/src/libautocode/def/photcode-ps1-ref-v3.d
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libautocode/def/photcode-ps1-ref-v3.d	(revision 42431)
+++ /tags/ipp-ops-20220906/Ohana/src/libautocode/def/photcode-ps1-ref-v3.d	(revision 42431)
@@ -0,0 +1,33 @@
+STRUCT       PhotCode_PS1_REF_V3
+EXTNAME      DVO_PHOTCODE_PS1_REF_V3
+TYPE         BINTABLE
+SIZE         104
+DESCRIPTION  DVO Photcode Description Table 
+
+# elements of data structure / FITS table
+FIELD  code,         	  CODE,          	 unsigned short, code number (stored in Measure.source) 
+FIELD  name,         	  NAME,          	 char[32],       name for filter combination 
+FIELD  type,         	  TYPE,          	 char,           PRI/SEC/DEP/REF 
+FIELD  dummy,        	  DUMMY,         	 char[3],        padding
+FIELD  C,            	  C_LAM,         	 short,          primary phot calibration terms (millimags) 
+FIELD  dC,           	  C_LAM_ERR,     	 short,          primary phot calibration terms (millimags) 
+FIELD  dX,           	  X_ERR,         	 short,          primary phot calibration terms (millimags) 
+FIELD  K,            	  K,             	 float,          secondary phot calibration terms (millimags) 
+FIELD  c1,           	  C1,            	 int,            color is average.M[c1] - average.M[c2] 
+FIELD  c2,           	  C2,            	 int,            color is average.M[c1] - average.M[c2] 
+FIELD  equiv,        	  EQUIV,         	 int,            this dependent filter is equivalent to equiv PRI/SEC
+FIELD  Nc,           	  NC,            	 int,            number of color terms 
+FIELD  X,            	  X,             	 float[4],       color terms $X[0]*mc + X[1]*mc^2 + X[2]*mc^3$, etc 
+FIELD  astromErrSys,      ASTROM_ERR_SYS,  	 float,          systematic astrometry error (arcsec)
+FIELD  astromErrScale,    ASTROM_ERR_SCALE,  	 float,          astrometric error scale
+FIELD  astromErrMagScale, ASTROM_ERR_MAG_SCALE,  float,          astrometric error / mag error scale
+FIELD  astromPoorMask,    ASTROM_POOR_MASK,      short,          detections matching this mask should only be used in emergencies
+FIELD  astromBadMask,     ASTROM_BAD_MASK,       short,          detections matching this mask should not be used
+FIELD  photomErrSys,   	  PHOTOM_ERR_SYS,  	 float,          systematic photometric error
+FIELD  photomPoorMask, 	  PHOTOM_POOR_MASK,  	 short,          detections matching this mask should only be used in emergencies
+FIELD  photomBadMask,  	  PHOTOM_BAD_MASK,  	 short,          detections matching this mask should not be used
+
+#   dR_total^2 =  dR_sys^2 + AS * dR_obs^2 + MS * dM_obs^2
+#   dR_sys : systematicAstrometryError
+#   AS     : astrometryErrorScale
+#   MS     : astrometryErrorMagScale
Index: /tags/ipp-ops-20220906/Ohana/src/libautocode/def/secfilt-ps1-ref-v3.d
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libautocode/def/secfilt-ps1-ref-v3.d	(revision 42431)
+++ /tags/ipp-ops-20220906/Ohana/src/libautocode/def/secfilt-ps1-ref-v3.d	(revision 42431)
@@ -0,0 +1,11 @@
+STRUCT       SecFilt_PS1_REF_V3
+EXTNAME      DVO_SECFILT_PS1_REF_V3
+TYPE         BINTABLE
+SIZE         12
+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  flags, FLAGS,    uint32_t,             photometry flags
+
Index: /tags/ipp-ops-20220906/Ohana/src/libdvo/Makefile
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libdvo/Makefile	(revision 42430)
+++ /tags/ipp-ops-20220906/Ohana/src/libdvo/Makefile	(revision 42431)
@@ -106,4 +106,5 @@
 $(SRC)/dvo_convert_PS1_REF.$(ARCH).o \
 $(SRC)/dvo_convert_PS1_REF_V2.$(ARCH).o \
+$(SRC)/dvo_convert_PS1_REF_V3.$(ARCH).o \
 $(SRC)/dvo_convert_PS1_SIM.$(ARCH).o \
 $(SRC)/flatcorr_io.$(ARCH).o    \
Index: /tags/ipp-ops-20220906/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libdvo/include/dvo.h	(revision 42430)
+++ /tags/ipp-ops-20220906/Ohana/src/libdvo/include/dvo.h	(revision 42431)
@@ -28,4 +28,5 @@
   DVO_FORMAT_PS1_REF,
   DVO_FORMAT_PS1_REF_V2,
+  DVO_FORMAT_PS1_REF_V3,
   DVO_FORMAT_PS1_SIM,
   DVO_FORMAT_PS1_V1,
@@ -252,4 +253,9 @@
 
   ID_SECF_OBJ_EXT       	 = 0x01000000, // extended in this band
+
+  //ID_SECF_PHO_SYNTH       	 = 0x00000001, // this photcode has SYNTH photometry, turn on only for reference catalog
+  //ID_SECF_PHO_ATLAS       	 = 0x00000002, // this photcode has ATLAS photometry, turn on only for reference catalog
+  //ID_SECF_PHO_PV3         	 = 0x00000004, // this photcode has PV3   photometry, turn on only for reference catalog
+  //ID_SECF_PHO_SOUTH       	 = 0x00000008, // this photcode has SOUTH photometry, turn on only for reference catalog
 
   ID_SECF_CHIP_FLAGS    	 = 0x01003f1f, // all chip-related bits (used to reset the correct bits only)
@@ -1088,4 +1094,5 @@
 # include "ps1_ref_defs.h"
 # include "ps1_ref_v2_defs.h"
+# include "ps1_ref_v3_defs.h"
 # include "ps1_sim_defs.h"
 
Index: /tags/ipp-ops-20220906/Ohana/src/libdvo/include/ps1_ref_v3_defs.h
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libdvo/include/ps1_ref_v3_defs.h	(revision 42431)
+++ /tags/ipp-ops-20220906/Ohana/src/libdvo/include/ps1_ref_v3_defs.h	(revision 42431)
@@ -0,0 +1,11 @@
+Image 		       	*Image_PS1_REF_V3_ToInternal (Image_PS1_REF_V3 *in, off_t Nvalues, off_t Nalloc);
+Image_PS1_REF_V3    	*ImageInternalTo_PS1_REF_V3 (Image *in, off_t Nvalues);
+Average 	       	*Average_PS1_REF_V3_ToInternal (Average_PS1_REF_V3 *in, off_t Nvalues, SecFilt **primary);
+Average_PS1_REF_V3      *AverageInternalTo_PS1_REF_V3 (Average *in, off_t Nvalues, SecFilt *primary);
+Measure 	       	*Measure_PS1_REF_V3_ToInternal (Average *ave, Measure_PS1_REF_V3 *in, off_t Nvalues);
+Measure_PS1_REF_V3      *MeasureInternalTo_PS1_REF_V3 (Average *ave, Measure *in, off_t Nvalues);
+SecFilt 	       	*SecFilt_PS1_REF_V3_ToInternal (SecFilt_PS1_REF_V3 *in, off_t Nvalues);
+SecFilt_PS1_REF_V3      *SecFiltInternalTo_PS1_REF_V3 (SecFilt *in, off_t Nvalues);
+
+PhotCode                *PhotCode_PS1_REF_V3_To_Internal (PhotCode_PS1_REF_V3 *in, off_t Nvalues);
+PhotCode_PS1_REF_V3     *PhotCode_Internal_To_PS1_REF_V3 (PhotCode *in, off_t Nvalues);
Index: /tags/ipp-ops-20220906/Ohana/src/libdvo/src/LoadPhotcodesFITS.c
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 42430)
+++ /tags/ipp-ops-20220906/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 42431)
@@ -60,4 +60,5 @@
   CONVERT_FORMAT("DVO_PHOTCODE_PS1_REF",     PS1_REF);
   CONVERT_FORMAT("DVO_PHOTCODE_PS1_REF_V2",  PS1_REF_V2);
+  CONVERT_FORMAT("DVO_PHOTCODE_PS1_REF_V3",  PS1_REF_V3);
   CONVERT_FORMAT("DVO_PHOTCODE_PS1_V1",      PS1_V1);
   CONVERT_FORMAT("DVO_PHOTCODE_PS1_V2",      PS1_V2);
Index: /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_catalog.c	(revision 42430)
+++ /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_catalog.c	(revision 42431)
@@ -61,4 +61,5 @@
   if (!strcasecmp (catformat, "PS1_REF"))         return (DVO_FORMAT_PS1_REF);
   if (!strcasecmp (catformat, "PS1_REF_V2"))      return (DVO_FORMAT_PS1_REF_V2);
+  if (!strcasecmp (catformat, "PS1_REF_V3"))      return (DVO_FORMAT_PS1_REF_V3);
   if (!strcasecmp (catformat, "PS1_SIM"))         return (DVO_FORMAT_PS1_SIM);
   return (DVO_FORMAT_UNDEF);
Index: /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_catalog_raw.c
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 42430)
+++ /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 42431)
@@ -95,4 +95,5 @@
       FORMAT_CASE (PS1_REF,     PS1_REF);
       FORMAT_CASE (PS1_REF_V2,  PS1_REF_V2);
+      FORMAT_CASE (PS1_REF_V3,  PS1_REF_V3);
       FORMAT_CASE (PS1_SIM,     PS1_SIM);
 
@@ -294,4 +295,5 @@
   if (catalog[0].catformat == DVO_FORMAT_PS1_REF)         gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_REF");
   if (catalog[0].catformat == DVO_FORMAT_PS1_REF_V2)      gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_REF_V2");
+  if (catalog[0].catformat == DVO_FORMAT_PS1_REF_V3)      gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_REF_V3");
   if (catalog[0].catformat == DVO_FORMAT_PS1_SIM)         gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_SIM");
 
@@ -402,4 +404,5 @@
       FORMAT_CASE (PS1_REF,     PS1_REF);
       FORMAT_CASE (PS1_REF_V2,  PS1_REF_V2);
+      FORMAT_CASE (PS1_REF_V3,  PS1_REF_V3);
       FORMAT_CASE (PS1_SIM,     PS1_SIM);
 
@@ -458,4 +461,5 @@
       FORMAT_CASE (PS1_REF,     PS1_REF);
       FORMAT_CASE (PS1_REF_V2,  PS1_REF_V2);
+      FORMAT_CASE (PS1_REF_V3,  PS1_REF_V3);
       FORMAT_CASE (PS1_SIM,     PS1_SIM);
 
@@ -517,4 +521,5 @@
       FORMAT_CASE (PS1_REF,     PS1_REF);
       FORMAT_CASE (PS1_REF_V2,  PS1_REF_V2);
+      FORMAT_CASE (PS1_REF_V3,  PS1_REF_V3);
       FORMAT_CASE (PS1_SIM,     PS1_SIM);
 
@@ -573,4 +578,5 @@
       FORMAT_CASE (PS1_REF,     PS1_REF);
       FORMAT_CASE (PS1_REF_V2,  PS1_REF_V2);
+      FORMAT_CASE (PS1_REF_V3,  PS1_REF_V3);
       FORMAT_CASE (PS1_SIM,     PS1_SIM);
 
@@ -633,4 +639,5 @@
       FORMAT_CASE (PS1_REF,     PS1_REF);
       FORMAT_CASE (PS1_REF_V2,  PS1_REF_V2);
+      FORMAT_CASE (PS1_REF_V3,  PS1_REF_V3);
       FORMAT_CASE (PS1_SIM,     PS1_SIM);
 
@@ -689,4 +696,5 @@
       FORMAT_CASE (PS1_REF,     PS1_REF);
       FORMAT_CASE (PS1_REF_V2,  PS1_REF_V2);
+      FORMAT_CASE (PS1_REF_V3,  PS1_REF_V3);
       FORMAT_CASE (PS1_SIM,     PS1_SIM);
 
Index: /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_convert.c
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_convert.c	(revision 42430)
+++ /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_convert.c	(revision 42431)
@@ -46,4 +46,5 @@
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF);
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF_V2",      PS1_REF_V2);
+  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF_V3",      PS1_REF_V3);
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_SIM",         PS1_SIM);
 # undef CONVERT_FORMAT
@@ -139,4 +140,5 @@
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF,         PS1_REF);
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF_V2",      PS1_REF_V2,      PS1_REF_V2);
+  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF_V3",      PS1_REF_V3,      PS1_REF_V3);
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_SIM",         PS1_SIM,         PS1_SIM);
 # undef CONVERT_FORMAT
@@ -179,4 +181,5 @@
       FORMAT_CASE (PS1_REF,         PS1_REF);
       FORMAT_CASE (PS1_REF_V2,      PS1_REF_V2);
+      FORMAT_CASE (PS1_REF_V3,      PS1_REF_V3);
       FORMAT_CASE (PS1_SIM,         PS1_SIM);
 # undef FORMAT_CASE
@@ -280,4 +283,5 @@
   CONVERT_FORMAT ("DVO_MEASURE_PS1_REF",         PS1_REF,         PS1_REF,         FALSE);
   CONVERT_FORMAT ("DVO_MEASURE_PS1_REF_V2",      PS1_REF_V2,      PS1_REF_V2,      FALSE);
+  CONVERT_FORMAT ("DVO_MEASURE_PS1_REF_V3",      PS1_REF_V3,      PS1_REF_V3,      FALSE);
   CONVERT_FORMAT ("DVO_MEASURE_PS1_SIM",         PS1_SIM,         PS1_SIM,         TRUE);
 # undef CONVERT_FORMAT
@@ -322,4 +326,5 @@
       FORMAT_CASE (PS1_REF,         PS1_REF,         FALSE);
       FORMAT_CASE (PS1_REF_V2,      PS1_REF_V2,      FALSE);
+      FORMAT_CASE (PS1_REF_V3,      PS1_REF_V3,      FALSE);
       FORMAT_CASE (PS1_SIM,         PS1_SIM,         TRUE);
 # undef FORMAT_CASE
@@ -391,4 +396,5 @@
   SKIPPING_FORMAT ("DVO_MISSING_PS1_REF",         PS1_REF,         PS1_REF);
   SKIPPING_FORMAT ("DVO_MISSING_PS1_REF_V2",      PS1_REF_V2,      PS1_REF_V2);
+  SKIPPING_FORMAT ("DVO_MISSING_PS1_REF_V3",      PS1_REF_V3,      PS1_REF_V3);
   SKIPPING_FORMAT ("DVO_MISSING_ELIXIR", 	  ELIXIR,  	   Elixir);
   SKIPPING_FORMAT ("DVO_MISSING_LONEOS", 	  LONEOS,          Loneos);
@@ -482,4 +488,5 @@
   CONVERT_FORMAT ("DVO_SECFILT_PS1_REF",         PS1_REF,         PS1_REF);
   CONVERT_FORMAT ("DVO_SECFILT_PS1_REF_V2",      PS1_REF_V2,      PS1_REF_V2);
+  CONVERT_FORMAT ("DVO_SECFILT_PS1_REF_V3",      PS1_REF_V3,      PS1_REF_V3);
   CONVERT_FORMAT ("DVO_SECFILT_PS1_SIM",         PS1_SIM,         PS1_SIM);
 # undef CONVERT_FORMAT
@@ -522,4 +529,5 @@
       FORMAT_CASE (PS1_REF,         PS1_REF);
       FORMAT_CASE (PS1_REF_V2,      PS1_REF_V2);
+      FORMAT_CASE (PS1_REF_V3,      PS1_REF_V3);
       FORMAT_CASE (PS1_SIM,         PS1_SIM);
 # undef FORMAT_CASE
@@ -618,4 +626,5 @@
   SKIPPING_FORMAT ("DVO_LENSING_PS1_REF",         PS1_REF,         PS1_REF);
   SKIPPING_FORMAT ("DVO_LENSING_PS1_REF_V2",      PS1_REF_V2,      PS1_REF_V2);
+  SKIPPING_FORMAT ("DVO_LENSING_PS1_REF_V3",      PS1_REF_V3,      PS1_REF_V3);
   SKIPPING_FORMAT ("DVO_LENSING_ELIXIR", 	  ELIXIR,  	   Elixir);
   SKIPPING_FORMAT ("DVO_LENSING_LONEOS", 	  LONEOS,          Loneos);
@@ -660,4 +669,5 @@
 //    FORMAT_CASE (PS1_REF,         PS1_REF);
 //    FORMAT_CASE (PS1_REF_V2,      PS1_REF_V2);
+//    FORMAT_CASE (PS1_REF_V3,      PS1_REF_V3);
 //    FORMAT_CASE (ELIXIR, 	    Elixir);
 //    FORMAT_CASE (LONEOS, 	    Loneos);
@@ -742,4 +752,5 @@
   SKIPPING_FORMAT ("DVO_LENSOBJ_PS1_REF",         PS1_REF,         PS1_REF);
   SKIPPING_FORMAT ("DVO_LENSOBJ_PS1_REF_V2",      PS1_REF_V2,      PS1_REF_V2);
+  SKIPPING_FORMAT ("DVO_LENSOBJ_PS1_REF_V3",      PS1_REF_V3,      PS1_REF_V3);
   SKIPPING_FORMAT ("DVO_LENSOBJ_ELIXIR", 	  ELIXIR,  	   Elixir);
   SKIPPING_FORMAT ("DVO_LENSOBJ_LONEOS", 	  LONEOS,          Loneos);
@@ -784,4 +795,5 @@
 //    FORMAT_CASE (PS1_REF,         PS1_REF);
 //    FORMAT_CASE (PS1_REF_V2,      PS1_REF_V2);
+//    FORMAT_CASE (PS1_REF_V3,      PS1_REF_V3);
 //    FORMAT_CASE (ELIXIR, 	    Elixir);
 //    FORMAT_CASE (LONEOS, 	    Loneos);
@@ -854,4 +866,5 @@
   SKIPPING_FORMAT ("DVO_STARPAR_PS1_REF",         PS1_REF,         PS1_REF);
   SKIPPING_FORMAT ("DVO_STARPAR_PS1_REF_V2",      PS1_REF_V2,      PS1_REF_V2);
+  SKIPPING_FORMAT ("DVO_STARPAR_PS1_REF_V3",      PS1_REF_V3,      PS1_REF_V3);
   SKIPPING_FORMAT ("DVO_STARPAR_ELIXIR", 	  ELIXIR,  	   Elixir);
   SKIPPING_FORMAT ("DVO_STARPAR_LONEOS", 	  LONEOS,          Loneos);
@@ -896,4 +909,5 @@
 //    FORMAT_CASE (PS1_REF,         PS1_REF);
 //    FORMAT_CASE (PS1_REF_V2,      PS1_REF_V2);
+//    FORMAT_CASE (PS1_REF_V3,      PS1_REF_V3);
 //    FORMAT_CASE (ELIXIR, 	    Elixir);
 //    FORMAT_CASE (LONEOS, 	    Loneos);
@@ -979,4 +993,5 @@
   SKIPPING_FORMAT ("DVO_GALPHOT_PS1_REF",         PS1_REF,         PS1_REF);
   SKIPPING_FORMAT ("DVO_GALPHOT_PS1_REF_V2",      PS1_REF_V2,      PS1_REF_V2);
+  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_REF_V3",      PS1_REF_V3,      PS1_REF_V3);
   SKIPPING_FORMAT ("DVO_GALPHOT_ELIXIR", 	  ELIXIR,  	   Elixir);
   SKIPPING_FORMAT ("DVO_GALPHOT_LONEOS", 	  LONEOS,          Loneos);
@@ -1021,4 +1036,5 @@
 //    FORMAT_CASE (PS1_REF,         PS1_REF);
 //    FORMAT_CASE (PS1_REF_V2,      PS1_REF_V2);
+//    FORMAT_CASE (PS1_REF_V3,      PS1_REF_V3);
 //    FORMAT_CASE (ELIXIR, 	    Elixir);
 //    FORMAT_CASE (LONEOS, 	    Loneos);
@@ -1111,4 +1127,5 @@
   CONVERT_FORMAT ("DVO_IMAGE_PS1_REF",         PS1_REF,         PS1_REF);
   CONVERT_FORMAT ("DVO_IMAGE_PS1_REF_V2",      PS1_REF_V2,      PS1_REF_V2);
+  CONVERT_FORMAT ("DVO_IMAGE_PS1_REF_V3",      PS1_REF_V3,      PS1_REF_V3);
   CONVERT_FORMAT ("DVO_IMAGE_PS1_SIM",         PS1_SIM,         PS1_SIM);
 
@@ -1153,4 +1170,5 @@
     FORMAT_CASE (PS1_REF,         PS1_REF);
     FORMAT_CASE (PS1_REF_V2,      PS1_REF_V2);
+    FORMAT_CASE (PS1_REF_V3,      PS1_REF_V3);
     FORMAT_CASE (PS1_SIM,         PS1_SIM);
 
@@ -1207,4 +1225,5 @@
     FORMAT_CASE (PS1_REF,         PS1_REF);
     FORMAT_CASE (PS1_REF_V2,      PS1_REF_V2);
+    FORMAT_CASE (PS1_REF_V3,      PS1_REF_V3);
     FORMAT_CASE (PS1_SIM,         PS1_SIM);
 
Index: /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_convert_PS1_REF_V3.c
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_convert_PS1_REF_V3.c	(revision 42431)
+++ /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_convert_PS1_REF_V3.c	(revision 42431)
@@ -0,0 +1,364 @@
+# include <dvo.h>
+
+/* convert PS1_REF_V3 formats to internal formats */
+
+Measure *Measure_PS1_REF_V3_ToInternal (Average *ave, Measure_PS1_REF_V3 *in, off_t Nvalues) {
+
+  off_t i;
+  Measure *out;
+
+  ALLOCATE_ZERO (out, Measure, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    dvo_measure_init (&out[i]);
+
+    int averef = in[i].averef;
+    out[i].R          = ave[averef].R - in[i].dR / 3600.0;
+    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
+    out[i].M          = in[i].M;
+    out[i].dM         = in[i].dM;
+    out[i].dt         = in[i].dt;
+    out[i].t          = in[i].t;
+    out[i].McalPSF    = in[i].Mcal;
+    out[i].McalAPER   = in[i].Mcal;
+    out[i].dMcal      = in[i].dMcal;
+    out[i].averef     = in[i].averef;
+    out[i].objID      = in[i].objID;
+    out[i].catID      = in[i].catID;
+    out[i].psfQF      = 1.0; // we do not save a value, but some operations (relphot/average) filter on this value..
+    out[i].photcode   = in[i].photcode;
+    out[i].dbFlags    = in[i].dbFlags;
+    out[i].photFlags  = in[i].photFlags;
+  }
+  return (out);
+}
+
+Measure_PS1_REF_V3 *MeasureInternalTo_PS1_REF_V3 (Average *ave, Measure *in, off_t Nvalues) {
+
+  off_t i;
+  Measure_PS1_REF_V3 *out;
+
+  ALLOCATE_ZERO (out, Measure_PS1_REF_V3, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    int averef = in[i].averef;
+
+    out[i].dR         = 3600.0*(ave[averef].R - in[i].R);
+    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
+    out[i].M          = in[i].M;
+    out[i].dM         = in[i].dM;
+    out[i].dt         = in[i].dt;
+    out[i].t          = in[i].t;
+    out[i].Mcal       = in[i].McalPSF;
+    out[i].dMcal      = in[i].dMcal;
+    out[i].averef     = in[i].averef;
+    out[i].objID      = in[i].objID;
+    out[i].catID      = in[i].catID;
+    out[i].photcode   = in[i].photcode;
+    out[i].dbFlags    = in[i].dbFlags;
+    out[i].photFlags  = in[i].photFlags;
+  }
+  return (out);
+}
+
+// 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
+Average *Average_PS1_REF_V3_ToInternal (Average_PS1_REF_V3 *in, off_t Nvalues, SecFilt **primary) {
+  OHANA_UNUSED_PARAM(primary);
+
+  off_t i;
+  Average *out;
+
+  ALLOCATE_ZERO (out, Average, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    dvo_average_init (&out[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].Nmeasure      = in[i].Nmeasure;     
+    out[i].Nmissing      = in[i].Nmissing;     
+    out[i].measureOffset = in[i].measureOffset; 
+    out[i].missingOffset = in[i].missingOffset;
+    out[i].objID 	 = in[i].objID;
+    out[i].catID 	 = in[i].catID;
+  }
+  return (out);
+}
+
+// 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
+Average_PS1_REF_V3 *AverageInternalTo_PS1_REF_V3 (Average *in, off_t Nvalues, SecFilt *primary) {
+  OHANA_UNUSED_PARAM(primary);
+
+  off_t i;
+  Average_PS1_REF_V3 *out;
+
+  ALLOCATE_ZERO (out, Average_PS1_REF_V3, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].R        	 = in[i].R;      
+    out[i].D        	 = in[i].D;      
+    out[i].dR       	 = in[i].dR;
+    out[i].dD       	 = in[i].dD;
+    out[i].uR       	 = in[i].uR;
+    out[i].uD       	 = in[i].uD;
+    out[i].duR      	 = in[i].duR;
+    out[i].duD      	 = in[i].duD;
+    out[i].P        	 = in[i].P;
+    out[i].dP       	 = in[i].dP;
+    out[i].Nmeasure      = in[i].Nmeasure;     
+    out[i].Nmissing      = in[i].Nmissing;     
+    out[i].measureOffset = in[i].measureOffset; 
+    out[i].missingOffset = in[i].missingOffset;
+    out[i].objID 	 = in[i].objID;
+    out[i].catID 	 = in[i].catID;
+    memset(out[i].pad, 0, sizeof(out[i].pad));
+  }
+  return (out);
+}
+
+SecFilt *SecFilt_PS1_REF_V3_ToInternal (SecFilt_PS1_REF_V3 *in, off_t Nvalues) {
+
+  off_t i;
+  SecFilt *out;
+
+  ALLOCATE_ZERO (out, SecFilt, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
+
+    out[i].MpsfChp     = in[i].M;      
+    out[i].dMpsfChp    = in[i].dM;      
+    out[i].flags         = in[i].flags;     
+ }
+  return (out);
+}
+
+SecFilt_PS1_REF_V3 *SecFiltInternalTo_PS1_REF_V3 (SecFilt *in, off_t Nvalues) {
+
+  off_t i;
+  SecFilt_PS1_REF_V3 *out;
+
+  ALLOCATE_ZERO (out, SecFilt_PS1_REF_V3, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].M             = in[i].MpsfChp;      
+    out[i].dM            = in[i].dMpsfChp;      
+    out[i].flags         = in[i].flags;     
+  }
+  return (out);
+}
+
+# define RAW_IMAGE_NAME_LEN 121
+
+Image *Image_PS1_REF_V3_ToInternal (Image_PS1_REF_V3 *in, off_t Nvalues, off_t Nalloc) {
+
+  off_t i;
+  Image *out;
+
+  char *buffer;
+  ALLOCATE_ZERO (buffer, char, Nalloc);
+  out = (Image *) buffer;
+  // ALLOCATE_ZERO (out, Image, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
+    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
+    out[i].coords.mosaic   = NULL;
+    out[i].coords.offsetMap = NULL;
+
+    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
+    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
+    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 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].McalPSF    	    = in[i].Mcal;
+    out[i].McalAPER    	    = in[i].Mcal;
+    out[i].dMcal    	    = in[i].dMcal;
+    out[i].McalChiSq  	    = pow(10.0, 0.01*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;
+
+    // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced
+    // with the following.  (no real databases used those values -- see
+    // libdvo/doc/dvo-images.txt)
+    out[i].nLinkAstrom	    = in[i].nLinkAstrom;
+    out[i].nLinkPhotom	    = in[i].nLinkPhotom;
+    out[i].ubercalDist	    = in[i].dummy3; // new name PS1_V3
+    out[i].dXpixSys	    = in[i].dXpixSys;
+    out[i].dYpixSys	    = in[i].dYpixSys;
+    out[i].dMagSys	    = in[i].dMagSys;
+    out[i].nFitAstrom       = in[i].nFitAstrom;
+    out[i].nFitPhotom       = in[i].nFitPhotom;
+    out[i].photom_map_id    = in[i].photom_map_id;
+    out[i].astrom_map_id    = in[i].astrom_map_id;
+
+    // changed or added for PS1_V2
+    out[i].RAo  	    = NAN;
+    out[i].DECo  	    = NAN;
+    out[i].Radius  	    = NAN;
+  }
+  return (out);
+}
+
+Image_PS1_REF_V3 *ImageInternalTo_PS1_REF_V3 (Image *in, off_t Nvalues) {
+
+  off_t i;
+  Image_PS1_REF_V3 *out;
+
+  ALLOCATE_ZERO (out, Image_PS1_REF_V3, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
+    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
+
+    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
+    strncpy (out[i].name, in[i].name, DVO_IMAGE_NAME_LEN - 1);
+    out[i].name[DVO_IMAGE_NAME_LEN - 1] = 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].McalPSF;
+    out[i].dMcal    	    = in[i].dMcal;
+    out[i].Xm	    	    = 100.0*log10(in[i].McalChiSq);
+
+    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;
+
+    // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced
+    // with the following.  (no real databases used those values -- see
+    // libdvo/doc/dvo-images.txt)
+    out[i].nLinkAstrom	    = in[i].nLinkAstrom;
+    out[i].nLinkPhotom	    = in[i].nLinkPhotom;
+    out[i].dummy3	    = in[i].ubercalDist; // new name PS1_V3
+    out[i].dXpixSys	    = in[i].dXpixSys;
+    out[i].dYpixSys	    = in[i].dYpixSys;
+    out[i].dMagSys	    = in[i].dMagSys;
+    out[i].nFitAstrom       = in[i].nFitAstrom;
+    out[i].nFitPhotom       = in[i].nFitPhotom;
+    out[i].photom_map_id    = in[i].photom_map_id;
+    out[i].astrom_map_id    = in[i].astrom_map_id;
+  }
+  return (out);
+}
+
+PhotCode *PhotCode_PS1_REF_V3_To_Internal (PhotCode_PS1_REF_V3 *in, off_t Nvalues) {
+
+  off_t i;
+  PhotCode *out;
+
+  ALLOCATE_ZERO (out, PhotCode, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
+    out[i].name[31] = 0; // force termination
+
+    out[i].code  = in[i].code;         
+    out[i].type  = in[i].type;         
+    out[i].C     = in[i].C;            
+    out[i].dC 	 = in[i].dC;           
+    out[i].dX 	 = in[i].dX;           
+    out[i].K  	 = in[i].K;            
+    out[i].c1 	 = in[i].c1;           
+    out[i].c2 	 = in[i].c2;           
+    out[i].equiv = in[i].equiv;        
+    out[i].Nc    = in[i].Nc;           
+    memcpy (out[i].X, in[i].X, 4*sizeof(float));            
+
+    out[i].astromErrSys      = in[i].astromErrSys;
+    out[i].astromErrScale    = in[i].astromErrScale;
+    out[i].astromErrMagScale = in[i].astromErrMagScale;
+    out[i].photomErrSys      = in[i].photomErrSys;
+
+    out[i].photomPoorMask      = in[i].photomPoorMask;
+    out[i].photomBadMask       = in[i].photomBadMask;
+    out[i].astromPoorMask      = in[i].astromPoorMask;
+    out[i].astromBadMask       = in[i].astromBadMask;
+  }
+  return (out);
+}
+
+PhotCode_PS1_REF_V3 *PhotCode_Internal_To_PS1_REF_V3 (PhotCode *in, off_t Nvalues) {
+
+  off_t i;
+  PhotCode_PS1_REF_V3 *out;
+
+  ALLOCATE_ZERO (out, PhotCode_PS1_REF_V3, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
+    out[i].name[31] = 0; // force termination
+
+    out[i].code  = in[i].code;         
+    out[i].type  = in[i].type;         
+    out[i].C     = in[i].C;            
+    out[i].dC 	 = in[i].dC;           
+    out[i].dX 	 = in[i].dX;           
+    out[i].K  	 = in[i].K;            
+    out[i].c1 	 = in[i].c1;           
+    out[i].c2 	 = in[i].c2;           
+    out[i].equiv = in[i].equiv;        
+    out[i].Nc    = in[i].Nc;           
+    memcpy (out[i].X, in[i].X, 4*sizeof(float));            
+
+    out[i].astromErrSys      = in[i].astromErrSys;
+    out[i].astromErrScale    = in[i].astromErrScale;
+    out[i].astromErrMagScale = in[i].astromErrMagScale;
+    out[i].photomErrSys      = in[i].photomErrSys;
+
+    out[i].photomPoorMask      = in[i].photomPoorMask;
+    out[i].photomBadMask       = in[i].photomBadMask;
+    out[i].astromPoorMask      = in[i].astromPoorMask;
+    out[i].astromBadMask       = in[i].astromBadMask;
+  }
+  return (out);
+}
Index: /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_image.c
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_image.c	(revision 42430)
+++ /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_image.c	(revision 42431)
@@ -227,4 +227,5 @@
   if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_REF");
   if (db[0].format == DVO_FORMAT_PS1_REF_V2)      gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_REF_V2");
+  if (db[0].format == DVO_FORMAT_PS1_REF_V3)      gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_REF_V3");
   if (db[0].format == DVO_FORMAT_PS1_SIM)         gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_SIM");
   
Index: /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_image_raw.c
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 42430)
+++ /tags/ipp-ops-20220906/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 42431)
@@ -64,4 +64,5 @@
   if (db[0].format == DVO_FORMAT_PS1_REF)         ImageSize = sizeof(Image_PS1_REF);
   if (db[0].format == DVO_FORMAT_PS1_REF_V2)      ImageSize = sizeof(Image_PS1_REF_V2);
+  if (db[0].format == DVO_FORMAT_PS1_REF_V3)      ImageSize = sizeof(Image_PS1_REF_V3);
   if (db[0].format == DVO_FORMAT_PS1_SIM)         ImageSize = sizeof(Image_PS1_SIM);
 
@@ -99,4 +100,5 @@
   if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_table_mkheader_Image_PS1_REF (&db[0].theader);
   if (db[0].format == DVO_FORMAT_PS1_REF_V2)      gfits_table_mkheader_Image_PS1_REF_V2 (&db[0].theader);
+  if (db[0].format == DVO_FORMAT_PS1_REF_V3)      gfits_table_mkheader_Image_PS1_REF_V3 (&db[0].theader);
   if (db[0].format == DVO_FORMAT_PS1_SIM)         gfits_table_mkheader_Image_PS1_SIM (&db[0].theader);
     
Index: /tags/ipp-ops-20220906/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- /tags/ipp-ops-20220906/Ohana/src/relphot/src/setMrelCatalog.c	(revision 42430)
+++ /tags/ipp-ops-20220906/Ohana/src/relphot/src/setMrelCatalog.c	(revision 42431)
@@ -406,4 +406,10 @@
       secfilt[Nsec].flags |= ID_SECF_HAS_CFH;
     }
+//  secfilt[Nsec].flags |= ID_SECF_AST_GAIA ;
+//  secfilt[Nsec].flags |= ID_SECF_PHO_SYNTH;
+//  secfilt[Nsec].flags |= ID_SECF_PHO_ATLAS;
+//  secfilt[Nsec].flags |= ID_SECF_PHO_PV3  ;
+  secfilt[Nsec].flags |= ID_SECF_PHO_SOUTH;
+//  fprintf (stderr, "test obj %d %f %f %f %f %d %d\n", Ns, average[0].R, average[0].D, average[0].uR, average[0].uD, average[0].flags, isSetMrelFinal);
 
     // if -preserve-ps1 is set and this object has PS1 data, skip the rest of the steps:
@@ -463,10 +469,10 @@
     int NrankingPSF = useOLS ? magStatsByRanking (&results->psfData[Nsec], psfstats) : magStatsByRankingIRLS (&results->psfData[Nsec], psfstats);
     if (NrankingPSF < Nminmeas) { 
-      secfilt[Nsec].flags |= ID_SECF_STAR_FEW;
+//      secfilt[Nsec].flags |= ID_SECF_STAR_FEW;
     } else {
       secfilt[Nsec].MpsfChp  = psfstats->mean;
       secfilt[Nsec].dMpsfChp = psfstats->error;
       secfilt[Nsec].Mchisq   = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN;
-      secfilt[Nsec].flags &= ~ID_SECF_STAR_FEW;
+//      secfilt[Nsec].flags &= ~ID_SECF_STAR_FEW;
     }
 
@@ -552,5 +558,5 @@
 	  break;
 	case 3:
-	  secfilt[Nsec].flags |= ID_SECF_RANK_3;
+	  //secfilt[Nsec].flags |= ID_SECF_RANK_3;
 	  break;
 	case 4:
