| 1 | #include "sofa.h"
|
|---|
| 2 |
|
|---|
| 3 | int iauCal2jd(int iy, int im, int id, double *djm0, double *djm)
|
|---|
| 4 | /*
|
|---|
| 5 | ** - - - - - - - - - -
|
|---|
| 6 | ** i a u C a l 2 j d
|
|---|
| 7 | ** - - - - - - - - - -
|
|---|
| 8 | **
|
|---|
| 9 | ** Gregorian Calendar to Julian Date.
|
|---|
| 10 | **
|
|---|
| 11 | ** This function is part of the International Astronomical Union's
|
|---|
| 12 | ** SOFA (Standards Of Fundamental Astronomy) software collection.
|
|---|
| 13 | **
|
|---|
| 14 | ** Status: support function.
|
|---|
| 15 | **
|
|---|
| 16 | ** Given:
|
|---|
| 17 | ** iy,im,id int year, month, day in Gregorian calendar (Note 1)
|
|---|
| 18 | **
|
|---|
| 19 | ** Returned:
|
|---|
| 20 | ** djm0 double MJD zero-point: always 2400000.5
|
|---|
| 21 | ** djm double Modified Julian Date for 0 hrs
|
|---|
| 22 | **
|
|---|
| 23 | ** Returned (function value):
|
|---|
| 24 | ** int status:
|
|---|
| 25 | ** 0 = OK
|
|---|
| 26 | ** -1 = bad year (Note 3: JD not computed)
|
|---|
| 27 | ** -2 = bad month (JD not computed)
|
|---|
| 28 | ** -3 = bad day (JD computed)
|
|---|
| 29 | **
|
|---|
| 30 | ** Notes:
|
|---|
| 31 | **
|
|---|
| 32 | ** 1) The algorithm used is valid from -4800 March 1, but this
|
|---|
| 33 | ** implementation rejects dates before -4799 January 1.
|
|---|
| 34 | **
|
|---|
| 35 | ** 2) The Julian Date is returned in two pieces, in the usual SOFA
|
|---|
| 36 | ** manner, which is designed to preserve time resolution. The
|
|---|
| 37 | ** Julian Date is available as a single number by adding djm0 and
|
|---|
| 38 | ** djm.
|
|---|
| 39 | **
|
|---|
| 40 | ** 3) In early eras the conversion is from the "Proleptic Gregorian
|
|---|
| 41 | ** Calendar"; no account is taken of the date(s) of adoption of
|
|---|
| 42 | ** the Gregorian Calendar, nor is the AD/BC numbering convention
|
|---|
| 43 | ** observed.
|
|---|
| 44 | **
|
|---|
| 45 | ** Reference:
|
|---|
| 46 | **
|
|---|
| 47 | ** Explanatory Supplement to the Astronomical Almanac,
|
|---|
| 48 | ** P. Kenneth Seidelmann (ed), University Science Books (1992),
|
|---|
| 49 | ** Section 12.92 (p604).
|
|---|
| 50 | **
|
|---|
| 51 | ** This revision: 2013 August 7
|
|---|
| 52 | **
|
|---|
| 53 | ** SOFA release 2015-02-09
|
|---|
| 54 | **
|
|---|
| 55 | ** Copyright (C) 2015 IAU SOFA Board. See notes at end.
|
|---|
| 56 | */
|
|---|
| 57 | {
|
|---|
| 58 | int j, ly, my;
|
|---|
| 59 | long iypmy;
|
|---|
| 60 |
|
|---|
| 61 | /* Earliest year allowed (4800BC) */
|
|---|
| 62 | const int IYMIN = -4799;
|
|---|
| 63 |
|
|---|
| 64 | /* Month lengths in days */
|
|---|
| 65 | static const int mtab[]
|
|---|
| 66 | = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
|---|
| 67 |
|
|---|
| 68 | /* Preset status. */
|
|---|
| 69 | j = 0;
|
|---|
| 70 |
|
|---|
| 71 | /* Validate year and month. */
|
|---|
| 72 | if (iy < IYMIN) return -1;
|
|---|
| 73 | if (im < 1 || im > 12) return -2;
|
|---|
| 74 |
|
|---|
| 75 | /* If February in a leap year, 1, otherwise 0. */
|
|---|
| 76 | ly = ((im == 2) && !(iy%4) && (iy%100 || !(iy%400)));
|
|---|
| 77 |
|
|---|
| 78 | /* Validate day, taking into account leap years. */
|
|---|
| 79 | if ( (id < 1) || (id > (mtab[im-1] + ly))) j = -3;
|
|---|
| 80 |
|
|---|
| 81 | /* Return result. */
|
|---|
| 82 | my = (im - 14) / 12;
|
|---|
| 83 | iypmy = (long) (iy + my);
|
|---|
| 84 | *djm0 = DJM0;
|
|---|
| 85 | *djm = (double)((1461L * (iypmy + 4800L)) / 4L
|
|---|
| 86 | + (367L * (long) (im - 2 - 12 * my)) / 12L
|
|---|
| 87 | - (3L * ((iypmy + 4900L) / 100L)) / 4L
|
|---|
| 88 | + (long) id - 2432076L);
|
|---|
| 89 |
|
|---|
| 90 | /* Return status. */
|
|---|
| 91 | return j;
|
|---|
| 92 |
|
|---|
| 93 | /*----------------------------------------------------------------------
|
|---|
| 94 | **
|
|---|
| 95 | ** Copyright (C) 2015
|
|---|
| 96 | ** Standards Of Fundamental Astronomy Board
|
|---|
| 97 | ** of the International Astronomical Union.
|
|---|
| 98 | **
|
|---|
| 99 | ** =====================
|
|---|
| 100 | ** SOFA Software License
|
|---|
| 101 | ** =====================
|
|---|
| 102 | **
|
|---|
| 103 | ** NOTICE TO USER:
|
|---|
| 104 | **
|
|---|
| 105 | ** BY USING THIS SOFTWARE YOU ACCEPT THE FOLLOWING SIX TERMS AND
|
|---|
| 106 | ** CONDITIONS WHICH APPLY TO ITS USE.
|
|---|
| 107 | **
|
|---|
| 108 | ** 1. The Software is owned by the IAU SOFA Board ("SOFA").
|
|---|
| 109 | **
|
|---|
| 110 | ** 2. Permission is granted to anyone to use the SOFA software for any
|
|---|
| 111 | ** purpose, including commercial applications, free of charge and
|
|---|
| 112 | ** without payment of royalties, subject to the conditions and
|
|---|
| 113 | ** restrictions listed below.
|
|---|
| 114 | **
|
|---|
| 115 | ** 3. You (the user) may copy and distribute SOFA source code to others,
|
|---|
| 116 | ** and use and adapt its code and algorithms in your own software,
|
|---|
| 117 | ** on a world-wide, royalty-free basis. That portion of your
|
|---|
| 118 | ** distribution that does not consist of intact and unchanged copies
|
|---|
| 119 | ** of SOFA source code files is a "derived work" that must comply
|
|---|
| 120 | ** with the following requirements:
|
|---|
| 121 | **
|
|---|
| 122 | ** a) Your work shall be marked or carry a statement that it
|
|---|
| 123 | ** (i) uses routines and computations derived by you from
|
|---|
| 124 | ** software provided by SOFA under license to you; and
|
|---|
| 125 | ** (ii) does not itself constitute software provided by and/or
|
|---|
| 126 | ** endorsed by SOFA.
|
|---|
| 127 | **
|
|---|
| 128 | ** b) The source code of your derived work must contain descriptions
|
|---|
| 129 | ** of how the derived work is based upon, contains and/or differs
|
|---|
| 130 | ** from the original SOFA software.
|
|---|
| 131 | **
|
|---|
| 132 | ** c) The names of all routines in your derived work shall not
|
|---|
| 133 | ** include the prefix "iau" or "sofa" or trivial modifications
|
|---|
| 134 | ** thereof such as changes of case.
|
|---|
| 135 | **
|
|---|
| 136 | ** d) The origin of the SOFA components of your derived work must
|
|---|
| 137 | ** not be misrepresented; you must not claim that you wrote the
|
|---|
| 138 | ** original software, nor file a patent application for SOFA
|
|---|
| 139 | ** software or algorithms embedded in the SOFA software.
|
|---|
| 140 | **
|
|---|
| 141 | ** e) These requirements must be reproduced intact in any source
|
|---|
| 142 | ** distribution and shall apply to anyone to whom you have
|
|---|
| 143 | ** granted a further right to modify the source code of your
|
|---|
| 144 | ** derived work.
|
|---|
| 145 | **
|
|---|
| 146 | ** Note that, as originally distributed, the SOFA software is
|
|---|
| 147 | ** intended to be a definitive implementation of the IAU standards,
|
|---|
| 148 | ** and consequently third-party modifications are discouraged. All
|
|---|
| 149 | ** variations, no matter how minor, must be explicitly marked as
|
|---|
| 150 | ** such, as explained above.
|
|---|
| 151 | **
|
|---|
| 152 | ** 4. You shall not cause the SOFA software to be brought into
|
|---|
| 153 | ** disrepute, either by misuse, or use for inappropriate tasks, or
|
|---|
| 154 | ** by inappropriate modification.
|
|---|
| 155 | **
|
|---|
| 156 | ** 5. The SOFA software is provided "as is" and SOFA makes no warranty
|
|---|
| 157 | ** as to its use or performance. SOFA does not and cannot warrant
|
|---|
| 158 | ** the performance or results which the user may obtain by using the
|
|---|
| 159 | ** SOFA software. SOFA makes no warranties, express or implied, as
|
|---|
| 160 | ** to non-infringement of third party rights, merchantability, or
|
|---|
| 161 | ** fitness for any particular purpose. In no event will SOFA be
|
|---|
| 162 | ** liable to the user for any consequential, incidental, or special
|
|---|
| 163 | ** damages, including any lost profits or lost savings, even if a
|
|---|
| 164 | ** SOFA representative has been advised of such damages, or for any
|
|---|
| 165 | ** claim by any third party.
|
|---|
| 166 | **
|
|---|
| 167 | ** 6. The provision of any version of the SOFA software under the terms
|
|---|
| 168 | ** and conditions specified herein does not imply that future
|
|---|
| 169 | ** versions will also be made available under the same terms and
|
|---|
| 170 | ** conditions.
|
|---|
| 171 | *
|
|---|
| 172 | ** In any published work or commercial product which uses the SOFA
|
|---|
| 173 | ** software directly, acknowledgement (see www.iausofa.org) is
|
|---|
| 174 | ** appreciated.
|
|---|
| 175 | **
|
|---|
| 176 | ** Correspondence concerning SOFA software should be addressed as
|
|---|
| 177 | ** follows:
|
|---|
| 178 | **
|
|---|
| 179 | ** By email: sofa@ukho.gov.uk
|
|---|
| 180 | ** By post: IAU SOFA Center
|
|---|
| 181 | ** HM Nautical Almanac Office
|
|---|
| 182 | ** UK Hydrographic Office
|
|---|
| 183 | ** Admiralty Way, Taunton
|
|---|
| 184 | ** Somerset, TA1 2DN
|
|---|
| 185 | ** United Kingdom
|
|---|
| 186 | **
|
|---|
| 187 | **--------------------------------------------------------------------*/
|
|---|
| 188 | }
|
|---|