Index: trunk/psModules/src/objects/pmPSF_IO.c
===================================================================
--- trunk/psModules/src/objects/pmPSF_IO.c	(revision 25854)
+++ trunk/psModules/src/objects/pmPSF_IO.c	(revision 25979)
@@ -49,4 +49,5 @@
 #include "pmSource.h"
 #include "pmModelClass.h"
+#include "pmModelUtils.h"
 #include "pmSourceIO.h"
 
@@ -267,4 +268,15 @@
         }
         residName = pmFPAfileNameFromRule (rule, file, view);
+
+        // EXTNAME for psf image
+        // rule = psMetadataLookupStr(&status, menu, "PSF.RESID");
+        // if (!rule) {
+        //     psError(PS_ERR_UNKNOWN, false, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config");
+        //     psFree (headName);
+        //     psFree (tableName);
+        //     psFree(hdu);
+        //     return false;
+        // }
+        // residName = pmFPAfileNameFromRule (rule, file, view);
     }
 
@@ -477,4 +489,63 @@
     }
 
+    // write a representation of the psf model
+    {
+        psMetadata *header = psMetadataAlloc ();
+
+        if (0) {
+            // set some header keywords to make it clear there are no residuals?
+            psFitsWriteBlank (file->fits, header, residName);
+            psFree (residName);
+            psFree (header);
+            return true;
+        }
+
+	int DX = 65;
+	int DY = 65;
+
+	psImage *psfMosaic = psImageAlloc (DX, DY, PS_TYPE_F32);
+	psImageInit (psfMosaic, 0.0);
+
+	pmModel *modelRef = pmModelAlloc(psf->type);
+
+	// use the center of the center pixel of the image
+	float xc = 0.5*psf->fieldNx;
+	float yc = 0.5*psf->fieldNy;
+
+	// assign the x and y coords to the image center
+	// create an object with center intensity of 1000
+	modelRef->params->data.F32[PM_PAR_SKY] = 0;
+	modelRef->params->data.F32[PM_PAR_I0] = 1.000;
+	modelRef->params->data.F32[PM_PAR_XPOS] = xc;
+	modelRef->params->data.F32[PM_PAR_YPOS] = yc;
+
+	// create modelPSF from this model
+	pmModel *model = pmModelFromPSF (modelRef, psf);
+	if (model) {
+	    // place the reference object in the image center
+	    pmModelAddWithOffset (psfMosaic, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_CENTER, 0, 0.0, 0.0);
+	    psFree (model);
+	
+	    if (false) {
+		// this call creates an extension with NAXIS3 = 3
+		psArray *images = psArrayAllocEmpty (3);
+		psArrayAdd (images, 1, psfMosaic);
+		// psArrayAdd (images, 1, psfModel);
+		// psArrayAdd (images, 1, psfModel);
+
+		psFitsWriteImageCube (file->fits, header, images, "PSF_MODEL");
+		psFree (images);
+	    } else {
+		// this call creates an extension with NAXIS3 = 1
+		// XXX need to replace PSF_MODEL with rule-based name like residName
+		psFitsWriteImage(file->fits, header, psfMosaic, 0, "PSF_MODEL");
+	    }
+	}
+
+        psFree (psfMosaic);
+        psFree (modelRef);
+        psFree (header);
+    }
+
     return true;
 
@@ -693,5 +764,5 @@
         psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
     } else {
-        psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", nRegions);
+        psMetadataAddS32 (analysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", nRegions);
 
         for (int i = 0; i < nRegions; i++) {
