Index: /branches/eam_branches/ipp-20230313/Ohana/src/relphot/include/relphot.h
===================================================================
--- /branches/eam_branches/ipp-20230313/Ohana/src/relphot/include/relphot.h	(revision 42695)
+++ /branches/eam_branches/ipp-20230313/Ohana/src/relphot/include/relphot.h	(revision 42696)
@@ -414,6 +414,11 @@
 int IS_DIFF_DB;
 
+double MAG_MIN;
 double MAG_LIM;
 double SIGMA_LIM;
+
+double STAR_MAX_PSF_KRON;
+double PSF_QF_MIN;
+
 double IMAGE_SCATTER;
 double IMAGE_OFFSET;
@@ -468,4 +473,5 @@
 int    RESET_FLATCORR;
 int    REPAIR_WARPS;
+int    USE_REF_EQUIV;
 int    PRESERVE_PS1;
 int    REQUIRE_PSFFIT;
Index: /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/ConfigInit.c
===================================================================
--- /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/ConfigInit.c	(revision 42695)
+++ /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/ConfigInit.c	(revision 42696)
@@ -23,6 +23,12 @@
   if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);
 
-  GetConfig (config, "MAG_LIM",                "%lf", 0, &MAG_LIM);
-  GetConfig (config, "SIGMA_LIM",              "%lf", 0, &SIGMA_LIM);
+  // the following cuts are limit the objects used to calculate the image zero points.
+  // These are used in bcatalog.c and apply to Mcat (nominal measurement magnitude)
+  GetConfig (config, "SIGMA_LIM",              "%lf",    0, &SIGMA_LIM);
+  GetConfig (config, "MAG_LIM",                "%lf",    0, &MAG_LIM);
+
+  DefConfig ("MAG_MIN",                        "%lf", 15.0, MAG_MIN);
+  DefConfig ("STAR_MAX_PSF_KRON",              "%lf",  0.2, STAR_MAX_PSF_KRON);
+  DefConfig ("PSF_QF_MIN",                     "%lf", 0.95, PSF_QF_MIN);
 
   DefConfig ("STAR_SCATTER",                    "%lf",  0.1, STAR_SCATTER);
Index: /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/StarOps.c
===================================================================
--- /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/StarOps.c	(revision 42695)
+++ /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/StarOps.c	(revision 42696)
@@ -34,5 +34,8 @@
 }  
 
-// 
+// Nsecfilt is a property of the photcode table.  we only need to retrieve it once.
+static int Nsecfilt = -1;
+
+// return the average photometry for this measurement
 float getMrel (Catalog *catalog, off_t meas, int cat, dvoMagClassType class, dvoMagSourceType source) {
 
@@ -41,6 +44,16 @@
 
   int ecode = GetPhotcodeEquivCodebyCode (photcode);
+  if (USE_REF_EQUIV) {
+    // tie this photometry to an alternative refernce
+    // (e.g., tie UDR4.i to PV3.i)
+    int refcode = GetPhotcodeEquivCodebyCode (ecode);
+    if (refcode < 0) return NAN;
+    ecode = refcode;
+  }
+
   int Nsec = GetPhotcodeNsec(ecode);
-  int Nsecfilt = GetPhotcodeNsecfilt ();
+  if (Nsec < 0) return NAN;
+
+  if (Nsecfilt < 0) { Nsecfilt = GetPhotcodeNsecfilt (); }
 
   int entry = Nsecfilt*ave+Nsec;
@@ -312,5 +325,5 @@
   }
 
-  int Nsecfilt = GetPhotcodeNsecfilt ();
+  if (Nsecfilt < 0) { Nsecfilt = GetPhotcodeNsecfilt (); }
 
   SetMrelInfo summary, results;
@@ -334,5 +347,5 @@
   int i;
 
-  int Nsecfilt = GetPhotcodeNsecfilt ();
+  if (Nsecfilt < 0) { Nsecfilt = GetPhotcodeNsecfilt (); }
 
   SetMrelInfo summary, results;
@@ -424,5 +437,5 @@
   ThreadInfo *threadinfo = data;
 
-  int Nsecfilt = GetPhotcodeNsecfilt ();
+  if (Nsecfilt < 0) { Nsecfilt = GetPhotcodeNsecfilt (); }
 
   SetMrelInfo results;
@@ -451,5 +464,5 @@
   off_t k;
 
-  int Nsecfilt = GetPhotcodeNsecfilt ();
+  if (Nsecfilt < 0) { Nsecfilt = GetPhotcodeNsecfilt (); }
 
   off_t m = average[0].measureOffset;
@@ -559,5 +572,5 @@
   off_t j;
 
-  int Nsecfilt = GetPhotcodeNsecfilt ();
+  if (Nsecfilt < 0) { Nsecfilt = GetPhotcodeNsecfilt (); }
 
   for (i = 0; i < Ncatalog; i++) {
@@ -601,5 +614,5 @@
   ALLOCATE (slist, double, Ntot);
 
-  int Nsecfilt = GetPhotcodeNsecfilt ();
+  if (Nsecfilt < 0) { Nsecfilt = GetPhotcodeNsecfilt (); }
 
   // eliminate bad stars using the stats for a single secfilt at a time
@@ -666,5 +679,5 @@
   // N1 = N2 = N3 = N4 = N0 = 0;
 
-  int Nsecfilt = GetPhotcodeNsecfilt ();
+  if (Nsecfilt < 0) { Nsecfilt = GetPhotcodeNsecfilt (); }
 
   Ntot = 0;
@@ -719,5 +732,5 @@
   StatType stats;
 
-  int Nsecfilt = GetPhotcodeNsecfilt ();
+  if (Nsecfilt < 0) { Nsecfilt = GetPhotcodeNsecfilt (); }
 
   Ntot = 0;
@@ -760,5 +773,5 @@
   StatType stats;
 
-  int Nsecfilt = GetPhotcodeNsecfilt ();
+  if (Nsecfilt < 0) { Nsecfilt = GetPhotcodeNsecfilt (); }
 
   Ntot = 0;
@@ -805,5 +818,5 @@
   ALLOCATE (Mlist, double, NBIN);
 
-  int Nsecfilt = GetPhotcodeNsecfilt ();
+  if (Nsecfilt < 0) { Nsecfilt = GetPhotcodeNsecfilt (); }
 
   int Ns;
@@ -840,5 +853,5 @@
   Graphdata graphdata;
 
-  int Nsecfilt = GetPhotcodeNsecfilt ();
+  if (Nsecfilt < 0) { Nsecfilt = GetPhotcodeNsecfilt (); }
 
   Ntotal = 0;
@@ -911,5 +924,5 @@
   return;
 
-  int Nsecfilt = GetPhotcodeNsecfilt ();
+  if (Nsecfilt < 0) { Nsecfilt = GetPhotcodeNsecfilt (); }
 
   FILE *fout = NULL;
Index: /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/args.c	(revision 42695)
+++ /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/args.c	(revision 42696)
@@ -237,4 +237,9 @@
   }
 
+  USE_REF_EQUIV = FALSE;
+  if ((N = get_argument (argc, argv, "-use-ref-equiv"))) {
+    remove_argument (N, &argc, argv);
+    USE_REF_EQUIV = TRUE;
+  }
   PRESERVE_PS1 = FALSE;
   if ((N = get_argument (argc, argv, "-preserve-ps1"))) {
@@ -836,4 +841,9 @@
   }
 
+  USE_REF_EQUIV = FALSE;
+  if ((N = get_argument (argc, argv, "-use-ref-equiv"))) {
+    remove_argument (N, &argc, argv);
+    USE_REF_EQUIV = TRUE;
+  }
   PRESERVE_PS1 = FALSE;
   if ((N = get_argument (argc, argv, "-preserve-ps1"))) {
Index: /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/bcatalog.c
===================================================================
--- /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/bcatalog.c	(revision 42695)
+++ /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/bcatalog.c	(revision 42696)
@@ -85,6 +85,6 @@
 
       // skip garbage measurements
-      if (isnan(catalog[0].measure[offset].psfQF)     || (catalog[0].measure[offset].psfQF < 0.95))     { Npsfqf ++; continue; }
-      if (isnan(catalog[0].measure[offset].psfQFperf) || (catalog[0].measure[offset].psfQFperf < 0.95)) { Npsfqf ++; continue; }
+      if (isnan(catalog[0].measure[offset].psfQF)     || (catalog[0].measure[offset].psfQF     < PSF_QF_MIN)) { Npsfqf ++; continue; }
+      if (isnan(catalog[0].measure[offset].psfQFperf) || (catalog[0].measure[offset].psfQFperf < PSF_QF_MIN)) { Npsfqf ++; continue; }
       if (isnan(catalog[0].measure[offset].M)) { Nnan ++; continue; }
       if (isnan(Maper)) { Nnan ++; continue; }
@@ -104,5 +104,5 @@
 
       // weak test for galaxies
-      if (Mkp > 0.5) {
+      if (Mkp > STAR_MAX_PSF_KRON) {
 	nEXT ++;
       } else {
@@ -113,4 +113,9 @@
       mag = PhotCat (&catalog[0].measure[offset], MAG_CLASS_PSF);
       if (mag > MAG_LIM) { Nmag ++; continue; } 
+      if (mag < MAG_MIN) { Nmag ++; continue; } 
+      // note that these two cuts are applied to all photcodes. these are also applied to
+      // the nominal apparent mags : if the expected sensitivity is very different between
+      // different filters, or if exposure times have a large range, these cuts may not be
+      // effective (or may exclude too much).
 
       /* select measurements by measurement error */
@@ -123,4 +128,7 @@
 	if (mag > ImagMax) { Nimag ++; continue; }
       }
+      // note that instrumental mag cuts are reasonable for individual exposures using the same
+      // detector, but are probably not appropriate for stacks with a large range of the number
+      // of inputs.  
 
       // count this measurement as valid for this secfilt entry
Index: /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/extra.c
===================================================================
--- /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/extra.c	(revision 42695)
+++ /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/extra.c	(revision 42696)
@@ -70,13 +70,18 @@
 }
 
-// for now (20140710) I need to identify gpc1 stacks explicitly.  generalize in the future
+// for now (20140710) I need to identify gpc1 & gpc2 stacks explicitly.  generalize in the future
 int isGPC1stack (int photcode) {
 
-  if ((photcode == 11000) || (photcode == 14100)) return TRUE; // g-band
-  if ((photcode == 11100) || (photcode == 14200)) return TRUE; // r-band
-  if ((photcode == 11200) || (photcode == 14300)) return TRUE; // i-band
-  if ((photcode == 11300) || (photcode == 14400)) return TRUE; // z-band
-  if ((photcode == 11400) || (photcode == 14500)) return TRUE; // y-band
-  if ((photcode == 11500) || (photcode == 14600)) return TRUE; // w-band
+  // 11000 : GPC1.g.SkyChip
+  // 11001 : VARIOUS.g.SkyChip (output of xcamera stacks)
+  // 14100 : SIMTEST.g.SkyChip
+  // 31000 : GPC2.g.SkyChip
+  
+  if ((photcode == 11000) || (photcode == 11001) || (photcode == 14100) || (photcode == 31000)) return TRUE; // g-band
+  if ((photcode == 11100) || (photcode == 11101) || (photcode == 14200) || (photcode == 31100)) return TRUE; // r-band
+  if ((photcode == 11200) || (photcode == 11201) || (photcode == 14300) || (photcode == 31200)) return TRUE; // i-band
+  if ((photcode == 11300) || (photcode == 11301) || (photcode == 14400) || (photcode == 31300)) return TRUE; // z-band
+  if ((photcode == 11400) || (photcode == 11401) || (photcode == 14500) || (photcode == 31400)) return TRUE; // y-band
+  if ((photcode == 11500) || (photcode == 11501) || (photcode == 14600) || (photcode == 31500)) return TRUE; // w-band
 
   return FALSE;
@@ -85,4 +90,11 @@
 // for now (20140710) I need to identify gpc1 stacks explicitly.  generalize in the future
 int isGPC1warp (int photcode) {
+
+  // 11000 : GPC1.g.SkyChip
+  // 14100 : SIMTEST.g.SkyChip
+
+  // 12000 : GPC1.g.ForcedWarp
+  // 15100 : SIMTEST.g.ForcedWarp
+  // 32000 : GPC2.g.ForcedWarp
 
   // diff warps get stack-like photcodes (kind of lame)
@@ -97,10 +109,10 @@
   }
 
-  if ((photcode == 12000) || (photcode == 15100)) return TRUE; // g-band
-  if ((photcode == 12100) || (photcode == 15200)) return TRUE; // r-band
-  if ((photcode == 12200) || (photcode == 15300)) return TRUE; // i-band
-  if ((photcode == 12300) || (photcode == 15400)) return TRUE; // z-band
-  if ((photcode == 12400) || (photcode == 15500)) return TRUE; // y-band
-  if ((photcode == 12500) || (photcode == 15600)) return TRUE; // w-band
+  if ((photcode == 12000) || (photcode == 15100) || (photcode == 32000)) return TRUE; // g-band
+  if ((photcode == 12100) || (photcode == 15200) || (photcode == 32100)) return TRUE; // r-band
+  if ((photcode == 12200) || (photcode == 15300) || (photcode == 32200)) return TRUE; // i-band
+  if ((photcode == 12300) || (photcode == 15400) || (photcode == 32300)) return TRUE; // z-band
+  if ((photcode == 12400) || (photcode == 15500) || (photcode == 32400)) return TRUE; // y-band
+  if ((photcode == 12500) || (photcode == 15600) || (photcode == 32500)) return TRUE; // w-band
 
   return FALSE;
Index: /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/initialize.c
===================================================================
--- /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/initialize.c	(revision 42695)
+++ /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/initialize.c	(revision 42696)
@@ -50,11 +50,12 @@
       fprintf (stderr, "DophotSelect: FALSE\n");
     }
-    fprintf (stderr, "PSF_QF limit: 0.85 (hardwired)\n");
+    fprintf (stderr, "PSF_QF limit: %f\n", PSF_QF_MIN);
 
     // fprintf (stderr, "Photom Bad Mask: 0x%08x, Photom Poor Mask: 0x%08x\n");
 
-    fprintf (stderr, "MAG_LIM: %f, SIGMA_LIM: %f\n", MAG_LIM, SIGMA_LIM);
+    fprintf (stderr, "MAG_MIN: %f, MAG_LIM: %f, SIGMA_LIM: %f\n", MAG_MIN, MAG_LIM, SIGMA_LIM);
     fprintf (stderr, "INST_MAG_MIN: %f, INST_MAG_MAX: %f\n", ImagMin, ImagMax);
 
+    fprintf (stderr, "STAR_MAX_PSF_KRON: %f\n", STAR_MAX_PSF_KRON);
     fprintf (stderr, "STAR_TOOFEW: %d\n", STAR_TOOFEW);
 
Index: /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/load_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/load_catalogs.c	(revision 42695)
+++ /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/load_catalogs.c	(revision 42696)
@@ -151,5 +151,7 @@
     // TimeSelect -time
     // DophotSelect
-    // (note that psfQF is applied rigidly at 0.85, as is the galaxy test)
+    // PSF_QF_MIN
+    // STAR_MAX_PSF_KRON
+    // MAG_MIN
     // MAG_LIM
     // SIGMA_LIM
@@ -158,6 +160,8 @@
 
     char *command = NULL;
-    strextend (&command, "relphot_client %s -load %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -D CAMERA %s -D MAG_LIM %f -D SIGMA_LIM %f", 
-	      PhotcodeList, table->hosts[i].results, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, CAMERA, MAG_LIM, SIGMA_LIM);
+    strextend (&command, "relphot_client %s -load %s -hostID %d -D CATDIR %s -hostdir %s", PhotcodeList, table->hosts[i].results, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname);
+    strextend (&command, "-region %f %f %f %f -D CAMERA %s", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, CAMERA);
+    strextend (&command, "-D MAG_MIN %f -D MAG_LIM %f -D SIGMA_LIM %f", MAG_MIN, MAG_LIM, SIGMA_LIM);
+    strextend (&command, "-D STAR_MAX_PSF_KRON %f -D PSF_QF_MIN %f", STAR_MAX_PSF_KRON, PSF_QF_MIN);
 
     if (VERBOSE)       	     { strextend (&command, "-v"); }
Index: /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/relphot.c
===================================================================
--- /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/relphot.c	(revision 42695)
+++ /branches/eam_branches/ipp-20230313/Ohana/src/relphot/src/relphot.c	(revision 42696)
@@ -33,7 +33,8 @@
   
   switch (mode) {
-    case UPDATE_IMAGES:
+    case UPDATE_IMAGES: // -images
       // calculate zero points for images (may group by exposure [mosaic], night [tgroups]; may measure flat-correction)
-      // IF CALLED WITH NLOOP == 0, DOES NOT LOAD bcatalog, just loads image table and generates ImageSubset.dat
+      // IF CALLED WITH NLOOP == 0 (and NOT -only-stacks-and-warps), this step DOES NOT LOAD bcatalog.  Instead it just loads
+      // the image table and applies the Mcal values to the measurements.  In parallel context, it generates ImageSubset.dat.
       // If called with -update, calls reload_catalogs() just like apply_offsets, UNLESS -only-stacks-and-warps is selected
       relphot_images (skylist);
