Index: trunk/Ohana/src/libautocode/Makefile.Targets
===================================================================
--- trunk/Ohana/src/libautocode/Makefile.Targets	(revision 24745)
+++ trunk/Ohana/src/libautocode/Makefile.Targets	(revision 24746)
@@ -9,4 +9,5 @@
 $(ASRC)/average-ps1-dev-2.$(ARCH).o \
 $(ASRC)/average-ps1-v1.$(ARCH).o \
+$(ASRC)/average-ps1-ref.$(ARCH).o \
 $(ASRC)/secfilt.$(ARCH).o \
 $(ASRC)/secfilt-loneos.$(ARCH).o \
@@ -17,4 +18,5 @@
 $(ASRC)/secfilt-ps1-dev-2.$(ARCH).o \
 $(ASRC)/secfilt-ps1-v1.$(ARCH).o \
+$(ASRC)/secfilt-ps1-ref.$(ARCH).o \
 $(ASRC)/measure.$(ARCH).o \
 $(ASRC)/measure-loneos.$(ARCH).o \
@@ -25,4 +27,5 @@
 $(ASRC)/measure-ps1-dev-2.$(ARCH).o \
 $(ASRC)/measure-ps1-v1.$(ARCH).o \
+$(ASRC)/measure-ps1-ref.$(ARCH).o \
 $(ASRC)/missing.$(ARCH).o \
 $(ASRC)/photcode.$(ARCH).o \
@@ -32,4 +35,5 @@
 $(ASRC)/photcode-ps1-dev-3.$(ARCH).o \
 $(ASRC)/photcode-ps1-v1.$(ARCH).o \
+$(ASRC)/photcode-ps1-ref.$(ARCH).o \
 $(ASRC)/image.$(ARCH).o \
 $(ASRC)/image-loneos.$(ARCH).o \
@@ -41,4 +45,5 @@
 $(ASRC)/image-ps1-dev-3.$(ARCH).o \
 $(ASRC)/image-ps1-v1.$(ARCH).o \
+$(ASRC)/image-ps1-ref.$(ARCH).o \
 $(ASRC)/regimage.$(ARCH).o \
 $(ASRC)/detreg.$(ARCH).o \
@@ -69,4 +74,5 @@
 $(AINC)/average-ps1-dev-2.h \
 $(AINC)/average-ps1-v1.h \
+$(AINC)/average-ps1-ref.h \
 $(AINC)/secfilt.h \
 $(AINC)/secfilt-loneos.h \
@@ -77,4 +83,5 @@
 $(AINC)/secfilt-ps1-dev-2.h \
 $(AINC)/secfilt-ps1-v1.h \
+$(AINC)/secfilt-ps1-ref.h \
 $(AINC)/measure.h \
 $(AINC)/measure-loneos.h \
@@ -85,4 +92,5 @@
 $(AINC)/measure-ps1-dev-2.h \
 $(AINC)/measure-ps1-v1.h \
+$(AINC)/measure-ps1-ref.h \
 $(AINC)/missing.h \
 $(AINC)/photcode.h \
@@ -92,4 +100,5 @@
 $(AINC)/photcode-ps1-dev-3.h \
 $(AINC)/photcode-ps1-v1.h \
+$(AINC)/photcode-ps1-ref.h \
 $(AINC)/image.h \
 $(AINC)/image-loneos.h \
@@ -101,4 +110,5 @@
 $(AINC)/image-ps1-dev-3.h \
 $(AINC)/image-ps1-v1.h \
+$(AINC)/image-ps1-ref.h \
 $(AINC)/regimage.h \
 $(AINC)/detreg.h \
Index: trunk/Ohana/src/libautocode/def/average-ps1-ref.d
===================================================================
--- trunk/Ohana/src/libautocode/def/average-ps1-ref.d	(revision 24746)
+++ trunk/Ohana/src/libautocode/def/average-ps1-ref.d	(revision 24746)
@@ -0,0 +1,31 @@
+STRUCT       Average_PS1_REF
+EXTNAME      DVO_AVERAGE_PS1_REF
+TYPE         BINTABLE
+SIZE         48
+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 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 x double
+# 2 x float
+# 4 x int
+# 2 x short
+# 4 x char
+# = 48
Index: trunk/Ohana/src/libautocode/def/image-ps1-ref.d
===================================================================
--- trunk/Ohana/src/libautocode/def/image-ps1-ref.d	(revision 24746)
+++ trunk/Ohana/src/libautocode/def/image-ps1-ref.d	(revision 24746)
@@ -0,0 +1,72 @@
+STRUCT       Image_PS1_REF
+EXTNAME      DVO_IMAGE_PS1_REF
+TYPE         BINTABLE
+SIZE         344
+DESCRIPTION  DVO Image Table 
+
+# elements of the image structure
+
+SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
+SUBFIELD  crval1,           CRVAL1,               double,   	 coordinate at reference pixel
+SUBFIELD  crval2,           CRVAL2,               double,  	 coordinate at reference pixel
+SUBFIELD  crpix1,           CRPIX1,               float,   	 coordinate of reference pixel
+SUBFIELD  crpix2,           CRPIX2,               float,   	 coordinate of reference pixel
+SUBFIELD  cdelt1,           CDELT1,               float,   	 degrees per pixel
+SUBFIELD  cdelt2,           CDELT2,               float,    	 degrees per pixel
+SUBFIELD  pc1_1,            PC1_1,                float,    	 rotation matrix
+SUBFIELD  pc1_2,            PC1_2,                float,    	 rotation matrix
+SUBFIELD  pc2_1,            PC2_1,                float,    	 rotation matrix
+SUBFIELD  pc2_2,            PC2_2,                float,    	 rotation matrix
+SUBFIELD  polyterms,        POLYTERMS,            float[7][2],	 higher order warping terms
+SUBFIELD  ctype,            CTYPE,                char[15],      coordinate type
+SUBFIELD  Npolyterms,       NPOLYTERMS,           char,     	 order of polynomial
+# 120 bytes
+
+FIELD 	  tzero,            TZERO,                e_time,         readout time (row 0)
+FIELD 	  nstar,            NSTAR,                unsigned int,   number of stars on image
+FIELD 	  secz,             SECZ,                 float,      	  airmass,                   mag
+FIELD 	  NX,               NX,                   unsigned short, image width
+FIELD 	  NY,               NY,                   unsigned short, image height
+FIELD 	  apmifit,          APMIFIT,              float,      	  aperture correction,       mag
+FIELD 	  dapmifit,         DAPMIFIT,             float,      	  apmifit error,             mag
+FIELD 	  Mcal,             MCAL,                 float,      	  calibration mag,           mag
+FIELD 	  dMcal,            DMCAL,                float,      	  error on Mcal,             mag
+FIELD 	  Xm,               XM,                   short,      	  image chisq,               10*log(value)
+FIELD 	  photcode,         PHOTCODE,             short,      	  identifier for CCD,
+FIELD 	  exptime,          EXPTIME,              float,          exposure time,             seconds
+FIELD     sidtime,          ST,			  float,          sidereal time of exposure
+FIELD     latitude,         LAT,		  float,          observatory latitude,      degrees
+# 40 bytes
+
+# should we define the max length of name as a macro?
+FIELD 	  name,             NAME,                 char[121],      name of original image 
+FIELD 	  detection_limit,  DETECTION_LIMIT,      unsigned char,  detection limit,           10*mag
+FIELD 	  saturation_limit, SATURATION_LIMIT,     unsigned char,  saturation limit,          10*mag
+FIELD 	  cerror,           CERROR,               unsigned char,  astrometric error,         50*arcsec
+FIELD 	  fwhm_x,           FWHM_X,               unsigned char,  PSF x width,               25*arcsec
+FIELD 	  fwhm_y,           FWHM_Y,               unsigned char,  PSF y width,               25*arcsec
+FIELD 	  trate,            TRATE,                unsigned char,  scan rate,                 100 usec/pixel
+FIELD 	  ccdnum,           CCDNUM,               unsigned char,  CCD ID number
+FIELD 	  flags,            FLAGS,                unsigned int,   image quality flags
+FIELD 	  imageID,          IMAGE_ID,             unsigned int,   internal image ID
+FIELD 	  parentID,         PARENT_ID,            unsigned int,   associated ref image
+FIELD 	  externID,         EXTERN_ID,            unsigned int,   external image ID
+FIELD 	  sourceID,         SOURCE_ID,            unsigned short, analysis source ID
+# 48 bytes 
+
+FIELD 	  order,            ORDER,                short,      	  Mrel 2D polynomical order 
+FIELD 	  Mx,               MX,                   short,      	  Mrel polyterm
+FIELD 	  My,               MY,                   short,      	  Mrel polyterm
+FIELD 	  Mxx,              MXX,                  short,      	  Mrel polyterm
+FIELD 	  Mxy,              MXY,                  short,      	  Mrel polyterm
+FIELD 	  Myy,              MYY,                  short,      	  Mrel polyterm
+FIELD 	  Mxxx,             MXXX,                 short,      	  Mrel polyterm
+FIELD 	  Mxxy,             MXXY,                 short,      	  Mrel polyterm
+FIELD 	  Mxyy,             MXYY,                 short,      	  Mrel polyterm
+FIELD 	  Myyy,             MYYY,                 short,      	  Mrel polyterm
+FIELD 	  Mxxxx,            MXXXX,                short,      	  Mrel polyterm
+FIELD 	  Mxxxy,            MXXXY,                short,      	  Mrel polyterm
+FIELD 	  Mxxyy,            MXXYY,                short,      	  Mrel polyterm
+FIELD 	  Mxyyy,            MXYYY,                short,      	  Mrel polyterm
+FIELD 	  Myyyy,            MYYYY,                short,      	  Mrel polyterm
+# 40 bytes
Index: trunk/Ohana/src/libautocode/def/measure-ps1-ref.d
===================================================================
--- trunk/Ohana/src/libautocode/def/measure-ps1-ref.d	(revision 24746)
+++ trunk/Ohana/src/libautocode/def/measure-ps1-ref.d	(revision 24746)
@@ -0,0 +1,30 @@
+STRUCT       Measure_PS1_REF
+EXTNAME      DVO_MEASURE_PS1_REF
+TYPE         BINTABLE
+SIZE         40
+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 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
+
+# 5 x float 
+# 4 x int
+# 2 + 2
+# = 40 bytes
Index: trunk/Ohana/src/libautocode/def/photcode-ps1-ref.d
===================================================================
--- trunk/Ohana/src/libautocode/def/photcode-ps1-ref.d	(revision 24746)
+++ trunk/Ohana/src/libautocode/def/photcode-ps1-ref.d	(revision 24746)
@@ -0,0 +1,33 @@
+STRUCT       PhotCode_PS1_REF
+EXTNAME      DVO_PHOTCODE_PS1_REF
+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: trunk/Ohana/src/libautocode/def/secfilt-ps1-ref.d
===================================================================
--- trunk/Ohana/src/libautocode/def/secfilt-ps1-ref.d	(revision 24746)
+++ trunk/Ohana/src/libautocode/def/secfilt-ps1-ref.d	(revision 24746)
@@ -0,0 +1,9 @@
+STRUCT       SecFilt_PS1_REF
+EXTNAME      DVO_SECFILT_PS1_REF
+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
