Index: trunk/ppStack/src/ppStack.h
===================================================================
--- trunk/ppStack/src/ppStack.h	(revision 23195)
+++ trunk/ppStack/src/ppStack.h	(revision 23341)
@@ -1,4 +1,4 @@
-#ifndef PP_STACK_H
-#define PP_STACK_H
+#ifndef PPSTACK_H
+#define PPSTACK_H
 
 #define PPSTACK_RECIPE "PPSTACK"        // Name of the recipe
@@ -18,47 +18,12 @@
 } ppStackMask;
 
-// Thread for stacking chunks
-//
-// Each input file contributes a readout, into which is read a chunk from that file
-typedef struct {
-    psArray *readouts;                  // Input readouts to read and stack
-    bool read;                          // Has the scan been read?
-    bool busy;                          // Is the scan being processed?
-    int firstScan;                      // First row of the chunk to be read for this group
-    int lastScan;                       // Last row of the chunk to be read for this group
-} ppStackThread;
+// List of files
+typedef enum {
+    PPSTACK_FILES_PREPARE,              // Files for preparation
+    PPSTACK_FILES_CONVOLVE,             // Files for convolution
+    PPSTACK_FILES_COMBINE,              // Files for combination
+    PPSTACK_FILES_PHOT                  // Files for photometry
+} ppStackFileList;
 
-// Allocator
-ppStackThread *ppStackThreadAlloc(psArray *readouts // Inputs readouts to read and stack
-    );
-
-// Data for threads
-typedef struct {
-    psArray *threads;                   // Threads doing stacking
-    int lastScan;                       // Last row that's been read
-    psArray *imageFits;                 // FITS file pointers for images
-    psArray *maskFits;                  // FITS file pointers for masks
-    psArray *varianceFits;                // FITS file pointers for variances
-} ppStackThreadData;
-
-// Set up thread data
-ppStackThreadData *ppStackThreadDataSetup(const psArray *cells, // Array of input cells
-                                          const psArray *imageNames, // Names of images to read
-                                          const psArray *maskNames, // Names of masks to read
-                                          const psArray *varianceNames, // Names of variance maps to read
-                                          const psArray *covariances, // Covariance matrices (already read)
-                                          const pmConfig *config // Configuration
-    );
-
-// Read chunk into the first available file thread
-ppStackThread *ppStackThreadRead(bool *status, // Status of read
-                                 ppStackThreadData *stack, // Stacks available for reading
-                                 pmConfig *config, // Configuration
-                                 int numChunk, // Chunk number (only for interest)
-                                 int overlap // Overlap between subsequent scans
-    );
-
-// Initialise the threads
-void ppStackThreadInit(void);
 
 // Setup command-line arguments
@@ -73,8 +38,4 @@
 // Parse cameras
 bool ppStackCamera(pmConfig *config     // Configuration
-    );
-
-// Loop over the inputs, doing the combination
-bool ppStackLoop(pmConfig *config       // Configuration
     );
 
@@ -127,10 +88,4 @@
     );
 
-// Perform photometry on stack
-bool ppStackPhotometry(pmConfig *config, // Configuration
-                       const pmReadout *readout, // Readout to be photometered
-                       const pmFPAview *view // View to readout
-    );
-
 // Return software version
 psString ppStackVersion(void);
@@ -171,3 +126,46 @@
     );
 
+/// Dump memory debugging information
+void ppStackMemDump(
+    const char *name                    ///< Stage name, for inclusion in the output file name
+    );
+
+/// Activate/deactivate a list of files
+void ppStackFileActivation(
+    pmConfig *config,                   // Configuration
+    ppStackFileList list,               // Files to turn on/off
+    bool state                          // Activation state
+    );
+
+// Activate/deactivate a single element for a list
+void ppStackFileActivationSingle(
+    pmConfig *config,                   // Configuration
+    ppStackFileList list,               // Files to turn on/off
+    bool state,                         // Activation state
+    int num                             // Number of file in sequence
+    );
+
+/// Iterate down the hierarchy, loading files
+///
+/// We can get away with this simplistic treatment of the FPA hierarchy because we're working on skycells.
+pmFPAview *ppStackFilesIterateDown(
+    pmConfig *config                    // Configuration
+    );
+
+/// Iterate up the hierarchy, writing files
+///
+/// We can get away with this simplistic treatment of the FPA hierarchy because we're working on skycells.
+bool ppStackFilesIterateUp(
+    pmConfig *config                    // Configuration
+    );
+
+/// Write an image to a FITS file
+bool ppStackWriteImage(
+    const char *name,                   // Name of image
+    psMetadata *header,                 // Header
+    const psImage *image,               // Image
+    pmConfig *config                    // Configuration
+    );
+
+
 #endif
