Index: branches/eam_branches/20091201/psphot/src/psphotFindDetections.c
===================================================================
--- branches/eam_branches/20091201/psphot/src/psphotFindDetections.c	(revision 26595)
+++ branches/eam_branches/20091201/psphot/src/psphotFindDetections.c	(revision 26596)
@@ -53,5 +53,8 @@
     psMetadataAddF32  (recipe, PS_LIST_TAIL, "PEAK_THRESHOLD", PS_META_REPLACE, "Peak Detection Threshold", threshold);
     if (!detections->peaks) {
-        // No peaks found
+	// we only get a NULL peaks array due to a programming or config error. 
+	// this will result in a failure.
+	psFree (detections);
+	psError (PSPHOT_ERR_CONFIG, false, "failed on peak search");
         return NULL;
     }
Index: branches/eam_branches/20091201/psphot/src/psphotFindPeaks.c
===================================================================
--- branches/eam_branches/20091201/psphot/src/psphotFindPeaks.c	(revision 26595)
+++ branches/eam_branches/20091201/psphot/src/psphotFindPeaks.c	(revision 26596)
@@ -13,10 +13,15 @@
     psArray *peaks = pmPeaksInImage (significance, threshold);
     if (peaks == NULL) {
-	// XXX should we be sending back an empty array instead of NULL?
-        // XXX this may also be due to a programming or config error
+	// we only get a NULL peaks array due to a programming or config error. 
+	// this will result in a failure.
+        psError(PSPHOT_ERR_DATA, false, "no peaks found in this image");
+        return NULL;
+    }
+
+    if (peaks->n == 0) {
         // XXX do we need to set something in the readout->analysis to indicate that
         // we tried and failed to find peaks (something in the header data)
-        psError(PSPHOT_ERR_DATA, false, "no peaks found in this image");
-        return false;
+	psLogMsg ("psphot", PS_LOG_INFO, "no peaks found in this image");
+	return peaks;
     }
 
Index: branches/eam_branches/20091201/psphot/src/psphotModelTest.c
===================================================================
--- branches/eam_branches/20091201/psphot/src/psphotModelTest.c	(revision 26595)
+++ branches/eam_branches/20091201/psphot/src/psphotModelTest.c	(revision 26596)
@@ -139,5 +139,5 @@
 
     // get the source moments
-    status = pmSourceMoments (source, mRADIUS, 0.0, 1.0);
+    status = pmSourceMoments (source, mRADIUS, 0.0, 1.0, maskVal);
     if (!status) psAbort("psSourceMoments error");
     source->peak->value = source->moments->Peak;
Index: branches/eam_branches/20091201/psphot/src/psphotMomentsStudy.c
===================================================================
--- branches/eam_branches/20091201/psphot/src/psphotMomentsStudy.c	(revision 26595)
+++ branches/eam_branches/20091201/psphot/src/psphotMomentsStudy.c	(revision 26596)
@@ -148,5 +148,5 @@
       pmSourceAdd(source, PM_MODEL_OP_FUNC, 0); 
 
-      pmSourceMoments (source, 32.0, sigWindow, 0.0);
+      pmSourceMoments (source, 32.0, sigWindow, 0.0, 0xffff);
       // fprintf (stderr, "sigOut : %f\n", sqrt(source->moments->Mxx));
 
Index: branches/eam_branches/20091201/psphot/src/psphotPSFConvModel.c
===================================================================
--- branches/eam_branches/20091201/psphot/src/psphotPSFConvModel.c	(revision 26595)
+++ branches/eam_branches/20091201/psphot/src/psphotPSFConvModel.c	(revision 26596)
@@ -39,5 +39,5 @@
     // adjust the pixels based on the footprint
     float radius = psphotSetRadiusEXT (readout, source, markVal);
-    if (!pmSourceMoments (source, radius, 0.0, 0.0)) return false;
+    if (!pmSourceMoments (source, radius, 0.0, 0.0, maskVal)) return false;
 
     // XXX test : modify the Io, SXX, SYY terms based on the psf SXX, SYY terms:
Index: branches/eam_branches/20091201/psphot/src/psphotReadout.c
===================================================================
--- branches/eam_branches/20091201/psphot/src/psphotReadout.c	(revision 26595)
+++ branches/eam_branches/20091201/psphot/src/psphotReadout.c	(revision 26596)
@@ -76,4 +76,9 @@
     pmDetections *detections = psphotFindDetections (NULL, readout, recipe);
     if (!detections) {
+	// this only happens if we had an error in psphotFindDetections
+        psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
+        return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL);
+    }
+    if (!detections->peaks->n) {
         psLogMsg ("psphot", 3, "unable to find detections in this image");
         return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL);
Index: branches/eam_branches/20091201/psphot/src/psphotReadoutMinimal.c
===================================================================
--- branches/eam_branches/20091201/psphot/src/psphotReadoutMinimal.c	(revision 26595)
+++ branches/eam_branches/20091201/psphot/src/psphotReadoutMinimal.c	(revision 26596)
@@ -51,4 +51,8 @@
     detections = psphotFindDetections(detections, readout, recipe);
     if (!detections) {
+        psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
+        return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL);
+    }
+    if (!detections->peaks->n) {
         psLogMsg ("psphot", 3, "unable to find detections in this image");
         return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL);
Index: branches/eam_branches/20091201/psphot/src/psphotSourceFits.c
===================================================================
--- branches/eam_branches/20091201/psphot/src/psphotSourceFits.c	(revision 26595)
+++ branches/eam_branches/20091201/psphot/src/psphotSourceFits.c	(revision 26596)
@@ -235,5 +235,5 @@
     // at this stage, skip Gaussian windowing, and do not clip pixels by S/N
     // this uses the footprint to judge both radius and aperture?
-    if (!pmSourceMoments (source, radius, 0.0, 0.0)) return false;
+    if (!pmSourceMoments (source, radius, 0.0, 0.0, maskVal)) return false;
 
     psTrace ("psphot", 5, "trying blob...\n");
Index: branches/eam_branches/20091201/psphot/src/psphotSourceStats.c
===================================================================
--- branches/eam_branches/20091201/psphot/src/psphotSourceStats.c	(revision 26595)
+++ branches/eam_branches/20091201/psphot/src/psphotSourceStats.c	(revision 26596)
@@ -325,5 +325,5 @@
 
         // measure basic source moments (no S/N clipping on input pixels)
-        status = pmSourceMoments (source, RADIUS, SIGMA, 0.0);
+        status = pmSourceMoments (source, RADIUS, SIGMA, 0.0, maskVal);
         if (status) {
             Nmoments ++;
@@ -335,5 +335,5 @@
         BIG_RADIUS = PS_MIN (INNER, 3*RADIUS);
         psTrace ("psphot", 4, "retrying moments for %d, %d\n", source->peak->x, source->peak->y);
-        status = pmSourceMoments (source, BIG_RADIUS, 3.0*SIGMA, 0.0);
+        status = pmSourceMoments (source, BIG_RADIUS, 3.0*SIGMA, 0.0, maskVal);
         if (status) {
             source->mode |= PM_SOURCE_MODE_BIG_RADIUS;
@@ -394,5 +394,5 @@
 
             // measure basic source moments (no S/N clipping on input pixels)
-            status = pmSourceMoments (source, 4*sigma[i], sigma[i], 0.0);
+            status = pmSourceMoments (source, 4*sigma[i], sigma[i], 0.0, 0xffff);
         }
 
