Index: trunk/psModules/src/pmSubtractBias.c
===================================================================
--- trunk/psModules/src/pmSubtractBias.c	(revision 2141)
+++ trunk/psModules/src/pmSubtractBias.c	(revision 2147)
@@ -6,6 +6,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-15 01:11:16 $
+ *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-15 02:15:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -200,5 +200,5 @@
                           pmOverscanAxis overScanAxis,
                           psStats *stat,
-                          int nBin,
+                          int nBinOrig,
                           pmFit fit,
                           const psReadout *bias)
@@ -217,4 +217,5 @@
     psPolynomial1D *myPoly;
     psSpline1D *mySpline;
+    int nBin;
 
     PS_CHECK_NULL_PTR_RETURN_NULL(in);
@@ -265,25 +266,23 @@
     }
 
-    // XXX: Is there a better way to extract a psVector from a psImage without
-    // having to copy every element in that vector?
-
-    // XXX: If we get here, do we know that overScanAxis == PM_OVERSCAN_ROWS
-    // or PM_OVERSCAN_COL?
-
-    // XXX: How to use multiple overscans?  Currently, only the first is used.
-
-    if ((overScanAxis == PM_OVERSCAN_ROWS) || (overScanAxis == PM_OVERSCAN_COLUMNS)) {
-        myOverscanImage = (psImage *) ((overscans->head)->data);
-
-        if (overScanAxis == PM_OVERSCAN_ROWS) {
-            // We create a row vector and subtract this vector from image.
-            overscanVector = psVectorAlloc(myOverscanImage->numCols, PS_TYPE_F32);
-            for (i=0;i<overscanVector->n;i++) {
-                overscanVector->data.F32[i] = 0.0;
-            }
-            tmpRow = psVectorAlloc((in->image)->numRows, PS_TYPE_F32);
-
-            tmpOverscan = (psListElem *) overscans->head;
-            while (tmpOverscan) {
+
+    tmpOverscan = (psListElem *) overscans->head;
+    while (NULL != tmpOverscan) {
+        myOverscanImage = (psImage *) tmpOverscan->data;
+
+        // XXX: Is there a better way to extract a psVector from a psImage without
+        // having to copy every element in that vector?
+        // XXX: If we get here, do we know that overScanAxis == PM_OVERSCAN_ROWS
+        // or PM_OVERSCAN_COL?
+
+        if ((overScanAxis == PM_OVERSCAN_ROWS) || (overScanAxis == PM_OVERSCAN_COLUMNS)) {
+            if (overScanAxis == PM_OVERSCAN_ROWS) {
+                // We create a row vector and subtract this vector from image.
+                overscanVector = psVectorAlloc(myOverscanImage->numCols, PS_TYPE_F32);
+                for (i=0;i<overscanVector->n;i++) {
+                    overscanVector->data.F32[i] = 0.0;
+                }
+                tmpRow = psVectorAlloc((in->image)->numRows, PS_TYPE_F32);
+
                 for (i=0;i<myOverscanImage->numCols;i++) {
                     for (j=0;j<myOverscanImage->numRows;j++) {
@@ -294,25 +293,20 @@
                     overscanVector->data.F32[i] = statValue;
                 }
-                // tmpOverscan = tmpOverscan->next;
-                tmpOverscan = NULL;
-            }
-            psFree(tmpRow);
-            if ((fit == PM_FIT_POLYNOMIAL) ||
-                    (fit == PM_FIT_SPLINE)) {
-                psVector *newVec = ScaleOverscanVector(overscanVector, (in->image)->numCols, fitSpec, fit);
-                psFree(overscanVector);
-                overscanVector = newVec;
-            }
-        }
-        if (overScanAxis == PM_OVERSCAN_COLUMNS) {
-            // We create a column vector and subtract this vector from image.
-            overscanVector = psVectorAlloc(myOverscanImage->numRows, PS_TYPE_F32);
-            for (i=0;i<overscanVector->n;i++) {
-                overscanVector->data.F32[i] = 0.0;
-            }
-            tmpCol = psVectorAlloc((in->image)->numCols, PS_TYPE_F32);
-
-            tmpOverscan = (psListElem *) overscans->head;
-            while (tmpOverscan) {
+                psFree(tmpRow);
+                if ((fit == PM_FIT_POLYNOMIAL) || (fit == PM_FIT_SPLINE)) {
+                    psVector *newVec = ScaleOverscanVector(overscanVector, (in->image)->numCols, fitSpec, fit);
+                    psFree(overscanVector);
+                    overscanVector = newVec;
+                }
+            }
+
+            if (overScanAxis == PM_OVERSCAN_COLUMNS) {
+                // We create a column vector and subtract this vector from image.
+                overscanVector = psVectorAlloc(myOverscanImage->numRows, PS_TYPE_F32);
+                for (i=0;i<overscanVector->n;i++) {
+                    overscanVector->data.F32[i] = 0.0;
+                }
+                tmpCol = psVectorAlloc((in->image)->numCols, PS_TYPE_F32);
+
                 for (i=0;i<myOverscanImage->numRows;i++) {
                     for (j=0;j<myOverscanImage->numCols;j++) {
@@ -323,99 +317,96 @@
                     overscanVector->data.F32[i] = statValue;
                 }
-                // tmpOverscan = tmpOverscan->next;
-                tmpOverscan = NULL;
-            }
-            psFree(tmpCol);
-            if ((fit == PM_FIT_POLYNOMIAL) ||
-                    (fit == PM_FIT_SPLINE)) {
-                psVector *newVec = ScaleOverscanVector(overscanVector, (in->image)->numRows, fitSpec, fit);
-                psFree(overscanVector);
-                overscanVector = newVec;
-            }
-        }
-
-        //
-        // Re-bin the overscan vector (change its length).
-        //
-        if ((nBin > 0) && (nBin < overscanVector->n)) {
-            numBins = 1+((overscanVector->n)/nBin);
-            myBin = psVectorAlloc(numBins, PS_TYPE_F32);
-            binVec = psVectorAlloc(nBin, PS_TYPE_F32);
-
-            for (i=0;i<numBins;i++) {
-                for(j=0;j<nBin;j++) {
-                    if (overscanVector->n > ((i*nBin)+j)) {
-                        binVec->data.F32[j] = overscanVector->data.F32[(i*nBin)+j];
-                    } else {
-                        // XXX: we get here if nBin does not evenly divide
-                        // the overscanVector vector.  This is the last bin.  Should
-                        // we change the binVec->n to acknowledge that?
-                        binVec->n = j;
-                    }
-                }
-                stat = psVectorStats(stat, binVec, NULL, 0);
-                p_psGetStatValue(stat, &statValue);
-                myBin->data.F32[i] = statValue;
-
-            }
-
-            // Change the effective size of overscanVector.
-            overscanVector->n = numBins;
-            for (i=0;i<numBins;i++) {
-                overscanVector->data.F32[i] = myBin->data.F32[i];
-            }
-            psFree(binVec);
-            psFree(myBin);
-        } else {
-            nBin = 1;
-        }
-
-        //
-        // Fit a polynomial to the overscan vector.
-        //
-        if (!((fitSpec == NULL) || (fit == PM_FIT_NONE))) {
-            if (fit == PM_FIT_POLYNOMIAL) {
-                myPoly = (psPolynomial1D *) fitSpec;
-                myPoly = psVectorFitPolynomial1D(myPoly, NULL, overscanVector, NULL);
+
+                psFree(tmpCol);
+                if ((fit == PM_FIT_POLYNOMIAL) || (fit == PM_FIT_SPLINE)) {
+                    psVector *newVec = ScaleOverscanVector(overscanVector, (in->image)->numRows, fitSpec, fit);
+                    psFree(overscanVector);
+                    overscanVector = newVec;
+                }
+            }
+
+            //
+            // Re-bin the overscan vector (change its length).
+            //
+            if ((nBinOrig > 0) && (nBinOrig < overscanVector->n)) {
+                numBins = 1+((overscanVector->n)/nBinOrig);
+                myBin = psVectorAlloc(numBins, PS_TYPE_F32);
+                binVec = psVectorAlloc(nBinOrig, PS_TYPE_F32);
+
                 for (i=0;i<numBins;i++) {
-                    overscanVector->data.F32[i] = psPolynomial1DEval((float) i, myPoly);
-                }
-
-            } else if (fit == PM_FIT_SPLINE) {
-                mySpline = (psSpline1D *) fitSpec;
-                // XXX: What is the point of doing this?
-            }
-        }
-
-        //
-        // Subtract overscan vector row-wise from the image.
-        //
-        if (overScanAxis == PM_OVERSCAN_ROWS) {
-            for (i=0;i<(in->image)->numCols;i++) {
-                for (j=0;j<(in->image)->numRows;j++) {
-                    (in->image)->data.F32[j][i]-= overscanVector->data.F32[i/nBin];
-                }
-            }
-        }
-
-        //
-        // Subtract overscan vector column-wise from the image.
-        //
-        if (overScanAxis == PM_OVERSCAN_COLUMNS) {
-            for (i=0;i<(in->image)->numRows;i++) {
-                for (j=0;j<(in->image)->numCols;j++) {
-                    (in->image)->data.F32[i][j]-= overscanVector->data.F32[i/nBin];
-                }
-            }
-        }
-        psFree(overscanVector);
-        return(in);
-    }
+                    for(j=0;j<nBinOrig;j++) {
+                        if (overscanVector->n > ((i*nBinOrig)+j)) {
+                            binVec->data.F32[j] = overscanVector->data.F32[(i*nBinOrig)+j];
+                        } else {
+                            // XXX: we get here if nBinOrig does not evenly divide
+                            // the overscanVector vector.  This is the last bin.  Should
+                            // we change the binVec->n to acknowledge that?
+                            binVec->n = j;
+                        }
+                    }
+                    stat = psVectorStats(stat, binVec, NULL, 0);
+                    p_psGetStatValue(stat, &statValue);
+                    myBin->data.F32[i] = statValue;
+                }
+
+                // Change the effective size of overscanVector.
+                overscanVector->n = numBins;
+                for (i=0;i<numBins;i++) {
+                    overscanVector->data.F32[i] = myBin->data.F32[i];
+                }
+                psFree(binVec);
+                psFree(myBin);
+                nBin = nBinOrig;
+            } else {
+                nBin = 1;
+            }
+
+            //
+            // Fit a polynomial to the overscan vector.
+            //
+            if (!((fitSpec == NULL) || (fit == PM_FIT_NONE))) {
+                if (fit == PM_FIT_POLYNOMIAL) {
+                    myPoly = (psPolynomial1D *) fitSpec;
+                    myPoly = psVectorFitPolynomial1D(myPoly, NULL, overscanVector, NULL);
+                    for (i=0;i<numBins;i++) {
+                        overscanVector->data.F32[i] = psPolynomial1DEval((float) i, myPoly);
+                    }
+
+                } else if (fit == PM_FIT_SPLINE) {
+                    mySpline = (psSpline1D *) fitSpec;
+                    // XXX: What is the point of doing this?
+                }
+            }
+
+            //
+            // Subtract overscan vector row-wise from the image.
+            //
+            if (overScanAxis == PM_OVERSCAN_ROWS) {
+                for (i=0;i<(in->image)->numCols;i++) {
+                    for (j=0;j<(in->image)->numRows;j++) {
+                        (in->image)->data.F32[j][i]-= overscanVector->data.F32[i/nBin];
+                    }
+                }
+            }
+
+            //
+            // Subtract overscan vector column-wise from the image.
+            //
+            if (overScanAxis == PM_OVERSCAN_COLUMNS) {
+                for (i=0;i<(in->image)->numRows;i++) {
+                    for (j=0;j<(in->image)->numCols;j++) {
+                        (in->image)->data.F32[i][j]-= overscanVector->data.F32[i/nBin];
+                    }
+                }
+            }
+            psFree(overscanVector);
+        }
+        tmpOverscan = tmpOverscan->next;
+    }
+
 
     if (bias != NULL) {
         return(psSubtractFrame(in, bias));
     }
-
-    // XXX: psErrorMsg(): Shouldn't get here?
     return(in);
 }
