Index: /trunk/psLib/test/dataManip/Makefile
===================================================================
--- /trunk/psLib/test/dataManip/Makefile	(revision 1094)
+++ /trunk/psLib/test/dataManip/Makefile	(revision 1095)
@@ -3,6 +3,6 @@
 ##  Makefile:   test/sysUtils
 ##
-##  $Revision: 1.17 $  $Name: not supported by cvs2svn $
-##  $Date: 2004-06-25 07:27:25 $
+##  $Revision: 1.18 $  $Name: not supported by cvs2svn $
+##  $Date: 2004-06-25 07:28:04 $
 ##
 ##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -46,4 +46,6 @@
  tst_psImageStats03 \
  tst_psMinimize00 \
+ tst_psMinimize01 \
+ tst_psMinimize02 \
  tst_psImageIO \
  tst_psVectorFFT \
Index: /trunk/psLib/test/dataManip/tst_psMinimize00.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psMinimize00.c	(revision 1095)
+++ /trunk/psLib/test/dataManip/tst_psMinimize00.c	(revision 1095)
@@ -0,0 +1,132 @@
+/*****************************************************************************
+    This routine must ensure that the psMinimizeChi2 function correctly
+    minimizes an arbitrary function.
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psMemory.h"
+#include "psVector.h"
+#include "psImage.h"
+#include "psFunctions.h"
+#include "psMinimize.h"
+#define NUM_DATA 10
+#define DATA_WIDTH 2
+#define NUM_PARAMS 4
+
+float *myFunc(psVector *myData,
+              psVector *myParams)
+{
+    float x = myData->data.F32[0];
+    float y = myData->data.F32[1];
+    float A = myParams->data.F32[0];
+    float B = myParams->data.F32[1];
+    float C = myParams->data.F32[2];
+    float D = myParams->data.F32[3];
+    float *tmp = (float *) psAlloc(sizeof(float));
+
+    *tmp = A + (B*x) + (C*y) + (D*x*y);
+    return(tmp);
+}
+
+float *myFuncDeriv(psVector *myData,
+                   psVector *myParams,
+                   int whichParamDeriv)
+{
+    float x = myData->data.F32[0];
+    float y = myData->data.F32[1];
+    float *tmp = (float *) psAlloc(sizeof(float));
+
+    if (whichParamDeriv == 0) {
+        *tmp = 1.0;
+    } else if (whichParamDeriv == 1) {
+        *tmp = x;
+    } else if (whichParamDeriv == 2) {
+        *tmp = y;
+    } else if (whichParamDeriv == 3) {
+        *tmp = x * y;
+    }
+    return(tmp);
+}
+
+
+int main()
+{
+    psImage *domain = NULL;
+    psVector *data = NULL;
+    psVector *errors = NULL;
+    psVector *initialGuess = NULL;
+    psVector *paramMask = NULL;
+    psVector *tmpVecPtr = NULL;
+    float chiSq = 0.0;
+    int i = 0;
+    int j = 0;
+    int currentId = psMemGetId();
+    int testStatus = 0;
+    int memLeaks = 0;
+
+    domain = psImageAlloc(NUM_DATA, DATA_WIDTH, PS_TYPE_F32);
+    data = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+    errors = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+    initialGuess = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
+    paramMask = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
+    tmpVecPtr = psVectorAlloc(DATA_WIDTH, PS_TYPE_F32);
+
+    // Build the data.
+    initialGuess->data.F32[0] = 2.0;
+    initialGuess->data.F32[1] = 3.0;
+    initialGuess->data.F32[2] = 4.0;
+    initialGuess->data.F32[3] = 5.0;
+    for (i = 0; i<NUM_DATA; i++) {
+        for (j=0; j<DATA_WIDTH; j++) {
+            domain->data.F32[i][j] = (float) (i + j);
+        }
+    }
+    for (i = 0; i<NUM_DATA; i++) {
+        errors->data.F32[i] = 0.1;
+    }
+
+    for (i = 0; i<NUM_DATA; i++) {
+        for (j=0; j<DATA_WIDTH; j++) {
+            tmpVecPtr->data.F32[i] = domain->data.F32[i][j];
+        }
+        data->data.F32[i] = *myFunc(tmpVecPtr, initialGuess);
+    }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "Calculate Histogram, no mask");
+
+    psMinimizeChi2(myFunc,
+                   myFuncDeriv,
+                   domain,
+                   data,
+                   errors,
+                   initialGuess,
+                   paramMask,
+                   &chiSq);
+
+    printf("chiSq is %f\n", chiSq);
+    psMemCheckCorruption(1);
+    printFooter(stdout,
+                "psMinimize functions",
+                "Calculate Histogram, no mask",
+                testStatus);
+
+
+    psMemCheckCorruption(1);
+    psFree(domain);
+    psFree(data);
+    psFree(errors);
+    psFree(initialGuess);
+    psFree(paramMask);
+    psFree(tmpVecPtr);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    return (!testStatus);
+}
