Index: trunk/ppSim/src/ppSimCreate.c
===================================================================
--- trunk/ppSim/src/ppSimCreate.c	(revision 14531)
+++ trunk/ppSim/src/ppSimCreate.c	(revision 14657)
@@ -1,3 +1,9 @@
 # include "ppSim.h"
+
+// XXX this function forces us to define the camera (on the command line) and format (via the
+// PPSIM.OUTPUT entry).  In this case, we need to set config->format,formatName based on these
+// values.  This will be a problem when we want to load an input image (in order to add fake
+// stars).  We will need to add some logic in ppSimArguments to distinguish the cases of 1)
+// input image and 2) specified camera
 
 pmFPAfile *ppSimCreate(pmConfig *config)
@@ -12,5 +18,4 @@
 
     pmFPAfile *file = pmFPAfileDefineOutput(config, fpa, OUTPUT_FILE);
-    psFree(fpa);
     if (!file) {
         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to create output file from %s.  "
@@ -20,4 +25,5 @@
     if (file->type != PM_FPA_FILE_IMAGE) {
         psError(PS_ERR_BAD_PARAMETER_TYPE, true, "%s type is not IMAGE", OUTPUT_FILE);
+	psFree(fpa);
         psFree(file);
         return NULL;
@@ -25,13 +31,29 @@
     file->save = true;
 
+    config->format = psMemIncrRefCounter (file->format);
+    config->formatName = psStringCopy (file->formatName);
+
     // have we supplied a psf model?
     if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) {
 	bool status = false;
+
+	// tie the psf file to the chipMosaic 
         pmFPAfileBindFromArgs(&status, file, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
         if (!status) {
             psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD");
-            return status;
+	    psFree(fpa);
+	    psFree(file);
+            return NULL;
         }
     }
+
+    // XXX only invoke this code for OBJECT types of images
+    // PPSIM.SOURCES carries the constructed, fake sources with their true parameters
+    pmFPAfile *simSources = pmFPAfileDefineOutput (config, file->fpa, "PPSIM.SOURCES");
+    if (!simSources) {
+        psError(PS_ERR_UNKNOWN, false, "Cannot find a rule for PPSIM.SOURCES");
+        return false;
+    }
+    simSources->save = true;
 
     pmFPALevel phuLevel = pmFPAPHULevel(file->format); // Level at which PHU goes
@@ -44,4 +66,5 @@
             psFree(fpa);
             psFree(view);
+	    psFree(file);
             return NULL;
         }
@@ -55,4 +78,5 @@
                 psFree(fpa);
                 psFree(view);
+		psFree(file);
                 return NULL;
             }
@@ -66,4 +90,5 @@
                     psFree(fpa);
                     psFree(view);
+		    psFree(file);
                     return NULL;
                 }
@@ -71,4 +96,6 @@
         }
     }
+
+    psFree(fpa);
     psFree(view);
 
