Index: /branches/eam_branch_20070830/psLib/src/imageops/psImageMap.c
===================================================================
--- /branches/eam_branch_20070830/psLib/src/imageops/psImageMap.c	(revision 14722)
+++ /branches/eam_branch_20070830/psLib/src/imageops/psImageMap.c	(revision 14723)
@@ -7,6 +7,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-01 00:41:01 $
+ *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-09-02 02:03:58 $
  *
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
@@ -22,7 +22,10 @@
 #include "psAssert.h"
 #include "psRegion.h"
+#include "psVector.h"
 #include "psImage.h"
+#include "psStats.h"
 #include "psImageBinning.h"
 #include "psImageMap.h"
+#include "psImagePixelInterpolate.h"
 
 static void psImageMapFree(psImageMap *map) {
@@ -57,8 +60,5 @@
 
 // generate a psImageMap (or NULL) with the given number of superpixels in X and Y
-psImageMap *psImageMapGenerate (psImageMap *map, psVector *x, psVector *y, psVector *f, float badFrac) {
-
-    int nBad;
-    int nPoor;
+bool psImageMapGenerate (psImageMap *map, psVector *x, psVector *y, psVector *f, float badFrac) {
 
     psImage *mask = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_MASK);
@@ -84,14 +84,20 @@
     }
 
-    for (int iy = 0; iy < map->map->numRows; iy++) {
-	for (int ix = 0; ix < map->map->numCols; ix++) {
+    int Nx = map->map->numCols;
+    int Ny = map->map->numRows;
+    for (int iy = 0; iy < Ny; iy++) {
+	for (int ix = 0; ix < Nx; ix++) {
     
 	    // select the vector
 	    psVector *vector = vectors->data[ix + iy*Nx];
-	    
+
+	    // reset the stats to avoid contamination from the previous loop
+	    psStatsInit (map->stats);
+
 	    // get the value
-	    if (psVectorStats (stats, vector, NULL, NULL, 0)) {
+	    if (psVectorStats (map->stats, vector, NULL, NULL, 0)) {
 		mask->data.U8[iy][ix] = 0;
-		map->map->data.F32[iy][ix] = stats->robustMedian; // XXX select correct stats
+		// XXX ensure only one option is selected, or save both position and width
+		map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options); 
 	    } else {
 		mask->data.U8[iy][ix] = 1;
@@ -102,6 +108,6 @@
     psImage *state = psImagePixelInterpolateState (&map->nBad, &map->nPoor, mask, 0xff);
     map->nGood = mask->numCols * mask->numRows - map->nBad - map->nPoor;
-    if (nBad > badFrac * mask->numCols * mask->numRows) {
-	return false:
+    if (map->nBad > badFrac * mask->numCols * mask->numRows) {
+	return false;
     }
 
Index: /branches/eam_branch_20070830/psLib/src/imageops/psImageMap.h
===================================================================
--- /branches/eam_branch_20070830/psLib/src/imageops/psImageMap.h	(revision 14722)
+++ /branches/eam_branch_20070830/psLib/src/imageops/psImageMap.h	(revision 14723)
@@ -7,6 +7,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-01 00:41:01 $
+ *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-09-02 02:03:58 $
  *
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
@@ -27,5 +27,5 @@
     psImage *map;
     psImage *field;
-    psImageMap *binning;
+    psImageBinning *binning;
     int nBad;
     int nPoor;
@@ -36,5 +36,5 @@
 
 // generate a psImageMap (or NULL) with the given number of superpixels in X and Y
-psImageMap *psImageMapGenerate (psImageMap *map, psVector *x, psVector *y, psVector *f, float badFrac);
+bool psImageMapGenerate (psImageMap *map, psVector *x, psVector *y, psVector *f, float badFrac);
 
 /// @}
Index: /branches/eam_branch_20070830/psLib/src/imageops/psImagePixelInterpolate.c
===================================================================
--- /branches/eam_branch_20070830/psLib/src/imageops/psImagePixelInterpolate.c	(revision 14722)
+++ /branches/eam_branch_20070830/psLib/src/imageops/psImagePixelInterpolate.c	(revision 14723)
@@ -11,6 +11,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-01 00:41:01 $
+ *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-09-02 02:03:58 $
  *
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
@@ -32,18 +32,21 @@
 #include "psAssert.h"
 #include "psString.h"
+#include "psPolynomial.h"
+#include "psPolynomialUtils.h"
 #include "psImage.h"
 #include "psImageInterpolate.h"
+#include "psImagePixelInterpolate.h"
 
 # define PS_IMAGE_ITER_STATE(XS,XE,YS,YE,N_MIN,TYPE) \
 	    nGood = 0; \
-	    for (jy = YS; jy <= YE; jy++) { \
-		// stick to pixels in image grid \
+	    for (int jy = YS; jy <= YE; jy++) { \
+		/* stick to pixels in image grid */ \
 		if (jy + iy < 0) { continue; } \
 		if (jy + iy >= mask->numRows) { continue; } \
-		for (jx = XS; jx <= XE; jx++) { \
-		    // stick to pixels in image grid \
+		for (int jx = XS; jx <= XE; jx++) { \
+		    /* stick to pixels in image grid */ \
 		    if (jx + ix < 0) { continue; } \
 		    if (jx + ix >= mask->numCols) { continue; } \
-		    // do not test self \
+		    /* do not test self */ \
 		    if (!jx && jy) { continue; } \
 		    if (mask->data.PS_TYPE_MASK_DATA[iy][ix] & maskVal) { continue; } \
@@ -66,6 +69,6 @@
     psImageInit (result, 0);
     
-    int nPoor = 0;
-    int nBad = 0;
+    *nPoor = 0;
+    *nBad = 0;
 
     for (int iy = 0; iy < mask->numRows; iy++) {
@@ -103,45 +106,52 @@
 	      case PS_IMAGE_INTERPOLATE_GOOD: 
 		// skip the good pixels
-		continue; 
+		break; 
 
 	      case PS_IMAGE_INTERPOLATE_BAD:
 		// skip the bad pixels
-		continue; 
+		break; 
 
-	      case PS_IMAGE_INTERPOLATE_CENTER:
-		// fit a quadratic to the valid neighbor pixels
-		// apply the quadratic to get the poor pixel value
-		psPolynomial2D *poly = psImageBicubeFit (image, mask, maskVal, ix, iy);
-		image->data.F32[iy][ix] = poly->coeff[0][0];
-		continue;
+	      case PS_IMAGE_INTERPOLATE_CENTER: {
+		  // fit a quadratic to the valid neighbor pixels
+		  // apply the quadratic to get the poor pixel value
+		  psPolynomial2D *poly = psImageBicubeFit (image, mask, maskVal, ix, iy);
+		  image->data.F32[iy][ix] = poly->coeff[0][0];
+		  break; }
 
-	      case PS_IMAGE_INTERPOLATE_LL:
-		// fit a plane to the valid neighbor pixels
-		// apply the plane to get the poor pixel value
-		psPolynomial2D *poly = psImageBilinearFit (image, mask, maskVal, ix - 1, iy - 1);
-		image->data.F32[iy][ix] = poly->coeff[0][0] + poly->coeff[1][0] + poly->coeff[0][1];
-		continue;
-	      case PS_IMAGE_INTERPOLATE_LR:
-		// fit a plane to the valid neighbor pixels
-		// apply the plane to get the poor pixel value
-		psPolynomial2D *poly = psImageBilinearFit (image, mask, maskVal, ix - 0, iy - 1);
-		image->data.F32[iy][ix] = poly->coeff[0][0] + poly->coeff[0][1];
-		continue;
-	      case PS_IMAGE_INTERPOLATE_UL:
-		// fit a plane to the valid neighbor pixels
-		// apply the plane to get the poor pixel value
-		psPolynomial2D *poly = psImageBilinearFit (image, mask, maskVal, ix - 1, iy - 0);
-		image->data.F32[iy][ix] = poly->coeff[0][0] + poly->coeff[1][0];
-		continue;
-	      case PS_IMAGE_INTERPOLATE_UR:
-		// fit a plane to the valid neighbor pixels
-		// apply the plane to get the poor pixel value
-		psPolynomial2D *poly = psImageBilinearFit (image, mask, maskVal, ix - 0, iy - 0);
-		image->data.F32[iy][ix] = poly->coeff[0][0];
-		continue;
+	      case PS_IMAGE_INTERPOLATE_LL: {
+		  // fit a plane to the valid neighbor pixels
+		  // apply the plane to get the poor pixel value
+		  psPolynomial2D *poly = psImageBilinearFit (image, mask, maskVal, ix - 1, iy - 1);
+		  image->data.F32[iy][ix] = poly->coeff[0][0] + poly->coeff[1][0] + poly->coeff[0][1];
+		  break; }
+
+	      case PS_IMAGE_INTERPOLATE_LR: {
+		  // fit a plane to the valid neighbor pixels
+		  // apply the plane to get the poor pixel value
+		  psPolynomial2D *poly = psImageBilinearFit (image, mask, maskVal, ix - 0, iy - 1);
+		  image->data.F32[iy][ix] = poly->coeff[0][0] + poly->coeff[0][1];
+		  break; }
+
+	      case PS_IMAGE_INTERPOLATE_UL: {
+		  // fit a plane to the valid neighbor pixels
+		  // apply the plane to get the poor pixel value
+		  psPolynomial2D *poly = psImageBilinearFit (image, mask, maskVal, ix - 1, iy - 0);
+		  image->data.F32[iy][ix] = poly->coeff[0][0] + poly->coeff[1][0];
+		  break; }
+
+	      case PS_IMAGE_INTERPOLATE_UR: {
+		  // fit a plane to the valid neighbor pixels
+		  // apply the plane to get the poor pixel value
+		  psPolynomial2D *poly = psImageBilinearFit (image, mask, maskVal, ix - 0, iy - 0);
+		  image->data.F32[iy][ix] = poly->coeff[0][0];
+		  break; }
+
+	      default:
+		psAbort("impossible case in __func__");
 	    }
 	}	    
     }
-    return result;
+    return true;
 }
 
+    
Index: /branches/eam_branch_20070830/psLib/src/math/psStats.c
===================================================================
--- /branches/eam_branch_20070830/psLib/src/math/psStats.c	(revision 14722)
+++ /branches/eam_branch_20070830/psLib/src/math/psStats.c	(revision 14723)
@@ -13,6 +13,6 @@
  * use ->min and ->max (PS_STAT_USE_RANGE)
  *
- *  @version $Revision: 1.215 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-08 21:31:42 $
+ *  @version $Revision: 1.215.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-09-02 02:03:58 $
  *
  *  Copyright 2006 IfA, University of Hawaii
@@ -1748,4 +1748,22 @@
     psStats *stats = p_psAlloc(file, lineno, func, sizeof(psStats));
     psMemSetDeallocator(stats, (psFreeFunc)statsFree);
+
+    // set initial, default values
+    psStatsInit (stats);
+
+    // these values are can be set as desired by the user.  they are not affected by
+    // psStatsInit
+    stats->clipSigma = 3.0;
+    stats->clipIter = 3;
+    stats->nSubsample = 100000;
+    stats->options = options;
+
+    psTrace(TRACE, 3, "---- %s() end  ----\n", __func__);
+    return stats;
+}
+
+// reset the values which are output, and which may be used from one psStats stage to the next
+void psStatsInit(psStats *stats)
+{
     stats->sampleMean = NAN;
     stats->sampleMedian = NAN;
@@ -1766,14 +1784,8 @@
     stats->clippedStdev = NAN;
     stats->clippedNvalues = -1;     // XXX: This is never used
-    stats->clipSigma = 3.0;
-    stats->clipIter = 3;
     stats->min = NAN;
     stats->max = NAN;
     stats->binsize = NAN;
-    stats->nSubsample = 100000;
-    stats->options = options;
-
-    psTrace(TRACE, 3, "---- %s() end  ----\n", __func__);
-    return stats;
+    return;
 }
 
Index: /branches/eam_branch_20070830/psLib/src/math/psStats.h
===================================================================
--- /branches/eam_branch_20070830/psLib/src/math/psStats.h	(revision 14722)
+++ /branches/eam_branch_20070830/psLib/src/math/psStats.h	(revision 14723)
@@ -8,6 +8,6 @@
  * @author GLG, MHPCC
  *
- * @version $Revision: 1.62 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-08-09 01:40:07 $
+ * @version $Revision: 1.62.2.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-09-02 02:03:58 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -131,4 +131,7 @@
 );
 
+// reset the values which are output, and which may be used from one psStats stage to the next
+void psStatsInit(psStats *stats);
+
 // Get the statistics option from a string
 psStatsOptions psStatsOptionFromString(const char *string);
