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