Index: trunk/ppSim/src/ppSimLoop.c
===================================================================
--- trunk/ppSim/src/ppSimLoop.c	(revision 14657)
+++ trunk/ppSim/src/ppSimLoop.c	(revision 14667)
@@ -17,7 +17,7 @@
 
     // Load catalogue stars
-    psArray *stars = NULL;
+    psArray *stars = psArrayAllocEmpty (1);
     if (type == PPSIM_TYPE_OBJECT) {
-	stars = ppSimLoadStars (fpa, config);
+	ppSimLoadStars (stars, fpa, config);
     }
 
@@ -25,4 +25,10 @@
     if (type == PPSIM_TYPE_OBJECT) {
 	ppSimMakeStars (stars, fpa, config, rng);
+    }
+
+    // Add random galaxies
+    psArray *galaxies = psArrayAllocEmpty (1);
+    if (type == PPSIM_TYPE_OBJECT) {
+	ppSimMakeGalaxies (galaxies, fpa, config, rng);
     }
 
@@ -62,8 +68,5 @@
         while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
 
-            // Size, position and orientation of cell
-            int numCols = psMetadataLookupS32(NULL, cell->concepts, "CELL.XSIZE") / binning;
-            int numRows = psMetadataLookupS32(NULL, cell->concepts, "CELL.YSIZE") / binning;
-
+	    // check that we are able to work with this cell (readdir must be 1)
             int readdir = psMetadataLookupS32(NULL, cell->concepts, "CELL.READDIR"); // Read direction
             if (readdir != 1) {
@@ -73,8 +76,12 @@
             }
 
-	    psVector *biasCols = ppSimMakeBiassec (cell, config);
+	    // if no readout exists, generate a single readout (upgrade to allow multiple
+	    // readouts?)
+	    if (cell->readouts->n == 0) {
+		// Size, position and orientation of cell
+		int numCols = psMetadataLookupS32(NULL, cell->concepts, "CELL.XSIZE") / binning;
+		int numRows = psMetadataLookupS32(NULL, cell->concepts, "CELL.YSIZE") / binning;
 
-	    int numReadouts = 1;
-            for (int i = 0; i < numReadouts; i++) {
+		// generate a new readout for this cell
                 pmReadout *readout = pmReadoutAlloc(cell); // Readout within cell
 
@@ -83,12 +90,32 @@
                 readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Noise in pixels
 
+		psImageInit (readout->image, 0.0);
+		psImageInit (readout->weight, 0.0);
+	    }
+
+	    psVector *biasCols = ppSimMakeBiassec (cell, config);
+
+            for (int i = 0; i < cell->readouts->n; i++) {
+
+		pmReadout *readout = cell->readouts->data[i];
+		assert (readout);
+
+		// if we have not read in a weight or generated a fake image above, we need to
+		// build one here
+		if (!readout->weight) {
+		    if (!pmReadoutGenerateWeight(readout, true)) {
+			psError (PS_ERR_UNKNOWN, false, "trouble creating weight");
+			return false;
+		    }
+		}
+
                 psImage *expCorr = NULL; // Exposure correction per pixel, for adding objects
                 if (type == PPSIM_TYPE_OBJECT) {
-                    expCorr = psImageAlloc(numCols, numRows, PS_TYPE_F32);
+                    expCorr = psImageAlloc(readout->image->numCols, readout->image->numRows, PS_TYPE_F32);
                 }
 
 		psVector *biasRows = ppSimMakeBias (readout, config, rng);
 		if (type == PPSIM_TYPE_BIAS) goto done;
-		
+	
 		ppSimMakeDark (readout, config);
 		if (type == PPSIM_TYPE_DARK) goto done;
@@ -99,4 +126,8 @@
 		if (type == PPSIM_TYPE_OBJECT) {
 		    ppSimInsertSources (readout, expCorr, stars, config);
+		}
+
+		if (type == PPSIM_TYPE_OBJECT) {
+		    ppSimInsertGalaxies (readout, expCorr, galaxies, config);
 		}
 
@@ -111,5 +142,4 @@
                 readout->parent->data_exists = true;
                 readout->parent->parent->data_exists = true;
-                psFree(readout);        // Drop reference
             }
             psFree(biasCols);
