Index: trunk/psModules/src/detrend/pmFlatField.c
===================================================================
--- trunk/psModules/src/detrend/pmFlatField.c	(revision 5309)
+++ 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 5309)
+++ 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 5309)
+++ 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 5309)
+++ 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
