Index: trunk/psLib/test/astronomy/tst_psAstrometry01.c
===================================================================
--- trunk/psLib/test/astronomy/tst_psAstrometry01.c	(revision 2981)
+++ trunk/psLib/test/astronomy/tst_psAstrometry01.c	(revision 2983)
@@ -5,6 +5,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-11-30 21:56:20 $
+*  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-01-13 22:45:40 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -21,5 +21,5 @@
                               {test1, 0000, "Tests psFixedPatternAlloc()", 0, false},
                               {test2, 0000, "Tests psGrommitAlloc()", 0, false},
-                              {test3, 0000, "psFunctionBar", 0, false},
+                              {test3, 0000, "MISC", 0, false},
                               {NULL}
                           };
@@ -189,5 +189,5 @@
     psLogSetLevel( PS_LOG_INFO );
 
-    return ( ! runTestSuite( stderr, "psImage", tests, argc, argv ) );
+    return ( ! runTestSuite( stderr, "psAstrometry", tests, argc, argv ) );
 }
 
@@ -440,5 +440,10 @@
 
                     if ((myCell == NULL) || (tmpChip == NULL)) {
-                        printf("ERROR: NULL\n");
+                        if (myCell == NULL) {
+                            printf("ERROR: myCell is NULL\n");
+                        }
+                        if (tmpChip == NULL) {
+                            printf("ERROR: tmpChip is NULL\n");
+                        }
                     } else {
                         psCoordFPAToChip(&chipCoord, &fpaCoord, tmpChip);
@@ -517,5 +522,7 @@
     }
 
+    printf("HERE 00\n");
     psFree(myFPA);
+    printf("HERE 01\n");
 
     return(0);
Index: trunk/psLib/test/astronomy/tst_psCoord.c
===================================================================
--- trunk/psLib/test/astronomy/tst_psCoord.c	(revision 2981)
+++ trunk/psLib/test/astronomy/tst_psCoord.c	(revision 2983)
@@ -6,6 +6,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-01-08 00:12:44 $
+*  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-01-13 22:45:40 $
 *
 *  XXX: Must test psSpherePrecess.
@@ -18,4 +18,5 @@
 #include "psTest.h"
 #include "pslib.h"
+/*
 static psS32 test1( void );
 static psS32 test1b( void );
@@ -24,4 +25,5 @@
 static psS32 test3( void );
 static psS32 test4( void );
+static psS32 test4b( void );
 static psS32 test5( void );
 static psS32 test6( void );
@@ -32,19 +34,27 @@
 static psS32 test40( void );
 static psS32 test41( void );
+static psS32 test43( void );
+*/
+static psS32 test42( void );
 testDescription tests[] = {
-                              {test1, 0000, "psSphereTransformAlloc()", 0, false},
-                              {test1b, 0000, "psPlaneTransformAlloc()", 0, false},
-                              {test1c, 0000, "psPlaneDistortAlloc()", 0, false},
-                              {test2, 0000, "psPlaneTransformApply()", 0, false},
-                              {test3, 0000, "psPlaneDistortApply()", 0, false},
-                              {test4, 0000, "psPSphereTransformApply()", 0, false},
-                              {test5, 0000, "psSphereTransformICRSToEcliptic()", 0, false},
-                              {test6, 0000, "psSphereTransformEclipticToICRS()", 0, false},
-                              {test7, 0000, "psSphereTransformICRSToGalatic()", 0, false},
-                              {test8, 0000, "psSphereTransformGalaticToICRS()", 0, false},
-                              {test20, 0000, "psProject()", 0, false},
-                              {test21, 0000, "psDeProject()", 0, false},
-                              {test40, 0000, "psSphereGetOffset()", 0, false},
-                              {test41, 0000, "psSphereSetOffset()", 0, false},
+                              /*
+                                                            {test1, 0000, "psSphereTransformAlloc()", 0, false},
+                                                            {test1b, 0000, "psPlaneTransformAlloc()", 0, false},
+                                                            {test1c, 0000, "psPlaneDistortAlloc()", 0, false},
+                                                            {test2, 0000, "psPlaneTransformApply()", 0, false},
+                                                            {test3, 0000, "psPlaneDistortApply()", 0, false},
+                                                            {test4, 0000, "psPSphereTransformApply()", 0, false},
+                                                            {test4b, 0000, "psPSphereTransformApply()", 0, false},
+                                                            {test5, 0000, "psSphereTransformICRSToEcliptic()", 0, false},
+                                                            {test6, 0000, "psSphereTransformEclipticToICRS()", 0, false},
+                                                            {test7, 0000, "psSphereTransformICRSToGalatic()", 0, false},
+                                                            {test8, 0000, "psSphereTransformGalaticToICRS()", 0, false},
+                                                            {test20, 0000, "psProject()", 0, false},
+                                                            {test21, 0000, "psDeProject()", 0, false},
+                                                            {test40, 0000, "psSphereGetOffset()", 0, false},
+                                                            {test41, 0000, "psSphereSetOffset()", 0, false},
+                                                            {test43, 0000, "psProject(), psDeproject", 0, false},
+                              */
+                              {test42, 0000, "psProject(), psDeproject", 0, false},
                               {NULL}
                           };
@@ -436,6 +446,6 @@
     psSphereTransform *myST = psSphereTransformAlloc(0.0, 0.0, 0.0);
 
-    in.r = 45.0 * MY_DEG_TO_RAD;
-    in.d = 30.0 * MY_DEG_TO_RAD;
+    in.r = DEG_TO_RAD(45.0);
+    in.d = DEG_TO_RAD(30.0);
     in.rErr = 0.0;
     in.dErr = 0.0;
@@ -443,6 +453,6 @@
     for (float r=0.0;r<180.0;r+=DEG_INC) {
         for (float d=0.0;d<90.0;d+=DEG_INC) {
-            in.r = r * MY_DEG_TO_RAD;
-            in.d = d * MY_DEG_TO_RAD;
+            in.r = DEG_TO_RAD(r);
+            in.d = DEG_TO_RAD(d);
             in.rErr = 0.0;
             in.dErr = 0.0;
@@ -483,4 +493,88 @@
     printf("-------------------------------------------------------------------\n");
     psFree(myST);
+    return(testStatus);
+}
+
+/******************************************************************************
+test4b(): This test verifies that psSphereTransformApply() works properly.  We
+create two psSphereTransforms: a forward transform and a reverse transform
+(which is the mathematical inverse of the forward transform).  We apply both
+transforms to several spherical coordinates and ensure that the original input
+coordinate is obtained after applying both transforms.
+ 
+XXX: We currently test the alpha and delta offsets independently.  Attempts to
+test them both concurrently failed.  Determine why this is.  Are the following
+spherical transforms not mathematical inverses?
+    psSphereTransformAlloc(X, Y, 0.0)
+    psSphereTransformAlloc(-X, -Y, 0.0)
+ *****************************************************************************/
+#define ERROR_PERCENT 0.01
+psS32 test4b( void )
+{
+    psS32 testStatus = 0;
+    psSphere in;
+    psSphere out;
+    psSphere out2;
+    psSphereTransform *mySphereTransformForward = NULL;
+    psSphereTransform *mySphereTransformReverse = NULL;
+
+
+    mySphereTransformForward = psSphereTransformAlloc(DEG_TO_RAD(22.0),
+                               0.0,
+                               0.0);
+    mySphereTransformReverse = psSphereTransformAlloc(DEG_TO_RAD(-22.0),
+                               0.0,
+                               0.0);
+
+    for (float r=0.1;r<180.0;r+=(DEG_INC/5.0)) {
+        for (float d=0.1;d<90.0;d+=(DEG_INC/5.0)) {
+            in.r = DEG_TO_RAD(r);
+            in.d = DEG_TO_RAD(d);
+            in.rErr = 0.0;
+            in.dErr = 0.0;
+
+            psSphereTransformApply(&out, mySphereTransformForward, &in);
+            psSphereTransformApply(&out2, mySphereTransformReverse, &out);
+
+            if ((fabs((in.r - out2.r) / in.r) > ERROR_PERCENT) ||
+                    (fabs((in.d - out2.d) / in.d) > ERROR_PERCENT)) {
+                printf("ERROR: \n");
+                printf("Input  coords (R, D) are (%f, %f)\n", in.r, in.d);
+                printf("Output coords (R, D) are (%f, %f)\n", out2.r, out2.d);
+                testStatus = 4;
+            }
+        }
+    }
+    psFree(mySphereTransformForward);
+    psFree(mySphereTransformReverse);
+
+    mySphereTransformForward = psSphereTransformAlloc(0.0,
+                               DEG_TO_RAD(33.0),
+                               0.0);
+    mySphereTransformReverse = psSphereTransformAlloc(0.0,
+                               DEG_TO_RAD(-33.0),
+                               0.0);
+    for (float r=0.1;r<180.0;r+=(DEG_INC/5.0)) {
+        for (float d=0.1;d<90.0;d+=(DEG_INC/5.0)) {
+            in.r = DEG_TO_RAD(r);
+            in.d = DEG_TO_RAD(d);
+            in.rErr = 0.0;
+            in.dErr = 0.0;
+
+            psSphereTransformApply(&out, mySphereTransformForward, &in);
+            psSphereTransformApply(&out2, mySphereTransformReverse, &out);
+
+            if ((fabs((in.r - out2.r) / in.r) > ERROR_PERCENT) ||
+                    (fabs((in.d - out2.d) / in.d) > ERROR_PERCENT)) {
+                printf("ERROR: \n");
+                printf("Input  coords (R, D) are (%f, %f)\n", in.r, in.d);
+                printf("Output coords (R, D) are (%f, %f)\n", out2.r, out2.d);
+                testStatus = 4;
+            }
+        }
+    }
+    psFree(mySphereTransformForward);
+    psFree(mySphereTransformReverse);
+
     return(testStatus);
 }
@@ -677,6 +771,6 @@
     psPlane *out;
     psProjection myProjection;
-    myProjection.R = 20.0 * MY_DEG_TO_RAD;
-    myProjection.D = 10.0 * MY_DEG_TO_RAD;
+    myProjection.R = DEG_TO_RAD(20.0);
+    myProjection.D = DEG_TO_RAD(10.0);
     myProjection.Xs = 1.0;
     myProjection.Ys = 1.0;
@@ -684,6 +778,6 @@
     for (float r=0.0;r<180.0;r+=DEG_INC) {
         for (float d=0.0;d<90.0;d+=DEG_INC) {
-            in.r = r * MY_DEG_TO_RAD;
-            in.d = d * MY_DEG_TO_RAD;
+            in.r = DEG_TO_RAD(r);
+            in.d = DEG_TO_RAD(d);
             in.rErr = 0.0;
             in.dErr = 0.0;
@@ -789,6 +883,6 @@
     psSphere *out;
     psProjection myProjection;
-    myProjection.R = 20.0 * MY_DEG_TO_RAD;
-    myProjection.D = 10.0 * MY_DEG_TO_RAD;
+    myProjection.R = DEG_TO_RAD(20.0);
+    myProjection.D = DEG_TO_RAD(10.0);
     myProjection.Xs = 1.0;
     myProjection.Ys = 1.0;
@@ -904,6 +998,6 @@
     psSphere *offset = NULL;
 
-    position1.r = 90.0 * MY_DEG_TO_RAD;
-    position1.d = 45.0 * MY_DEG_TO_RAD;
+    position1.r = DEG_TO_RAD(90.0);
+    position1.d = DEG_TO_RAD(45.0);
     position1.rErr = 0.0;
     position1.dErr = 0.0;
@@ -911,6 +1005,6 @@
     for (float r=0.0;r<180.0;r+=DEG_INC) {
         for (float d=0.0;d<90.0;d+=DEG_INC) {
-            position2.r = r * MY_DEG_TO_RAD;
-            position2.d = d * MY_DEG_TO_RAD;
+            position2.r = DEG_TO_RAD(r);
+            position2.d = DEG_TO_RAD(d);
             position2.rErr = 0.0;
             position2.dErr = 0.0;
@@ -924,6 +1018,6 @@
             offset = psSphereGetOffset(&position1, &position2,
                                        PS_SPHERICAL, PS_DEGREE);
-            offset->r = offset->r * MY_DEG_TO_RAD;
-            offset->d = offset->d * MY_DEG_TO_RAD;
+            offset->r = DEG_TO_RAD(offset->r);
+            offset->d = DEG_TO_RAD(offset->d);
             PS_COMPARE_TINY_THEN_PRINT_ERROR(offset->r, (position2.r - position1.r), 2);
             PS_COMPARE_TINY_THEN_PRINT_ERROR(offset->d, (position2.d - position1.d), 3);
@@ -946,14 +1040,15 @@
             psFree(offset);
 
-            /* XXX: This code does not work correctly.
-                        offset = psSphereGetOffset(&position1, &position2,
-                                                   PS_LINEAR, 0);
-                        printf("--------------- (%f, %f) to (%f, %f) is (%f, %f) ---------------\n",
-                                position1.r, position1.d, position2.r, position2.d,
-                                offset->r, offset->d);
+            //HEY            /* XXX: This code does not work correctly.
+            printf("--------------- (%f, %f) to (%f, %f) is (%f, %f) ---------------\n",
+                   position1.r, position1.d, position2.r, position2.d,
+                   offset->r, offset->d);
+            /*
+                        offset = psSphereGetOffset(&position1, &position2, PS_LINEAR, 0);
                         PS_COMPARE_TINY_THEN_PRINT_ERROR(offset->r, (position2.r - position1.r), 1);
                         PS_COMPARE_TINY_THEN_PRINT_ERROR(offset->d, (position2.d - position1.d), 1);
-                        psFree(offset);
             */
+            psFree(offset);
+            //            */
         }
     }
@@ -1007,6 +1102,6 @@
     psSphere tmpOffset;
 
-    position1.r = 90.0 * MY_DEG_TO_RAD;
-    position1.d = 45.0 * MY_DEG_TO_RAD;
+    position1.r = DEG_TO_RAD(90.0);
+    position1.d = DEG_TO_RAD(45.0);
     position1.rErr = 0.0;
     position1.dErr = 0.0;
@@ -1014,6 +1109,6 @@
     for (float r=0.0;r<180.0;r+=DEG_INC) {
         for (float d=0.0;d<90.0;d+=DEG_INC) {
-            offset.r = r * MY_DEG_TO_RAD;
-            offset.d = d * MY_DEG_TO_RAD;
+            offset.r = DEG_TO_RAD(offset.r);
+            offset.d = DEG_TO_RAD(offset.d);
             offset.rErr = 0.0;
             offset.dErr = 0.0;
@@ -1025,6 +1120,6 @@
             psFree(position2);
 
-            tmpOffset.r = offset.r * MY_RAD_TO_DEG;
-            tmpOffset.d = offset.d * MY_RAD_TO_DEG;
+            tmpOffset.r = DEG_TO_RAD(offset.r);
+            tmpOffset.d = DEG_TO_RAD(offset.d);
             tmpOffset.rErr = 0.0;
             tmpOffset.dErr = 0.0;
@@ -1108,3 +1203,106 @@
 }
 
+/******************************************************************************
+test43(): Not really a test.  We simply project many points and print the
+results.
+ *****************************************************************************/
+psS32 test43( void )
+{
+    psS32 testStatus = 0;
+    psSphere projCenter;
+    psSphere startCoords;
+    psPlane *planeCoords;
+
+    projCenter.r = DEG_TO_RAD(33.0);
+    projCenter.d = DEG_TO_RAD(22.0);
+    projCenter.r = 0.0;
+    projCenter.d = 0.0;
+    // Create the psProjection plane:
+    psProjection myProj;
+    myProj.R = projCenter.r;
+    myProj.D = projCenter.d;
+    myProj.Xs = 1.0;
+    myProj.Ys = 1.0;
+    myProj.type = PS_PROJ_TAN;
+
+    printf("    projCenter is (%f, %f)\n", projCenter.r, projCenter.d);
+    for (float r=-90.0;r<90.0;r+=DEG_INC/5.0) {
+        for (float d=-90.0;d<90.0;d+=DEG_INC/5.0) {
+            printf("----------------------------------------------------------\n");
+            printf("Angles (R, D) are (%.2f, %.2f)\n", r, d);
+            startCoords.r = DEG_TO_RAD(r);
+            startCoords.d = DEG_TO_RAD(d);
+
+            planeCoords = psProject(&startCoords, &myProj);
+            printf("    startCoords (R, D) is (%f, %f)\n", startCoords.r, startCoords.d);
+            printf("        plane Coords (X, Y) is (%f, %f)\n", planeCoords->x, planeCoords->y);
+            psFree(planeCoords);
+        }
+    }
+    printf("----------------------------------------------------------\n");
+    return(testStatus);
+}
+
+#define NUM_DEGREES 5
+/******************************************************************************
+test42(): This test attempts to verify the psProject() and psDeproject()
+functions.  We create an arbitrary psProjection.  We then project several
+spherical coordinates onto the plane and then immediately deproject them; we
+ensure that the resulting spherical coordinates are identical to the start
+coordinates.
+ *****************************************************************************/
+psS32 test42( void )
+{
+    psS32 testStatus = 0;
+    psSphere projCenter;
+    psSphere startCoords;
+    psSphere *endCoords;
+    psPlane *planeCoords;
+
+    #define PROG_CENTER_R_DEG 20.0
+    #define PROG_CENTER_D_DEG 20.0
+
+    projCenter.r = DEG_TO_RAD(PROG_CENTER_R_DEG);
+    projCenter.d = DEG_TO_RAD(PROG_CENTER_D_DEG);
+    // Create the psProjection plane:
+    psProjection myProj;
+    myProj.R = projCenter.r;
+    myProj.D = projCenter.d;
+    myProj.Xs = 1.0;
+    myProj.Ys = 1.0;
+    myProj.type = PS_PROJ_TAN;
+
+    #define RADIUS_DEG 30.0
+    #define NUM_ANGLES 20
+    #define MY_DEG_INC ((2.0 * RADIUS_DEG) / NUM_ANGLES)
+
+    for (float r= (PROG_CENTER_R_DEG - RADIUS_DEG);
+            r<=(PROG_CENTER_R_DEG + RADIUS_DEG);
+            r+=MY_DEG_INC) {
+        printf("------------------------ r is %.1f ------------------------\n", r);
+        for (float d= (PROG_CENTER_D_DEG - RADIUS_DEG);
+                d<=(PROG_CENTER_D_DEG + RADIUS_DEG);
+                d+=MY_DEG_INC) {
+            startCoords.r = DEG_TO_RAD(r);
+            startCoords.d = DEG_TO_RAD(d);
+            printf("----- startCoords (R, D) is (%f, %f) is deg (%.1f, %.1f)  -----\n", startCoords.r, startCoords.d, r, d);
+
+            planeCoords = psProject(&startCoords, &myProj);
+            endCoords = psDeproject(planeCoords, &myProj);
+
+            if ((fabs((endCoords->r - startCoords.r) / startCoords.r) > ERROR_PERCENT) ||
+                    (fabs((endCoords->d - startCoords.d) / startCoords.d) > ERROR_PERCENT)) {
+                printf("ERROR: \n");
+                printf("    startCoords (R, D) is (%f, %f)\n", startCoords.r, startCoords.d);
+                //                printf("        plane Coords is (%f, %f)\n", planeCoords->x, planeCoords->y);
+                printf("    endCoords (R, D) is (%f, %f)\n", endCoords->r, endCoords->d);
+            }
+
+            psFree(planeCoords);
+            psFree(endCoords);
+        }
+    }
+    return(testStatus);
+}
+
 // This code will ...
