Index: trunk/psphot/src/psphotFindPeaks.c
===================================================================
--- trunk/psphot/src/psphotFindPeaks.c	(revision 12817)
+++ trunk/psphot/src/psphotFindPeaks.c	(revision 13012)
@@ -2,5 +2,7 @@
 
 // In this function, we smooth the image, then search for the peaks 
-psArray *psphotFindPeaks (pmReadout *readout, psMetadata *recipe, int pass) {
+psArray *psphotFindPeaks (pmReadout *readout, psMetadata *recipe,
+			  bool returnFootprints,
+			  const int pass) {
 
     float SIGMA_SMTH, NSIGMA_SMTH, NSIGMA_PEAK;
@@ -110,7 +112,4 @@
     }
 
-    psFree (smooth_im);
-    psFree (smooth_wt);
-
     // optional dump of all peak data
     char *output = psMetadataLookupStr (&status, recipe, "PEAKS_OUTPUT_FILE");
@@ -119,5 +118,58 @@
     }
     psLogMsg ("psphot", PS_LOG_INFO, "%ld peaks: %f sec\n", peaks->n, psTimerMark ("psphot"));
+    //
+    // If they asked us to return a set of pmFootprints, not a raw pmPeak list,
+    // go ahead and find the footprints, and assign them their peaks.
+    //
+    // N.b. We're not culling this list; call pmFootprintCullPeaks if you
+    // want to do that
+    //
+    if (returnFootprints) {	// We want an array of pmFootprint, not pmPeak
+	int npixMin = psMetadataLookupS32(&status, recipe, "FOOTPRINT_NPIXMIN");
+	if (!status) {
+	    npixMin = 1;
+	}
+	float FOOTPRINT_NSIGMA_LIMIT =
+	    psMetadataLookupS32(&status, recipe,
+				(pass == 1) ? "FOOTPRINT_NSIGMA_LIMIT" : "FOOTPRINT_NSIGMA_LIMIT_2");
+	if (!status) {
+	    FOOTPRINT_NSIGMA_LIMIT = NSIGMA_PEAK;
+	}
+	threshold = PS_SQR(FOOTPRINT_NSIGMA_LIMIT)/effArea;
+
+	psArray *footprints = pmFindFootprints(smooth_im, threshold, npixMin);
+	pmPeaksAssignToFootprints(footprints, peaks);
+
+	psFree(peaks);
+	peaks = footprints;		// well, you know what I mean
+    }
+
+    psFree (smooth_im);
+    psFree (smooth_wt);
 
     return (peaks);
 }
+
+
+/************************************************************************************************************/
+/*
+ * Cull a set of peaks contained in a psArray of pmFootprints
+ */
+psErrorCode
+psphotCullPeaks(const pmReadout *readout, 
+		const psMetadata *recipe,
+		psArray *footprints) { // array of pmFootprints
+    bool status = false;
+    float nsigma_delta = psMetadataLookupF32(&status, recipe, "FOOTPRINT_CULL_NSIGMA_DELTA");
+    if (!status) {
+	nsigma_delta = 0; // min. 
+    }
+    float nsigma_min = psMetadataLookupF32(&status, recipe, "FOOTPRINT_CULL_NSIGMA_MIN");
+    if (!status) {
+	nsigma_min = 0;
+    }
+    const float skyStdev = psMetadataLookupF32(NULL, recipe, "SKY_STDEV");
+
+    return pmFootprintArrayCullPeaks(readout->image, readout->weight, footprints,
+				     nsigma_delta, nsigma_min*skyStdev);
+}
