1 | #include "erfa.h"
|
---|
2 |
|
---|
3 | int eraUt1utc(double ut11, double ut12, double dut1,
|
---|
4 | double *utc1, double *utc2)
|
---|
5 | /*
|
---|
6 | ** - - - - - - - - - -
|
---|
7 | ** e r a U t 1 u t c
|
---|
8 | ** - - - - - - - - - -
|
---|
9 | **
|
---|
10 | ** Time scale transformation: Universal Time, UT1, to Coordinated
|
---|
11 | ** Universal Time, UTC.
|
---|
12 | **
|
---|
13 | ** Given:
|
---|
14 | ** ut11,ut12 double UT1 as a 2-part Julian Date (Note 1)
|
---|
15 | ** dut1 double Delta UT1: UT1-UTC in seconds (Note 2)
|
---|
16 | **
|
---|
17 | ** Returned:
|
---|
18 | ** utc1,utc2 double UTC as a 2-part quasi Julian Date (Notes 3,4)
|
---|
19 | **
|
---|
20 | ** Returned (function value):
|
---|
21 | ** int status: +1 = dubious year (Note 5)
|
---|
22 | ** 0 = OK
|
---|
23 | ** -1 = unacceptable date
|
---|
24 | **
|
---|
25 | ** Notes:
|
---|
26 | **
|
---|
27 | ** 1) ut11+ut12 is Julian Date, apportioned in any convenient way
|
---|
28 | ** between the two arguments, for example where ut11 is the Julian
|
---|
29 | ** Day Number and ut12 is the fraction of a day. The returned utc1
|
---|
30 | ** and utc2 form an analogous pair, except that a special convention
|
---|
31 | ** is used, to deal with the problem of leap seconds - see Note 3.
|
---|
32 | **
|
---|
33 | ** 2) Delta UT1 can be obtained from tabulations provided by the
|
---|
34 | ** International Earth Rotation and Reference Systems Service. The
|
---|
35 | ** value changes abruptly by 1s at a leap second; however, close to
|
---|
36 | ** a leap second the algorithm used here is tolerant of the "wrong"
|
---|
37 | ** choice of value being made.
|
---|
38 | **
|
---|
39 | ** 3) JD cannot unambiguously represent UTC during a leap second unless
|
---|
40 | ** special measures are taken. The convention in the present
|
---|
41 | ** function is that the returned quasi JD day UTC1+UTC2 represents
|
---|
42 | ** UTC days whether the length is 86399, 86400 or 86401 SI seconds.
|
---|
43 | **
|
---|
44 | ** 4) The function eraD2dtf can be used to transform the UTC quasi-JD
|
---|
45 | ** into calendar date and clock time, including UTC leap second
|
---|
46 | ** handling.
|
---|
47 | **
|
---|
48 | ** 5) The warning status "dubious year" flags UTCs that predate the
|
---|
49 | ** introduction of the time scale or that are too far in the future
|
---|
50 | ** to be trusted. See eraDat for further details.
|
---|
51 | **
|
---|
52 | ** Called:
|
---|
53 | ** eraJd2cal JD to Gregorian calendar
|
---|
54 | ** eraDat delta(AT) = TAI-UTC
|
---|
55 | ** eraCal2jd Gregorian calendar to JD
|
---|
56 | **
|
---|
57 | ** References:
|
---|
58 | **
|
---|
59 | ** McCarthy, D. D., Petit, G. (eds.), IERS Conventions (2003),
|
---|
60 | ** IERS Technical Note No. 32, BKG (2004)
|
---|
61 | **
|
---|
62 | ** Explanatory Supplement to the Astronomical Almanac,
|
---|
63 | ** P. Kenneth Seidelmann (ed), University Science Books (1992)
|
---|
64 | **
|
---|
65 | ** Copyright (C) 2013-2015, NumFOCUS Foundation.
|
---|
66 | ** Derived, with permission, from the SOFA library. See notes at end of file.
|
---|
67 | */
|
---|
68 | {
|
---|
69 | int big1;
|
---|
70 | int i, iy, im, id, js;
|
---|
71 | double duts, u1, u2, d1, dats1, d2, fd, dats2, ddats, us1, us2, du;
|
---|
72 |
|
---|
73 | /* UT1-UTC in seconds. */
|
---|
74 | duts = dut1;
|
---|
75 |
|
---|
76 | /* Put the two parts of the UT1 into big-first order. */
|
---|
77 | big1 = ( ut11 >= ut12 );
|
---|
78 | if ( big1 ) {
|
---|
79 | u1 = ut11;
|
---|
80 | u2 = ut12;
|
---|
81 | } else {
|
---|
82 | u1 = ut12;
|
---|
83 | u2 = ut11;
|
---|
84 | }
|
---|
85 |
|
---|
86 | /* See if the UT1 can possibly be in a leap-second day. */
|
---|
87 | d1 = u1;
|
---|
88 | dats1 = 0;
|
---|
89 | for ( i = -1; i <= 3; i++ ) {
|
---|
90 | d2 = u2 + (double) i;
|
---|
91 | if ( eraJd2cal(d1, d2, &iy, &im, &id, &fd) ) return -1;
|
---|
92 | js = eraDat(iy, im, id, 0.0, &dats2);
|
---|
93 | if ( js < 0 ) return -1;
|
---|
94 | if ( i == - 1 ) dats1 = dats2;
|
---|
95 | ddats = dats2 - dats1;
|
---|
96 | if ( fabs(ddats) >= 0.5 ) {
|
---|
97 |
|
---|
98 | /* Yes, leap second nearby: ensure UT1-UTC is "before" value. */
|
---|
99 | if ( ddats * duts >= 0 ) duts -= ddats;
|
---|
100 |
|
---|
101 | /* UT1 for the start of the UTC day that ends in a leap. */
|
---|
102 | if ( eraCal2jd(iy, im, id, &d1, &d2) ) return -1;
|
---|
103 | us1 = d1;
|
---|
104 | us2 = d2 - 1.0 + duts/ERFA_DAYSEC;
|
---|
105 |
|
---|
106 | /* Is the UT1 after this point? */
|
---|
107 | du = u1 - us1;
|
---|
108 | du += u2 - us2;
|
---|
109 | if ( du > 0 ) {
|
---|
110 |
|
---|
111 | /* Yes: fraction of the current UTC day that has elapsed. */
|
---|
112 | fd = du * ERFA_DAYSEC / ( ERFA_DAYSEC + ddats );
|
---|
113 |
|
---|
114 | /* Ramp UT1-UTC to bring about ERFA's JD(UTC) convention. */
|
---|
115 | duts += ddats * ( fd <= 1.0 ? fd : 1.0 );
|
---|
116 | }
|
---|
117 |
|
---|
118 | /* Done. */
|
---|
119 | break;
|
---|
120 | }
|
---|
121 | dats1 = dats2;
|
---|
122 | }
|
---|
123 |
|
---|
124 | /* Subtract the (possibly adjusted) UT1-UTC from UT1 to give UTC. */
|
---|
125 | u2 -= duts / ERFA_DAYSEC;
|
---|
126 |
|
---|
127 | /* Result, safeguarding precision. */
|
---|
128 | if ( big1 ) {
|
---|
129 | *utc1 = u1;
|
---|
130 | *utc2 = u2;
|
---|
131 | } else {
|
---|
132 | *utc1 = u2;
|
---|
133 | *utc2 = u1;
|
---|
134 | }
|
---|
135 |
|
---|
136 | /* Status. */
|
---|
137 | return js;
|
---|
138 |
|
---|
139 | }
|
---|
140 | /*----------------------------------------------------------------------
|
---|
141 | **
|
---|
142 | **
|
---|
143 | ** Copyright (C) 2013-2015, NumFOCUS Foundation.
|
---|
144 | ** All rights reserved.
|
---|
145 | **
|
---|
146 | ** This library is derived, with permission, from the International
|
---|
147 | ** Astronomical Union's "Standards of Fundamental Astronomy" library,
|
---|
148 | ** available from http://www.iausofa.org.
|
---|
149 | **
|
---|
150 | ** The ERFA version is intended to retain identical functionality to
|
---|
151 | ** the SOFA library, but made distinct through different function and
|
---|
152 | ** file names, as set out in the SOFA license conditions. The SOFA
|
---|
153 | ** original has a role as a reference standard for the IAU and IERS,
|
---|
154 | ** and consequently redistribution is permitted only in its unaltered
|
---|
155 | ** state. The ERFA version is not subject to this restriction and
|
---|
156 | ** therefore can be included in distributions which do not support the
|
---|
157 | ** concept of "read only" software.
|
---|
158 | **
|
---|
159 | ** Although the intent is to replicate the SOFA API (other than
|
---|
160 | ** replacement of prefix names) and results (with the exception of
|
---|
161 | ** bugs; any that are discovered will be fixed), SOFA is not
|
---|
162 | ** responsible for any errors found in this version of the library.
|
---|
163 | **
|
---|
164 | ** If you wish to acknowledge the SOFA heritage, please acknowledge
|
---|
165 | ** that you are using a library derived from SOFA, rather than SOFA
|
---|
166 | ** itself.
|
---|
167 | **
|
---|
168 | **
|
---|
169 | ** TERMS AND CONDITIONS
|
---|
170 | **
|
---|
171 | ** Redistribution and use in source and binary forms, with or without
|
---|
172 | ** modification, are permitted provided that the following conditions
|
---|
173 | ** are met:
|
---|
174 | **
|
---|
175 | ** 1 Redistributions of source code must retain the above copyright
|
---|
176 | ** notice, this list of conditions and the following disclaimer.
|
---|
177 | **
|
---|
178 | ** 2 Redistributions in binary form must reproduce the above copyright
|
---|
179 | ** notice, this list of conditions and the following disclaimer in
|
---|
180 | ** the documentation and/or other materials provided with the
|
---|
181 | ** distribution.
|
---|
182 | **
|
---|
183 | ** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
|
---|
184 | ** the International Astronomical Union nor the names of its
|
---|
185 | ** contributors may be used to endorse or promote products derived
|
---|
186 | ** from this software without specific prior written permission.
|
---|
187 | **
|
---|
188 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
189 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
190 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
---|
191 | ** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
---|
192 | ** COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
193 | ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
---|
194 | ** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
195 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
---|
196 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
197 | ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
---|
198 | ** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
---|
199 | ** POSSIBILITY OF SUCH DAMAGE.
|
---|
200 | **
|
---|
201 | */
|
---|