Index: /trunk/psLib/src/dataManip/psMinimize.c
===================================================================
--- /trunk/psLib/src/dataManip/psMinimize.c	(revision 2907)
+++ /trunk/psLib/src/dataManip/psMinimize.c	(revision 2908)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.96 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-22 05:09:32 $
+ *  @version $Revision: 1.97 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-01-05 20:59:03 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -190,4 +190,9 @@
     n = spline->n;
     klo = p_psVectorBinDisect32(spline->domains, (spline->n)+1, X);
+    if (klo < 0) {
+        psLogMsg(__func__, PS_LOG_WARN,
+                 "WARNING: psMinimize.c: p_psNRSpline1DEval(): p_psVectorBinDisect32 returned an error (%d).\n", klo);
+        return(NAN);
+    }
     khi = klo + 1;
     H = (spline->domains)[khi] - (spline->domains)[klo];
@@ -245,7 +250,4 @@
                                 const psVector* restrict yErr)     ///< Errors in coordinates, or NULL
 {
-    PS_PTR_CHECK_NULL(mySpline, NULL);
-    PS_INT_CHECK_NON_NEGATIVE(mySpline->n, NULL);
-    PS_VECTOR_CHECK_NULL(x, NULL);
     PS_VECTOR_CHECK_NULL(y, NULL);
     PS_VECTOR_CHECK_TYPE_F32_OR_F64(y, NULL);
@@ -278,4 +280,5 @@
     // If x==NULL, create an x32 vector with x values set to (0:n).
     if (x == NULL) {
+
         PS_VECTOR_GEN_X_INDEX_STATIC_F32(x32Static, y->n);
         x32 = x32Static;
@@ -286,4 +289,18 @@
     PS_VECTOR_CHECK_SIZE_EQUAL(x32, y32, NULL);
     PS_VECTOR_CHECK_SIZE_EQUAL(yErr32, y32, NULL);
+
+    /*
+        XXX:
+        This can not be implemented until SDR states what order spline should be
+        created.
+     
+        Should we error if mySPline is not NULL?
+    */
+    if (mySpline == NULL) {
+        mySpline = psSpline1DAllocGeneric(x32, 3);
+    }
+    PS_PTR_CHECK_NULL(mySpline, NULL);
+    PS_INT_CHECK_NON_NEGATIVE(mySpline->n, NULL);
+
 
     if (y32->n != (1 + mySpline->n)) {
@@ -335,5 +352,7 @@
         H = x32->data.F32[i+1] - x32->data.F32[i];
         psTrace(".psLib.dataManip.psVectorFitSpline1D", 4,
-                "x data (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H);
+                "x data (%f - %f) (%f)\n",
+                x32->data.F32[i],
+                x32->data.F32[i+1], H);
         //
         // ******** Calculate 0-order term ********
@@ -429,5 +448,6 @@
         deriv = psImageAlloc(params->n, coords->n, PS_TYPE_F32);
     } else {
-        // XXX: Check size of derivative
+        PS_IMAGE_CHECK_SIZE(deriv, params->n, coords->n, NULL);
+        PS_IMAGE_CHECK_TYPE(deriv, PS_TYPE_F32, NULL);
     }
 
@@ -499,4 +519,5 @@
     } else {
         PS_IMAGE_CHECK_SIZE(deriv, 6, coords->n, NULL);
+        PS_IMAGE_CHECK_TYPE(deriv, PS_TYPE_F32, NULL);
     }
 
@@ -715,4 +736,6 @@
         // Solve A * alpha = Beta
         //
+        // XXX: How do we know if these functions were successful?
+        //
         aOut = psMatrixLUD(aOut, perm, A);
         paramDeltasF64 = psMatrixLUSolve(paramDeltasF64, aOut, beta, perm);
@@ -963,4 +986,5 @@
     }
 
+    // XXX: How do we know if these routines were successful?
     ALUD = psMatrixLUD(ALUD, outPerm, A);
     coeffs = psMatrixLUSolve(coeffs, ALUD, B, outPerm);
@@ -970,9 +994,4 @@
         // printf("myPoly->coeff[%d] is %f\n", k, myPoly->coeff[k]);
     }
-
-    // for (i=0;i<x->n;i++) {
-    // printf("HMMM: psEvalPolynomial1D(%f) is %f\n", x->data.F64[i], psEvalPolynomial1D(x->data.F64[i],
-    // myPoly));
-    // }
 
     psFree(A);
@@ -1008,5 +1027,4 @@
 
     psS32 i;
-    psPolynomial1D *tmpPoly;
     psVector *x64 = NULL;
     psVector *y64 = NULL;
@@ -1044,11 +1062,16 @@
 
     // Call the appropriate vector fitting routine.
+    psPolynomial1D *rc = NULL;
     if (myPoly->type == PS_POLYNOMIAL_CHEB) {
-        VectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64);
+        rc = VectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64);
     } else if (myPoly->type == PS_POLYNOMIAL_ORD) {
-        tmpPoly = VectorFitPolynomial1DOrd(myPoly, x64, y64, yErr64);
+        rc = VectorFitPolynomial1DOrd(myPoly, x64, y64, yErr64);
     } else {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                 "unknown polynomial type.\n");
+        return(NULL);
+    }
+    if (rc == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "Could not fit a polynomial to the data.  Returning NULL.\n");
         return(NULL);
     }
@@ -1448,5 +1471,5 @@
     if (bracket == NULL) {
         psError(PS_ERR_UNKNOWN, false,
-                "Could not bracket minimum.");
+                "Could not bracket minimum.  Returning NAN.\n");
         return(NAN);
     }
@@ -1636,5 +1659,5 @@
                 if (isnan(mul)) {
                     psError(PS_ERR_UNKNOWN, false,
-                            "Could not perform line minimization");
+                            "Could not perform line minimization.  Returning FALSE.\n");
                     psFree(v);
                     return(false);
@@ -1677,5 +1700,5 @@
         if (isnan(mul)) {
             psError(PS_ERR_UNKNOWN, false,
-                    "Could not perform line minimization.");
+                    "Could not perform line minimization.  Returning FALSE.\n");
             psFree(v);
             return(false);
Index: /trunk/psLib/src/math/psMinimize.c
===================================================================
--- /trunk/psLib/src/math/psMinimize.c	(revision 2907)
+++ /trunk/psLib/src/math/psMinimize.c	(revision 2908)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.96 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-22 05:09:32 $
+ *  @version $Revision: 1.97 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-01-05 20:59:03 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -190,4 +190,9 @@
     n = spline->n;
     klo = p_psVectorBinDisect32(spline->domains, (spline->n)+1, X);
+    if (klo < 0) {
+        psLogMsg(__func__, PS_LOG_WARN,
+                 "WARNING: psMinimize.c: p_psNRSpline1DEval(): p_psVectorBinDisect32 returned an error (%d).\n", klo);
+        return(NAN);
+    }
     khi = klo + 1;
     H = (spline->domains)[khi] - (spline->domains)[klo];
@@ -245,7 +250,4 @@
                                 const psVector* restrict yErr)     ///< Errors in coordinates, or NULL
 {
-    PS_PTR_CHECK_NULL(mySpline, NULL);
-    PS_INT_CHECK_NON_NEGATIVE(mySpline->n, NULL);
-    PS_VECTOR_CHECK_NULL(x, NULL);
     PS_VECTOR_CHECK_NULL(y, NULL);
     PS_VECTOR_CHECK_TYPE_F32_OR_F64(y, NULL);
@@ -278,4 +280,5 @@
     // If x==NULL, create an x32 vector with x values set to (0:n).
     if (x == NULL) {
+
         PS_VECTOR_GEN_X_INDEX_STATIC_F32(x32Static, y->n);
         x32 = x32Static;
@@ -286,4 +289,18 @@
     PS_VECTOR_CHECK_SIZE_EQUAL(x32, y32, NULL);
     PS_VECTOR_CHECK_SIZE_EQUAL(yErr32, y32, NULL);
+
+    /*
+        XXX:
+        This can not be implemented until SDR states what order spline should be
+        created.
+     
+        Should we error if mySPline is not NULL?
+    */
+    if (mySpline == NULL) {
+        mySpline = psSpline1DAllocGeneric(x32, 3);
+    }
+    PS_PTR_CHECK_NULL(mySpline, NULL);
+    PS_INT_CHECK_NON_NEGATIVE(mySpline->n, NULL);
+
 
     if (y32->n != (1 + mySpline->n)) {
@@ -335,5 +352,7 @@
         H = x32->data.F32[i+1] - x32->data.F32[i];
         psTrace(".psLib.dataManip.psVectorFitSpline1D", 4,
-                "x data (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H);
+                "x data (%f - %f) (%f)\n",
+                x32->data.F32[i],
+                x32->data.F32[i+1], H);
         //
         // ******** Calculate 0-order term ********
@@ -429,5 +448,6 @@
         deriv = psImageAlloc(params->n, coords->n, PS_TYPE_F32);
     } else {
-        // XXX: Check size of derivative
+        PS_IMAGE_CHECK_SIZE(deriv, params->n, coords->n, NULL);
+        PS_IMAGE_CHECK_TYPE(deriv, PS_TYPE_F32, NULL);
     }
 
@@ -499,4 +519,5 @@
     } else {
         PS_IMAGE_CHECK_SIZE(deriv, 6, coords->n, NULL);
+        PS_IMAGE_CHECK_TYPE(deriv, PS_TYPE_F32, NULL);
     }
 
@@ -715,4 +736,6 @@
         // Solve A * alpha = Beta
         //
+        // XXX: How do we know if these functions were successful?
+        //
         aOut = psMatrixLUD(aOut, perm, A);
         paramDeltasF64 = psMatrixLUSolve(paramDeltasF64, aOut, beta, perm);
@@ -963,4 +986,5 @@
     }
 
+    // XXX: How do we know if these routines were successful?
     ALUD = psMatrixLUD(ALUD, outPerm, A);
     coeffs = psMatrixLUSolve(coeffs, ALUD, B, outPerm);
@@ -970,9 +994,4 @@
         // printf("myPoly->coeff[%d] is %f\n", k, myPoly->coeff[k]);
     }
-
-    // for (i=0;i<x->n;i++) {
-    // printf("HMMM: psEvalPolynomial1D(%f) is %f\n", x->data.F64[i], psEvalPolynomial1D(x->data.F64[i],
-    // myPoly));
-    // }
 
     psFree(A);
@@ -1008,5 +1027,4 @@
 
     psS32 i;
-    psPolynomial1D *tmpPoly;
     psVector *x64 = NULL;
     psVector *y64 = NULL;
@@ -1044,11 +1062,16 @@
 
     // Call the appropriate vector fitting routine.
+    psPolynomial1D *rc = NULL;
     if (myPoly->type == PS_POLYNOMIAL_CHEB) {
-        VectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64);
+        rc = VectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64);
     } else if (myPoly->type == PS_POLYNOMIAL_ORD) {
-        tmpPoly = VectorFitPolynomial1DOrd(myPoly, x64, y64, yErr64);
+        rc = VectorFitPolynomial1DOrd(myPoly, x64, y64, yErr64);
     } else {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                 "unknown polynomial type.\n");
+        return(NULL);
+    }
+    if (rc == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "Could not fit a polynomial to the data.  Returning NULL.\n");
         return(NULL);
     }
@@ -1448,5 +1471,5 @@
     if (bracket == NULL) {
         psError(PS_ERR_UNKNOWN, false,
-                "Could not bracket minimum.");
+                "Could not bracket minimum.  Returning NAN.\n");
         return(NAN);
     }
@@ -1636,5 +1659,5 @@
                 if (isnan(mul)) {
                     psError(PS_ERR_UNKNOWN, false,
-                            "Could not perform line minimization");
+                            "Could not perform line minimization.  Returning FALSE.\n");
                     psFree(v);
                     return(false);
@@ -1677,5 +1700,5 @@
         if (isnan(mul)) {
             psError(PS_ERR_UNKNOWN, false,
-                    "Could not perform line minimization.");
+                    "Could not perform line minimization.  Returning FALSE.\n");
             psFree(v);
             return(false);
