Index: /trunk/psLib/src/astro/psEarthOrientation.c
===================================================================
--- /trunk/psLib/src/astro/psEarthOrientation.c	(revision 5445)
+++ /trunk/psLib/src/astro/psEarthOrientation.c	(revision 5446)
@@ -6,8 +6,9 @@
 *  @ingroup EarthOrientation
 *
+*  @author Dave Robbins, MHPCC
 *  @author Robert Daniel DeSonia, MHPCC
 *
-*  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-10-07 21:27:49 $
+*  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-10-26 01:20:15 $
 *
 *  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
@@ -166,20 +167,22 @@
 psSphere *psGravityDeflection(psSphere *apparent, psSphere *actual, psSphere *sun)
 {
-    // calculating the apparent angle from the actual angle and the sun position
-
-    // first, calculate the angle between the sun vector and the actual vector
+    PS_ASSERT_PTR_NON_NULL(apparent, NULL);
+    PS_ASSERT_PTR_NON_NULL(sun, NULL);
+
+    // calculating the actual angle from the apparent angle and the sun position
+
+    // first, calculate the angle between the sun vector and the apparent vector
 
     // Moving to cartesian first:  XXX -- is this required?
     psCube* sunVector = psSphereToCube(sun);
-    psCube* actualVector = psSphereToCube(actual);
+    psCube* apparentVector = psSphereToCube(apparent);
 
     // use dot product to calculate the angle of separation
     // N.B., assuming the psSphereToCube function returns a unit vector.
-    double theta = acos(sunVector->x*actualVector->x +
-                        sunVector->y*actualVector->y +
-                        sunVector->z*actualVector->z);
+    double theta = acos(sunVector->x*apparentVector->x +
+                        sunVector->y*apparentVector->y +
+                        sunVector->z*apparentVector->z);
 
     double r0 = PS_AU * tan(theta);
-
     double deflection = 4.0*PS_G*PS_M/(PS_C0*PS_C0*r0);
 
@@ -187,12 +190,34 @@
     double limit = SEC_TO_RAD(1.75);
     if (deflection > limit) {
-        deflection = limit;
-    }
-
-    // bend the actual vector away from the sun vector by deflection angle.
+        //       deflection = limit;
+        //if deflection is greater than limit, the light rays will hit the sun
+        psWarning("Invalid positions.  Light ray will not be seen on earth.\n");
+        psFree(apparentVector);
+        psFree(sunVector);
+        return actual;
+    }
+
+    if (actual == NULL) {
+        actual = psSphereAlloc();
+    } else {
+        actual->r = 0.0;
+        actual->d = 0.0;
+        actual->rErr = 0.0;
+        actual->dErr = 0.0;
+    }
+
+    // bend the apparent vector away from the sun vector by deflection angle.
     // XXX: Not sure how to do this.  Dave thinks the formula should be:
     //      theta = atan(r0/d)*tan(deflection), phi = thete/tan(deflection)
-
-    return NULL;
+    theta = 0.0;
+    double phi = 0.0;
+    deflection = SEC_TO_RAD(deflection);
+    theta = atan(r0/PS_AU) * tan(deflection);
+    phi = sqrt( deflection*deflection - theta*theta );
+    actual->r = theta;
+    actual->d = phi;
+    psFree(apparentVector);
+    psFree(sunVector);
+    return actual;
 }
 
Index: /trunk/psLib/src/astro/psEarthOrientation.h
===================================================================
--- /trunk/psLib/src/astro/psEarthOrientation.h	(revision 5445)
+++ /trunk/psLib/src/astro/psEarthOrientation.h	(revision 5446)
@@ -6,8 +6,9 @@
 *  @ingroup EarthOrientation
 *
+*  @author Dave Robbins, MHPCC
 *  @author Robert Daniel DeSonia, MHPCC
 *
-*  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-10-13 20:23:57 $
+*  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-10-26 01:20:15 $
 *
 *  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
@@ -55,13 +56,17 @@
 );
 
-/**
+/** Calculates the actual position of a star, given its apparent position and the
+ *  position of the sun.
  *
+ *  The actual and apparent positions are represented as psSphere entries, as is
+ *  position of the sun.  If the value of actual is NULL, a new psSphere is allocated,
+ *  otherwise the point to actual is used for the result.
  *
- *
+ *  @return psSphere*:      the apparent position of a star.
  */
 psSphere *psGravityDeflection(
-    psSphere *apparent,                ///<
-    psSphere *actual,                  ///<
-    psSphere *sun                      ///<
+    psSphere *apparent,                ///< apparent position of star
+    psSphere *actual,                  ///< actual position of star
+    psSphere *sun                      ///< position of the sun
 );
 
Index: /trunk/psLib/src/pslib_strict.h
===================================================================
--- /trunk/psLib/src/pslib_strict.h	(revision 5445)
+++ /trunk/psLib/src/pslib_strict.h	(revision 5446)
@@ -9,6 +9,6 @@
 *  @author Eric Van Alst, MHPCC
 *
-*  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-10-06 02:41:07 $
+*  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-10-26 01:20:14 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -31,4 +31,5 @@
 #include "psCoord.h"
 #include "psSphereOps.h"
+#include "psEarthOrientation.h"
 /// @}
 
Index: /trunk/psLib/test/astro/tst_psEarthOrientation.c
===================================================================
--- /trunk/psLib/test/astro/tst_psEarthOrientation.c	(revision 5445)
+++ /trunk/psLib/test/astro/tst_psEarthOrientation.c	(revision 5446)
@@ -6,6 +6,6 @@
 *  @author d-Rob, MHPCC
 *
-*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-10-13 20:23:57 $
+*  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-10-26 01:20:15 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -15,5 +15,20 @@
 #include "pslib_strict.h"
 
+static psS32 testEOCParallax(void);
+static psS32 testAberration(void);
+static psS32 testGravityDeflect(void);
+static psS32 testEOCPrecession(void);
+static psS32 testEOCPolar(void);
+static psS32 testEOCNutation(void);
+static psS32 testSphereRotTransforms(void);
+
 testDescription tests[] = {
+                              {testEOCParallax, 666, "psEOCParallax()", 0, false},
+                              {testAberration, 667, "psAberration()", 0, false},
+                              {testGravityDeflect, 668, "psGravityDeflect()", 0, false},
+                              {testEOCPrecession, 669, "psEOCPrecession()", 0, false},
+                              {testEOCPolar, 670, "psEOCPolar()", 0, false},
+                              {testEOCNutation, 671, "psEOCNutation()", 0, false},
+                              {testSphereRotTransforms, 672, "psSphereRotTransforms()", 0, false},
                               {NULL}
                           };
@@ -23,7 +38,65 @@
     psLogSetLevel( PS_LOG_INFO );
 
-    return ( ! runTestSuite( stderr, "psCoord", tests, argc, argv ) );
+    return ( ! runTestSuite( stderr, "psEarthOrientation", tests, argc, argv ) );
 }
 
+psS32 testEOCParallax(void)
+{
 
+    return 0;
+}
 
+psS32 testAberration(void)
+{
+
+    return 0;
+}
+
+psS32 testGravityDeflect(void)
+{
+
+    psSphere *actual = NULL;
+    psSphere *apparent = psSphereAlloc();
+    psSphere *sun = psSphereAlloc();
+
+    sun->r = 0.2;
+    sun->d = 0.2;
+    apparent->r = 0.2035;
+    apparent->d = 0.2035;
+
+    actual = psGravityDeflection(apparent, actual, sun);
+    psSphere *result = psSphereSetOffset(apparent, actual, PS_SPHERICAL, PS_RADIAN);
+    printf("\nApparent r,d = %.13g,%.13g    Actual r,d = %.13g, %.13g \n",
+           apparent->r, apparent->d, result->r, result->d);
+    psFree(result);
+    psFree(actual);
+    psFree(apparent);
+    psFree(sun);
+
+    return 0;
+}
+
+psS32 testEOCPrecession(void)
+{
+
+    return 0;
+}
+
+psS32 testEOCPolar(void)
+{
+
+    return 0;
+}
+
+psS32 testEOCNutation(void)
+{
+
+    return 0;
+}
+
+psS32 testSphereRotTransforms(void)
+{
+
+    return 0;
+}
+
Index: /trunk/psLib/test/astro/tst_psSphereOps.c
===================================================================
--- /trunk/psLib/test/astro/tst_psSphereOps.c	(revision 5445)
+++ /trunk/psLib/test/astro/tst_psSphereOps.c	(revision 5446)
@@ -6,6 +6,6 @@
 *  @author d-Rob, MHPCC
 *
-*  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-10-25 00:38:00 $
+*  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-10-26 01:20:15 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -35,5 +35,5 @@
     psLogSetLevel( PS_LOG_INFO );
 
-    return ( ! runTestSuite( stderr, "psCoord", tests, argc, argv ) );
+    return ( ! runTestSuite( stderr, "psSphereOps", tests, argc, argv ) );
 }
 
