Index: trunk/psLib/src/astro/psCoord.c
===================================================================
--- trunk/psLib/src/astro/psCoord.c	(revision 5087)
+++ trunk/psLib/src/astro/psCoord.c	(revision 5090)
@@ -10,6 +10,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.86 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-09-11 22:18:40 $
+*  @version $Revision: 1.87 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-09-22 02:47:16 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -90,15 +90,15 @@
 
     A = transform->x->coeff[0][0];
-    if (transform->x->nX >= 2) {
+    if (transform->x->COOL_2D_nX >= 1) {
         B = transform->x->coeff[1][0];
     }
-    if (transform->x->nY >= 2) {
+    if (transform->x->COOL_2D_nY >= 1) {
         C = transform->x->coeff[0][1];
     }
     D = transform->y->coeff[0][0];
-    if (transform->y->nX >= 2) {
+    if (transform->y->COOL_2D_nX >= 1) {
         E = transform->y->coeff[1][0];
     }
-    if (transform->y->nY >= 2) {
+    if (transform->y->COOL_2D_nY >= 1) {
         F = transform->y->coeff[0][1];
     }
@@ -154,6 +154,6 @@
     PS_ASSERT_PTR_NON_NULL(transform->y, 0);
 
-    for (psS32 i=0;i<(transform->x->nX);i++) {
-        for (psS32 j=0;j<(transform->x->nY);j++) {
+    for (psS32 i=0;i<(1 + transform->x->COOL_2D_nX);i++) {
+        for (psS32 j=0;j<(1 + transform->x->COOL_2D_nY);j++) {
             if (transform->x->coeff[i][j] != 0.0) {
                 if (!(((i == 0) && (j == 0)) ||
@@ -166,6 +166,6 @@
     }
 
-    for (psS32 i=0;i<(transform->y->nX);i++) {
-        for (psS32 j=0;j<(transform->y->nY);j++) {
+    for (psS32 i=0;i<(1 + transform->y->COOL_2D_nX);i++) {
+        for (psS32 j=0;j<(1 + transform->y->COOL_2D_nY);j++) {
             if (transform->y->coeff[i][j] != 0.0) {
                 if (!(((i == 0) && (j == 0)) ||
@@ -208,4 +208,5 @@
 }
 
+// XXX: Verify the order/nterms poly changes
 psPlaneTransform* psPlaneTransformAlloc(int n1, int n2)
 {
@@ -214,6 +215,6 @@
 
     psPlaneTransform *pt = psAlloc(sizeof(psPlaneTransform));
-    pt->x = psPolynomial2DAlloc(n1, n2, PS_POLYNOMIAL_ORD);
-    pt->y = psPolynomial2DAlloc(n1, n2, PS_POLYNOMIAL_ORD);
+    pt->x = psPolynomial2DAlloc(n1-1, n2-1, PS_POLYNOMIAL_ORD);
+    pt->y = psPolynomial2DAlloc(n1-1, n2-1, PS_POLYNOMIAL_ORD);
 
     psMemSetDeallocator(pt, (psFreeFunc) planeTransformFree);
@@ -276,4 +277,5 @@
 }
 
+// XXX: Verify the order/nterms poly changes
 psPlaneDistort* psPlaneDistortAlloc(int n1, int n2, int n3, int n4)
 {
@@ -284,6 +286,6 @@
 
     psPlaneDistort *pt = psAlloc(sizeof(psPlaneDistort));
-    pt->x = psPolynomial4DAlloc(n1, n2, n3, n4, PS_POLYNOMIAL_ORD);
-    pt->y = psPolynomial4DAlloc(n1, n2, n3, n4, PS_POLYNOMIAL_ORD);
+    pt->x = psPolynomial4DAlloc(n1-1, n2-1, n3-1, n4-1, PS_POLYNOMIAL_ORD);
+    pt->y = psPolynomial4DAlloc(n1-1, n2-1, n3-1, n4-1, PS_POLYNOMIAL_ORD);
 
     psMemSetDeallocator(pt, (psFreeFunc) planeDistortFree);
@@ -499,12 +501,15 @@
                                        psPolynomial2D *trans2)
 {
-    //TRACE: printf("multiplyDPoly2D(%d %d: %d %d)\n", trans1->nX, trans1->nY, trans2->nX, trans2->nY);
-    psS32 orderX = (trans1->nX + trans2->nX) - 1;
-    psS32 orderY = (trans1->nY + trans2->nY) - 1;
-
-    psPolynomial2D *out = psPolynomial2DAlloc(orderX, orderY, PS_POLYNOMIAL_ORD);
+    //TRACE: printf("multiplyDPoly2D(%d %d: %d %d)\n", trans1->COOL_2D_nX, trans1->COOL_2D_nY, trans2->COOL_2D_nX, trans2->COOL_2D_nY);
+    // XXX: OLD:  psS32 orderX = (trans1->nX + trans2->nX) - 1;
+    // XXX: Verify this (the poly order change)
+    psS32 orderX = trans1->COOL_2D_nX + trans2->COOL_2D_nX + 1;
+    psS32 orderY = trans1->COOL_2D_nY + trans2->COOL_2D_nY + 1;
+
+    // XXX: Verify this (the poly order change)
+    psPolynomial2D *out = psPolynomial2DAlloc(orderX-1, orderY-1, PS_POLYNOMIAL_ORD);
     //TRACE: printf("Creating poly (%d, %d)\n", orderX, orderY);
-    for (psS32 i = 0 ; i < out->nX; i++) {
-        for (psS32 j = 0 ; j < out->nY; j++) {
+    for (psS32 i = 0 ; i < (1 + out->COOL_2D_nX); i++) {
+        for (psS32 j = 0 ; j < (1 + out->COOL_2D_nY); j++) {
             out->coeff[i][j] = 0.0;
             out->mask[i][j] = 0;
@@ -512,9 +517,9 @@
     }
 
-    for (psS32 t1x = 0 ; t1x < trans1->nX ; t1x++) {
-        for (psS32 t1y = 0 ; t1y < trans1->nY ; t1y++) {
+    for (psS32 t1x = 0 ; t1x < (1 + trans1->COOL_2D_nX) ; t1x++) {
+        for (psS32 t1y = 0 ; t1y < (1 + trans1->COOL_2D_nY) ; t1y++) {
             if (0.0 != trans1->coeff[t1x][t1y]) {
-                for (psS32 t2x = 0 ; t2x < trans2->nX ; t2x++) {
-                    for (psS32 t2y = 0 ; t2y < trans2->nY ; t2y++) {
+                for (psS32 t2x = 0 ; t2x < (1 + trans2->COOL_2D_nX) ; t2x++) {
+                    for (psS32 t2y = 0 ; t2y < (1 + trans2->COOL_2D_nY) ; t2y++) {
                         /* Possible debug-only macro which checks these coords?
                         if ((t1x+t2x) >= orderX)
@@ -547,5 +552,5 @@
     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->nX, trans2->x->nY, trans2->y->nX, trans2->y->nY);
+    //TRACE: printf("psPlaneTransformCombine(%d, %d, %d, %d: %d, %d, %d, %d)\n", trans1->x->COOL_2D_nX, trans1->x->COOL_2D_nY, trans1->y->COOL_2D_nX, trans1->y->COOL_2D_nY, trans2->x->COOL_2D_nX, trans2->x->COOL_2D_nY, trans2->y->COOL_2D_nX, trans2->y->COOL_2D_nY);
     //
     // Determine the size of the new psPlaneTransform.
@@ -553,13 +558,13 @@
     // 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((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 = PS_MAX(((1 + trans2->x->COOL_2D_nX) * (1 + trans1->x->COOL_2D_nX)),
+                            ((1 + trans2->x->COOL_2D_nY) * (1 + trans1->y->COOL_2D_nX)));
+    psS32 orderXnY = PS_MAX(((1 + trans2->x->COOL_2D_nX) * (1 + trans1->x->COOL_2D_nY)),
+                            ((1 + trans2->x->COOL_2D_nY) * (1 + trans1->y->COOL_2D_nY)));
+
+    psS32 orderYnX = PS_MAX(((1 + trans2->y->COOL_2D_nX) * (1 + trans1->x->COOL_2D_nX)),
+                            ((1 + trans2->y->COOL_2D_nY) * (1 + trans1->y->COOL_2D_nX)));
+    psS32 orderYnY = PS_MAX(((1 + trans2->y->COOL_2D_nX) * (1 + trans1->x->COOL_2D_nY)),
+                            ((1 + trans2->y->COOL_2D_nY) * (1 + trans1->y->COOL_2D_nY)));
     psS32 orderX = PS_MAX(orderXnX, orderYnX);
     psS32 orderY = PS_MAX(orderXnY, orderYnY);
@@ -568,10 +573,11 @@
     // Allocate the new psPlaneTransform, if necessary.
     //
+    // XXX: rename, or verify, or recode, after the poly norder/nterm change.
     psPlaneTransform *myPT = NULL;
     if (out == NULL) {
         myPT = psPlaneTransformAlloc(orderX, orderY);
     } else {
-        if ((out->x->nX == orderX) && (out->x->nY == orderY) &&
-                (out->y->nX == orderX) && (out->y->nY == orderY)) {
+        if (((1 + out->x->COOL_2D_nX) == orderX) && ((1 + out->x->COOL_2D_nY) == orderY) &&
+                ((1 + out->y->COOL_2D_nX) == orderX) && ((1 + out->y->COOL_2D_nY) == orderY)) {
             myPT = out;
         } else {
@@ -603,7 +609,8 @@
     //
 
-    for (psS32 t2x = 0 ; t2x < trans2->x->nX ; t2x++) {
-        for (psS32 t2y = 0 ; t2y < trans2->x->nY ; t2y++) {
-            psPolynomial2D *currPoly = psPolynomial2DAlloc(1, 1, PS_POLYNOMIAL_ORD);
+    for (psS32 t2x = 0 ; t2x < (1 + trans2->x->COOL_2D_nX) ; t2x++) {
+        for (psS32 t2y = 0 ; t2y < (1 + trans2->x->COOL_2D_nX) ; t2y++) {
+            // XXX: Verify this (poly order/nterm change)
+            psPolynomial2D *currPoly = psPolynomial2DAlloc(1-1, 1-1, PS_POLYNOMIAL_ORD);
 
             currPoly->coeff[0][0] = 1.0;
@@ -627,6 +634,6 @@
 
                 // Set the appropriate coeffs in myPT->x
-                for (psS32 i = 0 ; i < currPoly->nX ; i++) {
-                    for (psS32 j = 0 ; j < currPoly->nY ; j++) {
+                for (psS32 i = 0 ; i < (1 + currPoly->COOL_2D_nX) ; i++) {
+                    for (psS32 j = 0 ; j < (1 + currPoly->COOL_2D_nY) ; j++) {
                         myPT->x->coeff[i][j]+= currPoly->coeff[i][j] * trans2->x->coeff[t2x][t2y];
                     }
@@ -638,7 +645,8 @@
 
 
-    for (psS32 t2x = 0 ; t2x < trans2->y->nX ; t2x++) {
-        for (psS32 t2y = 0 ; t2y < trans2->y->nY ; t2y++) {
-            psPolynomial2D *currPoly = psPolynomial2DAlloc(1, 1, PS_POLYNOMIAL_ORD);
+    for (psS32 t2x = 0 ; t2x < (1 + trans2->y->COOL_2D_nX) ; t2x++) {
+        for (psS32 t2y = 0 ; t2y < (1 + trans2->y->COOL_2D_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;
@@ -662,6 +670,6 @@
 
                 // Set the appropriate coeffs in myPT->x
-                for (psS32 i = 0 ; i < currPoly->nX ; i++) {
-                    for (psS32 j = 0 ; j < currPoly->nY ; j++) {
+                for (psS32 i = 0 ; i < (1 + currPoly->COOL_2D_nX) ; i++) {
+                    for (psS32 j = 0 ; j < (1 + currPoly->COOL_2D_nY) ; j++) {
                         myPT->y->coeff[i][j]+= currPoly->coeff[i][j] * trans2->y->coeff[t2x][t2y];
                     }
@@ -694,12 +702,15 @@
 
     psS32 numCoords = PS_MIN(source->n, dest->n);
-    psS32 order = PS_MAX(trans->x->nX, trans->x->nY);
-    order = PS_MAX(order, trans->y->nX);
-    order = PS_MAX(order, trans->y->nY);
+    psS32 order = PS_MAX(trans->x->COOL_2D_nX, trans->x->COOL_2D_nY);
+    order = PS_MAX(order, trans->y->COOL_2D_nX);
+    order = PS_MAX(order, trans->y->COOL_2D_nY);
+    // XXX: Verify, or recode, after the poly norder/nterm change.
+    order++;
 
     //
     // Create fake polynomial to use in evaluation
     //
-    psPolynomial2D *fakePoly = psPolynomial2DAlloc(order, order, PS_POLYNOMIAL_ORD);
+    // XXX: Verify this (poly order/nterm change)
+    psPolynomial2D *fakePoly = psPolynomial2DAlloc(order-1, order-1, PS_POLYNOMIAL_ORD);
     for (int i = 0; i < order; i++) {
         for (int j = 0; j < order; j++) {
@@ -811,10 +822,11 @@
 
     // Ensure that the input transformation is symmetrical.
-    if ((in->x->nX != in->x->nY) ||
-            (in->y->nX != in->y->nY) ||
-            (in->x->nX != in->y->nX)) {
+    if ((in->x->COOL_2D_nX != in->x->COOL_2D_nY) ||
+            (in->y->COOL_2D_nX != in->y->COOL_2D_nY) ||
+            (in->x->COOL_2D_nX != in->y->COOL_2D_nX)) {
         psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Input transformation must have same nX==nY.");
     }
-    psS32 order = in->x->nX;
+    // XXX: recode or verify after poly changes
+    psS32 order = 1 + in->x->COOL_2D_nX;
 
     psPlaneTransform *myPT = NULL;
@@ -826,8 +838,10 @@
     //
     if (out == NULL) {
+        // XXX: Verify this (poly order/nterm change)
         myPT = psPlaneTransformAlloc(order, order);
     } else {
-        if ((out->x->nX == order) && (out->x->nY == order) &&
-                (out->y->nX == order) && (out->y->nY == order)) {
+        // XXX: recode or verify after poly changes
+        if (((1 + out->x->COOL_2D_nX) == order) && ((1 + out->x->COOL_2D_nY) == order) &&
+                ((1 + out->y->COOL_2D_nX) == order) && ((1 + out->y->COOL_2D_nX) == order)) {
             myPT = out;
         } else {
@@ -840,11 +854,11 @@
     // Copy the input transform to myPT.
     //
-    for (psS32 i = 0 ; i < in->x->nX ; i++) {
-        for (psS32 j = 0 ; j < in->x->nY ; j++) {
+    for (psS32 i = 0 ; i < (1 + in->x->COOL_2D_nX) ; i++) {
+        for (psS32 j = 0 ; j < (1 + in->x->COOL_2D_nY) ; j++) {
             myPT->x->coeff[i][j] = in->x->coeff[i][j];
         }
     }
-    for (psS32 i = 0 ; i < in->y->nX ; i++) {
-        for (psS32 j = 0 ; j < in->y->nY ; j++) {
+    for (psS32 i = 0 ; i < (1 + in->y->COOL_2D_nX) ; i++) {
+        for (psS32 j = 0 ; j < (1 + in->y->COOL_2D_nY) ; j++) {
             myPT->y->coeff[i][j] = in->y->coeff[i][j];
         }
@@ -926,7 +940,7 @@
 
     // This loop starts at loop_x=1 since the derivative of the loop_x=0 terms are all 0.0
-    for (psS32 loop_x = 1; loop_x < xPoly->nX; loop_x++) {
+    for (psS32 loop_x = 1; loop_x < (1 + xPoly->COOL_2D_nX); loop_x++) {
         ySum = 1.0;
-        for (psS32 loop_y = 0; loop_y < xPoly->nY; loop_y++) {
+        for (psS32 loop_y = 0; loop_y < (1 + xPoly->COOL_2D_nY); loop_y++) {
             //
             // For each iteration of the loop, we multiple the (x, y) coefficient
@@ -946,7 +960,7 @@
 
     // This loop starts at loop_y=1 since the derivative of the loop_y=0 terms are all 0.0
-    for (psS32 loop_x = 0; loop_x < yPoly->nX; loop_x++) {
+    for (psS32 loop_x = 0; loop_x < (1 + yPoly->COOL_2D_nX); loop_x++) {
         ySum = 1.0;
-        for (psS32 loop_y = 1; loop_y < yPoly->nY; loop_y++) {
+        for (psS32 loop_y = 1; loop_y < (1 + yPoly->COOL_2D_nY); loop_y++) {
             //
             // For each iteration of the loop, we multiple the (x, y) coefficient
