X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Ftiming%2Fsg_time.hxx;h=319afec61df0207dd0e28b2f06344a512ad383ea;hb=9af5f9f094706685bae09a885fb6adf6394124c2;hp=0a1cd0a08d1cb6459e913615eb5e9405bb824770;hpb=8159b749f49be587e794a8438db7a4373d527b1d;p=simgear.git diff --git a/simgear/timing/sg_time.hxx b/simgear/timing/sg_time.hxx index 0a1cd0a0..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 @@ -71,99 +53,86 @@ private: // tzContainer stores all the current Timezone control points/ TimezoneContainer* tzContainer; - //Store the current local timezone name; + // Points to the current local timezone name; char *zonename; // Unix "calendar" time in seconds time_t cur_time; - // Break down of GMT time + // Break down of equivalent GMT time struct tm *gmt; + // offset of local time relative to GMT + time_t local_offset; + // Julian date double jd; // modified Julian date double mjd; - double last_mjd, last_dy; - int last_mn, last_yr; - // side real time at prime meridian double gst; // local sidereal time double lst; - // local offset to GMT - time_t localOffset; - - // the difference between the precise sidereal time algorithm - // result and the course result. course + 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; - // An offset in seconds from the true time. Allows us to adjust - // the effective time of day. - long int warp; - - // How much to change the value of warp each iteration. Allows us - // to make time progress faster than normal. - long int warp_delta; - 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 ); - 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); - - char* format_time( const struct tm* p, char* buf ); - long int fix_up_timezone( long int timezone_orig ); - - inline int get_warp_delta() const { return warp_delta; } -}; +// Some useful utility functions that don't make sense to be part of +// the SGTime class +// 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); -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); +// 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); } +// 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 ); + +// format time +char* sgTimeFormatTime( const struct tm* p, char* buf ); + #endif // _SG_TIME_HXX