Index: trunk/psModules/src/pmReadoutCombine.c
===================================================================
--- trunk/psModules/src/pmReadoutCombine.c	(revision 2286)
+++ trunk/psModules/src/pmReadoutCombine.c	(revision 2287)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-05 02:45:42 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-05 04:49:47 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -65,5 +65,5 @@
     psListElem *tmpInput = NULL;
     int numInputs = 0;
-    psReadout *tmpReadout;
+    psReadout *tmpReadout = NULL;
     float tmpF;
 
@@ -135,6 +135,6 @@
     //
     if (output == NULL) {
-        output = psImageAlloc(1+maxInputCols-minInputCols,
-                              1+maxInputRows-minInputRows, PS_TYPE_F32);
+        output = psImageAlloc(maxInputCols-minInputCols,
+                              maxInputRows-minInputRows, PS_TYPE_F32);
         *(int *) &(output->col0) = minInputCols;
         *(int *) &(output->row0) = minInputRows;
@@ -168,5 +168,4 @@
     psReadout **tmpReadouts = (psReadout **) psAlloc(numInputs * sizeof(psReadout *));
 
-
     // For each input readout, we create a pointer to that readout in
     // "tmpReadouts[]", and we store the min/max pixel indices for that
@@ -174,8 +173,9 @@
     // (outRowLower, outColLower, outRowUpper, outColUpper).
     i = 0;
+    tmpInput = (psListElem *) inputs->head;
     while (NULL != tmpInput) {
         tmpReadouts[i] = (psReadout *) tmpInput->data;
-        outRowLower->data.U32[i] = tmpReadouts[i]->row0 + tmpReadout->image->row0;
-        outColLower->data.U32[i] = tmpReadouts[i]->col0 + tmpReadout->image->col0;
+        outRowLower->data.U32[i] = tmpReadouts[i]->row0 + tmpReadouts[i]->image->row0;
+        outColLower->data.U32[i] = tmpReadouts[i]->col0 + tmpReadouts[i]->image->col0;
         outRowUpper->data.U32[i] = tmpReadouts[i]->row0 +
                                    tmpReadouts[i]->image->row0 +
@@ -185,7 +185,9 @@
                                    tmpReadouts[i]->image->numCols;
 
+        //        printf("Bounds: [%d][%d] to [%d][%d]\n", outRowLower->data.U32[i], outColLower->data.U32[i], outRowUpper->data.U32[i], outColUpper->data.U32[i]);
+
+
         tmpInput = tmpInput->next;
         i++;
-
     }
 
@@ -197,7 +199,9 @@
     // stats routine on those pixels/mask.  Then we set the output pixel value
     // to the result of the stats call.
-    for (i = output->row0; i < output->numRows ; i++) {
-        for (j = output->col0; j < output->numCols ; j++) {
+
+    for (i = output->row0; i < (output->row0 + output->numRows) ; i++) {
+        for (j = output->col0; j < (output->col0 + output->numCols) ; j++) {
             for (int r = 0; r < numInputs ; r++) {
+                //                printf("[%d][%d]: [%d][%d] to [%d][%d]\n", i, j, outRowLower->data.U32[r], outColLower->data.U32[r], outRowUpper->data.U32[r], outColUpper->data.U32[r]);
                 if ((outRowLower->data.U32[r] <= i) &&
                         (outColLower->data.U32[r] <= j) &&
@@ -206,9 +210,11 @@
 
                     int imageRow = i - (tmpReadouts[r]->row0 +
-                                        tmpReadouts[i]->image->row0);
+                                        tmpReadouts[r]->image->row0);
                     int imageCol = j - (tmpReadouts[r]->col0 +
                                         tmpReadouts[r]->image->col0);
-                    if (!(maskVal && tmpReadouts[i]->mask->data.U8[imageRow][imageCol])) {
-                        tmpPixels->data.F32[r] = tmpReadouts[i]->image->data.F32[imageRow][imageCol];
+
+                    if ((NULL == tmpReadouts[r]->mask) ||
+                            !(maskVal && tmpReadouts[r]->mask->data.U8[imageRow][imageCol])) {
+                        tmpPixels->data.F32[r] = tmpReadouts[r]->image->data.F32[imageRow][imageCol];
                         tmpPixelMask->data.U8[r] = 0;
                     } else {
@@ -220,4 +226,5 @@
                     tmpPixelMask->data.U8[r] = 1;
                 }
+                //                printf("readout[%d], image [%d][%d] is %f\n", r, i, j, tmpPixels->data.F32[r]);
             }
             // At this point, we have scanned all input readouts for this
@@ -299,5 +306,4 @@
 
     psFree(tmpPixels);
-    psFree(tmpPixels);
     psFree(tmpPixelMask);
     psFree(tmpPixelMaskNKeep);
