1 |
PRO DAYCNV, XJD, YR, MN, DAY, HR |
2 |
;+ |
3 |
; NAME: |
4 |
; DAYCNV |
5 |
; PURPOSE: |
6 |
; Converts Julian dates to Gregorian calendar dates |
7 |
; |
8 |
; CALLING SEQUENCE: |
9 |
; DAYCNV, XJD, YR, MN, DAY, HR |
10 |
; |
11 |
; INPUTS: |
12 |
; XJD = Julian date, positive double precision scalar or vector |
13 |
; |
14 |
; OUTPUTS: |
15 |
; YR = Year (Integer) |
16 |
; MN = Month (Integer) |
17 |
; DAY = Day (Integer) |
18 |
; HR = Hours and fractional hours (Real). If XJD is a vector, |
19 |
; then YR,MN,DAY and HR will be vectors of the same length. |
20 |
; |
21 |
; EXAMPLE: |
22 |
; IDL> DAYCNV, 2440000.D, yr, mn, day, hr |
23 |
; |
24 |
; yields yr = 1968, mn =5, day = 23, hr =12. |
25 |
; |
26 |
; WARNING: |
27 |
; Be sure that the Julian date is specified as double precision to |
28 |
; maintain accuracy at the fractional hour level. |
29 |
; |
30 |
; METHOD: |
31 |
; Uses the algorithm of Fliegel and Van Falndern (1968) as reported in |
32 |
; the "Explanatory Supplement to the Astronomical Almanac" (1992), p. 604 |
33 |
; Works for all Gregorian calendar dates with XJD > 0, i.e., dates after |
34 |
; -4713 November 23. |
35 |
; REVISION HISTORY: |
36 |
; Converted to IDL from Yeoman's Comet Ephemeris Generator, |
37 |
; B. Pfarr, STX, 6/16/88 |
38 |
; Converted to IDL V5.0 W. Landsman September 1997 |
39 |
;- |
40 |
On_error,2 |
41 |
|
42 |
if N_params() lt 2 then begin |
43 |
print,"Syntax - DAYCNV, xjd, yr, mn, day, hr' |
44 |
print,' Julian date, xjd, should be specified in double precision' |
45 |
return |
46 |
endif |
47 |
|
48 |
; Adjustment needed because Julian day starts at noon, calendar day at midnight |
49 |
|
50 |
jd = long(xjd) ;Truncate to integral day |
51 |
frac = double(xjd) - jd + 0.5 ;Fractional part of calendar day |
52 |
after_noon = where(frac ge 1.0, Next) |
53 |
if Next GT 0 then begin ;Is it really the next calendar day? |
54 |
frac[after_noon] = frac[after_noon] - 1.0 |
55 |
jd[after_noon] = jd[after_noon] + 1 |
56 |
endif |
57 |
hr = frac*24.0 |
58 |
l = jd + 68569 |
59 |
n = 4*l / 146097l |
60 |
l = l - (146097*n + 3l) / 4 |
61 |
yr = 4000*(l+1) / 1461001 |
62 |
l = l - 1461*yr / 4 + 31 ;1461 = 365.25 * 4 |
63 |
mn = 80*l / 2447 |
64 |
day = l - 2447*mn / 80 |
65 |
l = mn/11 |
66 |
mn = mn + 2 - 12*l |
67 |
yr = 100*(n-49) + yr + l |
68 |
return |
69 |
end |