]> git.mxchange.org Git - simgear.git/blob - simgear/timing/sg_time.hxx
More SGTime tidying.
[simgear.git] / simgear / timing / sg_time.hxx
1 // sg_time.hxx -- data structures and routines for managing time related stuff.
2 //
3 // Written by Curtis Olson, started August 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@flightgear.org
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifndef _SG_TIME_HXX
25 #define _SG_TIME_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32
33 #ifdef HAVE_CONFIG_H
34 #  include <config.h>
35 #endif
36
37 #ifdef HAVE_WINDOWS_H
38 #  include <windows.h>
39 #endif
40
41 #include <GL/glut.h>
42
43 #include <simgear/compiler.h>
44
45 #ifdef FG_HAVE_STD_INCLUDES
46 #  include <ctime>
47 #else
48 #  include <time.h>
49 #endif
50
51 // #include <FDM/flight.hxx>
52
53 #include "timezone.h"
54 // #include "lowleveltime.h"
55
56
57 enum sgTimingOffsetType {
58     SG_TIME_SYS_OFFSET   = 0,
59     SG_TIME_GMT_OFFSET   = 1,
60     SG_TIME_LAT_OFFSET   = 2,
61     SG_TIME_SYS_ABSOLUTE = 3,
62     SG_TIME_GMT_ABSOLUTE = 4,
63     SG_TIME_LAT_ABSOLUTE = 5
64 };
65
66
67 // Define a structure containing time parameters
68 class SGTime {
69
70 private:
71     // tzContainer stores all the current Timezone control points/
72     TimezoneContainer* tzContainer;
73
74     // Points to the current local timezone name;
75     char *zonename;
76
77     // Unix "calendar" time in seconds
78     time_t cur_time;
79
80     // Break down of equivalent GMT time
81     struct tm *gmt;
82
83     // offset of local time relative to GMT
84     time_t local_offset;
85
86     // Julian date
87     double jd;
88
89     // modified Julian date
90     double mjd;
91
92     // side real time at prime meridian
93     double gst;
94
95     // local sidereal time
96     double lst;
97
98     // the difference between the precise sidereal time algorithm
99     // result and the course result.  course_gst + diff has good
100     // accuracy for the short term
101     double gst_diff;
102
103     // internal book keeping data
104     double last_mjd, last_dy;
105     int last_mn, last_yr;
106
107 public:
108
109     SGTime( const string& root );
110     ~SGTime();
111
112     inline double getJD() const { return jd; };
113     inline double getMjd() const { return mjd; };
114     inline double getLst() const { return lst; };
115     inline double getGst() const { return gst; };
116     inline time_t get_cur_time() const { return cur_time; };
117     inline struct tm* getGmt()const { return gmt; };
118   
119     // void adjust_warp(int val) { warp += val; };
120     // void adjust_warp_delta(int val) { warp_delta += val; };
121
122     // Initialize the time dependent variables
123     void init( double lon, double lat, const string& root );
124     // time_t timeOffset, sgTimingOffsetType offsetType );
125
126     // Update the time dependent variables
127     void update( double lon, double lat, double alt_m, long int warp );
128     void updateLocal( double lon, double lat, const string& root );
129
130     void cal_mjd (int mn, double dy, int yr);
131     void utc_gst(); 
132     double sidereal_precise (double lng);
133     double sidereal_course(double lng); 
134     // static SGTime *cur_time_params;
135
136     // Some other stuff which were changed to SGTime members on
137     // questionable grounds -:)
138     // time_t get_start_gmt(int year);
139     time_t get_gmt(int year, int month, int day, 
140                    int hour, int minute, int second);
141     time_t get_gmt(struct tm* the_time);
142
143     inline char* get_zonename() const { return zonename; }
144
145     char* format_time( const struct tm* p, char* buf );
146     long int fix_up_timezone( long int timezone_orig );
147
148     // inline int get_warp_delta() const { return warp_delta; }
149 };
150
151
152 inline time_t SGTime::get_gmt(struct tm* the_time) // this is just a wrapper
153 {
154   //printf("Using: %24s as input\n", asctime(the_time));
155   return get_gmt(the_time->tm_year,
156           the_time->tm_mon,
157           the_time->tm_mday,
158           the_time->tm_hour,
159           the_time->tm_min,
160           the_time->tm_sec);
161 }
162
163
164 #endif // _SG_TIME_HXX