Index: trunk/ppSim/src/ppSimLoop.c
===================================================================
--- trunk/ppSim/src/ppSimLoop.c	(revision 14531)
+++ trunk/ppSim/src/ppSimLoop.c	(revision 14657)
@@ -1,5 +1,5 @@
 #include "ppSim.h"
 
-psExit ppSimLoop(pmConfig *config)
+bool ppSimLoop(pmConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, PS_EXIT_PROG_ERROR);
@@ -29,7 +29,10 @@
     pmFPAview *view = pmFPAviewAlloc(0);// View for iterating over FPA
 
+    // XXX if we include the psphot analysis, we will need to activate the correct pmFPAfiles
+    // at the correct times.  ppSim operates on PPSIM.OUTPUT and PPSIM.SOURCES
+
     // load any needed files (eg, input image, PSF)
     if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
-	psError(PSPHOT_ERR_DATA, false, "failed IO for fpa in ppSim\n");
+	psError(PS_ERR_UNKNOWN, false, "failed IO for fpa in ppSim\n");
 	psFree(view);
 	return false;
@@ -43,12 +46,15 @@
 	// load any needed files (eg, input image, PSF)
 	if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
-            psError(PSPHOT_ERR_DATA, false, "failed IO for chip %d in ppSim\n", view->chip);
+            psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d in ppSim\n", view->chip);
 	    psFree (view);
 	    return false;
 	}
 
-	pmPSF *psf = NULL;
 	if (type == PPSIM_TYPE_OBJECT) {
-	    psf = ppSimSetPSF (config);
+	    if (!ppSimSetPSF (chip, config)) {
+		psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d in ppSim\n", view->chip);
+		psFree (view);
+		return false;
+	    }
 	}
 
@@ -64,5 +70,5 @@
                 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "CELL.READDIR = 1 is the only supported mode.");
                 psFree(rng);
-                return PS_EXIT_CONFIG_ERROR;
+                return false;
             }
 
@@ -74,6 +80,6 @@
 
 		// TO DO: Decide if cell is to be windowed, reduce numCols, numRows appropriately
-                psImage *signal = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Signal in pixels
-                psImage *variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Noise in pixels
+                readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Signal in pixels
+                readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Noise in pixels
 
                 psImage *expCorr = NULL; // Exposure correction per pixel, for adding objects
@@ -82,24 +88,20 @@
                 }
 
-		psVector *biasRows = ppSimMakeBias (signal, variance, cell, config, rng);
+		psVector *biasRows = ppSimMakeBias (readout, config, rng);
 		if (type == PPSIM_TYPE_BIAS) goto done;
 		
-		ppSimMakeDark (signal, variance, config);
+		ppSimMakeDark (readout, config);
 		if (type == PPSIM_TYPE_DARK) goto done;
 
-		ppSimMakeSky (signal, variance, expCorr, type, config, fpa, chip, cell);
+		ppSimMakeSky (readout, expCorr, type, config);
 		if (type == PPSIM_TYPE_FLAT) goto done;
 
 		if (type == PPSIM_TYPE_OBJECT) {
-		    ppSimInsertStars (signal, variance, expCorr, stars, config, chip, cell);
+		    ppSimInsertSources (readout, expCorr, stars, config);
 		}
 
 	    done:
-		ppSimAddNoise(signal, variance, config, cell, rng);
-                ppSimSaturate(signal, config, cell);
-
-                readout->image = signal;
-                psFree(variance);
-                psFree(expCorr);
+		ppSimAddNoise(readout->image, readout->weight, cell, config, rng);
+                ppSimSaturate(readout, config);
 
 		ppSimAddOverscan (readout, config, biasCols, biasRows, rng);
@@ -123,5 +125,6 @@
                 psFree(rng);
                 psFree(view);
-                return PS_EXIT_SYS_ERROR;
+                // return PS_EXIT_SYS_ERROR;
+                return false;
             }
         }
@@ -135,5 +138,6 @@
             psFree(rng);
             psFree(view);
-            return PS_EXIT_SYS_ERROR;
+            // return PS_EXIT_SYS_ERROR;
+            return false;
         }
 
@@ -148,5 +152,6 @@
         psFree(rng);
         psFree(view);
-        return PS_EXIT_SYS_ERROR;
+        // return PS_EXIT_SYS_ERROR;
+        return false;
     }
 
@@ -154,4 +159,4 @@
     psFree(view);
 
-    return 0;
+    return true;
 }
