Index: trunk/psLib/src/astro/psSphereOps.c
===================================================================
--- trunk/psLib/src/astro/psSphereOps.c	(revision 5306)
+++ trunk/psLib/src/astro/psSphereOps.c	(revision 5319)
@@ -6,7 +6,8 @@
  *
  *  @author Robert DeSonia, MHPCC
+ *  @author Dave Robbins, 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-14 00:07:37 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -62,5 +63,4 @@
     // calculate t*s*r.
     psSphereRot* result = psSphereRotCombine(NULL,&t,&s);
-    psMemSetDeallocator(result, (psFreeFunc)sphereRotFree);
     psSphereRotCombine(result,result,&r);
 
@@ -79,5 +79,6 @@
                              double q3)
 {
-    psSphereRot* rot = psAlloc(sizeof(psSphereRot));
+    psSphereRot* rot = (psSphereRot*)psAlloc(sizeof(psSphereRot));
+    psMemSetDeallocator(rot, (psFreeFunc)sphereRotFree);
 
     double len = sqrt(q0*q0 + q1*q1 + q2*q2 + q3*q3);
@@ -113,19 +114,33 @@
                                  sin(coord->d),
                                  0.0);
-    psSphereRot* coordQuatConjugate = psSphereRotQuat(
-                                          coordQuat->q0, coordQuat->q1, coordQuat->q2, coordQuat->q3);
-    coordQuat = psSphereRotInvert(coordQuat);
+    //    psSphereRot* coordQuatConjugate = psSphereRotQuat(
+    //                                       coordQuat->q0, coordQuat->q1, coordQuat->q2, coordQuat->q3);
+    //    coordQuat = psSphereRotInvert(coordQuat);
 
     // calculate q=(rp)r'
-    coordQuat = psSphereRotCombine(coordQuat, transform, coordQuat);
-    coordQuat = psSphereRotCombine(coordQuat, coordQuat, coordQuatConjugate);
+    //    coordQuat = psSphereRotCombine(coordQuat, transform, coordQuat);
+    //    coordQuat = psSphereRotCombine(coordQuat, coordQuat, coordQuatConjugate);
     // N.B., we can recycle coordQuat right away due to the implementation of
     // psSphereRotCombine; it puts the input values in a local variable first
 
-    out->r = atan2(coordQuat->q1,coordQuat->q0);
-    out->d = asin(coordQuat->q2);
+    //    out->r = atan2(coordQuat->q1,coordQuat->q0);
+    //    out->d = asin(coordQuat->q2);
+
+
+    //     psSphereRot *inv = psSphereRotInvert(transform);
+    psSphereRot *inv = (psSphereRot*)psAlloc(sizeof(psSphereRot));
+    *inv = *transform;
+    psSphereRot *result = psSphereRotCombine(NULL, transform, coordQuat);
+    psSphereRotInvert(inv);
+    psSphereRotCombine(result, result, inv);
+    out->r = atan2(result->q1, result->q0);
+    out->d = asin(result->q2);
+    out->rErr = 0.0;
+    out->dErr = 0.0;
+    psFree(inv);
+    psFree(result);
 
     psFree(coordQuat);
-    psFree(coordQuatConjugate);
+    //    psFree(coordQuatConjugate);
 
     return out;
@@ -141,4 +156,5 @@
     if (out == NULL) {
         out = (psSphereRot* ) psAlloc(sizeof(psSphereRot));
+        psMemSetDeallocator(out, (psFreeFunc)sphereRotFree);
     }
 
