Index: /trunk/pswarp/configure.ac
===================================================================
--- /trunk/pswarp/configure.ac	(revision 14873)
+++ /trunk/pswarp/configure.ac	(revision 14874)
@@ -29,4 +29,5 @@
 PKG_CHECK_MODULES([PSMODULE], [psmodules >= 1.0.0])
 PKG_CHECK_MODULES([PPSTATS], [ppStats >= 1.0.0]) 
+PKG_CHECK_MODULES([PSPHOT], [psphot >= 0.8.0]) 
 
 dnl Set CFLAGS for build
Index: /trunk/pswarp/src/Makefile.am
===================================================================
--- /trunk/pswarp/src/Makefile.am	(revision 14873)
+++ /trunk/pswarp/src/Makefile.am	(revision 14874)
@@ -1,5 +1,5 @@
 bin_PROGRAMS = pswarp
-pswarp_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PPSTATS_CFLAGS) $(PSWARP_CFLAGS)
-pswarp_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PPSTATS_LIBS) $(PSWARP_LIBS)
+pswarp_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PPSTATS_CFLAGS) $(PSPHOT_CFLAGS) $(PSWARP_CFLAGS)
+pswarp_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PPSTATS_LIBS) $(PSPHOT_LIBS) $(PSWARP_LIBS)
 
 pswarp_SOURCES = \
Index: /trunk/pswarp/src/pswarp.h
===================================================================
--- /trunk/pswarp/src/pswarp.h	(revision 14873)
+++ /trunk/pswarp/src/pswarp.h	(revision 14874)
@@ -9,4 +9,5 @@
 # include <pslib.h>
 # include <psmodules.h>
+# include <psphot.h>
 
 # include "pswarpErrorCodes.h"
Index: /trunk/pswarp/src/pswarpArguments.c
===================================================================
--- /trunk/pswarp/src/pswarpArguments.c	(revision 14873)
+++ /trunk/pswarp/src/pswarpArguments.c	(revision 14874)
@@ -23,5 +23,5 @@
     pmConfigRecipeOptions (config, PSWARP_RECIPE);
 
-    pmConfigFileSetsMD (config->arguments, &argc, argv, "ASTROM",   "-astrom", "-astromlist");
+    pmConfigFileSetsMD(config->arguments, &argc, argv, "ASTROM",   "-astrom", "-astromlist");
 
     // chip selection is used to limit chips to be processed
@@ -39,4 +39,10 @@
                          "Filename for statistics of output image", argv[N]);
         psArgumentRemove(N, &argc, argv);
+    }
+
+    // PSF determination?
+    if ((N = psArgumentGet(argc, argv, "-psf"))) {
+        psArgumentRemove(N, &argc, argv);
+        psMetadataAddBool(config->arguments, PS_LIST_TAIL, "PSF", 0, "Do PSF determination?", true);
     }
 
Index: /trunk/pswarp/src/pswarpLoop.c
===================================================================
--- /trunk/pswarp/src/pswarpLoop.c	(revision 14873)
+++ /trunk/pswarp/src/pswarpLoop.c	(revision 14874)
@@ -198,33 +198,38 @@
     }
 
+    // We need a new PSF model for the warped frame
+    // It would be good to generate this analytically, but that's going to be tricky.
+    // We have a list of sources, so we could use those to redetermine the PSF model.
+    // Until Gene makes the necessary adaptations to psphot, we will simply redetermine the PSF model from
+    // scratch.
+    if (psMetadataLookupBool(&mdok, config->arguments, "PSF")) {
+        psMetadata *psphotRecipe = psMetadataLookupPtr(NULL, config->recipes,
+                                                       PSPHOT_RECIPE); // Recipe for psphot
+        if (!psphotRecipe) {
+            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find %s recipe.", PSPHOT_RECIPE);
+            return false;
+        }
+
+        psMetadataAddStr(psphotRecipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE,
+                         "Break point for psphot operations", "PSFMODEL");
+
+        pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT");
+        pmFPACopy(photFile->fpa, outFPA);
+
+        pmFPAview *view = pmFPAviewAlloc(0); // View into skycell
+        if (!psphotReadout(config, view)) {
+            psError(psErrorCodeLast(), false, "Unable to determine PSF for warped image.\n");
+            psFree(view);
+            return false;
+        }
+        psFree(view);
+
+        pmFPAfileActivate(config->files, false, "PSPHOT.INPUT");
+    }
+
     output->data_exists = true;
     outCell->data_exists = true;
     outChip->data_exists = true;
 
-#if 0
-    float gain = 0.0, readnoise = 0.0, saturation = INFINITY, exposure = 0.0, darktime = 0.0;
-    double mjd = 0.0;
-#endif
-
-#if 0
-    // XXX Hack so that INSTRUME header keyword and the like are not updated properly
-    // If INSTRUME (etc) is updated, then the FITS file with the warped image will be often
-    // recognised as coming from the old camera, not the new, warped camera.
-    // The proper solution to this, I believe, would be to define a skycell derivative of the
-    // old camera, so that the skycell can be recognised as coming from the old camera (and would
-    // also therefore inherit all its recipes, which would be good), rather than having a completely
-    // different camera.  That will take some work; the below solution should be good enough for now.
-    {
-        psMetadataItem *item;           // Concepts item to update
-
-        item = psMetadataLookup(outFPA->concepts, "FPA.INSTRUMENT");
-        psFree(item->data.V);
-        item->data.V = NULL;
-
-        item = psMetadataLookup(outFPA->concepts, "FPA.DETECTOR");
-        psFree(item->data.V);
-        item->data.V = NULL;
-    }
-#endif
 
     // Perform statistics on the output image
Index: /trunk/pswarp/src/pswarpParseCamera.c
===================================================================
--- /trunk/pswarp/src/pswarpParseCamera.c	(revision 14873)
+++ /trunk/pswarp/src/pswarpParseCamera.c	(revision 14874)
@@ -4,4 +4,5 @@
 
     bool status;
+    bool mdok;                          // Status of MD lookup
     pmFPAfile *skycell = NULL;
     pmConfig *skyConfig = NULL;
@@ -89,7 +90,22 @@
     }
 
+    if (psMetadataLookupBool(&mdok, config->arguments, "PSF")) {
+        // This file, PSPHOT.INPUT, is just used as a carrier; output files (eg, PSPHOT.RESID) are defined by
+        // psphotDefineFiles
+        pmFPAfile *psphotInput = pmFPAfileDefineFromFPA(config, output->fpa, 1, 1, "PSPHOT.INPUT");
+        if (!psphotInput) {
+            psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.INPUT"));
+            return false;
+        }
+
+        // Define associated psphot input/output files
+        if (!psphotDefineFiles(config, psphotInput)) {
+            psError(PSPHOT_ERR_CONFIG, false,
+                    "Unable to define the additional input/output files for psphot");
+            return false;
+        }
+    }
 
     // Chip selection: turn on only the chips specified
-    bool mdok;                          // Status of MD lookup
     char *chipLine = psMetadataLookupStr(&mdok, config->arguments, "CHIP_SELECTIONS");
     if (mdok) {
Index: /trunk/pswarp/src/pswarpTransformReadout_Opt.c
===================================================================
--- /trunk/pswarp/src/pswarpTransformReadout_Opt.c	(revision 14873)
+++ /trunk/pswarp/src/pswarpTransformReadout_Opt.c	(revision 14874)
@@ -11,5 +11,6 @@
     psTimerStart ("warp");
 
-    // Get grid size
+    // Get warp parameters
+    bool mdok;
     int nGridX = psMetadataLookupS32(NULL, config->arguments, "GRID.NX");
     int nGridY = psMetadataLookupS32(NULL, config->arguments, "GRID.NY");
@@ -145,5 +146,4 @@
 
     // Transform sources
-    bool mdok;
     psArray *inSources = psMetadataLookupPtr(&mdok, input->analysis, "PSPHOT.SOURCES"); // Sources in source
     if (goodPixels && mdok && inSources) {
