Index: trunk/psLib/src/dataManip/psMinimize.c
===================================================================
--- trunk/psLib/src/dataManip/psMinimize.c	(revision 1775)
+++ trunk/psLib/src/dataManip/psMinimize.c	(revision 1781)
@@ -9,6 +9,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-10 02:52:02 $
+ *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-10 22:25:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -845,5 +845,16 @@
 }
 /******************************************************************************
+This routine will take an procedure which calculates an arbitrary function
+and it's derivative and minimize it.
+ 
 GUS
+ 
+XXX: Do this:
+ After checking that all entries in the paramMask are 1 or 0, when
+ forming the A matrix from alpha, try this:
+ 
+     A[i][i] = (1 + lambda*paramask[i]) * alpha[i][i];
+ 
+ 
  *****************************************************************************/
 bool psMinimizeLM(psMinimization *min,
@@ -857,4 +868,5 @@
     psVector *perm = psVectorAlloc(params->n, PS_TYPE_F32);
     psVector *newParams = psVectorAlloc(params->n, PS_TYPE_F32);
+    psVector *origParams = psVectorAlloc(params->n, PS_TYPE_F32);
     psImage *alpha = psImageAlloc(params->n, params->n, PS_TYPE_F32);
     psImage *A = psImageAlloc(params->n, params->n, PS_TYPE_F32);
@@ -869,7 +881,17 @@
     float lamda = 1.0;
 
+    for (i=0;i<params->n;i++) {
+        origParams->data.F32[i] = params->data.F32[i];
+    }
+
     min->lastDelta = -HUGE;
     min->iter = 0;
     min->value = func(deriv, params, coords);
+    for (i=0;i<params->n;i++) {
+        if ((paramMask != NULL) &&
+                (paramMask->data.U8[i] != 0)) {
+            deriv->data.F32[i] = 0.0;
+        }
+    }
 
     while ((min->lastDelta > min->tol) &&
@@ -897,10 +919,26 @@
         newParams = psMatrixLUSolve(newParams, aOut, beta, perm);
 
+        for (i=0;i<params->n;i++) {
+            if ((paramMask != NULL) &&
+                    (paramMask->data.U8[i] != 0)) {
+                newParams->data.F32[i] = origParams->data.F32[i];
+            }
+        }
+
         oldValue = min->value;
         newValue = func(newDeriv, newParams, coords);
+        for (i=0;i<params->n;i++) {
+            if ((paramMask != NULL) &&
+                    (paramMask->data.U8[i] != 0)) {
+                deriv->data.F32[i] = 0.0;
+            }
+        }
+
         if (oldValue > newValue) {
             min->lastDelta = oldValue - newValue;
             min->value = newValue;
 
+            // No need to check the paramMask here since we already did so
+            // before the last function evaluation.
             for (i=0;i<params->n;i++) {
                 params->data.F32[i] = newParams->data.F32[i];
@@ -918,4 +956,5 @@
     psFree(perm);
     psFree(newParams);
+    psFree(origParams);
     psFree(alpha);
     psFree(A);
@@ -1769,5 +1808,5 @@
  
 The basic idea is calculate chi-squared for a set of params/coords/errors.
-This functions uses globale variables to receive the function pointer, the
+This functions uses global variables to receive the function pointer, the
 data values, and the data errors.
  *****************************************************************************/
