Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 38546)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 38547)
@@ -874,4 +874,5 @@
   Catalog *catalog = addstar_catalog_init (Nstars);
   ALLOCATE (catalog->lensing, Lensing, Nstars);
+  catalog->Nlensing = Nstars;
 
   for (i = 0; i < Nstars; i++) {
@@ -997,4 +998,5 @@
   Catalog *catalog = addstar_catalog_init (Nstars);
   ALLOCATE (catalog->lensing, Lensing, Nstars);
+  catalog->Nlensing = Nstars;
 
   for (i = 0; i < Nstars; i++) {
@@ -1111,5 +1113,28 @@
   CMF_PS1_V5_R2_Lensing *ps1data;
 
-  ps1data = gfits_table_get_CMF_PS1_V5_R2_Lensing (table, &Nstars, NULL);
+  // this code expects the output cmf files to have a fixed column order
+  // unfortunatly, psphot is not consistent for the obj lensing values:
+  // if the first object in the list is not a valid object for the lensing measurement, then
+  // the lensingOBJ structure is not allocated for that source and the corresponding rows
+  // are not added to the output metadata until an object which does include the
+  // measurement.
+
+  char field[128];
+  gfits_scan (table->header, "TTYPE45", "%s", 1, field);
+
+  int mode = 0;
+  if (!strcmp (field, "LENS_X11_SM_OBJ")) { mode = 1; }
+  if (!strcmp (field, "LENS_X11_SM_PSF")) { mode = 2; }
+  myAssert (mode, "invalid table layout\n");
+
+  if (mode == 1) {
+    ps1data = gfits_table_get_CMF_PS1_V5_R2_Lensing (table, &Nstars, NULL);
+    fprintf (stderr, "PS1_V5_R2_Lensing mode 1\n");
+  } 
+  if (mode == 2) {
+    ps1data = gfits_table_get_CMF_PS1_V5_R2x_Lensing (table, &Nstars, NULL);
+    fprintf (stderr, "PS1_V5_R2_Lensing mode 2\n");
+  } 
+
   if (!ps1data) {
     fprintf (stderr, "skipping inconsistent entry\n");
@@ -1120,4 +1145,5 @@
   Catalog *catalog = addstar_catalog_init (Nstars);
   ALLOCATE (catalog->lensing, Lensing, Nstars);
+  catalog->Nlensing = Nstars;
 
   for (i = 0; i < Nstars; i++) {
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/loadgalphot_readstars.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/loadgalphot_readstars.c	(revision 38546)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/loadgalphot_readstars.c	(revision 38547)
@@ -375,5 +375,5 @@
   // use bilinear interpolation to choose Flux @ (Xmin,Ymin)?
   galphot->mag    = -2.5*log10(flux[iMin]); // correct for exptime?
-  galphot->magErr = fluxErr[iMin] / flux[iMin];
+  galphot->magErr = sqrt(fluxErr[iMin]) / flux[iMin];
   galphot->chisq  = chisqMin;
   
