Index: /trunk/psModules/src/detrend/pmSubtractBias.c
===================================================================
--- /trunk/psModules/src/detrend/pmSubtractBias.c	(revision 9618)
+++ /trunk/psModules/src/detrend/pmSubtractBias.c	(revision 9619)
@@ -1,21 +1,2 @@
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the
-// one that was being worked on.
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-/** @file  pmSubtractBias.c
- *
- *  This file will contain a module which will subtract the detector bias
- *  in place from an input image.
- *
- *  @author GLG, MHPCC
- *
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-08-29 21:39:44 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- *
- */
-
 #if HAVE_CONFIG_H
 #include <config.h>
@@ -25,4 +6,6 @@
 #include <assert.h>
 #include <pslib.h>
+
+#include "pmFPA.h"
 #include "pmSubtractBias.h"
 
@@ -31,39 +14,5 @@
 
 
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-
-
-// XXX: put these in psConstants.h
-void PS_POLY1D_PRINT(psPolynomial1D *poly)
-{
-    printf("-------------- PS_POLY1D_PRINT() --------------\n");
-    printf("poly->nX is %d\n", poly->nX);
-    for (psS32 i = 0 ; i < (1 + poly->nX) ; i++) {
-        printf("poly->coeff[%d] is %f\n", i, poly->coeff[i]);
-    }
-}
-
-void PS_PRINT_SPLINE(psSpline1D *mySpline)
-{
-    printf("-------------- PS_PRINT_SPLINE() --------------\n");
-    printf("mySpline->n is %d\n", mySpline->n);
-    for (psS32 i = 0 ; i < mySpline->n ; i++) {
-        PS_POLY1D_PRINT(mySpline->spline[i]);
-    }
-    PS_VECTOR_PRINT_F32(mySpline->knots);
-}
-
-#define PS_IMAGE_PRINT_F32_HIDEF(NAME) \
-printf("======== printing %s ========\n", #NAME); \
-for (int i = 0 ; i < (NAME)->numRows ; i++) { \
-    for (int j = 0 ; j < (NAME)->numCols ; j++) { \
-        printf("%.5f ", (NAME)->data.F32[i][j]); \
-    } \
-    printf("\n"); \
-}\
-
-
-void overscanOptionsFree(pmOverscanOptions *options)
+static void overscanOptionsFree(pmOverscanOptions *options)
 {
     psFree(options->stat);
@@ -91,10 +40,7 @@
 
 
-/******************************************************************************
-psSubtractFrame(): this routine will take as input a readout for the input
-image and a readout for the bias image.  The bias image is subtracted in
-place from the input image.
-*****************************************************************************/
-static bool SubtractFrame(pmReadout *in,// Input readout
+// psSubtractFrame(): this routine will take as input a readout for the input image and a readout for the bias
+// image.  The bias image is subtracted in place from the input image.
+static bool SubtractFrame(pmReadout *in, // Input readout
                           const pmReadout *sub, // Readout to be subtracted from input
                           float scale   // Scale to apply before subtracting
@@ -109,4 +55,5 @@
     psImage *subMask  = sub->mask;      // The mask for the subtraction image
 
+    // Check parities
     int xIpar = psMetadataLookupS32(NULL, in->parent->concepts, "CELL.XPARITY");
     int xSpar = psMetadataLookupS32(NULL, sub->parent->concepts, "CELL.XPARITY");
@@ -252,8 +199,4 @@
 
 
-
-/******************************************************************************
-XXX: The SDRS does not specify type support.  F32 is implemented here.
- *****************************************************************************/
 bool pmSubtractBias(pmReadout *in, pmOverscanOptions *overscanOpts,
                     const pmReadout *bias, const pmReadout *dark)
@@ -280,5 +223,6 @@
         if (overscanOpts->fitType != PM_FIT_NONE && overscanOpts->fitType != PM_FIT_POLY_ORD &&
                 overscanOpts->fitType != PM_FIT_POLY_CHEBY && overscanOpts->fitType != PM_FIT_SPLINE) {
-            psError(PS_ERR_UNKNOWN, true, "Invalid fit type (%d).  Returning original image.\n", overscanOpts->fitType);
+            psError(PS_ERR_UNKNOWN, true, "Invalid fit type (%d).  Returning original image.\n",
+                    overscanOpts->fitType);
             return false;
         }
@@ -335,5 +279,5 @@
                 while ((overscan = psListGetAndIncrement(iter))) {
                     int diff = image->row0 - overscan->row0; // Offset between the two regions
-                    for (int i = MAX(0,diff); i < MIN(image->numRows, overscan->numRows + diff); i++) {
+                    for (int i = PS_MAX(0,diff); i < PS_MIN(image->numRows, overscan->numRows + diff); i++) {
                         // i is row on overscan
                         // XXX Reimplement with memcpy
@@ -379,5 +323,5 @@
                 while ((overscan = psListGetAndIncrement(iter))) {
                     int diff = image->col0 - overscan->col0; // Offset between the two regions
-                    for (int i = MAX(0,diff); i < MIN(image->numCols, overscan->numCols + diff); i++) {
+                    for (int i = PS_MAX(0,diff); i < PS_MIN(image->numCols, overscan->numCols + diff); i++) {
                         // i is column on overscan
                         // XXX Reimplement with memcpy
Index: /trunk/psModules/src/detrend/pmSubtractBias.h
===================================================================
--- /trunk/psModules/src/detrend/pmSubtractBias.h	(revision 9618)
+++ /trunk/psModules/src/detrend/pmSubtractBias.h	(revision 9619)
@@ -1,42 +1,26 @@
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the
-// one that was being worked on.
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+/// @file pmSubtractBias.h
+///
+/// @brief Subtract the overscan, bias and dark
+///
+/// @ingroup Detrend
+///
+/// @author George Gusciora, MHPCC
+/// @author Paul Price, IfA
+///
+/// @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+/// @date $Date: 2006-10-18 01:05:59 $
+///
+/// Copyright 2004--2006 Institute for Astronomy, University of Hawaii
+///
 
-/** @file  pmSubtractBias.h
- *
- *  This file will contain a module which will subtract the detector bias
- *  in place from an input image.
- *
- *  @author GLG, MHPCC
- *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-17 01:50:43 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- *
- */
-
-#if !defined(PM_SUBTRACT_BIAS_H)
+#ifndef PM_SUBTRACT_BIAS_H
 #define PM_SUBTRACT_BIAS_H
 
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include<stdio.h>
-#include<math.h>
-#include "pslib.h"
+#include <stdio.h>
+#include <pslib.h>
 
 #include "pmFPA.h"
 
-typedef enum {
-    PM_OVERSCAN_NONE,                         ///< No overscan subtraction
-    PM_OVERSCAN_EDGE,                         ///< Subtract the statistic of pixels along the to-be-determined readout direction
-    PM_OVERSCAN_ROWS,                         ///< Subtract rows
-    PM_OVERSCAN_COLUMNS,                      ///< Subtract columns
-    PM_OVERSCAN_ALL                           ///< Subtract the statistic of all pixels in overscan region
-} pmOverscanAxis;
-
+/// Type of fit to perform
 typedef enum {
     PM_FIT_NONE,                        ///< No fit
@@ -46,32 +30,40 @@
 } pmFit;
 
+/// Options for overscan subtraction
+///
+/// The overscan subtraction may be performed by reducing all overscan regions to a single value (e.g., if
+/// there is no structure); or the overscan may be fit perpendicular to the read direction (usually the
+/// columns) with a particular functional form; or a single value may be subtracted for each read/scan without
+/// fitting (if the structure defies characterisation).  In any case, statistics are required to reduce
+/// multiple values to a single value (either for the scan, or for the entire overscan regions).
 typedef struct
 {
     // Inputs
-    bool single;                // Reduce all overscan regions to a single value?
-    pmFit fitType;              // Type of fit to overscan
-    unsigned int order;         // Order of polynomial, or number of spline pieces
-    psStats *stat;              // Statistic to use when reducing the minor direction
+    bool single;                ///< Reduce all overscan regions to a single value?
+    pmFit fitType;              ///< Type of fit to overscan
+    unsigned int order;         ///< Order of polynomial, or number of spline pieces
+    psStats *stat;              ///< Statistic to use when reducing the minor direction
     // Outputs
-    psPolynomial1D *poly;       // Result of polynomial fit
-    psSpline1D *spline;         // Result of spline fit
+    psPolynomial1D *poly;       ///< Result of polynomial fit
+    psSpline1D *spline;         ///< Result of spline fit
 }
 pmOverscanOptions;
 
-pmOverscanOptions *pmOverscanOptionsAlloc(bool single, pmFit fitType, unsigned int order, psStats *stat);
+/// Allocator for overscan options
+pmOverscanOptions *pmOverscanOptionsAlloc(bool single, ///< Reduce all overscan regions to a single value?
+        pmFit fitType, ///< Type of fit to overscan
+        unsigned int order, ///< Order of polynomial, or number of splines
+        psStats *stat ///< Statistic to use
+                                         );
 
-bool pmSubtractBias(pmReadout *in, pmOverscanOptions *overscanOpts,
-                    const pmReadout *bias, const pmReadout *dark);
-
-#if 0
-pmReadout *pmSubtractBias(pmReadout *in,                ///< The input pmReadout image
-                          void *fitSpec,                ///< A polynomial or spline, defining the fit type.
-                          const psList *overscans,      ///< A psList of overscan images
-                          pmOverscanAxis overScanAxis,  ///< Defines how overscans are applied
-                          psStats *stat,                ///< The statistic to be used in combining overscan data
-                          int nBin,                     ///< The amount of binning to be done image pixels.
-                          pmFit fit,                    ///< PM_FIT_SPLINE, PM_FIT_POLYNOMIAL, or PM_FIT_NONE
-                          const pmReadout *bias);       ///< A possibly NULL bias pmReadout which is to be subtracted
-#endif
+/// Subtract the overscan, bias and/or dark
+///
+/// Subtracts the overscan, as measured from the bias member of the input readout (if options are non-NULL),
+/// bias (if non-NULL) and dark (if non-NULL) scaled by the CELL.DARKTIME concept.
+bool pmSubtractBias(pmReadout *in,      ///< Input readout, to be overscan/bias/dark corrected
+                    pmOverscanOptions *overscanOpts, ///< Options for overscan subtraction, or NULL
+                    const pmReadout *bias, ///< Bias image to subtract, or NULL
+                    const pmReadout *dark ///< Dark image to scale and subtract, or NULL
+                   );
 
 #endif
