From 5ea53efb27503e50fb2e62c0c2bcb807204d606a Mon Sep 17 00:00:00 2001 From: Georg Zotti Date: Wed, 28 Aug 2024 01:11:19 +0200 Subject: [PATCH] Satellites plugin changes - concurrent computing (simple QConcurrent::blockingMap()) - Update code style, avoid preliminary variable declarations --- plugins/Satellites/src/CMakeLists.txt | 4 +- plugins/Satellites/src/Satellite.cpp | 75 +++++++++-------- plugins/Satellites/src/Satellite.hpp | 3 +- plugins/Satellites/src/Satellites.cpp | 11 +-- plugins/Satellites/src/gSatWrapper.cpp | 38 ++++----- .../Satellites/src/gsatellite/gSatTEME.cpp | 14 ++-- plugins/Satellites/src/gsatellite/gTime.cpp | 40 +++------ plugins/Satellites/src/gsatellite/sgp4ext.cpp | 81 +++++++++---------- plugins/Satellites/src/gsatellite/sgp4io.cpp | 6 +- src/gui/AstroCalcDialog.cpp | 4 +- 10 files changed, 125 insertions(+), 151 deletions(-) diff --git a/plugins/Satellites/src/CMakeLists.txt b/plugins/Satellites/src/CMakeLists.txt index 332a6663793f1..1938a4d774ba1 100644 --- a/plugins/Satellites/src/CMakeLists.txt +++ b/plugins/Satellites/src/CMakeLists.txt @@ -67,11 +67,11 @@ ENDIF(ENABLE_TESTING) ADD_LIBRARY(Satellites-static STATIC ${Satellites_SRCS} ${Satellites_RES_CXX} ${SatellitesDialog_UIS_H}) IF(ENABLE_XLSX AND (${SATELLITES_PLUGIN_IRIDIUM} EQUAL "1")) TARGET_LINK_LIBRARIES(Satellites-static Qt${QT_VERSION_MAJOR}::Core - Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Concurrent Qt${QT_VERSION_MAJOR}::GuiPrivate QXlsx::QXlsx) ELSE() TARGET_LINK_LIBRARIES(Satellites-static Qt${QT_VERSION_MAJOR}::Core - Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Concurrent Qt${QT_VERSION_MAJOR}::GuiPrivate) ENDIF() # The library target "Satellites-static" has a default OUTPUT_NAME of "Satellites-static", so change it. diff --git a/plugins/Satellites/src/Satellite.cpp b/plugins/Satellites/src/Satellite.cpp index 16cd2e663f619..0f4f2b6b5804f 100644 --- a/plugins/Satellites/src/Satellite.cpp +++ b/plugins/Satellites/src/Satellite.cpp @@ -18,22 +18,16 @@ */ #include "Satellite.hpp" -#include "StelObject.hpp" -//#include "StelObjectMgr.hpp" -#include "StelPainter.hpp" + #include "StelApp.hpp" #include "StelCore.hpp" -#include "VecMath.hpp" -#include "StelUtils.hpp" -#include "StelTranslator.hpp" -#include "StelModuleMgr.hpp" #include "StelLocaleMgr.hpp" - -#include -#include -#include -#include -#include +#include "StelModuleMgr.hpp" +#include "StelObject.hpp" +#include "StelPainter.hpp" +#include "StelTranslator.hpp" +#include "StelUtils.hpp" +#include "VecMath.hpp" #include #include @@ -104,9 +98,14 @@ Satellite::Satellite(const QString& identifier, const QVariantMap& map) , userDefined(false) , newlyAdded(false) , orbitValid(false) + , tleEpochJD(0.) , jdLaunchYearJan1(0) , stdMag(99.) , RCS(-1.) + , perigee(0.) + , apogee(0.) + , inclination(0.) + , eccentricity(0.) , status(StatusUnknown) , height(0.) , range(0.) @@ -226,7 +225,7 @@ Satellite::Satellite(const QString& identifier, const QVariantMap& map) StelCore *core = StelApp::getInstance().getCore(); double JD=core->getJD(); - update(core, JD, 0.); + update(core, JD); } Satellite::~Satellite() @@ -315,7 +314,7 @@ QString Satellite::getInfoString(const StelCore *core, const InfoStringGroup& fl { QString str; QTextStream oss(&str); - QString degree = QChar(0x00B0); + static const QString degree = QChar(0x00B0); const bool withDecimalDegree = StelApp::getInstance().getFlagShowDecimalDegrees(); if (flags & Name) @@ -369,7 +368,7 @@ QString Satellite::getInfoString(const StelCore *core, const InfoStringGroup& fl if (flags&Size && RCS>0.) { const double angularSize = getAngularRadius(core)*2.*M_PI_180; - QString sizeStr = ""; + QString sizeStr; if (withDecimalDegree) sizeStr = StelUtils::radToDecDegStr(angularSize, 5, false, true); else @@ -379,7 +378,7 @@ QString Satellite::getInfoString(const StelCore *core, const InfoStringGroup& fl if (flags & Extra) { - double orbitalPeriod = pSatWrapper->getOrbitalPeriod(); + const double orbitalPeriod = pSatWrapper->getOrbitalPeriod(); if (orbitalPeriod>0.0) { // TRANSLATORS: Revolutions per day - measurement of the frequency of a rotation @@ -391,7 +390,7 @@ QString Satellite::getInfoString(const StelCore *core, const InfoStringGroup& fl .arg(mins, StelUtils::hoursToHmsStr(orbitalPeriod/60.0, true)) .arg(1440.0/orbitalPeriod, 9, 'f', 5).arg(rpd) << "
"; } - double inclination = pSatWrapper->getOrbitalInclination(); + const double inclination = pSatWrapper->getOrbitalInclination(); oss << QString("%1: %2 (%3%4)").arg(q_("Inclination"), StelUtils::decDegToDmsStr(inclination), QString::number(inclination, 'f', 4), degree) << "
"; oss << QString("%1: %2°/%3°").arg(q_("SubPoint (Lat./Long.)")).arg(latLongSubPointPosition[0], 5, 'f', 2).arg(latLongSubPointPosition[1], 5, 'f', 3) << "
"; @@ -424,8 +423,8 @@ QString Satellite::getInfoString(const StelCore *core, const InfoStringGroup& fl updDate = qc_("unknown", "unknown date"); else { - QDate sd = lastUpdated.date(); - double hours = lastUpdated.time().hour() + lastUpdated.time().minute()/60. + lastUpdated.time().second()/3600.; + const QDate sd = lastUpdated.date(); + const double hours = lastUpdated.time().hour() + lastUpdated.time().minute()/60. + lastUpdated.time().second()/3600.; updDate = QString("%1 %2 %3 %4 %5").arg(sd.day()) .arg(StelLocaleMgr::longGenitiveMonthName(sd.month())).arg(sd.year()) .arg(qc_("at","at time"), StelUtils::hoursToHmsStr(hours, true)); @@ -492,16 +491,14 @@ QString Satellite::getCommLinkInfo(const CommLink &comm) const } commLinkData.replace("&", q_("and")); - double dop = getDoppler(comm.frequency); + const double dop = getDoppler(comm.frequency); double ddop = dop; - QString sign; + QString sign("+"); if (dop<0.) { sign='-'; ddop*=-1; } - else - sign='+'; commLinkData.append(QString(": %1 %2 (%3%4 %5)
").arg(QString::number(comm.frequency, 'f', 3), qc_("MHz", "frequency"), sign, QString::number(ddop, 'f', 3), qc_("kHz", "frequency"))); return commLinkData; @@ -743,8 +740,8 @@ float Satellite::getVMagnitude(const StelCore* core) const else if (1.745<=phaseAngle && phaseAngle<=2.618) albedo = ((0.510905*phaseAngle - 2.72607)*phaseAngle + 4.96646)*phaseAngle - 3.02085; - double rm = range*1000.; - double fdiff = (std::sin(phaseAngle) + (M_PI - phaseAngle)*std::cos(phaseAngle))*(2.*albedo*RCS)/(3.* M_PI * M_PI * rm * rm); + const double rm = range*1000.; + const double fdiff = (std::sin(phaseAngle) + (M_PI - phaseAngle)*std::cos(phaseAngle))*(2.*albedo*RCS)/(3.* M_PI * M_PI * rm * rm); vmag = static_cast(-26.74 - 2.5*std::log10(fdiff)); } @@ -812,9 +809,8 @@ void Satellite::recomputeSatData() calculateSatDataFromLine2(tleElements.second); } -void Satellite::update(StelCore *core, double JD, double deltaTime) +void Satellite::update(const StelCore *core, const double JD) { - Q_UNUSED(deltaTime) if (pSatWrapper && orbitValid) { epochTime = JD; // + timeShift; // We have "true" JD (UTC) from core, satellites don't need JDE! @@ -871,15 +867,16 @@ Vec4d Satellite::getUmbraData() //! Vec4d(umbraDistance, umbraRadius, penumbraDistance, penumbraRadius); Vec4d Satellite::getUmbraData(const double rhoE) { - static PlanetP earth=GETSTELMODULE(SolarSystem)->getEarth(); - static PlanetP sun = GETSTELMODULE(SolarSystem)->getSun(); + static StelCore *core = StelApp::getInstance().getCore(); + static PlanetP earth = GETSTELMODULE(SolarSystem)->getEarth(); + static PlanetP sun = GETSTELMODULE(SolarSystem)->getSun(); // Compute locations of umbra and penumbra circles. These should show where the satellite enters/exits umbra/penumbra. // The computation follows ideas from https://celestrak.org/columns/v03n01/ // These sources mention ECI coordinates (Earth Centered Inertial). Presumably TEME (True Equator Mean Equinox) are equivalent, at least for our purposes. const double rS=earth->getHeliocentricEclipticPos().norm()*AU; // distance earth...sun const double thetaE=asin((earth->getEquatorialRadius()*AU)/(rhoE)); - Vec3d sunEquinoxEqPos = sun->getEquinoxEquatorialPos(StelApp::getInstance().getCore()); + Vec3d sunEquinoxEqPos = sun->getEquinoxEquatorialPos(core); Vec3d sunTEME=sunEquinoxEqPos*AU; const double thetaS=asin((sun->getEquatorialRadius()*AU)/(sunTEME.norm())); Q_ASSERT(thetaE>thetaS); @@ -891,9 +888,9 @@ Vec4d Satellite::getUmbraData(const double rhoE) // complement const double mu=M_PI-eta; // geocentric distance of shadow circle towards antisun - double umbraDistance=rhoE*cos(mu); + const double umbraDistance=rhoE*cos(mu); // radius of shadow circle - double umbraRadius=rhoE*sin(mu); + const double umbraRadius=rhoE*sin(mu); // Repeat for penumbra const double thetaP=thetaE+thetaS; // angle so that satellite touches penumbra // angle at Sun: @@ -903,9 +900,9 @@ Vec4d Satellite::getUmbraData(const double rhoE) // complement const double muP=M_PI-etaP; // geocentric distance of shadow circle towards antisun - double penumbraDistance=rhoE*cos(muP); + const double penumbraDistance=rhoE*cos(muP); // radius of shadow circle - double penumbraRadius=rhoE*sin(muP); + const double penumbraRadius=rhoE*sin(muP); //// DBG OUT //StelObjectMgr *om=GETSTELMODULE(StelObjectMgr); //om->setExtraInfoString(StelObject::DebugAid, QString("ρE %1, rS %2, θE %3°, θS %4°
") @@ -1142,7 +1139,7 @@ void Satellite::draw(StelCore* core, StelPainter& painter) { if (!iconicModeFlag) { - Vec3f color(1.f,1.f,1.f); + static const Vec3f color(1.f,1.f,1.f); // Special case: crossing of the satellite of the Moon or the Sun if (XYZ.angle(moon->getJ2000EquatorialPos(core))*M_180_PI <= moon->getSpheroidAngularRadius(core) || XYZ.angle(sun->getJ2000EquatorialPos(core))*M_180_PI <= sun->getSpheroidAngularRadius(core)) { @@ -1160,7 +1157,7 @@ void Satellite::draw(StelCore* core, StelPainter& painter) } else { - StelSkyDrawer* sd = core->getSkyDrawer(); + static StelSkyDrawer* sd = core->getSkyDrawer(); RCMag rcMag; // Draw the satellite @@ -1193,7 +1190,7 @@ void Satellite::draw(StelCore* core, StelPainter& painter) } else if (!(hideInvisibleSatellitesFlag && visibility != gSatWrapper::VISIBLE)) { - Vec3f drawColor = (coloredInvisibleSatellitesFlag && visibility != gSatWrapper::VISIBLE) ? invisibleSatelliteColor : hintColor; // Use hintColor for visible satellites only when coloredInvisibleSatellitesFlag is true + const Vec3f drawColor = (coloredInvisibleSatellitesFlag && visibility != gSatWrapper::VISIBLE) ? invisibleSatelliteColor : hintColor; // Use hintColor for visible satellites only when coloredInvisibleSatellitesFlag is true painter.setColor(drawColor*hintBrightness, hintBrightness); if (XYZ.angle(moon->getJ2000EquatorialPos(core))*M_180_PI <= moon->getSpheroidAngularRadius(core) || XYZ.angle(sun->getJ2000EquatorialPos(core))*M_180_PI <= sun->getSpheroidAngularRadius(core)) painter.setColor(transitSatelliteColor, 1.f); @@ -1265,7 +1262,7 @@ void Satellite::drawOrbit(StelCore *core, StelPainter& painter) float Satellite::calculateOrbitSegmentIntensity(int segNum) { - int endDist = (orbitLineSegments/2) - abs(segNum-1 - (orbitLineSegments/2) % orbitLineSegments); + const int endDist = (orbitLineSegments/2) - abs(segNum-1 - (orbitLineSegments/2) % orbitLineSegments); if (endDist > orbitLineFadeSegments) return 1.0; else diff --git a/plugins/Satellites/src/Satellite.hpp b/plugins/Satellites/src/Satellite.hpp index 5f65990e61d43..d13efccc9775a 100644 --- a/plugins/Satellites/src/Satellite.hpp +++ b/plugins/Satellites/src/Satellite.hpp @@ -229,8 +229,7 @@ class Satellite : public StelObject //! calculate faders, new position //! @param core current StelCore //! @param JD Julian day, UTC. (Satellites don't use JDE!) - //! @param deltaTime (currently unused) - void update(StelCore *core, double JD, double deltaTime); + void update(const StelCore *core, const double JD); double getDoppler(double freq) const; static bool showLabels; diff --git a/plugins/Satellites/src/Satellites.cpp b/plugins/Satellites/src/Satellites.cpp index eea88a8628aba..e3468f71fba66 100644 --- a/plugins/Satellites/src/Satellites.cpp +++ b/plugins/Satellites/src/Satellites.cpp @@ -60,6 +60,7 @@ #include #include #include +#include StelModule* SatellitesStelPluginInterface::getStelModule() const { @@ -2809,7 +2810,7 @@ void Satellites::update(double deltaTime) if (!hintFader && hintFader.getInterstate() <= 0.f) return; - static StelCore *core = StelApp::getInstance().getCore(); + static const StelCore *core = StelApp::getInstance().getCore(); double JD=core->getJD(); if (qAbs(core->getTimeRate())>=Satellite::timeRateLimit) // Do not show satellites when time rate is over limit @@ -2820,11 +2821,11 @@ void Satellites::update(double deltaTime) hintFader.update(static_cast(deltaTime*1000)); - for (const auto& sat : std::as_const(satellites)) - { + const auto updateSat = [this, JD](QSharedPointer& sat){ if (sat->initialized && sat->displayed) - sat->update(core, JD, deltaTime); - } + sat->update(core, JD); + }; + QtConcurrent::blockingMap(QThreadPool::globalInstance(), satellites, updateSat); } void Satellites::draw(StelCore* core) diff --git a/plugins/Satellites/src/gSatWrapper.cpp b/plugins/Satellites/src/gSatWrapper.cpp index 07a67c1fa7799..75618fa3cd864 100644 --- a/plugins/Satellites/src/gSatWrapper.cpp +++ b/plugins/Satellites/src/gSatWrapper.cpp @@ -109,8 +109,8 @@ void gSatWrapper::calcObserverECIPosition(Vec3d& ao_position, Vec3d& ao_velocity { StelLocation loc = StelApp::getInstance().getCore()->getCurrentLocation(); - double radLatitude = loc.getLatitude() * M_PI_180; - double theta = epoch.toThetaLMST(loc.getLongitude() * M_PI_180); + const double radLatitude = loc.getLatitude() * M_PI_180; + const double theta = epoch.toThetaLMST(loc.getLongitude() * M_PI_180); /* Reference: Explanatory supplement to the Astronomical Almanac 1992, page 209-210. */ /* Ellipsoid earth model*/ @@ -132,8 +132,7 @@ void gSatWrapper::calcObserverECIPosition(Vec3d& ao_position, Vec3d& ao_velocity Vec3d gSatWrapper::getAltAz() const { - StelLocation loc = StelApp::getInstance().getCore()->getCurrentLocation(); - Vec3d topoSatPos; + const StelLocation loc = StelApp::getInstance().getCore()->getCurrentLocation(); const double radLatitude = loc.getLatitude() * M_PI_180; const double sinRadLatitude = sin(radLatitude); @@ -145,9 +144,10 @@ Vec3d gSatWrapper::getAltAz() const // This now only updates if required. calcObserverECIPosition(observerECIPos, observerECIVel); - Vec3d satECIPos = getTEMEPos(); - Vec3d slantRange = satECIPos - observerECIPos; + const Vec3d satECIPos = getTEMEPos(); + const Vec3d slantRange = satECIPos - observerECIPos; + Vec3d topoSatPos; //top_s topoSatPos[0] = (sinRadLatitude * cosTheta*slantRange[0] + sinRadLatitude* sinTheta*slantRange[1] @@ -168,10 +168,10 @@ void gSatWrapper::getSlantRange(double &ao_slantRange, double &ao_slantRangeRat { calcObserverECIPosition(observerECIPos, observerECIVel); - Vec3d satECIPos = getTEMEPos(); - Vec3d satECIVel = getTEMEVel(); - Vec3d slantRange = satECIPos - observerECIPos; - Vec3d slantRangeVelocity = satECIVel - observerECIVel; + const Vec3d satECIPos = getTEMEPos(); + const Vec3d satECIVel = getTEMEVel(); + const Vec3d slantRange = satECIPos - observerECIPos; + const Vec3d slantRangeVelocity = satECIVel - observerECIVel; ao_slantRange = slantRange.norm(); ao_slantRangeRate = slantRange.dot(slantRangeVelocity)/ao_slantRange; @@ -205,7 +205,7 @@ Vec3d gSatWrapper::getSunECIPos() gSatWrapper::Visibility gSatWrapper::getVisibilityPredict() const { gSatWrapper::Visibility rval = BELOW_HORIZON; - Vec3d satAltAzPos = getAltAz(); + const Vec3d satAltAzPos = getAltAz(); if (satAltAzPos[2] > 0) { static const SolarSystem* solsystem = (SolarSystem*)StelApp::getInstance().getModuleMgr().getModule("SolarSystem"); @@ -216,20 +216,20 @@ gSatWrapper::Visibility gSatWrapper::getVisibilityPredict() const } else { - Vec3d sunECIPos = getSunECIPos(); - Vec3d satECIPos = getTEMEPos(); + const Vec3d sunECIPos = getSunECIPos(); + const Vec3d satECIPos = getTEMEPos(); rval = VISIBLE; /* Satellites in umbra/penumbra based on:- Visually Observing Earth Satellites By Dr. T.S. Kelso https://celestrak.org/columns/v03n01/ */ - double psun = std::sqrt(pow(satECIPos[0] - sunECIPos[0], 2) + pow(satECIPos[1] - sunECIPos[1], 2) + pow(satECIPos[2] - sunECIPos[2], 2) ); - double pearth = std::sqrt(std::pow(satECIPos[0], 2) + std::pow(satECIPos[1], 2) + std::pow(satECIPos[2], 2)); - double theta_e = std::asin((12742. / 2.) / pearth); - double theta_s = std::asin((1391000. / 2.) / psun); - double dotproduct_peps = std::abs((satECIPos[0] * sunECIPos[0]) + (satECIPos[1] * sunECIPos[1]) + (satECIPos[2] * sunECIPos[2])); - double theta = std::acos(dotproduct_peps / (psun * pearth)); + const double psun = std::sqrt(pow(satECIPos[0] - sunECIPos[0], 2) + pow(satECIPos[1] - sunECIPos[1], 2) + pow(satECIPos[2] - sunECIPos[2], 2) ); + const double pearth = std::sqrt(std::pow(satECIPos[0], 2) + std::pow(satECIPos[1], 2) + std::pow(satECIPos[2], 2)); + const double theta_e = std::asin((12742. / 2.) / pearth); + const double theta_s = std::asin((1391000. / 2.) / psun); + const double dotproduct_peps = std::abs((satECIPos[0] * sunECIPos[0]) + (satECIPos[1] * sunECIPos[1]) + (satECIPos[2] * sunECIPos[2])); + const double theta = std::acos(dotproduct_peps / (psun * pearth)); if (theta_e > theta_s && theta < (theta_e - theta_s)) { rval = RADAR_NIGHT; diff --git a/plugins/Satellites/src/gsatellite/gSatTEME.cpp b/plugins/Satellites/src/gsatellite/gSatTEME.cpp index 62e1fe52287ee..c028200a27350 100644 --- a/plugins/Satellites/src/gsatellite/gSatTEME.cpp +++ b/plugins/Satellites/src/gsatellite/gSatTEME.cpp @@ -36,8 +36,8 @@ // GKepFile #include "gSatTEME.hpp" -#include -#include +//#include +//#include #include #include "mathUtils.hpp" @@ -55,7 +55,7 @@ // Constructors gSatTEME::gSatTEME(const char *pstrName, char *pstrTleLine1, char *pstrTleLine2) { - double startmfe, stopmfe, deltamin; + double startmfe, stopmfe, deltamin; // dummies m_SatName = pstrName; @@ -96,16 +96,16 @@ void gSatTEME::setMinSinceKepEpoch(double ai_minSinceKepEpoch) Vec3d gSatTEME::computeSubPoint(gTime ai_Time) { Vec3d resultVector; // (0) Latitude, (1) Longitude, (2) altitude - double theta, r, e2, phi, c; - theta = atan2(m_Position[1], m_Position[0]); // radians + const double theta = atan2(m_Position[1], m_Position[0]); // radians resultVector[ LONGITUDE] = fmod((theta - ai_Time.toThetaGMST()), 2.*M_PI); //radians - r = std::sqrt(Sqr(m_Position[0]) + Sqr(m_Position[1])); - e2 = __f*(2. - __f); + const double r = std::sqrt(Sqr(m_Position[0]) + Sqr(m_Position[1])); + const double e2 = __f*(2. - __f); resultVector[ LATITUDE] = atan2(m_Position[2],r); /*radians*/ + double phi, c; do { phi = resultVector[ LATITUDE]; diff --git a/plugins/Satellites/src/gsatellite/gTime.cpp b/plugins/Satellites/src/gsatellite/gTime.cpp index c9435b7a78948..b94f2b73b986e 100644 --- a/plugins/Satellites/src/gsatellite/gTime.cpp +++ b/plugins/Satellites/src/gsatellite/gTime.cpp @@ -29,10 +29,10 @@ // gtime #include "gTime.hpp" // GExcpt -#include "stdsat.h" +//#include "stdsat.h" #include -#include -#include +//#include +//#include // Class GTimeSpan @@ -88,22 +88,10 @@ gTime::gTime(int nYear, int nMonth, int nDay, int nHour, int nMin, double nSec) // Calculate N, the day of the year (1..366) int F1 = static_cast((275.0 * nMonth) / 9.0); int F2 = static_cast((nMonth + 9.0) / 12.0); - int N; - - if(isLeapYear(nYear)) - { - // Leap year - N = F1 - F2 + nDay - 30; - } - else - { - // Common year - N = F1 - (2 * F2) + nDay - 30; - } + int N = F1 + nDay - 30 - (isLeapYear(nYear) ? F2 : 2*F2); double dDay = N + (nHour + (nMin + (nSec / 60.0)) / 60.0) / 24.0; - setTime(nYear, dDay); } @@ -194,9 +182,9 @@ void gTime::toCalendarDate(int *pYear, int *pMonth , double *pDom) const assert(pMonth != nullptr); assert(pDom != nullptr); - double jdAdj = m_time + 0.5; - int Z = static_cast(jdAdj); // integer part - double F = jdAdj - Z; // fractional part + const double jdAdj = m_time + 0.5; + const int Z = static_cast(jdAdj); // integer part + const double F = jdAdj - Z; // fractional part double A=Z; if(Z >= 2299161) @@ -221,9 +209,8 @@ void gTime::toCalendarDate(int *pYear, int *pMonth , double *pDom) const double gTime::toJCenturies() const { - double jd; - double UT = fmod((m_time + 0.5), 1.0); - jd = m_time - UT; + const double UT = fmod((m_time + 0.5), 1.0); + const double jd = m_time - UT; return (jd- JDAY_JAN1_12H_2000) / 36525.0; } @@ -233,16 +220,15 @@ double gTime::toJCenturies() const // prime meridian. double gTime::toThetaGMST() const { - double jd, Theta_JD; - double UT = fmod((m_time + 0.5), 1.0); - jd = m_time - UT; - double TU = (jd- JDAY_JAN1_12H_2000) / 36525.0; + const double UT = fmod((m_time + 0.5), 1.0); + const double jd = m_time - UT; + const double TU = (jd- JDAY_JAN1_12H_2000) / 36525.0; double GMST = 24110.54841 + TU * (8640184.812866 + TU * (0.093104 - TU * 6.2e-06)); GMST = fmod((GMST + KSEC_PER_DAY * OMEGA_E * UT),KSEC_PER_DAY); - Theta_JD=(2.*M_PI * (GMST / KSEC_PER_DAY)); + double Theta_JD=(2.*M_PI * (GMST / KSEC_PER_DAY)); if(Theta_JD <0.0) Theta_JD+=2.*M_PI; diff --git a/plugins/Satellites/src/gsatellite/sgp4ext.cpp b/plugins/Satellites/src/gsatellite/sgp4ext.cpp index 15bd9129ef436..5437f1e106e28 100644 --- a/plugins/Satellites/src/gsatellite/sgp4ext.cpp +++ b/plugins/Satellites/src/gsatellite/sgp4ext.cpp @@ -193,22 +193,20 @@ double angle(double vec1[3], double vec2[3]) void newtonnu(double ecc, double nu, double& e0, double& m) { - double sv, sine, cose; - // --------------------- implementation --------------------- e0 = 999999.9; m = 999999.9; - sv = 0.00000001; + static const double sv = 0.00000001; if ( std::fabs( ecc ) < sv ) // circular { - m = nu; e0 = nu; + m = nu; } else if ( ecc < 1.0-sv ) // elliptical { - sine = ( std::sqrt( 1.0 -ecc*ecc ) * std::sin(nu) ) / ( 1.0 +ecc*std::cos(nu) ); - cose = ( ecc + std::cos(nu) ) / ( 1.0 + ecc*std::cos(nu) ); + const double sine = ( std::sqrt( 1.0 -ecc*ecc ) * std::sin(nu) ) / ( 1.0 +ecc*std::cos(nu) ); + const double cose = ( ecc + std::cos(nu) ) / ( 1.0 + ecc*std::cos(nu) ); e0 = std::atan2( sine,cose ); m = e0 - ecc*std::sin(e0); } @@ -216,7 +214,7 @@ void newtonnu(double ecc, double nu, double& e0, double& m) { if (std::fabs(nu)+0.00001 < M_PI-std::acos(1.0 /ecc)) { - sine = ( std::sqrt( ecc*ecc-1.0 ) * std::sin(nu) ) / ( 1.0 + ecc*std::cos(nu) ); + const double sine = ( std::sqrt( ecc*ecc-1.0 ) * std::sin(nu) ) / ( 1.0 + ecc*std::cos(nu) ); #ifdef _MSC_BUILD e0 = StelUtils::asinh( sine ); #else @@ -235,7 +233,7 @@ void newtonnu(double ecc, double nu, double& e0, double& m) { m = std::fmod( m,2.0 *M_PI ); if ( m < 0.0 ) - m = m + 2.0 *M_PI; + m += 2.0 *M_PI; e0 = std::fmod( e0,2.0 *M_PI ); } @@ -303,40 +301,36 @@ void rv2coe(double r[3], double v[3], double mu, double& p, double& a, double& ecc, double& incl, double& omega, double& argp, double& nu, double& m, double& arglat, double& truelon, double& lonper) { - double undefined, sv, hbar[3], nbar[3], magr, magv, magn, ebar[3], sme, - rdotv, infinite, temp, c1, hk, twopi, magh, halfpi, e; - - int i; - char typeorbit[3]; - - twopi = 2.0 * M_PI; - halfpi = 0.5 * M_PI; - sv = 0.00000001; - undefined = 999999.1; - infinite = 999999.9; + static const double twopi = 2.0 * M_PI; + static const double halfpi = 0.5 * M_PI; + static const double sv = 0.00000001; + static const double undefined = 999999.1; + static const double infinite = 999999.9; // ------------------------- implementation ----------------- - magr = mag( r ); - magv = mag( v ); + const double magr = mag( r ); + const double magv = mag( v ); // ------------------ find h n and e vectors ---------------- + double hbar[3]; cross( r,v, hbar ); - magh = mag( hbar ); + const double magh = mag( hbar ); if ( magh > sv ) { + double nbar[3], ebar[3]; nbar[0] = -hbar[1]; nbar[1] = hbar[0]; nbar[2] = 0.0; - magn = mag( nbar ); - c1 = magv*magv - mu /magr; - rdotv = dot( r,v ); - for (i= 0; i <= 2; i++) + const double magn = mag( nbar ); + const double c1 = magv*magv - mu /magr; + const double rdotv = dot( r,v ); + for (int i= 0; i <= 2; i++) ebar[i] = (c1*r[i] - rdotv*v[i])/mu; ecc = mag( ebar ); // ------------ find a e and semi-latus rectum ---------- - sme = ( magv*magv*0.5 ) - ( mu /magr ); + const double sme = ( magv*magv*0.5 ) - ( mu /magr ); if ( std::fabs( sme ) > sv ) a = -mu / (2.0 *sme); else @@ -345,10 +339,11 @@ void rv2coe(double r[3], double v[3], double mu, p = magh*magh/mu; // ----------------- find inclination ------------------- - hk = hbar[2]/magh; + const double hk = hbar[2]/magh; incl = std::acos( hk ); // -------- determine type of orbit for later use -------- + char typeorbit[3]; std::strcpy(typeorbit,"ei"); // elliptical, parabolic, hyperbolic inclined if ( ecc < sv ) { @@ -366,7 +361,7 @@ void rv2coe(double r[3], double v[3], double mu, // ---------- find longitude of ascending node ------------ if ( magn > sv ) { - temp = nbar[0] / magn; + double temp = nbar[0] / magn; if ( std::fabs(temp) > 1.0 ) temp = StelUtils::sign(temp); omega = std::acos( temp ); @@ -410,7 +405,7 @@ void rv2coe(double r[3], double v[3], double mu, // -- find longitude of perigee - elliptical equatorial ---- if (( ecc>sv ) && (std::strcmp(typeorbit,"ee") == 0)) { - temp = ebar[0]/ecc; + double temp = ebar[0]/ecc; if ( std::fabs(temp) > 1.0 ) temp = StelUtils::sign(temp); lonper = std::acos( temp ); @@ -425,7 +420,7 @@ void rv2coe(double r[3], double v[3], double mu, // -------- find true longitude - circular equatorial ------ if (( magr>sv ) && ( std::strcmp(typeorbit,"ce") == 0 )) { - temp = r[0]/magr; + double temp = r[0]/magr; if ( std::fabs(temp) > 1.0 ) temp = StelUtils::sign(temp); truelon = std::acos( temp ); @@ -439,6 +434,7 @@ void rv2coe(double r[3], double v[3], double mu, truelon = undefined; // ------------ find mean anomaly for all orbits ----------- + double e; if ( typeorbit[0] == 'e' ) newtonnu(ecc, nu, e, m); } @@ -540,17 +536,15 @@ void jday(int year, int mon, int day, int hr, int minute, double sec, double& jd void days2mdhms(int year, double days, int& mon, int& day, int& hr, int& minute, double& sec) { - int i, inttemp, dayofyr; - double temp; int lmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - dayofyr = static_cast(std::floor(days)); + int dayofyr = static_cast(std::floor(days)); /* ----------------- find month and day of month ---------------- */ if ( (year % 4) == 0 ) lmonth[1] = 29; - i = 1; - inttemp = 0; + int i = 1; + int inttemp = 0; while ((dayofyr > inttemp + lmonth[i-1]) && (i < 12)) { inttemp = inttemp + lmonth[i-1]; @@ -560,7 +554,7 @@ void days2mdhms(int year, double days, int& mon, int& day, int& hr, int& minute, day = dayofyr - inttemp; /* ----------------- find hours minutes and seconds ------------- */ - temp = (days - dayofyr) * 24.0; + double temp = (days - dayofyr) * 24.0; hr = static_cast(std::floor(temp)); temp = (temp - hr) * 60.0; minute = static_cast(std::floor(temp)); @@ -609,17 +603,14 @@ void days2mdhms(int year, double days, int& mon, int& day, int& hr, int& minute, void invjday(double jd, int& year, int& mon, int& day, int& hr, int& minute, double& sec) { - int leapyrs; - double days, tu, temp; - /* --------------- find year and days of the year --------------- */ - temp = jd - 2415019.5; - tu = temp / 365.25; - year = 1900 + static_cast(std::floor(tu)); - leapyrs = static_cast(std::floor((year - 1901) * 0.25)); + double temp = jd - 2415019.5; + double tu = temp / 365.25; + year = 1900 + static_cast(std::floor(tu)); + int leapyrs = static_cast(std::floor((year - 1901) * 0.25)); // optional nudge by 8.64x10-7 sec to get even outputs - days = temp - ((year - 1900) * 365.0 + leapyrs) + 0.00000000001; + double days = temp - ((year - 1900) * 365.0 + leapyrs) + 0.00000000001; /* ------------ check for case of beginning of a year ----------- */ if (days < 1.0) diff --git a/plugins/Satellites/src/gsatellite/sgp4io.cpp b/plugins/Satellites/src/gsatellite/sgp4io.cpp index 3a7be674cbc61..c6969cab91c79 100644 --- a/plugins/Satellites/src/gsatellite/sgp4io.cpp +++ b/plugins/Satellites/src/gsatellite/sgp4io.cpp @@ -81,14 +81,13 @@ void twoline2rv elsetrec& satrec ) { - const double deg2rad = M_PI / 180.0; // 0.0174532925199433 - const double xpdotp = 1440.0 / (2.0 *M_PI); // 229.1831180523293 + static const double deg2rad = M_PI / 180.0; // 0.0174532925199433 + static const double xpdotp = 1440.0 / (2.0 *M_PI); // 229.1831180523293 double sec, mu, radiusearthkm, tumin, xke, j2, j3, j4, j3oj2; int cardnumb, numb, j; long revnum = 0, elnum = 0; char classification, intldesg[11]; - int year = 0; int mon, day, hr, minute, nexp, ibexp; getgravconst( whichconst, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2 ); @@ -184,6 +183,7 @@ void twoline2rv // ---------------- temp fix for years from 1957-2056 ------------------- // --------- correct fix will occur when year is 4-digit in tle --------- + int year = 0; if (satrec.epochyr < 57) year= satrec.epochyr + 2000; else diff --git a/src/gui/AstroCalcDialog.cpp b/src/gui/AstroCalcDialog.cpp index 0137d136d8fcf..311bef9f97007 100644 --- a/src/gui/AstroCalcDialog.cpp +++ b/src/gui/AstroCalcDialog.cpp @@ -752,7 +752,7 @@ void AstroCalcDialog::drawAziVsTimeDiagram() #ifdef USE_STATIC_PLUGIN_SATELLITES if (isSatellite) { - sat->update(core, JD, 0.0); + sat->update(core, JD); } else #endif @@ -5030,7 +5030,7 @@ void AstroCalcDialog::drawAltVsTimeDiagram() if (isSatellite) { // update data for that single satellite only - sat->update(core, JD, 0.0); + sat->update(core, JD); } #endif StelUtils::rectToSphe(&az, &alt, selectedObject->getAltAzPosAuto(core));