Index: trunk/psphot/src/psphotReadout.c
===================================================================
--- trunk/psphot/src/psphotReadout.c	(revision 29004)
+++ trunk/psphot/src/psphotReadout.c	(revision 29936)
@@ -9,5 +9,5 @@
 }
 
-bool psphotReadout(pmConfig *config, const pmFPAview *view) {
+bool psphotReadout(pmConfig *config, const pmFPAview *view, const char *filerule) {
 
     // measure the total elapsed time in psphotReadout.  dtime is the elapsed time used jointly
@@ -27,6 +27,12 @@
     psAssert (breakPt, "configuration error: set BREAK_POINT");
 
+    // remove cruft from the input analysis structure
+    if (!psphotCleanInputs (config, view, filerule)) {
+        psError (PSPHOT_ERR_PROG, false, "trouble setting up the inputs");
+        return false;
+    }
+
     // set the photcode for this image
-    if (!psphotAddPhotcode (config, view, "PSPHOT.INPUT")) {
+    if (!psphotAddPhotcode (config, view, filerule)) {
         psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
         return false;
@@ -34,102 +40,101 @@
 
     // Generate the mask and weight images, including the user-defined analysis region of interest
-    if (!psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT")) {
-        return psphotReadoutCleanup(config, view, "PSPHOT.INPUT");
+    if (!psphotSetMaskAndVariance (config, view, filerule)) {
+        return psphotReadoutCleanup(config, view, filerule);
     }
     if (!strcasecmp (breakPt, "NOTHING")) {
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
 
     // generate a background model (median, smoothed image)
-    if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) {
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
-    }
-
-    if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+    if (!psphotModelBackground (config, view, filerule)) {
+        return psphotReadoutCleanup (config, view, filerule);
+    }
+
+    if (!psphotSubtractBackground (config, view, filerule)) {
+        return psphotReadoutCleanup (config, view, filerule);
     }
     if (!strcasecmp (breakPt, "BACKMDL")) {
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
 
     // load the psf model, if suppled.  FWHM_MAJ,FWHM_MIN,etc are determined and saved on
-    // readout->analysis. XXX Note: this function currently only works with a single
-    // PSPHOT.INPUT
-    if (!psphotLoadPSF (config, view)) { // ??? need to supply 2 ?
+    // readout->analysis. NOTE: this function currently only loads from PSPHOT.PSF.LOAD
+    if (!psphotLoadPSF (config, view, filerule)) { // ??? need to supply 2 ?
         psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model");
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
 
     // find the detections (by peak and/or footprint) in the image.
-    if (!psphotFindDetections (config, view, "PSPHOT.INPUT", true)) { // pass 1
+    if (!psphotFindDetections (config, view, filerule, true)) { // pass 1
         // this only happens if we had an error in psphotFindDetections
         psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
 
     // construct sources and measure basic stats (saved on detections->newSources)
-    if (!psphotSourceStats (config, view, "PSPHOT.INPUT", true)) { // pass 1
+    if (!psphotSourceStats (config, view, filerule, true)) { // pass 1
         psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
     if (!strcasecmp (breakPt, "PEAKS")) {
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
 
     // find blended neighbors of very saturated stars (detections->newSources)
-    if (!psphotDeblendSatstars (config, view, "PSPHOT.INPUT")) {
+    if (!psphotDeblendSatstars (config, view, filerule)) {
         psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
 
     // mark blended peaks PS_SOURCE_BLEND (detections->newSources)
-    if (!psphotBasicDeblend (config, view, "PSPHOT.INPUT")) {
+    if (!psphotBasicDeblend (config, view, filerule)) {
         psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis");
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
 
     // classify sources based on moments, brightness.  if a PSF model has been loaded, the PSF
     // clump defined for it is used not measured (detections->newSources)
-    if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) { // pass 1
+    if (!psphotRoughClass (config, view, filerule)) { // pass 1
         psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications");
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
 
     // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources)
-    if (!psphotImageQuality (config, view, "PSPHOT.INPUT")) { // pass 1
+    if (!psphotImageQuality (config, view, filerule)) { // pass 1
         psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality");
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
     if (!strcasecmp (breakPt, "MOMENTS")) {
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
 
     // use bright stellar objects to measure PSF if we were supplied a PSF for any input file,
     // this step is skipped
-    if (!psphotChoosePSF (config, view, "PSPHOT.INPUT")) { // pass 1
+    if (!psphotChoosePSF (config, view, filerule)) { // pass 1
         psLogMsg ("psphot", 3, "failure to construct a psf model");
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
     if (!strcasecmp (breakPt, "PSFMODEL")) {
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
 
     // include externally-supplied sources
     // XXX fix this in the new multi-input context
-    // psphotLoadExtSources (config, view, "PSPHOT.INPUT"); // pass 1
+    // psphotLoadExtSources (config, view, filerule); // pass 1
 
     // construct an initial model for each object, set the radius to fitRadius, set circular
     // fit mask (detections->newSources)
-    psphotGuessModels (config, view, "PSPHOT.INPUT"); // pass 1
+    psphotGuessModels (config, view, filerule); // pass 1
 
     // merge the newly selected sources into the existing list
     // NOTE: merge OLD and NEW
-    psphotMergeSources (config, view, "PSPHOT.INPUT");
+    psphotMergeSources (config, view, filerule);
 
     // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
-    psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", false); // pass 1 (detections->allSources)
+    psphotFitSourcesLinear (config, view, filerule, false); // pass 1 (detections->allSources)
 
     // identify CRs and extended sources (only unmeasured sources are measured)
-    psphotSourceSize (config, view, "PSPHOT.INPUT", true); // pass 1 (detections->allSources)
+    psphotSourceSize (config, view, filerule, true); // pass 1 (detections->allSources)
     if (!strcasecmp (breakPt, "ENSEMBLE")) {
         goto finish;
@@ -138,12 +143,12 @@
     // non-linear PSF and EXT fit to brighter sources
     // replace model flux, adjust mask as needed, fit, subtract the models (full stamp)
-    psphotBlendFit (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
+    psphotBlendFit (config, view, filerule); // pass 1 (detections->allSources)
 
     // replace all sources
-    psphotReplaceAllSources (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
+    psphotReplaceAllSources (config, view, filerule); // pass 1 (detections->allSources)
 
     // linear fit to include all sources (subtract again)
     // NOTE : apply to ALL sources (extended + psf)
-    psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", true); // pass 2 (detections->allSources)
+    psphotFitSourcesLinear (config, view, filerule, true); // pass 2 (detections->allSources)
 
     // if we only do one pass, skip to extended source analysis
@@ -153,40 +158,40 @@
 
     // add noise for subtracted objects
-    psphotAddNoise (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
+    psphotAddNoise (config, view, filerule); // pass 1 (detections->allSources)
 
     // find fainter sources
     // NOTE: finds new peaks and new footprints, OLD and FULL set are saved on detections
-    psphotFindDetections (config, view, "PSPHOT.INPUT", false); // pass 2 (detections->peaks, detections->footprints)
+    psphotFindDetections (config, view, filerule, false); // pass 2 (detections->peaks, detections->footprints)
 
     // remove noise for subtracted objects (ie, return to normal noise level)
     // NOTE: this needs to operate only on the OLD sources
-    psphotSubNoise (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
+    psphotSubNoise (config, view, filerule); // pass 1 (detections->allSources)
 
     // define new sources based on only the new peaks
     // NOTE: new sources are saved on detections->newSources
-    psphotSourceStats (config, view, "PSPHOT.INPUT", false); // pass 2 (detections->newSources)
+    psphotSourceStats (config, view, filerule, false); // pass 2 (detections->newSources)
 
     // set source type
     // NOTE: apply only to detections->newSources
-    if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) { // pass 2 (detections->newSources)
+    if (!psphotRoughClass (config, view, filerule)) { // pass 2 (detections->newSources)
         psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
 
     // create full input models, set the radius to fitRadius, set circular fit mask
     // NOTE: apply only to detections->newSources
-    psphotGuessModels (config, view, "PSPHOT.INPUT"); // pass 2 (detections->newSources)
+    psphotGuessModels (config, view, filerule); // pass 2 (detections->newSources)
 
     // replace all sources so fit below applies to all at once
     // NOTE: apply only to OLD sources (which have been subtracted)
-    psphotReplaceAllSources (config, view, "PSPHOT.INPUT"); // pass 2
+    psphotReplaceAllSources (config, view, filerule); // pass 2
 
     // merge the newly selected sources into the existing list
     // NOTE: merge OLD and NEW
     // XXX check on free of sources...
-    psphotMergeSources (config, view, "PSPHOT.INPUT"); // (detections->newSources + detections->allSources -> detections->allSources)
+    psphotMergeSources (config, view, filerule); // (detections->newSources + detections->allSources -> detections->allSources)
 
     // NOTE: apply to ALL sources
-    psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", true); // pass 3 (detections->allSources)
+    psphotFitSourcesLinear (config, view, filerule, true); // pass 3 (detections->allSources)
 
 pass1finish:
@@ -194,8 +199,8 @@
     // measure source size for the remaining sources
     // NOTE: applies only to NEW (unmeasured) sources
-    psphotSourceSize (config, view, "PSPHOT.INPUT", false); // pass 2 (detections->allSources)
-
-    psphotExtendedSourceAnalysis (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
-    psphotExtendedSourceFits (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
+    psphotSourceSize (config, view, filerule, false); // pass 2 (detections->allSources)
+
+    psphotExtendedSourceAnalysis (config, view, filerule); // pass 1 (detections->allSources)
+    psphotExtendedSourceFits (config, view, filerule); // pass 1 (detections->allSources)
 
 finish:
@@ -205,15 +210,15 @@
 
     // measure aperture photometry corrections
-    if (!psphotApResid (config, view, "PSPHOT.INPUT")) { // pass 1 (detections->allSources)
+    if (!psphotApResid (config, view, filerule)) { // pass 1 (detections->allSources)
         psLogMsg ("psphot", 3, "failed on psphotApResid");
-        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
+        return psphotReadoutCleanup (config, view, filerule);
     }
 
     // calculate source magnitudes
-    if (!psphotMagnitudes(config, view, "PSPHOT.INPUT")) { // pass 1 (detections->allSources)
+    if (!psphotMagnitudes(config, view, filerule)) { // pass 1 (detections->allSources)
       psErrorStackPrint(stderr, "Unable to do magnitudes.");
         psErrorClear();
     }
-    if (!psphotEfficiency(config, view, "PSPHOT.INPUT")) { // pass 1
+    if (!psphotEfficiency(config, view, filerule)) { // pass 1
         psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
         psErrorClear();
@@ -224,20 +229,20 @@
 
     // replace background in residual image
-    if (!psphotSkyReplace (config, view, "PSPHOT.INPUT")) { // pass 1
+    if (!psphotSkyReplace (config, view, filerule)) { // pass 1
       psErrorStackPrint(stderr, "Unable to replace sky");
       psErrorClear();
 
 /*       psLogMsg("psphot", 3, "failed on psphotSkyReplace"); */
-/*       return(psphotReadoutCleanup(config, view, "PSPHOT.INPUT")); */
+/*       return(psphotReadoutCleanup(config, view, filerule)); */
     }
     // drop the references to the image pixels held by each source
-    if (!psphotSourceFreePixels (config, view, "PSPHOT.INPUT")) { // pass 1
+    if (!psphotSourceFreePixels (config, view, filerule)) { // pass 1
       psErrorStackPrint(stderr, "Unable to free source pixels");
       psErrorClear();
 
 /*       psLogMsg ("psphot", 3, "failed on psphotSourceFreePixels"); */
-/*       return(psphotReadoutCleanup(config, view, "PSPHOT.INPUT")); */
+/*       return(psphotReadoutCleanup(config, view, filerule)); */
     }
     // create the exported-metadata and free local data
-    return psphotReadoutCleanup(config, view, "PSPHOT.INPUT");
+    return psphotReadoutCleanup(config, view, filerule);
 }
