Index: trunk/ppSub/src/ppSubArguments.c
===================================================================
--- trunk/ppSub/src/ppSubArguments.c	(revision 18770)
+++ trunk/ppSub/src/ppSubArguments.c	(revision 18920)
@@ -41,5 +41,5 @@
         } \
     } \
-    psMetadataAdd##TYPE(config->arguments, PS_LIST_TAIL, RECIPENAME, 0, NULL, value); \
+    psMetadataAdd##TYPE(recipe, PS_LIST_TAIL, RECIPENAME, PS_META_REPLACE, NULL, value); \
 }
 
@@ -56,5 +56,5 @@
         } \
     } \
-    psMetadataAdd##TYPE(config->arguments, PS_LIST_TAIL, RECIPENAME, 0, NULL, value); \
+    psMetadataAdd##TYPE(recipe, PS_LIST_TAIL, RECIPENAME, PS_META_REPLACE, NULL, value); \
 }
 
@@ -68,5 +68,5 @@
     psString value = psMetadataLookupStr(NULL, arguments, argName); // Value of interest
     if (value && strlen(value) > 0) {
-        return psMetadataAddStr(target, PS_LIST_TAIL, mdName, 0, NULL, value);
+        return psMetadataAddStr(target, PS_LIST_TAIL, mdName, PS_META_REPLACE, NULL, value);
     }
     return false;
@@ -91,5 +91,5 @@
         }
     }
-    return psMetadataAddStr(target, PS_LIST_TAIL, mdName, 0, NULL, value);
+    return psMetadataAddStr(target, PS_LIST_TAIL, mdName, PS_META_REPLACE, NULL, value);
 }
 
@@ -149,5 +149,5 @@
     }
 
-    psMetadataAddVector(target, PS_LIST_TAIL, recipeName, 0, NULL, vector);
+    psMetadataAddVector(target, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, vector);
     psFree(vector);                     // Drop reference
 
@@ -184,8 +184,11 @@
     psMetadataAddS32(arguments, PS_LIST_TAIL, "-size", 0, "Kernel half-size (pixels)", 0);
     psMetadataAddS32(arguments, PS_LIST_TAIL, "-order", 0, "Spatial polynomial order", -1);
-    psMetadataAddStr(arguments, PS_LIST_TAIL, "-type", 0, "Kernel type (ISIS|POIS|SPAM|FRIES|GUNK|RINGS)", NULL);
+    psMetadataAddStr(arguments, PS_LIST_TAIL, "-type", 0,
+                     "Kernel type (ISIS|POIS|SPAM|FRIES|GUNK|RINGS)", NULL);
     psMetadataAddF32(arguments, PS_LIST_TAIL, "-penalty", 0, "Penalty for wideness", NAN);
-    psMetadataAddStr(arguments, PS_LIST_TAIL, "-isis-widths", 0, "ISIS Gaussian FWHMs (comma-separated)", NULL);
-    psMetadataAddStr(arguments, PS_LIST_TAIL, "-isis-orders", 0, "ISIS polynomial orders (comma-separated)", NULL);
+    psMetadataAddStr(arguments, PS_LIST_TAIL, "-isis-widths", 0,
+                     "ISIS Gaussian FWHMs (comma-separated)", NULL);
+    psMetadataAddStr(arguments, PS_LIST_TAIL, "-isis-orders", 0,
+                     "ISIS polynomial orders (comma-separated)", NULL);
     psMetadataAddS32(arguments, PS_LIST_TAIL, "-rings-order", 0, "RINGS polynomial order", -1);
     psMetadataAddS32(arguments, PS_LIST_TAIL, "-inner", 0, "SPAM and FRIES inner radius", -1);
@@ -201,6 +204,8 @@
     psMetadataAddBool(arguments,  PS_LIST_TAIL, "-reverse", 0, "Reverse sense of subtraction?", false);
     psMetadataAddBool(arguments,  PS_LIST_TAIL, "-generate-mask", 0, "Generate mask if not supplied?", false);
-    psMetadataAddStr(arguments,  PS_LIST_TAIL, "-stamps", 0, "Stamps filename; file has x,y on each line", NULL);
-    psMetadataAddBool(arguments, PS_LIST_TAIL, "-opt", 0, "Derive optimum parameters for ISIS kernels?", false);
+    psMetadataAddStr(arguments,  PS_LIST_TAIL, "-stamps", 0,
+                     "Stamps filename; file has x,y on each line", NULL);
+    psMetadataAddBool(arguments, PS_LIST_TAIL, "-opt", 0,
+                      "Derive optimum parameters for ISIS kernels?", false);
     psMetadataAddF32(arguments, PS_LIST_TAIL, "-opt-min", 0, "Minimum value for optimum kernel search", NAN);
     psMetadataAddF32(arguments, PS_LIST_TAIL, "-opt-max", 0, "Minimum value for optimum kernel search", NAN);
@@ -221,24 +226,30 @@
     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Name of the output image", argv[3]);
 
-    const char *inMask = psMetadataLookupStr(NULL, config->arguments, "-inmask"); // Name of input mask
+    const char *inMask = psMetadataLookupStr(NULL, arguments, "-inmask"); // Name of input mask
     if (inMask && strlen(inMask) > 0) {
         fileList("INPUT.MASK", inMask, "Name of the input mask image", config);
     }
-    const char *inWeight = psMetadataLookupStr(NULL, config->arguments, "-inweight"); // Name of input weight
+    const char *inWeight = psMetadataLookupStr(NULL, arguments, "-inweight"); // Name of input weight
     if (inWeight && strlen(inWeight) > 0) {
         fileList("INPUT.WEIGHT", inWeight, "Name of the input weight image", config);
     }
 
-    const char *refMask = psMetadataLookupStr(NULL, config->arguments, "-refmask"); // Name of reference mask
+    const char *refMask = psMetadataLookupStr(NULL, arguments, "-refmask"); // Name of reference mask
     if (refMask && strlen(refMask) > 0) {
         fileList("REF.MASK", refMask, "Name of the reference mask image", config);
     }
-    const char *refWeight = psMetadataLookupStr(NULL, config->arguments, "-refweight"); // Name of ref weight
+    const char *refWeight = psMetadataLookupStr(NULL, arguments, "-refweight"); // Name of ref weight
     if (refWeight && strlen(refWeight) > 0) {
         fileList("REF.WEIGHT", refWeight, "Name of the reference weight image", config);
     }
 
-    if (psMetadataLookupBool(NULL, config->arguments, "-photometry")) {
-        psMetadataAddBool(config->arguments, PS_LIST_TAIL, "PHOTOMETRY", 0, "Perform photometry?", true);
+    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
+    if (!recipe) {
+        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSUB_RECIPE);
+        return false;
+    }
+
+    if (psMetadataLookupBool(NULL, arguments, "-photometry")) {
+        psMetadataAddBool(recipe, PS_LIST_TAIL, "PHOTOMETRY", PS_META_REPLACE, "Perform photometry?", true);
     }
 
@@ -250,6 +261,8 @@
     assert(config);
 
-    valueArgStr(config->arguments, "-stats",  "STATS",  config->arguments);
-    valueArgStr(config->arguments, "-stamps", "STAMPS", config->arguments);
+    psMetadata *arguments = config->arguments; // Command-line arguments
+
+    valueArgStr(arguments, "-stats",  "STATS",  arguments);
+    valueArgStr(arguments, "-stamps", "STAMPS", arguments);
 
     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
@@ -273,12 +286,12 @@
     VALUE_ARG_RECIPE_FLOAT("-penalty",    "PENALTY",         F32);
 
-    valueArgRecipeStr(config->arguments, recipe, "-mask-bad",   "MASK.BAD",   config->arguments);
-    valueArgRecipeStr(config->arguments, recipe, "-mask-blank", "MASK.BLANK", config->arguments);
-
-    vectorArgRecipe(config->arguments, "-isis-widths", recipe, "ISIS.WIDTHS", config->arguments, PS_TYPE_F32);
-    vectorArgRecipe(config->arguments, "-isis-orders", recipe, "ISIS.ORDERS", config->arguments, PS_TYPE_S32);
-
-    psVector *widths = psMetadataLookupPtr(NULL, config->arguments, "ISIS.WIDTHS"); // ISIS Gaussian widths
-    psVector *orders = psMetadataLookupPtr(NULL, config->arguments, "ISIS.ORDERS"); // ISIS Polynomial orders
+    valueArgRecipeStr(arguments, recipe, "-mask-bad",   "MASK.BAD",   recipe);
+    valueArgRecipeStr(arguments, recipe, "-mask-blank", "MASK.BLANK", recipe);
+
+    vectorArgRecipe(arguments, "-isis-widths", recipe, "ISIS.WIDTHS", recipe, PS_TYPE_F32);
+    vectorArgRecipe(arguments, "-isis-orders", recipe, "ISIS.ORDERS", recipe, PS_TYPE_S32);
+
+    psVector *widths = psMetadataLookupPtr(NULL, recipe, "ISIS.WIDTHS"); // ISIS Gaussian widths
+    psVector *orders = psMetadataLookupPtr(NULL, recipe, "ISIS.ORDERS"); // ISIS Polynomial orders
     if (widths->n != orders->n) {
         psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Size of vectors for ISIS widths and orders do not match.");
@@ -286,7 +299,6 @@
     }
 
-    if (psMetadataLookupBool(NULL, config->arguments, "-opt") ||
-        psMetadataLookupBool(NULL, recipe, "OPTIMUM")) {
-        psMetadataAddBool(config->arguments, PS_LIST_TAIL, "OPTIMUM", 0,
+    if (psMetadataLookupBool(NULL, arguments, "-opt") || psMetadataLookupBool(NULL, recipe, "OPTIMUM")) {
+        psMetadataAddBool(recipe, PS_LIST_TAIL, "OPTIMUM", PS_META_REPLACE,
                           "Derive optimum parameters for ISIS kernels?", true);
         VALUE_ARG_RECIPE_FLOAT("-opt-min", "OPTIMUM.MIN",   F32);
@@ -297,25 +309,24 @@
     }
 
-    psMetadataAddBool(config->arguments, PS_LIST_TAIL, "REVERSE", 0, "Reverse sense of subtraction",
-                      psMetadataLookupBool(NULL, config->arguments, "-reverse"));
-    psMetadataAddBool(config->arguments, PS_LIST_TAIL, "MASK.GENERATE", 0, "Generate mask if not supplied",
-                      psMetadataLookupBool(NULL, config->arguments, "-generate-mask"));
-    psMetadataAddBool(config->arguments, PS_LIST_TAIL, "DUAL", 0, "Dual convolution?",
-                      psMetadataLookupBool(NULL, config->arguments, "-dual"));
-
-    if (psMetadataLookupBool(NULL, config->arguments, "-renorm") ||
+    psMetadataAddBool(arguments, PS_LIST_TAIL, "REVERSE", 0, "Reverse sense of subtraction",
+                      psMetadataLookupBool(NULL, arguments, "-reverse"));
+    psMetadataAddBool(recipe, PS_LIST_TAIL, "MASK.GENERATE", PS_META_REPLACE, "Generate mask if not supplied",
+                      psMetadataLookupBool(NULL, arguments, "-generate-mask"));
+    psMetadataAddBool(recipe, PS_LIST_TAIL, "DUAL", PS_META_REPLACE, "Dual convolution?",
+                      psMetadataLookupBool(NULL, arguments, "-dual"));
+
+    if (psMetadataLookupBool(NULL, arguments, "-renorm") ||
         psMetadataLookupBool(NULL, recipe, "RENORM")) {
-        psMetadataAddBool(config->arguments, PS_LIST_TAIL, "RENORM", 0, "Renormalise weights?", true);
+        psMetadataAddBool(recipe, PS_LIST_TAIL, "RENORM", PS_META_REPLACE, "Renormalise weights?", true);
         VALUE_ARG_RECIPE_INT("-renorm-width", "RENORM.WIDTH", S32, 0);
     }
 
-    if (psMetadataLookupBool(NULL, config->arguments, "-photometry") ||
-        psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) {
-        psMetadataAddBool(config->arguments, PS_LIST_TAIL, "PHOTOMETRY", PS_META_REPLACE,
-                          "Perform photometry?", true);
+    // Need to update this because it could have been overwritten by the camera's own recipe
+    if (psMetadataLookupBool(NULL, arguments, "-photometry")) {
+        psMetadataAddBool(recipe, PS_LIST_TAIL, "PHOTOMETRY", PS_META_REPLACE, "Perform photometry?", true);
     }
 
     // Translate the kernel type
-    psString type = psMetadataLookupStr(NULL, config->arguments, "-type"); // Name of kernel type
+    psString type = psMetadataLookupStr(NULL, arguments, "-type"); // Name of kernel type
     if (!type || strlen(type) == 0) {
         type = psMetadataLookupStr(NULL, recipe, "KERNEL.TYPE");
@@ -325,12 +336,20 @@
         }
     }
-    pmSubtractionKernelsType kernelType = pmSubtractionKernelsTypeFromString(type); // Type of kernel
-    if (kernelType == PM_SUBTRACTION_KERNEL_NONE) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unrecognised kernel type: %s", type);
-        goto ERROR;
-    }
-    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "KERNEL.TYPE", 0, "Type of kernel", kernelType);
+    psMetadataAddStr(recipe, PS_LIST_TAIL, "KERNEL.TYPE", PS_META_REPLACE, "Type of kernel", type);
 
     psTrace("ppSub", 1, "Done reading command-line arguments\n");
+
+    // Dump configuration, now that's it's settled
+    {
+        pmConfigCamerasCull(config);
+        pmConfigRecipesCull(config, "PPSUB,PPSTATS,PSPHOT,MASKS");
+
+        const char *outroot = psMetadataLookupStr(NULL, arguments, "OUTPUT"); // Output root name
+        psAssert(outroot, "Should be there, we put it there!");
+
+        pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT"); // Input file
+        pmConfigDump(config, input->fpa, outroot);
+    }
+
     return true;
 
