Index: branches/tap_branches/ppSim/src/ppSimPhotomReadout.c
===================================================================
--- branches/tap_branches/ppSim/src/ppSimPhotomReadout.c	(revision 25900)
+++ branches/tap_branches/ppSim/src/ppSimPhotomReadout.c	(revision 27838)
@@ -6,5 +6,8 @@
     PS_ASSERT_PTR_NON_NULL (readout, NULL);
 
-    psArray *sources = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.SOURCES");
+    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
+    psAssert (detections, "missing detections?");
+
+    psArray *sources = detections->allSources;
     return sources;
 }
@@ -39,5 +42,5 @@
 # if 0    
     // set the photcode for this image
-    if (!psphotAddPhotcode (recipe, config, view, "PPSIM.CHIP")) {
+    if (!psphotAddPhotcodeReadout (recipe, config, view, "PPSIM.CHIP", 0)) {
         psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
         return false;
@@ -74,5 +77,5 @@
 
     // Generate the mask and weight images, including the user-defined analysis region of interest
-    psphotSetMaskAndWeight (config, readout, recipe);
+    psphotSetMaskAndWeight (config, view, recipe);
 
     // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are saved in the recipe
@@ -85,8 +88,8 @@
 
     // generate a background model (median, smoothed image)
-    if (!psphotModelBackground (config, view, "PPSIM.CHIP")) {
+    if (!psphotModelBackgroundReadoutFileIndex (config, view, "PPSIM.CHIP", 0)) {
         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     }
-    if (!psphotSubtractBackground (config, view, "PPSIM.CHIP")) {
+    if (!psphotSubtractBackgroundReadout (config, view, "PPSIM.CHIP", 0)) {
         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     }
@@ -151,6 +154,4 @@
 
     // create the exported-metadata and free local data
-    // XXX this places the sources on readout->analysis as PSPHOT.SOURCES.  modify?
-    // (or don't supply the sources, and do this with a different function)
     psphotReadoutCleanup(config, readout, recipe, NULL, psf, NULL);
 
@@ -167,6 +168,14 @@
     psAssert (forceReadout, "no forceReadout?");
     pmChipSetDataStatus (forceChip, true);
-    psMetadataAddArray (forceReadout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_META_REPLACE, "forced photometry ", forceSources);
-    psFree (forceSources);
+
+    pmDetections *detectionsForce = pmDetectionsAlloc();
+    detectionForce->allSources = forceSources;
+
+    // save detections on the readout->analysis
+    if (!psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "force sources", detectionsForce)) {
+	psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout");
+	return false;
+    }
+    psFree(detectionsForce);
 
     pmCell    *fakeCell    = pmFPAfileThisCell (config->files, view, "PPSIM.FAKE.SOURCES"); psAssert (fakeCell, "no cell?");
@@ -179,5 +188,14 @@
     psAssert (fakeReadout, "no fakeReadout?");
     pmChipSetDataStatus (fakeChip, true);
-    psMetadataAddArray (fakeReadout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_META_REPLACE, "fake photometry ", fakeSources);
+
+    pmDetections *detectionsFake = pmDetectionsAlloc();
+    detectionFake->allSources = fakeSources;
+
+    // save detections on the readout->analysis
+    if (!psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "fake sources", detectionsFake)) {
+	psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout");
+	return false;
+    }
+    psFree(detectionsFake);
 
     return true;
