Index: branches/eam_branches/relphot.20210521/src/setMrelFinal.c
===================================================================
--- branches/eam_branches/relphot.20210521/src/setMrelFinal.c	(revision 41608)
+++ branches/eam_branches/relphot.20210521/src/setMrelFinal.c	(revision 41620)
@@ -11,74 +11,6 @@
   int Nsecfilt = GetPhotcodeNsecfilt ();
 
-  /*** RESET photometry flags and Mcal values ***/
-  if (RESET) {
-    // flags used by the photometry analysis (excluding UBERCAL)
-    unsigned int PHOTOM_FLAGS = 
-      ID_MEAS_NOCAL |          // detection ignored for this analysis (photcode, time range)
-      ID_MEAS_POOR_PHOTOM |    // detection is photometry outlier 
-      ID_MEAS_SKIP_PHOTOM |    // detection was ignored for photometry measurement 
-      ID_MEAS_AREA |	       // detetion was outside acceptable area of device
-      ID_MEAS_SYNTH_MAG |      // magnitude is synthetic
-      ID_MEAS_STACK_PRIMARY |  // this stack measurement is in the primary skycell
-      ID_MEAS_STACK_PHOT_SRC;  // this measurement supplied the stack photometry
-
-    // ID_MEAS_PHOTOM_UBERCAL -- externally-supplied zero point from ubercal analysis
-    // this is set by 'setphot', do not reset here
-
-    // flags used by the photometry analysis (excluding UBERCAL)
-    // unsigned int secfiltFlags = 
-    //   ID_PHOTOM_PASS_0 | // average measured at pass 0
-    //   ID_PHOTOM_PASS_1 | // average measured at pass 1
-    //   ID_PHOTOM_PASS_2 | // average measured at pass 2
-    //   ID_PHOTOM_PASS_3 | // average measured at pass 3
-    //   ID_PHOTOM_PASS_4 | // average measured at pass 3
-    //   ID_SECF_USE_SYNTH | // average measured at pass 3
-    //   ID_SECF_USE_UBERCAL | // average measured at pass 3
-    //   ID_SECF_OBJ_EXT; // average measured at pass 3
-    
-    // XXX I should really deprecate the concept of applying the average 
-    // calculation to a limited set of photcodes.  
-    // for now, just do all photcodes here (
-    // as it stands, only stacks are limited by photcode; mean exp and forced warp 
-    // are applied to all Nsecfilt
-
-    for (i = 0; i < catalog[0].Naverage; i++) {
-      int Ns;
-      for (Ns = 0; Ns < Nsecfilt; Ns++) {
-	
-	off_t N = Nsecfilt*i+Ns;
-	dvo_secfilt_init (&catalog[0].secfilt[N], SECFILT_RESET_ALL);
-
-	off_t m = catalog[0].average[i].measureOffset;
-	off_t j;
-	for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {
-	
-	  /* select measurements by time */
-	  if (TimeSelect) {
-	    if (catalog[0].measure[m].t < TSTART) continue;
-	    if (catalog[0].measure[m].t > TSTOP) continue;
-	  }
-	
-	  // only reset Mcal for measures with a matching image
-	  // do not reset Mcal for ubercal images unless explicitly requested
-
-	  if (catalog[0].measure[m].dbFlags & ID_MEAS_PHOTOM_UBERCAL) {
-	    if (!KEEP_UBERCAL) {
-	      catalog[0].measure[m].McalPSF  = 0.0;
-	      catalog[0].measure[m].McalAPER = 0.0;
-	      catalog[0].measure[m].dbFlags &= ~ID_MEAS_PHOTOM_UBERCAL;
-	    } 
-	  } else {
-	    if (RESET_ZEROPTS && (getImageEntry (m, 0) >= 0)) {
-	      catalog[0].measure[m].McalPSF  = 0.0;
-	      catalog[0].measure[m].McalAPER = 0.0;
-	    }
-	  }
-	  catalog[0].measure[m].dbFlags &= ~PHOTOM_FLAGS;
-	}
-      }
-    }
-  }
-
+  ResetAverageAndMeasure (catalog);
+  
   // this sets flags in the measureT element, not the measure element
   setExclusions (catalog, 1, VERBOSE);  /* mark by area */
