Index: trunk/ppSim/src/ppSimArguments.c
===================================================================
--- trunk/ppSim/src/ppSimArguments.c	(revision 16494)
+++ trunk/ppSim/src/ppSimArguments.c	(revision 17557)
@@ -18,31 +18,26 @@
 }
 
-// Get a value from the command-line arguments or the recipe, and add it to the target
-bool valueArgRecipe(pmConfig *config,   // Configuration
-                    psMetadata *arguments, // Command-line arguments
-                    const char *argName, // Argument name in the command-line arguments
-                    const psMetadata *recipe, // Recipe
+// Get a value from the command-line arguments and add it to recipe options
+bool valueArgRecipe(psMetadata *options,    // Target to which to add value
                     const char *recipeName, // Name for value in the recipe
-                    psMetadata *target // Target to which to add value
+		    psMetadata *arguments,  // Command-line arguments
+                    const char *argName	    // Argument name in the command-line arguments
     )
 {
-    float value = psMetadataLookupF32(NULL, arguments, argName); // Value of interest
-    if (isnan(value)) {
-        bool mdok;                      // Status of MD lookup
-        value = psMetadataLookupF32(&mdok, recipe, recipeName);
-        if (!mdok) {
-            psErrorStackPrint(stderr, "Unable to find %s in recipe %s", recipeName, PPSIM_RECIPE);
-            psFree((psPtr)arguments);
-            psFree(config);
-            exit(PS_EXIT_CONFIG_ERROR);
-        }
-    }
-    return psMetadataAddF32(target, PS_LIST_TAIL, recipeName, 0, NULL, value);
+    bool status;						    // Status of MD lookup
+    float value = psMetadataLookupF32(&status, arguments, argName); // Value of interest
+    if (isnan(value)) return true;
+    status = psMetadataAddF32(options, PS_LIST_TAIL, recipeName, 0, NULL, value);
+    return status;
 }
 
+// this function supplements the RECIPE:OPTIONS folder with command-line options
 void ppSimArguments(int argc, char *argv[], pmConfig *config)
 {
+    bool mdok;                          // Status of MD lookup
+
     assert(config);
 
+    // save the following command-line options in the arguments structure
     psMetadata *arguments = psMetadataAlloc(); // Command-line arguments
     psMetadataAddStr(arguments, PS_LIST_TAIL, "-format", 0, "Camera format name", NULL);
@@ -68,4 +63,5 @@
     psMetadataAddF32(arguments, PS_LIST_TAIL, "-starsdensity", 0, "Density of fake stars at magnitude", NAN);
     psMetadataAddStr(arguments, PS_LIST_TAIL, "-psfclass", 0, "Type of PSF model", NULL);
+    psMetadataAddStr(arguments, PS_LIST_TAIL, "-galmodel", 0, "Type of Galaxy model", NULL);
     psMetadataAddS32(arguments, PS_LIST_TAIL, "-bin", 0, "Binning in x and y", 1);
 
@@ -92,4 +88,5 @@
     }
 
+    // apply an alternate camera format
     psString formatName = psMetadataLookupStr(NULL, arguments, "-format"); // Name of format
     if (formatName) {
@@ -114,4 +111,6 @@
     }
 
+    // specify the type of simulated image to produce
+    // XXX this should not be required if we supplied INPUT
     const char *typeStr = psMetadataLookupStr(NULL, arguments, "-type"); // Exposure type
     if (!typeStr) {
@@ -138,4 +137,14 @@
     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "FILTER", 0, "Filter name", filter);
 
+    // save the following additional recipe values based on command-line options
+    // these options override the PPSIM recipe values loaded from recipe files
+    psMetadata *options = pmConfigRecipeOptions (config, PPSIM_RECIPE);
+    if (!options) {
+        psErrorStackPrint(stderr, "Unable to find recipe options for %s", PPSIM_RECIPE);
+        psFree(arguments);
+        psFree(config);
+        exit(PS_EXIT_CONFIG_ERROR);
+    }
+
     float expTime;
     if (type == PPSIM_TYPE_BIAS) {
@@ -148,32 +157,25 @@
         }
     }
-    psMetadataAddF32(config->arguments, PS_LIST_TAIL, "EXPTIME", 0, "Exposure time (s)", expTime);
-
-    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe for ppSim
-    if (!recipe) {
-        psErrorStackPrint(stderr, "Unable to find recipe %s", PPSIM_RECIPE);
-        psFree(arguments);
-        psFree(config);
-        exit(PS_EXIT_CONFIG_ERROR);
-    }
-
-    valueArgRecipe(config, arguments, "-biaslevel",    recipe, "BIAS.LEVEL",    config->arguments);
-    valueArgRecipe(config, arguments, "-biasrange",    recipe, "BIAS.RANGE",    config->arguments);
-    valueArgRecipe(config, arguments, "-darkrate",     recipe, "DARK.RATE",     config->arguments);
-    valueArgRecipe(config, arguments, "-flatsigma",    recipe, "FLAT.SIGMA",    config->arguments);
-    valueArgRecipe(config, arguments, "-flatrate",     recipe, "FLAT.RATE",     config->arguments);
-    valueArgRecipe(config, arguments, "-shuttertime",  recipe, "SHUTTER.TIME",  config->arguments);
-    valueArgRecipe(config, arguments, "-skyrate",      recipe, "SKY.RATE",      config->arguments);
-    valueArgRecipe(config, arguments, "-starslum",     recipe, "STARS.LUM",     config->arguments);
-    valueArgRecipe(config, arguments, "-starsmag",     recipe, "STARS.MAG",     config->arguments);
-    valueArgRecipe(config, arguments, "-starsdensity", recipe, "STARS.DENSITY", config->arguments);
-
-    bool mdok;                          // Status of MD lookup
+    psMetadataAddF32(options, PS_LIST_TAIL, "EXPTIME", 0, "Exposure time (s)", expTime);
+
+    // these values all get moved from arguments to RECIPE:OPTIONS
+    valueArgRecipe(options, "BIAS.LEVEL",    arguments, "-biaslevel");
+    valueArgRecipe(options, "BIAS.RANGE",    arguments, "-biasrange");
+    valueArgRecipe(options, "DARK.RATE",     arguments, "-darkrate");
+    valueArgRecipe(options, "FLAT.SIGMA",    arguments, "-flatsigma");
+    valueArgRecipe(options, "FLAT.RATE",     arguments, "-flatrate");
+    valueArgRecipe(options, "SHUTTER.TIME",  arguments, "-shuttertime");
+    valueArgRecipe(options, "SKY.RATE",      arguments, "-skyrate");
+    valueArgRecipe(options, "STARS.LUM",     arguments, "-starslum");
+    valueArgRecipe(options, "STARS.MAG",     arguments, "-starsmag");
+    valueArgRecipe(options, "STARS.DENSITY", arguments, "-starsdensity");
+
+    psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe
+
     int biasOrder = psMetadataLookupS32(&mdok, recipe, "BIAS.ORDER"); // Overscan polynomial order
     if (!mdok) {
         psWarning("BIAS.ORDER(S32) is not set in the recipe %s --- assuming %d", PPSIM_RECIPE, biasOrder);
     }
-    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BIAS.ORDER", 0,
-                     "Overscan polynomial order", biasOrder);
+    psMetadataAddS32(options, PS_LIST_TAIL, "BIAS.ORDER", 0, "Overscan polynomial order", biasOrder);
 
     int binning = psMetadataLookupS32(NULL, arguments, "-bin"); // Binning in x and y
@@ -190,6 +192,6 @@
         float ra0     = psMetadataLookupF32(NULL, arguments, "-ra"); // Right Ascension of boresight
         float dec0    = psMetadataLookupF32(NULL, arguments, "-dec"); // Declination of boresight
-        float pa      = psMetadataLookupF32(NULL, arguments, "-pa"); // Position angle
-        float seeing  = psMetadataLookupF32(NULL, arguments, "-seeing"); // Zero point
+        float pa      = psMetadataLookupF32(NULL, arguments, "-pa");  // Position angle
+        float seeing  = psMetadataLookupF32(NULL, arguments, "-seeing"); // seeing (FWHM in arcsec)
 
 	// XXX scale and zp should be supplied by the config file (allow override, but this is camera-dependent)
@@ -199,5 +201,5 @@
         }
 
-        float zp      = psMetadataLookupF32(NULL, arguments, "-zp"); // Zero point
+        float zp = psMetadataLookupF32(NULL, arguments, "-zp"); // Zero point
 	if (isnan(zp)) {
 	    // use the filter to get the zeropoint from the recipe
@@ -234,15 +236,20 @@
 	}
 
-        psMetadataAddF32(config->arguments, PS_LIST_TAIL, "RA", 0, "Boresight RA (radians)", ra0 * M_PI / 180.0);
-        psMetadataAddF32(config->arguments, PS_LIST_TAIL, "DEC", 0, "Boresight Declination (radians)", dec0 * M_PI / 180.0);
-        psMetadataAddF32(config->arguments, PS_LIST_TAIL, "PA", 0, "Boresight position angle (radians)",pa * M_PI / 180.0);
-        psMetadataAddF32(config->arguments, PS_LIST_TAIL, "SEEING", 0, "Seeing sigma (pix)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale);
-
-        psMetadataAddF32(config->arguments, PS_LIST_TAIL, "SCALE", 0, "Plate scale (arcsec/pix)", scale);
-        psMetadataAddF32(config->arguments, PS_LIST_TAIL, "ZEROPOINT", 0, "Photometric zeropoint", zp);
-        psMetadataAddF32(config->arguments, PS_LIST_TAIL, "SKY.MAGS", 0, "sky surface brightness", skymags);
-
-        const char *psfClass = psMetadataLookupStr(NULL, arguments, "-psfclass"); // Filter name
+        psMetadataAddF32(options, PS_LIST_TAIL, "RA", 0, "Boresight RA (radians)", ra0 * M_PI / 180.0);
+        psMetadataAddF32(options, PS_LIST_TAIL, "DEC", 0, "Boresight Declination (radians)", dec0 * M_PI / 180.0);
+        psMetadataAddF32(options, PS_LIST_TAIL, "PA", 0, "Boresight position angle (radians)",pa * M_PI / 180.0);
+
+	// the user supplies FWHM in arcsec; here we convert to Sigma in pixels
+        psMetadataAddF32(options, PS_LIST_TAIL, "SEEING", 0, "Seeing SIGMA (pixels)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale);
+
+        psMetadataAddF32(options, PS_LIST_TAIL, "SCALE", 0, "Plate scale (arcsec/pix)", scale);
+        psMetadataAddF32(options, PS_LIST_TAIL, "ZEROPOINT", 0, "Photometric zeropoint", zp);
+        psMetadataAddF32(options, PS_LIST_TAIL, "SKY.MAGS", 0, "sky surface brightness", skymags);
+
+        const char *psfClass = psMetadataLookupStr(NULL, arguments, "-psfclass"); // PSF model class
         psMetadataAddStr(config->arguments, PS_LIST_TAIL, "PSF.MODEL", 0, "PSF model class", psfClass);
+
+        const char *galModel = psMetadataLookupStr(NULL, arguments, "-galmodel"); // Galaxy model name
+        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "GALAXY.MODEL", 0, "Galaxy model", galModel);
     }
 
@@ -250,2 +257,17 @@
     return;
 }
+
+/* the following elements come from the config->arguments:
+   
+   PSPHOT.PSF
+   INPUT
+   TYPE
+   FILTER
+   BIAS.ORDER
+   BINNING
+   OUTPUT
+   PSF.MODEL
+   GALAXY.MODEL
+
+   all othr values should come from the recipe
+*/
