Julian Date to Gregorian year, month, day, and fraction of a day.
Status: support routine.
The earliest valid date is -68569.5 (-4900 March 1). The largest value accepted is 10^9.
The Julian Date is apportioned in any convenient way between the arguments DJ1 and DJ2. For example, JD=2450123.7 could be expressed in any of these ways, among others:
DJ1 DJ2
2450123.7D0 0D0 (JD method)
2451545D0 -1421.3D0 (J2000 method)
2400000.5D0 50123.2D0 (MJD method)
2450123.5D0 0.2D0 (date & time method)
In early eras the conversion is from the "Proleptic Gregorian Calendar"; no account is taken of the date(s) of adoption of the Gregorian Calendar, nor is the AD/BC numbering convention observed.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | dj1 | Julian Date (Notes 1, 2) |
||
real(kind=wp), | intent(in) | :: | dj2 | Julian Date (Notes 1, 2) |
||
integer, | intent(out) | :: | iy | year |
||
integer, | intent(out) | :: | im | month |
||
integer, | intent(out) | :: | id | day |
||
real(kind=wp), | intent(out) | :: | fd | fraction of day |
||
integer, | intent(out) | :: | j |
|
subroutine JD2CAL ( dj1, dj2, iy, im, id, fd, j )
implicit none
real(wp),intent(in) :: dj1 !! Julian Date (Notes 1, 2)
real(wp),intent(in) :: dj2 !! Julian Date (Notes 1, 2)
integer,intent(out) :: iy !! year
integer,intent(out) :: im !! month
integer,intent(out) :: id !! day
real(wp),intent(out) :: fd !! fraction of day
integer,intent(out) :: j !! status:
!! * 0 = OK
!! * -1 = unacceptable date (Note 1)
! Minimum and maximum allowed JD
real(wp),parameter :: djmin = -68569.5_wp
real(wp),parameter :: djmax = 1.0e9_wp
integer :: jd, l, n, i, k
real(wp) :: dj, d1, d2, f1, f2, f, d
! Check if date is acceptable.
dj = dj1 + dj2
if ( dj<djmin .or. dj>djmax ) then
j = -1
else
j = 0
! Copy the date, big then small, and re-align to midnight.
if ( abs(dj1) >= abs(dj2) ) then
d1 = dj1
d2 = dj2
else
d1 = dj2
d2 = dj1
end if
d2 = d2 - 0.5_wp
! Separate day and fraction.
f1 = mod(d1,1.0_wp)
f2 = mod(d2,1.0_wp)
f = mod(f1+f2,1.0_wp)
if ( f < 0.0_wp ) f = f+1.0_wp
d = anint(d1-f1) + anint(d2-f2) + anint(f1+f2-f)
jd = nint(d) + 1
! Express day in Gregorian calendar.
l = jd + 68569
n = ( 4*l ) / 146097
l = l - ( 146097*n + 3 ) / 4
i = ( 4000 * (l+1) ) / 1461001
l = l - ( 1461*i ) / 4 + 31
k = ( 80*l ) / 2447
id = l - ( 2447*k ) / 80
l = k / 11
im = k + 2 - 12*l
iy = 100 * ( n-49 ) + i + l
fd = f
end if
end subroutine JD2CAL