Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/LoadPhotcodesText.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/LoadPhotcodesText.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/LoadPhotcodesText.c	(revision 36975)
@@ -142,8 +142,8 @@
     photcode[Ncode].photomErrSys      = atof (photomErrSys);
 
-    photcode[Ncode].astromPoorMask    = strtol (astromPoorMask, NULL, 0);
-    photcode[Ncode].astromBadMask     = strtol (astromBadMask, NULL, 0);
-    photcode[Ncode].photomPoorMask    = strtol (photomPoorMask, NULL, 0);
-    photcode[Ncode].photomBadMask     = strtol (photomBadMask, NULL, 0);
+    photcode[Ncode].astromPoorMask    = strtoll (astromPoorMask, NULL, 0);
+    photcode[Ncode].astromBadMask     = strtoll (astromBadMask, NULL, 0);
+    photcode[Ncode].photomPoorMask    = strtoll (photomPoorMask, NULL, 0);
+    photcode[Ncode].photomBadMask     = strtoll (photomBadMask, NULL, 0);
 
     switch (photcode[Ncode].type) {
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_catalog.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_catalog.c	(revision 36975)
@@ -174,5 +174,5 @@
   secfilt->Mmin        = NAN;
   secfilt->Mmax        = NAN;
-  secfilt->Xm          = NAN;
+  secfilt->Mchisq      = NAN;
 
   secfilt->Ncode       = 0;
@@ -770,12 +770,12 @@
     for (in = out = i = 0; i < catalog[0].Naverage; i++) {
       for (j = 0; j < catalog[0].Nsecfilt; j++, in++, out++) {
-	outsec[out].M  = insec[in].M;
-	outsec[out].dM = insec[in].dM;
-	outsec[out].Xm = insec[in].Xm;
+	outsec[out].M  	   = insec[in].M;
+	outsec[out].dM 	   = insec[in].dM;
+	outsec[out].Mchisq = insec[in].Mchisq;
       }
       for (j = 0; j < Nextra; j++, out++) {
-	outsec[out].M  = NAN;
-	outsec[out].dM = NAN;
-	outsec[out].Xm = NAN_S_SHORT;
+	outsec[out].M  	   = NAN;
+	outsec[out].dM 	   = NAN;
+	outsec[out].Mchisq = NAN;
       }
     }
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 36975)
@@ -184,5 +184,5 @@
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = in[i].Xm;     
+    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
@@ -201,5 +201,5 @@
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = in[i].Xm;     
+    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 36975)
@@ -179,5 +179,5 @@
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = in[i].Xm;     
+    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
@@ -196,5 +196,5 @@
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = in[i].Xm;     
+    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 36975)
@@ -199,5 +199,5 @@
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = in[i].Xm;     
+    out[i].Mchisq= in[i].Mchisq;     
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
@@ -218,5 +218,5 @@
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = in[i].Xm;     
+    out[i].Mchisq= in[i].Mchisq;     
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c	(revision 36975)
@@ -208,5 +208,5 @@
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = in[i].Xm;     
+    out[i].Mchisq= in[i].Mchisq;     
     out[i].flags = in[i].flags;     
     out[i].Ncode = in[i].Ncode;
@@ -228,5 +228,5 @@
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = in[i].Xm;     
+    out[i].Mchisq= in[i].Mchisq;     
     out[i].flags = in[i].flags;     
     out[i].Ncode = in[i].Ncode;
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c	(revision 36975)
@@ -213,5 +213,5 @@
     out[i].Map         = in[i].Map;      
     out[i].dM          = in[i].dM;      
-    out[i].Xm          = in[i].Xm;     
+    out[i].Mchisq      = in[i].Mchisq;     
     out[i].flags       = in[i].flags;     
     out[i].Ncode       = in[i].Ncode;
@@ -236,5 +236,5 @@
     out[i].Map         = in[i].Map;      
     out[i].dM          = in[i].dM;      
-    out[i].Xm          = in[i].Xm;     
+    out[i].Mchisq      = in[i].Mchisq;     
     out[i].flags       = in[i].flags;     
     out[i].Ncode       = in[i].Ncode;
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c	(revision 36975)
@@ -239,5 +239,5 @@
     out[i].dMkron        = in[i].dMkron;      
     out[i].dM            = in[i].dM;      
-    out[i].Xm            = in[i].Xm;     
+    out[i].Mchisq        = in[i].Mchisq;     
     out[i].FpsfStk       = in[i].FluxPSF;
     out[i].dFpsfStk      = in[i].dFluxPSF;
@@ -269,5 +269,5 @@
     out[i].dMkron      	 = in[i].dMkron;      
     out[i].dM          	 = in[i].dM;      
-    out[i].Xm          	 = in[i].Xm;     
+    out[i].Mchisq        = in[i].Mchisq;
     out[i].FluxPSF     	 = in[i].FpsfStk;
     out[i].dFluxPSF    	 = in[i].dFpsfStk;
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c	(revision 36975)
@@ -292,5 +292,5 @@
     out[i].Mmin          = in[i].Mmin;      
     out[i].Mmax          = in[i].Mmax;      
-    out[i].Xm            = in[i].Xm;     
+    out[i].Mchisq        = in[i].Mchisq;     
 
     out[i].Ncode         = in[i].Ncode;
@@ -360,5 +360,5 @@
     out[i].Mmin          = in[i].Mmin;      
     out[i].Mmax          = in[i].Mmax;      
-    out[i].Xm            = in[i].Xm;     
+    out[i].Mchisq        = in[i].Mchisq;     
 
     out[i].Ncode         = in[i].Ncode;
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_elixir.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 36975)
@@ -111,5 +111,5 @@
     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].Mchisq= pow (10.0, 0.01*in[i].Xm);     
 
     // added for PANSTARRS_DEV_0
@@ -144,5 +144,5 @@
     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;     
+    out[i].Xm      = 100.0*log10(primary[i].Mchisq);     
 
     // changed or added for PS1_DEV_2
@@ -169,5 +169,5 @@
     dvo_secfilt_init (&out[i]);
 
-    out[i].Xm    = in[i].Xm;     
+    out[i].Mchisq = pow (10.0, 0.01*in[i].Xm);     
 
     // added or changed for PANSTARRS_DEV_0
@@ -187,5 +187,5 @@
 
   for (i = 0; i < Nvalues; i++) {
-    out[i].Xm    = in[i].Xm;     
+    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
 
     // added or changed for PANSTARRS_DEV_0
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_loneos.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 36975)
@@ -90,5 +90,5 @@
     // 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].Mchisq= pow (10.0, 0.01*in[i].Xm);     
 
     // added for PANSTARRS_DEV_0
@@ -124,5 +124,5 @@
     // 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;     
+    out[i].Xm      = 100.0*log10(primary[i].Mchisq);     
 
     // changed or added for PS1_DEV_2
@@ -149,5 +149,5 @@
     dvo_secfilt_init (&out[i]);
 
-    out[i].Xm    = in[i].Xm;      
+    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
 
     // added or changed for PANSTARRS_DEV_0
@@ -166,5 +166,5 @@
 
   for (i = 0; i < Nvalues; i++) {
-    out[i].Xm   = in[i].Xm;      
+    out[i].Xm   = 100.0*log10(in[i].Mchisq);      
 
     // added or changed for PANSTARRS_DEV_0
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 36975)
@@ -188,5 +188,5 @@
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = in[i].Xm;     
+    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
@@ -206,5 +206,5 @@
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = in[i].Xm;     
+    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 36975)
@@ -188,5 +188,5 @@
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = in[i].Xm;     
+    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
@@ -206,5 +206,5 @@
     out[i].M     = in[i].M;      
     out[i].dM    = in[i].dM;      
-    out[i].Xm    = in[i].Xm;     
+    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
     out[i].Ncode = in[i].Ncode;
     out[i].Nused = in[i].Nused;
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_photcode_ops.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_photcode_ops.c	(revision 36974)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_photcode_ops.c	(revision 36975)
@@ -795,9 +795,8 @@
 }
 
-// XXX return NAN or NAN_S_SHORT? (secfilt->Xm is short)
+// Xm is now (2014.07.03) stored as the chisq except in dvo formats which use as short
 float PhotXm (PhotCode *code, Average *average, SecFilt *secfilt) {
 
   int Ns;
-  short Mi;
   float Xm;
 
@@ -805,6 +804,5 @@
 
   Ns = photcodes[0].hashNsec[code[0].code];
-  Mi = (Ns == -1) ? NAN : secfilt[Ns].Xm;
-  Xm = (isnan(Mi)) ? -1.0 : pow (10.0, 0.01*Mi);
+  Xm = (Ns == -1) ? NAN : secfilt[Ns].Mchisq;
   return (Xm);
 }
@@ -889,8 +887,29 @@
   PhotCode *code = &photcodes[0].code[Np];
 
+  // mag_AB = -2.5 log (flux_cgs) - 48.6 (by definition) [~Vega flux in V-band]
+  // flux_Jy = flux_cgs * 10^23
+  // -2.5 log (flux_cgs) = -2.5 log (flux_Jy * 10^-23) = -2.5 log (flux_Jy) + 2.5*23
+
+  // from these we get:
+  // mag_AB = -2.5 log (flux_Jy) + 8.9
+  // log (flux_Jy) = -0.4*mag_AB + 3.56
+
+  // mag_AB = mag_inst + ZP
+
+  // log(flux_Jy) = -0.4*mag_inst -0.4*ZP + 3.56
+  // mag_inst = -2.5 log (flux_Jy) - ZP + 8.9
+
+  // log (flux_Jy) = -0.4*(mag_inst + ZP - 8.9)
+
+  // -2.5 log (flux_inst) = -2.5 log (flux_Jy) - ZP + 8.9
+  // log (flux_inst) = log (flux_Jy) + 0.4 ZP - 3.56
+  // flux_inst = flux_Jy * 10^(0.4*ZP - 3.56)
+  // flux_Jy = flux_inst * 10^(3.56 - 0.4*ZP) = flux_inst * zpFactor
+  // flux_Jy = flux_inst * 3630.8 * 10^(-0.4*ZP)
+
   // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
   float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
-  float Moff = Mcal - ZERO_POINT;
-  float Foff = MagToFlux(Mcal);
+  float Moff = Mcal - ZERO_POINT + 8.9;
+  float Foff = 3630.8 * MagToFlux(Mcal);
   float Fcat = NAN;
   switch (class) {
@@ -919,6 +938,6 @@
   // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
   float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
-  float Moff = Mcal - ZERO_POINT;
-  float Foff = MagToFlux(Mcal);
+  float Moff = Mcal - ZERO_POINT + 8.9;
+  float Foff = 3630.8 * MagToFlux(Mcal);
   float Fcat = NAN;
   switch (class) {
@@ -964,6 +983,6 @@
   // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
   float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
-  float Moff = Mcal - ZERO_POINT;
-  float Foff = MagToFlux(Mcal);
+  float Moff = Mcal - ZERO_POINT + 8.9;
+  float Foff = 3630.8 * MagToFlux(Mcal);
   float Fcat = NAN;
   switch (class) {
@@ -1168,6 +1187,6 @@
   // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
   float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
-  float Moff = Mcal - ZERO_POINT;
-  float Foff = MagToFlux(Mcal);
+  float Moff = Mcal - ZERO_POINT + 8.9;
+  float Foff = 3630.8 * MagToFlux(Mcal);
 
   // use dFlux if we can, but use dMag if we must:
@@ -1544,9 +1563,8 @@
 }
 
-// XXX return NAN or NAN_S_SHORT? (secfilt->Xm is short)
+// Xm is now (2014.07.03) stored as the chisq except in dvo formats which use as short
 float PhotXmTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt) {
 
   int Ns;
-  short Mi;
   float Xm;
 
@@ -1554,6 +1572,5 @@
 
   Ns = photcodes[0].hashNsec[code[0].code];
-  Mi = (Ns == -1) ? NAN : secfilt[Ns].Xm;
-  Xm = (isnan(Mi)) ? -1.0 : pow (10.0, 0.01*Mi);
+  Xm = (Ns == -1) ? NAN : secfilt[Ns].Mchisq;
   return (Xm);
 }
