source: trunk/FACT++/erfa/src/ut1utc.c@ 19536

Last change on this file since 19536 was 18921, checked in by tbretz, 7 years ago
Updated to ERFA 1.4.0
File size: 7.2 KB
Line 
1#include "erfa.h"
2
3int 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-2017, 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
74/* UT1-UTC in seconds. */
75 duts = dut1;
76
77/* Put the two parts of the UT1 into big-first order. */
78 big1 = ( ut11 >= ut12 );
79 if ( big1 ) {
80 u1 = ut11;
81 u2 = ut12;
82 } else {
83 u1 = ut12;
84 u2 = ut11;
85 }
86
87/* See if the UT1 can possibly be in a leap-second day. */
88 d1 = u1;
89 dats1 = 0;
90 for ( i = -1; i <= 3; i++ ) {
91 d2 = u2 + (double) i;
92 if ( eraJd2cal(d1, d2, &iy, &im, &id, &fd) ) return -1;
93 js = eraDat(iy, im, id, 0.0, &dats2);
94 if ( js < 0 ) return -1;
95 if ( i == - 1 ) dats1 = dats2;
96 ddats = dats2 - dats1;
97 if ( fabs(ddats) >= 0.5 ) {
98
99 /* Yes, leap second nearby: ensure UT1-UTC is "before" value. */
100 if ( ddats * duts >= 0 ) duts -= ddats;
101
102 /* UT1 for the start of the UTC day that ends in a leap. */
103 if ( eraCal2jd(iy, im, id, &d1, &d2) ) return -1;
104 us1 = d1;
105 us2 = d2 - 1.0 + duts/ERFA_DAYSEC;
106
107 /* Is the UT1 after this point? */
108 du = u1 - us1;
109 du += u2 - us2;
110 if ( du > 0 ) {
111
112 /* Yes: fraction of the current UTC day that has elapsed. */
113 fd = du * ERFA_DAYSEC / ( ERFA_DAYSEC + ddats );
114
115 /* Ramp UT1-UTC to bring about ERFA's JD(UTC) convention. */
116 duts += ddats * ( fd <= 1.0 ? fd : 1.0 );
117 }
118
119 /* Done. */
120 break;
121 }
122 dats1 = dats2;
123 }
124
125/* Subtract the (possibly adjusted) UT1-UTC from UT1 to give UTC. */
126 u2 -= duts / ERFA_DAYSEC;
127
128/* Result, safeguarding precision. */
129 if ( big1 ) {
130 *utc1 = u1;
131 *utc2 = u2;
132 } else {
133 *utc1 = u2;
134 *utc2 = u1;
135 }
136
137/* Status. */
138 return js;
139
140}
141/*----------------------------------------------------------------------
142**
143**
144** Copyright (C) 2013-2017, NumFOCUS Foundation.
145** All rights reserved.
146**
147** This library is derived, with permission, from the International
148** Astronomical Union's "Standards of Fundamental Astronomy" library,
149** available from http://www.iausofa.org.
150**
151** The ERFA version is intended to retain identical functionality to
152** the SOFA library, but made distinct through different function and
153** file names, as set out in the SOFA license conditions. The SOFA
154** original has a role as a reference standard for the IAU and IERS,
155** and consequently redistribution is permitted only in its unaltered
156** state. The ERFA version is not subject to this restriction and
157** therefore can be included in distributions which do not support the
158** concept of "read only" software.
159**
160** Although the intent is to replicate the SOFA API (other than
161** replacement of prefix names) and results (with the exception of
162** bugs; any that are discovered will be fixed), SOFA is not
163** responsible for any errors found in this version of the library.
164**
165** If you wish to acknowledge the SOFA heritage, please acknowledge
166** that you are using a library derived from SOFA, rather than SOFA
167** itself.
168**
169**
170** TERMS AND CONDITIONS
171**
172** Redistribution and use in source and binary forms, with or without
173** modification, are permitted provided that the following conditions
174** are met:
175**
176** 1 Redistributions of source code must retain the above copyright
177** notice, this list of conditions and the following disclaimer.
178**
179** 2 Redistributions in binary form must reproduce the above copyright
180** notice, this list of conditions and the following disclaimer in
181** the documentation and/or other materials provided with the
182** distribution.
183**
184** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
185** the International Astronomical Union nor the names of its
186** contributors may be used to endorse or promote products derived
187** from this software without specific prior written permission.
188**
189** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
190** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
191** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
192** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
193** COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
194** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
195** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
196** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
197** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
198** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
199** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
200** POSSIBILITY OF SUCH DAMAGE.
201**
202*/
Note: See TracBrowser for help on using the repository browser.