Index: /trunk/ppMerge/src/ppMerge.c
===================================================================
--- /trunk/ppMerge/src/ppMerge.c	(revision 7066)
+++ /trunk/ppMerge/src/ppMerge.c	(revision 7067)
@@ -12,4 +12,10 @@
 
 //#include "ppMem.h"
+
+// Yet to do:
+//
+// 1. Mask pixels with less than the minimum number of electrons
+// 2. Sampling factor for background measurement
+// 3. On/off pairs
 
 int main(int argc, char **argv)
Index: /trunk/ppMerge/src/ppMerge.h
===================================================================
--- /trunk/ppMerge/src/ppMerge.h	(revision 7066)
+++ /trunk/ppMerge/src/ppMerge.h	(revision 7067)
@@ -3,4 +3,5 @@
 
 #define TIMERNAME "ppMerge"
+#define RECIPENAME "PPMERGE"
 
 #endif
Index: /trunk/ppMerge/src/ppMergeBackground.c
===================================================================
--- /trunk/ppMerge/src/ppMergeBackground.c	(revision 7066)
+++ /trunk/ppMerge/src/ppMergeBackground.c	(revision 7067)
@@ -4,4 +4,5 @@
 #include <psmodules.h>
 
+#include "ppMerge.h"
 #include "ppMergeBackground.h"
 
@@ -150,5 +151,5 @@
 
                     // Get the background
-                    psImageStats(bgStats, image, readout->mask, options->maskVal);
+                    psImageStats(bgStats, image, readout->mask, options->combine->maskVal);
                     background->data.F64[i][cellNum] = getStat(bgStats, options->background);
                 }
Index: /trunk/ppMerge/src/ppMergeCheckInputs.c
===================================================================
--- /trunk/ppMerge/src/ppMergeCheckInputs.c	(revision 7066)
+++ /trunk/ppMerge/src/ppMergeCheckInputs.c	(revision 7067)
@@ -4,4 +4,5 @@
 #include <psmodules.h>
 
+#include "ppMerge.h"
 #include "ppMergeCheckInputs.h"
 #include "ppMergeData.h"
@@ -9,5 +10,5 @@
 // Check input files to make sure everything's consistent
 ppMergeData *ppMergeCheckInputs(ppMergeOptions *options, // Options
-                                const pmConfig *config // Configuration
+                                pmConfig *config // Configuration
     )
 {
@@ -34,5 +35,5 @@
         psFits *inFile = psFitsOpen(filenames->data[i], "r"); // The FITS file to read
         if (!inFile) {
-            psErrorPrint(PS_ERR_IO, false, "Unable to open input file %s --- ignored.\n", name);
+            psLogMsg(__func__, PS_LOG_WARN, "Unable to open input file %s --- ignored.\n", name);
             // Kick it out
             psFree(filenames->data[i]);
@@ -51,5 +52,5 @@
             data->format = pmConfigCameraFormatFromHeader(config, header);
             psFree(header);
-            if (!options->format) {
+            if (!data->format) {
                 psLogMsg(__func__, PS_LOG_WARN, "Unable to identify camera format for input file %s --- "
                              "ignored.\n", name);
@@ -59,5 +60,5 @@
                 continue;
             }
-        } else if (!pmConfigValidateCameraFormat(options->format, header)) {
+        } else if (!pmConfigValidateCameraFormat(data->format, header)) {
             psLogMsg(__func__, PS_LOG_WARN, "Input file %s doesn't match camera format --- ignored.\n", name);
             // Kick it out
@@ -99,5 +100,10 @@
     data->numCells = numCells;
 
-    return (numGood > 1);
+    if (numGood > 1) {
+        return data;
+    }
+
+    psFree(data);
+    return NULL;
 }
 
Index: /trunk/ppMerge/src/ppMergeCheckInputs.h
===================================================================
--- /trunk/ppMerge/src/ppMergeCheckInputs.h	(revision 7066)
+++ /trunk/ppMerge/src/ppMergeCheckInputs.h	(revision 7067)
@@ -8,5 +8,5 @@
 // Check input files to make sure everything's consistent
 ppMergeData *ppMergeCheckInputs(ppMergeOptions *options, // Options
-                                const pmConfig *config // Configuration
+                                pmConfig *config // Configuration
     );
 
Index: /trunk/ppMerge/src/ppMergeCombine.c
===================================================================
--- /trunk/ppMerge/src/ppMergeCombine.c	(revision 7066)
+++ /trunk/ppMerge/src/ppMergeCombine.c	(revision 7067)
@@ -4,4 +4,5 @@
 #include <psmodules.h>
 
+#include "ppMerge.h"
 #include "ppMergeData.h"
 #include "ppMergeCombine.h"
@@ -21,11 +22,11 @@
     // Sanity checks
     assert(!options->scale || scales);
-    assert(!scales || !*scales || ((*scales)->type.type == PS_TYPE_F64 &&
-                                   (*scales)->numCols == data->numCells &&
-                                   (*scales)->numRows == filenames->n));
+    assert(!scales || (scales->type.type == PS_TYPE_F64 &&
+                       scales->numCols == data->numCells &&
+                       scales->numRows == filenames->n));
     assert(!options->zero || zeros);
-    assert(!zeros || !*zeros || ((*zeros)->type.type == PS_TYPE_F64 &&
-                                 (*zeros)->numCols == data->numCells &&
-                                 (*zeros)->numRows == filenames->n));
+    assert(!zeros || (zeros->type.type == PS_TYPE_F64 &&
+                      zeros->numCols == data->numCells &&
+                      zeros->numRows == filenames->n));
 
     // Iterate over the FPA
@@ -38,5 +39,5 @@
             continue;
         }
-        pmChipWrite(chip, outFile, config->database, false);
+        pmChipWrite(chip, data->outFile, config->database, false);
         psArray *cells = chip->cells;   // Array of output cells
         for (int j = 0; j < cells->n; j++) {
@@ -46,5 +47,5 @@
             }
             cellNum++;
-            pmCellWrite(cell, outFile, config->database, false);
+            pmCellWrite(cell, data->outFile, config->database, false);
             pmReadout *readout = pmReadoutAlloc(cell); // Output readout of interest
             psArray *stack = psArrayAlloc(filenames->n); // Stack of readouts to combine
@@ -53,5 +54,5 @@
                 cellScales = psImageCol(NULL, scales, cellNum);
             }
-            psVector cellZeros = NULL;  // Zeros for this cell
+            psVector *cellZeros = NULL;  // Zeros for this cell
             if (zeros) {
                 cellZeros = psImageCol(NULL, zeros, cellNum);
@@ -81,15 +82,15 @@
 
                     // Only reading and writing the first readout in each cell (plane 0)
-                    stillReading |= pmReadoutReadNext(stack->data[k], fits, 0, options->rows);
+                    stillReadingRows |= pmReadoutReadNext(stack->data[k], fits, 0, options->rows);
                     psFitsClose(fits);
                 }
 
-                pmReadoutCombine(readout, stack, cellZeros, cellScales, combineParams);
-                pmReadoutWriteNext(readout, outFile, 0);
+                pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine);
+                pmReadoutWriteNext(readout, data->outFile, 0);
 
             } while (stillReadingRows);
 
             // Write the pixels
-            pmCellWrite(cell, outFile, config->database, true);
+            pmCellWrite(cell, data->outFile, config->database, true);
 
             // Blow away the cell data
@@ -104,5 +105,5 @@
 
         // Write the pixels
-        pmChipWrite(chip, outFile, config->database, true);
+        pmChipWrite(chip, data->outFile, config->database, true);
 
         // Blow away the chip data
@@ -117,5 +118,5 @@
 
     // Write the pixels
-    pmFPAWrite(fpa, outFile, config->database, true);
+    pmFPAWrite(data->out, data->outFile, config->database, true);
 
     // Blow away the FPA data
@@ -124,5 +125,5 @@
         pmFPAFreeData(fpaIn);
     }
-    pmFPAFreeData(fpa);
+    pmFPAFreeData(data->out);
 
     return true;
Index: /trunk/ppMerge/src/ppMergeConfig.c
===================================================================
--- /trunk/ppMerge/src/ppMergeConfig.c	(revision 7066)
+++ /trunk/ppMerge/src/ppMergeConfig.c	(revision 7067)
@@ -3,4 +3,5 @@
 #include <psmodules.h>
 
+#include "ppMerge.h"
 #include "ppMergeConfig.h"
 
Index: /trunk/ppMerge/src/ppMergeData.c
===================================================================
--- /trunk/ppMerge/src/ppMergeData.c	(revision 7066)
+++ /trunk/ppMerge/src/ppMergeData.c	(revision 7067)
@@ -2,4 +2,5 @@
 #include <pslib.h>
 
+#include "ppMerge.h"
 #include "ppMergeData.h"
 
@@ -20,5 +21,5 @@
 {
     ppMergeData *data = psAlloc(sizeof(ppMergeData)); // The data, to return
-    psMemSetFreeFunction(data, (psFreeFunc)mergeDataFree);
+    psMemSetDeallocator(data, (psFreeFunc)mergeDataFree);
 
     data->format = NULL;
Index: /trunk/ppMerge/src/ppMergeOptions.c
===================================================================
--- /trunk/ppMerge/src/ppMergeOptions.c	(revision 7066)
+++ /trunk/ppMerge/src/ppMergeOptions.c	(revision 7067)
@@ -2,4 +2,7 @@
 #include <pslib.h>
 #include <psmodules.h>
+
+#include "ppMerge.h"
+#include "ppMergeOptions.h"
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -7,11 +10,10 @@
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-#if 0
 // Free function
 static void mergeOptionsFree(ppMergeOptions *options // Options to free
     )
 {
+    psFree(options->combine);
 }
-#endif
 
 // Allocator
@@ -19,5 +21,5 @@
 {
     ppMergeOptions *options = psAlloc(sizeof(ppMergeOptions)); // The options, to return
-    // psMemSetDeallocator(options, (psFreeFunc)mergeOptionsFree);
+    psMemSetDeallocator(options, (psFreeFunc)mergeOptionsFree);
 
     options->rows = 0;
@@ -29,11 +31,11 @@
     options->background = PS_STAT_SAMPLE_MEDIAN;
     options->onOff = 0;
-    options->combine = PS_STAT_SAMPLE_MEAN;
-    options->ref = 3.0;
-    options->iter = 1;
-    options->fracHigh = 0.0;
-    options->fracLow = 0.0;
-    options->nKeep = 1;
-    options->maskVal = 0xffff;
+    options->combine = pmCombineParamsAlloc(PS_STAT_SAMPLE_MEAN);
+    options->combine->rej = 3.0;
+    options->combine->iter = 1;
+    options->combine->fracHigh = 0.0;
+    options->combine->fracLow = 0.0;
+    options->combine->nKeep = 1;
+    options->combine->maskVal = 0xff;
 
     return options;
@@ -84,21 +86,28 @@
 
 // Parse the options
-ppMergeOptions *ppMergeOptionsParse(ppConfig *config // Configuration
+ppMergeOptions *ppMergeOptionsParse(pmConfig *config // Configuration
     )
 {
     ppMergeOptions *options = ppMergeOptionsAlloc(); // The merge options
 
+    bool mdok = true;                   // Status of MD lookup
+    psMetadata *recipe = psMetadataLookupMD(&mdok, config->recipes, RECIPENAME); // Recipe information
+    if (!mdok || !recipe) {
+        psError(PS_ERR_IO, true, "Unable to find recipe %s", RECIPENAME);
+        exit(EXIT_FAILURE);
+    }
+
     // First, deal with the recipe.  These are parameters that will typically be constant for a camera.
-    OPTION_PARSE(options->rows,         config->recipe, "ROWS",      U16 );
-    OPTION_PARSE(options->minElectrons, config->recipe, "ELECTRONS", F32 );
-    OPTION_PARSE(options->sample,       config->recipe, "SAMPLE",    S32 );
-    OPTION_PARSE(options->rej,          config->recipe, "REJ",       F32 );
-    OPTION_PARSE(options->iter,         config->recipe, "ITER",      S32 );
-    OPTION_PARSE(options->fracHigh,     config->recipe, "FRACHIGH",  F32 );
-    OPTION_PARSE(options->fracLow,      config->recipe, "FRACLOW",   F32 );
-    OPTION_PARSE(options->nKeep,        config->recipe, "NKEEP",     S32 );
-    OPTION_PARSE(options->maskVal,      config->recipe, "MASKVAL",   U8  );
-    options->combine = parseStat(config->recipe, "COMBINE");
-    options->background = parseStat(config->recipe, "BACKGROUND");
+    OPTION_PARSE(options->rows,              recipe, "ROWS",      U16 );
+    OPTION_PARSE(options->minElectrons,      recipe, "ELECTRONS", F32 );
+    OPTION_PARSE(options->sample,            recipe, "SAMPLE",    S32 );
+    OPTION_PARSE(options->combine->rej,      recipe, "REJ",       F32 );
+    OPTION_PARSE(options->combine->iter,     recipe, "ITER",      S32 );
+    OPTION_PARSE(options->combine->fracHigh, recipe, "FRACHIGH",  F32 );
+    OPTION_PARSE(options->combine->fracLow,  recipe, "FRACLOW",   F32 );
+    OPTION_PARSE(options->combine->nKeep,    recipe, "NKEEP",     S32 );
+    OPTION_PARSE(options->combine->maskVal,  recipe, "MASKVAL",   U8  );
+    options->combine->combine = parseStat(recipe, "COMBINE");
+    options->background       = parseStat(recipe, "BACKGROUND");
 
     // Now the command-line options.  These are parameters that depend on what type of frame is being combined
@@ -127,10 +136,10 @@
 
     // Or you can set them individually
-    OPTION_PARSE(options->zero,    config->recipe, "-zero",    Bool);
-    OPTION_PARSE(options->scale,   config->recipe, "-scale",   Bool);
-    OPTION_PARSE(options->exptime, config->recipe, "-exptime", Bool);
+    OPTION_PARSE(options->zero,    config->arguments, "-zero",    Bool);
+    OPTION_PARSE(options->scale,   config->arguments, "-scale",   Bool);
+    OPTION_PARSE(options->exptime, config->arguments, "-exptime", Bool);
 
     // Number of on/off images
-    OPTION_PARSE(options->onoff, config->recipe, "-onoff", S32);
+    OPTION_PARSE(options->onOff, config->arguments, "-onoff", S32);
 
     return options;
Index: /trunk/ppMerge/src/ppMergeOptions.h
===================================================================
--- /trunk/ppMerge/src/ppMergeOptions.h	(revision 7066)
+++ /trunk/ppMerge/src/ppMergeOptions.h	(revision 7067)
@@ -24,16 +24,9 @@
     psStatsOptions background;          // Statistic to use to measure the background
     ppOnOff onOff;                      // On/off pairs?
-    psStatsOptions combine;             // Statistic to use in combination
-    float rej;                          // Rejection level in combination (for sigma clipping)
-    unsigned int iter;                  // Number of iterations for combination (for sigma clipping)
-    float fracHigh;                     // Fraction of high pixels to throw
-    float fracLow;                      // Fraction of low pixels to throw
-    int nKeep;                          // Minimum number of pixels to keep
-    psMaskType maskVal;                 // Mask value
+    pmCombineParams *combine;           // Combination parameters
 } ppMergeOptions;
 
 // Allocator
-ppMergeOptions *ppMergeOptionsAlloc(psStatsOptions stat // Statistic to use in the merge
-    );
+ppMergeOptions *ppMergeOptionsAlloc(void);
 
 
