Index: trunk/SophyaExt/XephemAstroLib/earthsat.c
===================================================================
--- trunk/SophyaExt/XephemAstroLib/earthsat.c	(revision 1719)
+++ trunk/SophyaExt/XephemAstroLib/earthsat.c	(revision 2551)
@@ -23,12 +23,7 @@
 #include <math.h>
 #include <string.h>
-
-#if defined(__STDC__)
 #include <stdlib.h>
-#endif
-
-#include "P_.h"
+
 #include "astro.h"
-#include "circum.h"
 #include "preferences.h"
 
@@ -42,36 +37,37 @@
 typedef double MAT3x3[3][3];
 
-static void esat_prop P_((Now *np, Obj *op, double *SatX, double *SatY, double
-    *SatZ, double *SatVX, double *SatVY, double *SatVZ));
-static void GetSatelliteParams P_((Obj *op));
-static void GetSiteParams P_((Now *np));
-static double Kepler P_((double MeanAnomaly, double Eccentricity));
-static void GetSubSatPoint P_((double SatX, double SatY, double SatZ,
-    double T, double *Latitude, double *Longitude, double *Height));
-static void GetSatPosition P_((double EpochTime, double EpochRAAN,
+static int crazyOp (Now *np, Obj *op);
+static void esat_prop (Now *np, Obj *op, double *SatX, double *SatY, double
+    *SatZ, double *SatVX, double *SatVY, double *SatVZ);
+static void GetSatelliteParams (Obj *op);
+static void GetSiteParams (Now *np);
+static double Kepler (double MeanAnomaly, double Eccentricity);
+static void GetSubSatPoint (double SatX, double SatY, double SatZ,
+    double T, double *Latitude, double *Longitude, double *Height);
+static void GetSatPosition (double EpochTime, double EpochRAAN,
     double EpochArgPerigee, double SemiMajorAxis, double Inclination,
     double Eccentricity, double RAANPrecession, double PerigeePrecession,
     double T, double TrueAnomaly, double *X, double *Y, double *Z,
-    double *Radius, double *VX, double *VY, double *VZ));
-static void GetSitPosition P_((double SiteLat, double SiteLong,
+    double *Radius, double *VX, double *VY, double *VZ);
+static void GetSitPosition (double SiteLat, double SiteLong,
     double SiteElevation, double CrntTime, double *SiteX, double *SiteY,
-    double *SiteZ, double *SiteVX, double *SiteVY, MAT3x3 SiteMatrix));
-static void GetRange P_((double SiteX, double SiteY, double SiteZ,
+    double *SiteZ, double *SiteVX, double *SiteVY, MAT3x3 SiteMatrix);
+static void GetRange (double SiteX, double SiteY, double SiteZ,
     double SiteVX, double SiteVY, double SatX, double SatY, double SatZ,
     double SatVX, double SatVY, double SatVZ, double *Range,
-    double *RangeRate));
-static void GetTopocentric P_((double SatX, double SatY, double SatZ,
+    double *RangeRate);
+static void GetTopocentric (double SatX, double SatY, double SatZ,
     double SiteX, double SiteY, double SiteZ, MAT3x3 SiteMatrix, double *X,
-    double *Y, double *Z));
-static void GetBearings P_((double SatX, double SatY, double SatZ,
+    double *Y, double *Z);
+static void GetBearings (double SatX, double SatY, double SatZ,
     double SiteX, double SiteY, double SiteZ, MAT3x3 SiteMatrix,
-    double *Azimuth, double *Elevation));
-static int Eclipsed P_((double SatX, double SatY, double SatZ,
-    double SatRadius, double CrntTime));
-static void InitOrbitRoutines P_((double EpochDay, int AtEod));
+    double *Azimuth, double *Elevation);
+static int Eclipsed (double SatX, double SatY, double SatZ,
+    double SatRadius, double CrntTime);
+static void InitOrbitRoutines (double EpochDay, int AtEod);
 
 #ifdef USE_ORBIT_PROPAGATOR 
-static void GetPrecession P_((double SemiMajorAxis, double Eccentricity,
-    double Inclination, double *RAANPrecession, double *PerigeePrecession));
+static void GetPrecession (double SemiMajorAxis, double Eccentricity,
+    double Inclination, double *RAANPrecession, double *PerigeePrecession);
 #endif /* USE_ORBIT_PROPAGATOR */
 
@@ -135,7 +131,5 @@
  */
 int
-obj_earthsat (np, op)
-Now *np;
-Obj *op;
+obj_earthsat (Now *np, Obj *op)
 {
 	double Radius;              /* From geocenter                  */
@@ -267,9 +261,6 @@
  */
 static void
-esat_prop (np, op, SatX, SatY, SatZ, SatVX, SatVY, SatVZ)
-Now *np;
-Obj *op;
-double *SatX,*SatY,*SatZ;
-double *SatVX,*SatVY,*SatVZ;
+esat_prop (Now *np, Obj *op, double *SatX, double *SatY, double *SatZ,
+double *SatVX, double *SatVY, double *SatVZ)
 {
 #ifdef USE_ORBIT_PROPAGATOR
@@ -284,4 +275,9 @@
 	double Radius;
 	double CrntTime;
+
+	if (crazyOp (np, op)) {
+	    *SatX = *SatY = *SatZ = *SatVX = *SatVY = *SatVZ = 0;
+	    return;
+	}
 
 	SemiMajorAxis = 331.25 * exp(2*log(MinutesPerDay/epochMeanMotion)/3);
@@ -331,4 +327,9 @@
 	double dt;
 	int yr;
+
+	if (crazyOp (np, op)) {
+	    *SatX = *SatY = *SatZ = *SatVX = *SatVY = *SatVZ = 0;
+	    return;
+	}
 
 	/* init */
@@ -392,10 +393,16 @@
 }
 
+/* return 1 if op is crazy @ np */
+static int
+crazyOp (Now *np, Obj *op)
+{
+	/* figure its daft if long enough to decay 1 rev/day */
+	return (fabs(op->es_epoch - mjd) > 1/op->es_decay);
+}
 
 /* grab the xephem stuff from op and copy into orbit's globals.
  */
 static void
-GetSatelliteParams(op)
-Obj *op;
+GetSatelliteParams(Obj *op)
 {
 	/* the following are for the orbit functions */
@@ -429,6 +436,5 @@
  
 static void
-GetSiteParams(np)
-Now *np;
+GetSiteParams(Now *np)
 {
 	SiteLat = lat;
@@ -465,7 +471,5 @@
  
 static
-double Kepler(MeanAnomaly,Eccentricity)
-register double MeanAnomaly,Eccentricity;
- 
+double Kepler(double MeanAnomaly, double Eccentricity)
 {
 register double E;              /* Eccentric Anomaly                    */
@@ -494,7 +498,6 @@
  
 static void
-GetSubSatPoint(SatX,SatY,SatZ,T,Latitude,Longitude,Height)
-double SatX,SatY,SatZ,T;
-double *Latitude,*Longitude,*Height;
+GetSubSatPoint(double SatX, double SatY, double SatZ, double T,
+double *Latitude, double *Longitude, double *Height)
 {
     double r;
@@ -524,8 +527,6 @@
 #ifdef USE_ORBIT_PROPAGATOR
 static void
-GetPrecession(SemiMajorAxis,Eccentricity,Inclination,
-        RAANPrecession,PerigeePrecession)
-double SemiMajorAxis,Eccentricity,Inclination;
-double *RAANPrecession,*PerigeePrecession;
+GetPrecession(double SemiMajorAxis, double Eccentricity, double Inclination,
+double *RAANPrecession, double *PerigeePrecession)
 {
   *RAANPrecession = 9.95*pow(EarthRadius/SemiMajorAxis,3.5) * cos(Inclination)
@@ -544,12 +545,9 @@
 
 static void
-GetSatPosition(EpochTime,EpochRAAN,EpochArgPerigee,SemiMajorAxis,
-	Inclination,Eccentricity,RAANPrecession,PerigeePrecession,
-	T,TrueAnomaly,X,Y,Z,Radius,VX,VY,VZ)
- 
-double EpochTime,EpochRAAN,EpochArgPerigee;
-double SemiMajorAxis,Inclination,Eccentricity;
-double RAANPrecession,PerigeePrecession,T, TrueAnomaly;
-double *X,*Y,*Z,*Radius,*VX,*VY,*VZ;
+GetSatPosition(double EpochTime, double EpochRAAN, double EpochArgPerigee,
+double SemiMajorAxis, double Inclination, double Eccentricity,
+double RAANPrecession, double PerigeePrecession, double T,
+double TrueAnomaly, double *X, double *Y, double *Z, double *Radius,
+double *VX, double *VY, double *VZ)
 
 {
@@ -607,11 +605,7 @@
 
 static void
-GetSitPosition(SiteLat,SiteLong,SiteElevation,CrntTime,
-             SiteX,SiteY,SiteZ,SiteVX,SiteVY,SiteMatrix)
-
-double SiteLat,SiteLong,SiteElevation,CrntTime;
-double *SiteX,*SiteY,*SiteZ,*SiteVX,*SiteVY;
-MAT3x3 SiteMatrix;
-
+GetSitPosition(double SiteLat, double SiteLong, double SiteElevation,
+double CrntTime, double *SiteX, double *SiteY, double *SiteZ, double *SiteVX,
+double *SiteVY, MAT3x3 SiteMatrix)
 {
     static double G1,G2; /* Used to correct for flattening of the Earth */
@@ -663,10 +657,7 @@
 
 static void
-GetRange(SiteX,SiteY,SiteZ,SiteVX,SiteVY,
-	SatX,SatY,SatZ,SatVX,SatVY,SatVZ,Range,RangeRate)
-
-double SiteX,SiteY,SiteZ,SiteVX,SiteVY;
-double SatX,SatY,SatZ,SatVX,SatVY,SatVZ;
-double *Range,*RangeRate;
+GetRange(double SiteX, double SiteY, double SiteZ, double SiteVX,
+double SiteVY, double SatX, double SatY, double SatZ, double SatVX,
+double SatVY, double SatVZ, double *Range, double *RangeRate)
 {
     double DX,DY,DZ;
@@ -684,8 +675,7 @@
 
 static void
-GetTopocentric(SatX,SatY,SatZ,SiteX,SiteY,SiteZ,SiteMatrix,X,Y,Z)
-double SatX,SatY,SatZ,SiteX,SiteY,SiteZ;
-double *X,*Y,*Z;
-MAT3x3 SiteMatrix;
+GetTopocentric(double SatX, double SatY, double SatZ, double SiteX,
+double SiteY, double SiteZ, MAT3x3 SiteMatrix, double *X, double *Y,
+double *Z)
 {
     SatX -= SiteX;
@@ -702,8 +692,7 @@
 
 static void
-GetBearings(SatX,SatY,SatZ,SiteX,SiteY,SiteZ,SiteMatrix,Azimuth,Elevation)
-double SatX,SatY,SatZ,SiteX,SiteY,SiteZ;
-MAT3x3 SiteMatrix;
-double *Azimuth,*Elevation;
+GetBearings(double SatX, double SatY, double SatZ, double SiteX,
+double SiteY, double SiteZ, MAT3x3 SiteMatrix, double *Azimuth,
+double *Elevation)
 {
     double x,y,z;
@@ -720,6 +709,6 @@
 
 static int
-Eclipsed(SatX,SatY,SatZ,SatRadius,CrntTime)
-double SatX,SatY,SatZ,SatRadius,CrntTime;
+Eclipsed(double SatX, double SatY, double SatZ, double SatRadius,
+double CrntTime)
 {
     double MeanAnomaly,TrueAnomaly;
@@ -751,7 +740,5 @@
 
 static void
-InitOrbitRoutines(EpochDay, AtEod)
-double EpochDay;
-int AtEod;
+InitOrbitRoutines(double EpochDay, int AtEod)
 {
     double T,T2,T3,Omega;
@@ -797,3 +784,3 @@
 
 /* For RCS Only -- Do Not Edit */
-static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: earthsat.c,v $ $Date: 2001-10-22 12:08:27 $ $Revision: 1.2 $ $Name: not supported by cvs2svn $"};
+static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: earthsat.c,v $ $Date: 2004-06-15 16:52:38 $ $Revision: 1.3 $ $Name: not supported by cvs2svn $"};
