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