Index: trunk/pswarp/src/pswarpArguments.c
===================================================================
--- trunk/pswarp/src/pswarpArguments.c	(revision 34800)
+++ trunk/pswarp/src/pswarpArguments.c	(revision 35563)
@@ -12,10 +12,10 @@
 
 # include "pswarp.h"
-# include <glob.h>
-
 
 static void usage (void) {
-    fprintf(stderr, "USAGE: pswarp [-file image(s)] [-list imagelist] [options] (output) (skycell)\n");
+    fprintf(stderr, "USAGE: pswarp [-input input.mdc] [-file image(s)] [-list imagelist] [options] (output) (skycell)\n");
     fprintf(stderr, "  options:\n");
+    fprintf(stderr, "    [-input input.mdc] : input image information in a metadata file\n");
+    fprintf(stderr, "    [-file input.fits[,input.fits]] : input image to be warped\n");
     fprintf(stderr, "    [-astrom astrom.cmp] : provide an alternative astrometry calibration\n");
     fprintf(stderr, "    [-mask mask.fits] : provide a corresponding mask image\n");
@@ -24,5 +24,4 @@
     exit(PS_EXIT_CONFIG_ERROR);
 }
-
 
 pmConfig *pswarpArguments (int argc, char **argv) {
@@ -55,12 +54,11 @@
     }
 
+    // XXX move to the single group below?
     pmConfigFileSetsMD(config->arguments, &argc, argv, "ASTROM",   "-astrom", "-astromlist");
 
-    {
-        int arg;                        ///< Argument Number
-        if ((arg = psArgumentGet(argc, argv, "-psphot-visual"))) {
-            psArgumentRemove(arg, &argc, argv);
-            pmVisualSetVisual(true);
-        }
+    // turn on psphot visualization
+    if ((N = psArgumentGet(argc, argv, "-psphot-visual"))) {
+	psArgumentRemove(N, &argc, argv);
+	pmVisualSetVisual(true);
     }
 
@@ -83,14 +81,50 @@
     pswarpSetThreads();
 
-    pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
-    pmConfigFileSetsMD (config->arguments, &argc, argv, "MASK", "-mask", "-masklist");
-    pmConfigFileSetsMD (config->arguments, &argc, argv, "VARIANCE", "-variance", "-variancelist");
-    pmConfigFileSetsMD (config->arguments, &argc, argv, "BACKGROUND", "-background", "-bkglist");
+    // there are three mutually exclusive ways of providing the input
+    // 1) supply -file (filename) [-mask .. -variance ..] on the command line
+    // 2) supply -input (input.mdc) on the command line
+    // 3) load inputs from RUN config info
+
+    // below, we check first for -file then for -input.  failure to find either implies use of
+    // the configuration metadata file.
+
+    bool singleInput = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
+    if (singleInput) {
+	if (psArgumentGet(argc, argv, "-input")) {
+	    psErrorStackPrint(stderr, "error in arguments : -input and -file / -list are mutually exclusive");
+	    exit(PS_EXIT_CONFIG_ERROR);
+	}	
+	pmConfigFileSetsMD (config->arguments, &argc, argv, "MASK", "-mask", "-masklist");
+	pmConfigFileSetsMD (config->arguments, &argc, argv, "VARIANCE", "-variance", "-variancelist");
+	pmConfigFileSetsMD (config->arguments, &argc, argv, "BACKGROUND", "-background", "-bkglist");
+    } else {
+	// find the input data file (an mdc file)
+	if ((N = psArgumentGet(argc, argv, "-input"))) {
+	    if (argc <= N+1) {
+		psErrorStackPrint(stderr, "Expected to see 1 more argument; saw %d", argc - 1);
+		exit(PS_EXIT_CONFIG_ERROR);
+	    }
+	    psArgumentRemove(N, &argc, argv);
+
+	    unsigned int numBad = 0;                     // Number of bad lines
+	    psMetadata *inputs = psMetadataConfigRead(NULL, &numBad, argv[N], false); // Input file info
+	    if (!inputs || numBad > 0) {
+		psErrorStackPrint(stderr, "Unable to cleanly read MDC file with inputs.");
+		exit(PS_EXIT_CONFIG_ERROR);
+	    }
+	    psMetadataAddMetadata(config->arguments, PS_LIST_TAIL, "INPUTS", 0, "Metadata with input details", inputs);
+	    psFree(inputs);
+
+	    psArgumentRemove(N, &argc, argv);
+	}
+    }
+    if (argc != 3) {
+	usage();
+    }
+    if (psErrorCodeLast() != PS_ERR_NONE) {
+	psErrorStackPrint(stderr, "error in arguments");
+	exit(PS_EXIT_CONFIG_ERROR);
+    }
     
-    if (argc != 3) {
-        usage();
-    }
-
-
     psArray *array;
 
@@ -107,114 +141,2 @@
     return config;
 }
-
-/**
- * Parse the recipe and format into the arguments
- */
-bool pswarpOptions(pmConfig *config)
-{
-    // Select the appropriate recipe
-    psMetadata *recipe  = psMetadataLookupPtr(NULL, config->recipes, PSWARP_RECIPE);
-    if (!recipe) {
-        psError(PSWARP_ERR_CONFIG, true, "Can't find %s recipe!\n", PSWARP_RECIPE);
-        return false;
-    }
-
-    // Get grid size
-    bool status;                        ///< Status of MD lookup
-    int nGridX = psMetadataLookupS32(&status, recipe, "GRID.NX");
-    if (!status || nGridX <= 0) {
-        nGridX = 128;
-        psWarning("GRID.NX is not set in the recipe --- defaulting to %d", nGridX);
-    }
-    int nGridY = psMetadataLookupS32(&status, recipe, "GRID.NY");
-    if (!status) {
-        nGridY = 128;
-        psWarning("GRID.NY is not set in the recipe --- defaulting to %d", nGridY);
-    }
-
-    // Get interpolation mode
-    const char *name = psMetadataLookupStr (&status, recipe, "INTERPOLATION.MODE"); ///< Name of interp mode
-    if (!name) {
-        name = "BILINEAR";
-        psLogMsg("pswarp", 3, "defaulting to %s interpolation", name);
-    }
-    psImageInterpolateMode interpolationMode = psImageInterpolateModeFromString(name); ///< Mode for interp.
-    if (interpolationMode == PS_INTERPOLATE_NONE) {
-        interpolationMode = PS_INTERPOLATE_BILINEAR;
-        psLogMsg ("pswarp", 3,
-                  "Unknown interpolation mode %s, defaulting to bilinear interpolation\n", name);
-        name = "BILINEAR";
-    }
-
-    int numKernels = psMetadataLookupS32(&status, recipe, "INTERPOLATION.NUM");
-    if (!status) {
-        numKernels = 0;
-        psWarning("INTERPOLATION.NUM is not set in the recipe --- defaulting to %d", numKernels);
-    }
-
-    float poorFrac = psMetadataLookupF32(&status, recipe, "POOR.FRAC"); ///< Frac of bad flux for a "poor"
-    if (!status) {
-        poorFrac = 0.0;
-        psWarning("POOR.FRAC is not set in the %s recipe --- defaulting to %f.", PSWARP_RECIPE, poorFrac);
-    }
-
-    bool PSF = psMetadataLookupBool(&status, recipe, "PSF"); ///< Generate a PSF model?
-    if (!status) {
-        PSF = true;
-        psWarning("PSF is not set in the %s recipe --- defaulting to TRUE.", PSWARP_RECIPE);
-    }
-
-    bool doBKG = psMetadataLookupBool(&status,recipe, "BACKGROUND.MODEL"); ///< Generate the warped background model?
-    if (!status) {
-      doBKG = false;
-      psWarning("BACKGROUND.MODEL is not set in the %s recipe -- defaulting to FALSE.", PSWARP_RECIPE);
-    }
-    int bkgXgrid = psMetadataLookupS32(&status,recipe, "BKG.XGRID"); ///< Xsize of background model
-    if (!status) {
-      bkgXgrid = 10;
-      psWarning("BKG.XGRID is not set in the %s recipe -- defaultint to %d.",PSWARP_RECIPE,bkgXgrid);
-    }
-    int bkgYgrid = psMetadataLookupS32(&status,recipe, "BKG.YGRID"); ///< Xsize of background model
-    if (!status) {
-      bkgYgrid = 10;
-      psWarning("BKG.YGRID is not set in the %s recipe -- defaultint to %d.",PSWARP_RECIPE,bkgYgrid);
-    }
-
-    
-    // Set recipe values in the recipe (since we've possibly altered some)
-    psMetadataAddS32(recipe, PS_LIST_TAIL, "GRID.NX", PS_META_REPLACE,
-                     "Iso-astrom grid spacing in x", nGridX);
-    psMetadataAddS32(recipe, PS_LIST_TAIL, "GRID.NY", PS_META_REPLACE,
-                     "Iso-astrom grid spacing in y", nGridY);
-    psMetadataAddStr(recipe, PS_LIST_TAIL, "INTERPOLATION.MODE", PS_META_REPLACE,
-                     "Interpolation mode", name);
-    psMetadataAddS32(recipe, PS_LIST_TAIL, "INTERPOLATION.NUM", PS_META_REPLACE,
-                     "Interpolation pre-calculated kernels", numKernels);
-    psMetadataAddF32(recipe, PS_LIST_TAIL, "POOR.FRAC", PS_META_REPLACE,
-                     "Fraction of bad flux for a pixel to be marked as poor", poorFrac);
-    psMetadataAddBool(recipe, PS_LIST_TAIL, "PSF", PS_META_REPLACE, "Generate a PSF Model?", PSF);
-    psMetadataAddBool(recipe, PS_LIST_TAIL, "BACKGROUND.MODEL", PS_META_REPLACE, "Generate the warped background model?", doBKG);
-    psMetadataAddS32(recipe, PS_LIST_TAIL, "BKG.XGRID", PS_META_REPLACE, "Xsize of background model", bkgXgrid);
-    psMetadataAddS32(recipe, PS_LIST_TAIL, "BKG.YGRID", PS_META_REPLACE, "Ysize of background model", bkgYgrid);
-    
-    
-    // Set recipe values in the arguments
-    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "GRID.NX", 0,
-                     "Iso-astrom grid spacing in x", nGridX);
-    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "GRID.NY", 0,
-                     "Iso-astrom grid spacing in y", nGridY);
-    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INTERPOLATION.MODE", 0,
-                     "Interpolation mode", interpolationMode);
-    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INTERPOLATION.NUM", 0,
-                     "Interpolation pre-calculated kernels", numKernels);
-    psMetadataAddF32(config->arguments, PS_LIST_TAIL, "POOR.FRAC", 0,
-                     "Fraction of bad flux for a pixel to be marked as poor", poorFrac);
-    psMetadataAddBool(config->arguments, PS_LIST_TAIL, "PSF", PS_META_REPLACE, "Generate a PSF Model?", PSF);
-    psMetadataAddBool(config->arguments, PS_LIST_TAIL, "BACKGROUND.MODEL", PS_META_REPLACE, "Generate the warped background model?", doBKG);
-    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BKG.XGRID", PS_META_REPLACE, "Xsize of background model", bkgXgrid);
-    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BKG.YGRID", PS_META_REPLACE, "Ysize of background model", bkgYgrid);
-
-    psTrace("pswarp", 1, "Done with pswarpArguments...\n");
-
-    return (config);
-}
