Index: trunk/psLib/src/astro/psCoord.c
===================================================================
--- trunk/psLib/src/astro/psCoord.c	(revision 1531)
+++ trunk/psLib/src/astro/psCoord.c	(revision 1532)
@@ -10,10 +10,12 @@
 *  @author George Gusciora, MHPCC
 *
-*  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-13 23:33:13 $
+*  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-13 23:43:29 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
 */
-
+/******************************************************************************/
+/*  INCLUDE FILES                                                             */
+/******************************************************************************/
 #include "psType.h"
 #include "psImage.h"
@@ -26,141 +28,39 @@
 #include <math.h>
 #include <float.h>
-
-static float cot(float x);
-static float arg(float x, float y);
-
-psPlane* psPlaneTransformApply(psPlane* out,
-                               const psPlaneTransform* transform,
-                               const psPlane* coords)
-{
-    if (out == NULL) {
-        out = (psPlane* ) psAlloc(sizeof(psPlane));
-    }
-    out->x = transform->x->coeff[0][0] +
-             (transform->x->coeff[1][0] * coords->x) +
-             (transform->x->coeff[0][1] * coords->y);
-
-    out->y = transform->y->coeff[0][0] +
-             (transform->y->coeff[1][0] * coords->x) +
-             (transform->y->coeff[0][1] * coords->y);
-
-    return (out);
-}
-
-// This transformation takes into account parameters beyond an objects
-// spatial coordinates: term3 and term4 (magnitude and color).
-psPlane* psPlaneDistortApply(psPlane* out,
-                             const psPlaneDistort* transform,
-                             const psPlane* coords,
-                             float term3,
-                             float term4)
-{
-    if (out == NULL) {
-        out = (psPlane* ) psAlloc(sizeof(psPlane));
-    }
-
-    out->x = transform->x->coeff[0][0][0][0] +
-             (transform->x->coeff[1][0][0][0] * coords->x) +
-             (transform->x->coeff[0][1][0][0] * coords->y) +
-             (transform->x->coeff[0][0][1][0] * term3) +
-             (transform->x->coeff[0][0][0][1] * term4);
-
-    out->y = transform->y->coeff[0][0][0][0] +
-             (transform->y->coeff[1][0][0][0] * coords->x) +
-             (transform->y->coeff[0][1][0][0] * coords->y) +
-             (transform->y->coeff[0][0][1][0] * term3) +
-             (transform->y->coeff[0][0][0][1] * term4);
-
-    return (out);
-}
-
-// This function prototype has been modified since the SDRS.
-psSphereTransform* psSphereTransformAlloc(double NPlat,
-        double Xo,
-        double xo)
-{
-    psSphereTransform* tmp = (psSphereTransform* ) psAlloc(sizeof(psSphereTransform));
-
-    tmp->sinPhi = sin(NPlat);
-    tmp->cosPhi = cos(NPlat);
-    tmp->Xo = Xo;
-    tmp->xo = xo;
-
-    return (tmp);
-}
-
-/******************************************************************************
-This algorithm comes from an email from Gene.  I assume (x,y) corresponds to
-(r,d) in the sphere coordinates.
- 
-XXX: In Gene's email, there are different variables with similar names (y
-and Y) and in the code, there's cos_y, cos_Y, and cos(y).  Verify that there
-are no typo's.
- *****************************************************************************/
-psSphere* psSphereTransformApply(psSphere* out,
-                                 const psSphereTransform* transform,
-                                 const psSphere* coord)
-{
-    double sinY = 0.0;
-    double cosY = 0.0;
-    double sinX = 0.0;
-    double cosX = 0.0;
-    double x = 0.0;
-    double y = 0.0;
-    double dx = 0.0;
-
-    if (out == NULL) {
-        out = (psSphere* ) psAlloc(sizeof(psSphere));
-    }
-
-    x = coord->r;
-    y = coord->d;
-    dx = x - transform->xo;
-    sinY = cos(y) * sin(dx) * transform->sinPhi + sin(y) * transform->cosPhi;
-    cosY = sqrt(1.0 - sinY * sinY);
-    sinX = (cos(y) * sin(dx) * transform->cosPhi - sin(y) * transform->sinPhi) / cos(y);
-    cosX = cos(y) * cos(dx) / cos(y);
-
-    out->r = atan2(sinX, cosX) + transform->Xo;
-    out->d = atan2(sinY, cosY);
-
-    return (out);
-}
-
-psSphereTransform* psSphereTransformICRStoEcliptic(psTime time)
-{
-    struct tm *tmTime = psTimeToTM(time);
-    double year = (double)(1900 + tmTime->tm_year);
-    double T = year / 100.0;
-    double phi = -23.452294 + 0.013013 * T + 0.000001639 * T * T - 0.000000503 * T * T * T;
-    double Xo = 0.0;
-    double xo = 0.0;
-
-    return (psSphereTransformAlloc(phi, Xo, xo));
-}
-
-psSphereTransform* psSphereTransformEcliptictoICRS(psTime time)
-{
-    struct tm *tmTime = psTimeToTM(time);
-    double year = (double)(1900 + tmTime->tm_year);
-    double T = year / 100.0;
-    double phi = +23.452294 - 0.013013 * T - 0.000001639 * T * T + 0.000000503 * T * T * T;
-    double Xo = 0.0;
-    double xo = 0.0;
-
-    return (psSphereTransformAlloc(phi, Xo, xo));
-}
-
-psSphereTransform* psSphereTransformICRStoGalatic(void)
-{
-    return (psSphereTransformAlloc(62.6, 282.25, 33.0));
-}
-
-psSphereTransform* psSphereTransformGalatictoICRS(void)
-{
-    return (psSphereTransformAlloc(-62.6, 33.0, 282.25));
-}
-
-float cot(float x)
+/******************************************************************************/
+/*  DEFINE STATEMENTS                                                         */
+/******************************************************************************/
+
+// None
+
+/******************************************************************************/
+/*  TYPE DEFINITIONS                                                          */
+/******************************************************************************/
+
+// None
+
+/*****************************************************************************/
+/*  GLOBAL VARIABLES                                                         */
+/*****************************************************************************/
+
+// None
+
+/*****************************************************************************/
+/*  FILE STATIC VARIABLES                                                    */
+/*****************************************************************************/
+
+// None
+
+/*****************************************************************************/
+/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
+/*****************************************************************************/
+
+static float p_psCot(float x);
+static float p_psArg(float x, float y);
+
+/******************************************************************************
+XXX: Do this with a macro.
+ *****************************************************************************/
+float p_psCot(float x)
 {
     return (1.0 / atan(x));
@@ -170,6 +70,6 @@
 XXX: Verify this arc tan function.
  *****************************************************************************/
-float arg(float x,
-          float y)
+float p_psArg(float x,
+              float y)
 {
     if (x > 0) {
@@ -185,6 +85,145 @@
     }
 
-    psAbort(__func__, "Unacceptable range for (arg(%f, %f).\n", x, y);
+    psAbort(__func__, "Unacceptable range for (p_psArg(%f, %f).\n", x, y);
     return (0.0);
+}
+
+/*****************************************************************************/
+/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
+/*****************************************************************************/
+psPlane* psPlaneTransformApply(psPlane* out,
+                               const psPlaneTransform* transform,
+                               const psPlane* coords)
+{
+    if (out == NULL) {
+        out = (psPlane* ) psAlloc(sizeof(psPlane));
+    }
+    out->x = transform->x->coeff[0][0] +
+             (transform->x->coeff[1][0] * coords->x) +
+             (transform->x->coeff[0][1] * coords->y);
+
+    out->y = transform->y->coeff[0][0] +
+             (transform->y->coeff[1][0] * coords->x) +
+             (transform->y->coeff[0][1] * coords->y);
+
+    return (out);
+}
+
+/******************************************************************************
+This transformation takes into account parameters beyond an objects spatial
+coordinates: term3 and term4 (magnitude and color).
+ *****************************************************************************/
+psPlane* psPlaneDistortApply(psPlane* out,
+                             const psPlaneDistort* transform,
+                             const psPlane* coords,
+                             float color,
+                             float magnitude)
+{
+    if (out == NULL) {
+        out = (psPlane* ) psAlloc(sizeof(psPlane));
+    }
+
+    out->x = transform->x->coeff[0][0][0][0] +
+             (transform->x->coeff[1][0][0][0] * coords->x) +
+             (transform->x->coeff[0][1][0][0] * coords->y) +
+             (transform->x->coeff[0][0][1][0] * color) +
+             (transform->x->coeff[0][0][0][1] * magnitude);
+
+    out->y = transform->y->coeff[0][0][0][0] +
+             (transform->y->coeff[1][0][0][0] * coords->x) +
+             (transform->y->coeff[0][1][0][0] * coords->y) +
+             (transform->y->coeff[0][0][1][0] * color) +
+             (transform->y->coeff[0][0][0][1] * magnitude);
+
+    return (out);
+}
+
+/******************************************************************************
+This function prototype has been modified since the SDRS.
+ *****************************************************************************/
+psSphereTransform* psSphereTransformAlloc(double NPlat,
+        double Xo,
+        double xo)
+{
+    psSphereTransform* tmp = (psSphereTransform* ) psAlloc(sizeof(psSphereTransform));
+
+    tmp->sinPhi = sin(NPlat);
+    tmp->cosPhi = cos(NPlat);
+    tmp->Xo = Xo;
+    tmp->xo = xo;
+
+    return (tmp);
+}
+
+/******************************************************************************
+This algorithm comes from an email from Gene.  I assume (x,y) corresponds to
+(r,d) in the sphere coordinates.
+ 
+XXX: In Gene's email, there are different variables with similar names (y
+and Y) and in the code, there's cos_y, cos_Y, and cos(y).  Verify that there
+are no typo's.
+ *****************************************************************************/
+psSphere* psSphereTransformApply(psSphere* out,
+                                 const psSphereTransform* transform,
+                                 const psSphere* coord)
+{
+    double sinY = 0.0;
+    double cosY = 0.0;
+    double sinX = 0.0;
+    double cosX = 0.0;
+    double x = 0.0;
+    double y = 0.0;
+    double dx = 0.0;
+
+    if (out == NULL) {
+        out = (psSphere* ) psAlloc(sizeof(psSphere));
+    }
+
+    x = coord->r;
+    y = coord->d;
+    dx = x - transform->xo;
+    sinY = cos(y) * sin(dx) * transform->sinPhi + sin(y) * transform->cosPhi;
+    cosY = sqrt(1.0 - sinY * sinY);
+    sinX = (cos(y) * sin(dx) * transform->cosPhi - sin(y) * transform->sinPhi) / cos(y);
+    cosX = cos(y) * cos(dx) / cos(y);
+
+    out->r = atan2(sinX, cosX) + transform->Xo;
+    out->d = atan2(sinY, cosY);
+
+    return (out);
+}
+
+psSphereTransform* psSphereTransformICRStoEcliptic(psTime time)
+{
+    struct tm *tmTime = psTimeToTM(time);
+    double year = (double)(1900 + tmTime->tm_year);
+    double T = year / 100.0;
+    double phi = -23.452294 + 0.013013 * T + 0.000001639 * T * T - 0.000000503 * T * T * T;
+    double Xo = 0.0;
+    double xo = 0.0;
+
+    return (psSphereTransformAlloc(phi, Xo, xo));
+}
+
+psSphereTransform* psSphereTransformEcliptictoICRS(psTime time)
+{
+    struct tm *tmTime = psTimeToTM(time);
+    double year = (double)(1900 + tmTime->tm_year);
+    double T = year / 100.0;
+    double phi = +23.452294 - 0.013013 * T - 0.000001639 * T * T + 0.000000503 * T * T * T;
+    double Xo = 0.0;
+    double xo = 0.0;
+
+    return (psSphereTransformAlloc(phi, Xo, xo));
+}
+
+psSphereTransform* psSphereTransformICRStoGalatic(void)
+{
+    return (psSphereTransformAlloc(62.6, 282.25, 33.0));
+}
+
+psSphereTransform* psSphereTransformGalatictoICRS(void)
+{
+    return (psSphereTransformAlloc(-62.6, 33.0, 282.25));
 }
 
@@ -201,5 +240,5 @@
 
     if (projection->type == PS_PROJ_TAN) {
-        R = cot(coord->r) * (180.0 / M_PI);
+        R = p_psCot(coord->r) * (180.0 / M_PI);
         tmp->x = R * sin(coord->d);
         tmp->y = R * cos(coord->d);
@@ -249,10 +288,10 @@
     if (projection->type == PS_PROJ_TAN) {
         R = sqrt((coord->x * coord->x) + (coord->y * coord->y));
-        tmp->d = arg(-coord->y, coord->x);
+        tmp->d = p_psArg(-coord->y, coord->x);
         tmp->r = atan(180.0 / (R * M_PI));
 
     } else if (projection->type == PS_PROJ_SIN) {
         R = sqrt((coord->x * coord->x) + (coord->y * coord->y));
-        tmp->d = arg(-coord->y, coord->x);
+        tmp->d = p_psArg(-coord->y, coord->x);
         tmp->r = acos((R * M_PI) / 180.0);
 
@@ -271,5 +310,5 @@
         chu2 *= chu2;
         chu = sqrt(1.0 - chu1 - chu2);
-        tmp->d = 2.0 * arg((2.0 * chu * chu) - 1.0, (coord->x * chu * M_PI) / 360.0);
+        tmp->d = 2.0 * p_psArg((2.0 * chu * chu) - 1.0, (coord->x * chu * M_PI) / 360.0);
         tmp->r = asin((coord->y * chu * M_PI) / 180.0);
 
@@ -314,4 +353,5 @@
         lin = psProject(position2, &proj);
         tmp = psDeproject(lin, &proj);
+        psFree(lin);
 
         // XXX: Do we need to convert units in tmp?
@@ -349,8 +389,8 @@
 
 /******************************************************************************
-XXX: Do I need to check for unacceptable transformation parameters?  Maybe,
+XXX: Do we need to check for unacceptable transformation parameters?  Maybe,
      if the points are on the North/South Pole, etc?
  
-XXX: Do I need to somehow scale this projection?
+XXX: Do we need to somehow scale this projection?
  
 XXX: I copied the algorithm from the ADD exactly.
