Index: trunk/psModules/src/pmReadoutCombine.c
===================================================================
--- trunk/psModules/src/pmReadoutCombine.c	(revision 2829)
+++ 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);
