Index: /trunk/pswarp/src/pswarpLoop.c
===================================================================
--- /trunk/pswarp/src/pswarpLoop.c	(revision 20114)
+++ /trunk/pswarp/src/pswarpLoop.c	(revision 20115)
@@ -7,11 +7,11 @@
 // Lists must end with a NULL
 static char *detectorFiles[] = { "PSWARP.INPUT", "PSWARP.MASK", "PSWARP.WEIGHT", NULL };
-static char *skycellFiles[] = { "PSWARP.OUTPUT", "PSWARP.OUTPUT.MASK", "PSWARP.OUTPUT.WEIGHT",
-                                "PSPHOT.OUTPUT", "PSPHOT.RESID", "PSPHOT.BACKMDL", "PSPHOT.BACKMDL.STDEV",
-                                "PSPHOT.BACKGND", "PSPHOT.BACKSUB", "PSPHOT.PSF.SAVE", "SOURCE.PLOT.MOMENTS",
-                                "SOURCE.PLOT.PSFMODEL", "SOURCE.PLOT.APRESID", NULL };
+static char *skycellFiles[] = { "PSWARP.OUTPUT", "PSWARP.OUTPUT.MASK", "PSWARP.OUTPUT.WEIGHT", NULL };
+static char *photFiles[] = { "PSPHOT.INPUT", "PSPHOT.OUTPUT", "PSPHOT.INPUT.CMF", "PSPHOT.RESID",
+                             "PSPHOT.BACKMDL", "PSPHOT.BACKMDL.STDEV", "PSPHOT.BACKGND", "PSPHOT.BACKSUB",
+                             "PSPHOT.PSF.SAVE", "SOURCE.PLOT.MOMENTS", "SOURCE.PLOT.PSFMODEL",
+                             "SOURCE.PLOT.APRESID", NULL };
 static char *independentFiles[] = { "PSWARP.ASTROM", // Read independently from the input pixels
                                     "PSWARP.SKYCELL", // Don't care about the skycell once we have its WCS
-                                    "PSPHOT.INPUT", // This is just a pointer to PSWARP.OUTPUT
                                     "PSWARP.OUTPUT.SOURCES", // Save these independently so we can do the PSF
                                     NULL };
@@ -127,4 +127,5 @@
     {
         fileActivation(config, detectorFiles, false);
+        fileActivation(config, photFiles, false);
         fileActivation(config, independentFiles, false);
         fileActivation(config, skycellFiles, true);
@@ -326,5 +327,4 @@
     fileActivation(config, detectorFiles, false);
     fileActivation(config, independentFiles, false);
-    fileActivation(config, skycellFiles, true);
 
     // We need a new PSF model for the warped frame
@@ -334,4 +334,8 @@
     // scratch.
     if (psMetadataLookupBool(&mdok, config->arguments, "PSF")) {
+        fileActivation(config, photFiles, true);
+        ioChecksBefore(config);
+
+        // Tweak recipe
         psMetadata *psphotRecipe = psMetadataLookupPtr(NULL, config->recipes,
                                                        PSPHOT_RECIPE); // Recipe for psphot
@@ -346,23 +350,22 @@
                           "Don't allow psphot to fit a fake PSF!", false);
 
+#if 0
         // Get rid of the transformed sources so that we can measure the PSF
         psMetadataRemoveKey(output->analysis, "PSPHOT.SOURCES");
-
-#if 0
+#endif
+
         pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT");
         pmFPACopy(photFile->fpa, outFPA);
-#endif
 
         pmFPAview *view = pmFPAviewAlloc(0); // View into skycell
         view->chip = view->cell = view->readout = 0;
-        if (!psphotReadout(config, view)) {
+        if (!psphotReadoutFindPSF(config, view)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to determine PSF for warped image.");
             return false;
         }
         psFree(view);
-
-        pmFPAfileActivate(config->files, true, "PSPHOT.INPUT");
-        pmFPAfileActivate(config->files, true, "PSPHOT.PSF.SAVE");
-    }
+    }
+
+    fileActivation(config, skycellFiles, true);
 
     // Perform statistics on the output image
Index: /trunk/pswarp/src/pswarpParseCamera.c
===================================================================
--- /trunk/pswarp/src/pswarpParseCamera.c	(revision 20114)
+++ /trunk/pswarp/src/pswarpParseCamera.c	(revision 20115)
@@ -99,7 +99,14 @@
         // This file, PSPHOT.INPUT, is just used as a carrier; output files (eg, PSPHOT.RESID) are defined by
         // psphotDefineFiles
-        pmFPAfile *psphotInput = pmFPAfileDefineSkycell(config, output->fpa, "PSPHOT.INPUT");
+        pmFPAfile *psphotInput = pmFPAfileDefineSkycell(config, NULL, "PSPHOT.INPUT");
         if (!psphotInput) {
             psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.INPUT"));
+            return false;
+        }
+        psphotInput->src = psMemIncrRefCounter(output->fpa);
+
+        pmFPAfile *psphotInSources = pmFPAfileDefineSkycell(config, psphotInput->fpa, "PSPHOT.INPUT.CMF");
+        if (!psphotInSources) {
+            psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.INPUT.CMF"));
             return false;
         }
Index: /trunk/pswarp/src/pswarpTransformSources.c
===================================================================
--- /trunk/pswarp/src/pswarpTransformSources.c	(revision 20114)
+++ /trunk/pswarp/src/pswarpTransformSources.c	(revision 20115)
@@ -1,5 +1,5 @@
-# include "pswarp.h"
+#include "pswarp.h"
 
-# define SOURCE_ARRAY_BUFFER 100         // Size to grow the array of sources at a time
+#define SOURCE_ARRAY_BUFFER 100         // Size to grow the array of sources at a time
 
 // NOTE: in this function, the coordinates are transformed from the OUTPUT to the INPUT
