Index: trunk/psLib/src/math/psMinimize.c
===================================================================
--- trunk/psLib/src/math/psMinimize.c	(revision 2347)
+++ trunk/psLib/src/math/psMinimize.c	(revision 2406)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.88 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-12 20:45:27 $
+ *  @version $Revision: 1.89 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-23 19:35:30 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -416,9 +416,9 @@
                                   const psArray *coords)
 {
+    PS_PTR_CHECK_NULL(coords, NULL);
+    PS_PTR_CHECK_NULL(params, NULL);
+
     psTrace(".psLib.dataManip.psMinimize", 4,
             "---- psMinimizeLMChi2Gauss1D() begin ----\n");
-
-    PS_PTR_CHECK_NULL(coords, NULL);
-    PS_PTR_CHECK_NULL(params, NULL);
     float x;
     int i;
@@ -432,4 +432,6 @@
     if (deriv == NULL) {
         deriv = psImageAlloc(params->n, coords->n, PS_TYPE_F32);
+    } else {
+        // XXX: Check size of derivative
     }
 
@@ -453,4 +455,54 @@
 }
 
+
+psVector *psMinimizeLMChi2Gauss2D(psImage *deriv,
+                                  const psVector *params,
+                                  const psArray *coords)
+{
+    PS_PTR_CHECK_NULL(coords, NULL);
+    PS_PTR_CHECK_NULL(params, NULL);
+
+    double normalization = params->data.F32[0];
+    double x0 = params->data.F32[1];
+    double y0 = params->data.F32[2];
+    double sigmaX = params->data.F32[3];
+    double sigmaY = params->data.F32[4];
+    double theta = params->data.F32[5];
+    psVector *out = psVectorAlloc(coords->n, PS_TYPE_F32);
+
+    if (deriv == NULL) {
+        deriv = psImageAlloc(params->n, coords->n, PS_TYPE_F32);
+    } else {
+        // XXX: Check size of derivative
+    }
+
+    psTrace(".psLib.dataManip.psMinimize", 4,
+            "---- psMinimizeLMChi2Gauss2D() begin ----\n");
+
+    for (int i=0;i<coords->n;i++) {
+        double x = ((psVector *) coords->data[i])->data.F32[0];
+        double y = ((psVector *) coords->data[i])->data.F32[0];
+
+        double u = - (x-x0)*cos(theta) + (y-y0)*sin(theta);
+        double v = (x-x0)*cos(theta) + (y-y0)*sin(theta);
+
+        double flux = normalization * exp(-( u*u/(2.0 * sigmaX * sigmaX) +
+                                             v*v/(2.0 * sigmaY * sigmaY)))/
+                      (2.0 * M_PI * sigmaX * sigmaY);
+        out->data.F32[i] = flux;
+
+        // XXX: Calculate these correctly.
+        deriv->data.F32[i][0] = 0.0;
+        deriv->data.F32[i][1] = 0.0;
+        deriv->data.F32[i][2] = 0.0;
+        deriv->data.F32[i][3] = 0.0;
+        deriv->data.F32[i][4] = 0.0;
+        deriv->data.F32[i][5] = 0.0;
+    }
+
+    psTrace(".psLib.dataManip.psMinimize", 4,
+            "---- psMinimizeLMChi2Gauss2D() end ----\n");
+    return(out);
+}
 
 /******************************************************************************
