Index: trunk/ppImage/src/ppImage.h
===================================================================
--- trunk/ppImage/src/ppImage.h	(revision 5860)
+++ trunk/ppImage/src/ppImage.h	(revision 5976)
@@ -1,2 +1,5 @@
+#ifndef PP_IMAGE_H
+#define PP_IMAGE_H
+
 #include <stdio.h>
 #include <strings.h>
@@ -22,87 +25,129 @@
 
 #define RECIPE "PHASE2"                 // Name of the recipe to use
+#define TIMERNAME "ppImage"             // Name of timer
 
+// How much of the FPA to load at a time
 typedef enum {
-    PP_LOAD_NONE,
-    PP_LOAD_FPA,
-    PP_LOAD_CHIP,
-    PP_LOAD_CELL,
+    PP_LOAD_NONE,                       // Don't load anything
+    PP_LOAD_FPA,                        // Load the entire FPA at once
+    PP_LOAD_CHIP,                       // Load by chip
+    PP_LOAD_CELL,                       // Load by cell
 } ppImageLoadDepth;
 
+// Configuration data
 typedef struct {
-    psMetadata *site;
-    psMetadata *camera;
-    psMetadata *recipe;
-    psMetadata *arguments;
-    psDB       *database;
+    psMetadata *site;                   // The site configuration
+    psMetadata *camera;                 // The camera configuration
+    psMetadata *recipe;                 // The recipe (i.e., specific setups)
+    psMetadata *arguments;              // The command-line arguments
+    psDB       *database;               // Database handle
 } ppConfig;
 
+// Options
 typedef struct {
-    bool doMask;			// Mask bad pixles
-    bool doBias;			// Bias subtraction
-    bool doDark;			// Dark subtraction
-    bool doFlat;			// Flat-field normalisation
-    bool doFringe;			// Fringe subtraction
-    bool doSource;			// Source identification and photometry
-    bool doAstrom;			// Astrometry
+    bool doMask;                        // Mask bad pixels
+    bool doBias;                        // Bias subtraction
+    bool doDark;                        // Dark subtraction
+    bool doFlat;                        // Flat-field normalisation
+    bool doFringe;                      // Fringe subtraction
+    bool doSource;                      // Source identification and photometry
+    bool doAstrom;                      // Astrometry
 
-    bool doOverscan;			// Overscan subtraction
-    int overscanBins;			// Number of pixels per bin for overscan
-    psStats *overscanStats;		// Statistics for overscan
-    void *overscanFit;			// Overscan fit (polynomial or spline)
-    pmFit overscanFitType;		// Fit type for overscan
-    pmOverscanAxis overscanMode;	// Axis for overscan
+    bool doOverscan;                    // Overscan subtraction
+    int overscanBins;                   // Number of pixels per bin for overscan
+    psStats *overscanStats;             // Statistics for overscan
+    void *overscanFit;                  // Overscan fit (polynomial or spline)
+    pmFit overscanFitType;              // Fit type for overscan
+    pmOverscanAxis overscanMode;        // Axis for overscan
 
-    bool doNonLin;			// Non-linearity correction
+    bool doNonLin;                      // Non-linearity correction
     psDataType nonLinearType;
     psMetadataItem *nonLinearData;
     void *nonLinearSource;
 
-    ppImageLoadDepth imageLoadDepth;
+    ppImageLoadDepth imageLoadDepth;    // How much of the FPA to load at once
 } ppOptions;
 
+// A file to process
 typedef struct {
-    char *filename;
-    pmFPA *fpa;
-    psFits *fits;
-    psMetadata *header;
-} ppFPA; 
+    char *filename;                     // File name
+    psFits *fits;                       // The FITS file handle
+    psMetadata *phu;                    // The FITS header
+    pmFPA *fpa;                         // The FPA, with pixels and extensions
+} ppFile;
 
+// The data to be processed
 typedef struct {
-    ppFPA *input;
-    ppFPA *mask;
-    ppFPA *bias;
-    ppFPA *dark;
-    ppFPA *flat;
-    ppFPA *fringe;
-    ppFPA *process;
+    ppFile *input;                      // The input, to be operated upon
+    ppFile *mask;                       // The bad pixel mask image
+    ppFile *bias;                       // The bias correction image
+    ppFile *dark;                       // The dark correction image
+    ppFile *flat;                       // The flat-field correction image
+    ppFile *fringe;                     // The fringe correction image
+#if 0
+    ppFile *process;                    // A dummy file pointing out what needs to be processed
+#endif
 } ppData;
 
+// Cells to be used in the detrend
 typedef struct {
-    pmCell *input;
-    pmCell *mask;
-    pmCell *bias;
-    pmCell *dark;
-    pmCell *flat;
+    pmCell *input;                      // The input cell, to be operated upon
+    pmCell *mask;                       // The bad pixel mask
+    pmCell *bias;                       // The bias correction
+    pmCell *dark;                       // The dark correction
+    pmCell *flat;                       // The flat-field correction
 } ppDetrend;
 
-bool ppImageConfig (ppConfig *config, int argc, char **argv);
-bool ppImageLoadPixels (ppFPA *input, ppFPA *process, psDB *db, int nChip, int nCell);
-bool ppImageLoop (ppData *data, ppOptions *options, ppConfig *config);
-bool ppImageOptions (ppData *data, ppOptions *options, ppConfig *config);
-bool ppImageParseCamera (ppData *data, ppConfig *config);
-bool ppImageParseDetrend (ppData *data, ppOptions *options, ppConfig *config);
 
-bool ppReadoutWeights (pmReadout *readout);
+// Allocators
+ppFile *ppFileAlloc(void);
 
-bool ppDetrendCell (ppDetrend *detrend, ppOptions *options, ppConfig *config);
 
-bool ppDetrendMask (pmCell *cell, pmReadout *input, pmReadout *mask);
-bool ppDetrendNonLinear (pmCell *cell, pmReadout *input, ppOptions *options);
-bool ppDetrendNonLinearLookup (pmReadout *input, psMetadataItem *dataItem);
-bool ppDetrendNonLinearPolynomial (pmReadout *input, psMetadataItem *dataItem);
-bool ppDetrendBias (pmCell *inputCell, pmReadout *inputReadout, pmReadout *pedestal, ppOptions *options);
-pmReadout* ppDetrendPedestal (pmReadout *pedestal, pmCell *input, pmReadout *bias, pmReadout *dark, float darkTime, ppOptions *options);
-pmReadout* ppDetrendSelectFirst (pmCell *cell, char *name, bool doThis);
 
-bool ppFPAOpen (ppFPA *fpa, psMetadata *camera, char *name, bool doThis);
+// Parse the site configuration (and camera and recipe if specified); read the command-line arguments
+bool ppImageConfig(ppConfig *config,   // The configuration(output)
+                   int argc, char **argv // Command-line arguments
+                   );
+
+// Determine what type of camera, and initialise
+bool ppImageParseCamera(ppData *data,   // The data to be processed
+                        ppConfig *config // Configuration
+                        );
+
+// Determine the procession options
+bool ppImageOptions(ppData *data,       // The data to be processed
+                    ppOptions *options, // Processing options
+                    ppConfig *config    // Configuration
+                    );
+
+
+// Loop over the
+bool ppImageLoop(ppData *data, ppOptions *options, ppConfig *config);
+
+// Load the pixels for the given file
+bool ppImageLoadPixels(ppFile *input,   // File for which to load the pixels
+                       psDB *db,        // Database handle (for reading concepts)
+                       int nChip,       // Chip number to load
+                       int nCell        // Cell number to load
+                       );
+
+bool ppImageParseDetrend(ppData *data, ppOptions *options, ppConfig *config);
+
+bool ppReadoutWeights(pmReadout *readout);
+
+bool ppDetrendCell(ppDetrend *detrend, ppOptions *options, ppConfig *config);
+
+bool ppDetrendMask(pmCell *cell, pmReadout *input, pmReadout *mask);
+bool ppDetrendNonLinear(pmCell *cell, pmReadout *input, ppOptions *options);
+bool ppDetrendNonLinearLookup(pmReadout *input, psMetadataItem *dataItem);
+bool ppDetrendNonLinearPolynomial(pmReadout *input, psMetadataItem *dataItem);
+bool ppDetrendBias(pmCell *inputCell, pmReadout *inputReadout, pmReadout *pedestal, ppOptions *options);
+pmReadout* ppDetrendPedestal(pmReadout *pedestal, pmCell *input, pmReadout *bias, pmReadout *dark, float darkTime, ppOptions *options);
+pmReadout* ppDetrendSelectFirst(pmCell *cell, char *name, bool doThis);
+
+#if 0
+bool ppFileOpen(ppFile *fpa, psMetadata *camera, char *name, bool doThis);
+#endif
+
+
+#endif // Pau.
