Index: /trunk/psModules/src/pmReadoutCombine.c
===================================================================
--- /trunk/psModules/src/pmReadoutCombine.c	(revision 2831)
+++ /trunk/psModules/src/pmReadoutCombine.c	(revision 2832)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-27 20:14:29 $
+ *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-27 23:16:51 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -20,8 +20,6 @@
 p_psDetermineNumBits(data): This routine takes an enum psStatsOptions as an
 argument and returns the number of non-zero bits.
- 
-XXX: Use static vectors.
  *****************************************************************************/
-psStatsOptions p_psDetermineNumBits(psStatsOptions data)
+psStatsOptions DetermineNumBits(psStatsOptions data)
 {
     psS32 i;
@@ -38,4 +36,10 @@
 }
 
+/******************************************************************************
+p_psDetermineNumBits(data): This routine takes an enum psStatsOptions as an
+argument and returns the number of non-zero bits.
+ 
+XXX: Must add support for S16 and S32 types.  F32 currently supported.
+ *****************************************************************************/
 psImage *pmReadoutCombine(psImage *output,
                           const psList *inputs,
@@ -52,11 +56,12 @@
     if (zero != NULL) {
         PS_VECTOR_CHECK_TYPE(zero, PS_TYPE_F32, NULL);
+        //        PS_VECTOR_CHECK_TYPE_S16_S32_F32(zero, NULL);
     }
     if (scale != NULL) {
         PS_VECTOR_CHECK_TYPE(scale, PS_TYPE_F32, NULL);
+        //        PS_VECTOR_CHECK_TYPE_S16_S32_F32(scale, NULL);
     }
     if ((zero != NULL) && (scale != NULL)) {
         PS_VECTOR_CHECK_TYPE_EQUAL(zero, scale, NULL);
-        // XXX: Currently only type F32 is implemented.
         // PS_VECTOR_CHECK_TYPE_S16_S32_F32(scale, NULL);
     }
@@ -75,5 +80,5 @@
     psElemType outputType = PS_TYPE_F32;
 
-    if (1 < p_psDetermineNumBits(params->stats->options)) {
+    if (1 < DetermineNumBits(params->stats->options)) {
         psError(PS_ERR_UNKNOWN, true,
                 "Multiple statistical options have been requested.\n");
@@ -92,5 +97,5 @@
     //     output->row0 + output->numRows
     // to determine if the output image actually stores that pixel.  A similar
-    // thing is done for the minimul row and column.
+    // thing is done for the minimum row and column.
     //
     tmpInput = (psListElem *) inputs->head;
@@ -120,5 +125,4 @@
 
     // We ensure that the zero vector is of the proper size.
-
     if (zero != NULL) {
         PS_VECTOR_CHECK_TYPE(zero, PS_TYPE_F32, NULL);
@@ -166,5 +170,6 @@
 
         if ((output->col0 > minInputCols) || (output->row0 > minInputRows)) {
-            //XXX ERROR "Output image offset is larger then input image offset.\n");
+            psError(PS_ERR_UNKNOWN, true,
+                    "Output image offset is larger then input image offset.\n");
             return(NULL);
         }
@@ -172,4 +177,5 @@
 
     psVector *tmpPixels = psVectorAlloc(numInputs, PS_TYPE_F32);
+    psVector *tmpPixelErrors = psVectorAlloc(numInputs, PS_TYPE_F32);
     psVector *tmpPixelMask = psVectorAlloc(numInputs, PS_TYPE_U8);
     psVector *tmpPixelMaskNKeep = psVectorAlloc(numInputs, PS_TYPE_U8);
@@ -266,8 +272,5 @@
             }
 
-            // XXX: Still waiting on clarification of the algorithm.
-            #define SOME_FUNC(X, SIGMA) ((X))
-            if ((gain > 0.0) && (readnoise >= 0.0))
-            {
+            if ((gain > 0.0) && (readnoise >= 0.0)) {
                 psF32 x;
                 psF32 sigma;
@@ -286,5 +289,6 @@
                         sigma = PS_SQRT_F32((readnoise*readnoise) + gain * x) / gain;
 
-                        tmpPixels->data.F32[r]= SOME_FUNC(x, sigma);
+                        tmpPixelErrors->data.F32[r] = sigma;
+                        tmpPixels->data.F32[r]= x;
                     }
                 } else {
@@ -304,7 +308,14 @@
                         sigma = PS_SQRT_F32((readnoise*readnoise) + (gain * sigma)) / gain;
 
-                        tmpPixels->data.F32[r]= SOME_FUNC(x, sigma);
-                    }
-                }
+                        tmpPixelErrors->data.F32[r] = sigma;
+                        tmpPixels->data.F32[r]= x;
+                    }
+                }
+                // Calculate the specified statistic on the stack of pixels.
+                stats = psVectorStats(stats,
+                                      tmpPixels,
+                                      tmpPixelErrors,
+                                      tmpPixelMaskNKeep,
+                                      1);
             } else {
                 if (scale != NULL) {
@@ -320,17 +331,18 @@
                     }
                 }
-            }
-
-            // Calculate the specified statistic on the stack of pixels.
-            stats = psVectorStats(stats,
-                                  tmpPixels,
-                                  NULL,
-                                  tmpPixelMaskNKeep,
-                                  1);
+
+                // Calculate the specified statistic on the stack of pixels.
+                stats = psVectorStats(stats,
+                                      tmpPixels,
+                                      NULL,
+                                      tmpPixelMaskNKeep,
+                                      1);
+            }
+
 
             // Set the pixel value in the output image to the stat value.
             double statValue;
             if (!p_psGetStatValue(stats, &statValue)) {
-                //XXX ERROR: "Could not determine stats value.\n"
+                psError(PS_ERR_UNKNOWN, true, "Could not determine stats value.\n");
                 return(NULL);
             } else {
@@ -341,4 +353,5 @@
 
     psFree(tmpPixels);
+    psFree(tmpPixelErrors);
     psFree(tmpPixelMask);
     psFree(tmpPixelMaskNKeep);
Index: /trunk/psModules/test/tst_pmReadoutCombine.c
===================================================================
--- /trunk/psModules/test/tst_pmReadoutCombine.c	(revision 2831)
+++ /trunk/psModules/test/tst_pmReadoutCombine.c	(revision 2832)
@@ -5,8 +5,17 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-27 20:14:29 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-27 23:16:51 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ *
+ *  XXX: Untested:
+ * S16, S32 types
+ * Multiple input readouts with varying sizes and offsets.
+ * params->fracLow and params->fracHigh
+ * params->nKeep
+ * (gain > 0.0) && (readnoise >= 0.0) (applyZeroScale == true)
+ * (gain > 0.0) && (readnoise >= 0.0) (applyZeroScale == false)
+ *
  */
 
@@ -23,6 +32,6 @@
 
 #define NUM_READOUTS  10
-#define INPUT_NUM_ROWS 10
-#define INPUT_NUM_COLS 10
+#define INPUT_NUM_ROWS 20
+#define INPUT_NUM_COLS 20
 #define VEC_ZERO 1.0
 #define VEC_SCALE 2.0
@@ -50,5 +59,10 @@
 }
 
-int doit()
+/******************************************************************************
+simpleCombineNoOverlap(): this routine creates a list of NUM_READOUTS input
+readouts and calls pmReadoutCombine().
+ *****************************************************************************/
+
+int simpleCombineNoOverlap(psS32 numInputCols, psS32 numInputRows)
 {
     int i;
@@ -94,6 +108,6 @@
         baseRows[r] = 0;
         baseCols[r] = 0;
-        numRows[r] = INPUT_NUM_ROWS;
-        numCols[r] = INPUT_NUM_COLS;
+        numRows[r] = numInputRows;
+        numCols[r] = numInputCols;
 
         psImage *tmpImage = psImageAlloc(numCols[r], numRows[r], PS_TYPE_F32);
@@ -146,5 +160,8 @@
     int testStatus = 0;
 
-    testStatus |= doit();
+    testStatus |= simpleCombineNoOverlap(1, 1);
+    testStatus |= simpleCombineNoOverlap(INPUT_NUM_COLS, 1);
+    testStatus |= simpleCombineNoOverlap(1, INPUT_NUM_ROWS);
+    testStatus |= simpleCombineNoOverlap(INPUT_NUM_COLS, INPUT_NUM_ROWS);
 
     return(testStatus);
@@ -345,4 +362,17 @@
 
     printf("----------------------------------------------------------------------------\n");
+    printf("Calling pmReadoutCombine() row0/col0 too large.  Should generate error, return NULL.\n");
+    output = psImageAlloc(1, 1, PS_TYPE_F32);
+    *(psS32*)&output->row0 = 10000;
+    *(psS32*)&output->col0 = 10000;
+    rc = pmReadoutCombine(output, list, params, zero, scale, true, 0.0, 0.0);
+    if (rc != NULL) {
+        printf("ERROR: pmReadoutCombine() did not return NULL\n");
+        testStatus = false;
+    }
+    psFree(output);
+    output = NULL;
+
+    printf("----------------------------------------------------------------------------\n");
     printf("Calling pmReadoutCombine() with NULL input list.  Should generate error, return NULL.\n");
     rc = pmReadoutCombine(output, NULL, params, zero, scale, true, 0.0, 0.0);
