Index: trunk/psLib/test/astro/tst_psSphereOps.c
===================================================================
--- trunk/psLib/test/astro/tst_psSphereOps.c	(revision 5306)
+++ trunk/psLib/test/astro/tst_psSphereOps.c	(revision 5319)
@@ -1,11 +1,11 @@
-/** @file  tst_psCoord.c
+/** @file  tst_psSphereOps.c
 *
-*  @brief The code will ...
+*  @brief The code will ..... Work ....
 *
 *
-*  @author GLG, MHPCC
+*  @author d-Rob, MHPCC
 *
-*  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-10-13 20:23:57 $
+*  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-10-14 00:07:37 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -15,6 +15,6 @@
 #include "pslib_strict.h"
 static psS32 testSphereRotAlloc(void);
+static psS32 testSphereRotQuat(void);
 static psS32 testSphereRotApply1(void);
-static psS32 testSphereRotApply2(void);
 static psS32 testSphereRotApplyCelestial(void);
 static psS32 testSphereRotPrecess(void);
@@ -22,12 +22,12 @@
 testDescription tests[] = {
                               {testSphereRotAlloc, 819, "psSphereRotAlloc()", 0, false},
-                              {testSphereRotApply1, 820, "psSphereRotApply()", 0, false},
-                              {testSphereRotApply2, 820, "psSphereRotApply()", 0, false},
-                              {testSphereRotApplyCelestial, 820, "psSphereRotApply()", 0, false},
-                              //                              {testSphereRotApplyCelestial, 821, "psSphereRotICRSToEcliptic()", true},
-                              //                              {testSphereRotApplyCelestial, 822, "psSphereRotEclipticToICRS()", 0, true},
-                              //                              {testSphereRotApplyCelestial, 824, "psSphereRotICRSToGalactic()", 0, true},
-                              //                              {testSphereRotApplyCelestial, 823, "psSphereRotGalacticToICRS()", 0, true},
-                              {testSphereRotPrecess, 825, "psSphereRotPrecess()", 0, false},
+                              {testSphereRotQuat, 820, "psSphereRotQuat()", 0, false},
+                              {testSphereRotApply1, 821, "psSphereRotApply()", 0, false},
+                              {testSphereRotApplyCelestial, 822, "psSphereRotApplyCel()", 0, false},
+                              {testSphereRotPrecess, 823, "psSphereRotPrecess()", 0, false},
+                              //                           {testSphereRotApplyCelestial, 821, "psSphereRotICRSToEcliptic()", true},
+                              //                         {testSphereRotApplyCelestial, 822, "psSphereRotEclipticToICRS()", 0, true},
+                              //                         {testSphereRotApplyCelestial, 824, "psSphereRotICRSToGalactic()", 0, true},
+                              //                         {testSphereRotApplyCelestial, 823, "psSphereRotGalacticToICRS()", 0, true},
                               {NULL}
                           };
@@ -50,5 +50,5 @@
 #define ALPHA_P M_PI/6
 #define DELTA_P M_PI/4
-#define PHI_P M_PI/2
+#define PHI_P M_PI/3
 
 psS32 testSphereRotAlloc( void )
@@ -73,6 +73,6 @@
     double q2 = sin(a2)*cos(DELTA_P/2);
 
-    printf("\n q0=%lf, q1=%lf, q2=%lf, q3=%lf,\n", q0, q1, q2, q3);
-    printf("myq0=%lf, myq1=%lf, myq2=%lf, myq3=%lf\n", myST->q0, myST->q1, myST->q2, myST->q3);
+    //    printf("\n q0=%lf, q1=%lf, q2=%lf, q3=%lf,\n", q0, q1, q2, q3);
+    //    printf("myq0=%lf, myq1=%lf, myq2=%lf, myq3=%lf\n", myST->q0, myST->q1, myST->q2, myST->q3);
     if (FLT_EPSILON < fabs(q0 - myST->q0)) {
         psError(PS_ERR_UNKNOWN,true,"myST->q0 is %lf, should be %lf\n", myST->q0, q0);
@@ -98,153 +98,116 @@
 }
 
+psS32 testSphereRotQuat(void)
+{
+    double a0 = (ALPHA_P - PHI_P)/2.0;
+    double a1 = (ALPHA_P - PHI_P)/2.0;
+    double a2 = (ALPHA_P + PHI_P)/2.0;
+    double a3 = (ALPHA_P + PHI_P)/2.0;
+
+    double q3 = cos(a3)*cos(DELTA_P/2);
+    double q0 = sin(a0)*sin(DELTA_P/2);
+    double q1 = cos(a1)*sin(DELTA_P/2);
+    double q2 = sin(a2)*cos(DELTA_P/2);
+
+    psSphereRot *myST = psSphereRotQuat(q0*2.0, q1*2.0, q2*2.0, q3*2.0);
+    // Verify null not returned
+    if(myST == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Returned NULL with valid parameters");
+        return 1;
+    }
+
+    //    printf("\n q0=%lf, q1=%lf, q2=%lf, q3=%lf,\n", q0, q1, q2, q3);
+    //    printf("myq0=%lf, myq1=%lf, myq2=%lf, myq3=%lf\n", myST->q0, myST->q1, myST->q2, myST->q3);
+    if (FLT_EPSILON < fabs(q0 - myST->q0)) {
+        psError(PS_ERR_UNKNOWN,true,"myST->q0 is %lf, should be %lf\n", myST->q0, q0);
+        return 2;
+    }
+    if (FLT_EPSILON < fabs(q1 - myST->q1)) {
+        psError(PS_ERR_UNKNOWN,true,"myST->q1 is %f, should be %f\n", myST->q1, q1);
+        return 3;
+    }
+    if (FLT_EPSILON < fabs(q2 - myST->q2)) {
+        psError(PS_ERR_UNKNOWN,true,"myST->q2 is %f, should be %f\n", myST->q2, q2);
+        return 4;
+    }
+    if (FLT_EPSILON < fabs(q3 - myST->q3)) {
+        psError(PS_ERR_UNKNOWN,true,"myST->q0 is %f, should be %f\n", myST->q3, q3);
+        return 5;
+    }
+
+    // Free data structure
+    psFree(myST);
+
+    return 0;
+}
+
+
 // We do a simple identity transformation on a few RA, DEC pairs.
 psS32 testSphereRotApply1( void )
 {
-    /*
-        psSphere *in = psSphereAlloc();
-        psSphere *out = psSphereAlloc();
-        psSphere *temp = NULL;
-        psSphere *rc = NULL;
-        psSphereRot *myST = psSphereRotAlloc(0.0, 0.0, 0.0);
-
-        for (float r=0.0;r<180.0;r+=DEG_INC) {
-            for (float d=0.0;d<90.0;d+=DEG_INC) {
-                in->r = DEG_TO_RAD(r);
-                in->d = DEG_TO_RAD(d);
-                in->rErr = 0.0;
-                in->dErr = 0.0;
-
-                if(psSphereRotApply(out, myST, in) != out) {
-                    psError(PS_ERR_UNKNOWN,true,"Did not return output pointer.");
-                    return 1;
-                }
-                if (ERROR_TOL < fabs(out->r - in->r)) {
-                    psError(PS_ERR_UNKNOWN,true,"out->r is %f, should be %f\n", out->r, in->r);
-                    return 2;
-                }
-                if (ERROR_TOL < fabs(out->d - in->d)) {
-                    psError(PS_ERR_UNKNOWN,true,"out->d is %f, should be %f\n", out->d, in->d);
-                    return 3;
-                }
-            }
-        }
-
-        // Verify new sphere object is created if out parameter NULL
-        temp = psSphereRotApply(NULL, myST, in);
-        if ( temp == NULL) {
-            psError(PS_ERR_UNKNOWN,true,"Returned NULL when out parameter was null");
-            return 4;
-        }
-        psFree(temp);
-
-        // Verify NULL returned if transform structure null
-        psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error");
-        rc = psSphereRotApply(NULL, NULL, in);
-        if (rc != NULL) {
-            psError(PS_ERR_UNKNOWN,true,"psSphereRotApply() did not return NULL.");
-            return 5;
-        }
-
-        // Verify NULL returned when input sphere is NULL
-        psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error");
-        rc = psSphereRotApply(NULL, myST, NULL);
-        if (rc != NULL) {
-            psError(PS_ERR_UNKNOWN,true,"psSphereRotApply() did not return NULL");
-            return 6;
-        }
-
-        psFree(myST);
-        psFree(out);
-        psFree(in);
-    */
+
+    psSphere *in = psSphereAlloc();
+    psSphere *out = psSphereAlloc();
+    psSphere *temp = NULL;
+    psSphere *rc = NULL;
+    //        psSphereRot *myST = psSphereRotAlloc(0.0, 0.0, 0.0);
+    psSphereRot *myST = psSphereRotAlloc(ALPHA_P, DELTA_P, PHI_P);
+
+    for (float r=0.0;r<180.0;r+=DEG_INC) {
+        for (float d=0.0;d<90.0;d+=DEG_INC) {
+            in->r = DEG_TO_RAD(r);
+            in->d = DEG_TO_RAD(d);
+            in->rErr = 0.0;
+            in->dErr = 0.0;
+
+            if(psSphereRotApply(out, myST, in) != out) {
+                psError(PS_ERR_UNKNOWN,true,"Did not return output pointer.");
+                return 1;
+            }
+            psSphereRotInvert(myST);
+            psSphereRotApply(out, myST, out);
+
+            if (ERROR_TOL < fabs(out->r - in->r)) {
+                psError(PS_ERR_UNKNOWN,true,"out->r is %f, should be %f\n", out->r, in->r);
+                return 2;
+            }
+            if (ERROR_TOL < fabs(out->d - in->d)) {
+                psError(PS_ERR_UNKNOWN,true,"out->d is %f, should be %f\n", out->d, in->d);
+                return 3;
+            }
+        }
+    }
+    // Verify new sphere object is created if out parameter NULL
+    temp = psSphereRotApply(NULL, myST, in);
+    if ( temp == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Returned NULL when out parameter was null");
+        return 4;
+    }
+    psFree(temp);
+
+    // Verify NULL returned if transform structure null
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error");
+    rc = psSphereRotApply(NULL, NULL, in);
+    if (rc != NULL) {
+        psError(PS_ERR_UNKNOWN,true,"psSphereRotApply() did not return NULL.");
+        return 5;
+    }
+
+    // Verify NULL returned when input sphere is NULL
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error");
+    rc = psSphereRotApply(NULL, myST, NULL);
+    if (rc != NULL) {
+        psError(PS_ERR_UNKNOWN,true,"psSphereRotApply() did not return NULL");
+        return 6;
+    }
+
+    psFree(myST);
+    psFree(out);
+    psFree(in);
+
     return 0;
 }
 
-/******************************************************************************
-testSphereRotApply2(): This test verifies that psSphereRotApply()
-works properly.  We create two psSphereRots: 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?
-    psSphereRotAlloc(X, Y, 0.0)
-    psSphereRotAlloc(-X, -Y, 0.0)
- *****************************************************************************/
 #define ERROR_PERCENT 0.01
-psS32 testSphereRotApply2( void )
-{
-    /*
-        psS32 testStatus = 0;
-        psSphere in;
-        psSphere out;
-        psSphere out2;
-        psSphereRot *mySphereRotForward = NULL;
-        psSphereRot *mySphereRotReverse = NULL;
-
-
-        mySphereRotForward = psSphereRotAlloc(DEG_TO_RAD(22.0),
-                                              0.0,
-                                              0.0);
-        mySphereRotReverse = psSphereRotAlloc(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;
-
-                psSphereRotApply(&out, mySphereRotForward, &in);
-                psSphereRotApply(&out2, mySphereRotReverse, &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(mySphereRotForward);
-        psFree(mySphereRotReverse);
-
-        mySphereRotForward = psSphereRotAlloc(0.0,
-                                              DEG_TO_RAD(33.0),
-                                              0.0);
-        mySphereRotReverse = psSphereRotAlloc(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;
-
-                psSphereRotApply(&out, mySphereRotForward, &in);
-                psSphereRotApply(&out2, mySphereRotReverse, &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(mySphereRotForward);
-        psFree(mySphereRotReverse);
-
-        return(testStatus);
-        */
-    return 0;
-}
 
 psS32 testSphereRotApplyCelestial( void)
