Index: trunk/psModules/src/imcombine/pmReadoutCombine.c
===================================================================
--- trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 7362)
+++ trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 7740)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-06 03:32:59 $
+ *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-29 00:27:51 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -126,6 +126,4 @@
     long minInputCols = LONG_MAX;       // The smallest input column value
     long minInputRows = LONG_MAX;       // The smallest input row value
-    psVector *mask   = psVectorAlloc(inputs->n, PS_TYPE_U8); // Mask for stack
-    mask->n = inputs->n;
 
     bool haveWeights = false;           // Do we have weight images?
@@ -245,15 +243,23 @@
 
     // We loop through each pixel in the output image.  We loop through each input readout.  We determine if
-    // that output pixel is contained in the image from that readout.  If so, we save it in psVector
-    // tmpPixels.  If not, we set a mask for that element in tmpPixels.  Then, we mask off pixels not between
-    // fracLow and fracHigh.  Then we call the vector stats routine on those pixels/mask.  Then we set the
-    // output pixel value to the result of the stats call.
+    // that output pixel is contained in the image from that readout.  If so, we save it in psVector pixels.
+    // If not, we set a mask for that element in pixels.  Then, we mask off pixels not between fracLow and
+    // fracHigh.  Then we call the vector stats routine on those pixels/mask.  Then we set the output pixel
+    // value to the result of the stats call.
 
     psVector *pixels = psVectorAlloc(inputs->n, PS_TYPE_F32); // Stack of pixels
     pixels->n = inputs->n;
+    psF32 *pixelsData = pixels->data.F32; // Dereference pixels
+
+    psVector *mask   = psVectorAlloc(inputs->n, PS_TYPE_U8); // Mask for stack
+    mask->n = inputs->n;
+    psU8 *maskData = mask->data.U8;     // Dereference mask
+
     psVector *weights = NULL;           // Stack of weights
+    psF32 *weightsData = NULL;          // Dereference weights
     if (haveWeights) {
         weights = psVectorAlloc(inputs->n, PS_TYPE_F32); // Stack of weights
         weights->n = inputs->n;
+        weightsData = weights->data.F32;
     }
     psVector *index = NULL;             // The indices to sort the pixels
@@ -274,6 +280,13 @@
     }
 
+    // Dereference output products
+    psF32 **outputImage  = output->image->data.F32; // Output image
+    psU8  **outputMask   = output->mask->data.U8; // Output mask
+    psF32 **outputWeight = output->weight->data.F32; // Output weight map
+
     for (int i = minInputRows; i < maxInputRows; i++) {
+        int yOut = i - output->row0; // y position on output readout
         #if 0
+
         if (psTraceGetLevel(__func__) > 9) {
             printf("Processing row %d\r", i);
@@ -282,6 +295,8 @@
         #endif
         for (int j = minInputCols; j < maxInputCols; j++) {
+            int xOut = j - output->col0; // x position on output readout
+
             int numValid = 0;           // Number of valid pixels in the stack
-            memset(mask->data.U8, 0, mask->n * sizeof(psU8)); // Reset the mask
+            memset(maskData, 0, mask->n * sizeof(psU8)); // Reset the mask
             for (int r = 0; r < inputs->n; r++) {
                 pmReadout *readout = inputs->data[r]; // Input readout
@@ -296,9 +311,10 @@
                 }
 
-                pixels->data.F32[r] = image->data.F32[yIn][xIn];
+                pixelsData[r] = image->data.F32[yIn][xIn];
 
                 // Check mask
-                if (readout->mask && readout->mask->data.U8[yIn][xIn] & maskVal) {
-                    mask->data.U8[r] = 1;
+                psImage *roMask = readout->mask; // The mask image
+                if (roMask && roMask->data.U8[yIn][xIn] & maskVal) {
+                    maskData[r] = 1;
                     continue;
                 }
@@ -307,10 +323,7 @@
             }
 
-            int yOut = i - output->row0; // y position on output readout
-            int xOut = j - output->col0; // x position on output readout
-
             if (numValid == 0) {
-                output->mask->data.U8[yOut][xOut] = PM_MASK_FLAT;
-                output->image->data.F32[yOut][xOut] = NAN;
+                outputMask[yOut][xOut] = PM_MASK_FLAT;
+                outputImage[yOut][xOut] = NAN;
                 continue;
             }
@@ -322,8 +335,9 @@
                 int numHigh = numValid * params->fracHigh; // Number of high pixels to clip
                 // Low pixels
+                psS32 *indexData = index->data.S32; // Dereference index
                 for (int k = 0, numMasked = 0; numMasked < numLow && k < index->n; k++) {
                     // Don't count the ones that are already masked
-                    if (!mask->data.U8[index->data.S32[k]]) {
-                        mask->data.U8[index->data.S32[k]] = 1;
+                    if (!maskData[indexData[k]]) {
+                        maskData[indexData[k]] = 1;
                         numMasked++;
                     }
@@ -332,6 +346,6 @@
                 for (int k = pixels->n - 1, numMasked = 0; numMasked < numHigh && k >= 0; k--) {
                     // Don't count the ones that are already masked
-                    if (! mask->data.U8[index->data.S32[k]]) {
-                        mask->data.U8[index->data.S32[k]] = 1;
+                    if (! maskData[indexData[k]]) {
+                        maskData[indexData[k]] = 1;
                         numMasked++;
                     }
@@ -341,8 +355,8 @@
             // Combination
             psVectorStats(stats, pixels, weights, mask, 1);
-            output->image->data.F32[yOut][xOut] = getStat(stats, params->combine);
+            outputImage[yOut][xOut] = getStat(stats, params->combine);
             if (haveWeights) {
                 float stdev = getStat(stats, combineStdev);
-                output->weight->data.F32[yOut][xOut] = PS_SQR(stdev); // Variance
+                outputWeight[yOut][xOut] = PS_SQR(stdev); // Variance
             }
         }
