Index: trunk/ppImage/src/ppImageArguments.c
===================================================================
--- trunk/ppImage/src/ppImageArguments.c	(revision 23259)
+++ trunk/ppImage/src/ppImageArguments.c	(revision 23268)
@@ -108,8 +108,5 @@
 
     // the input file is a required argument; if not found, we will exit
-    bool status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
-    if (!status) {
-        usage ();
-    }
+    pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
 
     // if these command-line options are supplied, load the file name lists into config->arguments
@@ -142,10 +139,10 @@
         psArgumentRemove(argnum, &argc, argv);
 
-	unsigned int nFail = 0;
-	psMetadata *normlist = psMetadataConfigRead (NULL, &nFail, argv[argnum], false);
-	// XXX allow this file to be in nebulous?
+        unsigned int nFail = 0;
+        psMetadata *normlist = psMetadataConfigRead (NULL, &nFail, argv[argnum], false);
+        // XXX allow this file to be in nebulous?
 
         psMetadataAddMetadata(config->arguments, PS_LIST_TAIL, "NORMALIZATION.TABLE", 0, "Normalization to apply", normlist);
-	psFree (normlist);
+        psFree (normlist);
         psArgumentRemove(argnum, &argc, argv);
     }
Index: trunk/ppImage/src/ppImageDefineFile.c
===================================================================
--- trunk/ppImage/src/ppImageDefineFile.c	(revision 23259)
+++ trunk/ppImage/src/ppImageDefineFile.c	(revision 23268)
@@ -5,51 +5,52 @@
 # include "ppImage.h"
 
-bool ppImageDefineFile (pmConfig *config, pmFPA *input, char *filerule, char *argname, pmFPAfileType fileType, pmDetrendType detrendType) {
+bool ppImageDefineFile(pmConfig *config, pmFPA *input, char *filerule, char *argname,
+                       pmFPAfileType fileType, pmDetrendType detrendType)
+{
+    bool status;
+    pmFPAfile *file = NULL;             // File to be defined
 
-    bool status;
-    pmFPAfile *file;
-
-    // look for the file on the argument list
-    file = pmFPAfileDefineFromArgs  (&status, config, filerule, argname);
-    if (!status) {
-	psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
-	return false;
+    if (!file) {
+        // look for the file on the RUN metadata
+        file = pmFPAfileDefineFromRun(&status, config, filerule);
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to load file definition");
+            return false;
+        }
     }
-    if (file) {
-	if (file->type != fileType) {
-	    psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType (fileType));
-	    return false;
-	}
-	return true;
+    if (!file) {
+        // look for the file on the argument list
+        file = pmFPAfileDefineFromArgs(&status, config, filerule, argname);
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to load file definition");
+            return false;
+        }
+    }
+    if (!file) {
+        // look for the file in the camera config table
+        file = pmFPAfileDefineFromConf(&status, config, filerule);
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to load file definition");
+            return false;
+        }
+    }
+    if (!file) {
+        // look for the file to be loaded from the detrend database
+        file = pmFPAfileDefineFromDetDB(&status, config, filerule, input, detrendType);
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to load file definition");
+            return false;
+        }
     }
 
-    // look for the file in the camera config table
-    file = pmFPAfileDefineFromConf  (&status, config, filerule);
-    if (!status) {
-	psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
-	return false;
-    }
-    if (file) {
-	if (file->type != fileType) {
-	    psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType (fileType));
-	    return false;
-	}
-	return true;
+    if (!file) {
+        return false;
     }
 
-    // look for the file to be loaded from the detrend database
-    file = pmFPAfileDefineFromDetDB (&status, config, filerule, input, detrendType);
-    if (!status) {
-	psError (PS_ERR_UNKNOWN, false, "failed to load file definition");
-	return false;
+    if (file->type != fileType) {
+        psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType));
+        return false;
     }
-    if (file) {
-	if (file->type != fileType) {
-	    psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType (fileType));
-	    return false;
-	}
-	return true;
-    }
-    return false;
+    return true;
 }
 
Index: trunk/ppImage/src/ppImageParseCamera.c
===================================================================
--- trunk/ppImage/src/ppImageParseCamera.c	(revision 23259)
+++ trunk/ppImage/src/ppImageParseCamera.c	(revision 23268)
@@ -9,44 +9,16 @@
     bool status = false;
 
-    // the input image defines the camera, and all recipes and options the follow
-    pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PPIMAGE.INPUT", "INPUT");
-    if (!status || !input) {
-        psError(PS_ERR_IO, false, "Failed to build FPA from PPIMAGE.INPUT");
-        return NULL;
-    }
-    if (input->type != PM_FPA_FILE_IMAGE) {
-        psError(PS_ERR_IO, true, "PPIMAGE.INPUT is not of type IMAGE");
-        return NULL;
-    }
-
-    // if MASK or VARIANCE was supplied on command line, bind files to 'input'.
-    // the mask and variance will be mosaicked with the image
-    pmFPAfile *inputMask = pmFPAfileBindFromArgs(&status, input, config, "PPIMAGE.INPUT.MASK", "PPIMAGE.INPUT.MASK");
-    if (!status) {
-        psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
-        return NULL;
-    }
-    if (inputMask) {
-      if (inputMask->type != PM_FPA_FILE_MASK) {
-        psError(PS_ERR_IO, true, "PPIMAGE.INPUT.MASK is not of type MASK");
-        return NULL;
-      }
-    }
-
-    pmFPAfile *inputVariance = pmFPAfileBindFromArgs(&status, input, config, "PPIMAGE.INPUT.VARIANCE", "PPIMAGE.INPUT.VARIANCE");
-    if (!status) {
-        psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
-        return NULL;
-    }
-    if (inputVariance && inputVariance->type != PM_FPA_FILE_VARIANCE) {
-        psError(PS_ERR_IO, true, "PPIMAGE.INPUT.VARIANCE is not of type VARIANCE");
-        return NULL;
-    }
+    if (!ppImageDefineFile(config, NULL, "PPIMAGE.INPUT", "INPUT", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_NONE)) {
+        psError(PS_ERR_IO, false, "Can't find an input image source");
+        return NULL;
+    }
+    pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPIMAGE.INPUT"); // Input file
+    psAssert(input, "We just put it there!");
 
     // add recipe options supplied on command line
-    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, RECIPE_NAME);
+    psMetadata *recipe  = psMetadataLookupPtr(&status, config->recipes, RECIPE_NAME);
 
     // parse the options from the metadata format to the ppImageOptions structure
-    ppImageOptions *options = ppImageOptionsParse (config);
+    ppImageOptions *options = ppImageOptionsParse(config);
 
     // the following are defined from the argument list, if given,
@@ -54,27 +26,33 @@
     // not all input or output images are used in a given recipe
     if (options->doBias) {
-        if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.BIAS", "BIAS", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_BIAS)) {
-            psError (PS_ERR_IO, false, "Can't find a bias image source");
-            psFree (options);
+        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.BIAS", "BIAS",
+                               PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_BIAS)) {
+            psError(PS_ERR_IO, false, "Can't find a bias image source");
+            psFree(options);
             return NULL;
         }
     }
     if (options->doDark) {
-        if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.DARK", "DARK", PM_FPA_FILE_DARK, PM_DETREND_TYPE_DARK)) {
-            psError (PS_ERR_IO, false, "Can't find a dark image source");
-            psFree (options);
+        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.DARK", "DARK",
+                               PM_FPA_FILE_DARK, PM_DETREND_TYPE_DARK)) {
+            psError(PS_ERR_IO, false, "Can't find a dark image source");
+            psFree(options);
             return NULL;
         }
     }
     if (options->doMask) {
-
-        if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.MASK", "MASK", PM_FPA_FILE_MASK, PM_DETREND_TYPE_MASK)) {
-            psError (PS_ERR_IO, false, "Can't find a mask image source");
-            psFree (options);
-            return NULL;
-        }
+        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.MASK", "MASK",
+                               PM_FPA_FILE_MASK, PM_DETREND_TYPE_MASK)) {
+            psError(PS_ERR_IO, false, "Can't find a mask image source");
+            psFree(options);
+            return NULL;
+        }
+
+#if 0
+        // I think this is now done automatically in the pmFPAfileDefine and pmFPAfileIOChecks -- PAP.
+
         // XXX have ppImageDefineFile return the pmFPAfile?
         pmFPAfile *mask = psMetadataLookupPtr(&status, config->files, "PPIMAGE.MASK");
-        psAssert (mask, "mask not defined?  not possible!");
+        psAssert(mask, "Just defined the mask!");
 
         // Need to read the names of bit masks from the mask header and set them in the
@@ -84,5 +62,5 @@
             // XXX need to load the mask bit names from one of the headers
             // this grabs the first available hdu : no guarantee that it will be valid, though
-            pmHDU *hdu = pmHDUGetFirst (mask->fpa);
+            pmHDU *hdu = pmHDUGetFirst(mask->fpa);
             if (!hdu) {
                 psError(PS_ERR_IO, true, "no valid HDU for PPIMAGE.INPUT.MASK");
@@ -90,14 +68,16 @@
             }
             // XXX is this consistent with the pmConfigMaskReadHeader call above?
-            if (!pmConfigMaskReadHeader (config, hdu->header)) {
+            if (!pmConfigMaskReadHeader(config, hdu->header)) {
                 psError(PS_ERR_IO, false, "error in mask bits");
                 return NULL;
             }
         }
+#endif
     }
     if (options->doShutter) {
-        if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.SHUTTER", "SHUTTER", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_SHUTTER)) {
-            psError (PS_ERR_IO, false, "Can't find a shutter image source");
-            psFree (options);
+        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.SHUTTER", "SHUTTER",
+                               PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_SHUTTER)) {
+            psError(PS_ERR_IO, false, "Can't find a shutter image source");
+            psFree(options);
             return NULL;
         }
@@ -105,15 +85,16 @@
 
     if (options->doFlat) {
-        if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.FLAT", "FLAT", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_FLAT)) {
-            psError (PS_ERR_IO, false, "Can't find a flat image source");
-            psFree (options);
-            return NULL;
-        }
-    }
-
-    int nThreads = psMetadataLookupS32 (&status, config->arguments, "NTHREADS");
+        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.FLAT", "FLAT",
+                               PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_FLAT)) {
+            psError(PS_ERR_IO, false, "Can't find a flat image source");
+            psFree(options);
+            return NULL;
+        }
+    }
+
+    int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS");
     if (nThreads > 0) {
-        int nScanRows = psMetadataLookupS32 (&status, recipe, "SCAN.ROWS");
-        pmDetrendSetThreadTasks (nScanRows);
+        int nScanRows = psMetadataLookupS32(&status, recipe, "SCAN.ROWS");
+        pmDetrendSetThreadTasks(nScanRows);
     }
 
@@ -166,5 +147,6 @@
 skip_fringe:
     if (options->doFringe) {
-        if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.FRINGE", "FRINGE", PM_FPA_FILE_FRINGE, PM_DETREND_TYPE_FRINGE)) {
+        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.FRINGE", "FRINGE",
+                               PM_FPA_FILE_FRINGE, PM_DETREND_TYPE_FRINGE)) {
             psError (PS_ERR_IO, false, "Can't find a fringe image source");
             return NULL;
@@ -283,5 +265,6 @@
         // define associated psphot input/output files
         if (!psphotDefineFiles (config, psphotInput)) {
-            psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot");
+            psError(PSPHOT_ERR_CONFIG, false,
+                    "Trouble defining the additional input/output files for psphot");
             return false;
         }
@@ -291,23 +274,25 @@
     if (options->doAstromChip || options->doAstromMosaic) {
         if (!options->doPhotom) {
-            psError (PSASTRO_ERR_CONFIG, false, "photometry mode is not selected; it is required for astrometry");
+            psError(PSASTRO_ERR_CONFIG, false,
+                    "Photometry mode is not selected; it is required for astrometry");
             return false;
         }
 
-        pmFPAfile *psphotOutput = psMetadataLookupPtr (&status, config->files, "PSPHOT.OUTPUT");
-        PS_ASSERT (psphotOutput, false);
-
-        pmFPAfile *psastroInput = pmFPAfileDefineInput (config, psphotOutput->fpa, NULL, "PSASTRO.INPUT");
-        PS_ASSERT (psastroInput, false);
+        pmFPAfile *psphotOutput = psMetadataLookupPtr(&status, config->files, "PSPHOT.OUTPUT");
+        PS_ASSERT(psphotOutput, false);
+
+        pmFPAfile *psastroInput = pmFPAfileDefineInput(config, psphotOutput->fpa, NULL, "PSASTRO.INPUT");
+        PS_ASSERT(psastroInput, false);
         psastroInput->mode = PM_FPA_MODE_REFERENCE;
 
         // define associated psphot input/output files
-        if (!psastroDefineFiles (config, psastroInput)) {
-            psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psastro");
+        if (!psastroDefineFiles(config, psastroInput)) {
+            psError(PSPHOT_ERR_CONFIG, false,
+                    "Trouble defining the additional input/output files for psastro");
             return false;
         }
 
         // deactivate the psastro files, reactive when needed
-        pmFPAfileActivate (config->files, false, "PSASTRO.OUTPUT");
+        pmFPAfileActivate(config->files, false, "PSASTRO.OUTPUT");
     }
 
@@ -325,7 +310,7 @@
 
     // outImage is used as a carrier: input to chipImage -> require the data to remain at the CHIP level
-    outImage->freeLevel = PS_MIN (outImage->freeLevel, PM_FPA_LEVEL_CHIP);
+    outImage->freeLevel = PS_MIN(outImage->freeLevel, PM_FPA_LEVEL_CHIP);
     outImage->dataLevel = outImage->freeLevel;
-    outImage->fileLevel = PS_MIN (outImage->fileLevel, outImage->dataLevel);
+    outImage->fileLevel = PS_MIN(outImage->fileLevel, outImage->dataLevel);
 
     // outMask and outVariance must be freed at the same level as outImage (all freed by pmFPAFreeData)
@@ -342,8 +327,9 @@
 
     // the input data is the same as the outImage data : force the free levels to match
-    input->freeLevel = PS_MIN (outImage->freeLevel, input->freeLevel);
+    input->freeLevel = PS_MIN(outImage->freeLevel, input->freeLevel);
 
     // define the binned target files (which may just be carriers for some camera configurations)
-    pmFPAfile *bin1 = pmFPAfileDefineFromFPA (config, chipImage->fpa, options->xBin1, options->yBin1, "PPIMAGE.BIN1");
+    pmFPAfile *bin1 = pmFPAfileDefineFromFPA(config, chipImage->fpa, options->xBin1, options->yBin1,
+                                             "PPIMAGE.BIN1");
     if (!bin1) {
         psError(PS_ERR_IO, false, _("Unable to generate new file from PPIMAGE.BIN1"));
@@ -357,5 +343,6 @@
     }
 
-    pmFPAfile *bin2 = pmFPAfileDefineFromFPA (config, chipImage->fpa, options->xBin2, options->yBin2, "PPIMAGE.BIN2");
+    pmFPAfile *bin2 = pmFPAfileDefineFromFPA(config, chipImage->fpa, options->xBin2, options->yBin2,
+                                             "PPIMAGE.BIN2");
     if (!bin2) {
         psError(PS_ERR_IO, false, _("Unable to generate new file from PPIMAGE.BIN2"));
@@ -373,5 +360,5 @@
     bin2->freeLevel = PM_FPA_LEVEL_FPA;
 
-    pmFPAfile *jpg1 = pmFPAfileDefineOutput (config, byFPA1->fpa, "PPIMAGE.JPEG1");
+    pmFPAfile *jpg1 = pmFPAfileDefineOutput(config, byFPA1->fpa, "PPIMAGE.JPEG1");
     if (!jpg1) {
         psError(PS_ERR_IO, false, _("Unable to generate new file from PPIMAGE.JPEG1"));
@@ -384,5 +371,5 @@
         return NULL;
     }
-    pmFPAfile *jpg2 = pmFPAfileDefineOutput (config, byFPA2->fpa, "PPIMAGE.JPEG2");
+    pmFPAfile *jpg2 = pmFPAfileDefineOutput(config, byFPA2->fpa, "PPIMAGE.JPEG2");
     if (!jpg2) {
         psError(PS_ERR_IO, false, _("Unable to generate new file from PPIMAGE.JPEG2"));
@@ -404,5 +391,5 @@
     // Chip selection: turn on only the chips specified (pass status to suppress missing-key log msg)
     char *chipLine = psMetadataLookupStr(&status, config->arguments, "CHIP_SELECTIONS");
-    psArray *chips = psStringSplitArray (chipLine, ",", false);
+    psArray *chips = psStringSplitArray(chipLine, ",", false);
     if (chips->n > 0) {
         pmFPASelectChip (input->fpa, -1, true); // deselect all chips
@@ -454,5 +441,5 @@
     if (psTraceGetLevel("ppImage.config") > 0) {
         // Get a look inside all the files.
-        psMetadataIterator *filesIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD, NULL); // Iterator
+        psMetadataIterator *filesIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD, NULL);
         psMetadataItem *item;               // Item from iteration
         fprintf(stderr, "Files:\n");
