-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGreenwichSideralTime.c
More file actions
210 lines (173 loc) · 5.31 KB
/
GreenwichSideralTime.c
File metadata and controls
210 lines (173 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/**************************************************************************
AstronomicalAlgorithms
A portable ANSI C implementation of some of the algorithms published in
Astronomical Algorithms
by Jean Meeus
2nd edition (December 1998)
Willmann-Bell
ISBN: 0943396638
by Christophe DAVID (christophe.david@christophedavid.org)
You may use parts of this source code as long as
- you mention clearly that its latest version can be obtained
free of charge at
http://www.christophedavid.org/
AND
- you send me a free copy of whatever you make using this code.
Comments and suggestions welcome.
**************************************************************************/
/*!
@file
@brief calculates the Greenwich Mean Sideral Time
@author Christophe DAVID \n
christophe.david@christophedavid.org \n
http://www.christophedavid.org
@since 01/07/1999
@version 1.0
@date 05/04/2001
@bug no known bug
@param double *GreenwichSideralTime
@param short Year
@param short Month
@param short Day
@param short Hours
@param short Minutes
@param short Seconds
@param short Calendar
@param short Mode
@return
- 0 : completed successfully
- 1 : error in parameter 1
- 2 : error in parameter 2
- 3 : error in parameter 3
- 4 : error in parameter 4
- 5 : error in parameter 5
- 6 : error in parameter 6
- 7 : error in parameter 7
- 8 : error in parameter 8
- 9 : error in parameter 9
@if logger
@image html http://www.mot.be/cgi-bin/logger.cgi?GreenwichSideralTime.c
@endif
*/
/* see page 87 */
#ifdef ASTROALGO
#include <math.h>
#include <stdio.h>
#include "AstronomicalAlgorithms.h"
#if _WIN32
__declspec(dllexport) short __stdcall
#endif
#else
short
#endif
int
ShGreenwichMeanSideralTime(double *pdoGreenwichSideralTime, short shY,
short shM, short shD, short shH, short shm,
short shS, short shCalendar, short shMode)
/* shCalendar JULIAN for julian, GREGORIAN for gregorian */
/* shMode 1 gives the result in seconds */
/* shMode 2 gives the result in degrees */
{
short shReturnValue = (short) 0;
short shIsLeap = (short) 0;
double ashDaysInMonth[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
double doInputJulianDate = (double) 0;
if (pdoGreenwichSideralTime != NULL)
{
*pdoGreenwichSideralTime = (double) 0;
}
if (pdoGreenwichSideralTime == NULL)
{
shReturnValue = (short) 1;
}
else if ((shM < 1) || (shM > 12))
{
shReturnValue = (short) 3;
}
else if ((shD < 1) || (shD > ashDaysInMonth[(int) shM - 1]))
{
shReturnValue = (short) 4;
}
else if ( (shH < 0)
|| (shH > 23)
)
{
shReturnValue = (short) 5;
}
else if ( (shm < 0)
|| (shm > 59)
)
{
shReturnValue = (short) 6;
}
else if ( (shS < 0)
|| (shS > 59)
)
{
shReturnValue = (short) 7;
}
else if ( (shCalendar != (short) JULIAN)
&& (shCalendar != (short) GREGORIAN)
)
{
shReturnValue = (short) 8;
}
else if ( (shMode != (short) 1)
&& (shMode != (short) 2)
)
{
shReturnValue = (short) 9;
}
/* leap year validation */
else if (ShIsLeapYear(&shIsLeap, (short) shY, shCalendar) != 0)
{
shReturnValue = (short) 901;
}
else if ((shM == 2) && (shD == 29) && (shIsLeap != 1))
{
shReturnValue = (short) 101;
}
else if (ShJulianDay(&doInputJulianDate, shY, shM, shD, shCalendar) != 0)
{
shReturnValue = (short) 102;
}
else if (doInputJulianDate - floor(doInputJulianDate) != (double) 0.5)
{
shReturnValue = (short) 103;
}
else
{
double doT = (double) ((doInputJulianDate - (double) 2451545) /
(double) 36525);
if (shMode == 1)
{
*pdoGreenwichSideralTime =
( ( ((double) 6 * (double) 3600)
+ ((double) 41 * (double) 60)
+ (double) 50.54841
)
+ ((double) 8640184.812866 * doT)
+ ((double) 0.093104 * doT * doT)
- ((double) 0.0000062 * doT * doT * doT)
);
*pdoGreenwichSideralTime +=
(double) 1.00273790935 *
(
((double) shH * (double) 3600)
+ ((double) shm * (double) 60)
+ ((double) shS)
);
}
else if (shMode == 2)
{
*pdoGreenwichSideralTime =
( (double) 100.46061837
+ ((double) 36000.770053608 * doT)
+ ((double) 0.000387933 * doT * doT)
- ((doT * doT * doT) / (double) 38710000)
);
/* add H m S to InputJulianDate, see page 88 */
}
}
return shReturnValue;
}