Index: /branches/eam_branches/psphot.20100506/src/psphot.h
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphot.h	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphot.h	(revision 27909)
@@ -37,6 +37,6 @@
 bool            psphotReadoutMinimal(pmConfig *config, const pmFPAview *view);
 
-bool            psphotReadoutCleanup (pmConfig *config, const pmFPAview *view);
-bool            psphotReadoutCleanupReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe);
+bool            psphotReadoutCleanup (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotReadoutCleanupReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
 
 bool            psphotDefineFiles (pmConfig *config, pmFPAfile *input);
@@ -51,86 +51,86 @@
 
 // psphotReadout functions
-bool            psphotAddPhotcode (pmConfig *config, const pmFPAview *view);
+bool            psphotAddPhotcode (pmConfig *config, const pmFPAview *view, const char *filerule);
 bool            psphotAddPhotcodeReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index);
 
-bool            psphotSetMaskAndVariance (pmConfig *config, const pmFPAview *view);
-bool            psphotSetMaskAndVarianceReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe);
-
-bool            psphotModelBackground (pmConfig *config, const pmFPAview *view);
-bool            psphotModelBackgroundReadoutFileIndex (pmConfig *config, const pmFPAview *view, const char *filename, int index);
-
-bool            psphotSubtractBackground (pmConfig *config, const pmFPAview *view);
-bool            psphotSubtractBackgroundReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe);
-
-bool            psphotFindDetections (pmConfig *config, const pmFPAview *view, bool firstPass);
-bool            psphotFindDetectionsReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool firstPass);
-
-bool            psphotSourceStats (pmConfig *config, const pmFPAview *view, bool setWindow);
-bool            psphotSourceStatsReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool setWindow);
-
-bool            psphotDeblendSatstars (pmConfig *config, const pmFPAview *view);
-bool            psphotDeblendSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index);
-
-bool            psphotBasicDeblend (pmConfig *config, const pmFPAview *view);
-bool            psphotBasicDeblendReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index);
-
-bool            psphotRoughClass (pmConfig *config, const pmFPAview *view);
-bool            psphotRoughClassReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe);
+bool            psphotSetMaskAndVariance (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotSetMaskAndVarianceReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
+
+bool            psphotModelBackground (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotModelBackgroundReadoutFileIndex (pmConfig *config, const pmFPAview *view, const char *filerule, int index);
+
+bool            psphotSubtractBackground (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotSubtractBackgroundReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
+
+bool            psphotFindDetections (pmConfig *config, const pmFPAview *view, const char *filerule, bool firstPass);
+bool            psphotFindDetectionsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool firstPass);
+
+bool            psphotSourceStats (pmConfig *config, const pmFPAview *view, const char *filerule, bool setWindow);
+bool            psphotSourceStatsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool setWindow);
+
+bool            psphotDeblendSatstars (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotDeblendSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index);
+
+bool            psphotBasicDeblend (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotBasicDeblendReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index);
+
+bool            psphotRoughClass (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotRoughClassReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
 bool            psphotRoughClassRegion (int nRegion, psRegion *region, psArray *sources, psMetadata *analysis, psMetadata *recipe, const bool havePSF);
 
-bool            psphotImageQuality (pmConfig *config, const pmFPAview *view);
-bool            psphotImageQualityReadout(pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe);
-
-bool            psphotChoosePSF (pmConfig *config, const pmFPAview *view);
-bool            psphotChoosePSFReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe);
-
-bool            psphotGuessModels (pmConfig *config, const pmFPAview *view);
-bool            psphotGuessModelsReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index);
-
-bool            psphotMergeSources (pmConfig *config, const pmFPAview *view);
-bool            psphotMergeSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index);
-
-bool            psphotFitSourcesLinear (pmConfig *config, const pmFPAview *view, bool final);
+bool            psphotImageQuality (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotImageQualityReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
+
+bool            psphotChoosePSF (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotChoosePSFReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
+
+bool            psphotGuessModels (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotGuessModelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index);
+
+bool            psphotMergeSources (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotMergeSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index);
+
+bool            psphotFitSourcesLinear (pmConfig *config, const pmFPAview *view, const char *filerule, bool final);
 bool            psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final);
 
-bool            psphotSourceSize (pmConfig *config, const pmFPAview *view, bool getPSFsize);
-bool            psphotSourceSizeReadout(pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool getPSFsize);
-
-bool            psphotBlendFit (pmConfig *config, const pmFPAview *view);
-bool            psphotBlendFitReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe);
+bool            psphotSourceSize (pmConfig *config, const pmFPAview *view, const char *filerule, bool getPSFsize);
+bool            psphotSourceSizeReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool getPSFsize);
+
+bool            psphotBlendFit (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotBlendFitReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
 bool            psphotBlendFit_Threaded (psThreadJob *job);
 
-bool            psphotReplaceAllSources (pmConfig *config, const pmFPAview *view);
-bool            psphotReplaceAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe);
-
-bool            psphotAddNoise (pmConfig *config, const pmFPAview *view);
-bool            psphotSubNoise (pmConfig *config, const pmFPAview *view);
-bool            psphotAddOrSubNoise (pmConfig *config, const pmFPAview *view, bool add);
-bool            psphotAddOrSubNoiseReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool add);
-
-bool            psphotExtendedSourceAnalysis (pmConfig *config, const pmFPAview *view);
-bool            psphotExtendedSourceAnalysisReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe);
-
-bool            psphotExtendedSourceFits (pmConfig *config, const pmFPAview *view);
-bool            psphotExtendedSourceFitsReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe);
-
-bool            psphotApResid (pmConfig *config, const pmFPAview *view);
-bool            psphotApResidReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe);
-
-bool            psphotMagnitudes (pmConfig *config, const pmFPAview *view);
+bool            psphotReplaceAllSources (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotReplaceAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
+
+bool            psphotAddNoise (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotSubNoise (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotAddOrSubNoise (pmConfig *config, const pmFPAview *view, const char *filerule, bool add);
+bool            psphotAddOrSubNoiseReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool add);
+
+bool            psphotExtendedSourceAnalysis (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotExtendedSourceAnalysisReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
+
+bool            psphotExtendedSourceFits (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotExtendedSourceFitsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
+
+bool            psphotApResid (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotApResidReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
+
+bool            psphotMagnitudes (pmConfig *config, const pmFPAview *view, const char *filerule);
 bool            psphotMagnitudesReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, pmReadout *readout, psArray *sources, pmPSF *psf);
 bool            psphotMagnitudes_Threaded (psThreadJob *job);
 
-bool            psphotEfficiency (pmConfig *config, const pmFPAview *view);
-bool            psphotEfficiencyReadout(pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe);
+bool            psphotEfficiency (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotEfficiencyReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
 
 bool            psphotPSFWeights(pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources);
 bool            psphotPSFWeights_Threaded (psThreadJob *job);
 
-bool            psphotSkyReplace (pmConfig *config, const pmFPAview *view);
-bool            psphotSkyReplaceReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index);
-
-bool            psphotSourceFreePixels (pmConfig *config, const pmFPAview *view);
-bool            psphotSourceFreePixelsReadout(pmConfig *config, const pmFPAview *view, const char *filename, int index);
+bool            psphotSkyReplace (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotSkyReplaceReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index);
+
+bool            psphotSourceFreePixels (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotSourceFreePixelsReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index);
 
 // in psphotSourceStats.c:
@@ -147,11 +147,11 @@
 
 // in psphotMergeSources.c:
-bool            psphotLoadExtSources (pmConfig *config, const pmFPAview *view);
+bool            psphotLoadExtSources (pmConfig *config, const pmFPAview *view, const char *filerule);
 psArray        *psphotLoadPSFSources (pmConfig *config, const pmFPAview *view);
-bool            psphotRepairLoadedSources (pmConfig *config, const pmFPAview *view);
-bool            psphotCheckExtSources (pmConfig *config, const pmFPAview *view);
+bool            psphotRepairLoadedSources (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotCheckExtSources (pmConfig *config, const pmFPAview *view, const char *filerule);
 
 // generate the detection structure for the supplied array of sources
-bool            psphotDetectionsFromSources (pmConfig *config, const pmFPAview *view, psArray *sources);
+bool            psphotDetectionsFromSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *sources);
 
 // generate the detection structure for the supplied array of sources
@@ -349,16 +349,16 @@
 bool psphotStackImageLoop (pmConfig *config);
 bool psphotStackReadout (pmConfig *config, const pmFPAview *view);
-bool psphotStackChisqImage (pmConfig *config, const pmFPAview *view);
+bool psphotStackChisqImage (pmConfig *config, const pmFPAview *view, const char *filerule);
 bool psphotStackChisqImageAddReadout(const pmConfig *config, // Configuration
 				     const pmFPAview *view,
+				     const char *filename, 
 				     pmReadout **chiReadout,
-				     char *filename, 
 				     int index);
 
-bool psphotStackRemoveChisqFromInputs (pmConfig *config);
+bool psphotStackRemoveChisqFromInputs (pmConfig *config, const char *filerule);
 bool pmFPAfileRemoveSingle(psMetadata *files, const char *name, int num);
 
-psArray *psphotMatchSources (pmConfig *config, const pmFPAview *view);
-bool psphotMatchSourcesReadout (psArray *objects, pmConfig *config, const pmFPAview *view, char *filename, int index);
+psArray *psphotMatchSources (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool psphotMatchSourcesReadout (psArray *objects, pmConfig *config, const pmFPAview *view, const char *filerule, int index);
 bool psphotMatchSourcesToObjects (psArray *objects, psArray *sources, float RADIUS);
 
Index: /branches/eam_branches/psphot.20100506/src/psphotAddNoise.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotAddNoise.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotAddNoise.c	(revision 27909)
@@ -1,14 +1,14 @@
 # include "psphotInternal.h"
 
-bool psphotAddNoise (pmConfig *config, const pmFPAview *view) {
-    return psphotAddOrSubNoise (config, view, true);
+bool psphotAddNoise (pmConfig *config, const pmFPAview *view, const char *filerule) {
+    return psphotAddOrSubNoise (config, view, filerule, true);
 }
 
-bool psphotSubNoise (pmConfig *config, const pmFPAview *view) {
-    return psphotAddOrSubNoise (config, view, false);
+bool psphotSubNoise (pmConfig *config, const pmFPAview *view, const char *filerule) {
+    return psphotAddOrSubNoise (config, view, filerule, false);
 }
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotAddOrSubNoise (pmConfig *config, const pmFPAview *view, bool add)
+bool psphotAddOrSubNoise (pmConfig *config, const pmFPAview *view, const char *filerule, bool add)
 {
     bool status = true;
@@ -23,6 +23,6 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotAddOrSubNoiseReadout (config, view, "PSPHOT.INPUT", i, recipe, add)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed on to modify noise for PSPHOT.INPUT entry %d", i);
+	if (!psphotAddOrSubNoiseReadout (config, view, filerule, i, recipe, add)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed on to modify noise for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -31,5 +31,5 @@
 }
 
-bool psphotAddOrSubNoiseReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool add) {
+bool psphotAddOrSubNoiseReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool add) {
 
     bool status = false;
@@ -39,5 +39,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotApResid.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotApResid.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotApResid.c	(revision 27909)
@@ -5,5 +5,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotApResid (pmConfig *config, const pmFPAview *view)
+bool psphotApResid (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -23,6 +23,6 @@
     for (int i = 0; i < num; i++) {
 	if (i == chisqNum) continue; // skip chisq image
-	if (!psphotApResidReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to measure aperture residual for PSPHOT.INPUT entry %d", i);
+	if (!psphotApResidReadout (config, view, filerule, i, recipe)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to measure aperture residual for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -31,5 +31,5 @@
 }
 
-bool psphotApResidReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe)
+bool psphotApResidReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe)
 {
     int Nfail = 0;
@@ -43,5 +43,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotBasicDeblend.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotBasicDeblend.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotBasicDeblend.c	(revision 27909)
@@ -2,5 +2,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotBasicDeblend (pmConfig *config, const pmFPAview *view)
+bool psphotBasicDeblend (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -11,6 +11,6 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotBasicDeblendReadout (config, view, "PSPHOT.INPUT", i)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed on basic deblend analysis for PSPHOT.INPUT entry %d", i);
+	if (!psphotBasicDeblendReadout (config, view, filerule, i)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed on basic deblend analysis for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -19,5 +19,5 @@
 }
 
-bool psphotBasicDeblendReadout (pmConfig *config, const pmFPAview *view, const char *filename, int fileIndex) {
+bool psphotBasicDeblendReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int fileIndex) {
 
     int N;
@@ -31,5 +31,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, fileIndex); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, fileIndex); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotBlendFit.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotBlendFit.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotBlendFit.c	(revision 27909)
@@ -2,5 +2,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotBlendFit (pmConfig *config, const pmFPAview *view)
+bool psphotBlendFit (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -15,6 +15,6 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotBlendFitReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (non-linear) for PSPHOT.INPUT entry %d", i);
+	if (!psphotBlendFitReadout (config, view, filerule, i, recipe)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (non-linear) for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -24,5 +24,5 @@
 
 // XXX I don't like this name
-bool psphotBlendFitReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe) {
+bool psphotBlendFitReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) {
 
     int Nfit = 0;
@@ -35,5 +35,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotChoosePSF.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotChoosePSF.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotChoosePSF.c	(revision 27909)
@@ -2,5 +2,5 @@
 
 // generate a PSF model for inputs without PSF models already loaded
-bool psphotChoosePSF (pmConfig *config, const pmFPAview *view)
+bool psphotChoosePSF (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -20,6 +20,6 @@
     for (int i = 0; i < num; i++) {
 	if (i == chisqNum) continue; // skip chisq image
-        if (!psphotChoosePSFReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to choose a psf model for PSPHOT.INPUT entry %d", i);
+        if (!psphotChoosePSFReadout (config, view, filerule, i, recipe)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to choose a psf model for %s entry %d", filerule, i);
             return false;
         }
@@ -29,5 +29,5 @@
 
 // try PSF models and select best option
-bool psphotChoosePSFReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe) {
+bool psphotChoosePSFReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) {
 
     bool status;
@@ -36,5 +36,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotDeblendSatstars.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotDeblendSatstars.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotDeblendSatstars.c	(revision 27909)
@@ -2,5 +2,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotDeblendSatstars (pmConfig *config, const pmFPAview *view)
+bool psphotDeblendSatstars (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -11,6 +11,6 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotDeblendSatstarsReadout (config, view, "PSPHOT.INPUT", i)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed on saturated star deblend analysis for PSPHOT.INPUT entry %d", i);
+	if (!psphotDeblendSatstarsReadout (config, view, filerule, i)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed on saturated star deblend analysis for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -19,5 +19,5 @@
 }
 
-bool psphotDeblendSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filename, int fileIndex) {
+bool psphotDeblendSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int fileIndex) {
 
     int N;
@@ -31,5 +31,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, fileIndex); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, fileIndex); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotEfficiency.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotEfficiency.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotEfficiency.c	(revision 27909)
@@ -149,5 +149,5 @@
 }
 
-bool psphotEfficiency (pmConfig *config, const pmFPAview *view)
+bool psphotEfficiency (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -167,6 +167,6 @@
     for (int i = 0; i < num; i++) {
 	if (i == chisqNum) continue; // skip chisq image
-	if (!psphotEfficiencyReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to measure detection efficiency for PSPHOT.INPUT entry %d", i);
+	if (!psphotEfficiencyReadout (config, view, filerule, i, recipe)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to measure detection efficiency for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -176,5 +176,5 @@
 
 // Determine detection efficiency
-bool psphotEfficiencyReadout(pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe)
+bool psphotEfficiencyReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe)
 {
     bool status = true;
@@ -183,5 +183,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotExtendedSourceAnalysis.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotExtendedSourceAnalysis.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotExtendedSourceAnalysis.c	(revision 27909)
@@ -2,5 +2,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotExtendedSourceAnalysis (pmConfig *config, const pmFPAview *view)
+bool psphotExtendedSourceAnalysis (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -21,6 +21,6 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotExtendedSourceAnalysisReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed on measure extended source aperture-like parameters for PSPHOT.INPUT entry %d", i);
+	if (!psphotExtendedSourceAnalysisReadout (config, view, filerule, i, recipe)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed on measure extended source aperture-like parameters for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -30,5 +30,5 @@
 
 // aperture-like measurements for extended sources
-bool psphotExtendedSourceAnalysisReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe) {
+bool psphotExtendedSourceAnalysisReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) {
 
     bool status;
@@ -42,5 +42,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotExtendedSourceFits.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotExtendedSourceFits.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotExtendedSourceFits.c	(revision 27909)
@@ -2,5 +2,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotExtendedSourceFits (pmConfig *config, const pmFPAview *view)
+bool psphotExtendedSourceFits (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -21,6 +21,6 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotExtendedSourceFitsReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed on to fit extended sources for PSPHOT.INPUT entry %d", i);
+	if (!psphotExtendedSourceFitsReadout (config, view, filerule, i, recipe)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed on to fit extended sources for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -30,5 +30,5 @@
 
 // non-linear model fitting for extended sources
-bool psphotExtendedSourceFitsReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe) {
+bool psphotExtendedSourceFitsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) {
 
     bool status;
@@ -41,5 +41,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotFindDetections.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotFindDetections.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotFindDetections.c	(revision 27909)
@@ -4,5 +4,5 @@
 // peaks and new footprints.  any old peaks are saved on oldPeaks.  the resulting footprint set
 // contains all footprints (old and new)
-bool psphotFindDetections (pmConfig *config, const pmFPAview *view, bool firstPass)
+bool psphotFindDetections (pmConfig *config, const pmFPAview *view, const char *filerule, bool firstPass)
 {
     bool status = true;
@@ -17,6 +17,6 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotFindDetectionsReadout (config, view, "PSPHOT.INPUT", i, recipe, firstPass)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to find initial detections for PSPHOT.INPUT entry %d", i);
+	if (!psphotFindDetectionsReadout (config, view, filerule, i, recipe, firstPass)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to find initial detections for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -26,5 +26,5 @@
 
 // smooth the image, search for peaks, optionally define footprints based on the peaks
-bool psphotFindDetectionsReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool firstPass) {
+bool psphotFindDetectionsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool firstPass) {
 
     bool status;
@@ -34,5 +34,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotFitSourcesLinear.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotFitSourcesLinear.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotFitSourcesLinear.c	(revision 27909)
@@ -13,5 +13,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotFitSourcesLinear (pmConfig *config, const pmFPAview *view, bool final)
+bool psphotFitSourcesLinear (pmConfig *config, const pmFPAview *view, const char *filerule, bool final)
 {
     bool status = true;
@@ -28,5 +28,5 @@
 
 	// find the currently selected readout
-	pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", i); // File of interest
+	pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
 	psAssert (file, "missing file?");
 
@@ -44,5 +44,5 @@
 
 	if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (linear) for PSPHOT.INPUT entry %d", i);
+            psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (linear) for %s entry %d", filerule, i);
 	    return false;
 	}
Index: /branches/eam_branches/psphot.20100506/src/psphotForcedReadout.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotForcedReadout.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotForcedReadout.c	(revision 27909)
@@ -20,5 +20,5 @@
 
     // set the photcode for this image
-    if (!psphotAddPhotcode (config, view)) {
+    if (!psphotAddPhotcode (config, view, "PSPHOT.INPUT")) {
         psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
         return false;
@@ -30,18 +30,18 @@
 
     // Generate the mask and weight images, including the user-defined analysis region of interest
-    psphotSetMaskAndVariance (config, view);
+    psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT");
     if (!strcasecmp (breakPt, "NOTHING")) {
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // generate a background model (median, smoothed image)
-    if (!psphotModelBackground (config, view)) {
-        return psphotReadoutCleanup (config, view);
+    if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) {
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
-    if (!psphotSubtractBackground (config, view)) {
-        return psphotReadoutCleanup (config, view);
+    if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
     if (!strcasecmp (breakPt, "BACKMDL")) {
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
@@ -49,19 +49,19 @@
     	// this only happens if we had a programming error in psphotLoadPSF
         psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // include externally-supplied sources
-    psphotLoadExtSources (config, view);
+    psphotLoadExtSources (config, view, "PSPHOT.INPUT");
 
     // construct an initial model for each object, set the radius to fitRadius, set circular fit mask
-    psphotGuessModels (config, view);
+    psphotGuessModels (config, view, "PSPHOT.INPUT");
 
     // merge the newly selected sources into the existing list
     // NOTE: merge OLD and NEW
-    psphotMergeSources (config, view);
+    psphotMergeSources (config, view, "PSPHOT.INPUT");
 
     // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
-    psphotFitSourcesLinear (config, view, false);
+    psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", false);
 
     // identify CRs and extended sources
@@ -71,5 +71,5 @@
 
     // calculate source magnitudes
-    psphotMagnitudes(config, view);
+    psphotMagnitudes(config, view, "PSPHOT.INPUT");
 
     // XXX do I want to do this?
@@ -80,10 +80,10 @@
 
     // replace background in residual image
-    psphotSkyReplace (config, view);
+    psphotSkyReplace (config, view, "PSPHOT.INPUT");
 
     // drop the references to the image pixels held by each source
-    psphotSourceFreePixels (config, view);
+    psphotSourceFreePixels (config, view, "PSPHOT.INPUT");
 
     // create the exported-metadata and free local data
-    return psphotReadoutCleanup(config, view);
+    return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
 }
Index: /branches/eam_branches/psphot.20100506/src/psphotGuessModels.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotGuessModels.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotGuessModels.c	(revision 27909)
@@ -8,5 +8,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotGuessModels (pmConfig *config, const pmFPAview *view)
+bool psphotGuessModels (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -22,6 +22,6 @@
     for (int i = 0; i < num; i++) {
 	if (i == chisqNum) continue; // skip chisq image
-        if (!psphotGuessModelsReadout (config, view, "PSPHOT.INPUT", i)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed on to guess models for PSPHOT.INPUT entry %d", i);
+        if (!psphotGuessModelsReadout (config, view, filerule, i)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed on to guess models for %s entry %d", filerule, i);
             return false;
         }
@@ -31,5 +31,5 @@
 
 // construct an initial PSF model for each object (new sources only)
-bool psphotGuessModelsReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index) {
+bool psphotGuessModelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index) {
 
     bool status;
@@ -38,5 +38,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotImageQuality.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotImageQuality.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotImageQuality.c	(revision 27909)
@@ -5,5 +5,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotImageQuality (pmConfig *config, const pmFPAview *view)
+bool psphotImageQuality (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -23,6 +23,6 @@
     for (int i = 0; i < num; i++) {
 	if (i == chisqNum) continue; // skip chisq image
-	if (!psphotImageQualityReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed on to measure image quality for PSPHOT.INPUT entry %d", i);
+	if (!psphotImageQualityReadout (config, view, filerule, i, recipe)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed on to measure image quality for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -32,10 +32,10 @@
 
 // selecting the 'good' stars (likely to be psf stars), measure the M_cn, M_sn terms for n = 2,3,4
-bool psphotImageQualityReadout(pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe)
+bool psphotImageQualityReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe)
 {
     bool status = true;
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotMagnitudes.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotMagnitudes.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotMagnitudes.c	(revision 27909)
@@ -1,5 +1,5 @@
 # include "psphotInternal.h"
 
-bool psphotMagnitudes (pmConfig *config, const pmFPAview *view)
+bool psphotMagnitudes (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -21,5 +21,5 @@
 
 	// find the currently selected readout
-	pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", i); // File of interest
+	pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
 	psAssert (file, "missing file?");
 
@@ -37,5 +37,5 @@
 
 	if (!psphotMagnitudesReadout (config, recipe, view, readout, sources, psf)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to measure magnitudes for PSPHOT.INPUT entry %d", i);
+            psError (PSPHOT_ERR_CONFIG, false, "failed to measure magnitudes for %s entry %d", filerule, i);
 	    return false;
 	}
Index: /branches/eam_branches/psphot.20100506/src/psphotMakePSFReadout.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotMakePSFReadout.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotMakePSFReadout.c	(revision 27909)
@@ -19,5 +19,5 @@
 
     // set the photcode for this image
-    if (!psphotAddPhotcode (config, view)) {
+    if (!psphotAddPhotcode (config, view, "PSPHOT.INPUT")) {
         psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
         return false;
@@ -29,21 +29,21 @@
 
     // Generate the mask and weight images, including the user-defined analysis region of interest
-    psphotSetMaskAndVariance (config, view);
+    psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT");
     if (!strcasecmp (breakPt, "NOTHING")) {
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // generate a background model (median, smoothed image)
-    if (!psphotModelBackground (config, view)) {
-        return psphotReadoutCleanup (config, view);
+    if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) {
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
-    if (!psphotSubtractBackground (config, view)) {
-        return psphotReadoutCleanup (config, view);
+    if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
     if (!strcasecmp (breakPt, "BACKMDL")) {
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
-    psphotLoadExtSources (config, view);
+    psphotLoadExtSources (config, view, "PSPHOT.INPUT");
 
     // If sources have been supplied, then these should be used to measure the PSF include
@@ -53,24 +53,24 @@
     // a text file have no valid SN values, but psphotChoosePSF needs to select the top
     // PSF_MAX_NSTARS to generate the PSF.
-    if (!psphotCheckExtSources (config, view)) {
+    if (!psphotCheckExtSources (config, view, "PSPHOT.INPUT")) {
 	psLogMsg ("psphot", 3, "failure to select possible PSF sources (external or internal)");
-	return psphotReadoutCleanup (config, view);
+	return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // Use bright stellar objects to measure PSF. If we do not have enough stars to generate
     // the PSF, build one from the SEEING guess and model class
-    if (!psphotChoosePSF (config, view)) {
+    if (!psphotChoosePSF (config, view, "PSPHOT.INPUT")) {
 	psLogMsg ("psphot", 3, "failure to construct a psf model");
-	return psphotReadoutCleanup (config, view);
+	return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // measure aperture photometry corrections
 # if 0
-    if (!psphotApResid (config, view)) {
+    if (!psphotApResid (config, view, "PSPHOT.INPUT")) {
         psLogMsg ("psphot", 3, "failed on psphotApResid");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 # endif
 
-    return psphotReadoutCleanup (config, view);
+    return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
 }
Index: /branches/eam_branches/psphot.20100506/src/psphotMaskReadout.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotMaskReadout.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotMaskReadout.c	(revision 27909)
@@ -1,5 +1,5 @@
 # include "psphotInternal.h"
 
-bool psphotSetMaskAndVariance (pmConfig *config, const pmFPAview *view) {
+bool psphotSetMaskAndVariance (pmConfig *config, const pmFPAview *view, const char *filerule) {
 
     bool status = false;
@@ -16,5 +16,5 @@
 
 	// Generate the mask and weight images, including the user-defined analysis region of interest
-	if (!psphotSetMaskAndVarianceReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
+	if (!psphotSetMaskAndVarianceReadout (config, view, filerule, i, recipe)) {
             psError (PSPHOT_ERR_CONFIG, false, "failed to generate mask for PSPHOT.INPUT entry %d", i);
 	    return false;
@@ -25,9 +25,9 @@
 
 // generate mask and variance if not defined, additional mask for restricted subregion
-bool psphotSetMaskAndVarianceReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe) {
+bool psphotSetMaskAndVarianceReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) {
 
     bool status;
 
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotMergeSources.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotMergeSources.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotMergeSources.c	(revision 27909)
@@ -6,5 +6,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotMergeSources (pmConfig *config, const pmFPAview *view)
+bool psphotMergeSources (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -15,6 +15,6 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-        if (!psphotMergeSourcesReadout (config, view, "PSPHOT.INPUT", i)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to merge sources for PSPHOT.INPUT entry %d", i);
+        if (!psphotMergeSourcesReadout (config, view, filerule, i)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to merge sources for %s entry %d", filerule, i);
             return false;
         }
@@ -24,10 +24,10 @@
 
 // add newly selected sources to the existing list of sources
-bool psphotMergeSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index) {
+bool psphotMergeSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index) {
 
     bool status;
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
@@ -71,5 +71,5 @@
 // only expect a single entry for PSPHOT.INPUT.CMF and PSPHOT.SOURCES.TEXT, so we can only
 // associate input sources with a single entry for PSPHOT.INPUT
-bool psphotLoadExtSources (pmConfig *config, const pmFPAview *view) {
+bool psphotLoadExtSources (pmConfig *config, const pmFPAview *view, const char *filerule) {
 
     bool status;
@@ -79,5 +79,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
@@ -130,5 +130,5 @@
     // load data from input TXT file:
     {
-        pmChip *chipTXT = pmFPAfileThisChip (config->files, view, "PSPHOT.INPUT");
+        pmChip *chipTXT = pmFPAfileThisChip (config->files, view, filerule);
         if (!chipTXT) goto finish;
 
@@ -167,5 +167,5 @@
 
 // extract the input sources corresponding to this readout
-// XXX this function needs to be updated to work with the new context of pshot inputs
+// XXX this function needs to be updated to work with the new context of psphot inputs
 psArray *psphotLoadPSFSources (pmConfig *config, const pmFPAview *view) {
 
@@ -197,8 +197,8 @@
 // psphotDetectionsFromSources to psphotSourceStats and are now stored on
 // detections->newSources.
-bool psphotRepairLoadedSources (pmConfig *config, const pmFPAview *view) {
-
-    // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", 0); // File of interest
+bool psphotRepairLoadedSources (pmConfig *config, const pmFPAview *view, const char *filerule) {
+
+    // find the currently selected readout
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, 0); // File of interest
     psAssert (file, "missing file?");
 
@@ -227,8 +227,8 @@
 // generate the detection structure for the supplied array of sources
 // XXX this currently assumes there is a single input file
-bool psphotDetectionsFromSources (pmConfig *config, const pmFPAview *view, psArray *sources) {
-
-    // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", 0); // File of interest
+bool psphotDetectionsFromSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *sources) {
+
+    // find the currently selected readout
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, 0); // File of interest
     psAssert (file, "missing file?");
 
@@ -335,5 +335,5 @@
 }
 
-bool psphotCheckExtSources (pmConfig *config, const pmFPAview *view) {
+bool psphotCheckExtSources (pmConfig *config, const pmFPAview *view, const char *filerule) {
 
     bool status;
@@ -343,5 +343,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", 0); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, 0); // File of interest
     psAssert (file, "missing file?");
 
@@ -373,28 +373,28 @@
 
         // find the detections (by peak and/or footprint) in the image.
-        if (!psphotFindDetections (config, view, true)) {
+        if (!psphotFindDetections (config, view, filerule, true)) {
             psError(PSPHOT_ERR_CONFIG, false, "unable to find detections in this image");
-            return psphotReadoutCleanup (config, view);
+            return psphotReadoutCleanup (config, view, filerule);
         }
 
         // construct sources and measure basic stats
-        psphotSourceStats (config, view, true);
+        psphotSourceStats (config, view, filerule, true);
 
         // find blended neighbors of very saturated stars
-        psphotDeblendSatstars (config, view);
+        psphotDeblendSatstars (config, view, filerule);
 
         // mark blended peaks PS_SOURCE_BLEND
-        if (!psphotBasicDeblend (config, view)) {
+        if (!psphotBasicDeblend (config, view, filerule)) {
             psLogMsg ("psphot", 3, "failed on deblend analysis");
-            return psphotReadoutCleanup (config, view);
+            return psphotReadoutCleanup (config, view, filerule);
         }
 
         // classify sources based on moments, brightness
-        if (!psphotRoughClass (config, view)) {
+        if (!psphotRoughClass (config, view, filerule)) {
             psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
-            return psphotReadoutCleanup (config, view);
-        }
-    }
-
-    return true;
-}
+            return psphotReadoutCleanup (config, view, filerule);
+        }
+    }
+
+    return true;
+}
Index: /branches/eam_branches/psphot.20100506/src/psphotModelBackground.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotModelBackground.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotModelBackground.c	(revision 27909)
@@ -384,5 +384,5 @@
 
 // XXX supply filename or keep PSPHOT.INPUT fixed?
-bool psphotModelBackground (pmConfig *config, const pmFPAview *view)
+bool psphotModelBackground (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = false;
@@ -393,5 +393,5 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-        if (!psphotModelBackgroundReadoutFileIndex(config, view, "PSPHOT.INPUT", i)) {
+        if (!psphotModelBackgroundReadoutFileIndex(config, view, filerule, i)) {
             psError (PSPHOT_ERR_CONFIG, false, "failed to model background for PSPHOT.INPUT entry %d", i);
             return false;
Index: /branches/eam_branches/psphot.20100506/src/psphotModelTest.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotModelTest.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotModelTest.c	(revision 27909)
@@ -3,5 +3,5 @@
 
 // XXX add more test information?
-bool psphotModelTest (pmConfig *config, const pmFPAview *view, psMetadata *recipe) {
+bool psphotModelTest (pmConfig *config, const pmFPAview *view, const char *filerule, psMetadata *recipe) {
 
     bool status;
@@ -33,5 +33,5 @@
 
     // use poissonian errors or local-sky errors
-    bool POISSON_ERRORS = psMetadataLookupBool (&status, recipe, "POISSON_ERRORS");
+    bool POISSON_ERRORS = psMetadataLookupBool (&status, recipe, filerule);
     if (!status) POISSON_ERRORS = true;
     pmSourceFitModelInit (15, 0.1, 1.0, POISSON_ERRORS);
Index: /branches/eam_branches/psphot.20100506/src/psphotOutput.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotOutput.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotOutput.c	(revision 27909)
@@ -126,5 +126,5 @@
 }
 
-bool psphotAddPhotcode (pmConfig *config, const pmFPAview *view) {
+bool psphotAddPhotcode (pmConfig *config, const pmFPAview *view, const char *filerule) {
 
     bool status = false;
@@ -135,5 +135,5 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotAddPhotcodeReadout (config, view, "PSPHOT.INPUT", i)) {
+	if (!psphotAddPhotcodeReadout (config, view, filerule, i)) {
             psError (PSPHOT_ERR_CONFIG, false, "failed to add photcode to PSPHOT.INPUT entry %d", i);
 	    return false;
Index: /branches/eam_branches/psphot.20100506/src/psphotReadout.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotReadout.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotReadout.c	(revision 27909)
@@ -28,5 +28,5 @@
 
     // set the photcode for this image
-    if (!psphotAddPhotcode (config, view)) {
+    if (!psphotAddPhotcode (config, view, "PSPHOT.INPUT")) {
         psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
         return false;
@@ -34,99 +34,99 @@
 
     // Generate the mask and weight images, including the user-defined analysis region of interest
-    if (!psphotSetMaskAndVariance (config, view)) {
-        return psphotReadoutCleanup(config, view);
+    if (!psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT")) {
+        return psphotReadoutCleanup(config, view, "PSPHOT.INPUT");
     }
     if (!strcasecmp (breakPt, "NOTHING")) {
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // generate a background model (median, smoothed image)
-    if (!psphotModelBackground (config, view)) {
-        return psphotReadoutCleanup (config, view);
-    }
-    if (!psphotSubtractBackground (config, view)) {
-        return psphotReadoutCleanup (config, view);
+    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 (!strcasecmp (breakPt, "BACKMDL")) {
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are determined and saved on
     // readout->analysis XXX this function currently only works with a single PSPHOT.INPUT
-    if (!psphotLoadPSF (config, view)) {
+    if (!psphotLoadPSF (config, view)) { // ??? need to supply 2 ?
         psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // find the detections (by peak and/or footprint) in the image.
-    if (!psphotFindDetections (config, view, true)) { // pass 1
+    if (!psphotFindDetections (config, view, "PSPHOT.INPUT", 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);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // construct sources and measure basic stats (saved on detections->newSources)
-    if (!psphotSourceStats (config, view, true)) { // pass 1
+    if (!psphotSourceStats (config, view, "PSPHOT.INPUT", true)) { // pass 1
         psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
     if (!strcasecmp (breakPt, "PEAKS")) {
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // find blended neighbors of very saturated stars (detections->newSources)
-    if (!psphotDeblendSatstars (config, view)) {
+    if (!psphotDeblendSatstars (config, view, "PSPHOT.INPUT")) {
         psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // mark blended peaks PS_SOURCE_BLEND (detections->newSources)
-    if (!psphotBasicDeblend (config, view)) {
+    if (!psphotBasicDeblend (config, view, "PSPHOT.INPUT")) {
         psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // 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)) { // pass 1
+    if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) { // pass 1
         psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
     // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources)
-    if (!psphotImageQuality (config, view)) { // pass 1
+    if (!psphotImageQuality (config, view, "PSPHOT.INPUT")) { // pass 1
         psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality");
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
     if (!strcasecmp (breakPt, "MOMENTS")) {
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // 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)) { // pass 1
+    if (!psphotChoosePSF (config, view, "PSPHOT.INPUT")) { // pass 1
         psLogMsg ("psphot", 3, "failure to construct a psf model");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
     if (!strcasecmp (breakPt, "PSFMODEL")) {
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // include externally-supplied sources
     // XXX fix this in the new multi-input context
-    // psphotLoadExtSources (config, view); // pass 1
+    // psphotLoadExtSources (config, view, "PSPHOT.INPUT"); // pass 1
 
     // construct an initial model for each object, set the radius to fitRadius, set circular
     // fit mask (detections->newSources)
-    psphotGuessModels (config, view); // pass 1
+    psphotGuessModels (config, view, "PSPHOT.INPUT"); // pass 1
 
     // merge the newly selected sources into the existing list
     // NOTE: merge OLD and NEW
-    psphotMergeSources (config, view);
+    psphotMergeSources (config, view, "PSPHOT.INPUT");
 
     // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
-    psphotFitSourcesLinear (config, view, false); // pass 1 (detections->allSources)
+    psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", false); // pass 1 (detections->allSources)
 
     // identify CRs and extended sources (only unmeasured sources are measured)
-    psphotSourceSize (config, view, true); // pass 1 (detections->allSources)
+    psphotSourceSize (config, view, "PSPHOT.INPUT", true); // pass 1 (detections->allSources)
     if (!strcasecmp (breakPt, "ENSEMBLE")) {
         goto finish;
@@ -135,12 +135,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); // pass 1 (detections->allSources)
+    psphotBlendFit (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
 
     // replace all sources
-    psphotReplaceAllSources (config, view); // pass 1 (detections->allSources)
+    psphotReplaceAllSources (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
 
     // linear fit to include all sources (subtract again)
     // NOTE : apply to ALL sources (extended + psf)
-    psphotFitSourcesLinear (config, view, true); // pass 2 (detections->allSources)
+    psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", true); // pass 2 (detections->allSources)
 
     // if we only do one pass, skip to extended source analysis
@@ -150,40 +150,40 @@
 
     // add noise for subtracted objects
-    psphotAddNoise (config, view); // pass 1 (detections->allSources)
+    psphotAddNoise (config, view, "PSPHOT.INPUT"); // 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, false); // pass 2 (detections->peaks, detections->footprints)
+    psphotFindDetections (config, view, "PSPHOT.INPUT", 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); // pass 1 (detections->allSources)
+    psphotSubNoise (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
 
     // define new sources based on only the new peaks
     // NOTE: new sources are saved on detections->newSources
-    psphotSourceStats (config, view, false); // pass 2 (detections->newSources)
+    psphotSourceStats (config, view, "PSPHOT.INPUT", false); // pass 2 (detections->newSources)
 
     // set source type
     // NOTE: apply only to detections->newSources
-    if (!psphotRoughClass (config, view)) { // pass 2 (detections->newSources)
+    if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) { // pass 2 (detections->newSources)
         psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // create full input models, set the radius to fitRadius, set circular fit mask
     // NOTE: apply only to detections->newSources
-    psphotGuessModels (config, view); // pass 2 (detections->newSources)
+    psphotGuessModels (config, view, "PSPHOT.INPUT"); // 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); // pass 2
+    psphotReplaceAllSources (config, view, "PSPHOT.INPUT"); // 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); // (detections->newSources + detections->allSources -> detections->allSources)
+    psphotMergeSources (config, view, "PSPHOT.INPUT"); // (detections->newSources + detections->allSources -> detections->allSources)
 
     // NOTE: apply to ALL sources
-    psphotFitSourcesLinear (config, view, true); // pass 3 (detections->allSources)
+    psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", true); // pass 3 (detections->allSources)
 
 pass1finish:
@@ -191,8 +191,8 @@
     // measure source size for the remaining sources
     // NOTE: applies only to NEW (unmeasured) sources
-    psphotSourceSize (config, view, false); // pass 2 (detections->allSources)
-
-    psphotExtendedSourceAnalysis (config, view); // pass 1 (detections->allSources)
-    psphotExtendedSourceFits (config, view); // pass 1 (detections->allSources)
+    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)
 
 finish:
@@ -202,13 +202,13 @@
 
     // measure aperture photometry corrections
-    if (!psphotApResid (config, view)) { // pass 1 (detections->allSources)
+    if (!psphotApResid (config, view, "PSPHOT.INPUT")) { // pass 1 (detections->allSources)
         psLogMsg ("psphot", 3, "failed on psphotApResid");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // calculate source magnitudes
-    psphotMagnitudes(config, view); // pass 1 (detections->allSources)
-
-    if (!psphotEfficiency(config, view)) { // pass 1
+    psphotMagnitudes(config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
+
+    if (!psphotEfficiency(config, view, "PSPHOT.INPUT")) { // pass 1
         psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
         psErrorClear();
@@ -219,10 +219,10 @@
 
     // replace background in residual image
-    psphotSkyReplace (config, view); // pass 1
+    psphotSkyReplace (config, view, "PSPHOT.INPUT"); // pass 1
 
     // drop the references to the image pixels held by each source
-    psphotSourceFreePixels (config, view); // pass 1
+    psphotSourceFreePixels (config, view, "PSPHOT.INPUT"); // pass 1
 
     // create the exported-metadata and free local data
-    return psphotReadoutCleanup(config, view);
+    return psphotReadoutCleanup(config, view, "PSPHOT.INPUT");
 }
Index: /branches/eam_branches/psphot.20100506/src/psphotReadoutCleanup.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotReadoutCleanup.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotReadoutCleanup.c	(revision 27909)
@@ -2,5 +2,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotReadoutCleanup (pmConfig *config, const pmFPAview *view)
+bool psphotReadoutCleanup (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -24,6 +24,6 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotReadoutCleanupReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed on psphotReadoutCleanup for PSPHOT.INPUT entry %d", i);
+	if (!psphotReadoutCleanupReadout (config, view, filerule, i, recipe)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed on psphotReadoutCleanup for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -39,10 +39,10 @@
 // not a DATA error, then there was a serious problem.  Only in this case, or if the fail
 // on the stats measurement, do we return false
-bool psphotReadoutCleanupReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe) {
+bool psphotReadoutCleanupReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) {
 
     bool status = true;
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotReadoutFindPSF.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotReadoutFindPSF.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotReadoutFindPSF.c	(revision 27909)
@@ -8,5 +8,5 @@
 
     // set the photcode for the PSPHOT.INPUT
-    if (!psphotAddPhotcode(config, view)) {
+    if (!psphotAddPhotcode(config, view, "PSPHOT.INPUT")) {
         psError(PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
         return false;
@@ -14,5 +14,5 @@
 
     // Generate the mask and variance images, including the user-defined analysis region of interest
-    psphotSetMaskAndVariance (config, view);
+    psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT");
 
     // Note that in this implementation, we do NOT model the background and we do not
@@ -21,11 +21,11 @@
     // include externally-supplied sources (supplied as PSPHOT.INPUT.CMF)
     // XXX we assume a single set of input sources is supplied
-    if (!psphotDetectionsFromSources (config, view, inSources)) {
+    if (!psphotDetectionsFromSources (config, view, "PSPHOT.INPUT", inSources)) {
         psError(PSPHOT_ERR_ARGUMENTS, true, "Can't find PSF stars");
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // construct detections->newSources and measure basic stats (moments, local sky)
-    if (!psphotSourceStats(config, view, true)) {
+    if (!psphotSourceStats(config, view, "PSPHOT.INPUT", true)) {
         psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
 	return false;
@@ -33,5 +33,5 @@
 
     // peak flux is wrong : use the peak measured in the moments analysis:
-    if (!psphotRepairLoadedSources(config, view)) {
+    if (!psphotRepairLoadedSources(config, view, "PSPHOT.INPUT")) {
         psError(PSPHOT_ERR_UNKNOWN, false, "failure to repair sources");
 	return false;
@@ -39,17 +39,17 @@
 
     // classify sources based on moments, brightness (psf is not known)
-    if (!psphotRoughClass (config, view)) {
+    if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) {
         psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough source class");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
-    if (!psphotImageQuality (config, view)) {
+    if (!psphotImageQuality (config, view, "PSPHOT.INPUT")) {
         psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality");
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
-    if (!psphotChoosePSF(config, view)) {
+    if (!psphotChoosePSF(config, view, "PSPHOT.INPUT")) {
         psError(PSPHOT_ERR_PSF, false, "Failed to construct a psf model");
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
@@ -59,23 +59,23 @@
     // fits from that analysis, or run the linear PSF fit for all objects currently in hand
     // construct an initial model for each object, set the radius to fitRadius, set circular fit mask
-    psphotGuessModels (config, view);
+    psphotGuessModels (config, view, "PSPHOT.INPUT");
 # endif
 
     // merge the newly selected sources into the existing list
     // NOTE: merge OLD and NEW
-    psphotMergeSources (config, view); 
+    psphotMergeSources (config, view, "PSPHOT.INPUT"); 
 
 # if 0
     // measure aperture photometry corrections
-    if (!psphotApResid (config, view)) {
+    if (!psphotApResid (config, view, "PSPHOT.INPUT")) {
         psLogMsg ("psphot", 3, "failed on psphotApResid");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 # endif
 
     // drop the references to the image pixels held by each source
-    psphotSourceFreePixels(config, view);
+    psphotSourceFreePixels(config, view, "PSPHOT.INPUT");
 
     // create the exported-metadata and free local data
-    return psphotReadoutCleanup(config, view);
+    return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
 }
Index: /branches/eam_branches/psphot.20100506/src/psphotReadoutKnownSources.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotReadoutKnownSources.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotReadoutKnownSources.c	(revision 27909)
@@ -8,5 +8,5 @@
 
     // set the photcode for this image
-    if (!psphotAddPhotcode(config, view)) {
+    if (!psphotAddPhotcode(config, view, "PSPHOT.INPUT")) {
         psError(PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
         return false;
@@ -14,5 +14,5 @@
 
     // Generate the mask and weight images, including the user-defined analysis region of interest
-    psphotSetMaskAndVariance (config, view);
+    psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT");
 
     // Note that in this implementation, we do NOT model the background and we do not
@@ -20,11 +20,11 @@
 
     // include externally-supplied sources (supplied as PSPHOT.INPUT.CMF)
-    if (!psphotDetectionsFromSources (config, view, inSources)) {
+    if (!psphotDetectionsFromSources (config, view, "PSPHOT.INPUT", inSources)) {
         psError(PSPHOT_ERR_ARGUMENTS, true, "Can't find PSF stars");
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // construct sources and measure basic stats
-    if (!psphotSourceStats (config, view, true)) {
+    if (!psphotSourceStats (config, view, "PSPHOT.INPUT", true)) {
         psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
 	return false;
@@ -32,5 +32,5 @@
 
     // peak flux is wrong : use the peak measured in the moments analysis:
-    if (!psphotRepairLoadedSources(config, view)) {
+    if (!psphotRepairLoadedSources(config, view, "PSPHOT.INPUT")) {
         psError(PSPHOT_ERR_UNKNOWN, false, "failure to repair sources");
 	return false;
@@ -38,37 +38,37 @@
 
     // classify sources based on moments, brightness (psf is not known)
-    if (!psphotRoughClass (config, view)) {
+    if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) {
         psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough source class");
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
-    if (!psphotChoosePSF (config, view)) {
+    if (!psphotChoosePSF (config, view, "PSPHOT.INPUT")) {
         psError(PSPHOT_ERR_PSF, false, "Failed to construct a psf model");
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // construct an initial model for each object
-    psphotGuessModels (config, view);
+    psphotGuessModels (config, view, "PSPHOT.INPUT");
 
     // merge the newly selected sources into the existing list
     // NOTE: merge OLD and NEW
-    psphotMergeSources (config, view); 
+    psphotMergeSources (config, view, "PSPHOT.INPUT"); 
 
     // linear PSF fit to source peaks
-    psphotFitSourcesLinear (config, view, false);
+    psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", false);
 
     // measure aperture photometry corrections
-    if (!psphotApResid (config, view)) {
+    if (!psphotApResid (config, view, "PSPHOT.INPUT")) {
         psLogMsg ("psphot", 3, "failed on psphotApResid");
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // calculate source magnitudes
-    psphotMagnitudes(config, view);
+    psphotMagnitudes(config, view, "PSPHOT.INPUT");
 
     // drop the references to the image pixels held by each source
-    psphotSourceFreePixels (config, view);
+    psphotSourceFreePixels (config, view, "PSPHOT.INPUT");
 
     // create the exported-metadata and free local data
-    return psphotReadoutCleanup(config, view);
+    return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
 }
Index: /branches/eam_branches/psphot.20100506/src/psphotReadoutMinimal.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotReadoutMinimal.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotReadoutMinimal.c	(revision 27909)
@@ -18,5 +18,5 @@
 
     // set the photcode for this image
-    if (!psphotAddPhotcode(config, view)) {
+    if (!psphotAddPhotcode(config, view, "PSPHOT.INPUT")) {
         psError(PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
         return false;
@@ -24,63 +24,63 @@
 
     // Generate the mask and weight images, including the user-defined analysis region of interest
-    psphotSetMaskAndVariance (config, view);
+    psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT");
 
     // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are saved on readout->analysis
     if (!psphotLoadPSF (config, view)) {
       psError (PSPHOT_ERR_CONFIG, false, "missing psf model");
-      return psphotReadoutCleanup (config, view);
+      return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // find the detections (by peak and/or footprint) in the image. (final pass)
-    if (!psphotFindDetections(config, view, false)) {
+    if (!psphotFindDetections(config, view, "PSPHOT.INPUT", false)) {
         psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // construct sources and measure basic stats (saved on detections->newSources)
-    if (!psphotSourceStats (config, view, false)) { // pass 1
+    if (!psphotSourceStats (config, view, "PSPHOT.INPUT", false)) { // pass 1
         psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // find blended neighbors of very saturated stars
-    psphotDeblendSatstars (config, view);
+    psphotDeblendSatstars (config, view, "PSPHOT.INPUT");
 
     // mark blended peaks PS_SOURCE_BLEND
-    if (!psphotBasicDeblend (config, view)) {
+    if (!psphotBasicDeblend (config, view, "PSPHOT.INPUT")) {
         psLogMsg ("psphot", 3, "failed on deblend analysis");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // classify sources based on moments, brightness (use supplied psf shape parameters)
-    if (!psphotRoughClass (config, view)) {
+    if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) {
         psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     }
 
     // construct an initial model for each object
-    psphotGuessModels (config, view);
+    psphotGuessModels (config, view, "PSPHOT.INPUT");
 
     // merge the newly selected sources into the existing list
-    psphotMergeSources (config, view);
+    psphotMergeSources (config, view, "PSPHOT.INPUT");
 
     // linear PSF fit to source peaks
-    psphotFitSourcesLinear (config, view, false);
+    psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", false);
 
 // XXX eventually, add the extended source fits here
 # if (0)
     // measure source size for the remaining sources
-    psphotSourceSize (config, view);
+    psphotSourceSize (config, view, "PSPHOT.INPUT");
 
-    psphotExtendedSourceAnalysis (config, view);
+    psphotExtendedSourceAnalysis (config, view, "PSPHOT.INPUT");
 
-    psphotExtendedSourceFits (config, view);
+    psphotExtendedSourceFits (config, view, "PSPHOT.INPUT");
 # endif
 
     // calculate source magnitudes
-    psphotMagnitudes(config, view);
+    psphotMagnitudes(config, view, "PSPHOT.INPUT");
 
     // XXX ensure this is measured if the analysis succeeds (even if quality is low)
-    if (!psphotEfficiency(config, view)) {
+    if (!psphotEfficiency(config, view, "PSPHOT.INPUT")) {
         psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
         psErrorClear();
@@ -88,7 +88,7 @@
 
     // drop the references to the image pixels held by each source
-    psphotSourceFreePixels (config, view);
+    psphotSourceFreePixels (config, view, "PSPHOT.INPUT");
 
     // create the exported-metadata and free local data
-    return psphotReadoutCleanup(config, view);
+    return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
 }
Index: /branches/eam_branches/psphot.20100506/src/psphotReplaceUnfit.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotReplaceUnfit.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotReplaceUnfit.c	(revision 27909)
@@ -23,5 +23,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotReplaceAllSources (pmConfig *config, const pmFPAview *view)
+bool psphotReplaceAllSources (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -36,5 +36,5 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotReplaceAllSourcesReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
+	if (!psphotReplaceAllSourcesReadout (config, view, filerule, i, recipe)) {
             psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for PSPHOT.INPUT entry %d", i);
 	    return false;
Index: /branches/eam_branches/psphot.20100506/src/psphotRoughClass.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotRoughClass.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotRoughClass.c	(revision 27909)
@@ -8,5 +8,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotRoughClass (pmConfig *config, const pmFPAview *view)
+bool psphotRoughClass (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -26,6 +26,6 @@
     for (int i = 0; i < num; i++) {
 	if (i == chisqNum) continue; // skip chisq image
-	if (!psphotRoughClassReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed on rough classification for PSPHOT.INPUT entry %d", i);
+	if (!psphotRoughClassReadout (config, view, filerule, i, recipe)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed on rough classification for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -34,5 +34,5 @@
 }
 
-bool psphotRoughClassReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe) {
+bool psphotRoughClassReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) {
 
     bool status;
@@ -41,5 +41,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotSkyReplace.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotSkyReplace.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotSkyReplace.c	(revision 27909)
@@ -1,5 +1,5 @@
 # include "psphotInternal.h"
 
-bool psphotSkyReplace (pmConfig *config, const pmFPAview *view)
+bool psphotSkyReplace (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -15,6 +15,6 @@
     for (int i = 0; i < num; i++) {
 	if (i == chisqNum) continue; // skip chisq image
-	if (!psphotSkyReplaceReadout (config, view, "PSPHOT.INPUT", i)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to replace sky for PSPHOT.INPUT entry %d", i);
+	if (!psphotSkyReplaceReadout (config, view, filerule, i)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to replace sky for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -25,10 +25,10 @@
 // XXX make this an option?
 // in order to  successfully replace the sky, we must define a corresponding file...
-bool psphotSkyReplaceReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index) {
+bool psphotSkyReplaceReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index) {
 
     psTimerStart ("psphot.skyreplace");
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotSourceFreePixels.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotSourceFreePixels.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotSourceFreePixels.c	(revision 27909)
@@ -1,5 +1,5 @@
 # include "psphotInternal.h"
 
-bool psphotSourceFreePixels (pmConfig *config, const pmFPAview *view)
+bool psphotSourceFreePixels (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = true;
@@ -10,6 +10,6 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotSourceFreePixelsReadout (config, view, "PSPHOT.INPUT", i)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to free source pixels for PSPHOT.INPUT entry %d", i);
+	if (!psphotSourceFreePixelsReadout (config, view, filerule, i)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to free source pixels for %s entry %d", filerule, i);
 	    return false;
 	}
@@ -18,10 +18,10 @@
 }
 
-bool psphotSourceFreePixelsReadout(pmConfig *config, const pmFPAview *view, const char *filename, int index) {
+bool psphotSourceFreePixelsReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index) {
 
     bool status;
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotSourceMatch.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotSourceMatch.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotSourceMatch.c	(revision 27909)
@@ -1,7 +1,7 @@
 # include "psphotInternal.h" 
 
-bool psphotMatchSourcesGenerate (pmConfig *config, const pmFPAview *view, psArray *objects);
- 
-psArray *psphotMatchSources (pmConfig *config, const pmFPAview *view) 
+bool psphotMatchSourcesGenerate (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects);
+ 
+psArray *psphotMatchSources (pmConfig *config, const pmFPAview *view, const char *filerule) 
 {
     bool status = true;
@@ -14,5 +14,5 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-        if (!psphotMatchSourcesReadout (objects, config, view, "PSPHOT.INPUT", i)) {
+        if (!psphotMatchSourcesReadout (objects, config, view, filerule, i)) {
             psError (PSPHOT_ERR_CONFIG, false, "failed to merge sources for PSPHOT.INPUT entry %d", i);
 	    psFree (objects);
@@ -21,10 +21,10 @@
     }
 
-    psphotMatchSourcesGenerate (config, view, objects);
+    psphotMatchSourcesGenerate (config, view, filerule, objects);
 
     return objects;
 }
 
-bool psphotMatchSourcesReadout (psArray *objects, pmConfig *config, const pmFPAview *view, char *filename, int index) { 
+bool psphotMatchSourcesReadout (psArray *objects, pmConfig *config, const pmFPAview *view, const char *filerule, int index) { 
  
     bool status = false;
@@ -38,5 +38,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
@@ -145,5 +145,5 @@
 } 
 
-bool psphotMatchSourcesGenerate (pmConfig *config, const pmFPAview *view, psArray *objects) {
+bool psphotMatchSourcesGenerate (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects) {
 
     bool status = false;
@@ -167,5 +167,5 @@
 
 	// find the currently selected readout
-	pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", i); // File of interest
+	pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
 	psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotSourceSize.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotSourceSize.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotSourceSize.c	(revision 27909)
@@ -33,5 +33,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotSourceSize (pmConfig *config, const pmFPAview *view, bool getPSFsize)
+bool psphotSourceSize (pmConfig *config, const pmFPAview *view, const char *filerule, bool getPSFsize)
 {
     bool status = true;
@@ -51,5 +51,5 @@
     for (int i = 0; i < num; i++) {
         if (i == chisqNum) continue; // skip chisq image
-        if (!psphotSourceSizeReadout (config, view, "PSPHOT.INPUT", i, recipe, getPSFsize)) {
+        if (!psphotSourceSizeReadout (config, view, filerule, i, recipe, getPSFsize)) {
             psError (PSPHOT_ERR_CONFIG, false, "failed on source size analysis for PSPHOT.INPUT entry %d", i);
             return false;
@@ -60,5 +60,5 @@
 
 // this function use an internal flag to mark sources which have already been measured
-bool psphotSourceSizeReadout(pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool getPSFsize)
+bool psphotSourceSizeReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool getPSFsize)
 {
     bool status;
@@ -68,5 +68,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotSourceStats.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotSourceStats.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotSourceStats.c	(revision 27909)
@@ -5,5 +5,5 @@
 // The new sources are added to any existing sources on detections->newSources.  The sources 
 // on detections->allSources are ignored.
-bool psphotSourceStats (pmConfig *config, const pmFPAview *view, bool setWindow)
+bool psphotSourceStats (pmConfig *config, const pmFPAview *view, const char *filerule, bool setWindow)
 {
     bool status = true;
@@ -18,6 +18,6 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-        if (!psphotSourceStatsReadout (config, view, "PSPHOT.INPUT", i, recipe, setWindow)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to find initial detections for PSPHOT.INPUT entry %d", i);
+        if (!psphotSourceStatsReadout (config, view, filerule, i, recipe, setWindow)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to find initial detections for %s entry %d", filerule, i);
             return false;
         }
@@ -26,5 +26,5 @@
 }
 
-bool psphotSourceStatsReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool setWindow) {
+bool psphotSourceStatsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool setWindow) {
 
     bool status = false;
@@ -34,5 +34,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (file, "missing file?");
 
Index: /branches/eam_branches/psphot.20100506/src/psphotStackChisqImage.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotStackChisqImage.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotStackChisqImage.c	(revision 27909)
@@ -6,5 +6,5 @@
 
 // XXX supply filename or keep PSPHOT.INPUT fixed?
-bool psphotStackChisqImage (pmConfig *config, const pmFPAview *view)
+bool psphotStackChisqImage (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = false;
@@ -22,6 +22,6 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-        if (!psphotStackChisqImageAddReadout(config, view, &chiReadout, "PSPHOT.INPUT", i)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to model background for PSPHOT.INPUT entry %d", i);
+        if (!psphotStackChisqImageAddReadout(config, view, filerule, &chiReadout, i)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to model background for %s entry %d", filerule, i);
             return false;
         }
@@ -35,6 +35,6 @@
     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "", num);
 
-    // need to save the resulting image somewhere (PSPHOT.INPUT?)
-    if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", chisqFile)) {
+    // save the resulting image
+    if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, filerule, PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", chisqFile)) {
         psError(PM_ERR_CONFIG, false, "could not add chisqFPA to config files");
         return false;
@@ -48,6 +48,6 @@
 bool psphotStackChisqImageAddReadout(const pmConfig *config, // Configuration
 				     const pmFPAview *view,
+				     const char *filerule, 
 				     pmReadout **chiReadout,
-				     char *filename, 
 				     int index) 
 {
@@ -55,5 +55,5 @@
 
     // find the currently selected readout
-    pmFPAfile *input = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *input = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     psAssert (input, "missing file?");
 
@@ -111,5 +111,5 @@
 }
 
-bool psphotStackRemoveChisqFromInputs (pmConfig *config) {
+bool psphotStackRemoveChisqFromInputs (pmConfig *config, const char *filerule) {
 
     bool status = false;
@@ -121,5 +121,5 @@
     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
 
-    pmFPAfileRemoveSingle (config->files, "PSPHOT.INPUT", chisqNum);
+    pmFPAfileRemoveSingle (config->files, filerule, chisqNum);
 
     inputNum --;
Index: /branches/eam_branches/psphot.20100506/src/psphotStackImageLoop.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotStackImageLoop.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotStackImageLoop.c	(revision 27909)
@@ -53,5 +53,5 @@
 
 		// XXX for now, we assume there is only a single chip in the PHU:
-		if (0 && !psphotStackReadout (config, view)) {
+		if (!psphotStackReadout (config, view)) {
                     psError(psErrorCodeLast(), false, "failure in psphotStackReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
                     psFree (view);
Index: /branches/eam_branches/psphot.20100506/src/psphotStackReadout.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotStackReadout.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotStackReadout.c	(revision 27909)
@@ -1,3 +1,6 @@
 # include "psphotInternal.h"
+
+# define STACK_RAW "PSPHOT.STACK.INPUT.RAW"
+# define STACK_OUT "PSPHOT.STACK.OUTPUT.IMAGE"
 
 bool psphotStackReadout (pmConfig *config, const pmFPAview *view) {
@@ -17,6 +20,8 @@
     PS_ASSERT_PTR_NON_NULL (breakPt, false);
 
+    // we have 3 relevant files: RAW, CNV, OUT 
+
     // set the photcode for each image
-    if (!psphotAddPhotcode (config, view)) {
+    if (!psphotAddPhotcode (config, view, STACK_OUT)) {
         psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
         return false;
@@ -24,21 +29,22 @@
 
     // Generate the mask and weight images
-    if (!psphotSetMaskAndVariance (config, view)) {
-	return psphotReadoutCleanup (config, view);
+    // XXX this should be done before we perform the convolutions
+    if (!psphotSetMaskAndVariance (config, view, STACK_RAW)) {
+	return psphotReadoutCleanup (config, view, STACK_OUT);
     }
     if (!strcasecmp (breakPt, "NOTHING")) {
-	return psphotReadoutCleanup (config, view);
+	return psphotReadoutCleanup (config, view, STACK_OUT);
     }
 
     // generate a background model (median, smoothed image)
     // XXX I think this is not defined correctly for an array of images.
-    if (!psphotModelBackground (config, view)) {
-	return psphotReadoutCleanup (config, view);
+    if (!psphotModelBackground (config, view, STACK_RAW)) {
+	return psphotReadoutCleanup (config, view, STACK_OUT);
     }
-    if (!psphotSubtractBackground (config, view)) {
-	return psphotReadoutCleanup (config, view);
+    if (!psphotSubtractBackground (config, view, STACK_RAW)) {
+	return psphotReadoutCleanup (config, view, STACK_OUT);
     }
     if (!strcasecmp (breakPt, "BACKMDL")) {
-	return psphotReadoutCleanup (config, view);
+	return psphotReadoutCleanup (config, view, STACK_OUT);
     }
 
@@ -47,37 +53,37 @@
     if (!psphotLoadPSF (config, view)) {
         psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, STACK_OUT);
     }
 
-    if (!psphotStackChisqImage(config, view)) {
+    if (!psphotStackChisqImage(config, view, STACK_RAW)) {
         psError (PSPHOT_ERR_UNKNOWN, false, "failure to generate chisq image");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, STACK_OUT);
     }
     if (!strcasecmp (breakPt, "CHISQ")) {
-	return psphotReadoutCleanup (config, view);
+	return psphotReadoutCleanup (config, view, STACK_OUT);
     }
 
     // find the detections (by peak and/or footprint) in the image.
     // This finds the detections on Chisq image as well as the individuals
-    if (!psphotFindDetections (config, view, true)) { // pass 1
+    if (!psphotFindDetections (config, view, STACK_RAW, 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);
+        return psphotReadoutCleanup (config, view, STACK_OUT);
     }
 
     // construct sources and measure basic stats (saved on detections->newSources)
     // only run this on detections from the input images, not chisq image
-    if (!psphotSourceStats (config, view, true)) { // pass 1
+    if (!psphotSourceStats (config, view, STACK_OUT, true)) { // pass 1
         psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, STACK_OUT);
     }
 
     // *** generate the objects (which unify the sources from the different images)
-    psArray *objects = psphotMatchSources (config, view);
+    psArray *objects = psphotMatchSources (config, view, STACK_OUT);
 
     // construct sources for the newly-generated sources (from other images)
-    if (!psphotSourceStats (config, view, false)) { // pass 1
+    if (!psphotSourceStats (config, view, STACK_OUT, false)) { // pass 1
         psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, STACK_OUT);
     }
 
@@ -85,5 +91,5 @@
     // if (!psphotDeblendSatstars (config, view)) {
     //     psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
-    //     return psphotReadoutCleanup (config, view);
+    //     return psphotReadoutCleanup (config, view, STACK_OUT);
     // }
 
@@ -91,43 +97,43 @@
     // if (!psphotBasicDeblend (config, view)) {
     //     psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis");
-    //     return psphotReadoutCleanup (config, view);
+    //     return psphotReadoutCleanup (config, view, STACK_OUT);
     // }
 
     // classify sources based on moments, brightness
     // only run this on detections from the input images, not chisq image
-    if (!psphotRoughClass (config, view)) {
+    if (!psphotRoughClass (config, view, STACK_OUT)) {
         psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications");
-	return psphotReadoutCleanup (config, view);
+	return psphotReadoutCleanup (config, view, STACK_OUT);
     }
     // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources)
     // only run this on detections from the input images, not chisq image
-    if (!psphotImageQuality (config, view)) { // pass 1
+    if (!psphotImageQuality (config, view, STACK_OUT)) { // pass 1
         psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality");
-        return psphotReadoutCleanup(config, view);
+        return psphotReadoutCleanup (config, view, STACK_OUT);
     }
     if (!strcasecmp (breakPt, "MOMENTS")) {
-	return psphotReadoutCleanup (config, view);
+	return psphotReadoutCleanup (config, view, STACK_OUT);
     }
 
     // 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)) { // pass 1
+    if (!psphotChoosePSF (config, view, STACK_OUT)) { // pass 1
         psLogMsg ("psphot", 3, "failure to construct a psf model");
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, STACK_OUT);
     }
     if (!strcasecmp (breakPt, "PSFMODEL")) {
-        return psphotReadoutCleanup (config, view);
+        return psphotReadoutCleanup (config, view, STACK_OUT);
     }
 
     // include externally-supplied sources
     // XXX fix this in the new multi-input context
-    // psphotLoadExtSources (config, view); // pass 1
+    // psphotLoadExtSources (config, view, "PSPHOT.INPUT"); // pass 1
 
     // construct an initial model for each object, set the radius to fitRadius, set circular fit mask
-    psphotGuessModels (config, view);
+    psphotGuessModels (config, view, STACK_OUT);
 
     // merge the newly selected sources into the existing list
     // NOTE: merge OLD and NEW
-    psphotMergeSources (config, view);
+    psphotMergeSources (config, view, STACK_OUT);
 
     // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
@@ -136,16 +142,19 @@
 
     // identify CRs and extended sources
-    psphotSourceSize (config, view, TRUE);
+    psphotSourceSize (config, view, STACK_OUT, TRUE);
 
     // measure aperture photometry corrections
-    if (!psphotApResid (config, view)) {
+    if (!psphotApResid (config, view, STACK_OUT)) {
         psLogMsg ("psphot", 3, "failed on psphotApResid");
-	return psphotReadoutCleanup (config, view);
+	return psphotReadoutCleanup (config, view, STACK_OUT);
     }
 
+    psphotExtendedSourceAnalysis (config, view, STACK_OUT); // pass 1 (detections->allSources)
+    psphotExtendedSourceFits (config, view, STACK_OUT); // pass 1 (detections->allSources)
+
     // calculate source magnitudes
-    psphotMagnitudes(config, view);
+    psphotMagnitudes(config, view, STACK_OUT);
 
-    if (!psphotEfficiency(config, view)) {
+    if (!psphotEfficiency(config, view, STACK_OUT)) {
         psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
         psErrorClear();
@@ -156,14 +165,14 @@
 
     // replace background in residual image
-    psphotSkyReplace (config, view);
+    psphotSkyReplace (config, view, STACK_RAW);
 
     // drop the references to the image pixels held by each source
-    psphotSourceFreePixels (config, view);
+    psphotSourceFreePixels (config, view, STACK_OUT);
 
     // remove chisq image from config->file:PSPHOT.INPUT (why?)
-    psphotStackRemoveChisqFromInputs(config);
+    psphotStackRemoveChisqFromInputs(config, STACK_RAW);
 
     // create the exported-metadata and free local data
-    return psphotReadoutCleanup (config, view);
+    return psphotReadoutCleanup (config, view, STACK_OUT);
 }
 
Index: /branches/eam_branches/psphot.20100506/src/psphotSubtractBackground.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotSubtractBackground.c	(revision 27908)
+++ /branches/eam_branches/psphot.20100506/src/psphotSubtractBackground.c	(revision 27909)
@@ -4,5 +4,5 @@
 // generate the median in NxN boxes, clipping heavily
 // linear interpolation to generate full-scale model
-bool psphotSubtractBackgroundReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe)
+bool psphotSubtractBackgroundReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe)
 {
     bool status = true;
@@ -13,5 +13,5 @@
 
     // find the currently selected readout
-    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
 
     pmFPA *inFPA = file->fpa;
@@ -124,5 +124,5 @@
 }
 
-bool psphotSubtractBackground (pmConfig *config, const pmFPAview *view)
+bool psphotSubtractBackground (pmConfig *config, const pmFPAview *view, const char *filerule)
 {
     bool status = false;
@@ -137,5 +137,5 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotSubtractBackgroundReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
+	if (!psphotSubtractBackgroundReadout (config, view, filerule, i, recipe)) {
             psError (PSPHOT_ERR_CONFIG, false, "failed to subtract background for PSPHOT.INPUT entry %d", i);
 	    return false;
