Index: /branches/eam_rel9_p0/psModules/src/objects/pmPSF.c
===================================================================
--- /branches/eam_rel9_p0/psModules/src/objects/pmPSF.c	(revision 5986)
+++ /branches/eam_rel9_p0/psModules/src/objects/pmPSF.c	(revision 5987)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.3.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-01-10 04:46:03 $
+ *  @version $Revision: 1.3.4.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-01-14 07:03:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -57,4 +57,6 @@
         return;
 
+    psFree (psf->ApTrend);
+    psFree (psf->growth);
     psFree (psf->params);
     return;
@@ -83,24 +85,12 @@
     psf->dApResid = 0.0;
     psf->skyBias  = 0.0;
-
-    // the ApTrend components are (x, y, rflux)
-    psf->ApTrend = psPolynomial3DAlloc (2, 2, 1, PS_POLYNOMIAL_ORD);
-
-    // we do not allow any rflux vs X,Y cross-terms
-    psf->ApTrend->mask[0][1][1] = 1;  // rflux x^0 y^1
-    psf->ApTrend->mask[0][2][1] = 1;  // rflux x^0 y^2
-    psf->ApTrend->mask[1][0][1] = 1;  // rflux x^1 y^0
-    psf->ApTrend->mask[1][1][1] = 1;  // rflux x^1 y^1
-    psf->ApTrend->mask[1][2][1] = 1;  // rflux x^1 y^2
-    psf->ApTrend->mask[2][0][1] = 1;  // rflux x^2 y^0
-    psf->ApTrend->mask[2][1][1] = 1;  // rflux x^2 y^1
-    psf->ApTrend->mask[2][2][1] = 1;  // rflux x^2 y^2
-
-    // only 2nd order terms, no such combinations
-    psf->ApTrend->mask[2][2][0] = 1;  // x^2 y^2
-    psf->ApTrend->mask[2][1][0] = 1;  // x^2 y^1
-    psf->ApTrend->mask[1][2][0] = 1;  // x^1 y^2
-
-    // total free parameters = 18 - 11 = 7
+    psf->skySat   = 0.0;
+
+    // the ApTrend components are (x, y, r2rflux, flux)
+    psf->ApTrend = psPolynomial4DAlloc (2, 2, 1, 1, PS_POLYNOMIAL_ORD);
+    pmPSF_MaskApTrend (psf, PM_PSF_SKYBIAS);
+
+    // don't define a growth curve : user needs to choose radius bins
+    psf->growth = NULL;
 
     Nparams = pmModelParameterCount (type);
@@ -208,2 +198,100 @@
     return (modelPSF);
 }
+
+// zero and mask out all terms:
+static bool maskAllTerms (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;
+}
+
+/***********************************************
+ * this function masks the psf.ApTrend polynomial 
+ * to enable the specific subset of the coefficients
+ **********************************************/
+bool pmPSF_MaskApTrend (pmPSF *psf, pmPSF_ApTrendOptions option)
+{
+
+    switch (option) {
+    case PM_PSF_NONE:
+        maskAllTerms (psf->ApTrend);
+        return true;
+
+    case PM_PSF_CONSTANT:
+        maskAllTerms (psf->ApTrend);
+        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
+        return true;
+
+    case PM_PSF_SKYBIAS:
+        maskAllTerms (psf->ApTrend);
+        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
+        psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
+        return true;
+
+    case PM_PSF_SKYSAT:
+        maskAllTerms (psf->ApTrend);
+        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
+        psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
+        psf->ApTrend->mask[0][0][0][1] = 0;  // unmask skybias
+        return true;
+
+    case PM_PSF_XY_LIN:
+        maskAllTerms (psf->ApTrend);
+        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
+        psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
+        psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
+        return true;
+
+    case PM_PSF_XY_QUAD:
+        maskAllTerms (psf->ApTrend);
+        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
+        psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
+        psf->ApTrend->mask[2][0][0][0] = 0;  // unmask x^2
+        psf->ApTrend->mask[1][1][0][0] = 0;  // unmask x y
+        psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
+        psf->ApTrend->mask[0][2][0][0] = 0;  // unmask y^2
+        return true;
+
+    case PM_PSF_SKY_XY_LIN:
+        maskAllTerms (psf->ApTrend);
+        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
+        psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
+        psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
+        psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
+        return true;
+
+    case PM_PSF_SKYSAT_XY_LIN:
+        maskAllTerms (psf->ApTrend);
+        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
+        psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
+        psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
+        psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
+        psf->ApTrend->mask[0][0][0][1] = 0;  // unmask skysat
+        return true;
+
+    case PM_PSF_ALL:
+    default:
+        maskAllTerms (psf->ApTrend);
+        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
+        psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
+        psf->ApTrend->mask[0][0][0][1] = 0;  // unmask skysat
+
+        psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
+        psf->ApTrend->mask[2][0][0][0] = 0;  // unmask x^2
+        psf->ApTrend->mask[1][1][0][0] = 0;  // unmask x y
+        psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
+        psf->ApTrend->mask[0][2][0][0] = 0;  // unmask y^2
+        return true;
+    }
+    return false;
+}
