Index: branches/eam_branches/psphot.20100506/src/psphotStackPSF.c
===================================================================
--- branches/eam_branches/psphot.20100506/src/psphotStackPSF.c	(revision 27883)
+++ branches/eam_branches/psphot.20100506/src/psphotStackPSF.c	(revision 27888)
@@ -4,43 +4,60 @@
 {
     bool mdok = false;
+    pmPSF *psf = NULL;
 
-#ifndef TESTING
     // Get the recipe values
-    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "PPSTACK"); // ppStack recipe
-    psAssert(recipe, "We've thrown an error on this before.");
+    psMetadata *psphotRecipe = psMetadataLookupMetadata(NULL, config->recipes, "PSPHOT"); // psphot recipe
+    psAssert(psphotRecipe, "We've thrown an error on this before.");
 
-    int psfInstances = psMetadataLookupS32(NULL, recipe, "PSF.INSTANCES"); // Number of instances for PSF
-    float psfRadius = psMetadataLookupF32(NULL, recipe, "PSF.RADIUS"); // Radius for PSF
-    const char *psfModel = psMetadataLookupStr(NULL, recipe, "PSF.MODEL"); // Model for PSF
-    int psfOrder = psMetadataLookupS32(NULL, recipe, "PSF.ORDER"); // Spatial order for PSF
+    bool autoPSF = psMetadataLookupBool (&mdok, psphotRecipe, "PSPHOT.STACK.TARGET.PSF.AUTO");
 
-    psString maskValStr = psMetadataLookupStr(&mdok, recipe, "MASK.VAL"); // Name of bits to mask going in
-    if (!mdok || !maskValStr) {
-        psError(PSPHOT_ERR_CONFIG, false, "Unable to find MASK.VAL in recipe");
-        return false;
+    if (autoPSF) {
+	// Get the recipe values
+	psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "PPSTACK"); // ppStack recipe
+	psAssert(recipe, "We've thrown an error on this before.");
+
+	int psfInstances = psMetadataLookupS32(NULL, recipe, "PSF.INSTANCES"); // Number of instances for PSF
+	float psfRadius = psMetadataLookupF32(NULL, recipe, "PSF.RADIUS"); // Radius for PSF
+	const char *psfModel = psMetadataLookupStr(NULL, recipe, "PSF.MODEL"); // Model for PSF
+	int psfOrder = psMetadataLookupS32(NULL, recipe, "PSF.ORDER"); // Spatial order for PSF
+
+	psString maskValStr = psMetadataLookupStr(&mdok, recipe, "MASK.VAL"); // Name of bits to mask going in
+	if (!mdok || !maskValStr) {
+	    psError(PSPHOT_ERR_CONFIG, false, "Unable to find MASK.VAL in recipe");
+	    return false;
+	}
+	psImageMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask
+
+	for (int i = 0; i < psfs->n; i++) {
+	    if (inputMask->data.U8[i]) {
+		psFree(psfs->data[i]);
+		psfs->data[i] = NULL;
+	    }
+	}
+
+	// Solve for the target PSF
+	psf = pmPSFEnvelope(numCols, numRows, psfs, psfInstances, psfRadius, psfModel, psfOrder, psfOrder, maskVal);
+	if (!psf) {
+	    psError(PSPHOT_ERR_PSF, false, "Unable to determine output PSF.");
+	    return NULL;
+	}
+
+    } else {
+
+	// externally-defined PSF
+	// XXX need to test for compatibility of target with inputs
+
+	float targetFWHM = psMetadataLookupF32 (&mdok, psphotRecipe, "PSPHOT.STACK.TARGET.PSF.FWHM");
+	psAssert (isfinite(targetFWHM), "missing psphot recipe value PSPHOT.STACK.TARGET.PSF.FWHM");
+
+	float Sxx = sqrt(2.0)*targetFWHM / 2.35;
+
+	// XXX probably should make the model type (and par 7) optional from recipe
+	psf = pmPSFBuildSimple("PS_MODEL_PS1_V1", Sxx, Sxx, 0.0, 1.0);
+	if (!psf) {
+	    psError(PSPHOT_ERR_PSF, false, "Unable to build dummy PSF.");
+	    return NULL;
+	}
     }
-    psImageMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask
-
-    for (int i = 0; i < psfs->n; i++) {
-        if (inputMask->data.U8[i]) {
-            psFree(psfs->data[i]);
-            psfs->data[i] = NULL;
-        }
-    }
-
-    // Solve for the target PSF
-    pmPSF *psf = pmPSFEnvelope(numCols, numRows, psfs, psfInstances, psfRadius, psfModel, psfOrder, psfOrder, maskVal);
-    if (!psf) {
-        psError(PSPHOT_ERR_PSF, false, "Unable to determine output PSF.");
-        return NULL;
-    }
-#else
-    // Dummy PSF
-    pmPSF *psf = pmPSFBuildSimple("PS_MODEL_PS1_V1", 4.0, 4.0, 0.0, 1.0);
-    if (!psf) {
-        psError(PSPHOT_ERR_PSF, false, "Unable to build dummy PSF.");
-        return NULL;
-    }
-#endif
 
     return psf;
