Index: trunk/psLib/src/math/psConstants.h
===================================================================
--- trunk/psLib/src/math/psConstants.h	(revision 6199)
+++ trunk/psLib/src/math/psConstants.h	(revision 6204)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.83 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-01-26 00:31:19 $
+ *  @version $Revision: 1.84 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-01-26 21:10:22 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -512,5 +512,5 @@
 static psPolynomial1D *(NAME) = NULL; \
 if ((NAME) == NULL) { \
-    (NAME) = psPolynomial1DAlloc(ORDER, TYPE); \
+    (NAME) = psPolynomial1DAlloc(TYPE, ORDER); \
     p_psMemSetPersistent((NAME), true); \
     p_psMemSetPersistent((NAME)->coeff, true); \
@@ -519,52 +519,56 @@
 } \
 
-#define PS_POLY_2D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
-static psPolynomial2D *(NAME) = NULL; \
-if ((NAME) == NULL) { \
-    (NAME) = psPolynomial2DAlloc(ORDER, TYPE); \
-    p_psMemSetPersistent((NAME), true); \
-} \
-
-#define PS_POLY_3D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
-static psPolynomial3D *(NAME) = NULL; \
-if ((NAME) == NULL) { \
-    (NAME) = psPolynomial3DAlloc(ORDER, TYPE); \
-    p_psMemSetPersistent((NAME), true); \
-} \
-
-#define PS_POLY_4D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
-static psPolynomial4D *(NAME) = NULL; \
-if ((NAME) == NULL) { \
-    (NAME) = psPolynomial4DAlloc(ORDER, TYPE); \
-    p_psMemSetPersistent((NAME), true); \
-} \
+/* XXX: This is not correct
+    #define PS_POLY_2D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
+    static psPolynomial2D *(NAME) = NULL; \
+    if ((NAME) == NULL) { \
+        (NAME) = psPolynomial2DAlloc(ORDER, TYPE); \
+        p_psMemSetPersistent((NAME), true); \
+    } \
+ 
+    #define PS_POLY_3D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
+    static psPolynomial3D *(NAME) = NULL; \
+    if ((NAME) == NULL) { \
+        (NAME) = psPolynomial3DAlloc(ORDER, TYPE); \
+        p_psMemSetPersistent((NAME), true); \
+    } \
+ 
+    #define PS_POLY_4D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
+    static psPolynomial4D *(NAME) = NULL; \
+    if ((NAME) == NULL) { \
+        (NAME) = psPolynomial4DAlloc(ORDER, TYPE); \
+        p_psMemSetPersistent((NAME), true); \
+    } \
+*/
 
 #define PS_POLY_1D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
 static psPolynomial1D *(NAME) = NULL; \
 if ((NAME) == NULL) { \
-    (NAME) = psPolynomial1DAlloc(ORDER, TYPE); \
+    (NAME) = psPolynomial1DAlloc(TYPE, ORDER); \
     p_psMemSetPersistent((NAME), true); \
 } \
 
-#define PS_POLY_2D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
-static psPolynomial2D *(NAME) = NULL; \
-if ((NAME) == NULL) { \
-    (NAME) = psPolynomial2DAlloc(ORDER, TYPE); \
-    p_psMemSetPersistent((NAME), true); \
-} \
-
-#define PS_POLY_3D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
-static psPolynomial3D *(NAME) = NULL; \
-if ((NAME) == NULL) { \
-    (NAME) = psPolynomial3DAlloc(ORDER, TYPE); \
-    p_psMemSetPersistent((NAME), true); \
-} \
-
-#define PS_POLY_4D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
-static psPolynomial4D *(NAME) = NULL; \
-if ((NAME) == NULL) { \
-    (NAME) = psPolynomial4DAlloc(ORDER, TYPE); \
-    p_psMemSetPersistent((NAME), true); \
-} \
+/* XXX: This is not correct
+    #define PS_POLY_2D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
+    static psPolynomial2D *(NAME) = NULL; \
+    if ((NAME) == NULL) { \
+        (NAME) = psPolynomial2DAlloc(ORDER, TYPE); \
+        p_psMemSetPersistent((NAME), true); \
+    } \
+ 
+    #define PS_POLY_3D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
+    static psPolynomial3D *(NAME) = NULL; \
+    if ((NAME) == NULL) { \
+        (NAME) = psPolynomial3DAlloc(ORDER, TYPE); \
+        p_psMemSetPersistent((NAME), true); \
+    } \
+ 
+    #define PS_POLY_4D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
+    static psPolynomial4D *(NAME) = NULL; \
+    if ((NAME) == NULL) { \
+        (NAME) = psPolynomial4DAlloc(ORDER, TYPE); \
+        p_psMemSetPersistent((NAME), true); \
+    } \
+*/
 
 #define PS_POLY_PRINT_1D(NAME) \
Index: trunk/psLib/src/math/psMinimizeLMM.c
===================================================================
--- trunk/psLib/src/math/psMinimizeLMM.c	(revision 6199)
+++ trunk/psLib/src/math/psMinimizeLMM.c	(revision 6204)
@@ -10,6 +10,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-01-21 02:43:31 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-01-26 21:10:22 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -204,4 +204,5 @@
     psMinimizeLMChi2Func func)
 {
+    // XXX: Check vector sizes.
     PS_ASSERT_IMAGE_NON_NULL(alpha, NAN);
     PS_ASSERT_VECTOR_NON_NULL(beta, NAN);
@@ -218,6 +219,6 @@
 
     // zero alpha and beta for summing below
-    for (int j = 0; j < params->n; j++) {
-        for (int k = 0; k < params->n; k++) {
+    for (psS32 j = 0; j < params->n; j++) {
+        for (psS32 k = 0; k < params->n; k++) {
             alpha->data.F64[j][k] = 0;
         }
@@ -227,5 +228,5 @@
 
     // calculate chisq, alpha, beta
-    for (int i = 0; i < y->n; i++) {
+    for (psS32 i = 0; i < y->n; i++) {
         ymodel = func(deriv, params, (psVector *) x->data[i]);
 
@@ -233,9 +234,9 @@
         chisq += PS_SQR(delta) * dy->data.F32[i];
 
-        for (int j = 0; j < params->n; j++) {
+        for (psS32 j = 0; j < params->n; j++) {
             if ((paramMask != NULL) && (paramMask->data.U8[j]))
                 continue;
             weight = deriv->data.F32[j] * dy->data.F32[i];
-            for (int k = 0; k <= j; k++) {
+            for (psS32 k = 0; k <= j; k++) {
                 if ((paramMask != NULL) && (paramMask->data.U8[k]))
                     continue;
@@ -247,6 +248,6 @@
 
     // calculate lower-left half of alpha
-    for (int j = 1; j < params->n; j++) {
-        for (int k = 0; k < j; k++) {
+    for (psS32 j = 1; j < params->n; j++) {
+        for (psS32 k = 0; k < j; k++) {
             alpha->data.F64[k][j] = alpha->data.F64[j][k];
         }
@@ -255,5 +256,5 @@
     // fill in pivots if we apply a mask
     if (paramMask != NULL) {
-        for (int j = 0; j < params->n; j++) {
+        for (psS32 j = 0; j < params->n; j++) {
             if (paramMask->data.U8[j]) {
                 alpha->data.F64[j][j] = 1;
Index: trunk/psLib/src/math/psMinimizePolyFit.c
===================================================================
--- trunk/psLib/src/math/psMinimizePolyFit.c	(revision 6199)
+++ trunk/psLib/src/math/psMinimizePolyFit.c	(revision 6204)
@@ -10,6 +10,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-01-26 00:31:19 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-01-26 21:10:22 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -350,5 +350,5 @@
     // We first fit an ordinary polynomial to the data.
     //
-    psPolynomial1D *ordPoly = psPolynomial1DAlloc(polyOrder, PS_POLYNOMIAL_ORD);
+    psPolynomial1D *ordPoly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, polyOrder);
     psPolynomial1D *rc = VectorFitPolynomial1DOrd(ordPoly, mask, maskValue, y, yErr, x);
     if (rc == NULL) {
@@ -965,5 +965,5 @@
         }
     } else {
-        psError(PS_ERR_UNKNOWN, true, "Incorrect polynomial type.  Returning NULL.\n");
+        psError(PS_ERR_UNKNOWN, true, "Incorrect polynomial type (%d).  Returning NULL.\n", poly->type);
         poly = NULL;
     }
Index: trunk/psLib/src/math/psPolynomial.c
===================================================================
--- trunk/psLib/src/math/psPolynomial.c	(revision 6199)
+++ trunk/psLib/src/math/psPolynomial.c	(revision 6204)
@@ -7,6 +7,6 @@
 *  polynomials.  It also contains a Gaussian functions.
 *
-*  @version $Revision: 1.139 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-01-26 02:44:56 $
+*  @version $Revision: 1.140 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-01-26 21:10:22 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -168,5 +168,5 @@
         psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *));
         for (psS32 i = 0; i < numPolys; i++) {
-            chebPolys[i] = psPolynomial1DAlloc(i, PS_POLYNOMIAL_ORD);
+            chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i);
             chebPolys[i]->coeff[i] = 1;
         }
@@ -175,5 +175,5 @@
         psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *));
         for (psS32 i = 0; i < numPolys; i++) {
-            chebPolys[i] = psPolynomial1DAlloc(i, PS_POLYNOMIAL_ORD);
+            chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i);
         }
 
@@ -615,9 +615,9 @@
  *****************************************************************************/
 psPolynomial1D* psPolynomial1DAlloc(
-    unsigned int n,
-    psPolynomialType type)
+    psPolynomialType type,
+    unsigned int nX)
 {
     //PS_ASSERT_INT_NONNEGATIVE(n, NULL);
-    psU32 nOrder = n;
+    psU32 nOrder = nX;
     psPolynomial1D *newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D));
     psMemSetDeallocator(newPoly, (psFreeFunc) polynomial1DFree);
@@ -639,7 +639,8 @@
 }
 
-psPolynomial2D* psPolynomial2DAlloc( unsigned int nX,
-                                     unsigned int nY,
-                                     psPolynomialType type)
+psPolynomial2D* psPolynomial2DAlloc(
+    psPolynomialType type,
+    unsigned int nX,
+    unsigned int nY)
 {
     //PS_ASSERT_INT_NONNEGATIVE(nX, NULL);
@@ -676,8 +677,9 @@
 }
 
-psPolynomial3D* psPolynomial3DAlloc( unsigned int nX,
-                                     unsigned int nY,
-                                     unsigned int nZ,
-                                     psPolynomialType type)
+psPolynomial3D* psPolynomial3DAlloc(
+    psPolynomialType type,
+    unsigned int nX,
+    unsigned int nY,
+    unsigned int nZ)
 {
     //PS_ASSERT_INT_NONNEGATIVE(nX, NULL);
@@ -724,9 +726,10 @@
 }
 
-psPolynomial4D* psPolynomial4DAlloc( unsigned int nX,
-                                     unsigned int nY,
-                                     unsigned int nZ,
-                                     unsigned int nT,
-                                     psPolynomialType type)
+psPolynomial4D* psPolynomial4DAlloc(
+    psPolynomialType type,
+    unsigned int nX,
+    unsigned int nY,
+    unsigned int nZ,
+    unsigned int nT)
 {
     //PS_ASSERT_INT_NONNEGATIVE(nX, NULL);
Index: trunk/psLib/src/math/psPolynomial.h
===================================================================
--- trunk/psLib/src/math/psPolynomial.h	(revision 6199)
+++ trunk/psLib/src/math/psPolynomial.h	(revision 6204)
@@ -11,6 +11,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.60 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-01-23 22:25:31 $
+ *  @version $Revision: 1.61 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-01-26 21:10:22 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -127,6 +127,6 @@
  */
 psPolynomial1D* psPolynomial1DAlloc(
-    unsigned int n,                    ///< Number of terms
-    psPolynomialType type              ///< Polynomial Type
+    psPolynomialType type,             ///< Polynomial Type
+    unsigned int nX                    ///< Number of terms
 );
 
@@ -136,30 +136,30 @@
  */
 psPolynomial2D* psPolynomial2DAlloc(
+    psPolynomialType type,             ///< Polynomial Type
+    unsigned int nX,                   ///< Number of terms in x
+    unsigned int nY                    ///< Number of terms in y
+);
+
+/** Allocates a 3-D polynomial structure
+ *
+ *  @return  psPolynomial3D*    new 3-D polynomial struct
+ */
+psPolynomial3D* psPolynomial3DAlloc(
+    psPolynomialType type,             ///< Polynomial Type
     unsigned int nX,                   ///< Number of terms in x
     unsigned int nY,                   ///< Number of terms in y
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a 3-D polynomial structure
- *
- *  @return  psPolynomial3D*    new 3-D polynomial struct
- */
-psPolynomial3D* psPolynomial3DAlloc(
+    unsigned int nZ                    ///< Number of terms in z
+);
+
+/** Allocates a 4-D polynomial structure
+ *
+ *  @return  psPolynomial4D*    new 4-D polynomial struct
+ */
+psPolynomial4D* psPolynomial4DAlloc(
+    psPolynomialType type,             ///< Polynomial Type
     unsigned int nX,                   ///< Number of terms in x
     unsigned int nY,                   ///< Number of terms in y
     unsigned int nZ,                   ///< Number of terms in z
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a 4-D polynomial structure
- *
- *  @return  psPolynomial4D*    new 4-D polynomial struct
- */
-psPolynomial4D* psPolynomial4DAlloc(
-    unsigned int nX,                   ///< Number of terms in x
-    unsigned int nY,                   ///< Number of terms in y
-    unsigned int nZ,                   ///< Number of terms in z
-    unsigned int nT,                   ///< Number of terms in t
-    psPolynomialType type              ///< Polynomial Type
+    unsigned int nT                    ///< Number of terms in t
 );
 
Index: trunk/psLib/src/math/psSpline.c
===================================================================
--- trunk/psLib/src/math/psSpline.c	(revision 6199)
+++ trunk/psLib/src/math/psSpline.c	(revision 6204)
@@ -7,6 +7,6 @@
 *  splines.
 *
-*  @version $Revision: 1.133 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-01-23 22:25:31 $
+*  @version $Revision: 1.134 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-01-26 21:10:22 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -507,5 +507,5 @@
     spline->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *));
     for (psS32 i=0;i<numSplines;i++) {
-        spline->spline[i] = psPolynomial1DAlloc(3, PS_POLYNOMIAL_ORD);
+        spline->spline[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 3);
     }
 
Index: trunk/psLib/src/math/psStats.c
===================================================================
--- trunk/psLib/src/math/psStats.c	(revision 6199)
+++ trunk/psLib/src/math/psStats.c	(revision 6204)
@@ -14,6 +14,6 @@
  *      stats->binsize
  *
- *  @version $Revision: 1.161 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-01-26 00:31:19 $
+ *  @version $Revision: 1.162 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-01-26 21:10:22 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -1457,5 +1457,5 @@
     psVector *y = psVectorAlloc(3, PS_TYPE_F64);
     psVector *yErr = psVectorAlloc(3, PS_TYPE_F64);
-    psPolynomial1D *myPoly = psPolynomial1DAlloc(2, PS_POLYNOMIAL_ORD);
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 2);
 
     psF32 tmpFloat = 0.0f;
