Index: /trunk/psModules/src/astrom/pmAstrometry.c
===================================================================
--- /trunk/psModules/src/astrom/pmAstrometry.c	(revision 5434)
+++ /trunk/psModules/src/astrom/pmAstrometry.c	(revision 5435)
@@ -8,6 +8,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-09-28 20:43:52 $
+*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-10-20 23:06:24 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -71,6 +71,6 @@
         }
         psFree(fpa->chips);
-        psFree(fpa->header);
-        psFree(fpa->db);
+        psFree(fpa->private);
+        psFree(fpa->phu);
     }
 }
@@ -93,7 +93,5 @@
         psFree(chip->cells);
         psFree(chip->parent);
-        psFree(chip->extname);
-        psFree(chip->pixels);
-        psFree(chip->header);
+        psFree(chip->private);
     }
 }
@@ -106,4 +104,5 @@
         psFree(cell->toSky);
         psFree(cell->concepts);
+        psFree(cell->camera);
         psFree(cell->analysis);
         //
@@ -117,7 +116,5 @@
         psFree(cell->readouts);
         psFree(cell->parent);
-        psFree(cell->extname);
-        psFree(cell->pixels);
-        psFree(cell->header);
+        psFree(cell->private);
     }
 }
@@ -128,6 +125,7 @@
         psFree(readout->image);
         psFree(readout->mask);
+        psFree(readout->weight);
+        psFree(readout->bias);
         psFree(readout->analysis);
-        psFree(readout->concepts);
         psFree(readout->parent);
     }
@@ -145,6 +143,7 @@
     tmpReadout->image = NULL;
     tmpReadout->mask = NULL;
+    tmpReadout->weight = NULL;
+    tmpReadout->bias = NULL;
     tmpReadout->analysis = psMetadataAlloc();
-    tmpReadout->concepts = psMetadataAlloc();
     tmpReadout->parent = cell;
     if (cell != NULL) {
@@ -155,5 +154,9 @@
 }
 
-pmCell *pmCellAlloc(pmChip *chip)
+pmCell *pmCellAlloc(
+    pmChip *chip,
+    psMetadata *cameradata,
+    psString name
+)
 {
     pmCell *tmpCell = (pmCell *) psAlloc(sizeof(pmCell));
@@ -164,6 +167,12 @@
     tmpCell->toFPA = NULL;
     tmpCell->toSky = NULL;
-    tmpCell->analysis = psMetadataAlloc();
     tmpCell->concepts = psMetadataAlloc();
+    psBool rc = psMetadataAddStr(tmpCell->concepts, PS_LIST_HEAD, "CELL.NAME", 0, NULL, name);
+    if (rc == false) {
+        psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not add CELL.NAME to metadata.\n");
+    }
+    tmpCell->camera = cameradata;
+    psMemIncrRefCounter((psMetadata *) cameradata);
+    tmpCell->analysis = NULL;
     tmpCell->readouts = psArrayAlloc(0);
     tmpCell->parent = chip;
@@ -172,7 +181,5 @@
     }
     tmpCell->valid = false;
-    tmpCell->extname = NULL;
-    tmpCell->pixels = NULL;
-    tmpCell->header = NULL;
+    tmpCell->private = NULL;
 
     psMemSetDeallocator(tmpCell, (psFreeFunc) cellFree);
@@ -180,5 +187,8 @@
 }
 
-pmChip *pmChipAlloc(pmFPA *fpa)
+pmChip *pmChipAlloc(
+    pmFPA *fpa,
+    psString name
+)
 {
     pmChip *tmpChip = (pmChip *) psAlloc(sizeof(pmChip));
@@ -189,5 +199,9 @@
     tmpChip->fromFPA = NULL;
     tmpChip->concepts = psMetadataAlloc();
-    tmpChip->analysis = psMetadataAlloc();
+    psBool rc = psMetadataAddStr(tmpChip->concepts, PS_LIST_HEAD, "CHIP.NAME", 0, NULL, name);
+    if (rc == false) {
+        psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not add CHIP.NAME to metadata.\n");
+    }
+    tmpChip->analysis = NULL;
     tmpChip->cells = psArrayAlloc(0);
     tmpChip->parent = fpa;
@@ -196,7 +210,5 @@
     }
     tmpChip->valid = false;
-    tmpChip->extname = NULL;
-    tmpChip->pixels = NULL;
-    tmpChip->header = NULL;
+    tmpChip->private = NULL;
 
     psMemSetDeallocator(tmpChip, (psFreeFunc) chipFree);
@@ -204,7 +216,5 @@
 }
 
-pmFPA *pmFPAAlloc(
-    const psMetadata *camera,
-    psDB *db)
+pmFPA *pmFPAAlloc(const psMetadata *camera)
 {
     pmFPA *tmpFPA = (pmFPA *) psAlloc(sizeof(pmFPA));
@@ -214,11 +224,10 @@
     tmpFPA->projection = NULL;
     tmpFPA->concepts = psMetadataAlloc();
-    tmpFPA->analysis = psMetadataAlloc();
+    tmpFPA->analysis = NULL;
     tmpFPA->camera = camera;
     psMemIncrRefCounter((psPtr) camera);
     tmpFPA->chips = psArrayAlloc(0);
-    tmpFPA->header = NULL;
-    tmpFPA->db = db;
-    psMemIncrRefCounter((psPtr) db);
+    tmpFPA->private = NULL;
+    tmpFPA->phu = NULL;
 
     psMemSetDeallocator(tmpFPA, (psFreeFunc) FPAFree);
@@ -739,5 +748,6 @@
 psMetadataItem *pmReadoutGetConcept(pmReadout *readout, const char *concept)
 {
-    return(psMetadataLookup(readout->concepts, concept));
+    //    return(psMetadataLookup(readout->concepts, concept));
+    return(NULL);
 }
 
Index: /trunk/psModules/src/astrom/pmAstrometry.h
===================================================================
--- /trunk/psModules/src/astrom/pmAstrometry.h	(revision 5434)
+++ /trunk/psModules/src/astrom/pmAstrometry.h	(revision 5435)
@@ -8,6 +8,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-09-28 20:43:52 $
+*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-10-20 23:06:24 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -24,4 +24,11 @@
 /// @addtogroup AstroImage
 /// @{
+
+// XXXX: This is incorrect.  Must determine what p_pmHDU is.
+typedef struct
+{
+    int what;
+}
+p_pmHDU;
 
 /** Focal plane data structure
@@ -52,7 +59,6 @@
     const psMetadata *camera;           ///< Camera configuration
     psArray *chips;                     ///< The chips
-    // FITS data
-    psMetadata *header;                 ///< The FITS header, if it corresponds to this level
-    psDB *db;                           ///< Database handle
+    p_pmHDU *private;                   ///< FITS data
+    psMetadata *phu;                    ///< Primary Header
 }
 pmFPA;
@@ -86,8 +92,5 @@
     pmFPA *parent;                      ///< Parent FPA
     bool valid;                         ///< Do we bother about reading and working with this chip?
-    // FITS data
-    const char *extname;                ///< Extension name, if it corresponds to this level
-    psArray *pixels;                    ///< The pixel data, if it corresponds to this level
-    psMetadata *header;                 ///< The FITS header, if it corresponds to this level
+    p_pmHDU *private;                   ///< FITS data
 }
 pmChip;
@@ -113,12 +116,10 @@
     // Information
     psMetadata *concepts;               ///< Cache for PS concepts
+    psMetadata *camera;                 ///< Camera Info
     psMetadata *analysis;               ///< Cell-level analysis metadata
     psArray *readouts;                  ///< The readouts (referred to by number)
     pmChip *parent;                     ///< Parent chip
     bool valid;                         ///< Do we bother about reading and working with this cell?
-    // FITS data
-    const char *extname;                ///< Extension name, if it corresponds to this level
-    psArray *pixels;                    ///< The pixel data, if it corresponds to this level
-    psMetadata *header;                 ///< The FITS header, if it corresponds to this level
+    p_pmHDU *private;                   ///< FITS data
 }
 pmCell;
@@ -143,10 +144,8 @@
     // Information
     psImage *image;                     ///< Imaging area of readout
-    // XXX: The following mask was removed from the pmReadout struct in recent SDRS
-    // versions.  However, I'm keeping it here since al ot of modules still require
-    // it.
     psImage *mask;                      ///< Mask of input image
+    psImage *weight;                    ///< Weight of input image
+    psList *bias;                       ///< List of bias section (sub-)images
     psMetadata *analysis;               ///< Readout-level analysis metadata
-    psMetadata *concepts;               ///< Cache for PS Concepts
     pmCell *parent;                     ///< Parent cell
 }
@@ -178,5 +177,7 @@
  */
 pmCell *pmCellAlloc(
-    pmChip *chip                        ///< Parent chip
+    pmChip *chip,                        ///< Parent chip
+    psMetadata *cameradata,
+    psString name
 );
 
@@ -191,5 +192,9 @@
  *  @return pmChip*    newly allocated pmChip
  */
-pmChip *pmChipAlloc(pmFPA *fpa);
+pmChip *pmChipAlloc(
+    pmFPA *fpa,
+    psString name
+
+);
 
 /** Allocates a pmFPA
@@ -202,6 +207,5 @@
  */
 pmFPA *pmFPAAlloc(
-    const psMetadata *camera,           ///< Camera configuration
-    psDB *db                            ///< Database handle
+    const psMetadata *camera            ///< Camera configuration
 );
 
Index: /trunk/psModules/src/config/pmConfig.c
===================================================================
--- /trunk/psModules/src/config/pmConfig.c	(revision 5434)
+++ /trunk/psModules/src/config/pmConfig.c	(revision 5435)
@@ -3,6 +3,6 @@
  *  @author PAP, IfA
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-10-17 23:37:11 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-20 23:06:24 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -404,2 +404,28 @@
     return recipe;
 }
+
+/******************************************************************************
+pmConfigDB(*site)
+ 
+XXX: What should we use for the Database namespace in the call to psDBInit()?
+This is currently NULL.
+ *****************************************************************************/
+
+psDB *pmConfigDB(
+    psMetadata *site)
+{
+    PS_ASSERT_PTR_NON_NULL(site, NULL);
+    psBool mdStatus01 = false;
+    psBool mdStatus02 = false;
+    psBool mdStatus03 = false;
+
+    psString dbServer = psMetadataLookupStr(&mdStatus01, site, "DBSERVER");
+    psString dbUsername = psMetadataLookupStr(&mdStatus02, site, "DBUSER");
+    psString dbPassword = psMetadataLookupStr(&mdStatus03, site, "DBPASSWORD");
+    if (!(mdStatus01 & mdStatus02 & mdStatus03)) {
+        psLogMsg(__func__, PS_LOG_WARN, "Could not determine database server name, userID, and password from site metadata.\n");
+        return(NULL);
+    }
+
+    return(psDBInit(dbServer, dbUsername, dbPassword, NULL));
+}
Index: /trunk/psModules/src/config/pmConfig.h
===================================================================
--- /trunk/psModules/src/config/pmConfig.h	(revision 5434)
+++ /trunk/psModules/src/config/pmConfig.h	(revision 5435)
@@ -3,6 +3,6 @@
  *  @author PAP, IfA
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-10-17 21:34:12 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-20 23:06:24 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -84,3 +84,15 @@
 );
 
+/** pmConfigDB
+ * 
+ * pmConfigDB shall use the site configuration data to open a database handle.
+ * This is fairly straightforward at the moment, but will change when we beef up
+ * security. (TBD)
+ * 
+ */
+psDB *pmConfigDB(
+    psMetadata *site
+);
+
+
 #endif
Index: /trunk/psModules/src/detrend/pmFlatField.c
===================================================================
--- /trunk/psModules/src/detrend/pmFlatField.c	(revision 5434)
+++ /trunk/psModules/src/detrend/pmFlatField.c	(revision 5435)
@@ -18,6 +18,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-28 20:43:52 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-20 23:06:24 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -38,8 +38,10 @@
 
 
-bool pmFlatField(pmReadout *in, pmReadout *mask, const pmReadout *flat)
+bool pmFlatField(
+    pmReadout *in,
+    const pmReadout *flat)
 {
     // XXX: Not sure if this is correct.  Must consult with IfA.
-    PS_ASSERT_PTR_NON_NULL(mask, false);
+    PS_ASSERT_PTR_NON_NULL(in->mask, false);
     int i = 0;
     int j = 0;
@@ -56,5 +58,5 @@
     // Check for nulls
     if (in == NULL) {
-        return true;       // Readout may not have data in it
+        return true;       // Readout might have data in it
     } else if(flat==NULL) {
         psError( PS_ERR_BAD_PARAMETER_NULL, true,
@@ -74,5 +76,5 @@
         return false;
     }
-    inMask = mask->image;
+    inMask = in->mask;
 
     // Check input image and its mask are not larger than flat image
Index: /trunk/psModules/src/detrend/pmFlatField.h
===================================================================
--- /trunk/psModules/src/detrend/pmFlatField.h	(revision 5434)
+++ /trunk/psModules/src/detrend/pmFlatField.h	(revision 5435)
@@ -18,6 +18,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-28 20:43:52 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-20 23:06:24 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -37,5 +37,4 @@
 bool pmFlatField(
     pmReadout *in,          ///< Readout with input image
-    pmReadout *mask,        ///< Input image mask
     const pmReadout *flat   ///< Readout with flat image
 );
Index: /trunk/psModules/src/detrend/pmNonLinear.c
===================================================================
--- /trunk/psModules/src/detrend/pmNonLinear.c	(revision 5434)
+++ /trunk/psModules/src/detrend/pmNonLinear.c	(revision 5435)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-28 20:43:52 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-20 23:06:24 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -56,68 +56,39 @@
 inFluxe, and the corresponding value in outFlux.  The image pixel will then
 be set to the value from outFlux.
+ 
+XXX: Must assert that filename exists.  This should probably happen in
+the lookup files.
  *****************************************************************************/
-pmReadout *pmNonLinearityLookup(pmReadout *inputReadout,
-                                const psVector *inFlux,
-                                const psVector *outFlux)
+pmReadout *pmNonLinearityLookup(
+    pmReadout *inputReadout,
+    const char *filename
+)
 {
     PS_ASSERT_PTR_NON_NULL(inputReadout,NULL);
     PS_ASSERT_PTR_NON_NULL(inputReadout->image,NULL);
     PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL);
-    PS_ASSERT_PTR_NON_NULL(inFlux,NULL);
-    if (inFlux->n < 2) {
-        psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): input vector less than 2 elements.  Returning inputReadout image.");
-        return(inputReadout);
-    }
-    PS_ASSERT_PTR_NON_NULL(outFlux,NULL);
-    psS32 tableSize = inFlux->n;
-    if (inFlux->n != outFlux->n) {
-        tableSize = PS_MIN(inFlux->n, outFlux->n);
+    psLookupTable *tmpLT = psLookupTableAlloc(filename, "%f %f", 0);
+    psS32 numLines = psLookupTableRead(tmpLT);
+    psS32 numPixels = 0;
+    if (numLines < 2) {
         psLogMsg(__func__, PS_LOG_WARN,
-                 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): input vectors have different sizes (%d, %d)\n", inFlux->n, outFlux->n);
-    }
-    PS_ASSERT_VECTOR_TYPE(inFlux, PS_TYPE_F32, NULL);
-    PS_ASSERT_VECTOR_TYPE(outFlux, PS_TYPE_F32, NULL);
-
-    psS32 i;
-    psS32 j;
-    psS32 binNum;
-    psScalar x;
-    psS32 numPixels = 0;
-    psF32 slope;
-
-    x.type.type = PS_TYPE_F32;
-    for (i=0;i<inputReadout->image->numRows;i++) {
-        for (j=0;j<inputReadout->image->numCols;j++) {
-            x.data.F32 = inputReadout->image->data.F32[i][j];
-            binNum = p_psVectorBinDisect((psVector *)inFlux, &x);
-
-            if (binNum == -2) {
-                // We get here if x is below the table lookup range.
-                inputReadout->image->data.F32[i][j] = outFlux->data.F32[0];
-                numPixels++;
-
-            } else if (binNum == -1) {
-                // We get here if x is above the table lookup range.
-                inputReadout->image->data.F32[i][j] = outFlux->data.F32[tableSize-1];
-                numPixels++;
-
-            } else if (binNum < -2) {
-                // We get here if there was some other problem.
-                psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): Could not perform p_psVectorBinDisect().  Returning inputReadout image.");
-                return(inputReadout);
-                numPixels++;
-            } else {
-                // Perform linear interpolation.
-                slope = (outFlux->data.F32[binNum+1] - outFlux->data.F32[binNum]) /
-                        (inFlux->data.F32[binNum+1]  - inFlux->data.F32[binNum]);
-                inputReadout->image->data.F32[i][j] = outFlux->data.F32[binNum] +
-                                                      ((x.data.F32 - inFlux->data.F32[binNum]) * slope);
+                 "WARNING: Lookup Table is too small.  Returning original pmReadout.\n");
+    } else {
+        for (psS32 i=0;i<inputReadout->image->numRows;i++) {
+            for (psS32 j=0;j<inputReadout->image->numCols;j++) {
+                psF64 tmpD = psLookupTableInterpolate(tmpLT, inputReadout->image->data.F32[i][j], 1);
+                if (!isnan(tmpD)) {
+                    inputReadout->image->data.F32[i][j] = tmpD;
+                } else {
+                    numPixels++;
+                }
             }
         }
+        if (numPixels > 0) {
+            psLogMsg(__func__, PS_LOG_WARN,
+                     "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels);
+        }
     }
-    if (numPixels > 0) {
-        psLogMsg(__func__, PS_LOG_WARN,
-                 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels);
-    }
+
     return(inputReadout);
 }
Index: /trunk/psModules/src/detrend/pmNonLinear.h
===================================================================
--- /trunk/psModules/src/detrend/pmNonLinear.h	(revision 5434)
+++ /trunk/psModules/src/detrend/pmNonLinear.h	(revision 5435)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-28 20:43:52 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-20 23:06:24 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -18,10 +18,13 @@
 #include "pmAstrometry.h"
 
-pmReadout *pmNonLinearityPolynomial(pmReadout *in,
-                                    const psPolynomial1D *coeff);
+pmReadout *pmNonLinearityPolynomial(
+    pmReadout *in,
+    const psPolynomial1D *coeff
+);
 
-pmReadout *pmNonLinearityLookup(pmReadout *in,
-                                const psVector *inFlux,
-                                const psVector *outFlux);
+pmReadout *pmNonLinearityLookup(
+    pmReadout *in,
+    const char *filename
+);
 
 #endif
Index: /trunk/psModules/src/imsubtract/pmSubtractBias.c
===================================================================
--- /trunk/psModules/src/imsubtract/pmSubtractBias.c	(revision 5434)
+++ /trunk/psModules/src/imsubtract/pmSubtractBias.c	(revision 5435)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-10-12 21:02:04 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-20 23:06:24 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -282,12 +282,14 @@
 XXX: The SDRS does not specify type support.  F32 is implemented here.
  *****************************************************************************/
-pmReadout *pmSubtractBias(pmReadout *in,
-                          void *fitSpec,
-                          const psList *overscans,
-                          pmOverscanAxis overScanAxis,
-                          psStats *stat,
-                          psS32 nBinOrig,
-                          pmFit fit,
-                          const pmReadout *bias)
+pmReadout *pmSubtractBias(
+    pmReadout *in,
+    void *fitSpec,
+    pmFit fit,
+    bool overscan,
+    psStats *stat,
+    int nBin,
+    const pmReadout *bias,
+    const pmReadout *dark
+)
 {
     psTrace(".psModule.pmSubtracBias.pmSubtractBias", 4,
Index: /trunk/psModules/src/imsubtract/pmSubtractBias.h
===================================================================
--- /trunk/psModules/src/imsubtract/pmSubtractBias.h	(revision 5434)
+++ /trunk/psModules/src/imsubtract/pmSubtractBias.h	(revision 5435)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-28 20:43:52 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-20 23:06:24 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -38,12 +38,17 @@
 } pmFit;
 
-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
+pmReadout *pmSubtractBias(
+    pmReadout *in,                      ///< The input pmReadout image
+    void *fitSpec,                      ///< A polynomial or spline, defining the fit type.
+    pmFit fit,                          ///< PM_FIT_SPLINE, PM_FIT_POLYNOMIAL, or PM_FIT_NONE
+    bool overscan,
+    psStats *stat,                      ///< The statistic to be used in combining overscan data
+    int nBin,                           ///< The amount of binning to be done image pixels.
+    const pmReadout *bias,              ///< A possibly NULL bias pmReadout which is to be subtracted
+    const pmReadout *dark               ///< A possibly NULL bias pmReadout which is to be subtracted
+)
+// OLD: remove this
+//    const psList *overscans,      ///< A psList of overscan images
+//    pmOverscanAxis overScanAxis,  ///< Defines how overscans are applied
 
 #endif
Index: /trunk/psModules/src/objects/pmObjects.c
===================================================================
--- /trunk/psModules/src/objects/pmObjects.c	(revision 5434)
+++ /trunk/psModules/src/objects/pmObjects.c	(revision 5435)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-10-10 19:53:40 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-20 23:06:24 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -1445,5 +1445,5 @@
 XXX: What is mode?
 XXX: The top, bottom of the contour is not correctly determined.
-XXX EAM : this functions is using the model for the contour, but it should
+XXX EAM : this function is using the model for the contour, but it should
           be using only the image counts
 *****************************************************************************/
Index: /trunk/psModules/test/astrom/tst_pmAstrometry.c
===================================================================
--- /trunk/psModules/test/astrom/tst_pmAstrometry.c	(revision 5434)
+++ /trunk/psModules/test/astrom/tst_pmAstrometry.c	(revision 5435)
@@ -1,11 +1,11 @@
 /** @file  tst_pmAstrometry.c
  *
- *  @brief Contains the tests for pmAstrometry.[ch].  Only the pmxxxAlloc()
+ *  @brief Contains the tests: pmAstrometry.[ch].  Only the pmxxxAlloc()
  *  and psFree() functionality are used here.
  *
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-28 20:42:51 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-20 23:06:24 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -32,4 +32,7 @@
                           };
 
+#define CHIP_ALLOC_NAME "ChipName"
+#define CELL_ALLOC_NAME "CellName"
+
 psS32 main(psS32 argc, char* argv[])
 {
@@ -44,136 +47,126 @@
     // XXX: Do something more with these arguments.
     const psMetadata *camera = psMetadataAlloc();
-    psDB *db = NULL;
-    pmFPA* fpa = pmFPAAlloc(camera, db);
+    pmFPA* fpa = pmFPAAlloc(camera);
 
     if (fpa == NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc returned a NULL.");
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.");
         return 1;
     }
 
     if (fpa->fromTangentPlane != NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->fromTangentPlane to NULL.");
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->fromTangentPlane to NULL.");
         return 2;
     }
 
     if (fpa->toTangentPlane != NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->toTangentPlane to NULL.");
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->toTangentPlane to NULL.");
         return 3;
     }
     if (fpa->projection != NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->projection to NULL.");
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->projection to NULL.");
         return 4;
     }
 
     if (fpa->concepts == NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->concepts.");
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->concepts.");
         return 5;
     }
 
-    if (fpa->analysis == NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->analysis.");
+    if (fpa->analysis != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->analysis to NULL.");
         return 6;
     }
 
     if (fpa->camera != camera) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->camera.");
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->camera.");
         return 7;
     }
 
     if (fpa->chips == NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->chips.");
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->chips.");
         return 8;
     }
 
-    if (fpa->header != NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->header to NULL.");
+    if (fpa->private != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->private to NULL.");
         return 9;
     }
 
-    if (fpa->db != db) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->db.");
+    psFree(fpa);
+    psFree(camera);
+
+    return 0;
+}
+
+static psS32 testChipAlloc(void)
+{
+    const psMetadata *camera = psMetadataAlloc();
+    pmFPA* fpa = pmFPAAlloc(camera);
+    if (fpa == NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.");
+        return 1;
+    }
+
+    pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME);
+    if (chip == NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmChipAlloc returned a NULL.");
+        return 1;
+    }
+
+    if (chip->col0 != -1) {
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->col0 set improperly.\n");
+        return 5;
+    }
+
+    if (chip->row0 != -1) {
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->row0 set improperly.\n");
+        return 6;
+    }
+
+    if (chip->toFPA != NULL) {
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->toChip set improperly.\n");
+        return 7;
+    }
+
+    if (chip->fromFPA != NULL) {
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->toFPA set improperly.\n");
+        return 8;
+    }
+
+    if (chip->concepts == NULL) {
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->concepts set improperly.\n");
+        return 21;
+    } else {
+        psMetadataItem *tmpMeta = psMetadataLookup(chip->concepts, "CHIP.NAME");
+        if (0 != strcmp((char *) tmpMeta->data.V, CHIP_ALLOC_NAME)) {
+            psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: The metadata was set improperly.\n");
+            return (32);
+        }
+        // XXX: Code a test to ensure the metadata has the correct type
+    }
+
+    if (chip->analysis != NULL) {
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->analysis set improperly.\n");
         return 10;
     }
 
-    psFree(camera);
-    psFree(fpa);
-
-    return 0;
-}
-
-static psS32 testChipAlloc(void)
-{
-    const psMetadata *camera = psMetadataAlloc();
-    psDB *db = NULL;
-    pmFPA* fpa = pmFPAAlloc(camera, db);
-    if (fpa == NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc returned a NULL.");
-        return 1;
-    }
-
-    pmChip *chip = pmChipAlloc(fpa);
-    if (chip == NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmChipAlloc returned a NULL.");
-        return 1;
-    }
-
-    if (chip->col0 != -1) {
-        psLogMsg(__func__, PS_LOG_ERROR, "chip->col0 set improperly.\n");
-        return 5;
-    }
-
-    if (chip->row0 != -1) {
-        psLogMsg(__func__, PS_LOG_ERROR, "chip->row0 set improperly.\n");
-        return 6;
-    }
-
-    if (chip->toFPA != NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "chip->toChip set improperly.\n");
-        return 7;
-    }
-
-    if (chip->fromFPA != NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "chip->toFPA set improperly.\n");
-        return 8;
-    }
-
-    if (chip->concepts == NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "chip->concepts set improperly.\n");
-        return 21;
-    }
-
-    if (chip->analysis == NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "chip->analysis set improperly.\n");
-        return 10;
-    }
-
     if (chip->cells == NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "chip->cells set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->cells set improperly.\n");
         return 22;
     }
 
     if (chip->parent != fpa) {
-        psLogMsg(__func__, PS_LOG_ERROR, "chip->parent set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->parent set improperly.\n");
         return 23;
     }
 
     if (chip->valid != false) {
-        psLogMsg(__func__, PS_LOG_ERROR, "chip->valid set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->valid set improperly.\n");
         return 24;
     }
 
-    if (chip->extname != NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "chip->extname set improperly.\n");
+    if (chip->private != NULL) {
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->private set improperly.\n");
         return 25;
-    }
-
-    if (chip->pixels != NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "chip->pixels set improperly.\n");
-        return 26;
-    }
-
-    if (chip->header != NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "chip->header set improperly.\n");
-        return 27;
     }
 
@@ -187,86 +180,87 @@
 static psS32 testCellAlloc(void)
 {
-    psDB *db = NULL;
     const psMetadata *camera = psMetadataAlloc();
-    pmFPA* fpa = pmFPAAlloc(camera, db);
+    pmFPA* fpa = pmFPAAlloc(camera);
     if (fpa == NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc returned a NULL.n");
-        return 1;
-    }
-
-    pmChip *chip = pmChipAlloc(fpa);
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.n");
+        return 1;
+    }
+
+    pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME);
     if (chip == NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmChipAlloc returned a NULL.n");
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmChipAlloc returned a NULL.n");
         return 2;
     }
 
-    pmCell *cell = pmCellAlloc(chip);
+    pmCell *cell = pmCellAlloc(chip, (psMetadata *) camera, CELL_ALLOC_NAME);
     if (cell == NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmCellAlloc returned a NULL.n");
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmCellAlloc returned a NULL.n");
         return 3;
     }
 
     if (cell->col0 != -1) {
-        psLogMsg(__func__, PS_LOG_ERROR, "cell->col0 set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->col0 set improperly.\n");
         return 5;
     }
 
     if (cell->row0 != -1) {
-        psLogMsg(__func__, PS_LOG_ERROR, "cell->row0 set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->row0 set improperly.\n");
         return 6;
     }
 
     if (cell->toChip != NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "cell->toChip set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->toChip set improperly.\n");
         return 7;
     }
 
     if (cell->toFPA != NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "cell->toFPA set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->toFPA set improperly.\n");
         return 8;
     }
 
     if (cell->toSky != NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "cell->toSky set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->toSky set improperly.\n");
         return 9;
     }
 
-    if (cell->analysis == NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "cell->analysis set improperly.\n");
+    if (cell->concepts == NULL) {
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->concepts set improperly.\n");
+        return 21;
+    } else {
+        psMetadataItem *tmpMeta = psMetadataLookup(cell->concepts, "CELL.NAME");
+        if (0 != strcmp((char *) tmpMeta->data.V, CELL_ALLOC_NAME)) {
+            psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: The metadata was set improperly.\n");
+            return (32);
+        }
+        // XXX: Code a test to ensure the metadata has the correct type
+    }
+
+    if (cell->camera != camera) {
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->camera set improperly.\n");
+        return 20;
+    }
+
+    if (cell->analysis != NULL) {
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->analysis set improperly.\n");
         return 10;
     }
 
-    if (cell->concepts == NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "cell->concepts set improperly.\n");
-        return 21;
-    }
-
     if (cell->readouts == NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "cell->readouts set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->readouts set improperly.\n");
         return 22;
     }
 
     if (cell->parent != chip) {
-        psLogMsg(__func__, PS_LOG_ERROR, "cell->parent set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->parent set improperly.\n");
         return 23;
     }
 
     if (cell->valid != false) {
-        psLogMsg(__func__, PS_LOG_ERROR, "cell->valid set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->valid set improperly.\n");
         return 24;
     }
 
-    if (cell->extname != NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "cell->extname set improperly.\n");
-        return 25;
-    }
-
-    if (cell->pixels != NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "cell->pixels set improperly.\n");
-        return 26;
-    }
-
-    if (cell->header != NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "cell->header set improperly.\n");
+    if (cell->private != NULL) {
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->private set improperly.\n");
         return 27;
     }
@@ -282,22 +276,21 @@
 static psS32 testReadoutAlloc(void)
 {
-    psDB *db = NULL;
     const psMetadata *camera = psMetadataAlloc();
-    pmFPA* fpa = pmFPAAlloc(camera, db);
+    pmFPA* fpa = pmFPAAlloc(camera);
 
     if (fpa == NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc returned a NULL.\n");
-        return 1;
-    }
-
-    pmChip *chip = pmChipAlloc(fpa);
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.\n");
+        return 1;
+    }
+
+    pmChip *chip = pmChipAlloc(fpa, "ChipName");
     if (chip == NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmChipAlloc returned a NULL.\n");
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmChipAlloc returned a NULL.\n");
         return 2;
     }
 
-    pmCell *cell = pmCellAlloc(chip);
+    pmCell *cell = pmCellAlloc(chip, (psMetadata *) camera, "CellName");
     if (cell == NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmCellAlloc returned a NULL.\n");
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmCellAlloc returned a NULL.\n");
         return 3;
     }
@@ -305,51 +298,56 @@
     pmReadout *readout = pmReadoutAlloc(cell);
     if (readout == NULL) {
-        psLogMsg(__func__,PS_LOG_ERROR, "pmReadoutAlloc returned a NULL.\n");
+        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmReadoutAlloc returned a NULL.\n");
         return 4;
     }
 
     if (readout->col0 != -1) {
-        psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->col0 set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->col0 set improperly.\n");
         return 5;
     }
 
     if (readout->row0 != -1) {
-        psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->row0 set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->row0 set improperly.\n");
         return 6;
     }
 
     if (readout->colBins != -1) {
-        psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->colBins set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->colBins set improperly.\n");
         return 7;
     }
 
     if (readout->rowBins != -1) {
-        psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->colBins set improperly.\n");
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->colBins set improperly.\n");
         return 8;
     }
 
     if (readout->image != NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->image set improperly.\n");
-        return 9;
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->image set improperly.\n");
+        return 10;
     }
 
     if (readout->mask != NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->mask set improperly.\n");
-        return 10;
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->mask set improperly.\n");
+        return 12;
+    }
+
+    if (readout->weight != NULL) {
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->weight set improperly.\n");
+        return 14;
+    }
+
+    if (readout->bias != NULL) {
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->bias set improperly.\n");
+        return 16;
     }
 
     if (readout->analysis == NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->analysis set improperly.\n");
-        return 11;
-    }
-
-    if (readout->concepts == NULL) {
-        psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->concepts set improperly.\n");
-        return 12;
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->analysis set improperly.\n");
+        return 18;
     }
 
     if (readout->parent != cell) {
-        psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->parent set improperly.\n");
-        return 15;
+        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->parent set improperly.\n");
+        return 20;
     }
 
@@ -362,2 +360,3 @@
     return 0;
 }
+
Index: /trunk/psModules/test/config/Makefile.am
===================================================================
--- /trunk/psModules/test/config/Makefile.am	(revision 5434)
+++ /trunk/psModules/test/config/Makefile.am	(revision 5435)
@@ -4,5 +4,8 @@
 AM_CFLAGS  = @AM_CFLAGS@ $(PSMODULE_CFLAGS) $(SRCINC)
 
-TESTS =
+TESTS = \
+    tst_pmConfig
+
+tst_pmConfig_SOURCES = tst_pmConfig.c
 
 check_PROGRAMS = $(TESTS)
@@ -10,5 +13,9 @@
 TESTS_ENVIRONMENT = perl $(top_srcdir)/test/runTest --verified=$(srcdir)/verified
 
-tests:
+tests: $(TESTS)
+
+EXTRA_DIST = verified
+
+CLEANFILES = $(TESTS) temp/*
 
 test: check
Index: /trunk/psModules/test/detrend/tst_pmFlatField.c
===================================================================
--- /trunk/psModules/test/detrend/tst_pmFlatField.c	(revision 5434)
+++ /trunk/psModules/test/detrend/tst_pmFlatField.c	(revision 5435)
@@ -21,6 +21,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-28 20:42:52 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-20 23:06:24 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -85,12 +85,8 @@
     inReadout->row0 = 0;
     inReadout->col0 = 0;
+    CREATE_AND_SET_IMAGE(inMask, U8, 0, 3,3);
+    inReadout->mask = inMask;
+    PRINT_MATRIX((inReadout->mask),U8,"Input mask:");
     PRINT_MATRIX(inImage,F64,"Input image:");
-
-    CREATE_AND_SET_IMAGE(inMask,U8,0,3,3)
-    pmReadout *inMaskReadout = pmReadoutAlloc(NULL);
-    inMaskReadout->image = inMask;
-    inMaskReadout->row0 = 0;
-    inMaskReadout->col0 = 0;
-    PRINT_MATRIX(inMask,U8,"Input mask:");
 
     CREATE_AND_SET_IMAGE(flatImage1,F64,2.0,3,3)
@@ -101,5 +97,5 @@
     PRINT_MATRIX(flatImage1,F64,"Flat image:");
 
-    if ( !pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
+    if ( !pmFlatField(inReadout, flatReadout) ) {
         psError(PS_ERR_UNKNOWN,true,"Test A - Returned false should be true");
         return 1;
@@ -116,9 +112,9 @@
     PRINT_MATRIX(flatImage2, F64, "Flat image:");
     flatReadout->image = flatImage2;
-    if ( !pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
+    if ( !pmFlatField(inReadout, flatReadout) ) {
         psError(PS_ERR_UNKNOWN,true,"Test B - Returned false should be true");
         return 2;
     }
-    PRINT_MATRIX(inMaskReadout->image, PS_TYPE_MASK_DATA, "Resulting mask:");
+    PRINT_MATRIX(inReadout->mask, PS_TYPE_MASK_DATA, "Resulting mask:");
     PRINT_MATRIX(inImage,F64,"Resulting image:");
     printFooter(stdout, "pmFlatField", "Test B - Mask flat image data", true);
@@ -135,5 +131,5 @@
     psFree(inReadout->mask);
     inReadout->mask = mask1;
-    if ( !pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
+    if ( !pmFlatField(inReadout, flatReadout) ) {
         psError(PS_ERR_UNKNOWN,true,"Test C - Returned false should be true");
         return 3;
@@ -149,5 +145,5 @@
     printNegativeTestHeader(stdout,"pmFlatField", "Test D - Attempt to use null flat readout",
                             "Null not allowed for flat readout", 0);
-    if( pmFlatField(inReadout, inMaskReadout, NULL) ) {
+    if( pmFlatField(inReadout, NULL) ) {
         psError(PS_ERR_UNKNOWN,true,"Test D - Returned true should be false");
         return 4;
@@ -162,9 +158,9 @@
     psImage *temp = inReadout->image;
     inReadout->image = NULL;
-    if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
+    if ( pmFlatField(inReadout, flatReadout) ) {
         psError(PS_ERR_UNKNOWN,true,"Test E - Returned true should be false" );
         return 5;
     }
-    inReadout->image = temp;
+    inReadout->image = temp    ;
     printFooter(stdout, "pmFlatField", "Test E - Attempt to use null input image", true);
     printf("\n\n\n");
@@ -176,5 +172,5 @@
     temp = flatReadout->image;
     flatReadout->image = NULL;
-    if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
+    if ( pmFlatField(inReadout, flatReadout) ) {
         psError(PS_ERR_UNKNOWN,true,"Test F - Returned true should be false" );
         return 6;
@@ -191,5 +187,5 @@
     temp = flatReadout->image;
     flatReadout->image = smallFlat;
-    if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
+    if ( pmFlatField(inReadout, flatReadout) ) {
         psError(PS_ERR_UNKNOWN,true,"Test G - Returned true should be false");
         return 7;
@@ -198,5 +194,4 @@
     printFooter(stdout, "pmFlatField", "Test G - Attempt to use input image bigger than flat image", true);
     printf("\n\n\n");
-
 
     // Test H - Attempt to use input image mask bigger than flat image
@@ -204,14 +199,12 @@
                             "Input image mask size exceeds that of flat image", 0);
     CREATE_AND_SET_IMAGE(largeMask,F64,0.0,5,5);
-    temp = inReadout->mask;
-    inMaskReadout->image = largeMask;
-    if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
+    inReadout->mask = largeMask;
+    if ( pmFlatField(inReadout, flatReadout) ) {
         psError(PS_ERR_UNKNOWN,true,"Test H - Returned true should be false");
         return 8;
     }
-    inReadout->mask = temp;
     printFooter(stdout, "pmFlatField", "Test H - Attempt to use input image mask bigger than flat image", true);
     printf("\n\n\n");
-
+    inReadout->mask = mask1;
 
     // Test I - Attempt to use offset greater than input image
@@ -220,5 +213,5 @@
     *(int*)&inReadout->col0 = 50;
     *(int*)&inReadout->row0 = 50;
-    if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
+    if ( pmFlatField(inReadout, flatReadout) ) {
         psError(PS_ERR_UNKNOWN,true,"Test I - Returned true should be false");
         return 9;
@@ -234,5 +227,5 @@
                             "Complex types not allowed for input image", 0);
     *(psElemType* ) & inReadout->image->type.type = PS_TYPE_C64;
-    if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
+    if ( pmFlatField(inReadout, flatReadout) ) {
         psError(PS_ERR_UNKNOWN,true,"Test J - Returned true should be false");
         return 10;
@@ -247,5 +240,5 @@
                             "Complex types not allowed for flat image", 0);
     *(psElemType* ) & flatReadout->image->type.type = PS_TYPE_C64;
-    if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
+    if ( pmFlatField(inReadout, flatReadout) ) {
         psError(PS_ERR_UNKNOWN,true,"Test K - Returned ture should be false");
         return 11;
@@ -260,5 +253,5 @@
                             "Input and flat image types differ", 0);
     *(psElemType* ) & flatReadout->image->type.type = PS_TYPE_F32;
-    if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
+    if ( pmFlatField(inReadout, flatReadout) ) {
         psError(PS_ERR_UNKNOWN,true,"Test L - Returned true should be false");
         return 12;
@@ -273,5 +266,5 @@
                             "Mask must be PS_TYPE_MASK type", 0);
     *(psElemType* ) & inReadout->mask->type.type = PS_TYPE_F32;
-    if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
+    if ( pmFlatField(inReadout, flatReadout) ) {
         psError(PS_ERR_UNKNOWN,true,"Test M - Returned true should be false");
         return 13;
@@ -283,8 +276,4 @@
 
     // Free memory
-    psFree(inMask);
-    psFree(largeMask);
-    inMaskReadout->image = NULL;
-    psFree(inMaskReadout);
     psFree(inReadout);
     psFree(flatReadout);
@@ -293,4 +282,5 @@
     //psFree(flatImage1);
     psFree(smallFlat);
+    psFree(largeMask);
 
     return 0;
Index: /trunk/psModules/test/detrend/tst_pmNonLinear.c
===================================================================
--- /trunk/psModules/test/detrend/tst_pmNonLinear.c	(revision 5434)
+++ /trunk/psModules/test/detrend/tst_pmNonLinear.c	(revision 5435)
@@ -1,3 +1,3 @@
-/** @file tst_pmNonLinear.c
+/* @file tst_pmNonLinear.c
  *
  *  @brief Contains the tests for pmNonLinear.c:
@@ -16,6 +16,9 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-28 20:42:52 $
+ *  XXX: Add tests in which the lookup file has incorrect number of entries,
+ *  and where the data is outside the pmReadout range.
+ *
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-20 23:06:24 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -37,13 +40,25 @@
                           };
 
-
-int main(int argc, char* argv[])
-{
-    psLogSetFormat("HLNM");
-    return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv);
-}
-
 #define NUM_ROWS 8
 #define NUM_COLS 8
+#define LOOKUP_FILENAME ".tmp_tst_pmNonLinearLookupFile"
+int main(int argc, char* argv[])
+{
+    psLogSetFormat("HLNM");
+    //
+    // We generate a lookup file for future tests.  We should probably remove
+    // it when we're done.
+    //
+    FILE *fp = fopen(LOOKUP_FILENAME, "w");
+    ;
+    for (psS32 i=0;i<PS_MAX(NUM_COLS, NUM_ROWS)*3;i++) {
+        fprintf(fp, "%f %f\n", (float) i, (float) (2 * i));
+    }
+    fclose(fp);
+
+    //    system("rm LOOKUP_FILENAME");
+    return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv);
+}
+
 int doNonLinearityPolynomialTest(int numCols, int numRows)
 {
@@ -105,10 +120,7 @@
     float expect;
     int testStatus = true;
-    int tableSize = PS_MAX(numCols, numRows)*2;
     psImage *myImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     pmReadout *myReadout = pmReadoutAlloc(NULL);
     myReadout->image = myImage;
-    psVector *in = psVectorAlloc(tableSize, PS_TYPE_F32);
-    psVector *out = psVectorAlloc(tableSize, PS_TYPE_F32);
 
     printPositiveTestHeader(stdout, "pmNonLinear", "doNonLinearityLookupTest");
@@ -119,10 +131,5 @@
     }
 
-    for (i=0;i<tableSize;i++) {
-        in->data.F32[i] = (float) i;
-        out->data.F32[i] = (float) (2 * i);
-    }
-
-    myReadout = pmNonLinearityLookup(myReadout, in, out);
+    myReadout = pmNonLinearityLookup(myReadout, LOOKUP_FILENAME);
     for (i=0;i<numRows;i++) {
         for (j=0;j<numCols;j++) {
@@ -136,8 +143,5 @@
     }
 
-
-    psFree(myReadout);
-    psFree(in);
-    psFree(out);
+    psFree(myReadout);
     printFooter(stdout, "pmNonLinear", "doNonLinearityLookupTest", true);
     return(testStatus);
@@ -220,40 +224,14 @@
 int test03()
 {
-    int i;
-    int j;
-    int testStatus = true;
-    int tableSize = PS_MAX(NUM_COLS, NUM_ROWS)*3;
+    int testStatus = true;
     psImage *myImage = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32);
     pmReadout *myReadout = pmReadoutAlloc(NULL);
     pmReadout *rc = NULL;
     myReadout->image = myImage;
-    psVector *in = psVectorAlloc(tableSize, PS_TYPE_F32);
-    psVector *inOne = psVectorAlloc(1, PS_TYPE_F32);
-    psVector *inSmall = psVectorAlloc(tableSize-1, PS_TYPE_F32);
-    psVector *inBig = psVectorAlloc(tableSize+1, PS_TYPE_F32);
-    psVector *out = psVectorAlloc(tableSize, PS_TYPE_F32);
-    psVector *outOne = psVectorAlloc(1, PS_TYPE_F32);
-    psVector *outSmall = psVectorAlloc(tableSize-1, PS_TYPE_F32);
-    psVector *outBig = psVectorAlloc(tableSize+1, PS_TYPE_F32);
 
     test03Init(myReadout);
-    for (i=0;i<tableSize;i++) {
-        in->data.F32[i] = (float) i;
-        out->data.F32[i] = (float) (2 * i);
-        inBig->data.F32[i] = (float) i;
-        outBig->data.F32[i] = (float) (2 * i);
-        if (i < tableSize-1) {
-            inSmall->data.F32[i] = (float) i;
-            outSmall->data.F32[i] = (float) (2 * i);
-        }
-    }
-    inBig->data.F32[tableSize] = (float) tableSize;
-    outBig->data.F32[tableSize] = (float) (2 * tableSize);
-    inOne->data.F32[0] = 0.0;
-    outOne->data.F32[0] = 0.0;
-
     printf("------------------------------------------------------------\n");
     printf("Calling pmNonLinearityLookup() with NULL input pmReadout.  Should generate error, return NULL.\n");
-    rc = pmNonLinearityLookup(NULL, in, out);
+    rc = pmNonLinearityLookup(NULL, LOOKUP_FILENAME);
     if (rc != NULL) {
         printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL pmReadout\n");
@@ -265,5 +243,5 @@
     psImage *tmpImage = myReadout->image;
     myReadout->image = NULL;
-    rc = pmNonLinearityLookup(myReadout, in, out);
+    rc = pmNonLinearityLookup(myReadout, LOOKUP_FILENAME);
     if (rc != NULL) {
         printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL pmReadout\n");
@@ -273,237 +251,16 @@
 
     printf("------------------------------------------------------------\n");
-    printf("Calling pmNonLinearityLookup() with NULL inFlux psVector.  Should generate error, return NULL.\n");
-    rc = pmNonLinearityLookup(myReadout, NULL, out);
-    if (rc != NULL) {
-        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL pmReadout\n");
-        testStatus = false;
-    }
-
-    printf("------------------------------------------------------------\n");
-    printf("Calling pmNonLinearityLookup() with NULL outFlux psVector.  Should generate error, return NULL.\n");
-    rc = pmNonLinearityLookup(myReadout, in, NULL);
-    if (rc != NULL) {
-        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL pmReadout\n");
-        testStatus = false;
-    }
-
-    test03Init(myReadout);
-    printf("------------------------------------------------------------\n");
-    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
-    rc = pmNonLinearityLookup(myReadout, in, outBig);
+    printf("Calling pmNonLinearityLookup() with non-existent lookup file.\n");
+    rc = pmNonLinearityLookup(myReadout, "I_DONT_EXIST");
     if (rc == NULL) {
         printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
         testStatus = false;
     }
-    for (i=0;i<NUM_ROWS;i++) {
-        for (j=0;j<NUM_COLS;j++) {
-            psF32 expect = (float) (2 * (i + j));
-            psF32 actual = rc->image->data.F32[i][j];
-            if (FLT_EPSILON < fabs(expect - actual)) {
-                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
-                testStatus = false;
-            }
-        }
-    }
-
-
-    test03Init(myReadout);
-    printf("------------------------------------------------------------\n");
-    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
-    rc = pmNonLinearityLookup(myReadout, in, outSmall);
-    if (rc == NULL) {
-        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
-        testStatus = false;
-    }
-    for (i=0;i<NUM_ROWS;i++) {
-        for (j=0;j<NUM_COLS;j++) {
-            psF32 expect = (float) (2 * (i + j));
-            psF32 actual = rc->image->data.F32[i][j];
-            if (FLT_EPSILON < fabs(expect - actual)) {
-                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
-                testStatus = false;
-            }
-        }
-    }
-
-    test03Init(myReadout);
-    printf("------------------------------------------------------------\n");
-    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
-    rc = pmNonLinearityLookup(myReadout, inSmall, out);
-    if (rc == NULL) {
-        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
-        testStatus = false;
-    }
-    for (i=0;i<NUM_ROWS;i++) {
-        for (j=0;j<NUM_COLS;j++) {
-            psF32 expect = (float) (2 * (i + j));
-            psF32 actual = rc->image->data.F32[i][j];
-            if (FLT_EPSILON < fabs(expect - actual)) {
-                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
-                testStatus = false;
-            }
-        }
-    }
-
-    test03Init(myReadout);
-    printf("------------------------------------------------------------\n");
-    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
-    rc = pmNonLinearityLookup(myReadout, inBig, out);
-    if (rc == NULL) {
-        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
-        testStatus = false;
-    }
-    for (i=0;i<NUM_ROWS;i++) {
-        for (j=0;j<NUM_COLS;j++) {
-            psF32 expect = (float) (2 * (i + j));
-            psF32 actual = rc->image->data.F32[i][j];
-            if (FLT_EPSILON < fabs(expect - actual)) {
-                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
-                testStatus = false;
-            }
-        }
-    }
-
-    test03Init(myReadout);
-    printf("------------------------------------------------------------\n");
-    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
-    rc = pmNonLinearityLookup(myReadout, inSmall, outBig);
-    if (rc == NULL) {
-        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
-        testStatus = false;
-    }
-    for (i=0;i<NUM_ROWS;i++) {
-        for (j=0;j<NUM_COLS;j++) {
-            psF32 expect = (float) (2 * (i + j));
-            psF32 actual = rc->image->data.F32[i][j];
-            if (FLT_EPSILON < fabs(expect - actual)) {
-                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
-                testStatus = false;
-            }
-        }
-    }
-
-    test03Init(myReadout);
-    printf("------------------------------------------------------------\n");
-    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
-    rc = pmNonLinearityLookup(myReadout, inBig, outSmall);
-    if (rc == NULL) {
-        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
-        testStatus = false;
-    }
-    for (i=0;i<NUM_ROWS;i++) {
-        for (j=0;j<NUM_COLS;j++) {
-            psF32 expect = (float) (2 * (i + j));
-            psF32 actual = rc->image->data.F32[i][j];
-            if (FLT_EPSILON < fabs(expect - actual)) {
-                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
-                testStatus = false;
-            }
-        }
-    }
-
-    test03Init(myReadout);
-    printf("------------------------------------------------------------\n");
-    printf("Calling pmNonLinearityLookup() with inFlux psVector size 1.  Should generate error, return original pmReadout.\n");
-    rc = pmNonLinearityLookup(myReadout, inOne, out);
-    if (rc != myReadout) {
-        printf("TEST ERROR: pmNonLinearityPolynomial() did not return the original pmReadout\n");
-        testStatus = false;
-    }
-    for (i=0;i<NUM_ROWS;i++) {
-        for (j=0;j<NUM_COLS;j++) {
-            psF32 expect = (float) ((i + j));
-            psF32 actual = rc->image->data.F32[i][j];
-            if (FLT_EPSILON < fabs(expect - actual)) {
-                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
-                testStatus = false;
-            }
-        }
-    }
+
 
     printf("------------------------------------------------------------\n");
     printf("Calling pmNonLinearityLookup() with one pixels outside inFlux range.  Should generate warnings.\n");
-    test03Init(myReadout);
-    myReadout->image->data.F32[0][0] = -1;
-    rc = pmNonLinearityLookup(myReadout, in, out);
-    if (rc == NULL) {
-        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
-        testStatus = false;
-    }
-    for (i=0;i<NUM_ROWS;i++) {
-        for (j=0;j<NUM_COLS;j++) {
-            psF32 expect = (float) (2 * (i + j));
-            psF32 actual = rc->image->data.F32[i][j];
-            if(i==0 && j==0) {
-                if(actual != 0.0) {
-                    printf("TEST ERROR: image[%d][%d] is %f, should be %f\n",i,j,actual,0.0);
-                }
-            } else {
-                if (FLT_EPSILON < fabs(expect - actual)) {
-                    printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
-                    testStatus = false;
-                }
-            }
-        }
-    }
-
-    printf("------------------------------------------------------------\n");
-    printf("Calling pmNonLinearityLookup() with one pixels outside inFlux range.  Should generate warnings.\n");
-    test03Init(myReadout);
-    myReadout->image->data.F32[NUM_ROWS-1][NUM_COLS-1] = 100;
-    rc = pmNonLinearityLookup(myReadout, in, out);
-    if (rc == NULL) {
-        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
-        testStatus = false;
-    }
-    for (i=0;i<NUM_ROWS;i++) {
-        for (j=0;j<NUM_COLS;j++) {
-            psF32 expect = (float) (2 * (i + j));
-            psF32 actual = rc->image->data.F32[i][j];
-            if(i==(NUM_ROWS-1) && j==(NUM_COLS-1)) {
-                if(actual != (tableSize-1)*2) {
-                    printf("TEST ERROR: image[%d][%d] is %f, should be %f\n",i,j,actual,(tableSize-1)*2.0);
-                }
-            } else {
-                if (FLT_EPSILON < fabs(expect - actual)) {
-                    printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
-                    testStatus = false;
-                }
-            }
-        }
-    }
-
-    test03Init(myReadout);
-    printf("------------------------------------------------------------\n");
-    printf("Calling pmNonLinearityLookup() with image values not in vector.\n");
-    myReadout->image->data.F32[0][0] = 0.5;
-    rc = pmNonLinearityLookup(myReadout, in, out);
-    if (rc == NULL) {
-        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
-        testStatus = false;
-    }
-    for (i=0;i<NUM_ROWS;i++) {
-        for (j=0;j<NUM_COLS;j++) {
-            psF32 expect = (float) (2 * (i + j));
-            if(i==0 && j==0) {
-                expect = 1.0;
-            }
-            psF32 actual = rc->image->data.F32[i][j];
-            if (FLT_EPSILON < fabs(expect - actual)) {
-                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
-                testStatus = false;
-            }
-        }
-    }
-
-    psFree(myReadout);
-    psFree(in);
-    psFree(inOne);
-    psFree(inSmall);
-    psFree(inBig);
-    psFree(out);
-    psFree(outOne);
-    psFree(outSmall);
-    psFree(outBig);
+
+    psFree(myReadout);
 
     printFooter(stdout, "pmNonLinear", "Testing bad input parameter conditions.", true);
Index: /trunk/psModules/test/objects/tst_pmObjects01.c
===================================================================
--- /trunk/psModules/test/objects/tst_pmObjects01.c	(revision 5434)
+++ /trunk/psModules/test/objects/tst_pmObjects01.c	(revision 5435)
@@ -1,5 +1,5 @@
-/** @file tst_pmFindObjects.c
+/** @file tst_pmObjects.c
  *
- *  @brief Contains the tests for pmSubtractSky.c:
+ *  @brief Contains the tests for pmObjects.c:
  *
  * test00: This code will ...
@@ -9,4 +9,6 @@
  * XXX: Must test
  *       pmSourceRoughClass
+ *  many others...
+ *
  *
  * XXX: Must test output results for many other functions.
@@ -23,8 +25,8 @@
 Weakly Tested:
     pmSourceMoments()
- 
+    most of psObjects.c is not tested
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-10-10 21:55:42 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-20 23:06:24 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -47,11 +49,9 @@
 //static int test06(void);
 //static int test07(void);
-/*
-static int test08(void);
+//static int test08(void);
 static int test09(void);
 static int test15(void);
 static int test16(void);
 static int test20(void);
-*/
 testDescription tests[] = {
                               {test00, 000, "pmObjects: structure allocators and deallocators", true, false},
@@ -63,11 +63,9 @@
                               //                              {test06, 001, "pmObjects: pmSourceSetPixelsCircle()", true, false},
                               //                              {test07, 001, "pmObjects: pmMin()", true, false},
-                              /*
-                                                            {test08, 001, "pmObjects: pmSourceModelGuess()", true, false},
-                                                            {test09, 001, "pmObjects: pmSourceContour()", true, false},
-                                                            {test15, 001, "pmObjects: pmSourceAddModel()", true, false},
-                                                            {test16, 001, "pmObjects: pmSourceSubModel()", true, false},
-                                                            {test20, 001, "pmObjects: pmSourceSubModel()", true, false},
-                              */
+                              //                              {test08, 001, "pmObjects: pmSourceModelGuess()", true, false},
+                              {test09, 001, "pmObjects: pmSourceContour()", true, false},
+                              {test15, 001, "pmObjects: pmSourceAddModel()", true, false},
+                              {test16, 001, "pmObjects: pmSourceSubModel()", true, false},
+                              {test20, 001, "pmObjects: pmSourceSubModel()", true, false},
                               {NULL}
                           };
@@ -975,4 +973,318 @@
 }
 
+#define TST09_NUM_ROWS 70
+#define TST09_NUM_COLS 70
+#define TST09_SKY 5.0
+#define TST09_INNER_RADIUS 3
+#define TST09_OUTER_RADIUS 10
+#define LEVEL (TST09_SKY + 10.0)
+/******************************************************************************
+test09(): We first test pmSourceContour() with various NULL and unallowable
+input parameters.
+ 
+XXX: We don't verify the numbers.
+ *****************************************************************************/
+int test09( void )
+{
+    bool testStatus = true;
+    psImage *imgData = psImageAlloc(TST09_NUM_COLS, TST09_NUM_ROWS, PS_TYPE_F32);
+    psImageInit(imgData, TST09_SKY);
+    psImage *imgMask = psImageAlloc(TST09_NUM_COLS, TST09_NUM_ROWS, PS_TYPE_U8);
+    psImageInit(imgMask, 0);
+    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST09_NUM_ROWS / 2),
+                                  (psF32) (TST09_NUM_COLS / 2),
+                                  200.0,
+                                  PM_PEAK_LONE);
+    pmSource *tmpSource = pmSourceAlloc();
+    tmpSource->pixels = imgData;
+    tmpSource->mask = imgMask;
+    tmpSource->peak = tmpPeak;
+    psBool rc = pmSourceLocalSky(tmpSource, PS_STAT_SAMPLE_MEAN, 10.0);
+    if (rc == false) {
+        printf("TEST ERROR: pmSourceLocalSky() returned a FALSE pmSource.\n");
+        testStatus = false;
+    }
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceContour with NULL pmSource .  Should generate error, return FALSE.\n");
+    rc = pmSourceContour(NULL, imgData, LEVEL, PS_CONTOUR_CRUDE);
+    if (rc != false) {
+        printf("TEST ERROR: pmSourceContour() returned TRUE.\n");
+        testStatus = false;
+        psFree(rc);
+    }
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceContour with NULL psImage .  Should generate error, return FALSE.\n");
+    rc = pmSourceContour(tmpSource, NULL, LEVEL, PS_CONTOUR_CRUDE);
+    if (rc != FALSE) {
+        printf("TEST ERROR: pmSourceContour() returned TRUE.\n");
+        testStatus = false;
+        psFree(rc);
+    }
+
+    //
+    // XXX: pmSourceContour() has a problem with contour tops/bottoms.
+    // Must correct this.
+    //
+    if (1) {
+        printf("----------------------------------------------------------------------------------\n");
+        printf("Calling pmSourceContour with acceptable data.\n");
+        printf("NOTE: must figure out the parameters for this test to be meaningful.\n");
+        tmpSource->modelPSF->params->data.F32[0] = TST09_SKY;
+        tmpSource->modelPSF->params->data.F32[1] = 15.0;
+        tmpSource->modelPSF->params->data.F32[2] = (psF32) (TST09_NUM_ROWS / 2);
+        tmpSource->modelPSF->params->data.F32[3] = (psF32) (TST09_NUM_COLS / 2);
+        tmpSource->modelPSF->params->data.F32[4] = 2.0;
+        tmpSource->modelPSF->params->data.F32[5] = 2.0;
+        tmpSource->modelPSF->params->data.F32[6] = 2.0;
+        rc = pmSourceContour(tmpSource, imgData, LEVEL, PS_CONTOUR_CRUDE);
+        if (rc == false) {
+            printf("TEST ERROR: pmSourceContour() returned FALSE.\n");
+            testStatus = false;
+        } else {
+            psFree(rc);
+        }
+    }
+
+    psFree(tmpSource);
+    return(testStatus);
+}
+
+#define TST15_NUM_ROWS 100
+#define TST15_NUM_COLS 100
+#define TST15_SKY 10.0
+#define TST15_INNER_RADIUS 3
+#define TST15_OUTER_RADIUS 5
+/******************************************************************************
+test15(): We first test pmSourceAddModel() with various NULL and unallowable
+input parameters.
+ 
+XXX: We don't verify the numbers.
+ *****************************************************************************/
+int test15( void )
+{
+    bool testStatus = true;
+    psImage *imgData = psImageAlloc(TST15_NUM_COLS, TST15_NUM_ROWS, PS_TYPE_F32);
+    psImageInit(imgData, TST15_SKY);
+    psImage *imgMask = psImageAlloc(TST15_NUM_COLS, TST15_NUM_ROWS, PS_TYPE_U8);
+    psImageInit(imgMask, 0);
+    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST15_NUM_ROWS / 2),
+                                  (psF32) (TST15_NUM_COLS / 2),
+                                  200.0,
+                                  PM_PEAK_LONE);
+    pmSource *tmpSource = pmSourceAlloc();
+    tmpSource->pixels = imgData;
+    tmpSource->mask = imgMask;
+    tmpSource->peak = tmpPeak;
+    psBool rc = pmSourceLocalSky(tmpSource, PS_STAT_SAMPLE_MEAN, 10.0);
+    if (rc == false) {
+        printf("TEST ERROR: pmSourceLocalSky() returned a FALSE pmSource.\n");
+        testStatus = false;
+    }
+
+
+    tmpSource->modelPSF = pmModelAlloc(PS_MODEL_GAUSS);
+    tmpSource->modelPSF->params->data.F32[0] = 5.0;
+    tmpSource->modelPSF->params->data.F32[1] = 70.0;
+    tmpSource->modelPSF->params->data.F32[2] = (psF32) (TST15_NUM_ROWS / 2);
+    tmpSource->modelPSF->params->data.F32[3] = (psF32) (TST15_NUM_COLS / 2);
+    tmpSource->modelPSF->params->data.F32[4] = 1.0;
+    tmpSource->modelPSF->params->data.F32[5] = 1.0;
+    tmpSource->modelPSF->params->data.F32[6] = 2.0;
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceAddModel with NULL psImage.  Should generate error, return FALSE.\n");
+    rc = pmSourceAddModel(NULL, tmpSource, true);
+    if (rc == true) {
+        printf("TEST ERROR: pmSourceAddModel() returned TRUE.\n");
+        testStatus = false;
+    }
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceAddModel with NULL psSrc.  Should generate error, return FALSE.\n");
+    rc = pmSourceAddModel(imgData, NULL, true);
+    if (rc == true) {
+        printf("TEST ERROR: pmSourceAddModel() returned TRUE.\n");
+        testStatus = false;
+    }
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceAddModel with acceptable data.\n");
+    rc = pmSourceAddModel(imgData, tmpSource, true);
+    if (rc != true) {
+        printf("TEST ERROR: pmSourceAddModel() returned FALSE.\n");
+        testStatus = false;
+    }
+
+    psFree(tmpSource);
+    psFree(imgData);
+    return(testStatus);
+}
+
+#define TST16_NUM_ROWS 100
+#define TST16_NUM_COLS 100
+#define TST16_SKY 10.0
+#define TST16_INNER_RADIUS 3
+#define TST16_OUTER_RADIUS 5
+/******************************************************************************
+test16(): We first test pmSourceSubModel() with various NULL and unallowable
+input parameters.
+ 
+XXX: We don't verify the numbers.
+ *****************************************************************************/
+int test16( void )
+{
+    bool testStatus = true;
+    psImage *imgData = psImageAlloc(TST16_NUM_COLS, TST16_NUM_ROWS, PS_TYPE_F32);
+    for (psS32 i = 0 ; i < imgData->numRows; i++) {
+        for (psS32 j = 0 ; j < imgData->numCols; j++) {
+            imgData->data.F32[i][j] = TST16_SKY;
+        }
+    }
+    pmSource *tmpSource = NULL;
+    psBool rc = false;
+
+    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST16_NUM_ROWS / 2),
+                                  (psF32) (TST16_NUM_COLS / 2),
+                                  200.0,
+                                  PM_PEAK_LONE);
+
+    printf("Calling pmSourceLocalSky with valid data.\n");
+    tmpPeak->x = (psF32) (TST16_NUM_ROWS / 2);
+    tmpPeak->y = (psF32) (TST16_NUM_COLS / 2);
+    tmpSource = pmSourceLocalSky(imgData,
+                                 tmpPeak,
+                                 PS_STAT_SAMPLE_MEAN,
+                                 (psF32) TST16_INNER_RADIUS,
+                                 (psF32) TST16_OUTER_RADIUS);
+
+    if (tmpSource == NULL) {
+        printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource.\n");
+        testStatus = false;
+    }
+
+    tmpSource->modelPSF = pmModelAlloc(PS_MODEL_GAUSS);
+    tmpSource->modelPSF->params->data.F32[0] = 5.0;
+    tmpSource->modelPSF->params->data.F32[1] = 70.0;
+    tmpSource->modelPSF->params->data.F32[2] = (psF32) (TST16_NUM_ROWS / 2);
+    tmpSource->modelPSF->params->data.F32[3] = (psF32) (TST16_NUM_COLS / 2);
+    tmpSource->modelPSF->params->data.F32[4] = 1.0;
+    tmpSource->modelPSF->params->data.F32[5] = 1.0;
+    tmpSource->modelPSF->params->data.F32[6] = 2.0;
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceSubModel with NULL psImage.  Should generate error, return FALSE.\n");
+    rc = pmSourceSubModel(NULL, tmpSource, true);
+    if (rc == true) {
+        printf("TEST ERROR: pmSourceSubModel() returned TRUE.\n");
+        testStatus = false;
+    }
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceSubModel with NULL psSrc.  Should generate error, return FALSE.\n");
+    rc = pmSourceSubModel(imgData, NULL, true);
+    if (rc == true) {
+        printf("TEST ERROR: pmSourceSubModel() returned TRUE.\n");
+        testStatus = false;
+    }
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceSubModel with acceptable data.\n");
+    rc = pmSourceSubModel(imgData, tmpSource, true);
+    if (rc != true) {
+        printf("TEST ERROR: pmSourceSubModel() returned FALSE.\n");
+        testStatus = false;
+    }
+
+    psFree(tmpSource);
+    psFree(imgData);
+    return(testStatus);
+}
+
+#define TST20_NUM_ROWS 100
+#define TST20_NUM_COLS 100
+#define TST20_SKY 10.0
+#define TST20_INNER_RADIUS 3
+#define TST20_OUTER_RADIUS 5
+/******************************************************************************
+test20(): We first test pmSourceSubModel() with various NULL and unallowable
+input parameters.
+ 
+XXX: We don't verify the numbers.
+ *****************************************************************************/
+int test20( void )
+{
+    bool testStatus = true;
+    psImage *imgData = psImageAlloc(TST20_NUM_COLS, TST20_NUM_ROWS, PS_TYPE_F32);
+    for (psS32 i = 0 ; i < imgData->numRows; i++) {
+        for (psS32 j = 0 ; j < imgData->numCols; j++) {
+            imgData->data.F32[i][j] = TST20_SKY;
+        }
+    }
+    pmSource *tmpSource = NULL;
+    psBool rc = false;
+
+    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST20_NUM_ROWS / 2),
+                                  (psF32) (TST20_NUM_COLS / 2),
+                                  200.0,
+                                  PM_PEAK_LONE);
+
+    printf("Calling pmSourceLocalSky with valid data.\n");
+    tmpPeak->x = (psF32) (TST20_NUM_ROWS / 2);
+    tmpPeak->y = (psF32) (TST20_NUM_COLS / 2);
+    tmpSource = pmSourceLocalSky(imgData,
+                                 tmpPeak,
+                                 PS_STAT_SAMPLE_MEAN,
+                                 (psF32) TST20_INNER_RADIUS,
+                                 (psF32) TST20_OUTER_RADIUS);
+
+    if (tmpSource == NULL) {
+        printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource.\n");
+        testStatus = false;
+    }
+
+    tmpSource->modelPSF = pmModelAlloc(PS_MODEL_GAUSS);
+
+
+    tmpSource->modelPSF->params->data.F32[0] = 5.0;
+    tmpSource->modelPSF->params->data.F32[1] = 70.0;
+    tmpSource->modelPSF->params->data.F32[2] = (psF32) (TST20_NUM_ROWS / 2);
+    tmpSource->modelPSF->params->data.F32[3] = (psF32) (TST20_NUM_COLS / 2);
+    tmpSource->modelPSF->params->data.F32[4] = 1.0;
+    tmpSource->modelPSF->params->data.F32[5] = 1.0;
+    tmpSource->modelPSF->params->data.F32[6] = 2.0;
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceFitModel with NULL psImage.  Should generate error, return FALSE.\n");
+    rc = pmSourceFitModel(tmpSource, NULL);
+    if (rc == true) {
+        printf("TEST ERROR: pmSourceFitModel() returned TRUE.\n");
+        testStatus = false;
+    }
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceFitModel with NULL pmSource.  Should generate error, return FALSE.\n");
+    rc = pmSourceFitModel(NULL, imgData);
+    if (rc == true) {
+        printf("TEST ERROR: pmSourceFitModel() returned TRUE.\n");
+        testStatus = false;
+    }
+
+    printf("----------------------------------------------------------------------------------\n");
+    printf("Calling pmSourceFitModel with acceptable data.\n");
+    rc = pmSourceFitModel(tmpSource, imgData);
+    printf("pmSourceFitModel returned %d\n", rc);
+
+    // XXX: Memory leaks are not being tested
+    psVector *junk = psVectorAlloc(10, PS_TYPE_F32);
+    junk->data.F32[0] = 0.0;
+
+    psFree(tmpSource);
+    psFree(imgData);
+    return(testStatus);
+}
+
+
 // this code will
 
