Index: trunk/ppSim/src/ppSimInsertGalaxies.c
===================================================================
--- trunk/ppSim/src/ppSimInsertGalaxies.c	(revision 18011)
+++ trunk/ppSim/src/ppSimInsertGalaxies.c	(revision 27657)
@@ -74,8 +74,13 @@
     int dY = PM_CELL_TO_CHIP (0.0, y0Cell, yParityCell, binning);
 
-    // psMetadataLookupPtr (readout->analysis, "PSPHOT.SOURCES", 0);
-
-    psArray *sources = psArrayAllocEmpty (galaxies->n);
-
+    pmDetections *detections = psMetadataLookupPtr (&mdok, readout->analysis, "PSPHOT.DETECTIONS");
+    if (!detections) {
+	detections = pmDetectionsAlloc();
+	detections->allSources = psArrayAllocEmpty (galaxies->n);
+	psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY | PS_META_REPLACE, "psphot detections", detections);
+    } else {
+	psMemIncrRefCounter (detections);
+    }
+    psArray *sources = sources = detections->allSources;
 
     // add sources to the readout image & weight
@@ -181,8 +186,7 @@
     }
 
-    // NOTE: readout must be part of the pmFPAfile named "PPSIM.OUTPUT"
-    // psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY | PS_META_REPLACE, "psphot sources", sources);
+    // XXX many leaks in here, i think 
+    psFree (detections);
 
-    // XXX many leaks in here, i think 
     return true;
 }
