[Kstars-devel] branches/kstars/summer/kstars/kstars
Prakash Mohan
prak902000 at gmail.com
Sat May 9 01:29:57 CEST 2009
SVN commit 965465 by prakash:
Creating a class KSAlmanac to keep track of / provide an easy way to get rise and set times of sun and moon for any given location and date.
It also computes Astronomical, Nautical and Civil Twilights to the accuracy of about a minute.
CCMAIL: kstars-devel at kde.org
M +2 -1 CMakeLists.txt
M +101 -0 ksalmanac.cpp
M +54 -0 ksalmanac.h
--- branches/kstars/summer/kstars/kstars/CMakeLists.txt #965464:965465
@@ -102,9 +102,10 @@
tools/scriptargwidgets.cpp
tools/scriptbuilder.cpp
tools/scriptfunction.cpp
- tools/skycalendar.cpp
+ tools/skycalendar.cpp
tools/wutdialog.cpp
tools/flagmanager.cpp
+
)
kde4_add_ui_files(libkstarstools_SRCS
--- branches/kstars/summer/kstars/kstars/ksalmanac.cpp #965464:965465
@@ -0,0 +1,101 @@
+/***************************************************************************
+ ksalmanac.cpp - description
+
+ -------------------
+ begin : Friday May 8, 2009
+ copyright : (C) 2009 by Prakash Mohan
+ email : prak902000 at gmail.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "ksalmanac.h"
+
+#include <math.h>
+
+#include "skyobjects/kssun.h"
+#include "skyobjects/ksmoon.h"
+#include "geolocation.h"
+#include "kstars.h"
+#include "kstarsdatetime.h"
+#include "ksnumbers.h"
+#include "dms.h"
+
+KSAlmanac* KSAlmanac::pinstance=NULL;
+
+KSAlmanac* KSAlmanac::Instance() {
+ if(!pinstance) pinstance = new KSAlmanac;
+ return pinstance;
+}
+
+KSAlmanac::KSAlmanac() {
+ ks = KStars::Instance();
+ dt = KStarsDateTime::currentDateTime();
+ geo = ks->geo();
+ update();
+ riseRate = 4.0/cos(m_Sun->dec())/14400.0;
+}
+
+void update() {
+ RiseSetTime( (SkyObject*)m_Sun, &SunRise, &SunSet );
+ RiseSetTime( (SkyObject*)m_Moon, &MoonRise, &MoonSet );
+}
+void KSAlmanac::RiseSetTime( SkyObject *o, double *riseTime, double *setTime ) {
+ //Compute Sun rise and set times
+ *riseTime = -1.0 * o->riseSetTime( dt.djd() + 1.0, geo, true ).secsTo(QTime()) / 86400.0;
+ *setTime = -1.0 * o->riseSetTime( dt.djd(), geo, false ).secsTo(QTime()) / 86400.0;
+ //check to see if Sun is circumpolar
+ //requires temporary repositioning of Sun to target date
+ KSNumbers *num = new KSNumbers( dt.djd() );
+ KSNumbers *oldNum = new KSNumbers( ks->data()->ut().djd() );
+ dms LST = geo->GSTtoLST( dt.gst() );
+ o->updateCoords( num, true, geo->lat(), &LST );
+ if ( o->checkCircumpolar( geo->lat() ) ) {
+ if ( o->alt()->Degrees() > 0.0 ) {
+ //Circumpolar, signal it this way:
+ *riseTime = 0.0;
+ *setTime = 1.0;
+ } else {
+ //never rises, signal it this way:
+ *riseTime = 0.0;
+ *setTime = -1.0;
+ }
+ }
+ o->updateCoords( oldNum, true, ks->geo()->lat(), ks->LST() );
+ o->EquatorialToHorizontal( ks->LST(), ks->geo()->lat() );
+ delete num;
+ delete oldNum;
+
+}
+
+void KSAlmanac::setDate( KStarsDateTime *newdt ) {
+ dt = *newdt;
+ update();
+}
+
+void KSAlmanac::setLocation( Geolocation *m_geo ) {
+ geo = *m_geo;
+ update();
+}
+
+double KSAlmanac::getAstroTwilight( bool begin = true ) {
+ if(begin) return ( SunRise - 18 * riseRate );
+ return ( SunSet + 18 * riseRate );
+}
+
+double KSAlmanac::getNauticalTwilight( bool begin = true ) {
+ if(begin) return ( SunRise - 12 * riseRate );
+ return ( SunSet + 12 * riseRate );
+}
+
+double KSAlmanac::getCivilTwilight( bool begin = true ) {
+ if(begin) return ( SunRise - 6 * riseRate );
+ return ( SunSet + 6 * riseRate );
+}
--- branches/kstars/summer/kstars/kstars/ksalmanac.h #965464:965465
@@ -0,0 +1,54 @@
+/***************************************************************************
+ ksalmanac.h - description
+
+ -------------------
+ begin : Friday May 8, 2009
+ copyright : (C) 2009 by Prakash Mohan
+ email : prak902000 at gmail.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef KSALMANAC_H_
+#define KSALMANAC_H_
+
+#include "skyobjects/kssun.h"
+#include "skyobjects/ksmoon.h"
+#include "geolocation.h"
+#include "kstars.h"
+#include "kstarsdatetime.h"
+#include "kstarsdata.h"
+class KSAlmanac {
+ public:
+ void RiseSetTime( SkyObject *o, double *riseTime, double *setTime );
+ void setDate( KStarsDateTime *newdt );
+ void setLocation( GeoLocation *m_geo );
+ static KSAlmanac* Instance();
+ inline double getSunRise() { return SunRise; }
+ inline double getSunSet() { return SunSet; }
+ inline double getMoonRise() { return MoonRise; }
+ inline double getMoonSet() { return MoonSet; }
+ double getAstroTwilight( bool begin = true );
+ double getNauticalTwilight( bool begin = true );
+ double getCivilTwilight( bool begin = true );
+
+ private:
+ KSAlmanac( );
+ void update();
+ static KSAlmanac *pinstance;
+ KSSun m_Sun();
+ KSMoon m_Moon();
+ KStars *ks;
+ KStarsDateTime dt;
+ GeoLocation geo;
+ double SunRise, SunSet, MoonRise, MoonSet, riseRate;
+};
+
+#endif
More information about the Kstars-devel
mailing list