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