Index: trunk/ppSub/src/ppSub.h
===================================================================
--- trunk/ppSub/src/ppSub.h	(revision 23688)
+++ trunk/ppSub/src/ppSub.h	(revision 23740)
@@ -14,6 +14,9 @@
 #define PP_SUB_H
 
+#include <stdio.h>
 #include <pslib.h>
 #include <psmodules.h>
+
+#include "ppSubErrorCodes.h"
 
 /// @addtogroup ppSub
@@ -24,13 +27,24 @@
 // Output files, for activation/deactivation
 typedef enum {
-    PPSUB_FILES_IMAGE = 0x01,           // Image files
-    PPSUB_FILES_PHOT  = 0x02,           // Photometry files
-    PPSUB_FILES_ALL   = 0xFF,           // All files
+    PPSUB_FILES_INPUT    = 0x01,        // Input files
+    PPSUB_FILES_CONV     = 0x02,        // Convolved files (output)
+    PPSUB_FILES_SUB      = 0x04,        // Subtracted files (output)
+    PPSUB_FILES_INV      = 0x08,        // Inverse subtracted files (output)
+    PPSUB_FILES_PSF      = 0x10,        // PSF files (output)
+    PPSUB_FILES_PHOT_SUB = 0x20,        // Subtraction photometry files (output)
+    PPSUB_FILES_PHOT_INV = 0x40,        // Inverse subtraction photometry files (output)
+    PPSUB_FILES_PHOT     = 0x80,        // General photometry files (internal)
+    PPSUB_FILES_ALL      = 0xFF,        // All files
 } ppSubFiles;
 
 /// Data for processing
 typedef struct {
-    psErrorCode quality;                /// Quality code; 0 for no problem
-    psMetadata *stats;                  /// Statistics
+    psErrorCode quality;                // Quality code; 0 for no problem
+    bool photometry;                    // Perform photometry?
+    bool inverse;                       // Output inverse subtraction as well?
+    psString stamps;                    // Stamps file
+    pmPSF *psf;                         // Point Spread Function
+    FILE *statsFile;                    // Statistics file
+    psMetadata *stats;                  // Statistics
 } ppSubData;
 
@@ -39,70 +53,62 @@
 
 /// Setup the arguments parsing
-bool ppSubArgumentsSetup(int argc, char *argv[], ///< Command-line arguments
-                         pmConfig *config    ///< Configuration
-    );
-
-/// Parse the arguments
-bool ppSubArgumentsParse(pmConfig *config ///< Configuration
+bool ppSubArguments(int argc, char *argv[], ///< Command-line arguments
+                    pmConfig *config, ///< Configuration
+                    ppSubData *data ///< Processing data
     );
 
 /// Parse the camera input
-bool ppSubCamera(pmConfig *config       ///< Configuration
+bool ppSubCamera(pmConfig *config,      ///< Configuration
+                 ppSubData *data        ///< Processing data
     );
 
 /// Loop over the FPA hierarchy
-bool ppSubLoop(pmConfig *config         ///< Configuration
+bool ppSubLoop(pmConfig *config,        ///< Configuration
+               ppSubData *data          ///< Processing data
     );
 
 /// Perform PSF-matched image subtraction on the readout
 bool ppSubReadout(pmConfig *config,     ///< Configuration
-                  ppSubData *data,      ///< Processing data
-                  const pmFPAview *view ///< View of readout to subtract
+                  ppSubData *data       ///< Processing data
     );
 
 /// Generate (if needed) and set or update the masks for input and reference images
-bool ppSubSetMasks(pmConfig *config,     ///< Configuration
-                   const pmFPAview *view ///< View of active readout
+bool ppSubSetMasks(pmConfig *config     ///< Configuration
     );
 
 /// Generate the PSF-matching kernel and convolve the images as needed.  Most of this function involves
 /// looking up the parameters in the recipe and supplying them to the function pmSubtractionMatch()
-bool ppSubMatchPSFs(pmConfig *config,    ///< Configuration
-                    ppSubData *data,    ///< Processing data
-                    const pmFPAview *view ///< View of active readout
+bool ppSubMatchPSFs(pmConfig *config,   ///< Configuration
+                    ppSubData *data     ///< Processing data
     );
 
 /// Generate the output readout and pass the kernel info to the header
-bool ppSubDefineOutput(pmConfig *config, ///< Configuration
-                       const pmFPAview *view ///< View of active readout
+bool ppSubDefineOutput(const char *name,///< Name of output to define
+                       pmConfig *config ///< Configuration
     );
 
 /// Photometry stage 1: measure the PSF from the minuend image
-bool ppSubMakePSF(pmConfig *config,       ///< Configuration
-                  ppSubData *data,    ///< Processing data
-                  const pmFPAview *view ///< View of active readout
+bool ppSubMakePSF(pmConfig *config,     ///< Configuration
+                  ppSubData *data       ///< Processing data
     );
 
 /// Perform the actual image subtraction, update output concepts
-bool ppSubReadoutSubtract(pmConfig *config,       ///< Configuration
-                          const pmFPAview *view ///< View of active readout
+bool ppSubReadoutSubtract(pmConfig *config ///< Configuration
     );
 
 
 /// Photometry stage 2: find and measure sources on the subtracted image
-bool ppSubReadoutPhotometry(pmConfig *config,     ///< Configuration
-                            ppSubData *data,    ///< Processing data
-                            const pmFPAview *view ///< View of active readout
+bool ppSubReadoutPhotometry(const char *name, ///< Name of file to photometer
+                            pmConfig *config, ///< Configuration
+                            ppSubData *data ///< Processing data
     );
 
 /// Renormalize, update headers and generate JPEGs
 bool ppSubReadoutUpdate(pmConfig *config, ///< Configuration
-                        ppSubData *data,    ///< Processing data
-                        const pmFPAview *view ///< View of active readout
+                        ppSubData *data ///< Processing data
     );
 
 /// Higher-order background subtraction
-bool ppSubBackground(pmConfig *config,  ///< Configuration
-                     const pmFPAview *view ///< View to readout
+bool ppSubBackground(pmConfig *config   ///< Configuration
     );
 
@@ -121,4 +127,40 @@
     );
 
+
+/// Activate or deactivate files
+void ppSubFilesActivate(pmConfig *config, // Configuration
+                        ppSubFiles files, // File to activate/deactivate
+                        bool state      // Activation state
+    );
+
+/// Generate a view suitable for a readout
+///
+/// Assumes we're working with skycells
+pmFPAview *ppSubViewReadout(void);
+
+/// Iterate down the FPA hierarchy, opening files
+bool ppSubFilesIterateDown(pmConfig *config, // Configuration
+                           ppSubFiles files // Files to open
+    );
+
+/// Iterate up the FPA hierarchy, closing files
+bool ppSubFilesIterateUp(pmConfig *config, // Configuration
+                         ppSubFiles files // Files to open
+    );
+
+/// Collect statistics
+bool ppSubReadoutStats(pmConfig *config,// Configuration
+                       ppSubData *data  // Processing data
+    );
+
+/// Generate JPEG images
+bool ppSubReadoutJpeg(pmConfig *config  // Configuration
+    );
+
+/// Generate inverse subtraction
+bool ppSubReadoutInverse(pmConfig *config // Configuration
+    );
+
+
 // Copy every instance of a single keyword from one metadata to another
 bool psMetadataCopySingle(psMetadata *target, psMetadata *source, const char *name);
