Index: /trunk/psLib/src/astro/psCoord.c
===================================================================
--- /trunk/psLib/src/astro/psCoord.c	(revision 5577)
+++ /trunk/psLib/src/astro/psCoord.c	(revision 5578)
@@ -10,6 +10,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.91 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-11-22 21:40:40 $
+*  @version $Revision: 1.92 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-11-23 00:59:58 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -25,4 +25,5 @@
 #include "psError.h"
 #include "psLogMsg.h"
+#include "psTrace.h"
 #include "psErrorText.h"
 #include "psMatrix.h"
@@ -517,14 +518,12 @@
                                        psPolynomial2D *trans2)
 {
-    printf("multiplyDPoly2D(%d %d: %d %d)\n", trans1->nX, trans1->nY, trans2->nX, trans2->nY);
-    // XXX: OLD:  psS32 orderX = (trans1->nX + trans2->nX) - 1;
-    // XXX: Verify this (the poly order change)
+    psTrace(__func__, 4, "---- %s() begin ----\n", __func__);
+    psTrace(__func__, 5, "multiplyDPoly2D(%d %d: %d %d)\n", trans1->nX, trans1->nY, trans2->nX, trans2->nY);
     psS32 orderX = trans1->nX + trans2->nX;
     psS32 orderY = trans1->nY + trans2->nY;
-    printf("out poly (nX, nY) is (%d, %d)\n", orderX, orderY);
-
-    // XXX: Verify this (the poly order change)
+    psTrace(__func__, 5, "out poly (nX, nY) is (%d, %d)\n", orderX, orderY);
+
     psPolynomial2D *out = psPolynomial2DAlloc(orderX, orderY, PS_POLYNOMIAL_ORD);
-    //TRACE: printf("Creating poly (%d, %d)\n", orderX, orderY);
+    psTrace(__func__, 5, "Creating poly (%d, %d)\n", orderX, orderY);
 
     for (psS32 t1x = 0 ; t1x < (1 + trans1->nX) ; t1x++) {
@@ -545,4 +544,5 @@
         }
     }
+    psTrace(__func__, 4, "---- %s() end ----\n", __func__);
     return(out);
 }
@@ -562,38 +562,30 @@
     int nSamples)
 {
+    psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
+    psTrace(__func__, 3, "tracelevel(%s) is %d\n", __func__, psTraceGetLevel(__func__));
+
     PS_ASSERT_PTR_NON_NULL(trans1, NULL);
     PS_ASSERT_PTR_NON_NULL(trans2, NULL);
-    printf("-------------------------------------------------------------------------------\n");
-    printf("psPlaneTransformCombine(%d, %d) (%d, %d) (%d, %d) (%d, %d)\n",
-           trans1->x->nX, trans1->x->nY, trans1->y->nX, trans1->y->nY,
-           trans2->x->nX, trans2->x->nY, trans2->y->nX, trans2->y->nY);
-    printf("trans1->x is (%d, %d) order.\n", trans1->x->nX, trans1->x->nY);
-    printf("trans1->y is (%d, %d) order.\n", trans1->y->nX, trans1->y->nY);
-    printf("trans2->x is (%d, %d) order.\n", trans2->x->nX, trans2->x->nY);
-    printf("trans2->y is (%d, %d) order.\n", trans2->y->nX, trans2->y->nY);
+    psTrace(__func__, 5, "trans1->x is (%d, %d) order.\n", trans1->x->nX, trans1->x->nY);
+    psTrace(__func__, 5, "trans1->y is (%d, %d) order.\n", trans1->y->nX, trans1->y->nY);
+    psTrace(__func__, 5, "trans2->x is (%d, %d) order.\n", trans2->x->nX, trans2->x->nY);
+    psTrace(__func__, 5, "trans2->y is (%d, %d) order.\n", trans2->y->nX, trans2->y->nY);
+    if (psTraceGetLevel(__func__) >= 6) {
+        PS_POLY_PRINT_2D(trans1->x);
+        PS_POLY_PRINT_2D(trans1->y);
+        PS_POLY_PRINT_2D(trans2->x);
+        PS_POLY_PRINT_2D(trans2->y);
+    }
+
     //
     // Determine the size of the new psPlaneTransform.
     //
-    psS32 orderXnX = PS_MAX((trans2->x->nX * trans1->x->nX),
-                            (trans2->x->nY * trans1->y->nX));
-    psS32 orderXnY = PS_MAX((trans2->x->nX * trans1->x->nY),
-                            (trans2->x->nY * trans1->y->nY));
-
-    psS32 orderYnX = PS_MAX((trans2->y->nX * trans1->x->nX),
-                            (trans2->y->nY * trans1->y->nX));
-    psS32 orderYnY = PS_MAX((trans2->y->nX * trans1->x->nY),
-                            (trans2->y->nY * trans1->y->nY));
+    psS32 orderXnX = (trans2->x->nX * trans1->x->nX) + (trans2->x->nY * trans1->y->nX);
+    psS32 orderXnY = (trans2->x->nX * trans1->x->nY) + (trans2->x->nY * trans1->y->nY);
+    psS32 orderYnX = (trans2->y->nX * trans1->x->nX) + (trans2->y->nY * trans1->y->nX);
+    psS32 orderYnY = (trans2->y->nX * trans1->x->nY) + (trans2->y->nY * trans1->y->nY);
     psS32 orderX = PS_MAX(orderXnX, orderYnX);
     psS32 orderY = PS_MAX(orderXnY, orderYnY);
-    printf("OLD (orderX, orderY) is (%d, %d)\n", orderX, orderY);
-
-    orderXnX = (trans2->x->nX * trans1->x->nX) + (trans2->x->nY * trans1->y->nX);
-    orderXnY = (trans2->x->nX * trans1->x->nY) + (trans2->x->nY * trans1->y->nY);
-    orderYnX = (trans2->y->nX * trans1->x->nX) + (trans2->y->nY * trans1->y->nX);
-    orderYnY = (trans2->y->nX * trans1->x->nY) + (trans2->y->nY * trans1->y->nY);
-    orderX = PS_MAX(orderXnX, orderYnX);
-    orderY = PS_MAX(orderXnY, orderYnY);
-    printf("(orderX, orderY) is (%d, %d)\n", orderX, orderY);
-
+    psTrace(__func__, 5, "The new (orderX, orderY) is (%d, %d)\n", orderX, orderY);
 
     //
@@ -626,5 +618,5 @@
         }
     }
-    printf("New polynomial is (%d %d %d %d)\n", myPT->x->nX, myPT->x->nY, myPT->y->nX, myPT->y->nY);
+    psTrace(__func__, 5, "New polynomial ranks are (%d %d %d %d)\n", myPT->x->nX, myPT->x->nY, myPT->y->nX, myPT->y->nY);
 
     //
@@ -638,57 +630,24 @@
     //
 
+    //
+    // Determine the new x-polynomial
+    //
+    psTrace(__func__, 5, "Determine the new x-polynomial\n");
     for (psS32 t2x = 0 ; t2x < (1 + trans2->x->nX) ; t2x++) {
-        for (psS32 t2y = 0 ; t2y < (1 + trans2->x->nX) ; t2y++) {
-            printf("-------------------- (t2x, t2y) (%d, %d) --------------------\n", t2x, t2y);
-            // XXX: Verify this (poly order/nterm change)
-            psPolynomial2D *currPoly = psPolynomial2DAlloc(0, 0, PS_POLYNOMIAL_ORD);
-
-            currPoly->coeff[0][0] = 1.0;
-            currPoly->mask[0][0] = 0;
-            psPolynomial2D *newPoly = NULL;
-
+        for (psS32 t2y = 0 ; t2y < (1 + trans2->x->nY) ; t2y++) {
+            psTrace(__func__, 6, "X: -------------------- (t2x, t2y) (%d, %d) --------------------\n", t2x, t2y);
             if (trans2->x->mask[t2x][t2y] == 0) {
-                // Must raise trans1->y to the (t2y-1)-power.
-                for (psS32 c = 0 ; c < t2y-1; c++) {
-                    newPoly = multiplyDPoly2D(currPoly, trans1->y);
-                    psFree(currPoly);
-                    currPoly = newPoly;
-                }
-
-                // Must raise trans1->x to the (t2x-1)-power.
-                for (psS32 c = 0 ; c < t2x-1; c++) {
+                psTrace(__func__, 6, "In this iteration, we raise trans1->x to the %d power and trans1->y to the %d-power.\n", t2x, t2y);
+                // Create the constant "f(x, y) = 1" polynomial.
+                psPolynomial2D *currPoly = psPolynomial2DAlloc(0, 0, PS_POLYNOMIAL_ORD);
+                currPoly->coeff[0][0] = 1.0;
+
+                psPolynomial2D *newPoly = NULL;
+                // Must raise trans1->x to the t2x-power.
+                for (psS32 c = 0 ; c < t2x; c++) {
                     newPoly = multiplyDPoly2D(currPoly, trans1->x);
                     psFree(currPoly);
                     currPoly = newPoly;
                 }
-                printf("trans1->x is (%d, %d) order.\n", trans1->x->nX, trans1->x->nY);
-                printf("trans1->x was raised to the %d power.\n", t2x);
-                printf("trans1->y is (%d, %d) order.\n", trans1->y->nX, trans1->y->nY);
-                printf("trans1->y was raised to the %d power.\n", t2y);
-                printf("HERE 00\n");
-                printf("HEY (%d, %d) (%d, %d)\n", myPT->x->nX, myPT->x->nY, currPoly->nX, currPoly->nY);
-                // Set the appropriate coeffs in myPT->x
-                for (psS32 i = 0 ; i < (1 + currPoly->nX) ; i++) {
-                    for (psS32 j = 0 ; j < (1 + currPoly->nY) ; j++) {
-                        //                        printf("    HMMM (%d, %d)\n", i, j);
-                        myPT->x->coeff[i][j]+= currPoly->coeff[i][j] * trans2->x->coeff[t2x][t2y];
-                    }
-                }
-                printf("HERE 01\n");
-            }
-            psFree(currPoly);
-        }
-    }
-
-
-    for (psS32 t2x = 0 ; t2x < (1 + trans2->y->nX) ; t2x++) {
-        for (psS32 t2y = 0 ; t2y < (1 + trans2->y->nY) ; t2y++) {
-            // XXX: Verify this (poly order/nterm change)
-            psPolynomial2D *currPoly = psPolynomial2DAlloc(1-1, 1-1, PS_POLYNOMIAL_ORD);
-            currPoly->coeff[0][0] = 1.0;
-            currPoly->mask[0][0] = 0;
-            psPolynomial2D *newPoly = NULL;
-
-            if (trans2->y->mask[t2x][t2y] == 0) {
 
                 // Must raise trans1->y to the t2y-power.
@@ -698,5 +657,40 @@
                     currPoly = newPoly;
                 }
-
+                if (psTraceGetLevel(__func__) >= 6) {
+                    PS_POLY_PRINT_2D(currPoly);
+                }
+
+                // Set the appropriate coeffs in myPT->x
+                for (psS32 i = 0 ; i < (1 + currPoly->nX) ; i++) {
+                    for (psS32 j = 0 ; j < (1 + currPoly->nY) ; j++) {
+                        myPT->x->coeff[i][j]+= currPoly->coeff[i][j] * trans2->x->coeff[t2x][t2y];
+                    }
+                }
+                if (psTraceGetLevel(__func__) >= 6) {
+                    PS_POLY_PRINT_2D(myPT->x);
+                }
+                psFree(currPoly);
+            }
+        }
+    }
+    if (psTraceGetLevel(__func__) >= 6) {
+        psTrace(__func__, 6, "The final x-polynomial\n");
+        PS_POLY_PRINT_2D(myPT->x);
+    }
+
+    //
+    // Determine the new y-polynomial
+    //
+    psTrace(__func__, 5, "Determine the new y-polynomial\n");
+    for (psS32 t2x = 0 ; t2x < (1 + trans2->y->nX) ; t2x++) {
+        for (psS32 t2y = 0 ; t2y < (1 + trans2->y->nY) ; t2y++) {
+            psTrace(__func__, 5, "Y: -------------------- (t2x, t2y) (%d, %d) --------------------\n", t2x, t2y);
+            if (trans2->y->mask[t2x][t2y] == 0) {
+                psTrace(__func__, 5, "In this iteration, we raise trans1->x to the %d power and trans1->y to the %d-power.\n", t2x, t2y);
+                // Create the constant "f(x, y) = 1" polynomial.
+                psPolynomial2D *currPoly = psPolynomial2DAlloc(0, 0, PS_POLYNOMIAL_ORD);
+                currPoly->coeff[0][0] = 1.0;
+
+                psPolynomial2D *newPoly = NULL;
                 // Must raise trans1->x to the t2x-power.
                 for (psS32 c = 0 ; c < t2x; c++) {
@@ -706,4 +700,14 @@
                 }
 
+                // Must raise trans1->y to the t2y-power.
+                for (psS32 c = 0 ; c < t2y; c++) {
+                    newPoly = multiplyDPoly2D(currPoly, trans1->y);
+                    psFree(currPoly);
+                    currPoly = newPoly;
+                }
+                if (psTraceGetLevel(__func__) >= 6) {
+                    PS_POLY_PRINT_2D(currPoly);
+                }
+
                 // Set the appropriate coeffs in myPT->x
                 for (psS32 i = 0 ; i < (1 + currPoly->nX) ; i++) {
@@ -712,10 +716,17 @@
                     }
                 }
+                if (psTraceGetLevel(__func__) >= 6) {
+                    PS_POLY_PRINT_2D(myPT->x);
+                }
+                psFree(currPoly);
             }
-            psFree(currPoly);
-        }
-    }
-
-    //TRACE: printf("Exiting combine()\n");
+        }
+    }
+    if (psTraceGetLevel(__func__) >= 6) {
+        psTrace(__func__, 6, "The final y-polynomial\n");
+        PS_POLY_PRINT_2D(myPT->y);
+    }
+
+    psTrace(__func__, 3, "---- %s() end ----\n", __func__);
     return(myPT);
 }
Index: /trunk/psLib/test/astro/Makefile.am
===================================================================
--- /trunk/psLib/test/astro/Makefile.am	(revision 5577)
+++ /trunk/psLib/test/astro/Makefile.am	(revision 5578)
@@ -7,4 +7,5 @@
 TESTS =  \
 	tst_psCoord01 \
+	tst_psCoord02 \
 	tst_psTime_01 \
 	tst_psTime_02 \
@@ -22,4 +23,5 @@
 tst_psSphereOps_SOURCES = tst_psSphereOps.c
 tst_psCoord01_SOURCES = tst_psCoord01.c
+tst_psCoord02_SOURCES = tst_psCoord02.c
 tst_psEarthOrientation_SOURCES = tst_psEarthOrientation.c
 
