| 1 | #include "astro.h"
 | 
|---|
| 2 | 
 | 
|---|
| 3 | static double gmst0 (double mj);
 | 
|---|
| 4 | 
 | 
|---|
| 5 | /* given a modified julian date, mj, and a universally coordinated time, utc,
 | 
|---|
| 6 |  * return greenwich mean siderial time, *gst.
 | 
|---|
| 7 |  * N.B. mj must be at the beginning of the day.
 | 
|---|
| 8 |  */
 | 
|---|
| 9 | void
 | 
|---|
| 10 | utc_gst (double mj, double utc, double *gst)
 | 
|---|
| 11 | {
 | 
|---|
| 12 |         static double lastmj = -18981;
 | 
|---|
| 13 |         static double t0;
 | 
|---|
| 14 | 
 | 
|---|
| 15 |         if (mj != lastmj) {
 | 
|---|
| 16 |             t0 = gmst0(mj);
 | 
|---|
| 17 |             lastmj = mj;
 | 
|---|
| 18 |         }
 | 
|---|
| 19 |         *gst = (1.0/SIDRATE)*utc + t0;
 | 
|---|
| 20 |         range (gst, 24.0);
 | 
|---|
| 21 | }
 | 
|---|
| 22 | 
 | 
|---|
| 23 | /* given a modified julian date, mj, and a greenwich mean siderial time, gst,
 | 
|---|
| 24 |  * return universally coordinated time, *utc.
 | 
|---|
| 25 |  * N.B. mj must be at the beginning of the day.
 | 
|---|
| 26 |  */
 | 
|---|
| 27 | void
 | 
|---|
| 28 | gst_utc (double mj, double gst, double *utc)
 | 
|---|
| 29 | {
 | 
|---|
| 30 |         static double lastmj = -10000;
 | 
|---|
| 31 |         static double t0;
 | 
|---|
| 32 | 
 | 
|---|
| 33 |         if (mj != lastmj) {
 | 
|---|
| 34 |             t0 = gmst0 (mj);
 | 
|---|
| 35 |             lastmj = mj;
 | 
|---|
| 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
 | 
|---|
| 45 | gmst0 (
 | 
|---|
| 46 | double mj)      /* date at 0h UT in julian days since MJD0 */
 | 
|---|
| 47 | {
 | 
|---|
| 48 |         double T, x;
 | 
|---|
| 49 | 
 | 
|---|
| 50 |         T = ((int)(mj - 0.5) + 0.5 - J2000)/36525.0;
 | 
|---|
| 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
 | 
|---|
| 62 | tnaught (mj)
 | 
|---|
| 63 | double mj;      /* julian days since 1900 jan 0.5 */
 | 
|---|
| 64 | {
 | 
|---|
| 65 |         double dmj;
 | 
|---|
| 66 |         int m, y;
 | 
|---|
| 67 |         double d;
 | 
|---|
| 68 |         double t, t0;
 | 
|---|
| 69 | 
 | 
|---|
| 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) - 
 | 
|---|
| 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 | {
 | 
|---|
| 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));
 | 
|---|
| 90 |         }
 | 
|---|
| 91 | }
 | 
|---|
| 92 | #endif
 | 
|---|
| 93 | 
 | 
|---|
| 94 | /* For RCS Only -- Do Not Edit */
 | 
|---|
| 95 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: utc_gst.c,v $ $Date: 2005-01-17 10:13:08 $ $Revision: 1.4 $ $Name: not supported by cvs2svn $"};
 | 
|---|