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

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