Index: trunk/pswarp/src/pswarpArguments.c
===================================================================
--- trunk/pswarp/src/pswarpArguments.c	(revision 23292)
+++ trunk/pswarp/src/pswarpArguments.c	(revision 23293)
@@ -87,11 +87,6 @@
 
 
-    if (!pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list")) {
-        psError(PSWARP_ERR_ARGUMENTS, true, "Missing -file (input) or -list (input)");
-        return NULL;
-    }
-
-    // the mask and variance entries are optional (build from gain?)
-    pmConfigFileSetsMD (config->arguments, &argc, argv, "MASK",   "-mask",   "-masklist");
+    pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
+    pmConfigFileSetsMD (config->arguments, &argc, argv, "MASK", "-mask", "-masklist");
     pmConfigFileSetsMD (config->arguments, &argc, argv, "VARIANCE", "-variance", "-variancelist");
 
@@ -105,14 +100,14 @@
 
     // output position is fixed
-    psMetadataAddStr (config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "", argv[1]);
+    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "", argv[1]);
 
     // skycell position is fixed
     array = psArrayAlloc(1);
-    array->data[0] = psStringCopy (argv[2]);
-    status = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "SKYCELL", PS_DATA_ARRAY, "", array);
-    psFree (array);
+    array->data[0] = psStringCopy(argv[2]);
+    status = psMetadataAddPtr(config->arguments, PS_LIST_TAIL, "SKYCELL", PS_DATA_ARRAY, "", array);
+    psFree(array);
 
     psTrace("pswarp", 1, "Done with pswarpArguments...\n");
-    return (config);
+    return config;
 }
 
Index: trunk/pswarp/src/pswarpLoop.c
===================================================================
--- trunk/pswarp/src/pswarpLoop.c	(revision 23292)
+++ trunk/pswarp/src/pswarpLoop.c	(revision 23293)
@@ -83,4 +83,9 @@
     }
 
+    if (!pswarpSetMaskBits(config)) {
+        psError(PS_ERR_IO, false, "failed to set mask bits");
+        return NULL;
+    }
+
     // output mask bits
     psImageMaskType maskValue = psMetadataLookupImageMask(&status, recipe, "MASK.OUTPUT");
Index: trunk/pswarp/src/pswarpParseCamera.c
===================================================================
--- trunk/pswarp/src/pswarpParseCamera.c	(revision 23292)
+++ trunk/pswarp/src/pswarpParseCamera.c	(revision 23293)
@@ -11,62 +11,80 @@
  */
 
-# include "pswarp.h"
+#include "pswarp.h"
+
+// Define an input file
+static pmFPAfile *defineInputFile(pmConfig *config,// Configuration
+                                  pmFPAfile *bind,    // File to which to bind, or NULL
+                                  char *filerule,     // Name of file rule
+                                  char *argname,      // Argument name
+                                  pmFPAfileType fileType // Type of file
+    )
+{
+    bool status;
+
+    // look for the file on the RUN metadata
+    pmFPAfile *file = pmFPAfileDefineFromRun(&status, config, filerule); // File to return
+    if (!status) {
+        psError(PSWARP_ERR_CONFIG, false, "Failed to load file definition");
+        return NULL;
+    }
+    if (!file) {
+        // look for the file on the argument list
+        if (bind) {
+            file = pmFPAfileBindFromArgs(&status, bind, config, filerule, argname);
+        } else {
+            file = pmFPAfileDefineFromArgs(&status, config, filerule, argname);
+        }
+        if (!status) {
+            psError(PSWARP_ERR_CONFIG, false, "Failed to load file definition");
+            return false;
+        }
+    }
+
+    if (!file) {
+        return NULL;
+    }
+
+    if (file->type != fileType) {
+        psError(PSWARP_ERR_CONFIG, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType));
+        return NULL;
+    }
+
+    return file;
+}
+
+
+
 
 bool pswarpParseCamera(pmConfig *config)
 {
-    bool status;
-    bool mdok;                          ///< Status of MD lookup
-    pmFPAfile *skycell = NULL;
-    pmConfig *skyConfig = NULL;
+    psAssert(config, "Require configuration");
 
-    // the input image(s) are required arguments; they define the camera
-    status = false;
-    pmFPAfile *input = pmFPAfileDefineFromArgs(&status, config, "PSWARP.INPUT", "INPUT");
-    if (!input || !status) {
+    // The input image(s) is required: it defines the camera
+    pmFPAfile *input = defineInputFile(config, NULL, "PSWARP.INPUT", "INPUT", PM_FPA_FILE_IMAGE);
+    if (!input) {
         psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.INPUT");
         return false;
     }
 
-    // the input image(s) are required arguments; they define the camera
-    status = false;
-    pmFPAfile *astrom = pmFPAfileDefineFromArgs(&status, config, "PSWARP.ASTROM", "ASTROM");
-    if (!status) {
-        psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
-        return NULL;
-    }
-    if (astrom) {
-        psLogMsg ("pswarp", 3, "using supplied astrometry\n");
-    } else {
-        psLogMsg ("pswarp", 3, "using header astrometry\n");
+    pmFPAfile *astrom = defineInputFile(config, NULL, "PSWARP.ASTROM", "ASTROM", PM_FPA_FILE_CMF);
+    psLogMsg("pswarp", PS_LOG_INFO, "Astrometry source: %s", astrom ? "supplied" : "header");
+
+    pmFPAfile *inMask = defineInputFile(config, input, "PSWARP.MASK", "MASK", PM_FPA_FILE_MASK);
+    if (!inMask) {
+        psLogMsg("pswarp", PS_LOG_INFO, "No mask supplied");
     }
 
-    // the mask is not required - but must conform to input camera
-    pmFPAfile *inMask = pmFPAfileBindFromArgs(&status, input, config, "PSWARP.MASK", "MASK");
-    if (!status) {
-        psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
-        return NULL;
-    }
-    if (!inMask) {
-        psLogMsg ("pswarp", 3, "no mask supplied\n");
+    pmFPAfile *inVariance = defineInputFile(config, input, "PSWARP.VARIANCE", "VARIANCE",
+                                            PM_FPA_FILE_VARIANCE);
+    if (!inVariance) {
+        psLogMsg("pswarp", PS_LOG_INFO, "No variance supplied");
     }
 
-    // loading the mask here should have invoked pmConfigMaskReadHeader()
-    if (!pswarpSetMaskBits (config)) {
-        psError(PS_ERR_IO, false, "failed to set mask bits");
-        return NULL;
-    }
-
-    pmFPAfile *inVariance = pmFPAfileBindFromArgs(&status, input, config, "PSWARP.VARIANCE", "VARIANCE");
-    if (!status) {
-        psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
-        return NULL;
-    }
-    if (!inVariance) {
-        psLogMsg ("pswarp", 3, "no variance supplied\n");
-    }
-
-    // the input skycell is a required argument: it defines the output image
+    // The input skycell is a required argument: it defines the output image
     // XXX we may need a different skycell structure here
-    status = pswarpDefineSkycell(&skycell, &skyConfig, config, "PSWARP.SKYCELL", "SKYCELL");
+    pmFPAfile *skycell = NULL;
+    pmConfig *skyConfig = NULL;
+    bool status = pswarpDefineSkycell(&skycell, &skyConfig, config, "PSWARP.SKYCELL", "SKYCELL");
     if (!status) {
         psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.SKYCELL");
@@ -81,4 +99,6 @@
         return false;
     }
+    output->save = true;
+
     pmFPAfile *outMask = pmFPAfileDefineSkycell(config, output->fpa, "PSWARP.OUTPUT.MASK");
     if (!outMask) {
@@ -86,6 +106,4 @@
         return false;
     }
-
-    output->save = true;
     outMask->save = true;
 
@@ -108,4 +126,5 @@
     }
 
+    bool mdok;                          // Status of MD lookup
     if (psMetadataLookupBool(&mdok, config->arguments, "PSF")) {
         // This file, PSPHOT.INPUT, is just used as a carrier; output files (eg, PSPHOT.RESID) are defined by
@@ -160,5 +179,5 @@
             }
         }
-        psFree (chips);
+        psFree(chips);
     }
 
