Index: /branches/eam_branches/psphot.20100506/src/psphot.h
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphot.h	(revision 27883)
+++ /branches/eam_branches/psphot.20100506/src/psphot.h	(revision 27884)
@@ -453,4 +453,5 @@
 psphotStackOptions *psphotStackOptionsAlloc (int num);
 psphotStackConvolveSource psphotStackConvolveSourceFromString (const char *string);
+pmFPAfile *psphotStackGetConvolveSource (pmConfig *config, psphotStackOptions *options, int index);
 
 #endif
Index: /branches/eam_branches/psphot.20100506/src/psphotStackImageLoop.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotStackImageLoop.c	(revision 27883)
+++ /branches/eam_branches/psphot.20100506/src/psphotStackImageLoop.c	(revision 27884)
@@ -33,10 +33,10 @@
         psLogMsg ("psphot", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (! chip->process || ! chip->file_exists) { continue; }
-        // if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psphotStack.");
+        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psphotStack.");
 
         // there is now only a single chip (multiple readouts?). loop over it and process
         while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
             psLogMsg ("psphot", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
-	    // if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Cell in psphotStack.");
+	    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Cell in psphotStack.");
 
             // process each of the readouts
Index: /branches/eam_branches/psphot.20100506/src/psphotStackMatchPSFs.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotStackMatchPSFs.c	(revision 27883)
+++ /branches/eam_branches/psphot.20100506/src/psphotStackMatchPSFs.c	(revision 27884)
@@ -64,20 +64,25 @@
 bool psphotStackMatchPSFsReadout (pmConfig *config, const pmFPAview *view, psphotStackOptions *options, int index) {
 
-    // find the currently selected readout
-    pmFPAfile *fileRaw = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", index); // File of interest
-    psAssert (fileRaw, "missing file?");
+    pmFPAfile *fileSrc = psphotStackGetConvolveSource(config, options, index);
+    if (!fileSrc) {
+	psError(PSPHOT_ERR_CONFIG, false, "desired convolution source is missing");
+	return false;
+    }
 
-    pmFPAfile *fileCnv = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.CNV", index); // File of interest
-    psAssert (fileCnv, "missing file?");
+    pmFPAfile *fileOut = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.OUTPUT.IMAGE", index); // File of interest
+    psAssert (fileOut, "missing output file?");
 
-    pmReadout *readoutRaw = pmFPAviewThisReadout(view, fileRaw->fpa);
-    psAssert (readoutRaw, "missing readout?");
+    pmReadout *readoutSrc = pmFPAviewThisReadout(view, fileSrc->fpa);
+    psAssert (readoutSrc, "missing readout?");
 
-    pmReadout *readoutCnv = pmFPAviewThisReadout(view, fileCnv->fpa);
-    psAssert (readoutCnv, "missing readout?");
+    pmReadout *readoutOut = pmFPAviewThisReadout(view, fileOut->fpa);
+    if (readoutOut == NULL) {
+	readoutOut = pmFPAGenerateReadout(config, view, "PSPHOT.STACK.OUTPUT.IMAGE", fileSrc->fpa, NULL, 0);
+	psAssert (readoutOut, "missing readout?");
+    }
 
     // set NAN pixels to 'SAT'
     psImageMaskType maskVal = pmConfigMaskGet("SAT", config);
-    if (!pmReadoutMaskNonfinite(readoutRaw, maskVal)) {
+    if (!pmReadoutMaskNonfinite(readoutSrc, maskVal)) {
         psError(psErrorCodeLast(), false, "Unable to mask non-finite pixels in readout.");
         return false;
@@ -86,6 +91,6 @@
     // Image Matching (PSFs or just flux)
     if (options->convolve) {
-	matchKernel(config, readoutCnv, readoutRaw, options, index);
-	saveMatchData(readoutCnv, options, index);
+	matchKernel(config, readoutOut, readoutSrc, options, index);
+	saveMatchData(readoutOut, options, index);
 	// renormKernel(readoutCnv, options, index);
     } else {
@@ -97,7 +102,7 @@
     }
 
-    rescaleData(readoutCnv, config, options, index);
+    rescaleData(readoutOut, config, options, index);
 
-    dumpImage(readoutCnv, readoutRaw, index, "convolved");
+    dumpImage(readoutOut, readoutSrc, index, "convolved");
 
     return true;
Index: /branches/eam_branches/psphot.20100506/src/psphotStackMatchPSFsPrepare.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotStackMatchPSFsPrepare.c	(revision 27883)
+++ /branches/eam_branches/psphot.20100506/src/psphotStackMatchPSFsPrepare.c	(revision 27884)
@@ -1,3 +1,6 @@
 # include "psphotInternal.h"
+
+pmPSF *selectPSF (pmFPAfile *fileSrc, const pmFPAview *view, psphotStackOptions *options, int index);
+bool determineSeeing (pmPSF *psf, psphotStackOptions *options, int index);
 
 // set up the stacking parameters
@@ -9,73 +12,22 @@
     }
 
-    // which image do we want to convolve?  RAW, CNV, AUTO?
-    // find the currently selected readout
-    pmFPAfile *fileRaw = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", index); // File of interest
-    pmFPAfile *fileCnv = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.CNV", index); // File of interest
-
-    pmFPAfile *fileSrc = NULL;
-    pmPSF *psf = NULL;
-
-    switch (options->convolveSource) {
-      case PSPHOT_CNV_SRC_AUTO:
-	fileSrc = fileCnv ? fileCnv : fileRaw;
-	break;
-
-      case PSPHOT_CNV_SRC_RAW:
-	fileSrc = fileRaw;
-	break;
-
-      case PSPHOT_CNV_SRC_CNV:
-	fileSrc = fileCnv;
-	break;
-
-      default:
-	psAbort("impossible case");
-    }
+    pmFPAfile *fileSrc = psphotStackGetConvolveSource(config, options, index);
     if (!fileSrc) {
-	psError(PSPHOT_ERR_CONFIG, true, "desired convolution source is missing (cnv : %llx, raw : %llx)", (long long) fileCnv, (long long) fileRaw);
+	psError(PSPHOT_ERR_CONFIG, false, "desired convolution source is missing");
 	return false;
     }
 
-    // select the corresponding input psf
-    {
-	pmChip *chip = pmFPAviewThisChip(view, fileSrc->fpa); // The chip holds the PSF
-	pmPSF *psf = psMetadataLookupPtr(NULL, chip->analysis, "PSPHOT.PSF"); // PSF
-	if (!psf) {
-	    // XXX if we were not supplied a PSF, we should be able to generate one by calling psphot
-	    psError(PSPHOT_ERR_PROG, false, "Unable to find PSF.");
-	    return false;
-	}
-	options->psfs->data[index] = psMemIncrRefCounter(psf);
+    pmPSF *psf = selectPSF (fileSrc, view, options, index);
+    if (!psf) {
+	psError(PSPHOT_ERR_PSF, false, "Problem with PSF.");
+	return false;
+    }
 
-	// find the image size
-	pmCell *cell = pmFPAviewThisCell(view, fileSrc->fpa); // Cell of interest
-	pmHDU *hdu = pmHDUFromCell(cell);
-	assert(hdu && hdu->header);
-	int naxis1 = psMetadataLookupS32(NULL, hdu->header, "NAXIS1"); // Number of columns
-	int naxis2 = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); // Number of rows
-	psAssert ((naxis1 > 0) && (naxis2 > 0), "Unable to determine size of image from PSF.");
-	if (!options->numCols) {
-	    options->numCols = naxis1;
-	} else {
-	    if (options->numCols != naxis1) {
-		psError (PSPHOT_ERR_CONFIG, true, "mismatched sizes (NAXIS1) for input images");
-		return false;
-	    }
-	}
-	if (!options->numRows) {
-	    options->numRows = naxis2;
-	} else {
-	    if (options->numRows != naxis2) {
-		psError (PSPHOT_ERR_CONFIG, true, "mismatched sizes (NAXIS2) for input images");
-		return false;
-	    }
-	}
-    }
+    determineSeeing (psf, options, index);
 
     // load the sources (used to find reference sources for the kernel stamps)
     {
-	pmFPAfile *outputImage = pmFPAfileDefineOutput(config, NULL, "PSPHOT.STACK.OUTPUT.IMAGE");
-	pmReadout *readout = pmFPAviewThisReadout(view, outputImage->fpa); // Readout with sources
+	pmFPAfile *inputSrc = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.SOURCES", index); // File of interest
+	pmReadout *readout = pmFPAviewThisReadout(view, inputSrc->fpa); // Readout with sources
 	pmDetections *detections = psMetadataLookupPtr(NULL, readout->analysis, "PSPHOT.DETECTIONS"); // Sources
 	if (!detections || !detections->allSources) {
@@ -88,32 +40,75 @@
     }
 
+    return true;
+}
+
+// select the corresponding input psf
+pmPSF *selectPSF (pmFPAfile *fileSrc, const pmFPAview *view, psphotStackOptions *options, int index) {
+
+    bool status;
+
+    pmChip *chip = pmFPAviewThisChip(view, fileSrc->fpa); // The chip holds the PSF
+    pmPSF *psf = psMetadataLookupPtr(&status, chip->analysis, "PSPHOT.PSF"); // PSF
+    if (!psf) {
+	// XXX if we were not supplied a PSF, we should be able to generate one by calling psphot
+	psError(PSPHOT_ERR_PROG, true, "Unable to find PSF.");
+	return NULL;
+    }
+    options->psfs->data[index] = psMemIncrRefCounter(psf);
+
+    // find the image size
+    pmCell *cell = pmFPAviewThisCell(view, fileSrc->fpa); // Cell of interest
+    pmHDU *hdu = pmHDUFromCell(cell);
+    assert(hdu && hdu->header);
+    int naxis1 = psMetadataLookupS32(NULL, hdu->header, "NAXIS1"); // Number of columns
+    int naxis2 = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); // Number of rows
+    psAssert ((naxis1 > 0) && (naxis2 > 0), "Unable to determine size of image from PSF.");
+    if (!options->numCols) {
+	options->numCols = naxis1;
+    } else {
+	if (options->numCols != naxis1) {
+	    psError (PSPHOT_ERR_CONFIG, true, "mismatched sizes (NAXIS1) for input images");
+	    return NULL;
+	}
+    }
+    if (!options->numRows) {
+	options->numRows = naxis2;
+    } else {
+	if (options->numRows != naxis2) {
+	    psError (PSPHOT_ERR_CONFIG, true, "mismatched sizes (NAXIS2) for input images");
+	    return NULL;
+	}
+    }
+    return psf;
+}
+
     // determine the input seeing
-    {
-	// XXX set this based on the mode (+1 for poly, +0 for map)
-	float xNum = PS_MAX(psf->trendNx, 1); 
-	float yNum = PS_MAX(psf->trendNy, 1); // Number of realisations
-	float sumFWHM = 0.0;		  // FWHM for image
-	int numFWHM = 0;			  // Number of FWHM measurements
-	for (float y = 0; y < yNum; y += 1.0) {
-	    float yPos = options->numRows * ((y + 0.5) / yNum);
-	    for (float x = 0; x < xNum; x++) {
-		float xPos = options->numCols * ((x + 0.5) / xNum);
-		float fwhm = pmPSFtoFWHM(psf, xPos, yPos); // FWHM for image
-		if (isfinite(fwhm)) {
-		    sumFWHM += fwhm;
-		    numFWHM++;
-		}
+bool determineSeeing (pmPSF *psf, psphotStackOptions *options, int index) {
+
+    // XXX set this based on the mode (+1 for poly, +0 for map)
+    float xNum = PS_MAX(psf->trendNx, 1); 
+    float yNum = PS_MAX(psf->trendNy, 1); // Number of realisations
+    float sumFWHM = 0.0;		  // FWHM for image
+    int numFWHM = 0;			  // Number of FWHM measurements
+    for (float y = 0; y < yNum; y += 1.0) {
+	float yPos = options->numRows * ((y + 0.5) / yNum);
+	for (float x = 0; x < xNum; x++) {
+	    float xPos = options->numCols * ((x + 0.5) / xNum);
+	    float fwhm = pmPSFtoFWHM(psf, xPos, yPos); // FWHM for image
+	    if (isfinite(fwhm)) {
+		sumFWHM += fwhm;
+		numFWHM++;
 	    }
 	}
-	if (numFWHM == 0) {
-	    options->inputSeeing->data.F32[index] = NAN;
-	    options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[index] = 0x02;
-	    psLogMsg("ppStack", PS_LOG_INFO, "Unable to measure PSF FWHM for image %d --- rejected.", index);
-	} else {
-	    options->inputSeeing->data.F32[index] = sumFWHM / (float)numFWHM;
-	}
-	psLogMsg ("psphotStack", PS_LOG_INFO, "Input Seeing for %d: %f\n", index, options->inputSeeing->data.F32[index]);
     }
-
+    if (numFWHM == 0) {
+	options->inputSeeing->data.F32[index] = NAN;
+	options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[index] = 0x02;
+	psLogMsg("ppStack", PS_LOG_INFO, "Unable to measure PSF FWHM for image %d --- rejected.", index);
+    } else {
+	options->inputSeeing->data.F32[index] = sumFWHM / (float)numFWHM;
+    }
+    psLogMsg ("psphotStack", PS_LOG_INFO, "Input Seeing for %d: %f\n", index, options->inputSeeing->data.F32[index]);
     return true;
 }
+
Index: /branches/eam_branches/psphot.20100506/src/psphotStackMatchPSFsUtils.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotStackMatchPSFsUtils.c	(revision 27883)
+++ /branches/eam_branches/psphot.20100506/src/psphotStackMatchPSFsUtils.c	(revision 27884)
@@ -259,5 +259,5 @@
 
 // perform the bulk of the PSF-matching
-bool matchKernel(pmConfig *config, pmReadout *readoutCnv, pmReadout *readoutRaw, psphotStackOptions *options, int index) {
+bool matchKernel(pmConfig *config, pmReadout *readoutOut, pmReadout *readoutSrc, psphotStackOptions *options, int index) {
 
     bool mdok;
@@ -338,16 +338,16 @@
     stampSources = stackSourcesFilter(options->sourceLists->data[index], footprint); // Filtered list of sources
 
-    fake = makeFakeReadout(config, readoutRaw, stampSources, options->psf, maskVal | maskBad, footprint + size);
+    fake = makeFakeReadout(config, readoutSrc, stampSources, options->psf, maskVal | maskBad, footprint + size);
     if (!fake) goto escape;
 
-    dumpImage(fake, readoutRaw, index, "fake");
-    dumpImage(readoutRaw,  readoutRaw, index, "real");
+    dumpImage(fake, readoutSrc, index, "fake");
+    dumpImage(readoutSrc,  readoutSrc, index, "real");
 
     if (threads) pmSubtractionThreadsInit();
 
     // Do the image matching
-    pmSubtractionKernels *kernel = psMetadataLookupPtr(&mdok, readoutRaw->analysis, PM_SUBTRACTION_ANALYSIS_KERNEL); // Conv kernel
+    pmSubtractionKernels *kernel = psMetadataLookupPtr(&mdok, readoutSrc->analysis, PM_SUBTRACTION_ANALYSIS_KERNEL); // Conv kernel
     if (kernel) {
-	if (!pmSubtractionMatchPrecalc(NULL, readoutCnv, fake, readoutRaw, readoutRaw->analysis, stride, kernelError, covarFrac, maskVal, maskBad, maskPoor, poorFrac, badFrac)) {
+	if (!pmSubtractionMatchPrecalc(NULL, readoutOut, fake, readoutSrc, readoutSrc->analysis, stride, kernelError, covarFrac, maskVal, maskBad, maskPoor, poorFrac, badFrac)) {
 	    psError(psErrorCodeLast(), false, "Unable to convolve images.");
 	    goto escape;
@@ -361,5 +361,5 @@
 	}
 
-	if (!pmSubtractionMatch(NULL, readoutCnv, fake, readoutRaw, footprint, stride, regionSize, spacing, threshold, stampSources, stampsName, type, size, order, widthsCopy, orders, inner, ringsOrder, binning, penalty, optimum, optWidths, optOrder, optThresh, iter, rej, normFrac, sysError, skyErr, kernelError, covarFrac, maskVal, maskBad, maskPoor, poorFrac, badFrac, PM_SUBTRACTION_MODE_2)) {
+	if (!pmSubtractionMatch(NULL, readoutOut, fake, readoutSrc, footprint, stride, regionSize, spacing, threshold, stampSources, stampsName, type, size, order, widthsCopy, orders, inner, ringsOrder, binning, penalty, optimum, optWidths, optOrder, optThresh, iter, rej, normFrac, sysError, skyErr, kernelError, covarFrac, maskVal, maskBad, maskPoor, poorFrac, badFrac, PM_SUBTRACTION_MODE_2)) {
 	    psError(psErrorCodeLast(), false, "Unable to match images.");
 	    goto escape;
@@ -369,5 +369,5 @@
     // Reject image completely if the maximum deconvolution fraction exceeds the limit
     float deconvLimit = psMetadataLookupF32(NULL, stackRecipe, "DECONV.LIMIT"); // Limit on deconvolution fraction
-    float deconv = psMetadataLookupF32(NULL, readoutCnv->analysis, PM_SUBTRACTION_ANALYSIS_DECONV_MAX); // Max deconvolution fraction
+    float deconv = psMetadataLookupF32(NULL, readoutOut->analysis, PM_SUBTRACTION_ANALYSIS_DECONV_MAX); // Max deconvolution fraction
     if (deconv > deconvLimit) {
 	psWarning("Maximum deconvolution fraction (%f) exceeds limit (%f) --- rejecting image %d\n", deconv, deconvLimit, index);
@@ -375,6 +375,6 @@
     }
 
-    dumpImage(readoutCnv, readoutRaw, index, "conv");
-    dumpImageDiff(readoutCnv, fake, readoutRaw, index, "diff");
+    dumpImage(readoutOut, readoutSrc, index, "conv");
+    dumpImageDiff(readoutOut, fake, readoutSrc, index, "diff");
 
     psFree(fake);
@@ -542,5 +542,5 @@
 
 // generate a fake readout against which to PSF match
-pmReadout *makeFakeReadout(pmConfig *config, pmReadout *readoutRaw, psArray *sources, pmPSF *psf, psImageMaskType maskVal, int fullSize) {
+pmReadout *makeFakeReadout(pmConfig *config, pmReadout *readoutSrc, psArray *sources, pmPSF *psf, psImageMaskType maskVal, int fullSize) {
 
     pmReadout *fake = pmReadoutAlloc(NULL); // Fake readout with target PSF
@@ -548,5 +548,5 @@
     psStats *bg = psStatsAlloc(PS_STAT_ROBUST_STDEV); // Statistics for background
     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
-    if (!psImageBackground(bg, NULL, readoutRaw->image, readoutRaw->mask, maskVal, rng)) {
+    if (!psImageBackground(bg, NULL, readoutSrc->image, readoutSrc->mask, maskVal, rng)) {
 	psError(PSPHOT_ERR_DATA, false, "Can't measure background for image.");
 	psFree(fake);
@@ -560,5 +560,5 @@
 
     bool oldThreads = pmReadoutFakeThreads(true); // Old threading state
-    if (!pmReadoutFakeFromSources(fake, readoutRaw->image->numCols, readoutRaw->image->numRows, sources, SOURCE_MASK, NULL, NULL, psf, minFlux, fullSize, false, true)) {
+    if (!pmReadoutFakeFromSources(fake, readoutSrc->image->numCols, readoutSrc->image->numRows, sources, SOURCE_MASK, NULL, NULL, psf, minFlux, fullSize, false, true)) {
 	psError(PSPHOT_ERR_DATA, false, "Unable to generate fake image with target PSF.");
 	psFree(fake);
@@ -567,8 +567,8 @@
     pmReadoutFakeThreads(oldThreads);
 
-    fake->mask = psImageCopy(NULL, readoutRaw->mask, PS_TYPE_IMAGE_MASK);
+    fake->mask = psImageCopy(NULL, readoutSrc->mask, PS_TYPE_IMAGE_MASK);
 
     // Add the background into the target image
-    psImage *bgImage = stackBackgroundModel(readoutRaw, config); // Image of background
+    psImage *bgImage = stackBackgroundModel(readoutSrc, config); // Image of background
     psBinaryOp(fake->image, fake->image, "+", bgImage);
     psFree(bgImage);
Index: /branches/eam_branches/psphot.20100506/src/psphotStackOptions.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotStackOptions.c	(revision 27883)
+++ /branches/eam_branches/psphot.20100506/src/psphotStackOptions.c	(revision 27884)
@@ -29,26 +29,22 @@
     options->convolve = false;
     options->convolveSource = PSPHOT_CNV_SRC_NONE;
-
-    options->psfs = psArrayAlloc(num);
-
-    options->inputSeeing = psVectorAlloc(num, PS_TYPE_F32);
-    psVectorInit(options->inputSeeing, NAN);
-
-    options->matchChi2 = psVectorAlloc(num, PS_TYPE_F32);
-    psVectorInit(options->matchChi2, NAN);
-
-    options->inputMask = psVectorAlloc(num, PS_TYPE_VECTOR_MASK); // Mask for inputs
-    psVectorInit(options->inputMask, 0);
-
     options->targetSeeing = NAN;
 
+    options->psfs        = psArrayAlloc(num);
     options->sourceLists = psArrayAlloc(num); // Individual lists of sources for matching
-    options->norm = psVectorAlloc(num, PS_TYPE_F32);
-    psVectorInit(options->norm, NAN);
+    options->kernels     = psArrayAlloc(num); 
+    options->regions     = psArrayAlloc(num); 
 
-    options->kernels = NULL;
-    options->regions = NULL;
-    options->matchChi2 = NULL;
-    options->weightings = NULL;
+    options->inputMask   = psVectorAlloc(num, PS_TYPE_VECTOR_MASK); // Mask for inputs
+    options->inputSeeing = psVectorAlloc(num, PS_TYPE_F32);
+    options->norm        = psVectorAlloc(num, PS_TYPE_F32);
+    options->matchChi2   = psVectorAlloc(num, PS_TYPE_F32); // chi^2 for stamps when matching
+    options->weightings  = psVectorAlloc(num, PS_TYPE_F32); // Combination weightings for images (1/noise^2)
+
+    psVectorInit(options->inputMask,   0);
+    psVectorInit(options->inputSeeing, NAN);
+    psVectorInit(options->norm,        NAN);
+    psVectorInit(options->matchChi2,   NAN);
+    psVectorInit(options->weightings,  NAN);
 
     return options;
@@ -62,2 +58,34 @@
     return PSPHOT_CNV_SRC_NONE;
 }
+
+pmFPAfile *psphotStackGetConvolveSource (pmConfig *config, psphotStackOptions *options, int index) {
+
+    // which image do we want to convolve?  RAW, CNV, AUTO?
+    // find the currently selected readout
+    pmFPAfile *fileRaw = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", index); // File of interest
+    pmFPAfile *fileCnv = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.CNV", index); // File of interest
+
+    pmFPAfile *fileSrc = NULL;
+
+    switch (options->convolveSource) {
+      case PSPHOT_CNV_SRC_AUTO:
+	fileSrc = fileCnv ? fileCnv : fileRaw;
+	break;
+
+      case PSPHOT_CNV_SRC_RAW:
+	fileSrc = fileRaw;
+	break;
+
+      case PSPHOT_CNV_SRC_CNV:
+	fileSrc = fileCnv;
+	break;
+
+      default:
+	psAbort("impossible case");
+    }
+    if (!fileSrc) {
+	psError(PSPHOT_ERR_CONFIG, true, "desired convolution source is missing (cnv : %llx, raw : %llx)", (long long) fileCnv, (long long) fileRaw);
+    }
+    
+    return fileSrc;
+}
Index: /branches/eam_branches/psphot.20100506/src/psphotStackParseCamera.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotStackParseCamera.c	(revision 27883)
+++ /branches/eam_branches/psphot.20100506/src/psphotStackParseCamera.c	(revision 27884)
@@ -29,7 +29,7 @@
 
 	// RAW (unconvolved) input data (RAW:IMAGE, RAW:MASK, RAW:VARIANCE, RAW:PSF)
-	psString rawImage = psMetadataLookupStr(NULL, input, "RAW:IMAGE"); // Name of image
+	psString rawImage = psMetadataLookupStr(&status, input, "RAW:IMAGE"); // Name of image
 	if (rawImage && strlen(rawImage) > 0) {
-	    pmFPAfile *rawInputFile = defineFile(config, NULL, "PSPHOT.STACK.INPUT.RAW", rawImage, PM_FPA_FILE_IMAGE); // File for image
+	    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);
@@ -60,7 +60,7 @@
 
 	// CNV (convolved) input data (CNV:IMAGE, CNV:MASK, CNV:VARIANCE, CNV:PSF)
-	psString cnvImage = psMetadataLookupStr(NULL, input, "CNV:IMAGE"); // Name of image
+	psString cnvImage = psMetadataLookupStr(&status, input, "CNV:IMAGE"); // Name of image
 	if (cnvImage && strlen(cnvImage) > 0) {
-	    pmFPAfile *cnvInputFile = defineFile(config, NULL, "PSPHOT.STACK.INPUT.CNV", cnvImage, PM_FPA_FILE_IMAGE); // File for image
+	    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);
@@ -96,7 +96,7 @@
 
 	psString sources = psMetadataLookupStr(&status, input, "SOURCES"); // Name of mask
-	pmFPAfile *srcInputFile = rawInputFile ? rawInputFile : cnvInputFile;
+	// pmFPAfile *srcInputFile = rawInputFile ? rawInputFile : cnvInputFile;
 	if (sources && strlen(sources) > 0) {
-	    if (!defineFile(config, srcInputFile, "PSPHOT.STACK.SOURCES.CNV", sources, PM_FPA_FILE_CMF)) {
+	    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;
