X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Ftiming%2Fsg_time.hxx;h=319afec61df0207dd0e28b2f06344a512ad383ea;hb=9af5f9f094706685bae09a885fb6adf6394124c2;hp=8acd4293118a8284d63b7f4801924c91df209fae;hpb=1a6e2509c729c596e6ce06d010c59dad69ec1a1d;p=simgear.git diff --git a/simgear/timing/sg_time.hxx b/simgear/timing/sg_time.hxx index 8acd4293..319afec6 100644 --- a/simgear/timing/sg_time.hxx +++ b/simgear/timing/sg_time.hxx @@ -4,19 +4,20 @@ // // Copyright (C) 1997 Curtis L. Olson - curt@flightgear.org // -// 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. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. // -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. +// Library General Public License for more details. // -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. // // $Id$ @@ -34,12 +35,6 @@ # include #endif -#ifdef HAVE_WINDOWS_H -# include -#endif - -#include - #include #ifdef FG_HAVE_STD_INCLUDES @@ -48,20 +43,7 @@ # include #endif -// #include - -#include "timezone.h" -// #include "lowleveltime.h" - - -enum sgTimingOffsetType { - SG_TIME_SYS_OFFSET = 0, - SG_TIME_GMT_OFFSET = 1, - SG_TIME_LAT_OFFSET = 2, - SG_TIME_SYS_ABSOLUTE = 3, - SG_TIME_GMT_ABSOLUTE = 4, - SG_TIME_LAT_ABSOLUTE = 5 -}; +#include // Define a structure containing time parameters @@ -95,70 +77,62 @@ private: // local sidereal time double lst; - // the difference between the precise sidereal time algorithm - // result and the course result. course_gst + diff has good - // accuracy for the short term + // the difference between the precise / expensive sidereal time + // algorithm result and the quick course result. course_gst + + // gst_diff has pretty good accuracy over the span of a couple hours double gst_diff; - // internal book keeping data - double last_mjd, last_dy; - int last_mn, last_yr; - public: + SGTime( double lon, double lat, const string& root ); SGTime( const string& root ); + SGTime(); ~SGTime(); + // Update the time related variables + void update( double lon, double lat, long int warp = 0 ); + + // Given lon/lat, update timezone information and local_offset + void updateLocal( double lon, double lat, const string& root ); + + inline time_t get_cur_time() const { return cur_time; }; + inline char* get_zonename() const { return zonename; } + inline struct tm* getGmt()const { return gmt; }; inline double getJD() const { return jd; }; inline double getMjd() const { return mjd; }; inline double getLst() const { return lst; }; inline double getGst() const { return gst; }; - inline time_t get_cur_time() const { return cur_time; }; - inline struct tm* getGmt()const { return gmt; }; - - // void adjust_warp(int val) { warp += val; }; - // void adjust_warp_delta(int val) { warp_delta += val; }; - - // Initialize the time dependent variables - void init( double lon, double lat, const string& root ); - // time_t timeOffset, sgTimingOffsetType offsetType ); - - // Update the time dependent variables - void update( double lon, double lat, double alt_m, long int warp ); - void updateLocal( double lon, double lat, const string& root ); +}; - void cal_mjd (int mn, double dy, int yr); - void utc_gst(); - double sidereal_precise (double lng); - double sidereal_course(double lng); - static SGTime *cur_time_params; - // Some other stuff which were changed to SGTime members on - // questionable grounds -:) - // time_t get_start_gmt(int year); - time_t get_gmt(int year, int month, int day, - int hour, int minute, int second); - time_t get_gmt(struct tm* the_time); +// Some useful utility functions that don't make sense to be part of +// the SGTime class - inline char* get_zonename() const { return zonename; } +// Return unix time in seconds for the given data (relative to GMT) +time_t sgTimeGetGMT(int year, int month, int day, + int hour, int minute, int second); - char* format_time( const struct tm* p, char* buf ); - long int fix_up_timezone( long int timezone_orig ); +// this is just a wrapper +inline time_t sgTimeGetGMT(struct tm* the_time) { + // printf("Using: %24s as input\n", asctime(the_time)); + return sgTimeGetGMT(the_time->tm_year, + the_time->tm_mon, + the_time->tm_mday, + the_time->tm_hour, + the_time->tm_min, + the_time->tm_sec); +} - // inline int get_warp_delta() const { return warp_delta; } -}; +// given a date in months, mn, days, dy, years, yr, return the +// modified Julian date (number of days elapsed since 1900 jan 0.5), +// mjd. Adapted from Xephem. +double sgTimeCalcMJD(int mn, double dy, int yr); +// given an mjd, calculate greenwich mean sidereal time, gst +double sgTimeCalcGST( double mjd ); -inline time_t SGTime::get_gmt(struct tm* the_time) // this is just a wrapper -{ - //printf("Using: %24s as input\n", asctime(the_time)); - return get_gmt(the_time->tm_year, - the_time->tm_mon, - the_time->tm_mday, - the_time->tm_hour, - the_time->tm_min, - the_time->tm_sec); -} +// format time +char* sgTimeFormatTime( const struct tm* p, char* buf ); #endif // _SG_TIME_HXX