Index: /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_GAUSS.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_GAUSS.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_GAUSS.c	(revision 14612)
@@ -28,4 +28,5 @@
 # define PM_MODEL_FIT_STATUS      pmModelFitStatus_GAUSS
 
+// the model is a function of the pixel coordinate (pixcoord[0,1] = x,y)
 psF32 PM_MODEL_FUNC(psVector *deriv,
                     const psVector *params,
@@ -39,4 +40,6 @@
     psF32 py = Y / PAR[PM_PAR_SYY];
     psF32 z  = PS_SQR(px) + PS_SQR(py) + PAR[PM_PAR_SXY]*X*Y;
+    assert (z >= 0.0);
+
     psF32 r  = exp(-z);
     psF32 q  = PAR[PM_PAR_I0]*r;
@@ -62,4 +65,5 @@
 # define AR_MAX 20.0
 # define AR_RATIO 0.99
+
 bool PM_MODEL_LIMITS (psMinConstraintMode mode, int nParam, float *params, float *beta)
 {
@@ -94,8 +98,8 @@
             break;
         case PM_PAR_SXX:
-            beta_lim = 0.5;
+            beta_lim = 2.0;
             break;
         case PM_PAR_SYY:
-            beta_lim = 0.5;
+            beta_lim = 2.0;
             break;
         case PM_PAR_SXY:
@@ -186,9 +190,6 @@
 
 // make an initial guess for parameters
-bool PM_MODEL_GUESS (void *inModel, void *inSource)
-{
-    pmModel *model = inModel;
-    pmSource *source = inSource;
-
+bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
+{
     pmMoments *moments = source->moments;
     psF32     *PAR  = model->params->data.F32;
@@ -259,23 +260,19 @@
 
 // construct the PSF model from the FLT model and the psf
-bool PM_MODEL_FROM_PSF (void *inModelPSF, void *inModelFLT, void *inPSF)
-{
-    pmModel *modelPSF = inModelPSF;
-    pmModel *modelFLT = inModelFLT;
-    pmPSF *psf = inPSF;
-
+bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf)
+{
     psF32 *out = modelPSF->params->data.F32;
     psF32 *in  = modelFLT->params->data.F32;
 
     // we require these two parameters to exist
-    assert (psf->params_NEW->n > PM_PAR_YPOS);
-    assert (psf->params_NEW->n > PM_PAR_XPOS);
+    assert (psf->params->n > PM_PAR_YPOS);
+    assert (psf->params->n > PM_PAR_XPOS);
 
     // supply the model-fitted parameters, or copy from the input
-    for (int i = 0; i < psf->params_NEW->n; i++) {
-        if (psf->params_NEW->data[i] == NULL) {
+    for (int i = 0; i < psf->params->n; i++) {
+        if (psf->params->data[i] == NULL) {
             out[i] = in[i];
         } else {
-            psPolynomial2D *poly = psf->params_NEW->data[i];
+            psPolynomial2D *poly = psf->params->data[i];
             out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
         }
@@ -296,7 +293,7 @@
     // apply the model limits here: this truncates excessive extrapolation
     // XXX do we need to do this still?  should we put in asserts to test?
-    for (int i = 0; i < psf->params_NEW->n; i++) {
+    for (int i = 0; i < psf->params->n; i++) {
         // apply the limits to all components or just the psf-model parameters?
-        if (psf->params_NEW->data[i] == NULL)
+        if (psf->params->data[i] == NULL)
             continue;
 
@@ -315,14 +312,11 @@
 // construct the PSF model from the FLT model and the psf
 // XXX is this sufficiently general do be a global function, not a pmModelClass function?
-bool PM_MODEL_PARAMS_FROM_PSF (void *inModel, void *inPSF, float Xo, float Yo, float Io)
-{
-    pmModel *model = inModel;
-    pmPSF *psf = inPSF;
-
+bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io)
+{
     psF32 *PAR = model->params->data.F32;
 
     // we require these two parameters to exist
-    assert (psf->params_NEW->n > PM_PAR_YPOS);
-    assert (psf->params_NEW->n > PM_PAR_XPOS);
+    assert (psf->params->n > PM_PAR_YPOS);
+    assert (psf->params->n > PM_PAR_XPOS);
 
     PAR[PM_PAR_SKY]  = 0.0;
@@ -332,7 +326,10 @@
     
     // supply the model-fitted parameters, or copy from the input
-    for (int i = 0; i < psf->params_NEW->n; i++) {
+    for (int i = 0; i < psf->params->n; i++) {
 	if (i == PM_PAR_SKY) continue;
-	psPolynomial2D *poly = psf->params_NEW->data[i];
+	if (i == PM_PAR_I0) continue;
+	if (i == PM_PAR_XPOS) continue;
+	if (i == PM_PAR_YPOS) continue;
+	psPolynomial2D *poly = psf->params->data[i];
 	assert (poly);
 	PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
@@ -349,7 +346,7 @@
     // apply the model limits here: this truncates excessive extrapolation
     // XXX do we need to do this still?  should we put in asserts to test?
-    for (int i = 0; i < psf->params_NEW->n; i++) {
+    for (int i = 0; i < psf->params->n; i++) {
         // apply the limits to all components or just the psf-model parameters?
-        if (psf->params_NEW->data[i] == NULL)
+        if (psf->params->data[i] == NULL)
             continue;
 
@@ -368,8 +365,6 @@
 // this test is invalid if the parameters are derived
 // from the PSF model
-bool PM_MODEL_FIT_STATUS (void *inModel)
-{
-    pmModel *model = inModel;
-
+bool PM_MODEL_FIT_STATUS (pmModel *model)
+{
     psF32 dP;
     bool  status;
Index: /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_PGAUSS.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_PGAUSS.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_PGAUSS.c	(revision 14612)
@@ -19,11 +19,12 @@
  *****************************************************************************/
 
-# define PM_MODEL_FUNC       pmModelFunc_PGAUSS
-# define PM_MODEL_FLUX       pmModelFlux_PGAUSS
-# define PM_MODEL_GUESS      pmModelGuess_PGAUSS
-# define PM_MODEL_LIMITS     pmModelLimits_PGAUSS
-# define PM_MODEL_RADIUS     pmModelRadius_PGAUSS
-# define PM_MODEL_FROM_PSF   pmModelFromPSF_PGAUSS
-# define PM_MODEL_FIT_STATUS pmModelFitStatus_PGAUSS
+# define PM_MODEL_FUNC       	  pmModelFunc_PGAUSS
+# define PM_MODEL_FLUX       	  pmModelFlux_PGAUSS
+# define PM_MODEL_GUESS      	  pmModelGuess_PGAUSS
+# define PM_MODEL_LIMITS     	  pmModelLimits_PGAUSS
+# define PM_MODEL_RADIUS     	  pmModelRadius_PGAUSS
+# define PM_MODEL_FROM_PSF   	  pmModelFromPSF_PGAUSS
+# define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_PGAUSS
+# define PM_MODEL_FIT_STATUS      pmModelFitStatus_PGAUSS
 
 // the model is a function of the pixel coordinate (pixcoord[0,1] = x,y)
@@ -66,12 +67,4 @@
 # define AR_RATIO 0.99
 
-// we constraint limits by the min valid minor axis:
-# define MIN_MINOR_AXIS 0.5
-
-// f3 = (s_b^-2 - s_a^-2); F3_SQ_MAX is MIN_MINOR_AXIS^-4
-# define F3_SQ_MAX 16.0 
-
-static float saveParams[8];
-
 bool PM_MODEL_LIMITS (psMinConstraintMode mode, int nParam, float *params, float *beta)
 {
@@ -150,5 +143,4 @@
             psAbort("invalid parameter %d for param min test", nParam);
         }
-	saveParams[nParam] = params[nParam];
 	if (params[nParam] < params_min) {
             params[nParam] = params_min;
@@ -184,5 +176,4 @@
             psAbort("invalid parameter %d for param max test", nParam);
         }
-	saveParams[nParam] = params[nParam];
         if (params[nParam] > params_max) {
             params[nParam] = params_max;
@@ -263,4 +254,6 @@
 psF64 PM_MODEL_RADIUS (const psVector *params, psF64 flux)
 {
+    psF64 z, f;
+    int Nstep = 0;
     psEllipseShape shape;
 
@@ -280,5 +273,36 @@
     // this estimates the radius assuming f(z) is roughly exp(-z)
     psEllipseAxes axes = psEllipseShapeToAxes (shape, 20.0);
-    psF64 radius = axes.major * sqrt (2.0 * log(PAR[PM_PAR_I0] / flux));
+    psF64 sigma = axes.major;
+
+    psF64 limit = flux / PAR[PM_PAR_I0];
+
+    // use the fact that f is monotonically decreasing
+    z = 0;
+    Nstep = 0;
+
+    // choose a z value guaranteed to be beyond our limit
+    float z0 = pow((1.0 / limit), (1.0 / 3.0));
+    float z1 = (1.0 / limit);
+    z1 = PS_MAX (z0, z1);
+    z0 = 0.0;
+
+    // perform a type of bisection to find the value
+    float f0 = 1.0 / (1 + z0 + z0*z0/2.0 + z0*z0*z0/6.0);
+    float f1 = 1.0 / (1 + z1 + z1*z1/2.0 + z1*z1*z1/6.0);
+    while ((Nstep < 10) && (fabs(z1 - z0) > 0.5)) {
+        z = 0.5*(z0 + z1);
+	f = 1.0 / (1 + z + z*z/2.0 + z*z*z/6.0);
+        if (f > limit) {
+            z0 = z;
+            f0 = f;
+        } else {
+            z1 = z;
+            f1 = f;
+        }
+        Nstep ++;
+    }
+    psF64 radius = sigma * sqrt (2.0 * z);
+
+    // psF64 radius = axes.major * sqrt (2.0 * log(PAR[PM_PAR_I0] / flux));
 
     if (isnan(radius))
@@ -297,12 +321,12 @@
 
     // we require these two parameters to exist
-    assert (psf->params_NEW->n > PM_PAR_YPOS);
-    assert (psf->params_NEW->n > PM_PAR_XPOS);
-
-    for (int i = 0; i < psf->params_NEW->n; i++) {
-        if (psf->params_NEW->data[i] == NULL) {
+    assert (psf->params->n > PM_PAR_YPOS);
+    assert (psf->params->n > PM_PAR_XPOS);
+
+    for (int i = 0; i < psf->params->n; i++) {
+        if (psf->params->data[i] == NULL) {
             out[i] = in[i];
         } else {
-            psPolynomial2D *poly = psf->params_NEW->data[i];
+            psPolynomial2D *poly = psf->params->data[i];
             out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
         }
@@ -322,7 +346,7 @@
     // apply the model limits here: this truncates excessive extrapolation
     // XXX do we need to do this still?  should we put in asserts to test?
-    for (int i = 0; i < psf->params_NEW->n; i++) {
+    for (int i = 0; i < psf->params->n; i++) {
         // apply the limits to all components or just the psf-model parameters?
-        if (psf->params_NEW->data[i] == NULL)
+        if (psf->params->data[i] == NULL)
             continue;
 
@@ -339,4 +363,56 @@
 }
 
+// construct the PSF model from the FLT model and the psf
+// XXX is this sufficiently general do be a global function, not a pmModelClass function?
+bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io)
+{
+    psF32 *PAR = model->params->data.F32;
+
+    // we require these two parameters to exist
+    assert (psf->params->n > PM_PAR_YPOS);
+    assert (psf->params->n > PM_PAR_XPOS);
+
+    PAR[PM_PAR_SKY]  = 0.0;
+    PAR[PM_PAR_I0]   = Io;
+    PAR[PM_PAR_XPOS] = Xo;
+    PAR[PM_PAR_YPOS] = Yo;
+    
+    // supply the model-fitted parameters, or copy from the input
+    for (int i = 0; i < psf->params->n; i++) {
+	if (i == PM_PAR_SKY) continue;
+	if (i == PM_PAR_I0) continue;
+	if (i == PM_PAR_XPOS) continue;
+	if (i == PM_PAR_YPOS) continue;
+	psPolynomial2D *poly = psf->params->data[i];
+	assert (poly);
+	PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
+    }
+
+    // the 2D PSF model fits polarization terms (E0,E1,E2)
+    // convert to shape terms (SXX,SYY,SXY)
+    // XXX user-defined value for limit?
+    if (!pmPSF_FitToModel (PAR, 0.1)) {
+	psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
+	return false;
+    }
+
+    // apply the model limits here: this truncates excessive extrapolation
+    // XXX do we need to do this still?  should we put in asserts to test?
+    for (int i = 0; i < psf->params->n; i++) {
+        // apply the limits to all components or just the psf-model parameters?
+        if (psf->params->data[i] == NULL)
+            continue;
+
+	bool status = true;
+        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL);
+        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL);
+	if (!status) {
+	    psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo);
+	    model->flags |= PM_MODEL_STATUS_LIMITS;
+	}
+    }
+    return(true);
+}
+
 bool PM_MODEL_FIT_STATUS (pmModel *model)
 {
@@ -367,3 +443,4 @@
 # undef PM_MODEL_RADIUS
 # undef PM_MODEL_FROM_PSF
+# undef PM_MODEL_PARAMS_FROM_PSF
 # undef PM_MODEL_FIT_STATUS
Index: /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_QGAUSS.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_QGAUSS.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_QGAUSS.c	(revision 14612)
@@ -20,11 +20,12 @@
    *****************************************************************************/
 
-# define PM_MODEL_FUNC       pmModelFunc_QGAUSS
-# define PM_MODEL_FLUX       pmModelFlux_QGAUSS
-# define PM_MODEL_GUESS      pmModelGuess_QGAUSS
-# define PM_MODEL_LIMITS     pmModelLimits_QGAUSS
-# define PM_MODEL_RADIUS     pmModelRadius_QGAUSS
-# define PM_MODEL_FROM_PSF   pmModelFromPSF_QGAUSS
-# define PM_MODEL_FIT_STATUS pmModelFitStatus_QGAUSS
+# define PM_MODEL_FUNC       	  pmModelFunc_QGAUSS
+# define PM_MODEL_FLUX       	  pmModelFlux_QGAUSS
+# define PM_MODEL_GUESS      	  pmModelGuess_QGAUSS
+# define PM_MODEL_LIMITS     	  pmModelLimits_QGAUSS
+# define PM_MODEL_RADIUS     	  pmModelRadius_QGAUSS
+# define PM_MODEL_FROM_PSF   	  pmModelFromPSF_QGAUSS
+# define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_QGAUSS
+# define PM_MODEL_FIT_STATUS      pmModelFitStatus_QGAUSS
 
 psF32 PM_MODEL_FUNC (psVector *deriv,
@@ -350,12 +351,12 @@
 
     // we require these two parameters to exist
-    assert (psf->params_NEW->n > PM_PAR_YPOS);
-    assert (psf->params_NEW->n > PM_PAR_XPOS);
-
-    for (int i = 0; i < psf->params_NEW->n; i++) {
-        if (psf->params_NEW->data[i] == NULL) {
+    assert (psf->params->n > PM_PAR_YPOS);
+    assert (psf->params->n > PM_PAR_XPOS);
+
+    for (int i = 0; i < psf->params->n; i++) {
+        if (psf->params->data[i] == NULL) {
             out[i] = in[i];
         } else {
-            psPolynomial2D *poly = psf->params_NEW->data[i];
+            psPolynomial2D *poly = psf->params->data[i];
             out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
         }
@@ -372,7 +373,7 @@
     // apply the model limits here: this truncates excessive extrapolation
     // XXX do we need to do this still?  should we put in asserts to test?
-    for (int i = 0; i < psf->params_NEW->n; i++) {
+    for (int i = 0; i < psf->params->n; i++) {
         // apply the limits to all components or just the psf-model parameters?
-        if (psf->params_NEW->data[i] == NULL)
+        if (psf->params->data[i] == NULL)
             continue;
 
@@ -390,4 +391,56 @@
 }
 
+// construct the PSF model from the FLT model and the psf
+// XXX is this sufficiently general do be a global function, not a pmModelClass function?
+bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io)
+{
+    psF32 *PAR = model->params->data.F32;
+
+    // we require these two parameters to exist
+    assert (psf->params->n > PM_PAR_YPOS);
+    assert (psf->params->n > PM_PAR_XPOS);
+
+    PAR[PM_PAR_SKY]  = 0.0;
+    PAR[PM_PAR_I0]   = Io;
+    PAR[PM_PAR_XPOS] = Xo;
+    PAR[PM_PAR_YPOS] = Yo;
+    
+    // supply the model-fitted parameters, or copy from the input
+    for (int i = 0; i < psf->params->n; i++) {
+	if (i == PM_PAR_SKY) continue;
+	if (i == PM_PAR_I0) continue;
+	if (i == PM_PAR_XPOS) continue;
+	if (i == PM_PAR_YPOS) continue;
+	psPolynomial2D *poly = psf->params->data[i];
+	assert (poly);
+	PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
+    }
+
+    // the 2D PSF model fits polarization terms (E0,E1,E2)
+    // convert to shape terms (SXX,SYY,SXY)
+    // XXX user-defined value for limit?
+    if (!pmPSF_FitToModel (PAR, 0.1)) {
+	psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
+	return false;
+    }
+
+    // apply the model limits here: this truncates excessive extrapolation
+    // XXX do we need to do this still?  should we put in asserts to test?
+    for (int i = 0; i < psf->params->n; i++) {
+        // apply the limits to all components or just the psf-model parameters?
+        if (psf->params->data[i] == NULL)
+            continue;
+
+	bool status = true;
+        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL);
+        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL);
+	if (!status) {
+	    psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo);
+	    model->flags |= PM_MODEL_STATUS_LIMITS;
+	}
+    }
+    return(true);
+}
+
 bool PM_MODEL_FIT_STATUS (pmModel *model)
 {
@@ -418,3 +471,4 @@
 # undef PM_MODEL_RADIUS
 # undef PM_MODEL_FROM_PSF
+# undef PM_MODEL_PARAMS_FROM_PSF
 # undef PM_MODEL_FIT_STATUS
Index: /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_RGAUSS.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_RGAUSS.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_RGAUSS.c	(revision 14612)
@@ -20,11 +20,12 @@
  *****************************************************************************/
 
-# define PM_MODEL_FUNC       pmModelFunc_RGAUSS
-# define PM_MODEL_FLUX       pmModelFlux_RGAUSS
-# define PM_MODEL_GUESS      pmModelGuess_RGAUSS
-# define PM_MODEL_LIMITS     pmModelLimits_RGAUSS
-# define PM_MODEL_RADIUS     pmModelRadius_RGAUSS
-# define PM_MODEL_FROM_PSF   pmModelFromPSF_RGAUSS
-# define PM_MODEL_FIT_STATUS pmModelFitStatus_RGAUSS
+# define PM_MODEL_FUNC       	  pmModelFunc_RGAUSS
+# define PM_MODEL_FLUX       	  pmModelFlux_RGAUSS
+# define PM_MODEL_GUESS      	  pmModelGuess_RGAUSS
+# define PM_MODEL_LIMITS     	  pmModelLimits_RGAUSS
+# define PM_MODEL_RADIUS     	  pmModelRadius_RGAUSS
+# define PM_MODEL_FROM_PSF   	  pmModelFromPSF_RGAUSS
+# define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_RGAUSS
+# define PM_MODEL_FIT_STATUS      pmModelFitStatus_RGAUSS
 
 psF32 PM_MODEL_FUNC (psVector *deriv,
@@ -343,12 +344,12 @@
 
     // we require these two parameters to exist
-    assert (psf->params_NEW->n > PM_PAR_YPOS);
-    assert (psf->params_NEW->n > PM_PAR_XPOS);
-
-    for (int i = 0; i < psf->params_NEW->n; i++) {
-        if (psf->params_NEW->data[i] == NULL) {
+    assert (psf->params->n > PM_PAR_YPOS);
+    assert (psf->params->n > PM_PAR_XPOS);
+
+    for (int i = 0; i < psf->params->n; i++) {
+        if (psf->params->data[i] == NULL) {
             out[i] = in[i];
         } else {
-            psPolynomial2D *poly = psf->params_NEW->data[i];
+            psPolynomial2D *poly = psf->params->data[i];
             out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
         }
@@ -365,7 +366,7 @@
     // apply the model limits here: this truncates excessive extrapolation
     // XXX do we need to do this still?  should we put in asserts to test?
-    for (int i = 0; i < psf->params_NEW->n; i++) {
+    for (int i = 0; i < psf->params->n; i++) {
         // apply the limits to all components or just the psf-model parameters?
-        if (psf->params_NEW->data[i] == NULL)
+        if (psf->params->data[i] == NULL)
             continue;
 
@@ -383,4 +384,56 @@
 }
 
+// construct the PSF model from the FLT model and the psf
+// XXX is this sufficiently general do be a global function, not a pmModelClass function?
+bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io)
+{
+    psF32 *PAR = model->params->data.F32;
+
+    // we require these two parameters to exist
+    assert (psf->params->n > PM_PAR_YPOS);
+    assert (psf->params->n > PM_PAR_XPOS);
+
+    PAR[PM_PAR_SKY]  = 0.0;
+    PAR[PM_PAR_I0]   = Io;
+    PAR[PM_PAR_XPOS] = Xo;
+    PAR[PM_PAR_YPOS] = Yo;
+    
+    // supply the model-fitted parameters, or copy from the input
+    for (int i = 0; i < psf->params->n; i++) {
+	if (i == PM_PAR_SKY) continue;
+	if (i == PM_PAR_I0) continue;
+	if (i == PM_PAR_XPOS) continue;
+	if (i == PM_PAR_YPOS) continue;
+	psPolynomial2D *poly = psf->params->data[i];
+	assert (poly);
+	PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
+    }
+
+    // the 2D PSF model fits polarization terms (E0,E1,E2)
+    // convert to shape terms (SXX,SYY,SXY)
+    // XXX user-defined value for limit?
+    if (!pmPSF_FitToModel (PAR, 0.1)) {
+	psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
+	return false;
+    }
+
+    // apply the model limits here: this truncates excessive extrapolation
+    // XXX do we need to do this still?  should we put in asserts to test?
+    for (int i = 0; i < psf->params->n; i++) {
+        // apply the limits to all components or just the psf-model parameters?
+        if (psf->params->data[i] == NULL)
+            continue;
+
+	bool status = true;
+        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL);
+        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL);
+	if (!status) {
+	    psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo);
+	    model->flags |= PM_MODEL_STATUS_LIMITS;
+	}
+    }
+    return(true);
+}
+
 bool PM_MODEL_FIT_STATUS (pmModel *model)
 {
@@ -411,3 +464,4 @@
 # undef PM_MODEL_RADIUS
 # undef PM_MODEL_FROM_PSF
+# undef PM_MODEL_PARAMS_FROM_PSF
 # undef PM_MODEL_FIT_STATUS
Index: /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_SERSIC.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_SERSIC.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_SERSIC.c	(revision 14612)
@@ -23,11 +23,12 @@
    *****************************************************************************/
 
-# define PM_MODEL_FUNC       pmModelFunc_SERSIC
-# define PM_MODEL_FLUX       pmModelFlux_SERSIC
-# define PM_MODEL_GUESS      pmModelGuess_SERSIC
-# define PM_MODEL_LIMITS     pmModelLimits_SERSIC
-# define PM_MODEL_RADIUS     pmModelRadius_SERSIC
-# define PM_MODEL_FROM_PSF   pmModelFromPSF_SERSIC
-# define PM_MODEL_FIT_STATUS pmModelFitStatus_SERSIC
+# define PM_MODEL_FUNC       	  pmModelFunc_SERSIC
+# define PM_MODEL_FLUX       	  pmModelFlux_SERSIC
+# define PM_MODEL_GUESS      	  pmModelGuess_SERSIC
+# define PM_MODEL_LIMITS     	  pmModelLimits_SERSIC
+# define PM_MODEL_RADIUS     	  pmModelRadius_SERSIC
+# define PM_MODEL_FROM_PSF   	  pmModelFromPSF_SERSIC
+# define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_SERSIC
+# define PM_MODEL_FIT_STATUS      pmModelFitStatus_SERSIC
 
 psF32 PM_MODEL_FUNC (psVector *deriv,
@@ -360,12 +361,12 @@
 
     // we require these two parameters to exist
-    assert (psf->params_NEW->n > PM_PAR_YPOS);
-    assert (psf->params_NEW->n > PM_PAR_XPOS);
-
-    for (int i = 0; i < psf->params_NEW->n; i++) {
-        if (psf->params_NEW->data[i] == NULL) {
+    assert (psf->params->n > PM_PAR_YPOS);
+    assert (psf->params->n > PM_PAR_XPOS);
+
+    for (int i = 0; i < psf->params->n; i++) {
+        if (psf->params->data[i] == NULL) {
             out[i] = in[i];
         } else {
-            psPolynomial2D *poly = psf->params_NEW->data[i];
+            psPolynomial2D *poly = psf->params->data[i];
             out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
         }
@@ -382,7 +383,7 @@
     // apply the model limits here: this truncates excessive extrapolation
     // XXX do we need to do this still?  should we put in asserts to test?
-    for (int i = 0; i < psf->params_NEW->n; i++) {
+    for (int i = 0; i < psf->params->n; i++) {
         // apply the limits to all components or just the psf-model parameters?
-        if (psf->params_NEW->data[i] == NULL)
+        if (psf->params->data[i] == NULL)
             continue;
 
@@ -400,4 +401,56 @@
 }
 
+// construct the PSF model from the FLT model and the psf
+// XXX is this sufficiently general do be a global function, not a pmModelClass function?
+bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io)
+{
+    psF32 *PAR = model->params->data.F32;
+
+    // we require these two parameters to exist
+    assert (psf->params->n > PM_PAR_YPOS);
+    assert (psf->params->n > PM_PAR_XPOS);
+
+    PAR[PM_PAR_SKY]  = 0.0;
+    PAR[PM_PAR_I0]   = Io;
+    PAR[PM_PAR_XPOS] = Xo;
+    PAR[PM_PAR_YPOS] = Yo;
+    
+    // supply the model-fitted parameters, or copy from the input
+    for (int i = 0; i < psf->params->n; i++) {
+	if (i == PM_PAR_SKY) continue;
+	if (i == PM_PAR_I0) continue;
+	if (i == PM_PAR_XPOS) continue;
+	if (i == PM_PAR_YPOS) continue;
+	psPolynomial2D *poly = psf->params->data[i];
+	assert (poly);
+	PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
+    }
+
+    // the 2D PSF model fits polarization terms (E0,E1,E2)
+    // convert to shape terms (SXX,SYY,SXY)
+    // XXX user-defined value for limit?
+    if (!pmPSF_FitToModel (PAR, 0.1)) {
+	psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
+	return false;
+    }
+
+    // apply the model limits here: this truncates excessive extrapolation
+    // XXX do we need to do this still?  should we put in asserts to test?
+    for (int i = 0; i < psf->params->n; i++) {
+        // apply the limits to all components or just the psf-model parameters?
+        if (psf->params->data[i] == NULL)
+            continue;
+
+	bool status = true;
+        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL);
+        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL);
+	if (!status) {
+	    psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo);
+	    model->flags |= PM_MODEL_STATUS_LIMITS;
+	}
+    }
+    return(true);
+}
+
 bool PM_MODEL_FIT_STATUS (pmModel *model)
 {
@@ -428,3 +481,4 @@
 # undef PM_MODEL_RADIUS
 # undef PM_MODEL_FROM_PSF
+# undef PM_MODEL_PARAMS_FROM_PSF
 # undef PM_MODEL_FIT_STATUS
Index: /branches/eam_branch_20070817/psModules/src/objects/pmGrowthCurve.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmGrowthCurve.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmGrowthCurve.c	(revision 14612)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-04-21 19:47:14 $
+ *  @version $Revision: 1.10.8.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -23,8 +23,8 @@
 #include "pmMoments.h"
 #include "pmResiduals.h"
+#include "pmGrowthCurve.h"
+#include "pmPSF.h"
 #include "pmModel.h"
 #include "pmSource.h"
-#include "pmGrowthCurve.h"
-#include "pmPSF.h"
 #include "psVectorBracket.h"
 
Index: /branches/eam_branch_20070817/psModules/src/objects/pmModel.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmModel.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModel.c	(revision 14612)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.13.6.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.13.6.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -21,5 +21,9 @@
 #include <string.h>
 #include <pslib.h>
+#include "pmHDU.h"
+#include "pmFPA.h"
 #include "pmResiduals.h"
+#include "pmGrowthCurve.h"
+#include "pmPSF.h"
 #include "pmModel.h"
 #include "pmModelClass.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmModel.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmModel.h	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModel.h	(revision 14612)
@@ -5,6 +5,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.11.6.2 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-08-20 01:58:16 $
+ * @version $Revision: 1.11.6.3 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-23 00:55:49 $
  *
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -14,8 +14,4 @@
 # define PM_MODEL_H
 
-# define TMP_PSF_TYPE void
-# define TMP_MODEL_TYPE void
-# define TMP_SOURCE_TYPE void
-
 /// @addtogroup Objects Object Detection / Analysis Functions
 /// @{
@@ -23,7 +19,4 @@
 /* pointers for the functions types below are supplied to each pmModel, and can be used by
    the programmer without needing to know the model class */
-
-// type of model carried by the pmModel structure
-typedef int pmModelType;
 
 typedef enum {
@@ -48,4 +41,7 @@
 } pmModelOpMode;
 
+typedef struct pmModel pmModel;
+typedef struct pmSource pmSource;
+
 //  This function is the model chi-square minimization function for this model.
 typedef psMinimizeLMChi2Func pmModelFunc;
@@ -63,16 +59,16 @@
 //  This function provides the model guess parameters based on the details of
 //  the given source.
-typedef bool (*pmModelGuessFunc)(TMP_MODEL_TYPE *model, TMP_SOURCE_TYPE *source);
+typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source);
 
 //  This function constructs the PSF model for the given source based on the
 //  supplied psf and the EXT model for the object.
-typedef bool (*pmModelFromPSFFunc)(TMP_MODEL_TYPE *modelPSF, TMP_MODEL_TYPE *modelEXT, TMP_PSF_TYPE *psf);
+typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelEXT, pmPSF *psf);
 
 //  This function sets the model parameters based on the PSF for a given coordinate and central
 //  intensity
-typedef bool (*pmModelParamsFromPSF)(TMP_MODEL_TYPE *model, TMP_PSF_TYPE *psf, float Xo, float Yo, float Io);
+typedef bool (*pmModelParamsFromPSF)(pmModel *model, pmPSF *psf, float Xo, float Yo, float Io);
 
 //  This function returns the success / failure status of the given model fit
-typedef bool (*pmModelFitStatusFunc)(TMP_MODEL_TYPE *model);
+typedef bool (*pmModelFitStatusFunc)(pmModel *model);
 
 /** pmModel data structure
@@ -85,6 +81,5 @@
  *
  */
-typedef struct
-{
+struct pmModel {
     pmModelType type;                   ///< Model to be used.
     psVector *params;                   ///< Paramater values.
@@ -107,5 +102,5 @@
     pmModelParamsFromPSF modelParamsFromPSF;
     pmModelFitStatusFunc modelFitStatus;
-} pmModel;
+};
 
 /** Symbolic names for the elements of [d]params
Index: /branches/eam_branch_20070817/psModules/src/objects/pmModelClass.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmModelClass.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModelClass.c	(revision 14612)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -25,8 +25,8 @@
 #include "pmPeaks.h"
 #include "pmMoments.h"
+#include "pmResiduals.h"
 #include "pmGrowthCurve.h"
-#include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmModelClass.h"
@@ -45,8 +45,8 @@
 static pmModelClass defaultModels[] = {
     {"PS_MODEL_GAUSS",        7, pmModelFunc_GAUSS,   pmModelFlux_GAUSS,   pmModelRadius_GAUSS,   pmModelLimits_GAUSS,   pmModelGuess_GAUSS,  pmModelFromPSF_GAUSS,  pmModelParamsFromPSF_GAUSS,  pmModelFitStatus_GAUSS},
-//    {"PS_MODEL_PGAUSS",       7, pmModelFunc_PGAUSS,  pmModelFlux_PGAUSS,  pmModelRadius_PGAUSS,  pmModelLimits_PGAUSS,  pmModelGuess_PGAUSS, pmModelFromPSF_PGAUSS, pmModelParamsFromPSF_PGAUSS, pmModelFitStatus_PGAUSS},
-//    {"PS_MODEL_QGAUSS",       8, pmModelFunc_QGAUSS,  pmModelFlux_QGAUSS,  pmModelRadius_QGAUSS,  pmModelLimits_QGAUSS,  pmModelGuess_QGAUSS, pmModelFromPSF_QGAUSS, pmModelParamsFromPSF_QGAUSS, pmModelFitStatus_QGAUSS},
-//    {"PS_MODEL_RGAUSS",       8, pmModelFunc_RGAUSS,  pmModelFlux_RGAUSS,  pmModelRadius_RGAUSS,  pmModelLimits_RGAUSS,  pmModelGuess_RGAUSS, pmModelFromPSF_RGAUSS, pmModelParamsFromPSF_RGAUSS, pmModelFitStatus_RGAUSS},
-//    {"PS_MODEL_SERSIC",       8, pmModelFunc_SERSIC,  pmModelFlux_SERSIC,  pmModelRadius_SERSIC,  pmModelLimits_SERSIC,  pmModelGuess_SERSIC, pmModelFromPSF_SERSIC, pmModelParamsFromPSF_SERSIC, pmModelFitStatus_SERSIC}
+    {"PS_MODEL_PGAUSS",       7, pmModelFunc_PGAUSS,  pmModelFlux_PGAUSS,  pmModelRadius_PGAUSS,  pmModelLimits_PGAUSS,  pmModelGuess_PGAUSS, pmModelFromPSF_PGAUSS, pmModelParamsFromPSF_PGAUSS, pmModelFitStatus_PGAUSS},
+    {"PS_MODEL_QGAUSS",       8, pmModelFunc_QGAUSS,  pmModelFlux_QGAUSS,  pmModelRadius_QGAUSS,  pmModelLimits_QGAUSS,  pmModelGuess_QGAUSS, pmModelFromPSF_QGAUSS, pmModelParamsFromPSF_QGAUSS, pmModelFitStatus_QGAUSS},
+    {"PS_MODEL_RGAUSS",       8, pmModelFunc_RGAUSS,  pmModelFlux_RGAUSS,  pmModelRadius_RGAUSS,  pmModelLimits_RGAUSS,  pmModelGuess_RGAUSS, pmModelFromPSF_RGAUSS, pmModelParamsFromPSF_RGAUSS, pmModelFitStatus_RGAUSS},
+    {"PS_MODEL_SERSIC",       8, pmModelFunc_SERSIC,  pmModelFlux_SERSIC,  pmModelRadius_SERSIC,  pmModelLimits_SERSIC,  pmModelGuess_SERSIC, pmModelFromPSF_SERSIC, pmModelParamsFromPSF_SERSIC, pmModelFitStatus_SERSIC}
 };
 
Index: /branches/eam_branch_20070817/psModules/src/objects/pmModelGroup.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmModelGroup.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModelGroup.c	(revision 14612)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.17.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.17.4.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -28,7 +28,4 @@
 #include "pmResiduals.h"
 #include "pmModel.h"
-// #include "pmResiduals.h"
-// #include "pmPSF.h"
-// #include "pmSource.h"
 #include "pmModelGroup.h"
 #include "pmErrorCodes.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmModelUtils.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmModelUtils.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModelUtils.c	(revision 14612)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -22,10 +22,31 @@
 #include "pmHDU.h"
 #include "pmFPA.h"
+#include "pmResiduals.h"
 #include "pmGrowthCurve.h"
-#include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmErrorCodes.h"
 #include "pmModelUtils.h"
+
+/*****************************************************************************
+pmModelFromPSF (*modelEXT, *psf):  use the model position parameters to
+construct a realization of the PSF model at the object coordinates
+ *****************************************************************************/
+pmModel *pmModelFromPSF (pmModel *modelEXT, pmPSF *psf)
+{
+    // allocate a new pmModel to hold the PSF version
+    pmModel *modelPSF = pmModelAlloc (psf->type);
+
+    // set model parameters for this source based on PSF information
+    if (!modelEXT->modelFromPSF (modelPSF, modelEXT, psf)) {
+        psError(PM_ERR_PSF, false, "Failed to set model params from PSF");
+        psFree(modelPSF);
+        return NULL;
+    }
+    // XXX note that model->residuals is just a reference
+    modelPSF->residuals = psf->residuals;
+
+    return (modelPSF);
+}
 
 // instantiate a model for the PSF at this location with peak flux
Index: /branches/eam_branch_20070817/psModules/src/objects/pmModelUtils.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmModelUtils.h	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModelUtils.h	(revision 14612)
@@ -5,6 +5,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-08-17 21:01:59 $
+ * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-23 00:55:49 $
  * Copyright 2007 IfA, University of Hawaii
  */
@@ -15,4 +15,18 @@
 /// @addtogroup Objects Object Detection / Analysis Functions
 /// @{
+
+/**
+ *
+ * This function constructs a pmModel instance based on the pmPSF description
+ * of the PSF. The input is a pmModel with at least the values of the centroid
+ * coordinates (possibly normalization if this is needed) defined. The values of
+ * the PSF-dependent parameters are specified for the specific realization based
+ * on the coordinates of the object.
+ *
+ */
+pmModel *pmModelFromPSF(
+    pmModel *model,                     ///< Add comment
+    pmPSF *psf                          ///< Add comment
+);
 
 pmModel *pmModelFromPSFforXY (
@@ -28,4 +42,6 @@
     );
 
+
+
 /// @}
 # endif /* PM_MODEL_UTILS_H */
Index: /branches/eam_branch_20070817/psModules/src/objects/pmPSF.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmPSF.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmPSF.c	(revision 14612)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.25.6.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.25.6.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -28,9 +28,10 @@
 #include "pmMoments.h"
 #include "pmResiduals.h"
+#include "pmGrowthCurve.h"
+#include "pmPSF.h"
 #include "pmModel.h"
 #include "pmSource.h"
-#include "pmGrowthCurve.h"
-#include "pmPSF.h"
 #include "pmModelClass.h"
+#include "pmModelUtils.h"
 #include "pmSourcePhotometry.h"
 #include "pmFPAMaskWeight.h"
@@ -74,5 +75,5 @@
     psFree (psf->ApTrend);
     psFree (psf->growth);
-    psFree (psf->params_NEW);
+    psFree (psf->params);
     psFree (psf->residuals);
     return;
@@ -103,4 +104,6 @@
     psf->skyBias  = 0.0;
     psf->skySat   = 0.0;
+    psf->nPSFstars  = 0;
+    psf->nApResid   = 0;
     psf->poissonErrors = poissonErrors;
 
@@ -129,5 +132,5 @@
         return(NULL);
     }
-    psf->params_NEW = psArrayAlloc(Nparams);
+    psf->params = psArrayAlloc(Nparams);
 
     // the order of the PSF parameter (X,Y) fits is determined by the psfTrendMask polynomial
@@ -139,5 +142,5 @@
 
     if (psfTrendMask) {
-        for (int i = 0; i < psf->params_NEW->n; i++) {
+        for (int i = 0; i < psf->params->n; i++) {
             if (i == PM_PAR_SKY)
                 continue;
@@ -155,5 +158,5 @@
                 }
             }
-            psf->params_NEW->data[i] = param;
+            psf->params->data[i] = param;
         }
     }
@@ -161,25 +164,4 @@
     psMemSetDeallocator(psf, (psFreeFunc) pmPSFFree);
     return(psf);
-}
-
-/*****************************************************************************
-pmModelFromPSF (*modelEXT, *psf):  use the model position parameters to
-construct a realization of the PSF model at the object coordinates
- *****************************************************************************/
-pmModel *pmModelFromPSF (pmModel *modelEXT, pmPSF *psf)
-{
-    // allocate a new pmModel to hold the PSF version
-    pmModel *modelPSF = pmModelAlloc (psf->type);
-
-    // set model parameters for this source based on PSF information
-    if (!modelEXT->modelFromPSF (modelPSF, modelEXT, psf)) {
-        psError(PM_ERR_PSF, false, "Failed to set model params from PSF");
-        psFree(modelPSF);
-        return NULL;
-    }
-    // XXX note that model->residuals is just a reference
-    modelPSF->residuals = psf->residuals;
-
-    return (modelPSF);
 }
 
@@ -333,5 +315,5 @@
     pmPSF *psf = pmPSFAlloc (type, true, psfTrend);
 
-    psVector *par = psVectorAlloc (psf->params_NEW->n, PS_TYPE_F32);
+    psVector *par = psVectorAlloc (psf->params->n, PS_TYPE_F32);
     par->data.F32[PM_PAR_SXX] = sxx;
     par->data.F32[PM_PAR_SYY] = syy;
@@ -342,15 +324,15 @@
     // set the psf shape parameters
     psPolynomial2D *poly = NULL;
-    poly = psf->params_NEW->data[PM_PAR_E0];
+    poly = psf->params->data[PM_PAR_E0];
     poly->coeff[0][0] = pol.e0;
 
-    poly = psf->params_NEW->data[PM_PAR_E1];
+    poly = psf->params->data[PM_PAR_E1];
     poly->coeff[0][0] = pol.e1;
 
-    poly = psf->params_NEW->data[PM_PAR_E2];
+    poly = psf->params->data[PM_PAR_E2];
     poly->coeff[0][0] = pol.e2;
 
-    for (int i = PM_PAR_SXY + 1; i < psf->params_NEW->n; i++) {
-        poly = psf->params_NEW->data[i];
+    for (int i = PM_PAR_SXY + 1; i < psf->params->n; i++) {
+        poly = psf->params->data[i];
         poly->coeff[0][0] = (psF32)va_arg(ap, psF64);
     }
Index: /branches/eam_branch_20070817/psModules/src/objects/pmPSF.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmPSF.h	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmPSF.h	(revision 14612)
@@ -6,6 +6,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-06-20 02:22:26 $
+ * @version $Revision: 1.14.6.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-23 00:55:49 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -16,4 +16,7 @@
 /// @addtogroup Objects Object Detection / Analysis Functions
 /// @{
+
+// type of model carried by the pmModel structure
+typedef int pmModelType;
 
 typedef enum {
@@ -44,9 +47,6 @@
 typedef struct
 {
-    pmModelType type;   ///< PSF Model in use
-    psArray *params_NEW;   ///< Model parameters (psPolynomial2D)
-    // XXXXX I am changing params: we will allocate elements for the
-    // unfitted elements (So, Io, Xo, Yo) and leave them as NULL
-    // I am using a new name to catch all refs to params with gcc
+    pmModelType type;			///< PSF Model in use
+    psArray *params;			///< Model parameters (psPolynomial2D)
     psPolynomial1D *ChiTrend;         ///< Chisq vs flux fit (correction for systematic errors)
     psPolynomial4D *ApTrend;            ///< ApResid vs (x,y,rflux) (rflux = ten(0.4*mInst))
@@ -79,18 +79,4 @@
 );
 
-/**
- *
- * This function constructs a pmModel instance based on the pmPSF description
- * of the PSF. The input is a pmModel with at least the values of the centroid
- * coordinates (possibly normalization if this is needed) defined. The values of
- * the PSF-dependent parameters are specified for the specific realization based
- * on the coordinates of the object.
- *
- */
-pmModel *pmModelFromPSF(
-    pmModel *model,                     ///< Add comment
-    pmPSF *psf                          ///< Add comment
-);
-
 bool pmPSFMaskApTrend (psPolynomial4D *trend, pmPSFApTrendOptions option);
 
Index: /branches/eam_branch_20070817/psModules/src/objects/pmPSF_IO.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmPSF_IO.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmPSF_IO.c	(revision 14612)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.20.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.20.4.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -40,6 +40,6 @@
 #include "pmGrowthCurve.h"
 #include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmPSF_IO.h"
 #include "pmSource.h"
@@ -47,10 +47,10 @@
 #include "pmSourceIO.h"
 
-bool pmFPAviewCheckDataStatusForPSFmodel (const pmFPAview *view, const pmFPAfile *file)
+bool pmPSFmodelCheckDataStatusForView (const pmFPAview *view, const pmFPAfile *file)
 {
     pmFPA *fpa = file->fpa;
 
     if (view->chip == -1) {
-        bool exists = pmFPACheckDataStatusForPSFmodel (fpa);
+        bool exists = pmPSFmodelCheckDataStatusForFPA (fpa);
         return exists;
     }
@@ -62,5 +62,5 @@
 
     if (view->cell == -1) {
-        bool exists = pmChipCheckDataStatusForPSFmodel (chip);
+        bool exists = pmPSFmodelCheckDataStatusForChip (chip);
         return exists;
     }
@@ -69,60 +69,28 @@
         return false;
     }
-    pmCell *cell = chip->cells->data[view->cell];
-
-    if (view->readout == -1) {
-        bool exists = pmCellCheckDataStatusForPSFmodel (cell);
-        return exists;
-    }
-
-    if (view->readout >= cell->readouts->n) {
-        psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouds->n == %ld", view->readout, cell->readouts->n);
-        return false;
-    }
-    pmReadout *readout = cell->readouts->data[view->readout];
-
-    return pmReadoutCheckDataStatusForPSFmodel (readout);
-}
-
-bool pmFPACheckDataStatusForPSFmodel (const pmFPA *fpa) {
+    psError(PS_ERR_IO, false, "PSF only valid at the chip level");
+    return false;
+}
+
+bool pmPSFmodelCheckDataStatusForFPA (const pmFPA *fpa) {
 
     for (int i = 0; i < fpa->chips->n; i++) {
         pmChip *chip = fpa->chips->data[i];
         if (!chip) continue;
-        if (pmChipCheckDataStatusForPSFmodel (chip)) return true;
+        if (pmPSFmodelCheckDataStatusForChip (chip)) return true;
     }
     return false;
 }
 
-bool pmChipCheckDataStatusForPSFmodel (const pmChip *chip) {
-
-    for (int i = 0; i < chip->cells->n; i++) {
-        pmCell *cell = chip->cells->data[i];
-        if (!cell) continue;
-        if (pmCellCheckDataStatusForPSFmodel (cell)) return true;
-    }
-    return false;
-}
-
-bool pmCellCheckDataStatusForPSFmodel (const pmCell *cell) {
-
-    for (int i = 0; i < cell->readouts->n; i++) {
-        pmReadout *readout = cell->readouts->data[i];
-        if (!readout) continue;
-        if (pmReadoutCheckDataStatusForPSFmodel (readout)) return true;
-    }
-    return false;
-}
-
-bool pmReadoutCheckDataStatusForPSFmodel (const pmReadout *readout) {
+bool pmPSFmodelCheckDataStatusForChip (const pmChip *chip) {
 
     bool status;
 
     // select the psf of interest
-    pmPSF *psf = psMetadataLookupPtr(&status, readout->analysis, "PSPHOT.PSF");
+    pmPSF *psf = psMetadataLookupPtr(&status, chip->analysis, "PSPHOT.PSF");
     return psf ? true : false;
 }
 
-bool pmFPAviewWritePSFmodel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
+bool pmPSFmodelWriteForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
 
@@ -130,5 +98,5 @@
 
     if (view->chip == -1) {
-        if (!pmFPAWritePSFmodel(fpa, view, file, config)) {
+        if (!pmPSFmodelWriteFPA(fpa, view, file, config)) {
             psError(PS_ERR_IO, false, "Failed to write PSF for fpa");
             return false;
@@ -143,5 +111,5 @@
 
     if (view->cell == -1) {
-        if (!pmChipWritePSFmodel (chip, view, file, config)) {
+        if (!pmPSFmodelWriteChip (chip, view, file, config)) {
             psError(PS_ERR_IO, false, "Failed to write PSF for chip");
             return false;
@@ -150,36 +118,15 @@
     }
 
-    if (view->cell >= chip->cells->n) {
-        return false;
-    }
-    pmCell *cell = chip->cells->data[view->cell];
-
-    if (view->readout == -1) {
-        if (!pmCellWritePSFmodel (cell, view, file, config)) {
-            psError(PS_ERR_IO, false, "Failed to write PSF for cell");
-            return false;
-        }
-        return true;
-    }
-
-    if (view->readout >= cell->readouts->n) {
-        return false;
-    }
-    pmReadout *readout = cell->readouts->data[view->readout];
-
-    if (!pmReadoutWritePSFmodel (readout, view, file, config)) {
-        psError(PS_ERR_IO, false, "Failed to write PSF for readout");
-        return false;
-    }
-    return true;
+    psError(PS_ERR_IO, false, "PSF must be written at the chip level");
+    return false;
 }
 
 // read in all chip-level PSFmodel files for this FPA
-bool pmFPAWritePSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
+bool pmPSFmodelWriteFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
 
     for (int i = 0; i < fpa->chips->n; i++) {
         pmChip *chip = fpa->chips->data[i];
-        if (!pmChipWritePSFmodel (chip, view, file, config)) {
+        if (!pmPSFmodelWriteChip (chip, view, file, config)) {
             psError(PS_ERR_IO, false, "Failed to write PSF for %dth chip", i);
             return false;
@@ -190,39 +137,25 @@
 
 // read in all cell-level PSFmodel files for this chip
-bool pmChipWritePSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
-{
-    for (int i = 0; i < chip->cells->n; i++) {
-        pmCell *cell = chip->cells->data[i];
-        if (!pmCellWritePSFmodel (cell, view, file, config)) {
-            psError(PS_ERR_IO, false, "Failed to write PSF for %dth cell", i);
-            return false;
-        }
+bool pmPSFmodelWriteChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
+{
+    if (!pmPSFmodelWrite (chip->analysis, view, file, config)) {
+	psError(PS_ERR_IO, false, "Failed to write PSF for chip");
+	return false;
     }
     return true;
 }
 
-// read in all readout-level PSFmodel files for this cell
-bool pmCellWritePSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
-{
-    for (int i = 0; i < cell->readouts->n; i++) {
-        pmReadout *readout = cell->readouts->data[i];
-        if (!pmReadoutWritePSFmodel (readout, view, file, config)) {
-            psError(PS_ERR_IO, false, "Failed to write PSF for %dth readout", i);
-            return false;
-        }
-    }
-    return true;
-}
-
-// for each Readout (ie, analysed image), we write out
+// for a pmPSF supplied on the analysis metadata, we write out
 // - image header        : FITS Image NAXIS = 0
 // - psf table (+header) : FITS Table
 // - psf resid (+header) : FITS Image
 // if needed, we also write out a PHU blank header
-bool pmReadoutWritePSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
+bool pmPSFmodelWrite (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
     bool status;
     pmHDU *hdu;
     char *headName, *tableName, *residName;
+
+    if (!analysis) return false;
 
     // write a PHU? (only if input image is MEF)
@@ -300,7 +233,7 @@
 
     // select the psf of interest
-    pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
+    pmPSF *psf = psMetadataLookupPtr (&status, analysis, "PSPHOT.PSF");
     if (!psf) {
-	psError(PS_ERR_UNKNOWN, true, "missing PSF for this readout");
+	psError(PS_ERR_UNKNOWN, true, "missing PSF for this analysis metadata");
 	psFree (tableName);
 	psFree (residName);
@@ -324,5 +257,5 @@
 	for (int i = 0; i < nPar; i++) {
 	    char name[9];
-	    psPolynomial2D *poly = psf->params_NEW->data[i];
+	    psPolynomial2D *poly = psf->params->data[i];
 	    if (poly == NULL) continue;
 	    snprintf (name, 9, "PAR%02d_NX", i);
@@ -344,5 +277,5 @@
 	psArray *psfTable = psArrayAllocEmpty (100);
 	for (int i = 0; i < nPar; i++) {
-	    psPolynomial2D *poly = psf->params_NEW->data[i];
+	    psPolynomial2D *poly = psf->params->data[i];
 	    if (poly == NULL) continue; // skip unset parameters (eg, XPOS)
 	    for (int ix = 0; ix <= poly->nX; ix++) {
@@ -445,5 +378,5 @@
 
 // if this file needs to have a PHU written out, write one
-bool pmPSF_WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) {
+bool pmPSFmodelWritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) {
 
     // not needed if already written
@@ -487,5 +420,5 @@
 }
 
-bool pmFPAviewReadPSFmodel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
+bool pmPSFmodelReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
 
@@ -493,5 +426,5 @@
 
     if (view->chip == -1) {
-        return pmFPAReadPSFmodel(fpa, view, file, config);
+        return pmPSFmodelReadFPA(fpa, view, file, config);
     }
 
@@ -502,31 +435,18 @@
 
     if (view->cell == -1) {
-        return pmChipReadPSFmodel(chip, view, file, config);
-    }
-
-    if (view->cell >= chip->cells->n) {
-        psAbort("Programming error: view does not apply to FPA.");
-    }
-    pmCell *cell = chip->cells->data[view->cell];
-
-    if (view->readout == -1) {
-        return pmCellReadPSFmodel(cell, view, file, config);
-    }
-
-    if (view->readout >= cell->readouts->n) {
-        psAbort("Programming error: view does not apply to FPA.");
-    }
-    pmReadout *readout = cell->readouts->data[view->readout];
-
-    return pmReadoutReadPSFmodel(readout, view, file, config);
+        return pmPSFmodelReadChip(chip, view, file, config);
+    }
+
+    psError(PS_ERR_IO, false, "PSF must be read at the chip level");
+    return false;
 }
 
 // read in all chip-level PSFmodel files for this FPA
-bool pmFPAReadPSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
+bool pmPSFmodelReadFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
     bool success = true;                // Was everything successful?
     for (int i = 0; i < fpa->chips->n; i++) {
         pmChip *chip = fpa->chips->data[i];
-        success &= pmChipReadPSFmodel(chip, view, file, config);
+        success &= pmPSFmodelReadChip(chip, view, file, config);
     }
     return success;
@@ -534,28 +454,16 @@
 
 // read in all cell-level PSFmodel files for this chip
-bool pmChipReadPSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
-{
-    bool success = true;                // Was everything successful?
-    for (int i = 0; i < chip->cells->n; i++) {
-        pmCell *cell = chip->cells->data[i];
-        success &= pmCellReadPSFmodel (cell, view, file, config);
-    }
-    return success;
-}
-
-// read in all readout-level PSFmodel files for this cell
-bool pmCellReadPSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
-{
-    bool success = true;                // Was everything successful?
-    for (int i = 0; i < cell->readouts->n; i++) {
-        pmReadout *readout = cell->readouts->data[i];
-        success &= pmReadoutReadPSFmodel(readout, view, file, config);
-    }
-    return success;
+bool pmPSFmodelReadChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
+{
+    if (!pmPSFmodelRead (chip->analysis, view, file, config)) {
+	psError(PS_ERR_IO, false, "Failed to write PSF for chip");
+	return false;
+    }
+    return true;
 }
 
 // for each Readout (ie, analysed image), we write out: header + table with PSF model parameters,
 // and header + image for the PSF residual images
-bool pmReadoutReadPSFmodel(pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
+bool pmPSFmodelRead (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
     bool status;
@@ -627,5 +535,5 @@
 	    return false;
 	}
-        psf->params_NEW->data[i] = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder);
+        psf->params->data[i] = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder);
     }
 
@@ -650,5 +558,5 @@
         // XXX sanity check here
 
-        psPolynomial2D *poly = psf->params_NEW->data[iPar];
+        psPolynomial2D *poly = psf->params->data[iPar];
 	if (poly == NULL) {
 	    psError(PS_ERR_UNKNOWN, true, "values for parameter %d, but missing NX", iPar);
@@ -698,5 +606,5 @@
     }
 
-    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF",     PS_DATA_UNKNOWN,  "psphot psf", psf);
+    psMetadataAdd (analysis, PS_LIST_TAIL, "PSPHOT.PSF",     PS_DATA_UNKNOWN,  "psphot psf", psf);
     psFree (psf);
 
@@ -708,6 +616,5 @@
 }
 
-/************ old support functions, deprecate? **************/
-
+// create a psMetadata representation (human-readable) of a psf model
 psMetadata *pmPSFtoMetadata (psMetadata *metadata, pmPSF *psf)
 {
@@ -724,5 +631,5 @@
 
     for (int i = 0; i < nPar; i++) {
-        psPolynomial2D *poly = psf->params_NEW->data[i];
+        psPolynomial2D *poly = psf->params->data[i];
         if (poly == NULL)
             continue;
@@ -742,4 +649,5 @@
 }
 
+// parse a psMetadata representation (human-readable) of a psf model
 pmPSF *pmPSFfromMetadata (psMetadata *metadata)
 {
@@ -770,6 +678,6 @@
             continue;
         psPolynomial2D *poly = psPolynomial2DfromMetadata (folder);
-        psFree (psf->params_NEW->data[i]);
-        psf->params_NEW->data[i] = poly;
+        psFree (psf->params->data[i]);
+        psf->params->data[i] = poly;
     }
     sprintf (keyword, "APTREND");
@@ -789,64 +697,2 @@
     return (psf);
 }
-
-// read in all readout-level Objects files for this cell
-bool pmReadoutWritePSFmodel_Config (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
-{
-    bool status;
-    char *filename;
-    char *realname;
-
-    pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
-
-    switch (file->type) {
-      case PM_FPA_FILE_PSF:
-        filename = pmFPAfileNameFromRule (file->filerule, file, view);
-        bool create = file->mode == PM_FPA_MODE_WRITE ? true : false;
-        realname = pmConfigConvertFilename (filename, config, create);
-
-        psMetadata *psfData = pmPSFtoMetadata (NULL, psf);
-        psMetadataConfigWrite (psfData, realname);
-        psFree (psfData);
-        psFree (realname);
-        psFree (filename);
-        return true;
-
-      default:
-        fprintf (stderr, "warning: type mismatch\n");
-        break;
-    }
-    return false;
-}
-
-// read in all readout-level Objects files for this cell
-bool pmReadoutReadPSFmodel_Config (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
-{
-
-    unsigned int Nfail;
-    char *filename;
-    char *realname;
-
-    switch (file->type) {
-      case PM_FPA_FILE_PSF:
-        filename = pmFPAfileNameFromRule (file->filerule, file, view);
-        bool create = file->mode == PM_FPA_MODE_WRITE ? true : false;
-        realname = pmConfigConvertFilename (filename, config, create);
-
-        psMetadata *psfData = psMetadataConfigRead(NULL, &Nfail, realname, FALSE);
-        pmPSF *psf = pmPSFfromMetadata (psfData);
-        psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN, "psphot psf", psf);
-
-        psFree (psf);
-        psFree (psfData);
-        psFree (realname);
-        psFree (filename);
-
-        return true;
-
-      default:
-        fprintf (stderr, "warning: type mismatch\n");
-        break;
-    }
-    return false;
-}
-
Index: /branches/eam_branch_20070817/psModules/src/objects/pmPSF_IO.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmPSF_IO.h	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmPSF_IO.h	(revision 14612)
@@ -6,6 +6,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-07-14 03:20:22 $
+ * @version $Revision: 1.8.4.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-23 00:55:49 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -17,25 +17,22 @@
 /// @{
 
+bool pmPSFmodelWriteForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
+bool pmPSFmodelWriteFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
+bool pmPSFmodelWriteChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
+bool pmPSFmodelWrite (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
+
+bool pmPSFmodelWritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
+
+bool pmPSFmodelReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
+bool pmPSFmodelReadFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
+bool pmPSFmodelReadChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
+bool pmPSFmodelRead (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
+
+bool pmPSFmodelCheckDataStatusForView (const pmFPAview *view, const pmFPAfile *file);
+bool pmPSFmodelCheckDataStatusForFPA (const pmFPA *fpa);
+bool pmPSFmodelCheckDataStatusForChip (const pmChip *chip);
+
 psMetadata *pmPSFtoMetadata (psMetadata *metadata, pmPSF *psf);
 pmPSF *pmPSFfromMetadata (psMetadata *metadata);
-bool pmFPAviewWritePSFmodel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
-bool pmFPAWritePSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
-bool pmChipWritePSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
-bool pmCellWritePSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
-bool pmReadoutWritePSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
-
-bool pmPSF_WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
-
-bool pmFPAviewReadPSFmodel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
-bool pmFPAReadPSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
-bool pmChipReadPSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
-bool pmCellReadPSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
-bool pmReadoutReadPSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
-
-bool pmFPAviewCheckDataStatusForPSFmodel (const pmFPAview *view, const pmFPAfile *file);
-bool pmFPACheckDataStatusForPSFmodel (const pmFPA *fpa);
-bool pmChipCheckDataStatusForPSFmodel (const pmChip *chip);
-bool pmCellCheckDataStatusForPSFmodel (const pmCell *cell);
-bool pmReadoutCheckDataStatusForPSFmodel (const pmReadout *readout);
 
 /// @}
Index: /branches/eam_branch_20070817/psModules/src/objects/pmPSFtry.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmPSFtry.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmPSFtry.c	(revision 14612)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.43.6.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.43.6.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -23,11 +23,12 @@
 #include "pmMoments.h"
 #include "pmResiduals.h"
+#include "pmGrowthCurve.h"
+#include "pmPSF.h"
 #include "pmModel.h"
 #include "pmSource.h"
 #include "pmSourceUtils.h"
-#include "pmGrowthCurve.h"
-#include "pmPSF.h"
 #include "pmPSFtry.h"
 #include "pmModelClass.h"
+#include "pmModelUtils.h"
 #include "pmSourceFitModel.h"
 #include "pmSourcePhotometry.h"
@@ -413,9 +414,9 @@
     // This way, the parameters masked by one of the fits will be applied to the others
     for (int i = 0; i < stats->clipIter; i++) {
-        psVectorClipFitPolynomial2D (psf->params_NEW->data[PM_PAR_E0], stats, psfTry->mask, 0xff, e0, dz, x, y);
+        psVectorClipFitPolynomial2D (psf->params->data[PM_PAR_E0], stats, psfTry->mask, 0xff, e0, dz, x, y);
         psTrace ("psModules.pmPSFtry", 4, "clipped E0 : keeping %ld of %ld\n", stats->clippedNvalues, e0->n);
-        psVectorClipFitPolynomial2D (psf->params_NEW->data[PM_PAR_E1], stats, psfTry->mask, 0xff, e1, dz, x, y);
+        psVectorClipFitPolynomial2D (psf->params->data[PM_PAR_E1], stats, psfTry->mask, 0xff, e1, dz, x, y);
         psTrace ("psModules.pmPSFtry", 4, "clipped E1 : keeping %ld of %ld\n", stats->clippedNvalues, e1->n);
-        psVectorClipFitPolynomial2D (psf->params_NEW->data[PM_PAR_E2], stats, psfTry->mask, 0xff, e2, dz, x, y);
+        psVectorClipFitPolynomial2D (psf->params->data[PM_PAR_E2], stats, psfTry->mask, 0xff, e2, dz, x, y);
         psTrace ("psModules.pmPSFtry", 4, "clipped E2 : keeping %ld of %ld\n", stats->clippedNvalues, e2->n);
     }
@@ -437,5 +438,5 @@
 
     // skip the unfitted parameters (X, Y, Io, Sky) and the shape parameters (SXX, SYY, SXY)
-    for (int i = 0; i < psf->params_NEW->n; i++) {
+    for (int i = 0; i < psf->params->n; i++) {
         switch (i) {
           case PM_PAR_SKY:
@@ -462,5 +463,5 @@
         // the mask is carried from previous steps and updated with this operation
         // the weight is either the flux error or NULL, depending on 'applyWeights'
-        if (!psVectorClipFitPolynomial2D(psf->params_NEW->data[i], stats, psfTry->mask, 0xff, z, NULL, x, y)) {
+        if (!psVectorClipFitPolynomial2D(psf->params->data[i], stats, psfTry->mask, 0xff, z, NULL, x, y)) {
             psError(PS_ERR_UNKNOWN, false, "failed to build psf model for parameter %d", i);
             psFree(stats);
@@ -490,6 +491,6 @@
             fprintf (f, "%f %f : ", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]);
 
-            for (int i = 0; i < psf->params_NEW->n; i++) {
-                if (psf->params_NEW->data[i] == NULL)
+            for (int i = 0; i < psf->params->n; i++) {
+                if (psf->params->data[i] == NULL)
                     continue;
                 fprintf (f, "%f %f : ", model->params->data.F32[i], modelPSF->params->data.F32[i]);
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSource.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSource.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSource.c	(revision 14612)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.34.2.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-20 01:58:16 $
+ *  @version $Revision: 1.34.2.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -27,4 +27,6 @@
 #include "pmMoments.h"
 #include "pmResiduals.h"
+#include "pmGrowthCurve.h"
+#include "pmPSF.h"
 #include "pmModel.h"
 #include "pmSource.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSource.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSource.h	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSource.h	(revision 14612)
@@ -3,6 +3,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.16.2.2 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-08-20 01:58:16 $
+ * @version $Revision: 1.16.2.3 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-23 00:55:49 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -57,6 +57,5 @@
  *
  */
-typedef struct
-{
+struct pmSource {
     const int id;                       ///< Unique ID for object
     pmPeak *peak;                       ///< Description of peak pixel.
@@ -81,6 +80,5 @@
     psRegion region;                    ///< area on image covered by selected pixels
     float sky, skyErr;                  ///< The sky and its error at the center of the object
-}
-pmSource;
+};
 
 /** pmPSFClump data structure
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceContour.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceContour.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceContour.c	(revision 14612)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-04-21 19:47:14 $
+ *  @version $Revision: 1.7.8.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -26,4 +26,6 @@
 #include "pmMoments.h"
 #include "pmResiduals.h"
+#include "pmGrowthCurve.h"
+#include "pmPSF.h"
 #include "pmModel.h"
 #include "pmSource.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceFitModel.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceFitModel.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceFitModel.c	(revision 14612)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.24.4.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-20 01:58:16 $
+ *  @version $Revision: 1.24.4.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -27,6 +27,6 @@
 #include "pmGrowthCurve.h"
 #include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmModelClass.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceFitSet.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceFitSet.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceFitSet.c	(revision 14612)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.3.2.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-20 01:58:16 $
+ *  @version $Revision: 1.3.2.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -27,6 +27,6 @@
 #include "pmGrowthCurve.h"
 #include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmModelClass.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO.c	(revision 14612)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.45.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.45.4.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -34,6 +34,6 @@
 #include "pmGrowthCurve.h"
 #include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmModelClass.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_CMP.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_CMP.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_CMP.c	(revision 14612)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.29.8.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.29.8.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -32,6 +32,6 @@
 #include "pmGrowthCurve.h"
 #include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmModelClass.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_OBJ.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_OBJ.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_OBJ.c	(revision 14612)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.13.8.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.13.8.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -32,6 +32,6 @@
 #include "pmGrowthCurve.h"
 #include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmModelClass.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_PS1_DEV_0.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_PS1_DEV_0.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_PS1_DEV_0.c	(revision 14612)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.10.8.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.10.8.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -32,6 +32,6 @@
 #include "pmGrowthCurve.h"
 #include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmModelClass.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_RAW.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_RAW.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_RAW.c	(revision 14612)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.15.8.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.15.8.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -32,6 +32,6 @@
 #include "pmGrowthCurve.h"
 #include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmModelClass.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SMPDATA.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SMPDATA.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SMPDATA.c	(revision 14612)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.9.8.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.9.8.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -30,8 +30,8 @@
 #include "pmPeaks.h"
 #include "pmMoments.h"
+#include "pmResiduals.h"
 #include "pmGrowthCurve.h"
-#include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmModelClass.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SX.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SX.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SX.c	(revision 14612)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.11.8.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.11.8.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -32,6 +32,6 @@
 #include "pmGrowthCurve.h"
 #include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmModelClass.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourcePhotometry.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourcePhotometry.c	(revision 14612)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.28.6.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-17 21:01:59 $
+ *  @version $Revision: 1.28.6.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -26,6 +26,6 @@
 #include "pmGrowthCurve.h"
 #include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmModelClass.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourcePlotApResid.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourcePlotApResid.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourcePlotApResid.c	(revision 14612)
@@ -4,6 +4,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-05-22 21:45:48 $
+ *  @version $Revision: 1.2.6.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *  Copyright 2006 IfA, University of Hawaii
  */
@@ -27,8 +27,8 @@
 #include "pmPeaks.h"
 #include "pmMoments.h"
+#include "pmResiduals.h"
 #include "pmGrowthCurve.h"
-#include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmSourcePlots.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourcePlotMoments.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourcePlotMoments.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourcePlotMoments.c	(revision 14612)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-05-22 21:45:48 $
+ *  @version $Revision: 1.7.6.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2006 IfA, University of Hawaii
@@ -32,6 +32,6 @@
 #include "pmGrowthCurve.h"
 #include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmSourcePlots.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourcePlotPSFModel.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourcePlotPSFModel.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourcePlotPSFModel.c	(revision 14612)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-05-22 21:45:48 $
+ *  @version $Revision: 1.9.6.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2006 IfA, University of Hawaii
@@ -32,6 +32,6 @@
 #include "pmGrowthCurve.h"
 #include "pmResiduals.h"
+#include "pmPSF.h"
 #include "pmModel.h"
-#include "pmPSF.h"
 #include "pmSource.h"
 #include "pmSourcePlots.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceSky.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceSky.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceSky.c	(revision 14612)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-06-20 02:22:26 $
+ *  @version $Revision: 1.13.6.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -27,4 +27,6 @@
 #include "pmMoments.h"
 #include "pmResiduals.h"
+#include "pmGrowthCurve.h"
+#include "pmPSF.h"
 #include "pmModel.h"
 #include "pmSource.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceUtils.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceUtils.c	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceUtils.c	(revision 14612)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-20 01:58:16 $
+ *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-23 00:55:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -27,4 +27,6 @@
 #include "pmMoments.h"
 #include "pmResiduals.h"
+#include "pmGrowthCurve.h"
+#include "pmPSF.h"
 #include "pmModel.h"
 #include "pmSource.h"
@@ -60,5 +62,5 @@
 }
 
-pmSource *pmSourceFromModel (pmModel *model, pmReadout *readout, pmSourceType type) {
+pmSource *pmSourceFromModel (pmModel *model, pmReadout *readout, float radius, pmSourceType type) {
 
     pmSource *source = pmSourceAlloc ();
@@ -75,4 +77,5 @@
 	psAbort ("invalid source type");
     }
+    source->type = type;
 
     pmCell *cell = readout->parent;
@@ -89,7 +92,9 @@
     int yParityCell = psMetadataLookupS32(NULL, cell->concepts, "CELL.YPARITY");
 
-    // XXX whose binning? 
-    int xBin = psMetadataLookupS32(NULL, cell->concepts, "CELL.XBIN"); // Binning in x and y
-    int yBin = psMetadataLookupS32(NULL, cell->concepts, "CELL.YBIN"); // Binning in x and y
+    // XXX fix the binning : currently not selected from concepts
+    // int xBin = psMetadataLookupS32(NULL, cell->concepts, "CELL.XBIN"); // Binning in x and y
+    // int yBin = psMetadataLookupS32(NULL, cell->concepts, "CELL.YBIN"); // Binning in x and y
+    int xBin = 1;
+    int yBin = 1;
 
     // Position on the cell 
@@ -101,6 +106,4 @@
     // float yReadout = CELL_TO_READOUT(yCell, y0Readout);
     
-    float radius = 5.0; // XXX need to define the radius in some rational way
-
     pmSourceDefinePixels (source, readout, xCell, yCell, radius);
 
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceUtils.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceUtils.h	(revision 14611)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceUtils.h	(revision 14612)
@@ -5,6 +5,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-08-17 21:01:59 $
+ * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-23 00:55:49 $
  * Copyright 2007 IfA, University of Hawaii
  */
@@ -33,4 +33,5 @@
   pmModel *model, 
   pmReadout *readout, 
+  float radius,
   pmSourceType type
   );
