Index: trunk/psphot/src/psphotSourceStats.c
===================================================================
--- trunk/psphot/src/psphotSourceStats.c	(revision 27570)
+++ trunk/psphot/src/psphotSourceStats.c	(revision 27571)
@@ -16,8 +16,8 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotSourceStatsReadout (config, view, "PSPHOT.INPUT", i, recipe, setWindow)) {
+        if (!psphotSourceStatsReadout (config, view, "PSPHOT.INPUT", i, recipe, setWindow)) {
             psError (PSPHOT_ERR_CONFIG, false, "failed to find initial detections for PSPHOT.INPUT entry %d", i);
-	    return false;
-	}
+            return false;
+        }
     }
     return true;
@@ -44,8 +44,8 @@
     // XXX TEST:
     if (detections->allSources) {
-	psphotMaskCosmicRayFootprintCheck(detections->allSources);
+        psphotMaskCosmicRayFootprintCheck(detections->allSources);
     }
     if (detections->newSources) {
-	psphotMaskCosmicRayFootprintCheck(detections->newSources);
+        psphotMaskCosmicRayFootprintCheck(detections->newSources);
     }
 
@@ -88,7 +88,7 @@
     // if there are no peaks, we save the empty source array and return
     if (!peaks->n) {
-	// save the new sources on the detection structure:
-	detections->newSources = sources;
-	return true;
+        // save the new sources on the detection structure:
+        detections->newSources = sources;
+        return true;
     }
 
@@ -119,5 +119,5 @@
         psLogMsg ("psphot", PS_LOG_INFO, "break point PEAKS, skipping MOMENTS\n");
         psphotVisualShowMoments (sources);
-	detections->newSources = sources;
+        detections->newSources = sources;
         return true;
     }
@@ -126,5 +126,5 @@
         if (!psphotSetMomentsWindow(recipe, readout->analysis, sources)) {
             psError(PS_ERR_UNEXPECTED_NULL, false, "Failed to determine Moments Window!");
-	    psFree(sources);
+            psFree(sources);
             return false;
         }
@@ -134,9 +134,9 @@
     float SIGMA = psMetadataLookupF32 (&status, readout->analysis, "MOMENTS_GAUSS_SIGMA");
     if (!status) {
-	SIGMA = psMetadataLookupF32 (&status, recipe, "MOMENTS_GAUSS_SIGMA");
+        SIGMA = psMetadataLookupF32 (&status, recipe, "MOMENTS_GAUSS_SIGMA");
     }
     float RADIUS = psMetadataLookupF32 (&status, readout->analysis, "PSF_MOMENTS_RADIUS");
     if (!status) {
-	RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS");
+        RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS");
     }
 
@@ -178,5 +178,5 @@
                 psError(PS_ERR_UNKNOWN, false, "Unable to launch thread job PSPHOT_SOURCE_STATS");
                 psFree (job);
-		psFree(sources);
+                psFree(sources);
                 return false;
             }
@@ -187,5 +187,5 @@
         if (!psThreadPoolWait (false)) {
             psError(PS_ERR_UNKNOWN, false, "Failure in thread job PSPHOT_SOURCE_STATS");
-	    psFree(sources);
+            psFree(sources);
             return false;
         }
@@ -220,8 +220,8 @@
 
     if (detections->allSources) {
-	psphotMaskCosmicRayFootprintCheck(detections->allSources);
+        psphotMaskCosmicRayFootprintCheck(detections->allSources);
     }
     if (detections->newSources) {
-	psphotMaskCosmicRayFootprintCheck(detections->newSources);
+        psphotMaskCosmicRayFootprintCheck(detections->newSources);
     }
 
@@ -229,5 +229,5 @@
 }
 
-// this function is currently only called by psphotCheckExtSources 
+// this function is currently only called by psphotCheckExtSources
 bool psphotSourceStatsUpdate (psArray *sources, pmConfig *config, pmReadout *readout) {
 
@@ -261,7 +261,7 @@
 
         // allocate space for moments
-	if (!source->moments) {
-	    source->moments = pmMomentsAlloc();
-	}
+        if (!source->moments) {
+            source->moments = pmMomentsAlloc();
+        }
 
         // allocate image, weight, mask arrays for each peak (square of radius OUTER)
@@ -279,6 +279,6 @@
     // XXX how else could we get the window size in?
     if (!psphotSetMomentsWindow(recipe, readout->analysis, sources)) {
-	psError(PS_ERR_UNEXPECTED_NULL, false, "Failed to determine Moments Window!");
-	return NULL;
+        psError(PS_ERR_UNEXPECTED_NULL, false, "Failed to determine Moments Window!");
+        return NULL;
     }
 
@@ -303,5 +303,5 @@
             psThreadJob *job = psThreadJobAlloc ("PSPHOT_SOURCE_STATS");
 
-	    // XXX: this must match the above
+            // XXX: this must match the above
             psArrayAdd(job->args, 1, cells->data[j]); // sources
             psArrayAdd(job->args, 1, recipe);
@@ -515,5 +515,6 @@
     if (maxS < 0.65) Sigma = sigma[0];
 
-    for (int i = 0; i < NSIGMA - 1; i++) {
+    for (int i = 0; i < NSIGMA - 1 && isnan(Sigma); i++) {
+        if (!isfinite(Sout[i]) || !isfinite(Sout[i+1])) continue;
         if ((Sout[i] > 0.65) && (Sout[i+1] > 0.65)) continue;
         if ((Sout[i] < 0.65) && (Sout[i+1] < 0.65)) continue;
