1 | #include "erfa.h"
|
---|
2 |
|
---|
3 | int eraUtctai(double utc1, double utc2, double *tai1, double *tai2)
|
---|
4 | /*
|
---|
5 | ** - - - - - - - - - -
|
---|
6 | ** e r a U t c t a i
|
---|
7 | ** - - - - - - - - - -
|
---|
8 | **
|
---|
9 | ** Time scale transformation: Coordinated Universal Time, UTC, to
|
---|
10 | ** International Atomic Time, TAI.
|
---|
11 | **
|
---|
12 | ** Given:
|
---|
13 | ** utc1,utc2 double UTC as a 2-part quasi Julian Date (Notes 1-4)
|
---|
14 | **
|
---|
15 | ** Returned:
|
---|
16 | ** tai1,tai2 double TAI as a 2-part Julian Date (Note 5)
|
---|
17 | **
|
---|
18 | ** Returned (function value):
|
---|
19 | ** int status: +1 = dubious year (Note 3)
|
---|
20 | ** 0 = OK
|
---|
21 | ** -1 = unacceptable date
|
---|
22 | **
|
---|
23 | ** Notes:
|
---|
24 | **
|
---|
25 | ** 1) utc1+utc2 is quasi Julian Date (see Note 2), apportioned in any
|
---|
26 | ** convenient way between the two arguments, for example where utc1
|
---|
27 | ** is the Julian Day Number and utc2 is the fraction of a day.
|
---|
28 | **
|
---|
29 | ** 2) JD cannot unambiguously represent UTC during a leap second unless
|
---|
30 | ** special measures are taken. The convention in the present
|
---|
31 | ** function is that the JD day represents UTC days whether the
|
---|
32 | ** length is 86399, 86400 or 86401 SI seconds. In the 1960-1972 era
|
---|
33 | ** there were smaller jumps (in either direction) each time the
|
---|
34 | ** linear UTC(TAI) expression was changed, and these "mini-leaps"
|
---|
35 | ** are also included in the ERFA convention.
|
---|
36 | **
|
---|
37 | ** 3) The warning status "dubious year" flags UTCs that predate the
|
---|
38 | ** introduction of the time scale or that are too far in the future
|
---|
39 | ** to be trusted. See eraDat for further details.
|
---|
40 | **
|
---|
41 | ** 4) The function eraDtf2d converts from calendar date and time of day
|
---|
42 | ** into 2-part Julian Date, and in the case of UTC implements the
|
---|
43 | ** leap-second-ambiguity convention described above.
|
---|
44 | **
|
---|
45 | ** 5) The returned TAI1,TAI2 are such that their sum is the TAI Julian
|
---|
46 | ** Date.
|
---|
47 | **
|
---|
48 | ** Called:
|
---|
49 | ** eraJd2cal JD to Gregorian calendar
|
---|
50 | ** eraDat delta(AT) = TAI-UTC
|
---|
51 | ** eraCal2jd Gregorian calendar to JD
|
---|
52 | **
|
---|
53 | ** References:
|
---|
54 | **
|
---|
55 | ** McCarthy, D. D., Petit, G. (eds.), IERS Conventions (2003),
|
---|
56 | ** IERS Technical Note No. 32, BKG (2004)
|
---|
57 | **
|
---|
58 | ** Explanatory Supplement to the Astronomical Almanac,
|
---|
59 | ** P. Kenneth Seidelmann (ed), University Science Books (1992)
|
---|
60 | **
|
---|
61 | ** Copyright (C) 2013-2016, NumFOCUS Foundation.
|
---|
62 | ** Derived, with permission, from the SOFA library. See notes at end of file.
|
---|
63 | */
|
---|
64 | {
|
---|
65 | int big1;
|
---|
66 | int iy, im, id, j, iyt, imt, idt;
|
---|
67 | double u1, u2, fd, dat0, dat12, w, dat24, dlod, dleap, z1, z2, a2;
|
---|
68 |
|
---|
69 |
|
---|
70 | /* Put the two parts of the UTC into big-first order. */
|
---|
71 | big1 = ( utc1 >= utc2 );
|
---|
72 | if ( big1 ) {
|
---|
73 | u1 = utc1;
|
---|
74 | u2 = utc2;
|
---|
75 | } else {
|
---|
76 | u1 = utc2;
|
---|
77 | u2 = utc1;
|
---|
78 | }
|
---|
79 |
|
---|
80 | /* Get TAI-UTC at 0h today. */
|
---|
81 | j = eraJd2cal(u1, u2, &iy, &im, &id, &fd);
|
---|
82 | if ( j ) return j;
|
---|
83 | j = eraDat(iy, im, id, 0.0, &dat0);
|
---|
84 | if ( j < 0 ) return j;
|
---|
85 |
|
---|
86 | /* Get TAI-UTC at 12h today (to detect drift). */
|
---|
87 | j = eraDat(iy, im, id, 0.5, &dat12);
|
---|
88 | if ( j < 0 ) return j;
|
---|
89 |
|
---|
90 | /* Get TAI-UTC at 0h tomorrow (to detect jumps). */
|
---|
91 | j = eraJd2cal(u1+1.5, u2-fd, &iyt, &imt, &idt, &w);
|
---|
92 | if ( j ) return j;
|
---|
93 | j = eraDat(iyt, imt, idt, 0.0, &dat24);
|
---|
94 | if ( j < 0 ) return j;
|
---|
95 |
|
---|
96 | /* Separate TAI-UTC change into per-day (DLOD) and any jump (DLEAP). */
|
---|
97 | dlod = 2.0 * (dat12 - dat0);
|
---|
98 | dleap = dat24 - (dat0 + dlod);
|
---|
99 |
|
---|
100 | /* Remove any scaling applied to spread leap into preceding day. */
|
---|
101 | fd *= (ERFA_DAYSEC+dleap)/ERFA_DAYSEC;
|
---|
102 |
|
---|
103 | /* Scale from (pre-1972) UTC seconds to SI seconds. */
|
---|
104 | fd *= (ERFA_DAYSEC+dlod)/ERFA_DAYSEC;
|
---|
105 |
|
---|
106 | /* Today's calendar date to 2-part JD. */
|
---|
107 | if ( eraCal2jd(iy, im, id, &z1, &z2) ) return -1;
|
---|
108 |
|
---|
109 | /* Assemble the TAI result, preserving the UTC split and order. */
|
---|
110 | a2 = z1 - u1;
|
---|
111 | a2 += z2;
|
---|
112 | a2 += fd + dat0/ERFA_DAYSEC;
|
---|
113 | if ( big1 ) {
|
---|
114 | *tai1 = u1;
|
---|
115 | *tai2 = a2;
|
---|
116 | } else {
|
---|
117 | *tai1 = a2;
|
---|
118 | *tai2 = u1;
|
---|
119 | }
|
---|
120 |
|
---|
121 | /* Status. */
|
---|
122 | return j;
|
---|
123 |
|
---|
124 | }
|
---|
125 | /*----------------------------------------------------------------------
|
---|
126 | **
|
---|
127 | **
|
---|
128 | ** Copyright (C) 2013-2016, NumFOCUS Foundation.
|
---|
129 | ** All rights reserved.
|
---|
130 | **
|
---|
131 | ** This library is derived, with permission, from the International
|
---|
132 | ** Astronomical Union's "Standards of Fundamental Astronomy" library,
|
---|
133 | ** available from http://www.iausofa.org.
|
---|
134 | **
|
---|
135 | ** The ERFA version is intended to retain identical functionality to
|
---|
136 | ** the SOFA library, but made distinct through different function and
|
---|
137 | ** file names, as set out in the SOFA license conditions. The SOFA
|
---|
138 | ** original has a role as a reference standard for the IAU and IERS,
|
---|
139 | ** and consequently redistribution is permitted only in its unaltered
|
---|
140 | ** state. The ERFA version is not subject to this restriction and
|
---|
141 | ** therefore can be included in distributions which do not support the
|
---|
142 | ** concept of "read only" software.
|
---|
143 | **
|
---|
144 | ** Although the intent is to replicate the SOFA API (other than
|
---|
145 | ** replacement of prefix names) and results (with the exception of
|
---|
146 | ** bugs; any that are discovered will be fixed), SOFA is not
|
---|
147 | ** responsible for any errors found in this version of the library.
|
---|
148 | **
|
---|
149 | ** If you wish to acknowledge the SOFA heritage, please acknowledge
|
---|
150 | ** that you are using a library derived from SOFA, rather than SOFA
|
---|
151 | ** itself.
|
---|
152 | **
|
---|
153 | **
|
---|
154 | ** TERMS AND CONDITIONS
|
---|
155 | **
|
---|
156 | ** Redistribution and use in source and binary forms, with or without
|
---|
157 | ** modification, are permitted provided that the following conditions
|
---|
158 | ** are met:
|
---|
159 | **
|
---|
160 | ** 1 Redistributions of source code must retain the above copyright
|
---|
161 | ** notice, this list of conditions and the following disclaimer.
|
---|
162 | **
|
---|
163 | ** 2 Redistributions in binary form must reproduce the above copyright
|
---|
164 | ** notice, this list of conditions and the following disclaimer in
|
---|
165 | ** the documentation and/or other materials provided with the
|
---|
166 | ** distribution.
|
---|
167 | **
|
---|
168 | ** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
|
---|
169 | ** the International Astronomical Union nor the names of its
|
---|
170 | ** contributors may be used to endorse or promote products derived
|
---|
171 | ** from this software without specific prior written permission.
|
---|
172 | **
|
---|
173 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
174 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
175 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
---|
176 | ** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
---|
177 | ** COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
178 | ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
---|
179 | ** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
180 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
---|
181 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
182 | ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
---|
183 | ** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
---|
184 | ** POSSIBILITY OF SUCH DAMAGE.
|
---|
185 | **
|
---|
186 | */
|
---|