Index: trunk/psphot/src/psphotStackChisqImage.c
===================================================================
--- trunk/psphot/src/psphotStackChisqImage.c	(revision 27657)
+++ trunk/psphot/src/psphotStackChisqImage.c	(revision 28013)
@@ -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 *ruleDet, const char *ruleCnv)
 {
     bool status = false;
@@ -21,7 +21,8 @@
 
     // loop over the available readouts
+    // generate the chisq image from the 'detection' images
     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, ruleDet, &chiReadout, i)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to model background for %s entry %d", ruleDet, i);
             return false;
         }
@@ -35,6 +36,12 @@
     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 in the 'detection' set
+    if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, ruleDet, PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", chisqFile)) {
+        psError(PM_ERR_CONFIG, false, "could not add chisqFPA to config files");
+        return false;
+    }
+
+    // save the resulting image in the 'convolved' set
+    if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, ruleCnv, PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", chisqFile)) {
         psError(PM_ERR_CONFIG, false, "could not add chisqFPA to config files");
         return false;
@@ -48,6 +55,6 @@
 bool psphotStackChisqImageAddReadout(const pmConfig *config, // Configuration
 				     const pmFPAview *view,
+				     const char *filerule, 
 				     pmReadout **chiReadout,
-				     char *filename, 
 				     int index) 
 {
@@ -55,5 +62,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 +118,5 @@
 }
 
-bool psphotStackRemoveChisqFromInputs (pmConfig *config) {
+bool psphotStackRemoveChisqFromInputs (pmConfig *config, const char *filerule) {
 
     bool status = false;
@@ -121,5 +128,5 @@
     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
 
-    pmFPAfileRemoveSingle (config->files, "PSPHOT.INPUT", chisqNum);
+    pmFPAfileRemoveSingle (config->files, filerule, chisqNum);
 
     inputNum --;
