Index: trunk/ppSub/src/ppSubLoop.c
===================================================================
--- trunk/ppSub/src/ppSubLoop.c	(revision 31435)
+++ trunk/ppSub/src/ppSubLoop.c	(revision 32676)
@@ -23,9 +23,9 @@
 bool dumpout(pmConfig *config, char *name) 
 {
-  pmFPAview *view = ppSubViewReadout(); // View to readout
-  pmReadout *out = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT");
-  psphotSaveImage (NULL, out->image, name);
-  psFree(view);
-  return true;
+    pmFPAview *view = ppSubViewReadout(); // View to readout
+    pmReadout *out = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT");
+    psphotSaveImage (NULL, out->image, name);
+    psFree(view);
+    return true;
 }
 
@@ -33,13 +33,17 @@
 bool ppSubLoop(ppSubData *data)
 {
+    bool mdok = false;
+    bool success = true;
+
     psAssert(data, "Require processing data");
     pmConfig *config = data->config;    // Configuration
     psAssert(config, "Require configuration.");
 
-    bool success = true;
+    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
+    psAssert(recipe, "We checked this earlier, so it should be here.");
+    bool noConvolve = psMetadataLookupBool(&mdok, recipe, "NOCONVOLVE"); // Do not use convolved images.
 
     pmConfigCamerasCull(config, NULL);
     pmConfigRecipesCull(config, "PPSUB,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG");
-
 
     pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT");
@@ -75,28 +79,27 @@
     if (data->forcedPhot2) {
         // Change the recipe to use a higher nsigma limit and quit after pass1
-        psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
-
-        psF32 nsigma_peak_save = psMetadataLookupF32 (NULL, recipe, "PEAKS_NSIGMA_LIMIT");
-        char *breakPt_save =  psMetadataLookupStr (NULL, recipe, "BREAK_POINT");
-
-        bool mdok;
-        psF32 pos2_nsigma_peak = psMetadataLookupF32 (&mdok, recipe, "PEAKS_POS2_NSIGMA_LIMIT");
+        psMetadata *psphotRecipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
+
+        psF32 nsigma_peak_save = psMetadataLookupF32 (NULL, psphotRecipe, "PEAKS_NSIGMA_LIMIT");
+        char *breakPt_save =  psMetadataLookupStr (NULL, psphotRecipe, "BREAK_POINT");
+
+        psF32 pos2_nsigma_peak = psMetadataLookupF32 (&mdok, psphotRecipe, "PEAKS_POS2_NSIGMA_LIMIT");
         if (!mdok) {
-            psWarning("PEAKS_POS2_NSIGMA_LIMIT not found in recipe. Will use 25.\n");
+            psWarning("PEAKS_POS2_NSIGMA_LIMIT not found in psphotRecipe. Will use 25.\n");
             pos2_nsigma_peak = 25.;
         }
-        psMetadataAddF32(recipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", pos2_nsigma_peak);
-        psMetadataAddStr(recipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", "PASS1");
+        psMetadataAddF32(psphotRecipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", pos2_nsigma_peak);
+        psMetadataAddStr(psphotRecipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", "PASS1");
 
 	bool foundDetections = false;
 	if (!ppSubInputDetections(&foundDetections, "PPSUB.POS2.SOURCES", "PPSUB.REF", data)) {
 	    psError(psErrorCodeLast(), false, "Unable to measure positive detections (2)");
-            psMetadataAddF32(recipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", nsigma_peak_save);
-            psMetadataAddStr(recipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", breakPt_save);
-	    success = false;
-            goto ESCAPE;
-	}
-        psMetadataAddF32(recipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", nsigma_peak_save);
-        psMetadataAddStr(recipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", breakPt_save);
+            psMetadataAddF32(psphotRecipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", nsigma_peak_save);
+            psMetadataAddStr(psphotRecipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", breakPt_save);
+	    success = false;
+            goto ESCAPE;
+	}
+        psMetadataAddF32(psphotRecipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", nsigma_peak_save);
+        psMetadataAddStr(psphotRecipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", breakPt_save);
 	// if nothing was found, don't bother doing the forced photometry below
 	if (!foundDetections) {
@@ -107,16 +110,9 @@
 
     // XXX if it exists, use the POS1, POS2 successs for the FWHMs
-    psMetadata *recipe = psMetadataLookupPtr(NULL, config->recipes, PPSUB_RECIPE);
-    bool noConvolve = psMetadataLookupBool(NULL, recipe, "NOCONVOLVE"); // Do not use convolved images.
-    if (noConvolve) {
-      psWarning("not matching PSFs because NOCONVOLVE is TRUE\n");
-    } else {
-      if (!ppSubMatchPSFs(data)) {
-        psError(psErrorCodeLast(), false, "Unable to match PSFs.");
-        success = false;
-        goto ESCAPE;
-      }
-    }
-
+    if (!ppSubMatchPSFs(data)) {
+	psError(psErrorCodeLast(), false, "Unable to match PSFs.");
+	success = false;
+	goto ESCAPE;
+    }
 
     if (data->quality) {
@@ -138,11 +134,12 @@
                      psTimerClear("PPSUB_MATCH"));
 
-    // Close input files
+    // Close input files (freeing up space) : for the noConvolve case, we cannot close the
+    // inputs since we will use them for subtraction below.  wait until later to do the work
     if (!noConvolve) {
-    if (!ppSubFilesIterateUp(config, PPSUB_FILES_INPUT)) {
-        psError(PPSUB_ERR_IO, false, "Unable to close input files.");
-        success = false;
-        goto ESCAPE;
-    }
+	if (!ppSubFilesIterateUp(config, PPSUB_FILES_INPUT)) {
+	    psError(PPSUB_ERR_IO, false, "Unable to close input files.");
+	    success = false;
+	    goto ESCAPE;
+	}
     }
     if (!ppSubLowThreshold(data)) {
@@ -165,5 +162,4 @@
     }
 
-    if (!noConvolve) {
     if (!data->quality && !ppSubMakePSF(data)) {
         psError(psErrorCodeLast(), false, "Unable to generate PSF.");
@@ -171,5 +167,5 @@
         goto ESCAPE;
     }
-    }
+
     // Now we've got a PSF, blow away detections in case they're confused with real output detections
     {
@@ -197,9 +193,9 @@
     // dumpout(config, "diff.2a.fits");
     if (noConvolve) {
-      if (!ppSubFilesIterateUp(config, PPSUB_FILES_INPUT)) {
-	psError(PPSUB_ERR_IO, false, "Unable to close input files.");
-	success = false;
-	goto ESCAPE;
-      }
+	if (!ppSubFilesIterateUp(config, PPSUB_FILES_INPUT)) {
+	    psError(PPSUB_ERR_IO, false, "Unable to close input files.");
+	    success = false;
+	    goto ESCAPE;
+	}
     }
     
@@ -271,12 +267,12 @@
     // Do Mask Stats
     {
-      pmFPAview *view = ppSubViewReadout(); // View to readout
-      if (!ppSubMaskStats(config, view,data->stats)) {
-	psError(psErrorCodeLast(), false, "Unable to generate mask statistics");
-	success = false;
-        psFree(view);
-        goto ESCAPE;
-      }
-      psFree(view);
+	pmFPAview *view = ppSubViewReadout(); // View to readout
+	if (!ppSubMaskStats(config, view,data->stats)) {
+	    psError(psErrorCodeLast(), false, "Unable to generate mask statistics");
+	    success = false;
+	    psFree(view);
+	    goto ESCAPE;
+	}
+	psFree(view);
     }
     // dumpout(config, "diff.4.fits");
@@ -344,5 +340,5 @@
     }
 
-ESCAPE:
+ ESCAPE:
     pmFPAfileDropInternal(config->files, "PSPHOT.BACKGND");
     pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL");
