source: trunk/FACT++/erfa/src/taiutc.c@ 18679

Last change on this file since 18679 was 18348, checked in by tbretz, 9 years ago
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-2015, 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/* Put the two parts of the TAI into big-first order. */
68 big1 = ( tai1 >= tai2 );
69 if ( big1 ) {
70 a1 = tai1;
71 a2 = tai2;
72 } else {
73 a1 = tai2;
74 a2 = tai1;
75 }
76
77/* Initial guess for UTC. */
78 u1 = a1;
79 u2 = a2;
80
81/* Iterate (though in most cases just once is enough). */
82 for ( i = 0; i < 3; i++ ) {
83
84 /* Guessed UTC to TAI. */
85 j = eraUtctai(u1, u2, &g1, &g2);
86 if ( j < 0 ) return j;
87
88 /* Adjust guessed UTC. */
89 u2 += a1 - g1;
90 u2 += a2 - g2;
91 }
92
93/* Return the UTC result, preserving the TAI order. */
94 if ( big1 ) {
95 *utc1 = u1;
96 *utc2 = u2;
97 } else {
98 *utc1 = u2;
99 *utc2 = u1;
100 }
101
102/* Status. */
103 return j;
104
105}
106/*----------------------------------------------------------------------
107**
108**
109** Copyright (C) 2013-2015, NumFOCUS Foundation.
110** All rights reserved.
111**
112** This library is derived, with permission, from the International
113** Astronomical Union's "Standards of Fundamental Astronomy" library,
114** available from http://www.iausofa.org.
115**
116** The ERFA version is intended to retain identical functionality to
117** the SOFA library, but made distinct through different function and
118** file names, as set out in the SOFA license conditions. The SOFA
119** original has a role as a reference standard for the IAU and IERS,
120** and consequently redistribution is permitted only in its unaltered
121** state. The ERFA version is not subject to this restriction and
122** therefore can be included in distributions which do not support the
123** concept of "read only" software.
124**
125** Although the intent is to replicate the SOFA API (other than
126** replacement of prefix names) and results (with the exception of
127** bugs; any that are discovered will be fixed), SOFA is not
128** responsible for any errors found in this version of the library.
129**
130** If you wish to acknowledge the SOFA heritage, please acknowledge
131** that you are using a library derived from SOFA, rather than SOFA
132** itself.
133**
134**
135** TERMS AND CONDITIONS
136**
137** Redistribution and use in source and binary forms, with or without
138** modification, are permitted provided that the following conditions
139** are met:
140**
141** 1 Redistributions of source code must retain the above copyright
142** notice, this list of conditions and the following disclaimer.
143**
144** 2 Redistributions in binary form must reproduce the above copyright
145** notice, this list of conditions and the following disclaimer in
146** the documentation and/or other materials provided with the
147** distribution.
148**
149** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
150** the International Astronomical Union nor the names of its
151** contributors may be used to endorse or promote products derived
152** from this software without specific prior written permission.
153**
154** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
155** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
156** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
157** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
158** COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
159** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
160** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
161** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
162** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
163** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
164** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
165** POSSIBILITY OF SUCH DAMAGE.
166**
167*/
Note: See TracBrowser for help on using the repository browser.