Index: trunk/SophyaExt/XephemAstroLib/mjd.c
===================================================================
--- trunk/SophyaExt/XephemAstroLib/mjd.c	(revision 1719)
+++ trunk/SophyaExt/XephemAstroLib/mjd.c	(revision 2551)
@@ -4,5 +4,4 @@
 #include <math.h>
 
-#include "P_.h"
 #include "astro.h"
 
@@ -12,8 +11,5 @@
  */
 void
-cal_mjd (mn, dy, yr, mjd)
-int mn, yr;
-double dy;
-double *mjd;
+cal_mjd (int mn, double dy, int yr, double *mjp)
 {
 	static double last_mjd, last_dy;
@@ -23,5 +19,5 @@
 
 	if (mn == last_mn && yr == last_yr && dy == last_dy) {
-	    *mjd = last_mjd;
+	    *mjp = last_mjd;
 	    return;
 	}
@@ -49,22 +45,19 @@
 	d = (int)(30.6001*(m+1));
 
-	*mjd = b + c + d + dy - 0.5;
+	*mjp = b + c + d + dy - 0.5;
 
 	last_mn = mn;
 	last_dy = dy;
 	last_yr = yr;
-	last_mjd = *mjd;
+	last_mjd = *mjp;
 }
 
 /* given the modified Julian date (number of days elapsed since 1900 jan 0.5,),
- * mjd, return the calendar date in months, *mn, days, *dy, and years, *yr.
- */
-void
-mjd_cal (mjd, mn, dy, yr)
-double mjd;
-int *mn, *yr;
-double *dy;
-{
-	static double last_mjd, last_dy;
+ * mj, return the calendar date in months, *mn, days, *dy, and years, *yr.
+ */
+void
+mjd_cal (double mj, int *mn, double *dy, int *yr)
+{
+	static double last_mj, last_dy;
 	static int last_mn, last_yr;
 	double d, f;
@@ -74,5 +67,5 @@
 	 * 0 is noon the last day of 1899.
 	 */
-	if (mjd == 0.0) {
+	if (mj == 0.0) {
 	    *mn = 12;
 	    *dy = 31.5;
@@ -81,5 +74,5 @@
 	}
 
-	if (mjd == last_mjd) {
+	if (mj == last_mj) {
 	    *mn = last_mn;
 	    *yr = last_yr;
@@ -88,5 +81,5 @@
 	}
 
-	d = mjd + 0.5;
+	d = mj + 0.5;
 	i = floor(d);
 	f = d-i;
@@ -118,5 +111,5 @@
 	last_dy = *dy;
 	last_yr = *yr;
-	last_mjd = mjd;
+	last_mj = mj;
 }
 
@@ -126,7 +119,5 @@
  */
 int
-mjd_dow (mjd, dow)
-double mjd;
-int *dow;
+mjd_dow (double mj, int *dow)
 {
 	/* cal_mjd() uses Gregorian dates on or after Oct 15, 1582.
@@ -137,9 +128,9 @@
 	 * can not easily be accounted for from the cal_mjd() number...
 	 */
-	if (mjd < -53798.5) {
+	if (mj < -53798.5) {
 	    /* pre sept 14, 1752 too hard to correct |:-S */
 	    return (-1);
 	}
-	*dow = ((long)floor(mjd-.5) + 1) % 7;/* 1/1/1900 (mjd 0.5) is a Monday*/
+	*dow = ((long)floor(mj-.5) + 1) % 7;/* 1/1/1900 (mj 0.5) is a Monday*/
 	if (*dow < 0)
 	    *dow += 7;
@@ -149,6 +140,5 @@
 /* given a year, return whether it is a leap year */
 int
-isleapyear (y)
-int y;
+isleapyear (int y)
 {
 	return ((y%4==0 && y%100!=0) || y%400==0);
@@ -157,7 +147,5 @@
 /* given a mjd, return the the number of days in the month.  */
 void
-mjd_dpm (mjd, ndays)
-double mjd;
-int *ndays;
+mjd_dpm (double mj, int *ndays)
 {
 	static short dpm[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
@@ -165,5 +153,5 @@
 	double d;
 
-	mjd_cal (mjd, &m, &d, &y);
+	mjd_cal (mj, &m, &d, &y);
 	*ndays = (m==2 && isleapyear(y)) ? 29 : dpm[m-1];
 }
@@ -171,8 +159,5 @@
 /* given a mjd, return the year and number of days since 00:00 Jan 1 */
 void
-mjd_dayno (mjd, yr, dy)
-double mjd;
-int *yr;
-double *dy;
+mjd_dayno (double mj, int *yr, double *dy)
 {
 	double yrd;
@@ -180,5 +165,5 @@
 	int dpy;
 
-	mjd_year (mjd, &yrd);
+	mjd_year (mj, &yrd);
 	*yr = yri = (int)yrd;
 	dpy = isleapyear(yri) ? 366 : 365;
@@ -188,25 +173,23 @@
 /* given a mjd, return the year as a double. */
 void
-mjd_year (mjd, yr)
-double mjd;
-double *yr;
-{
-	static double last_mjd, last_yr;
+mjd_year (double mj, double *yr)
+{
+	static double last_mj, last_yr;
 	int m, y;
 	double d;
 	double e0, e1;	/* mjd of start of this year, start of next year */
 
-	if (mjd == last_mjd) {
+	if (mj == last_mj) {
 	    *yr = last_yr;
 	    return;
 	}
 
-	mjd_cal (mjd, &m, &d, &y);
+	mjd_cal (mj, &m, &d, &y);
 	if (y == -1) y = -2;
 	cal_mjd (1, 1.0, y, &e0);
 	cal_mjd (1, 1.0, y+1, &e1);
-	*yr = y + (mjd - e0)/(e1 - e0);
-
-	last_mjd = mjd;
+	*yr = y + (mj - e0)/(e1 - e0);
+
+	last_mj = mj;
 	last_yr = *yr;
 }
@@ -214,7 +197,5 @@
 /* given a decimal year, return mjd */
 void
-year_mjd (y, mjd)
-double y;
-double *mjd;
+year_mjd (double y, double *mjp)
 {
 	double e0, e1;	/* mjd of start of this year, start of next year */
@@ -224,11 +205,10 @@
 	cal_mjd (1, 1.0, yf, &e0);
 	cal_mjd (1, 1.0, yf+1, &e1);
-	*mjd = e0 + (y - yf)*(e1-e0);
+	*mjp = e0 + (y - yf)*(e1-e0);
 }
 
 /* round a time in days, *t, to the nearest second, IN PLACE. */
 void
-rnd_second (t)
-double *t;
+rnd_second (double *t)
 {
 	*t = floor(*t*SPD+0.5)/SPD;
@@ -237,16 +217,14 @@
 /* given an mjd, truncate it to the beginning of the whole day */
 double
-mjd_day(jd)
-double jd;
-{
-	return (floor(jd-0.5)+0.5);
+mjd_day(double mj)
+{
+	return (floor(mj-0.5)+0.5);
 }
 
 /* given an mjd, return the number of hours past midnight of the whole day */
 double
-mjd_hr(jd)
-double jd;
-{
-	return ((jd-mjd_day(jd))*24.0);
+mjd_hr(double mj)
+{
+	return ((mj-mjd_day(mj))*24.0);
 }
 
@@ -254,10 +232,25 @@
  */
 void
-range (v, r)
-double *v, r;
+range (double *v, double r)
 {
 	*v -= r*floor(*v/r);
 }
 
+/* insure 0 <= ra < 2PI and -PI/2 <= dec <= PI/2. if dec needs 
+ * complimenting, reflect ra too
+ */
+void
+radecrange (double *ra, double *dec)
+{
+	if (*dec < -PI/2) {
+	    *dec = -PI - *dec;
+	    *ra += PI;
+	} else if (*dec > PI/2) {
+	    *dec = PI - *dec;
+	    *ra += PI;
+	}
+	range (ra, 2*PI);
+}
+
 /* For RCS Only -- Do Not Edit */
-static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: mjd.c,v $ $Date: 2001-10-22 12:08:27 $ $Revision: 1.2 $ $Name: not supported by cvs2svn $"};
+static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: mjd.c,v $ $Date: 2004-06-15 16:52:39 $ $Revision: 1.3 $ $Name: not supported by cvs2svn $"};
