Index: trunk/psModules/src/objects/pmPSF.c
===================================================================
--- trunk/psModules/src/objects/pmPSF.c	(revision 14652)
+++ trunk/psModules/src/objects/pmPSF.c	(revision 14936)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-24 00:11:02 $
+ *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-09-21 00:05:35 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -29,4 +29,5 @@
 #include "pmResiduals.h"
 #include "pmGrowthCurve.h"
+#include "pmTrend2D.h"
 #include "pmPSF.h"
 #include "pmModel.h"
@@ -108,10 +109,8 @@
     psf->poissonErrors = poissonErrors;
 
-    // the ApTrend components are (x, y, r2rflux, flux)
-    // the ApTrend order is defined by the masking
-    // initially we set it to SKYBIAS (no X,Y variation)
-    // this is adjusted in psphotApResid based on the user's choices
-    psf->ApTrend = psPolynomial4DAlloc (PS_POLYNOMIAL_ORD, 2, 2, 1, 1);
-    pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
+    // the ApTrend components are (x, y).  It may be represented with a polynomial or with a
+    // psImageMap.  We set it initially to NULL. the user must allocate it before using.
+    // psf->ApTrend = pmTrend2DAlloc (PM_TREND_MAP, Nx, Ny, 1, 1, stats);
+    psf->ApTrend = NULL;
 
     if (psf->poissonErrors) {
@@ -166,21 +165,4 @@
 }
 
-// zero and mask out all terms:
-static bool maskAllApTerms (psPolynomial4D *trend)
-{
-
-    for (int i = 0; i < trend->nX + 1; i++) {
-        for (int j = 0; j < trend->nY + 1; j++) {
-            for (int k = 0; k < trend->nZ + 1; k++) {
-                for (int m = 0; m < trend->nT + 1; m++) {
-                    trend->mask[i][j][k][m] = 1;  // mask coeff
-                    trend->coeff[i][j][k][m] = 0;  // zero coeff
-                }
-            }
-        }
-    }
-    return true;
-}
-
 // the PSF models the \sigma_{xy} variation of the elliptical contour as a function of position in the image with a
 // polynomial.  an individual object has a contour of the form (x^2/2sx^2) + (y^2/2sy^2) + sxy*x*y
@@ -344,113 +326,4 @@
 }
 
-/***********************************************
- * this function masks the psf.ApTrend polynomial
- * to enable the specific subset of the coefficients
- **********************************************/
-bool pmPSFMaskApTrend (psPolynomial4D *trend,
-                       pmPSFApTrendOptions option)
-{
-
-    switch (option) {
-    case PM_PSF_APTREND_NONE:
-        maskAllApTerms (trend);
-        return true;
-
-    case PM_PSF_APTREND_CONSTANT:
-        maskAllApTerms (trend);
-        trend->mask[0][0][0][0] = 0;  // unmask constant
-        return true;
-
-    case PM_PSF_APTREND_SKYBIAS:
-        maskAllApTerms (trend);
-        trend->mask[0][0][0][0] = 0;  // unmask constant
-        trend->mask[0][0][1][0] = 0;  // unmask skybias
-        return true;
-
-    case PM_PSF_APTREND_SKYSAT:
-        maskAllApTerms (trend);
-        trend->mask[0][0][0][0] = 0;  // unmask constant
-        trend->mask[0][0][1][0] = 0;  // unmask skybias
-        trend->mask[0][0][0][1] = 0;  // unmask skysat
-        return true;
-
-    case PM_PSF_APTREND_XY_LIN:
-        maskAllApTerms (trend);
-        trend->mask[0][0][0][0] = 0;  // unmask constant
-        trend->mask[1][0][0][0] = 0;  // unmask x
-        trend->mask[0][1][0][0] = 0;  // unmask y
-        return true;
-
-    case PM_PSF_APTREND_XY_QUAD:
-        maskAllApTerms (trend);
-        trend->mask[0][0][0][0] = 0;  // unmask constant
-        trend->mask[1][0][0][0] = 0;  // unmask x
-        trend->mask[2][0][0][0] = 0;  // unmask x^2
-        trend->mask[1][1][0][0] = 0;  // unmask x y
-        trend->mask[0][1][0][0] = 0;  // unmask y
-        trend->mask[0][2][0][0] = 0;  // unmask y^2
-        return true;
-
-    case PM_PSF_APTREND_SKY_XY_LIN:
-        maskAllApTerms (trend);
-        trend->mask[0][0][0][0] = 0;  // unmask constant
-        trend->mask[1][0][0][0] = 0;  // unmask x
-        trend->mask[0][1][0][0] = 0;  // unmask y
-        trend->mask[0][0][1][0] = 0;  // unmask skybias
-        return true;
-
-    case PM_PSF_APTREND_SKYSAT_XY_LIN:
-        maskAllApTerms (trend);
-        trend->mask[0][0][0][0] = 0;  // unmask constant
-        trend->mask[1][0][0][0] = 0;  // unmask x
-        trend->mask[0][1][0][0] = 0;  // unmask y
-        trend->mask[0][0][1][0] = 0;  // unmask skybias
-        trend->mask[0][0][0][1] = 0;  // unmask skysat
-        return true;
-
-    case PM_PSF_APTREND_ALL:
-    default:
-        maskAllApTerms (trend);
-        trend->mask[0][0][0][0] = 0;  // unmask constant
-        trend->mask[0][0][1][0] = 0;  // unmask skybias
-        trend->mask[0][0][0][1] = 0;  // unmask skysat
-
-        trend->mask[1][0][0][0] = 0;  // unmask x
-        trend->mask[2][0][0][0] = 0;  // unmask x^2
-        trend->mask[1][1][0][0] = 0;  // unmask x y
-        trend->mask[0][1][0][0] = 0;  // unmask y
-        trend->mask[0][2][0][0] = 0;  // unmask y^2
-        return true;
-    }
-    return false;
-}
-
-pmPSFApTrendOptions pmPSFApTrendOptionFromName (char *name)
-{
-
-    // no correction
-    if (!strcasecmp (name, "NONE"))
-        return PM_PSF_APTREND_NONE;
-    if (!strcasecmp (name, "CONSTANT"))
-        return PM_PSF_APTREND_CONSTANT;
-    if (!strcasecmp (name, "SKYBIAS"))
-        return PM_PSF_APTREND_SKYBIAS;
-    if (!strcasecmp (name, "SKYSAT"))
-        return PM_PSF_APTREND_SKYSAT;
-    if (!strcasecmp (name, "XY_LIN"))
-        return PM_PSF_APTREND_XY_LIN;
-    if (!strcasecmp (name, "XY_QUAD"))
-        return PM_PSF_APTREND_XY_QUAD;
-    if (!strcasecmp (name, "SKY_XY_LIN"))
-        return PM_PSF_APTREND_SKY_XY_LIN;
-    if (!strcasecmp (name, "SKYSAT_XY_LIN"))
-        return PM_PSF_APTREND_SKYSAT_XY_LIN;
-    if (!strcasecmp (name, "ALL"))
-        return PM_PSF_APTREND_ALL;
-
-    psError(PS_ERR_UNKNOWN, true, "Unknown APTREND value: %s", name);
-    return PM_PSF_APTREND_ERROR;
-}
-
 // we generate the growth curve for the center of the image with the specified psf model
 bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore, psMaskType maskVal, psMaskType mark)
