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);
Index: /trunk/psModules/test/Makefile.am
===================================================================
--- /trunk/psModules/test/Makefile.am	(revision 2286)
+++ /trunk/psModules/test/Makefile.am	(revision 2287)
@@ -1,3 +1,3 @@
-bin_PROGRAMS = tst_pmFlatField tst_pmMaskBadPixels tst_pmNonLinear tst_pmSubtractBias
+bin_PROGRAMS = tst_pmFlatField tst_pmMaskBadPixels tst_pmNonLinear tst_pmSubtractBias tst_pmReadoutCombine
 
 tst_pmFlatField_SOURCES = tst_pmFlatField.c
@@ -13,2 +13,4 @@
 tst_pmSubtractBias_LDFLAGS = -L../src -lpsmodule
 
+tst_pmReadoutCombine_SOURCES = tst_pmReadoutCombine.c
+tst_pmReadoutCombine_LDFLAGS = -L../src -lpsmodule
Index: /trunk/psModules/test/Makefile.in
===================================================================
--- /trunk/psModules/test/Makefile.in	(revision 2286)
+++ /trunk/psModules/test/Makefile.in	(revision 2287)
@@ -94,5 +94,5 @@
 am__quote = @am__quote@
 install_sh = @install_sh@
-bin_PROGRAMS = tst_pmFlatField tst_pmMaskBadPixels tst_pmNonLinear tst_pmSubtractBias
+bin_PROGRAMS = tst_pmFlatField tst_pmMaskBadPixels tst_pmNonLinear tst_pmSubtractBias tst_pmReadoutCombine
 
 tst_pmFlatField_SOURCES = tst_pmFlatField.c
@@ -107,4 +107,7 @@
 tst_pmSubtractBias_SOURCES = tst_pmSubtractBias.c
 tst_pmSubtractBias_LDFLAGS = -L../src -lpsmodule
+
+tst_pmReadoutCombine_SOURCES = tst_pmReadoutCombine.c
+tst_pmReadoutCombine_LDFLAGS = -L../src -lpsmodule
 subdir = test
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
@@ -112,5 +115,6 @@
 CONFIG_CLEAN_FILES =
 bin_PROGRAMS = tst_pmFlatField$(EXEEXT) tst_pmMaskBadPixels$(EXEEXT) \
-	tst_pmNonLinear$(EXEEXT) tst_pmSubtractBias$(EXEEXT)
+	tst_pmNonLinear$(EXEEXT) tst_pmSubtractBias$(EXEEXT) \
+	tst_pmReadoutCombine$(EXEEXT)
 PROGRAMS = $(bin_PROGRAMS)
 
@@ -127,4 +131,8 @@
 tst_pmNonLinear_LDADD = $(LDADD)
 tst_pmNonLinear_DEPENDENCIES =
+am_tst_pmReadoutCombine_OBJECTS = tst_pmReadoutCombine.$(OBJEXT)
+tst_pmReadoutCombine_OBJECTS = $(am_tst_pmReadoutCombine_OBJECTS)
+tst_pmReadoutCombine_LDADD = $(LDADD)
+tst_pmReadoutCombine_DEPENDENCIES =
 am_tst_pmSubtractBias_OBJECTS = tst_pmSubtractBias.$(OBJEXT)
 tst_pmSubtractBias_OBJECTS = $(am_tst_pmSubtractBias_OBJECTS)
@@ -142,4 +150,5 @@
 @AMDEP_TRUE@	./$(DEPDIR)/tst_pmMaskBadPixels.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/tst_pmNonLinear.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/tst_pmReadoutCombine.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/tst_pmSubtractBias.Po
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
@@ -151,7 +160,8 @@
 	$(AM_LDFLAGS) $(LDFLAGS) -o $@
 DIST_SOURCES = $(tst_pmFlatField_SOURCES) $(tst_pmMaskBadPixels_SOURCES) \
-	$(tst_pmNonLinear_SOURCES) $(tst_pmSubtractBias_SOURCES)
+	$(tst_pmNonLinear_SOURCES) $(tst_pmReadoutCombine_SOURCES) \
+	$(tst_pmSubtractBias_SOURCES)
 DIST_COMMON = Makefile.am Makefile.in
-SOURCES = $(tst_pmFlatField_SOURCES) $(tst_pmMaskBadPixels_SOURCES) $(tst_pmNonLinear_SOURCES) $(tst_pmSubtractBias_SOURCES)
+SOURCES = $(tst_pmFlatField_SOURCES) $(tst_pmMaskBadPixels_SOURCES) $(tst_pmNonLinear_SOURCES) $(tst_pmReadoutCombine_SOURCES) $(tst_pmSubtractBias_SOURCES)
 
 all: all-am
@@ -202,4 +212,7 @@
 	@rm -f tst_pmNonLinear$(EXEEXT)
 	$(LINK) $(tst_pmNonLinear_LDFLAGS) $(tst_pmNonLinear_OBJECTS) $(tst_pmNonLinear_LDADD) $(LIBS)
+tst_pmReadoutCombine$(EXEEXT): $(tst_pmReadoutCombine_OBJECTS) $(tst_pmReadoutCombine_DEPENDENCIES) 
+	@rm -f tst_pmReadoutCombine$(EXEEXT)
+	$(LINK) $(tst_pmReadoutCombine_LDFLAGS) $(tst_pmReadoutCombine_OBJECTS) $(tst_pmReadoutCombine_LDADD) $(LIBS)
 tst_pmSubtractBias$(EXEEXT): $(tst_pmSubtractBias_OBJECTS) $(tst_pmSubtractBias_DEPENDENCIES) 
 	@rm -f tst_pmSubtractBias$(EXEEXT)
@@ -215,4 +228,5 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tst_pmMaskBadPixels.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tst_pmNonLinear.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tst_pmReadoutCombine.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tst_pmSubtractBias.Po@am__quote@
 
Index: /trunk/psModules/test/tst_pmReadoutCombine.c
===================================================================
--- /trunk/psModules/test/tst_pmReadoutCombine.c	(revision 2287)
+++ /trunk/psModules/test/tst_pmReadoutCombine.c	(revision 2287)
@@ -0,0 +1,143 @@
+/** @file tst_pmReadoutCombine.c
+ *
+ *  @brief This file contains the tests for pmReadoutCombine.c:
+ *
+ *  test00() This routine will test the basic functionality.
+ *
+ *  @author GLG, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-05 04:49:47 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#include "psTest.h"
+#include "pslib.h"
+#include "pmReadoutCombine.h"
+static int test00(void);
+testDescription tests[] = {
+                              {test00, 000, "pmSubtractBias", 0, false},
+                              {NULL}
+                          };
+
+#define OUTPUT_ROWS_BASE 8
+#define OUTPUT_COLS_BASE 16
+#define OUTPUT_ROWS_NUM  32
+#define OUTPUT_COLS_NUM  32
+#define NUM_READOUTS  10
+
+int main(int argc, char* argv[])
+{
+    return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv);
+}
+
+int doit()
+{
+    int i;
+    int j;
+    int r;
+    psList *list = NULL;
+    int baseRowsReadout[NUM_READOUTS];
+    int baseColsReadout[NUM_READOUTS];
+    int baseRows[NUM_READOUTS];
+    int baseCols[NUM_READOUTS];
+    int numRows[NUM_READOUTS];
+    int numCols[NUM_READOUTS];
+    int minOutRow = 10000;
+    int minOutCol = 10000;
+    int maxOutRow = -1;
+    int maxOutCol = -1;
+    psImage *output = NULL;
+    psCombineParams *params = (psCombineParams *) psAlloc(sizeof(psCombineParams));
+    psVector *zero = psVectorAlloc(NUM_READOUTS, PS_TYPE_F32);
+    psVector *scale = psVectorAlloc(NUM_READOUTS, PS_TYPE_F32);
+    for (i=0;i<NUM_READOUTS;i++) {
+        zero->data.F32[i] = 0.0;
+    }
+    for (i=0;i<NUM_READOUTS;i++) {
+        scale->data.F32[i] = 1.0;
+    }
+
+    params->stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
+    params->maskVal = 1;
+    params->fracLow = 0.0;
+    params->fracHigh = 10000.0;
+    params->nKeep = 0;
+
+    for (r=0;r<NUM_READOUTS;r++) {
+        baseRowsReadout[r] = r + 40;
+        baseColsReadout[r] = r + 42;
+        baseRows[r] = r;
+        baseCols[r] = r+2;
+        numRows[r] = 4 + (2 * r);
+        numCols[r] = 8 + (2 * r);
+
+        baseRowsReadout[r] = 0;
+        baseColsReadout[r] = 0;
+        baseRows[r] = 0;
+        baseCols[r] = 0;
+        numRows[r] = 10;
+        numCols[r] = 10;
+
+        psImage *tmpImage = psImageAlloc(numCols[r], numRows[r], PS_TYPE_F32);
+        for (i=0;i<numRows[r];i++) {
+            for (j=0;j<numCols[r];j++) {
+                tmpImage->data.F32[i][j] = (float) (i + j);
+                tmpImage->data.F32[i][j] = 1.0;
+            }
+        }
+
+        *(int *) (& (tmpImage->row0)) = baseRows[r];
+        *(int *) (& (tmpImage->col0)) = baseCols[r];
+        psReadout *tmpReadout = psReadoutAlloc(baseColsReadout[r],
+                                               baseRowsReadout[r],
+                                               tmpImage);
+        minOutRow = PS_MIN(minOutRow, (baseRowsReadout[r] + baseRows[r]));
+        minOutCol = PS_MIN(minOutCol, (baseColsReadout[r] + baseCols[r]));
+        maxOutRow = PS_MAX(maxOutRow, (baseRowsReadout[r] + baseRows[r] + numRows[r]));
+        maxOutCol = PS_MAX(maxOutCol, (baseColsReadout[r] + baseCols[r] + numCols[r]));
+
+        if (r == 0) {
+            list = psListAlloc(tmpReadout);
+        } else {
+            psListAdd(list, PS_LIST_HEAD, tmpReadout);
+        }
+    }
+    printf("tst_pmReadoutCombine(): (minOutRow, minOutCol) to (maxOutRow, maxOutCol) is (%d, %d) (%d, %d)\n",
+           minOutRow, minOutCol, maxOutRow, maxOutCol);
+
+    output = pmReadoutCombine(output, list, params, zero, scale, true, 1.0, 0.0);
+
+    for (i=output->row0; i < (output->row0 + output->numRows) ; i++) {
+        for (j=output->col0; j < (output->col0 + output->numCols) ; j++) {
+            printf("%.1f ", output->data.F32[i-output->row0][j-output->col0]);
+        }
+        printf("\n");
+    }
+
+    psFree(params->stats);
+    psFree(params);
+    psFree(output);
+    psFree(zero);
+    psFree(scale);
+
+    psListElem *tmpInput = (psListElem *) list->head;
+    while (NULL != tmpInput) {
+        psReadout *tmpReadout = (psReadout *) tmpInput->data;
+        psFree(tmpReadout);
+        tmpInput = tmpInput->next;
+    }
+    psFree(list);
+
+    return(0);
+}
+
+int test00( void )
+{
+    int testStatus = 0;
+
+    testStatus |= doit();
+
+    return(testStatus);
+}
Index: /trunk/psModules/test/tst_pmSubtractBias.c
===================================================================
--- /trunk/psModules/test/tst_pmSubtractBias.c	(revision 2286)
+++ /trunk/psModules/test/tst_pmSubtractBias.c	(revision 2287)
@@ -1,3 +1,3 @@
-/** @file tst_pmFlatField.c
+/** @file tst_pmSubtractBias.c
  *
  *  @brief Contains the tests for pmSubtractBias.c:
@@ -11,9 +11,8 @@
  *  row in the input image.
  *
- *
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-15 02:15:34 $
+ *  @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
