Index: branches/eam_branches/psphot.stack.20100120/src/psphotFindDetections.c
===================================================================
--- branches/eam_branches/psphot.stack.20100120/src/psphotFindDetections.c	(revision 26642)
+++ branches/eam_branches/psphot.stack.20100120/src/psphotFindDetections.c	(revision 26643)
@@ -2,5 +2,5 @@
 
 // smooth the image, search for peaks, optionally define footprints based on the peaks
-pmDetections *psphotFindDetections (pmDetections *detections, pmReadout *readout, psMetadata *recipe) {
+bool psphotFindDetections (pmConfig *config, const pmFPAview *view, const char *filename, int index) {
 
     bool status;
@@ -9,7 +9,18 @@
     int NMAX = 0;
 
+    // find the currently selected readout
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    psAssert (readout, "missing file?");
+
+    pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
+    psAssert (readout, "missing readout?");
+
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
-    assert (maskVal);
+    psAssert (maskVal, "missing mask value?");
 
     // Use the new pmFootprints approach?
@@ -71,5 +82,11 @@
     psphotVisualShowFootprints (detections);
 
-    return detections;
+    // save detections on the readout->analysis
+    if (!psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_PTR, "psphot detectinos", detections)) {
+	psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout");
+        return NULL;
+    }
+
+    return true;
 }
 
@@ -77,6 +94,5 @@
 // otherwise it only contains the new peaks.
 
-# if 0
-// XXX where do we place the N sets of detections?
+// for now, let's store the detections on the readout->analysis for each readout
 bool psphotFindDetections (pmConfig *config, const pmFPAview *view)
 {
@@ -84,10 +100,10 @@
 
     int num = psMetadataAddS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
-    psAbort (!status, "programming error: must define PSPHOT.INPUT.NUM");
+    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
 
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
 	if (!psphotFindDetectionsReadout (config, view, "PSPHOT.INPUT", i)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to subtract background for PSPHOT.INPUT entry %d", i);
+            psError (PSPHOT_ERR_CONFIG, false, "failed to find initial detections for PSPHOT.INPUT entry %d", i);
 	    return false;
 	}
@@ -95,3 +111,2 @@
     return true;
 }
-# endif
