| 1 | #include "sofa.h"
|
|---|
| 2 | #include <string.h>
|
|---|
| 3 |
|
|---|
| 4 | int iauDtf2d(const char *scale, int iy, int im, int id,
|
|---|
| 5 | int ihr, int imn, double sec, double *d1, double *d2)
|
|---|
| 6 | /*
|
|---|
| 7 | ** - - - - - - - - -
|
|---|
| 8 | ** i a u D t f 2 d
|
|---|
| 9 | ** - - - - - - - - -
|
|---|
| 10 | **
|
|---|
| 11 | ** Encode date and time fields into 2-part Julian Date (or in the case
|
|---|
| 12 | ** of UTC a quasi-JD form that includes special provision for leap
|
|---|
| 13 | ** seconds).
|
|---|
| 14 | **
|
|---|
| 15 | ** This function is part of the International Astronomical Union's
|
|---|
| 16 | ** SOFA (Standards of Fundamental Astronomy) software collection.
|
|---|
| 17 | **
|
|---|
| 18 | ** Status: support function.
|
|---|
| 19 | **
|
|---|
| 20 | ** Given:
|
|---|
| 21 | ** scale char[] time scale ID (Note 1)
|
|---|
| 22 | ** iy,im,id int year, month, day in Gregorian calendar (Note 2)
|
|---|
| 23 | ** ihr,imn int hour, minute
|
|---|
| 24 | ** sec double seconds
|
|---|
| 25 | **
|
|---|
| 26 | ** Returned:
|
|---|
| 27 | ** d1,d2 double 2-part Julian Date (Notes 3,4)
|
|---|
| 28 | **
|
|---|
| 29 | ** Returned (function value):
|
|---|
| 30 | ** int status: +3 = both of next two
|
|---|
| 31 | ** +2 = time is after end of day (Note 5)
|
|---|
| 32 | ** +1 = dubious year (Note 6)
|
|---|
| 33 | ** 0 = OK
|
|---|
| 34 | ** -1 = bad year
|
|---|
| 35 | ** -2 = bad month
|
|---|
| 36 | ** -3 = bad day
|
|---|
| 37 | ** -4 = bad hour
|
|---|
| 38 | ** -5 = bad minute
|
|---|
| 39 | ** -6 = bad second (<0)
|
|---|
| 40 | **
|
|---|
| 41 | ** Notes:
|
|---|
| 42 | **
|
|---|
| 43 | ** 1) scale identifies the time scale. Only the value "UTC" (in upper
|
|---|
| 44 | ** case) is significant, and enables handling of leap seconds (see
|
|---|
| 45 | ** Note 4).
|
|---|
| 46 | **
|
|---|
| 47 | ** 2) For calendar conventions and limitations, see iauCal2jd.
|
|---|
| 48 | **
|
|---|
| 49 | ** 3) The sum of the results, d1+d2, is Julian Date, where normally d1
|
|---|
| 50 | ** is the Julian Day Number and d2 is the fraction of a day. In the
|
|---|
| 51 | ** case of UTC, where the use of JD is problematical, special
|
|---|
| 52 | ** conventions apply: see the next note.
|
|---|
| 53 | **
|
|---|
| 54 | ** 4) JD cannot unambiguously represent UTC during a leap second unless
|
|---|
| 55 | ** special measures are taken. The SOFA internal convention is that
|
|---|
| 56 | ** the quasi-JD day represents UTC days whether the length is 86399,
|
|---|
| 57 | ** 86400 or 86401 SI seconds. In the 1960-1972 era there were
|
|---|
| 58 | ** smaller jumps (in either direction) each time the linear UTC(TAI)
|
|---|
| 59 | ** expression was changed, and these "mini-leaps" are also included
|
|---|
| 60 | ** in the SOFA convention.
|
|---|
| 61 | **
|
|---|
| 62 | ** 5) The warning status "time is after end of day" usually means that
|
|---|
| 63 | ** the sec argument is greater than 60.0. However, in a day ending
|
|---|
| 64 | ** in a leap second the limit changes to 61.0 (or 59.0 in the case
|
|---|
| 65 | ** of a negative leap second).
|
|---|
| 66 | **
|
|---|
| 67 | ** 6) The warning status "dubious year" flags UTCs that predate the
|
|---|
| 68 | ** introduction of the time scale or that are too far in the future
|
|---|
| 69 | ** to be trusted. See iauDat for further details.
|
|---|
| 70 | **
|
|---|
| 71 | ** 7) Only in the case of continuous and regular time scales (TAI, TT,
|
|---|
| 72 | ** TCG, TCB and TDB) is the result d1+d2 a Julian Date, strictly
|
|---|
| 73 | ** speaking. In the other cases (UT1 and UTC) the result must be
|
|---|
| 74 | ** used with circumspection; in particular the difference between
|
|---|
| 75 | ** two such results cannot be interpreted as a precise time
|
|---|
| 76 | ** interval.
|
|---|
| 77 | **
|
|---|
| 78 | ** Called:
|
|---|
| 79 | ** iauCal2jd Gregorian calendar to JD
|
|---|
| 80 | ** iauDat delta(AT) = TAI-UTC
|
|---|
| 81 | ** iauJd2cal JD to Gregorian calendar
|
|---|
| 82 | **
|
|---|
| 83 | ** This revision: 2013 July 26
|
|---|
| 84 | **
|
|---|
| 85 | ** SOFA release 2015-02-09
|
|---|
| 86 | **
|
|---|
| 87 | ** Copyright (C) 2015 IAU SOFA Board. See notes at end.
|
|---|
| 88 | */
|
|---|
| 89 | {
|
|---|
| 90 | int js, iy2, im2, id2;
|
|---|
| 91 | double dj, w, day, seclim, dat0, dat12, dat24, dleap, time;
|
|---|
| 92 |
|
|---|
| 93 | /* Today's Julian Day Number. */
|
|---|
| 94 | js = iauCal2jd(iy, im, id, &dj, &w);
|
|---|
| 95 | if ( js ) return js;
|
|---|
| 96 | dj += w;
|
|---|
| 97 |
|
|---|
| 98 | /* Day length and final minute length in seconds (provisional). */
|
|---|
| 99 | day = DAYSEC;
|
|---|
| 100 | seclim = 60.0;
|
|---|
| 101 |
|
|---|
| 102 | /* Deal with the UTC leap second case. */
|
|---|
| 103 | if ( ! strcmp(scale,"UTC") ) {
|
|---|
| 104 |
|
|---|
| 105 | /* TAI-UTC at 0h today. */
|
|---|
| 106 | js = iauDat(iy, im, id, 0.0, &dat0);
|
|---|
| 107 | if ( js < 0 ) return js;
|
|---|
| 108 |
|
|---|
| 109 | /* TAI-UTC at 12h today (to detect drift). */
|
|---|
| 110 | js = iauDat(iy, im, id, 0.5, &dat12);
|
|---|
| 111 | if ( js < 0 ) return js;
|
|---|
| 112 |
|
|---|
| 113 | /* TAI-UTC at 0h tomorrow (to detect jumps). */
|
|---|
| 114 | js = iauJd2cal ( dj, 1.5, &iy2, &im2, &id2, &w);
|
|---|
| 115 | if ( js ) return js;
|
|---|
| 116 | js = iauDat(iy2, im2, id2, 0.0, &dat24);
|
|---|
| 117 | if ( js < 0 ) return js;
|
|---|
| 118 |
|
|---|
| 119 | /* Any sudden change in TAI-UTC between today and tomorrow. */
|
|---|
| 120 | dleap = dat24 - (2.0*dat12 - dat0);
|
|---|
| 121 |
|
|---|
| 122 | /* If leap second day, correct the day and final minute lengths. */
|
|---|
| 123 | day += dleap;
|
|---|
| 124 | if ( ihr == 23 && imn == 59 ) seclim += dleap;
|
|---|
| 125 |
|
|---|
| 126 | /* End of UTC-specific actions. */
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | /* Validate the time. */
|
|---|
| 130 | if ( ihr >= 0 && ihr <= 23 ) {
|
|---|
| 131 | if ( imn >= 0 && imn <= 59 ) {
|
|---|
| 132 | if ( sec >= 0 ) {
|
|---|
| 133 | if ( sec >= seclim ) {
|
|---|
| 134 | js += 2;
|
|---|
| 135 | }
|
|---|
| 136 | } else {
|
|---|
| 137 | js = -6;
|
|---|
| 138 | }
|
|---|
| 139 | } else {
|
|---|
| 140 | js = -5;
|
|---|
| 141 | }
|
|---|
| 142 | } else {
|
|---|
| 143 | js = -4;
|
|---|
| 144 | }
|
|---|
| 145 | if ( js < 0 ) return js;
|
|---|
| 146 |
|
|---|
| 147 | /* The time in days. */
|
|---|
| 148 | time = ( 60.0 * ( (double) ( 60 * ihr + imn ) ) + sec ) / day;
|
|---|
| 149 |
|
|---|
| 150 | /* Return the date and time. */
|
|---|
| 151 | *d1 = dj;
|
|---|
| 152 | *d2 = time;
|
|---|
| 153 |
|
|---|
| 154 | /* Status. */
|
|---|
| 155 | return js;
|
|---|
| 156 |
|
|---|
| 157 | /*----------------------------------------------------------------------
|
|---|
| 158 | **
|
|---|
| 159 | ** Copyright (C) 2015
|
|---|
| 160 | ** Standards Of Fundamental Astronomy Board
|
|---|
| 161 | ** of the International Astronomical Union.
|
|---|
| 162 | **
|
|---|
| 163 | ** =====================
|
|---|
| 164 | ** SOFA Software License
|
|---|
| 165 | ** =====================
|
|---|
| 166 | **
|
|---|
| 167 | ** NOTICE TO USER:
|
|---|
| 168 | **
|
|---|
| 169 | ** BY USING THIS SOFTWARE YOU ACCEPT THE FOLLOWING SIX TERMS AND
|
|---|
| 170 | ** CONDITIONS WHICH APPLY TO ITS USE.
|
|---|
| 171 | **
|
|---|
| 172 | ** 1. The Software is owned by the IAU SOFA Board ("SOFA").
|
|---|
| 173 | **
|
|---|
| 174 | ** 2. Permission is granted to anyone to use the SOFA software for any
|
|---|
| 175 | ** purpose, including commercial applications, free of charge and
|
|---|
| 176 | ** without payment of royalties, subject to the conditions and
|
|---|
| 177 | ** restrictions listed below.
|
|---|
| 178 | **
|
|---|
| 179 | ** 3. You (the user) may copy and distribute SOFA source code to others,
|
|---|
| 180 | ** and use and adapt its code and algorithms in your own software,
|
|---|
| 181 | ** on a world-wide, royalty-free basis. That portion of your
|
|---|
| 182 | ** distribution that does not consist of intact and unchanged copies
|
|---|
| 183 | ** of SOFA source code files is a "derived work" that must comply
|
|---|
| 184 | ** with the following requirements:
|
|---|
| 185 | **
|
|---|
| 186 | ** a) Your work shall be marked or carry a statement that it
|
|---|
| 187 | ** (i) uses routines and computations derived by you from
|
|---|
| 188 | ** software provided by SOFA under license to you; and
|
|---|
| 189 | ** (ii) does not itself constitute software provided by and/or
|
|---|
| 190 | ** endorsed by SOFA.
|
|---|
| 191 | **
|
|---|
| 192 | ** b) The source code of your derived work must contain descriptions
|
|---|
| 193 | ** of how the derived work is based upon, contains and/or differs
|
|---|
| 194 | ** from the original SOFA software.
|
|---|
| 195 | **
|
|---|
| 196 | ** c) The names of all routines in your derived work shall not
|
|---|
| 197 | ** include the prefix "iau" or "sofa" or trivial modifications
|
|---|
| 198 | ** thereof such as changes of case.
|
|---|
| 199 | **
|
|---|
| 200 | ** d) The origin of the SOFA components of your derived work must
|
|---|
| 201 | ** not be misrepresented; you must not claim that you wrote the
|
|---|
| 202 | ** original software, nor file a patent application for SOFA
|
|---|
| 203 | ** software or algorithms embedded in the SOFA software.
|
|---|
| 204 | **
|
|---|
| 205 | ** e) These requirements must be reproduced intact in any source
|
|---|
| 206 | ** distribution and shall apply to anyone to whom you have
|
|---|
| 207 | ** granted a further right to modify the source code of your
|
|---|
| 208 | ** derived work.
|
|---|
| 209 | **
|
|---|
| 210 | ** Note that, as originally distributed, the SOFA software is
|
|---|
| 211 | ** intended to be a definitive implementation of the IAU standards,
|
|---|
| 212 | ** and consequently third-party modifications are discouraged. All
|
|---|
| 213 | ** variations, no matter how minor, must be explicitly marked as
|
|---|
| 214 | ** such, as explained above.
|
|---|
| 215 | **
|
|---|
| 216 | ** 4. You shall not cause the SOFA software to be brought into
|
|---|
| 217 | ** disrepute, either by misuse, or use for inappropriate tasks, or
|
|---|
| 218 | ** by inappropriate modification.
|
|---|
| 219 | **
|
|---|
| 220 | ** 5. The SOFA software is provided "as is" and SOFA makes no warranty
|
|---|
| 221 | ** as to its use or performance. SOFA does not and cannot warrant
|
|---|
| 222 | ** the performance or results which the user may obtain by using the
|
|---|
| 223 | ** SOFA software. SOFA makes no warranties, express or implied, as
|
|---|
| 224 | ** to non-infringement of third party rights, merchantability, or
|
|---|
| 225 | ** fitness for any particular purpose. In no event will SOFA be
|
|---|
| 226 | ** liable to the user for any consequential, incidental, or special
|
|---|
| 227 | ** damages, including any lost profits or lost savings, even if a
|
|---|
| 228 | ** SOFA representative has been advised of such damages, or for any
|
|---|
| 229 | ** claim by any third party.
|
|---|
| 230 | **
|
|---|
| 231 | ** 6. The provision of any version of the SOFA software under the terms
|
|---|
| 232 | ** and conditions specified herein does not imply that future
|
|---|
| 233 | ** versions will also be made available under the same terms and
|
|---|
| 234 | ** conditions.
|
|---|
| 235 | *
|
|---|
| 236 | ** In any published work or commercial product which uses the SOFA
|
|---|
| 237 | ** software directly, acknowledgement (see www.iausofa.org) is
|
|---|
| 238 | ** appreciated.
|
|---|
| 239 | **
|
|---|
| 240 | ** Correspondence concerning SOFA software should be addressed as
|
|---|
| 241 | ** follows:
|
|---|
| 242 | **
|
|---|
| 243 | ** By email: sofa@ukho.gov.uk
|
|---|
| 244 | ** By post: IAU SOFA Center
|
|---|
| 245 | ** HM Nautical Almanac Office
|
|---|
| 246 | ** UK Hydrographic Office
|
|---|
| 247 | ** Admiralty Way, Taunton
|
|---|
| 248 | ** Somerset, TA1 2DN
|
|---|
| 249 | ** United Kingdom
|
|---|
| 250 | **
|
|---|
| 251 | **--------------------------------------------------------------------*/
|
|---|
| 252 | }
|
|---|