-
Notifications
You must be signed in to change notification settings - Fork 43
/
utc_test.cpp
90 lines (81 loc) · 3.56 KB
/
utc_test.cpp
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
/* Copyright (C) 2018, Project Pluto
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA. */
/* These macros determine the MJD of the given date in 'YEAR'.
They are explained a bit in comments in 'delta_t.cpp' (q.v.).
We're only using the July and January ones (the months in which
leap seconds occur). Unused macros are commented out, just to
avoid nuisance compiler warnings. */
#define BASE_YEAR 19999999999L
#define JAN_1( YEAR) (((YEAR) * 365L + ((YEAR) + BASE_YEAR) / 4L - ((YEAR) + BASE_YEAR) / 100L \
+ ((YEAR) + BASE_YEAR) / 400L) - 678940L \
- ((BASE_YEAR + 1L) / 400L) * 97L)
// #define FEB_1( YEAR) (JAN_1( YEAR) + 31)
#define DEC_1( YEAR) (JAN_1( (YEAR)+1) - 31)
#define NOV_1( YEAR) (DEC_1( YEAR) - 30)
#define OCT_1( YEAR) (NOV_1( YEAR) - 31)
#define SEP_1( YEAR) (OCT_1( YEAR) - 30)
#define AUG_1( YEAR) (SEP_1( YEAR) - 31)
#define JUL_1( YEAR) (AUG_1( YEAR) - 31)
// #define JUN_1( YEAR) (JUL_1( YEAR) - 30)
// #define MAY_1( YEAR) (JUN_1( YEAR) - 31)
// #define APR_1( YEAR) (MAY_1( YEAR) - 30)
// #define MAR_1( YEAR) (APR_1( YEAR) - 31)
#include <stdio.h>
#include <stdlib.h>
#include "watdefs.h"
#include "afuncs.h"
int main( const int argc, const char **argv)
{
int year = 1970, end_year = 2040, i;
unsigned count = 0;
for( i = 1; i < argc; i++)
if( argv[i][0] == '-')
switch( argv[i][1])
{
case 'p':
mjd_end_of_predictive_leap_seconds = atoi( argv[i] + 2);
printf( "No predicted leap seconds after MJD %d\n",
mjd_end_of_predictive_leap_seconds);
break;
default:
printf( "Option '%s' ignored\n", argv[i]);
break;
}
else
sscanf( argv[i], "%d,%d", &year, &end_year);
printf( "Leap seconds for years %d to %d\n", year, end_year);
printf( "(See the 'official' list at https://hpiers.obspm.fr/iers/bul/bulc/UTC-TAI.history)\n");
printf( "Future leap seconds are predicted using the method described\n");
printf( "in 'delta_t.cpp', and come without warranty of any kind.\n");
for( ; year <= end_year; year++)
if( year >= 1972)
for( unsigned pass = 0; pass < 2; pass++)
{
const double tai_minus_tdt = -32.184; /* by definition */
const double jd = 2400000.5 + (pass ? JUL_1( year) : JAN_1( year));
const double tai_minus_utc_before =
tai_minus_tdt + td_minus_utc( jd - .0001);
const double tai_minus_utc_after =
tai_minus_tdt + td_minus_utc( jd + .0001);
if( tai_minus_utc_before != tai_minus_utc_after)
{
printf( "%d %s : %.3f%s", year, (pass ? "Jul" : "Jan"),
tai_minus_utc_after,
(count % 3 == 2 ? "\n" : " "));
count++;
}
}
printf( "\n");
return( 0);
}