In SGP4 changed non const reference changed to pointer

feature/19
Daniel Warner 2011-05-08 14:00:43 +01:00
parent 96c05ca4cb
commit b607678395
3 changed files with 77 additions and 77 deletions

View File

@ -36,7 +36,7 @@ void RunTle(Tle tle, double start, double end, double inc) {
*/ */
val = current; val = current;
} }
model.FindPosition(eci, val); model.FindPosition(&eci, val);
Vector position = eci.GetPosition(); Vector position = eci.GetPosition();
Vector velocity = eci.GetVelocity(); Vector velocity = eci.GetVelocity();

128
SGP4.cpp
View File

@ -243,7 +243,7 @@ void SGP4::Initialize(const double& theta2, const double& betao2, const double&
first_run_ = false; first_run_ = false;
} }
void SGP4::FindPosition(Eci& eci, double tsince) const { void SGP4::FindPosition(Eci* eci, double tsince) const {
if (i_use_deep_space_) if (i_use_deep_space_)
FindPositionSDP4(eci, tsince); FindPositionSDP4(eci, tsince);
@ -251,14 +251,14 @@ void SGP4::FindPosition(Eci& eci, double tsince) const {
FindPositionSGP4(eci, tsince); FindPositionSGP4(eci, tsince);
} }
void SGP4::FindPosition(Eci& eci, const Julian& date) const { void SGP4::FindPosition(Eci* eci, const Julian& date) const {
const double tsince = date.SpanMin(Epoch()); const double tsince = date.SpanMin(Epoch());
FindPosition(eci, tsince); FindPosition(eci, tsince);
} }
void SGP4::FindPositionSDP4(Eci& eci, double tsince) const { void SGP4::FindPositionSDP4(Eci* eci, double tsince) const {
/* /*
* the final values * the final values
@ -287,7 +287,7 @@ void SGP4::FindPositionSDP4(Eci& eci, double tsince) const {
e = Eccentricity(); e = Eccentricity();
xincl = Inclination(); xincl = Inclination();
DeepSpaceSecular(tsince, xmdf, omgadf, xnode, e, xincl, xn); DeepSpaceSecular(tsince, &xmdf, &omgadf, &xnode, &e, &xincl, &xn);
if (xn <= 0.0) { if (xn <= 0.0) {
throw new SatelliteException("Error: #2 (xn <= 0.0)"); throw new SatelliteException("Error: #2 (xn <= 0.0)");
@ -319,7 +319,7 @@ void SGP4::FindPositionSDP4(Eci& eci, double tsince) const {
double xmam = xmdf + RecoveredMeanMotion() * templ; double xmam = xmdf + RecoveredMeanMotion() * templ;
DeepSpacePeriodics(tsince, e, xincl, omgadf, xnode, xmam); DeepSpacePeriodics(tsince, &e, &xincl, &omgadf, &xnode, &xmam);
/* /*
* keeping xincl positive important unless you need to display xincl * keeping xincl positive important unless you need to display xincl
@ -369,7 +369,7 @@ void SGP4::FindPositionSDP4(Eci& eci, double tsince) const {
} }
void SGP4::FindPositionSGP4(Eci& eci, double tsince) const { void SGP4::FindPositionSGP4(Eci* eci, double tsince) const {
/* /*
* the final values * the final values
@ -446,7 +446,7 @@ void SGP4::FindPositionSGP4(Eci& eci, double tsince) const {
} }
void SGP4::CalculateFinalPositionVelocity(Eci& eci, const double& tsince, const double& e, void SGP4::CalculateFinalPositionVelocity(Eci* eci, const double& tsince, const double& e,
const double& a, const double& omega, const double& xl, const double& xnode, const double& a, const double& omega, const double& xl, const double& xnode,
const double& xincl, const double& xlcof, const double& aycof, const double& xincl, const double& xlcof, const double& aycof,
const double& x3thm1, const double& x1mth2, const double& x7thm1, const double& x3thm1, const double& x1mth2, const double& x7thm1,
@ -600,7 +600,7 @@ void SGP4::CalculateFinalPositionVelocity(Eci& eci, const double& tsince, const
Julian julian = Epoch(); Julian julian = Epoch();
julian.AddMin(tsince); julian.AddMin(tsince);
eci = Eci(julian, position, velocity); (*eci) = Eci(julian, position, velocity);
} }
/* /*
@ -934,12 +934,12 @@ void SGP4::DeepSpaceInitialize(const double& eosq, const double& sinio, const do
/* /*
* precompute dot terms for epoch * precompute dot terms for epoch
*/ */
DeepSpaceCalcDotTerms(d_xndot_0_, d_xnddt_0_, d_xldot_0_); DeepSpaceCalcDotTerms(&d_xndot_0_, &d_xnddt_0_, &d_xldot_0_);
} }
} }
void SGP4::DeepSpaceCalculateLunarSolarTerms(const double t, double& pe, double& pinc, void SGP4::DeepSpaceCalculateLunarSolarTerms(const double t, double* pe, double* pinc,
double& pl, double& pgh, double& ph) const { double* pl, double* pgh, double* ph) const {
static const double ZES = 0.01675; static const double ZES = 0.01675;
static const double ZNS = 1.19459E-5; static const double ZNS = 1.19459E-5;
@ -981,18 +981,18 @@ void SGP4::DeepSpaceCalculateLunarSolarTerms(const double t, double& pe, double&
/* /*
* merge calculated values * merge calculated values
*/ */
pe = ses + sel; (*pe) = ses + sel;
pinc = sis + sil; (*pinc) = sis + sil;
pl = sls + sll; (*pl) = sls + sll;
pgh = sghs + sghl; (*pgh) = sghs + sghl;
ph = shs + shl; (*ph) = shs + shl;
} }
/* /*
* calculate lunar / solar periodics and apply * calculate lunar / solar periodics and apply
*/ */
void SGP4::DeepSpacePeriodics(const double& t, double& em, void SGP4::DeepSpacePeriodics(const double& t, double* em,
double& xinc, double& omgasm, double& xnodes, double& xll) const { double* xinc, double* omgasm, double* xnodes, double* xll) const {
/* /*
* storage for lunar / solar terms set by DeepSpaceCalculateLunarSolarTerms() * storage for lunar / solar terms set by DeepSpaceCalculateLunarSolarTerms()
@ -1006,12 +1006,12 @@ void SGP4::DeepSpacePeriodics(const double& t, double& em,
/* /*
* calculate lunar / solar terms for current time * calculate lunar / solar terms for current time
*/ */
DeepSpaceCalculateLunarSolarTerms(t, pe, pinc, pl, pgh, ph); DeepSpaceCalculateLunarSolarTerms(t, &pe, &pinc, &pl, &pgh, &ph);
if (!first_run_) { if (!first_run_) {
xinc += pinc; (*xinc) += pinc;
em += pe; (*em) += pe;
/* Spacetrack report #3 has sin/cos from before perturbations /* Spacetrack report #3 has sin/cos from before perturbations
* added to xinc (oldxinc), but apparently report # 6 has then * added to xinc (oldxinc), but apparently report # 6 has then
@ -1022,24 +1022,24 @@ void SGP4::DeepSpacePeriodics(const double& t, double& em,
* if (xinc >= 0.2) * if (xinc >= 0.2)
* (moved from start of function) * (moved from start of function)
*/ */
const double sinis = sin(xinc); const double sinis = sin((*xinc));
const double cosis = cos(xinc); const double cosis = cos((*xinc));
if (xinc >= 0.2) { if ((*xinc) >= 0.2) {
/* /*
* apply periodics directly * apply periodics directly
*/ */
const double tmp_ph = ph / sinis; const double tmp_ph = ph / sinis;
omgasm += pgh - cosis * tmp_ph; (*omgasm) += pgh - cosis * tmp_ph;
xnodes += tmp_ph; (*xnodes) += tmp_ph;
xll += pl; (*xll) += pl;
} else { } else {
/* /*
* apply periodics with lyddane modification * apply periodics with lyddane modification
*/ */
const double sinok = sin(xnodes); const double sinok = sin((*xnodes));
const double cosok = cos(xnodes); const double cosok = cos((*xnodes));
double alfdp = sinis * sinok; double alfdp = sinis * sinok;
double betdp = sinis * cosok; double betdp = sinis * cosok;
const double dalf = ph * cosok + pinc * cosis * sinok; const double dalf = ph * cosok + pinc * cosis * sinok;
@ -1048,37 +1048,37 @@ void SGP4::DeepSpacePeriodics(const double& t, double& em,
alfdp += dalf; alfdp += dalf;
betdp += dbet; betdp += dbet;
xnodes = fmod(xnodes, TWOPI); (*xnodes) = fmod((*xnodes), TWOPI);
if (xnodes < 0.0) if ((*xnodes) < 0.0)
xnodes += TWOPI; (*xnodes) += TWOPI;
double xls = xll + omgasm + cosis * xnodes; double xls = (*xll) + (*omgasm) + cosis * (*xnodes);
double dls = pl + pgh - pinc * xnodes * sinis; double dls = pl + pgh - pinc * (*xnodes) * sinis;
xls += dls; xls += dls;
/* /*
* save old xnodes value * save old xnodes value
*/ */
const double oldxnodes = xnodes; const double oldxnodes = (*xnodes);
xnodes = atan2(alfdp, betdp); (*xnodes) = atan2(alfdp, betdp);
if (xnodes < 0.0) if ((*xnodes) < 0.0)
xnodes += TWOPI; (*xnodes) += TWOPI;
/* /*
* Get perturbed xnodes in to same quadrant as original. * Get perturbed xnodes in to same quadrant as original.
* RAAN is in the range of 0 to 360 degrees * RAAN is in the range of 0 to 360 degrees
* atan2 is in the range of -180 to 180 degrees * atan2 is in the range of -180 to 180 degrees
*/ */
if (fabs(oldxnodes - xnodes) > PI) { if (fabs(oldxnodes - (*xnodes)) > PI) {
if (xnodes < oldxnodes) if ((*xnodes) < oldxnodes)
xnodes += TWOPI; (*xnodes) += TWOPI;
else else
xnodes = xnodes - TWOPI; (*xnodes) = (*xnodes) - TWOPI;
} }
xll += pl; (*xll) += pl;
omgasm = xls - xll - cosis * xnodes; (*omgasm) = xls - (*xll) - cosis * (*xnodes);
} }
} }
} }
@ -1086,17 +1086,17 @@ void SGP4::DeepSpacePeriodics(const double& t, double& em,
/* /*
* deep space secular effects * deep space secular effects
*/ */
void SGP4::DeepSpaceSecular(const double& t, double& xll, double& omgasm, void SGP4::DeepSpaceSecular(const double& t, double* xll, double* omgasm,
double& xnodes, double& em, double& xinc, double& xn) const { double* xnodes, double* em, double* xinc, double* xn) const {
static const double STEP = 720.0; static const double STEP = 720.0;
static const double STEP2 = 259200.0; static const double STEP2 = 259200.0;
xll += d_ssl_ * t; (*xll) += d_ssl_ * t;
omgasm += d_ssg_ * t; (*omgasm) += d_ssg_ * t;
xnodes += d_ssh_ * t; (*xnodes) += d_ssh_ * t;
em += d_sse_ * t; (*em) += d_sse_ * t;
xinc += d_ssi_ * t; (*xinc) += d_ssi_ * t;
if (!d_resonance_flag_) if (!d_resonance_flag_)
return; return;
@ -1149,7 +1149,7 @@ void SGP4::DeepSpaceSecular(const double& t, double& xll, double& omgasm,
/* /*
* calculate dot terms for next integration * calculate dot terms for next integration
*/ */
DeepSpaceCalcDotTerms(d_xndot_t_, d_xnddt_t_, d_xldot_t_); DeepSpaceCalcDotTerms(&d_xndot_t_, &d_xnddt_t_, &d_xldot_t_);
ft = t - d_atime_; ft = t - d_atime_;
} while (fabs(ft) >= STEP); } while (fabs(ft) >= STEP);
@ -1158,20 +1158,20 @@ void SGP4::DeepSpaceSecular(const double& t, double& xll, double& omgasm,
/* /*
* integrator * integrator
*/ */
xn = d_xni_ + d_xndot_t_ * ft + d_xnddt_t_ * ft * ft * 0.5; (*xn) = d_xni_ + d_xndot_t_ * ft + d_xnddt_t_ * ft * ft * 0.5;
const double xl = d_xli_ + d_xldot_t_ * ft + d_xndot_t_ * ft * ft * 0.5; const double xl = d_xli_ + d_xldot_t_ * ft + d_xndot_t_ * ft * ft * 0.5;
const double temp = -xnodes + d_gsto_ + t * THDT; const double temp = -(*xnodes) + d_gsto_ + t * THDT;
if (d_synchronous_flag_) if (d_synchronous_flag_)
xll = xl + temp - omgasm; (*xll) = xl + temp - (*omgasm);
else else
xll = xl + temp + temp; (*xll) = xl + temp + temp;
} }
/* /*
* calculate dot terms * calculate dot terms
*/ */
void SGP4::DeepSpaceCalcDotTerms(double& xndot, double& xnddt, double& xldot) const { void SGP4::DeepSpaceCalcDotTerms(double* xndot, double* xnddt, double* xldot) const {
static const double G22 = 5.7686396; static const double G22 = 5.7686396;
static const double G32 = 0.95240898; static const double G32 = 0.95240898;
@ -1184,10 +1184,10 @@ void SGP4::DeepSpaceCalcDotTerms(double& xndot, double& xnddt, double& xldot) co
if (d_synchronous_flag_) { if (d_synchronous_flag_) {
xndot = d_del1_ * sin(d_xli_ - FASX2) + (*xndot) = d_del1_ * sin(d_xli_ - FASX2) +
d_del2_ * sin(2.0 * (d_xli_ - FASX4)) + d_del2_ * sin(2.0 * (d_xli_ - FASX4)) +
d_del3_ * sin(3.0 * (d_xli_ - FASX6)); d_del3_ * sin(3.0 * (d_xli_ - FASX6));
xnddt = d_del1_ * cos(d_xli_ - FASX2) + 2.0 * (*xnddt) = d_del1_ * cos(d_xli_ - FASX2) + 2.0 *
d_del2_ * cos(2.0 * (d_xli_ - FASX4)) + 3.0 * d_del2_ * cos(2.0 * (d_xli_ - FASX4)) + 3.0 *
d_del3_ * cos(3.0 * (d_xli_ - FASX6)); d_del3_ * cos(3.0 * (d_xli_ - FASX6));
@ -1197,7 +1197,7 @@ void SGP4::DeepSpaceCalcDotTerms(double& xndot, double& xnddt, double& xldot) co
const double x2omi = xomi + xomi; const double x2omi = xomi + xomi;
const double x2li = d_xli_ + d_xli_; const double x2li = d_xli_ + d_xli_;
xndot = d_d2201_ * sin(x2omi + d_xli_ - G22) (*xndot) = d_d2201_ * sin(x2omi + d_xli_ - G22)
+ d_d2211_ * sin(d_xli_ - G22) + d_d2211_ * sin(d_xli_ - G22)
+ d_d3210_ * sin(xomi + d_xli_ - G32) + d_d3210_ * sin(xomi + d_xli_ - G32)
+ d_d3222_ * sin(-xomi + d_xli_ - G32) + d_d3222_ * sin(-xomi + d_xli_ - G32)
@ -1207,7 +1207,7 @@ void SGP4::DeepSpaceCalcDotTerms(double& xndot, double& xnddt, double& xldot) co
+ d_d5232_ * sin(-xomi + d_xli_ - G52) + d_d5232_ * sin(-xomi + d_xli_ - G52)
+ d_d5421_ * sin(xomi + x2li - G54) + d_d5421_ * sin(xomi + x2li - G54)
+ d_d5433_ * sin(-xomi + x2li - G54); + d_d5433_ * sin(-xomi + x2li - G54);
xnddt = d_d2201_ * cos(x2omi + d_xli_ - G22) (*xnddt) = d_d2201_ * cos(x2omi + d_xli_ - G22)
+ d_d2211_ * cos(d_xli_ - G22) + d_d2211_ * cos(d_xli_ - G22)
+ d_d3210_ * cos(xomi + d_xli_ - G32) + d_d3210_ * cos(xomi + d_xli_ - G32)
+ d_d3222_ * cos(-xomi + d_xli_ - G32) + d_d3222_ * cos(-xomi + d_xli_ - G32)
@ -1219,8 +1219,8 @@ void SGP4::DeepSpaceCalcDotTerms(double& xndot, double& xnddt, double& xldot) co
+ d_d5433_ * cos(-xomi + x2li - G54)); + d_d5433_ * cos(-xomi + x2li - G54));
} }
xldot = d_xni_ + d_xfact_; (*xldot) = d_xni_ + d_xfact_;
xnddt = xnddt * xldot; (*xnddt) = (*xnddt) * (*xldot);
} }
/* /*
@ -1290,4 +1290,4 @@ void SGP4::ResetGlobalVariables() {
epoch_ = Julian(); epoch_ = Julian();
orbit_number_ = 0; orbit_number_ = 0;
} }

24
SGP4.h
View File

@ -10,8 +10,8 @@ public:
virtual ~SGP4(void); virtual ~SGP4(void);
void SetTle(const Tle& tle); void SetTle(const Tle& tle);
void FindPosition(Eci& eci, double tsince) const; void FindPosition(Eci* eci, double tsince) const;
void FindPosition(Eci& eci, const Julian& date) const; void FindPosition(Eci* eci, const Julian& date) const;
/* /*
* XMO * XMO
@ -103,20 +103,20 @@ private:
void DeepSpaceInitialize(const double& eosq, const double& sinio, const double& cosio, const double& betao, void DeepSpaceInitialize(const double& eosq, const double& sinio, const double& cosio, const double& betao,
const double& theta2, const double& betao2, const double& theta2, const double& betao2,
const double& xmdot, const double& omgdot, const double& xnodot); const double& xmdot, const double& omgdot, const double& xnodot);
void DeepSpaceCalculateLunarSolarTerms(const double t, double& pe, double& pinc, void DeepSpaceCalculateLunarSolarTerms(const double t, double* pe, double* pinc,
double& pl, double& pgh, double& ph) const; double* pl, double* pgh, double* ph) const;
void DeepSpacePeriodics(const double& t, double& em, double& xinc, void DeepSpacePeriodics(const double& t, double* em, double* xinc,
double& omgasm, double& xnodes, double& xll) const; double* omgasm, double* xnodes, double* xll) const;
void DeepSpaceSecular(const double& t, double& xll, double& omgasm, void DeepSpaceSecular(const double& t, double* xll, double* omgasm,
double& xnodes, double& em, double& xinc, double& xn) const; double* xnodes, double* em, double* xinc, double* xn) const;
void FindPositionSDP4(Eci& eci, double tsince) const; void FindPositionSDP4(Eci* eci, double tsince) const;
void FindPositionSGP4(Eci& eci, double tsince) const; void FindPositionSGP4(Eci* eci, double tsince) const;
void CalculateFinalPositionVelocity(Eci& eci, const double& tsince, const double& e, void CalculateFinalPositionVelocity(Eci* eci, const double& tsince, const double& e,
const double& a, const double& omega, const double& xl, const double& xnode, const double& a, const double& omega, const double& xl, const double& xnode,
const double& xincl, const double& xlcof, const double& aycof, const double& xincl, const double& xlcof, const double& aycof,
const double& x3thm1, const double& x1mth2, const double& x7thm1, const double& x3thm1, const double& x1mth2, const double& x7thm1,
const double& cosio, const double& sinio) const; const double& cosio, const double& sinio) const;
void DeepSpaceCalcDotTerms(double& xndot, double& xnddt, double& xldot) const; void DeepSpaceCalcDotTerms(double* xndot, double* xnddt, double* xldot) const;
void DeepSpaceIntegrator(const double delt, const double step2, void DeepSpaceIntegrator(const double delt, const double step2,
const double xndot, const double xnddt, const double xldot)const; const double xndot, const double xnddt, const double xldot)const;
void ResetGlobalVariables(); void ResetGlobalVariables();