Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceStats.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceStats.c	(revision 30865)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotSourceStats.c	(revision 30866)
@@ -377,4 +377,9 @@
     psImageMaskType markVal         = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA);
 
+    // if no valid pixels, massive swing or very large Mrf, likely saturated source,
+    // try a much larger box
+    float BIG_RADIUS = 3.0*RADIUS;
+    float BIG_SIGMA  = 3.0*SIGMA;
+
     // maskVal is used to test for rejected pixels, and must include markVal
     maskVal |= markVal;
@@ -419,37 +424,17 @@
         }
 
+	// XXX how can this be set: this is raised in pmSourceRoughClass, called after this function?
 	if (source->mode & PM_SOURCE_MODE_SATSTAR) {
 	    fprintf (stderr, "satstar: %f,%f\n", source->peak->xf, source->peak->yf);
 	}
 
-        // measure basic source moments (no S/N clipping on input pixels)
-        status = pmSourceMoments (source, RADIUS, SIGMA, 0.0, maskVal);
-	// XXX moments / aperture test:
-	if (0) {
-	    // clear the mask bit and set the circular mask pixels
-	    psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
-	    psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, 4.0*source->moments->Mrf, "OR", markVal);
-	    
-	    float apMag = NAN;
-	    pmSourcePhotometryAper (&apMag, NULL, NULL, NULL, source->pixels, source->variance, source->maskObj, maskVal);
-	    fprintf (stderr, "apMag: %f, kronMag: %f\n", apMag, -2.5*log10(source->moments->KronFlux));
-
-	    // clear the mask bit
-	    psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
-	}	    
-        if (status && (source->moments->Mrf < 2.0*SIGMA)) {
-            Nmoments ++;
-            continue;
-        }
-
-        // if no valid pixels, massive swing or very large Mrf, likely saturated source,
-        // try a much larger box
-        float BIG_RADIUS = 3.0*RADIUS;
-        float BIG_SIGMA  = 3.0*SIGMA;
-
-	{ 
-	    // NOTE this is slightly sleazy, but only slightly: pmSourceRedefinePixels uses the readout
-	    // to pass the pointers to the parent image data.  I guess the API could be simplified:
-	    // we could recover this from the source in the function
+	if (!(source->peak->type == PM_PEAK_SUSPECT_SATURATION)) {
+	    // measure basic source moments (no S/N clipping on input pixels)
+	    status = pmSourceMoments (source, RADIUS, SIGMA, 0.0, maskVal);
+	} else { 
+	    // For saturated stars, choose a much larger box NOTE this is slightly sleazy, but
+	    // only slightly: pmSourceRedefinePixels uses the readout to pass the pointers to
+	    // the parent image data.  I guess the API could be simplified: we could recover
+	    // this from the source in the function
 
 	    pmReadout tmpReadout;
@@ -458,20 +443,21 @@
 	    tmpReadout.variance = (psImage *)source->variance->parent;
 
-	    // re-allocate image, weight, mask arrays for each peak (square of radius OUTER)
+	    // re-allocate image, weight, mask arrays for each peak with box big enough to fit BIG_RADIUS
 	    pmSourceRedefinePixels (source, &tmpReadout, source->peak->x, source->peak->y, BIG_RADIUS + 2);
+
+	    psTrace ("psphot", 4, "retrying moments for %d, %d\n", source->peak->x, source->peak->y);
+	    status = pmSourceMoments (source, BIG_RADIUS, BIG_SIGMA, 0.0, maskVal);
+	    source->mode |= PM_SOURCE_MODE_BIG_RADIUS;
 	}
-
-        psTrace ("psphot", 4, "retrying moments for %d, %d\n", source->peak->x, source->peak->y);
-        status = pmSourceMoments (source, BIG_RADIUS, BIG_SIGMA, 0.0, maskVal);
-        if (status) {
-            source->mode |= PM_SOURCE_MODE_BIG_RADIUS;
-            Nmoments ++;
-            continue;
-        }
-
-        source->mode |= PM_SOURCE_MODE_MOMENTS_FAILURE;
-        Nfail ++;
-        psErrorClear();
-        continue;
+	if (!status) {
+	    source->mode |= PM_SOURCE_MODE_MOMENTS_FAILURE;
+	    Nfail ++;
+	    psErrorClear();
+	    continue;
+	}
+	Nmoments ++;
+
+	// re-try big sources or not??
+	// if (source->moments->Mrf < 2.0*SIGMA)
     }
 
