Index: trunk/psModules/src/pmReadoutCombine.c
===================================================================
--- trunk/psModules/src/pmReadoutCombine.c	(revision 2277)
+++ trunk/psModules/src/pmReadoutCombine.c	(revision 2282)
@@ -1,3 +1,3 @@
-p/** @file  pmReadoutCombine.c
+/** @file  pmReadoutCombine.c
  *
  *  This file will contain a module which will combine multiple readout images.
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-04 19:22:07 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-04 20:52:17 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -43,5 +43,5 @@
 }
 
-
+#define MAX_INT 10000
 psImage *pmReadoutCombine(psImage *output,
                           const psList *inputs,
@@ -55,5 +55,5 @@
     PS_PTR_CHECK_NULL(inputs, NULL);
     PS_PTR_CHECK_NULL(params, NULL);
-    unsigned int maskVal = params->maskVal;
+    //    unsigned int maskVal = params->maskVal;
     psStats *stats = params->stats;
     int i;
@@ -61,9 +61,12 @@
     int numInputCols = -1;
     int numInputRows = -1;
-    int minInputCols = HUGE;
-    int minInputRowss = HUGE;
+    int maxInputCols = 0;
+    int maxInputRows = 0;
+    int minInputCols = MAX_INT;
+    int minInputRows = MAX_INT;
     psListElem *tmpInput = NULL;
     int numInputs = 0;
     psReadout *tmpReadout;
+    float tmpF;
 
     //
@@ -90,5 +93,4 @@
                               (tmpReadout->row0 + tmpReadout->image->row0));
         tmpF = tmpReadout->col0 +
-               tmpReadout->numCols +
                tmpReadout->image->col0 +
                tmpReadout->image->numCols;
@@ -98,5 +100,4 @@
                               (tmpReadout->col0 + tmpReadout->image->col0));
         tmpF = tmpReadout->row0 +
-               tmpReadout->numRows +
                tmpReadout->image->row0 +
                tmpReadout->image->numRows;
@@ -109,12 +110,12 @@
         output = psImageAlloc(numInputCols-minInputCols,
                               numInputRows-minInputRows, PS_TYPE_F32);
-        output->col0 = minInputCols;
-        output->row0 = minInputRows;
+        *(int *) &(output->col0) = minInputCols;
+        *(int *) &(output->row0) = minInputRows;
     } else {
         if (((output->col0 + output->numCols) < maxInputCols) ||
                 ((output->row0 + output->numRows) < maxInputRows)) {
-            psError(__func__, "Output image (%d, %d) is too small to hold combined images.\n",
-                    output->row0 + output->numRows,
-                    output->col0 + output->numCols);
+            //XXX            psError(__func__, "Output image (%d, %d) is too small to hold combined images.\n",
+            //                    output->row0 + output->numRows,
+            //                    output->col0 + output->numCols);
             return(NULL);
         }
@@ -122,5 +123,5 @@
         if ((output->col0 > minInputCols) ||
                 (output->row0 > minInputRows)) {
-            psError(__func__, "Output image offset is larger then input image offset.\n");
+            //XXX            psError(__func__, "Output image offset is larger then input image offset.\n");
             return(NULL);
         }
@@ -128,5 +129,5 @@
 
     if (1 < p_psDetermineNumBits(params->stats->options)) {
-        psError(PS_ERR_UNKNOWN,true, "Multiple statistical options have been requested.\n");
+        //XXX        psError(PS_ERR_UNKNOWN,true, "Multiple statistical options have been requested.\n");
         return(NULL);
     }
@@ -145,69 +146,65 @@
     for (i = 0; i < output->numRows ; i++) {
         for (j = 0; j < output->numCols ; j++) {
-
-            // XXX: put code in here to figure out for each readout if it has
-            a pixel that corresponds to this output pixel.
-
             for (int r = 0; r < numInputs ; r++) {
-                if (i,j are valid for this readout) {
-                        if (0) {
-                            tmpPixels->data.F32[r] = WHATEVER;
-                            tmpPixelMask->data.U8[r] = 0;
-                        } else {
-                            tmpPixels->data.F32[r] = 0.0;
-                            tmpPixelMask->data.U8[r] = 1;
-                        }
+                //                if (i,j are valid for this readout) {
+                if (0) {
+                    //                     tmpPixels->data.F32[r] = WHATEVER;
+                    tmpPixelMask->data.U8[r] = 0;
+                } else {
+                    tmpPixels->data.F32[r] = 0.0;
+                    tmpPixelMask->data.U8[r] = 1;
+                }
+            }
+
+            // Determine how many pixels lie between fracLow and fracHigh.
+            int pixelCount = 0;
+            for (int r = 0; r < numInputs ; r++) {
+                if (tmpPixelMask->data.U8[r] == 0) {
+                    if ((params->fracLow <= tmpPixels->data.F32[r]) &&
+                            (params->fracHigh >= tmpPixels->data.F32[r])) {
+                        pixelCount++;
                     }
-
-                // Determine how many pixels lie between fracLow and fracHigh.
-                int pixelCount = 0;
+                }
+            }
+
+            // If more than params->nKeep pixels lie between the valid range,
+            // then loop through the pixels, and mask away any pixels outside
+            // that range.
+            if (pixelCount >= params->nKeep) {
                 for (int r = 0; r < numInputs ; r++) {
                     if (tmpPixelMask->data.U8[r] == 0) {
                         if ((params->fracLow <= tmpPixels->data.F32[r]) &&
                                 (params->fracHigh >= tmpPixels->data.F32[r])) {
-                            pixelCount++;
+                            tmpPixelMaskNKeep->data.U8[r] = 0;
+                        } else {
+                            tmpPixelMaskNKeep->data.U8[r] = 1;
                         }
                     }
                 }
-
-                // If more than params->nKeep pixels lie between the valid range,
-                // then loop through the pixels, and mask away any pixels outside
-                // that range.
-                if (pixelCount >= params->nKeep) {
-                    for (int r = 0; r < numInputs ; r++) {
-                        if (tmpPixelMask->data.U8[r] == 0) {
-                            if ((params->fracLow <= tmpPixels->data.F32[r]) &&
-                                    (params->fracHigh >= tmpPixels->data.F32[r])) {
-                                tmpPixelMaskNKeep->data.U8[r] = 0;
-                            } else {
-                                tmpPixelMaskNKeep->data.U8[r] = 1;
-                            }
-                        }
-                    }
-                }
-
-                // Calculate the specified statistic on the stack of pixels.
-                stats = psVectorStats(stats,
-                                      tmpPixels,
-                                      tmpPixelMaskNKeep,
-                                      1);
-
-                // Set the pixel value in the output image to the stat value.
-                double statValue;
-                if (!p_psGetStatValue(stats, &statValue)) {
-                    psError(PS_ERR_UNKNOWN,true, "Could not determine stats value.\n");
-                    return(NULL);
-                } else {
-                    output->data.F32[i][j] = (float) statValue;
-                }
-            }
-        }
-
-        psFree(tmpPixels);
-        psFree(tmpPixels);
-        psFree(tmpPixelMask);
-        psFree(tmpPixelMaskNKeep);
-        psFree(tmpReadouts);
-
-        return(output);
-    }
+            }
+
+            // Calculate the specified statistic on the stack of pixels.
+            stats = psVectorStats(stats,
+                                  tmpPixels,
+                                  tmpPixelMaskNKeep,
+                                  1);
+
+            // Set the pixel value in the output image to the stat value.
+            double statValue;
+            if (!p_psGetStatValue(stats, &statValue)) {
+                psError(PS_ERR_UNKNOWN,true, "Could not determine stats value.\n");
+                return(NULL);
+            } else {
+                output->data.F32[i][j] = (float) statValue;
+            }
+        }
+    }
+
+    psFree(tmpPixels);
+    psFree(tmpPixels);
+    psFree(tmpPixelMask);
+    psFree(tmpPixelMaskNKeep);
+    psFree(tmpReadouts);
+
+    return(output);
+}
