Index: /branches/eam_branches/ipp-20150405/Ohana/src/dvolens/src/update_objects_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20150405/Ohana/src/dvolens/src/update_objects_catalog.c	(revision 38139)
+++ /branches/eam_branches/ipp-20150405/Ohana/src/dvolens/src/update_objects_catalog.c	(revision 38140)
@@ -51,4 +51,12 @@
       if (!isfinite(lensing->X11_sm_obj)) continue;
 
+      // pointer from lensing entry to corresponding measure entry (keep updated?)
+      int Mseq = lensing->measureSeq;
+      myAssert (Mseq < average->Nmeasure, "oops");
+
+      Measure *measure = &catalog->measure[Moff + Mseq];
+      myAssert (measure->imageID == lensing->imageID, "oops, deux");
+
+# if (0)      
       Measure *measure = NULL;
       int found = FALSE;
@@ -64,4 +72,5 @@
 	abort();
       }
+# endif
       
       // skip measurements that do not match the current photcode
@@ -77,4 +86,8 @@
       if (measure->psfQFperf < 0.85) continue; 
       
+      // I should probably only use lensing entries which correspond to warps 
+      // included in the mean warp flux (setMrelCatalog.c)
+      if (measure->dbFlags & ID_MEAS_WARP_USED == 0) continue;
+
       Mxx_obj[Nsec] += measure->Mxx;
       Mxy_obj[Nsec] += measure->Mxy;
@@ -105,18 +118,32 @@
       lensobj[Nsec]. E2_sh_psf += lensing-> E2_sh_psf;
 
-      lensobj[Nsec]. F_ApR5 += lensing-> F_ApR5;
-      lensobj[Nsec].dF_ApR5 += SQ(lensing->dF_ApR5);
-      lensobj[Nsec].sF_ApR5 += SQ(lensing->sF_ApR5);
-      lensobj[Nsec].fF_ApR5 += lensing->fF_ApR5;
-
-      lensobj[Nsec]. F_ApR6 += lensing-> F_ApR6;
-      lensobj[Nsec].dF_ApR6 += SQ(lensing->dF_ApR6);
-      lensobj[Nsec].sF_ApR6 += SQ(lensing->sF_ApR6);
-      lensobj[Nsec].fF_ApR6 += lensing->fF_ApR6;
-
-      lensobj[Nsec]. F_ApR7 += lensing-> F_ApR7;
-      lensobj[Nsec].dF_ApR7 += SQ(lensing->dF_ApR7);
-      lensobj[Nsec].sF_ApR7 += SQ(lensing->sF_ApR7);
-      lensobj[Nsec].fF_ApR7 += lensing->fF_ApR7;
+      myAbort ("NOTE: relphot needs to set measure->Mcal -- is this happening or not??");
+
+      int Np = photcodes[0].hashcode[measure[0].photcode];
+      if (Np == -1) return (NAN);
+      PhotCode *code = &photcodes[0].code[Np];
+      
+      float Mdef = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
+      float Moff = Mdef + 8.9 - measure->Mcal;
+      float Foff = 3630.8 * MagToFlux(Moff);
+
+      // lensing->F_ApR5, etc need to be in units of DN/sec
+      // Foff * lensing->F_ApR5 is in Jy
+      // XXX this is unweighted -- apply a weighting?
+
+      lensobj[Nsec]. F_ApR5 += Foff * lensing-> F_ApR5;
+      lensobj[Nsec].dF_ApR5 += SQ(Foff * lensing->dF_ApR5);
+      lensobj[Nsec].sF_ApR5 += SQ(Foff * lensing->sF_ApR5);
+      lensobj[Nsec].fF_ApR5 += Foff * lensing->fF_ApR5;
+
+      lensobj[Nsec]. F_ApR6 += Foff * lensing-> F_ApR6;
+      lensobj[Nsec].dF_ApR6 += SQ(Foff * lensing->dF_ApR6);
+      lensobj[Nsec].sF_ApR6 += SQ(Foff * lensing->sF_ApR6);
+      lensobj[Nsec].fF_ApR6 += Foff * lensing->fF_ApR6;
+
+      lensobj[Nsec]. F_ApR7 += Foff * lensing-> F_ApR7;
+      lensobj[Nsec].dF_ApR7 += SQ(Foff * lensing->dF_ApR7);
+      lensobj[Nsec].sF_ApR7 += SQ(Foff * lensing->sF_ApR7);
+      lensobj[Nsec].fF_ApR7 += Foff * lensing->fF_ApR7;
 
       lensobj[Nsec].Nmeas   ++;
