Index: /branches/eam_branches/20091201/ppSub/src/ppSubMakePSF.c
===================================================================
--- /branches/eam_branches/20091201/ppSub/src/ppSubMakePSF.c	(revision 26783)
+++ /branches/eam_branches/20091201/ppSub/src/ppSubMakePSF.c	(revision 26784)
@@ -66,7 +66,7 @@
     pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
 
-    // we need to remove any existing PSPHOT.SOURCES (why not do this in psphot?)
-    if (psMetadataLookup(photRO->analysis, "PSPHOT.SOURCES")) {
-        psMetadataRemoveKey(photRO->analysis, "PSPHOT.SOURCES");
+    // we need to remove any existing PSPHOT.DETECTIONS (why not do this in psphot?)
+    if (psMetadataLookup(photRO->analysis, "PSPHOT.DETECTIONS")) {
+        psMetadataRemoveKey(photRO->analysis, "PSPHOT.DETECTIONS");
     }
     if (psMetadataLookup(photRO->parent->parent->analysis, "PSPHOT.PSF")) {
@@ -83,5 +83,8 @@
     // Extract the loaded sources from the associated readout, and generate PSF
     // Here, we assume the image is background-subtracted
-    psArray *sources = psMetadataLookupPtr(&mdok, minuend->analysis, "PSPHOT.SOURCES");
+    pmDetections *detections = psMetadataLookupPtr(&mdok, minuend->analysis, "PSPHOT.DETECTIONS");
+    psAssert(detections, "missing detections?");
+    psArray *sources = detections->allSources;
+    psAssert(sources, "missing sources?");
     
     // XXX filter sources?  limit the total number and return only brighter objects?
Index: /branches/eam_branches/20091201/ppSub/src/ppSubMatchPSFs.c
===================================================================
--- /branches/eam_branches/20091201/ppSub/src/ppSubMatchPSFs.c	(revision 26783)
+++ /branches/eam_branches/20091201/ppSub/src/ppSubMatchPSFs.c	(revision 26784)
@@ -63,6 +63,6 @@
     pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
 
-    if (psMetadataLookup(photRO->analysis, "PSPHOT.SOURCES")) {
-        psMetadataRemoveKey(photRO->analysis, "PSPHOT.SOURCES");
+    if (psMetadataLookup(photRO->analysis, "PSPHOT.DETECTIONS")) {
+        psMetadataRemoveKey(photRO->analysis, "PSPHOT.DETECTIONS");
     }
     if (psMetadataLookup(photRO->parent->parent->analysis, "PSPHOT.PSF")) {
@@ -123,13 +123,21 @@
     pmReadout *inSourceRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.SOURCES");
     pmReadout *refSourceRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.SOURCES");
-    psArray *inSources = psMetadataLookupPtr(NULL, inSourceRO->analysis, "PSPHOT.SOURCES"); // Input sources
-    psArray *refSources = psMetadataLookupPtr(NULL, refSourceRO->analysis, "PSPHOT.SOURCES"); // Ref sources
+    // XXX assert on inSourcesRO and refSourcesRO?
+
+    pmDetections *inDetections = psMetadataLookupPtr(NULL, inSourceRO->analysis, "PSPHOT.DETECTIONS"); // Input sources
+    pmDetections *refDetections = psMetadataLookupPtr(NULL, refSourceRO->analysis, "PSPHOT.DETECTIONS"); // Ref sources
 
     psFree(view);
 
-    if (!inSources || !refSources) {
+    if (!inDetections || !refDetections) {
         psWarning("Unable to scale kernel, since no sources were provided.");
         return true;
     }
+
+    psArray *inSources = inDetections->allSources;
+    psAssert (inSources, "missing inSources?");
+
+    psArray *refSources = refDetections->allSources;
+    psAssert (refSources, "missing refSources?");
 
     float inFWHM = subImagePSF(data, inRO, inSources); // FWHM for input
@@ -198,34 +206,41 @@
     pmReadout *inSourceRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.SOURCES");
     pmReadout *refSourceRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.SOURCES");
-    psArray *inSources = inSourceRO ? psMetadataLookupPtr(&mdok, inSourceRO->analysis, "PSPHOT.SOURCES") :
-        NULL; // Source list from input image
-    psArray *refSources = refSourceRO ? psMetadataLookupPtr(&mdok, refSourceRO->analysis, "PSPHOT.SOURCES") :
-        NULL ; // Source list from reference image
+
+    pmDetections *inDetections  = inSourceRO  ? psMetadataLookupPtr(&mdok, inSourceRO->analysis,  "PSPHOT.DETECTIONS") : NULL; // Input sources
+    pmDetections *refDetections = refSourceRO ? psMetadataLookupPtr(&mdok, refSourceRO->analysis, "PSPHOT.DETECTIONS") : NULL; // Ref sources
 
     psFree(view);
 
-    psArray *sources = NULL;            // Merged list of sources
-    if (inSources && refSources) {
+    pmDetections *detections = NULL;    // Merged detection set
+    if (inDetections && refDetections) {
+	psArray *inSources  = inDetections->allSources;
+	psArray *refSources = refDetections->allSources;
+
+	psAssert (inSources, "missing in sources?");
+	psAssert (refSources, "missing ref sources?");
+
+	detections = pmDetectionsAlloc();
         float radius = psMetadataLookupF32(NULL, recipe, "SOURCE.RADIUS"); // Matching radius
         psArray *lists = psArrayAlloc(2); // Source lists
         lists->data[0] = psMemIncrRefCounter(inSources);
         lists->data[1] = psMemIncrRefCounter(refSources);
-        sources = pmSourceMatchMerge(lists, radius);
+        detections->allSources = pmSourceMatchMerge(lists, radius);
         psFree(lists);
-        if (!sources) {
+        if (!detections->allSources) {
             psError(PS_ERR_UNKNOWN, false, "Unable to merge source lists");
+	    psFree(detections);
             return false;
         }
-    } else if (inSources) {
-        sources = psMemIncrRefCounter(inSources);
-    } else if (refSources) {
-        sources = psMemIncrRefCounter(refSources);
-    }
-
-    psMetadataAddArray(inConv->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_META_REPLACE,
-                       "Merged source list", sources);
-    psMetadataAddArray(refConv->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_META_REPLACE,
-                       "Merged source list", sources);
-    psFree(sources);                    // Drop reference
+    } 
+    if (!detections && inDetections) {
+        detections = psMemIncrRefCounter(inDetections);
+    } 
+    if (!detections && refDetections) {
+        detections = psMemIncrRefCounter(refDetections);
+    }
+
+    psMetadataAddPtr(inConv->analysis,  PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "Merged source list", detections);
+    psMetadataAddPtr(refConv->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "Merged source list", detections);
+    psFree(detections);                    // Drop reference
 
     int footprint = psMetadataLookupS32(NULL, recipe, "STAMP.FOOTPRINT"); // Stamp half-size
@@ -326,5 +341,5 @@
     } else {
         success = pmSubtractionMatch(inConv, refConv, inRO, refRO, footprint, stride, regionSize,
-                                     spacing, threshold, sources, data->stamps, type, size, order,
+                                     spacing, threshold, detections->allSources, data->stamps, type, size, order,
                                      widths, orders, inner, ringsOrder, binning, penalty, optimum,
                                      optWidths, optOrder, optThresh, iter, rej, normFrac,
Index: /branches/eam_branches/20091201/ppSub/src/ppSubReadoutPhotometry.c
===================================================================
--- /branches/eam_branches/20091201/ppSub/src/ppSubReadoutPhotometry.c	(revision 26783)
+++ /branches/eam_branches/20091201/ppSub/src/ppSubReadoutPhotometry.c	(revision 26784)
@@ -58,12 +58,12 @@
     }
 
-    // drop references to PSPHOT.SOURCES on both of these  (why is this needed for both??)
+    // drop references to PSPHOT.DETECTIONS on both of these  (why is this needed for both??)
     pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
-    if (psMetadataLookup(photRO->analysis, "PSPHOT.SOURCES")) {
-        psMetadataRemoveKey(photRO->analysis, "PSPHOT.SOURCES");
+    if (psMetadataLookup(photRO->analysis, "PSPHOT.DETECTIONS")) {
+        psMetadataRemoveKey(photRO->analysis, "PSPHOT.DETECTIONS");
     }
     pmReadout *inRO = pmFPAfileThisReadout(config->files, view, name); // Readout with image and sources
-    if (psMetadataLookup(inRO->analysis, "PSPHOT.SOURCES")) {
-        psMetadataRemoveKey(inRO->analysis, "PSPHOT.SOURCES");
+    if (psMetadataLookup(inRO->analysis, "PSPHOT.DETECTIONS")) {
+        psMetadataRemoveKey(inRO->analysis, "PSPHOT.DETECTIONS");
     }
 
@@ -90,8 +90,10 @@
 
     // If no sources were found, there's no error,  but we want to trigger 'bad quality'
-    psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources
-    if (!sources) {
+    pmDetections *detections = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.DETECTIONS"); // Sources
+    if (!detections) {
         ppSubDataQuality(data, PSPHOT_ERR_DATA, PPSUB_FILES_PHOT_SUB | PPSUB_FILES_PHOT_INV);
     }
+    psArray *sources = detections->allSources;
+    psAssert (sources, "missing sources?");
 
     if (data->stats) {
@@ -108,6 +110,6 @@
 
     if (!data->quality) {
-        if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.SOURCES")) {
-            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to copy PSPHOT.SOURCES");
+        if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.DETECTIONS")) {
+            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to copy PSPHOT.DETECTIONS");
             return false;
         }
@@ -132,5 +134,6 @@
     {
         pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with the sources
-        psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources
+        pmDetections *detections = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.DETECTIONS"); // Sources
+	psArray *sources = detections->allSources;
         FILE *sourceFile = fopen("sources.dat", "w"); // File for sources
         fprintf(sourceFile,
