Index: /branches/eam_branches/relphot.20210521/include/relphot.h
===================================================================
--- /branches/eam_branches/relphot.20210521/include/relphot.h	(revision 41623)
+++ /branches/eam_branches/relphot.20210521/include/relphot.h	(revision 41624)
@@ -445,4 +445,5 @@
 int    REPAIR_WARPS;
 int    PRESERVE_PS1;
+int    REQUIRE_PSFFIT;
 int    UPDATE;
 int    SAVE_IMAGE_UPDATES;
@@ -735,5 +736,7 @@
 
 int print_measure_set_alt (Average *average, SecFilt *secfilt, Measure *measure);
-int setMrel_catalog_alt (Catalog *catalog, int Nc, int isSetMrelFinal, SetMrelInfo *results, int Nsecfilt);
+
+// in setMrelCatalog.c:
+int setMrelCatalog (Catalog *catalog, int Nc, int isSetMrelFinal, SetMrelInfo *results, int Nsecfilt);
 int setMrelAverageExposure (Catalog *catalog, int cat, off_t ave, int Nsecfilt, int isSetMrelFinal, SetMrelInfo *results);
 int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt);
Index: /branches/eam_branches/relphot.20210521/src/ResetOps.c
===================================================================
--- /branches/eam_branches/relphot.20210521/src/ResetOps.c	(revision 41623)
+++ /branches/eam_branches/relphot.20210521/src/ResetOps.c	(revision 41624)
@@ -39,5 +39,5 @@
     
 
-// Used in bcatalog.c
+// Used in bcatalog.c, applied to the subset catalogs (bright, good stars used for calibration)
 void ResetAverageActivePhotcodes (SecFilt *secfilt) {
 
@@ -56,5 +56,5 @@
 }
 
-// Used in bcatalog.c
+// Used in bcatalog.c, applied to the selected measurements which are already selected by photcode
 void ResetMeasureZeroPoints (MeasureTiny *measure, off_t Nmeasure, off_t Ncat) {
 
@@ -78,6 +78,7 @@
 }
 
-// Used in load_images.c:
-// XXX NOTE : This resets all images regardless of active photcode
+// Used in load_images.c.  Applied to the subset of selected images used for the calibration.
+// This will be only those images in the selected region and only those with the active
+// photcode *unless* -use-all-images is selected.  
 void ResetImages (Image *subset, off_t Nsubset) {
 
Index: /branches/eam_branches/relphot.20210521/src/StarOps.c
===================================================================
--- /branches/eam_branches/relphot.20210521/src/StarOps.c	(revision 41623)
+++ /branches/eam_branches/relphot.20210521/src/StarOps.c	(revision 41624)
@@ -14,5 +14,4 @@
 void *setMrel_worker (void *data);
 int setMrel_threaded (Catalog *catalog, int Ncatalog);
-int setMrel_catalog (Catalog *catalog, int Nc, int pass, SetMrelInfo *results, int Nsecfilt);
 int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure);
 
@@ -315,5 +314,5 @@
 
   for (i = 0; i < Ncatalog; i++) {
-    setMrel_catalog_alt (catalog, i, FALSE, &results, Nsecfilt);
+    setMrelCatalog (catalog, i, FALSE, &results, Nsecfilt);
     SetMrelInfoAccum (&summary, &results);
   }
@@ -338,5 +337,5 @@
 
   for (i = 0; i < Ncatalog; i++) {
-    setMrel_catalog_alt (catalog, i, TRUE, &results, Nsecfilt);
+    setMrelCatalog (catalog, i, TRUE, &results, Nsecfilt);
     SetMrelInfoAccum (&summary, &results);
   }
@@ -436,5 +435,5 @@
     Catalog *catalog = threadinfo->catalog;
 
-    setMrel_catalog_alt (catalog, i, FALSE, &results, Nsecfilt);
+    setMrelCatalog (catalog, i, FALSE, &results, Nsecfilt);
     SetMrelInfoAccum (&threadinfo->summary, &results);
   }
Index: /branches/eam_branches/relphot.20210521/src/args.c
===================================================================
--- /branches/eam_branches/relphot.20210521/src/args.c	(revision 41623)
+++ /branches/eam_branches/relphot.20210521/src/args.c	(revision 41624)
@@ -241,4 +241,9 @@
     remove_argument (N, &argc, argv);
     PRESERVE_PS1 = TRUE;
+  }
+  REQUIRE_PSFFIT = FALSE;
+  if ((N = get_argument (argc, argv, "-require-psffit"))) {
+    remove_argument (N, &argc, argv);
+    REQUIRE_PSFFIT = TRUE;
   }
 
Index: /branches/eam_branches/relphot.20210521/src/bcatalog.c
===================================================================
--- /branches/eam_branches/relphot.20210521/src/bcatalog.c	(revision 41623)
+++ /branches/eam_branches/relphot.20210521/src/bcatalog.c	(revision 41624)
@@ -89,5 +89,5 @@
 
       // require 0x01 in photFlags (fitted with a PSF) -- add to the test data
-// XXX EAM : test is inconsistent -- fix      if ((catalog[0].measure[offset].photFlags & 0x01) == 0) { Nbad ++; continue; }
+      if (REQUIRE_PSFFIT && (catalog[0].measure[offset].photFlags & 0x01) == 0) { Nbad ++; continue; }
 
       // very loose cut on PSF - Kron 
Index: /branches/eam_branches/relphot.20210521/src/reload_catalogs.c
===================================================================
--- /branches/eam_branches/relphot.20210521/src/reload_catalogs.c	(revision 41623)
+++ /branches/eam_branches/relphot.20210521/src/reload_catalogs.c	(revision 41624)
@@ -85,5 +85,4 @@
     initMrel (&catalog, 1);
 
-    setMflatFromGrid (&catalog); // Mgrid is used to set Mflat; Mgrid is the ignored in setMrelFinal/setMrelCatalog.c
     setMrelFinal (&catalog, FALSE);
     TIMESTAMP(time6);
Index: /branches/eam_branches/relphot.20210521/src/relphot_images.c
===================================================================
--- /branches/eam_branches/relphot.20210521/src/relphot_images.c	(revision 41623)
+++ /branches/eam_branches/relphot.20210521/src/relphot_images.c	(revision 41624)
@@ -96,5 +96,5 @@
       SetZptIteration (i);
 
-      setMrel  (catalog, Ncatalog); // threaded (calls setMrel_catalog_alt in setMrelCatalog.c)
+      setMrel  (catalog, Ncatalog); // threaded (calls setMrelCatalog)
 
       setMcal  (catalog);
@@ -177,5 +177,5 @@
      clients */
   if (!CALIBRATE_STACKS_AND_WARPS) {
-    reload_catalogs (skylist, 0, NULL); // calls setMrelFinal which setMrelOutput which calls setMrel_catalog_alt
+    reload_catalogs (skylist, 0, NULL); // calls setMrelFinal which setMrelOutput which calls setMrelCatalog
     MARKTIME("-- updated all catalogs: %f sec\n", dtime);
   }
Index: /branches/eam_branches/relphot.20210521/src/select_images.c
===================================================================
--- /branches/eam_branches/relphot.20210521/src/select_images.c	(revision 41623)
+++ /branches/eam_branches/relphot.20210521/src/select_images.c	(revision 41624)
@@ -103,5 +103,5 @@
     if (!(i % 300000)) fprintf (stderr, ".");
 
-    /* exclude images by photcode (we are not doing this, but I'm not sure why) */
+    // only include active photcodes in the analysis
     if (timage[i].photcode) {
       int Ns = GetActivePhotcodeIndex (timage[i].photcode);
Index: /branches/eam_branches/relphot.20210521/src/setMrelCatalog.c
===================================================================
--- /branches/eam_branches/relphot.20210521/src/setMrelCatalog.c	(revision 41623)
+++ /branches/eam_branches/relphot.20210521/src/setMrelCatalog.c	(revision 41624)
@@ -60,5 +60,5 @@
 int useOLS = TRUE; // chosen based on iteration below
 
-int setMrel_catalog_alt (Catalog *catalog, int Nc, int isSetMrelFinal, SetMrelInfo *results, int Nsecfilt) {
+int setMrelCatalog (Catalog *catalog, int Nc, int isSetMrelFinal, SetMrelInfo *results, int Nsecfilt) {
 
   off_t j;
Index: /branches/eam_branches/relphot.20210521/src/setMrelFinal.c
===================================================================
--- /branches/eam_branches/relphot.20210521/src/setMrelFinal.c	(revision 41623)
+++ /branches/eam_branches/relphot.20210521/src/setMrelFinal.c	(revision 41624)
@@ -27,9 +27,12 @@
   ALLOCATE (catalog[0].measureRank, char, catalog[0].Nmeasure);
   setMeasureRank (catalog);
+
+  setMflatFromGrid (catalog); // Mgrid is used to set Mflat; Mgrid is the ignored in setMrelOutput / setMrelCatalog
   setMrelOutput (catalog, 1); // sets the values secfilt.MpsfChp = <measure.M - image.Mcal - measure.Mflat>
   setMcalOutput (catalog, 1); // sets measure.Mcal = image.Mcal
 
-  /* clear ID_OBJ_POOR, ID_OBJ_FEW values before writing ??? */
-  /* ID_MEAS_NOCAL is an internal bit, so it should be cleared */
+  // clear ID_OBJ_POOR, ID_OBJ_FEW, ID_MEAS_NOCAL values before writing 
+  // These are internal bits, so they should be cleared
+  // XXX are these still used?
   // XXX eventually: move these internal flags to an internal-only catalog->FOO element (like found)
   for (i = 0; i < catalog[0].Naverage; i++) {
@@ -83,4 +86,5 @@
 int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure);
 
+// XXX this function is no longer used:
 void skip_measurements (Catalog *catalog, int pass) {
 
