Index: trunk/psModules/test/objects/tst_pmObjects01.c
===================================================================
--- trunk/psModules/test/objects/tst_pmObjects01.c	(revision 5169)
+++ trunk/psModules/test/objects/tst_pmObjects01.c	(revision 5255)
@@ -17,8 +17,14 @@
  *
  * XXX: Memory leaks are not being caught.  If I allocated a psVector in these functions
- * abd never deallocate, no error is generated.
+ * and never deallocate, no error is generated.
+Fully Tested:
+    pmPeakAlloc()
+    pmMomentsAlloc()
+Weakly Tested:
+    pmSourceMoments()
+ 
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-28 20:42:52 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-10 19:53:54 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -27,4 +33,6 @@
 #include "pslib.h"
 #include "pmObjects.h"
+#include "pmModelGroup.h"
+
 #define NUM_ROWS 10
 #define NUM_COLS 10
@@ -37,6 +45,7 @@
 static int test04(void);
 static int test05(void);
-static int test06(void);
+//static int test06(void);
 static int test07(void);
+/*
 static int test08(void);
 static int test09(void);
@@ -44,4 +53,5 @@
 static int test16(void);
 static int test20(void);
+*/
 testDescription tests[] = {
                               {test00, 000, "pmObjects: structure allocators and deallocators", true, false},
@@ -50,12 +60,14 @@
                               {test03, 001, "pmObjects: pmCullPeaks()", true, false},
                               {test04, 001, "pmObjects: pmSourceLocalSky()", true, false},
-                              {test06, 001, "pmObjects: pmSourceSetPixelsCircle()", true, false},
                               {test05, 001, "pmObjects: pmSourceMoments()", true, false},
+                              //                              {test06, 001, "pmObjects: pmSourceSetPixelsCircle()", true, false},
                               {test07, 001, "pmObjects: pmMin()", true, false},
-                              {test08, 001, "pmObjects: pmSourceModelGuess()", true, false},
-                              {test09, 001, "pmObjects: pmSourceContour()", true, false},
-                              {test15, 001, "pmObjects: pmSourceAddModel()", true, false},
-                              {test16, 001, "pmObjects: pmSourceSubModel()", true, false},
-                              {test20, 001, "pmObjects: pmSourceSubModel()", true, false},
+                              /*
+                                                            {test08, 001, "pmObjects: pmSourceModelGuess()", true, false},
+                                                            {test09, 001, "pmObjects: pmSourceContour()", true, false},
+                                                            {test15, 001, "pmObjects: pmSourceAddModel()", true, false},
+                                                            {test16, 001, "pmObjects: pmSourceSubModel()", true, false},
+                                                            {test20, 001, "pmObjects: pmSourceSubModel()", true, false},
+                              */
                               {NULL}
                           };
@@ -64,4 +76,41 @@
 {
     psLogSetFormat("HLNM");
+    //
+    // We include the function names here in psTraceSetLevel() commands for
+    // debugging convenience.  There is no guarantee that this list of functions
+    // is complete.
+    //
+    psTraceSetLevel(".", 0);
+    psTraceSetLevel("pmPeakAlloc", 0);
+    psTraceSetLevel("pmMomentsAlloc", 0);
+    psTraceSetLevel("modelFree", 0);
+    psTraceSetLevel("pmModelAlloc", 0);
+    psTraceSetLevel("sourceFree", 0);
+    psTraceSetLevel("pmSourceAlloc", 0);
+    psTraceSetLevel("pmFindVectorPeaks", 0);
+    psTraceSetLevel("getRowVectorFromImage", 0);
+    psTraceSetLevel("myListAddPeak", 0);
+    psTraceSetLevel("pmFindImagePeaks", 0);
+    psTraceSetLevel("isItInThisRegion", 0);
+    psTraceSetLevel("pmCullPeaks", 0);
+    psTraceSetLevel("pmPeaksSubset", 0);
+    psTraceSetLevel("pmSourceLocalSky", 0);
+    psTraceSetLevel("checkRadius2", 0);
+    psTraceSetLevel("pmSourceMoments", 0);
+    psTraceSetLevel("pmComparePeakAscend", 0);
+    psTraceSetLevel("pmComparePeakDescend", 0);
+    psTraceSetLevel("pmSourcePSFClump", 0);
+    psTraceSetLevel("pmSourceRoughClass", 0);
+    psTraceSetLevel("pmSourceDefinePixels", 0);
+    psTraceSetLevel("pmSourceModelGuess", 0);
+    psTraceSetLevel("pmModelEval", 0);
+    psTraceSetLevel("findValue", 0);
+    psTraceSetLevel("pmSourceContour", 0);
+    psTraceSetLevel("pmSourceFitModel_v5", 0);
+    psTraceSetLevel("pmSourceFitModel", 0);
+    psTraceSetLevel("p_pmSourceAddOrSubModel", 0);
+    psTraceSetLevel("pmSourceAddModel", 0);
+    psTraceSetLevel("pmSourceSubModel", 0);
+
     return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv);
 }
@@ -116,4 +165,13 @@
                 (tmpMoments->nPixels != 0)) {
             printf("TEST ERROR: pmMomentsAlloc() did not properly initialize the pmMoments structure.\n");
+            printf("    tmpMoments->x is %f\n", tmpMoments->x);
+            printf("    tmpMoments->y is %f\n", tmpMoments->y);
+            printf("    tmpMoments->Sx is %f\n", tmpMoments->Sx);
+            printf("    tmpMoments->Sy is %f\n", tmpMoments->Sy);
+            printf("    tmpMoments->Sxy is %f\n", tmpMoments->Sxy);
+            printf("    tmpMoments->Sum is %f\n", tmpMoments->Sum);
+            printf("    tmpMoments->Peak is %f\n", tmpMoments->Peak);
+            printf("    tmpMoments->Sky is %f\n", tmpMoments->Sky);
+            printf("    tmp    Moments->nPixels is %d\n", tmpMoments->nPixels);
             testStatus = false;
         }
@@ -121,135 +179,37 @@
     psFree(tmpMoments);
 
-    printf("Testing pmModelAlloc(PS_MODEL_GAUSS)...\n");
-    pmModel *tmpModel = pmModelAlloc(PS_MODEL_GAUSS);
-    if (tmpModel == NULL) {
-        printf("TEST ERROR: pmModelAlloc(PS_MODEL_GAUSS) returned a NULL pmModel\n");
-        testStatus = false;
-    } else {
-        if ((tmpModel->params->n != 7) || (tmpModel->dparams->n != 7)) {
-            printf("TEST ERROR: pmModelAlloc(PS_MODEL_GAUSS) allocated an incorrect number of params (%ld, %ld)\n",
-                   tmpModel->params->n, tmpModel->dparams->n);
+
+    //
+    // Loop through each type of model
+    //
+    psS32 i = 0;
+    while (0 != pmModelParameterCount(i)) {
+        printf("Testing pmModelAlloc(%s)...\n", pmModelGetType(0));
+        pmModel *tmpModel = pmModelAlloc(i);
+        if (tmpModel == NULL) {
+            printf("TEST ERROR: pmModelAlloc(%s) returned a NULL pmModel\n", pmModelGetType(0));
             testStatus = false;
         } else {
-            for (psS32 i = 0 ; i < 7 ; i++) {
-                if ((tmpModel->params->data.F32[i] != 0.0) ||
-                        (tmpModel->dparams->data.F32[i] != 0.0)) {
-                    printf("TEST ERROR: pmModelAlloc(PS_MODEL_GAUSS) did not ininitialize the params/dparams array to 0.0.\n");
-                    testStatus = false;
-                }
-            }
-        }
-    }
-    psFree(tmpModel);
-
-    printf("Testing pmModelAlloc(PS_MODEL_PGAUSS)...\n");
-    tmpModel = pmModelAlloc(PS_MODEL_PGAUSS);
-    if (tmpModel == NULL) {
-        printf("TEST ERROR: pmModelAlloc(PS_MODEL_PGAUSS) returned a NULL pmModel\n");
-        testStatus = false;
-    } else {
-        if ((tmpModel->params->n != 7) || (tmpModel->dparams->n != 7)) {
-            printf("TEST ERROR: pmModelAlloc(PS_MODEL_PGAUSS) allocated an incorrect number of params (%ld, %ld)\n",
-                   tmpModel->params->n, tmpModel->dparams->n);
-            testStatus = false;
-        } else {
-            for (psS32 i = 0 ; i < 7 ; i++) {
-                if ((tmpModel->params->data.F32[i] != 0.0) ||
-                        (tmpModel->dparams->data.F32[i] != 0.0)) {
-                    printf("TEST ERROR: pmModelAlloc(PS_MODEL_PGAUSS) did not ininitialize the params/dparams array to 0.0.\n");
-                    testStatus = false;
-                }
-            }
-        }
-    }
-    psFree(tmpModel);
-
-    printf("Testing pmModelAlloc(PS_MODEL_TWIST_GAUSS)...\n");
-    tmpModel = pmModelAlloc(PS_MODEL_TWIST_GAUSS);
-    if (tmpModel == NULL) {
-        printf("TEST ERROR: pmModelAlloc(PS_MODEL_TWIST_GAUSS) returned a NULL pmModel\n");
-        testStatus = false;
-    } else {
-        if ((tmpModel->params->n != 11) || (tmpModel->dparams->n != 11)) {
-            printf("TEST ERROR: pmModelAlloc(PS_MODEL_TWIST_GAUSS) allocated an incorrect number of params (%ld, %ld)\n",
-                   tmpModel->params->n, tmpModel->dparams->n);
-            testStatus = false;
-        } else {
-            for (psS32 i = 0 ; i < 11 ; i++) {
-                if ((tmpModel->params->data.F32[i] != 0.0) ||
-                        (tmpModel->dparams->data.F32[i] != 0.0)) {
-                    printf("TEST ERROR: pmModelAlloc(PS_MODEL_TWIST_GAUSS) did not ininitialize the params/dparams array to 0.0.\n");
-                    testStatus = false;
-                }
-            }
-        }
-    }
-    psFree(tmpModel);
-
-    printf("Testing pmModelAlloc(PS_MODEL_WAUSS)...\n");
-    tmpModel = pmModelAlloc(PS_MODEL_WAUSS);
-    if (tmpModel == NULL) {
-        printf("TEST ERROR: pmModelAlloc(PS_MODEL_WAUSS) returned a NULL pmModel\n");
-        testStatus = false;
-    } else {
-        if ((tmpModel->params->n != 9) || (tmpModel->dparams->n != 9)) {
-            printf("TEST ERROR: pmModelAlloc(PS_MODEL_WAUSS) allocated an incorrect number of params (%ld, %ld)\n",
-                   tmpModel->params->n, tmpModel->dparams->n);
-            testStatus = false;
-        } else {
-            for (psS32 i = 0 ; i < 9 ; i++) {
-                if ((tmpModel->params->data.F32[i] != 0.0) ||
-                        (tmpModel->dparams->data.F32[i] != 0.0)) {
-                    printf("TEST ERROR: pmModelAlloc(PS_MODEL_WAUSS) did not ininitialize the params/dparams array to 0.0.\n");
-                    testStatus = false;
-                }
-            }
-        }
-    }
-    psFree(tmpModel);
-
-    printf("Testing pmModelAlloc(PS_MODEL_SERSIC)...\n");
-    tmpModel = pmModelAlloc(PS_MODEL_SERSIC);
-    if (tmpModel == NULL) {
-        printf("TEST ERROR: pmModelAlloc(PS_MODEL_SERSIC) returned a NULL pmModel\n");
-        testStatus = false;
-    } else {
-        if ((tmpModel->params->n != 8) || (tmpModel->dparams->n != 8)) {
-            printf("TEST ERROR: pmModelAlloc(PS_MODEL_SERSIC) allocated an incorrect number of params (%ld, %ld)\n",
-                   tmpModel->params->n, tmpModel->dparams->n);
-            testStatus = false;
-        } else {
-            for (psS32 i = 0 ; i < 8 ; i++) {
-                if ((tmpModel->params->data.F32[i] != 0.0) ||
-                        (tmpModel->dparams->data.F32[i] != 0.0)) {
-                    printf("TEST ERROR: pmModelAlloc(PS_MODEL_SERSIC) did not ininitialize the params/dparams array to 0.0.\n");
-                    testStatus = false;
-                }
-            }
-        }
-    }
-    psFree(tmpModel);
-
-    printf("Testing pmModelAlloc(PS_MODEL_SERSIC_CORE)...\n");
-    tmpModel = pmModelAlloc(PS_MODEL_SERSIC_CORE);
-    if (tmpModel == NULL) {
-        printf("TEST ERROR: pmModelAlloc(PS_MODEL_SERSIC_CORE) returned a NULL pmModel\n");
-        testStatus = false;
-    } else {
-        if ((tmpModel->params->n != 12) || (tmpModel->dparams->n != 12)) {
-            printf("TEST ERROR: pmModelAlloc(PS_MODEL_SERSIC_CORE) allocated an incorrect number of params (%ld, %ld)\n",
-                   tmpModel->params->n, tmpModel->dparams->n);
-            testStatus = false;
-        } else {
-            for (psS32 i = 0 ; i < 12 ; i++) {
-                if ((tmpModel->params->data.F32[i] != 0.0) ||
-                        (tmpModel->dparams->data.F32[i] != 0.0)) {
-                    printf("TEST ERROR: pmModelAlloc(PS_MODEL_SERSIC_CORE) did not ininitialize the params/dparams array to 0.0.\n");
-                    testStatus = false;
-                }
-            }
-        }
-    }
-    psFree(tmpModel);
+
+            /* XXX: Should we test that the members were set correctly?
+                        if ((tmpModel->params->n != 7) || (tmpModel->dparams->n != 7)) {
+                            printf("TEST ERROR: pmModelAlloc(PS_MODEL_GAUSS) allocated an incorrect number of params (%ld, %ld)\n",
+                                   tmpModel->params->n, tmpModel->dparams->n);
+                            testStatus = false;
+                        } else {
+                            for (psS32 i = 0 ; i < 7 ; i++) {
+                                if ((tmpModel->params->data.F32[i] != 0.0) ||
+                                        (tmpModel->dparams->data.F32[i] != 0.0)) {
+                                    printf("TEST ERROR: pmModelAlloc(PS_MODEL_GAUSS) did not ininitialize the params/dparams array to 0.0.\n");
+                                    testStatus = false;
+                                }
+                            }
+                        }
+            */
+        }
+        psFree(tmpModel);
+        i++;
+    }
+
 
     pmSource *tmpSource = pmSourceAlloc();
@@ -775,4 +735,70 @@
 }
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 #define TST04_NUM_ROWS 100
 #define TST04_NUM_COLS 100
@@ -792,111 +818,35 @@
     bool testStatus = true;
     psImage *imgData = psImageAlloc(TST04_NUM_COLS, TST04_NUM_ROWS, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < imgData->numRows; i++) {
-        for (psS32 j = 0 ; j < imgData->numCols; j++) {
-            imgData->data.F32[i][j] = TST04_SKY;
-        }
-    }
+    psImageInit(imgData, TST04_SKY);
+    psImage *imgMask = psImageAlloc(TST04_NUM_COLS, TST04_NUM_ROWS, PS_TYPE_U8);
+    psImageInit(imgMask, 0);
+    //    psImage *imgMaskS8 = psImageAlloc(TST04_NUM_COLS, TST04_NUM_ROWS, PS_TYPE_S8);
+    //    psImageInit(imgMaskS8, 0);
     psImage *imgDataF64 = psImageAlloc(TST04_NUM_COLS, TST04_NUM_ROWS, PS_TYPE_F64);
-    for (psS32 i = 0 ; i < imgDataF64->numRows; i++) {
-        for (psS32 j = 0 ; j < imgDataF64->numCols; j++) {
-            imgDataF64->data.F64[i][j] = 0.0;
-        }
-    }
-    pmSource *rc = NULL;
+    psImageInit(imgDataF64, 0.0);
     pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST04_NUM_ROWS / 2),
                                   (psF32) (TST04_NUM_COLS / 2),
                                   200.0,
                                   PM_PEAK_LONE);
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceLocalSky with NULL psImage.  Should generate error and return NULL.\n");
-    rc = pmSourceLocalSky(NULL, tmpPeak, PS_STAT_SAMPLE_MEAN, 10.0, 20.0);
-    if (rc != NULL) {
-        printf("TEST ERROR: pmSourceLocalSky() returned a non-NULL pmSource.\n");
-        psFree(rc);
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceLocalSky with wrong-type psImage.  Should generate error and return NULL.\n");
-    rc = pmSourceLocalSky(imgDataF64, tmpPeak, PS_STAT_SAMPLE_MEAN, 10.0, 20.0);
-    if (rc != NULL) {
-        printf("TEST ERROR: pmSourceLocalSky() returned a non-NULL pmSource.\n");
-        psFree(rc);
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceLocalSky with NULL pmPeak.  Should generate error and return NULL.\n");
-    rc = pmSourceLocalSky(imgData, NULL, PS_STAT_SAMPLE_MEAN, 10.0, 20.0);
-    if (rc != NULL) {
-        printf("TEST ERROR: pmSourceLocalSky() returned a non-NULL pmSource.\n");
-        psFree(rc);
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceLocalSky with innerRadius<0.0.  Should generate error and return NULL.\n");
-    rc = pmSourceLocalSky(imgData, tmpPeak, PS_STAT_SAMPLE_MEAN, -10.0, 20.0);
-    if (rc != NULL) {
-        printf("TEST ERROR: pmSourceLocalSky() returned a non-NULL pmSource.\n");
-        psFree(rc);
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceLocalSky with innerRadius>outerRadius.  Should generate error and return NULL.\n");
-    rc = pmSourceLocalSky(imgData, tmpPeak, PS_STAT_SAMPLE_MEAN, 10.0, 5.0);
-    if (rc != NULL) {
-        printf("TEST ERROR: pmSourceLocalSky() returned a non-NULL pmSource.\n");
-        psFree(rc);
-        testStatus = false;
-    }
-    /* XXX: This is commented out since the EAM modification no longer generated NULLS for these tests.
-        printf("----------------------------------------------------------------------------------\n");
-        printf("Calling pmSourceLocalSky with subImage startRow < 0.  Should generate error and return NULL.\n");
-        tmpPeak->x = (psF32) (TST04_NUM_ROWS / 2);
-        tmpPeak->y = (psF32) (TST04_NUM_COLS / 2);
-        tmpPeak->y = 1;
-        rc = pmSourceLocalSky(imgData, tmpPeak, PS_STAT_SAMPLE_MEAN, 10.0, 20.0);
-        if (rc != NULL) {
-            printf("TEST ERROR: pmSourceLocalSky() returned a non-NULL pmSource.\n");
-            psFree(rc);
-            testStatus = false;
-        }
-        printf("----------------------------------------------------------------------------------\n");
-        printf("Calling pmSourceLocalSky with subImage endRow > numRows.  Should generate error and return NULL.\n");
-        tmpPeak->x = (psF32) (TST04_NUM_ROWS / 2);
-        tmpPeak->y = (psF32) (TST04_NUM_COLS / 2);
-        tmpPeak->y = TST04_NUM_ROWS;
-        rc = pmSourceLocalSky(imgData, tmpPeak, PS_STAT_SAMPLE_MEAN, 10.0, 20.0);
-        if (rc != NULL) {
-            printf("TEST ERROR: pmSourceLocalSky() returned a non-NULL pmSource.\n");
-            psFree(rc);
-            testStatus = false;
-        }
-        printf("----------------------------------------------------------------------------------\n");
-        printf("Calling pmSourceLocalSky with subImage startCol < 0.  Should generate error and return NULL.\n");
-        tmpPeak->x = (psF32) (TST04_NUM_ROWS / 2);
-        tmpPeak->y = (psF32) (TST04_NUM_COLS / 2);
-        tmpPeak->x = 1;
-        rc = pmSourceLocalSky(imgData, tmpPeak, PS_STAT_SAMPLE_MEAN, 10.0, 20.0);
-        if (rc != NULL) {
-            printf("TEST ERROR: pmSourceLocalSky() returned a non-NULL pmSource.\n");
-            psFree(rc);
-            testStatus = false;
-        }
-        printf("----------------------------------------------------------------------------------\n");
-        printf("Calling pmSourceLocalSky with subImage endCol > numCols.  Should generate error and return NULL.\n");
-        tmpPeak->x = (psF32) (TST04_NUM_ROWS / 2);
-        tmpPeak->y = (psF32) (TST04_NUM_COLS / 2);
-        tmpPeak->x = TST04_NUM_COLS;
-        rc = pmSourceLocalSky(imgData, tmpPeak, PS_STAT_SAMPLE_MEAN, (psF32) TST04_INNER_RADIUS, (psF32) TST04_OUTER_RADIUS);
-        if (rc != NULL) {
-            printf("TEST ERROR: pmSourceLocalSky() returned a non-NULL pmSource.\n");
-            psFree(rc);
-            testStatus = false;
-        }
-    */
+    pmSource *tmpSource = pmSourceAlloc();
+    tmpSource->pixels = imgData;
+    tmpSource->mask = imgMask;
+    tmpSource->peak = tmpPeak;
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceLocalSky with NULL tmpSource.  Should generate error and return FALSE.\n");
+    bool rc = pmSourceLocalSky(NULL, PS_STAT_SAMPLE_MEAN, 10.0);
+    if (rc != false) {
+        printf("TEST ERROR: pmSourceLocalSky() returned a non-FALSE pmSource.\n");
+        testStatus = false;
+    }
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceLocalSky with Radius<0.0.  Should generate error and return FALSE.\n");
+    rc = pmSourceLocalSky(tmpSource, PS_STAT_SAMPLE_MEAN, -10.0);
+    if (rc != false) {
+        printf("TEST ERROR: pmSourceLocalSky() returned a non-FALSE pmSource.\n");
+        testStatus = false;
+    }
 
     //
@@ -908,294 +858,57 @@
     tmpPeak->x = (psF32) (TST04_NUM_ROWS / 2);
     tmpPeak->y = (psF32) (TST04_NUM_COLS / 2);
-    rc = pmSourceLocalSky(imgData,
-                          tmpPeak,
-                          PS_STAT_SAMPLE_MEAN,
-                          (psF32) TST04_INNER_RADIUS,
-                          (psF32) TST04_OUTER_RADIUS);
-
-    if (rc == NULL) {
-        printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource.\n");
+    rc = pmSourceLocalSky(tmpSource, PS_STAT_SAMPLE_MEAN, 10.0);
+
+    if (rc == false) {
+        printf("TEST ERROR: pmSourceLocalSky() returned a FALSE pmSource.\n");
         testStatus = false;
     } else {
-        if (rc->peak == NULL) {
+        if (tmpSource->peak == NULL) {
             printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource->peak.\n");
             testStatus = false;
         } else {
-            if (rc->peak->x != tmpPeak->x) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->peak->x was %d, should have been %d.\n", rc->peak->x, tmpPeak->x);
+            if (tmpSource->peak->x != tmpPeak->x) {
+                printf("TEST ERROR: pmSourceLocalSky() pmSource->peak->x was %d, should have been %d.\n",
+                       tmpSource->peak->x, tmpPeak->x);
                 testStatus = false;
             }
 
-            if (rc->peak->y != tmpPeak->y) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->peak->y was %d, should have been %d.\n", rc->peak->y, tmpPeak->y);
+            if (tmpSource->peak->y != tmpPeak->y) {
+                printf("TEST ERROR: pmSourceLocalSky() pmSource->peak->y was %d, should have been %d.\n",
+                       tmpSource->peak->y, tmpPeak->y);
                 testStatus = false;
             }
 
-            if (rc->peak->counts != tmpPeak->counts) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->peak->counts was %f, should have been %f.\n", rc->peak->counts, tmpPeak->counts);
+            if (tmpSource->peak->counts != tmpPeak->counts) {
+                printf("TEST ERROR: pmSourceLocalSky() pmSource->peak->counts was %f, should have been %f.\n",
+                       tmpSource->peak->counts, tmpPeak->counts);
                 testStatus = false;
             }
 
-            if (rc->peak->class != tmpPeak->class) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->peak->class was %d, should have been %d.\n", rc->peak->class, tmpPeak->class);
+            if (tmpSource->peak->class != tmpPeak->class) {
+                printf("TEST ERROR: pmSourceLocalSky() pmSource->peak->class was %d, should have been %d.\n",
+                       tmpSource->peak->class, tmpPeak->class);
                 testStatus = false;
             }
         }
 
-        if (rc->pixels == NULL) {
-            printf("TEST ERROR: pmSourceLocalSky() pmSource->pixels was NULL.\n");
+        if (tmpSource->moments == NULL) {
+            printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource->moments.\n");
             testStatus = false;
         } else {
-            if (rc->pixels->numRows != (2 * TST04_OUTER_RADIUS)) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->pixels->numRows was %d, should have been %d.\n",
-                       rc->pixels->numRows, (2 * TST04_OUTER_RADIUS));
+            if (tmpSource->moments->Sky != TST04_SKY) {
+                printf("TEST ERROR: pmSourceLocalSky() pmSource->moments->Sky was %f, should have been %f.\n", tmpSource->moments->Sky, TST04_SKY);
                 testStatus = false;
             }
-
-            if (rc->pixels->numCols != (2 * TST04_OUTER_RADIUS)) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->pixels->numCols was %d, should have been %d.\n",
-                       rc->pixels->numCols, (2 * TST04_OUTER_RADIUS));
-                testStatus = false;
-            }
-
-            if (rc->pixels->col0 != (tmpPeak->x - TST04_OUTER_RADIUS)) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->pixels->col0 was %d, should have been %d.\n",
-                       rc->pixels->col0, (tmpPeak->x - TST04_OUTER_RADIUS));
-                testStatus = false;
-            }
-
-            if (rc->pixels->row0 != (tmpPeak->y - TST04_OUTER_RADIUS)) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->pixels->row0 was %d, should have been %d.\n",
-                       rc->pixels->row0, (tmpPeak->y - TST04_OUTER_RADIUS));
-                testStatus = false;
-            }
-
-            if (rc->pixels->type.type != PS_TYPE_F32) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->pixels->type was %d, should have been %d.\n",
-                       rc->pixels->type.type, PS_TYPE_F32);
-                testStatus = false;
-            }
-
-            // XXX: Test the rc->pixels-> row/col offsets.
-            // XXX: Test that the pixels corresponds to the source image pixels.
-        }
-
-        if (rc->mask == NULL) {
-            printf("TEST ERROR: pmSourceLocalSky() pmSource->mask was NULL.\n");
-            testStatus = false;
-        } else {
-            if (rc->mask->numRows != (2 * TST04_OUTER_RADIUS)) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->mask->numRows was %d, should have been %d.\n",
-                       rc->mask->numRows, (2 * TST04_OUTER_RADIUS));
-                testStatus = false;
-            }
-
-            if (rc->mask->numCols != (2 * TST04_OUTER_RADIUS)) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->mask->numCols was %d, should have been %d.\n",
-                       rc->mask->numCols, (2 * TST04_OUTER_RADIUS));
-                testStatus = false;
-            }
-
-            if (rc->mask->type.type != PS_TYPE_U8) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->mask->type was %d, should have been %d.\n",
-                       rc->mask->type.type, PS_TYPE_U8);
-                testStatus = false;
-            }
-
-            // XXX: Test the rc->mask-> row/col offsets.
-            // XXX: Test that the correct pixels were masked, not merely the number of masked pixels.
-            psS32 unmaskedPixels = 0;
-            psS32 maskedPixels = 0;
-
-            for (psS32 row = 0 ; row < rc->mask->numRows; row++) {
-                for (psS32 col = 0 ; col < rc->mask->numCols; col++) {
-                    if (rc->mask->data.U8[row][col] == 0) {
-                        unmaskedPixels++;
-                    } else {
-                        maskedPixels++;
-                    }
-                }
-            }
-            if (maskedPixels != PS_SQR(2*(TST04_INNER_RADIUS-1))) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->mask had %d masked pixels, should have been %d.\n",
-                       maskedPixels, PS_SQR(2*(TST04_INNER_RADIUS-1)));
-                testStatus = false;
-            }
-            if (unmaskedPixels != (PS_SQR(2*TST04_OUTER_RADIUS) - PS_SQR(2*(TST04_INNER_RADIUS-1)))) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->mask had %d masked pixels, should have been %d.\n",
-                       unmaskedPixels, (PS_SQR(2*TST04_OUTER_RADIUS) - PS_SQR(2*(TST04_INNER_RADIUS-1))));
-                testStatus = false;
-            }
-        }
-
-        if (rc->moments == NULL) {
-            printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource->moments.\n");
-            testStatus = false;
-        } else {
-            if (rc->moments->Sky != TST04_SKY) {
-                printf("TEST ERROR: pmSourceLocalSky() pmSource->moments->Sky was %f, should have been %f.\n", rc->moments->Sky, TST04_SKY);
-                testStatus = false;
-            }
-        }
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    psFree(rc);
-    psFree(imgData);
-    psFree(imgDataF64);
-    return(testStatus);
-}
-
-#define TST06_NUM_ROWS 100
-#define TST06_NUM_COLS 100
-#define TST06_SKY 20.0
-#define TST06_INNER_RADIUS 3
-#define TST06_OUTER_RADIUS 5
-/******************************************************************************
-test06(): We first test pmSourceLocalSky() with various NULL and unallowable
-input parameters.
- 
-XXX: Should we produce tests with boundary numbers for the inner/outer radius?
- 
-XXX: Call this with varying sizes for the image.
- *****************************************************************************/
-int test06( void )
-{
-    bool testStatus = true;
-    pmSource *tmpSource = NULL;
-    bool rc = false;
-    // Create the image used in this test.
-    psImage *imgData = psImageAlloc(TST06_NUM_COLS, TST06_NUM_ROWS, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < imgData->numRows; i++) {
-        for (psS32 j = 0 ; j < imgData->numCols; j++) {
-            imgData->data.F32[i][j] = TST06_SKY;
-        }
-    }
-    psImage *imgDataF64 = psImageAlloc(TST06_NUM_COLS, TST06_NUM_ROWS, PS_TYPE_F64);
-    for (psS32 i = 0 ; i < imgDataF64->numRows; i++) {
-        for (psS32 j = 0 ; j < imgDataF64->numCols; j++) {
-            imgDataF64->data.F64[i][j] = 0.0;
-        }
-    }
-
-    //
-    // Create a pmPeak with the center pixel set to the peak.
-    //
-    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST06_NUM_ROWS / 2),
-                                  (psF32) (TST06_NUM_COLS / 2),
-                                  200.0,
-                                  PM_PEAK_LONE);
-
-    tmpSource = pmSourceLocalSky(imgData,
-                                 tmpPeak,
-                                 PS_STAT_SAMPLE_MEAN,
-                                 (psF32) TST06_INNER_RADIUS,
-                                 (psF32) TST06_OUTER_RADIUS);
-    if (tmpSource == NULL) {
-        printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource.\n");
-        psFree(imgData);
-        psFree(imgDataF64);
-        psFree(tmpSource);
-        testStatus = false;
-        return(testStatus);
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceSetPixelsCircle with NULL pmSource.  Should generate error and return NULL.\n");
-    rc = pmSourceSetPixelsCircle(NULL, imgData, 10.0);
-    if (rc == true) {
-        printf("TEST ERROR: pmSourceSetPixelsCircle() returned TRUE.\n");
-        testStatus = false;
-    }
-    // XXX: test with pmSource->peaks NULL
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceSetPixelsCircle with NULL psImage.  Should generate error and return NULL.\n");
-    rc = pmSourceSetPixelsCircle(tmpSource, NULL, 10.0);
-    if (rc == true) {
-        printf("TEST ERROR: pmSourceSetPixelsCircle() returned TRUE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceSetPixelsCircle with wrong type psImage.  Should generate error and return NULL.\n");
-    rc = pmSourceSetPixelsCircle(tmpSource, imgDataF64, 10.0);
-    if (rc == true) {
-        printf("TEST ERROR: pmSourceSetPixelsCircle() returned TRUE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceSetPixelsCircle with radius < 0.0.  Should generate error and return NULL.\n");
-    rc = pmSourceSetPixelsCircle(tmpSource, imgData, -10.0);
-    if (rc == true) {
-        printf("TEST ERROR: pmSourceSetPixelsCircle() returned TRUE.\n");
-        testStatus = false;
-    }
-
-    /* XXX: Commented away since the EAM mods no longer produced errors.
-        printf("----------------------------------------------------------------------------------\n");
-        printf("Calling pmSourceSetPixelsCircle with subImage startCol < 0.  Should generate error and return NULL.\n");
-        tmpSource->peak->x = (psF32) (TST06_NUM_ROWS / 2);
-        tmpSource->peak->y = (psF32) (TST06_NUM_COLS / 2);
-        tmpSource->peak->x = 1;
-        rc = pmSourceSetPixelsCircle(tmpSource, imgData, 10.0);
-        if (rc == true) {
-            printf("TEST ERROR: pmSourceSetPixelsCircle() returned TRUE.\n");
-            testStatus = false;
-        }
-
-        printf("----------------------------------------------------------------------------------\n");
-        printf("Calling pmSourceSetPixelsCircle with subImage endCol > numCols.  Should generate error and return NULL.\n");
-        tmpSource->peak->x = (psF32) (TST06_NUM_ROWS / 2);
-        tmpSource->peak->y = (psF32) (TST06_NUM_COLS / 2);
-        tmpSource->peak->x = TST06_NUM_COLS;
-        rc = pmSourceSetPixelsCircle(tmpSource, imgData, 10.0);
-        if (rc == true) {
-            printf("TEST ERROR: pmSourceSetPixelsCircle() returned TRUE.\n");
-            testStatus = false;
-        }
-
-        printf("----------------------------------------------------------------------------------\n");
-        printf("Calling pmSourceSetPixelsCircle with subImage startRow < 0.  Should generate error and return NULL.\n");
-        tmpSource->peak->x = (psF32) (TST06_NUM_ROWS / 2);
-        tmpSource->peak->y = (psF32) (TST06_NUM_COLS / 2);
-        tmpSource->peak->y = 1;
-        rc = pmSourceSetPixelsCircle(tmpSource, imgData, 10.0);
-        if (rc == true) {
-            printf("TEST ERROR: pmSourceSetPixelsCircle() returned TRUE.\n");
-            testStatus = false;
-        }
-
-        printf("----------------------------------------------------------------------------------\n");
-        printf("Calling pmSourceSetPixelsCircle with subImage endRow > numRows.  Should generate error and return NULL.\n");
-        tmpSource->peak->x = (psF32) (TST06_NUM_ROWS / 2);
-        tmpSource->peak->y = (psF32) (TST06_NUM_COLS / 2);
-        tmpSource->peak->y = TST06_NUM_ROWS;
-        rc = pmSourceSetPixelsCircle(tmpSource, imgData, 10.0);
-        if (rc == true) {
-            printf("TEST ERROR: pmSourceSetPixelsCircle() returned TRUE.\n");
-            testStatus = false;
-        }
-    */
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceSetPixelsCircle with valid data.\n");
-    tmpSource->peak->x = (psF32) (TST06_NUM_ROWS / 2);
-    tmpSource->peak->y = (psF32) (TST06_NUM_COLS / 2);
-    rc = pmSourceSetPixelsCircle(tmpSource, imgData, 10.0);
-
-    if (rc == false) {
-        printf("TEST ERROR: pmSourceSetPixelsCircle() returned FALSE.\n");
-        testStatus = false;
-    } else {
-        // XXX: Test correctness of the various psSetPixelsCircle members.
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
+        }
+    }
+
+    printf("----------------------------------------------------------------------------------\n");
+    psFree(tmpSource);
     //    psFree(imgData);
     //    psFree(imgDataF64);
-    psFree(tmpSource);
+    //    psFree(imgMask);
+    //    psFree(imgMaskS8);
     return(testStatus);
-
 }
 
@@ -1218,713 +931,48 @@
 {
     bool testStatus = true;
-    pmSource *tmpSource = NULL;
-    pmSource *rc = NULL;
-    // Create the image used in this test.
-    psImage *imgData = psImageAlloc(TST05_NUM_COLS, TST05_NUM_ROWS, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < imgData->numRows; i++) {
-        for (psS32 j = 0 ; j < imgData->numCols; j++) {
-            imgData->data.F32[i][j] = TST05_SKY;
-        }
-    }
-
-    //
-    // Create a pmPeak with the center pixel set to the peak.
-    //
-    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST05_NUM_ROWS / 2),
-                                  (psF32) (TST05_NUM_COLS / 2),
-                                  200.0,
-                                  PM_PEAK_LONE);
-
-    tmpSource = pmSourceLocalSky(imgData,
-                                 tmpPeak,
-                                 PS_STAT_SAMPLE_MEAN,
-                                 (psF32) TST05_INNER_RADIUS,
-                                 (psF32) TST05_OUTER_RADIUS);
-    if (tmpSource == NULL) {
-        printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource.\n");
-        psFree(tmpSource);
-        testStatus = false;
-        return(testStatus);
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceMoments with NULL pmSource.  Should generate error and return NULL.\n");
-    rc = pmSourceMoments(NULL, 10.0);
-    if (rc != NULL) {
-        printf("TEST ERROR: pmSourceMoments() returned a non-NULL pmSource.\n");
-        testStatus = false;
-    }
-    // XXX: test with pmSource->peaks NULL
-    // XXX: test with pmSource->pixels NULL
-    // XXX: test with pmSource->mask NULL
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceMoments with radius < 0.0.  Should generate error and return NULL.\n");
-    rc = pmSourceMoments(tmpSource, -10.0);
-    if (rc != NULL) {
-        printf("TEST ERROR: pmSourceMoments() returned a non-NULL pmSource.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    psFree(tmpSource);
-    return(testStatus);
-
-}
-
-/******************************************************************************
-test07(): We first test the various psMinLM_... routines with various NULL and
-unallowable input parameters.
- 
-XXX: We don't verify the numbers.  Must do this.
- *****************************************************************************/
-int test07( void )
-{
-    bool testStatus = true;
-    psF32 rc;
-    psVector *deriv = psVectorAlloc(7, PS_TYPE_F32);
-    psVector *params = psVectorAlloc(7, PS_TYPE_F32);
-    psVector *x = psVectorAlloc(2, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < 7 ; i++) {
-        deriv->data.F32[i] = 1.0;
-        params->data.F32[i] = 1.0;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_Gauss2D with NULL deriv vector.  Should not generate error.\n");
-    rc = pmMinLM_Gauss2D(NULL, params, x);
-    if (isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_Gauss2D() returned a NAN psF32.\n");
-        testStatus = false;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_Gauss2D with NULL params vector.  Should generate error and return NAN.\n");
-    rc = pmMinLM_Gauss2D(deriv, NULL, x);
-    if (!isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_Gauss2D() returned a non-NAN psF32 (%f).\n", rc);
-        testStatus = false;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_Gauss2D with NULL x vector.  Should generate error and return NAN.\n");
-    rc = pmMinLM_Gauss2D(deriv, params, NULL);
-    if (!isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_Gauss2D() returned a non-NAN psF32 (%f).\n", rc);
-        testStatus = false;
-    }
-    psFree(deriv);
-    psFree(params);
-
-    deriv = psVectorAlloc(7, PS_TYPE_F32);
-    params = psVectorAlloc(7, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < 7 ; i++) {
-        deriv->data.F32[i] = 1.0;
-        params->data.F32[i] = 1.0;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_PsuedoGauss2D with NULL deriv vector.  Should not generate error.\n");
-    rc = pmMinLM_PsuedoGauss2D(NULL, params, x);
-    if (isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_PsuedoGauss2D() returned a NAN psF32.\n");
-        testStatus = false;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_PsuedoGauss2D with NULL params vector.  Should generate error and return NAN.\n");
-    rc = pmMinLM_PsuedoGauss2D(deriv, NULL, x);
-    if (!isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_PsuedoGauss2D() returned a non-NAN psF32 (%f).\n", rc);
-        testStatus = false;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_PsuedoGauss2D with NULL x vector.  Should generate error and return NAN.\n");
-    rc = pmMinLM_PsuedoGauss2D(deriv, params, NULL);
-    if (!isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_PsuedoGauss2D() returned a non-NAN psF32 (%f).\n", rc);
-        testStatus = false;
-    }
-    psFree(deriv);
-    psFree(params);
-
-
-    deriv = psVectorAlloc(9, PS_TYPE_F32);
-    params = psVectorAlloc(9, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < 9 ; i++) {
-        deriv->data.F32[i] = 1.0;
-        params->data.F32[i] = 1.0;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_Wauss2D with NULL deriv vector.  Should not generate error.\n");
-    rc = pmMinLM_Wauss2D(NULL, params, x);
-    if (isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_Wauss2D() returned a NAN psF32.\n");
-        testStatus = false;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_Wauss2D with NULL params vector.  Should generate error and return NAN.\n");
-    rc = pmMinLM_Wauss2D(deriv, NULL, x);
-    if (!isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_Wauss2D() returned a non-NAN psF32 (%f).\n", rc);
-        testStatus = false;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_Wauss2D with NULL x vector.  Should generate error and return NAN.\n");
-    rc = pmMinLM_Wauss2D(deriv, params, NULL);
-    if (!isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_Wauss2D() returned a non-NAN psF32 (%f).\n", rc);
-        testStatus = false;
-    }
-    psFree(deriv);
-    psFree(params);
-
-    deriv = psVectorAlloc(11, PS_TYPE_F32);
-    params = psVectorAlloc(11, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < 11 ; i++) {
-        deriv->data.F32[i] = 1.0;
-        params->data.F32[i] = 1.0;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_TwistGauss2D with NULL deriv vector.  Should not generate error.\n");
-    rc = pmMinLM_TwistGauss2D(NULL, params, x);
-    if (isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_TwistGauss2D() returned a NAN psF32.\n");
-        testStatus = false;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_TwistGauss2D with NULL params vector.  Should generate error and return NAN.\n");
-    rc = pmMinLM_TwistGauss2D(deriv, NULL, x);
-    if (!isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_TwistGauss2D() returned a non-NAN psF32 (%f).\n", rc);
-        testStatus = false;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_TwistGauss2D with NULL x vector.  Should generate error and return NAN.\n");
-    rc = pmMinLM_TwistGauss2D(deriv, params, NULL);
-    if (!isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_TwistGauss2D() returned a non-NAN psF32 (%f).\n", rc);
-        testStatus = false;
-    }
-    psFree(deriv);
-    psFree(params);
-
-    deriv = psVectorAlloc(8, PS_TYPE_F32);
-    params = psVectorAlloc(8, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < 8 ; i++) {
-        deriv->data.F32[i] = 1.0;
-        params->data.F32[i] = 1.0;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_Sersic with NULL deriv vector.  Should not generate error.\n");
-    rc = pmMinLM_Sersic(NULL, params, x);
-    if (isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_Sersic() returned a NAN psF32.\n");
-        testStatus = false;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_Sersic with NULL params vector.  Should generate error and return NAN.\n");
-    rc = pmMinLM_Sersic(deriv, NULL, x);
-    if (!isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_Sersic() returned a non-NAN psF32 (%f).\n", rc);
-        testStatus = false;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_Sersic with NULL x vector.  Should generate error and return NAN.\n");
-    rc = pmMinLM_Sersic(deriv, params, NULL);
-    if (!isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_Sersic() returned a non-NAN psF32 (%f).\n", rc);
-        testStatus = false;
-    }
-    psFree(deriv);
-    psFree(params);
-
-    deriv = psVectorAlloc(12, PS_TYPE_F32);
-    params = psVectorAlloc(12, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < 12 ; i++) {
-        deriv->data.F32[i] = 1.0;
-        params->data.F32[i] = 1.0;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_SersicCore with NULL deriv vector.  Should not generate error.\n");
-    rc = pmMinLM_SersicCore(NULL, params, x);
-    if (isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_SersicCore() returned a NAN psF32.\n");
-        testStatus = false;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_SersicCore with NULL params vector.  Should generate error and return NAN.\n");
-    rc = pmMinLM_SersicCore(deriv, NULL, x);
-    if (!isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_SersicCore() returned a non-NAN psF32 (%f).\n", rc);
-        testStatus = false;
-    }
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmMinLM_SersicCore with NULL x vector.  Should generate error and return NAN.\n");
-    rc = pmMinLM_SersicCore(deriv, params, NULL);
-    if (!isnan(rc)) {
-        printf("TEST ERROR: pmMinLM_SersicCore() returned a non-NAN psF32 (%f).\n", rc);
-        testStatus = false;
-    }
-
-    psFree(deriv);
-    psFree(params);
-    psFree(x);
-    return(testStatus);
-}
-
-/******************************************************************************
-test08(): We first test pmSourceModelGuess() with various NULL and unallowable
-input parameters.
- 
-XXX: We don't verify the numbers.
- *****************************************************************************/
-int test08( void )
-{
-    bool testStatus = true;
     psImage *imgData = psImageAlloc(TST04_NUM_COLS, TST04_NUM_ROWS, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < imgData->numRows; i++) {
-        for (psS32 j = 0 ; j < imgData->numCols; j++) {
-            imgData->data.F32[i][j] = TST04_SKY;
-        }
-    }
-    pmSource *mySrc = NULL;
-    bool rc = false;
+    psImageInit(imgData, TST04_SKY);
+    psImage *imgMask = psImageAlloc(TST04_NUM_COLS, TST04_NUM_ROWS, PS_TYPE_U8);
+    psImageInit(imgMask, 0);
     pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST04_NUM_ROWS / 2),
                                   (psF32) (TST04_NUM_COLS / 2),
                                   200.0,
                                   PM_PEAK_LONE);
-
-    printf("Calling pmSourceLocalSky with valid data.\n");
-    tmpPeak->x = (psF32) (TST04_NUM_ROWS / 2);
-    tmpPeak->y = (psF32) (TST04_NUM_COLS / 2);
-    mySrc = pmSourceLocalSky(imgData,
-                             tmpPeak,
-                             PS_STAT_SAMPLE_MEAN,
-                             (psF32) TST04_INNER_RADIUS,
-                             (psF32) TST04_OUTER_RADIUS);
-
-    if (mySrc == NULL) {
-        printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceModelGuess with NULL pmSource.  Should generate error, return FALSE.\n");
-    rc = pmSourceModelGuess(NULL, imgData, PS_MODEL_GAUSS);
-    if (rc == true) {
-        printf("TEST ERROR: pmSourceModelGuess() returned TRUE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceModelGuess with NULL psImage.  Should generate error, return FALSE.\n");
-    rc = pmSourceModelGuess(mySrc, NULL, PS_MODEL_GAUSS);
-    if (rc == true) {
-        printf("TEST ERROR: pmSourceModelGuess() returned TRUE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceModelGuess with bad model type.  Should generate error, return FALSE.\n");
-    rc = pmSourceModelGuess(mySrc, imgData, PS_MODEL_UNDEFINED);
-    if (rc == true) {
-        printf("TEST ERROR: pmSourceModelGuess() returned TRUE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceModelGuess with PS_MODEL_GAUSS\n");
-    rc = pmSourceModelGuess(mySrc, imgData, PS_MODEL_GAUSS);
-    if (rc != true) {
-        printf("TEST ERROR: pmSourceModelGuess() returned FALSE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceModelGuess with PS_MODEL_PGAUSS\n");
-    rc = pmSourceModelGuess(mySrc, imgData, PS_MODEL_PGAUSS);
-    if (rc != true) {
-        printf("TEST ERROR: pmSourceModelGuess() returned FALSE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceModelGuess with PS_MODEL_TWIST_GAUSS\n");
-    rc = pmSourceModelGuess(mySrc, imgData, PS_MODEL_TWIST_GAUSS);
-    if (rc != true) {
-        printf("TEST ERROR: pmSourceModelGuess() returned FALSE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceModelGuess with PS_MODEL_WAUSS\n");
-    rc = pmSourceModelGuess(mySrc, imgData, PS_MODEL_WAUSS);
-    if (rc != true) {
-        printf("TEST ERROR: pmSourceModelGuess() returned FALSE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceModelGuess with PS_MODEL_SERSIC\n");
-    rc = pmSourceModelGuess(mySrc, imgData, PS_MODEL_SERSIC);
-    if (rc != true) {
-        printf("TEST ERROR: pmSourceModelGuess() returned FALSE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceModelGuess with PS_MODEL_SERSIC_CORE\n");
-    rc = pmSourceModelGuess(mySrc, imgData, PS_MODEL_SERSIC_CORE);
-    if (rc != true) {
-        printf("TEST ERROR: pmSourceModelGuess() returned FALSE.\n");
-        testStatus = false;
-    }
-
-    psFree(mySrc);
-    //    psFree(tmpPeak);
-    psFree(imgData);
+    pmSource *tmpSource = pmSourceAlloc();
+    tmpSource->pixels = imgData;
+    tmpSource->mask = imgMask;
+    tmpSource->peak = tmpPeak;
+    psBool rc = pmSourceLocalSky(tmpSource, PS_STAT_SAMPLE_MEAN, 10.0);
+
+    if (rc == false) {
+        printf("TEST ERROR: pmSourceLocalSky() returned a FALSE pmSource.\n");
+        testStatus = false;
+    }
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceMoments with NULL pmSource.  Should generate error and return FALSE.\n");
+    rc = pmSourceMoments(NULL, 10.0);
+    if (rc != false) {
+        printf("TEST ERROR: pmSourceMoments() returned TRUE.\n");
+        testStatus = false;
+    }
+    // XXX: test with pmSource->peaks NULL
+    // XXX: test with pmSource->pixels NULL
+    // XXX: test with pmSource->mask NULL
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceMoments with radius < 0.0.  Should generate error and return FALSE.\n");
+    rc = pmSourceMoments(tmpSource, -10.0);
+    if (rc != false) {
+        printf("TEST ERROR: pmSourceMoments() returned TRUE.\n");
+        testStatus = false;
+    }
+
+    printf("----------------------------------------------------------------------------------\n");
+    psFree(tmpSource);
     return(testStatus);
+
 }
 
-
-#define TST09_NUM_ROWS 70
-#define TST09_NUM_COLS 70
-#define TST09_SKY 5.0
-#define TST09_INNER_RADIUS 3
-#define TST09_OUTER_RADIUS 10
-#define LEVEL (TST09_SKY + 10.0)
-/******************************************************************************
-test09(): We first test pmSourceContour() with various NULL and unallowable
-input parameters.
- 
-XXX: We don't verify the numbers.
- *****************************************************************************/
-int test09( void )
-{
-    bool testStatus = true;
-    psImage *imgData = psImageAlloc(TST09_NUM_COLS, TST09_NUM_ROWS, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < imgData->numRows; i++) {
-        for (psS32 j = 0 ; j < imgData->numCols; j++) {
-            imgData->data.F32[i][j] = TST09_SKY;
-        }
-    }
-    pmSource *mySrc = NULL;
-    psArray *rc = NULL;
-
-    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST09_NUM_ROWS / 2),
-                                  (psF32) (TST09_NUM_COLS / 2),
-                                  200.0,
-                                  PM_PEAK_LONE);
-
-    printf("Calling pmSourceLocalSky with valid data.\n");
-    tmpPeak->x = (psF32) (TST09_NUM_ROWS / 2);
-    tmpPeak->y = (psF32) (TST09_NUM_COLS / 2);
-    mySrc = pmSourceLocalSky(imgData,
-                             tmpPeak,
-                             PS_STAT_SAMPLE_MEAN,
-                             (psF32) TST09_INNER_RADIUS,
-                             (psF32) TST09_OUTER_RADIUS);
-
-    if (mySrc == NULL) {
-        printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource.\n");
-        testStatus = false;
-    }
-
-    bool rcBool = pmSourceModelGuess(mySrc, imgData, PS_MODEL_GAUSS);
-    if (rcBool != true) {
-        printf("TEST ERROR: pmSourceModelGuess() returned FALSE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceContour with NULL pmSource .  Should generate error, return NULL.\n");
-    rc = pmSourceContour(NULL, imgData, LEVEL, PS_CONTOUR_CRUDE);
-    if (rc != NULL) {
-        printf("TEST ERROR: pmSourceContour() returned non-NULL.\n");
-        testStatus = false;
-        psFree(rc);
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceContour with NULL psImage .  Should generate error, return NULL.\n");
-    rc = pmSourceContour(mySrc, NULL, LEVEL, PS_CONTOUR_CRUDE);
-    if (rc != NULL) {
-        printf("TEST ERROR: pmSourceContour() returned non-NULL.\n");
-        testStatus = false;
-        psFree(rc);
-    }
-
-    //
-    // XXX: pmSourceContour() has a problem with contour tops/bottoms.
-    // Must correct this.
-    //
-    if (0) {
-        printf("----------------------------------------------------------------------------------\n");
-        printf("Calling pmSourceContour with acceptable data.\n");
-        printf("NOTE: must figure out the parameters for this test to be meaningful.\n");
-        mySrc->modelPSF->params->data.F32[0] = TST09_SKY;
-        mySrc->modelPSF->params->data.F32[1] = 15.0;
-        mySrc->modelPSF->params->data.F32[2] = (psF32) (TST09_NUM_ROWS / 2);
-        mySrc->modelPSF->params->data.F32[3] = (psF32) (TST09_NUM_COLS / 2);
-        mySrc->modelPSF->params->data.F32[4] = 2.0;
-        mySrc->modelPSF->params->data.F32[5] = 2.0;
-        mySrc->modelPSF->params->data.F32[6] = 2.0;
-        rc = pmSourceContour(mySrc, imgData, LEVEL, PS_CONTOUR_CRUDE);
-        if (rc == NULL) {
-            printf("TEST ERROR: pmSourceContour() returned NULL.\n");
-            testStatus = false;
-        } else {
-            psFree(rc);
-        }
-    }
-
-    psFree(mySrc);
-    psFree(imgData);
-    // XXX: This psFree() causes an error.  Why?
-    //psFree(tmpPeak);
-    return(testStatus);
-}
-
-#define TST15_NUM_ROWS 100
-#define TST15_NUM_COLS 100
-#define TST15_SKY 10.0
-#define TST15_INNER_RADIUS 3
-#define TST15_OUTER_RADIUS 5
-/******************************************************************************
-test15(): We first test pmSourceAddModel() with various NULL and unallowable
-input parameters.
- 
-XXX: We don't verify the numbers.
- *****************************************************************************/
-int test15( void )
-{
-    bool testStatus = true;
-    psImage *imgData = psImageAlloc(TST15_NUM_COLS, TST15_NUM_ROWS, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < imgData->numRows; i++) {
-        for (psS32 j = 0 ; j < imgData->numCols; j++) {
-            imgData->data.F32[i][j] = TST15_SKY;
-        }
-    }
-    pmSource *mySrc = NULL;
-    psBool rc = false;
-
-    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST15_NUM_ROWS / 2),
-                                  (psF32) (TST15_NUM_COLS / 2),
-                                  200.0,
-                                  PM_PEAK_LONE);
-
-    printf("Calling pmSourceLocalSky with valid data.\n");
-    tmpPeak->x = (psF32) (TST15_NUM_ROWS / 2);
-    tmpPeak->y = (psF32) (TST15_NUM_COLS / 2);
-    mySrc = pmSourceLocalSky(imgData,
-                             tmpPeak,
-                             PS_STAT_SAMPLE_MEAN,
-                             (psF32) TST15_INNER_RADIUS,
-                             (psF32) TST15_OUTER_RADIUS);
-
-    if (mySrc == NULL) {
-        printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource.\n");
-        testStatus = false;
-    }
-
-    mySrc->modelPSF = pmModelAlloc(PS_MODEL_GAUSS);
-    mySrc->modelPSF->params->data.F32[0] = 5.0;
-    mySrc->modelPSF->params->data.F32[1] = 70.0;
-    mySrc->modelPSF->params->data.F32[2] = (psF32) (TST15_NUM_ROWS / 2);
-    mySrc->modelPSF->params->data.F32[3] = (psF32) (TST15_NUM_COLS / 2);
-    mySrc->modelPSF->params->data.F32[4] = 1.0;
-    mySrc->modelPSF->params->data.F32[5] = 1.0;
-    mySrc->modelPSF->params->data.F32[6] = 2.0;
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceAddModel with NULL psImage.  Should generate error, return FALSE.\n");
-    rc = pmSourceAddModel(NULL, mySrc, true);
-    if (rc == true) {
-        printf("TEST ERROR: pmSourceAddModel() returned TRUE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceAddModel with NULL psSrc.  Should generate error, return FALSE.\n");
-    rc = pmSourceAddModel(imgData, NULL, true);
-    if (rc == true) {
-        printf("TEST ERROR: pmSourceAddModel() returned TRUE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceAddModel with acceptable data.\n");
-    rc = pmSourceAddModel(imgData, mySrc, true);
-    if (rc != true) {
-        printf("TEST ERROR: pmSourceAddModel() returned FALSE.\n");
-        testStatus = false;
-    }
-
-    psFree(mySrc);
-    psFree(imgData);
-    return(testStatus);
-}
-
-#define TST16_NUM_ROWS 100
-#define TST16_NUM_COLS 100
-#define TST16_SKY 10.0
-#define TST16_INNER_RADIUS 3
-#define TST16_OUTER_RADIUS 5
-/******************************************************************************
-test16(): We first test pmSourceSubModel() with various NULL and unallowable
-input parameters.
- 
-XXX: We don't verify the numbers.
- *****************************************************************************/
-int test16( void )
-{
-    bool testStatus = true;
-    psImage *imgData = psImageAlloc(TST16_NUM_COLS, TST16_NUM_ROWS, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < imgData->numRows; i++) {
-        for (psS32 j = 0 ; j < imgData->numCols; j++) {
-            imgData->data.F32[i][j] = TST16_SKY;
-        }
-    }
-    pmSource *mySrc = NULL;
-    psBool rc = false;
-
-    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST16_NUM_ROWS / 2),
-                                  (psF32) (TST16_NUM_COLS / 2),
-                                  200.0,
-                                  PM_PEAK_LONE);
-
-    printf("Calling pmSourceLocalSky with valid data.\n");
-    tmpPeak->x = (psF32) (TST16_NUM_ROWS / 2);
-    tmpPeak->y = (psF32) (TST16_NUM_COLS / 2);
-    mySrc = pmSourceLocalSky(imgData,
-                             tmpPeak,
-                             PS_STAT_SAMPLE_MEAN,
-                             (psF32) TST16_INNER_RADIUS,
-                             (psF32) TST16_OUTER_RADIUS);
-
-    if (mySrc == NULL) {
-        printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource.\n");
-        testStatus = false;
-    }
-
-    mySrc->modelPSF = pmModelAlloc(PS_MODEL_GAUSS);
-    mySrc->modelPSF->params->data.F32[0] = 5.0;
-    mySrc->modelPSF->params->data.F32[1] = 70.0;
-    mySrc->modelPSF->params->data.F32[2] = (psF32) (TST16_NUM_ROWS / 2);
-    mySrc->modelPSF->params->data.F32[3] = (psF32) (TST16_NUM_COLS / 2);
-    mySrc->modelPSF->params->data.F32[4] = 1.0;
-    mySrc->modelPSF->params->data.F32[5] = 1.0;
-    mySrc->modelPSF->params->data.F32[6] = 2.0;
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceSubModel with NULL psImage.  Should generate error, return FALSE.\n");
-    rc = pmSourceSubModel(NULL, mySrc, true);
-    if (rc == true) {
-        printf("TEST ERROR: pmSourceSubModel() returned TRUE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceSubModel with NULL psSrc.  Should generate error, return FALSE.\n");
-    rc = pmSourceSubModel(imgData, NULL, true);
-    if (rc == true) {
-        printf("TEST ERROR: pmSourceSubModel() returned TRUE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceSubModel with acceptable data.\n");
-    rc = pmSourceSubModel(imgData, mySrc, true);
-    if (rc != true) {
-        printf("TEST ERROR: pmSourceSubModel() returned FALSE.\n");
-        testStatus = false;
-    }
-
-    psFree(mySrc);
-    psFree(imgData);
-    return(testStatus);
-}
-
-#define TST20_NUM_ROWS 100
-#define TST20_NUM_COLS 100
-#define TST20_SKY 10.0
-#define TST20_INNER_RADIUS 3
-#define TST20_OUTER_RADIUS 5
-/******************************************************************************
-test20(): We first test pmSourceSubModel() with various NULL and unallowable
-input parameters.
- 
-XXX: We don't verify the numbers.
- *****************************************************************************/
-int test20( void )
-{
-    bool testStatus = true;
-    psImage *imgData = psImageAlloc(TST20_NUM_COLS, TST20_NUM_ROWS, PS_TYPE_F32);
-    for (psS32 i = 0 ; i < imgData->numRows; i++) {
-        for (psS32 j = 0 ; j < imgData->numCols; j++) {
-            imgData->data.F32[i][j] = TST20_SKY;
-        }
-    }
-    pmSource *mySrc = NULL;
-    psBool rc = false;
-
-    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST20_NUM_ROWS / 2),
-                                  (psF32) (TST20_NUM_COLS / 2),
-                                  200.0,
-                                  PM_PEAK_LONE);
-
-    printf("Calling pmSourceLocalSky with valid data.\n");
-    tmpPeak->x = (psF32) (TST20_NUM_ROWS / 2);
-    tmpPeak->y = (psF32) (TST20_NUM_COLS / 2);
-    mySrc = pmSourceLocalSky(imgData,
-                             tmpPeak,
-                             PS_STAT_SAMPLE_MEAN,
-                             (psF32) TST20_INNER_RADIUS,
-                             (psF32) TST20_OUTER_RADIUS);
-
-    if (mySrc == NULL) {
-        printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource.\n");
-        testStatus = false;
-    }
-
-    mySrc->modelPSF = pmModelAlloc(PS_MODEL_GAUSS);
-
-
-    mySrc->modelPSF->params->data.F32[0] = 5.0;
-    mySrc->modelPSF->params->data.F32[1] = 70.0;
-    mySrc->modelPSF->params->data.F32[2] = (psF32) (TST20_NUM_ROWS / 2);
-    mySrc->modelPSF->params->data.F32[3] = (psF32) (TST20_NUM_COLS / 2);
-    mySrc->modelPSF->params->data.F32[4] = 1.0;
-    mySrc->modelPSF->params->data.F32[5] = 1.0;
-    mySrc->modelPSF->params->data.F32[6] = 2.0;
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceFitModel with NULL psImage.  Should generate error, return FALSE.\n");
-    rc = pmSourceFitModel(mySrc, NULL);
-    if (rc == true) {
-        printf("TEST ERROR: pmSourceFitModel() returned TRUE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceFitModel with NULL pmSource.  Should generate error, return FALSE.\n");
-    rc = pmSourceFitModel(NULL, imgData);
-    if (rc == true) {
-        printf("TEST ERROR: pmSourceFitModel() returned TRUE.\n");
-        testStatus = false;
-    }
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling pmSourceFitModel with acceptable data.\n");
-    rc = pmSourceFitModel(mySrc, imgData);
-    printf("pmSourceFitModel returned %d\n", rc);
-
-    // XXX: Memory leaks are not being tested
-    psVector *junk = psVectorAlloc(10, PS_TYPE_F32);
-    junk->data.F32[0] = 0.0;
-
-    psFree(mySrc);
-    psFree(imgData);
-    return(testStatus);
-}
-
-
 // this code will
 
