File Coverage

erfasrc/src/jdcalf.c
Criterion Covered Total %
statement 0 22 0.0
branch 0 28 0.0
condition n/a
subroutine n/a
pod n/a
total 0 50 0.0


line stmt bran cond sub pod time code
1             #include "erfa.h"
2              
3 0           int eraJdcalf(int ndp, double dj1, double dj2, int iymdf[4])
4             /*
5             ** - - - - - - - - - -
6             ** e r a J d c a l f
7             ** - - - - - - - - - -
8             **
9             ** Julian Date to Gregorian Calendar, expressed in a form convenient
10             ** for formatting messages: rounded to a specified precision.
11             **
12             ** Given:
13             ** ndp int number of decimal places of days in fraction
14             ** dj1,dj2 double dj1+dj2 = Julian Date (Note 1)
15             **
16             ** Returned:
17             ** iymdf int[4] year, month, day, fraction in Gregorian
18             ** calendar
19             **
20             ** Returned (function value):
21             ** int status:
22             ** -1 = date out of range
23             ** 0 = OK
24             ** +1 = NDP not 0-9 (interpreted as 0)
25             **
26             ** Notes:
27             **
28             ** 1) The Julian Date is apportioned in any convenient way between
29             ** the arguments dj1 and dj2. For example, JD=2450123.7 could
30             ** be expressed in any of these ways, among others:
31             **
32             ** dj1 dj2
33             **
34             ** 2450123.7 0.0 (JD method)
35             ** 2451545.0 -1421.3 (J2000 method)
36             ** 2400000.5 50123.2 (MJD method)
37             ** 2450123.5 0.2 (date & time method)
38             **
39             ** 2) In early eras the conversion is from the "Proleptic Gregorian
40             ** Calendar"; no account is taken of the date(s) of adoption of
41             ** the Gregorian Calendar, nor is the AD/BC numbering convention
42             ** observed.
43             **
44             ** 3) Refer to the function eraJd2cal.
45             **
46             ** 4) NDP should be 4 or less if internal overflows are to be
47             ** avoided on machines which use 16-bit integers.
48             **
49             ** Called:
50             ** eraJd2cal JD to Gregorian calendar
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             ** Copyright (C) 2013-2020, NumFOCUS Foundation.
59             ** Derived, with permission, from the SOFA library. See notes at end of file.
60             */
61             {
62             int j, js;
63             double denom, d1, d2, f1, f2, d, djd, f, rf;
64              
65              
66             /* Denominator of fraction (e.g. 100 for 2 decimal places). */
67 0 0         if ((ndp >= 0) && (ndp <= 9)) {
68             j = 0;
69 0           denom = pow(10.0, ndp);
70             } else {
71             j = 1;
72             denom = 1.0;
73             }
74              
75             /* Copy the date, big then small. */
76 0 0         if (fabs(dj1) >= fabs(dj2)) {
77             d1 = dj1;
78             d2 = dj2;
79             } else {
80             d1 = dj2;
81             d2 = dj1;
82             }
83              
84             /* Realign to midnight (without rounding error). */
85 0           d1 -= 0.5;
86              
87             /* Separate day and fraction (as precisely as possible). */
88 0 0         d = ERFA_DNINT(d1);
    0          
89 0           f1 = d1 - d;
90             djd = d;
91 0 0         d = ERFA_DNINT(d2);
    0          
92 0           f2 = d2 - d;
93 0           djd += d;
94 0 0         d = ERFA_DNINT(f1 + f2);
    0          
95 0           f = (f1 - d) + f2;
96 0 0         if (f < 0.0) {
97 0           f += 1.0;
98 0           d -= 1.0;
99             }
100 0           djd += d;
101              
102             /* Round the total fraction to the specified number of places. */
103 0 0         rf = ERFA_DNINT(f*denom) / denom;
    0          
104              
105             /* Re-align to noon. */
106 0           djd += 0.5;
107              
108             /* Convert to Gregorian calendar. */
109 0           js = eraJd2cal(djd, rf, &iymdf[0], &iymdf[1], &iymdf[2], &f);
110 0 0         if (js == 0) {
111 0 0         iymdf[3] = (int) ERFA_DNINT(f * denom);
    0          
112             } else {
113             j = js;
114             }
115              
116             /* Return the status. */
117 0           return j;
118              
119             }
120             /*----------------------------------------------------------------------
121             **
122             **
123             ** Copyright (C) 2013-2020, NumFOCUS Foundation.
124             ** All rights reserved.
125             **
126             ** This library is derived, with permission, from the International
127             ** Astronomical Union's "Standards of Fundamental Astronomy" library,
128             ** available from http://www.iausofa.org.
129             **
130             ** The ERFA version is intended to retain identical functionality to
131             ** the SOFA library, but made distinct through different function and
132             ** file names, as set out in the SOFA license conditions. The SOFA
133             ** original has a role as a reference standard for the IAU and IERS,
134             ** and consequently redistribution is permitted only in its unaltered
135             ** state. The ERFA version is not subject to this restriction and
136             ** therefore can be included in distributions which do not support the
137             ** concept of "read only" software.
138             **
139             ** Although the intent is to replicate the SOFA API (other than
140             ** replacement of prefix names) and results (with the exception of
141             ** bugs; any that are discovered will be fixed), SOFA is not
142             ** responsible for any errors found in this version of the library.
143             **
144             ** If you wish to acknowledge the SOFA heritage, please acknowledge
145             ** that you are using a library derived from SOFA, rather than SOFA
146             ** itself.
147             **
148             **
149             ** TERMS AND CONDITIONS
150             **
151             ** Redistribution and use in source and binary forms, with or without
152             ** modification, are permitted provided that the following conditions
153             ** are met:
154             **
155             ** 1 Redistributions of source code must retain the above copyright
156             ** notice, this list of conditions and the following disclaimer.
157             **
158             ** 2 Redistributions in binary form must reproduce the above copyright
159             ** notice, this list of conditions and the following disclaimer in
160             ** the documentation and/or other materials provided with the
161             ** distribution.
162             **
163             ** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
164             ** the International Astronomical Union nor the names of its
165             ** contributors may be used to endorse or promote products derived
166             ** from this software without specific prior written permission.
167             **
168             ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
169             ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
170             ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
171             ** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
172             ** COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
173             ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
174             ** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
175             ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
176             ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
177             ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
178             ** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
179             ** POSSIBILITY OF SUCH DAMAGE.
180             **
181             */