| 1 | #include "sofa.h"
|
|---|
| 2 |
|
|---|
| 3 | int iauJd2cal(double dj1, double dj2,
|
|---|
| 4 | int *iy, int *im, int *id, double *fd)
|
|---|
| 5 | /*
|
|---|
| 6 | ** - - - - - - - - - -
|
|---|
| 7 | ** i a u J d 2 c a l
|
|---|
| 8 | ** - - - - - - - - - -
|
|---|
| 9 | **
|
|---|
| 10 | ** Julian Date to Gregorian year, month, day, and fraction of a day.
|
|---|
| 11 | **
|
|---|
| 12 | ** This function is part of the International Astronomical Union's
|
|---|
| 13 | ** SOFA (Standards Of Fundamental Astronomy) software collection.
|
|---|
| 14 | **
|
|---|
| 15 | ** Status: support function.
|
|---|
| 16 | **
|
|---|
| 17 | ** Given:
|
|---|
| 18 | ** dj1,dj2 double Julian Date (Notes 1, 2)
|
|---|
| 19 | **
|
|---|
| 20 | ** Returned (arguments):
|
|---|
| 21 | ** iy int year
|
|---|
| 22 | ** im int month
|
|---|
| 23 | ** id int day
|
|---|
| 24 | ** fd double fraction of day
|
|---|
| 25 | **
|
|---|
| 26 | ** Returned (function value):
|
|---|
| 27 | ** int status:
|
|---|
| 28 | ** 0 = OK
|
|---|
| 29 | ** -1 = unacceptable date (Note 3)
|
|---|
| 30 | **
|
|---|
| 31 | ** Notes:
|
|---|
| 32 | **
|
|---|
| 33 | ** 1) The earliest valid date is -68569.5 (-4900 March 1). The
|
|---|
| 34 | ** largest value accepted is 1e9.
|
|---|
| 35 | **
|
|---|
| 36 | ** 2) The Julian Date is apportioned in any convenient way between
|
|---|
| 37 | ** the arguments dj1 and dj2. For example, JD=2450123.7 could
|
|---|
| 38 | ** be expressed in any of these ways, among others:
|
|---|
| 39 | **
|
|---|
| 40 | ** dj1 dj2
|
|---|
| 41 | **
|
|---|
| 42 | ** 2450123.7 0.0 (JD method)
|
|---|
| 43 | ** 2451545.0 -1421.3 (J2000 method)
|
|---|
| 44 | ** 2400000.5 50123.2 (MJD method)
|
|---|
| 45 | ** 2450123.5 0.2 (date & time method)
|
|---|
| 46 | **
|
|---|
| 47 | ** 3) In early eras the conversion is from the "proleptic Gregorian
|
|---|
| 48 | ** calendar"; no account is taken of the date(s) of adoption of
|
|---|
| 49 | ** the Gregorian calendar, nor is the AD/BC numbering convention
|
|---|
| 50 | ** observed.
|
|---|
| 51 | **
|
|---|
| 52 | ** Reference:
|
|---|
| 53 | **
|
|---|
| 54 | ** Explanatory Supplement to the Astronomical Almanac,
|
|---|
| 55 | ** P. Kenneth Seidelmann (ed), University Science Books (1992),
|
|---|
| 56 | ** Section 12.92 (p604).
|
|---|
| 57 | **
|
|---|
| 58 | ** This revision: 2013 August 7
|
|---|
| 59 | **
|
|---|
| 60 | ** SOFA release 2015-02-09
|
|---|
| 61 | **
|
|---|
| 62 | ** Copyright (C) 2015 IAU SOFA Board. See notes at end.
|
|---|
| 63 | */
|
|---|
| 64 | {
|
|---|
| 65 | /* Minimum and maximum allowed JD */
|
|---|
| 66 | const double DJMIN = -68569.5;
|
|---|
| 67 | const double DJMAX = 1e9;
|
|---|
| 68 |
|
|---|
| 69 | long jd, l, n, i, k;
|
|---|
| 70 | double dj, d1, d2, f1, f2, f, d;
|
|---|
| 71 |
|
|---|
| 72 | /* Verify date is acceptable. */
|
|---|
| 73 | dj = dj1 + dj2;
|
|---|
| 74 | if (dj < DJMIN || dj > DJMAX) return -1;
|
|---|
| 75 |
|
|---|
| 76 | /* Copy the date, big then small, and re-align to midnight. */
|
|---|
| 77 | if (dj1 >= dj2) {
|
|---|
| 78 | d1 = dj1;
|
|---|
| 79 | d2 = dj2;
|
|---|
| 80 | } else {
|
|---|
| 81 | d1 = dj2;
|
|---|
| 82 | d2 = dj1;
|
|---|
| 83 | }
|
|---|
| 84 | d2 -= 0.5;
|
|---|
| 85 |
|
|---|
| 86 | /* Separate day and fraction. */
|
|---|
| 87 | f1 = fmod(d1, 1.0);
|
|---|
| 88 | f2 = fmod(d2, 1.0);
|
|---|
| 89 | f = fmod(f1 + f2, 1.0);
|
|---|
| 90 | if (f < 0.0) f += 1.0;
|
|---|
| 91 | d = floor(d1 - f1) + floor(d2 - f2) + floor(f1 + f2 - f);
|
|---|
| 92 | jd = (long) floor(d) + 1L;
|
|---|
| 93 |
|
|---|
| 94 | /* Express day in Gregorian calendar. */
|
|---|
| 95 | l = jd + 68569L;
|
|---|
| 96 | n = (4L * l) / 146097L;
|
|---|
| 97 | l -= (146097L * n + 3L) / 4L;
|
|---|
| 98 | i = (4000L * (l + 1L)) / 1461001L;
|
|---|
| 99 | l -= (1461L * i) / 4L - 31L;
|
|---|
| 100 | k = (80L * l) / 2447L;
|
|---|
| 101 | *id = (int) (l - (2447L * k) / 80L);
|
|---|
| 102 | l = k / 11L;
|
|---|
| 103 | *im = (int) (k + 2L - 12L * l);
|
|---|
| 104 | *iy = (int) (100L * (n - 49L) + i + l);
|
|---|
| 105 | *fd = f;
|
|---|
| 106 |
|
|---|
| 107 | return 0;
|
|---|
| 108 |
|
|---|
| 109 | /*----------------------------------------------------------------------
|
|---|
| 110 | **
|
|---|
| 111 | ** Copyright (C) 2015
|
|---|
| 112 | ** Standards Of Fundamental Astronomy Board
|
|---|
| 113 | ** of the International Astronomical Union.
|
|---|
| 114 | **
|
|---|
| 115 | ** =====================
|
|---|
| 116 | ** SOFA Software License
|
|---|
| 117 | ** =====================
|
|---|
| 118 | **
|
|---|
| 119 | ** NOTICE TO USER:
|
|---|
| 120 | **
|
|---|
| 121 | ** BY USING THIS SOFTWARE YOU ACCEPT THE FOLLOWING SIX TERMS AND
|
|---|
| 122 | ** CONDITIONS WHICH APPLY TO ITS USE.
|
|---|
| 123 | **
|
|---|
| 124 | ** 1. The Software is owned by the IAU SOFA Board ("SOFA").
|
|---|
| 125 | **
|
|---|
| 126 | ** 2. Permission is granted to anyone to use the SOFA software for any
|
|---|
| 127 | ** purpose, including commercial applications, free of charge and
|
|---|
| 128 | ** without payment of royalties, subject to the conditions and
|
|---|
| 129 | ** restrictions listed below.
|
|---|
| 130 | **
|
|---|
| 131 | ** 3. You (the user) may copy and distribute SOFA source code to others,
|
|---|
| 132 | ** and use and adapt its code and algorithms in your own software,
|
|---|
| 133 | ** on a world-wide, royalty-free basis. That portion of your
|
|---|
| 134 | ** distribution that does not consist of intact and unchanged copies
|
|---|
| 135 | ** of SOFA source code files is a "derived work" that must comply
|
|---|
| 136 | ** with the following requirements:
|
|---|
| 137 | **
|
|---|
| 138 | ** a) Your work shall be marked or carry a statement that it
|
|---|
| 139 | ** (i) uses routines and computations derived by you from
|
|---|
| 140 | ** software provided by SOFA under license to you; and
|
|---|
| 141 | ** (ii) does not itself constitute software provided by and/or
|
|---|
| 142 | ** endorsed by SOFA.
|
|---|
| 143 | **
|
|---|
| 144 | ** b) The source code of your derived work must contain descriptions
|
|---|
| 145 | ** of how the derived work is based upon, contains and/or differs
|
|---|
| 146 | ** from the original SOFA software.
|
|---|
| 147 | **
|
|---|
| 148 | ** c) The names of all routines in your derived work shall not
|
|---|
| 149 | ** include the prefix "iau" or "sofa" or trivial modifications
|
|---|
| 150 | ** thereof such as changes of case.
|
|---|
| 151 | **
|
|---|
| 152 | ** d) The origin of the SOFA components of your derived work must
|
|---|
| 153 | ** not be misrepresented; you must not claim that you wrote the
|
|---|
| 154 | ** original software, nor file a patent application for SOFA
|
|---|
| 155 | ** software or algorithms embedded in the SOFA software.
|
|---|
| 156 | **
|
|---|
| 157 | ** e) These requirements must be reproduced intact in any source
|
|---|
| 158 | ** distribution and shall apply to anyone to whom you have
|
|---|
| 159 | ** granted a further right to modify the source code of your
|
|---|
| 160 | ** derived work.
|
|---|
| 161 | **
|
|---|
| 162 | ** Note that, as originally distributed, the SOFA software is
|
|---|
| 163 | ** intended to be a definitive implementation of the IAU standards,
|
|---|
| 164 | ** and consequently third-party modifications are discouraged. All
|
|---|
| 165 | ** variations, no matter how minor, must be explicitly marked as
|
|---|
| 166 | ** such, as explained above.
|
|---|
| 167 | **
|
|---|
| 168 | ** 4. You shall not cause the SOFA software to be brought into
|
|---|
| 169 | ** disrepute, either by misuse, or use for inappropriate tasks, or
|
|---|
| 170 | ** by inappropriate modification.
|
|---|
| 171 | **
|
|---|
| 172 | ** 5. The SOFA software is provided "as is" and SOFA makes no warranty
|
|---|
| 173 | ** as to its use or performance. SOFA does not and cannot warrant
|
|---|
| 174 | ** the performance or results which the user may obtain by using the
|
|---|
| 175 | ** SOFA software. SOFA makes no warranties, express or implied, as
|
|---|
| 176 | ** to non-infringement of third party rights, merchantability, or
|
|---|
| 177 | ** fitness for any particular purpose. In no event will SOFA be
|
|---|
| 178 | ** liable to the user for any consequential, incidental, or special
|
|---|
| 179 | ** damages, including any lost profits or lost savings, even if a
|
|---|
| 180 | ** SOFA representative has been advised of such damages, or for any
|
|---|
| 181 | ** claim by any third party.
|
|---|
| 182 | **
|
|---|
| 183 | ** 6. The provision of any version of the SOFA software under the terms
|
|---|
| 184 | ** and conditions specified herein does not imply that future
|
|---|
| 185 | ** versions will also be made available under the same terms and
|
|---|
| 186 | ** conditions.
|
|---|
| 187 | *
|
|---|
| 188 | ** In any published work or commercial product which uses the SOFA
|
|---|
| 189 | ** software directly, acknowledgement (see www.iausofa.org) is
|
|---|
| 190 | ** appreciated.
|
|---|
| 191 | **
|
|---|
| 192 | ** Correspondence concerning SOFA software should be addressed as
|
|---|
| 193 | ** follows:
|
|---|
| 194 | **
|
|---|
| 195 | ** By email: sofa@ukho.gov.uk
|
|---|
| 196 | ** By post: IAU SOFA Center
|
|---|
| 197 | ** HM Nautical Almanac Office
|
|---|
| 198 | ** UK Hydrographic Office
|
|---|
| 199 | ** Admiralty Way, Taunton
|
|---|
| 200 | ** Somerset, TA1 2DN
|
|---|
| 201 | ** United Kingdom
|
|---|
| 202 | **
|
|---|
| 203 | **--------------------------------------------------------------------*/
|
|---|
| 204 | }
|
|---|