Index: trunk/psModules/src/objects/Makefile.am
===================================================================
--- trunk/psModules/src/objects/Makefile.am	(revision 15417)
+++ trunk/psModules/src/objects/Makefile.am	(revision 15562)
@@ -10,4 +10,5 @@
      pmModelUtils.c \
      pmSource.c \
+     pmSourceExtendedPars.c \
      pmSourceUtils.c \
      pmSourceSky.c \
@@ -50,4 +51,5 @@
      pmModelUtils.h \
      pmSource.h \
+     pmSourceExtendedPars.h \
      pmSourceUtils.h \
      pmSourceSky.h \
Index: trunk/psModules/src/objects/pmGrowthCurve.h
===================================================================
--- trunk/psModules/src/objects/pmGrowthCurve.h	(revision 15417)
+++ trunk/psModules/src/objects/pmGrowthCurve.h	(revision 15562)
@@ -4,6 +4,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-24 02:54:15 $
+ * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  * Copyright 2006 Institute for Astronomy, University of Hawaii
  */
@@ -27,4 +27,6 @@
 pmGrowthCurve;
 
+bool psMemCheckGrowthCurve(psPtr ptr);
+
 pmGrowthCurve *pmGrowthCurveAlloc (psF32 minRadius, psF32 maxRadius, psF32 refRadius);
 psF32 pmGrowthCurveCorrect (pmGrowthCurve *growth, psF32 radius);
Index: trunk/psModules/src/objects/pmModel.c
===================================================================
--- trunk/psModules/src/objects/pmModel.c	(revision 15417)
+++ trunk/psModules/src/objects/pmModel.c	(revision 15562)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:04:07 $
+ *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -46,7 +46,4 @@
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
 
-    pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel));
-    psMemSetDeallocator(tmp, (psFreeFunc) modelFree);
-
     pmModelClass *class = pmModelClassSelect (type);
     if (class == NULL) {
@@ -54,4 +51,7 @@
         return(NULL);
     }
+
+    pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel));
+    psMemSetDeallocator(tmp, (psFreeFunc) modelFree);
 
     tmp->type = type;
@@ -89,7 +89,14 @@
 }
 
+bool psMemCheckModel(psPtr ptr)
+{
+    PS_ASSERT_PTR(ptr, false);
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) modelFree);
+}
+
 // copy model to a new structure
 pmModel *pmModelCopy (pmModel *model)
 {
+    PS_ASSERT_PTR_NON_NULL(model, NULL);
 
     pmModel *new = pmModelAlloc (model->type);
@@ -217,5 +224,5 @@
         Ro = psImageInterpolateOptionsAlloc(
             PS_INTERPOLATE_BILINEAR,
-            model->residuals->Ro, NULL, NULL, 0, 0.0, 0.0, 1, 0, 0.0);
+            model->residuals->Ro, NULL, mask, 0, 0.0, 0.0, 1, 0, 0.0);
         Rx = psImageInterpolateOptionsAlloc(
             PS_INTERPOLATE_BILINEAR,
@@ -257,6 +264,6 @@
                 float oy = yBin*(imageRow + 0.5 - yCenter) + yResidCenter;
 
+		psU8 mflux = 0;
                 if (mode & PM_MODEL_OP_RES0) {
-                    psU8 mflux = 0;
                     double Fo = 0.0;
                     psImageInterpolate (&Fo, NULL, &mflux, ox, oy, Ro);
@@ -265,6 +272,6 @@
                     }
                 }
-                if (mode & PM_MODEL_OP_RES1) {
-                    psU8 mflux = 0;
+		// skip Rx,Ry if Ro is masked
+                if (!mflux && (mode & PM_MODEL_OP_RES1)) {
                     double Fx = 0.0;
                     double Fy = 0.0;
Index: trunk/psModules/src/objects/pmModel.h
===================================================================
--- trunk/psModules/src/objects/pmModel.h	(revision 15417)
+++ trunk/psModules/src/objects/pmModel.h	(revision 15562)
@@ -5,6 +5,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-08-24 00:11:02 $
+ * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  *
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -122,4 +122,5 @@
  */
 pmModel *pmModelAlloc(pmModelType type);
+bool psMemCheckModel(psPtr ptr);
 
 // copy model to a new structure
Index: trunk/psModules/src/objects/pmModelClass.c
===================================================================
--- trunk/psModules/src/objects/pmModelClass.c	(revision 15417)
+++ trunk/psModules/src/objects/pmModelClass.c	(revision 15562)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:05 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -57,5 +57,4 @@
 static void ModelClassFree (pmModelClass *modelClass)
 {
-
     if (modelClass == NULL)
         return;
@@ -70,8 +69,14 @@
 }
 
+bool psMemCheckModelClass(psPtr ptr)
+{
+    PS_ASSERT_PTR(ptr, false);
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) ModelClassFree);
+}
+
 void pmModelClassAdd (pmModelClass *model)
 {
     if (models == NULL) {
-        pmModelClassInit ();
+        pmModelClassInit();
     }
 
@@ -85,6 +90,7 @@
 {
     // if we do not need to init, return false;
-    if (models != NULL)
+    if (models != NULL) {
         return false;
+    }
 
     int Nnew = sizeof (defaultModels) / sizeof (pmModelClass);
@@ -100,4 +106,8 @@
 pmModelClass *pmModelClassSelect (pmModelType type)
 {
+    if (models == NULL) {
+        pmModelClassInit();
+    }
+
     if ((type < 0) || (type >= Nmodels)) {
         psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
@@ -111,4 +121,5 @@
     psFree (models);
     models = NULL;
+    Nmodels = 0;
     return;
 }
@@ -116,4 +127,8 @@
 psS32 pmModelClassParameterCount (pmModelType type)
 {
+    if (models == NULL) {
+        pmModelClassInit();
+    }
+
     if ((type < 0) || (type >= Nmodels)) {
         psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
@@ -125,4 +140,8 @@
 psS32 pmModelClassGetType (char *name)
 {
+    if (models == NULL) {
+        pmModelClassInit();
+    }
+
     for (int i = 0; i < Nmodels; i++) {
         if (!strcmp(models[i].name, name)) {
@@ -135,4 +154,8 @@
 char *pmModelClassGetName (pmModelType type)
 {
+    if (models == NULL) {
+        pmModelClassInit();
+    }
+
     if ((type < 0) || (type >= Nmodels)) {
         psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
Index: trunk/psModules/src/objects/pmModelClass.h
===================================================================
--- trunk/psModules/src/objects/pmModelClass.h	(revision 15417)
+++ trunk/psModules/src/objects/pmModelClass.h	(revision 15562)
@@ -21,6 +21,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-08-24 00:11:02 $
+ * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -49,4 +49,7 @@
 pmModelClass *pmModelClassAlloc (int nModels);
 
+//
+bool psMemCheckModelClass(psPtr ptr);
+
 // initialize the internal (static) model class with the default models
 bool pmModelClassInit (void);
Index: trunk/psModules/src/objects/pmModelGroup.c
===================================================================
--- trunk/psModules/src/objects/pmModelGroup.c	(revision 15417)
+++ trunk/psModules/src/objects/pmModelGroup.c	(revision 15562)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-24 00:11:02 $
+ *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -68,4 +68,10 @@
 }
 
+bool psMemCheckModelGroup(psPtr ptr)
+{
+    PS_ASSERT_PTR(ptr, false);
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) ModelGroupFree);
+}
+
 void pmModelGroupAdd (pmModelGroup *model)
 {
Index: trunk/psModules/src/objects/pmModelGroup.h
===================================================================
--- trunk/psModules/src/objects/pmModelGroup.h	(revision 15417)
+++ trunk/psModules/src/objects/pmModelGroup.h	(revision 15562)
@@ -21,6 +21,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-08-24 00:11:02 $
+ * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -78,4 +78,6 @@
 pmModelGroup *pmModelGroupAlloc (int nModels);
 
+bool psMemCheckModelGroup(psPtr ptr);
+
 // initialize the internal (static) model group with the default models
 bool pmModelGroupInit (void);
Index: trunk/psModules/src/objects/pmModelUtils.c
===================================================================
--- trunk/psModules/src/objects/pmModelUtils.c	(revision 15417)
+++ trunk/psModules/src/objects/pmModelUtils.c	(revision 15562)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:04:30 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -36,4 +36,7 @@
 pmModel *pmModelFromPSF (pmModel *modelEXT, pmPSF *psf)
 {
+    PS_ASSERT_PTR_NON_NULL(psf, NULL);
+    PS_ASSERT_PTR_NON_NULL(modelEXT, NULL);
+
     // allocate a new pmModel to hold the PSF version
     pmModel *modelPSF = pmModelAlloc (psf->type);
@@ -53,7 +56,7 @@
 // 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);
+pmModel *pmModelFromPSFforXY (pmPSF *psf, float Xo, float Yo, float Io)
+{
+    PS_ASSERT_PTR_NON_NULL(psf, NULL);
 
     // allocate a new pmModel to hold the PSF version
@@ -75,4 +78,6 @@
 // set this model to have the requested flux
 bool pmModelSetFlux (pmModel *model, float flux) {
+    PS_ASSERT_PTR_NON_NULL(model, NULL);
+    PS_ASSERT_PTR_NON_NULL(model->params, NULL);
 
     // set Io to be 1.0
Index: trunk/psModules/src/objects/pmPSF.c
===================================================================
--- trunk/psModules/src/objects/pmPSF.c	(revision 15417)
+++ trunk/psModules/src/objects/pmPSF.c	(revision 15562)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-29 00:15:32 $
+ *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -76,4 +76,10 @@
 }
 
+bool psMemCheckPSFOptions(psPtr ptr)
+{
+    PS_ASSERT_PTR(ptr, false);
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmPSFOptionsFree);
+}
+
 /*****************************************************************************
 pmPSFFree(psf): function to free a pmPSF structure
@@ -81,7 +87,7 @@
 static void pmPSFFree (pmPSF *psf)
 {
-
-    if (psf == NULL)
+    if (psf == NULL) {
         return;
+    }
 
     psFree (psf->ChiTrend);
@@ -98,5 +104,6 @@
  pmPSFAlloc (type): allocate a pmPSF.
 
- NOTE: PSF model parameters which are not modeled on an image are set to NULL in psf->params.
+ NOTE: PSF model parameters which are not modeled on an image are set to NULL
+ in psf->params.
 
  These are normally:
@@ -109,4 +116,5 @@
 pmPSF *pmPSFAlloc (pmPSFOptions *options)
 {
+    PS_ASSERT_PTR_NON_NULL(options, NULL);
     int Nparams;
 
@@ -205,4 +213,10 @@
 }
 
+bool psMemCheckPSF(psPtr ptr)
+{
+    PS_ASSERT_PTR(ptr, false);
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmPSFFree);
+}
+
 // the PSF models the \sigma_{xy} variation of the elliptical contour as a function of position in the image with a
 // polynomial.  an individual object has a contour of the form (x^2/2sx^2) + (y^2/2sy^2) + sxy*x*y
@@ -217,4 +231,5 @@
 double pmPSF_SXYfromModel (psF32 *modelPar)
 {
+    PS_ASSERT_PTR_NON_NULL(modelPar, NAN);
 
     double SXX = modelPar[PM_PAR_SXX];
@@ -229,4 +244,5 @@
 double pmPSF_SXYtoModel (psF32 *fittedPar)
 {
+    PS_ASSERT_PTR_NON_NULL(fittedPar, NAN);
 
     double SXX = fittedPar[PM_PAR_SXX];
@@ -247,4 +263,6 @@
 bool pmPSF_FitToModel (psF32 *fittedPar, float minMinorAxis)
 {
+    PS_ASSERT_PTR_NON_NULL(fittedPar, false);
+
     psEllipsePol pol;
 
@@ -272,4 +290,7 @@
 psEllipsePol pmPSF_ModelToFit (psF32 *modelPar)
 {
+//   XXX: must assert non-NULL input parameter
+//    PS_ASSERT_PTR_NON_NULL(modelPar, NAN);
+
     psEllipseShape shape;
 
@@ -289,4 +310,6 @@
     psEllipseShape shape;
     psEllipseAxes axes;
+//   XXX: must assert non-NULL input parameter
+//    PS_ASSERT_PTR_NON_NULL(modelPar, axes);
 
     shape.sx  = modelPar[PM_PAR_SXX] / M_SQRT2;
@@ -310,4 +333,6 @@
 bool pmPSF_AxesToModel (psF32 *modelPar, psEllipseAxes axes)
 {
+    PS_ASSERT_PTR_NON_NULL(modelPar, false);
+
     if ((axes.major <= 0) || (axes.minor <= 0)) {
         modelPar[PM_PAR_SXX] = 0.0;
@@ -374,4 +399,6 @@
 bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore, psMaskType maskVal, psMaskType mark)
 {
+    PS_ASSERT_PTR_NON_NULL(readout, false);
+    PS_ASSERT_PTR_NON_NULL(readout->image, false);
 
     // bool status;
Index: trunk/psModules/src/objects/pmPSF.h
===================================================================
--- trunk/psModules/src/objects/pmPSF.h	(revision 15417)
+++ trunk/psModules/src/objects/pmPSF.h	(revision 15562)
@@ -6,6 +6,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-09-25 22:05:05 $
+ * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -87,6 +87,9 @@
  *
  */
+
 pmPSF *pmPSFAlloc (pmPSFOptions *options);
-pmPSFOptions *pmPSFOptionsAlloc ();
+bool psMemCheckPSF(psPtr ptr);
+pmPSFOptions *pmPSFOptionsAlloc();
+bool psMemCheckPSFOptions(psPtr ptr);
 
 double pmPSF_SXYfromModel (psF32 *modelPar);
Index: trunk/psModules/src/objects/pmPSF_IO.c
===================================================================
--- trunk/psModules/src/objects/pmPSF_IO.c	(revision 15417)
+++ trunk/psModules/src/objects/pmPSF_IO.c	(revision 15562)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-10-09 19:26:25 $
+ *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -50,4 +50,9 @@
 bool pmPSFmodelCheckDataStatusForView (const pmFPAview *view, const pmFPAfile *file)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa->chips, false);
+
     pmFPA *fpa = file->fpa;
 
@@ -61,4 +66,6 @@
     }
     pmChip *chip = fpa->chips->data[view->chip];
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+    PS_ASSERT_PTR_NON_NULL(chip->cells, false);
 
     if (view->cell == -1) {
@@ -75,4 +82,7 @@
 
 bool pmPSFmodelCheckDataStatusForFPA (const pmFPA *fpa) {
+
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+    PS_ASSERT_PTR_NON_NULL(fpa->chips, false);
 
     for (int i = 0; i < fpa->chips->n; i++) {
@@ -85,4 +95,5 @@
 
 bool pmPSFmodelCheckDataStatusForChip (const pmChip *chip) {
+    PS_ASSERT_PTR_NON_NULL(chip, false);
 
     bool status;
@@ -95,4 +106,8 @@
 bool pmPSFmodelWriteForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa->chips, false);
 
     pmFPA *fpa = file->fpa;
@@ -126,4 +141,7 @@
 bool pmPSFmodelWriteFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+    PS_ASSERT_PTR_NON_NULL(fpa->chips, false);
     pmFPAview *thisView = pmFPAviewAlloc (view->nRows);
     *thisView = *view;
@@ -145,4 +163,7 @@
 bool pmPSFmodelWriteChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+
     if (!pmPSFmodelWrite (chip->analysis, view, file, config)) {
         psError(PS_ERR_IO, false, "Failed to write PSF for chip");
@@ -162,4 +183,7 @@
 bool pmPSFmodelWrite (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
     bool status;
     pmHDU *hdu;
@@ -450,6 +474,9 @@
 
 // if this file needs to have a PHU written out, write one
-bool pmPSFmodelWritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) {
-
+bool pmPSFmodelWritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
     // not needed if already written
     if (file->wrote_phu) return true;
@@ -494,4 +521,7 @@
 bool pmPSFmodelReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
 
     pmFPA *fpa = file->fpa;
@@ -517,4 +547,8 @@
 bool pmPSFmodelReadFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
+
     bool success = true;                // Was everything successful?
     for (int i = 0; i < fpa->chips->n; i++) {
@@ -528,4 +562,8 @@
 bool pmPSFmodelReadChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
+
     if (!pmPSFmodelRead (chip->analysis, view, file, config)) {
         psError(PS_ERR_IO, false, "Failed to write PSF for chip");
@@ -539,4 +577,8 @@
 bool pmPSFmodelRead (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
+
     bool status;
     char *rule = NULL;
@@ -763,4 +805,3 @@
 }
 
-// create a psMetadata representation (human-readable) of a psf model
 // XXX pmPSF to/from Metadata functions were defined for 1.22 and earlier, but were dropped
Index: trunk/psModules/src/objects/pmPSFtry.c
===================================================================
--- trunk/psModules/src/objects/pmPSFtry.c	(revision 15417)
+++ trunk/psModules/src/objects/pmPSFtry.c	(revision 15562)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-10-09 19:26:25 $
+ *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -81,4 +81,11 @@
 }
 
+bool psMemCheckPSFtry(psPtr ptr)
+{
+    PS_ASSERT_PTR(ptr, false);
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmPSFtryFree);
+}
+
+
 // build a pmPSFtry for the given model:
 // - fit each source with the free-floating model
@@ -249,4 +256,7 @@
 bool pmPSFtryMetric (pmPSFtry *psfTry, float RADIUS)
 {
+    PS_ASSERT_PTR_NON_NULL(psfTry, false);
+    PS_ASSERT_PTR_NON_NULL(psfTry->sources, false);
+
     // the measured (aperture - fit) magnitudes (dA == psfTry->metric)
     //   depend on both the true ap-fit (dAo) and the bias in the sky measurement:
@@ -346,4 +356,7 @@
 bool pmPSFFromPSFtry (pmPSFtry *psfTry)
 {
+    PS_ASSERT_PTR_NON_NULL(psfTry, false);
+    PS_ASSERT_PTR_NON_NULL(psfTry->sources, false);
+
     pmPSF *psf = psfTry->psf;
 
Index: trunk/psModules/src/objects/pmPSFtry.h
===================================================================
--- trunk/psModules/src/objects/pmPSFtry.h	(revision 15417)
+++ trunk/psModules/src/objects/pmPSFtry.h	(revision 15562)
@@ -6,6 +6,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-09-25 22:05:05 $
+ * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -78,5 +78,7 @@
  *
  */
+
 pmPSFtry *pmPSFtryAlloc (psArray *sources, pmPSFOptions *options);
+bool psMemCheckPSFtry(psPtr ptr);
 
 /** pmPSFtryModel()
Index: trunk/psModules/src/objects/pmPeaks.c
===================================================================
--- trunk/psModules/src/objects/pmPeaks.c	(revision 15417)
+++ trunk/psModules/src/objects/pmPeaks.c	(revision 15562)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-27 03:35:29 $
+ *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -150,4 +150,5 @@
 }
 
+// XXX: Get rid of this:
 bool pmPeakTest(const psPtr ptr)
 {
@@ -155,5 +156,13 @@
 }
 
+bool psMemCheckPeak(psPtr ptr)
+{
+    PS_ASSERT_PTR(ptr, false);
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) peakFree);
+}
+
+
 // psSort comparison function for peaks
+// XXX: Add error-checking for NULL args
 int pmPeaksCompareAscend (const void **a, const void **b)
 {
@@ -177,4 +186,5 @@
 
 // psSort comparison function for peaks
+// XXX: Add error-checking for NULL args
 int pmPeaksCompareDescend (const void **a, const void **b)
 {
Index: trunk/psModules/src/objects/pmPeaks.h
===================================================================
--- trunk/psModules/src/objects/pmPeaks.h	(revision 15417)
+++ trunk/psModules/src/objects/pmPeaks.h	(revision 15562)
@@ -10,6 +10,6 @@
  * @author GLG, MHPCC
  *
- * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-09-27 03:35:29 $
+ * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -75,4 +75,5 @@
 
 bool pmPeakTest(const psPtr ptr);
+bool psMemCheckPeak(psPtr ptr);
 
 /** pmPeaksInVector()
Index: trunk/psModules/src/objects/pmResiduals.c
===================================================================
--- trunk/psModules/src/objects/pmResiduals.c	(revision 15417)
+++ trunk/psModules/src/objects/pmResiduals.c	(revision 15562)
@@ -4,6 +4,6 @@
  *
  * @author EAM, IfA
- * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-04-21 19:47:14 $
+ * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  * Copyright 2004 IfA, University of Hawaii
  */
@@ -51,2 +51,9 @@
     return resid;
 }
+
+bool psMemCheckResiduals(psPtr ptr)
+{
+    PS_ASSERT_PTR(ptr, false);
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmResidualsFree);
+}
+
Index: trunk/psModules/src/objects/pmResiduals.h
===================================================================
--- trunk/psModules/src/objects/pmResiduals.h	(revision 15417)
+++ trunk/psModules/src/objects/pmResiduals.h	(revision 15562)
@@ -4,6 +4,6 @@
  *
  * @author EAM, IfA
- * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-04-21 19:47:14 $
+ * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  * Copyright 2004 IfA, University of Hawaii
  */
@@ -29,4 +29,5 @@
 
 pmResiduals *pmResidualsAlloc (int xSize, int ySize, int xBin, int yBin);
+bool psMemCheckResiduals(psPtr ptr);
 
 /// @}
Index: trunk/psModules/src/objects/pmSource.c
===================================================================
--- trunk/psModules/src/objects/pmSource.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSource.c	(revision 15562)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-10-06 02:29:47 $
+ *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -77,8 +77,15 @@
 }
 
+bool psMemCheckSource(psPtr ptr)
+{
+    PS_ASSERT_PTR(ptr, false);
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) sourceFree);
+}
+
 /******************************************************************************
 pmSourceAlloc(): Allocate the pmSource structure and initialize its members
 to NULL.
 *****************************************************************************/
+
 pmSource *pmSourceAlloc()
 {
@@ -132,4 +139,7 @@
 pmSource *pmSourceCopy(pmSource *in)
 {
+    if (in == NULL) {
+        return(NULL);
+    }
     // this copy is used to allow multiple fit attempts on the
     // same object.  the pixels, weight, and mask arrays all point to
@@ -139,19 +149,23 @@
 
     // this is actually the same peak as the original, is this the correct way to handle this?
-    source->peak = pmPeakAlloc (in->peak->x, in->peak->y, in->peak->value, in->peak->type);
-    source->peak->xf = in->peak->xf;
-    source->peak->yf = in->peak->yf;
-    source->peak->flux = in->peak->flux;
-    source->peak->SN = in->peak->SN;
+    if (in->peak != NULL) {
+        source->peak = pmPeakAlloc (in->peak->x, in->peak->y, in->peak->value, in->peak->type);
+        source->peak->xf = in->peak->xf;
+        source->peak->yf = in->peak->yf;
+        source->peak->flux = in->peak->flux;
+        source->peak->SN = in->peak->SN;
+    }
 
     // copy the values in the moments structure
-    source->moments  =  pmMomentsAlloc();
-    *source->moments = *in->moments;
+    if (in->moments != NULL) {
+        source->moments  =  pmMomentsAlloc();
+        *source->moments = *in->moments;
+    }
 
     // These images are all views to the parent.
     // We want a new view, but pointing at the same pixels.
-    source->pixels   = psImageCopyView (NULL, in->pixels);
-    source->weight   = psImageCopyView (NULL, in->weight);
-    source->maskView = psImageCopyView (NULL, in->maskView);
+    source->pixels   = psImageCopyView(NULL, in->pixels);
+    source->weight   = psImageCopyView(NULL, in->weight);
+    source->maskView = psImageCopyView(NULL, in->maskView);
 
     // the maskObj is a unique mask array; create a new mask image
@@ -173,4 +187,9 @@
                           psF32 Radius)
 {
+    PS_ASSERT_PTR_NON_NULL(mySource, false);
+    PS_ASSERT_PTR_NON_NULL(readout, false);
+    PS_ASSERT_PTR_NON_NULL(readout->image, false);
+    PS_ASSERT_INT_POSITIVE(Radius, false);
+
     psRegion srcRegion;
 
@@ -200,9 +219,11 @@
                             psF32 Radius)
 {
+    PS_ASSERT_PTR_NON_NULL(mySource, false);
+    PS_ASSERT_PTR_NON_NULL(readout, false);
+    PS_ASSERT_PTR_NON_NULL(readout->image, false);
+    PS_ASSERT_INT_POSITIVE(Radius, false);
+
     bool extend;
     psRegion newRegion;
-
-    if (Radius == 0)
-        return false;
 
     // check to see if new region is completely contained within old region
@@ -814,6 +835,8 @@
 
 // should we call pmSourceCacheModel if it does not exist?
-bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal, int dx, int dy) {
-
+bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, 
+                 psMaskType maskVal, int dx, int dy)
+{
+    PS_ASSERT_PTR_NON_NULL(source, false);
     bool status;
 
@@ -904,4 +927,5 @@
 pmModel *pmSourceGetModel (bool *isPSF, const pmSource *source)
 {
+    PS_ASSERT_PTR_NON_NULL(source, NULL);
 
     pmModel *model;
Index: trunk/psModules/src/objects/pmSource.h
===================================================================
--- trunk/psModules/src/objects/pmSource.h	(revision 15417)
+++ trunk/psModules/src/objects/pmSource.h	(revision 15562)
@@ -3,6 +3,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-09-27 03:35:29 $
+ * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -10,4 +10,6 @@
 # ifndef PM_SOURCE_H
 # define PM_SOURCE_H
+
+# include "pmSourceExtendedPars.h"
 
 /// @addtogroup Objects Object Detection / Analysis Functions
@@ -84,4 +86,5 @@
     psRegion region;                    ///< area on image covered by selected pixels
     float sky, skyErr;                  ///< The sky and its error at the center of the object
+    pmSourceExtendedPars *extpars;      ///< extended source parameters
 };
 
@@ -111,4 +114,7 @@
  *
  */
+
+bool psMemCheckSource(psPtr ptr);
+
 pmSource  *pmSourceCopy(pmSource *source);
 
@@ -178,8 +184,7 @@
  */
 pmPSFClump pmSourcePSFClump(
-    psArray *source,   ///< The input pmSource
-    psMetadata *metadata  ///< Contains classification parameters
-);
-
+    psArray *source,                    ///< The input pmSource
+    psMetadata *metadata                ///< Contains classification parameters
+);
 
 /** pmSourceRoughClass()
@@ -194,7 +199,7 @@
  */
 bool pmSourceRoughClass(
-    psArray *source,   ///< The input pmSource
-    psMetadata *metadata,  ///< Contains classification parameters
-    pmPSFClump clump,   ///< Statistics about the PSF clump
+    psArray *source,                    ///< The input pmSource
+    psMetadata *metadata,               ///< Contains classification parameters
+    pmPSFClump clump,                   ///< Statistics about the PSF clump
     psMaskType maskSat                  ///< Mask value for saturated pixels
 );
Index: trunk/psModules/src/objects/pmSourceContour.c
===================================================================
--- trunk/psModules/src/objects/pmSourceContour.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourceContour.c	(revision 15562)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:05 $
+ *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -220,4 +220,5 @@
 psArray *pmSourceContour (psImage *image, int xc, int yc, float threshold)
 {
+    PS_ASSERT_PTR_NON_NULL(image, NULL);
 
     int xR, yR, x0, x1, x0s, x1s;
Index: trunk/psModules/src/objects/pmSourceExtendedPars.c
===================================================================
--- trunk/psModules/src/objects/pmSourceExtendedPars.c	(revision 15562)
+++ trunk/psModules/src/objects/pmSourceExtendedPars.c	(revision 15562)
@@ -0,0 +1,155 @@
+/** @file  pmSourceExtendedPars.c
+ *
+ *  Functions to define and manipulate sources on images
+ *
+ *  @author GLG, MHPCC
+ *  @author EAM, IfA: significant modifications.
+ *
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
+ *
+ *  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 "pmGrowthCurve.h"
+#include "pmTrend2D.h"
+#include "pmPSF.h"
+#include "pmModel.h"
+#include "pmSource.h"
+
+static void pmSourceExtendedParsFree (pmSourceExtendedPars *pars) {
+    if (!pars) return;
+
+    psFree(pars->profile);
+    psFree(pars->annuli);
+    psFree(pars->isophot);
+    psFree(pars->petrosian);
+    psFree(pars->kron);
+    return;
+}
+
+pmSourceExtendedPars *pmSourceExtendedParsAlloc () {
+    pmSourceExtendedPars *pars = (pmSourceExtendedPars *) psAlloc(sizeof(pmSourceExtendedPars));
+    psMemSetDeallocator(pars, (psFreeFunc) pmSourceExtendedParsFree);
+
+    pars->profile = NULL;
+    pars->annuli = NULL;
+    pars->isophot = NULL;
+    pars->petrosian = NULL;
+    pars->kron = NULL;
+
+    return pars;
+}
+
+static void pmSourceRadialProfileFree (pmSourceRadialProfile *profile) {
+    if (!profile) return;
+
+    psFree(profile->radius);
+    psFree(profile->flux);
+    psFree(profile->weight);
+    return;
+}
+
+pmSourceRadialProfile *pmSourceRadialProfileAlloc () {
+
+    pmSourceRadialProfile *profile = (pmSourceRadialProfile *) psAlloc(sizeof(pmSourceRadialProfile));
+    psMemSetDeallocator(profile, (psFreeFunc) pmSourceRadialProfileFree);
+
+    profile->radius = NULL;
+    profile->flux = NULL;
+    profile->weight = NULL;
+
+    return profile;
+}
+
+static void pmSourceIsophotalValuesFree (pmSourceIsophotalValues *isophot) {
+    if (!isophot) return;
+    return;
+}
+
+pmSourceIsophotalValues *pmSourceIsophotalValuesAlloc () {
+
+    pmSourceIsophotalValues *isophot = (pmSourceIsophotalValues *) psAlloc(sizeof(pmSourceIsophotalValues));
+    psMemSetDeallocator(isophot, (psFreeFunc) pmSourceIsophotalValuesFree);
+
+    isophot->mag = 0.0;
+    isophot->magErr = 0.0;
+    isophot->rad = 0.0;
+    isophot->radErr = 0.0;
+
+    return isophot;
+}
+
+static void pmSourcePetrosianValuesFree (pmSourcePetrosianValues *petrosian) {
+    if (!petrosian) return;
+    return;
+}
+
+pmSourcePetrosianValues *pmSourcePetrosianValuesAlloc () {
+
+    pmSourcePetrosianValues *petrosian = (pmSourcePetrosianValues *) psAlloc(sizeof(pmSourcePetrosianValues));
+    psMemSetDeallocator(petrosian, (psFreeFunc) pmSourcePetrosianValuesFree);
+
+    petrosian->mag = 0.0;
+    petrosian->magErr = 0.0;
+    petrosian->rad = 0.0;
+    petrosian->radErr = 0.0;
+
+    return petrosian;
+}
+
+static void pmSourceKronValuesFree (pmSourceKronValues *kron) {
+    if (!kron) return;
+    return;
+}
+
+pmSourceKronValues *pmSourceKronValuesAlloc () {
+
+    pmSourceKronValues *kron = (pmSourceKronValues *) psAlloc(sizeof(pmSourceKronValues));
+    psMemSetDeallocator(kron, (psFreeFunc) pmSourceKronValuesFree);
+
+    kron->mag = 0.0;
+    kron->magErr = 0.0;
+    kron->rad = 0.0;
+    kron->radErr = 0.0;
+
+    return kron;
+}
+
+static void pmSourceAnnuliFree (pmSourceAnnuli *annuli) {
+    if (!annuli) return;
+
+    psFree (annuli->flux);
+    psFree (annuli->fluxErr);
+    psFree (annuli->fluxVar);
+
+    return;
+}
+
+pmSourceAnnuli *pmSourceAnnuliAlloc () {
+
+    pmSourceAnnuli *annuli = (pmSourceAnnuli *) psAlloc(sizeof(pmSourceAnnuli));
+    psMemSetDeallocator(annuli, (psFreeFunc) pmSourceAnnuliFree);
+
+    annuli->flux = NULL;
+    annuli->fluxErr = NULL;
+    annuli->fluxVar = NULL;
+
+    return annuli;
+}
+
Index: trunk/psModules/src/objects/pmSourceExtendedPars.h
===================================================================
--- trunk/psModules/src/objects/pmSourceExtendedPars.h	(revision 15562)
+++ trunk/psModules/src/objects/pmSourceExtendedPars.h	(revision 15562)
@@ -0,0 +1,65 @@
+/* @file  pmSourceExtendedPars.h
+ *
+ * @author EAM, IfA
+ *
+ * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
+ * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+# ifndef PM_SOURCE_EXTENDED_PARS_H
+# define PM_SOURCE_EXTENDED_PARS_H
+
+/// @addtogroup Objects Object Detection / Analysis Functions
+/// @{
+
+typedef struct {
+  psVector *radius;
+  psVector *flux;
+  psVector *weight;
+} pmSourceRadialProfile;
+
+typedef struct {
+  psVector *flux;
+  psVector *fluxErr;
+  psVector *fluxVar;
+} pmSourceAnnuli;
+
+typedef struct {
+  float mag;
+  float magErr;
+  float rad;
+  float radErr;
+} pmSourceIsophotalValues;
+
+typedef struct {
+  float mag;
+  float magErr;
+  float rad;
+  float radErr;
+} pmSourcePetrosianValues;
+
+typedef struct {
+  float mag;
+  float magErr;
+  float rad;
+  float radErr;
+} pmSourceKronValues;
+
+typedef struct {
+  pmSourceRadialProfile   *profile;
+  pmSourceAnnuli          *annuli;
+  pmSourceIsophotalValues *isophot;
+  pmSourcePetrosianValues *petrosian;
+  pmSourceKronValues      *kron;
+} pmSourceExtendedPars;
+
+pmSourceExtendedPars *pmSourceExtendedParsAlloc ();
+pmSourceRadialProfile *pmSourceRadialProfileAlloc ();
+pmSourceIsophotalValues *pmSourceIsophotalValuesAlloc ();
+pmSourcePetrosianValues *pmSourcePetrosianValuesAlloc ();
+pmSourceKronValues *pmSourceKronValuesAlloc ();
+pmSourceAnnuli *pmSourceAnnuliAlloc ();
+
+/// @}
+# endif /* PM_SOURCE_H */
Index: trunk/psModules/src/objects/pmSourceFitSet.c
===================================================================
--- trunk/psModules/src/objects/pmSourceFitSet.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourceFitSet.c	(revision 15562)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-28 00:39:41 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -79,8 +79,16 @@
 }
 
+bool psMemCheckSourceFitSetData(psPtr ptr)
+{
+    PS_ASSERT_PTR(ptr, false);
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmSourceFitSetDataFree);
+}
+
+
 // this function is called with the full set of parameters and the beta values in a single vector
-bool pmSourceFitSetCheckLimits (psMinConstraintMode mode, int nParam, float *params, float *betas)
-{
-    assert (thisSet);
+bool pmSourceFitSetCheckLimits (psMinConstraintMode mode, int nParam, float *params,
+                                float *betas)
+{
+    PS_ASSERT_PTR_NON_NULL(thisSet, false);
 
     // nParam is the parameter in the full sequence.  determine which single model this comes from
@@ -109,7 +117,9 @@
 
 // merge parameters from FitSet models into single param and deriv vectors
-bool pmSourceFitSetJoin (psVector *deriv, psVector *param, pmSourceFitSetData *set) {
-
-    assert (set);
+bool pmSourceFitSetJoin (psVector *deriv, psVector *param, pmSourceFitSetData *set)
+{
+    PS_ASSERT_PTR_NON_NULL(set, false);
+    PS_ASSERT_PTR_NON_NULL(param, false);
+
     assert (set->paramSet->n == set->derivSet->n);
 
@@ -138,6 +148,7 @@
 // distribute parameters from single param and deriv vectors into FitSet models
 bool pmSourceFitSetSplit (pmSourceFitSetData *set, const psVector *deriv, const psVector *param) {
-
-    assert (set);
+    PS_ASSERT_PTR_NON_NULL(set, false);
+    PS_ASSERT_PTR_NON_NULL(param, false);
+
     assert (set->paramSet->n == set->derivSet->n);
 
@@ -159,9 +170,10 @@
 }
 
-bool pmSourceFitSetValues (pmSourceFitSetData *set, const psVector *dparam, const psVector *param, pmSource *source, psMinimization *myMin, int nPix, bool fitStatus) {
-
+bool pmSourceFitSetValues (pmSourceFitSetData *set, const psVector *dparam, 
+                           const psVector *param, pmSource *source,
+                           psMinimization *myMin, int nPix, bool fitStatus)
+{
+    PS_ASSERT_PTR_NON_NULL(set, false);
     bool onPic = true;
-
-    assert (set);
 
     int n = 0;
@@ -203,8 +215,7 @@
 psF32 pmSourceFitSetFunction(psVector *deriv, const psVector *param, const psVector *x)
 {
+    PS_ASSERT_PTR_NON_NULL(thisSet, NAN);
     float chisqSum = 0.0;
     float chisqOne = 0.0;
-
-    assert (thisSet);
     pmSourceFitSetSplit (thisSet, deriv, param);
 
@@ -225,5 +236,9 @@
 
 // XXX allow the mode to be a function of the object (eg, S/N)
-bool pmSourceFitSetMasks (psMinConstraint *constraint, pmSourceFitSetData *set, pmSourceFitMode mode) {
+bool pmSourceFitSetMasks (psMinConstraint *constraint, pmSourceFitSetData *set,
+                          pmSourceFitMode mode)
+{
+    PS_ASSERT_PTR_NON_NULL(set, false);
+    PS_ASSERT_PTR_NON_NULL(constraint, false);
 
     // unmask everyone
Index: trunk/psModules/src/objects/pmSourceFitSet.h
===================================================================
--- trunk/psModules/src/objects/pmSourceFitSet.h	(revision 15417)
+++ trunk/psModules/src/objects/pmSourceFitSet.h	(revision 15562)
@@ -3,6 +3,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-09-28 00:39:47 $
+ * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -23,4 +23,5 @@
 // initialize data for a group of object models
 pmSourceFitSetData *pmSourceFitSetDataAlloc (psArray *modelSet);
+bool psMemCheckSourceFitSetData(psPtr ptr);
 
 // function used to set limits for a group of models
Index: trunk/psModules/src/objects/pmSourceIO.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourceIO.c	(revision 15562)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.52 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-10-05 22:46:34 $
+ *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -47,4 +47,6 @@
 int pmSourceGetDophotType (pmSource *source)
 {
+    PS_ASSERT_PTR_NON_NULL(source, -1);
+
     switch (source->type) {
 
@@ -74,4 +76,6 @@
 bool pmSourceSetDophotType (pmSource *source, int type)
 {
+    PS_ASSERT_PTR_NON_NULL(source, false);
+
     if (type == 4) {
         source->mode |= PM_SOURCE_MODE_FAIL;
@@ -106,4 +110,7 @@
 bool pmFPAviewWriteObjects (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
 
     pmFPA *fpa = file->fpa;
@@ -165,4 +172,8 @@
 bool pmFPAWriteObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+    PS_ASSERT_PTR_NON_NULL(fpa->chips, false);
+
     pmFPAview *thisView = pmFPAviewAlloc (view->nRows);
     *thisView = *view;
@@ -184,4 +195,8 @@
 bool pmChipWriteObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+    PS_ASSERT_PTR_NON_NULL(chip->cells, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+
     pmFPAview *thisView = pmFPAviewAlloc (view->nRows);
     *thisView = *view;
@@ -203,4 +218,8 @@
 bool pmCellWriteObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(cell, false);
+    PS_ASSERT_PTR_NON_NULL(cell->readouts, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+
     pmFPAview *thisView = pmFPAviewAlloc (view->nRows);
     *thisView = *view;
@@ -222,12 +241,18 @@
 bool pmReadoutWriteObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(readout, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
 
     bool status;
-    char *exttype;
-    char *dataname;
-    char *headname;
     pmHDU *hdu;
     psMetadata *updates;
     psMetadata *outhead;
+
+    char *exttype  = NULL;
+    char *dataname = NULL;
+    char *xsrcname = NULL;
+    char *headname = NULL;
 
     // XXX if sources is NULL, skip the cell or write out empty tables?
@@ -284,4 +309,14 @@
         // get the current header
         hdu = pmFPAviewThisHDU (view, file->fpa);
+
+	// determine the output table format
+	psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
+	if (!status) {
+	  psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
+	  return false;
+	}
+
+	// if this is not TRUE, the output files only contain the psf measurements.
+	bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "SAVE.XSRC");
 
         // define the EXTNAME values for the different data segments:
@@ -312,4 +347,14 @@
             }
             dataname = pmFPAfileNameFromRule (rule, file, view);
+
+	    if (XSRC_OUTPUT) {
+	      // EXTNAME for extended source data table
+	      rule = psMetadataLookupStr(&status, menu, "CMF.XSRC");
+	      if (!rule) {
+                psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.XSRC in EXTNAME.RULES in camera.config");
+                return false;
+	      }
+	      xsrcname = pmFPAfileNameFromRule (rule, file, view);
+	    }
         }
 
@@ -350,10 +395,4 @@
             outhead = psMetadataAlloc ();
 
-            // determine the output table format
-            psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
-            if (!status) {
-                psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
-                return false;
-            }
             exttype = psMemIncrRefCounter (psMetadataLookupStr(&status, recipe, "OUTPUT.FORMAT"));
             if (!exttype) {
@@ -375,7 +414,6 @@
             }
             if (!strcmp (exttype, "PS1_DEV_1")) {
-                status = pmSourcesWrite_PS1_DEV_1 (file->fits, sources, file->header, outhead, dataname);
+                status = pmSourcesWrite_PS1_DEV_1 (file->fits, sources, file->header, outhead, dataname, xsrcname);
             }
-
             if (!status) {
                 psError(PS_ERR_IO, false, "writing CMF data to %s with format %s\n", file->filename, exttype);
@@ -403,5 +441,8 @@
 
 // if this file needs to have a PHU written out, write one
-bool pmSource_CMF_WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) {
+bool pmSource_CMF_WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
 
     bool status;
@@ -512,4 +553,8 @@
 bool pmFPAviewReadObjects (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
+
     pmFPA *fpa = file->fpa;
 
@@ -551,4 +596,9 @@
 bool pmFPAReadObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa->chips, false);
+
     pmFPAview *thisView = pmFPAviewAlloc (view->nRows);
     *thisView = *view;
@@ -572,4 +622,8 @@
 bool pmChipReadObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+    PS_ASSERT_PTR_NON_NULL(chip->cells, false);
+
     pmFPAview *thisView = pmFPAviewAlloc (view->nRows);
     *thisView = *view;
@@ -596,4 +650,8 @@
 bool pmCellReadObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(cell, false);
+    PS_ASSERT_PTR_NON_NULL(cell->readouts, false);
+
     pmFPAview *thisView = pmFPAviewAlloc (view->nRows);
     *thisView = *view;
@@ -637,4 +695,6 @@
 bool pmReadoutReadObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
 
     bool status;
@@ -774,4 +834,8 @@
 bool pmFPAviewCheckDataStatusForSources (const pmFPAview *view, const pmFPAfile *file)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
+
     pmFPA *fpa = file->fpa;
 
@@ -811,5 +875,8 @@
 }
 
-bool pmFPACheckDataStatusForSources (const pmFPA *fpa) {
+bool pmFPACheckDataStatusForSources (const pmFPA *fpa)
+{
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+    PS_ASSERT_PTR_NON_NULL(fpa->chips, false);
 
     for (int i = 0; i < fpa->chips->n; i++) {
@@ -821,5 +888,8 @@
 }
 
-bool pmChipCheckDataStatusForSources (const pmChip *chip) {
+bool pmChipCheckDataStatusForSources (const pmChip *chip)
+{
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+    PS_ASSERT_PTR_NON_NULL(chip->cells, false);
 
     for (int i = 0; i < chip->cells->n; i++) {
@@ -831,5 +901,8 @@
 }
 
-bool pmCellCheckDataStatusForSources (const pmCell *cell) {
+bool pmCellCheckDataStatusForSources (const pmCell *cell)
+{
+    PS_ASSERT_PTR_NON_NULL(cell, false);
+    PS_ASSERT_PTR_NON_NULL(cell->readouts, false);
 
     for (int i = 0; i < cell->readouts->n; i++) {
@@ -841,5 +914,7 @@
 }
 
-bool pmReadoutCheckDataStatusForSources (const pmReadout *readout) {
+bool pmReadoutCheckDataStatusForSources (const pmReadout *readout)
+{
+    PS_ASSERT_PTR_NON_NULL(readout, false);
 
     bool status;
Index: trunk/psModules/src/objects/pmSourceIO.h
===================================================================
--- trunk/psModules/src/objects/pmSourceIO.h	(revision 15417)
+++ trunk/psModules/src/objects/pmSourceIO.h	(revision 15562)
@@ -4,6 +4,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-09-27 03:35:29 $
+ * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  *
@@ -26,5 +26,6 @@
 bool pmSourcesWrite_SMPDATA (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
 bool pmSourcesWrite_PS1_DEV_0 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
-bool pmSourcesWrite_PS1_DEV_1 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
+bool pmSourcesWrite_PS1_DEV_1 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, char *xsrcname);
+bool pmSourcesWrite_PS1_DEV_1_XSRC (psFits *fits, psArray *sources, char *extname);
 
 bool pmSource_CMF_WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
Index: trunk/psModules/src/objects/pmSourceIO_CMP.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_CMP.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourceIO_CMP.c	(revision 15562)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:05 $
+ *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -48,4 +48,7 @@
 bool pmSourcesWriteCMP (psArray *sources, char *filename, psMetadata *header)
 {
+    PS_ASSERT_PTR_NON_NULL(sources, false);
+    PS_ASSERT_PTR_NON_NULL(filename, false);
+    PS_ASSERT_PTR_NON_NULL(header, false);
 
     int i, type;
@@ -58,11 +61,13 @@
     // find config information for output header
     float ZERO_POINT = psMetadataLookupF32 (&status, header, "ZERO_PT");
-    if (!status)
+    if (!status) {
         ZERO_POINT = 25.0;
+    }
 
     // MEF elements have XTENSION, not SIMPLE: remove this (replace with SIMPLE)
     psMetadataLookupStr (&status, header, "XTENSION");
-    if (status)
+    if (status) {
         psMetadataRemoveKey (header, "XTENSION");
+    }
 
     // create file, write-out header
@@ -148,4 +153,6 @@
 psArray *pmSourcesReadCMP (char *filename, psMetadata *header)
 {
+    PS_ASSERT_PTR_NON_NULL(filename, false);
+    PS_ASSERT_PTR_NON_NULL(header, false);
 
     bool status;
Index: trunk/psModules/src/objects/pmSourceIO_OBJ.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_OBJ.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourceIO_OBJ.c	(revision 15562)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:05 $
+ *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -42,4 +42,6 @@
 bool pmSourcesWriteOBJ (psArray *sources, char *filename)
 {
+    PS_ASSERT_PTR_NON_NULL(sources, false);
+    PS_ASSERT_PTR_NON_NULL(filename, false);
 
     int type;
Index: trunk/psModules/src/objects/pmSourceIO_PS1_DEV_0.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_PS1_DEV_0.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourceIO_PS1_DEV_0.c	(revision 15562)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:05 $
+ *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -46,7 +46,11 @@
 // values derived in the DVO database.
 // XXX how do I generate the source tables which I need to send to PSPS?
-
-bool pmSourcesWrite_PS1_DEV_0 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname)
+// XXX: input parameter imageHeader is never used.
+bool pmSourcesWrite_PS1_DEV_0 (psFits *fits, psArray *sources, psMetadata *imageHeader,
+                               psMetadata *tableHeader, char *extname)
 {
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+    PS_ASSERT_PTR_NON_NULL(sources, false);
+    PS_ASSERT_PTR_NON_NULL(extname, false);
 
     psArray *table;
@@ -147,4 +151,6 @@
 psArray *pmSourcesRead_PS1_DEV_0 (psFits *fits, psMetadata *header)
 {
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+    PS_ASSERT_PTR_NON_NULL(header, false);
 
     bool status;
Index: trunk/psModules/src/objects/pmSourceIO_PS1_DEV_1.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_PS1_DEV_1.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourceIO_PS1_DEV_1.c	(revision 15562)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-10-09 03:10:05 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -47,5 +47,5 @@
 // XXX how do I generate the source tables which I need to send to PSPS?
 
-bool pmSourcesWrite_PS1_DEV_1 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname)
+bool pmSourcesWrite_PS1_DEV_1 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, char *xsrcname)
 {
 
@@ -57,4 +57,9 @@
     psF32 xPos, yPos;
     psF32 xErr, yErr;
+
+    // if we request XSRC output, add the XSRC name to this header
+    if (xsrcname) {
+      psMetadataAddStr (tableHeader, PS_LIST_TAIL, "XSRCNAME", PS_META_REPLACE, "name of XSRC table extension", xsrcname);
+    }
 
     // let's write these out in S/N order
@@ -144,6 +149,10 @@
         return false;
     }
-
     psFree (table);
+
+    if (xsrcname) {
+      pmSourcesWrite_PS1_DEV_1_XSRC (fits, sources, xsrcname);
+    }
+
     return true;
 }
@@ -165,4 +174,6 @@
     }
     assert (modelType > -1);
+
+    // XXX need to look up the XSRCNAME entries
 
     // validate a single row of the table (must match SMP)
@@ -241,2 +252,85 @@
     return sources;
 }
+
+bool pmSourcesWrite_PS1_DEV_1_XSRC (psFits *fits, psArray *sources, char *extname)
+{
+
+    psArray *table;
+    psMetadata *row;
+    int i;
+    psF32 *PAR, *dPAR;
+    psEllipseAxes axes;
+    psF32 xPos, yPos;
+    psF32 xErr, yErr;
+
+    // create a header to hold the output data
+    psMetadata *outhead = psMetadataAlloc ();
+
+    // write the links to the image header
+    psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "xsrc table extension", extname);
+
+    // let's write these out in S/N order
+    sources = psArraySort (sources, pmSourceSortBySN);
+
+    table = psArrayAllocEmpty (sources->n);
+
+    // we write out all sources, regardless of quality.  the source flags tell us the state
+    for (i = 0; i < sources->n; i++) {
+        pmSource *source = (pmSource *) sources->data[i];
+        source->seq = i;
+
+	// skip source if it is not a ext sourc
+
+        // no difference between PSF and non-PSF model
+	// XXX the PSF output should report the value for the psf, not the ext, model
+        pmModel *model = source->modelEXT;
+        if (model == NULL) continue;
+
+	PAR = model->params->data.F32;
+	dPAR = model->dparams->data.F32;
+	xPos = PAR[PM_PAR_XPOS];
+	yPos = PAR[PM_PAR_YPOS];
+	xErr = dPAR[PM_PAR_XPOS];
+	yErr = dPAR[PM_PAR_YPOS];
+
+	axes = pmPSF_ModelToAxes (PAR, 20.0);
+
+        row = psMetadataAlloc ();
+        // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)
+        psMetadataAdd (row, PS_LIST_TAIL, "IPP_IDET",         PS_DATA_U32, "IPP detection identifier index",             source->seq);
+        psMetadataAdd (row, PS_LIST_TAIL, "X_EXT",            PS_DATA_F32, "PSF x coordinate",                           xPos);
+        psMetadataAdd (row, PS_LIST_TAIL, "Y_EXT",            PS_DATA_F32, "PSF y coordinate",                           yPos);
+        psMetadataAdd (row, PS_LIST_TAIL, "X_EXT_SIG",        PS_DATA_F32, "Sigma in PSF x coordinate",                  xErr);
+        psMetadataAdd (row, PS_LIST_TAIL, "Y_EXT_SIG",        PS_DATA_F32, "Sigma in PSF y coordinate",                  yErr);
+        psMetadataAdd (row, PS_LIST_TAIL, "EXT_INST_MAG",     PS_DATA_F32, "PSF fit instrumental magnitude",             PS_MIN (99.0, source->extMag));
+	// XXX need to calculate psfMag, psfMagErr, extMag, extMagErr...
+        psMetadataAdd (row, PS_LIST_TAIL, "EXT_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        PS_MIN (99.0, source->errMag));
+
+        // XXX these should be major and minor, not 'x' and 'y'
+        psMetadataAdd (row, PS_LIST_TAIL, "EXT_WIDTH_X",      PS_DATA_F32, "PSF width in x coordinate",                  axes.major);
+        psMetadataAdd (row, PS_LIST_TAIL, "EXT_WIDTH_Y",      PS_DATA_F32, "PSF width in y coordinate",                  axes.minor);
+        psMetadataAdd (row, PS_LIST_TAIL, "EXT_THETA",        PS_DATA_F32, "PSF orientation angle",                      axes.theta);
+
+	// other values that I need to report:
+	// R, Mag Petrosian, .....
+
+        psArrayAdd (table, 100, row);
+        psFree (row);
+    }
+
+    if (table->n == 0) {
+        psFitsWriteBlank (fits, outhead, extname);
+        psFree (table);
+        return true;
+    }
+
+    psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname);
+    if (!psFitsWriteTable (fits, outhead, table, extname)) {
+        psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
+        psFree(table);
+        return false;
+    }
+    psFree (table);
+
+    return true;
+}
Index: trunk/psModules/src/objects/pmSourceIO_RAW.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_RAW.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourceIO_RAW.c	(revision 15562)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:05 $
+ *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -44,4 +44,7 @@
 {
 
+    PS_ASSERT_PTR_NON_NULL(sources, false);
+    PS_ASSERT_PTR_NON_NULL(filename, false);
+
     char *name = (char *) psAlloc (strlen(filename) + 10);
 
@@ -65,4 +68,6 @@
 bool pmSourcesWritePSFs (psArray *sources, char *filename)
 {
+    PS_ASSERT_PTR_NON_NULL(sources, false);
+    PS_ASSERT_PTR_NON_NULL(filename, false);
 
     double dPos;
@@ -124,4 +129,6 @@
 bool pmSourcesWriteEXTs (psArray *sources, char *filename, bool requireEXT)
 {
+    PS_ASSERT_PTR_NON_NULL(sources, false);
+    PS_ASSERT_PTR_NON_NULL(filename, false);
 
     double dPos;
@@ -184,4 +191,6 @@
 bool pmSourcesWriteNULLs (psArray *sources, char *filename)
 {
+    PS_ASSERT_PTR_NON_NULL(sources, false);
+    PS_ASSERT_PTR_NON_NULL(filename, false);
 
     int i;
@@ -230,4 +239,6 @@
 bool pmMomentsWriteText (psArray *sources, char *filename)
 {
+    PS_ASSERT_PTR_NON_NULL(sources, false);
+    PS_ASSERT_PTR_NON_NULL(filename, false);
 
     int i;
Index: trunk/psModules/src/objects/pmSourceIO_SMPDATA.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_SMPDATA.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourceIO_SMPDATA.c	(revision 15562)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:05 $
+ *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -42,6 +42,11 @@
 // this format consists of a header derived from the image header
 // followed by a zero-size matrix, followed by the table data
-bool pmSourcesWrite_SMPDATA (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname)
+// XXX: input parameter imageHeader is never used
+bool pmSourcesWrite_SMPDATA (psFits *fits, psArray *sources, psMetadata *imageHeader,
+                             psMetadata *tableHeader, char *extname)
 {
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+    PS_ASSERT_PTR_NON_NULL(sources, false);
+    PS_ASSERT_PTR_NON_NULL(extname, false);
 
     psArray *table;
@@ -126,4 +131,6 @@
 psArray *pmSourcesRead_SMPDATA (psFits *fits, psMetadata *header)
 {
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+    PS_ASSERT_PTR_NON_NULL(header, false);
 
     bool status;
Index: trunk/psModules/src/objects/pmSourceIO_SX.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_SX.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourceIO_SX.c	(revision 15562)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:05 $
+ *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -42,4 +42,6 @@
 bool pmSourcesWriteSX (psArray *sources, char *filename)
 {
+    PS_ASSERT_PTR_NON_NULL(sources, false);
+    PS_ASSERT_PTR_NON_NULL(filename, false);
 
     psF32 *PAR, *dPAR;
Index: trunk/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- trunk/psModules/src/objects/pmSourcePhotometry.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourcePhotometry.c	(revision 15562)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-29 03:14:55 $
+ *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -39,5 +39,5 @@
 bool pmSourceMagnitudesInit (psMetadata *config)
 {
-
+    PS_ASSERT_PTR_NON_NULL(config, false);
     bool status;
 
@@ -64,6 +64,9 @@
 
 // XXX masked region should be (optionally) elliptical
-bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psMaskType maskVal, psMaskType mark)
-{
+bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode,
+                         psMaskType maskVal, psMaskType mark)
+{
+    PS_ASSERT_PTR_NON_NULL(source, false);
+    PS_ASSERT_PTR_NON_NULL(psf, false);
 
     int status = false;
@@ -269,11 +272,11 @@
 bool pmSourcePhotometryModel (float *fitMag, pmModel *model)
 {
+    PS_ASSERT_PTR_NON_NULL(fitMag, false);
+    if (model == NULL) {
+        return false;
+    }
 
     float fitSum = 0;
     *fitMag = NAN;
-
-    if (model == NULL) {
-        return false;
-    }
 
     // measure fitMag
@@ -289,14 +292,15 @@
 
 // return source aperture magnitude
-bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask, psMaskType maskVal)
-{
+bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask,
+                             psMaskType maskVal)
+{
+    PS_ASSERT_PTR_NON_NULL(apMag, false);
+    PS_ASSERT_PTR_NON_NULL(image, false);
+    PS_ASSERT_PTR_NON_NULL(mask, false);
+    PS_ASSERT_PTR_NON_NULL(model, false);
+
     float apSum = 0;
     float sky = 0;
     *apMag = NAN;
-
-    if (model == NULL) {
-        psError(PM_ERR_OBJECTS, true, "Model is NULL");
-        return false;
-    }
 
     if (DO_SKY) {
@@ -327,6 +331,12 @@
 
 // return source aperture magnitude
-bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask, psMaskType maskVal)
-{
+bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask,
+                          psMaskType maskVal)
+{
+    PS_ASSERT_PTR_NON_NULL(pixWeight, false);
+    PS_ASSERT_PTR_NON_NULL(image, false);
+    PS_ASSERT_PTR_NON_NULL(mask, false);
+    PS_ASSERT_PTR_NON_NULL(model, false);
+
     float modelSum = 0;
     float validSum = 0;
@@ -339,7 +349,4 @@
 
     *pixWeight = 0.0;
-
-    if (model == NULL)
-        return false;
 
     // we only care about the value of the object model, not the local sky
@@ -412,4 +419,6 @@
                              const bool unweighted_sum) // should the cross product be weighted?
 {
+    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
+    PS_ASSERT_PTR_NON_NULL(Mj, NAN);
 
     int Xs, Xe, Ys, Ye;
@@ -475,4 +484,6 @@
                            const bool unweighted_sum) // should the cross product be weighted?
 {
+    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
+    PS_ASSERT_PTR_NON_NULL(Mj, NAN);
 
     int Xs, Xe, Ys, Ye;
@@ -538,4 +549,5 @@
                       const bool unweighted_sum) // should the cross product be weighted?
 {
+    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
     double flux = 0, wt = 0, factor = 0;
 
@@ -587,6 +599,11 @@
 # endif
 
-bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight, psMaskType maskVal)
-{
+bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight,
+                    psMaskType maskVal)
+{
+    PS_ASSERT_PTR_NON_NULL(model, false);
+    PS_ASSERT_PTR_NON_NULL(image, false);
+    PS_ASSERT_PTR_NON_NULL(mask, false);
+    PS_ASSERT_PTR_NON_NULL(weight, false);
 
     double dC = 0.0;
@@ -613,4 +630,5 @@
                       const bool unweighted_sum) // should the cross product be weighted?
 {
+    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
     double flux = 0, wt = 0, factor = 0;
 
@@ -662,4 +680,6 @@
                               const bool unweighted_sum) // should the cross product be weighted?
 {
+    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
+    PS_ASSERT_PTR_NON_NULL(Mj, NAN);
     int Xs, Xe, Ys, Ye;
     int xi, xj, yi, yj;
@@ -724,5 +744,6 @@
                              const bool unweighted_sum) // should the cross product be weighted?
 {
-
+    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
+    PS_ASSERT_PTR_NON_NULL(Mj, NAN);
     int Xs, Xe, Ys, Ye;
     int xi, xj, yi, yj;
Index: trunk/psModules/src/objects/pmSourcePlotApResid.c
===================================================================
--- trunk/psModules/src/objects/pmSourcePlotApResid.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourcePlotApResid.c	(revision 15562)
@@ -4,6 +4,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:05 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *  Copyright 2006 IfA, University of Hawaii
  */
@@ -40,9 +40,14 @@
     # include <kapa.h>
 
-    // plot the sx, sy, sxy as vector field,
-    // plot the PSF measured sx, sy, sxy as vector field
-    // pull the sources from the config / file?
-    bool pmSourcePlotApResid (const pmFPAview *view, pmFPAfile *file, const pmConfig *config, pmSourcePlotLayout *layout)
+// plot the sx, sy, sxy as vector field,
+// plot the PSF measured sx, sy, sxy as vector field
+// pull the sources from the config / file?
+bool pmSourcePlotApResid (const pmFPAview *view, pmFPAfile *file, const pmConfig *config,
+                          pmSourcePlotLayout *layout)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_PTR_NON_NULL(layout, false);
 
     Graphdata graphdata;
@@ -150,5 +155,5 @@
 # else
 
-    bool pmSourcePlotApResid (const pmFPAview *view, pmFPAfile *file, const pmConfig *config, pmSourcePlotLayout *layout)
+bool pmSourcePlotApResid (const pmFPAview *view, pmFPAfile *file, const pmConfig *config, pmSourcePlotLayout *layout)
 {
     psLogMsg ("psphot", 3, "skipping ap-mag resid plot");
Index: trunk/psModules/src/objects/pmSourcePlotMoments.c
===================================================================
--- trunk/psModules/src/objects/pmSourcePlotMoments.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourcePlotMoments.c	(revision 15562)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:05 $
+ *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2006 IfA, University of Hawaii
@@ -41,9 +41,14 @@
 // this variable is defined in psmodules.h if ohana-config is found
 # if (HAVE_KAPA)
-    # include <kapa.h>
+# include <kapa.h>
 
-    // plot the sx, sy moments plane (faint and bright sources)
-    bool pmSourcePlotMoments (const pmFPAview *view, pmFPAfile *file, const pmConfig *config, pmSourcePlotLayout *layout)
+// plot the sx, sy moments plane (faint and bright sources)
+bool pmSourcePlotMoments (const pmFPAview *view, pmFPAfile *file, const pmConfig *config,
+                          pmSourcePlotLayout *layout)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_PTR_NON_NULL(layout, false);
 
     Graphdata graphdata;
Index: trunk/psModules/src/objects/pmSourcePlotPSFModel.c
===================================================================
--- trunk/psModules/src/objects/pmSourcePlotPSFModel.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourcePlotPSFModel.c	(revision 15562)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:05 $
+ *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2006 IfA, University of Hawaii
@@ -41,11 +41,16 @@
 // this variable is defined in psmodules.h if ohana-config is found
 # if (HAVE_KAPA)
-    # include <kapa.h>
-
-    // plot the sx, sy, sxy as vector field,
-    // plot the PSF measured sx, sy, sxy as vector field
-    // pull the sources from the config / file?
-    bool pmSourcePlotPSFModel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config, pmSourcePlotLayout *layout)
+# include <kapa.h>
+
+// plot the sx, sy, sxy as vector field,
+// plot the PSF measured sx, sy, sxy as vector field
+// pull the sources from the config / file?
+bool pmSourcePlotPSFModel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config,
+                           pmSourcePlotLayout *layout)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_PTR_NON_NULL(layout, false);
 
     Graphdata graphdata;
Index: trunk/psModules/src/objects/pmSourcePlots.c
===================================================================
--- trunk/psModules/src/objects/pmSourcePlots.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourcePlots.c	(revision 15562)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-05-04 00:54:09 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2006 IfA, University of Hawaii
@@ -36,4 +36,5 @@
     PS_ASSERT_PTR_NON_NULL(view, false);
     PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(config, false);
 
     if ((view->readout != -1) || (view->cell != -1)) {
@@ -149,4 +150,11 @@
 }
 
+bool psMemCheckSourcePlotLayout(psPtr ptr)
+{
+    PS_ASSERT_PTR(ptr, false);
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmSourcePlotLayoutFree);
+}
+
+
 /* we have three types of plots to produce (maybe more?)
  * for each plot, we need to supply the following information:
Index: trunk/psModules/src/objects/pmSourcePlots.h
===================================================================
--- trunk/psModules/src/objects/pmSourcePlots.h	(revision 15417)
+++ trunk/psModules/src/objects/pmSourcePlots.h	(revision 15562)
@@ -4,6 +4,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-05-04 00:54:09 $
+ * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  * Copyright 2006 Institute for Astronomy, University of Hawaii
  */
@@ -30,4 +30,5 @@
 
 pmSourcePlotLayout *pmSourcePlotLayoutAlloc();
+bool psMemCheckSourcePlotLayout(psPtr ptr);
 
 bool pmFPAviewWriteSourcePlot(const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
Index: trunk/psModules/src/objects/pmSourceUtils.c
===================================================================
--- trunk/psModules/src/objects/pmSourceUtils.c	(revision 15417)
+++ trunk/psModules/src/objects/pmSourceUtils.c	(revision 15562)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:05 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -63,5 +63,9 @@
 }
 
-pmSource *pmSourceFromModel (pmModel *model, pmReadout *readout, float radius, pmSourceType type) {
+pmSource *pmSourceFromModel (pmModel *model, pmReadout *readout, float radius, 
+                             pmSourceType type)
+{
+    PS_ASSERT_PTR_NON_NULL(model, NULL);
+    PS_ASSERT_PTR_NON_NULL(readout, NULL);
 
     pmSource *source = pmSourceAlloc ();
Index: trunk/psModules/src/objects/pmTrend2D.c
===================================================================
--- trunk/psModules/src/objects/pmTrend2D.c	(revision 15417)
+++ trunk/psModules/src/objects/pmTrend2D.c	(revision 15562)
@@ -3,7 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-10-30 00:50:00 $
- *
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *  Copyright 2004 Institute for Astronomy, University of Hawaii
  *
Index: trunk/psModules/src/objects/pmTrend2D.h
===================================================================
--- trunk/psModules/src/objects/pmTrend2D.h	(revision 15417)
+++ trunk/psModules/src/objects/pmTrend2D.h	(revision 15562)
@@ -5,6 +5,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-09-24 21:27:58 $
+ * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-11-10 01:09:20 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -34,4 +34,6 @@
 pmTrend2D *pmTrend2DAlloc (pmTrend2DMode mode, psImage *image, int nXtrend, int nYtrend, psStats *stats);
 
+bool psMemCheckTrend2D(psPtr ptr);
+
 pmTrend2D *pmTrend2DNoImageAlloc (pmTrend2DMode mode, psImageBinning *binning, psStats *stats);
 
