Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/addstar/src/grefstars.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/addstar/src/grefstars.c	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/addstar/src/grefstars.c	(revision 42803)
@@ -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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/Makefile.Targets
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/Makefile.Targets	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/Makefile.Targets	(revision 42803)
@@ -18,4 +18,6 @@
 $(ASRC)/average-ps1-sim.$(ARCH).o \
 $(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 \
@@ -34,4 +36,6 @@
 $(ASRC)/secfilt-ps1-sim.$(ARCH).o \
 $(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 \
@@ -50,4 +54,6 @@
 $(ASRC)/measure-ps1-sim.$(ARCH).o \
 $(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 \
@@ -86,4 +92,6 @@
 $(ASRC)/photcode-ps1-v5-ld.$(ARCH).o \
 $(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 \
@@ -102,4 +110,6 @@
 $(ASRC)/image-ps1-sim.$(ARCH).o \
 $(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 \
@@ -149,4 +159,6 @@
 $(AINC)/average-ps1-sim.h \
 $(AINC)/average-ps1-ref.h \
+$(AINC)/average-ps1-ref-v2.h \
+$(AINC)/average-ps1-ref-v3.h \
 $(AINC)/secfilt.h \
 $(AINC)/secfilt-loneos.h \
@@ -165,4 +177,6 @@
 $(AINC)/secfilt-ps1-sim.h \
 $(AINC)/secfilt-ps1-ref.h \
+$(AINC)/secfilt-ps1-ref-v2.h \
+$(AINC)/secfilt-ps1-ref-v3.h \
 $(AINC)/measure.h \
 $(AINC)/measure-loneos.h \
@@ -181,4 +195,6 @@
 $(AINC)/measure-ps1-sim.h \
 $(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 \
@@ -217,4 +233,6 @@
 $(AINC)/photcode-ps1-v5-ld.h \
 $(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 \
@@ -233,4 +251,6 @@
 $(AINC)/image-ps1-sim.h \
 $(AINC)/image-ps1-ref.h \
+$(AINC)/image-ps1-ref-v2.h \
+$(AINC)/image-ps1-ref-v3.h \
 $(AINC)/regimage.h \
 $(AINC)/detreg.h \
Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/average-ps1-ref-v2.d
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/average-ps1-ref-v2.d	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/average-ps1-ref-v2.d	(revision 42803)
@@ -0,0 +1,35 @@
+STRUCT       Average_PS1_REF_V2
+EXTNAME      DVO_AVERAGE_PS1_REF_V2
+TYPE         BINTABLE
+SIZE         72
+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
+
+# 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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/average-ps1-ref-v3.d
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/average-ps1-ref-v3.d	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/average-ps1-ref-v3.d	(revision 42803)
@@ -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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/image-ps1-ref-v2.d
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/image-ps1-ref-v2.d	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/image-ps1-ref-v2.d	(revision 42803)
@@ -0,0 +1,77 @@
+STRUCT       Image_PS1_REF_V2
+EXTNAME      DVO_IMAGE_PS1_REF_V2
+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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/image-ps1-ref-v3.d
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/image-ps1-ref-v3.d	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/image-ps1-ref-v3.d	(revision 42803)
@@ -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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/measure-ps1-ref-v2.d
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/measure-ps1-ref-v2.d	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/measure-ps1-ref-v2.d	(revision 42803)
@@ -0,0 +1,37 @@
+STRUCT       Measure_PS1_REF_V2
+EXTNAME      DVO_MEASURE_PS1_REF_V2
+TYPE         BINTABLE
+SIZE         48
+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 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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/measure-ps1-ref-v3.d
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/measure-ps1-ref-v3.d	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/measure-ps1-ref-v3.d	(revision 42803)
@@ -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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/photcode-ps1-ref-v2.d
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/photcode-ps1-ref-v2.d	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/photcode-ps1-ref-v2.d	(revision 42803)
@@ -0,0 +1,33 @@
+STRUCT       PhotCode_PS1_REF_V2
+EXTNAME      DVO_PHOTCODE_PS1_REF_V2
+TYPE         BINTABLE
+SIZE         104
+DESCRIPTION  DVO Photcode Description Table 
+
+# elements of data structure / FITS table
+FIELD  code,         	  CODE,          	 unsigned short, code number (stored in Measure.source) 
+FIELD  name,         	  NAME,          	 char[32],       name for filter combination 
+FIELD  type,         	  TYPE,          	 char,           PRI/SEC/DEP/REF 
+FIELD  dummy,        	  DUMMY,         	 char[3],        padding
+FIELD  C,            	  C_LAM,         	 short,          primary phot calibration terms (millimags) 
+FIELD  dC,           	  C_LAM_ERR,     	 short,          primary phot calibration terms (millimags) 
+FIELD  dX,           	  X_ERR,         	 short,          primary phot calibration terms (millimags) 
+FIELD  K,            	  K,             	 float,          secondary phot calibration terms (millimags) 
+FIELD  c1,           	  C1,            	 int,            color is average.M[c1] - average.M[c2] 
+FIELD  c2,           	  C2,            	 int,            color is average.M[c1] - average.M[c2] 
+FIELD  equiv,        	  EQUIV,         	 int,            this dependent filter is equivalent to equiv PRI/SEC
+FIELD  Nc,           	  NC,            	 int,            number of color terms 
+FIELD  X,            	  X,             	 float[4],       color terms $X[0]*mc + X[1]*mc^2 + X[2]*mc^3$, etc 
+FIELD  astromErrSys,      ASTROM_ERR_SYS,  	 float,          systematic astrometry error (arcsec)
+FIELD  astromErrScale,    ASTROM_ERR_SCALE,  	 float,          astrometric error scale
+FIELD  astromErrMagScale, ASTROM_ERR_MAG_SCALE,  float,          astrometric error / mag error scale
+FIELD  astromPoorMask,    ASTROM_POOR_MASK,      short,          detections matching this mask should only be used in emergencies
+FIELD  astromBadMask,     ASTROM_BAD_MASK,       short,          detections matching this mask should not be used
+FIELD  photomErrSys,   	  PHOTOM_ERR_SYS,  	 float,          systematic photometric error
+FIELD  photomPoorMask, 	  PHOTOM_POOR_MASK,  	 short,          detections matching this mask should only be used in emergencies
+FIELD  photomBadMask,  	  PHOTOM_BAD_MASK,  	 short,          detections matching this mask should not be used
+
+#   dR_total^2 =  dR_sys^2 + AS * dR_obs^2 + MS * dM_obs^2
+#   dR_sys : systematicAstrometryError
+#   AS     : astrometryErrorScale
+#   MS     : astrometryErrorMagScale
Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/photcode-ps1-ref-v3.d
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/photcode-ps1-ref-v3.d	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/photcode-ps1-ref-v3.d	(revision 42803)
@@ -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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/secfilt-ps1-ref-v2.d
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/secfilt-ps1-ref-v2.d	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/secfilt-ps1-ref-v2.d	(revision 42803)
@@ -0,0 +1,9 @@
+STRUCT       SecFilt_PS1_REF_V2
+EXTNAME      DVO_SECFILT_PS1_REF_V2
+TYPE         BINTABLE
+SIZE         8
+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
Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/secfilt-ps1-ref-v3.d
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/secfilt-ps1-ref-v3.d	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libautocode/def/secfilt-ps1-ref-v3.d	(revision 42803)
@@ -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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/Makefile
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/Makefile	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/Makefile	(revision 42803)
@@ -53,4 +53,6 @@
 $(DESTINC)/ps1_v5_ld_defs.h \
 $(DESTINC)/ps1_ref_defs.h \
+$(DESTINC)/ps1_ref_v2_defs.h \
+$(DESTINC)/ps1_ref_v3_defs.h \
 $(DESTINC)/ps1_sim_defs.h \
 $(DESTINC)/cmf-ps1-dv3.h \
@@ -105,4 +107,6 @@
 $(SRC)/dvo_convert_PS1_V5_LOAD.$(ARCH).o \
 $(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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/include/dvo.h
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/include/dvo.h	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/include/dvo.h	(revision 42803)
@@ -27,4 +27,6 @@
   DVO_FORMAT_PS1_DEV_3,
   DVO_FORMAT_PS1_REF,
+  DVO_FORMAT_PS1_REF_V2,
+  DVO_FORMAT_PS1_REF_V3,
   DVO_FORMAT_PS1_SIM,
   DVO_FORMAT_PS1_V1,
@@ -251,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)
@@ -1087,4 +1094,6 @@
 # include "ps1_v5_ld_defs.h"
 # include "ps1_ref_defs.h"
+# include "ps1_ref_v2_defs.h"
+# include "ps1_ref_v3_defs.h"
 # include "ps1_sim_defs.h"
 
Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/include/ps1_ref_v2_defs.h
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/include/ps1_ref_v2_defs.h	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/include/ps1_ref_v2_defs.h	(revision 42803)
@@ -0,0 +1,11 @@
+Image 		       	*Image_PS1_REF_V2_ToInternal (Image_PS1_REF_V2 *in, off_t Nvalues, off_t Nalloc);
+Image_PS1_REF_V2    	*ImageInternalTo_PS1_REF_V2 (Image *in, off_t Nvalues);
+Average 	       	*Average_PS1_REF_V2_ToInternal (Average_PS1_REF_V2 *in, off_t Nvalues, SecFilt **primary);
+Average_PS1_REF_V2      *AverageInternalTo_PS1_REF_V2 (Average *in, off_t Nvalues, SecFilt *primary);
+Measure 	       	*Measure_PS1_REF_V2_ToInternal (Average *ave, Measure_PS1_REF_V2 *in, off_t Nvalues);
+Measure_PS1_REF_V2      *MeasureInternalTo_PS1_REF_V2 (Average *ave, Measure *in, off_t Nvalues);
+SecFilt 	       	*SecFilt_PS1_REF_V2_ToInternal (SecFilt_PS1_REF_V2 *in, off_t Nvalues);
+SecFilt_PS1_REF_V2      *SecFiltInternalTo_PS1_REF_V2 (SecFilt *in, off_t Nvalues);
+
+PhotCode                *PhotCode_PS1_REF_V2_To_Internal (PhotCode_PS1_REF_V2 *in, off_t Nvalues);
+PhotCode_PS1_REF_V2     *PhotCode_Internal_To_PS1_REF_V2 (PhotCode *in, off_t Nvalues);
Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/include/ps1_ref_v3_defs.h
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/include/ps1_ref_v3_defs.h	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/include/ps1_ref_v3_defs.h	(revision 42803)
@@ -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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/LoadPhotcodesFITS.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 42803)
@@ -59,4 +59,6 @@
   CONVERT_FORMAT("DVO_PHOTCODE_PS1_DEV_3",   PS1_DEV_3);
   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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_catalog.c	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_catalog.c	(revision 42803)
@@ -60,4 +60,6 @@
   if (!strcasecmp (catformat, "PS1_V5_LOAD"))     return (DVO_FORMAT_PS1_V5_LOAD);
   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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_catalog_raw.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 42803)
@@ -94,4 +94,6 @@
       FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
       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);
 
@@ -292,4 +294,6 @@
   if (catalog[0].catformat == DVO_FORMAT_PS1_V5_LOAD)     gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V5_LOAD");
   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");
 
@@ -399,4 +403,6 @@
       FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
       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);
 
@@ -454,4 +460,6 @@
       FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
       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);
 
@@ -512,4 +520,6 @@
       FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
       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);
 
@@ -567,4 +577,6 @@
       FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
       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);
 
@@ -626,4 +638,6 @@
       FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
       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);
 
@@ -681,4 +695,6 @@
       FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
       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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_convert.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_convert.c	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_convert.c	(revision 42803)
@@ -45,4 +45,6 @@
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5_LOAD",     PS1_V5_LOAD);
   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
@@ -137,4 +139,6 @@
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5_LOAD",     PS1_V5_LOAD,     PS1_V5_LOAD);
   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
@@ -176,4 +180,6 @@
       FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD);
       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
@@ -276,4 +282,6 @@
   CONVERT_FORMAT ("DVO_MEASURE_PS1_V5_LOAD",     PS1_V5_LOAD,     PS1_V5_LOAD,     TRUE);
   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
@@ -317,4 +325,6 @@
       FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD,     TRUE);
       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
@@ -385,4 +395,6 @@
   SKIPPING_FORMAT ("DVO_MISSING_PS1_SIM",         PS1_SIM,         PS1_SIM);
   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);
@@ -475,4 +487,6 @@
   CONVERT_FORMAT ("DVO_SECFILT_PS1_V5_LOAD",     PS1_V5_LOAD,     PS1_V5_LOAD);
   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
@@ -514,4 +528,6 @@
       FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD);
       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
@@ -609,4 +625,6 @@
 
   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);
@@ -650,4 +668,6 @@
 
 //    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);
@@ -731,4 +751,6 @@
 
   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);
@@ -772,4 +794,6 @@
 
 //    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);
@@ -841,4 +865,6 @@
   CONVERT_FORMAT  ("DVO_STARPAR_PS1_SIM",         PS1_SIM,         PS1_SIM);
   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);
@@ -882,4 +908,6 @@
       FORMAT_CASE (PS1_SIM,         PS1_SIM);
 //    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);
@@ -964,4 +992,6 @@
 
   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);
@@ -1005,4 +1035,6 @@
 
 //    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);
@@ -1094,4 +1126,6 @@
   CONVERT_FORMAT ("DVO_IMAGE_PS1_V5_LOAD",     PS1_V5_LOAD,     PS1_V5_LOAD);
   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);
 
@@ -1135,4 +1169,6 @@
     FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD);
     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);
 
@@ -1188,4 +1224,6 @@
     FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD);
     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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_convert_PS1_REF_V2.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_convert_PS1_REF_V2.c	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_convert_PS1_REF_V2.c	(revision 42803)
@@ -0,0 +1,358 @@
+# include <dvo.h>
+
+/* convert PS1_REF_V2 formats to internal formats */
+
+Measure *Measure_PS1_REF_V2_ToInternal (Average *ave, Measure_PS1_REF_V2 *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;
+  }
+  return (out);
+}
+
+Measure_PS1_REF_V2 *MeasureInternalTo_PS1_REF_V2 (Average *ave, Measure *in, off_t Nvalues) {
+
+  off_t i;
+  Measure_PS1_REF_V2 *out;
+
+  ALLOCATE_ZERO (out, Measure_PS1_REF_V2, 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;
+  }
+  return (out);
+}
+
+// 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
+Average *Average_PS1_REF_V2_ToInternal (Average_PS1_REF_V2 *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_V2 *AverageInternalTo_PS1_REF_V2 (Average *in, off_t Nvalues, SecFilt *primary) {
+  OHANA_UNUSED_PARAM(primary);
+
+  off_t i;
+  Average_PS1_REF_V2 *out;
+
+  ALLOCATE_ZERO (out, Average_PS1_REF_V2, 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_V2_ToInternal (SecFilt_PS1_REF_V2 *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;      
+ }
+  return (out);
+}
+
+SecFilt_PS1_REF_V2 *SecFiltInternalTo_PS1_REF_V2 (SecFilt *in, off_t Nvalues) {
+
+  off_t i;
+  SecFilt_PS1_REF_V2 *out;
+
+  ALLOCATE_ZERO (out, SecFilt_PS1_REF_V2, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].M             = in[i].MpsfChp;      
+    out[i].dM            = in[i].dMpsfChp;      
+  }
+  return (out);
+}
+
+# define RAW_IMAGE_NAME_LEN 121
+
+Image *Image_PS1_REF_V2_ToInternal (Image_PS1_REF_V2 *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_V2 *ImageInternalTo_PS1_REF_V2 (Image *in, off_t Nvalues) {
+
+  off_t i;
+  Image_PS1_REF_V2 *out;
+
+  ALLOCATE_ZERO (out, Image_PS1_REF_V2, 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_V2_To_Internal (PhotCode_PS1_REF_V2 *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_V2 *PhotCode_Internal_To_PS1_REF_V2 (PhotCode *in, off_t Nvalues) {
+
+  off_t i;
+  PhotCode_PS1_REF_V2 *out;
+
+  ALLOCATE_ZERO (out, PhotCode_PS1_REF_V2, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
+    out[i].name[31] = 0; // force termination
+
+    out[i].code  = in[i].code;         
+    out[i].type  = in[i].type;         
+    out[i].C     = in[i].C;            
+    out[i].dC 	 = in[i].dC;           
+    out[i].dX 	 = in[i].dX;           
+    out[i].K  	 = in[i].K;            
+    out[i].c1 	 = in[i].c1;           
+    out[i].c2 	 = in[i].c2;           
+    out[i].equiv = in[i].equiv;        
+    out[i].Nc    = in[i].Nc;           
+    memcpy (out[i].X, in[i].X, 4*sizeof(float));            
+
+    out[i].astromErrSys      = in[i].astromErrSys;
+    out[i].astromErrScale    = in[i].astromErrScale;
+    out[i].astromErrMagScale = in[i].astromErrMagScale;
+    out[i].photomErrSys      = in[i].photomErrSys;
+
+    out[i].photomPoorMask      = in[i].photomPoorMask;
+    out[i].photomBadMask       = in[i].photomBadMask;
+    out[i].astromPoorMask      = in[i].astromPoorMask;
+    out[i].astromBadMask       = in[i].astromBadMask;
+  }
+  return (out);
+}
Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_convert_PS1_REF_V3.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_convert_PS1_REF_V3.c	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_convert_PS1_REF_V3.c	(revision 42803)
@@ -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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_image.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_image.c	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_image.c	(revision 42803)
@@ -226,4 +226,6 @@
   if (db[0].format == DVO_FORMAT_PS1_V5_LOAD)     gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V5_LOAD");
   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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_image_raw.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 42803)
@@ -63,4 +63,6 @@
   if (db[0].format == DVO_FORMAT_PS1_V5_LOAD)     ImageSize = sizeof(Image_PS1_V5_LOAD);
   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);
 
@@ -97,4 +99,6 @@
   if (db[0].format == DVO_FORMAT_PS1_V5_LOAD)     gfits_table_mkheader_Image_PS1_V5_LOAD (&db[0].theader);
   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: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/Makefile
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/Makefile	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/Makefile	(revision 42803)
@@ -82,6 +82,7 @@
 $(SRC)/setExclusions.$(ARCH).o 	 \
 $(SRC)/setMrelFinal.$(ARCH).o 	 \
-$(SRC)/setMrelCatalog.$(ARCH).o 	 \
-$(SRC)/BoundaryTreeOps.$(ARCH).o 	 \
+$(SRC)/setMrelCatalog.$(ARCH).o   \
+$(SRC)/BoundaryTreeOps.$(ARCH).o  \
+$(SRC)/DumpAllMags.$(ARCH).o      \
 $(SRC)/write_coords.$(ARCH).o
 
Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/include/relphot.h
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/include/relphot.h	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/include/relphot.h	(revision 42803)
@@ -160,4 +160,7 @@
   float dY; // bin = int(Ychip * dY), dY = Ny / NyChip
   // NxChip, NyChip = 4900,4900 for now
+
+    int **nAlloc; // allocated vector length
+  double ***dMval; // values used to calculate corrections
 } GridCorrectionType;
 
@@ -607,4 +610,5 @@
 void          initGridBins        PROTO((void));
 GridCorrectionType *getGridCorrByCode PROTO((int code));
+GridCorrectionType *newGridCorrByCode PROTO((int code));
 GridCorrectionType *getGridCorrNext   PROTO((int *Nlast));
 int           GridCorrectionSave  PROTO((void));
@@ -894,2 +898,4 @@
 double get_median_zpt_tgroups (short photcode);
 void   set_median_zpt_tgroups (short photcode, double zpt);
+
+int DumpAllMags(char *filename, Catalog *catalog, int Ncatalog);
Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/DumpAllMags.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/DumpAllMags.c	(revision 42803)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/DumpAllMags.c	(revision 42803)
@@ -0,0 +1,231 @@
+# include "relphot.h"
+
+// STATUS is value expected for success
+# define CHECK_STATUS(STATUS,MSG,...)					\
+  if (!(STATUS)) {							\
+    fprintf (stderr, MSG, __VA_ARGS__);					\
+    return FALSE;							\
+  }
+
+int DumpAllMags(char *filename, Catalog *catalog, int Ncatalog) {
+
+  Header header;
+  Header theader;
+  Matrix matrix;
+  FTable ftable;
+
+  gfits_init_header (&header);
+  header.extend = TRUE;
+  gfits_create_header (&header);
+  gfits_create_matrix (&header, &matrix);
+
+  gfits_create_table_header (&theader, "BINTABLE", "DATA");
+
+  gfits_define_bintable_column (&theader, "D", "RA",       "ra",                         "degree", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "D", "DEC",      "dec",                        "degree", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "MCAL",     "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "MGRP",     "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "MMOS",     "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "MFLT",     "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "MGRD",     "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "MREL",     "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "MSYS",     "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "MOFF",     "", "", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "AIRMASS",  "", "unitless", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "D", "MJD",      "", "unitless", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "EXPTIME",  "", "unitless", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "J", "PHOTCODE", "", "unitless", 1.0, FT_BZERO_INT32);
+  gfits_define_bintable_column (&theader, "J", "IX",       "", "unitless", 1.0, FT_BZERO_INT32);
+  gfits_define_bintable_column (&theader, "J", "IY",       "", "unitless", 1.0, FT_BZERO_INT32);
+  gfits_define_bintable_column (&theader, "J", "XCCD",     "", "unitless", 1.0, FT_BZERO_INT32);
+  gfits_define_bintable_column (&theader, "J", "YCCD",     "", "unitless", 1.0, FT_BZERO_INT32);
+
+  // generate the output array that carries the data
+  gfits_create_table (&theader, &ftable);
+
+  // count the max number of measurements:
+  int NptsMax = 0;
+  for (int nc = 0; nc < Ncatalog; nc++) {
+    for (int na = 0; na < catalog[nc].Naverage; na++) {
+
+      int nm = catalog[nc].averageT[na].measureOffset;
+      for (int k = 0; k < catalog[nc].averageT[na].Nmeasure; k++, nm++) {
+	NptsMax++;
+      }
+    }
+  }
+
+  // create intermediate storage arrays
+  ALLOCATE_PTR (Rs,       double, NptsMax);
+  ALLOCATE_PTR (Ds,       double, NptsMax);
+  ALLOCATE_PTR (Mcal,     float,  NptsMax);
+  ALLOCATE_PTR (Mgrp,     float,  NptsMax);
+  ALLOCATE_PTR (Mmos,     float,  NptsMax);
+  ALLOCATE_PTR (Mflt,     float,  NptsMax);
+  ALLOCATE_PTR (Mgrd,     float,  NptsMax);
+  ALLOCATE_PTR (Mrel,     float,  NptsMax);
+  ALLOCATE_PTR (Msys,     float,  NptsMax);
+  ALLOCATE_PTR (Moff,     float,  NptsMax);
+  ALLOCATE_PTR (airmass,  float,  NptsMax);
+  ALLOCATE_PTR (mjd,      double, NptsMax);
+  ALLOCATE_PTR (exptime,  float,  NptsMax);
+  ALLOCATE_PTR (photcode, int,    NptsMax);
+  ALLOCATE_PTR (iX,       int,    NptsMax);
+  ALLOCATE_PTR (iY,       int,    NptsMax);
+  ALLOCATE_PTR (Xccd,     int,    NptsMax);
+  ALLOCATE_PTR (Yccd,     int,    NptsMax);
+
+  // XXXX fill in the vectors here
+  int Nsecfilt = GetPhotcodeNsecfilt ();
+
+  int Npts = 0;
+  for (int nc = 0; nc < Ncatalog; nc++) {
+    for (int na = 0; na < catalog[nc].Naverage; na++) {
+
+      int nm = catalog[nc].averageT[na].measureOffset;
+      for (int k = 0; k < catalog[nc].averageT[na].Nmeasure; k++, nm++) {
+
+	// skip measurements marked by AREA or TIME
+	if (catalog[nc].measureT[nm].dbFlags & MEAS_BAD) continue;
+
+	Mcal[Npts] = getMcal  (nm, nc, MAG_CLASS_PSF);
+	if (isnan(Mcal[Npts])) continue;
+
+	Mgrp[Npts] = getMgrp  (nm, nc, catalog[nc].measureT[nm].airmass, NULL);
+	if (isnan(Mgrp[Npts])) continue;
+
+	Mmos[Npts]  = getMmos  (nm, nc);
+	if (isnan(Mmos[Npts])) continue;
+
+	Mflt[Npts] = getMflat (nm, nc, catalog);
+	if (isnan(Mflt[Npts])) continue;
+
+	// Mrel* is the average magnitude for this star.  For PS1 stacks, we have too much
+	// PSF variability.  We need to calibrate the PSF magnitudes separately from the
+	// Aperture-like magnitues.  (We have an option to use the kron magnitudes or the
+	// other apertures here).  I basically need to do this analysis separately for each
+	// magnitude type
+    
+	// XXX works if we stop loop here
+	// Npts ++;
+	// continue;
+
+	Mrel[Npts] = getMrel  (catalog, nm, nc, MAG_CLASS_PSF, MAG_SRC_CHP);
+	if (isnan(Mrel[Npts])) continue;
+      
+	Msys[Npts] = PhotSysTiny (&catalog[nc].measureT[nm], &catalog[nc].averageT[na], &catalog[nc].secfilt[na*Nsecfilt], MAG_CLASS_PSF);
+	if (isnan(Msys[Npts])) continue;
+
+	Mgrd[Npts] = getMgridTiny (&catalog[nc].measureT[nm]); 
+	if (isnan(Mgrd[Npts])) continue;
+
+	Moff[Npts] = Mcal[Npts] + Mgrp[Npts] + Mmos[Npts] + Mflt[Npts] + Mgrd[Npts];
+
+	photcode[Npts] = catalog[nc].measureT[nm].photcode;
+
+	if (GRID_ZEROPT) {
+	  GridCorrectionType *grid = getGridCorrByCode(photcode[Npts]);
+	  if (!grid) continue; // does not match one of our images, skip
+
+	  // edge effects could cause some positions to be slightly out of range
+	  // probably should trap extreme outliers
+	  iX[Npts] = MIN(MAX(0, (int)(catalog[nc].measureT[nm].Xccd * grid->dX)), grid->Nx - 1);
+	  iY[Npts] = MIN(MAX(0, (int)(catalog[nc].measureT[nm].Yccd * grid->dY)), grid->Ny - 1);
+	} else {
+	  iX[Npts] = 0;
+	  iY[Npts] = 0;
+	}
+
+	Xccd[Npts] = catalog[nc].measureT[nm].Xccd;
+	Yccd[Npts] = catalog[nc].measureT[nm].Yccd;
+
+	Rs[Npts] = catalog[nc].measureT[nm].R;
+	Ds[Npts] = catalog[nc].measureT[nm].D;
+
+	airmass[Npts] = catalog[nc].measureT[nm].airmass;
+
+	exptime[Npts] = 0.0; // catalog[nc].measureT[nm].dt;
+	mjd[Npts]     = 0.0; // ohana_sec_to_mjd (catalog[nc].measureT[nm].tzero);
+
+	Npts ++;
+      }
+    }
+  }
+
+  // add the columns to the output array
+  gfits_set_bintable_column (&theader, &ftable, "RA",       Rs,       Npts);
+  gfits_set_bintable_column (&theader, &ftable, "DEC",      Ds,       Npts);
+  gfits_set_bintable_column (&theader, &ftable, "MCAL",     Mcal,     Npts);
+  gfits_set_bintable_column (&theader, &ftable, "MGRP",     Mgrp,     Npts);
+  gfits_set_bintable_column (&theader, &ftable, "MMOS",     Mmos,     Npts);
+  gfits_set_bintable_column (&theader, &ftable, "MFLT",     Mflt,     Npts);
+  gfits_set_bintable_column (&theader, &ftable, "MGRD",     Mgrd,     Npts);
+  gfits_set_bintable_column (&theader, &ftable, "MREL",     Mrel,     Npts);
+  gfits_set_bintable_column (&theader, &ftable, "MSYS",     Msys,     Npts);
+  gfits_set_bintable_column (&theader, &ftable, "MOFF",     Moff,     Npts);
+  gfits_set_bintable_column (&theader, &ftable, "AIRMASS",  airmass,  Npts);
+  gfits_set_bintable_column (&theader, &ftable, "MJD",      mjd,      Npts);
+  gfits_set_bintable_column (&theader, &ftable, "EXPTIME",  exptime,  Npts);
+  gfits_set_bintable_column (&theader, &ftable, "PHOTCODE", photcode, Npts);
+  gfits_set_bintable_column (&theader, &ftable, "IX",       iX,       Npts);
+  gfits_set_bintable_column (&theader, &ftable, "IY",       iY,       Npts);
+  gfits_set_bintable_column (&theader, &ftable, "XCCD",     Xccd,     Npts);
+  gfits_set_bintable_column (&theader, &ftable, "YCCD",     Yccd,     Npts);
+
+  free (Rs);
+  free (Ds);
+  free (Mcal);
+  free (Mgrp);
+  free (Mmos);
+  free (Mflt);
+  free (Mgrd);
+  free (Mrel);
+  free (Msys);
+  free (Moff);
+  free (airmass);
+  free (mjd);
+  free (exptime);
+  free (photcode);
+  free (iX);
+  free (iY);
+  free (Xccd);
+  free (Yccd);
+
+  FILE *f = fopen (filename, "w");
+  if (!f) {
+    fprintf (stderr, "ERROR: cannot open meanmag file for output %s\n", filename);
+    return FALSE;
+  }
+
+  int status;
+  status = gfits_fwrite_header  (f, &header);
+  CHECK_STATUS (status, "ERROR: cannot write header for meanmags %s\n", filename);
+
+  status = gfits_fwrite_matrix  (f, &matrix);
+  CHECK_STATUS (status, "ERROR: cannot write matrix for meanmags %s\n", filename);
+
+  status = gfits_fwrite_Theader (f, &theader);
+  CHECK_STATUS (status, "ERROR: cannot write table header for meanmags %s\n", filename);
+
+  status = gfits_fwrite_table  (f, &ftable);
+  CHECK_STATUS (status, "ERROR: cannot write table data for meanmags %s\n", filename);
+
+  gfits_free_header (&header);
+  gfits_free_matrix (&matrix);
+  gfits_free_header (&theader);
+  gfits_free_table (&ftable);
+
+  int fd = fileno (f);
+
+  status = fflush (f);
+  CHECK_STATUS (!status, "ERROR: cannot flush file mags %s\n", filename);
+
+  status = fsync (fd);
+  CHECK_STATUS (!status, "ERROR: cannot flush file mags %s\n", filename);
+
+  status = fclose (f);
+  CHECK_STATUS (!status, "ERROR: problem closing mags file %s\n", filename);
+
+  return TRUE;
+}
+
Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/GridIO.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/GridIO.c	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/GridIO.c	(revision 42803)
@@ -151,5 +151,5 @@
 
     if (!gfits_scan (&header, "PHOTCODE", "%d", 1, &photcode))    myAbort ("failed to get PHOTCODE");
-    GridCorrectionType *GridCorr = getGridCorrByCode (photcode);
+    GridCorrectionType *GridCorr = newGridCorrByCode (photcode);
     GridCorr->photcode = photcode;
 
Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/GridOps.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/GridOps.c	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/GridOps.c	(revision 42803)
@@ -30,6 +30,6 @@
 # define NX_CHIP_DEFAULT 1000
 # define NY_CHIP_DEFAULT 1000
-# define NX_BIN_DEFAULT 2
-# define NY_BIN_DEFAULT 2
+# define NX_BIN_DEFAULT 4
+# define NY_BIN_DEFAULT 4
 
 void initGridBins (void) {
@@ -76,4 +76,11 @@
       if (GridCorr[code]->dMgrid) FREE (GridCorr[code]->dMgrid[ix]);
       if (GridCorr[code]->nMgrid) FREE (GridCorr[code]->nMgrid[ix]);
+      if (GridCorr[code]->nAlloc) FREE (GridCorr[code]->nAlloc[ix]);
+
+      // dMval is a 2D array of vectors
+      for (int iy = 0; iy < GridCorr[code]->Ny; iy++) {
+	FREE (GridCorr[code]->dMval[ix][iy]);
+      }
+      FREE (GridCorr[code]->dMval[ix]);
     }      
 
@@ -81,4 +88,6 @@
     FREE (GridCorr[code]->dMgrid);
     FREE (GridCorr[code]->nMgrid);
+    FREE (GridCorr[code]->nAlloc);
+    FREE (GridCorr[code]-> dMval);
 
     FREE(GridCorr[code]);
@@ -109,5 +118,6 @@
 }
 
-GridCorrectionType *getGridCorrByCode (int code) {
+// generate a new GridCorr structure in the array
+GridCorrectionType *newGridCorrByCode (int code) {
 
   if (GridCorr == NULL) return NULL;
@@ -116,5 +126,18 @@
   if (code <          0) return NULL;
 
+  myAssert (GridCorr[code] == NULL, "oops, should not already be allocated!");
   ALLOCATE(GridCorr[code], GridCorrectionType, 1)
+  GridCorrectionType *result = GridCorr[code];
+  return result;
+}
+
+// return the GridCode structure corresponding to 'code'
+GridCorrectionType *getGridCorrByCode (int code) {
+
+  if (GridCorr == NULL) return NULL;
+
+  if (code >= NGridCorr) return NULL;
+  if (code <          0) return NULL;
+
   GridCorrectionType *result = GridCorr[code];
   return result;
@@ -163,11 +186,18 @@
     // we are normally accessing this array randomly, so there is no advantage to
     // doing Mgrid[y][x] vs Mgrid[x][y]
+    ALLOCATE (GridCorr[code]-> dMval, double **, NX_BIN);
     ALLOCATE (GridCorr[code]-> Mgrid, float *, NX_BIN);
     ALLOCATE (GridCorr[code]->dMgrid, float *, NX_BIN);
     ALLOCATE (GridCorr[code]->nMgrid,   int *, NX_BIN);
+    ALLOCATE (GridCorr[code]->nAlloc,   int *, NX_BIN);
     for (int ix = 0; ix < NX_BIN; ix++) {
       ALLOCATE (GridCorr[code]-> Mgrid[ix], float, NY_BIN);
       ALLOCATE (GridCorr[code]->dMgrid[ix], float, NY_BIN);
       ALLOCATE (GridCorr[code]->nMgrid[ix],   int, NY_BIN);
+      ALLOCATE (GridCorr[code]->nAlloc[ix],   int, NY_BIN);
+
+      // when we first allocate this array, set the elements to 0 (NULL)
+      // these arrays will be allocated or reallocated in resetMgrid
+      ALLOCATE_ZERO (GridCorr[code]-> dMval[ix], double *, NX_BIN);
     }      
   }
@@ -190,4 +220,12 @@
 	GridCorr[code]->dMgrid[ix][iy] = 0.0;
 	GridCorr[code]->nMgrid[ix][iy] =   0;
+	GridCorr[code]->nAlloc[ix][iy] = 100;
+
+	// allocate or reset vector length to default
+	if (GridCorr[code]->dMval[ix][iy]) {
+	  REALLOCATE (GridCorr[code]->dMval[ix][iy], double, GridCorr[code]->nAlloc[ix][iy]);
+	} else {
+	  ALLOCATE (GridCorr[code]->dMval[ix][iy], double, GridCorr[code]->nAlloc[ix][iy]);
+	}
       }
     }      
@@ -263,10 +301,49 @@
 	if (fabs(dM) > 0.5) continue;
 
-	grid-> Mgrid[ix][iy] += dM;
-	grid->dMgrid[ix][iy] += dM*dM;
+	int ival = grid->nMgrid[ix][iy];
+	grid-> dMval[ix][iy][ival] = dM;
 	grid->nMgrid[ix][iy] ++;
+	CHECK_REALLOCATE (grid-> dMval[ix][iy], double, grid->nAlloc[ix][iy], grid->nMgrid[ix][iy], 100);
+
+	/* XXX old code to calculate simple means:
+	   grid-> Mgrid[ix][iy] += dM;
+	   grid->dMgrid[ix][iy] += dM*dM;
+	   grid->nMgrid[ix][iy] ++;
+	*/
       }
     }
   }
+
+  StatType stats;
+  liststats_setmode (&stats, "MEDIAN");
+
+  // now calculate Mgrid, dMgrid, nMgrid from Sum, Sum, Npt
+  for (int code = 0; code < NGridCorr; code++) {
+    if (!GridCorr[code]) continue;
+
+    for (int ix = 0; ix < GridCorr[code]->Nx; ix++) {
+      for (int iy = 0; iy < GridCorr[code]->Ny; iy++) {
+
+	// cells without sufficient coverage stay at 0.0
+	if (GridCorr[code]->nMgrid[ix][iy] < 5) {
+	  GridCorr[code]-> Mgrid[ix][iy] = 0.0;
+	  GridCorr[code]->dMgrid[ix][iy] = 0.0;
+	  continue;
+	}
+
+	liststats_init (&stats);
+
+	liststats (GridCorr[code]->dMval[ix][iy], NULL, NULL, GridCorr[code]->nMgrid[ix][iy], &stats);
+	double altSigma = (stats.Upper80 - stats.Lower20) / 1.6;  // 20% to 80% encompasses 60% of the values, corresponds to the range (-0.85 sigma : +0.85 sigma)
+
+	GridCorr[code]-> Mgrid[ix][iy] = stats.median;
+	GridCorr[code]->dMgrid[ix][iy] = altSigma; // sample stdev
+      }
+    }
+  }
+  return;
+}
+
+# if (0)
 
   // now calculate Mgrid, dMgrid, nMgrid from Sum, Sum, Npt
@@ -300,7 +377,5 @@
     // float GridAve = GridSum / GridCnt;
     // fprintf (stderr, "grid average: %f\n", GridAve);
-  }
-  return;
-}
+# endif
 
 float getMgrid (Measure *measure) {
Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/MagResidSave.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/MagResidSave.c	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/MagResidSave.c	(revision 42803)
@@ -54,18 +54,18 @@
   gfits_create_table_header (&theader, "BINTABLE", "MAG_PSF_RESID");
 
-  gfits_define_bintable_column (&theader, "D", "RA",       "ra",                         "degree", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "D", "DEC",      "dec",                        "degree", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "MAG_RESID", "magnitude residual", "magnitudes", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "MAG_ERROR", "magnitude error", "magnitudes", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "MAG_CHISQ", "magnitude resid chisq", "unitless", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "MAG_MEDIAN", "median magnitude residual", "magnitudes", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "D", "RA",         "ra",                           "degree",     1.0, 0.0);
+  gfits_define_bintable_column (&theader, "D", "DEC",        "dec",                          "degree",     1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "MAG_RESID",  "magnitude residual",           "magnitudes", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "MAG_ERROR",  "magnitude error",              "magnitudes", 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "MAG_CHISQ",  "magnitude resid chisq",        "unitless",   1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "MAG_MEDIAN", "median magnitude residual",    "magnitudes", 1.0, 0.0);
   gfits_define_bintable_column (&theader, "E", "MAG_ALTSIG", "68 percentile range as sigma", "magnitudes", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "AIRMASS",   "", "unitless", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "D", "MJD",       "", "unitless", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "EXPTIME",   "", "unitless", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "J", "PHOTCODE",  "", "unitless", 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "J", "FLAGS",     "image flags", "unitless",   1.0, 0.0);
-  gfits_define_bintable_column (&theader, "J", "NFIT",      "number of stars fitted", NULL, 1.0, FT_BZERO_INT32);
-  gfits_define_bintable_column (&theader, "J", "NMEAS",     "number of stars on image", NULL, 1.0, FT_BZERO_INT32);
+  gfits_define_bintable_column (&theader, "E", "AIRMASS",    "",                             "unitless",   1.0, 0.0);
+  gfits_define_bintable_column (&theader, "D", "MJD",        "",                             "unitless",   1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "EXPTIME",    "",                             "unitless",   1.0, 0.0);
+  gfits_define_bintable_column (&theader, "J", "PHOTCODE",   "",                             "unitless",   1.0, 0.0);
+  gfits_define_bintable_column (&theader, "J", "FLAGS",      "image flags",                  "unitless",   1.0, 0.0);
+  gfits_define_bintable_column (&theader, "J", "NFIT",       "number of stars fitted",       NULL,         1.0, 0.0);
+  gfits_define_bintable_column (&theader, "J", "NMEAS",      "number of stars on image",     NULL,         1.0, 0.0);
 
   // generate the output array that carries the data
Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/relphot_images.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/relphot_images.c	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/relphot_images.c	(revision 42803)
@@ -147,4 +147,6 @@
     MagResidSave ("mag.resid.fits", catalog);
 
+    // DumpAllMags ("all.mags.fits", catalog, Ncatalog);
+
     save_images_updates (&db);
 
Index: branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/setMrelCatalog.c	(revision 42770)
+++ branches/eam_branches/ipp-ppmerge-20241229/Ohana/src/relphot/src/setMrelCatalog.c	(revision 42803)
@@ -412,4 +412,9 @@
       secfilt[Nsec].flags |= ID_SECF_HAS_CFH;
     }
+//  secfilt[Nsec].flags |= ID_SECF_AST_GAIA ; // for building reference catalog only, STAR_FEW need to comment out
+//  secfilt[Nsec].flags |= ID_SECF_PHO_SYNTH; // for building reference catalog only, STAR_FEW need to comment out
+//  secfilt[Nsec].flags |= ID_SECF_PHO_ATLAS; // for building reference catalog only, STAR_FEW need to comment out
+//  secfilt[Nsec].flags |= ID_SECF_PHO_PV3  ; // for building reference catalog only, STAR_FEW need to comment out
+//  secfilt[Nsec].flags |= ID_SECF_PHO_SOUTH; // for building reference catalog only, STAR_FEW need to comment out
 
     // if -preserve-ps1 is set and this object has PS1 data, skip the rest of the steps:
