Index: /trunk/psLib/test/astronomy/Makefile
===================================================================
--- /trunk/psLib/test/astronomy/Makefile	(revision 2929)
+++ /trunk/psLib/test/astronomy/Makefile	(revision 2930)
@@ -3,6 +3,6 @@
 ##  Makefile:   test/astronomy
 ##
-##  $Revision: 1.24 $  $Name: not supported by cvs2svn $
-##  $Date: 2004-12-10 02:50:15 $
+##  $Revision: 1.25 $  $Name: not supported by cvs2svn $
+##  $Date: 2005-01-07 23:52:00 $
 ##
 ##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -32,6 +32,6 @@
          tst_psMetadata_07 \
          tst_psAstrometry \
+         tst_psCoord \
          tst_psAstrometry01
-#         tst_psCoord \
 
 OBJS = $(addprefix builddir/,$(addsuffix .o,$(TARGET)))
Index: /trunk/psLib/test/astronomy/tst_psCoord.c
===================================================================
--- /trunk/psLib/test/astronomy/tst_psCoord.c	(revision 2929)
+++ /trunk/psLib/test/astronomy/tst_psCoord.c	(revision 2930)
@@ -1,3 +1,3 @@
-/** @file  tst_psImageManip.c
+/** @file  tst_psCoord.c
 *
 *  @brief The code will ...
@@ -6,6 +6,9 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-10-27 00:57:31 $
+*  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-01-07 23:52:00 $
+*
+*  XXX: Must test psSpherePrecess.
+*  XXX: psSphereSetOffset(&position1, &offset, PS_LINEAR, 0) doesn't work?
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -14,5 +17,4 @@
 #include "psTest.h"
 #include "pslib.h"
-
 static psS32 test1( void );
 static psS32 test1b( void );
@@ -29,5 +31,4 @@
 static psS32 test40( void );
 static psS32 test41( void );
-
 testDescription tests[] = {
                               {test1, 0000, "psSphereTransformAlloc()", 0, false},
@@ -50,6 +51,6 @@
 #define ARCSEC_TO_RAD (M_PI / (180.0 * 60.0 * 60.0))
 #define ARCMIN_TO_RAD (M_PI / (180.0 * 60.0))
-#define DEG_TO_RAD (M_PI / 180.0)
-#define RAD_TO_DEG (180.0 / M_PI)
+#define MY_DEG_TO_RAD (M_PI / 180.0)
+#define MY_RAD_TO_DEG (180.0 / M_PI)
 #define RAD_TO_ARCMIN ((180.0 * 60.0) / M_PI)
 #define RAD_TO_ARCSEC ((180.0 * 60.0 * 60.0) / M_PI)
@@ -60,5 +61,5 @@
     psLogSetLevel( PS_LOG_INFO );
 
-    return ( ! runTestSuite( stderr, "psImage", tests, argc, argv ) );
+    return ( ! runTestSuite( stderr, "psCoord", tests, argc, argv ) );
 }
 
@@ -66,11 +67,11 @@
 #define PS_COMPARE_TINY_THEN_PRINT_ERROR(ACTUAL, EXPECT, TESTSTATUS) \
 if (MY_TINY < fabs(EXPECT - ACTUAL)) { \
-    printf("ERROR: %s is %f, should be %f\n", #ACTUAL, ACTUAL, EXPECT); \
+    printf("ERROR: %s is %f, should be %f (testStatus = %d)\n", #ACTUAL, ACTUAL, EXPECT, TESTSTATUS); \
     testStatus = TESTSTATUS; \
 }
 #define MY_TINY 0.0001
 #define PS_COMPARE_EPSILON_THEN_PRINT_ERROR(ACTUAL, EXPECT, TESTSTATUS) \
-if (MY_TINY < fabs(EXPECT - ACTUAL)) { \
-    printf("ERROR: %s is %f, should be %f\n", #ACTUAL, ACTUAL, EXPECT); \
+if (FLT_EPSILON < fabs(EXPECT - ACTUAL)) { \
+    printf("ERROR: %s is %f, should be %f (testStatus = %d)\n", #ACTUAL, ACTUAL, EXPECT, TESTSTATUS); \
     testStatus = TESTSTATUS; \
 }
@@ -83,32 +84,30 @@
 }
 
-#define NPLAT 1.0
-#define X0_BIG 2.0
-#define X0_SMALL 2.0
-
+#define ALPHA_P 1.0
+#define DELTA_P 2.0
+#define PHI_P 3.0
 psS32 test1( void )
 {
-    float tmpF32;
-    psS32 testStatus = 0;
-    psSphereTransform *myST = psSphereTransformAlloc(NPLAT, X0_BIG, X0_SMALL);
-
-    tmpF32 = sin(NPLAT);
-    if (FLT_EPSILON < fabs(tmpF32 - myST->sinPhi)) {
-        printf("ERROR: myST->sinPhi is %f, should be %f\n", myST->sinPhi, tmpF32);
-        testStatus = 1;
-    }
-    tmpF32 = cos(NPLAT);
-    if (FLT_EPSILON < fabs(tmpF32 - myST->cosPhi)) {
-        printf("ERROR: myST->cosPhi is %f, should be %f\n", myST->cosPhi, tmpF32);
-        testStatus = 2;
-    }
-
-    if (FLT_EPSILON < fabs(X0_BIG - myST->Xo)) {
-        printf("ERROR: myST->Xo is %f, should be %f\n", myST->Xo, X0_BIG);
+    psS32 testStatus = 0;
+    psSphereTransform *myST = psSphereTransformAlloc(ALPHA_P, DELTA_P, PHI_P);
+
+    psF32 sinDeltaP = sin(DELTA_P);
+    if (FLT_EPSILON < fabs(sinDeltaP - myST->sinDeltaP)) {
+        printf("ERROR: myST->sinDeltaP is %f, should be %f\n", myST->sinDeltaP, sinDeltaP);
+        testStatus = 1;
+    }
+    psF32 cosDeltaP = cos(DELTA_P);
+    if (FLT_EPSILON < fabs(cosDeltaP - myST->cosDeltaP)) {
+        printf("ERROR: myST->cosDeltaP is %f, should be %f\n", myST->cosDeltaP, cosDeltaP);
+        testStatus = 1;
+    }
+
+    if (FLT_EPSILON < fabs(ALPHA_P - myST->alphaP)) {
+        printf("ERROR: myST->alphaP is %f, should be %f\n", myST->alphaP, ALPHA_P);
         testStatus = 3;
     }
 
-    if (FLT_EPSILON < fabs(X0_SMALL - myST->xo)) {
-        printf("ERROR: myST->xo is %f, should be %f\n", myST->xo, X0_SMALL);
+    if (FLT_EPSILON < fabs(PHI_P - myST->phiP)) {
+        printf("ERROR: myST->phiP is %f, should be %f\n", myST->phiP, PHI_P);
         testStatus = 4;
     }
@@ -144,4 +143,25 @@
         testStatus = 1;
     }
+    psFree(myPT);
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneTransformAlloc() with negative-order polynomial request.  Should generate error, return NULL.\n");
+    myPT = psPlaneTransformAlloc(-1.0, 1.0);
+    if (myPT != NULL) {
+        printf("TEST ERROR: psPlaneTransformAlloc() did not return NULL.\n");
+        testStatus = false;
+        myPT = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneTransformAlloc() with negative-order polynomial request.  Should generate error, return NULL.\n");
+    myPT = psPlaneTransformAlloc(1.0, -1.0);
+    if (myPT != NULL) {
+        printf("TEST ERROR: psPlaneTransformAlloc() did not return NULL.\n");
+        testStatus = false;
+        myPT = NULL;
+    }
+    printf("-------------------------------------------------------------------\n");
+
 
     psFree(myPT);
@@ -190,4 +210,42 @@
 
     psFree(myPD);
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneDistortAlloc() with negative-order polynomial request.  Should generate error, return NULL.\n");
+    myPD = psPlaneDistortAlloc(-1.0, 1.0, 1.0, 1.0);
+    if (myPD != NULL) {
+        printf("TEST ERROR: psPlaneDistortAlloc() did not return NULL.\n");
+        testStatus = false;
+        myPD = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneDistortAlloc() with negative-order polynomial request.  Should generate error, return NULL.\n");
+    myPD = psPlaneDistortAlloc(1.0, -1.0, 1.0, 1.0);
+    if (myPD != NULL) {
+        printf("TEST ERROR: psPlaneDistortAlloc() did not return NULL.\n");
+        testStatus = false;
+        myPD = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneDistortAlloc() with negative-order polynomial request.  Should generate error, return NULL.\n");
+    myPD = psPlaneDistortAlloc(1.0, 1.0, -1.0, 1.0);
+    if (myPD != NULL) {
+        printf("TEST ERROR: psPlaneDistortAlloc() did not return NULL.\n");
+        testStatus = false;
+        myPD = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneDistortAlloc() with negative-order polynomial request.  Should generate error, return NULL.\n");
+    myPD = psPlaneDistortAlloc(1.0, 1.0, 1.0, -1.0);
+    if (myPD != NULL) {
+        printf("TEST ERROR: psPlaneDistortAlloc() did not return NULL.\n");
+        testStatus = false;
+        myPD = NULL;
+    }
+    printf("-------------------------------------------------------------------\n");
+
     return(testStatus);
 }
@@ -201,5 +259,7 @@
     psPlane in;
     psPlane out;
+    psPlane *rc;
     psPlaneTransform pt;
+    psDPolynomial2D *tmp2DPoly = NULL;
 
     pt.x = psDPolynomial2DAlloc(2, 2, PS_POLYNOMIAL_ORD);
@@ -226,4 +286,47 @@
     }
 
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneTransformApply() with NULL psPlaneTransform.  Should generate error, return NULL.\n");
+    rc = psPlaneTransformApply(NULL, NULL, &in);
+    if (rc != NULL) {
+        printf("TEST ERROR: psPlaneTransformApply() did not return NULL.\n");
+        testStatus = false;
+        rc = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneTransformApply() with NULL psPlaneTransform->x.  Should generate error, return NULL.\n");
+    tmp2DPoly = pt.x;
+    pt.x = NULL;
+    rc = psPlaneTransformApply(NULL, &pt, &in);
+    if (rc != NULL) {
+        printf("TEST ERROR: psPlaneTransformApply() did not return NULL.\n");
+        testStatus = false;
+        rc = NULL;
+    }
+    pt.x = tmp2DPoly;
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneTransformApply() with NULL psPlaneTransform->y.  Should generate error, return NULL.\n");
+    tmp2DPoly = pt.y;
+    pt.y = NULL;
+    rc = psPlaneTransformApply(NULL, &pt, &in);
+    if (rc != NULL) {
+        printf("TEST ERROR: psPlaneTransformApply() did not return NULL.\n");
+        testStatus = false;
+        rc = NULL;
+    }
+    pt.y = tmp2DPoly;
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneTransformApply() with NULL input coords.  Should generate error, return NULL.\n");
+    rc = psPlaneTransformApply(NULL, &pt, NULL);
+    if (rc != NULL) {
+        printf("TEST ERROR: psPlaneTransformApply() did not return NULL.\n");
+        testStatus = false;
+        rc = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
     psFree(pt.x);
     psFree(pt.y);
@@ -242,4 +345,6 @@
     psPlane out;
     psPlaneDistort pt;
+    psPlane *rc = NULL;
+    psDPolynomial4D *tmp4DPoly = NULL;
 
     pt.x = psDPolynomial4DAlloc(2, 2, 2, 2, PS_POLYNOMIAL_ORD);
@@ -270,4 +375,49 @@
     }
 
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneDistortApply() with NULL psPlaneDistort.  Should generate error, return NULL.\n");
+    rc = psPlaneDistortApply(NULL, NULL, &in, COLOR, MAGNITUDE);
+    if (rc != NULL) {
+        printf("TEST ERROR: psPlaneDistortApply() did not return NULL.\n");
+        testStatus = false;
+        rc = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneDistortApply() with NULL psPlaneDistort->x.  Should generate error, return NULL.\n");
+    tmp4DPoly = pt.x;
+    pt.x = NULL;
+    rc = psPlaneDistortApply(NULL, &pt, &in, COLOR, MAGNITUDE);
+    if (rc != NULL) {
+        printf("TEST ERROR: psPlaneDistortApply() did not return NULL.\n");
+        testStatus = false;
+        rc = NULL;
+    }
+    pt.x = tmp4DPoly;
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneDistortApply() with NULL psPlaneDistort->y.  Should generate error, return NULL.\n");
+    tmp4DPoly = pt.y;
+    pt.y = NULL;
+    rc = psPlaneDistortApply(NULL, &pt, &in, COLOR, MAGNITUDE);
+    if (rc != NULL) {
+        printf("TEST ERROR: psPlaneDistortApply() did not return NULL.\n");
+        testStatus = false;
+        rc = NULL;
+    }
+    pt.y = tmp4DPoly;
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psPlaneDistortApply() with NULL input coords.  Should generate error, return NULL.\n");
+    rc = psPlaneDistortApply(NULL, &pt, NULL, COLOR, MAGNITUDE);
+    if (rc != NULL) {
+        printf("TEST ERROR: psPlaneDistortApply() did not return NULL.\n");
+        testStatus = false;
+        rc = NULL;
+    }
+
+
+
+    printf("-------------------------------------------------------------------\n");
     psFree(pt.x);
     psFree(pt.y);
@@ -282,8 +432,9 @@
     psSphere in;
     psSphere out;
+    psSphere *rc = NULL;
     psSphereTransform *myST = psSphereTransformAlloc(0.0, 0.0, 0.0);
 
-    in.r = 45.0 * DEG_TO_RAD;
-    in.d = 30.0 * DEG_TO_RAD;
+    in.r = 45.0 * MY_DEG_TO_RAD;
+    in.d = 30.0 * MY_DEG_TO_RAD;
     in.rErr = 0.0;
     in.dErr = 0.0;
@@ -291,6 +442,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 * DEG_TO_RAD;
-            in.d = d * DEG_TO_RAD;
+            in.r = r * MY_DEG_TO_RAD;
+            in.d = d * MY_DEG_TO_RAD;
             in.rErr = 0.0;
             in.dErr = 0.0;
@@ -311,4 +462,23 @@
     }
 
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psSphereTransformApply() with NULL psSphereTransform.  Should generate error, return NULL.\n");
+    rc = psSphereTransformApply(NULL, NULL, &in);
+    if (rc != NULL) {
+        printf("TEST ERROR: psSphereTransformApply() did not return NULL.\n");
+        testStatus = false;
+        rc = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psSphereTransformApply() with NULL input coords.  Should generate error, return NULL.\n");
+    rc = psSphereTransformApply(NULL, myST, NULL);
+    if (rc != NULL) {
+        printf("TEST ERROR: psSphereTransformApply() did not return NULL.\n");
+        testStatus = false;
+        rc = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
     psFree(myST);
     return(testStatus);
@@ -318,30 +488,42 @@
 {
     psS32 testStatus = 0;
+
+    // XXX: This test code is simply a copy of the original source code.
     psTime* now = psTimeGetTime(PS_TIME_UTC);
     struct tm *tm_time = psTimeToTM(now);
-
-    // XXX: This test code is simply a copy of the original source code.
-    double year = (double)(1900 + tm_time->tm_year);
-    double T = year / 100.0;
-    double phi = -23.452294 + 0.013013 * T + 0.000001639 * T * T - 0.000000503 * T * T * T;
-    psSphereTransform *myST = psSphereTransformICRSToEcliptic(*now);
-
-    if (FLT_EPSILON < fabs(sin(phi) - myST->sinPhi)) {
-        printf("ERROR: myST->sinPhi is %f, should be %f\n", myST->sinPhi, sin(phi));
-        testStatus = 1;
-    }
-
-    if (FLT_EPSILON < fabs(cos(phi) - myST->cosPhi)) {
-        printf("ERROR: myST->cosPhi is %f, should be %f\n", myST->cosPhi, cos(phi));
-        testStatus = 2;
-    }
-
-    if (FLT_EPSILON < fabs(0.0 - myST->Xo)) {
-        printf("ERROR: myST->Xo is %f, should be %f\n", myST->Xo, X0_BIG);
+    psF64 MJD = psTimeToMJD(now);
+    struct tm *tmTime = psTimeToTM(now);
+    psF64 year = (psF64)(1900 - MJD + tmTime->tm_year);
+    psF64 T = year / 100.0;
+    psF64 expectedAlphaP = 0.0;
+    psF64 expectedDeltaP = DEG_TO_RAD(23.0) +
+                           SEC_TO_RAD(27.0) +
+                           MIN_TO_RAD(8.0) -
+                           (SEC_TO_RAD(46.845) * T) -
+                           (SEC_TO_RAD(0.0059) * T * T) +
+                           (SEC_TO_RAD(0.00181) * T * T * T);
+    expectedDeltaP*= -1.0;
+    psF64 expectedPhiP = 0.0;
+    psFree(tmTime);
+
+    psSphereTransform *myST = psSphereTransformICRSToEcliptic(now);
+
+    if (FLT_EPSILON < fabs(sin(expectedDeltaP) - myST->sinDeltaP)) {
+        printf("ERROR: myST->sinDeltaP is %f, should be %f\n", myST->sinDeltaP, sin(expectedDeltaP));
+        testStatus = 1;
+    }
+
+    if (FLT_EPSILON < fabs(cos(expectedDeltaP) - myST->cosDeltaP)) {
+        printf("ERROR: myST->cosDeltaP is %f, should be %f\n", myST->cosDeltaP, cos(expectedDeltaP));
+        testStatus = 1;
+    }
+
+    if (FLT_EPSILON < fabs(expectedAlphaP - myST->alphaP)) {
+        printf("ERROR: myST->alphaP is %f, should be %f\n", myST->alphaP, expectedAlphaP);
         testStatus = 3;
     }
 
-    if (FLT_EPSILON < fabs(0.0 - myST->xo)) {
-        printf("ERROR: myST->xo is %f, should be %f\n", myST->xo, X0_SMALL);
+    if (FLT_EPSILON < fabs(expectedPhiP - myST->phiP)) {
+        printf("ERROR: myST->phiP is %f, should be %f\n", myST->phiP, expectedPhiP);
         testStatus = 4;
     }
@@ -350,4 +532,14 @@
     psFree(tm_time);
     psFree(now);
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psSphereTransformICRSToEcliptic() with NULL input.  Should generate error, return NULL.\n");
+    myST = psSphereTransformICRSToEcliptic(NULL);
+    if (myST != NULL) {
+        printf("TEST ERROR: psSphereTransformApply() did not return NULL.\n");
+        testStatus = false;
+        myST = NULL;
+    }
+
     return(testStatus);
 }
@@ -359,28 +551,35 @@
     psTime* now = psTimeGetTime(PS_TIME_UTC);
     struct tm *tm_time = psTimeToTM(now);
-
-    // XXX: This test code is simply a copy of the original source code.
-    double year = (double)(1900 + tm_time->tm_year);
-    double T = year / 100.0;
-    double phi = +23.452294 - 0.013013 * T - 0.000001639 * T * T + 0.000000503 * T * T * T;
-    psSphereTransform *myST = psSphereTransformEclipticToICRS(*now);
-
-    if (FLT_EPSILON < fabs(sin(phi) - myST->sinPhi)) {
-        printf("ERROR: myST->sinPhi is %f, should be %f\n", myST->sinPhi, sin(phi));
-        testStatus = 1;
-    }
-
-    if (FLT_EPSILON < fabs(cos(phi) - myST->cosPhi)) {
-        printf("ERROR: myST->cosPhi is %f, should be %f\n", myST->cosPhi, cos(phi));
-        testStatus = 2;
-    }
-
-    if (FLT_EPSILON < fabs(0.0 - myST->Xo)) {
-        printf("ERROR: myST->Xo is %f, should be %f\n", myST->Xo, X0_BIG);
+    psF64 MJD = psTimeToMJD(now);
+    struct tm *tmTime = psTimeToTM(now);
+    psF64 year = (psF64)(1900 - MJD + tmTime->tm_year);
+    psF64 T = year / 100.0;
+    psF64 expectedAlphaP = 0.0;
+    psF64 expectedDeltaP = DEG_TO_RAD(23.0) +
+                           SEC_TO_RAD(27.0) +
+                           MIN_TO_RAD(8.0) -
+                           (SEC_TO_RAD(46.845) * T) -
+                           (SEC_TO_RAD(0.0059) * T * T) +
+                           (SEC_TO_RAD(0.00181) * T * T * T);
+    psF64 expectedPhiP = 0.0;
+    psSphereTransform *myST = psSphereTransformEclipticToICRS(now);
+
+    if (FLT_EPSILON < fabs(sin(expectedDeltaP) - myST->sinDeltaP)) {
+        printf("ERROR: myST->sinDeltaP is %f, should be %f\n", myST->sinDeltaP, sin(expectedDeltaP));
+        testStatus = 1;
+    }
+
+    if (FLT_EPSILON < fabs(cos(expectedDeltaP) - myST->cosDeltaP)) {
+        printf("ERROR: myST->cosDeltaP is %f, should be %f\n", myST->cosDeltaP, cos(expectedDeltaP));
+        testStatus = 1;
+    }
+
+    if (FLT_EPSILON < fabs(expectedAlphaP - myST->alphaP)) {
+        printf("ERROR: myST->alphaP is %f, should be %f\n", myST->alphaP, expectedAlphaP);
         testStatus = 3;
     }
 
-    if (FLT_EPSILON < fabs(0.0 - myST->xo)) {
-        printf("ERROR: myST->xo is %f, should be %f\n", myST->xo, X0_SMALL);
+    if (FLT_EPSILON < fabs(expectedPhiP - myST->phiP)) {
+        printf("ERROR: myST->phiP is %f, should be %f\n", myST->phiP, expectedPhiP);
         testStatus = 4;
     }
@@ -388,8 +587,18 @@
     psFree(myST);
     psFree(tm_time);
+    psFree(tmTime);
     psFree(now);
-    return(testStatus);
-}
-
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psSphereTransformEclipticToICRS() with NULL input.  Should generate error, return NULL.\n");
+    myST = psSphereTransformEclipticToICRS(NULL);
+    if (myST != NULL) {
+        printf("TEST ERROR: psSphereTransformApply() did not return NULL.\n");
+        testStatus = false;
+        myST = NULL;
+    }
+
+    return(testStatus);
+}
 
 psS32 test7( void )
@@ -397,26 +606,26 @@
     psS32 testStatus = 0;
     // XXX: This test code is simply a copy of the original source code.
-    double phi = 62.6;
-    double Xo = 282.25;
-    double xo = 33.0;
+    psF64 expectedAlphaP = DEG_TO_RAD(32.93192);
+    psF64 expectedDeltaP = DEG_TO_RAD(-62.87175);
+    psF64 expectedPhiP = DEG_TO_RAD(282.85948);
     psSphereTransform *myST = psSphereTransformICRSToGalatic();
 
-    if (FLT_EPSILON < fabs(sin(phi) - myST->sinPhi)) {
-        printf("ERROR: myST->sinPhi is %f, should be %f\n", myST->sinPhi, sin(phi));
-        testStatus = 1;
-    }
-
-    if (FLT_EPSILON < fabs(cos(phi) - myST->cosPhi)) {
-        printf("ERROR: myST->cosPhi is %f, should be %f\n", myST->cosPhi, cos(phi));
-        testStatus = 2;
-    }
-
-    if (FLT_EPSILON < fabs(Xo - myST->Xo)) {
-        printf("ERROR: myST->Xo is %f, should be %f\n", myST->Xo, Xo);
+    if (FLT_EPSILON < fabs(sin(expectedDeltaP) - myST->sinDeltaP)) {
+        printf("ERROR: myST->sinDeltaP is %f, should be %f\n", myST->sinDeltaP, sin(expectedDeltaP));
+        testStatus = 1;
+    }
+
+    if (FLT_EPSILON < fabs(cos(expectedDeltaP) - myST->cosDeltaP)) {
+        printf("ERROR: myST->cosDeltaP is %f, should be %f\n", myST->cosDeltaP, cos(expectedDeltaP));
+        testStatus = 1;
+    }
+
+    if (FLT_EPSILON < fabs(expectedAlphaP - myST->alphaP)) {
+        printf("ERROR: myST->alphaP is %f, should be %f\n", myST->alphaP, expectedAlphaP);
         testStatus = 3;
     }
 
-    if (FLT_EPSILON < fabs(xo - myST->xo)) {
-        printf("ERROR: myST->xo is %f, should be %f\n", myST->xo, xo);
+    if (FLT_EPSILON < fabs(expectedPhiP - myST->phiP)) {
+        printf("ERROR: myST->phiP is %f, should be %f\n", myST->phiP, expectedPhiP);
         testStatus = 4;
     }
@@ -430,26 +639,26 @@
     psS32 testStatus = 0;
     // XXX: This test code is simply a copy of the original source code.
-    double phi = -62.6;
-    double Xo = 33.0;
-    double xo = 282.25;
+    psF64 expectedAlphaP = DEG_TO_RAD(282.85948);
+    psF64 expectedDeltaP = DEG_TO_RAD(62.87175);
+    psF64 expectedPhiP = DEG_TO_RAD(32.93192);
     psSphereTransform *myST = psSphereTransformGalaticToICRS();
 
-    if (FLT_EPSILON < fabs(sin(phi) - myST->sinPhi)) {
-        printf("ERROR: myST->sinPhi is %f, should be %f\n", myST->sinPhi, sin(phi));
-        testStatus = 1;
-    }
-
-    if (FLT_EPSILON < fabs(cos(phi) - myST->cosPhi)) {
-        printf("ERROR: myST->cosPhi is %f, should be %f\n", myST->cosPhi, cos(phi));
-        testStatus = 2;
-    }
-
-    if (FLT_EPSILON < fabs(Xo - myST->Xo)) {
-        printf("ERROR: myST->Xo is %f, should be %f\n", myST->Xo, Xo);
+    if (FLT_EPSILON < fabs(sin(expectedDeltaP) - myST->sinDeltaP)) {
+        printf("ERROR: myST->sinDeltaP is %f, should be %f\n", myST->sinDeltaP, sin(expectedDeltaP));
+        testStatus = 1;
+    }
+
+    if (FLT_EPSILON < fabs(cos(expectedDeltaP) - myST->cosDeltaP)) {
+        printf("ERROR: myST->cosDeltaP is %f, should be %f\n", myST->cosDeltaP, cos(expectedDeltaP));
+        testStatus = 1;
+    }
+
+    if (FLT_EPSILON < fabs(expectedAlphaP - myST->alphaP)) {
+        printf("ERROR: myST->alphaP is %f, should be %f\n", myST->alphaP, expectedAlphaP);
         testStatus = 3;
     }
 
-    if (FLT_EPSILON < fabs(xo - myST->xo)) {
-        printf("ERROR: myST->xo is %f, should be %f\n", myST->xo, xo);
+    if (FLT_EPSILON < fabs(expectedPhiP - myST->phiP)) {
+        printf("ERROR: myST->phiP is %f, should be %f\n", myST->phiP, expectedPhiP);
         testStatus = 4;
     }
@@ -463,11 +672,10 @@
     psS32 testStatus = 0;
     psSphere in;
-    double R;
     double expectX;
     double expectY;
     psPlane *out;
     psProjection myProjection;
-    myProjection.R = 20.0 * DEG_TO_RAD;
-    myProjection.D = 10.0 * DEG_TO_RAD;
+    myProjection.R = 20.0 * MY_DEG_TO_RAD;
+    myProjection.D = 10.0 * MY_DEG_TO_RAD;
     myProjection.Xs = 1.0;
     myProjection.Ys = 1.0;
@@ -475,6 +683,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 * DEG_TO_RAD;
-            in.d = d * DEG_TO_RAD;
+            in.r = r * MY_DEG_TO_RAD;
+            in.d = d * MY_DEG_TO_RAD;
             in.rErr = 0.0;
             in.dErr = 0.0;
@@ -485,8 +693,6 @@
             myProjection.type = PS_PROJ_TAN;
             out = psProject(&in, &myProjection);
-
-            R = PS_COT(in.r) * (180.0 / M_PI);
-            expectX = R * sin(in.d);
-            expectY = R * cos(in.d);
+            expectX = cos(in.r) * sin(in.d) / sin(in.r);
+            expectY = -cos(in.r) * cos(in.d) / sin(in.r);
             PS_COMPARE_TINY_THEN_PRINT_ERROR(out->x, expectX, 1);
             PS_COMPARE_TINY_THEN_PRINT_ERROR(out->y, expectY, 2);
@@ -498,8 +704,6 @@
             myProjection.type = PS_PROJ_SIN;
             out = psProject(&in, &myProjection);
-
-            R = cos(in.r) * (180.0 / M_PI);
-            expectX = R * sin(in.d);
-            expectY = R * cos(in.d);
+            expectX = cos(in.d) * sin(in.d);
+            expectY = -cos(in.d) * cos(in.d);
             PS_COMPARE_TINY_THEN_PRINT_ERROR(out->x, expectX, 3);
             PS_COMPARE_TINY_THEN_PRINT_ERROR(out->y, expectY, 4);
@@ -525,5 +729,5 @@
 
             expectX = in.d;
-            expectY = log(tan(45.0 + (0.5 * in.r))) * 180.0 / M_PI;
+            expectY = log(tan(DEG_TO_RAD(45.0) + (0.5 * in.r)));
 
             PS_COMPARE_TINY_THEN_PRINT_ERROR(out->x, expectX, 7);
@@ -537,11 +741,12 @@
             out = psProject(&in, &myProjection);
 
-            double alpha = 1.0 / ((180.0 / M_PI) * sqrt(1.0 + (cos(in.r) *
-                                  cos(0.5 * in.d) * 0.5)));
-            expectX = 2.0 * alpha * cos(in.r) * sin(0.5 * in.d);
-            expectY = alpha * sin(in.d);
-
-            PS_COMPARE_TINY_THEN_PRINT_ERROR(out->x, expectX, 7);
-            PS_COMPARE_TINY_THEN_PRINT_ERROR(out->y, expectY, 8);
+
+            psF64 tmpF64  = PS_SQRT_F32(0.5 * (1.0 + (cos(in.r) * cos(0.5 * in.d))));
+            tmpF64 = 1.0 / tmpF64;
+            expectX = 2.0 * tmpF64 * cos(in.r) * sin(0.5 * in.d);
+            expectY = sin(in.r) * tmpF64;
+
+            PS_COMPARE_TINY_THEN_PRINT_ERROR(out->x, expectX, 20);
+            PS_COMPARE_TINY_THEN_PRINT_ERROR(out->y, expectY, 21);
             psFree(out);
 
@@ -549,4 +754,25 @@
         }
     }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psProject() with NULL input coords.  Should generate error, return NULL.\n");
+    out = psProject(NULL, &myProjection);
+    if (out != NULL) {
+        printf("TEST ERROR: psSphereTransformEclipticToICRS() did not return NULL.\n");
+        testStatus = false;
+        out = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psProject() with NULL psProjection.  Should generate error, return NULL.\n");
+    out = psProject(&in, NULL);
+    if (out != NULL) {
+        printf("TEST ERROR: psProject() did not return NULL.\n");
+        testStatus = false;
+        out = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+
     return(testStatus);
 }
@@ -562,6 +788,6 @@
     psSphere *out;
     psProjection myProjection;
-    myProjection.R = 20.0 * DEG_TO_RAD;
-    myProjection.D = 10.0 * DEG_TO_RAD;
+    myProjection.R = 20.0 * MY_DEG_TO_RAD;
+    myProjection.D = 10.0 * MY_DEG_TO_RAD;
     myProjection.Xs = 1.0;
     myProjection.Ys = 1.0;
@@ -578,7 +804,7 @@
             out = psDeproject(&in, &myProjection);
 
-            R = sqrt((in.x * in.x) + (in.y * in.y));
-            expectD = p_psArg(-in.y, in.x);
-            expectR = atan(180.0 / (R * M_PI));
+            R = PS_SQRT_F32((in.x * in.x) + (in.y * in.y));
+            expectD = atan(1.0 / R);
+            expectR = atan2(-in.y, in.x);
 
             PS_COMPARE_TINY_THEN_PRINT_ERROR(out->r, expectR, 1);
@@ -646,4 +872,25 @@
         }
     }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psDeproject() with NULL input coords.  Should generate error, return NULL.\n");
+    out = psDeproject(NULL, &myProjection);
+    if (out != NULL) {
+        printf("TEST ERROR: psDeproject() did not return NULL.\n");
+        testStatus = false;
+        out = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psDeproject() with NULL psProjection.  Should generate error, return NULL.\n");
+    out = psDeproject(&in, NULL);
+    if (out != NULL) {
+        printf("TEST ERROR: psDeproject() did not return NULL.\n");
+        testStatus = false;
+        out = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+
     return(testStatus);
 }
@@ -656,6 +903,6 @@
     psSphere *offset = NULL;
 
-    position1.r = 90.0 * DEG_TO_RAD;
-    position1.d = 45.0 * DEG_TO_RAD;
+    position1.r = 90.0 * MY_DEG_TO_RAD;
+    position1.d = 45.0 * MY_DEG_TO_RAD;
     position1.rErr = 0.0;
     position1.dErr = 0.0;
@@ -663,6 +910,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 * DEG_TO_RAD;
-            position2.d = d * DEG_TO_RAD;
+            position2.r = r * MY_DEG_TO_RAD;
+            position2.d = d * MY_DEG_TO_RAD;
             position2.rErr = 0.0;
             position2.dErr = 0.0;
@@ -676,6 +923,6 @@
             offset = psSphereGetOffset(&position1, &position2,
                                        PS_SPHERICAL, PS_DEGREE);
-            offset->r = offset->r * DEG_TO_RAD;
-            offset->d = offset->d * DEG_TO_RAD;
+            offset->r = offset->r * MY_DEG_TO_RAD;
+            offset->d = offset->d * MY_DEG_TO_RAD;
             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);
@@ -711,4 +958,32 @@
     }
 
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psSphereGetOffset() with NULL position1.  Should generate error, return NULL.\n");
+    offset = psSphereGetOffset(NULL, &position2, PS_LINEAR, 0);
+    if (offset != NULL) {
+        printf("TEST ERROR: psSphereGetOffset() did not return NULL.\n");
+        testStatus = false;
+        offset = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psSphereGetOffset() with NULL position2.  Should generate error, return NULL.\n");
+    offset = psSphereGetOffset(&position1, NULL, PS_LINEAR, 0);
+    if (offset != NULL) {
+        printf("TEST ERROR: psSphereGetOffset() did not return NULL.\n");
+        testStatus = false;
+        offset = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psSphereGetOffset() with bogus offset mode.  Should generate error, return NULL.\n");
+    offset = psSphereGetOffset(&position1, &position2, 0x54321, 0);
+    if (offset != NULL) {
+        printf("TEST ERROR: psSphereGetOffset() did not return NULL.\n");
+        testStatus = false;
+        offset = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
     return(testStatus);
 }
@@ -722,6 +997,6 @@
     psSphere tmpOffset;
 
-    position1.r = 90.0 * DEG_TO_RAD;
-    position1.d = 45.0 * DEG_TO_RAD;
+    position1.r = 90.0 * MY_DEG_TO_RAD;
+    position1.d = 45.0 * MY_DEG_TO_RAD;
     position1.rErr = 0.0;
     position1.dErr = 0.0;
@@ -729,6 +1004,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 * DEG_TO_RAD;
-            offset.d = d * DEG_TO_RAD;
+            offset.r = r * MY_DEG_TO_RAD;
+            offset.d = d * MY_DEG_TO_RAD;
             offset.rErr = 0.0;
             offset.dErr = 0.0;
@@ -740,6 +1015,6 @@
             psFree(position2);
 
-            tmpOffset.r = offset.r * RAD_TO_DEG;
-            tmpOffset.d = offset.d * RAD_TO_DEG;
+            tmpOffset.r = offset.r * MY_RAD_TO_DEG;
+            tmpOffset.d = offset.d * MY_RAD_TO_DEG;
             tmpOffset.rErr = 0.0;
             tmpOffset.dErr = 0.0;
@@ -783,4 +1058,34 @@
     }
 
-    return(testStatus);
-}
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psSphereSetOffset() with NULL position1.  Should generate error, return NULL.\n");
+    position2 = psSphereSetOffset(NULL, &offset, PS_LINEAR, 0);
+    if (position2 != NULL) {
+        printf("TEST ERROR: psSphereSetOffset() did not return NULL.\n");
+        testStatus = false;
+        position2 = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psSphereSetOffset() with NULL offset.  Should generate error, return NULL.\n");
+    position2 = psSphereSetOffset(&position1, NULL, PS_LINEAR, 0);
+    if (position2 != NULL) {
+        printf("TEST ERROR: psSphereSetOffset() did not return NULL.\n");
+        testStatus = false;
+        position2 = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    printf("Calling psSphereSetOffset() with bogus offset mode.  Should generate error, return NULL.\n");
+    position2 = psSphereSetOffset(&position1, &offset, 0x54321, 0);
+    if (position2 != NULL) {
+        printf("TEST ERROR: psSphereSetOffset() did not return NULL.\n");
+        testStatus = false;
+        position2 = NULL;
+    }
+
+    printf("-------------------------------------------------------------------\n");
+    return(testStatus);
+}
+
+// This code will ...
