Index: /branches/eam_branch_20070921/psModules/src/objects/pmPSF.c
===================================================================
--- /branches/eam_branch_20070921/psModules/src/objects/pmPSF.c	(revision 14968)
+++ /branches/eam_branch_20070921/psModules/src/objects/pmPSF.c	(revision 14969)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 02:46:25 $
+ *  @version $Revision: 1.28.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-09-21 18:55:11 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -64,4 +64,20 @@
 /*****************************************************************************/
 
+static void pmPSFOptionsFree (pmPSFOptions *options) {
+
+    return;
+}
+
+pmPSFOptions *pmPSFOptionsAlloc () {
+
+    pmPSFOptions *options = (pmPSFOptions *) psAlloc(sizeof(pmPSFOptions));
+
+    options->type          = 0;
+    options->poissonErrors = false;
+    options->psfTrendMode  = PM_TREND_MAP;
+    options->psfTrendNx    = 0;
+    options->psfTrendNy    = 0;
+}
+
 /*****************************************************************************
 pmPSFFree(psf): function to free a pmPSF structure
@@ -94,5 +110,5 @@
  Object Normalization
  *****************************************************************************/
-pmPSF *pmPSFAlloc (pmModelType type, bool poissonErrors, psPolynomial2D *psfTrendMask)
+pmPSF *pmPSFAlloc (pmPSFOptions *options)
 {
     int Nparams;
@@ -100,5 +116,5 @@
     pmPSF *psf = (pmPSF *) psAlloc(sizeof(pmPSF));
 
-    psf->type     = type;
+    psf->type     = options->type;
     psf->chisq    = 0.0;
     psf->ApResid  = 0.0;
@@ -108,5 +124,5 @@
     psf->nPSFstars  = 0;
     psf->nApResid   = 0;
-    psf->poissonErrors = poissonErrors;
+    psf->poissonErrors = options->poissonErrors;
 
     // the ApTrend components are (x, y).  It may be represented with a polynomial or with a
@@ -147,4 +163,5 @@
     // PM_PAR_XPOS, etc)
 
+    // XXX define new structure to carry in the psf options
     if (psfTrendMask) {
         for (int i = 0; i < psf->params->n; i++) {
@@ -158,10 +175,6 @@
                 continue;
 
-            psPolynomial2D *param = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, psfTrendMask->nX, psfTrendMask->nY);
-            for (int nx = 0; nx < param->nX + 1; nx++) {
-                for (int ny = 0; ny < param->nY + 1; ny++) {
-                    param->mask[nx][ny] = psfTrendMask->mask[nx][ny];
-                }
-            }
+	    // XXX need to set stats, image
+	    pmTrend2D *param = pmTrend2DAlloc (options->psfTrendMode, image, options->psfTrendNx, options->psfTrendNx, stats);
             psf->params->data[i] = param;
         }
Index: /branches/eam_branch_20070921/psModules/src/objects/pmPSF.h
===================================================================
--- /branches/eam_branch_20070921/psModules/src/objects/pmPSF.h	(revision 14968)
+++ /branches/eam_branch_20070921/psModules/src/objects/pmPSF.h	(revision 14969)
@@ -6,6 +6,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-09-21 00:05:35 $
+ * @version $Revision: 1.16.2.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-09-21 18:55:12 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -19,17 +19,4 @@
 // type of model carried by the pmModel structure
 typedef int pmModelType;
-
-typedef enum {
-    PM_PSF_APTREND_ERROR = 0,
-    PM_PSF_APTREND_NONE,
-    PM_PSF_APTREND_CONSTANT,
-    PM_PSF_APTREND_SKYBIAS,
-    PM_PSF_APTREND_SKYSAT,
-    PM_PSF_APTREND_XY_LIN,
-    PM_PSF_APTREND_XY_QUAD,
-    PM_PSF_APTREND_SKY_XY_LIN,
-    PM_PSF_APTREND_SKYSAT_XY_LIN,
-    PM_PSF_APTREND_ALL
-} pmPSFApTrendOptions;
 
 /** pmPSF data structure
@@ -65,4 +52,12 @@
 pmPSF;
 
+typedef struct {
+    pmModelType   type;
+    bool          poissonErrors;
+    pmTrend2DMode psfTrendMode;
+    int           psfTrendNx;
+    int           psfTrendNy;
+} pmPSFOptions;
+
 # define PM_PAR_E0 PM_PAR_SXX
 # define PM_PAR_E1 PM_PAR_SYY
Index: /branches/eam_branch_20070921/psModules/src/objects/pmPSF_IO.c
===================================================================
--- /branches/eam_branch_20070921/psModules/src/objects/pmPSF_IO.c	(revision 14968)
+++ /branches/eam_branch_20070921/psModules/src/objects/pmPSF_IO.c	(revision 14969)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:05:57 $
+ *  @version $Revision: 1.22.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-09-21 18:55:12 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -150,4 +150,5 @@
 // - image header        : FITS Image NAXIS = 0
 // - psf table (+header) : FITS Table
+// XXX if we are using psImageMap, this is also a FITS Image, with header data
 // - psf resid (+header) : FITS Image
 // if needed, we also write out a PHU blank header
@@ -356,4 +357,5 @@
     // XXX save the growth curve
     // XXX save ApTrend (as image?)
+    // XXX write the ApTrend with the same API as will be used for the PSF parameters above
 
 # if (0)
@@ -618,4 +620,5 @@
 
 // create a psMetadata representation (human-readable) of a psf model
+// XXX drop this function?
 psMetadata *pmPSFtoMetadata (psMetadata *metadata, pmPSF *psf)
 {
@@ -654,4 +657,5 @@
 
 // parse a psMetadata representation (human-readable) of a psf model
+// XXX drop this function?
 pmPSF *pmPSFfromMetadata (psMetadata *metadata)
 {
Index: /branches/eam_branch_20070921/psModules/src/objects/pmTrend2D.c
===================================================================
--- /branches/eam_branch_20070921/psModules/src/objects/pmTrend2D.c	(revision 14968)
+++ /branches/eam_branch_20070921/psModules/src/objects/pmTrend2D.c	(revision 14969)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:18 $
+ *  @version $Revision: 1.2.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-09-21 18:55:12 $
  *
  *  Copyright 2004 Institute for Astronomy, University of Hawaii
@@ -82,4 +82,10 @@
       case PM_TREND_POLY_ORD:
 	trend->poly = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXtrend, nYtrend);
+	// set masking somehow
+ 	for (int nx = 0; nx < trend->poly->nX + 1; nx++) {
+	    for (int ny = 0; ny < trend->poly->nY + 1; ny++) {
+		trend->poly->mask[nx][ny] = XXX;
+	    }
+	}
 	break;
 
