Index: /branches/eam_branches/psModules.20211028/src/imcombine/pmStack.c
===================================================================
--- /branches/eam_branches/psModules.20211028/src/imcombine/pmStack.c	(revision 41872)
+++ /branches/eam_branches/psModules.20211028/src/imcombine/pmStack.c	(revision 41873)
@@ -1533,7 +1533,8 @@
 
 bool pmStackCombineByPercentile(
-    pmReadout *combined,
-    psArray *stackData,
-    psF64 rejectFraction,
+    pmReadout *combined,		// output stacked readout
+    pmReadout *expmaps,			// output exposure map information
+    psArray *stackData,			// input exposures
+    psF64 rejectFraction,               // outlier fraction of pixels to reject
     psF64 maxRange,
     psImageMaskType badMaskBits, 	// treat these bits as 'bad'
@@ -1562,7 +1563,17 @@
     pmReadoutUpdateSize(combined, minInputCols, minInputRows, xSize, ySize, true, true, blankMaskBits);
 
+    psImage *exp = NULL, *expnum = NULL, *expweight = NULL; // Exposure map and exposure number
+    if (expmaps) {
+        if (!expmaps->image) { exp = expmaps->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); }
+        if (!expmaps->mask) { expnum = expmaps->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); }
+        if (!expmaps->variance) { expweight = expmaps->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); }
+    }
+   
     psVector *pixelData      = psVectorAlloc(stackData->n, PS_TYPE_F32);
     psVector *pixelVariances = psVectorAlloc(stackData->n, PS_TYPE_F32);
     psVector *pixelMask      = psVectorAlloc(stackData->n, PS_TYPE_VECTOR_MASK);
+
+    psVector *expTime        = expmask ? psVectorAlloc(stackData->n, PS_TYPE_F32) : NULL;
+    psVector *expNum         = expmask ? psVectorAlloc(stackData->n, PS_TYPE_VECTOR_MASK): NULL;
 
     int nGoodBits[16]; // accumulate the good pixel bits here for fuzzy logic
@@ -1607,13 +1618,10 @@
 
 		pixelData->data.F32[nGood] = image->data.F32[yIn][xIn];
-		if (variance) {
-		  // pixelVariances->data.F32[numGood] = variance->data.F32[yIn][xIn] * addVariance->data.F32[i];
-		  pixelVariances->data.F32[nGood] = variance->data.F32[yIn][xIn];
-		}
+		if (variance) { pixelVariances->data.F32[nGood] = variance->data.F32[yIn][xIn]; }
+		if (expmask) { pixelVariances->data.F32[nGood] = variance->data.F32[yIn][xIn]; }
 
 		nGood ++;
 	    }
 	    pixelData->n = nGood;
-
 
 	    // rather than define a min and max value,
@@ -1638,4 +1646,9 @@
 		combined->variance->data.F32[y][x] = NAN;
 		combined->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = blankMaskBits; // probably not needed since it was set above.
+		if (expmaps) {
+		    expmaps->image->F32[y][x] = NAN;
+		    expmaps->variance->F32[y][x] = NAN;
+		    expmaps->mask->PS_TYPE_IMAGE_MASK_DATA[y][x] = 0;
+		}
 		continue;
 	    }
