Index: trunk/Ohana/src/libdvo/Makefile
===================================================================
--- trunk/Ohana/src/libdvo/Makefile	(revision 24747)
+++ trunk/Ohana/src/libdvo/Makefile	(revision 24748)
@@ -32,5 +32,6 @@
 $(DESTINC)/ps1_dev_2_defs.h \
 $(DESTINC)/ps1_dev_3_defs.h \
-$(DESTINC)/ps1_v1_defs.h
+$(DESTINC)/ps1_v1_defs.h \
+$(DESTINC)/ps1_ref_defs.h
 
 INCS = $(DEFS) $(DESTINC)/dvo.h $(DESTINC)/autocode.h
@@ -67,4 +68,5 @@
 $(SRC)/dvo_convert_PS1_DEV_3.$(ARCH).o \
 $(SRC)/dvo_convert_PS1_V1.$(ARCH).o \
+$(SRC)/dvo_convert_PS1_REF.$(ARCH).o \
 $(SRC)/skyregion_io.$(ARCH).o    \
 $(SRC)/skyregion_gsc.$(ARCH).o    \
Index: trunk/Ohana/src/libdvo/include/dvo.h
===================================================================
--- trunk/Ohana/src/libdvo/include/dvo.h	(revision 24747)
+++ trunk/Ohana/src/libdvo/include/dvo.h	(revision 24748)
@@ -19,5 +19,6 @@
 	      DVO_FORMAT_PS1_DEV_2,
 	      DVO_FORMAT_PS1_DEV_3,
-	      DVO_FORMAT_PS1_V1
+	      DVO_FORMAT_PS1_V1,
+	      DVO_FORMAT_PS1_REF
 } DVOTableFormat;
 
@@ -412,4 +413,5 @@
 # include "ps1_dev_3_defs.h"
 # include "ps1_v1_defs.h"
+# include "ps1_ref_defs.h"
 
 /*** DVO image db I/O Functions ***/
Index: trunk/Ohana/src/libdvo/include/ps1_ref_defs.h
===================================================================
--- trunk/Ohana/src/libdvo/include/ps1_ref_defs.h	(revision 24748)
+++ trunk/Ohana/src/libdvo/include/ps1_ref_defs.h	(revision 24748)
@@ -0,0 +1,11 @@
+Image 		       	*Image_PS1_REF_ToInternal (Image_PS1_REF *in, int Nvalues);
+Image_PS1_REF    	*ImageInternalTo_PS1_REF (Image *in, int Nvalues);
+Average 	       	*Average_PS1_REF_ToInternal (Average_PS1_REF *in, int Nvalues, SecFilt **primary);
+Average_PS1_REF          *AverageInternalTo_PS1_REF (Average *in, int Nvalues, SecFilt *primary);
+Measure 	       	*Measure_PS1_REF_ToInternal (Measure_PS1_REF *in, int Nvalues);
+Measure_PS1_REF          *MeasureInternalTo_PS1_REF (Measure *in, int Nvalues);
+SecFilt 	       	*SecFilt_PS1_REF_ToInternal (SecFilt_PS1_REF *in, int Nvalues);
+SecFilt_PS1_REF          *SecFiltInternalTo_PS1_REF (SecFilt *in, int Nvalues);
+
+PhotCode                *PhotCode_PS1_REF_To_Internal (PhotCode_PS1_REF *in, int Nvalues);
+PhotCode_PS1_REF         *PhotCode_Internal_To_PS1_REF (PhotCode *in, int Nvalues);
Index: trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c
===================================================================
--- trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 24747)
+++ trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 24748)
@@ -76,4 +76,10 @@
   } 
 
+  if (!strcmp (extname, "DVO_PHOTCODE_PS1_REF")) {
+    PhotCode_PS1_REF *photcode_ps1_ref = gfits_table_get_PhotCode_PS1_REF (&db.ftable, &Ncode, &db.swapped);
+    photcode = PhotCode_PS1_REF_To_Internal (photcode_ps1_ref, Ncode);
+    free (photcode_ps1_ref);
+  } 
+
   table = GetPhotcodeTable ();
   if (table[0].code != NULL) free (table[0].code);
Index: trunk/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 24747)
+++ trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 24748)
@@ -53,4 +53,5 @@
   if (!strcasecmp (catformat, "PS1_DEV_2"))       return (DVO_FORMAT_PS1_DEV_2);
   if (!strcasecmp (catformat, "PS1_V1"))          return (DVO_FORMAT_PS1_V1);
+  if (!strcasecmp (catformat, "PS1_REF"))         return (DVO_FORMAT_PS1_REF);
   return (DVO_FORMAT_UNDEF);
 }
Index: trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 24747)
+++ trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 24748)
@@ -87,4 +87,5 @@
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
       FORMAT_CASE (PS1_V1,    PS1_V1);
+      FORMAT_CASE (PS1_REF,   PS1_REF);
 
     default:
@@ -273,4 +274,5 @@
   if (catalog[0].catformat == DVO_FORMAT_PS1_DEV_2)       gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_DEV_2");
   if (catalog[0].catformat == DVO_FORMAT_PS1_V1)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V1");
+  if (catalog[0].catformat == DVO_FORMAT_PS1_REF)         gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_REF");
 
   /* rewind file pointers and truncate file */
@@ -369,4 +371,5 @@
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
       FORMAT_CASE (PS1_V1,    PS1_V1);
+      FORMAT_CASE (PS1_REF,   PS1_REF);
 
     default:
@@ -416,4 +419,5 @@
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
       FORMAT_CASE (PS1_V1,    PS1_V1);
+      FORMAT_CASE (PS1_REF,   PS1_REF);
 
     default:
@@ -467,4 +471,5 @@
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
       FORMAT_CASE (PS1_V1,    PS1_V1);
+      FORMAT_CASE (PS1_REF,   PS1_REF);
 
     default:
@@ -514,4 +519,5 @@
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
       FORMAT_CASE (PS1_V1,    PS1_V1);
+      FORMAT_CASE (PS1_REF,   PS1_REF);
 
     default:
@@ -565,4 +571,5 @@
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
       FORMAT_CASE (PS1_V1,    PS1_V1);
+      FORMAT_CASE (PS1_REF,   PS1_REF);
 
     default:
@@ -612,4 +619,5 @@
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
       FORMAT_CASE (PS1_V1,    PS1_V1);
+      FORMAT_CASE (PS1_REF,   PS1_REF);
 
     default:
Index: trunk/Ohana/src/libdvo/src/dvo_convert.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert.c	(revision 24747)
+++ trunk/Ohana/src/libdvo/src/dvo_convert.c	(revision 24748)
@@ -50,4 +50,5 @@
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_V1",          PS1_V1,          PS1_V1);
+  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF,         PS1_REF);
 # undef CONVERT_FORMAT
 
@@ -81,4 +82,5 @@
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
       FORMAT_CASE (PS1_V1,          PS1_V1);
+      FORMAT_CASE (PS1_REF,         PS1_REF);
 # undef FORMAT_CASE
 
@@ -125,4 +127,5 @@
   CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
   CONVERT_FORMAT ("DVO_MEASURE_PS1_V1",          PS1_V1,          PS1_V1);
+  CONVERT_FORMAT ("DVO_MEASURE_PS1_REF",         PS1_REF,         PS1_REF);
 # undef CONVERT_FORMAT
 
@@ -156,4 +159,5 @@
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
       FORMAT_CASE (PS1_V1,          PS1_V1);
+      FORMAT_CASE (PS1_REF,         PS1_REF);
 # undef FORMAT_CASE
 
@@ -200,4 +204,5 @@
   CONVERT_FORMAT ("DVO_SECFILT_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
   CONVERT_FORMAT ("DVO_SECFILT_PS1_V1",          PS1_V1,          PS1_V1);
+  CONVERT_FORMAT ("DVO_SECFILT_PS1_REF",         PS1_REF,         PS1_REF);
 # undef CONVERT_FORMAT
 
@@ -231,4 +236,5 @@
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
       FORMAT_CASE (PS1_V1,          PS1_V1);
+      FORMAT_CASE (PS1_REF,         PS1_REF);
 # undef FORMAT_CASE
 
@@ -295,4 +301,5 @@
   CONVERT_FORMAT ("DVO_IMAGE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
   CONVERT_FORMAT ("DVO_IMAGE_PS1_V1",          PS1_V1,          PS1_V1);
+  CONVERT_FORMAT ("DVO_IMAGE_PS1_REF",         PS1_REF,         PS1_REF);
 
   // XXX Not sure this was ever actually used -- it was not complete...
@@ -333,4 +340,5 @@
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
       FORMAT_CASE (PS1_V1,          PS1_V1);
+      FORMAT_CASE (PS1_REF,         PS1_REF);
 
       // XXX not sure this was actually used: it was incomplete
@@ -386,4 +394,5 @@
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
       FORMAT_CASE (PS1_V1,          PS1_V1);
+      FORMAT_CASE (PS1_REF,         PS1_REF);
 
       // XXX not sure this was used, it was incomplete
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c	(revision 24748)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c	(revision 24748)
@@ -0,0 +1,360 @@
+# include <dvo.h>
+
+/* convert PS1_REF formats to internal formats */
+
+Measure *Measure_PS1_REF_ToInternal (Measure_PS1_REF *in, int Nvalues) {
+
+  int i;
+  Measure *out;
+
+  ALLOCATE (out, Measure, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].dR         = in[i].dR;
+    out[i].dD         = in[i].dD;
+    out[i].M          = in[i].M;
+    out[i].Mcal       = NAN;
+    out[i].Map        = NAN;
+    out[i].dM         = in[i].dM;
+    out[i].dMcal      = NAN;
+    out[i].dt         = in[i].dt;
+    out[i].airmass    = NAN;
+    out[i].az         = NAN;
+    out[i].Xccd       = NAN;
+    out[i].Yccd       = NAN;
+    out[i].Sky        = NAN;
+    out[i].dSky       = NAN;
+    out[i].t          = in[i].t;
+    out[i].t_msec     = 0;
+    out[i].averef     = in[i].averef;
+    out[i].detID      = 0;
+    out[i].imageID    = 0;
+    out[i].objID      = in[i].objID;
+    out[i].catID      = in[i].catID;
+    out[i].extID      = 0;
+    out[i].psfQual    = NAN;
+    out[i].psfChisq   = NAN;
+    out[i].psfNdof    = 0;
+    out[i].psfNpix    = 0;
+    out[i].crNsigma   = NAN;
+    out[i].extNsigma  = NAN;
+    out[i].FWx 	      = 0;
+    out[i].FWy 	      = 0;
+    out[i].theta      = 0;
+    out[i].Mxx 	      = 0;
+    out[i].Mxy 	      = 0;
+    out[i].Myy 	      = 0;
+    out[i].dXccd      = 0;
+    out[i].dYccd      = 0;
+    out[i].posangle   = 0;
+    out[i].pltscale   = NAN;
+    out[i].photcode   = in[i].photcode;
+    out[i].dbFlags    = 0;
+    out[i].photFlags  = 0;
+  }
+  return (out);
+}
+
+Measure_PS1_REF *MeasureInternalTo_PS1_REF (Measure *in, int Nvalues) {
+
+  int i;
+  Measure_PS1_REF *out;
+
+  ALLOCATE (out, Measure_PS1_REF, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].dR         = in[i].dR;
+    out[i].dD         = in[i].dD;
+    out[i].M          = in[i].M;
+    out[i].dM         = in[i].dM;
+    out[i].dt         = in[i].dt;
+    out[i].t          = in[i].t;
+    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_ToInternal (Average_PS1_REF *in, int Nvalues, SecFilt **primary) {
+
+  int i;
+  Average *out;
+
+  ALLOCATE (out, Average, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].R        	 = in[i].R;      
+    out[i].D        	 = in[i].D;      
+    out[i].dR       	 = in[i].dR;
+    out[i].dD       	 = in[i].dD;
+    out[i].uR       	 = NAN;
+    out[i].uD       	 = NAN;
+    out[i].duR      	 = NAN;
+    out[i].duD      	 = NAN;
+    out[i].P        	 = NAN;
+    out[i].dP       	 = NAN;
+    out[i].Xp       	 = NAN;
+    out[i].ChiSq       	 = NAN;
+    out[i].Npos       	 = 0;
+    out[i].Nmeasure      = in[i].Nmeasure;     
+    out[i].Nmissing      = in[i].Nmissing;     
+    out[i].Nextend       = 0;
+    out[i].measureOffset = in[i].measureOffset; 
+    out[i].missingOffset = in[i].missingOffset;
+    out[i].extendOffset  = 0;
+    out[i].flags     	 = 0;
+    out[i].objID 	 = in[i].objID;
+    out[i].catID 	 = in[i].catID;
+    out[i].extID 	 = 0;
+  }
+  return (out);
+}
+
+// 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
+Average_PS1_REF *AverageInternalTo_PS1_REF (Average *in, int Nvalues, SecFilt *primary) {
+
+  int i;
+  Average_PS1_REF *out;
+
+  ALLOCATE (out, Average_PS1_REF, 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].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);
+}
+
+SecFilt *SecFilt_PS1_REF_ToInternal (SecFilt_PS1_REF *in, int Nvalues) {
+
+  int i;
+  SecFilt *out;
+
+  ALLOCATE (out, SecFilt, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].M     = in[i].M;      
+    out[i].dM    = in[i].dM;      
+    out[i].Xm    = NAN;
+    out[i].Ncode = 0;
+    out[i].Nused = 0;
+    out[i].M_20  = 0;
+    out[i].M_80  = 0;
+ }
+  return (out);
+}
+
+SecFilt_PS1_REF *SecFiltInternalTo_PS1_REF (SecFilt *in, int Nvalues) {
+
+  int i;
+  SecFilt_PS1_REF *out;
+
+  ALLOCATE (out, SecFilt_PS1_REF, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].M     = in[i].M;      
+    out[i].dM    = in[i].dM;      
+  }
+  return (out);
+}
+
+Image *Image_PS1_REF_ToInternal (Image_PS1_REF *in, int Nvalues) {
+
+  int i;
+  Image *out;
+
+  ALLOCATE (out, Image, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
+
+    strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
+    out[i].name[120] = 0; // force termination
+
+    out[i].tzero    	    = in[i].tzero;
+    out[i].nstar    	    = in[i].nstar;
+    out[i].secz	    	    = in[i].secz;
+    out[i].NX	    	    = in[i].NX;
+    out[i].NY	    	    = in[i].NY;
+    out[i].apmifit  	    = in[i].apmifit;
+    out[i].dapmifit 	    = in[i].dapmifit;
+    out[i].Mcal	    	    = in[i].Mcal;
+    out[i].dMcal    	    = in[i].dMcal;
+    out[i].Xm	    	    = in[i].Xm;
+    out[i].photcode   	    = in[i].photcode;
+    out[i].exptime  	    = in[i].exptime;
+    out[i].sidtime  	    = in[i].sidtime;
+    out[i].latitude  	    = in[i].latitude;
+    out[i].detection_limit  = in[i].detection_limit;
+    out[i].saturation_limit = in[i].saturation_limit;
+    out[i].cerror	    = in[i].cerror;
+    out[i].fwhm_x	    = in[i].fwhm_x;
+    out[i].fwhm_y	    = in[i].fwhm_y;
+    out[i].trate	    = in[i].trate;
+    out[i].ccdnum	    = in[i].ccdnum;
+    out[i].flags	    = in[i].flags;
+    out[i].imageID	    = in[i].imageID;
+    out[i].parentID	    = in[i].parentID;
+    out[i].externID	    = in[i].externID;
+    out[i].sourceID	    = in[i].sourceID;
+
+    out[i].order	    = in[i].order;
+    out[i].Mx		    = in[i].Mx;
+    out[i].My		    = in[i].My;
+    out[i].Mxx		    = in[i].Mxx;
+    out[i].Mxy		    = in[i].Mxy;
+    out[i].Myy		    = in[i].Myy;
+    out[i].Mxxx		    = in[i].Mxxx;
+    out[i].Mxxy		    = in[i].Mxxy;
+    out[i].Mxyy		    = in[i].Mxyy;
+    out[i].Myyy		    = in[i].Myyy;
+    out[i].Mxxxx	    = in[i].Mxxxx;
+    out[i].Mxxxy	    = in[i].Mxxxy;
+    out[i].Mxxyy	    = in[i].Mxxyy;
+    out[i].Mxyyy	    = in[i].Mxyyy;
+    out[i].Myyyy	    = in[i].Myyyy;
+  }
+  return (out);
+}
+
+Image_PS1_REF *ImageInternalTo_PS1_REF (Image *in, int Nvalues) {
+
+  int i;
+  Image_PS1_REF *out;
+
+  ALLOCATE (out, Image_PS1_REF, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
+
+    strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
+    out[i].name[120] = 0; // force termination
+
+    out[i].tzero    	    = in[i].tzero;
+    out[i].nstar    	    = in[i].nstar;
+    out[i].secz	    	    = in[i].secz;
+    out[i].NX	    	    = in[i].NX;
+    out[i].NY	    	    = in[i].NY;
+    out[i].apmifit  	    = in[i].apmifit;
+    out[i].dapmifit 	    = in[i].dapmifit;
+    out[i].Mcal	    	    = in[i].Mcal;
+    out[i].dMcal    	    = in[i].dMcal;
+    out[i].Xm	    	    = in[i].Xm;
+    out[i].photcode   	    = in[i].photcode;
+    out[i].exptime  	    = in[i].exptime;
+    out[i].sidtime  	    = in[i].sidtime;
+    out[i].latitude  	    = in[i].latitude;
+    out[i].detection_limit  = in[i].detection_limit;
+    out[i].saturation_limit = in[i].saturation_limit;
+    out[i].cerror	    = in[i].cerror;
+    out[i].fwhm_x	    = in[i].fwhm_x;
+    out[i].fwhm_y	    = in[i].fwhm_y;
+    out[i].trate	    = in[i].trate;
+    out[i].ccdnum	    = in[i].ccdnum;
+    out[i].flags	    = in[i].flags;
+    out[i].imageID	    = in[i].imageID;
+    out[i].parentID	    = in[i].parentID;
+    out[i].externID	    = in[i].externID;
+    out[i].sourceID	    = in[i].sourceID;
+
+    out[i].order	    = in[i].order;
+    out[i].Mx		    = in[i].Mx;
+    out[i].My		    = in[i].My;
+    out[i].Mxx		    = in[i].Mxx;
+    out[i].Mxy		    = in[i].Mxy;
+    out[i].Myy		    = in[i].Myy;
+    out[i].Mxxx		    = in[i].Mxxx;
+    out[i].Mxxy		    = in[i].Mxxy;
+    out[i].Mxyy		    = in[i].Mxyy;
+    out[i].Myyy		    = in[i].Myyy;
+    out[i].Mxxxx	    = in[i].Mxxxx;
+    out[i].Mxxxy	    = in[i].Mxxxy;
+    out[i].Mxxyy	    = in[i].Mxxyy;
+    out[i].Mxyyy	    = in[i].Mxyyy;
+    out[i].Myyyy	    = in[i].Myyyy;
+  }
+  return (out);
+}
+
+PhotCode *PhotCode_PS1_REF_To_Internal (PhotCode_PS1_REF *in, int Nvalues) {
+
+  int i;
+  PhotCode *out;
+
+  ALLOCATE (out, PhotCode, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
+    out[i].name[31] = 0; // force termination
+
+    out[i].code  = in[i].code;         
+    out[i].type  = in[i].type;         
+    out[i].C     = in[i].C;            
+    out[i].dC 	 = in[i].dC;           
+    out[i].dX 	 = in[i].dX;           
+    out[i].K  	 = in[i].K;            
+    out[i].c1 	 = in[i].c1;           
+    out[i].c2 	 = in[i].c2;           
+    out[i].equiv = in[i].equiv;        
+    out[i].Nc    = in[i].Nc;           
+    memcpy (out[i].X, in[i].X, 4*sizeof(float));            
+
+    out[i].astromErrSys      = in[i].astromErrSys;
+    out[i].astromErrScale    = in[i].astromErrScale;
+    out[i].astromErrMagScale = in[i].astromErrMagScale;
+    out[i].photomErrSys      = in[i].photomErrSys;
+
+    out[i].photomPoorMask      = in[i].photomPoorMask;
+    out[i].photomBadMask       = in[i].photomBadMask;
+    out[i].astromPoorMask      = in[i].astromPoorMask;
+    out[i].astromBadMask       = in[i].astromBadMask;
+  }
+  return (out);
+}
+
+PhotCode_PS1_REF *PhotCode_Internal_To_PS1_REF (PhotCode *in, int Nvalues) {
+
+  int i;
+  PhotCode_PS1_REF *out;
+
+  ALLOCATE (out, PhotCode_PS1_REF, 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: trunk/Ohana/src/libdvo/src/dvo_image.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_image.c	(revision 24747)
+++ trunk/Ohana/src/libdvo/src/dvo_image.c	(revision 24748)
@@ -197,4 +197,5 @@
   if (db[0].format == DVO_FORMAT_PS1_DEV_3)       gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_DEV_3");
   if (db[0].format == DVO_FORMAT_PS1_V1)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V1");
+  if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_REF");
   
   return;
Index: trunk/Ohana/src/libdvo/src/dvo_image_raw.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 24747)
+++ trunk/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 24748)
@@ -56,4 +56,5 @@
   if (db[0].format == DVO_FORMAT_PS1_DEV_3)       ImageSize = sizeof(Image_PS1_DEV_3);
   if (db[0].format == DVO_FORMAT_PS1_V1)          ImageSize = sizeof(Image_PS1_V1);
+  if (db[0].format == DVO_FORMAT_PS1_REF)         ImageSize = sizeof(Image_PS1_REF);
 
   /* check that filesize makes sense */
@@ -82,4 +83,5 @@
   if (db[0].format == DVO_FORMAT_PS1_DEV_3)       gfits_table_mkheader_Image_PS1_DEV_3 (&db[0].theader);
   if (db[0].format == DVO_FORMAT_PS1_V1)          gfits_table_mkheader_Image_PS1_V1 (&db[0].theader);
+  if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_table_mkheader_Image_PS1_REF (&db[0].theader);
     
   /* read data from file */
