StelUtils.cpp   StelUtils.cpp 
skipping to change at line 35 skipping to change at line 35
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "VecMath.hpp" #include "VecMath.hpp"
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QTextStream> #include <QTextStream>
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
#include <QLocale> #include <QLocale>
#include <QRegExp> #include <QRegExp>
#include <QtGlobal>
namespace StelUtils namespace StelUtils
{ {
//! Return the full name of stellarium, i.e. "stellarium 0.9.0" //! Return the full name of stellarium, i.e. "stellarium 0.9.0"
QString getApplicationName() QString getApplicationName()
{ {
return QString("Stellarium")+" "+StelUtils::getApplicationVersion(); return QString("Stellarium")+" "+StelUtils::getApplicationVersion();
} }
//! Return the version of stellarium, i.e. "0.9.0" //! Return the version of stellarium, i.e. "0.9.0"
skipping to change at line 58 skipping to change at line 59
return QString(PACKAGE_VERSION)+" (BZR r"+BZR_REVISION+")"; return QString(PACKAGE_VERSION)+" (BZR r"+BZR_REVISION+")";
#elif SVN_REVISION #elif SVN_REVISION
return QString(PACKAGE_VERSION)+" (SVN r"+SVN_REVISION+")"; return QString(PACKAGE_VERSION)+" (SVN r"+SVN_REVISION+")";
#else #else
return QString(PACKAGE_VERSION); return QString(PACKAGE_VERSION);
#endif #endif
} }
double hmsToRad(unsigned int h, unsigned int m, double s ) double hmsToRad(unsigned int h, unsigned int m, double s )
{ {
return (double)M_PI/24.*h*2.+(double)M_PI/12.*m/60.+s*M_PI/43200.; //return (double)M_PI/24.*h*2.+(double)M_PI/12.*m/60.+s*M_PI/43200.;
// Wrong formula! --AW
return (double)h*M_PI/12.+(double)m*M_PI/10800.+(double)s*M_PI/64800
0.;
} }
double dmsToRad(int d, unsigned int m, double s) double dmsToRad(int d, unsigned int m, double s)
{ {
if (d>=0) if (d>=0)
return (double)M_PI/180.*d+(double)M_PI/10800.*m+s*M_PI/6480 00.; return (double)M_PI/180.*d+(double)M_PI/10800.*m+s*M_PI/6480 00.;
return (double)M_PI/180.*d-(double)M_PI/10800.*m-s*M_PI/648000.; return (double)M_PI/180.*d-(double)M_PI/10800.*m-s*M_PI/648000.;
} }
/************************************************************************* /*************************************************************************
skipping to change at line 418 skipping to change at line 420
qDebug() << "getDecAngle failed to parse angle string:" << str; qDebug() << "getDecAngle failed to parse angle string:" << str;
return -0.0; return -0.0;
} }
// Check if a number is a power of 2 // Check if a number is a power of 2
bool isPowerOfTwo(int value) bool isPowerOfTwo(int value)
{ {
return (value & -value) == value; return (value & -value) == value;
} }
// Return the first power of two bigger than the given value // Return the first power of two greater or equal to the given value
int getBiggerPowerOfTwo(int value) int smallestPowerOfTwoGreaterOrEqualTo(int value)
{ {
int p=1; #ifndef NDEBUG
while (p<value) const int twoTo30 = 1073741824;
p<<=1; Q_ASSERT_X(value <= twoTo30, Q_FUNC_INFO,
return p; "Value too large - smallest greater/equal power-of-2 is o
ut of range");
#endif
if(value == 0){return 0;}
int pot=1;
while (pot<value){pot<<=1;}
return pot;
}
QSize smallestPowerOfTwoSizeGreaterOrEqualTo(const QSize base)
{
return QSize(smallestPowerOfTwoGreaterOrEqualTo(base.width()),
smallestPowerOfTwoGreaterOrEqualTo(base.height()));
} }
// Return the inverse sinus hyperbolic of z // Return the inverse sinus hyperbolic of z
double asinh(double z) double asinh(double z)
{ {
return std::log(z+std::sqrt(z*z+1)); return std::log(z+std::sqrt(z*z+1));
} }
/************************************************************************* /*************************************************************************
Convert a QT QDateTime class to julian day Convert a QT QDateTime class to julian day
skipping to change at line 1034 skipping to change at line 1049
*min = finalRe.capturedTexts().at(5).toInt(&ok); *min = finalRe.capturedTexts().at(5).toInt(&ok);
error = error || !ok; error = error || !ok;
*s = finalRe.capturedTexts().at(6).toFloat(&ok); *s = finalRe.capturedTexts().at(6).toFloat(&ok);
error = error || !ok; error = error || !ok;
if (!error) if (!error)
return true; return true;
} }
return false; return false;
} }
// Calculate and getting orbital period in days from semi-major axis // Calculate and getting sidereal period in days from semi-major axis
double calculateOrbitalPeriod(double SemiMajorAxis) double calculateSiderealPeriod(double SemiMajorAxis)
{ {
// Calculate semi-major axis in meters // Calculate semi-major axis in meters
double a = AU*1000*SemiMajorAxis; double a = AU*1000*SemiMajorAxis;
// Calculate orbital period in seconds // Calculate orbital period in seconds
// Here 1.32712440018e20 is heliocentric gravitational constant // Here 1.32712440018e20 is heliocentric gravitational constant
double period = 2*M_PI*std::sqrt(a*a*a/1.32712440018e20); double period = 2*M_PI*std::sqrt(a*a*a/1.32712440018e20);
return period/86400; // return period in days return period/86400; // return period in days
} }
// Calculate duration of mean solar day
double calculateSolarDay(double siderealPeriod, double siderealDay, bool fo
rwardDirection)
{
double coeff;
if (forwardDirection)
coeff = (siderealPeriod + 1)/siderealPeriod;
else
coeff = -1 * (siderealPeriod - 1)/siderealPeriod;
return siderealDay/coeff;
}
QString hoursToHmsStr(double hours)
{
int h = (int)hours;
int m = (int)((hours-h)*60);
float s = (((hours-h)*60)-m)*60;
return QString("%1h%2m%3s").arg(h).arg(m).arg(QString::number(s, 'f'
, 1));
}
#if defined(Q_OS_MAC) || defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
#include <sys/time.h>
#else
#include <time.h>
#endif
//! Get current time in seconds (relative to some arbitrary beginning in th
e past)
//!
//! Currently we only have a high-precision implementation for Mac, Linux a
nd
//! FreeBSD. A Windows implementation would be good as well (clock_t,
//! which we use right now, might be faster/slower than wall clock time
//! and usually supports milliseconds at best).
static long double getTime()
{
#if defined(Q_OS_MAC) || defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
struct timeval timeVal;
if(gettimeofday(&timeVal, NULL) != 0)
{
Q_ASSERT_X(false, Q_FUNC_INFO, "Failed to get time");
}
return static_cast<long double>(timeVal.tv_sec) + 0.000001L * timeVa
l.tv_usec;
#else
clock_t cpuTime = clock();
return static_cast<long double>(cpuTime) / CLOCKS_PER_SEC;
#endif
}
//! Time when the program execution started.
long double startTime = getTime();
long double secondsSinceStart()
{
return getTime() - startTime;
}
double decYear2DeltaT(double y)
{
// Note: the method here is adapted from Adapted from
// "Five Millennium Canon of Solar Eclipses" [Espenak and Meeus]
// A summary is described here:
// http://eclipse.gsfc.nasa.gov/SEhelp/deltatpoly2004.html
// set the default value for Delta T
double u = (y-1820)/100.;
double r = (-20 + 32 * std::pow(u,2.0));
if (y < -500)
{
u = (y-1820)/100.;
r = (-20 + 32 * std::pow(u,2.0));
}
else if (y < 500)
{
u = y/100;
r = (10583.6 - 1014.41 * u + 33.78311 * std::pow(u,2) - 5.95
2053 * std::pow(u,3)
- 0.1798452 * std::pow(u,4) + 0.022174192 * std::pow(
u,5) + 0.0090316521 * std::pow(u,6));
}
else if (y < 1600)
{
u = (y-1000)/100;
r = (1574.2 - 556.01 * u + 71.23472 * std::pow(u,2) + 0.3197
81 * std::pow(u,3)
- 0.8503463 * std::pow(u,4) - 0.005050998 * std::pow(
u,5) + 0.0083572073 * std::pow(u,6));
}
else if (y < 1700)
{
double t = y - 1600;
r = (120 - 0.9808 * t - 0.01532 * std::pow(t,2) + std::pow(t
,3) / 7129);
}
else if (y < 1800)
{
double t = y - 1700;
r = (8.83 + 0.1603 * t - 0.0059285 * std::pow(t,2) + 0.00013
336 * std::pow(t,3) - std::pow(t,4) / 1174000);
}
else if (y < 1860)
{
double t = y - 1800;
r = (13.72 - 0.332447 * t + 0.0068612 * std::pow(t,2) + 0.00
41116 * std::pow(t,3) - 0.00037436 * std::pow(t,4)
+ 0.0000121272 * std::pow(t,5) - 0.0000001699 * std::
pow(t,6) + 0.000000000875 * std::pow(t,7));
}
else if (y < 1900)
{
double t = y - 1860;
r = (7.62 + 0.5737 * t - 0.251754 * std::pow(t,2) + 0.016806
68 * std::pow(t,3)
-0.0004473624 * std::pow(t,4) + std::pow(t,5) / 2331
74);
}
else if (y < 1920)
{
double t = y - 1900;
r = (-2.79 + 1.494119 * t - 0.0598939 * std::pow(t,2) + 0.00
61966 * std::pow(t,3) - 0.000197 * std::pow(t,4));
}
else if (y < 1941)
{
double t = y - 1920;
r = (21.20 + 0.84493*t - 0.076100 * std::pow(t,2) + 0.002093
6 * std::pow(t,3));
}
else if (y < 1961)
{
double t = y - 1950;
r = (29.07 + 0.407*t - std::pow(t,2)/233 + std::pow(t,3) / 2
547);
}
else if (y < 1986)
{
double t = y - 1975;
r = (45.45 + 1.067*t - std::pow(t,2)/260 - std::pow(t,3) / 7
18);
}
else if (y < 2005)
{
double t = y - 2000;
r = (63.86 + 0.3345 * t - 0.060374 * std::pow(t,2) + 0.00172
75 * std::pow(t,3) + 0.000651814 * std::pow(t,4)
+ 0.00002373599 * std::pow(t,5));
}
else if (y < 2050)
{
double t = y - 2000;
r = (62.92 + 0.32217 * t + 0.005589 * std::pow(t,2));
}
else if (y < 2150)
{
r = (-20 + 32 * std::pow((y-1820)/100,2) - 0.5628 * (2150 -
y));
}
return r;
}
double getDeltaT(double jDay)
{
int year, month, day;
double moon = 0.;
getDateFromJulianDay(jDay, &year, &month, &day);
if (year<1955 or year>2005)
moon = getMoonSecularAcceleration(jDay);
// approximate "decimal year" = year + (month - 0.5)/12
return decYear2DeltaT(year + (month - 0.5)/12)+moon;
}
double getMoonSecularAcceleration(double jDay)
{
// Method described is here: http://eclipse.gsfc.nasa.gov/SEcat5/sec
ular.html
int year, month, day;
getDateFromJulianDay(jDay, &year, &month, &day);
double t = (year-1995)/100;
return -0.12932224 * t * t;
}
} // end of the StelUtils namespace } // end of the StelUtils namespace
 End of changes. 6 change blocks. 
9 lines changed or deleted 214 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/