Index: /trunk/psphot/src/psphotStackReadout.c
===================================================================
--- /trunk/psphot/src/psphotStackReadout.c	(revision 33916)
+++ /trunk/psphot/src/psphotStackReadout.c	(revision 33917)
@@ -89,6 +89,16 @@
 	return psphotReadoutCleanup (config, view, STACK_SRC);
     }
-    if (!psphotSubtractBackground (config, view, STACK_SRC)) {
-	return psphotReadoutCleanup (config, view, STACK_SRC);
+    if (strcmp(STACK_SRC, STACK_DET)) {
+#define MODEL_BACKGROUND_SRC 1
+#ifdef MODEL_BACKGROUND_SRC
+        // work around the fact that the background levels on the convolved
+        // and unconvolved stacks can be different
+        if (!psphotModelBackground (config, view, STACK_SRC)) {
+            return psphotReadoutCleanup (config, view, STACK_SRC);
+        }
+#endif
+        if (!psphotSubtractBackground (config, view, STACK_SRC)) {
+            return psphotReadoutCleanup (config, view, STACK_SRC);
+        }
     }
     if (!strcasecmp (breakPt, "BACKMDL")) {
@@ -190,4 +200,5 @@
     psphotReplaceAllSources (config, view, STACK_SRC, false); // pass 1 (detections->allSources)
 
+
     // if we only do one pass, skip to extended source analysis
     if (!strcasecmp (breakPt, "PASS1")) goto pass1finish;
@@ -211,5 +222,5 @@
 	    //  subtract all sources from DET (this will subtract using the psf model for SRC, which
 	    //  will somewhat oversubtract the sources -- this is OK
-	    psphotRemoveAllSources (config, view, STACK_DET, false); // ignore subtraction state for sources
+	    psphotRemoveAllSources (config, view, STACK_DET, false); // do not ignore subtraction state for sources
 	}
 
@@ -223,5 +234,9 @@
 	// remove noise for subtracted objects (ie, return to normal noise level)
 	// NOTE: this needs to operate only on the OLD sources
-	psphotSubNoise (config, view, STACK_DET); // pass 1 (detections->allSources)
+        // NOTE: if fooprintsUseUnsubtracted, the noise has already been removed by psphotFindDetections
+        bool footprintsUseUnsubtracted = psMetadataLookupBool(NULL, recipe, "FOOTPRINT_USE_UNSUBTRACTED");
+        if (!footprintsUseUnsubtracted) {
+    	    psphotSubNoise (config, view, STACK_DET); // pass 1 (detections->allSources)
+        }
 
 	// if DET and SRC are different images, copy the detections from DET to SRC 
@@ -303,6 +318,8 @@
 
     // create source children for the OUT filerule (for radial aperture photometry) 
-    psArray *objectsRadial = psphotSourceChildrenByObject (config, view, STACK_OUT, objects);
-    if (!objectsRadial) {
+    // (These are not just for radial aperture photomoetry. If they aren't defined we
+    // get no sources output
+    psArray *objectsOut = psphotSourceChildrenByObject (config, view, STACK_OUT, objects);
+    if (!objectsOut) {
 	psFree(objects);
 	psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
@@ -310,33 +327,37 @@
     }
 
-    // measure circular, radial apertures (objects sorted by S/N)
-    // this forces photometry on the undetected sources from other images
-    psphotRadialApertures (config, view, STACK_SRC, 0); // XXX entry 0 == unmatched?
-    psMemDump("extmeas");
-
-    int nRadialEntries = psphotStackMatchPSFsEntries(config, view, STACK_OUT);
-
-    for (int entry = 1; entry < nRadialEntries; entry++) {
-	// NOTE: entry 0 is the unmatched image set
-
-	// re-measure the PSF for the smoothed image (using entries in 'allSources')
-	psphotChoosePSF (config, view, STACK_OUT, false);
-
-	// this is necessary to update the models based on the new PSF
-	psphotResetModels (config, view, STACK_OUT);
-
-	// this is necessary to get the right normalization for the new models
-	psphotFitSourcesLinear (config, view, STACK_OUT, false);
-
-	// measure circular, radial apertures (objects sorted by S/N)
-	// entry 0 == unmatched? pass entry + 1?
-	psphotRadialApertures (config, view, STACK_OUT, entry); 
-
-	// replace the flux in the image so it is returned to its original state
-	psphotReplaceAllSources (config, view, STACK_OUT, false);
-
-	// smooth to the next FWHM, or set 'smoothAgain' to false if no more 
-	psphotStackMatchPSFsNext(config, view, STACK_OUT, entry);
-	psMemDump("matched");
+
+    bool radial_apertures = psMetadataLookupBool(NULL, recipe, "RADIAL_APERTURES");
+    if (radial_apertures) {
+        // measure circular, radial apertures (objects sorted by S/N)
+        // this forces photometry on the undetected sources from other images
+        psphotRadialApertures (config, view, STACK_SRC, 0); // XXX entry 0 == unmatched?
+        psMemDump("extmeas");
+
+        int nRadialEntries = psphotStackMatchPSFsEntries(config, view, STACK_OUT);
+
+        for (int entry = 1; entry < nRadialEntries; entry++) {
+            // NOTE: entry 0 is the unmatched image set
+
+            // re-measure the PSF for the smoothed image (using entries in 'allSources')
+            psphotChoosePSF (config, view, STACK_OUT, false);
+
+            // this is necessary to update the models based on the new PSF
+            psphotResetModels (config, view, STACK_OUT);
+
+            // this is necessary to get the right normalization for the new models
+            psphotFitSourcesLinear (config, view, STACK_OUT, false);
+
+            // measure circular, radial apertures (objects sorted by S/N)
+            // entry 0 == unmatched? pass entry + 1?
+            psphotRadialApertures (config, view, STACK_OUT, entry); 
+
+            // replace the flux in the image so it is returned to its original state
+            psphotReplaceAllSources (config, view, STACK_OUT, false);
+
+            // smooth to the next FWHM, or set 'smoothAgain' to false if no more 
+            psphotStackMatchPSFsNext(config, view, STACK_OUT, entry);
+            psMemDump("matched");
+        }
     }
 
@@ -344,4 +365,5 @@
     if (!psphotApResid (config, view, STACK_SRC)) {
 	psFree (objects);
+	psFree (objectsOut);
         psLogMsg ("psphot", 3, "failed on psphotApResid");
 	return psphotReadoutCleanup (config, view, STACK_SRC);
@@ -375,5 +397,5 @@
 
     psFree (objects);
-    psFree (objectsRadial);
+    psFree (objectsOut);
 
     // create the exported-metadata and free local data
