-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCAL2JD.f90
73 lines (62 loc) · 2.08 KB
/
CAL2JD.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
SUBROUTINE CAL2JD (IY0,IM0,ID0,DJM,J)
* - - - - - - - - - - -
* i a u _ C A L 2 J D
* - - - - - - - - - - -
* Gregorian Calendar to Julian Date.
*
* Given:
* IY,IM,ID i year, month, day in Gregorian calendar (Note 1)
*
* Returned:
* DJM0 d MJD zero-point: always 2400000.5
* DJM d Modified Julian Date for 0 hrs
* J i status:
* 0 = OK
* -1 = bad year (Note 3: JD not computed)
* -2 = bad month (JD not computed)
* -3 = bad day (JD computed)
*-----------------------------------------------------------------------
IMPLICIT NONE
INTEGER IY0, IM0, ID0,IY, IM, ID
real*8 DJM0, DJM
INTEGER J, MY, IYPMY
* Earliest year allowed (4800BC)
INTEGER IYMIN
PARAMETER ( IYMIN = -4799 )
* Month lengths in days
INTEGER MTAB(12)
DATA MTAB / 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 /
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IY=IY0;IM=IM0;ID=ID0
* Preset status.
J = 0
* Validate year.
IF ( IY.LT.IYMIN ) THEN
J = -1
ELSE
* Validate month.
IF ( IM.GE.1 .AND. IM.LE.12 ) THEN
* Allow for leap year.
IF ( MOD(IY,4) .EQ. 0 ) THEN
MTAB(2) = 29
ELSE
MTAB(2) = 28
END IF
IF ( MOD(IY,100).EQ.0 .AND. MOD(IY,400).NE.0 ) MTAB(2) = 28
* Validate day.
IF ( ID.LT.1 .OR. ID.GT.MTAB(IM) ) J = -3
* Result.
MY = ( IM - 14 ) / 12
IYPMY = IY + MY
DJM0 = 2400000.5D0
DJM = DBLE( ( 1461 * ( IYPMY + 4800 ) ) / 4
: + ( 367 * ( IM-2 - 12*MY ) ) / 12
: - ( 3 * ( ( IYPMY + 4900 ) / 100 ) ) / 4
: + ID - 2432076)
DJM=DBLE(nint(DJM*1.d3))*1.d-3
* Bad month
ELSE
J = -2
END IF
END IF
END