Index: /branches/eam_branch_20070817/psModules/src/astrom/pmAstrometryObjects.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/astrom/pmAstrometryObjects.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/astrom/pmAstrometryObjects.c	(revision 14544)
@@ -8,6 +8,6 @@
 *  @author EAM, IfA
 *
-*  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2007-06-22 00:40:01 $
+*  @version $Revision: 1.31.4.1 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2007-08-17 21:01:59 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -135,6 +135,6 @@
     PS_ASSERT_PTR_NON_NULL(st2, NULL); \
     \
-    assert(st1->n == 0 || pmIsAstromObj(st1->data[0])); \
-    assert(st2->n == 0 || pmIsAstromObj(st2->data[0])); \
+    assert(st1->n == 0 || pmAstromObjTest(st1->data[0])); \
+    assert(st2->n == 0 || pmAstromObjTest(st2->data[0])); \
     \
     /* sort both lists by X coord; st1 first */ \
@@ -400,5 +400,5 @@
 }
 
-bool pmIsAstromObj(const psPtr ptr)
+bool pmAstromObjTest(const psPtr ptr)
 {
     return (psMemGetDeallocator(ptr) == (psFreeFunc)astromObjFree);
Index: /branches/eam_branch_20070817/psModules/src/astrom/pmAstrometryObjects.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/astrom/pmAstrometryObjects.h	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/astrom/pmAstrometryObjects.h	(revision 14544)
@@ -4,6 +4,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-24 02:54:14 $
+ * @version $Revision: 1.15.14.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-17 21:01:59 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -293,5 +293,5 @@
  * Is a given pointer a pmAstromObj?
  */
-bool pmIsAstromObj(const psPtr ptr);
+bool pmAstromObjTest(const psPtr ptr);
 
 
Index: /branches/eam_branch_20070817/psModules/src/objects/Makefile.am
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/Makefile.am	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/Makefile.am	(revision 14544)
@@ -7,6 +7,8 @@
      pmMoments.c \
      pmModel.c \
-     pmModelGroup.c \
+     pmModelClass.c \
+     pmModelUtils.c \
      pmSource.c \
+     pmSourceUtils.c \
      pmSourceSky.c \
      pmSourceContour.c \
@@ -31,10 +33,10 @@
 
 EXTRA_DIST = \
-	models/pmModel_GAUSS.c \
-	models/pmModel_PGAUSS.c \
-	models/pmModel_QGAUSS.c \
-	models/pmModel_SGAUSS.c \
-	models/pmModel_RGAUSS.c \
-	models/pmModel_SERSIC.c
+     models/pmModel_GAUSS.c \
+     models/pmModel_PGAUSS.c \
+     models/pmModel_QGAUSS.c \
+     models/pmModel_SGAUSS.c \
+     models/pmModel_RGAUSS.c \
+     models/pmModel_SERSIC.c
 
 pkginclude_HEADERS = \
@@ -42,6 +44,8 @@
      pmMoments.h \
      pmModel.h \
-     pmModelGroup.h \
+     pmModelClass.h \
+     pmModelUtils.h \
      pmSource.h \
+     pmSourceUtils.h \
      pmSourceSky.h \
      pmSourceContour.h \
Index: /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_GAUSS.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_GAUSS.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/models/pmModel_GAUSS.c	(revision 14544)
@@ -19,11 +19,12 @@
  *****************************************************************************/
 
-# define PM_MODEL_FUNC       pmModelFunc_GAUSS
-# define PM_MODEL_FLUX       pmModelFlux_GAUSS
-# define PM_MODEL_GUESS      pmModelGuess_GAUSS
-# define PM_MODEL_LIMITS     pmModelLimits_GAUSS
-# define PM_MODEL_RADIUS     pmModelRadius_GAUSS
-# define PM_MODEL_FROM_PSF   pmModelFromPSF_GAUSS
-# define PM_MODEL_FIT_STATUS pmModelFitStatus_GAUSS
+# define PM_MODEL_FUNC       	  pmModelFunc_GAUSS
+# define PM_MODEL_FLUX       	  pmModelFlux_GAUSS
+# define PM_MODEL_GUESS      	  pmModelGuess_GAUSS
+# define PM_MODEL_LIMITS     	  pmModelLimits_GAUSS
+# define PM_MODEL_RADIUS     	  pmModelRadius_GAUSS
+# define PM_MODEL_FROM_PSF   	  pmModelFromPSF_GAUSS
+# define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_GAUSS
+# define PM_MODEL_FIT_STATUS      pmModelFitStatus_GAUSS
 
 psF32 PM_MODEL_FUNC(psVector *deriv,
@@ -185,6 +186,9 @@
 
 // make an initial guess for parameters
-bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
-{
+bool PM_MODEL_GUESS (void *inModel, void *inSource)
+{
+    pmModel *model = inModel;
+    pmSource *source = inSource;
+
     pmMoments *moments = source->moments;
     psF32     *PAR  = model->params->data.F32;
@@ -255,6 +259,9 @@
 
 // construct the PSF model from the FLT model and the psf
-bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf)
-{
+bool PM_MODEL_FROM_PSF (void *inModelPSF, void *inModelFLT, void *inPSF)
+{
+    pmModel *modelPSF = inModelPSF;
+    pmModel *modelFLT = inModelFLT;
+    pmPSF *psf = inPSF;
 
     psF32 *out = modelPSF->params->data.F32;
@@ -306,9 +313,62 @@
 }
 
+// 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;
+
+    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);
+
+    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_NEW->n; i++) {
+	if (i == PM_PAR_SKY) continue;
+	psPolynomial2D *poly = psf->params_NEW->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_NEW->n; i++) {
+        // apply the limits to all components or just the psf-model parameters?
+        if (psf->params_NEW->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);
+}
+
 // check the status of the fitted model
 // this test is invalid if the parameters are derived
 // from the PSF model
-bool PM_MODEL_FIT_STATUS (pmModel *model)
-{
+bool PM_MODEL_FIT_STATUS (void *inModel)
+{
+    pmModel *model = inModel;
 
     psF32 dP;
@@ -339,3 +399,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/pmModel.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmModel.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModel.c	(revision 14544)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @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-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -23,14 +23,5 @@
 #include "pmResiduals.h"
 #include "pmModel.h"
-
-/* The following types and functions need to be known by pmModel.c and are defined in
-   pmModelGroup.h.  The use of pmSource and other types in pmModelGroup.h prevent us from
-   directly including it here  ***/
-
-typedef psMinimizeLMChi2Func pmModelFunc;
-typedef bool (*pmModelFitStatusFunc)(pmModel *model);
-pmModelFunc pmModelFunc_GetFunction (pmModelType type);
-pmModelFitStatusFunc pmModelFitStatusFunc_GetFunction (pmModelType type);
-int pmModelParameterCount(pmModelType type);
+#include "pmModelClass.h"
 
 static void modelFree(pmModel *tmp)
@@ -45,5 +36,4 @@
 pmModelAlloc(): Allocate the pmModel structure, along with its parameters,
 and initialize the type member.  Initialize the params to 0.0.
-XXX EAM: simplifying code with pmModelParameterCount
 *****************************************************************************/
 pmModel *pmModelAlloc(pmModelType type)
@@ -53,4 +43,10 @@
     pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel));
     psMemSetDeallocator(tmp, (psFreeFunc) modelFree);
+
+    pmModelClass *class = pmModelClassSelect (type);
+    if (class == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
+        return(NULL);
+    }
 
     tmp->type = type;
@@ -62,12 +58,11 @@
     tmp->residuals = NULL;              // XXX should the model own this memory?
 
-    psS32 Nparams = pmModelParameterCount(type);
-    if (Nparams == 0) {
-        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
-        return(NULL);
-    }
+    psS32 Nparams = pmModelClassParameterCount(type);
+    assert (Nparams);
 
     tmp->params  = psVectorAlloc(Nparams, PS_TYPE_F32);
     tmp->dparams = psVectorAlloc(Nparams, PS_TYPE_F32);
+    assert (tmp->params);
+    assert (tmp->dparams);
 
     for (psS32 i = 0; i < tmp->params->n; i++) {
@@ -75,4 +70,13 @@
         tmp->dparams->data.F32[i] = 0.0;
     }
+
+    tmp->modelFunc   	    = class->modelFunc;
+    tmp->modelFlux   	    = class->modelFlux;
+    tmp->modelRadius 	    = class->modelRadius;
+    tmp->modelLimits 	    = class->modelLimits;
+    tmp->modelGuess         = class->modelGuess;
+    tmp->modelFromPSF       = class->modelFromPSF;
+    tmp->modelParamsFromPSF = class->modelParamsFromPSF;
+    tmp->modelFitStatus     = class->modelFitStatus;
 
     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
@@ -92,11 +96,11 @@
     new->radiusFit = model->radiusFit;
 
-    // XXX note that model->residuals is just a reference
-    new->residuals = model->residuals;
-
     for (int i = 0; i < new->params->n; i++) {
         new->params->data.F32[i]  = model->params->data.F32[i];
         new->dparams->data.F32[i] = model->dparams->data.F32[i];
     }
+
+    // note that model->residuals is just a reference
+    new->residuals = model->residuals;
 
     return (new);
@@ -123,8 +127,26 @@
     x->data.F32[1] = (psF32) (row + image->row0);
     psF32 tmpF;
-    pmModelFunc modelFunc;
-
-    modelFunc = pmModelFunc_GetFunction (model->type);
-    tmpF = modelFunc (NULL, model->params, x);
+
+    tmpF = model->modelFunc (NULL, model->params, x);
+    psFree(x);
+    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
+    return(tmpF);
+}
+
+psF32 pmModelEvalWithOffset(pmModel *model, psImage *image, psS32 col, psS32 row, int dx, int dy)
+{
+    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
+    PS_ASSERT_PTR_NON_NULL(image, false);
+    PS_ASSERT_PTR_NON_NULL(model, false);
+    PS_ASSERT_PTR_NON_NULL(model->params, false);
+
+    // Allocate the x coordinate structure and convert row/col to image space.
+    //
+    psVector *x = psVectorAlloc(2, PS_TYPE_F32);
+    x->data.F32[0] = (psF32) (col + image->col0 + dx);
+    x->data.F32[1] = (psF32) (row + image->row0 + dy);
+    psF32 tmpF;
+
+    tmpF = model->modelFunc (NULL, model->params, x);
     psFree(x);
     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
@@ -137,5 +159,7 @@
                           pmModelOpMode mode,
                           bool add,
-                          psMaskType maskVal
+                          psMaskType maskVal,
+			  int dx,
+			  int dy
     )
 {
@@ -148,5 +172,5 @@
     psVector *x = psVectorAlloc(2, PS_TYPE_F32);
     psVector *params = model->params;
-    pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
+
     psS32 imageCol;
     psS32 imageRow;
@@ -209,6 +233,6 @@
             // Convert i/j to image coord space:
             // XXX should we use using 0.5 pixel offset?
-            imageCol = ix + image->col0;
-            imageRow = iy + image->row0;
+            imageCol = ix + image->col0 + dx;
+            imageRow = iy + image->row0 + dy;
 
             x->data.F32[0] = (float) imageCol;
@@ -219,5 +243,5 @@
             // add in the desired components for this coordinate
             if (mode & PM_MODEL_OP_FUNC) {
-                pixelValue += modelFunc (NULL, params, x);
+                pixelValue += model->modelFunc (NULL, params, x);
             }
 
@@ -280,5 +304,5 @@
 {
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
-    psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal);
+    psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, 0.0, 0.0);
     psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     return(rc);
@@ -294,19 +318,38 @@
 {
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
-    psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal);
+    psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, 0.0, 0.0);
     psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     return(rc);
 }
 
-// check for success of model fit
-bool pmModelFitStatus (pmModel *model)
-{
-
-    bool status;
-
-    pmModelFitStatusFunc statusFunc = pmModelFitStatusFunc_GetFunction (model->type);
-    status = statusFunc (model);
-
-    return (status);
-}
-
+/******************************************************************************
+ *****************************************************************************/
+bool pmModelAddWithOffset(psImage *image,
+			  psImage *mask,
+			  pmModel *model,
+			  pmModelOpMode mode,
+			  psMaskType maskVal,
+			  int dx,
+			  int dy)
+{
+    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
+    psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, dx, dy);
+    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
+    return(rc);
+}
+
+/******************************************************************************
+ *****************************************************************************/
+bool pmModelSubWithOffset(psImage *image,
+			  psImage *mask,
+			  pmModel *model,
+			  pmModelOpMode mode,
+			  psMaskType maskVal,
+			  int dx,
+			  int dy)
+{
+    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
+    psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, dx, dy);
+    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
+    return(rc);
+}
Index: /branches/eam_branch_20070817/psModules/src/objects/pmModel.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmModel.h	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModel.h	(revision 14544)
@@ -1,3 +1,3 @@
-/* @file  pmObjects.h
+/* @file  pmModel.h
  * @brief Functions to define and manipulate object models
  *
@@ -5,6 +5,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-06-20 02:22:26 $
+ * @version $Revision: 1.11.6.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-17 21:01:59 $
  *
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -14,6 +14,13 @@
 # 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
 /// @{
+
+/* 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
@@ -41,4 +48,32 @@
 } pmModelOpMode;
 
+//  This function is the model chi-square minimization function for this model.
+typedef psMinimizeLMChi2Func pmModelFunc;
+
+//  This function sets the parameter limits for this model.
+typedef psMinimizeLMLimitFunc pmModelLimits;
+
+// This function returns the integrated flux for the given model parameters.
+typedef psF64 (*pmModelFlux)(const psVector *params);
+
+// This function returns the radius at which the given model and parameters
+// achieves the given flux.
+typedef psF64 (*pmModelRadius)(const psVector *params, double flux);
+
+//  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);
+
+//  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);
+
+//  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);
+
+//  This function returns the success / failure status of the given model fit
+typedef bool (*pmModelFitStatusFunc)(TMP_MODEL_TYPE *model);
+
 /** pmModel data structure
  *
@@ -62,11 +97,15 @@
     float radiusFit;                    ///< fit radius actually used
     pmResiduals *residuals;             ///< normalized PSF residuals
-}
-pmModel;
 
-/* XXX we are currently saving the residuals with the pmModel.  It might be better to save this
- * in the pmSource.  we may want an API to Add/Sub a pmModel (analytical model only) or a
- * pmSource (analytical + residuals).
- */
+    // functions for this model which depend on the model class
+    pmModelFunc          modelFunc;
+    pmModelFlux          modelFlux;
+    pmModelRadius        modelRadius;
+    pmModelLimits        modelLimits;
+    pmModelGuessFunc     modelGuess;
+    pmModelFromPSFFunc   modelFromPSF;
+    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 14544)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModelClass.c	(revision 14544)
@@ -0,0 +1,141 @@
+/** @file  pmModelClass.c
+ *
+ *  Functions to define and manipulate object model attributes
+ *
+ *  @author GLG, MHPCC
+ *  @author EAM, IfA
+ *
+ *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+#include <pslib.h>
+#include "pmHDU.h"
+#include "pmFPA.h"
+#include "pmPeaks.h"
+#include "pmMoments.h"
+#include "pmGrowthCurve.h"
+#include "pmResiduals.h"
+#include "pmModel.h"
+#include "pmPSF.h"
+#include "pmSource.h"
+#include "pmModelClass.h"
+#include "pmErrorCodes.h"
+
+// XXX shouldn't these be defined for us in pslib.h ???
+double hypot(double x, double y);
+double sqrt (double x);
+
+# include "models/pmModel_GAUSS.c"
+# include "models/pmModel_PGAUSS.c"
+# include "models/pmModel_QGAUSS.c"
+# include "models/pmModel_RGAUSS.c"
+# include "models/pmModel_SERSIC.c"
+
+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}
+};
+
+static pmModelClass *models = NULL;
+static int Nmodels = 0;
+
+static void ModelClassFree (pmModelClass *modelClass)
+{
+
+    if (modelClass == NULL)
+        return;
+    return;
+}
+
+pmModelClass *pmModelClassAlloc (int nModels)
+{
+    pmModelClass *modelClass = (pmModelClass *) psAlloc (nModels * sizeof(pmModelClass));
+    psMemSetDeallocator(modelClass, (psFreeFunc) ModelClassFree);
+    return (modelClass);
+}
+
+void pmModelClassAdd (pmModelClass *model)
+{
+    if (models == NULL) {
+        pmModelClassInit ();
+    }
+
+    Nmodels ++;
+    models = (pmModelClass *) psRealloc (models, Nmodels*sizeof(pmModelClass));
+    models[Nmodels-1] = model[0];
+    return;
+}
+
+bool pmModelClassInit (void)
+{
+    // if we do not need to init, return false;
+    if (models != NULL)
+        return false;
+
+    int Nnew = sizeof (defaultModels) / sizeof (pmModelClass);
+
+    models = pmModelClassAlloc (Nnew);
+    for (int i = 0; i < Nnew; i++) {
+        models[i] = defaultModels[i];
+    }
+    Nmodels = Nnew;
+    return true;
+}
+
+pmModelClass *pmModelClassSelect (pmModelType type)
+{
+    if ((type < 0) || (type >= Nmodels)) {
+        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
+        return (NULL);
+    }
+    return (&models[type]);
+}
+
+void pmModelClassCleanup (void)
+{
+    psFree (models);
+    models = NULL;
+    return;
+}
+
+psS32 pmModelClassParameterCount (pmModelType type)
+{
+    if ((type < 0) || (type >= Nmodels)) {
+        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
+        return (0);
+    }
+    return (models[type].nParams);
+}
+
+psS32 pmModelClassGetType (char *name)
+{
+    for (int i = 0; i < Nmodels; i++) {
+        if (!strcmp(models[i].name, name)) {
+            return (i);
+        }
+    }
+    return (-1);
+}
+
+char *pmModelClassGetName (pmModelType type)
+{
+    if ((type < 0) || (type >= Nmodels)) {
+        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
+        return (NULL);
+    }
+    return (models[type].name);
+}
Index: /branches/eam_branch_20070817/psModules/src/objects/pmModelClass.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmModelClass.h	(revision 14544)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModelClass.h	(revision 14544)
@@ -0,0 +1,73 @@
+/* @file  pmModelClass.h
+ *
+ * The object model function types are desined to allow for the flexible addition of new
+ * object models. Every object model, with parameters represented by pmModel, has an
+ * associated set of functions which provide necessary support operations.  A These
+ * functions allow the programmer to select the approriate function or property for a
+ * specific object model class.
+ *
+ * Every model instance belongs to a class of models, defined by the value of the
+ * pmModelType type entry. Various functions need access to information about each of the
+ * models. Some of this information varies from model to model, and may depend on the
+ * current parameter values or other data quantities. In order to keep the code from
+ * requiring the information about each model to be coded into the low-level fitting
+ * routines, we define a collection of functions which allow us to abstract this type of
+ * model-dependent information. These generic functions take the model type and return the
+ * corresponding function pointer for the specified model. Each model is defined by
+ * creating this collection of specific functions, and placing them in a single file for
+ * each model. We define the following structure to carry the collection of information
+ * about the models.
+ *
+ * @author EAM, IfA
+ *
+ * @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-17 21:01:59 $
+ * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+# ifndef PM_MODEL_CLASS_H
+# define PM_MODEL_CLASS_H
+
+/// @addtogroup Objects Object Detection / Analysis Functions
+/// @{
+
+typedef struct
+{
+    char *name;
+    int nParams;
+    pmModelFunc          modelFunc;
+    pmModelFlux          modelFlux;
+    pmModelRadius        modelRadius;
+    pmModelLimits        modelLimits;
+    pmModelGuessFunc     modelGuess;
+    pmModelFromPSFFunc   modelFromPSF;
+    pmModelParamsFromPSF modelParamsFromPSF;
+    pmModelFitStatusFunc modelFitStatus;
+} pmModelClass;
+
+// allocate a pmModelClass to hold nModels entries
+pmModelClass *pmModelClassAlloc (int nModels);
+
+// initialize the internal (static) model class with the default models
+bool pmModelClassInit (void);
+
+// free the internal (static) model class
+void pmModelClassCleanup (void);
+
+// add a new model class to the collection of model classes
+void pmModelClassAdd (pmModelClass *modelClass);
+
+// get the specified model class
+pmModelClass *pmModelClassSelect (pmModelType type);
+
+// This function returns the number of parameters used by the listed function.
+int pmModelClassParameterCount (pmModelType type);
+
+// This function returns the user-space model names for the specified model type.
+char *pmModelClassGetName (pmModelType type);
+
+// This function returns the internal model type code for the user-space model names.
+pmModelType pmModelClassGetType (char *name);
+
+/// @}
+# endif /* PM_MODEL_CLASS_H */
Index: /branches/eam_branch_20070817/psModules/src/objects/pmModelGroup.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmModelGroup.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModelGroup.c	(revision 14544)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-07-20 00:31:43 $
+ *  @version $Revision: 1.17.4.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -28,7 +28,7 @@
 #include "pmResiduals.h"
 #include "pmModel.h"
-#include "pmResiduals.h"
-#include "pmPSF.h"
-#include "pmSource.h"
+// #include "pmResiduals.h"
+// #include "pmPSF.h"
+// #include "pmSource.h"
 #include "pmModelGroup.h"
 #include "pmErrorCodes.h"
@@ -198,33 +198,2 @@
     return (models[type].name);
 }
-
-/******************************************************************************
-    pmSourceModelGuess(source, model): This function allocates a new
-    pmModel structure based on the given modelType specified in the argument list.
-    The corresponding pmModelGuess function is returned, and used to
-    supply the values of the params array in the pmModel structure.
- 
-    XXX: Many parameters are based on the src->moments structure, which is in
-    image, not subImage coords.  Therefore, the calls to the model evaluation
-    functions will be in image, not subImage coords.  Remember this.
-*****************************************************************************/
-pmModel *pmSourceModelGuess(pmSource *source,
-                            pmModelType modelType)
-{
-    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
-    PS_ASSERT_PTR_NON_NULL(source, NULL);
-    PS_ASSERT_PTR_NON_NULL(source->moments, NULL);
-    PS_ASSERT_PTR_NON_NULL(source->peak, NULL);
-
-    pmModel *model = pmModelAlloc(modelType);
-
-    pmModelGuessFunc modelGuessFunc = pmModelGuessFunc_GetFunction(modelType);
-    if (!modelGuessFunc(model, source)) {
-	psFree (model);
-	return NULL;
-    }
-
-    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
-    return(model);
-}
-
Index: /branches/eam_branch_20070817/psModules/src/objects/pmModelGroup.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmModelGroup.h	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModelGroup.h	(revision 14544)
@@ -1,14 +1,26 @@
 /* @file  pmModelGroup.h
  *
- * The object model function types are defined to allow for the flexible addition
- * of new object models. Every object model, with parameters represented by
- * pmModel, has an associated set of functions which provide necessary support
- * operations. A set of abstract functions allow the programmer to select the
- * approriate function or property for a specific named object model.
+ * The object model function types are desined to allow for the flexible addition of new object
+ * models. Every object model, with parameters represented by pmModel, has an associated set of
+ * functions which provide necessary support operations. A set of abstract functions allow the
+ * programmer to select the approriate function or property for a specific named object model.
+ *
+ * Every model instance belongs to a class of models, defined by the value of
+ * the pmModelType type entry. Various functions need access to information about
+ * each of the models. Some of this information varies from model to model, and
+ * may depend on the current parameter values or other data quantities. In order
+ * to keep the code from requiring the information about each model to be coded
+ * into the low-level fitting routines, we define a collection of functions which
+ * allow us to abstract this type of model-dependent information. These generic
+ * functions take the model type and return the corresponding function pointer
+ * for the specified model. Each model is defined by creating this collection of
+ * specific functions, and placing them in a single file for each model. We
+ * define the following structure to carry the collection of information about
+ * the models.
  *
  * @author EAM, IfA
  *
- * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-24 02:54:15 $
+ * @version $Revision: 1.7.14.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-17 21:01:59 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -23,5 +35,5 @@
 typedef psMinimizeLMChi2Func pmModelFunc;
 
-//  This function is the model chi-square minimization function for this model.
+//  This function sets the parameter limits for this model.
 typedef psMinimizeLMLimitFunc pmModelLimits;
 
@@ -29,41 +41,23 @@
 typedef psF64 (*pmModelFlux)(const psVector *params);
 
-
 // This function returns the radius at which the given model and parameters
 // achieves the given flux.
 typedef psF64 (*pmModelRadius)(const psVector *params, double flux);
 
-/*  This function sets the model parameter limits vectors for the given model
- */
-// typedef bool (*pmModelLimits)(psVector **beta_lim, psVector **params_min, psVector **params_max);
-
-/*  This function provides the model guess parameters based on the details of
- *   the given source.
- */
+//  This function provides the model guess parameters based on the details of
+//  the given 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.
- */
+//  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)(pmModel *modelPSF, pmModel *modelEXT, pmPSF *psf);
 
-/*  This function returns the success / failure status of the given model fit
- */
+//  This function sets the model parameters based on the PSF for a given coordinate and central
+//  intensity
+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)(pmModel *model);
 
-/* Every model instance belongs to a class of models, defined by the value of
- * the pmModelType type entry. Various functions need access to information about
- * each of the models. Some of this information varies from model to model, and
- * may depend on the current parameter values or other data quantities. In order
- * to keep the code from requiring the information about each model to be coded
- * into the low-level fitting routines, we define a collection of functions which
- * allow us to abstract this type of model-dependent information. These generic
- * functions take the model type and return the corresponding function pointer
- * for the specified model. Each model is defined by creating this collection of
- * specific functions, and placing them in a single file for each model. We
- * define the following structure to carry the collection of information about
- * the models.
- */
 typedef struct
 {
@@ -76,4 +70,5 @@
     pmModelGuessFunc     modelGuessFunc;
     pmModelFromPSFFunc   modelFromPSFFunc;
+    pmModelParamsFromPSF modelParamsFromPSF;
     pmModelFitStatusFunc modelFitStatusFunc;
 }
Index: /branches/eam_branch_20070817/psModules/src/objects/pmModelUtils.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmModelUtils.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModelUtils.c	(revision 14544)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-16 18:33:37 $
+ *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -20,75 +20,49 @@
 #include <string.h>
 #include <pslib.h>
+#include "pmHDU.h"
+#include "pmFPA.h"
+#include "pmGrowthCurve.h"
 #include "pmResiduals.h"
 #include "pmModel.h"
+#include "pmPSF.h"
+#include "pmErrorCodes.h"
+#include "pmModelUtils.h"
 
-// instantiate a model for the PSF at this location (normalized or not?)
-// NOTE: psf and (x,y) are defined wrt chip coordinates
-pmModel *pmModelFromPSFforXY (pmPSF *psf, float x, float y, float flux) {
+// instantiate a model for the PSF at this location with peak flux
+// NOTE: psf and (Xo,Yo) are defined wrt chip coordinates
+pmModel *pmModelFromPSFforXY (pmPSF *psf, float Xo, float Yo, float Io) {
 
     assert (psf);
 
     // allocate a new pmModel to hold the PSF version
-    pmModel *modelEXT = pmModelAlloc (psf->type);
-
-    modelEXT->params->data.F32[PM_PAR_SKY]  = 0.0;
-    modelEXT->params->data.F32[PM_PAR_I0]   = 1.0;
-    modelEXT->params->data.F32[PM_PAR_XPOS] = x;
-    modelEXT->params->data.F32[PM_PAR_YPOS] = y;
-
-    // find function used to set the model parameters
-    pmModelFromPSFFunc modelFromPSFFunc = pmModelFromPSFFunc_GetFunction (psf->type);
-
-    // allocate a new pmModel to hold the PSF version
     pmModel *modelPSF = pmModelAlloc (psf->type);
 
-    // adjust the normalization: 
-    pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type);
-    normFlux = modelFluxFunc (model->params);
-    assert (isfinite(normFlux));
-    assert (normFlux > 0);
-
-    // set the correct normalization
-    modelEXT->params->data.F32[PM_PAR_I0] = flux / normFlux;
-
     // set model parameters for this source based on PSF information
-    if (!modelFromPSFFunc (modelPSF, modelEXT, psf)) {
+    if (!modelPSF->modelParamsFromPSF (modelPSF, psf, Xo, Yo, Io)) {
         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;
-    psFree (modelEXT);
 
     return (modelPSF);
 }
 
-pmSource *pmSourceFromModel (pmModel *model, pmReadout *readout, pmSourceType type) {
+// set this model to have the requested flux
+bool pmModelSetFlux (pmModel *model, float flux) {
 
-    pmSource *source = pmSourceAlloc ();
+    // set Io to be 1.0
+    model->params->data.F32[PM_PAR_I0] = 1.0;
 
-    // use the model centroid for the peak
-    switch (type) {
-      case PM_SOURCE_TYPE_STAR:
-	source->modelPSF = model;
-	break;
-      case PM_SOURCE_TYPE_EXTENDED:
-	source->modelEXT = model;
-	break;
-      default:
-	psAbort ("psphot", "error");
-    }
+    // determine the normalized flux
+    float normFlux = model->modelFlux (model->params);
+    assert (isfinite(normFlux));
+    assert (normFlux > 0);
 
-    source->peak = pmPeakAlloc ();
+    // set the desired normalization
+    model->params->data.F32[PM_PAR_I0] = flux / normFlux;
 
-    float x = model->params->data.F32[PM_PAR_XPOS];
-    float y = model->params->data.F32[PM_PAR_YPOS];
-
-    // XXX need to define the radius in some rational way
-    // XXX x,y are defined wrt readout->image parent, but the model
-    // parameters are defined wrt chip coordinates
-    pmSourceDefinePixels (source, readout, x, y, radius);
-
-    return (source);
+    return true;
 }
Index: /branches/eam_branch_20070817/psModules/src/objects/pmModelUtils.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmModelUtils.h	(revision 14544)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmModelUtils.h	(revision 14544)
@@ -0,0 +1,31 @@
+/* @file  pmModelUtils.h
+ *
+ * Utility functions for working with pmSources
+ *
+ * @author EAM, IfA
+ *
+ * @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-17 21:01:59 $
+ * Copyright 2007 IfA, University of Hawaii
+ */
+
+# ifndef PM_MODEL_UTILS_H
+# define PM_MODEL_UTILS_H
+
+/// @addtogroup Objects Object Detection / Analysis Functions
+/// @{
+
+pmModel *pmModelFromPSFforXY (
+    pmPSF *psf, 
+    float Xo, 
+    float Yo, 
+    float Io
+    );
+
+bool pmModelSetFlux (
+    pmModel *model, 
+    float flux
+    );
+
+/// @}
+# 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 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmPSF.c	(revision 14544)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-06-20 02:22:26 $
+ *  @version $Revision: 1.25.6.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -32,5 +32,5 @@
 #include "pmGrowthCurve.h"
 #include "pmPSF.h"
-#include "pmModelGroup.h"
+#include "pmModelClass.h"
 #include "pmSourcePhotometry.h"
 #include "pmFPAMaskWeight.h"
@@ -124,5 +124,5 @@
     psf->residuals = NULL;
 
-    Nparams = pmModelParameterCount (type);
+    Nparams = pmModelClassParameterCount (type);
     if (!Nparams) {
         psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
@@ -169,15 +169,9 @@
 pmModel *pmModelFromPSF (pmModel *modelEXT, pmPSF *psf)
 {
-
-    // need to define the relationship between the modelEXT and modelPSF ?
-
-    // find function used to set the model parameters
-    pmModelFromPSFFunc modelFromPSFFunc = pmModelFromPSFFunc_GetFunction (psf->type);
-
     // 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 (!modelFromPSFFunc (modelPSF, modelEXT, psf)) {
+    if (!modelEXT->modelFromPSF (modelPSF, modelEXT, psf)) {
         psError(PM_ERR_PSF, false, "Failed to set model params from PSF");
         psFree(modelPSF);
@@ -335,5 +329,5 @@
     va_start(ap, sxy);
 
-    pmModelType type = pmModelSetType (typeName);
+    pmModelType type = pmModelClassGetType (typeName);
     psPolynomial2D *psfTrend = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 0, 0);
     pmPSF *psf = pmPSFAlloc (type, true, psfTrend);
Index: /branches/eam_branch_20070817/psModules/src/objects/pmPSF_IO.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmPSF_IO.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmPSF_IO.c	(revision 14544)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-07-14 03:20:22 $
+ *  @version $Revision: 1.20.4.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -44,5 +44,5 @@
 #include "pmPSF_IO.h"
 #include "pmSource.h"
-#include "pmModelGroup.h"
+#include "pmModelClass.h"
 #include "pmSourceIO.h"
 
@@ -313,10 +313,10 @@
 	psMetadata *header = psMetadataAlloc();
 
-	char *modelName = pmModelGetType (psf->type);
+	char *modelName = pmModelClassGetName (psf->type);
 	psMetadataAddStr (header, PS_LIST_TAIL, "PSF_NAME", 0, "PSF model name", modelName);
 
 	psMetadataAddBool (header, PS_LIST_TAIL, "POISSON",  0, "Use Poisson errors in fits?", psf->poissonErrors);
 
-	int nPar = pmModelParameterCount (psf->type)    ;
+	int nPar = pmModelClassParameterCount (psf->type)    ;
 	psMetadataAdd (header, PS_LIST_TAIL, "PSF_NPAR", PS_DATA_S32, "PSF model parameter count", nPar);
 
@@ -599,5 +599,5 @@
     // load the PSF model parameters from the FITS table
     char *modelName = psMetadataLookupStr (&status, header, "PSF_NAME");
-    pmModelType type = pmModelSetType (modelName);
+    pmModelType type = pmModelClassGetType (modelName);
     if (type == -1) {
         psError(PS_ERR_UNKNOWN, true, "invalid model name %s in psf file %s", modelName, file->filename);
@@ -612,5 +612,5 @@
     // check the number of expected parameters
     int nPar = psMetadataLookupS32 (&status, header, "PSF_NPAR");
-    if (nPar != pmModelParameterCount (psf->type))
+    if (nPar != pmModelClassParameterCount (psf->type))
         psAbort("mismatch model par count");
 
@@ -717,8 +717,8 @@
     }
 
-    char *modelName = pmModelGetType (psf->type);
+    char *modelName = pmModelClassGetName (psf->type);
     psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NAME", PS_DATA_STRING, "PSF model name", modelName);
 
-    int nPar = pmModelParameterCount (psf->type)    ;
+    int nPar = pmModelClassParameterCount (psf->type)    ;
     psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NPAR", PS_DATA_S32, "PSF model parameter count", nPar);
 
@@ -749,5 +749,5 @@
 
     char *modelName = psMetadataLookupPtr (&status, metadata, "PSF_MODEL_NAME");
-    pmModelType type = pmModelSetType (modelName);
+    pmModelType type = pmModelClassGetType (modelName);
 
     bool poissonErrors = psMetadataLookupPtr (&status, metadata, "PSF_POISSON_ERRORS");
@@ -759,5 +759,5 @@
 
     int nPar = psMetadataLookupS32 (&status, metadata, "PSF_MODEL_NPAR");
-    if (nPar != pmModelParameterCount (psf->type))
+    if (nPar != pmModelClassParameterCount (psf->type))
         psAbort("mismatch model par count");
 
Index: /branches/eam_branch_20070817/psModules/src/objects/pmPSFtry.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmPSFtry.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmPSFtry.c	(revision 14544)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-06-20 02:22:26 $
+ *  @version $Revision: 1.43.6.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -25,8 +25,9 @@
 #include "pmModel.h"
 #include "pmSource.h"
+#include "pmSourceUtils.h"
 #include "pmGrowthCurve.h"
 #include "pmPSF.h"
 #include "pmPSFtry.h"
-#include "pmModelGroup.h"
+#include "pmModelClass.h"
 #include "pmSourceFitModel.h"
 #include "pmSourcePhotometry.h"
@@ -59,5 +60,5 @@
 
     // validate the requested model name
-    pmModelType type = pmModelSetType (modelName);
+    pmModelType type = pmModelClassGetType (modelName);
     if (type == -1) {
         psError (PS_ERR_UNKNOWN, true, "invalid model name %s", modelName);
Index: /branches/eam_branch_20070817/psModules/src/objects/pmPeaks.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmPeaks.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmPeaks.c	(revision 14544)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-04-26 01:20:29 $
+ *  @version $Revision: 1.15.8.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -35,5 +35,5 @@
                         pmPeakType type)
 {
-    psTrace(__func__, 5, "---- begin ----\n");
+    psTrace("psModules.objects", 5, "---- begin ----\n");
 
     if (peaks == NULL) {
@@ -67,5 +67,5 @@
     psFree (peak);
 
-    psTrace(__func__, 5, "---- end ----\n");
+    psTrace("psModules.objects", 5, "---- end ----\n");
     return(peaks);
 }
@@ -118,5 +118,5 @@
 *****************************************************************************/
 static void peakFree(pmPeak *tmp)
-{} // used by pmIsPeak()
+{} // used by pmPeakTest()
 
 pmPeak *pmPeakAlloc(psS32 x,
@@ -145,5 +145,5 @@
 }
 
-bool pmIsPeak(const psPtr ptr)
+bool pmPeakTest(const psPtr ptr)
 {
     return (psMemGetDeallocator(ptr) == (psFreeFunc)peakFree);
@@ -193,5 +193,5 @@
 
 /******************************************************************************
-pmFindVectorPeaks(vector, threshold): Find all local peaks in the given vector
+pmPeaksInVector(vector, threshold): Find all local peaks in the given vector
 above the given threshold.  Returns a vector of type PS_TYPE_U32 containing
 the location (x value) of all peaks.
@@ -203,6 +203,6 @@
 Depending upon actual use, this may need to be optimized.
 *****************************************************************************/
-psVector *pmFindVectorPeaks(const psVector *vector,
-                            psF32 threshold)
+psVector *pmPeaksInVector(const psVector *vector,
+			 psF32 threshold)
 {
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
@@ -295,5 +295,5 @@
 
 /******************************************************************************
-pmFindImagePeaks(image, threshold): Find all local peaks in the given psImage
+pmPeaksInImage(image, threshold): Find all local peaks in the given psImage
 above the given threshold.  Returns a psArray containing location (x/y value)
 of all peaks.
@@ -309,5 +309,5 @@
 
 *****************************************************************************/
-psArray *pmFindImagePeaks(const psImage *image, psF32 threshold)
+psArray *pmPeaksInImage(const psImage *image, psF32 threshold)
 {
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
@@ -327,6 +327,6 @@
     row = 0;
     tmpRow = getRowVectorFromImage((psImage *) image, row);
-    psVector *row1 = pmFindVectorPeaks(tmpRow, threshold);
-    // pmFindVectorPeaks returns coords in the vector, not corrected for col0
+    psVector *row1 = pmPeaksInVector(tmpRow, threshold);
+    // pmPeaksInVector returns coords in the vector, not corrected for col0
 
     for (psU32 i = 0 ; i < row1->n ; i++ ) {
@@ -382,5 +382,5 @@
     for (row = 1 ; row < (image->numRows - 1) ; row++) {
         tmpRow = getRowVectorFromImage((psImage *) image, row);
-        row1 = pmFindVectorPeaks(tmpRow, threshold);
+        row1 = pmPeaksInVector(tmpRow, threshold);
 
         // Step through all local peaks in this row.
@@ -461,5 +461,5 @@
     row = image->numRows - 1;
     tmpRow = getRowVectorFromImage((psImage *) image, row);
-    row1 = pmFindVectorPeaks(tmpRow, threshold);
+    row1 = pmPeaksInVector(tmpRow, threshold);
     for (psU32 i = 0 ; i < row1->n ; i++ ) {
         col = row1->data.U32[i];
@@ -501,48 +501,6 @@
 }
 
-
-/******************************************************************************
-psCullPeaks(peaks, maxValue, valid): eliminate peaks from the psArray that have
-a peak value above the given maximum, or fall outside the valid region.
- 
-XXX: Should the sky value be used when comparing the maximum?
- 
-XXX: warning message if valid is NULL?
- 
-XXX: changed API to create a NEW output psArray (should change name as well)
- 
-XXX: Do we free the psList elements of those culled peaks?
- 
-XXX EAM : do we still need pmCullPeaks, or only pmPeaksSubset?
-*****************************************************************************/
-psList *pmCullPeaks(psList *peaks,
-                    psF32 maxValue,
-                    const psRegion valid)
-{
-    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
-    PS_ASSERT_PTR_NON_NULL(peaks, NULL);
-
-    psListElem *tmpListElem = (psListElem *) peaks->head;
-    psS32 indexNum = 0;
-
-    //    printf("pmCullPeaks(): list size is %d\n", peaks->size);
-    while (tmpListElem != NULL) {
-        pmPeak *tmpPeak = (pmPeak *) tmpListElem->data;
-        if ((tmpPeak->value > maxValue) ||
-                (true == isItInThisRegion(valid, tmpPeak->x, tmpPeak->y))) {
-            psListRemoveData(peaks, (psPtr) tmpPeak);
-        }
-
-        indexNum++;
-        tmpListElem = tmpListElem->next;
-    }
-
-    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
-    return(peaks);
-}
-
-// XXX EAM: I changed this to return a new, subset array
-//          rather than alter the existing one
-// XXX: Fix the *valid pointer.
+// return a new array of peaks which are in the valid region and below threshold
+// XXX this function is unused and probably could be dropped
 psArray *pmPeaksSubset(
     psArray *peaks,
@@ -555,5 +513,5 @@
     psArray *output = psArrayAllocEmpty (200);
 
-    psTrace (".pmObjects.pmCullPeaks", 3, "list size is %ld\n", peaks->n);
+    psTrace ("psModules.objects", 3, "list size is %ld\n", peaks->n);
 
     for (int i = 0; i < peaks->n; i++) {
Index: /branches/eam_branch_20070817/psModules/src/objects/pmPeaks.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmPeaks.h	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmPeaks.h	(revision 14544)
@@ -10,6 +10,6 @@
  * @author GLG, MHPCC
  *
- * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-24 02:54:15 $
+ * @version $Revision: 1.6.14.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-17 21:01:59 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -72,7 +72,7 @@
 );
 
-bool pmIsPeak(const psPtr ptr);
+bool pmPeakTest(const psPtr ptr);
 
-/** pmFindVectorPeaks()
+/** pmPeaksInVector()
  *
  * Find all local peaks in the given vector above the given threshold. A peak
@@ -91,5 +91,5 @@
  *
  */
-psVector *pmFindVectorPeaks(
+psVector *pmPeaksInVector(
     const psVector *vector,  ///< The input vector (float)
     float threshold   ///< Threshold above which to find a peak
@@ -97,5 +97,5 @@
 
 
-/** pmFindImagePeaks()
+/** pmPeaksInImage()
  *
  * Find all local peaks in the given image above the given threshold. This
@@ -111,5 +111,5 @@
  *
  */
-psArray *pmFindImagePeaks(
+psArray *pmPeaksInImage(
     const psImage *image,  ///< The input image where peaks will be found (float)
     float threshold   ///< Threshold above which to find a peak
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSource.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSource.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSource.c	(revision 14544)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-16 18:33:00 $
+ *  @version $Revision: 1.34.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -113,5 +113,5 @@
 }
 
-bool pmIsSource(const psPtr ptr)
+bool pmSourceTest(const psPtr ptr)
 {
     return (psMemGetDeallocator(ptr) == (psFreeFunc)sourceFree);
@@ -337,5 +337,5 @@
             return emptyClump;
         }
-        peaks = pmFindImagePeaks (splane, stats[0].max / 2);
+        peaks = pmPeaksInImage (splane, stats[0].max / 2);
         psTrace ("psModules.objects", 2, "clump threshold is %f\n", stats[0].max/2);
 
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSource.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSource.h	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSource.h	(revision 14544)
@@ -3,6 +3,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-08-15 20:21:18 $
+ * @version $Revision: 1.16.2.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-17 21:01:59 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -114,5 +114,5 @@
 void pmSourceFreePixels(pmSource *source);
 
-bool pmIsSource(const psPtr ptr);
+bool pmSourceTest(const psPtr ptr);
 
 /** pmSourceDefinePixels()
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceFitModel.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceFitModel.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceFitModel.c	(revision 14544)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-06-21 22:58:11 $
+ *  @version $Revision: 1.24.4.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -30,5 +30,5 @@
 #include "pmPSF.h"
 #include "pmSource.h"
-#include "pmModelGroup.h"
+#include "pmModelClass.h"
 #include "pmSourceFitModel.h"
 
@@ -116,15 +116,8 @@
     psVector *dparams = model->dparams;
 
-    pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
-    if (!modelFunc)
-        psAbort("invalid model function");
-    pmModelLimits checkLimits = pmModelLimits_GetFunction (model->type);
-    if (!checkLimits)
-        psAbort("invalid model limits function");
-
     // create the minimization constraints
     psMinConstraint *constraint = psMinConstraintAlloc();
     constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_U8);
-    constraint->checkLimits = checkLimits;
+    constraint->checkLimits = model->modelLimits;
 
     // set parameter mask based on fitting mode
@@ -156,6 +149,6 @@
     // force the floating parameters to fall within the contraint ranges
     for (int i = 0; i < params->n; i++) {
-        checkLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);
-        checkLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);
+        model->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);
+        model->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);
     }
 
@@ -174,5 +167,5 @@
     psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);
 
-    fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, modelFunc);
+    fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, model->modelFunc);
     for (int i = 0; i < dparams->n; i++) {
         if (psTraceGetLevel("psModules.objects") >= 4) {
@@ -201,5 +194,5 @@
             altmask->data.U8[i] = (constraint->paramMask->data.U8[i]) ? 0 : 1;
         }
-        psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, modelFunc);
+        psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, model->modelFunc);
         for (int i = 0; i < dparams->n; i++) {
             if (!constraint->paramMask->data.U8[i])
@@ -236,4 +229,23 @@
     return(rc);
 }
+
+# define SKIP_FIT_SET 1
+# if (SKIP_FIT_SET)
+
+bool pmSourceFitSet (pmSource *source,
+                     psArray *modelSet,
+                     pmSourceFitMode mode,
+                     psMaskType maskVal)
+{
+    psTrace("psModules.objects", 3, "---- %s begin ----\n", __func__);
+    PS_ASSERT_PTR_NON_NULL(source, false);
+    PS_ASSERT_PTR_NON_NULL(source->pixels, false);
+    PS_ASSERT_PTR_NON_NULL(source->maskObj, false);
+    PS_ASSERT_PTR_NON_NULL(source->weight, false);
+
+    return true;
+}
+
+# else
 
 /********************* Source Model Set Functions ***************************/
@@ -255,5 +267,5 @@
     oneModelFunc = pmModelFunc_GetFunction (type);
     oneCheckLimits = pmModelLimits_GetFunction (type);
-    nOnePar = pmModelParameterCount (type);
+    nOnePar = pmModelClassParameterCount (type);
 
     onePar = psVectorAlloc (nOnePar, PS_DATA_F32);
@@ -567,2 +579,3 @@
 }
 
+# endif
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO.c	(revision 14544)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-07-14 03:20:44 $
+ *  @version $Revision: 1.45.4.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -37,5 +37,5 @@
 #include "pmPSF.h"
 #include "pmSource.h"
-#include "pmModelGroup.h"
+#include "pmModelClass.h"
 #include "pmSourceIO.h"
 
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_CMP.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_CMP.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_CMP.c	(revision 14544)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-05-03 00:13:03 $
+ *  @version $Revision: 1.29.8.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -35,5 +35,5 @@
 #include "pmPSF.h"
 #include "pmSource.h"
-#include "pmModelGroup.h"
+#include "pmModelClass.h"
 #include "pmSourceIO.h"
 
@@ -154,9 +154,9 @@
 
     // define PSF model type
-    int modelType = pmModelSetType ("PS_MODEL_GAUSS");
+    int modelType = pmModelClassGetType ("PS_MODEL_GAUSS");
 
     char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME");
     if (PSF_NAME != NULL) {
-        modelType = pmModelSetType (PSF_NAME);
+        modelType = pmModelClassGetType (PSF_NAME);
     }
 
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_OBJ.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_OBJ.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_OBJ.c	(revision 14544)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-05-03 00:13:03 $
+ *  @version $Revision: 1.13.8.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -35,5 +35,5 @@
 #include "pmPSF.h"
 #include "pmSource.h"
-#include "pmModelGroup.h"
+#include "pmModelClass.h"
 #include "pmSourceIO.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 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_PS1_DEV_0.c	(revision 14544)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-05-03 00:13:42 $
+ *  @version $Revision: 1.10.8.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -35,5 +35,5 @@
 #include "pmPSF.h"
 #include "pmSource.h"
-#include "pmModelGroup.h"
+#include "pmModelClass.h"
 #include "pmSourceIO.h"
 
@@ -152,9 +152,9 @@
 
     // define PSF model type
-    int modelType = pmModelSetType ("PS_MODEL_GAUSS");
+    int modelType = pmModelClassGetType ("PS_MODEL_GAUSS");
 
     char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME");
     if (PSF_NAME != NULL) {
-        modelType = pmModelSetType (PSF_NAME);
+        modelType = pmModelClassGetType (PSF_NAME);
     }
 
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_RAW.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_RAW.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_RAW.c	(revision 14544)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-04-21 19:47:14 $
+ *  @version $Revision: 1.15.8.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -35,5 +35,5 @@
 #include "pmPSF.h"
 #include "pmSource.h"
-#include "pmModelGroup.h"
+#include "pmModelClass.h"
 #include "pmSourcePhotometry.h"
 #include "pmSourceIO.h"
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SMPDATA.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SMPDATA.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SMPDATA.c	(revision 14544)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-05-03 00:13:42 $
+ *  @version $Revision: 1.9.8.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -35,5 +35,5 @@
 #include "pmPSF.h"
 #include "pmSource.h"
-#include "pmModelGroup.h"
+#include "pmModelClass.h"
 #include "pmSourceIO.h"
 
@@ -132,9 +132,9 @@
 
     // define PSF model type
-    int modelType = pmModelSetType ("PS_MODEL_GAUSS");
+    int modelType = pmModelClassGetType ("PS_MODEL_GAUSS");
 
     char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME");
     if (PSF_NAME != NULL) {
-        modelType = pmModelSetType (PSF_NAME);
+        modelType = pmModelClassGetType (PSF_NAME);
     }
 
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SX.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SX.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SX.c	(revision 14544)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-04-27 22:14:08 $
+ *  @version $Revision: 1.11.8.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -35,5 +35,5 @@
 #include "pmPSF.h"
 #include "pmSource.h"
-#include "pmModelGroup.h"
+#include "pmModelClass.h"
 #include "pmSourceIO.h"
 
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourcePhotometry.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourcePhotometry.c	(revision 14544)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-06-20 02:22:26 $
+ *  @version $Revision: 1.28.6.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -29,5 +29,5 @@
 #include "pmPSF.h"
 #include "pmSource.h"
-#include "pmModelGroup.h"
+#include "pmModelClass.h"
 #include "pmSourcePhotometry.h"
 
@@ -250,6 +250,5 @@
 
     // measure fitMag
-    pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type);
-    fitSum = modelFluxFunc (model->params);
+    fitSum = model->modelFlux (model->params);
     if (fitSum <= 0)
         return false;
@@ -324,5 +323,4 @@
 
     // the model function returns the source flux at a position
-    pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
     psVector *coord = psVectorAlloc(2, PS_TYPE_F32);
 
@@ -354,5 +352,5 @@
 
             // for the full model, add all points
-            value = modelFunc (NULL, params, coord) - sky;
+            value = model->modelFunc (NULL, params, coord) - sky;
             modelSum += value;
 
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceUtils.c
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceUtils.c	(revision 14544)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceUtils.c	(revision 14544)
@@ -0,0 +1,93 @@
+/** @file  pmSource.c
+ *
+ *  Functions to define and manipulate sources on images
+ *
+ *  @author GLG, MHPCC
+ *  @author EAM, IfA: significant modifications.
+ *
+ *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+#include <pslib.h>
+#include "pmHDU.h"
+#include "pmFPA.h"
+#include "pmFPAMaskWeight.h"
+#include "pmPeaks.h"
+#include "pmMoments.h"
+#include "pmResiduals.h"
+#include "pmModel.h"
+#include "pmSource.h"
+#include "pmSourceUtils.h"
+
+/******************************************************************************
+    pmSourceModelGuess(source, model): This function allocates a new
+    pmModel structure based on the given modelType specified in the argument list.
+    The corresponding pmModelGuess function is returned, and used to
+    supply the values of the params array in the pmModel structure.
+ 
+    XXX: Many parameters are based on the src->moments structure, which is in
+    image, not subImage coords.  Therefore, the calls to the model evaluation
+    functions will be in image, not subImage coords.  Remember this.
+*****************************************************************************/
+pmModel *pmSourceModelGuess(pmSource *source,
+                            pmModelType modelType)
+{
+    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
+    PS_ASSERT_PTR_NON_NULL(source, NULL);
+    PS_ASSERT_PTR_NON_NULL(source->moments, NULL);
+    PS_ASSERT_PTR_NON_NULL(source->peak, NULL);
+
+    pmModel *model = pmModelAlloc(modelType);
+
+    if (!model->modelGuess(model, source)) {
+	psFree (model);
+	return NULL;
+    }
+
+    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
+    return(model);
+}
+
+pmSource *pmSourceFromModel (pmModel *model, pmReadout *readout, pmSourceType type) {
+
+    pmSource *source = pmSourceAlloc ();
+
+    // use the model centroid for the peak
+    switch (type) {
+      case PM_SOURCE_TYPE_STAR:
+	source->modelPSF = model;
+	break;
+      case PM_SOURCE_TYPE_EXTENDED:
+	source->modelEXT = model;
+	break;
+      default:
+	psAbort ("invalid source type");
+    }
+
+    // XXX I don't yet know how this function should be defined
+# if (0) 
+    source->peak = pmPeakAlloc ();
+
+    float x = model->params->data.F32[PM_PAR_XPOS];
+    float y = model->params->data.F32[PM_PAR_YPOS];
+
+    // XXX need to define the radius in some rational way
+    // XXX x,y are defined wrt readout->image parent, but the model
+    // parameters are defined wrt chip coordinates
+    pmSourceDefinePixels (source, readout, x, y, radius);
+# endif
+
+    return (source);
+}
+
Index: /branches/eam_branch_20070817/psModules/src/objects/pmSourceUtils.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/objects/pmSourceUtils.h	(revision 14544)
+++ /branches/eam_branch_20070817/psModules/src/objects/pmSourceUtils.h	(revision 14544)
@@ -0,0 +1,39 @@
+/* @file  pmSourceUtils.h
+ *
+ * Utility functions for working with pmSources
+ *
+ * @author EAM, IfA
+ *
+ * @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-08-17 21:01:59 $
+ * Copyright 2007 IfA, University of Hawaii
+ */
+
+# ifndef PM_SOURCE_UTILS_H
+# define PM_SOURCE_UTILS_H
+
+/// @addtogroup Objects Object Detection / Analysis Functions
+/// @{
+
+/** pmSourceModelGuess()
+ *
+ * Convert available data to an initial guess for the given model. This
+ * function allocates a pmModel entry for the pmSource structure based on the
+ * provided model selection. The method of defining the model parameter guesses
+ * are specified for each model below. The guess values are placed in the model
+ * parameters. The function returns TRUE on success or FALSE on failure.
+ *
+ */
+pmModel *pmSourceModelGuess(
+    pmSource *source,   ///< The input pmSource
+    pmModelType model   ///< The type of model to be created.
+);
+
+pmSource *pmSourceFromModel (
+  pmModel *model, 
+  pmReadout *readout, 
+  pmSourceType type
+  );
+
+/// @}
+# endif /* PM_MODEL_CLASS_H */
Index: /branches/eam_branch_20070817/psModules/src/psmodules.h
===================================================================
--- /branches/eam_branch_20070817/psModules/src/psmodules.h	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/src/psmodules.h	(revision 14544)
@@ -84,4 +84,5 @@
 #include <pmModel.h>
 #include <pmSource.h>
+#include <pmSourceUtils.h>
 #include <pmSourceIO.h>
 #include <pmSourceSky.h>
@@ -93,5 +94,6 @@
 #include <pmPSF_IO.h>
 #include <pmPSFtry.h>
-#include <pmModelGroup.h>
+#include <pmModelClass.h>
+#include <pmModelUtils.h>
 #include <pmSourcePhotometry.h>
 
Index: /branches/eam_branch_20070817/psModules/test/objects/tap_pmSourceFitModel.c
===================================================================
--- /branches/eam_branch_20070817/psModules/test/objects/tap_pmSourceFitModel.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/test/objects/tap_pmSourceFitModel.c	(revision 14544)
@@ -117,5 +117,5 @@
     source->moments = pmMomentsAlloc ();
 
-    pmModelType type = pmModelSetType ("PS_MODEL_GAUSS");
+    pmModelType type = pmModelClassGetType ("PS_MODEL_GAUSS");
     source->modelEXT = pmModelAlloc (type);
 
Index: /branches/eam_branch_20070817/psModules/test/objects/tap_pmSourceFitModel_Delta.c
===================================================================
--- /branches/eam_branch_20070817/psModules/test/objects/tap_pmSourceFitModel_Delta.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/test/objects/tap_pmSourceFitModel_Delta.c	(revision 14544)
@@ -35,5 +35,5 @@
     source->moments = pmMomentsAlloc ();
 
-    pmModelType type = pmModelSetType ("PS_MODEL_GAUSS");
+    pmModelType type = pmModelClassGetType ("PS_MODEL_GAUSS");
     source->modelEXT = pmModelAlloc (type);
 
@@ -71,5 +71,5 @@
     pmModel *guess;
 
-    type = pmModelSetType ("PS_MODEL_PGAUSS");
+    type = pmModelClassGetType ("PS_MODEL_PGAUSS");
     guess = pmModelAlloc (type);
 
Index: /branches/eam_branch_20070817/psModules/test/objects/tst_pmObjects01.c
===================================================================
--- /branches/eam_branch_20070817/psModules/test/objects/tst_pmObjects01.c	(revision 14543)
+++ /branches/eam_branch_20070817/psModules/test/objects/tst_pmObjects01.c	(revision 14544)
@@ -31,6 +31,6 @@
     most of psObjects.c is not tested
  *
- *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-04 01:01:34 $
+ *  @version $Revision: 1.8.16.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-08-17 21:01:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -186,9 +186,9 @@
     //
     psS32 i = 0;
-    while (0 != pmModelParameterCount(i)) {
-        printf("Testing pmModelAlloc(%s)...\n", pmModelGetType(0));
+    while (0 != pmModelClassParameterCount(i)) {
+        printf("Testing pmModelAlloc(%s)...\n", pmModelClassGetName(0));
         pmModel *tmpModel = pmModelAlloc(i);
         if (tmpModel == NULL) {
-            printf("TEST ERROR: pmModelAlloc(%s) returned a NULL pmModel\n", pmModelGetType(0));
+            printf("TEST ERROR: pmModelAlloc(%s) returned a NULL pmModel\n", pmModelClassGetName(0));
             testStatus = false;
         } else {
