Index: /branches/eam_branches/ipp-20120805/psphot/src/psphot.h
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphot.h	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphot.h	(revision 34378)
@@ -513,3 +513,10 @@
     );
 
+bool psphotSatstarProfileModel (pmSource *source, psImageMaskType maskVal);
+bool psphotSatstarProfileCreate (pmSource *source, psVector **logRmodelOut, psVector **logFmodelOut, psVector *logR, psVector *flux, float Rmax);
+bool psphotSatstarProfileOp (pmSource *source, psImageMaskType maskVal, float FACTOR, pmModelOpMode mode, bool add);
+bool psphotVisualRadialProfileSatstar (pmSource *source, psImageMaskType maskVal);
+bool psphotAddOrSubSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int fileIndex, psMetadata *recipe, bool add);
+bool psphotSatstarPhotometry (pmSource *source);
+
 #endif
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotAddNoise.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotAddNoise.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotAddNoise.c	(revision 34378)
@@ -76,7 +76,16 @@
     }
 
+    psphotVisualShowImage (readout);
+
     // loop over all source
     for (int i = 0; i < sources->n; i++) {
         pmSource *source = sources->data[i];
+
+	// add or subtract noise for a saturated star.  satstars modeled as a radial profile
+	// need special handling
+	if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) {
+	    psphotSatstarProfileOp (source, maskVal, FACTOR, PM_MODEL_OP_NOISE, add);
+	    continue;
+	}
 
         // skip sources which were not subtracted
@@ -92,4 +101,6 @@
     }
 
+    psphotVisualShowImage (readout);
+
     return true;
 }
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotApResid.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotApResid.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotApResid.c	(revision 34378)
@@ -200,4 +200,7 @@
         if (source->mode &  PM_SOURCE_MODE_FAIL) SKIPSTAR ("FAIL STAR");
         if (source->mode &  PM_SOURCE_MODE_POOR) SKIPSTAR ("POOR STAR");
+
+	// skip saturated stars modeled with a radial profile 
+        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) SKIPSTAR ("SATSTAR");
 
         if (source->mode &  PM_SOURCE_MODE_EXT_LIMIT) SKIPSTAR ("EXTENDED");
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotBlendFit.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotBlendFit.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotBlendFit.c	(revision 34378)
@@ -241,12 +241,13 @@
         pmSource *source = sources->data[i];
 
-# if (0)
-# define TEST_X 34
-# define TEST_Y 28
-   
+	int TEST_ON = false;
+# if (1)
+# define TEST_X 653
+# define TEST_Y 466
 	if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) {
 	    fprintf (stderr, "test object\n");
-	}
-
+	    //  psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
+	    TEST_ON = true;
+	}
 # undef TEST_X
 # undef TEST_Y
@@ -258,4 +259,7 @@
         if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
         if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
+
+	// skip saturated stars modeled with a radial profile 
+        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
 
         // skip DBL second sources (ie, added by psphotFitBlob
@@ -306,4 +310,7 @@
         if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
             if (psphotFitBlob (readout, source, newSources, psf, fitOptions, maskVal, markVal)) {
+		if (TEST_ON) {
+		    psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0);
+		}
                 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);
                 Next ++;
@@ -312,4 +319,7 @@
         } else {
             if (psphotFitBlend (readout, source, psf, fitOptions, maskVal, markVal)) {
+		if (TEST_ON) {
+		    psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0);
+		}
                 source->type = PM_SOURCE_TYPE_STAR;
                 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotExtendedSourceAnalysis.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotExtendedSourceAnalysis.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotExtendedSourceAnalysis.c	(revision 34378)
@@ -218,4 +218,7 @@
 	if (source->mode & PM_SOURCE_MODE_SATSTAR) continue;
 
+	// skip saturated stars modeled with a radial profile 
+        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
+
 	// optionally allow non-extended objects to get petrosians as well
 	if (!doPetroStars) {
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotExtendedSourceFits.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotExtendedSourceFits.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotExtendedSourceFits.c	(revision 34378)
@@ -317,4 +317,7 @@
         if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
         if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
+
+	// skip saturated stars modeled with a radial profile 
+        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
 
         // XXX this should use peak?
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotFindDetections.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotFindDetections.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotFindDetections.c	(revision 34378)
@@ -120,8 +120,16 @@
     if (useFootprints) {
         if (replaceSourcesForFootprints) {
+	    // subtract the noise for all sources including satstars
             psphotAddOrSubNoiseReadout(config, view, filerule, index, recipe, false);
             psphotReplaceAllSourcesReadout (config, view, filerule, index, recipe, false);
+
+	    // add in the satstars
+	    psphotAddOrSubSatstarsReadout (config, view, filerule, index, recipe, true);
+
             psFree (significance);
             significance = psphotSignificanceImage (readout, recipe, maskVal);
+
+	    // display the significance image
+	    psphotVisualShowSignificance (significance->variance, 0.98*threshold, 1.02*threshold);
         }
 
@@ -130,4 +138,7 @@
         if (replaceSourcesForFootprints) {
             psphotRemoveAllSourcesReadout (config, view, filerule, index, recipe, false);
+
+	    // subtract the satstars
+	    psphotAddOrSubSatstarsReadout (config, view, filerule, index, recipe, false);
         }
     }
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotFitSourcesLinear.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotFitSourcesLinear.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotFitSourcesLinear.c	(revision 34378)
@@ -222,4 +222,7 @@
         if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
         if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
+
+	// skip saturated stars modeled with a radial profile 
+        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
 
         // do not include CRs in the full ensemble fit
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotGuessModels.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotGuessModels.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotGuessModels.c	(revision 34378)
@@ -169,6 +169,7 @@
         source->tmpFlags |= PM_SOURCE_TMPF_MODEL_GUESS;
 
-        // skip non-astronomical objects (very likely defects)
-        if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
+        // skip non-astronomical objects (very likely defects) and satstars with profiles subtracted
+        if (source->mode  & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
+        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
         if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
         if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotKronIterate.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotKronIterate.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotKronIterate.c	(revision 34378)
@@ -309,4 +309,7 @@
 	    if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
 
+	    // skip saturated stars modeled with a radial profile 
+	    if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
+
 	    // replace object in image
 	    bool reSubtract = false;
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotMagnitudes.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotMagnitudes.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotMagnitudes.c	(revision 34378)
@@ -182,4 +182,10 @@
 	if (saveTest) {
 	    psphotSaveImage(NULL, testImage, "test.image.1.fits");
+	}
+
+	// satstars modeled as a radial profile need special handling
+	if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) {
+	    psphotSatstarPhotometry (source);
+	    continue;
 	}
 
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotRadialApertures.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotRadialApertures.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotRadialApertures.c	(revision 34378)
@@ -240,4 +240,7 @@
 	if (source->mode & PM_SOURCE_MODE_DEFECT) continue;
 
+	// skip saturated stars modeled with a radial profile 
+        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
+
 	// XXX measure radial apertures even for saturated stars
 	// if (source->mode & PM_SOURCE_MODE_SATSTAR) continue;
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotRadialProfileWings.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotRadialProfileWings.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotRadialProfileWings.c	(revision 34378)
@@ -190,4 +190,15 @@
 	if (!source->moments) continue;
 
+	// skip saturated stars modeled with a radial profile 
+        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
+
+	// skip non-detected sources matched from other images
+	if (source->mode2 & PM_SOURCE_MODE2_MATCHED) return true; // skip matched sources (no signal)
+
+	// XXX unclear if I should run this analysis on both 1st and 2nd pass for 1st pass objects,
+	// or just use the 1st pass value.  I think I should just use the 1st pass value, so skip
+	// any that have already been assigned
+	if (isfinite(source->skyRadius)) return true;
+
 	// replace object in image
 	bool reSubtract = false;
@@ -226,11 +237,4 @@
 
     // psImageMaskType **vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
-
-    // XXX unclear if I should run this analysis on both 1st and 2nd pass for 1st pass objects,
-    // or just use the 1st pass value.  I think I should just use the 1st pass value, so skip
-    // any that have already been assigned
-    if (isfinite(source->skyRadius)) return true;
-
-    if (source->mode2 & PM_SOURCE_MODE2_MATCHED) return true; // skip matched sources (no signal)
 
     // radii will be MIN_RADIUS to MAX_RADIUS in NN log steps:
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotReadout.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotReadout.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotReadout.c	(revision 34378)
@@ -143,5 +143,5 @@
     }
 
-    // find blended neighbors of very saturated stars (detections->newSources)
+    // find and subtract radial profile models for saturated stars (XXX change name eventually)
     if (!psphotDeblendSatstars (config, view, filerule)) {
 	psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
@@ -221,5 +221,5 @@
     // NOTE: this block performs the 2nd pass low-significance PSF detection stage
     { 
-	// add noise for subtracted objects
+	// add noise for subtracted objects & subtracted saturated stars
 	psphotAddNoise (config, view, filerule); // pass 1 (detections->allSources)
 
@@ -253,5 +253,4 @@
 	// merge the newly selected sources into the existing list
 	// NOTE: merge OLD and NEW
-	// XXX check on free of sources...
 	psphotMergeSources (config, view, filerule); // (detections->newSources + detections->allSources -> detections->allSources)
 
@@ -294,5 +293,4 @@
 	// merge the newly selected sources into the existing list
 	// NOTE: merge OLD and NEW
-	// XXX check on free of sources...
 	psphotMergeSources (config, view, filerule); // (detections->newSources + detections->allSources -> detections->allSources)
 
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotSourceSize.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotSourceSize.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotSourceSize.c	(revision 34378)
@@ -498,4 +498,7 @@
             continue;
         }
+
+	// skip saturated stars modeled with a radial profile 
+        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
 
         // we are classifying by moments and PSF_MAG - KRON_MAG
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotSourceStats.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotSourceStats.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotSourceStats.c	(revision 34378)
@@ -447,4 +447,7 @@
 	}
 
+	// skip saturated stars modeled with a radial profile (this probably never happens, since it is set after)
+        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
+
 	if (!(source->peak->type == PM_PEAK_SUSPECT_SATURATION)) {
 	    // measure basic source moments (no S/N clipping on input pixels)
Index: /branches/eam_branches/ipp-20120805/psphot/src/psphotVisual.c
===================================================================
--- /branches/eam_branches/ipp-20120805/psphot/src/psphotVisual.c	(revision 34377)
+++ /branches/eam_branches/ipp-20120805/psphot/src/psphotVisual.c	(revision 34378)
@@ -262,4 +262,7 @@
 }
 
+static psImage *posImage = NULL;
+static psImage *delImage = NULL;
+
 bool psphotVisualShowImage (pmReadout *readout) {
 
@@ -277,4 +280,8 @@
     psphotVisualScaleImage (kapa, readout->variance, readout->mask, "variance", 1.0, 1);
     psphotVisualScaleImage (kapa, readout->image, readout->mask, "image", sqrt(factor), 0);
+
+    if (posImage == NULL) {
+	posImage = psImageCopy (NULL, readout->image, PS_TYPE_F32);
+    }
 
     pmVisualAskUser(NULL);
@@ -2580,9 +2587,16 @@
     }
 
-    if (reshow) {
+    if (false && reshow) {
 	psphotVisualShowMask (myKapa, readout->mask, "mask", 2);
 	psphotVisualScaleImage (myKapa, readout->variance, readout->mask, "variance", 1.0, 1);
     }
-    psphotVisualScaleImage (myKapa, readout->image, readout->mask, "resid", sqrt(factor), 0);
+
+    if (posImage) {
+	delImage = (psImage *) psBinaryOp(delImage, posImage, "-", readout->image);
+	psphotVisualScaleImage (myKapa, posImage, readout->mask, "posimage", sqrt(factor), 0);
+	psphotVisualScaleImage (myKapa, delImage, readout->mask, "delimage", sqrt(factor), 2);
+    }
+
+    psphotVisualScaleImage (myKapa, readout->image, readout->mask, "resid", sqrt(factor), 1);
 
     pmVisualAskUser(NULL);
