Index: branches/pap/psModules/src/imcombine/pmReadoutCombine.c
===================================================================
--- branches/pap/psModules/src/imcombine/pmReadoutCombine.c	(revision 23948)
+++ branches/pap/psModules/src/imcombine/pmReadoutCombine.c	(revision 25027)
@@ -173,4 +173,6 @@
     for (int i = 0; i < inputs->n; i++) {
         pmReadout *readout = inputs->data[i]; // Readout of interest
+	psAssert(readout, "readout was not defined");
+	if (!readout->process) continue;
         if (!readout->image) {
             psError(PS_ERR_UNEXPECTED_NULL, true, "Image data is missing for image %d.\n", i);
@@ -271,4 +273,5 @@
         for (int r = 0; r < inputs->n; r++) {
             pmReadout *readout = inputs->data[r]; // Input readout
+            if (!readout->process) continue; 
             psTrace("psModules.imcombine", 3, "Iterating input %d: %d --> %d, %d --> %d\n", r,
                     minInputCols - readout->col0, maxInputCols - readout->col0,
@@ -277,4 +280,7 @@
     }
     #endif
+
+    // set up windows for visualization (if selected)
+    pmReadoutCombineVisualInit();
 
     // Dereference output products
@@ -308,4 +314,8 @@
             for (int r = 0; r < inputs->n; r++) {
                 pmReadout *readout = inputs->data[r]; // Input readout
+		if (!readout->process) {
+		    maskData[r] = 1;
+		    continue;
+		}
                 int yIn = i - readout->row0; // y position on input readout
                 int xIn = j - readout->col0; // x position on input readout
@@ -384,23 +394,31 @@
             // Combination
             if (!psVectorStats(stats, pixels, errors, mask, 1)) {
-                // Can't do much about it, but it's not worth worrying about
-                psErrorClear();
+		psError(PS_ERR_UNKNOWN, false, "error in pixel stats");
+		return false;
+	    }
+	    
+	    outputImage[yOut][xOut] = psStatsGetValue(stats, params->combine);
+
+	    if (!isfinite(outputImage[yOut][xOut])) {
+		pmReadoutCombineVisualPixels(pixels, mask, outputImage[yOut][xOut]);
+	    }
+
+	    if (isnan(outputImage[yOut][xOut])) {
                 outputImage[yOut][xOut] = NAN;
                 outputMask[yOut][xOut] = params->blank;
+                sigma->data.F32[yOut][xOut] = NAN;
                 if (params->variances) {
                     outputVariance[yOut][xOut] = NAN;
                 }
-                sigma->data.F32[yOut][xOut] = NAN;
-            } else {
-                outputImage[yOut][xOut] = psStatsGetValue(stats, params->combine);
-                outputMask[yOut][xOut] = isfinite(outputImage[yOut][xOut]) ? 0 : params->blank;
-                if (params->variances) {
-                    float stdev = psStatsGetValue(stats, combineStdev);
-                    outputVariance[yOut][xOut] = PS_SQR(stdev); // Variance
-                    // XXXX this is not the correct formal error.
-                    // also, the weighted mean is not obviously the correct thing here
-                }
-                sigma->data.F32[yOut][xOut] = psStatsGetValue(stats, combineStdev);
-            }
+		continue;
+	    }
+	    outputMask[yOut][xOut] = 0;
+	    sigma->data.F32[yOut][xOut] = psStatsGetValue(stats, combineStdev);
+	    if (params->variances) {
+		float stdev = psStatsGetValue(stats, combineStdev);
+		outputVariance[yOut][xOut] = PS_SQR(stdev); // Variance
+		// XXXX this is not the correct formal error.
+		// also, the weighted mean is not obviously the correct thing here
+	    }
         }
     }
@@ -423,2 +441,106 @@
 }
 
+#if (HAVE_KAPA)
+#include <kapa.h>
+#include "pmKapaPlots.h"
+#include "pmVisual.h"
+
+static int kapa = -1;
+static bool plotFlag = true;
+
+// this init function only gets the ordinates for the first readout...
+bool pmReadoutCombineVisualInit(void) {
+    
+    if (!pmVisualIsVisual()) return true;
+
+    // skip if we have already opened the windows (or if none are requested...)
+    if (kapa != -1) return true;
+
+    pmVisualInitWindow(&kapa, "ppmerge");
+    return true;
+}
+
+bool pmReadoutCombineVisualPixels(psVector *pixels, psVector *mask, float mean) {
+
+    Graphdata graphdata;
+    float xline[2], yline[2];
+    
+    if (!pmVisualIsVisual()) return true;
+
+    if (!plotFlag) return true;
+
+    KapaInitGraph(&graphdata);
+
+    psVector *xAll = psVectorAlloc(pixels->n, PS_TYPE_F32);
+    psVector *xSub = psVectorAlloc(pixels->n, PS_TYPE_F32);
+    psVector *ySub = psVectorAlloc(pixels->n, PS_TYPE_F32);
+
+    // generate vectors of the unmasked values
+    int nSub = 0;
+    for (int j = 0; j < pixels->n; j++) {
+	xAll->data.F32[j] = j;
+	if (mask && mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) continue;
+	xSub->data.F32[nSub] = j;
+	ySub->data.F32[nSub] = pixels->data.F32[j];
+	nSub ++;
+    }
+    xSub->n = ySub->n = nSub;
+    xAll->n = pixels->n;
+	
+    xline[0] = 0;
+    xline[1] = pixels->n;
+    yline[0] = mean;
+    yline[1] = mean;
+
+    // plot the unmasked values
+    pmVisualScaleGraphdata (&graphdata, xAll, pixels, false);
+    KapaSetGraphData(kapa, &graphdata);
+    KapaSetLimits(kapa, &graphdata);
+    KapaClearPlots (kapa);
+
+    KapaSetFont (kapa, "courier", 14);
+    KapaBox (kapa, &graphdata);
+    KapaSendLabel (kapa, "ordinate", KAPA_LABEL_XM);
+    KapaSendLabel (kapa, "pixel values", KAPA_LABEL_YM);
+
+    graphdata.color = KapaColorByName("black");
+    graphdata.style = 2;
+    graphdata.ptype = 2;
+    KapaPrepPlot  (kapa, xSub->n, &graphdata);
+    KapaPlotVector(kapa, xSub->n, xSub->data.F32, "x");
+    KapaPlotVector(kapa, xSub->n, ySub->data.F32, "y");
+
+    graphdata.color = KapaColorByName("red");
+    graphdata.style = 2;
+    graphdata.ptype = 7;
+    KapaPrepPlot  (kapa, xAll->n, &graphdata);
+    KapaPlotVector(kapa, xAll->n, xAll->data.F32, "x");
+    KapaPlotVector(kapa, xAll->n, pixels->data.F32, "y");
+
+    graphdata.color = KapaColorByName("blue");
+    graphdata.style = 0;
+    graphdata.ptype = 7;
+    KapaPrepPlot  (kapa, 2, &graphdata);
+    KapaPlotVector(kapa, 2, xline, "x");
+    KapaPlotVector(kapa, 2, yline, "y");
+
+    pmVisualAskUser (&plotFlag);
+    return true;
+}
+
+bool pmReadoutCombineVisualCleanup(void) {
+
+    if (!pmVisualIsVisual()) return true;
+    if (kapa == -1) return true;
+
+    KapaClose(kapa);
+    return true;
+}
+
+# else
+
+bool pmReadoutCombineVisualInit(void) { return true; }
+bool pmReadoutCombineVisualPixels(psVector *pixels, psVector *mask, float mean) { return true; }
+bool pmReadoutCombineVisualCleanup(void) { return true; }
+
+# endif
