Index: /trunk/psLib/src/astro/psCoord.c
===================================================================
--- /trunk/psLib/src/astro/psCoord.c	(revision 5575)
+++ /trunk/psLib/src/astro/psCoord.c	(revision 5576)
@@ -10,6 +10,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.90 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-11-18 19:46:09 $
+*  @version $Revision: 1.91 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-11-22 21:40:40 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -140,4 +140,6 @@
     true: if linear
     false: otherwise
+ 
+Why isn't this called p_psIsPlaneTransformLinear()?
  *****************************************************************************/
 psBool p_psIsProjectionLinear(psPlaneTransform *transform)
@@ -324,5 +326,6 @@
 XXX: Private Function.
  
-piNormalize(): take an input angle in radians and convert it to the range 0:2*PI.
+piNormalize(): take an input angle in radians and convert it to the range
+0:2*PI.
  *****************************************************************************/
 psF32 piNormalize(psF32 angle)
@@ -454,6 +457,6 @@
 
     // Remove plate scales
-    psF64  x = coord->x/projection->Xs;
-    psF64  y = coord->y/projection->Ys;
+    psF64  x = coord->x * projection->Xs;
+    psF64  y = coord->y * projection->Ys;
 
     // Perform inverse projection
@@ -514,19 +517,14 @@
                                        psPolynomial2D *trans2)
 {
-    //TRACE: printf("multiplyDPoly2D(%d %d: %d %d)\n", trans1->nX, trans1->nY, trans2->nX, trans2->nY);
+    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)
-    psS32 orderX = trans1->nX + trans2->nX + 1;
-    psS32 orderY = trans1->nY + trans2->nY + 1;
+    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)
-    psPolynomial2D *out = psPolynomial2DAlloc(orderX-1, orderY-1, PS_POLYNOMIAL_ORD);
+    psPolynomial2D *out = psPolynomial2DAlloc(orderX, orderY, PS_POLYNOMIAL_ORD);
     //TRACE: printf("Creating poly (%d, %d)\n", orderX, orderY);
-    for (psS32 i = 0 ; i < (1 + out->nX); i++) {
-        for (psS32 j = 0 ; j < (1 + out->nY); j++) {
-            out->coeff[i][j] = 0.0;
-            out->mask[i][j] = 0;
-        }
-    }
 
     for (psS32 t1x = 0 ; t1x < (1 + trans1->nX) ; t1x++) {
@@ -557,29 +555,45 @@
 routine far too many times.
  *****************************************************************************/
-psPlaneTransform *psPlaneTransformCombine(psPlaneTransform *out,
-        const psPlaneTransform *trans1,
-        const psPlaneTransform *trans2,
-        psRegion region,
-        int nSamples)
+psPlaneTransform *psPlaneTransformCombine(
+    psPlaneTransform *out,
+    const psPlaneTransform *trans1,
+    const psPlaneTransform *trans2,
+    psRegion region,
+    int nSamples)
 {
     PS_ASSERT_PTR_NON_NULL(trans1, NULL);
     PS_ASSERT_PTR_NON_NULL(trans2, NULL);
-    //TRACE: 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->COOL_2D_nX, trans2->x->COOL_2D_nY, trans2->y->COOL_2D_nX, trans2->y->COOL_2D_nY);
+    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);
     //
     // Determine the size of the new psPlaneTransform.
     //
-    // PS_MAX(  Number of x terms in T2->x * number of x terms in T1->x,
-    //          Number of y terms in T2->x * number of x terms in T1->y,
-    psS32 orderXnX = PS_MAX(((1 + trans2->x->nX) * (1 + trans1->x->nX)),
-                            ((1 + trans2->x->nY) * (1 + trans1->y->nX)));
-    psS32 orderXnY = PS_MAX(((1 + trans2->x->nX) * (1 + trans1->x->nY)),
-                            ((1 + trans2->x->nY) * (1 + trans1->y->nY)));
-
-    psS32 orderYnX = PS_MAX(((1 + trans2->y->nX) * (1 + trans1->x->nX)),
-                            ((1 + trans2->y->nY) * (1 + trans1->y->nX)));
-    psS32 orderYnY = PS_MAX(((1 + trans2->y->nX) * (1 + trans1->x->nY)),
-                            ((1 + trans2->y->nY) * (1 + trans1->y->nY)));
+    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 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);
+
 
     //
@@ -591,7 +605,20 @@
         myPT = psPlaneTransformAlloc(orderX, orderY);
     } else {
-        if (((1 + out->x->nX) == orderX) && ((1 + out->x->nY) == orderY) &&
-                ((1 + out->y->nX) == orderX) && ((1 + out->y->nY) == orderY)) {
+        if ((out->x->nX == orderX) &&
+                (out->x->nY == orderY) &&
+                (out->y->nX == orderX) &&
+                (out->y->nY == orderY)) {
             myPT = out;
+            //
+            // Initialize the new psPlaneTransform, if necessary.
+            //
+            for (psS32 i = 0 ; i < orderX ; i++) {
+                for (psS32 j = 0 ; j < orderY ; j++) {
+                    myPT->x->coeff[i][j] = 0.0;
+                    myPT->x->mask[i][j] = 0;
+                    myPT->y->coeff[i][j] = 0.0;
+                    myPT->y->mask[i][j] = 0;
+                }
+            }
         } else {
             psFree(out);
@@ -599,16 +626,5 @@
         }
     }
-
-    //
-    // Initialize the new psPlaneTransform, if necessary.
-    //
-    for (psS32 i = 0 ; i < orderX ; i++) {
-        for (psS32 j = 0 ; j < orderY ; j++) {
-            myPT->x->coeff[i][j] = 0.0;
-            myPT->x->mask[i][j] = 0;
-            myPT->y->coeff[i][j] = 0.0;
-            myPT->y->mask[i][j] = 0;
-        }
-    }
+    printf("New polynomial is (%d %d %d %d)\n", myPT->x->nX, myPT->x->nY, myPT->y->nX, myPT->y->nY);
 
     //
@@ -624,6 +640,7 @@
     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(1-1, 1-1, PS_POLYNOMIAL_ORD);
+            psPolynomial2D *currPoly = psPolynomial2DAlloc(0, 0, PS_POLYNOMIAL_ORD);
 
             currPoly->coeff[0][0] = 1.0;
@@ -632,6 +649,6 @@
 
             if (trans2->x->mask[t2x][t2y] == 0) {
-                // Must raise trans1->y to the t2y-power.
-                for (psS32 c = 0 ; c < t2y; c++) {
+                // Must raise trans1->y to the (t2y-1)-power.
+                for (psS32 c = 0 ; c < t2y-1; c++) {
                     newPoly = multiplyDPoly2D(currPoly, trans1->y);
                     psFree(currPoly);
@@ -639,17 +656,24 @@
                 }
 
-                // Must raise trans1->x to the t2x-power.
-                for (psS32 c = 0 ; c < t2x; c++) {
+                // Must raise trans1->x to the (t2x-1)-power.
+                for (psS32 c = 0 ; c < t2x-1; 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);
Index: /trunk/psLib/src/math/psPolynomial.c
===================================================================
--- /trunk/psLib/src/math/psPolynomial.c	(revision 5575)
+++ /trunk/psLib/src/math/psPolynomial.c	(revision 5576)
@@ -7,6 +7,6 @@
 *  polynomials.  It also contains a Gaussian functions.
 *
-*  @version $Revision: 1.131 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-11-18 19:39:29 $
+*  @version $Revision: 1.132 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-11-22 21:40:40 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -725,9 +725,10 @@
 }
 
-psPolynomial4D* psPolynomial4DAlloc( unsigned int nX,
-                                     unsigned int nY,
-                                     unsigned int nZ,
-                                     unsigned int nT,
-                                     psPolynomialType type)
+psPolynomial4D* psPolynomial4DAlloc(
+    unsigned int nX,
+    unsigned int nY,
+    unsigned int nZ,
+    unsigned int nT,
+    psPolynomialType type)
 {
     PS_ASSERT_INT_NONNEGATIVE(nX, NULL);
Index: /trunk/psLib/src/math/psStats.c
===================================================================
--- /trunk/psLib/src/math/psStats.c	(revision 5575)
+++ /trunk/psLib/src/math/psStats.c	(revision 5576)
@@ -17,6 +17,6 @@
 *
 *
-*  @version $Revision: 1.153 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-11-22 01:18:13 $
+*  @version $Revision: 1.154 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-11-22 21:40:40 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
