Index: trunk/Ohana/src/libdvo/Makefile
===================================================================
--- trunk/Ohana/src/libdvo/Makefile	(revision 21153)
+++ trunk/Ohana/src/libdvo/Makefile	(revision 21508)
@@ -31,5 +31,6 @@
 $(DESTINC)/ps1_dev_1_defs.h \
 $(DESTINC)/ps1_dev_2_defs.h \
-$(DESTINC)/ps1_dev_3_defs.h
+$(DESTINC)/ps1_dev_3_defs.h \
+$(DESTINC)/ps1_v1_defs.h
 
 INCS = $(DEFS) $(DESTINC)/dvo.h $(DESTINC)/autocode.h
@@ -65,4 +66,5 @@
 $(SRC)/dvo_convert_PS1_DEV_2.$(ARCH).o \
 $(SRC)/dvo_convert_PS1_DEV_3.$(ARCH).o \
+$(SRC)/dvo_convert_PS1_V1.$(ARCH).o \
 $(SRC)/skyregion_io.$(ARCH).o    \
 $(SRC)/skyregion_gsc.$(ARCH).o    \
Index: trunk/Ohana/src/libdvo/doc/notes.txt
===================================================================
--- trunk/Ohana/src/libdvo/doc/notes.txt	(revision 21153)
+++ trunk/Ohana/src/libdvo/doc/notes.txt	(revision 21508)
@@ -2,9 +2,9 @@
 Adding a new dvo catalog format.  Assume the new format name is 'foo'.
 
-1) create the autocode definition files for average, measure, secfilt, image
-   these files must be a subset of the internal versions of these same
-   tables.  if you intend to add fields which don't exist in the
-   internal tables, you must update the internal tables as well.  the
-   naming convention is: average-foo.d, etc.
+1) create the autocode definition files for average, measure, secfilt,
+   image, and photcode.  these files must be a subset of the internal
+   versions of these same tables.  if you intend to add fields which
+   don't exist in the internal tables, you must update the internal
+   tables as well.  the naming convention is: average-foo.d, etc.
 
 2) add the new definition files to libautocode/Makefile.Targets (both
@@ -22,19 +22,26 @@
  (libdvo/src/dvo_catalog.c).  The name should be "FOO".
 
-6) add entry for structure size in dvo_catalog_load_raw
-   (libdvo/src/dvo_catalog_raw.c), since this is not available from
-   the header.
+6) in libdvo/src/dvo_catalog_raw.c, update the FORMAT_CASE lists to
+   include the new STRUCT name.
 
-7) add entries in ReadRawAverage, WriteRawAverage, ReadRawMeasure,
-   WriteRawMeasure, ReadRawSecFilt, WriteRawSecFilt.  Make sure to use
-   the new STRUCT names. the conversion function gfit_convert_Foo will
-   be automatically generated.
+7) create a new conversion file dvo_convert_foo.c and define the
+   internal to Foo conversions.
 
-8) add entry in WriteRawAverage, making sure to use the new STRUCT
-   name. the conversion function gfit_convert_Foo will be
-   automatically generated.  
+8) add the new format to the list of FORMAT conversion in dvo_convert.c.
 
-9) create a new conversion file dvo_convert_foo.c and define the
-   internal to Foo conversions.
+9) any changes to the internal format need to be reflected in the
+   functions in the dvo_convert_*.c files.  These files are defined so
+   that changed fields are sequential in the functions.  This should
+   make is easy to identify the new changes needed.
+
+10) add the new format to the section at the end of dvo_image.c
+
+11) add the new format to the dvo_image_raw.c
+
+12) add the photcode format conversions to libdvo/src/LoadPhotcodesFITS.c
+
+12) switch the output photcode format conversion ina libdvo/src/SavePhotcodesFITS.c
+
+13) Add the conversion functions to the header file libdvo/include/foo_defs.h
 
 * Note some esoteric format issues:  
@@ -54,2 +61,26 @@
     keywords.
 
+----
+
+20090207 : adding PS1_V1
+
+measure: 
+ new fields : t_msec, extID, Mxx, Mxy, Myy, dTccd; deprecated dophot
+ dbFlags, photFlags : uint16_t to uint64_t
+
+average:
+ new fields : ChiSq, Npos, flags (was code, uint16_t), extID
+
+secfilt:
+ new fields : M_20, M_80; dropped dummy
+
+image:
+ new fields : parentID, flags (was code char), changed name to 121 bytes.
+
+photcode:
+ new fields : NONE
+
+** parentID was added to enable easy lookups from chip->fpa for mosaic
+   astrometry.  In old databases, this conversion was done by making
+   the match via the time and photcode.  This conversion needs to be
+   done on load...
Index: trunk/Ohana/src/libdvo/include/dvo.h
===================================================================
--- trunk/Ohana/src/libdvo/include/dvo.h	(revision 21153)
+++ trunk/Ohana/src/libdvo/include/dvo.h	(revision 21508)
@@ -18,5 +18,6 @@
 	      DVO_FORMAT_PS1_DEV_1,
 	      DVO_FORMAT_PS1_DEV_2,
-	      DVO_FORMAT_PS1_DEV_3
+	      DVO_FORMAT_PS1_DEV_3,
+	      DVO_FORMAT_PS1_V1
 } DVOTableFormat;
 
@@ -407,4 +408,5 @@
 # include "ps1_dev_2_defs.h"
 # include "ps1_dev_3_defs.h"
+# include "ps1_v1_defs.h"
 
 /*** DVO image db I/O Functions ***/
@@ -444,5 +446,4 @@
 void sort_image_subset (Image *image, int *subset, int N);
 void sort_coords_index (double *X, double *Y, int *S, int N);
-void sort_stars_ra (Stars *stars, int N);
 void sort_regions (SkyRegion *region, int N);
 
Index: trunk/Ohana/src/libdvo/include/ps1_v1_defs.h
===================================================================
--- trunk/Ohana/src/libdvo/include/ps1_v1_defs.h	(revision 21508)
+++ trunk/Ohana/src/libdvo/include/ps1_v1_defs.h	(revision 21508)
@@ -0,0 +1,11 @@
+Image 		       	*Image_PS1_V1_ToInternal (Image_PS1_V1 *in, int Nvalues);
+Image_PS1_V1    	*ImageInternalTo_PS1_V1 (Image *in, int Nvalues);
+Average 	       	*Average_PS1_V1_ToInternal (Average_PS1_V1 *in, int Nvalues, SecFilt **primary);
+Average_PS1_V1          *AverageInternalTo_PS1_V1 (Average *in, int Nvalues, SecFilt *primary);
+Measure 	       	*Measure_PS1_V1_ToInternal (Measure_PS1_V1 *in, int Nvalues);
+Measure_PS1_V1          *MeasureInternalTo_PS1_V1 (Measure *in, int Nvalues);
+SecFilt 	       	*SecFilt_PS1_V1_ToInternal (SecFilt_PS1_V1 *in, int Nvalues);
+SecFilt_PS1_V1          *SecFiltInternalTo_PS1_V1 (SecFilt *in, int Nvalues);
+
+PhotCode                *PhotCode_PS1_V1_To_Internal (PhotCode_PS1_V1 *in, int Nvalues);
+PhotCode_PS1_V1         *PhotCode_Internal_To_PS1_V1 (PhotCode *in, int Nvalues);
Index: trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c
===================================================================
--- trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 21508)
@@ -40,5 +40,11 @@
   gfits_scan (&db.theader, "EXTNAME", "%s", 1, extname);
 
-  if (!strcmp (extname, "DVO_PHOTCODE") || !strcmp (extname, "DVO_PHOTCODE_ELIXIR")) {
+  if (!strcmp (extname, "DVO_PHOTCODE")) {
+    PhotCode_Elixir *photcode_elixir = gfits_table_get_PhotCode_Elixir (&db.ftable, &Ncode, &db.swapped);
+    photcode = PhotCode_Elixir_To_Internal (photcode_elixir, Ncode);
+    free (photcode_elixir);
+  } 
+
+  if (!strcmp (extname, "DVO_PHOTCODE_ELIXIR")) {
     PhotCode_Elixir *photcode_elixir = gfits_table_get_PhotCode_Elixir (&db.ftable, &Ncode, &db.swapped);
     photcode = PhotCode_Elixir_To_Internal (photcode_elixir, Ncode);
@@ -62,4 +68,10 @@
     photcode = PhotCode_PS1_DEV_3_To_Internal (photcode_ps1_dev_3, Ncode);
     free (photcode_ps1_dev_3);
+  } 
+
+  if (!strcmp (extname, "DVO_PHOTCODE_PS1_V1")) {
+    PhotCode_PS1_V1 *photcode_ps1_v1 = gfits_table_get_PhotCode_PS1_V1 (&db.ftable, &Ncode, &db.swapped);
+    photcode = PhotCode_PS1_V1_To_Internal (photcode_ps1_v1, Ncode);
+    free (photcode_ps1_v1);
   } 
 
Index: trunk/Ohana/src/libdvo/src/SavePhotcodesFITS.c
===================================================================
--- trunk/Ohana/src/libdvo/src/SavePhotcodesFITS.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/SavePhotcodesFITS.c	(revision 21508)
@@ -29,9 +29,9 @@
   // for the moment, we simply support the latest photcode format for output
   // XXX update this as needed as new formats are defined
-  PhotCode_PS1_DEV_3 *photcode_output = PhotCode_Internal_To_PS1_DEV_3 (table[0].code, table[0].Ncode);
+  PhotCode_PS1_V1 *photcode_output = PhotCode_Internal_To_PS1_V1 (table[0].code, table[0].Ncode);
 
   /* convert FITS format data to internal format (byteswaps & EXTNAME) */
   gfits_db_create (&db);
-  gfits_table_set_PhotCode_PS1_DEV_3 (&db.ftable, photcode_output, table[0].Ncode);
+  gfits_table_set_PhotCode_PS1_V1 (&db.ftable, photcode_output, table[0].Ncode);
   gfits_db_save (&db);
   gfits_db_close (&db);
Index: trunk/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 21508)
@@ -52,4 +52,5 @@
   if (!strcasecmp (catformat, "PS1_DEV_1"))       return (DVO_FORMAT_PS1_DEV_1);
   if (!strcasecmp (catformat, "PS1_DEV_2"))       return (DVO_FORMAT_PS1_DEV_2);
+  if (!strcasecmp (catformat, "PS1_V1"))          return (DVO_FORMAT_PS1_V1);
   return (DVO_FORMAT_UNDEF);
 }
Index: trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c	(revision 21508)
@@ -86,4 +86,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
@@ -271,4 +272,5 @@
   if (catalog[0].catformat == DVO_FORMAT_PS1_DEV_1)       gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_DEV_1");
   if (catalog[0].catformat == DVO_FORMAT_PS1_DEV_2)       gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_DEV_2");
+  if (catalog[0].catformat == DVO_FORMAT_PS1_V1)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V1");
 
   /* rewind file pointers and truncate file */
@@ -366,4 +368,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
@@ -412,4 +415,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
@@ -462,4 +466,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
@@ -508,4 +513,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
@@ -558,4 +564,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
@@ -604,4 +611,5 @@
       FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,    PS1_V1);
 
     default:
Index: trunk/Ohana/src/libdvo/src/dvo_convert.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/dvo_convert.c	(revision 21508)
@@ -49,4 +49,5 @@
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
   CONVERT_FORMAT ("DVO_AVERAGE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
+  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V1",          PS1_V1,          PS1_V1);
 # undef CONVERT_FORMAT
 
@@ -79,4 +80,5 @@
       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,          PS1_V1);
 # undef FORMAT_CASE
 
@@ -122,4 +124,5 @@
   CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
   CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
+  CONVERT_FORMAT ("DVO_MEASURE_PS1_V1",          PS1_V1,          PS1_V1);
 # undef CONVERT_FORMAT
 
@@ -152,4 +155,5 @@
       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,          PS1_V1);
 # undef FORMAT_CASE
 
@@ -195,4 +199,5 @@
   CONVERT_FORMAT ("DVO_SECFILT_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
   CONVERT_FORMAT ("DVO_SECFILT_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
+  CONVERT_FORMAT ("DVO_SECFILT_PS1_V1",          PS1_V1,          PS1_V1);
 # undef CONVERT_FORMAT
 
@@ -225,4 +230,5 @@
       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
+      FORMAT_CASE (PS1_V1,          PS1_V1);
 # undef FORMAT_CASE
 
@@ -288,5 +294,9 @@
   CONVERT_FORMAT ("DVO_IMAGE_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
   CONVERT_FORMAT ("DVO_IMAGE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
-  CONVERT_FORMAT ("DVO_IMAGE_PS1_DEV_3",       PS1_DEV_3,       PS1_DEV_3);
+  CONVERT_FORMAT ("DVO_IMAGE_PS1_V1",          PS1_V1,          PS1_V1);
+
+  // XXX Not sure this was ever actually used -- it was not complete...
+  // CONVERT_FORMAT ("DVO_IMAGE_PS1_DEV_3",       PS1_DEV_3,       PS1_DEV_3);
+
 # undef CONVERT_FORMAT
 
@@ -322,5 +332,8 @@
       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
-      FORMAT_CASE (PS1_DEV_3,       PS1_DEV_3);
+      FORMAT_CASE (PS1_V1,          PS1_V1);
+
+      // XXX not sure this was actually used: it was incomplete
+      // FORMAT_CASE (PS1_DEV_3,       PS1_DEV_3);
 # undef FORMAT_CASE
 
@@ -372,5 +385,9 @@
       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
-      FORMAT_CASE (PS1_DEV_3,       PS1_DEV_3);
+      FORMAT_CASE (PS1_V1,          PS1_V1);
+
+      // XXX not sure this was used, it was incomplete
+      // FORMAT_CASE (PS1_DEV_3,       PS1_DEV_3);
+
 # undef FORMAT_CASE
 
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 21508)
@@ -15,5 +15,4 @@
     out[i].M          = in[i].M;
     out[i].Mcal       = in[i].Mcal;
-    out[i].Map        = in[i].Mgal;
     out[i].dM         = in[i].dM;
     out[i].dt         = in[i].dt;
@@ -28,5 +27,5 @@
     out[i].detID      = in[i].detID;
     out[i].imageID    = in[i].imageID;
-    out[i].qPSF       = in[i].qPSF;
+    out[i].psfQual    = in[i].psfQual;
     out[i].psfChisq   = in[i].psfChisq;
     out[i].crNsigma   = in[i].crNsigma;
@@ -40,6 +39,22 @@
     out[i].dbFlags    = in[i].dbFlags;
     out[i].photFlags  = in[i].photFlags;
-    out[i].stargal    = in[i].stargal;
-    out[i].dophot     = in[i].dophot;
+
+    // changed or added for PS1_DEV_2
+    out[i].Map        = in[i].Mgal;
+    out[i].dMcal      = 0; 
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].photFlags | (in[i].dophot << 16);
+    out[i].t_msec     = 0;
+    out[i].extID      = 0;
+    out[i].objID      = 0;
+    out[i].catID      = 0;
+    out[i].Mxx 	      = 0.0;
+    out[i].Mxy 	      = 0.0;
+    out[i].Myy        = 0.0;
+    out[i].posangle   = 0;
+    out[i].pltscale   = 0;
+    out[i].psfNdof    = 0;
+    out[i].psfNpix    = 0;
   }
   return (out);
@@ -58,5 +73,4 @@
     out[i].M          = in[i].M;
     out[i].Mcal       = in[i].Mcal;
-    out[i].Mgal       = in[i].Map;
     out[i].dM         = in[i].dM;
     out[i].dt         = in[i].dt;
@@ -71,5 +85,5 @@
     out[i].detID      = in[i].detID;
     out[i].imageID    = in[i].imageID;
-    out[i].qPSF       = in[i].qPSF;
+    out[i].psfQual    = in[i].psfQual;
     out[i].psfChisq   = in[i].psfChisq;
     out[i].crNsigma   = in[i].crNsigma;
@@ -82,7 +96,11 @@
     out[i].dYccd      = in[i].dYccd;
     out[i].dbFlags    = in[i].dbFlags;
-    out[i].photFlags  = in[i].photFlags;
-    out[i].stargal    = in[i].stargal;
-    out[i].dophot     = in[i].dophot;
+
+    // changed or added for PS1_DEV_2
+    out[i].Mgal       = in[i].Map;
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].photFlags & 0x0000ffff;
+    out[i].dophot     = in[i].photFlags >> 16;
   }
   return (out);
@@ -101,9 +119,4 @@
     out[i].D        	 = in[i].D;      
     out[i].Xp       	 = in[i].Xp;     
-    out[i].Nmeasure      = in[i].Nm;     
-    out[i].Nmissing      = in[i].Nn;     
-    out[i].code     	 = in[i].code;   
-    out[i].measureOffset = in[i].offset; 
-    out[i].missingOffset = in[i].missing;
     out[i].dR       	 = in[i].dR;
     out[i].dD       	 = in[i].dD;
@@ -116,4 +129,18 @@
     out[i].objID 	 = in[i].objID;
     out[i].catID 	 = in[i].catID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Nmeasure      = in[i].Nm;     
+    out[i].Nmissing      = in[i].Nn;     
+    out[i].measureOffset = in[i].offset; 
+    out[i].missingOffset = in[i].missing;
+    out[i].Nextend       = 0;
+    out[i].extendOffset  = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags    	 = in[i].code;   
+    out[i].ChiSq       	 = 0.0;
+    out[i].Npos       	 = 0.0;
+    out[i].extID 	 = 0;
   }
   return (out);
@@ -129,22 +156,26 @@
 
   for (i = 0; i < Nvalues; i++) {
-    out[i].R        = in[i].R;      
-    out[i].D        = in[i].D;      
-    out[i].Xp       = in[i].Xp;     
-    out[i].Nm       = in[i].Nmeasure;     
-    out[i].Nn       = in[i].Nmissing;     
-    out[i].code     = in[i].code;   
-    out[i].offset   = in[i].measureOffset; 
-    out[i].missing  = in[i].missingOffset;
-    out[i].dR       = in[i].dR;
-    out[i].dD       = in[i].dD;
-    out[i].uR       = in[i].uR;
-    out[i].uD       = in[i].uD;
-    out[i].duR      = in[i].duR;
-    out[i].duD      = in[i].duD;
-    out[i].P        = in[i].P;
-    out[i].dP       = in[i].dP;
-    out[i].objID    = in[i].objID;
-    out[i].catID    = in[i].catID;
+    out[i].R        	 = in[i].R;      
+    out[i].D        	 = in[i].D;      
+    out[i].Xp       	 = in[i].Xp;     
+    out[i].dR       	 = in[i].dR;
+    out[i].dD       	 = in[i].dD;
+    out[i].uR       	 = in[i].uR;
+    out[i].uD       	 = in[i].uD;
+    out[i].duR      	 = in[i].duR;
+    out[i].duD      	 = in[i].duD;
+    out[i].P        	 = in[i].P;
+    out[i].dP       	 = in[i].dP;
+    out[i].objID    	 = in[i].objID;
+    out[i].catID    	 = in[i].catID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Nm       	 = in[i].Nmeasure;     
+    out[i].Nn       	 = in[i].Nmissing;     
+    out[i].offset   	 = in[i].measureOffset; 
+    out[i].missing  	 = in[i].missingOffset;
+
+    // changed or added for PS1_V1
+    out[i].code          = in[i].flags;   
   }
   return (out);
@@ -164,4 +195,8 @@
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
+
+    // changed or added for PS1_V1
+    out[i].M_20  = 0;      
+    out[i].M_80  = 0;      
  }
   return (out);
@@ -218,5 +253,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
     out[i].imageID	    = in[i].imageID;
@@ -237,4 +271,12 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_DEV_2
+    out[i].externID	    = 0;
+    out[i].sourceID	    = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -275,5 +317,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
     out[i].imageID	    = in[i].imageID;
@@ -294,4 +335,46 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
+
+PhotCode *PhotCode_PS1_DEV_1_To_Internal (PhotCode_PS1_DEV_1 *in, int Nvalues) {
+
+  int i;
+  PhotCode *out;
+
+  ALLOCATE (out, PhotCode, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
+    out[i].name[31] = 0; // force termination
+
+    out[i].code  = in[i].code;         
+    out[i].type  = in[i].type;         
+    out[i].C  	 = in[i].C;            
+    out[i].dC 	 = in[i].dC;           
+    out[i].dX 	 = in[i].dX;           
+    out[i].K  	 = in[i].K;            
+    out[i].c1 	 = in[i].c1;           
+    out[i].c2 	 = in[i].c2;           
+    out[i].equiv = in[i].equiv;        
+    out[i].Nc    = in[i].Nc;           
+    memcpy (out[i].X, in[i].X, 4*sizeof(float));            
+
+    out[i].astromErrMagScale = in[i].astromErrMagScale;
+    out[i].photomErrSys      = in[i].photomErrSys;
+
+    // changed or added for PS1_DEV_2
+    out[i].astromErrSys      = 0.0;
+    out[i].astromErrScale    = 0.0;
+
+    // changed or added for PS1_V1 (also PS1_DEV_3, deprecated)
+    out[i].photomPoorMask      = 0;
+    out[i].photomBadMask       = 0;
+    out[i].astromPoorMask      = 0;
+    out[i].astromBadMask       = 0;
   }
   return (out);
@@ -323,44 +406,5 @@
     out[i].astromErrMagScale = out[i].astromErrMagScale;
     out[i].photomErrSys      = out[i].photomErrSys;
-
-  }
-  return (out);
-}
-
-PhotCode *PhotCode_PS1_DEV_1_To_Internal (PhotCode_PS1_DEV_1 *in, int Nvalues) {
-
-  int i;
-  PhotCode *out;
-
-  ALLOCATE (out, PhotCode, Nvalues);
-
-  for (i = 0; i < Nvalues; i++) {
-    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
-    out[i].name[31] = 0; // force termination
-
-    out[i].code  = in[i].code;         
-    out[i].type  = in[i].type;         
-    out[i].C  	 = in[i].C;            
-    out[i].dC 	 = in[i].dC;           
-    out[i].dX 	 = in[i].dX;           
-    out[i].K  	 = in[i].K;            
-    out[i].c1 	 = in[i].c1;           
-    out[i].c2 	 = in[i].c2;           
-    out[i].equiv = in[i].equiv;        
-    out[i].Nc    = in[i].Nc;           
-
-    // not defined in PS1_DEV_1
-    out[i].astromErrSys      = 0.0;
-    out[i].astromErrScale    = 0.0;
-    out[i].astromErrMagScale = in[i].astromErrMagScale;
-    out[i].photomErrSys      = in[i].photomErrSys;
-
-    memcpy (out[i].X, in[i].X, 4*sizeof(float));            
-
-    out[i].photomPoorMask      = 0;
-    out[i].photomBadMask       = 0;
-    out[i].astromPoorMask      = 0;
-    out[i].astromBadMask       = 0;
-  }
-  return (out);
-}
+  }
+  return (out);
+}
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 21508)
@@ -29,5 +29,5 @@
     out[i].detID      = in[i].detID;
     out[i].imageID    = in[i].imageID;
-    out[i].qPSF       = in[i].qPSF;
+    out[i].psfQual    = in[i].psfQual;
     out[i].psfChisq   = in[i].psfChisq;
     out[i].crNsigma   = in[i].crNsigma;
@@ -40,7 +40,18 @@
     out[i].dYccd      = in[i].dYccd;
     out[i].dbFlags    = in[i].dbFlags;
-    out[i].photFlags  = in[i].photFlags;
-    out[i].stargal    = in[i].stargal;
-    out[i].dophot     = in[i].dophot;
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].photFlags | (in[i].dophot << 16);
+    out[i].t_msec     = 0;
+    out[i].extID      = 0;
+    out[i].objID      = 0;
+    out[i].catID      = 0;
+    out[i].Mxx 	      = 0.0;
+    out[i].Mxy 	      = 0.0;
+    out[i].Myy        = 0.0;
+    out[i].posangle   = 0;
+    out[i].pltscale   = 0;
+    out[i].psfNdof    = 0;
+    out[i].psfNpix    = 0;
   }
   return (out);
@@ -73,5 +84,5 @@
     out[i].detID      = in[i].detID;
     out[i].imageID    = in[i].imageID;
-    out[i].qPSF       = in[i].qPSF;
+    out[i].psfQual    = in[i].psfQual;
     out[i].psfChisq   = in[i].psfChisq;
     out[i].crNsigma   = in[i].crNsigma;
@@ -84,7 +95,8 @@
     out[i].dYccd      = in[i].dYccd;
     out[i].dbFlags    = in[i].dbFlags;
-    out[i].photFlags  = in[i].photFlags;
-    out[i].stargal    = in[i].stargal;
-    out[i].dophot     = in[i].dophot;
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].photFlags & 0x0000ffff;
+    out[i].dophot     = in[i].photFlags >> 16;
   }
   return (out);
@@ -114,5 +126,4 @@
     out[i].Nmissing      = in[i].Nmissing;     
     out[i].Nextend       = in[i].Nextend;     
-    out[i].code     	 = in[i].code;   
     out[i].measureOffset = in[i].measureOffset; 
     out[i].missingOffset = in[i].missingOffset;
@@ -120,4 +131,10 @@
     out[i].objID 	 = in[i].objID;
     out[i].catID 	 = in[i].catID;
+
+    // changed or added for PS1_V1
+    out[i].flags    	 = in[i].code;   
+    out[i].ChiSq       	 = 0.0;
+    out[i].Npos       	 = 0.0;
+    out[i].extID 	 = 0;
   }
   return (out);
@@ -147,5 +164,4 @@
     out[i].Nmissing      = in[i].Nmissing;     
     out[i].Nextend       = in[i].Nextend;     
-    out[i].code     	 = in[i].code;   
     out[i].measureOffset = in[i].measureOffset; 
     out[i].missingOffset = in[i].missingOffset;
@@ -153,4 +169,7 @@
     out[i].objID 	 = in[i].objID;
     out[i].catID 	 = in[i].catID;
+
+    // changed or added for PS1_V1
+    out[i].code     	 = in[i].flags;   
   }
   return (out);
@@ -170,4 +189,8 @@
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
+
+    // changed or added for PS1_V1
+    out[i].M_20  = 0;      
+    out[i].M_80  = 0;      
  }
   return (out);
@@ -201,5 +224,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
 
-    strncpy (out[i].name, in[i].name, 63); // out[128], int[64]
+    strncpy (out[i].name, in[i].name, 63); // out[121], int[64]
     out[i].name[63] = 0; // force termination
 
@@ -224,5 +247,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
     out[i].imageID	    = in[i].imageID;
@@ -245,4 +267,8 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -259,5 +285,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
 
-    strncpy (out[i].name, in[i].name, 63); // in[128], out[64]
+    strncpy (out[i].name, in[i].name, 63); // in[121], out[64]
     out[i].name[63] = 0; // force termination
 
@@ -282,5 +308,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
     out[i].imageID	    = in[i].imageID;
@@ -303,14 +328,17 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
-  }
-  return (out);
-}
-
-PhotCode_PS1_DEV_2 *PhotCode_Internal_To_PS1_DEV_2 (PhotCode *in, int Nvalues) {
-
-  int i;
-  PhotCode_PS1_DEV_2 *out;
-
-  ALLOCATE (out, PhotCode_PS1_DEV_2, Nvalues);
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
+
+PhotCode *PhotCode_PS1_DEV_2_To_Internal (PhotCode_PS1_DEV_2 *in, int Nvalues) {
+
+  int i;
+  PhotCode *out;
+
+  ALLOCATE (out, PhotCode, Nvalues);
 
   for (i = 0; i < Nvalues; i++) {
@@ -334,14 +362,20 @@
     out[i].astromErrMagScale = in[i].astromErrMagScale;
     out[i].photomErrSys      = in[i].photomErrSys;
-  }
-  return (out);
-}
-
-PhotCode *PhotCode_PS1_DEV_2_To_Internal (PhotCode_PS1_DEV_2 *in, int Nvalues) {
-
-  int i;
-  PhotCode *out;
-
-  ALLOCATE (out, PhotCode, Nvalues);
+
+    // changed or added for PS1_V1 (also PS1_DEV_3, deprecated)
+    out[i].photomPoorMask      = 0;
+    out[i].photomBadMask       = 0;
+    out[i].astromPoorMask      = 0;
+    out[i].astromBadMask       = 0;
+  }
+  return (out);
+}
+
+PhotCode_PS1_DEV_2 *PhotCode_Internal_To_PS1_DEV_2 (PhotCode *in, int Nvalues) {
+
+  int i;
+  PhotCode_PS1_DEV_2 *out;
+
+  ALLOCATE (out, PhotCode_PS1_DEV_2, Nvalues);
 
   for (i = 0; i < Nvalues; i++) {
@@ -365,10 +399,5 @@
     out[i].astromErrMagScale = in[i].astromErrMagScale;
     out[i].photomErrSys      = in[i].photomErrSys;
-
-    out[i].photomPoorMask      = 0;
-    out[i].photomBadMask       = 0;
-    out[i].astromPoorMask      = 0;
-    out[i].astromBadMask       = 0;
-  }
-  return (out);
-}
+  }
+  return (out);
+}
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c	(revision 21508)
@@ -3,5 +3,5 @@
 /* convert PS1_DEV_3 formats to internal formats */
 
-// XXX EAM I am not yet ready to commit to a full PS1_DEV_3 release, but I am providing image and photcode conversion
+// We only provide image and photcode conversion
 
 Image *Image_PS1_DEV_3_ToInternal (Image_PS1_DEV_3 *in, int Nvalues) {
@@ -38,5 +38,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
     out[i].imageID	    = in[i].imageID;
@@ -59,4 +58,8 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -96,5 +99,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
     out[i].imageID	    = in[i].imageID;
@@ -117,4 +119,43 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
+
+PhotCode *PhotCode_PS1_DEV_3_To_Internal (PhotCode_PS1_DEV_3 *in, int Nvalues) {
+
+  int i;
+  PhotCode *out;
+
+  ALLOCATE (out, PhotCode, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
+    out[i].name[31] = 0; // force termination
+
+    out[i].code  = in[i].code;         
+    out[i].type  = in[i].type;         
+    out[i].C     = in[i].C;            
+    out[i].dC 	 = in[i].dC;           
+    out[i].dX 	 = in[i].dX;           
+    out[i].K  	 = in[i].K;            
+    out[i].c1 	 = in[i].c1;           
+    out[i].c2 	 = in[i].c2;           
+    out[i].equiv = in[i].equiv;        
+    out[i].Nc    = in[i].Nc;           
+    memcpy (out[i].X, in[i].X, 4*sizeof(float));            
+
+    out[i].astromErrSys      = in[i].astromErrSys;
+    out[i].astromErrScale    = in[i].astromErrScale;
+    out[i].astromErrMagScale = in[i].astromErrMagScale;
+    out[i].photomErrSys      = in[i].photomErrSys;
+
+    out[i].photomPoorMask      = in[i].photomPoorMask;
+    out[i].photomBadMask       = in[i].photomBadMask;
+    out[i].astromPoorMask      = in[i].astromPoorMask;
+    out[i].astromBadMask       = in[i].astromBadMask;
   }
   return (out);
@@ -157,37 +198,2 @@
 }
 
-PhotCode *PhotCode_PS1_DEV_3_To_Internal (PhotCode_PS1_DEV_3 *in, int Nvalues) {
-
-  int i;
-  PhotCode *out;
-
-  ALLOCATE (out, PhotCode, Nvalues);
-
-  for (i = 0; i < Nvalues; i++) {
-    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
-    out[i].name[31] = 0; // force termination
-
-    out[i].code  = in[i].code;         
-    out[i].type  = in[i].type;         
-    out[i].C     = in[i].C;            
-    out[i].dC 	 = in[i].dC;           
-    out[i].dX 	 = in[i].dX;           
-    out[i].K  	 = in[i].K;            
-    out[i].c1 	 = in[i].c1;           
-    out[i].c2 	 = in[i].c2;           
-    out[i].equiv = in[i].equiv;        
-    out[i].Nc    = in[i].Nc;           
-    memcpy (out[i].X, in[i].X, 4*sizeof(float));            
-
-    out[i].astromErrSys      = in[i].astromErrSys;
-    out[i].astromErrScale    = in[i].astromErrScale;
-    out[i].astromErrMagScale = in[i].astromErrMagScale;
-    out[i].photomErrSys      = in[i].photomErrSys;
-
-    out[i].photomPoorMask      = in[i].photomPoorMask;
-    out[i].photomBadMask       = in[i].photomBadMask;
-    out[i].astromPoorMask      = in[i].astromPoorMask;
-    out[i].astromBadMask       = in[i].astromBadMask;
-  }
-  return (out);
-}
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 21508)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 21508)
@@ -0,0 +1,409 @@
+# include <dvo.h>
+
+/* convert PS1_V1 formats to internal formats */
+
+Measure *Measure_PS1_V1_ToInternal (Measure_PS1_V1 *in, int Nvalues) {
+
+  int i;
+  Measure *out;
+
+  ALLOCATE (out, Measure, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].dR         = in[i].dR;
+    out[i].dD         = in[i].dD;
+    out[i].M          = in[i].M;
+    out[i].Mcal       = in[i].Mcal;
+    out[i].Map        = in[i].Map;
+    out[i].dM         = in[i].dM;
+    out[i].dMcal      = in[i].dMcal;
+    out[i].dt         = in[i].dt;
+    out[i].airmass    = in[i].airmass;
+    out[i].az         = in[i].az;
+    out[i].Xccd       = in[i].Xccd;
+    out[i].Yccd       = in[i].Yccd;
+    out[i].Sky        = in[i].Sky;
+    out[i].dSky       = in[i].dSky;
+    out[i].t          = in[i].t;
+    out[i].t_msec     = in[i].t_msec;
+    out[i].averef     = in[i].averef;
+    out[i].detID      = in[i].detID;
+    out[i].imageID    = in[i].imageID;
+    out[i].objID      = in[i].objID;
+    out[i].catID      = in[i].catID;
+    out[i].extID      = in[i].extID;
+    out[i].psfQual    = in[i].psfQual;
+    out[i].psfChisq   = in[i].psfChisq;
+    out[i].psfNdof    = in[i].psfNdof;
+    out[i].psfNpix    = in[i].psfNpix;
+    out[i].crNsigma   = in[i].crNsigma;
+    out[i].extNsigma  = in[i].extNsigma;
+    out[i].FWx 	      = in[i].FWx;
+    out[i].FWy 	      = in[i].FWy;
+    out[i].theta      = in[i].theta;
+    out[i].Mxx 	      = in[i].Mxx;
+    out[i].Mxy 	      = in[i].Mxy;
+    out[i].Myy 	      = in[i].Myy;
+    out[i].dXccd      = in[i].dXccd;
+    out[i].dYccd      = in[i].dYccd;
+    out[i].posangle   = in[i].posangle;
+    out[i].pltscale   = in[i].pltscale;
+    out[i].photcode   = in[i].photcode;
+    out[i].dbFlags    = in[i].dbFlags;
+    out[i].photFlags  = in[i].photFlags;
+  }
+  return (out);
+}
+
+Measure_PS1_V1 *MeasureInternalTo_PS1_V1 (Measure *in, int Nvalues) {
+
+  int i;
+  Measure_PS1_V1 *out;
+
+  ALLOCATE (out, Measure_PS1_V1, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].dR         = in[i].dR;
+    out[i].dD         = in[i].dD;
+    out[i].M          = in[i].M;
+    out[i].Mcal       = in[i].Mcal;
+    out[i].Map        = in[i].Map;
+    out[i].dM         = in[i].dM;
+    out[i].dMcal      = in[i].dMcal;
+    out[i].dt         = in[i].dt;
+    out[i].airmass    = in[i].airmass;
+    out[i].az         = in[i].az;
+    out[i].Xccd       = in[i].Xccd;
+    out[i].Yccd       = in[i].Yccd;
+    out[i].Sky        = in[i].Sky;
+    out[i].dSky       = in[i].dSky;
+    out[i].t          = in[i].t;
+    out[i].t_msec     = in[i].t_msec;
+    out[i].averef     = in[i].averef;
+    out[i].detID      = in[i].detID;
+    out[i].imageID    = in[i].imageID;
+    out[i].objID      = in[i].objID;
+    out[i].catID      = in[i].catID;
+    out[i].extID      = in[i].extID;
+    out[i].psfQual    = in[i].psfQual;
+    out[i].psfChisq   = in[i].psfChisq;
+    out[i].psfNdof    = in[i].psfNdof;
+    out[i].psfNpix    = in[i].psfNpix;
+    out[i].crNsigma   = in[i].crNsigma;
+    out[i].extNsigma  = in[i].extNsigma;
+    out[i].FWx 	      = in[i].FWx;
+    out[i].FWy 	      = in[i].FWy;
+    out[i].theta      = in[i].theta;
+    out[i].Mxx 	      = in[i].Mxx;
+    out[i].Mxy 	      = in[i].Mxy;
+    out[i].Myy 	      = in[i].Myy;
+    out[i].dXccd      = in[i].dXccd;
+    out[i].dYccd      = in[i].dYccd;
+    out[i].posangle   = in[i].posangle;
+    out[i].pltscale   = in[i].pltscale;
+    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_V1_ToInternal (Average_PS1_V1 *in, int Nvalues, SecFilt **primary) {
+
+  int i;
+  Average *out;
+
+  ALLOCATE (out, Average, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].R        	 = in[i].R;      
+    out[i].D        	 = in[i].D;      
+    out[i].dR       	 = in[i].dR;
+    out[i].dD       	 = in[i].dD;
+    out[i].uR       	 = in[i].uR;
+    out[i].uD       	 = in[i].uD;
+    out[i].duR      	 = in[i].duR;
+    out[i].duD      	 = in[i].duD;
+    out[i].P        	 = in[i].P;
+    out[i].dP       	 = in[i].dP;
+    out[i].Xp       	 = in[i].Xp;     
+    out[i].ChiSq       	 = in[i].ChiSq;     
+    out[i].Npos       	 = in[i].Npos;     
+    out[i].Nmeasure      = in[i].Nmeasure;     
+    out[i].Nmissing      = in[i].Nmissing;     
+    out[i].Nextend       = in[i].Nextend;     
+    out[i].measureOffset = in[i].measureOffset; 
+    out[i].missingOffset = in[i].missingOffset;
+    out[i].extendOffset  = in[i].extendOffset;
+    out[i].flags     	 = in[i].flags;   
+    out[i].objID 	 = in[i].objID;
+    out[i].catID 	 = in[i].catID;
+    out[i].extID 	 = in[i].extID;
+  }
+  return (out);
+}
+
+// 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
+Average_PS1_V1 *AverageInternalTo_PS1_V1 (Average *in, int Nvalues, SecFilt *primary) {
+
+  int i;
+  Average_PS1_V1 *out;
+
+  ALLOCATE (out, Average_PS1_V1, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].R        	 = in[i].R;      
+    out[i].D        	 = in[i].D;      
+    out[i].dR       	 = in[i].dR;
+    out[i].dD       	 = in[i].dD;
+    out[i].uR       	 = in[i].uR;
+    out[i].uD       	 = in[i].uD;
+    out[i].duR      	 = in[i].duR;
+    out[i].duD      	 = in[i].duD;
+    out[i].P        	 = in[i].P;
+    out[i].dP       	 = in[i].dP;
+    out[i].Xp       	 = in[i].Xp;     
+    out[i].ChiSq       	 = in[i].ChiSq;     
+    out[i].Npos       	 = in[i].Npos;     
+    out[i].Nmeasure      = in[i].Nmeasure;     
+    out[i].Nmissing      = in[i].Nmissing;     
+    out[i].Nextend       = in[i].Nextend;     
+    out[i].measureOffset = in[i].measureOffset; 
+    out[i].missingOffset = in[i].missingOffset;
+    out[i].extendOffset  = in[i].extendOffset;
+    out[i].flags     	 = in[i].flags;   
+    out[i].objID 	 = in[i].objID;
+    out[i].catID 	 = in[i].catID;
+    out[i].extID 	 = in[i].extID;
+  }
+  return (out);
+}
+
+SecFilt *SecFilt_PS1_V1_ToInternal (SecFilt_PS1_V1 *in, int Nvalues) {
+
+  int i;
+  SecFilt *out;
+
+  ALLOCATE (out, SecFilt, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].M     = in[i].M;      
+    out[i].dM    = in[i].dM;      
+    out[i].Xm    = in[i].Xm;     
+    out[i].Ncode = in[i].Ncode;
+    out[i].Nused = in[i].Nused;
+    out[i].M_20  = in[i].M_20;      
+    out[i].M_80  = in[i].M_80;      
+ }
+  return (out);
+}
+
+SecFilt_PS1_V1 *SecFiltInternalTo_PS1_V1 (SecFilt *in, int Nvalues) {
+
+  int i;
+  SecFilt_PS1_V1 *out;
+
+  ALLOCATE (out, SecFilt_PS1_V1, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    out[i].M     = in[i].M;      
+    out[i].dM    = in[i].dM;      
+    out[i].Xm    = in[i].Xm;     
+    out[i].Ncode = in[i].Ncode;
+    out[i].Nused = in[i].Nused;
+    out[i].M_20  = in[i].M_20;      
+    out[i].M_80  = in[i].M_80;      
+  }
+  return (out);
+}
+
+Image *Image_PS1_V1_ToInternal (Image_PS1_V1 *in, int Nvalues) {
+
+  int i;
+  Image *out;
+
+  ALLOCATE (out, Image, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
+
+    strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
+    out[i].name[120] = 0; // force termination
+
+    out[i].tzero    	    = in[i].tzero;
+    out[i].nstar    	    = in[i].nstar;
+    out[i].secz	    	    = in[i].secz;
+    out[i].NX	    	    = in[i].NX;
+    out[i].NY	    	    = in[i].NY;
+    out[i].apmifit  	    = in[i].apmifit;
+    out[i].dapmifit 	    = in[i].dapmifit;
+    out[i].Mcal	    	    = in[i].Mcal;
+    out[i].dMcal    	    = in[i].dMcal;
+    out[i].Xm	    	    = in[i].Xm;
+    out[i].photcode   	    = in[i].photcode;
+    out[i].exptime  	    = in[i].exptime;
+    out[i].sidtime  	    = in[i].sidtime;
+    out[i].latitude  	    = in[i].latitude;
+    out[i].detection_limit  = in[i].detection_limit;
+    out[i].saturation_limit = in[i].saturation_limit;
+    out[i].cerror	    = in[i].cerror;
+    out[i].fwhm_x	    = in[i].fwhm_x;
+    out[i].fwhm_y	    = in[i].fwhm_y;
+    out[i].trate	    = in[i].trate;
+    out[i].ccdnum	    = in[i].ccdnum;
+    out[i].flags	    = in[i].flags;
+    out[i].imageID	    = in[i].imageID;
+    out[i].parentID	    = in[i].parentID;
+    out[i].externID	    = in[i].externID;
+    out[i].sourceID	    = in[i].sourceID;
+
+    out[i].order	    = in[i].order;
+    out[i].Mx		    = in[i].Mx;
+    out[i].My		    = in[i].My;
+    out[i].Mxx		    = in[i].Mxx;
+    out[i].Mxy		    = in[i].Mxy;
+    out[i].Myy		    = in[i].Myy;
+    out[i].Mxxx		    = in[i].Mxxx;
+    out[i].Mxxy		    = in[i].Mxxy;
+    out[i].Mxyy		    = in[i].Mxyy;
+    out[i].Myyy		    = in[i].Myyy;
+    out[i].Mxxxx	    = in[i].Mxxxx;
+    out[i].Mxxxy	    = in[i].Mxxxy;
+    out[i].Mxxyy	    = in[i].Mxxyy;
+    out[i].Mxyyy	    = in[i].Mxyyy;
+    out[i].Myyyy	    = in[i].Myyyy;
+  }
+  return (out);
+}
+
+Image_PS1_V1 *ImageInternalTo_PS1_V1 (Image *in, int Nvalues) {
+
+  int i;
+  Image_PS1_V1 *out;
+
+  ALLOCATE (out, Image_PS1_V1, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
+
+    strncpy (out[i].name, in[i].name, 120); // out[121], in[121]
+    out[i].name[120] = 0; // force termination
+
+    out[i].tzero    	    = in[i].tzero;
+    out[i].nstar    	    = in[i].nstar;
+    out[i].secz	    	    = in[i].secz;
+    out[i].NX	    	    = in[i].NX;
+    out[i].NY	    	    = in[i].NY;
+    out[i].apmifit  	    = in[i].apmifit;
+    out[i].dapmifit 	    = in[i].dapmifit;
+    out[i].Mcal	    	    = in[i].Mcal;
+    out[i].dMcal    	    = in[i].dMcal;
+    out[i].Xm	    	    = in[i].Xm;
+    out[i].photcode   	    = in[i].photcode;
+    out[i].exptime  	    = in[i].exptime;
+    out[i].sidtime  	    = in[i].sidtime;
+    out[i].latitude  	    = in[i].latitude;
+    out[i].detection_limit  = in[i].detection_limit;
+    out[i].saturation_limit = in[i].saturation_limit;
+    out[i].cerror	    = in[i].cerror;
+    out[i].fwhm_x	    = in[i].fwhm_x;
+    out[i].fwhm_y	    = in[i].fwhm_y;
+    out[i].trate	    = in[i].trate;
+    out[i].ccdnum	    = in[i].ccdnum;
+    out[i].flags	    = in[i].flags;
+    out[i].imageID	    = in[i].imageID;
+    out[i].parentID	    = in[i].parentID;
+    out[i].externID	    = in[i].externID;
+    out[i].sourceID	    = in[i].sourceID;
+
+    out[i].order	    = in[i].order;
+    out[i].Mx		    = in[i].Mx;
+    out[i].My		    = in[i].My;
+    out[i].Mxx		    = in[i].Mxx;
+    out[i].Mxy		    = in[i].Mxy;
+    out[i].Myy		    = in[i].Myy;
+    out[i].Mxxx		    = in[i].Mxxx;
+    out[i].Mxxy		    = in[i].Mxxy;
+    out[i].Mxyy		    = in[i].Mxyy;
+    out[i].Myyy		    = in[i].Myyy;
+    out[i].Mxxxx	    = in[i].Mxxxx;
+    out[i].Mxxxy	    = in[i].Mxxxy;
+    out[i].Mxxyy	    = in[i].Mxxyy;
+    out[i].Mxyyy	    = in[i].Mxyyy;
+    out[i].Myyyy	    = in[i].Myyyy;
+  }
+  return (out);
+}
+
+PhotCode *PhotCode_PS1_V1_To_Internal (PhotCode_PS1_V1 *in, int Nvalues) {
+
+  int i;
+  PhotCode *out;
+
+  ALLOCATE (out, PhotCode, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
+    out[i].name[31] = 0; // force termination
+
+    out[i].code  = in[i].code;         
+    out[i].type  = in[i].type;         
+    out[i].C     = in[i].C;            
+    out[i].dC 	 = in[i].dC;           
+    out[i].dX 	 = in[i].dX;           
+    out[i].K  	 = in[i].K;            
+    out[i].c1 	 = in[i].c1;           
+    out[i].c2 	 = in[i].c2;           
+    out[i].equiv = in[i].equiv;        
+    out[i].Nc    = in[i].Nc;           
+    memcpy (out[i].X, in[i].X, 4*sizeof(float));            
+
+    out[i].astromErrSys      = in[i].astromErrSys;
+    out[i].astromErrScale    = in[i].astromErrScale;
+    out[i].astromErrMagScale = in[i].astromErrMagScale;
+    out[i].photomErrSys      = in[i].photomErrSys;
+
+    out[i].photomPoorMask      = in[i].photomPoorMask;
+    out[i].photomBadMask       = in[i].photomBadMask;
+    out[i].astromPoorMask      = in[i].astromPoorMask;
+    out[i].astromBadMask       = in[i].astromBadMask;
+  }
+  return (out);
+}
+
+PhotCode_PS1_V1 *PhotCode_Internal_To_PS1_V1 (PhotCode *in, int Nvalues) {
+
+  int i;
+  PhotCode_PS1_V1 *out;
+
+  ALLOCATE (out, PhotCode_PS1_V1, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
+    out[i].name[31] = 0; // force termination
+
+    out[i].code  = in[i].code;         
+    out[i].type  = in[i].type;         
+    out[i].C     = in[i].C;            
+    out[i].dC 	 = in[i].dC;           
+    out[i].dX 	 = in[i].dX;           
+    out[i].K  	 = in[i].K;            
+    out[i].c1 	 = in[i].c1;           
+    out[i].c2 	 = in[i].c2;           
+    out[i].equiv = in[i].equiv;        
+    out[i].Nc    = in[i].Nc;           
+    memcpy (out[i].X, in[i].X, 4*sizeof(float));            
+
+    out[i].astromErrSys      = in[i].astromErrSys;
+    out[i].astromErrScale    = in[i].astromErrScale;
+    out[i].astromErrMagScale = in[i].astromErrMagScale;
+    out[i].photomErrSys      = in[i].photomErrSys;
+
+    out[i].photomPoorMask      = in[i].photomPoorMask;
+    out[i].photomBadMask       = in[i].photomBadMask;
+    out[i].astromPoorMask      = in[i].astromPoorMask;
+    out[i].astromBadMask       = in[i].astromBadMask;
+  }
+  return (out);
+}
Index: trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 21508)
@@ -10,4 +10,9 @@
 
   for (i = 0; i < Nvalues; i++) {
+    out[i].FWx 	    = in[i].FWx;
+    out[i].t        = in[i].t;
+    out[i].averef   = in[i].averef;
+
+    // changed for PANSTARRS_DEV_0
     out[i].dR       = (in[i].dR      == NAN_S_SHORT) ? NAN : in[i].dR     * 0.01;
     out[i].dD       = (in[i].dD      == NAN_S_SHORT) ? NAN : in[i].dD     * 0.01;
@@ -16,38 +21,47 @@
     out[i].dt       = (in[i].dt      == NAN_S_SHORT) ? NAN : in[i].dt     * 0.001;
     out[i].Mcal     = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
-
-    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
-    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
     out[i].Map      = (in[i].Mgal    == NAN_S_SHORT) ? NAN : in[i].Mgal   * 0.001;
     out[i].airmass  = (in[i].airmass == NAN_S_SHORT) ? NAN : in[i].airmass* 0.001;
-    out[i].FWx 	    = in[i].FWx;
     out[i].FWy 	    = in[i].fwy * in[i].FWx * 0.01;
     out[i].theta    = in[i].theta*(0x10000 / 0x100);
-    out[i].dophot   = in[i].dophot;
     out[i].photcode = in[i].source;
-    out[i].t        = in[i].t;
-    out[i].averef   = in[i].averef;
-    out[i].dbFlags  = in[i].flags;
     
-    /* these can be determined if needed / desired */
-    out[i].Xccd     = 0;
-    out[i].Yccd     = 0;
-    out[i].dXccd    = 0;
-    out[i].dYccd    = 0;
-
-    /* these do not have a corresponding value */
+    // added for PANSTARRS_DEV_0
+    out[i].Xccd      = 0;  // determine on-the-fly
+    out[i].Yccd      = 0;  // determine on-the-fly
+    out[i].dXccd     = 0;
+    out[i].dYccd     = 0;
     out[i].az        = 0;
-    out[i].stargal   = 0;
     out[i].Sky       = 0;
     out[i].dSky      = 0;
-    out[i].qPSF      = 0;
+    out[i].psfQual   = 0;
     out[i].psfChisq  = 0;
     out[i].crNsigma  = 0;
     out[i].extNsigma = 0;
-    out[i].photFlags = 0;
-
-    /* XXX add these later */
-    out[i].detID = 0;
-    out[i].imageID = 0;
+    out[i].detID     = 0;  // determine on-the-fly
+    out[i].imageID   = 0;  // determine on-the-fly
+
+    // changed or added for PS1_DEV_1 (2008.02.26)
+    out[i].dbFlags    = in[i].flags;
+    out[i].detID      = 0;
+    out[i].imageID    = 0;
+
+    // changed or added for PS1_DEV_2
+    out[i].Map        = in[i].Mgal;
+    out[i].dMcal      = 0; 
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].dophot << 16;
+    out[i].t_msec     = 0;
+    out[i].extID      = 0;
+    out[i].objID      = 0;
+    out[i].catID      = 0;
+    out[i].Mxx 	      = 0.0;
+    out[i].Mxy 	      = 0.0;
+    out[i].Myy        = 0.0;
+    out[i].posangle   = 0;
+    out[i].pltscale   = 0;
+    out[i].psfNdof    = 0;
+    out[i].psfNpix    = 0;
   }
   return (out);
@@ -63,4 +77,9 @@
 
   for (i = 0; i < Nvalues; i++) {
+    out[i].FWx 	   = in[i].FWx;
+    out[i].t       = in[i].t;
+    out[i].averef  = in[i].averef;
+
+    // changed for PANSTARRS_DEV_0
     out[i].dR       = isnan(in[i].dR     ) ? NAN_S_SHORT : in[i].dR      *  100.0;
     out[i].dD       = isnan(in[i].dD     ) ? NAN_S_SHORT : in[i].dD      *  100.0;
@@ -71,4 +90,7 @@
     out[i].Mgal     = isnan(in[i].Map    ) ? NAN_S_SHORT : in[i].Map     * 1000.0;
     out[i].airmass  = isnan(in[i].airmass) ? NAN_S_SHORT : in[i].airmass * 1000.0;
+    out[i].fwy 	    = in[i].FWy * 100.0 / in[i].FWx;
+    out[i].theta    = in[i].theta*(0x100/ 0x10000);
+    out[i].source   = in[i].photcode;
 
     if (out[i].M < 0) {
@@ -76,12 +98,9 @@
     }
 
-    out[i].FWx 	   = in[i].FWx;
-    out[i].fwy 	   = in[i].FWy * 100.0 / in[i].FWx;
-    out[i].theta   = in[i].theta*(0x100/ 0x10000);
-    out[i].dophot  = in[i].dophot;
-    out[i].source  = in[i].photcode;
-    out[i].t       = in[i].t;
-    out[i].averef  = in[i].averef;
+    // changed or added for PS1_DEV_1 (2008.02.26)
     out[i].flags   = in[i].dbFlags;
+
+    // changed or added for PS1_V1
+    out[i].dophot  = in[i].photFlags >> 16;
   }
   return (out);
@@ -101,11 +120,14 @@
     out[i].D       	 = in[i].D;      
     out[i].Xp      	 = in[i].Xp;     
-    out[i].Nmeasure 	 = in[i].Nm;     
-    out[i].Nmissing 	 = in[i].Nn;     
-    out[i].code     	 = in[i].code;   
-    out[i].measureOffset = in[i].offset; 
-    out[i].missingOffset = in[i].missing;
-
-    /* these don't exist in Elixir */
+
+    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
+    primary[0][i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;      
+    primary[0][i].dM    = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM * 0.001;      
+    primary[0][i].Xm    = in[i].Xm;     
+
+    primary[0][i].Ncode = 0;     
+    primary[0][i].Nused = 0;
+
+    // added for PANSTARRS_DEV_0
     out[i].dR      = 0;
     out[i].dD      = 0;
@@ -116,14 +138,20 @@
     out[i].P       = 0;
     out[i].dP      = 0;
-
-    /* XXX add these later */
-    out[i].objID   = 0;
-    out[i].catID   = 0;
-
-    primary[0][i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;      
-    primary[0][i].dM    = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM * 0.001;      
-    primary[0][i].Xm    = in[i].Xm;     
-    primary[0][i].Ncode = 0;     
-    primary[0][i].Nused = 0;
+    out[i].objID   = 0; // determine on-the-fly
+    out[i].catID   = 0; // determine on-the-fly
+
+    // changed or added for PS1_DEV_2
+    out[i].Nmeasure 	 = in[i].Nm;     
+    out[i].Nmissing 	 = in[i].Nn;     
+    out[i].measureOffset = in[i].offset; 
+    out[i].missingOffset = in[i].missing;
+    out[i].Nextend       = 0;
+    out[i].extendOffset  = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags    	 = in[i].code;   
+    out[i].ChiSq       	 = 0.0;
+    out[i].Npos       	 = 0.0;
+    out[i].extID 	 = 0;
   }
   return (out);
@@ -142,13 +170,18 @@
     out[i].D       = in[i].D;      
     out[i].Xp      = in[i].Xp;     
-    out[i].Nm      = in[i].Nmeasure;     
-    out[i].Nn      = in[i].Nmissing;     
-    out[i].code    = in[i].code;   
-    out[i].offset  = in[i].measureOffset; 
-    out[i].missing = in[i].missingOffset;
-
+
+    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
     out[i].M       = isnan(primary[i].M)  ? NAN_S_SHORT : primary[i].M   * 1000.0;
     out[i].dM      = isnan(primary[i].dM) ? NAN_S_SHORT : primary[i].dM  * 1000.0;
     out[i].Xm      = primary[i].Xm;     
+
+    // changed or added for PS1_DEV_2
+    out[i].Nm      = in[i].Nmeasure;     
+    out[i].Nn      = in[i].Nmissing;     
+    out[i].offset  = in[i].measureOffset; 
+    out[i].missing = in[i].missingOffset;
+
+    // changed or added for PS1_V1
+    out[i].code    = in[i].flags;   
   }
   return (out);
@@ -164,9 +197,15 @@
 
   for (i = 0; i < Nvalues; i++) {
+    out[i].Xm    = in[i].Xm;     
+
+    // added or changed for PANSTARRS_DEV_0
     out[i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M   * 0.001;
     out[i].dM    = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM  * 0.001;
-    out[i].Xm    = in[i].Xm;     
     out[i].Ncode = 0;
     out[i].Nused = 0;
+
+    // changed or added for PS1_V1
+    out[i].M_20  = 0;      
+    out[i].M_80  = 0;      
   }
   return (out);
@@ -182,7 +221,9 @@
 
   for (i = 0; i < Nvalues; i++) {
+    out[i].Xm    = in[i].Xm;     
+
+    // added or changed for PANSTARRS_DEV_0
     out[i].M     = isnan(in[i].M)  ? NAN_S_SHORT : in[i].M   * 1000.0;
     out[i].dM    = isnan(in[i].dM) ? NAN_S_SHORT : in[i].dM  * 1000.0;
-    out[i].Xm    = in[i].Xm;     
   }
   return (out);
@@ -207,9 +248,4 @@
     out[i].NX	    	    = in[i].NX;
     out[i].NY	    	    = in[i].NY;
-    out[i].secz    	    = (in[i].secz     == NAN_S_SHORT) ? NAN : in[i].secz     * 0.001;
-    out[i].apmifit  	    = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
-    out[i].dapmifit  	    = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
-    out[i].Mcal   	    = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
-    out[i].dMcal   	    = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
     out[i].Xm	    	    = in[i].Xm;
     out[i].photcode   	    = in[i].source;
@@ -221,5 +257,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
 
@@ -240,10 +275,21 @@
     out[i].Myyyy	    = in[i].Myyyy;
 
-    /* XXX add these later */
-    out[i].imageID = 0;
-
-    // not available in ELIXIR
+    // added or changed for PANSTARRS_DEV_0
+    out[i].secz    	    = (in[i].secz     == NAN_S_SHORT) ? NAN : in[i].secz     * 0.001;
+    out[i].apmifit  	    = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
+    out[i].dapmifit  	    = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
+    out[i].Mcal   	    = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
+    out[i].dMcal   	    = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
     out[i].sidtime  	    = NAN;
     out[i].latitude  	    = NAN;
+    out[i].imageID          = 0; // determine on-the-fly
+
+    // changed or added for PS1_DEV_2
+    out[i].externID	    = 0;
+    out[i].sourceID	    = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -268,9 +314,5 @@
     out[i].NX	    	    = in[i].NX;
     out[i].NY	    	    = in[i].NY;
-    out[i].secz    	    = isnan(in[i].secz    ) ? NAN_S_SHORT : in[i].secz     * 1000.0;
-    out[i].apmifit    	    = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
-    out[i].dapmifit    	    = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
-    out[i].Mcal    	    = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
-    out[i].dMcal    	    = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
+
     out[i].Xm	    	    = in[i].Xm;
     out[i].source   	    = in[i].photcode;
@@ -282,5 +324,4 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
 
@@ -300,14 +341,24 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
-  }
-  return (out);
-}
-
-PhotCode_Elixir *PhotCode_Internal_To_Elixir (PhotCode *in, int Nvalues) {
-
-  int i;
-  PhotCode_Elixir *out;
-
-  ALLOCATE (out, PhotCode_Elixir, Nvalues);
+
+    // added or changed for PANSTARRS_DEV_0
+    out[i].secz    	    = isnan(in[i].secz    ) ? NAN_S_SHORT : in[i].secz     * 1000.0;
+    out[i].apmifit    	    = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
+    out[i].dapmifit    	    = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
+    out[i].Mcal    	    = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
+    out[i].dMcal    	    = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
+
+PhotCode *PhotCode_Elixir_To_Internal (PhotCode_Elixir *in, int Nvalues) {
+
+  int i;
+  PhotCode *out;
+
+  ALLOCATE (out, PhotCode, Nvalues);
 
   for (i = 0; i < Nvalues; i++) {
@@ -326,14 +377,28 @@
     out[i].Nc    = in[i].Nc;           
     memcpy (out[i].X, in[i].X, 4*sizeof(float));            
-  }
-  return (out);
-}
-
-PhotCode *PhotCode_Elixir_To_Internal (PhotCode_Elixir *in, int Nvalues) {
-
-  int i;
-  PhotCode *out;
-
-  ALLOCATE (out, PhotCode, Nvalues);
+
+    // changed or added for PS1_DEV_1
+    out[i].astromErrMagScale = 0.0;
+    out[i].photomErrSys      = 0.0;
+
+    // changed or added for PS1_DEV_2
+    out[i].astromErrSys      = 0.0;
+    out[i].astromErrScale    = 0.0;
+
+    // changed or added for PS1_V1 (also PS1_DEV_3, deprecated)
+    out[i].photomPoorMask      = 0;
+    out[i].photomBadMask       = 0;
+    out[i].astromPoorMask      = 0;
+    out[i].astromBadMask       = 0;
+  }
+  return (out);
+}
+
+PhotCode_Elixir *PhotCode_Internal_To_Elixir (PhotCode *in, int Nvalues) {
+
+  int i;
+  PhotCode_Elixir *out;
+
+  ALLOCATE (out, PhotCode_Elixir, Nvalues);
 
   for (i = 0; i < Nvalues; i++) {
@@ -352,16 +417,5 @@
     out[i].Nc    = in[i].Nc;           
     memcpy (out[i].X, in[i].X, 4*sizeof(float));            
-
-    // not defined in Elixir:
-    out[i].astromErrSys      = 0.0;
-    out[i].astromErrScale    = 0.0;
-    out[i].astromErrMagScale = 0.0;
-    out[i].photomErrSys      = 0.0;
-
-    out[i].photomPoorMask      = 0;
-    out[i].photomBadMask       = 0;
-    out[i].astromPoorMask      = 0;
-    out[i].astromBadMask       = 0;
-  }
-  return (out);
-}
+  }
+  return (out);
+}
Index: trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 21508)
@@ -10,46 +10,60 @@
 
   for (i = 0; i < Nvalues; i++) {
-    out[i].dR        = (in[i].dR      == NAN_S_SHORT) ? NAN : in[i].dR     * 0.01;
-    out[i].dD        = (in[i].dD      == NAN_S_SHORT) ? NAN : in[i].dD     * 0.01;
-    out[i].M         = (in[i].M       == NAN_S_SHORT) ? NAN : in[i].M      * 0.001;
-    out[i].dM        = (in[i].dM      == NAN_U_CHAR)  ? NAN : in[i].dM     * 0.001;
-    out[i].Mcal      = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
-    out[i].dophot    = in[i].dophot;
-    out[i].photcode  = in[i].source;
-    out[i].t         = in[i].t;
-
-    /* flags and averef are now split */
+    out[i].t        = in[i].t;
+
+    // added or changed for ELIXIR
     out[i].averef    =  in[i].averef & 0x00ffffff;
     out[i].dbFlags   = (in[i].averef & 0xff000000) >> 24;
-
-    /* these values don't exist in the Loneos format */
-
-    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
-    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
-    out[i].Map       = out[i].M;
+    out[i].t         = in[i].t;
     out[i].dt        = 0;
     out[i].airmass   = 0;
+    out[i].FWy 	     = 0;
+    out[i].FWx       = 0;
+    out[i].theta     = 0;
+
+    // changed for PANSTARRS_DEV_0
+    out[i].dR       = (in[i].dR      == NAN_S_SHORT) ? NAN : in[i].dR     * 0.01;
+    out[i].dD       = (in[i].dD      == NAN_S_SHORT) ? NAN : in[i].dD     * 0.01;
+    out[i].M        = (in[i].M       == NAN_S_SHORT) ? NAN : in[i].M      * 0.001;
+    out[i].dM       = (in[i].dM      == NAN_U_CHAR)  ? NAN : in[i].dM     * 0.001;
+    out[i].Mcal     = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
+    out[i].Map      = (in[i].M       == NAN_S_SHORT) ? NAN : in[i].M      * 0.001;
+    out[i].photcode = in[i].source;
+    
+    // added for PANSTARRS_DEV_0
+    out[i].Xccd      = 0;  // determine on-the-fly
+    out[i].Yccd      = 0;  // determine on-the-fly
+    out[i].dXccd     = 0;
+    out[i].dYccd     = 0;
     out[i].az        = 0;
-    out[i].FWx 	     = 0;
-    out[i].FWy 	     = 0;
-    out[i].theta     = 0;
-    out[i].stargal   = 0;
     out[i].Sky       = 0;
     out[i].dSky      = 0;
-    out[i].qPSF      = 0;
+    out[i].psfQual   = 0;
     out[i].psfChisq  = 0;
     out[i].crNsigma  = 0;
     out[i].extNsigma = 0;
-    out[i].photFlags = 0;
-
-    /* these can be determined if needed / desired */
-    out[i].Xccd     = 0;
-    out[i].Yccd     = 0;
-    out[i].dXccd    = 0;
-    out[i].dYccd    = 0;
-
-    /* XXX add these later */
-    out[i].detID = 0;
-    out[i].imageID = 0;
+    out[i].detID     = 0;  // determine on-the-fly
+    out[i].imageID   = 0;  // determine on-the-fly
+
+    // changed or added for PS1_DEV_1 (2008.02.26)
+    out[i].detID      = 0;
+    out[i].imageID    = 0;
+
+    // changed or added for PS1_DEV_2
+    out[i].dMcal      = 0; 
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].dophot << 16;
+    out[i].t_msec     = 0;
+    out[i].extID      = 0;
+    out[i].objID      = 0;
+    out[i].catID      = 0;
+    out[i].Mxx 	      = 0.0;
+    out[i].Mxy 	      = 0.0;
+    out[i].Myy        = 0.0;
+    out[i].posangle   = 0;
+    out[i].pltscale   = 0;
+    out[i].psfNdof    = 0;
+    out[i].psfNpix    = 0;
   }
   return (out);
@@ -65,4 +79,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+
+    // changed for PANSTARRS_DEV_0
     out[i].dR     = isnan(in[i].dR     ) ? NAN_S_SHORT : in[i].dR      *  100.0;
     out[i].dD     = isnan(in[i].dD     ) ? NAN_S_SHORT : in[i].dD      *  100.0;
@@ -70,5 +86,4 @@
     out[i].dM     = isnan(in[i].dM     ) ? NAN_U_CHAR  : in[i].dM      * 1000.0;
     out[i].Mcal   = isnan(in[i].Mcal   ) ? NAN_S_SHORT : in[i].Mcal    * 1000.0;
-    out[i].dophot = in[i].dophot;
     out[i].source = in[i].photcode;
     out[i].t      = in[i].t;
@@ -76,4 +91,7 @@
     /* flags and averef are merged in Loneos */
     out[i].averef =  (in[i].averef & 0x00ffffff) | (in[i].dbFlags << 24);
+
+    // changed or added for PS1_V1
+    out[i].dophot  = in[i].photFlags >> 16;
   }
   return (out);
@@ -93,11 +111,15 @@
     out[i].D       	 = in[i].D;      
     out[i].Xp      	 = in[i].Xp;     
-    out[i].Nmeasure      = in[i].Nm;     
-    out[i].Nmissing      = in[i].Nn;     
-    out[i].code    	 = in[i].code;   
-    out[i].measureOffset = in[i].offset; 
-    out[i].missingOffset = in[i].missing;
-
-    /* these don't exist in Loneos */
+
+    // added for ELIXIR
+    primary[0][i].dM    = NAN;
+
+    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
+    primary[0][i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;      
+    primary[0][i].Xm    = in[i].Xm;     
+    primary[0][i].Ncode = 0;     
+    primary[0][i].Nused = 0;
+
+    // added for PANSTARRS_DEV_0
     out[i].dR      = 0;
     out[i].dD      = 0;
@@ -108,14 +130,20 @@
     out[i].P       = 0;
     out[i].dP      = 0;
-
-    /* XXX add these later */
-    out[i].objID   = 0;
-    out[i].catID   = 0;
-
-    primary[0][i].M  = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;      
-    primary[0][i].Xm = in[i].Xm;     
-    primary[0][i].dM = NAN;
-    primary[0][i].Ncode = 0;     
-    primary[0][i].Nused = 0;
+    out[i].objID   = 0; // determine on-the-fly
+    out[i].catID   = 0; // determine on-the-fly
+
+    // changed or added for PS1_DEV_2
+    out[i].Nmeasure 	 = in[i].Nm;     
+    out[i].Nmissing 	 = in[i].Nn;     
+    out[i].measureOffset = in[i].offset; 
+    out[i].missingOffset = in[i].missing;
+    out[i].Nextend       = 0;
+    out[i].extendOffset  = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags    	 = in[i].code;   
+    out[i].ChiSq       	 = 0.0;
+    out[i].Npos       	 = 0.0;
+    out[i].extID 	 = 0;
   }
   return (out);
@@ -134,12 +162,17 @@
     out[i].D       = in[i].D;      
     out[i].Xp      = in[i].Xp;     
+
+    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
+    out[i].M       = isnan(primary[i].M)  ? NAN_S_SHORT : primary[i].M   * 1000.0;
+    out[i].Xm      = primary[i].Xm;     
+
+    // changed or added for PS1_DEV_2
     out[i].Nm      = in[i].Nmeasure;     
     out[i].Nn      = in[i].Nmissing;     
-    out[i].code    = in[i].code;   
     out[i].offset  = in[i].measureOffset; 
     out[i].missing = in[i].missingOffset;
 
-    out[i].M       = isnan(primary[i].M)  ? NAN_S_SHORT : primary[i].M   * 1000.0;
-    out[i].Xm      = primary[i].Xm;     
+    // changed or added for PS1_V1
+    out[i].code    = in[i].flags;   
   }
   return (out);
@@ -155,9 +188,17 @@
 
   for (i = 0; i < Nvalues; i++) {
+    out[i].Xm    = in[i].Xm;      
+
+    // added for ELIXIR
+    out[i].dM    = NAN;
+
+    // added or changed for PANSTARRS_DEV_0
     out[i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M * 0.001;
-    out[i].Xm    = in[i].Xm;      
-    out[i].dM    = NAN;
     out[i].Ncode = 0;
     out[i].Nused = 0;
+
+    // changed or added for PS1_V1
+    out[i].M_20  = 0;      
+    out[i].M_80  = 0;      
   }
   return (out);
@@ -173,6 +214,8 @@
 
   for (i = 0; i < Nvalues; i++) {
+    out[i].Xm   = in[i].Xm;      
+
+    // added or changed for PANSTARRS_DEV_0
     out[i].M    = isnan(in[i].M)  ? NAN_S_SHORT : in[i].M * 1000.0;
-    out[i].Xm   = in[i].Xm;      
   }
   return (out);
@@ -197,10 +240,4 @@
     out[i].NX	    	    = in[i].NX;
     out[i].NY	    	    = in[i].NY;
-
-    out[i].secz    	    = (in[i].secz     == NAN_S_SHORT) ? NAN : in[i].secz     * 0.001;
-    out[i].apmifit  	    = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
-    out[i].dapmifit  	    = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
-    out[i].Mcal   	    = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
-    out[i].dMcal   	    = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
 
     out[i].Xm	    	    = in[i].Xm;
@@ -213,6 +250,6 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
+
     out[i].order	    = in[i].order;
     out[i].Mx		    = in[i].Mx;
@@ -231,6 +268,21 @@
     out[i].Myyyy	    = in[i].Myyyy;
 
-    /* XXX add these later */
-    out[i].imageID = 0;
+    // added or changed for PANSTARRS_DEV_0
+    out[i].secz    	    = (in[i].secz     == NAN_S_SHORT) ? NAN : in[i].secz     * 0.001;
+    out[i].apmifit  	    = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
+    out[i].dapmifit  	    = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
+    out[i].Mcal   	    = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
+    out[i].dMcal   	    = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
+    out[i].sidtime  	    = NAN;
+    out[i].latitude  	    = NAN;
+    out[i].imageID          = 0; // determine on-the-fly
+
+    // changed or added for PS1_DEV_2
+    out[i].externID	    = 0;
+    out[i].sourceID	    = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -255,10 +307,4 @@
     out[i].NX	    	    = in[i].NX;
     out[i].NY	    	    = in[i].NY;
-
-    out[i].secz    	    = isnan(in[i].secz    ) ? NAN_S_SHORT : in[i].secz     * 1000.0;
-    out[i].apmifit    	    = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
-    out[i].dapmifit    	    = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
-    out[i].Mcal    	    = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
-    out[i].dMcal    	    = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
 
     out[i].Xm	    	    = in[i].Xm;
@@ -271,6 +317,6 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
+
     out[i].order	    = in[i].order;
     out[i].Mx		    = in[i].Mx;
@@ -288,5 +334,15 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
-  }
-  return (out);
-}
+
+    // added or changed for PANSTARRS_DEV_0
+    out[i].secz    	    = isnan(in[i].secz    ) ? NAN_S_SHORT : in[i].secz     * 1000.0;
+    out[i].apmifit    	    = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
+    out[i].dapmifit    	    = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
+    out[i].Mcal    	    = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
+    out[i].dMcal    	    = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
Index: trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 21508)
@@ -16,7 +16,4 @@
     out[i].Mcal       = in[i].Mcal;
 
-    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
-    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
-    out[i].Map        = in[i].Mgal;
     out[i].airmass    = in[i].airmass;
     out[i].az         = in[i].az;
@@ -25,25 +22,43 @@
     out[i].FWy 	      = in[i].FWy;
     out[i].theta      = in[i].theta;
-    out[i].dophot     = in[i].dophot;
     out[i].photcode   = in[i].photcode;
     out[i].t          = in[i].t;
     out[i].averef     = in[i].averef;
-    out[i].dbFlags    = in[i].flags;
     out[i].Xccd       = in[i].Xccd;
     out[i].Yccd       = in[i].Yccd;
     out[i].dXccd      = in[i].dXccd;
     out[i].dYccd      = in[i].dYccd;
-    out[i].stargal    = in[i].stargal;
     out[i].Sky        = in[i].Sky;
     out[i].dSky       = in[i].dSky;
-    out[i].qPSF       = (in[i].qPSF == NAN_S_SHORT) ? NAN : in[i].qPSF;
+
+    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
+    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
+
+    // changed or added for PS1_DEV_1 (2008.02.26)
+    out[i].psfQual    = (in[i].psfQual == NAN_S_SHORT) ? NAN : in[i].psfQual;
+    out[i].dbFlags    = in[i].flags;
     out[i].detID      = in[i].detID_lo;
     out[i].imageID    = in[i].imageID_lo;
-
-    // these don't have a correspondence
-    out[i].psfChisq  = 0;
-    out[i].crNsigma  = 0;
-    out[i].extNsigma = 0;
-    out[i].photFlags = 0;
+    out[i].psfChisq   = 0;
+    out[i].crNsigma   = 0;
+    out[i].extNsigma  = 0;
+
+    // changed or added for PS1_DEV_2
+    out[i].Map        = in[i].Mgal;
+    out[i].dMcal      = 0; 
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].dophot << 16;
+    out[i].t_msec     = 0;
+    out[i].extID      = 0;
+    out[i].objID      = 0;
+    out[i].catID      = 0;
+    out[i].Mxx 	      = 0.0;
+    out[i].Mxy 	      = 0.0;
+    out[i].Myy        = 0.0;
+    out[i].posangle   = 0;
+    out[i].pltscale   = 0;
+    out[i].psfNdof    = 0;
+    out[i].psfNpix    = 0;
   }
   return (out);
@@ -64,5 +79,4 @@
     out[i].dM         = in[i].dM;
     out[i].Mcal       = in[i].Mcal;
-    out[i].Mgal       = in[i].Map;
     out[i].airmass    = in[i].airmass;
     out[i].az         = in[i].az;
@@ -71,21 +85,28 @@
     out[i].FWy 	      = in[i].FWy;
     out[i].theta      = in[i].theta;
-    out[i].dophot     = in[i].dophot;
     out[i].photcode   = in[i].photcode;
     out[i].t          = in[i].t;
     out[i].averef     = in[i].averef;
-    out[i].flags      = in[i].dbFlags;
     out[i].Xccd       = in[i].Xccd;
     out[i].Yccd       = in[i].Yccd;
     out[i].dXccd      = in[i].dXccd;
     out[i].dYccd      = in[i].dYccd;
-    out[i].stargal    = in[i].stargal;
     out[i].Sky        = in[i].Sky;
     out[i].dSky       = in[i].dSky;
-    out[i].qPSF       = isnan(in[i].qPSF) ? NAN_S_SHORT : in[i].qPSF;
+
+    // changed or added for PS1_DEV_1 (2008.02.26)
+    out[i].flags      = in[i].dbFlags;
+    out[i].psfQual    = isnan(in[i].psfQual) ? NAN_S_SHORT : in[i].psfQual;
     out[i].detID_hi   = 0;
     out[i].detID_lo   = in[i].detID;
     out[i].imageID_hi = 0;
     out[i].imageID_lo = in[i].imageID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Mgal       = in[i].Map;
+
+    // changed or added for PS1_V1
+    // out[i].photFlags  = in[i].photFlags & 0x0000ffff; (only dophot pre PS1_DEV_1)
+    out[i].dophot     = in[i].photFlags >> 16;
   }
   return (out);
@@ -105,9 +126,4 @@
     out[i].D        	 = in[i].D;      
     out[i].Xp       	 = in[i].Xp;     
-    out[i].Nmeasure      = in[i].Nm;     
-    out[i].Nmissing      = in[i].Nn;     
-    out[i].code          = in[i].code;   
-    out[i].measureOffset = in[i].offset; 
-    out[i].missingOffset = in[i].missing;
     out[i].dR       	 = in[i].dR;
     out[i].dD       	 = in[i].dD;
@@ -120,4 +136,18 @@
     out[i].objID 	 = in[i].objID;
     out[i].catID 	 = in[i].catID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Nmeasure      = in[i].Nm;     
+    out[i].Nmissing      = in[i].Nn;     
+    out[i].measureOffset = in[i].offset; 
+    out[i].missingOffset = in[i].missing;
+    out[i].Nextend       = 0;
+    out[i].extendOffset  = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags    	 = in[i].code;   
+    out[i].ChiSq       	 = 0.0;
+    out[i].Npos       	 = 0.0;
+    out[i].extID 	 = 0;
   }
   return (out);
@@ -137,9 +167,4 @@
     out[i].D        = in[i].D;      
     out[i].Xp       = in[i].Xp;     
-    out[i].Nm       = in[i].Nmeasure;     
-    out[i].Nn       = in[i].Nmissing;     
-    out[i].code     = in[i].code;   
-    out[i].offset   = in[i].measureOffset; 
-    out[i].missing  = in[i].missingOffset;
     out[i].dR       = in[i].dR;
     out[i].dD       = in[i].dD;
@@ -152,4 +177,13 @@
     out[i].objID    = in[i].objID;
     out[i].catID    = in[i].catID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Nm       = in[i].Nmeasure;     
+    out[i].Nn       = in[i].Nmissing;     
+    out[i].offset   = in[i].measureOffset; 
+    out[i].missing  = in[i].missingOffset;
+
+    // changed or added for PS1_V1
+    out[i].code          = in[i].flags;   
   }
   return (out);
@@ -170,4 +204,8 @@
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
+
+    // changed or added for PS1_V1
+    out[i].M_20  = 0;      
+    out[i].M_80  = 0;      
  }
   return (out);
@@ -226,7 +264,5 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID	    = in[i].imageID_lo;
 
     out[i].order	    = in[i].order;
@@ -245,4 +281,15 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_DEV_1
+    out[i].imageID	    = in[i].imageID_lo;
+
+    // changed or added for PS1_DEV_2
+    out[i].externID	    = 0;
+    out[i].sourceID	    = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -283,8 +330,5 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID_hi	    = 0;
-    out[i].imageID_lo	    = in[i].imageID;
 
     out[i].order	    = in[i].order;
@@ -303,5 +347,12 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
-  }
-  return (out);
-}
+
+    // changed or added for PS1_DEV_1
+    out[i].imageID_hi	    = 0;
+    out[i].imageID_lo	    = in[i].imageID;
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
Index: trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 21508)
@@ -16,7 +16,4 @@
     out[i].Mcal       = in[i].Mcal;
 
-    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
-    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
-    out[i].Map        = in[i].Mgal;
     out[i].airmass    = in[i].airmass;
     out[i].az         = in[i].az;
@@ -25,25 +22,43 @@
     out[i].FWy 	      = in[i].FWy;
     out[i].theta      = in[i].theta;
-    out[i].dophot     = in[i].dophot;
     out[i].photcode   = in[i].photcode;
     out[i].t          = in[i].t;
     out[i].averef     = in[i].averef;
-    out[i].dbFlags    = in[i].flags;
     out[i].Xccd       = in[i].Xccd;
     out[i].Yccd       = in[i].Yccd;
     out[i].dXccd      = in[i].dXccd;
     out[i].dYccd      = in[i].dYccd;
-    out[i].stargal    = in[i].stargal;
     out[i].Sky        = in[i].Sky;
     out[i].dSky       = in[i].dSky;
-    out[i].qPSF       = (in[i].qPSF == NAN_S_SHORT) ? NAN : in[i].qPSF;
+
+    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
+    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
+
+    // changed or added for PS1_DEV_1 (2008.02.26)
+    out[i].psfQual    = (in[i].psfQual == NAN_S_SHORT) ? NAN : in[i].psfQual;
+    out[i].dbFlags    = in[i].flags;
     out[i].detID      = in[i].detID_lo;
     out[i].imageID    = in[i].imageID_lo;
-
-    // these don't have a correspondence
-    out[i].psfChisq  = 0;
-    out[i].crNsigma  = 0;
-    out[i].extNsigma = 0;
-    out[i].photFlags = 0;
+    out[i].psfChisq   = 0;
+    out[i].crNsigma   = 0;
+    out[i].extNsigma  = 0;
+
+    // changed or added for PS1_DEV_2
+    out[i].Map        = in[i].Mgal;
+    out[i].dMcal      = 0; 
+
+    // changed or added for PS1_V1
+    out[i].photFlags  = in[i].dophot << 16;
+    out[i].t_msec     = 0;
+    out[i].extID      = 0;
+    out[i].objID      = 0;
+    out[i].catID      = 0;
+    out[i].Mxx 	      = 0.0;
+    out[i].Mxy 	      = 0.0;
+    out[i].Myy        = 0.0;
+    out[i].posangle   = 0;
+    out[i].pltscale   = 0;
+    out[i].psfNdof    = 0;
+    out[i].psfNpix    = 0;
   }
   return (out);
@@ -64,5 +79,4 @@
     out[i].dM         = in[i].dM;
     out[i].Mcal       = in[i].Mcal;
-    out[i].Mgal       = in[i].Map;
     out[i].airmass    = in[i].airmass;
     out[i].az         = in[i].az;
@@ -71,21 +85,28 @@
     out[i].FWy 	      = in[i].FWy;
     out[i].theta      = in[i].theta;
-    out[i].dophot     = in[i].dophot;
     out[i].photcode   = in[i].photcode;
     out[i].t          = in[i].t;
     out[i].averef     = in[i].averef;
-    out[i].flags      = in[i].dbFlags;
     out[i].Xccd       = in[i].Xccd;
     out[i].Yccd       = in[i].Yccd;
     out[i].dXccd      = in[i].dXccd;
     out[i].dYccd      = in[i].dYccd;
-    out[i].stargal    = in[i].stargal;
     out[i].Sky        = in[i].Sky;
     out[i].dSky       = in[i].dSky;
-    out[i].qPSF       = isnan(in[i].qPSF) ? NAN_S_SHORT : in[i].qPSF;
+
+    // changed or added for PS1_DEV_1 (2008.02.26)
+    out[i].flags      = in[i].dbFlags;
+    out[i].psfQual    = isnan(in[i].psfQual) ? NAN_S_SHORT : in[i].psfQual;
     out[i].detID_hi   = 0;
     out[i].detID_lo   = in[i].detID;
     out[i].imageID_hi = 0;
     out[i].imageID_lo = in[i].imageID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Mgal       = in[i].Map;
+
+    // changed or added for PS1_V1
+    // out[i].photFlags  = in[i].photFlags & 0x0000ffff; (only dophot pre PS1_DEV_1)
+    out[i].dophot     = in[i].photFlags >> 16;
   }
   return (out);
@@ -105,9 +126,4 @@
     out[i].D        	 = in[i].D;      
     out[i].Xp       	 = in[i].Xp;     
-    out[i].Nmeasure      = in[i].Nm;     
-    out[i].Nmissing      = in[i].Nn;     
-    out[i].code     	 = in[i].code;   
-    out[i].measureOffset = in[i].offset; 
-    out[i].missingOffset = in[i].missing;
     out[i].dR       	 = in[i].dR;
     out[i].dD       	 = in[i].dD;
@@ -120,4 +136,18 @@
     out[i].objID 	 = in[i].objID;
     out[i].catID 	 = in[i].catID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Nmeasure      = in[i].Nm;     
+    out[i].Nmissing      = in[i].Nn;     
+    out[i].measureOffset = in[i].offset; 
+    out[i].missingOffset = in[i].missing;
+    out[i].Nextend       = 0;
+    out[i].extendOffset  = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags    	 = in[i].code;   
+    out[i].ChiSq       	 = 0.0;
+    out[i].Npos       	 = 0.0;
+    out[i].extID 	 = 0;
   }
   return (out);
@@ -137,9 +167,4 @@
     out[i].D        = in[i].D;      
     out[i].Xp       = in[i].Xp;     
-    out[i].Nm       = in[i].Nmeasure;     
-    out[i].Nn       = in[i].Nmissing;     
-    out[i].code     = in[i].code;   
-    out[i].offset   = in[i].measureOffset; 
-    out[i].missing  = in[i].missingOffset;
     out[i].dR       = in[i].dR;
     out[i].dD       = in[i].dD;
@@ -152,4 +177,13 @@
     out[i].objID    = in[i].objID;
     out[i].catID    = in[i].catID;
+
+    // changed or added for PS1_DEV_2
+    out[i].Nm       = in[i].Nmeasure;     
+    out[i].Nn       = in[i].Nmissing;     
+    out[i].offset   = in[i].measureOffset; 
+    out[i].missing  = in[i].missingOffset;
+
+    // changed or added for PS1_V1
+    out[i].code          = in[i].flags;   
   }
   return (out);
@@ -170,4 +204,8 @@
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
+
+    // changed or added for PS1_V1
+    out[i].M_20  = 0;      
+    out[i].M_80  = 0;      
  }
   return (out);
@@ -226,7 +264,5 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID	    = in[i].imageID_lo;
 
     out[i].order	    = in[i].order;
@@ -245,4 +281,15 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
+
+    // changed or added for PS1_DEV_1
+    out[i].imageID	    = in[i].imageID_lo;
+
+    // changed or added for PS1_DEV_2
+    out[i].externID	    = 0;
+    out[i].sourceID	    = 0;
+
+    // changed or added for PS1_V1
+    out[i].flags	    = in[i].code;
+    out[i].parentID	    = 0;
   }
   return (out);
@@ -283,8 +330,5 @@
     out[i].fwhm_y	    = in[i].fwhm_y;
     out[i].trate	    = in[i].trate;
-    out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID_hi	    = 0;
-    out[i].imageID_lo	    = in[i].imageID;
 
     out[i].order	    = in[i].order;
@@ -303,5 +347,15 @@
     out[i].Mxyyy	    = in[i].Mxyyy;
     out[i].Myyyy	    = in[i].Myyyy;
-  }
-  return (out);
-}
+
+    // changed or added for PS1_DEV_1
+    out[i].imageID_hi	    = 0;
+    out[i].imageID_lo	    = in[i].imageID;
+
+    // changed or added for PS1_V1
+    out[i].code		    = in[i].flags;
+  }
+  return (out);
+}
+
+// XXX no photcode conversions?  this may be from before we had a photcode FITS table...
+
Index: trunk/Ohana/src/libdvo/src/dvo_image.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_image.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/dvo_image.c	(revision 21508)
@@ -196,4 +196,5 @@
   if (db[0].format == DVO_FORMAT_PS1_DEV_2)       gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_DEV_2");
   if (db[0].format == DVO_FORMAT_PS1_DEV_3)       gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_DEV_3");
+  if (db[0].format == DVO_FORMAT_PS1_V1)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V1");
   
   return;
Index: trunk/Ohana/src/libdvo/src/dvo_image_raw.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/dvo_image_raw.c	(revision 21508)
@@ -54,4 +54,6 @@
   if (db[0].format == DVO_FORMAT_PS1_DEV_1)       ImageSize = sizeof(Image_PS1_DEV_1);
   if (db[0].format == DVO_FORMAT_PS1_DEV_2)       ImageSize = sizeof(Image_PS1_DEV_2);
+  if (db[0].format == DVO_FORMAT_PS1_DEV_3)       ImageSize = sizeof(Image_PS1_DEV_3);
+  if (db[0].format == DVO_FORMAT_PS1_V1)          ImageSize = sizeof(Image_PS1_V1);
 
   /* check that filesize makes sense */
@@ -78,4 +80,6 @@
   if (db[0].format == DVO_FORMAT_PS1_DEV_1)       gfits_table_mkheader_Image_PS1_DEV_1 (&db[0].theader);
   if (db[0].format == DVO_FORMAT_PS1_DEV_2)       gfits_table_mkheader_Image_PS1_DEV_2 (&db[0].theader);
+  if (db[0].format == DVO_FORMAT_PS1_DEV_3)       gfits_table_mkheader_Image_PS1_DEV_3 (&db[0].theader);
+  if (db[0].format == DVO_FORMAT_PS1_V1)          gfits_table_mkheader_Image_PS1_V1 (&db[0].theader);
     
   /* read data from file */
Index: trunk/Ohana/src/libdvo/src/dvosorts.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvosorts.c	(revision 21153)
+++ trunk/Ohana/src/libdvo/src/dvosorts.c	(revision 21508)
@@ -46,16 +46,4 @@
 }
 
-void sort_stars_ra (Stars *stars, int N) {
-
-# define SWAPFUNC(A,B){ Stars tmp; tmp = stars[A]; stars[A] = stars[B]; stars[B] = tmp; }
-# define COMPARE(A,B)(stars[A].R < stars[B].R)
-
-  OHANA_SORT (N, COMPARE, SWAPFUNC);
-
-# undef SWAPFUNC
-# undef COMPARE
-
-}
-
 void sort_regions (SkyRegion *region, int N) {
 
@@ -70,2 +58,16 @@
 }
 
+# if (0)
+// deprecated along with Stars as an autocode type
+void sort_stars_ra (Stars *stars, int N) {
+
+# define SWAPFUNC(A,B){ Stars tmp; tmp = stars[A]; stars[A] = stars[B]; stars[B] = tmp; }
+# define COMPARE(A,B)(stars[A].R < stars[B].R)
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
+# endif
