Index: /trunk/psLib/src/math/psStats.c
===================================================================
--- /trunk/psLib/src/math/psStats.c	(revision 12607)
+++ /trunk/psLib/src/math/psStats.c	(revision 12608)
@@ -13,6 +13,6 @@
  * use ->min and ->max (PS_STAT_USE_RANGE)
  *
- *  @version $Revision: 1.204 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-03-19 22:48:11 $
+ *  @version $Revision: 1.205 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-03-28 00:49:13 $
  *
  *  Copyright 2006 IfA, University of Hawaii
@@ -746,9 +746,8 @@
         // ADD step 4: Find the bins which contains the 15.8655% (-1 sigma) and 84.1345% (+1 sigma) data points
         // also find the 30.8538% (-0.5 sigma) and 69.1462% (+0.5 sigma) points
-        PS_BIN_FOR_VALUE(binLo, cumulative->nums, totalDataPoints * 0.158655f, -1);
-        PS_BIN_FOR_VALUE(binHi, cumulative->nums, totalDataPoints * 0.841345f, +1);
-
-        PS_BIN_FOR_VALUE(binL2, cumulative->nums, totalDataPoints * 0.308538f, -1);
-        PS_BIN_FOR_VALUE(binH2, cumulative->nums, totalDataPoints * 0.691462f, +1);
+        PS_BIN_FOR_VALUE(binLo, cumulative->nums, totalDataPoints * 0.158655f, 0);
+        PS_BIN_FOR_VALUE(binHi, cumulative->nums, totalDataPoints * 0.841345f, 0);
+        PS_BIN_FOR_VALUE(binL2, cumulative->nums, totalDataPoints * 0.308538f, 0);
+        PS_BIN_FOR_VALUE(binH2, cumulative->nums, totalDataPoints * 0.691462f, 0);
 
         psTrace("psLib.math", 6, "The 15.8655%% and 84.1345%% data point bins are (%ld, %ld).\n",
@@ -756,4 +755,6 @@
         psTrace("psLib.math", 6, "binLo midpoint is %f\n", PS_BIN_MIDPOINT(cumulative, binLo));
         psTrace("psLib.math", 6, "binHi midpoint is %f\n", PS_BIN_MIDPOINT(cumulative, binHi));
+        psTrace("psLib.math", 6, "binL2 midpoint is %f\n", PS_BIN_MIDPOINT(cumulative, binL2));
+        psTrace("psLib.math", 6, "binH2 midpoint is %f\n", PS_BIN_MIDPOINT(cumulative, binH2));
 
         if ((binLo < 0) || (binHi < 0)) {
@@ -988,6 +989,6 @@
         // select the min and max bins, saturating on the lower and upper end-points
         long binMin, binMax;
-        PS_BIN_FOR_VALUE (binMin, histogram->bounds, guessMean - minFitSigma*guessStdev, -1);
-        PS_BIN_FOR_VALUE (binMax, histogram->bounds, guessMean + maxFitSigma*guessStdev, +1);
+        PS_BIN_FOR_VALUE (binMin, histogram->bounds, guessMean - minFitSigma*guessStdev, 0);
+        PS_BIN_FOR_VALUE (binMax, histogram->bounds, guessMean + maxFitSigma*guessStdev, 0);
 
         // Generate the variables that will be used in the Gaussian fitting
@@ -1166,6 +1167,6 @@
         // select the min and max bins, saturating on the lower and upper end-points
         long binMin, binMax;
-        PS_BIN_FOR_VALUE (binMin, histogram->bounds, guessMean - minFitSigma*guessStdev, -1);
-        PS_BIN_FOR_VALUE (binMax, histogram->bounds, guessMean + maxFitSigma*guessStdev, +1);
+        PS_BIN_FOR_VALUE (binMin, histogram->bounds, guessMean - minFitSigma*guessStdev, 0);
+        PS_BIN_FOR_VALUE (binMax, histogram->bounds, guessMean + maxFitSigma*guessStdev, 0);
 
         // Generate the variables that will be used in the Gaussian fitting
@@ -1359,6 +1360,9 @@
         // select the min and max bins, saturating on the lower and upper end-points
         long binMin, binMax;
-        PS_BIN_FOR_VALUE (binMin, histogram->bounds, guessMean - minFitSigma*guessStdev, -1);
-        PS_BIN_FOR_VALUE (binMax, histogram->bounds, guessMean + maxFitSigma*guessStdev, +1);
+        PS_BIN_FOR_VALUE (binMin, histogram->bounds, guessMean - minFitSigma*guessStdev, 0);
+        PS_BIN_FOR_VALUE (binMax, histogram->bounds, guessMean + maxFitSigma*guessStdev, 0);
+	if (binMin == binMax) {
+	    psAbort ("invalid range for fitted mean");   
+	}
 
         // search for mode (peak of histogram within range mean-2sigma - mean+2sigma
