Index: /trunk/psLib/test/dataManip/tst_psMinimize07.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psMinimize07.c	(revision 2236)
+++ /trunk/psLib/test/dataManip/tst_psMinimize07.c	(revision 2236)
@@ -0,0 +1,169 @@
+/*****************************************************************************
+    This routine must ensure that psMinimizeLMChi2Gauss1D() works correctly.
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include <math.h>
+#define NUM_ITERATIONS 100
+#define ERR_TOL 0.0
+#define N 24
+#define NUM_PARAMS 2
+#define MEAN 10.0
+#define STDEV 1.5
+
+float expectedParm[NUM_PARAMS];
+psS32 testStatus = true;
+
+psVector *genGaussianVector()
+{
+    psVector *y = psVectorAlloc(N, PS_TYPE_F32);
+
+    for (psS32 i=0;i<N;i++) {
+        y->data.F32[i] = psGaussian((float) i, MEAN, STDEV, false);
+    }
+    return(y);
+}
+
+psVector *myFunc(psVector *params,
+                 psArray *coords)
+{
+    PS_PTR_CHECK_NULL(coords, NULL);
+    PS_PTR_CHECK_NULL(params, NULL);
+
+    float x;
+    int i;
+    float mean = params->data.F32[0];
+    float stdev = params->data.F32[1];
+    psVector *out = psVectorAlloc(coords->n, PS_TYPE_F32);
+
+    for (i=0;i<coords->n;i++) {
+        x = ((psVector *) (coords->data[i]))->data.F32[0];
+        out->data.F32[i] = psGaussian(x, mean, stdev, false);
+    }
+
+    return(out);
+}
+
+psS32 t00()
+{
+    psS32 currentId = psMemGetId();
+    psS32 memLeaks = 0;
+    psS32 i = 0;
+    psArray *myCoords;
+    psVector *myParams;
+    psImage *myCovar;
+    psMinimization *min;
+
+    psTraceSetLevel(".psLib.dataManip.psMinimize", 6);
+    /**************************************************************************
+     *************************************************************************/
+    min = psMinimizationAlloc(NUM_ITERATIONS, ERR_TOL);
+    myCovar = psImageAlloc(NUM_PARAMS, NUM_PARAMS, PS_TYPE_F32);
+    myParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
+    myParams->data.F32[0] = (float) (N/2);
+    myParams->data.F32[1] = 0.5;
+    myCoords = psArrayAlloc(N);
+    psVector *y = genGaussianVector();
+
+    for (i=0;i<N;i++) {
+        myCoords->data[i] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32);
+        ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) i;
+    }
+
+    psMinimizeLMChi2(min,
+                     myCovar,
+                     myParams,
+                     NULL,
+                     myCoords,
+                     y,
+                     NULL,
+                     (psMinimizeLMChi2Func) psMinimizeLMChi2Gauss1D);
+
+    printf("\nThe chi-squared is %f\n", min->value);
+
+    expectedParm[0] = MEAN;
+    expectedParm[1] = STDEV;
+    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);
+}
+
+psS32 t01()
+{
+    psS32 currentId = psMemGetId();
+    psS32 memLeaks = 0;
+    psS32 i = 0;
+    psArray *myCoords;
+    psVector *myParams;
+    psImage *myCovar;
+    psMinimization *min;
+
+    psTraceSetLevel(".psLib.dataManip.psMinimizePowell", 10);
+    psTraceSetLevel(".psLib.dataManip.myPowellChi2Func", 10);
+    psTraceSetLevel(".psLib.dataManip.psFunctions.psGaussian", 0);
+    psTraceSetLevel(".psLib.dataManip.psFunctions", 0);
+    psTraceSetLevel(".", 10);
+    psTracePrintLevels();
+    /**************************************************************************
+     *************************************************************************/
+    min = psMinimizationAlloc(NUM_ITERATIONS, ERR_TOL);
+    myCovar = psImageAlloc(NUM_PARAMS, NUM_PARAMS, PS_TYPE_F32);
+    myParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
+    myParams->data.F32[0] = (float) (N/2);
+    myParams->data.F32[0] = 2.0 * MEAN;
+    myParams->data.F32[1] = 0.5;
+    myParams->data.F32[1] = 1.5 * STDEV;
+    myCoords = psArrayAlloc(N);
+    psVector *y = genGaussianVector();
+
+    for (i=0;i<N;i++) {
+        myCoords->data[i] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32);
+        ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) i;
+    }
+
+    psMinimizeChi2Powell(min, myParams, NULL, myCoords, y, NULL,
+                         (psMinimizeChi2PowellFunc) myFunc);
+
+    printf("\nThe chi-squared is %f\n", min->value);
+
+    expectedParm[0] = MEAN;
+    expectedParm[1] = STDEV;
+    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);
+}
+
+psS32 main()
+{
+    //    t00();
+    t01();
+}
