| 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-2019, 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, f; | 
| 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, and realign to midnight. */ | 
| 76 | 0 | 0 |  |  |  |  | if (dj1 >= dj2) { | 
| 77 |  |  |  |  |  |  | d1 = dj1; | 
| 78 |  |  |  |  |  |  | d2 = dj2; | 
| 79 |  |  |  |  |  |  | } else { | 
| 80 |  |  |  |  |  |  | d1 = dj2; | 
| 81 |  |  |  |  |  |  | d2 = dj1; | 
| 82 |  |  |  |  |  |  | } | 
| 83 | 0 |  |  |  |  |  | d2 -= 0.5; | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | /* Separate days and fractions. */ | 
| 86 | 0 |  |  |  |  |  | f1 = fmod(d1, 1.0); | 
| 87 | 0 |  |  |  |  |  | f2 = fmod(d2, 1.0); | 
| 88 | 0 | 0 |  |  |  |  | d1 = ERFA_DNINT(d1-f1); | 
| 89 | 0 | 0 |  |  |  |  | d2 = ERFA_DNINT(d2-f2); | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | /* Round the total fraction to the specified number of places. */ | 
| 92 | 0 | 0 |  |  |  |  | f = ERFA_DNINT((f1+f2)*denom) / denom; | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | /* Re-assemble the rounded date and re-align to noon. */ | 
| 95 | 0 |  |  |  |  |  | d2 += f + 0.5; | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | /* Convert to Gregorian calendar. */ | 
| 98 | 0 |  |  |  |  |  | js = eraJd2cal(d1, d2, &iymdf[0], &iymdf[1], &iymdf[2], &f); | 
| 99 | 0 | 0 |  |  |  |  | if (js == 0) { | 
| 100 | 0 |  |  |  |  |  | iymdf[3] = (int) (f * denom); | 
| 101 |  |  |  |  |  |  | } else { | 
| 102 |  |  |  |  |  |  | j = js; | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | /* Return the status. */ | 
| 106 | 0 |  |  |  |  |  | return j; | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | } | 
| 109 |  |  |  |  |  |  | /*---------------------------------------------------------------------- | 
| 110 |  |  |  |  |  |  | ** | 
| 111 |  |  |  |  |  |  | ** | 
| 112 |  |  |  |  |  |  | **  Copyright (C) 2013-2019, NumFOCUS Foundation. | 
| 113 |  |  |  |  |  |  | **  All rights reserved. | 
| 114 |  |  |  |  |  |  | ** | 
| 115 |  |  |  |  |  |  | **  This library is derived, with permission, from the International | 
| 116 |  |  |  |  |  |  | **  Astronomical Union's "Standards of Fundamental Astronomy" library, | 
| 117 |  |  |  |  |  |  | **  available from http://www.iausofa.org. | 
| 118 |  |  |  |  |  |  | ** | 
| 119 |  |  |  |  |  |  | **  The ERFA version is intended to retain identical functionality to | 
| 120 |  |  |  |  |  |  | **  the SOFA library, but made distinct through different function and | 
| 121 |  |  |  |  |  |  | **  file names, as set out in the SOFA license conditions.  The SOFA | 
| 122 |  |  |  |  |  |  | **  original has a role as a reference standard for the IAU and IERS, | 
| 123 |  |  |  |  |  |  | **  and consequently redistribution is permitted only in its unaltered | 
| 124 |  |  |  |  |  |  | **  state.  The ERFA version is not subject to this restriction and | 
| 125 |  |  |  |  |  |  | **  therefore can be included in distributions which do not support the | 
| 126 |  |  |  |  |  |  | **  concept of "read only" software. | 
| 127 |  |  |  |  |  |  | ** | 
| 128 |  |  |  |  |  |  | **  Although the intent is to replicate the SOFA API (other than | 
| 129 |  |  |  |  |  |  | **  replacement of prefix names) and results (with the exception of | 
| 130 |  |  |  |  |  |  | **  bugs;  any that are discovered will be fixed), SOFA is not | 
| 131 |  |  |  |  |  |  | **  responsible for any errors found in this version of the library. | 
| 132 |  |  |  |  |  |  | ** | 
| 133 |  |  |  |  |  |  | **  If you wish to acknowledge the SOFA heritage, please acknowledge | 
| 134 |  |  |  |  |  |  | **  that you are using a library derived from SOFA, rather than SOFA | 
| 135 |  |  |  |  |  |  | **  itself. | 
| 136 |  |  |  |  |  |  | ** | 
| 137 |  |  |  |  |  |  | ** | 
| 138 |  |  |  |  |  |  | **  TERMS AND CONDITIONS | 
| 139 |  |  |  |  |  |  | ** | 
| 140 |  |  |  |  |  |  | **  Redistribution and use in source and binary forms, with or without | 
| 141 |  |  |  |  |  |  | **  modification, are permitted provided that the following conditions | 
| 142 |  |  |  |  |  |  | **  are met: | 
| 143 |  |  |  |  |  |  | ** | 
| 144 |  |  |  |  |  |  | **  1 Redistributions of source code must retain the above copyright | 
| 145 |  |  |  |  |  |  | **    notice, this list of conditions and the following disclaimer. | 
| 146 |  |  |  |  |  |  | ** | 
| 147 |  |  |  |  |  |  | **  2 Redistributions in binary form must reproduce the above copyright | 
| 148 |  |  |  |  |  |  | **    notice, this list of conditions and the following disclaimer in | 
| 149 |  |  |  |  |  |  | **    the documentation and/or other materials provided with the | 
| 150 |  |  |  |  |  |  | **    distribution. | 
| 151 |  |  |  |  |  |  | ** | 
| 152 |  |  |  |  |  |  | **  3 Neither the name of the Standards Of Fundamental Astronomy Board, | 
| 153 |  |  |  |  |  |  | **    the International Astronomical Union nor the names of its | 
| 154 |  |  |  |  |  |  | **    contributors may be used to endorse or promote products derived | 
| 155 |  |  |  |  |  |  | **    from this software without specific prior written permission. | 
| 156 |  |  |  |  |  |  | ** | 
| 157 |  |  |  |  |  |  | **  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
| 158 |  |  |  |  |  |  | **  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
| 159 |  |  |  |  |  |  | **  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 
| 160 |  |  |  |  |  |  | **  FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE | 
| 161 |  |  |  |  |  |  | **  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | 
| 162 |  |  |  |  |  |  | **  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 
| 163 |  |  |  |  |  |  | **  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 
| 164 |  |  |  |  |  |  | **  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
| 165 |  |  |  |  |  |  | **  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 
| 166 |  |  |  |  |  |  | **  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | 
| 167 |  |  |  |  |  |  | **  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 
| 168 |  |  |  |  |  |  | **  POSSIBILITY OF SUCH DAMAGE. | 
| 169 |  |  |  |  |  |  | ** | 
| 170 |  |  |  |  |  |  | */ |