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

Last change on this file since 18365 was 18346, checked in by tbretz, 10 years ago
File size: 12.8 KB
Line 
1#include "sofa.h"
2
3int iauDat(int iy, int im, int id, double fd, double *deltat )
4/*
5** - - - - - - -
6** i a u D a t
7** - - - - - - -
8**
9** For a given UTC date, calculate delta(AT) = TAI-UTC.
10**
11** :------------------------------------------:
12** : :
13** : IMPORTANT :
14** : :
15** : A new version of this function must be :
16** : produced whenever a new leap second is :
17** : announced. There are four items to :
18** : change on each such occasion: :
19** : :
20** : 1) A new line must be added to the set :
21** : of statements that initialize the :
22** : array "changes". :
23** : :
24** : 2) The constant IYV must be set to the :
25** : current year. :
26** : :
27** : 3) The "Latest leap second" comment :
28** : below must be set to the new leap :
29** : second date. :
30** : :
31** : 4) The "This revision" comment, later, :
32** : must be set to the current date. :
33** : :
34** : Change (2) must also be carried out :
35** : whenever the function is re-issued, :
36** : even if no leap seconds have been :
37** : added. :
38** : :
39** : Latest leap second: 2015 June 30 :
40** : :
41** :__________________________________________:
42**
43** This function is part of the International Astronomical Union's
44** SOFA (Standards Of Fundamental Astronomy) software collection.
45**
46** Status: support function.
47**
48** Given:
49** iy int UTC: year (Notes 1 and 2)
50** im int month (Note 2)
51** id int day (Notes 2 and 3)
52** fd double fraction of day (Note 4)
53**
54** Returned:
55** deltat double TAI minus UTC, seconds
56**
57** Returned (function value):
58** int status (Note 5):
59** 1 = dubious year (Note 1)
60** 0 = OK
61** -1 = bad year
62** -2 = bad month
63** -3 = bad day (Note 3)
64** -4 = bad fraction (Note 4)
65** -5 = internal error (Note 5)
66**
67** Notes:
68**
69** 1) UTC began at 1960 January 1.0 (JD 2436934.5) and it is improper
70** to call the function with an earlier date. If this is attempted,
71** zero is returned together with a warning status.
72**
73** Because leap seconds cannot, in principle, be predicted in
74** advance, a reliable check for dates beyond the valid range is
75** impossible. To guard against gross errors, a year five or more
76** after the release year of the present function (see the constant
77** IYV) is considered dubious. In this case a warning status is
78** returned but the result is computed in the normal way.
79**
80** For both too-early and too-late years, the warning status is +1.
81** This is distinct from the error status -1, which signifies a year
82** so early that JD could not be computed.
83**
84** 2) If the specified date is for a day which ends with a leap second,
85** the UTC-TAI value returned is for the period leading up to the
86** leap second. If the date is for a day which begins as a leap
87** second ends, the UTC-TAI returned is for the period following the
88** leap second.
89**
90** 3) The day number must be in the normal calendar range, for example
91** 1 through 30 for April. The "almanac" convention of allowing
92** such dates as January 0 and December 32 is not supported in this
93** function, in order to avoid confusion near leap seconds.
94**
95** 4) The fraction of day is used only for dates before the
96** introduction of leap seconds, the first of which occurred at the
97** end of 1971. It is tested for validity (0 to 1 is the valid
98** range) even if not used; if invalid, zero is used and status -4
99** is returned. For many applications, setting fd to zero is
100** acceptable; the resulting error is always less than 3 ms (and
101** occurs only pre-1972).
102**
103** 5) The status value returned in the case where there are multiple
104** errors refers to the first error detected. For example, if the
105** month and day are 13 and 32 respectively, status -2 (bad month)
106** will be returned. The "internal error" status refers to a
107** case that is impossible but causes some compilers to issue a
108** warning.
109**
110** 6) In cases where a valid result is not available, zero is returned.
111**
112** References:
113**
114** 1) For dates from 1961 January 1 onwards, the expressions from the
115** file ftp://maia.usno.navy.mil/ser7/tai-utc.dat are used.
116**
117** 2) The 5ms timestep at 1961 January 1 is taken from 2.58.1 (p87) of
118** the 1992 Explanatory Supplement.
119**
120** Called:
121** iauCal2jd Gregorian calendar to JD
122**
123** This revision: 2015 February 27
124**
125** SOFA release 2015-02-09
126**
127** Copyright (C) 2015 IAU SOFA Board. See notes at end.
128*/
129{
130/* Release year for this version of iauDat */
131 enum { IYV = 2015};
132
133/* Reference dates (MJD) and drift rates (s/day), pre leap seconds */
134 static const double drift[][2] = {
135 { 37300.0, 0.0012960 },
136 { 37300.0, 0.0012960 },
137 { 37300.0, 0.0012960 },
138 { 37665.0, 0.0011232 },
139 { 37665.0, 0.0011232 },
140 { 38761.0, 0.0012960 },
141 { 38761.0, 0.0012960 },
142 { 38761.0, 0.0012960 },
143 { 38761.0, 0.0012960 },
144 { 38761.0, 0.0012960 },
145 { 38761.0, 0.0012960 },
146 { 38761.0, 0.0012960 },
147 { 39126.0, 0.0025920 },
148 { 39126.0, 0.0025920 }
149 };
150
151/* Number of Delta(AT) expressions before leap seconds were introduced */
152 enum { NERA1 = (int) (sizeof drift / sizeof (double) / 2) };
153
154/* Dates and Delta(AT)s */
155 static const struct {
156 int iyear, month;
157 double delat;
158 } changes[] = {
159 { 1960, 1, 1.4178180 },
160 { 1961, 1, 1.4228180 },
161 { 1961, 8, 1.3728180 },
162 { 1962, 1, 1.8458580 },
163 { 1963, 11, 1.9458580 },
164 { 1964, 1, 3.2401300 },
165 { 1964, 4, 3.3401300 },
166 { 1964, 9, 3.4401300 },
167 { 1965, 1, 3.5401300 },
168 { 1965, 3, 3.6401300 },
169 { 1965, 7, 3.7401300 },
170 { 1965, 9, 3.8401300 },
171 { 1966, 1, 4.3131700 },
172 { 1968, 2, 4.2131700 },
173 { 1972, 1, 10.0 },
174 { 1972, 7, 11.0 },
175 { 1973, 1, 12.0 },
176 { 1974, 1, 13.0 },
177 { 1975, 1, 14.0 },
178 { 1976, 1, 15.0 },
179 { 1977, 1, 16.0 },
180 { 1978, 1, 17.0 },
181 { 1979, 1, 18.0 },
182 { 1980, 1, 19.0 },
183 { 1981, 7, 20.0 },
184 { 1982, 7, 21.0 },
185 { 1983, 7, 22.0 },
186 { 1985, 7, 23.0 },
187 { 1988, 1, 24.0 },
188 { 1990, 1, 25.0 },
189 { 1991, 1, 26.0 },
190 { 1992, 7, 27.0 },
191 { 1993, 7, 28.0 },
192 { 1994, 7, 29.0 },
193 { 1996, 1, 30.0 },
194 { 1997, 7, 31.0 },
195 { 1999, 1, 32.0 },
196 { 2006, 1, 33.0 },
197 { 2009, 1, 34.0 },
198 { 2012, 7, 35.0 },
199 { 2015, 7, 36.0 }
200 };
201
202/* Number of Delta(AT) changes */
203 enum { NDAT = (int) (sizeof changes / sizeof changes[0]) };
204
205/* Miscellaneous local variables */
206 int j, i, m;
207 double da, djm0, djm;
208
209
210/* Initialize the result to zero. */
211 *deltat = da = 0.0;
212
213/* If invalid fraction of a day, set error status and give up. */
214 if (fd < 0.0 || fd > 1.0) return -4;
215
216/* Convert the date into an MJD. */
217 j = iauCal2jd(iy, im, id, &djm0, &djm);
218
219/* If invalid year, month, or day, give up. */
220 if (j < 0) return j;
221
222/* If pre-UTC year, set warning status and give up. */
223 if (iy < changes[0].iyear) return 1;
224
225/* If suspiciously late year, set warning status but proceed. */
226 if (iy > IYV + 5) j = 1;
227
228/* Combine year and month to form a date-ordered integer... */
229 m = 12*iy + im;
230
231/* ...and use it to find the preceding table entry. */
232 for (i = NDAT-1; i >=0; i--) {
233 if (m >= (12 * changes[i].iyear + changes[i].month)) break;
234 }
235
236/* Prevent underflow warnings. */
237 if (i < 0) return -5;
238
239/* Get the Delta(AT). */
240 da = changes[i].delat;
241
242/* If pre-1972, adjust for drift. */
243 if (i < NERA1) da += (djm + fd - drift[i][0]) * drift[i][1];
244
245/* Return the Delta(AT) value. */
246 *deltat = da;
247
248/* Return the status. */
249 return j;
250
251/*----------------------------------------------------------------------
252**
253** Copyright (C) 2015
254** Standards Of Fundamental Astronomy Board
255** of the International Astronomical Union.
256**
257** =====================
258** SOFA Software License
259** =====================
260**
261** NOTICE TO USER:
262**
263** BY USING THIS SOFTWARE YOU ACCEPT THE FOLLOWING SIX TERMS AND
264** CONDITIONS WHICH APPLY TO ITS USE.
265**
266** 1. The Software is owned by the IAU SOFA Board ("SOFA").
267**
268** 2. Permission is granted to anyone to use the SOFA software for any
269** purpose, including commercial applications, free of charge and
270** without payment of royalties, subject to the conditions and
271** restrictions listed below.
272**
273** 3. You (the user) may copy and distribute SOFA source code to others,
274** and use and adapt its code and algorithms in your own software,
275** on a world-wide, royalty-free basis. That portion of your
276** distribution that does not consist of intact and unchanged copies
277** of SOFA source code files is a "derived work" that must comply
278** with the following requirements:
279**
280** a) Your work shall be marked or carry a statement that it
281** (i) uses routines and computations derived by you from
282** software provided by SOFA under license to you; and
283** (ii) does not itself constitute software provided by and/or
284** endorsed by SOFA.
285**
286** b) The source code of your derived work must contain descriptions
287** of how the derived work is based upon, contains and/or differs
288** from the original SOFA software.
289**
290** c) The names of all routines in your derived work shall not
291** include the prefix "iau" or "sofa" or trivial modifications
292** thereof such as changes of case.
293**
294** d) The origin of the SOFA components of your derived work must
295** not be misrepresented; you must not claim that you wrote the
296** original software, nor file a patent application for SOFA
297** software or algorithms embedded in the SOFA software.
298**
299** e) These requirements must be reproduced intact in any source
300** distribution and shall apply to anyone to whom you have
301** granted a further right to modify the source code of your
302** derived work.
303**
304** Note that, as originally distributed, the SOFA software is
305** intended to be a definitive implementation of the IAU standards,
306** and consequently third-party modifications are discouraged. All
307** variations, no matter how minor, must be explicitly marked as
308** such, as explained above.
309**
310** 4. You shall not cause the SOFA software to be brought into
311** disrepute, either by misuse, or use for inappropriate tasks, or
312** by inappropriate modification.
313**
314** 5. The SOFA software is provided "as is" and SOFA makes no warranty
315** as to its use or performance. SOFA does not and cannot warrant
316** the performance or results which the user may obtain by using the
317** SOFA software. SOFA makes no warranties, express or implied, as
318** to non-infringement of third party rights, merchantability, or
319** fitness for any particular purpose. In no event will SOFA be
320** liable to the user for any consequential, incidental, or special
321** damages, including any lost profits or lost savings, even if a
322** SOFA representative has been advised of such damages, or for any
323** claim by any third party.
324**
325** 6. The provision of any version of the SOFA software under the terms
326** and conditions specified herein does not imply that future
327** versions will also be made available under the same terms and
328** conditions.
329*
330** In any published work or commercial product which uses the SOFA
331** software directly, acknowledgement (see www.iausofa.org) is
332** appreciated.
333**
334** Correspondence concerning SOFA software should be addressed as
335** follows:
336**
337** By email: sofa@ukho.gov.uk
338** By post: IAU SOFA Center
339** HM Nautical Almanac Office
340** UK Hydrographic Office
341** Admiralty Way, Taunton
342** Somerset, TA1 2DN
343** United Kingdom
344**
345**--------------------------------------------------------------------*/
346}
Note: See TracBrowser for help on using the repository browser.