• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

kstarsdatetime.cpp

Go to the documentation of this file.
00001  /***************************************************************************
00002                           kstarsdatetime.cpp  -  K Desktop Planetarium
00003                              -------------------
00004     begin                : Tue 05 May 2004
00005     copyright            : (C) 2004 by Jason Harris
00006     email                : jharris@30doradus.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <kdebug.h>
00019  
00020 #include "kstarsdatetime.h"
00021 #include "ksnumbers.h"
00022 #include "dms.h"
00023 
00024 KStarsDateTime::KStarsDateTime() : ExtDateTime() {
00025     setDJD( J2000 );
00026 }
00027 
00028 KStarsDateTime::KStarsDateTime( long int _jd ) : ExtDateTime(){
00029     setDJD( (long double)( _jd ) );
00030 }
00031 
00032 KStarsDateTime::KStarsDateTime( const KStarsDateTime &kdt ) : ExtDateTime() {
00033     setDJD( kdt.djd() );
00034 }
00035 
00036 KStarsDateTime::KStarsDateTime( const ExtDateTime &edt ) : ExtDateTime( edt ) {
00037     //don't call setDJD() because we don't need to compute the time; just set DJD directly
00038     QTime _t = edt.time();
00039     ExtDate _d = edt.date();
00040     long double jdFrac = ( _t.hour()-12 + ( _t.minute() + ( _t.second() + _t.msec()/1000.)/60.)/60.)/24.;
00041     DJD = (long double)( _d.jd() ) + jdFrac;
00042 }
00043 
00044 KStarsDateTime::KStarsDateTime( const ExtDate &_d, const QTime &_t ) : ExtDateTime( _d, _t ) {
00045     //don't call setDJD() because we don't need to compute the time; just set DJD directly
00046     long double jdFrac = ( _t.hour()-12 + ( _t.minute() + ( _t.second() + _t.msec()/1000.)/60.)/60.)/24.;
00047     DJD = (long double)( _d.jd() ) + jdFrac;
00048 }
00049 
00050 KStarsDateTime::KStarsDateTime( double _jd ) : ExtDateTime() {
00051     setDJD( (long double)_jd );
00052 }
00053 
00054 KStarsDateTime::KStarsDateTime( long double _jd ) : ExtDateTime() {
00055     setDJD( _jd );
00056 }
00057 
00058 KStarsDateTime KStarsDateTime::currentDateTime() {
00059     KStarsDateTime dt( ExtDate::currentDate(), QTime::currentTime() );
00060     if ( dt.time().hour()==0 && dt.time().minute()==0 ) // midnight or right after?
00061             dt.setDate( ExtDate::currentDate() );         // fetch date again
00062     
00063     return dt;
00064 }
00065 
00066 void KStarsDateTime::setDJD( long double _jd ) {
00067     DJD = _jd;
00068 
00069     ExtDate dd;
00070     dd.setJD( (long int)( _jd + 0.5 ) );
00071     ExtDateTime::setDate( dd );
00072 
00073     double dayfrac = _jd - (double)( date().jd() ) + 0.5;
00074     if ( dayfrac > 1.0 ) dayfrac -= 1.0;
00075     double hour = 24.*dayfrac;
00076     int h = int(hour);
00077     int m = int( 60.*(hour - h) );
00078     int s = int( 60.*(60.*(hour - h) - m) );
00079     int ms = int( 1000.*(60.*(60.*(hour - h) - m) - s) );
00080 
00081     ExtDateTime::setTime( QTime( h, m, s, ms ) );
00082 }
00083 
00084 void KStarsDateTime::setDate( const ExtDate &_d ) {
00085     //Save the JD fraction
00086     long double jdFrac = djd() - (long double)( date().jd() );
00087     
00088     //set the integer portion of the JD and add back the JD fraction:
00089     setDJD( (long double)_d.jd() + jdFrac );
00090 }
00091 
00092 void KStarsDateTime::setTime( const QTime &_t ) {
00093     KStarsDateTime _dt( date(), _t );
00094     setDJD( _dt.djd() );
00095 }
00096 
00097 dms KStarsDateTime::gst() const {
00098     dms gst0 = GSTat0hUT();
00099 
00100     double hr = double( time().hour() );
00101     double mn = double( time().minute() );
00102     double sc = double( time().second() ) + double ( 0.001 * time().msec() );
00103     double st = (hr + ( mn + sc/60.0)/60.0)*SIDEREALSECOND;
00104 
00105     dms gst = dms( gst0.Degrees() + st*15.0 ).reduce();
00106     return gst;
00107 }
00108 
00109 dms KStarsDateTime::GSTat0hUT() const {
00110     double sinOb, cosOb;
00111 
00112     // Mean greenwich sidereal time
00113     KStarsDateTime t0( date(), QTime( 0, 0, 0 ) );
00114     long double s = t0.djd() - J2000;
00115     double t = s/36525.0;
00116     double t1 = 6.697374558 + 2400.051336*t + 0.000025862*t*t +
00117         0.000000002*t*t*t;
00118 
00119     // To obtain the apparent sidereal time, we have to correct the
00120     // mean greenwich sidereal time with nutation in longitude multiplied
00121     // by the cosine of the obliquity of the ecliptic. This correction
00122     // is called nutation in right ascention, and may amount to 0.3 secs.
00123     KSNumbers num( t0.djd() );
00124     num.obliquity()->SinCos( sinOb, cosOb );
00125 
00126     // nutLong has to be in hours of time since t1 is hours of time.
00127     double nutLong = num.dEcLong()*cosOb/15.0;
00128     t1 += nutLong;
00129 
00130     dms gst;
00131     gst.setH( t1 );
00132     return gst.reduce();
00133 }
00134 
00135 QTime KStarsDateTime::GSTtoUT( dms GST ) const {
00136     dms gst0 = GSTat0hUT();
00137 
00138     //dt is the number of sidereal hours since UT 0h.
00139     double dt = GST.Hours() - gst0.Hours();
00140     while ( dt < 0.0 ) dt += 24.0;
00141     while ( dt >= 24.0 ) dt -= 24.0;
00142 
00143     //convert to solar time.  dt is now the number of hours since 0h UT.
00144     dt /= SIDEREALSECOND;
00145 
00146     int hr = int( dt );
00147     int mn = int( 60.0*( dt - double( hr ) ) );
00148     int sc = int( 60.0*( 60.0*( dt - double( hr ) ) - double( mn ) ) );
00149     int ms = int( 1000.0*( 60.0*( 60.0*( dt - double(hr) ) - double(mn) ) - double(sc) ) );
00150     
00151     return( QTime( hr, mn, sc, ms ) );
00152 }
00153 
00154 void KStarsDateTime::setFromEpoch( double epoch ) {
00155     if (epoch == 1950.0) {
00156         setDJD( 2433282.4235 );
00157     } else if ( epoch == 2000.0 ) {
00158         setDJD( J2000 );
00159     } else {
00160         int year = int( epoch );
00161         KStarsDateTime dt( ExtDate( year, 1, 1 ), QTime( 0, 0, 0 ) );
00162         double days = (double)(dt.date().daysInYear())*( epoch - (double)year );
00163         dt = dt.addSecs( days*86400. ); //set date and time based on the number of days into the year
00164         setDJD( dt.djd() );
00165     }
00166 }

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal