1 | #include "erfa.h"
|
---|
2 |
|
---|
3 | int eraJd2cal(double dj1, double dj2,
|
---|
4 | int *iy, int *im, int *id, double *fd)
|
---|
5 | /*
|
---|
6 | ** - - - - - - - - - -
|
---|
7 | ** e r a J d 2 c a l
|
---|
8 | ** - - - - - - - - - -
|
---|
9 | **
|
---|
10 | ** Julian Date to Gregorian year, month, day, and fraction of a day.
|
---|
11 | **
|
---|
12 | ** Given:
|
---|
13 | ** dj1,dj2 double Julian Date (Notes 1, 2)
|
---|
14 | **
|
---|
15 | ** Returned (arguments):
|
---|
16 | ** iy int year
|
---|
17 | ** im int month
|
---|
18 | ** id int day
|
---|
19 | ** fd double fraction of day
|
---|
20 | **
|
---|
21 | ** Returned (function value):
|
---|
22 | ** int status:
|
---|
23 | ** 0 = OK
|
---|
24 | ** -1 = unacceptable date (Note 3)
|
---|
25 | **
|
---|
26 | ** Notes:
|
---|
27 | **
|
---|
28 | ** 1) The earliest valid date is -68569.5 (-4900 March 1). The
|
---|
29 | ** largest value accepted is 1e9.
|
---|
30 | **
|
---|
31 | ** 2) The Julian Date is apportioned in any convenient way between
|
---|
32 | ** the arguments dj1 and dj2. For example, JD=2450123.7 could
|
---|
33 | ** be expressed in any of these ways, among others:
|
---|
34 | **
|
---|
35 | ** dj1 dj2
|
---|
36 | **
|
---|
37 | ** 2450123.7 0.0 (JD method)
|
---|
38 | ** 2451545.0 -1421.3 (J2000 method)
|
---|
39 | ** 2400000.5 50123.2 (MJD method)
|
---|
40 | ** 2450123.5 0.2 (date & time method)
|
---|
41 | **
|
---|
42 | ** 3) In early eras the conversion is from the "proleptic Gregorian
|
---|
43 | ** calendar"; no account is taken of the date(s) of adoption of
|
---|
44 | ** the Gregorian calendar, nor is the AD/BC numbering convention
|
---|
45 | ** observed.
|
---|
46 | **
|
---|
47 | ** Reference:
|
---|
48 | **
|
---|
49 | ** Explanatory Supplement to the Astronomical Almanac,
|
---|
50 | ** P. Kenneth Seidelmann (ed), University Science Books (1992),
|
---|
51 | ** Section 12.92 (p604).
|
---|
52 | **
|
---|
53 | ** Copyright (C) 2013-2015, NumFOCUS Foundation.
|
---|
54 | ** Derived, with permission, from the SOFA library. See notes at end of file.
|
---|
55 | */
|
---|
56 | {
|
---|
57 | /* Minimum and maximum allowed JD */
|
---|
58 | const double DJMIN = -68569.5;
|
---|
59 | const double DJMAX = 1e9;
|
---|
60 |
|
---|
61 | long jd, l, n, i, k;
|
---|
62 | double dj, d1, d2, f1, f2, f, d;
|
---|
63 |
|
---|
64 | /* Verify date is acceptable. */
|
---|
65 | dj = dj1 + dj2;
|
---|
66 | if (dj < DJMIN || dj > DJMAX) return -1;
|
---|
67 |
|
---|
68 | /* Copy the date, big then small, and re-align to midnight. */
|
---|
69 | if (dj1 >= dj2) {
|
---|
70 | d1 = dj1;
|
---|
71 | d2 = dj2;
|
---|
72 | } else {
|
---|
73 | d1 = dj2;
|
---|
74 | d2 = dj1;
|
---|
75 | }
|
---|
76 | d2 -= 0.5;
|
---|
77 |
|
---|
78 | /* Separate day and fraction. */
|
---|
79 | f1 = fmod(d1, 1.0);
|
---|
80 | f2 = fmod(d2, 1.0);
|
---|
81 | f = fmod(f1 + f2, 1.0);
|
---|
82 | if (f < 0.0) f += 1.0;
|
---|
83 | d = floor(d1 - f1) + floor(d2 - f2) + floor(f1 + f2 - f);
|
---|
84 | jd = (long) floor(d) + 1L;
|
---|
85 |
|
---|
86 | /* Express day in Gregorian calendar. */
|
---|
87 | l = jd + 68569L;
|
---|
88 | n = (4L * l) / 146097L;
|
---|
89 | l -= (146097L * n + 3L) / 4L;
|
---|
90 | i = (4000L * (l + 1L)) / 1461001L;
|
---|
91 | l -= (1461L * i) / 4L - 31L;
|
---|
92 | k = (80L * l) / 2447L;
|
---|
93 | *id = (int) (l - (2447L * k) / 80L);
|
---|
94 | l = k / 11L;
|
---|
95 | *im = (int) (k + 2L - 12L * l);
|
---|
96 | *iy = (int) (100L * (n - 49L) + i + l);
|
---|
97 | *fd = f;
|
---|
98 |
|
---|
99 | return 0;
|
---|
100 |
|
---|
101 | }
|
---|
102 | /*----------------------------------------------------------------------
|
---|
103 | **
|
---|
104 | **
|
---|
105 | ** Copyright (C) 2013-2015, NumFOCUS Foundation.
|
---|
106 | ** All rights reserved.
|
---|
107 | **
|
---|
108 | ** This library is derived, with permission, from the International
|
---|
109 | ** Astronomical Union's "Standards of Fundamental Astronomy" library,
|
---|
110 | ** available from http://www.iausofa.org.
|
---|
111 | **
|
---|
112 | ** The ERFA version is intended to retain identical functionality to
|
---|
113 | ** the SOFA library, but made distinct through different function and
|
---|
114 | ** file names, as set out in the SOFA license conditions. The SOFA
|
---|
115 | ** original has a role as a reference standard for the IAU and IERS,
|
---|
116 | ** and consequently redistribution is permitted only in its unaltered
|
---|
117 | ** state. The ERFA version is not subject to this restriction and
|
---|
118 | ** therefore can be included in distributions which do not support the
|
---|
119 | ** concept of "read only" software.
|
---|
120 | **
|
---|
121 | ** Although the intent is to replicate the SOFA API (other than
|
---|
122 | ** replacement of prefix names) and results (with the exception of
|
---|
123 | ** bugs; any that are discovered will be fixed), SOFA is not
|
---|
124 | ** responsible for any errors found in this version of the library.
|
---|
125 | **
|
---|
126 | ** If you wish to acknowledge the SOFA heritage, please acknowledge
|
---|
127 | ** that you are using a library derived from SOFA, rather than SOFA
|
---|
128 | ** itself.
|
---|
129 | **
|
---|
130 | **
|
---|
131 | ** TERMS AND CONDITIONS
|
---|
132 | **
|
---|
133 | ** Redistribution and use in source and binary forms, with or without
|
---|
134 | ** modification, are permitted provided that the following conditions
|
---|
135 | ** are met:
|
---|
136 | **
|
---|
137 | ** 1 Redistributions of source code must retain the above copyright
|
---|
138 | ** notice, this list of conditions and the following disclaimer.
|
---|
139 | **
|
---|
140 | ** 2 Redistributions in binary form must reproduce the above copyright
|
---|
141 | ** notice, this list of conditions and the following disclaimer in
|
---|
142 | ** the documentation and/or other materials provided with the
|
---|
143 | ** distribution.
|
---|
144 | **
|
---|
145 | ** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
|
---|
146 | ** the International Astronomical Union nor the names of its
|
---|
147 | ** contributors may be used to endorse or promote products derived
|
---|
148 | ** from this software without specific prior written permission.
|
---|
149 | **
|
---|
150 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
151 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
152 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
---|
153 | ** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
---|
154 | ** COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
155 | ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
---|
156 | ** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
157 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
---|
158 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
159 | ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
---|
160 | ** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
---|
161 | ** POSSIBILITY OF SUCH DAMAGE.
|
---|
162 | **
|
---|
163 | */
|
---|