source: trunk/FACT++/sofa/src/taiutc.c@ 18365

Last change on this file since 18365 was 18346, checked in by tbretz, 10 years ago
File size: 7.3 KB
Line 
1#include "sofa.h"
2
3int iauTaiutc(double tai1, double tai2, double *utc1, double *utc2)
4/*
5** - - - - - - - - - -
6** i a u T a i u t c
7** - - - - - - - - - -
8**
9** Time scale transformation: International Atomic Time, TAI, to
10** Coordinated Universal Time, UTC.
11**
12** This function is part of the International Astronomical Union's
13** SOFA (Standards of Fundamental Astronomy) software collection.
14**
15** Status: canonical.
16**
17** Given:
18** tai1,tai2 double TAI as a 2-part Julian Date (Note 1)
19**
20** Returned:
21** utc1,utc2 double UTC as a 2-part quasi Julian Date (Notes 1-3)
22**
23** Returned (function value):
24** int status: +1 = dubious year (Note 4)
25** 0 = OK
26** -1 = unacceptable date
27**
28** Notes:
29**
30** 1) tai1+tai2 is Julian Date, apportioned in any convenient way
31** between the two arguments, for example where tai1 is the Julian
32** Day Number and tai2 is the fraction of a day. The returned utc1
33** and utc2 form an analogous pair, except that a special convention
34** is used, to deal with the problem of leap seconds - see the next
35** note.
36**
37** 2) JD cannot unambiguously represent UTC during a leap second unless
38** special measures are taken. The convention in the present
39** function is that the JD day represents UTC days whether the
40** length is 86399, 86400 or 86401 SI seconds. In the 1960-1972 era
41** there were smaller jumps (in either direction) each time the
42** linear UTC(TAI) expression was changed, and these "mini-leaps"
43** are also included in the SOFA convention.
44**
45** 3) The function iauD2dtf can be used to transform the UTC quasi-JD
46** into calendar date and clock time, including UTC leap second
47** handling.
48**
49** 4) The warning status "dubious year" flags UTCs that predate the
50** introduction of the time scale or that are too far in the future
51** to be trusted. See iauDat for further details.
52**
53** Called:
54** iauUtctai UTC to TAI
55**
56** References:
57**
58** McCarthy, D. D., Petit, G. (eds.), IERS Conventions (2003),
59** IERS Technical Note No. 32, BKG (2004)
60**
61** Explanatory Supplement to the Astronomical Almanac,
62** P. Kenneth Seidelmann (ed), University Science Books (1992)
63**
64** This revision: 2013 September 12
65**
66** SOFA release 2015-02-09
67**
68** Copyright (C) 2015 IAU SOFA Board. See notes at end.
69*/
70{
71 int big1;
72 int i, j;
73 double a1, a2, u1, u2, g1, g2;
74
75/* Put the two parts of the TAI into big-first order. */
76 big1 = ( tai1 >= tai2 );
77 if ( big1 ) {
78 a1 = tai1;
79 a2 = tai2;
80 } else {
81 a1 = tai2;
82 a2 = tai1;
83 }
84
85/* Initial guess for UTC. */
86 u1 = a1;
87 u2 = a2;
88
89/* Iterate (though in most cases just once is enough). */
90 for ( i = 0; i < 3; i++ ) {
91
92 /* Guessed UTC to TAI. */
93 j = iauUtctai(u1, u2, &g1, &g2);
94 if ( j < 0 ) return j;
95
96 /* Adjust guessed UTC. */
97 u2 += a1 - g1;
98 u2 += a2 - g2;
99 }
100
101/* Return the UTC result, preserving the TAI order. */
102 if ( big1 ) {
103 *utc1 = u1;
104 *utc2 = u2;
105 } else {
106 *utc1 = u2;
107 *utc2 = u1;
108 }
109
110/* Status. */
111 return j;
112
113/*----------------------------------------------------------------------
114**
115** Copyright (C) 2015
116** Standards Of Fundamental Astronomy Board
117** of the International Astronomical Union.
118**
119** =====================
120** SOFA Software License
121** =====================
122**
123** NOTICE TO USER:
124**
125** BY USING THIS SOFTWARE YOU ACCEPT THE FOLLOWING SIX TERMS AND
126** CONDITIONS WHICH APPLY TO ITS USE.
127**
128** 1. The Software is owned by the IAU SOFA Board ("SOFA").
129**
130** 2. Permission is granted to anyone to use the SOFA software for any
131** purpose, including commercial applications, free of charge and
132** without payment of royalties, subject to the conditions and
133** restrictions listed below.
134**
135** 3. You (the user) may copy and distribute SOFA source code to others,
136** and use and adapt its code and algorithms in your own software,
137** on a world-wide, royalty-free basis. That portion of your
138** distribution that does not consist of intact and unchanged copies
139** of SOFA source code files is a "derived work" that must comply
140** with the following requirements:
141**
142** a) Your work shall be marked or carry a statement that it
143** (i) uses routines and computations derived by you from
144** software provided by SOFA under license to you; and
145** (ii) does not itself constitute software provided by and/or
146** endorsed by SOFA.
147**
148** b) The source code of your derived work must contain descriptions
149** of how the derived work is based upon, contains and/or differs
150** from the original SOFA software.
151**
152** c) The names of all routines in your derived work shall not
153** include the prefix "iau" or "sofa" or trivial modifications
154** thereof such as changes of case.
155**
156** d) The origin of the SOFA components of your derived work must
157** not be misrepresented; you must not claim that you wrote the
158** original software, nor file a patent application for SOFA
159** software or algorithms embedded in the SOFA software.
160**
161** e) These requirements must be reproduced intact in any source
162** distribution and shall apply to anyone to whom you have
163** granted a further right to modify the source code of your
164** derived work.
165**
166** Note that, as originally distributed, the SOFA software is
167** intended to be a definitive implementation of the IAU standards,
168** and consequently third-party modifications are discouraged. All
169** variations, no matter how minor, must be explicitly marked as
170** such, as explained above.
171**
172** 4. You shall not cause the SOFA software to be brought into
173** disrepute, either by misuse, or use for inappropriate tasks, or
174** by inappropriate modification.
175**
176** 5. The SOFA software is provided "as is" and SOFA makes no warranty
177** as to its use or performance. SOFA does not and cannot warrant
178** the performance or results which the user may obtain by using the
179** SOFA software. SOFA makes no warranties, express or implied, as
180** to non-infringement of third party rights, merchantability, or
181** fitness for any particular purpose. In no event will SOFA be
182** liable to the user for any consequential, incidental, or special
183** damages, including any lost profits or lost savings, even if a
184** SOFA representative has been advised of such damages, or for any
185** claim by any third party.
186**
187** 6. The provision of any version of the SOFA software under the terms
188** and conditions specified herein does not imply that future
189** versions will also be made available under the same terms and
190** conditions.
191*
192** In any published work or commercial product which uses the SOFA
193** software directly, acknowledgement (see www.iausofa.org) is
194** appreciated.
195**
196** Correspondence concerning SOFA software should be addressed as
197** follows:
198**
199** By email: sofa@ukho.gov.uk
200** By post: IAU SOFA Center
201** HM Nautical Almanac Office
202** UK Hydrographic Office
203** Admiralty Way, Taunton
204** Somerset, TA1 2DN
205** United Kingdom
206**
207**--------------------------------------------------------------------*/
208}
Note: See TracBrowser for help on using the repository browser.