Index: /branches/eam_branches/ipp-20120905/Ohana/src/libautocode/def/measure.d
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libautocode/def/measure.d	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libautocode/def/measure.d	(revision 34728)
@@ -2,5 +2,5 @@
 EXTNAME      DVO_MEASURE
 TYPE         BINTABLE
-SIZE         176
+SIZE         184
 DESCRIPTION  DVO Detection Measurement Table 
 
@@ -29,4 +29,7 @@
 FIELD Xccd,           X_CCD,        float,          X coord on chip,                pixels
 FIELD Yccd,           Y_CCD,        float,          Y coord on chip,                pixels
+
+FIELD Xoff,           X_OFF,        float,          X correction in chip coords,   pixels
+FIELD Yoff,           Y_OFF,        float,          Y correction in chip coords,   pixels
 
 # could these be packed into fewer bits?
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/doc/notes.txt
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/doc/notes.txt	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/doc/notes.txt	(revision 34728)
@@ -17,5 +17,5 @@
 
 4) create a DVOTableFormat entry for the new format
-   (libdvo/include/dvo.h).  the naming convetion is DVO_FORMAT_FOO.
+   (libdvo/include/dvo.h).  the naming convention is DVO_FORMAT_FOO.
 
 5) add an entry for the new format in dvo_catalog_catformat
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/include/dvo.h	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/include/dvo.h	(revision 34728)
@@ -175,4 +175,7 @@
   ID_OBJ_GOOD       = 0x04000000, // good-quality measurement in our data (eg,PS)
   ID_OBJ_GOOD_ALT   = 0x08000000, // good-quality measurement in  external data (eg, 2MASS)
+  ID_OBJ_GOOD_STACK = 0x10000000, // good-quality object in the stack (> 1 good stack)
+  ID_OBJ_SUSPECT_STACK = 0x20000000, // suspect object in the stack (> 1 good or suspect stack, < 2 good)
+  ID_OBJ_BAD_STACK  = 0x40000000, // good-quality object in the stack (> 1 good stack)
 } DVOAverageFlags;
 
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/include/dvodb.h
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/include/dvodb.h	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/include/dvodb.h	(revision 34728)
@@ -122,4 +122,6 @@
       MEAS_XCCD_ERR, 
       MEAS_YCCD_ERR, 
+      MEAS_XOFF, 
+      MEAS_YOFF, 
       MEAS_POS_SYS_ERR, 
       MEAS_XMOSAIC, 
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dbExtractMeasures.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dbExtractMeasures.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dbExtractMeasures.c	(revision 34728)
@@ -443,4 +443,10 @@
 # endif
       break;
+    case MEAS_XOFF: /* OK */
+      value.Flt = measure[0].Xoff;
+      break;
+    case MEAS_YOFF: /* OK */
+      value.Flt = measure[0].Yoff;
+      break;
     case MEAS_XCCD_ERR: /* OK */
       value.Flt = FromShortPixels(measure[0].dXccd);
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dbFields.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dbFields.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dbFields.c	(revision 34728)
@@ -217,4 +217,6 @@
   if (!strcasecmp (fieldName, "XCCD:ERR"))   	 ESCAPE (MEAS_XCCD_ERR,       MAG_NONE, OPIHI_FLT);
   if (!strcasecmp (fieldName, "YCCD:ERR"))   	 ESCAPE (MEAS_YCCD_ERR,       MAG_NONE, OPIHI_FLT);
+  if (!strcasecmp (fieldName, "XOFF"))       	 ESCAPE (MEAS_XOFF,           MAG_NONE, OPIHI_FLT);
+  if (!strcasecmp (fieldName, "YOFF"))       	 ESCAPE (MEAS_YOFF,           MAG_NONE, OPIHI_FLT);
   if (!strcasecmp (fieldName, "POS_SYS_ERR"))    ESCAPE (MEAS_POS_SYS_ERR,    MAG_NONE, OPIHI_FLT);
   if (!strcasecmp (fieldName, "XMOSAIC"))    	 ESCAPE (MEAS_XMOSAIC,        MAG_NONE, OPIHI_FLT);
@@ -228,4 +230,5 @@
   if (!strcasecmp (fieldName, "CATID"))      	 ESCAPE (MEAS_CAT_ID,         MAG_NONE, OPIHI_INT);
   if (!strcasecmp (fieldName, "IMAGEID"))    	 ESCAPE (MEAS_IMAGE_ID,       MAG_NONE, OPIHI_INT);
+  if (!strcasecmp (fieldName, "EXTERNID"))    	 ESCAPE (MEAS_EXTERN_ID,      MAG_NONE, OPIHI_INT);
   if (!strcasecmp (fieldName, "PSF_QF"))     	 ESCAPE (MEAS_PSF_QF,         MAG_NONE, OPIHI_FLT);
   if (!strcasecmp (fieldName, "PSF_QF_PERFECT")) ESCAPE (MEAS_PSF_QF_PERFECT, MAG_NONE, OPIHI_FLT);
@@ -237,5 +240,4 @@
   if (!strcasecmp (fieldName, "SKY"))        	 ESCAPE (MEAS_SKY,            MAG_NONE, OPIHI_FLT);
   if (!strcasecmp (fieldName, "SKY_ERR"))    	 ESCAPE (MEAS_dSKY,           MAG_NONE, OPIHI_FLT);
-  if (!strcasecmp (fieldName, "externID"))    	 ESCAPE (MEAS_EXTERN_ID,      MAG_NONE, OPIHI_INT);
   if (!strcasecmp (fieldName, "MCAL_OFFSET"))    ESCAPE (MEAS_MCAL_OFFSET,    MAG_NONE, OPIHI_FLT);
   if (!strcasecmp (fieldName, "FLAT"))    	 ESCAPE (MEAS_FLAT,           MAG_NONE, OPIHI_FLT);
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_catalog.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_catalog.c	(revision 34728)
@@ -83,12 +83,12 @@
   average->dP        	   = 0;
 
-  average->ChiSqAve  	   = 0.0;
-  average->ChiSqPM   	   = 0.0;
-  average->ChiSqPar  	   = 0.0;
+  average->ChiSqAve  	   = NAN;
+  average->ChiSqPM   	   = NAN;
+  average->ChiSqPar  	   = NAN;
   average->Tmean   	   = 0;
   average->Trange   	   = 0;
 
-  average->psfQF   	   = 0.0;
-  average->psfQFperf   	   = 0.0;
+  average->psfQF   	   = NAN;
+  average->psfQFperf   	   = NAN;
 
   average->stargal    	   = 0.0;
@@ -161,4 +161,6 @@
  measure->Xccd      = NAN;
  measure->Yccd      = NAN;
+ measure->Xoff      = 0.0;
+ measure->Yoff      = 0.0;
 
  measure->Sky       = NAN;
@@ -176,4 +178,5 @@
 
  measure->psfQF     = NAN;
+ measure->psfQFperf = NAN;
  measure->psfChisq  = NAN;
  measure->psfNdof   = 0;
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 34728)
@@ -11,4 +11,5 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_measure_init (&out[i]);
     out[i].dR         = in[i].dR;
     out[i].dD         = in[i].dD;
@@ -40,30 +41,9 @@
     out[i].photFlags  = in[i].photFlags;
 
-    // changed or added for PS1_DEV_2
+    // changed for PS1_DEV_2
     out[i].Map        = in[i].Mgal;
-    out[i].dMcal      = 0; 
-
-    // changed or added for PS1_V1
+
+    // changed 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;
-
-    // added for PS1_V4
-    out[i].Mkron      = NAN;
-    out[i].dMkron     = NAN;
-    out[i].FluxPSF    = NAN;
-    out[i].dFluxPSF   = NAN;
-    out[i].FluxKron   = NAN;
-    out[i].dFluxKron  = NAN;
-    out[i].psfQFperf  = NAN;
   }
   return (out);
@@ -125,4 +105,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_average_init (&out[i]);
+
     out[i].R        	 = in[i].R;      
     out[i].D        	 = in[i].D;      
@@ -138,30 +120,14 @@
     out[i].catID 	 = in[i].catID;
 
-    // changed or added for PS1_DEV_2
+    // changed 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
+
+    // changed for PS1_V1
     out[i].flags    	 = in[i].code;   
-    out[i].ChiSqAve    	 = NAN;
-    out[i].ChiSqPM    	 = NAN;
-    out[i].ChiSqPar    	 = NAN;
-    out[i].Tmean    	 = 0;
-    out[i].Trange   	 = 0;
-    out[i].Npos       	 = 0.0;
-    out[i].extID 	 = 0;
-
-    // added in PS1_V3
-    out[i].photFlagsUpper = 0;
-    out[i].photFlagsLower = 0;
-
-    // added for PS1_V4 (Xp dropped in V4 onward, was not really used anyway)
-    out[i].psfQF         = NAN;
-    out[i].psfQFperf     = NAN;
-    out[i].stargal     	 = NAN;
+
+    // PS1_V4 : Xp dropped in V4 onward, was not really used anyway
   }
   return (out);
@@ -210,4 +176,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_secfilt_init (&out[i]);
+
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
@@ -215,25 +183,4 @@
     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;      
-
-    // changed or added for PS1_V2
-    out[i].flags = 0;
-
-    // added in PS1_V3
-    out[i].Map         = 0;
-    out[i].Mstdev      = 0;
-    out[i].ubercalDist = 0;
-
-    // added for PS1_V4
-    out[i].Mkron       = NAN;
-    out[i].dMkron      = NAN;
-    out[i].FluxPSF     = NAN;
-    out[i].dFluxPSF    = NAN;
-    out[i].FluxKron    = NAN;
-    out[i].dFluxKron   = NAN;
-    out[i].stackDetectID     = 0;
  }
   return (out);
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 34728)
@@ -11,4 +11,5 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_measure_init (&out[i]);
     out[i].dR         = in[i].dR;
     out[i].dD         = in[i].dD;
@@ -41,26 +42,6 @@
     out[i].dbFlags    = in[i].dbFlags;
 
-    // changed or added for PS1_V1
+    // changed 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;
-
-    // added for PS1_V4
-    out[i].Mkron      = NAN;
-    out[i].dMkron     = NAN;
-    out[i].FluxPSF    = NAN;
-    out[i].dFluxPSF   = NAN;
-    out[i].FluxKron   = NAN;
-    out[i].dFluxKron  = NAN;
-    out[i].psfQFperf  = NAN;
  }
   return (out);
@@ -121,4 +102,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_average_init (&out[i]);
+
     out[i].R        	 = in[i].R;      
     out[i].D        	 = in[i].D;      
@@ -140,22 +123,6 @@
     out[i].catID 	 = in[i].catID;
 
-    // changed or added for PS1_V1
+    // changed for PS1_V1
     out[i].flags    	 = in[i].code;   
-    out[i].ChiSqAve    	 = NAN;
-    out[i].ChiSqPM    	 = NAN;
-    out[i].ChiSqPar    	 = NAN;
-    out[i].Tmean    	 = 0;
-    out[i].Trange   	 = 0;
-    out[i].Npos       	 = 0.0;
-    out[i].extID 	 = 0;
-
-    // added in PS1_V3
-    out[i].photFlagsUpper = 0;
-    out[i].photFlagsLower = 0;
-
-    // added for PS1_V4 (Xp dropped in V4 onward, was not really used anyway)
-    out[i].psfQF         = NAN;
-    out[i].psfQFperf     = NAN;
-    out[i].stargal     	 = NAN;
   }
   return (out);
@@ -204,4 +171,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_secfilt_init (&out[i]);
+
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
@@ -209,25 +178,4 @@
     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;      
-
-    // changed or added for PS1_V2
-    out[i].flags = 0;
-
-    // added in PS1_V3
-    out[i].Map         = 0;
-    out[i].Mstdev      = 0;
-    out[i].ubercalDist = 0;
-
-    // added for PS1_V4
-    out[i].Mkron       = NAN;
-    out[i].dMkron      = NAN;
-    out[i].FluxPSF     = NAN;
-    out[i].dFluxPSF    = NAN;
-    out[i].FluxKron    = NAN;
-    out[i].dFluxKron   = NAN;
-    out[i].stackDetectID     = 0;
  }
   return (out);
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c	(revision 34728)
@@ -11,54 +11,17 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_measure_init (&out[i]);
+
     out[i].dR         = in[i].dR;
     out[i].dD         = in[i].dD;
     out[i].M          = in[i].M;
-    out[i].Mcal       = 0.0;
-    out[i].Map        = NAN;
     out[i].dM         = in[i].dM;
-    out[i].dMcal      = 0.0;
     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].psfQF      = 1.0; // we do not save a value, but some operations (relphot/average) filter on this value..
-    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;
-
-    // added for PS1_V4
-    out[i].Mkron      = NAN;
-    out[i].dMkron     = NAN;
-    out[i].FluxPSF    = NAN;
-    out[i].dFluxPSF   = NAN;
-    out[i].FluxKron   = NAN;
-    out[i].dFluxKron  = NAN;
-    out[i].psfQFperf  = NAN;
   }
   return (out);
@@ -96,39 +59,16 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_average_init (&out[i]);
+
     out[i].R        	 = in[i].R;      
     out[i].D        	 = in[i].D;      
     out[i].dR       	 = in[i].dR;
     out[i].dD       	 = in[i].dD;
-    out[i].uR       	 = NAN;
-    out[i].uD       	 = NAN;
-    out[i].duR      	 = NAN;
-    out[i].duD      	 = NAN;
-    out[i].P        	 = NAN;
-    out[i].dP       	 = NAN;
-    out[i].ChiSqAve    	 = NAN;
-    out[i].ChiSqPM    	 = NAN;
-    out[i].ChiSqPar    	 = NAN;
-    out[i].Tmean    	 = 0;
-    out[i].Trange   	 = 0;
-    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;
-
-    // added in PS1_V3
-    out[i].photFlagsUpper = 0;
-    out[i].photFlagsLower = 0;
-
-    // added for PS1_V4 (Xp dropped in V4 onward, was not really used anyway)
-    out[i].psfQF         = NAN;
-    out[i].psfQFperf     = NAN;
-    out[i].stargal     	 = NAN;
   }
   return (out);
@@ -167,28 +107,8 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_secfilt_init (&out[i]);
+
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = NAN_S_SHORT;
-    out[i].Ncode = 0;
-    out[i].Nused = 0;
-    out[i].M_20  = 0;
-    out[i].M_80  = 0;
-
-    // changed or added for PS1_V2
-    out[i].flags = 0;
-
-    // added in PS1_V3
-    out[i].Map         = 0;
-    out[i].Mstdev      = 0;
-    out[i].ubercalDist = 0;
-
-    // added for PS1_V4
-    out[i].Mkron       = NAN;
-    out[i].dMkron      = NAN;
-    out[i].FluxPSF     = NAN;
-    out[i].dFluxPSF    = NAN;
-    out[i].FluxKron    = NAN;
-    out[i].dFluxKron   = NAN;
-    out[i].stackDetectID     = 0;
  }
   return (out);
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 34728)
@@ -11,4 +11,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_measure_init (&out[i]);
+
     out[i].dR         = in[i].dR;
     out[i].dD         = in[i].dD;
@@ -52,13 +54,4 @@
     out[i].dbFlags    = in[i].dbFlags;
     out[i].photFlags  = in[i].photFlags;
-
-    // added for PS1_V4
-    out[i].Mkron      = NAN;
-    out[i].dMkron     = NAN;
-    out[i].FluxPSF    = NAN;
-    out[i].dFluxPSF   = NAN;
-    out[i].FluxKron   = NAN;
-    out[i].dFluxKron  = NAN;
-    out[i].psfQFperf  = NAN;
   }
   return (out);
@@ -128,4 +121,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_average_init (&out[i]);
+
     out[i].R        	 = in[i].R;      
     out[i].D        	 = in[i].D;      
@@ -139,8 +134,4 @@
     out[i].dP       	 = in[i].dP;
     out[i].ChiSqAve    	 = in[i].ChiSq;     
-    out[i].ChiSqPM    	 = NAN;
-    out[i].ChiSqPar    	 = NAN;
-    out[i].Tmean    	 = 0;
-    out[i].Trange    	 = 0;
     out[i].Npos       	 = in[i].Npos;     
     out[i].Nmeasure      = in[i].Nmeasure;     
@@ -154,13 +145,4 @@
     out[i].catID 	 = in[i].catID;
     out[i].extID 	 = in[i].extID;
-
-    // added in PS1_V3
-    out[i].photFlagsUpper = 0;
-    out[i].photFlagsLower = 0;
-
-    // added for PS1_V4 (Xp dropped in V4 onward, was not really used anyway)
-    out[i].psfQF         = NAN;
-    out[i].psfQFperf     = NAN;
-    out[i].stargal     	 = NAN;
   }
   return (out);
@@ -210,4 +192,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_secfilt_init (&out[i]);
+
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
@@ -217,21 +201,4 @@
     out[i].M_20  = in[i].M_20;      
     out[i].M_80  = in[i].M_80;      
-
-    // changed or added for PS1_V2
-    out[i].flags = 0;
-
-    // added in PS1_V3
-    out[i].Map         = 0;
-    out[i].Mstdev      = 0;
-    out[i].ubercalDist = 0;
-
-    // added for PS1_V4
-    out[i].Mkron       = NAN;
-    out[i].dMkron      = NAN;
-    out[i].FluxPSF     = NAN;
-    out[i].dFluxPSF    = NAN;
-    out[i].FluxKron    = NAN;
-    out[i].dFluxKron   = NAN;
-    out[i].stackDetectID     = 0;
  }
   return (out);
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c	(revision 34728)
@@ -11,4 +11,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_measure_init (&out[i]);
+
     out[i].dR         = in[i].dR;
     out[i].dD         = in[i].dD;
@@ -53,13 +55,4 @@
     out[i].dbFlags    = in[i].dbFlags;
     out[i].photFlags  = in[i].photFlags;
-
-    // added for PS1_V4
-    out[i].Mkron      = NAN;
-    out[i].dMkron     = NAN;
-    out[i].FluxPSF    = NAN;
-    out[i].dFluxPSF   = NAN;
-    out[i].FluxKron   = NAN;
-    out[i].dFluxKron  = NAN;
-    out[i].psfQFperf  = NAN;
   }
   return (out);
@@ -129,4 +122,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_average_init (&out[i]);
+
     out[i].R        	 = in[i].R;      
     out[i].D        	 = in[i].D;      
@@ -155,13 +150,4 @@
     out[i].catID 	 = in[i].catID;
     out[i].extID 	 = in[i].extID;
-
-    // added in PS1_V3
-    out[i].photFlagsUpper = 0;
-    out[i].photFlagsLower = 0;
-
-    // added for PS1_V4 (Xp dropped in V4 onward, was not really used anyway)
-    out[i].psfQF         = NAN;
-    out[i].psfQFperf     = NAN;
-    out[i].stargal     	 = NAN;
   }
   return (out);
@@ -215,4 +201,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_secfilt_init (&out[i]);
+
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
@@ -223,18 +211,4 @@
     out[i].M_20  = in[i].M_20;      
     out[i].M_80  = in[i].M_80;      
-
-    // added in PS1_V3
-    out[i].Map         = 0;
-    out[i].Mstdev      = 0;
-    out[i].ubercalDist = 0;
-
-    // added for PS1_V4
-    out[i].Mkron       = NAN;
-    out[i].dMkron      = NAN;
-    out[i].FluxPSF     = NAN;
-    out[i].dFluxPSF    = NAN;
-    out[i].FluxKron    = NAN;
-    out[i].dFluxKron   = NAN;
-    out[i].stackDetectID     = 0;
  }
   return (out);
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c	(revision 34728)
@@ -11,4 +11,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_measure_init (&out[i]);
+
     out[i].dR         = in[i].dR;
     out[i].dD         = in[i].dD;
@@ -53,13 +55,4 @@
     out[i].dbFlags    = in[i].dbFlags;
     out[i].photFlags  = in[i].photFlags;
-
-    // added for PS1_V4
-    out[i].Mkron      = NAN;
-    out[i].dMkron     = NAN;
-    out[i].FluxPSF    = NAN;
-    out[i].dFluxPSF   = NAN;
-    out[i].FluxKron   = NAN;
-    out[i].dFluxKron  = NAN;
-    out[i].psfQFperf  = NAN;
   }
   return (out);
@@ -129,4 +122,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_average_init (&out[i]);
+
     out[i].R        	 = in[i].R;      
     out[i].D        	 = in[i].D;      
@@ -157,9 +152,4 @@
     out[i].catID 	 = in[i].catID;
     out[i].extID 	 = in[i].extID;
-
-    // added for PS1_V4 (Xp dropped in V4 onward, was not really used anyway)
-    out[i].psfQF         = NAN;
-    out[i].psfQFperf     = NAN;
-    out[i].stargal     	 = NAN;
   }
   return (out);
@@ -215,4 +205,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_secfilt_init (&out[i]);
+
     out[i].M           = in[i].M;      
     out[i].Map         = in[i].Map;      
@@ -226,13 +218,4 @@
     out[i].Mstdev      = in[i].Mstdev;      
     out[i].ubercalDist = in[i].ubercalDist;      
-
-    // added for PS1_V4
-    out[i].Mkron       = NAN;
-    out[i].dMkron      = NAN;
-    out[i].FluxPSF     = NAN;
-    out[i].dFluxPSF    = NAN;
-    out[i].FluxKron    = NAN;
-    out[i].dFluxKron   = NAN;
-    out[i].stackDetectID     = 0;
  }
   return (out);
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c	(revision 34728)
@@ -9,4 +9,69 @@
 
   ALLOCATE_ZERO (out, Measure, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    dvo_measure_init (&out[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].Mkron      = in[i].Mkron;
+    out[i].dMkron     = in[i].dMkron;
+    out[i].dM         = in[i].dM;
+    out[i].dMcal      = in[i].dMcal;
+    out[i].dt         = in[i].dt;
+    out[i].FluxPSF    = in[i].FluxPSF;
+    out[i].dFluxPSF   = in[i].dFluxPSF;
+    out[i].FluxKron   = in[i].FluxKron;
+    out[i].dFluxKron  = in[i].dFluxKron;
+    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].Xoff       = in[i].Xoff;
+    out[i].Yoff       = in[i].Yoff;
+    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].psfQF      = in[i].psfQF;
+    out[i].psfQFperf  = in[i].psfQFperf;
+    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].dRsys      = in[i].dRsys;
+    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_V4 *MeasureInternalTo_PS1_V4 (Measure *in, off_t Nvalues) {
+
+  off_t i;
+  Measure_PS1_V4 *out;
+
+  ALLOCATE_ZERO (out, Measure_PS1_V4, Nvalues);
 
   for (i = 0; i < Nvalues; i++) {
@@ -64,65 +129,4 @@
 }
 
-Measure_PS1_V4 *MeasureInternalTo_PS1_V4 (Measure *in, off_t Nvalues) {
-
-  off_t i;
-  Measure_PS1_V4 *out;
-
-  ALLOCATE_ZERO (out, Measure_PS1_V4, 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].Mkron      = in[i].Mkron;
-    out[i].dMkron     = in[i].dMkron;
-    out[i].dM         = in[i].dM;
-    out[i].dMcal      = in[i].dMcal;
-    out[i].dt         = in[i].dt;
-    out[i].FluxPSF    = in[i].FluxPSF;
-    out[i].dFluxPSF   = in[i].dFluxPSF;
-    out[i].FluxKron   = in[i].FluxKron;
-    out[i].dFluxKron  = in[i].dFluxKron;
-    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].psfQF      = in[i].psfQF;
-    out[i].psfQFperf  = in[i].psfQFperf;
-    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].dRsys      = in[i].dRsys;
-    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_V4_ToInternal (Average_PS1_V4 *in, off_t Nvalues, SecFilt **primary) {
@@ -134,4 +138,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_average_init (&out[i]);
+
     out[i].R        	 = in[i].R;      
     out[i].D        	 = in[i].D;      
@@ -221,4 +227,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_secfilt_init (&out[i]);
+
     out[i].M             = in[i].M;      
     out[i].Map           = in[i].Map;      
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_elixir.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 34728)
@@ -10,4 +10,5 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_measure_init (&out[i]);
     out[i].FWx 	    = in[i].FWx;
     out[i].t        = in[i].t;
@@ -28,49 +29,17 @@
     
     // 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].Sky       = 0;
-    out[i].dSky      = 0;
-    out[i].psfQF     = 0;
-    out[i].psfChisq  = 0;
-    out[i].crNsigma  = 0;
-    out[i].extNsigma = 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].Xccd      = 0;  // determine on-the-fly
+    // out[i].Yccd      = 0;  // determine on-the-fly
+    // out[i].detID     = 0;  // determine on-the-fly
+    // out[i].imageID   = 0;  // determine on-the-fly
+
+    // changed 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
+
+    // changed for PS1_DEV_2
     out[i].Map        = in[i].Mgal;
-    out[i].dMcal      = 0; 
-
-    // changed or added for PS1_V1
+
+    // changed 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;
-
-    // added for PS1_V4
-    out[i].Mkron      = NAN;
-    out[i].dMkron     = NAN;
-    out[i].FluxPSF    = NAN;
-    out[i].dFluxPSF   = NAN;
-    out[i].FluxKron   = NAN;
-    out[i].dFluxKron  = NAN;
-    out[i].psfQFperf  = NAN;
   }
   return (out);
@@ -126,4 +95,7 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_average_init (&out[i]);
+    dvo_secfilt_init (&primary[0][i]);
+
     out[i].R       	 = in[i].R;      
     out[i].D       	 = in[i].D;      
@@ -134,18 +106,7 @@
     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;
-    out[i].uR      = 0;
-    out[i].uD      = 0;
-    out[i].duR     = 0;
-    out[i].duD     = 0;
-    out[i].P       = 0;
-    out[i].dP      = 0;
-    out[i].objID   = 0; // determine on-the-fly
-    out[i].catID   = 0; // determine on-the-fly
+    // out[i].objID   = 0; // determine on-the-fly
+    // out[i].catID   = 0; // determine on-the-fly
 
     // changed or added for PS1_DEV_2
@@ -154,25 +115,7 @@
     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].ChiSqAve    	 = NAN;
-    out[i].ChiSqPM    	 = NAN;
-    out[i].ChiSqPar    	 = NAN;
-    out[i].Tmean    	 = 0;
-    out[i].Trange   	 = 0;
-    out[i].Npos       	 = 0.0;
-    out[i].extID 	 = 0;
-
-    // added in PS1_V3
-    out[i].photFlagsUpper = 0;
-    out[i].photFlagsLower = 0;
-
-    // added for PS1_V4 (Xp dropped in V4 onward, was not really used anyway)
-    out[i].psfQF         = NAN;
-    out[i].psfQFperf     = NAN;
-    out[i].stargal     	 = NAN;
   }
   return (out);
@@ -217,4 +160,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_secfilt_init (&out[i]);
+
     out[i].Xm    = in[i].Xm;     
 
@@ -222,27 +167,4 @@
     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].Ncode = 0;
-    out[i].Nused = 0;
-
-    // changed or added for PS1_V1
-    out[i].M_20  = 0;      
-    out[i].M_80  = 0;      
-
-    // changed or added for PS1_V2
-    out[i].flags = 0;
-
-    // added in PS1_V3
-    out[i].Map         = 0;
-    out[i].Mstdev      = 0;
-    out[i].ubercalDist = 0;
-
-    // added for PS1_V4
-    out[i].Mkron       = NAN;
-    out[i].dMkron      = NAN;
-    out[i].FluxPSF    = NAN;
-    out[i].dFluxPSF   = NAN;
-    out[i].FluxKron   = NAN;
-    out[i].dFluxKron  = NAN;
-    out[i].stackDetectID     = 0;
   }
   return (out);
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_loneos.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 34728)
@@ -10,4 +10,5 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_measure_init (&out[i]);
     out[i].t        = in[i].t;
 
@@ -16,9 +17,4 @@
     out[i].dbFlags   = (in[i].averef & 0xff000000) >> 24;
     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
@@ -32,47 +28,11 @@
     
     // 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].Sky       = 0;
-    out[i].dSky      = 0;
-    out[i].psfQF     = 0;
-    out[i].psfChisq  = 0;
-    out[i].crNsigma  = 0;
-    out[i].extNsigma = 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; 
+    // out[i].Xccd      = 0;  // determine on-the-fly
+    // out[i].Yccd      = 0;  // determine on-the-fly
+    // out[i].detID     = 0;  // determine on-the-fly
+    // out[i].imageID   = 0;  // determine on-the-fly
 
     // 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;
-
-    // added for PS1_V4
-    out[i].Mkron      = NAN;
-    out[i].dMkron     = NAN;
-    out[i].FluxPSF    = NAN;
-    out[i].dFluxPSF   = NAN;
-    out[i].FluxKron   = NAN;
-    out[i].dFluxKron  = NAN;
-    out[i].psfQFperf  = NAN;
   }
   return (out);
@@ -117,27 +77,17 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_average_init (&out[i]);
+    dvo_secfilt_init (&primary[0][i]);
+
     out[i].R       	 = in[i].R;      
     out[i].D       	 = in[i].D;      
-
-    // 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;
-    out[i].uR      = 0;
-    out[i].uD      = 0;
-    out[i].duR     = 0;
-    out[i].duD     = 0;
-    out[i].P       = 0;
-    out[i].dP      = 0;
-    out[i].objID   = 0; // determine on-the-fly
-    out[i].catID   = 0; // determine on-the-fly
+    // out[i].objID   = 0; // determine on-the-fly
+    // out[i].catID   = 0; // determine on-the-fly
 
     // changed or added for PS1_DEV_2
@@ -146,25 +96,9 @@
     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].ChiSqAve    	 = NAN;
-    out[i].ChiSqPM    	 = NAN;
-    out[i].ChiSqPar    	 = NAN;
-    out[i].Tmean    	 = 0;
-    out[i].Trange   	 = 0;
-    out[i].Npos       	 = 0.0;
-    out[i].extID 	 = 0;
-
-    // added in PS1_V3
-    out[i].photFlagsUpper = 0;
-    out[i].photFlagsLower = 0;
-
-    // added for PS1_V4 (Xp dropped in V4 onward, was not really used anyway)
-    out[i].psfQF         = NAN;
-    out[i].psfQFperf     = NAN;
-    out[i].stargal     	 = NAN;
+
+    // PS1_V4 : (Xp dropped in V4 onward, was not really used anyway)
   }
   return (out);
@@ -208,34 +142,10 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_secfilt_init (&out[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].Ncode = 0;
-    out[i].Nused = 0;
-
-    // changed or added for PS1_V1
-    out[i].M_20  = 0;      
-    out[i].M_80  = 0;      
-
-    // changed or added for PS1_V2
-    out[i].flags = 0;
-
-    // added in PS1_V3
-    out[i].Map         = 0;
-    out[i].Mstdev      = 0;
-    out[i].ubercalDist = 0;
-
-    // added for PS1_V4
-    out[i].Mkron       = NAN;
-    out[i].dMkron      = NAN;
-    out[i].FluxPSF    = NAN;
-    out[i].dFluxPSF   = NAN;
-    out[i].FluxKron   = NAN;
-    out[i].dFluxKron  = NAN;
-    out[i].stackDetectID     = 0;
   }
   return (out);
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 34728)
@@ -10,4 +10,5 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_measure_init (&out[i]);
     out[i].dR         = in[i].dR;
     out[i].dD         = in[i].dD;
@@ -35,39 +36,15 @@
     // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
 
-    // changed or added for PS1_DEV_1 (2008.02.26)
+    // changed for PS1_DEV_1 (2008.02.26)
     out[i].psfQF      = (in[i].psfQF == NAN_S_SHORT) ? NAN : in[i].psfQF;
     out[i].dbFlags    = in[i].flags;
     out[i].detID      = in[i].detID_lo;
     out[i].imageID    = in[i].imageID_lo;
-    out[i].psfChisq   = 0;
-    out[i].crNsigma   = 0;
-    out[i].extNsigma  = 0;
-
-    // changed or added for PS1_DEV_2
+
+    // changed for PS1_DEV_2
     out[i].Map        = in[i].Mgal;
-    out[i].dMcal      = 0; 
-
-    // changed or added for PS1_V1
+
+    // changed 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;
-
-    // added for PS1_V4
-    out[i].Mkron      = NAN;
-    out[i].dMkron     = NAN;
-    out[i].FluxPSF    = NAN;
-    out[i].dFluxPSF   = NAN;
-    out[i].FluxKron   = NAN;
-    out[i].dFluxKron  = NAN;
-    out[i].psfQFperf  = NAN;
   }
   return (out);
@@ -132,4 +109,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_average_init (&out[i]);
+
     out[i].R        	 = in[i].R;      
     out[i].D        	 = in[i].D;      
@@ -145,30 +124,12 @@
     out[i].catID 	 = in[i].catID;
 
-    // changed or added for PS1_DEV_2
+    // changed 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
+
+    // changed for PS1_V1
     out[i].flags    	 = in[i].code;   
-    out[i].ChiSqAve    	 = NAN;
-    out[i].ChiSqPM    	 = NAN;
-    out[i].ChiSqPar    	 = NAN;
-    out[i].Tmean    	 = 0;
-    out[i].Trange   	 = 0;
-    out[i].Npos       	 = 0.0;
-    out[i].extID 	 = 0;
-
-    // added in PS1_V3
-    out[i].photFlagsUpper = 0;
-    out[i].photFlagsLower = 0;
-
-    // added for PS1_V4 (Xp dropped in V4 onward, was not really used anyway)
-    out[i].psfQF         = NAN;
-    out[i].psfQFperf     = NAN;
-    out[i].stargal     	 = NAN;
   }
   return (out);
@@ -219,4 +180,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_secfilt_init (&out[i]);
+
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
@@ -224,25 +187,4 @@
     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;      
-
-    // changed or added for PS1_V2
-    out[i].flags = 0;
-
-    // added in PS1_V3
-    out[i].Map         = 0;
-    out[i].Mstdev      = 0;
-    out[i].ubercalDist = 0;
-
-    // added for PS1_V4
-    out[i].Mkron       = NAN;
-    out[i].dMkron      = NAN;
-    out[i].FluxPSF     = NAN;
-    out[i].dFluxPSF    = NAN;
-    out[i].FluxKron    = NAN;
-    out[i].dFluxKron   = NAN;
-    out[i].stackDetectID     = 0;
  }
   return (out);
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 34728)
@@ -10,4 +10,5 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_measure_init (&out[i]);
     out[i].dR         = in[i].dR;
     out[i].dD         = in[i].dD;
@@ -40,34 +41,10 @@
     out[i].detID      = in[i].detID_lo;
     out[i].imageID    = in[i].imageID_lo;
-    out[i].psfChisq   = 0;
-    out[i].crNsigma   = 0;
-    out[i].extNsigma  = 0;
-
-    // changed or added for PS1_DEV_2
+
+    // changed for PS1_DEV_2
     out[i].Map        = in[i].Mgal;
-    out[i].dMcal      = 0; 
-
-    // changed or added for PS1_V1
+
+    // changed 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;
-
-    // added for PS1_V4
-    out[i].Mkron      = NAN;
-    out[i].dMkron     = NAN;
-    out[i].FluxPSF    = NAN;
-    out[i].dFluxPSF   = NAN;
-    out[i].FluxKron   = NAN;
-    out[i].dFluxKron  = NAN;
-    out[i].psfQFperf  = NAN;
   }
   return (out);
@@ -132,4 +109,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_average_init (&out[i]);
+
     out[i].R        	 = in[i].R;      
     out[i].D        	 = in[i].D;      
@@ -145,30 +124,12 @@
     out[i].catID 	 = in[i].catID;
 
-    // changed or added for PS1_DEV_2
+    // changed 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
+
+    // changed for PS1_V1
     out[i].flags    	 = in[i].code;   
-    out[i].ChiSqAve    	 = NAN;
-    out[i].ChiSqPM    	 = NAN;
-    out[i].ChiSqPar    	 = NAN;
-    out[i].Tmean    	 = 0;
-    out[i].Trange    	 = 0;
-    out[i].Npos       	 = 0.0;
-    out[i].extID 	 = 0;
-
-    // added in PS1_V3
-    out[i].photFlagsUpper = 0;
-    out[i].photFlagsLower = 0;
-
-    // added for PS1_V4 (Xp dropped in V4 onward, was not really used anyway)
-    out[i].psfQF         = NAN;
-    out[i].psfQFperf     = NAN;
-    out[i].stargal     	 = NAN;
   }
   return (out);
@@ -219,4 +180,6 @@
 
   for (i = 0; i < Nvalues; i++) {
+    dvo_secfilt_init (&out[i]);
+
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
@@ -224,25 +187,4 @@
     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;      
-
-    // changed or added for PS1_V2
-    out[i].flags = 0;
-
-    // added in PS1_V3
-    out[i].Map         = 0;
-    out[i].Mstdev      = 0;
-    out[i].ubercalDist = 0;
-
-    // added for PS1_V4
-    out[i].Mkron       = NAN;
-    out[i].dMkron      = NAN;
-    out[i].FluxPSF     = NAN;
-    out[i].dFluxPSF    = NAN;
-    out[i].FluxKron    = NAN;
-    out[i].dFluxKron   = NAN;
-    out[i].stackDetectID     = 0;
  }
   return (out);
Index: /branches/eam_branches/ipp-20120905/Ohana/src/opihi/dvo/avextract.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/opihi/dvo/avextract.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/opihi/dvo/avextract.c	(revision 34728)
@@ -325,4 +325,24 @@
     gprint (GP_ERR, "  <photcode>:nphot : number of measurements used for average magnitude in this photcode\n");
 
+    // gprint (GP_ERR, "  <photcode>:ap :  catalog aperture magnitude for photcode\n");
+    // gprint (GP_ERR, "  <photcode>:aper :  catalog aperture magnitude for photcode\n");
+    // gprint (GP_ERR, "  <photcode>:aveerr : average error (stdev)\n");
+    // gprint (GP_ERR, "  <photcode>:aperinst : aperture flux\n");
+    // gprint (GP_ERR, "  <photcode>:aper_inst : aperture flux\n");
+
+    gprint (GP_ERR, "  <photcode>:kron : kron flux\n");
+    // gprint (GP_ERR, "  <photcode>:kronerr : kron error\n");
+    gprint (GP_ERR, "  <photcode>:photflags : photometry flags for measurements\n");
+    gprint (GP_ERR, "  <photcode>:flags : photometry flags for measurements\n");
+    gprint (GP_ERR, "  <photcode>:stdev : standard deviation of measurements\n");
+    gprint (GP_ERR, "  <photcode>:20 : 20 percentile psf mag\n");
+    gprint (GP_ERR, "  <photcode>:80 : 80 percentile psf mag\n");
+    gprint (GP_ERR, "  <photcode>:ucdist : distance to ubercalibrated exposure (in exposure overlaps)\n");
+    gprint (GP_ERR, "  <photcode>:stackDetectID : PSPS ID for stack detection\n");
+    gprint (GP_ERR, "  <photcode>:fluxpsf : psf flux\n");
+    gprint (GP_ERR, "  <photcode>:fluxpsferr : psf flux error\n");
+    gprint (GP_ERR, "  <photcode>:fluxkron : kron flux\n");
+    gprint (GP_ERR, "  <photcode>:fluxkronerr : kron flux error\n");
+
     // gprint (GP_ERR, "  type : dophot type (unused)\n");
     // gprint (GP_ERR, "  typefrac : dophot type fraction (unused)\n");
Index: /branches/eam_branches/ipp-20120905/Ohana/src/opihi/dvo/mextract.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/opihi/dvo/mextract.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/opihi/dvo/mextract.c	(revision 34728)
@@ -313,7 +313,8 @@
     gprint (GP_ERR, "  Npos  : number of measurments used for astrometry\n");
 
-    gprint (GP_ERR, "  objflags  : object flags\n");
-    gprint (GP_ERR, "  photflags : detection flags from image analysis\n");
-    gprint (GP_ERR, "  dbflags : detection flags from database analysis\n");
+    gprint (GP_ERR, "  objflags  : object flags [alias: obj_flags]\n");
+    gprint (GP_ERR, "  secflags  : average photometry flags [aliases: obj_phot_flags, sec_flags, secfilt_flags]\n");
+    gprint (GP_ERR, "  photflags : detection flags from image analysis [alias: phot_flags]\n");
+    gprint (GP_ERR, "  dbflags : detection flags from database analysis [alias: db_flags]\n");
 
     gprint (GP_ERR, "  obj_flags : object flags\n");
@@ -321,4 +322,73 @@
     gprint (GP_ERR, "  db_flags : detection flags from database analysis\n");
 
+    gprint (GP_ERR, "  airmass : airmass of detection\n");
+    gprint (GP_ERR, "  meas_airmass : airmass of exposure\n");
+    gprint (GP_ERR, "  alt : altitude of detection\n");
+    gprint (GP_ERR, "  az  : azimuth of detection\n");
+    gprint (GP_ERR, "  exptime : exposure time [s]\n");
+    gprint (GP_ERR, "  photcode : photcode \n");
+    gprint (GP_ERR, "  photcode:equiv : equivalent average photcode \n");
+    gprint (GP_ERR, "  photcode:c : zero point of photcode \n");
+    gprint (GP_ERR, "  photcode:klam : airmass slope of photcode \n");
+    gprint (GP_ERR, "  time : time of exposure [Seconds since Jan 1, 1970/\n");
+    gprint (GP_ERR, "  fwhm : fwhm (average) of fitted PSF [pixels]\n");
+    gprint (GP_ERR, "  fwhm_maj : fwhm (major axis) of fitted PSF [pixels]\n");
+    gprint (GP_ERR, "  fwhm_min : fwhm (minor axis) of fitted PSF [pixels]\n");
+    gprint (GP_ERR, "  theta : position angle of fitted PSF\n");
+    gprint (GP_ERR, "  posangle : position angle of detector at measurement [degrees]\n");
+    gprint (GP_ERR, "  platescale : plate scale of detector at measurement [arcsec/pixel] (negative = sky parity)\n");
+
+    gprint (GP_ERR, "  Mxx : second moment in X [pixels^2]\n");
+    gprint (GP_ERR, "  Mxy : second moment cross term [pixels^2]\n");
+    gprint (GP_ERR, "  Myy : second moment in Y [pixels^2]\n");
+
+    gprint (GP_ERR, "  xccd : ccd x position\n");
+    gprint (GP_ERR, "  yccd : ccd y position\n");
+    gprint (GP_ERR, "  xoff : ccd x correction\n");
+    gprint (GP_ERR, "  yoff : ccd y correction\n");
+    gprint (GP_ERR, "  xccd:err : ccd x position error\n");
+    gprint (GP_ERR, "  yccd:err : ccd y position error\n");
+
+    gprint (GP_ERR, "  pos_sys_err : systematic position error\n");
+
+    gprint (GP_ERR, "  xmosaic : mosaic x position\n");
+    gprint (GP_ERR, "  ymosaic : mosaic y position\n");
+
+    gprint (GP_ERR, "  xchip : chip x position (= ccd position)\n");
+    gprint (GP_ERR, "  ychip : chip y position (= ccd position)\n");
+    gprint (GP_ERR, "  xfpa : fpa x position (= mosaic position)\n");
+    gprint (GP_ERR, "  yfpa : fpa y position (= mosaic position)\n");
+
+    gprint (GP_ERR, "  detID : ID of detection (unique on source image)\n");
+    gprint (GP_ERR, "  objID : object ID (32 bit, unique in catalog)\n");
+    gprint (GP_ERR, "  catID : catalog ID (32 bit)\n");
+    gprint (GP_ERR, "  imageID : ID of source image (32 bit)\n");
+    gprint (GP_ERR, "  externID : externID of source image (32 bit)\n");
+
+    gprint (GP_ERR, "  psf_qf : PSF quality factor (psf-weighted mask fraction)\n");
+    gprint (GP_ERR, "  psf_qf_perfect : PSF quality factor, perfect mask version (psf-weighted mask fraction)\n");
+
+    gprint (GP_ERR, "  psf_chisq : PSF fit chi square\n");
+    gprint (GP_ERR, "  psf_ndof : PSF number of degrees of freedom\n");
+    gprint (GP_ERR, "  psf_npix : PSF number of pixels\n");
+
+    gprint (GP_ERR, "  cr_nsigma : Nsigma deviation towards cosmic ray\n");
+    gprint (GP_ERR, "  ext_nsigma : Nsigma deviation towards extended source\n");
+
+    gprint (GP_ERR, "  sky : sky model flux at measurement location\n");
+    gprint (GP_ERR, "  sky_err : sky model stdev at measurement location\n");
+
+    gprint (GP_ERR, "  Mcal_offset : difference wrt nominal zero point (clouds are positive)\n");
+    gprint (GP_ERR, "  flat : flat-field correction (measure.Mcal - image.Mcal)\n");
+
+    gprint (GP_ERR, "  center_offset : distance to image center\n");
+    gprint (GP_ERR, "  flux : PSF flux\n");
+    gprint (GP_ERR, "  flux_err : PSF flux error\n");
+    gprint (GP_ERR, "  flux_psf : PSF flux\n");
+    gprint (GP_ERR, "  flux_psf_err : PSF flux error\n");
+    gprint (GP_ERR, "  flux_kron : KRON flux\n");
+    gprint (GP_ERR, "  flux_kron_err : KRON flux error\n");
+
+    gprint (GP_ERR, "  --- the following fields are selected by giving a photcode with the attached ending\n");
     gprint (GP_ERR, "  <photcode>:ave : average magnitude for photcode (or equivalent)\n");
     gprint (GP_ERR, "  <photcode>:ref : reference magnitude system for photcode (or equivalent)\n");
@@ -335,49 +405,19 @@
     gprint (GP_ERR, "  <photcode>:ncode : number of measurements in photcode\n");
     gprint (GP_ERR, "  <photcode>:nphot : number of measurements used for average magnitude\n");
-    gprint (GP_ERR, "  airmass : airmass of detection\n");
-    gprint (GP_ERR, "  alt : altitude of detection\n");
-    gprint (GP_ERR, "  az  : azimuth of detection\n");
-    gprint (GP_ERR, "  exptime : exposure time [s]\n");
-    gprint (GP_ERR, "  photcode : photcode \n");
-    gprint (GP_ERR, "  photcode:equiv : equivalent average photcode \n");
-    gprint (GP_ERR, "  time : time of exposure [Seconds since Jan 1, 1970/\n");
-    gprint (GP_ERR, "  fwhm : fwhm (average) of fitted PSF [pixels]\n");
-    gprint (GP_ERR, "  fwhm_maj : fwhm (major axis) of fitted PSF [pixels]\n");
-    gprint (GP_ERR, "  fwhm_min : fwhm (minor axis) of fitted PSF [pixels]\n");
-    gprint (GP_ERR, "  theta : position angle of fitted PSF\n");
-    gprint (GP_ERR, "  posangle : position angle of detector at measurement [degrees]\n");
-    gprint (GP_ERR, "  platescale : plate scale of detector at measurement [arcsec/pixel] \n");
-
-    gprint (GP_ERR, "  psf_qf : PSF quality factor (psf-weighted mask fraction)\n");
-    gprint (GP_ERR, "  psf_chisq : PSF fit chi square\n");
-    gprint (GP_ERR, "  psf_ndof : PSF number of degrees of freedom\n");
-    gprint (GP_ERR, "  psf_npix : PSF number of pixels\n");
-
-    gprint (GP_ERR, "  cr_nsigma : Nsigma deviation towards cosmic ray\n");
-    gprint (GP_ERR, "  ext_nsigma : Nsigma deviation towards extended source\n");
-
-    gprint (GP_ERR, "  Mxx : second moment in X [pixels^2]\n");
-    gprint (GP_ERR, "  Mxy : second moment cross term [pixels^2]\n");
-    gprint (GP_ERR, "  Myy : second moment in Y [pixels^2]\n");
-
-    gprint (GP_ERR, "  xccd : ccd x position\n");
-    gprint (GP_ERR, "  yccd : ccd y position\n");
-    gprint (GP_ERR, "  xccd:err : ccd x position error\n");
-    gprint (GP_ERR, "  yccd:err : ccd y position error\n");
-    gprint (GP_ERR, "  xmosaic : mosaic x position\n");
-    gprint (GP_ERR, "  ymosaic : mosaic y position\n");
-    gprint (GP_ERR, "  xchip : chip x position (= ccd position)\n");
-    gprint (GP_ERR, "  ychip : chip y position (= ccd position)\n");
-    gprint (GP_ERR, "  xfpa : fpa x position (= mosaic position)\n");
-    gprint (GP_ERR, "  yfpa : fpa y position (= mosaic position)\n");
-
-    gprint (GP_ERR, "  detID : ID of detection (unique on source image)\n");
-    gprint (GP_ERR, "  objID : object ID (32 bit, unique in catalog)\n");
-    gprint (GP_ERR, "  catID : catalog ID (32 bit)\n");
-    gprint (GP_ERR, "  imageID : ID of source image (32 bit)\n");
-    gprint (GP_ERR, "  externID : externID of source image (32 bit)\n");
-
-    gprint (GP_ERR, "  Mcal_offset : difference wrt nominal zero point (clouds are positive)\n");
-    gprint (GP_ERR, "  flat : flat-field correction (measure.Mcal - image.Mcal)\n");
+
+    gprint (GP_ERR, "  <photcode>:aperinst : instrumental aperture magnitude\n");
+    gprint (GP_ERR, "  <photcode>:aper_inst : instrumental aperture magnitude\n");
+    gprint (GP_ERR, "  <photcode>:kron : kron mag\n");
+    gprint (GP_ERR, "  <photcode>:kroninst : instrumental kron mag\n");
+    gprint (GP_ERR, "  <photcode>:kron_inst : instrumental kron mag\n");
+    gprint (GP_ERR, "  <photcode>:kronerr : kron mag error\n");
+
+    gprint (GP_ERR, "  <photcode>:photflags : photometry flags for measurements\n");
+    gprint (GP_ERR, "  <photcode>:flags : photometry flags for measurements\n");
+    gprint (GP_ERR, "  <photcode>:fluxpsf : average psf flux\n");
+    gprint (GP_ERR, "  <photcode>:fluxpsferr : average psf flux error\n");
+    gprint (GP_ERR, "  <photcode>:fluxkron : average kron flux\n");
+    gprint (GP_ERR, "  <photcode>:fluxkronerr : average kron flux error\n");
+
     return (FALSE);
   }
Index: /branches/eam_branches/ipp-20120905/Ohana/src/relphot/src/ConfigInit.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/relphot/src/ConfigInit.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/relphot/src/ConfigInit.c	(revision 34728)
@@ -45,5 +45,5 @@
   ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
 
-  sprintf (ImageCat, DVO_MAX_PATH, "%s/Images.dat", CATDIR);
+  snprintf (ImageCat, DVO_MAX_PATH, "%s/Images.dat", CATDIR);
 
   if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
Index: /branches/eam_branches/ipp-20120905/Ohana/src/relphot/src/StarOps.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/relphot/src/StarOps.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/relphot/src/StarOps.c	(revision 34728)
@@ -356,6 +356,4 @@
 
   for (j = 0; j < catalog[Nc].Naverage; j++) {
-    // XXX accumulate all secfilt values in a single pass?
-
     // option for a test print
     if (FALSE && (catalog[Nc].average[j].objID == 0x7146) && (catalog[Nc].average[j].catID == 0x49d8)) {
@@ -376,4 +374,9 @@
 
     int Nmeas = 0; // number of meas used for psfqf, psfqfperf, and stargal
+
+    int NstackGood = 0;
+    int NstackSuspect = 0;
+
+    int haveStackObject = FALSE;
 
     int Ns;
@@ -401,9 +404,7 @@
 
       float stackCenterOffsetMin = 1e9;
-      // int stackCenterIDmin = -1;
       off_t stackCenterMeasureMin = -1;
 
       float stackPrimaryOffsetMin = 1e9;
-      // int stackPrimaryIDmin = -1;
       off_t stackPrimaryMeasureMin = -1;
 
@@ -415,4 +416,7 @@
       int minUbercalDist = 1000;
     
+      int isBad = FALSE;
+      int isSuspect = FALSE;
+
       N = 0;
       m = catalog[Nc].averageT[j].measureOffset;
@@ -447,23 +451,8 @@
 	if (isnan(Msys)) SKIP_THIS_MEAS(Nsys);
 
-	list[N] = Msys - Mcal - Mmos - Mgrid;
-
 	int myUbercalDist = getUbercalDist(m,Nc);
 	minUbercalDist = MIN(minUbercalDist, myUbercalDist);
 
 	if (isSetMrelFinal) {
-	  // Map (aplist) and Mkron (kronlist,dkronlist) are used to calculate mean mags per filter
-	  float Map = PhotAper (&catalog[Nc].measure[m]);
-	  aplist[N] = Map - Mcal - Mmos - Mgrid;
-
-	  float Mkron = PhotKron (&catalog[Nc].measure[m]);
-	  kronlist[N] = Mkron - Mcal - Mmos - Mgrid;
-	  dkronlist[N] = catalog[Nc].measure[m].dMkron;
-
-	  // mean psfQF, psfQFperf, and stargal values are calculated per object (all filters)
-	  psfqf_list[Nmeas]     = catalog[Nc].measure[m].psfQF;
-	  psfqfperf_list[Nmeas] = catalog[Nc].measure[m].psfQF;
-	  stargal_list[Nmeas]   = catalog[Nc].measure[m].extNsigma;
-
 	  // special options for PS1 data
 	  if ((catalog[Nc].measure[m].photcode >= 10000) && (catalog[Nc].measure[m].photcode <= 10500)) {
@@ -484,8 +473,9 @@
 	    havePS1 = TRUE;
 	  }
+
 	  // gpc1 stack data
 	  if ((catalog[Nc].measure[m].photcode >= 11000) && (catalog[Nc].measure[m].photcode <= 11400)) {
-	    // if (pass < 2) continue;
 	    haveStack = TRUE;
+	    haveStackObject = TRUE;
 
 	    unsigned int stackImageID;
@@ -509,4 +499,21 @@
 	      stackCenterMeasureMin = m;
 	    }
+
+	    // data quality assessment
+	    isBad |= (catalog[Nc].measure[m].photFlags & code->photomBadMask);
+	    isBad |= (catalog[Nc].measure[m].psfQF < 0.85);
+	    isBad |= isnan(catalog[Nc].measure[m].psfQF);
+	    isBad |= catalog[Nc].measure[m].dM > 0.2; // S/N < 5.0
+
+	    isSuspect |= (catalog[Nc].measure[m].photFlags & code->photomPoorMask);
+	    isSuspect |= (catalog[Nc].measure[m].psfQFperf < 0.85);
+
+	    // mean psfQF, psfQFperf, and stargal values are calculated per object (all filters, stacks and exposures)
+	    psfqf_list[Nmeas]     = catalog[Nc].measure[m].psfQF;
+	    psfqfperf_list[Nmeas] = catalog[Nc].measure[m].psfQFperf;
+	    stargal_list[Nmeas]   = catalog[Nc].measure[m].extNsigma;
+	    Nmeas++;
+
+	    continue; // do not include stack measurements in the per-exposure statistics
 	  }
 
@@ -523,5 +530,4 @@
 		// detections without one of these bits should only be used in PASS_1
 		SKIP_THIS_MEAS(Nbad);
-		continue;
 	      }
 	    }
@@ -557,9 +563,22 @@
 	      if (pass < 4) {
 		SKIP_THIS_MEAS(Nbad);
-		continue;
 	      }
 	      haveSynth = TRUE;
 	    }
 	  }
+
+	  // Map (aplist) and Mkron (kronlist,dkronlist) are used to calculate mean mags per filter
+	  float Map = PhotAper (&catalog[Nc].measure[m]);
+	  aplist[N] = Map - Mcal - Mmos - Mgrid;
+
+	  float Mkron = PhotKron (&catalog[Nc].measure[m]);
+	  kronlist[N] = Mkron - Mcal - Mmos - Mgrid;
+	  dkronlist[N] = catalog[Nc].measure[m].dMkron;
+
+	  // mean psfQF, psfQFperf, and stargal values are calculated per object (all filters, stacks and exposures)
+	  psfqf_list[Nmeas]     = catalog[Nc].measure[m].psfQF;
+	  psfqfperf_list[Nmeas] = catalog[Nc].measure[m].psfQFperf;
+	  stargal_list[Nmeas]   = catalog[Nc].measure[m].extNsigma;
+	  Nmeas++;
 	}
 
@@ -572,4 +591,5 @@
 	dlist[N] = MAX (hypot(catalog[Nc].measureT[m].dM, code->photomErrSys), MIN_ERROR);
 	wlist[N] = 1.0;
+	list[N]  = Msys - Mcal - Mmos - Mgrid;
 
 	// up-weight the ubercal values (or convergence can take a long time...)
@@ -588,5 +608,4 @@
 	}
 	N++;
-	Nmeas++;
       }
 
@@ -595,4 +614,13 @@
       if (haveStack && (N > 1)) {
 	// fprintf (stderr, "multiple stack values for %10.6f %10.6f\n", catalog[Nc].averageT[j].R, catalog[Nc].averageT[j].D);
+      }
+
+      if (haveStack) {
+	if (!isSuspect && !isBad) {
+	  NstackGood ++;
+	}
+	if (isSuspect && !isBad) {
+	  NstackSuspect ++;
+	}
       }
 
@@ -765,4 +793,12 @@
       }
 
+      if (NstackGood >= 2) {
+	catalog[Nc].average[j].flags |= ID_OBJ_GOOD_STACK;
+      } else if (NstackGood + NstackSuspect >= 2) {
+	catalog[Nc].average[j].flags |= ID_OBJ_SUSPECT_STACK;
+      } else if (haveStackObject) {
+	catalog[Nc].average[j].flags |= ID_OBJ_BAD_STACK;
+      }
+
       // use NAN values for catalog[Nc].average[j].psfQF as signal
       if (!isfinite(catalog[Nc].average[j].psfQF)) {
Index: /branches/eam_branches/ipp-20120905/Ohana/src/relphot/src/setMrelFinal.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/relphot/src/setMrelFinal.c	(revision 34727)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/relphot/src/setMrelFinal.c	(revision 34728)
@@ -40,15 +40,5 @@
       for (i = 0; i < catalog[0].Naverage; i++) {
 	off_t N = Nsecfilt*i+Nsec;
-	catalog[0].secfilt[N].M      = NAN;
-	catalog[0].secfilt[N].Map    = NAN;
-	catalog[0].secfilt[N].dM     = NAN;
-	catalog[0].secfilt[N].Mstdev = NAN_S_SHORT;
-	catalog[0].secfilt[N].Xm     = NAN;
-	catalog[0].secfilt[N].M_20   = NAN_S_SHORT;
-	catalog[0].secfilt[N].M_80   = NAN_S_SHORT;
-	catalog[0].secfilt[N].Ncode  = 0;
-	catalog[0].secfilt[N].Nused  = 0;
-	catalog[0].secfilt[N].flags  = 0; // XXX there are no *astrometry* bits in secfilt.flags
-	catalog[0].secfilt[N].ubercalDist = 1000;
+	dvo_secfilt_init (&catalog[0].secfilt[N]);
 
 	off_t m = catalog[0].average[i].measureOffset;
@@ -247,5 +237,5 @@
 	}
 	
-	// PASS 2 : accept stack measurements
+	// PASS 2 : (no additional cut)
 
 	// PASS 1 : accept poor measurements as well (eg, POOR FIT, etc)
