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

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