Index: /trunk/ppStats/src/Makefile.am
===================================================================
--- /trunk/ppStats/src/Makefile.am	(revision 13992)
+++ /trunk/ppStats/src/Makefile.am	(revision 13993)
@@ -1,2 +1,3 @@
+
 lib_LTLIBRARIES = libppStats.la
 libppStats_la_CPPFLAGS = $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
@@ -8,30 +9,21 @@
 ppStats_LDADD 	= libppStats.la
 
+ppStats_SOURCES =		\
+	ppStats.c	        
+
 libppStats_la_SOURCES = 		\
-	ppStats.c			\
+	ppStatsFPA.c			\
 	ppStatsData.c			\
 	ppStatsFringe.c			\
 	ppStatsLoop.c			\
 	ppStatsSetupFromRecipe.c	\
-	ppStatsVersion.c
-
-ppStats_SOURCES =		\
-	ppStatsData.c		\
-	ppStatsLoop.c		\
-	ppStatsSetupFromArgs.c	\
-	ppStatsStandAlone.c	\
+	ppStatsSetupFromArgs.c          \
 	ppStatsVersion.c
 
 include_HEADERS = 			\
-	ppStats.h			\
-	ppStatsData.h			\
-	ppStatsFringe.h			\
-	ppStatsLoop.h			\
-	ppStatsSetupFromRecipe.h	\
-	ppStatsVersion.h
+	ppStats.h
 
 noinst_HEADERS = 		\
-	ppStats.h		\
-	ppStatsSetupFromArgs.h
+	ppStatsInternal.h
 
 CLEANFILES = *~
Index: /trunk/ppStats/src/ppStats.c
===================================================================
--- /trunk/ppStats/src/ppStats.c	(revision 13992)
+++ /trunk/ppStats/src/ppStats.c	(revision 13993)
@@ -1,65 +1,91 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+# include "ppStatsInternal.h"
 
-#include <stdio.h>
-#include <pslib.h>
-#include <psmodules.h>
+int main(int argc, char **argv) {
 
-#include "ppStats.h"
+    psExit status = PS_EXIT_SUCCESS;
 
-psMetadata *ppStats(psMetadata *out,
-		    pmFPA *fpa,         // FPA for which to get statistics
-                    pmFPAview *view,    // View for analysis
-                    psMaskType maskVal, // Value to mask
-                    pmConfig *config    // Configuration
-    )
-{
-    PS_ASSERT_PTR_NON_NULL(fpa, NULL)
-    PS_ASSERT_PTR_NON_NULL(view, NULL);
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    psLibInit(NULL);
+    psTimerStart("PPSTATS");
 
-    ppStatsData *data = ppStatsDataAlloc(); // All the input data
+    // Parse the configuration and arguments
+    pmConfig *config = pmConfigRead(&argc, argv, PPSTATS_RECIPE);
+    if (!config) {
+        psErrorStackPrint(stderr, "Unable to read configuration.\n");
+        exit(PS_EXIT_CONFIG_ERROR);
+    }
 
     // Get the options, open the files
-    if (!ppStatsSetupFromRecipe(data, config)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to get ppStats options from recipe.");
-        psFree(data);
-        return NULL;
+    ppStatsData *data = ppStatsSetupFromArgs(&argc, argv, config);
+    if (!data) {
+        psErrorStackPrint(stderr, "Unable to parse command-line arguments.\n");
+        exit(PS_EXIT_CONFIG_ERROR);
     }
 
-    // Override recipe mask value if one is provided
-    if (maskVal != 0) {
-        data->maskVal = maskVal;
+    // Output filename is optional
+    const char *outName = NULL;         // Output file name
+    FILE *outFile = stdout;             // Output file
+    if (argc == 2) {
+        outName = argv[1];
+        psString resolved = pmConfigConvertFilename(outName, config, true); // Resolved filename
+
+        if (resolved && strlen(resolved) > 0) {
+            outFile = fopen(resolved, "w");
+            if (!outFile) {
+                psLogMsg("ppStats", PS_LOG_ERROR, "Unable to open output file %s\n", resolved);
+                psFree(resolved);
+                // XXX this could be a system or config error, but not a data error
+                status = PS_EXIT_CONFIG_ERROR;
+                goto die;
+            }
+        } else {
+            psErrorStackPrint(stderr, "Unable to open output file %s.\n", resolved);
+            exit(PS_EXIT_CONFIG_ERROR);
+        }
+        psFree(resolved);
     }
 
-    if (data->fpa) {
-        psFree(data->fpa);
+    // Go through the FPA and do the hard work
+    psMetadata *results = ppStatsLoop(&status, data, config);
+    if (status != PS_EXIT_SUCCESS) {
+        psErrorStackPrint(stderr, "Error in stats loop.\n");
+        exit (status);
     }
-    data->fpa = psMemIncrRefCounter(fpa);
-
-    if (data->view) {
-        psFree(data->view);
-    }
-    data->view = psMemIncrRefCounter(view);
-
-    // Go through the FPA and do the hard work
-    psExit status;                      // Status of statistics loop
-    psMetadata *result = ppStatsLoop(&status, data, config);
-    if (status != PS_EXIT_SUCCESS) {
-        psError (PS_ERR_UNKNOWN, false, "Not able to measure FPA statistics.\n");
-        psFree(result);
-        psFree(data);
-        return (NULL);
+    if (psListLength(results->list) == 0) {
+        psErrorStackPrint(stderr, "No output.\n");
+        exit (status);
     }
 
-    if (out != NULL) {
-	psMetadataCopy (out, result);
-	psFree(result);
-	psFree(data);
-	return out;
+    if (data->fileLevel) {
+        const char *level = pmFPALevelToName(pmFPAPHULevel(config->format)); // Level for file
+        psMetadataAddStr(results, PS_LIST_HEAD, "FILE.LEVEL", 0, "File level", level);
     }
 
+    // Format and print the output
+    psString output = psMetadataConfigFormat(results);
+    if (!output) {
+        psErrorStackPrint(stderr, "Unable to generate configuration file with result.\n");
+        psFree(results);
+        exit(PS_EXIT_CONFIG_ERROR);
+    }
+    fprintf(outFile, "%s", output);
+    psFree(output);
+
+    // Clean up
+    psFree(results);
+    if (outName) {
+        fclose(outFile);
+    }
+
+    // Common code for the death.
+die:
+    if (status) {
+        psErrorStackPrint (stderr, "failure in %s", __func__);
+    }
     psFree(data);
-    return result;
+    psFree(config);
+    pmConceptsDone();
+    pmConfigDone();
+    psLibFinalize();
+
+    return status;
 }
Index: /trunk/ppStats/src/ppStats.h
===================================================================
--- /trunk/ppStats/src/ppStats.h	(revision 13992)
+++ /trunk/ppStats/src/ppStats.h	(revision 13993)
@@ -1,2 +1,3 @@
+
 #ifndef PP_STATS_H
 #define PP_STATS_H
@@ -4,19 +5,63 @@
 #define PPSTATS_RECIPE "PPSTATS"
 
-#include <psmodules.h>
+typedef struct {
+    // Inputs
+    psFits *fits;                       // Input file handle
+    pmFPA *fpa;                         // FPA to analyse
+    pmFPAview *view;                    // View to analyse
+    // Stuff to output
+    psStats *stats;                     // Statistics to calculate
+    bool doStats;                       // Do statistics?
+    bool fileLevel;                     // Output file level?
+    psList *headers;                    // Headers to read
+    psList *concepts;                   // Concepts to read
+    psList *summary;                    // Summary statistics to calculate
+    // Options for input data
+    float sample;                       // Fraction of cell to sample for statistics
+    psMaskType maskVal;                 // Mask value for images
+    psList *chips;                      // Chips to look at
+    psList *cells;                      // Cells to look at
+} ppStatsData;
 
-#include "ppStatsData.h"
-#include "ppStatsSetupFromRecipe.h"
-#include "ppStatsLoop.h"
-#include "ppStatsVersion.h"
-#include "ppStatsFringe.h"
+// Allocator
+ppStatsData *ppStatsDataAlloc(void);
 
-// Perform the ppStats steps
-psMetadata *ppStats(psMetadata *out,
-                    pmFPA *fpa,         // FPA for which to get statistics
-                    pmFPAview *view,    // View for analysis
-                    psMaskType maskVal, // Value to mask
-                    pmConfig *config    // Configuration
+/// Perform the ppStats steps on the given FPA (optionally for specified view) 
+psMetadata *ppStatsFPA(psMetadata *out,
+		       pmFPA *fpa,         // FPA for which to get statistics
+		       pmFPAview *view,    // View for analysis
+		       psMaskType maskVal, // Value to mask
+		       pmConfig *config    // Configuration
     );
 
+/// Supplement the statistics with the fringe solution
+bool ppStatsFringe(psMetadata *stats,     ///< Statistics metadata to supplement
+                   const pmChip *chip,    ///< The chip containing the solution
+                   const char *root,      ///< Name of output entry
+                   const char *fringeName ///< Name of the solution in the chip->analysis
+    );
+
+
+/// Loop over the input image and do all the hard work
+psMetadata *ppStatsLoop(psExit *result,
+                        ppStatsData *data, // The data
+                        const pmConfig *config // Configuration
+    );
+
+/// Set up the options and input/output files
+ppStatsData *ppStatsSetupFromArgs(int *argc, char *argv[], // Command-line arguments
+                                  pmConfig *config // Configuration
+    );
+
+bool ppStatsSetupFromRecipe(ppStatsData *data, // Data for running ppStats
+                            pmConfig *config // Configuration
+    );
+
+
+/// Return short version information
+psString ppStatsVersion(void);
+
+/// Return long version information
+psString ppStatsVersionLong(void);
+
 #endif
Index: /trunk/ppStats/src/ppStatsData.c
===================================================================
--- /trunk/ppStats/src/ppStatsData.c	(revision 13992)
+++ /trunk/ppStats/src/ppStatsData.c	(revision 13993)
@@ -1,10 +1,3 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <pslib.h>
-
-#include "ppStatsData.h"
+#include "ppStatsInternal.h"
 
 static void statsDataFree(ppStatsData *data // Data to free
Index: unk/ppStats/src/ppStatsData.h
===================================================================
--- /trunk/ppStats/src/ppStatsData.h	(revision 13992)
+++ 	(revision )
@@ -1,29 +1,0 @@
-#ifndef PP_STATS_DATA_H
-#define PP_STATS_DATA_H
-
-#include <pslib.h>
-#include <psmodules.h>
-
-typedef struct {
-    // Inputs
-    psFits *fits;                       // Input file handle
-    pmFPA *fpa;                         // FPA to analyse
-    pmFPAview *view;                    // View to analyse
-    // Stuff to output
-    psStats *stats;                     // Statistics to calculate
-    bool doStats;                       // Do statistics?
-    bool fileLevel;                     // Output file level?
-    psList *headers;                    // Headers to read
-    psList *concepts;                   // Concepts to read
-    psList *summary;                    // Summary statistics to calculate
-    // Options for input data
-    float sample;                       // Fraction of cell to sample for statistics
-    psMaskType maskVal;                 // Mask value for images
-    psList *chips;                      // Chips to look at
-    psList *cells;                      // Cells to look at
-} ppStatsData;
-
-// Allocator
-ppStatsData *ppStatsDataAlloc(void);
-
-#endif
Index: /trunk/ppStats/src/ppStatsFPA.c
===================================================================
--- /trunk/ppStats/src/ppStatsFPA.c	(revision 13993)
+++ /trunk/ppStats/src/ppStatsFPA.c	(revision 13993)
@@ -0,0 +1,57 @@
+#include "ppStatsInternal.h"
+
+psMetadata *ppStatsFPA(psMetadata *out,
+		       pmFPA *fpa,         // FPA for which to get statistics
+		       pmFPAview *view,    // View for analysis
+		       psMaskType maskVal, // Value to mask
+		       pmConfig *config    // Configuration
+    )
+{
+    PS_ASSERT_PTR_NON_NULL(fpa, NULL)
+    PS_ASSERT_PTR_NON_NULL(view, NULL);
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+
+    ppStatsData *data = ppStatsDataAlloc(); // All the input data
+
+    // Get the options, open the files
+    if (!ppStatsSetupFromRecipe(data, config)) {
+        psError(PS_ERR_UNKNOWN, false, "Unable to get ppStats options from recipe.");
+        psFree(data);
+        return NULL;
+    }
+
+    // Override recipe mask value if one is provided
+    if (maskVal != 0) {
+        data->maskVal = maskVal;
+    }
+
+    if (data->fpa) {
+        psFree(data->fpa);
+    }
+    data->fpa = psMemIncrRefCounter(fpa);
+
+    if (data->view) {
+        psFree(data->view);
+    }
+    data->view = psMemIncrRefCounter(view);
+
+    // Go through the FPA and do the hard work
+    psExit status;                      // Status of statistics loop
+    psMetadata *result = ppStatsLoop(&status, data, config);
+    if (status != PS_EXIT_SUCCESS) {
+        psError (PS_ERR_UNKNOWN, false, "Not able to measure FPA statistics.\n");
+        psFree(result);
+        psFree(data);
+        return (NULL);
+    }
+
+    if (out != NULL) {
+	psMetadataCopy (out, result);
+	psFree(result);
+	psFree(data);
+	return out;
+    }
+
+    psFree(data);
+    return result;
+}
Index: /trunk/ppStats/src/ppStatsFringe.c
===================================================================
--- /trunk/ppStats/src/ppStatsFringe.c	(revision 13992)
+++ /trunk/ppStats/src/ppStatsFringe.c	(revision 13993)
@@ -1,11 +1,3 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string.h>
-#include <pslib.h>
-#include <psmodules.h>
-
-#include "ppStatsFringe.h"
+#include "ppStatsInternal.h"
 
 bool ppStatsFringe(psMetadata *stats, const pmChip *chip, const char *root, const char *fringeName)
Index: unk/ppStats/src/ppStatsFringe.h
===================================================================
--- /trunk/ppStats/src/ppStatsFringe.h	(revision 13992)
+++ 	(revision )
@@ -1,14 +1,0 @@
-#ifndef PP_STATS_FRINGE_H
-#define PP_STATS_FRINGE_H
-
-#include <pslib.h>
-#include <psmodules.h>
-
-/// Supplement the statistics with the fringe solution
-bool ppStatsFringe(psMetadata *stats,     ///< Statistics metadata to supplement
-                   const pmChip *chip,    ///< The chip containing the solution
-                   const char *root,      ///< Name of output entry
-                   const char *fringeName ///< Name of the solution in the chip->analysis
-    );
-
-#endif
Index: /trunk/ppStats/src/ppStatsInternal.h
===================================================================
--- /trunk/ppStats/src/ppStatsInternal.h	(revision 13993)
+++ /trunk/ppStats/src/ppStatsInternal.h	(revision 13993)
@@ -0,0 +1,16 @@
+
+# ifdef HAVE_CONFIG_H
+# include <config.h>
+# endif
+
+#ifndef PP_STATS_STAND_ALONE_H
+#define PP_STATS_STAND_ALONE_H
+
+#include <stdio.h>
+#include <string.h>
+#include <pslib.h>
+#include <psmodules.h>
+
+#include "ppStats.h"
+
+#endif
Index: /trunk/ppStats/src/ppStatsLoop.c
===================================================================
--- /trunk/ppStats/src/ppStatsLoop.c	(revision 13992)
+++ /trunk/ppStats/src/ppStatsLoop.c	(revision 13993)
@@ -1,15 +1,3 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-#include <pslib.h>
-#include <psmodules.h>
-
-#include "ppStats.h"
-#include "ppStatsLoop.h"
-
+#include "ppStatsInternal.h"
 
 static void getMetadata(psMetadata *target, // Target for metadata
Index: unk/ppStats/src/ppStatsLoop.h
===================================================================
--- /trunk/ppStats/src/ppStatsLoop.h	(revision 13992)
+++ 	(revision )
@@ -1,13 +1,0 @@
-#ifndef PP_STATS_LOOP_H
-#define PP_STATS_LOOP_H
-
-#include <psmodules.h>
-#include "ppStatsData.h"
-
-// Loop over the input image and do all the hard work
-psMetadata *ppStatsLoop(psExit *result,
-                        ppStatsData *data, // The data
-                        const pmConfig *config // Configuration
-    );
-
-#endif
Index: /trunk/ppStats/src/ppStatsSetupFromArgs.c
===================================================================
--- /trunk/ppStats/src/ppStatsSetupFromArgs.c	(revision 13992)
+++ /trunk/ppStats/src/ppStatsSetupFromArgs.c	(revision 13993)
@@ -1,14 +1,3 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <pslib.h>
-#include <psmodules.h>
-#include <string.h>
-
-#include "ppStats.h"
-#include "ppStatsData.h"
-#include "ppStatsSetupFromArgs.h"
+#include "ppStatsInternal.h"
 
 // This file is for setting up the required inputs from the command-line
Index: unk/ppStats/src/ppStatsSetupFromArgs.h
===================================================================
--- /trunk/ppStats/src/ppStatsSetupFromArgs.h	(revision 13992)
+++ 	(revision )
@@ -1,13 +1,0 @@
-#ifndef PP_STATS_SETUP_FROM_ARGS_H
-#define PP_STATS_SETUP_FROM_ARGS_H
-
-#include <psmodules.h>
-#include "ppStatsData.h"
-
-// Set up the options and input/output files
-ppStatsData *ppStatsSetupFromArgs(int *argc, char *argv[], // Command-line arguments
-                                  pmConfig *config // Configuration
-    );
-
-
-#endif
Index: /trunk/ppStats/src/ppStatsSetupFromRecipe.c
===================================================================
--- /trunk/ppStats/src/ppStatsSetupFromRecipe.c	(revision 13992)
+++ /trunk/ppStats/src/ppStatsSetupFromRecipe.c	(revision 13993)
@@ -1,14 +1,3 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <pslib.h>
-#include <psmodules.h>
-#include <string.h>
-
-#include "ppStats.h"
-#include "ppStatsData.h"
-#include "ppStatsSetupFromRecipe.h"
+#include "ppStatsInternal.h"
 
 // Strings in a recipe may be defined multiply (with MULTI) or listed on a single line
Index: unk/ppStats/src/ppStatsSetupFromRecipe.h
===================================================================
--- /trunk/ppStats/src/ppStatsSetupFromRecipe.h	(revision 13992)
+++ 	(revision )
@@ -1,11 +1,0 @@
-#ifndef PP_STATS_SETUP_FROM_RECIPE_H
-#define PP_STATS_SETUP_FROM_RECIPE_H
-
-#include <psmodules.h>
-#include "ppStatsData.h"
-
-bool ppStatsSetupFromRecipe(ppStatsData *data, // Data for running ppStats
-                            pmConfig *config // Configuration
-    );
-
-#endif
Index: unk/ppStats/src/ppStatsStandAlone.c
===================================================================
--- /trunk/ppStats/src/ppStatsStandAlone.c	(revision 13992)
+++ 	(revision )
@@ -1,103 +1,0 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <pslib.h>
-#include <psmodules.h>
-
-#define TIMERNAME "PPSTATS"
-
-#include "ppStats.h"
-#include "ppStatsSetupFromArgs.h"
-
-int main(int argc, char *argv[])
-{
-    psExit status = PS_EXIT_SUCCESS;
-
-    psLibInit(NULL);
-    psTimerStart(TIMERNAME);
-
-    // Parse the configuration and arguments
-    pmConfig *config = pmConfigRead(&argc, argv, PPSTATS_RECIPE);
-    if (!config) {
-        psErrorStackPrint(stderr, "Unable to read configuration.\n");
-        exit(PS_EXIT_CONFIG_ERROR);
-    }
-
-    // Get the options, open the files
-    ppStatsData *data = ppStatsSetupFromArgs(&argc, argv, config);
-    if (!data) {
-        psErrorStackPrint(stderr, "Unable to parse command-line arguments.\n");
-        exit(PS_EXIT_CONFIG_ERROR);
-    }
-
-    // Output filename is optional
-    const char *outName = NULL;         // Output file name
-    FILE *outFile = stdout;             // Output file
-    if (argc == 2) {
-        outName = argv[1];
-        psString resolved = pmConfigConvertFilename(outName, config, true); // Resolved filename
-
-        if (resolved && strlen(resolved) > 0) {
-            outFile = fopen(resolved, "w");
-            if (!outFile) {
-                psLogMsg("ppStats", PS_LOG_ERROR, "Unable to open output file %s\n", resolved);
-                psFree(resolved);
-                // XXX this could be a system or config error, but not a data error
-                status = PS_EXIT_CONFIG_ERROR;
-                goto die;
-            }
-        } else {
-            psErrorStackPrint(stderr, "Unable to open output file %s.\n", resolved);
-            exit(PS_EXIT_CONFIG_ERROR);
-        }
-        psFree(resolved);
-    }
-
-    // Go through the FPA and do the hard work
-    psMetadata *results = ppStatsLoop(&status, data, config);
-    if (status != PS_EXIT_SUCCESS) {
-        psErrorStackPrint(stderr, "Error in stats loop.\n");
-        exit (status);
-    }
-    if (psListLength(results->list) == 0) {
-        psErrorStackPrint(stderr, "No output.\n");
-        exit (status);
-    }
-
-    if (data->fileLevel) {
-        const char *level = pmFPALevelToName(pmFPAPHULevel(config->format)); // Level for file
-        psMetadataAddStr(results, PS_LIST_HEAD, "FILE.LEVEL", 0, "File level", level);
-    }
-
-    // Format and print the output
-    psString output = psMetadataConfigFormat(results);
-    if (!output) {
-        psErrorStackPrint(stderr, "Unable to generate configuration file with result.\n");
-        psFree(results);
-        exit(PS_EXIT_CONFIG_ERROR);
-    }
-    fprintf(outFile, "%s", output);
-    psFree(output);
-
-    // Clean up
-    psFree(results);
-    if (outName) {
-        fclose(outFile);
-    }
-
-    // Common code for the death.
-die:
-    if (status) {
-        psErrorStackPrint (stderr, "failure in %s", __func__);
-    }
-    psFree(data);
-    psFree(config);
-    pmConceptsDone();
-    pmConfigDone();
-    psLibFinalize();
-
-    return status;
-}
Index: /trunk/ppStats/src/ppStatsVersion.c
===================================================================
--- /trunk/ppStats/src/ppStatsVersion.c	(revision 13992)
+++ /trunk/ppStats/src/ppStatsVersion.c	(revision 13993)
@@ -1,10 +1,3 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <pslib.h>
-#include <psmodules.h>
-#include "ppStatsVersion.h"
+#include "ppStatsInternal.h"
 
 static const char *cvsTag = "$Name: not supported by cvs2svn $";// CVS tag name
Index: unk/ppStats/src/ppStatsVersion.h
===================================================================
--- /trunk/ppStats/src/ppStatsVersion.h	(revision 13992)
+++ 	(revision )
@@ -1,10 +1,0 @@
-#ifndef PP_STATS_VERSION_H
-#define PP_STATS_VERSION_H
-
-/// Return short version information
-psString ppStatsVersion(void);
-
-/// Return long version information
-psString ppStatsVersionLong(void);
-
-#endif
