Index: /branches/eam_branch_20070830/psModules/src/objects/pmTrend2D.c
===================================================================
--- /branches/eam_branch_20070830/psModules/src/objects/pmTrend2D.c	(revision 14910)
+++ /branches/eam_branch_20070830/psModules/src/objects/pmTrend2D.c	(revision 14911)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-07 20:24:34 $
+ *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-09-20 19:21:13 $
  *
  *  Copyright 2004 Institute for Astronomy, University of Hawaii
@@ -30,4 +30,7 @@
 pmTrend2D *pmTrend2DAlloc (pmTrend2DMode mode, psImage *image, int nXtrend, int nYtrend, psStats *stats)
 {
+    assert (image);
+    assert (stats);
+
     pmTrend2D *trend = (pmTrend2D *) psAlloc(sizeof(pmTrend2D));
     psMemSetDeallocator(trend, (psFreeFunc) pmTrend2DFree);
@@ -50,8 +53,8 @@
 	  // binning defines the map scale relationship
 	  psImageBinning *binning = psImageBinningAlloc();
+	  binning->nXruff = nXtrend;
+	  binning->nYruff = nYtrend;
 	  binning->nXfine = image->numCols;
 	  binning->nYfine = image->numRows;
-	  binning->nXruff = nXtrend;
-	  binning->nYruff = nYtrend;
 
 	  trend->map = psImageMapAlloc (image, binning, stats);
@@ -104,14 +107,12 @@
 }
 
-bool pmTrend2DFit (pmTrend2D *trend, psVector *x, psVector *y, psVector *f, psVector *df) {
+bool pmTrend2DFit (pmTrend2D *trend, psVector *mask, psMaskType maskVal, psVector *x, psVector *y, psVector *f, psVector *df) {
 
     bool status;
-
-    psVector *mask = psVectorAlloc (x->n, PS_TYPE_MASK);
 
     switch (trend->mode) {
       case PM_TREND_POLY_ORD:
       case PM_TREND_POLY_CHEB:
-        status = psVectorClipFitPolynomial2D (trend->poly, trend->stats, mask, 0xff, f, df, x, y);
+        status = psVectorClipFitPolynomial2D (trend->poly, trend->stats, mask, maskVal, f, df, x, y);
 	// we can use the API here which adjusts the polynomial order based on the number
 	// of points in the image, and potentially based on the fractional range of the
@@ -121,5 +122,6 @@
       case PM_TREND_MAP:
 	// XXX supply fraction from trend elements
-	status = psImageMapGenerateScale (trend->map, x, y, f, df, 0.1);
+	// XXX need to add the API which adjusts the scale
+	status = psImageMapClipFit (trend->map, trend->stats, mask, maskVal, x, y, f, df);
 	break;
 
@@ -127,5 +129,4 @@
 	psAbort ("error");
     }
-    psFree (mask);
     return status;
 }
