Index: trunk/psphot/src/psphotStackParseCamera.c
===================================================================
--- trunk/psphot/src/psphotStackParseCamera.c	(revision 27657)
+++ trunk/psphot/src/psphotStackParseCamera.c	(revision 28013)
@@ -25,40 +25,127 @@
 	psMetadata *input = item->data.md; // The input metadata of interest
 
-	// look for 'IMAGE', 'MASK', 'VARIANCE' in folder (only 'IMAGE' is required)
-
-	psString image = psMetadataLookupStr(NULL, input, "IMAGE"); // Name of image
-	if (!image || strlen(image) == 0) {
-	    psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks IMAGE of type STR", item->name);
+	pmFPAfile *rawInputFile = NULL;
+	pmFPAfile *cnvInputFile = NULL;
+
+	// RAW (unconvolved) input data (RAW:IMAGE, RAW:MASK, RAW:VARIANCE, RAW:PSF)
+	psString rawImage = psMetadataLookupStr(&status, input, "RAW:IMAGE"); // Name of image
+	if (rawImage && strlen(rawImage) > 0) {
+	    rawInputFile = defineFile(config, NULL, "PSPHOT.STACK.INPUT.RAW", rawImage, PM_FPA_FILE_IMAGE); // File for image
+	    if (!rawInputFile) {
+		psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", i, rawImage);
+		return false;
+	    }
+	    psString mask = psMetadataLookupStr(&status, input, "RAW:MASK"); // Name of mask
+	    if (mask && strlen(mask) > 0) {
+		if (!defineFile(config, rawInputFile, "PSPHOT.STACK.MASK.RAW", mask, PM_FPA_FILE_MASK)) {
+		    psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", i, mask);
+		    return false;
+		}
+	    }
+	    psString variance = psMetadataLookupStr(&status, input, "RAW:VARIANCE"); // Name of variance map
+	    if (variance && strlen(variance) > 0) {
+		if (!defineFile(config, rawInputFile, "PSPHOT.STACK.VARIANCE.RAW", variance, PM_FPA_FILE_VARIANCE)) {
+		    psError(PS_ERR_UNKNOWN, false, "Unable to define file from variance %d (%s)", i, variance);
+		    return false;
+		}
+	    }
+	    psString psf = psMetadataLookupStr(&status, input, "RAW:PSF"); // Name of mask
+	    if (psf && strlen(psf) > 0) {
+		if (!defineFile(config, rawInputFile, "PSPHOT.STACK.PSF.RAW", psf, PM_FPA_FILE_PSF)) {
+		    psError(PS_ERR_UNKNOWN, false, "Unable to define file from psf %d (%s)", i, psf);
+		    return false;
+		}
+	    }
+	}
+
+	// CNV (convolved) input data (CNV:IMAGE, CNV:MASK, CNV:VARIANCE, CNV:PSF)
+	psString cnvImage = psMetadataLookupStr(&status, input, "CNV:IMAGE"); // Name of image
+	if (cnvImage && strlen(cnvImage) > 0) {
+	    cnvInputFile = defineFile(config, NULL, "PSPHOT.STACK.INPUT.CNV", cnvImage, PM_FPA_FILE_IMAGE); // File for image
+	    if (!cnvInputFile) {
+		psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", i, cnvImage);
+		return false;
+	    }
+	    psString mask = psMetadataLookupStr(&status, input, "CNV:MASK"); // Name of mask
+	    if (mask && strlen(mask) > 0) {
+		if (!defineFile(config, cnvInputFile, "PSPHOT.STACK.MASK.CNV", mask, PM_FPA_FILE_MASK)) {
+		    psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", i, mask);
+		    return false;
+		}
+	    }
+	    psString variance = psMetadataLookupStr(&status, input, "CNV:VARIANCE"); // Name of variance map
+	    if (variance && strlen(variance) > 0) {
+		if (!defineFile(config, cnvInputFile, "PSPHOT.STACK.VARIANCE.CNV", variance, PM_FPA_FILE_VARIANCE)) {
+		    psError(PS_ERR_UNKNOWN, false, "Unable to define file from variance %d (%s)", i, variance);
+		    return false;
+		}
+	    }
+	    psString psf = psMetadataLookupStr(&status, input, "CNV:PSF"); // Name of mask
+	    if (psf && strlen(psf) > 0) {
+		if (!defineFile(config, cnvInputFile, "PSPHOT.STACK.PSF.CNV", psf, PM_FPA_FILE_PSF)) {
+		    psError(PS_ERR_UNKNOWN, false, "Unable to define file from psf %d (%s)", i, psf);
+		    return false;
+		}
+	    }
+	}
+
+	if (!rawInputFile && !cnvInputFile) {
+	    psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s (%d) lacks IMAGE of type STR", item->name, i);
 	    return false;
 	}
-	pmFPAfile *imageFile = defineFile(config, NULL, "PSPHOT.INPUT", image, PM_FPA_FILE_IMAGE); // File for image
-	if (!imageFile) {
-	    psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", i, image);
-	    return false;
-	}
-
-	psString mask = psMetadataLookupStr(&status, input, "MASK"); // Name of mask
-	if (mask && strlen(mask) > 0) {
-	    if (!defineFile(config, imageFile, "PSPHOT.MASK", mask, PM_FPA_FILE_MASK)) {
-		psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", i, mask);
-		return false;
-	    }
-	}
-
-	psString variance = psMetadataLookupStr(&status, input, "VARIANCE"); // Name of variance map
-	if (variance && strlen(variance) > 0) {
-	    if (!defineFile(config, imageFile, "PSPHOT.VARIANCE", variance, PM_FPA_FILE_VARIANCE)) {
-		psError(PS_ERR_UNKNOWN, false, "Unable to define file from variance %d (%s)", i, variance);
-		return false;
-	    }
-	}
-	// the output sources are carried on the input->fpa structures
-	pmFPAfile *outsources = pmFPAfileDefineOutputFromFile (config, imageFile, "PSPHOT.STACK.OUTPUT");
-	if (!outsources) {
-	    psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.STACK.OUTPUT");
-	    return false;
-	}
-	outsources->save = true;
-	outsources->fileID = i;		// this is used to generate output names
+
+	psString sources = psMetadataLookupStr(&status, input, "SOURCES"); // Name of mask
+	// pmFPAfile *srcInputFile = rawInputFile ? rawInputFile : cnvInputFile;
+	if (sources && strlen(sources) > 0) {
+	    if (!defineFile(config, NULL, "PSPHOT.STACK.SOURCES", sources, PM_FPA_FILE_CMF)) {
+		psError(PS_ERR_UNKNOWN, false, "Unable to define file from sources %d (%s)", i, sources);
+		return false;
+	    }
+	}
+
+	// generate an pmFPAimage for the output convolved image
+	// XXX output of these files should be optional
+	{
+	    pmFPAfile *outputImage = pmFPAfileDefineOutput(config, NULL, "PSPHOT.STACK.OUTPUT.IMAGE");
+	    if (!outputImage) {
+		psError(PSPHOT_ERR_CONFIG, false, "Trouble defining PSPHOT.STACK.OUTPUT.IMAGE");
+		return false;
+	    }
+	    outputImage->save = true;
+	    outputImage->fileID = i;		// this is used to generate output names
+
+	    pmFPAfile *outputMask = pmFPAfileDefineOutput(config, outputImage->fpa, "PSPHOT.STACK.OUTPUT.MASK");
+	    if (!outputMask) {
+		psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.STACK.OUTPUT.MASK"));
+		return NULL;
+	    }
+	    if (outputMask->type != PM_FPA_FILE_MASK) {
+		psError(PS_ERR_IO, true, "PSPHOT.STACK.OUTPUT.MASK is not of type MASK");
+		return NULL;
+	    }
+	    outputMask->save = true;
+	    outputMask->fileID = i;		// this is used to generate output names
+
+	    pmFPAfile *outputVariance = pmFPAfileDefineOutput(config, outputImage->fpa, "PSPHOT.STACK.OUTPUT.VARIANCE");
+	    if (!outputVariance) {
+		psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.STACK.OUTPUT.VARIANCE"));
+		return NULL;
+	    }
+	    if (outputVariance->type != PM_FPA_FILE_VARIANCE) {
+		psError(PS_ERR_IO, true, "PSPHOT.STACK.OUTPUT.VARIANCE is not of type VARIANCE");
+		return NULL;
+	    }
+	    outputVariance->save = true;
+	    outputVariance->fileID = i;		// this is used to generate output names
+
+	    // the output sources are carried on the outputImage->fpa structures
+	    pmFPAfile *outsources = pmFPAfileDefineOutputFromFile (config, outputImage, "PSPHOT.STACK.OUTPUT");
+	    if (!outsources) {
+		psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.STACK.OUTPUT");
+		return false;
+	    }
+	    outsources->save = true;
+	    outsources->fileID = i;		// this is used to generate output names
+	}
     }
     psMetadataRemoveKey(config->arguments, "FILENAMES");
@@ -71,41 +158,35 @@
 
     // generate an pmFPAimage for the chisqImage
-    pmFPAfile *chisqImage = pmFPAfileDefineOutput(config, NULL, "PSPHOT.CHISQ.IMAGE");
-    if (!chisqImage) {
-        psError(PSPHOT_ERR_CONFIG, false, "Trouble defining PSPHOT.CHISQ.IMAGE");
-        return false;
-    }
-    chisqImage->save = true;
-
-    pmFPAfile *chisqMask = pmFPAfileDefineOutput(config, chisqImage->fpa, "PSPHOT.CHISQ.MASK");
-    if (!chisqMask) {
-        psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.CHISQ.MASK"));
-        return NULL;
-    }
-    if (chisqMask->type != PM_FPA_FILE_MASK) {
-        psError(PS_ERR_IO, true, "PSPHOT.CHISQ.MASK is not of type MASK");
-        return NULL;
-    }
-    chisqMask->save = true;
-
-    pmFPAfile *chisqVariance = pmFPAfileDefineOutput(config, chisqImage->fpa, "PSPHOT.CHISQ.VARIANCE");
-    if (!chisqVariance) {
-        psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.CHISQ.VARIANCE"));
-        return NULL;
-    }
-    if (chisqVariance->type != PM_FPA_FILE_VARIANCE) {
-        psError(PS_ERR_IO, true, "PSPHOT.CHISQ.VARIANCE is not of type VARIANCE");
-        return NULL;
-    }
-    chisqVariance->save = true;
-
-# if (0)    
-    // define the additional input/output files associated with psphot
-    // XXX figure out which files are needed by psphotStack
-    if (false && !psphotDefineFiles (config, input)) {
-        psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files");
-        return false;
-    }
-# endif
+    // XXX output of these files should be optional
+    {
+	pmFPAfile *chisqImage = pmFPAfileDefineOutput(config, NULL, "PSPHOT.CHISQ.IMAGE");
+	if (!chisqImage) {
+	    psError(PSPHOT_ERR_CONFIG, false, "Trouble defining PSPHOT.CHISQ.IMAGE");
+	    return false;
+	}
+	chisqImage->save = true;
+
+	pmFPAfile *chisqMask = pmFPAfileDefineOutput(config, chisqImage->fpa, "PSPHOT.CHISQ.MASK");
+	if (!chisqMask) {
+	    psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.CHISQ.MASK"));
+	    return NULL;
+	}
+	if (chisqMask->type != PM_FPA_FILE_MASK) {
+	    psError(PS_ERR_IO, true, "PSPHOT.CHISQ.MASK is not of type MASK");
+	    return NULL;
+	}
+	chisqMask->save = true;
+
+	pmFPAfile *chisqVariance = pmFPAfileDefineOutput(config, chisqImage->fpa, "PSPHOT.CHISQ.VARIANCE");
+	if (!chisqVariance) {
+	    psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.CHISQ.VARIANCE"));
+	    return NULL;
+	}
+	if (chisqVariance->type != PM_FPA_FILE_VARIANCE) {
+	    psError(PS_ERR_IO, true, "PSPHOT.CHISQ.VARIANCE is not of type VARIANCE");
+	    return NULL;
+	}
+	chisqVariance->save = true;
+    }
 
     psTrace("psphot", 1, "Done with psphotStackParseCamera...\n");
@@ -145,2 +226,29 @@
 }
 
+
+/***
+ *
+ *  psphotStack :
+
+ *    * inputs:
+ *      * unconvolved images
+ *      * raw convolved images
+ *      * psfs (unconvolved or convolved?)
+ *      * sources
+ 
+ * optionally convolve the unconvolved or the raw inputs
+ * optionally perform no convolutions
+ * optionally save the psf-matched images
+
+ */
+
+    
+# if (0)    
+    // define the additional input/output files associated with psphot
+    // XXX figure out which files are needed by psphotStack
+    if (false && !psphotDefineFiles (config, input)) {
+        psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files");
+        return false;
+    }
+# endif
+
