Index: trunk/psLib/test/dataManip/tst_psMinimize06.c
===================================================================
--- trunk/psLib/test/dataManip/tst_psMinimize06.c	(revision 1992)
+++ trunk/psLib/test/dataManip/tst_psMinimize06.c	(revision 2197)
@@ -74,6 +74,96 @@
 }
 
-
-int main()
+psVector *myFunc2(psImage *myDeriv,
+                  psVector *myParams,
+                  psArray *myCoords)
+{
+    psVector *sum = psVectorAlloc(myCoords->n, PS_TYPE_F32);
+    int i;
+    int j;
+
+
+    if (myDeriv == NULL) {
+        myDeriv = psImageAlloc(myParams->n, myCoords->n, PS_TYPE_F32);
+        psError(__func__, "myDeriv is NULL.\n");
+    }
+
+    for (i=0;i<N;i++) {
+        sum->data.F32[i] = MIN_VALUE;
+        for (j=0;j<NUM_PARAMS;j++) {
+            sum->data.F32[i]+= (myParams->data.F32[j] - expectedParm[j]) *
+                               (myParams->data.F32[j] - expectedParm[j]);
+
+            myDeriv->data.F32[i][j] = (2.0 * myParams->data.F32[j]) -
+                                      (2.0 * expectedParm[j]);
+        }
+    }
+
+    return(sum);
+}
+
+int t01()
+{
+    int currentId = psMemGetId();
+    int memLeaks = 0;
+    int i = 0;
+    psArray *myCoords;
+    psVector *myParams;
+    psImage *myCovar;
+    psMinimization *min;
+    psVector *y;
+
+    psTraceSetLevel(".psLib", 0);
+    /**************************************************************************
+     *************************************************************************/
+    min = psMinimizationAlloc(NUM_ITERATIONS, ERR_TOL);
+    myCovar = psImageAlloc(NUM_PARAMS, NUM_PARAMS, PS_TYPE_F32);
+    myParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
+    myCoords = psArrayAlloc(N);
+    y = psVectorAlloc(N, PS_TYPE_F32);
+
+    for (i=0;i<N;i++) {
+        myCoords->data[i] = (psPTR *) psVectorAlloc(2, PS_TYPE_F32);
+        ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) (i+10);
+        ((psVector *) (myCoords->data[i]))->data.F32[1] = (float) (i+3);
+        y->data.F32[i] = (float) i;
+    }
+    for (i=0;i<NUM_PARAMS;i++) {
+        expectedParm[i] = 2.42 + (float) (2 * i);
+        myParams->data.F32[i] = (float) i;
+        myParams->data.F32[i] = expectedParm[i] * 1.3;
+        myParams->data.F32[i] = (float) (5 + i);
+        myParams->data.F32[i] = 0.0;
+    }
+
+    psMyMinimizeLMChi2(min,
+                       myCovar,
+                       myParams,
+                       NULL,
+                       myCoords,
+                       y,
+                       NULL,
+                       (psMyMinimizeLMChi2Func) myFunc2);
+
+    printf("\nThe chi-squared is %f\n", min->value);
+    for (i=0;i<NUM_PARAMS;i++) {
+        printf("Parameter %d at the minimum is %f (expected: %f)\n", i,
+               myParams->data.F32[i], expectedParm[i]);
+    }
+
+    psFree(min);
+    psFree(myCovar);
+    psFree(myParams);
+    psFree(myCoords);
+    psFree(y);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    return (!testStatus);
+}
+
+int t02()
 {
     int currentId = psMemGetId();
@@ -85,8 +175,8 @@
     psImage *myCovar;
     psMinimization *min;
-    psVector *x = psVectorAlloc(N, PS_TYPE_F32);
     psVector *y = psVectorAlloc(N, PS_TYPE_F32);
 
     psTraceSetLevel(".psLib", 0);
+    t02();
     /**************************************************************************
      *************************************************************************/
@@ -101,5 +191,4 @@
         ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) (i+10);
         ((psVector *) (myCoords->data[i]))->data.F32[1] = (float) (i+3);
-        x->data.F32[i] = (float) i;
         y->data.F32[i] = (float) i;
     }
@@ -131,5 +220,4 @@
     psFree(myParamMask);
     psFree(min);
-    psFree(x);
     psFree(y);
     psFree(myCovar);
@@ -142,2 +230,8 @@
     return (!testStatus);
 }
+
+int main()
+{
+    t01();
+    //    t02();
+}
