Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/args.c	(revision 38432)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/args.c	(revision 38433)
@@ -375,11 +375,11 @@
   }
 
-  // if -synthphot_zpts is supplied, the map of corrections needed for the synthetic photometry is supplied
+  // if -synthphot-zpts is supplied, the map of corrections needed for the synthetic photometry is supplied
   // and used to tie down the synthetic magnitudes
-  // NOTE: SYNTH_ZERO_POINTS is used for the same file in both -synthphot_zpts and -synthphot_means
+  // NOTE: SYNTH_ZERO_POINTS is used for the same file in both -synthphot-zpts and -synthphot_means
   SYNTH_ZERO_POINTS = NULL;
-  if ((N = get_argument (argc, argv, "-synthphot_zpts"))) {
-    remove_argument (N, &argc, argv);
-    myAssert (N < argc, "missing argument to -synthphot_zpts");
+  if ((N = get_argument (argc, argv, "-synthphot-zpts"))) {
+    remove_argument (N, &argc, argv);
+    myAssert (N < argc, "missing argument to -synthphot-zpts");
     SYNTH_ZERO_POINTS = strcreate (argv[N]);
     remove_argument (N, &argc, argv);
@@ -495,7 +495,7 @@
   }
   SYNTH_ZERO_POINTS = NULL;
-  if ((N = get_argument (argc, argv, "-synthphot_zpts"))) {
-    remove_argument (N, &argc, argv);
-    myAssert (N < argc, "missing argument to -synthphot_zpts");
+  if ((N = get_argument (argc, argv, "-synthphot-zpts"))) {
+    remove_argument (N, &argc, argv);
+    myAssert (N < argc, "missing argument to -synthphot-zpts");
     SYNTH_ZERO_POINTS = strcreate (argv[N]);
     remove_argument (N, &argc, argv);
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/reload_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/reload_catalogs.c	(revision 38432)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/reload_catalogs.c	(revision 38433)
@@ -65,6 +65,7 @@
 
     if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
-      fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename);
-      exit (1);
+      fprintf (stderr, "ERROR: failure reading catalog %s, skipping\n", catalog.filename);
+      continue;
+      // exit (1);
     }
     if (VERBOSE && (catalog.Naves_disk == 0)) {
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c	(revision 38432)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c	(revision 38433)
@@ -12,6 +12,6 @@
     continue; }
 
-# define CHECK_VALID_MAG(MAG) (!isnan(MAG) && (MAG > -5.0) && (MAG < 30.0))
-# define CHECK_VALID_FLUX(FLUX) (!isnan(FLUX))
+# define CHECK_VALID_MAG(MAG,D_MAG) (isfinite(MAG) && isfinite(D_MAG) && (MAG > -5.0) && (MAG < 30.0))
+# define CHECK_VALID_FLUX(FLUX,D_FLUX) (isfinite(FLUX) && isfinite(D_FLUX))
 
 static float MagToFlux (float Mag) {
@@ -126,4 +126,7 @@
   // assign measurements to the photcode lists 
   for (k = 0; k < averageT[0].Nmeasure; k++) {
+
+    // these bits should not be set unless we use them in this pass
+    measure[k].dbFlags &= ~(ID_MEAS_PHOTOM_PSF | ID_MEAS_PHOTOM_APER | ID_MEAS_PHOTOM_KRON);
 
     // skip measurements that do not have a valid photcode (raise exception?)
@@ -214,5 +217,5 @@
       Map = PhotCat (&measure[k], MAG_CLASS_APER);
       dMap = MAX (hypot(measure[k].dMap,   code->photomErrSys), MIN_ERROR);
-      if (CHECK_VALID_MAG(Map)) {
+      if (CHECK_VALID_MAG(Map, dMap)) {
 	int Nap = results->aperData[Nsec].Nlist;
 	results->aperData[Nsec].flxlist[Nap] = Map - Mcal - Mmos - Mgrid;
@@ -229,5 +232,5 @@
       Mkron = PhotCat (&measure[k], MAG_CLASS_KRON);
       dMkron = MAX (hypot(measure[k].dMkron, code->photomErrSys), MIN_ERROR);
-      if (CHECK_VALID_MAG(Mkron)) {
+      if (CHECK_VALID_MAG(Mkron, dMkron)) {
 	int Nkron = results->kronData[Nsec].Nlist;
 	results->kronData[Nsec].flxlist[Nkron] = Mkron - Mcal - Mmos - Mgrid;
@@ -242,5 +245,5 @@
     float Mpsf = PhotSysTiny (&measureT[k], &averageT[0], &secfilt[0], MAG_CLASS_PSF);
     float dMpsf  = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR);
-    if (CHECK_VALID_MAG(Mpsf)) {
+    if (CHECK_VALID_MAG(Mpsf, dMpsf)) {
       int Npsf = results->psfData[Nsec].Nlist;
       results->psfData[Nsec].flxlist[Npsf] = Mpsf - Mcal - Mmos - Mgrid;
@@ -338,5 +341,5 @@
 
     if (isSetMrelFinal) {
-      if ((average->objID == 0x1) && (average->catID)) {
+      if (FALSE && (average->objID == 0x1) && (average->catID)) {
 	fprintf (stderr, "test obj\n");
       }
@@ -555,6 +558,11 @@
       if (isnan(Finst)) SKIP_THIS_MEAS_STACK(Ninst);
 
+      // choose the best psfQFperf value for the BEST measurement
       if (measure[k].psfQFperf > psfQFbest) {
 	psfQFbest = measure[k].psfQFperf;
+	stackBestMeasure = k;
+      }
+      // ... UNLESS psfQFperf > 0.98 for the primary, in which case just use the primary.
+      if ((measure[k].dbFlags & ID_MEAS_STACK_PRIMARY) && (measure[k].psfQFperf > 0.98)) {
 	stackBestMeasure = k;
       }
@@ -678,6 +686,8 @@
   float Mcal = 0;
 
+  SetMrelInfoResetObject (results); // reset the per-object arrays
+
   // option for a test print
-  if ((average[0].objID == 0xd6e) && (average[0].catID == 0x4984)) {
+  if (FALSE && (average[0].objID == 0x0000020d) && (average[0].catID == 0x000049e1)) {
     fprintf (stderr, "test obj\n");
     print_measure_set_alt (average, secfilt, measure);
@@ -704,4 +714,6 @@
     off_t meas = measureOffset + k;
 
+    measure[k].dbFlags &= ~ID_MEAS_WARP_USED; // this should not be set unless we use it in this pass
+
     // skip measurements that do not have a valid photcode (raise exception?)
     PhotCode *code = GetPhotcodebyCode (measure[k].photcode);
@@ -717,6 +729,4 @@
     results->Nmeas[Nsec] ++;
     if (measure[k].psfQFperf > 0.85) results->NmeasGood[Nsec] ++;
-
-    measure[k].dbFlags &= ~ID_MEAS_WARP_USED;
 
     // use primary skycell for DIFF, stack skycell for WARP
@@ -749,5 +759,6 @@
     float Fpsf = PhotFluxCat (&measure[k], MAG_CLASS_PSF);
     float dFpsf = PhotFluxCatErr (&measure[k], MAG_CLASS_PSF);
-    if (CHECK_VALID_FLUX(Fpsf)) {
+    if (CHECK_VALID_FLUX(Fpsf, dFpsf)) {
+      dFpsf = MAX (hypot(dFpsf, code->photomErrSys*Fpsf), MIN_ERROR*Fpsf); // bump up the error by a systematic floor
       int Npsf = results->psfData[Nsec].Nlist;
       results->psfData[Nsec].flxlist[Npsf] = Fpsf * Fcal;
@@ -761,5 +772,6 @@
     float Fap = PhotFluxCat (&measure[k], MAG_CLASS_APER);
     float dFap = PhotFluxCatErr (&measure[k], MAG_CLASS_APER);
-    if (CHECK_VALID_FLUX(Fap)) {
+    if (CHECK_VALID_FLUX(Fap, dFap)) {
+      dFap = MAX (hypot(dFap, code->photomErrSys*Fap), MIN_ERROR*Fap); // bump up the error by a systematic floor
       int Naper = results->aperData[Nsec].Nlist;
       results->aperData[Nsec].flxlist[Naper] = Fap * Fcal;
@@ -773,5 +785,6 @@
     float Fkron = PhotFluxCat (&measure[k], MAG_CLASS_KRON);
     float dFkron = PhotFluxCatErr (&measure[k], MAG_CLASS_KRON);
-    if (CHECK_VALID_FLUX(Fkron)) {
+    if (CHECK_VALID_FLUX(Fkron, dFkron)) {
+      dFkron = MAX (hypot(dFkron, code->photomErrSys*Fkron), MIN_ERROR*Fkron); // bump up the error by a systematic floor
       int Nkron = results->kronData[Nsec].Nlist;
       results->kronData[Nsec].flxlist[Nkron] = Fkron * Fcal;
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelFinal.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelFinal.c	(revision 38432)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelFinal.c	(revision 38433)
@@ -329,5 +329,5 @@
 
     // RANK 2 : psfQF value
-    if (measure[i].psfQF < 0.85)                     { measureRank[i] = 4; continue; }
+    if (!isfinite(measure[i].psfQF) || measure[i].psfQF < 0.85) { measureRank[i] = 4; continue; }
 	
     // RANK 1 : POOR photFlags
@@ -338,5 +338,5 @@
     
     // RANK 1 : psfQFperfect value
-    if (measure[i].psfQFperf < 0.85)                 { measureRank[i] = 1; continue; }
+    if (!isfinite(measure[i].psfQFperf) || measure[i].psfQFperf < 0.85) { measureRank[i] = 1; continue; }
 	
     // RANK 0 : perfect measurement:
