Index: trunk/psModules/test/detrend/tst_pmNonLinear.c
===================================================================
--- trunk/psModules/test/detrend/tst_pmNonLinear.c	(revision 5169)
+++ 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);
