Index: /branches/eam_branches/ipp-20120905/psphot/src/psphot.h
===================================================================
--- /branches/eam_branches/ipp-20120905/psphot/src/psphot.h	(revision 34415)
+++ /branches/eam_branches/ipp-20120905/psphot/src/psphot.h	(revision 34416)
@@ -81,5 +81,5 @@
 
 bool            psphotDeblendSatstars (pmConfig *config, const pmFPAview *view, const char *filerule);
-bool            psphotDeblendSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index);
+bool            psphotDeblendSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
 
 bool            psphotBasicDeblend (pmConfig *config, const pmFPAview *view, const char *filerule);
Index: /branches/eam_branches/ipp-20120905/psphot/src/psphotDeblendSatstars.c
===================================================================
--- /branches/eam_branches/ipp-20120905/psphot/src/psphotDeblendSatstars.c	(revision 34415)
+++ /branches/eam_branches/ipp-20120905/psphot/src/psphotDeblendSatstars.c	(revision 34416)
@@ -16,9 +16,21 @@
 bool psphotDeblendSatstars (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
+    bool status = false;
+
     int num = psphotFileruleCount(config, filerule);
+
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
+    // perform full extended source non-linear fits?
+    if (!psMetadataLookupBool (&status, recipe, "SUBTRACT_SATSTAR_PROFILE")) {
+        psLogMsg ("psphot", PS_LOG_INFO, "skipping extended source fits\n");
+        return true;
+    }
 
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotDeblendSatstarsReadout (config, view, filerule, i)) {
+	if (!psphotDeblendSatstarsReadout (config, view, filerule, i, recipe)) {
             psError (PSPHOT_ERR_CONFIG, false, "failed on saturated star deblend analysis for %s entry %d", filerule, i);
 	    return false;
@@ -40,15 +52,12 @@
     4) subtract the radial profile
     
+    There is also support code for calculation of magnitudes and add/subtract the profile (a la pmSourceOp)
+
     TBD:
 
-    * function to replace the radial profile for a source
     * recenter the profile (based on cross-correlation / convolution with 1D profile)
-
-    * raise a bit somewhere for these super saturated stars (if they were so modeled)
-    * consider the subtraction bit : when to raise it?
-
  **/
 
-bool psphotDeblendSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int fileIndex) {
+bool psphotDeblendSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int fileIndex, psMetadata *recipe) {
 
     int N;
@@ -75,8 +84,4 @@
 	return true;
     }
-
-    // select the appropriate recipe information
-    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
-    psAssert (recipe, "missing recipe?");
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
@@ -448,4 +453,6 @@
     // XXX do something sensible here if the profile is crap
 
+    // replace an existing profile
+    psFree (source->satstar);
     source->satstar = pmSourceSatstarAlloc();
     source->satstar->Xo = Xo;
Index: /branches/eam_branches/ipp-20120905/psphot/src/psphotStackReadout.c
===================================================================
--- /branches/eam_branches/ipp-20120905/psphot/src/psphotStackReadout.c	(revision 34415)
+++ /branches/eam_branches/ipp-20120905/psphot/src/psphotStackReadout.c	(revision 34416)
@@ -169,4 +169,22 @@
     }
 
+    // If DET and SRC are different images, subtract radial profiles for the convolved
+    // image first.  The profiles found on the convolved image will be replaced by those
+    // found for the unconvolved image.  Downstream, in psphotFindDetections, we will
+    // replace the the profiles (and re-subtract them) for the detection image, so we want
+    // to keep those versions of the profiles on the sources.
+    if (strcmp(STACK_SRC, STACK_DET)) {
+      // find and subtract radial profile models for saturated stars (XXX change name eventually)
+      if (!psphotDeblendSatstars (config, view, STACK_SRC)) {
+	psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
+	return psphotReadoutCleanup (config, view, STACK_SRC);
+      }
+    }
+    // find and subtract radial profile models for saturated stars (XXX change name eventually)
+    if (!psphotDeblendSatstars (config, view, STACK_DET)) {
+	psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
+	return psphotReadoutCleanup (config, view, STACK_SRC);
+    }
+
     // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources)
     // only run this on detections from the input images, not chisq image
@@ -206,8 +224,8 @@
     // window of size PSF_MOMENTS_RADIUS (same window used to measure the psf-scale moments)
     // but iterates to an appropriately larger size
-        logMemStats("before.kron.1");
+    logMemStats("before.kron.1");
     psphotKronIterate(config, view, STACK_SRC, 1);
-        logMemStats("after.kron.1");
-
+    logMemStats("after.kron.1");
+	
     // identify CRs and extended sources
     psphotSourceSize (config, view, STACK_SRC, true);
