source: Sophya/trunk/SophyaExt/XephemAstroLib/utc_gst.c@ 1895

Last change on this file since 1895 was 1719, checked in by cmv, 24 years ago

Adapted to version 3.5 xephem cmv 22/10/2001

File size: 2.1 KB
Line 
1#include "P_.h"
2#include "astro.h"
3
4static double gmst0 P_((double mjd));
5
6/* given a modified julian date, mjd, and a universally coordinated time, utc,
7 * return greenwich mean siderial time, *gst.
8 * N.B. mjd must be at the beginning of the day.
9 */
10void
11utc_gst (mjd, utc, gst)
12double mjd;
13double utc;
14double *gst;
15{
16 static double lastmjd = -18981;
17 static double t0;
18
19 if (mjd != lastmjd) {
20 t0 = gmst0(mjd);
21 lastmjd = mjd;
22 }
23 *gst = (1.0/SIDRATE)*utc + t0;
24 range (gst, 24.0);
25}
26
27/* given a modified julian date, mjd, and a greenwich mean siderial time, gst,
28 * return universally coordinated time, *utc.
29 * N.B. mjd must be at the beginning of the day.
30 */
31void
32gst_utc (mjd, gst, utc)
33double mjd;
34double gst;
35double *utc;
36{
37 static double lastmjd = -10000;
38 static double t0;
39
40 if (mjd != lastmjd) {
41 t0 = gmst0 (mjd);
42 lastmjd = mjd;
43 }
44 *utc = gst - t0;
45 range (utc, 24.0);
46 *utc *= SIDRATE;
47}
48
49/* gmst0() - return Greenwich Mean Sidereal Time at 0h UT; stern
50 */
51static double
52gmst0 (mjd)
53double mjd; /* date at 0h UT in julian days since MJD0 */
54{
55 double T, x;
56
57 T = ((int)(mjd - 0.5) + 0.5 - J2000)/36525.0;
58 x = 24110.54841 +
59 (8640184.812866 + (0.093104 - 6.2e-6 * T) * T) * T;
60 x /= 3600.0;
61 range(&x, 24.0);
62 return (x);
63}
64
65#ifdef TEST_GMST
66
67/* original routine by elwood; has a secular drift of 0.08s/cty */
68static double
69tnaught (mjd)
70double mjd; /* julian days since 1900 jan 0.5 */
71{
72 double dmjd;
73 int m, y;
74 double d;
75 double t, t0;
76
77 mjd_cal (mjd, &m, &d, &y);
78 cal_mjd (1, 0., y, &dmjd);
79 t = dmjd/36525;
80 t0 = 6.57098e-2 * (mjd - dmjd) -
81 (24 - (6.6460656 + (5.1262e-2 + (t * 2.581e-5))*t) -
82 (2400 * (t - (((double)y - 1900)/100))));
83 range(&t0, 24.0);
84 return (t0);
85}
86
87#include <stdlib.h>
88main(argc, argv)
89 int argc;
90 char *argv[];
91{
92 double mjd, gst;
93 while (scanf("%lf", &mjd) == 1) {
94 mjd -= MJD0;
95 gst = tnaught(mjd);
96 printf("%17.9f %10.7f %10.7f\n", mjd + MJD0, gst, gmst0(mjd));
97 }
98}
99#endif
100
101/* For RCS Only -- Do Not Edit */
102static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: utc_gst.c,v $ $Date: 2001-10-22 12:08:28 $ $Revision: 1.2 $ $Name: not supported by cvs2svn $"};
Note: See TracBrowser for help on using the repository browser.