Index: trunk/ppSim/src/ppSim.h
===================================================================
--- trunk/ppSim/src/ppSim.h	(revision 12996)
+++ trunk/ppSim/src/ppSim.h	(revision 14463)
@@ -1,10 +1,32 @@
 #ifndef PP_SIM_H
 #define PP_SIM_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <strings.h>
+#include <pslib.h>
+#include <psmodules.h>
+#include <psastro.h>
 
 #define PPSIM_RECIPE "PPSIM"
 #define OUTPUT_FILE "PPSIM.OUTPUT"
 
+// Compare a value with minimum and maximum values, replacing where required.
+#define COMPARE(VALUE,MIN,MAX) { \
+        if (VALUE < MIN) { MIN = VALUE; } \
+        if (VALUE > MAX) { MAX = VALUE; } \
+    }
+
+// Return cell position, given an FPA position; calculations are all done in pixel units
+#define PPSIM_FPA_TO_CELL(pos, cell0, cellParity, binning, chip0, chipParity) \
+    (((pos) - (chip0))*(chipParity) - (cell0))*(cellParity) / (binning)
 
 
+// Return FPA position, given a cell position; calculations are all done in pixel units
+#define PPSIM_CELL_TO_FPA(pos, cell0, cellParity, binning, chip0, chipParity) \
+    ((chip0) + (binning)*(chipParity)*((cell0) + (cellParity)*(pos)))
 
 // Type of image to simulate
@@ -16,9 +38,21 @@
 } ppSimType;
 
+typedef struct {
+    double ra;
+    double dec;
+    float mag;
+    float x;
+    float y;
+    float flux;
+    float peak;
+} ppSimStar;
+
+
+ppSimStar *ppSimStarAlloc ();
 
 /// Parse command-line arguments
 void ppSimArguments(int argc, char *argv[], ///< Command-line arguments
-                    pmConfig *config ///< Configuration
-    );
+		    pmConfig *config ///< Configuration
+		    );
 
 /// Create output file
@@ -26,11 +60,58 @@
 /// Returns a borrowed pointer to the FPA file.
 pmFPAfile *ppSimCreate(pmConfig *config ///< Configuration
-    );
+		       );
+
+// Return bounds of a chip, based on the concepts
+psRegion *ppSimChipBounds(const pmChip *chip, // Chip for which to determine size
+			  pmFPAview *view // View for chip
+			  );
+
+// Return bounds of an FPA, based on the concepts
+psRegion *ppSimFPABounds(const pmFPA *fpa       // FPA for which to determine size
+			 );
 
 /// Loop over the output file, generating simulated data
 psExit ppSimLoop(pmConfig *config ///< Configuration
-    );
+		 );
 
+// Add a star into the signal and variance images
+bool ppSimInsertStar(psImage *signal,       // Signal image, to which to add star
+		     psImage *variance,     // Variance image, to which to add star
+		     float x0, float y0,    // Position of star
+		     float peak,            // Peak flux of star
+		     float noise,           // Rough noise estimate
+		     float seeing,          // Seeing for star
+		     const psImage *correction // Exposure correction as a function of position
+		     );
 
+psArray *ppSimLoadStars (pmFPA *fpa, pmConfig *config);
+bool ppSimMakeStars(psArray *stars, pmFPA *fpa, pmConfig *config, const psRandom *rng);
+
+psVector *ppSimMakeBiassec (pmCell *cell, pmConfig *config);
+psVector *ppSimMakeBias (psImage *signal, psImage *variance, pmCell *cell, pmConfig *config, const psRandom *rng) ;
+bool ppSimMakeDark (psImage *signal, psImage *variance, pmConfig *config);
+bool ppSimMakeSky (psImage *signal, psImage *variance, psImage *expCorr, ppSimType type, pmConfig *config, pmFPA *fpa, pmChip *chip, pmCell *cell);
+bool ppSimInsertStars (psImage *signal, psImage *variance, psImage *expCorr, psArray *stars, pmConfig *config, pmChip *chip, pmCell *cell);
+
+bool ppSimInitHeader(pmConfig *config,
+		     pmFPA *fpa,
+		     pmChip *chip,
+		     pmCell *cell);
+
+bool ppSimSaturate(psImage *image,	// Image to apply saturation
+		   const pmConfig *config,		       
+		   const pmCell *cell); // Saturation level
+
+bool ppSimUpdateConceptsFPA (pmFPA *fpa, pmConfig *config);
+bool ppSimUpdateConceptsCell (pmCell *cell, pmConfig *config);
+
+bool ppSimAddOverscan (pmReadout *readout, pmConfig *config, psVector *biasCols, psVector *biasRows, psRandom *rng);
+
+psImage *ppSimAddNoise(psImage *signal, // Signal image, modified and returned
+		       const psImage *variance, // Variance image
+		       const pmConfig *config,		       
+		       const pmCell *cell,
+		       const psRandom *rng // Random number generator
+		       );
 
 #endif
