Index: trunk/ppSub/src/ppSubArguments.c
===================================================================
--- trunk/ppSub/src/ppSubArguments.c	(revision 18289)
+++ trunk/ppSub/src/ppSubArguments.c	(revision 18649)
@@ -32,5 +32,5 @@
 // Get a float-point value from the command-line or recipe, and add it to the arguments
 #define VALUE_ARG_RECIPE_FLOAT(ARGNAME, RECIPENAME, TYPE) { \
-    ps##TYPE value = psMetadataLookup##TYPE(NULL, arguments, ARGNAME); \
+    ps##TYPE value = psMetadataLookup##TYPE(NULL, config->arguments, ARGNAME); \
     if (isnan(value)) { \
         bool mdok; \
@@ -47,5 +47,5 @@
 // Get an integer value from the command-line or recipe, and add it to the arguments
 #define VALUE_ARG_RECIPE_INT(ARGNAME, RECIPENAME, TYPE, UNSET) { \
-    ps##TYPE value = psMetadataLookup##TYPE(NULL, arguments, ARGNAME); \
+    ps##TYPE value = psMetadataLookup##TYPE(NULL, config->arguments, ARGNAME); \
     if (value == UNSET) { \
         bool mdok; \
@@ -170,5 +170,5 @@
 }
 
-bool ppSubArguments(int argc, char *argv[], pmConfig *config)
+bool ppSubArgumentsSetup(int argc, char *argv[], pmConfig *config)
 {
     assert(config);
@@ -176,5 +176,5 @@
     pmConfigFileSetsMD(config->arguments, &argc, argv, "PPSUB.SOURCES", "-sources", NULL);
 
-    psMetadata *arguments = psMetadataAlloc(); // Command-line arguments
+    psMetadata *arguments = config->arguments; // Command-line arguments
     psMetadataAddStr(arguments, PS_LIST_TAIL, "-inmask", 0, "Input mask image", NULL);
     psMetadataAddStr(arguments, PS_LIST_TAIL, "-inweight", 0, "Input weight image", NULL);
@@ -222,24 +222,31 @@
     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Name of the output image", argv[3]);
 
-    const char *inMask = psMetadataLookupStr(NULL, arguments, "-inmask"); // Name of input mask
+    const char *inMask = psMetadataLookupStr(NULL, config->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, arguments, "-inweight"); // Name of input weight
+    const char *inWeight = psMetadataLookupStr(NULL, config->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, arguments, "-refmask"); // Name of reference mask
+    const char *refMask = psMetadataLookupStr(NULL, config->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, arguments, "-refweight"); // Name of reference weight
+    const char *refWeight = psMetadataLookupStr(NULL, config->arguments, "-refweight"); // Name of ref weight
     if (refWeight && strlen(refWeight) > 0) {
         fileList("REF.WEIGHT", refWeight, "Name of the reference weight image", config);
     }
 
-    valueArgStr(arguments, "-stats",  "STATS",  config->arguments);
-    valueArgStr(arguments, "-stamps", "STAMPS", config->arguments);
+    return true;
+}
+
+bool ppSubArgumentsParse(pmConfig *config)
+{
+    assert(config);
+
+    valueArgStr(config->arguments, "-stats",  "STATS",  config->arguments);
+    valueArgStr(config->arguments, "-stamps", "STAMPS", config->arguments);
 
     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
@@ -263,9 +270,9 @@
     VALUE_ARG_RECIPE_FLOAT("-penalty",    "PENALTY",         F32);
 
-    valueArgRecipeStr(arguments, recipe, "-mask-bad",   "MASK.BAD",   config->arguments);
-    valueArgRecipeStr(arguments, recipe, "-mask-blank", "MASK.BLANK", config->arguments);
-
-    vectorArgRecipe(arguments, "-isis-widths", recipe, "ISIS.WIDTHS", config->arguments, PS_TYPE_F32);
-    vectorArgRecipe(arguments, "-isis-orders", recipe, "ISIS.ORDERS", config->arguments, PS_TYPE_S32);
+    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
@@ -276,5 +283,6 @@
     }
 
-    if (psMetadataLookupBool(NULL, arguments, "-opt") || psMetadataLookupBool(NULL, recipe, "OPTIMUM")) {
+    if (psMetadataLookupBool(NULL, config->arguments, "-opt") ||
+        psMetadataLookupBool(NULL, recipe, "OPTIMUM")) {
         psMetadataAddBool(config->arguments, PS_LIST_TAIL, "OPTIMUM", 0,
                           "Derive optimum parameters for ISIS kernels?", true);
@@ -287,16 +295,17 @@
 
     psMetadataAddBool(config->arguments, PS_LIST_TAIL, "REVERSE", 0, "Reverse sense of subtraction",
-                      psMetadataLookupBool(NULL, arguments, "-reverse"));
+                      psMetadataLookupBool(NULL, config->arguments, "-reverse"));
     psMetadataAddBool(config->arguments, PS_LIST_TAIL, "MASK.GENERATE", 0, "Generate mask if not supplied",
-                      psMetadataLookupBool(NULL, arguments, "-generate-mask"));
+                      psMetadataLookupBool(NULL, config->arguments, "-generate-mask"));
     psMetadataAddBool(config->arguments, PS_LIST_TAIL, "DUAL", 0, "Dual convolution?",
-                      psMetadataLookupBool(NULL, arguments, "-dual"));
-
-    if (psMetadataLookupBool(NULL, arguments, "-renorm") || psMetadataLookupBool(NULL, recipe, "RENORM")) {
+                      psMetadataLookupBool(NULL, config->arguments, "-dual"));
+
+    if (psMetadataLookupBool(NULL, config->arguments, "-renorm") ||
+        psMetadataLookupBool(NULL, recipe, "RENORM")) {
         psMetadataAddBool(config->arguments, PS_LIST_TAIL, "RENORM", 0, "Renormalise weights?", true);
         VALUE_ARG_RECIPE_INT("-renorm-width", "RENORM.WIDTH", S32, 0);
     }
 
-    if (psMetadataLookupBool(NULL, arguments, "-photometry") ||
+    if (psMetadataLookupBool(NULL, config->arguments, "-photometry") ||
         psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) {
         psMetadataAddBool(config->arguments, PS_LIST_TAIL, "PHOTOMETRY", 0, "Perform photometry?", true);
@@ -304,5 +313,5 @@
 
     // Translate the kernel type
-    psString type = psMetadataLookupStr(NULL, arguments, "-type"); // Name of kernel type
+    psString type = psMetadataLookupStr(NULL, config->arguments, "-type"); // Name of kernel type
     if (!type || strlen(type) == 0) {
         type = psMetadataLookupStr(NULL, recipe, "KERNEL.TYPE");
@@ -320,11 +329,7 @@
 
     psTrace("ppSub", 1, "Done reading command-line arguments\n");
-    psFree(arguments);
     return true;
 
 ERROR:
-    psFree(arguments);
     return false;
 }
-
-
