Index: branches/tap_branches/ppSim/src/Makefile.am
===================================================================
--- branches/tap_branches/ppSim/src/Makefile.am	(revision 25900)
+++ branches/tap_branches/ppSim/src/Makefile.am	(revision 27838)
@@ -30,4 +30,5 @@
 	ppSimLoadStars.c          \
 	ppSimMakeStars.c          \
+	ppSimMakeStarGrid.c       \
 	ppSimMakeGalaxies.c       \
 	ppSimMakeBiassec.c        \
@@ -47,6 +48,4 @@
 	ppSimLoadSpots.c	  \
 	ppSimPhotom.c		  \
-	ppSimPhotomReadoutFake.c  \
-	ppSimPhotomReadoutForce.c \
 	ppSimPhotomFiles.c	  \
 	ppSimLoadForceSources.c	  \
@@ -59,4 +58,8 @@
 	ppSimBadCTE.c             \
 	ppSimVersion.c
+
+# these functions have been broken by the API change in psphot (Jan 2010)
+#	ppSimPhotomReadoutFake.c  
+#	ppSimPhotomReadoutForce.c 
 
 ppSimSequence_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSASTRO_CFLAGS) $(ppSim_CFLAGS)
Index: branches/tap_branches/ppSim/src/ppSim.h
===================================================================
--- branches/tap_branches/ppSim/src/ppSim.h	(revision 25900)
+++ branches/tap_branches/ppSim/src/ppSim.h	(revision 27838)
@@ -103,4 +103,5 @@
 bool ppSimLoadStars (psArray *stars, pmFPA *fpa, pmConfig *config);
 bool ppSimMakeStars(psArray *stars, pmFPA *fpa, pmConfig *config, const psRandom *rng);
+bool ppSimMakeStarGrid(psArray *stars, pmFPA *fpa, pmConfig *config, const psRandom *rng);
 bool ppSimInsertStars (pmReadout *readout, psImage *expCorr, psArray *stars, pmConfig *config);
 
Index: branches/tap_branches/ppSim/src/ppSimAddNoise.c
===================================================================
--- branches/tap_branches/ppSim/src/ppSimAddNoise.c	(revision 25900)
+++ branches/tap_branches/ppSim/src/ppSimAddNoise.c	(revision 27838)
@@ -16,11 +16,11 @@
     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe
 
-    float gain = psMetadataLookupF32(NULL, cell->concepts, "CELL.GAIN"); // CCD gain, e/ADU
+    // the recipe should set GAIN to NAN, and only modify to override the concept value
+    float gain = psMetadataLookupF32(&mdok, recipe, "GAIN"); // CCD gain, e/ADU
     if (isnan(gain)) {
-	psWarning("CELL.GAIN is not set; reverting to recipe value GAIN.");
-	gain = psMetadataLookupF32(&mdok, recipe, "GAIN");
+	gain = psMetadataLookupF32(&mdok, cell->concepts, "CELL.GAIN");
 	if (!mdok) {
-	    psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find GAIN in recipe.");
-	    return false;
+	    psWarning("CELL.GAIN is not set; assuming gain of 1.0.");
+	    gain = 1.0;
 	}
     }
Index: branches/tap_branches/ppSim/src/ppSimInsertGalaxies.c
===================================================================
--- branches/tap_branches/ppSim/src/ppSimInsertGalaxies.c	(revision 25900)
+++ branches/tap_branches/ppSim/src/ppSimInsertGalaxies.c	(revision 27838)
@@ -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;
 }
Index: branches/tap_branches/ppSim/src/ppSimInsertStars.c
===================================================================
--- branches/tap_branches/ppSim/src/ppSimInsertStars.c	(revision 25900)
+++ branches/tap_branches/ppSim/src/ppSimInsertStars.c	(revision 27838)
@@ -26,4 +26,5 @@
     float expTime   = psMetadataLookupF32(NULL, recipe, "EXPTIME"); // Exposure time
     float darkRate  = psMetadataLookupF32(NULL, recipe, "DARK.RATE"); // Dark rate
+    float nSigmaLim = psMetadataLookupF32(NULL, recipe, "STARS.SIGMA.LIM"); // significance of faintest stars
 
     float readnoise = psMetadataLookupF32(NULL, cell->concepts, "CELL.READNOISE");// CCD read noise, e
@@ -106,6 +107,5 @@
         pmModelSetFlux (model, flux);
 
-        // XXX let the flux limit be a user-defined number of sky sigmas (not just 1.0)
-        float radius = model->modelRadius (model->params, roughNoise);
+        float radius = model->modelRadius (model->params, nSigmaLim * roughNoise);
         radius = PS_MAX (radius, 1.0);
 
@@ -136,5 +136,5 @@
         RESET(source->maskView);
         RESET(source->modelFlux);
-        RESET(source->psfFlux);
+        RESET(source->psfImage);
         RESET(source->blends);
 
@@ -145,7 +145,13 @@
     fclose (outfile);
 
-    // NOTE: the pmFPAfile "PPSIM.OUTPUT" points at these sources
-    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "fake sources", sources);
-    psFree(sources);
+    pmDetections *detections = pmDetectionsAlloc();
+    detections->allSources = sources;
+
+    // save detections on the readout->analysis
+    if (!psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "fake sources", detections)) {
+	psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout");
+	return false;
+    }
+    psFree(detections);
 
     // XXX many leaks in here, i think
Index: branches/tap_branches/ppSim/src/ppSimLoadForceSources.c
===================================================================
--- branches/tap_branches/ppSim/src/ppSimLoadForceSources.c	(revision 25900)
+++ branches/tap_branches/ppSim/src/ppSimLoadForceSources.c	(revision 27838)
@@ -102,5 +102,5 @@
         RESET(source->maskView);
         RESET(source->modelFlux);
-        RESET(source->psfFlux);
+        RESET(source->psfImage);
         RESET(source->blends);
 
Index: branches/tap_branches/ppSim/src/ppSimLoadStars.c
===================================================================
--- branches/tap_branches/ppSim/src/ppSimLoadStars.c	(revision 25900)
+++ branches/tap_branches/ppSim/src/ppSimLoadStars.c	(revision 27838)
@@ -30,8 +30,9 @@
     psRegion *bounds = ppSimFPABounds (fpa);
     float radius = 0.5 * PS_MAX(bounds->x1 - bounds->x0, bounds->y1 - bounds->y0) * scale;
-    psFree(bounds);
 
     float x0fpa = 0.5*(bounds->x0 + bounds->x1);
     float y0fpa = 0.5*(bounds->y0 + bounds->y1);
+
+    psFree(bounds);
 
     psMetadataAdd(astroRecipe, PS_LIST_TAIL, "RA_MIN",  PS_DATA_F32 | PS_META_REPLACE, "",
Index: branches/tap_branches/ppSim/src/ppSimLoop.c
===================================================================
--- branches/tap_branches/ppSim/src/ppSimLoop.c	(revision 25900)
+++ branches/tap_branches/ppSim/src/ppSimLoop.c	(revision 27838)
@@ -47,4 +47,7 @@
         // Add random stars
         if (!ppSimMakeStars (stars, fpa, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "failed to make random stars");
+
+        // Add random stars
+        if (!ppSimMakeStarGrid (stars, fpa, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "failed to make random stars");
 
         // Add random galaxies
Index: branches/tap_branches/ppSim/src/ppSimMakeStarGrid.c
===================================================================
--- branches/tap_branches/ppSim/src/ppSimMakeStarGrid.c	(revision 27838)
+++ branches/tap_branches/ppSim/src/ppSimMakeStarGrid.c	(revision 27838)
@@ -0,0 +1,70 @@
+# include "ppSim.h"
+
+# define ESCAPE(MSG) { \
+  psError(PS_ERR_BAD_PARAMETER_VALUE, true, MSG); \
+  return false; }
+
+bool ppSimMakeStarGrid(psArray *stars, pmFPA *fpa, pmConfig *config, const psRandom *rng) {
+
+    bool status;
+    assert (stars);
+
+    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
+
+    bool starsGrid = psMetadataLookupBool(&status, recipe, "STARS.GRID"); // Grid of stars
+    if (!starsGrid) return true;
+
+    float starMag = psMetadataLookupF32(&status, recipe, "STARS.GRID.MAG"); // magnitude of grid stars
+    float dX  	  = psMetadataLookupS32(&status, recipe, "STARS.GRID.DX"); // grid spacing in X
+    float dY  	  = psMetadataLookupS32(&status, recipe, "STARS.GRID.DY"); // grid spacing in Y
+
+    float expTime      = psMetadataLookupF32(&status, recipe, "EXPTIME"); // Exposure time
+    float zp           = psMetadataLookupF32(&status, recipe, "ZEROPOINT"); // Photometric zero point
+    float seeing       = psMetadataLookupF32(&status, recipe, "SEEING"); // Seeing SIGMA (pixels)
+    float scale        = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)
+
+    if (isnan(expTime))  ESCAPE("EXPTIME is not defined");
+    if (isnan(zp))       ESCAPE("ZEROPOINT is not defined");
+    if (isnan(seeing))   ESCAPE("SEEING is not defined");
+    if (isnan(scale))    ESCAPE("PIXEL.SCALE is not defined");
+
+    // Size of FPA
+    psRegion *bounds = ppSimFPABounds (fpa);
+
+    // Size of focal plane (can't I get this from the config?)
+    int xSize = bounds->x1 - bounds->x0;
+    int ySize = bounds->y1 - bounds->y0;
+    psFree(bounds);
+
+    int nX = xSize / dX;
+    int oX = 0.5*dX;
+
+    int nY = ySize / dY;
+    int oY = 0.5*dY;
+
+    psLogMsg("ppSim", PS_LOG_INFO, "Adding %d stars with %f mag\n", nX * nY, starMag);
+
+    long oldSize = stars->n;
+    psArrayRealloc (stars, stars->n + (nX * nY));
+
+    int i = 0;
+    for (int ix = 0; ix < nX; ix ++) {
+	for (int iy = 0; iy < nY; iy ++) {
+
+	    ppSimStar *star = ppSimStarAlloc ();
+
+	    // make fpa center of distribution
+	    star->x    = oX + dX*ix; // x position
+	    star->y    = oY + dY*iy; // y position
+
+	    star->flux = ppSimMagToFlux (starMag, zp) * expTime;
+	    star->peak = ppSimStarFluxToPeak (star->flux, seeing);
+
+	    stars->data[oldSize + i] = star;
+	    i++;
+	}
+    }
+    stars->n = oldSize + i;
+
+    return true;
+}
Index: branches/tap_branches/ppSim/src/ppSimPhotom.c
===================================================================
--- branches/tap_branches/ppSim/src/ppSimPhotom.c	(revision 25900)
+++ branches/tap_branches/ppSim/src/ppSimPhotom.c	(revision 27838)
@@ -46,4 +46,6 @@
             if (! readout->data_exists) { continue; }
 
+// these are broken by the Jan 2010 API changes to psphot
+#if 0
             // run the actual photometry analysis
             if (!ppSimPhotomReadoutFake (config, view)) {
@@ -56,4 +58,5 @@
             }
 	    // ppSimDetectionLimits (config, view);
+#endif
         }
     }
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;
Index: branches/tap_branches/ppSim/src/ppSimPhotomReadoutFake.c
===================================================================
--- branches/tap_branches/ppSim/src/ppSimPhotomReadoutFake.c	(revision 25900)
+++ branches/tap_branches/ppSim/src/ppSimPhotomReadoutFake.c	(revision 27838)
@@ -1,4 +1,6 @@
 # include "ppSim.h"
 
+// XXX this function is currently disabled -- need to update code below to distinguish the fake
+// and force positions, etc
 bool ppSimPhotomReadoutFake(pmConfig *config, const pmFPAview *view) {
 
@@ -11,12 +13,4 @@
         return false;
     }
-
-# if 0
-    // set the photcode for this image
-    if (!psphotAddPhotcode (recipe, config, view, "PPSIM.FAKE.CHIP")) {
-        psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
-        return false;
-    }
-# endif
 
     // *** in this section, perform the photometry for real + fake sources on PPSIM.FAKE.CHIP ***
@@ -36,5 +30,5 @@
 
     // Generate the mask and variance images, including the user-defined analysis region of interest
-    psphotSetMaskAndVariance (config, readout, recipe);
+    psphotSetMaskAndVariance (config, view);
 
     // XXX need to define the source pixels
@@ -58,6 +52,5 @@
     // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are saved in the recipe
     // this function uses PSPHOT.PSF.LOAD as the pmFPAfile
-    pmPSF *psf = psphotLoadPSF (config, view, recipe);
-    assert (psf);
+    psphotLoadPSF (config, view);
 
     // remove all sources
@@ -65,8 +58,8 @@
 
     // generate a background model (median, smoothed image)
-    if (!psphotModelBackground (config, view, "PPSIM.FAKE.CHIP")) {
+    if (!psphotModelBackgroundReadoutFileIndex (config, view, "PPSIM.FAKE.CHIP", 0)) {
         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     }
-    if (!psphotSubtractBackground (config, view, "PPSIM.FAKE.CHIP")) {
+    if (!psphotSubtractBackgroundReadout (config, view, "PPSIM.FAKE.CHIP", 0, recipe)) {
         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     }
@@ -118,5 +111,10 @@
     psAssert (fakeReadout, "no fakeReadout?");
     pmChipSetDataStatus (fakeChip, true);
-    psMetadataAddArray (fakeReadout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_META_REPLACE, "fake photometry ", fakeSources);
+
+    pmDetections *detections = pmDetectionsAlloc();
+    detection->allSources = fakeSources;
+
+    psMetadataAddArray (fakeReadout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE, "fake photometry ", detections);
+    psFree(detections);
 
     return true;
Index: branches/tap_branches/ppSim/src/ppSimPhotomReadoutForce.c
===================================================================
--- branches/tap_branches/ppSim/src/ppSimPhotomReadoutForce.c	(revision 25900)
+++ branches/tap_branches/ppSim/src/ppSimPhotomReadoutForce.c	(revision 27838)
@@ -14,5 +14,5 @@
 # if 0
     // set the photcode for this image
-    if (!psphotAddPhotcode (recipe, config, view, "PPSIM.FAKE.CHIP")) {
+    if (!psphotAddPhotcodeReadout (recipe, config, view, "PPSIM.FAKE.CHIP", 0)) {
         psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
         return false;
@@ -36,5 +36,5 @@
 
     // Generate the mask and variance images, including the user-defined analysis region of interest
-    psphotSetMaskAndVariance (config, readout, recipe);
+    psphotSetMaskAndVariance (config, view, recipe);
 
     // XXX need to define the source pixels
@@ -58,8 +58,8 @@
 
     // generate a background model (median, smoothed image)
-    if (!psphotModelBackground (config, view, "PPSIM.FORCE.CHIP")) {
+    if (!psphotModelBackgroundReadoutFileIndex (config, view, "PPSIM.FORCE.CHIP", 0)) {
         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     }
-    if (!psphotSubtractBackground (config, view, "PPSIM.FORCE.CHIP")) {
+    if (!psphotSubtractBackgroundReadout (config, view, "PPSIM.FORCE.CHIP", 0)) {
         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     }
@@ -98,6 +98,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);
 
@@ -111,5 +109,9 @@
     psAssert (forceReadout, "no forceReadout?");
     pmChipSetDataStatus (forceChip, true);
-    psMetadataAddArray (forceReadout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_META_REPLACE, "force photometry ", forceSources);
+
+    pmDetections *detections = pmDetectionsAlloc();
+    detection->allSources = forceSources;
+    psMetadataAddArray (forceReadout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE, "force photometry ", detections);
+    psFree(detections);
 
     return true;
Index: branches/tap_branches/ppSim/src/ppSimSetPSF.c
===================================================================
--- branches/tap_branches/ppSim/src/ppSimSetPSF.c	(revision 25900)
+++ branches/tap_branches/ppSim/src/ppSimSetPSF.c	(revision 27838)
@@ -20,4 +20,6 @@
     // ppSimArguments)
     float seeing   = psMetadataLookupF32(&status, recipe, "SEEING"); // Seeing SIGMA (pixels)
+    float aRatio   = psMetadataLookupF32(&status, recipe, "PSF.ARATIO"); // Seeing SIGMA (pixels)
+    float theta    = psMetadataLookupF32(&status, recipe, "PSF.THETA"); // Seeing SIGMA (pixels)
 
     char *psfModelName = psMetadataLookupStr(&status, recipe, "PSF.MODEL"); // Name of PSF model
@@ -55,6 +57,6 @@
     // supply the semi-major axis (these are SIGMA values in PIXELS)
     axes.major = seeing;
-    axes.minor = seeing;
-    axes.theta = 0.0;
+    axes.minor = aRatio * seeing;
+    axes.theta = theta * PS_RAD_DEG;
 
     pol = psEllipseAxesToPol (axes);
Index: branches/tap_branches/ppSim/src/ppSimUtils.c
===================================================================
--- branches/tap_branches/ppSim/src/ppSimUtils.c	(revision 25900)
+++ branches/tap_branches/ppSim/src/ppSimUtils.c	(revision 27838)
@@ -270,8 +270,13 @@
 psArray *ppSimSelectSources (pmConfig *config, const pmFPAview *view, const char *filename) {
 
+    bool status;
+
     pmReadout *readout = pmFPAfileThisReadout (config->files, view, filename);
     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;
 }
