Index: trunk/psphot/src/psphotReadout.c
===================================================================
--- trunk/psphot/src/psphotReadout.c	(revision 27657)
+++ trunk/psphot/src/psphotReadout.c	(revision 28013)
@@ -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");
 }
