da_diff_seconds.inc
References to this file elsewhere.
1 real function da_diff_seconds (date_char_1, date_char_2)
2
3 !-----------------------------------------------------------------------
4 ! Purpose: TBD
5 !-----------------------------------------------------------------------
6
7 implicit none
8
9 character(len=24), intent(in) :: date_char_1, date_char_2
10
11 integer :: ccyy_1,mo_1,dd_1,hh_1,mi_1,ss_1,jd_1
12 integer :: ccyy_2,mo_2,dd_2,hh_2,mi_2,ss_2,jd_2
13 integer :: i, year, diff_days
14 integer :: start_year, end_year
15 integer :: mmday(12)
16
17 real :: s_1, s_2
18
19 if (trace_use_dull) call da_trace_entry("da_diff_seconds")
20
21 mmday=(/31,28,31,30,31,30,31,31,30,31,30,31/)
22
23 read(date_char_1(1:19), fmt='(i4,1x,4(i2,1x),i2)') &
24 ccyy_1, &
25 mo_1, &
26 dd_1, &
27 hh_1, &
28 mi_1, &
29 ss_1
30
31 read(date_char_2(1:19), fmt='(i4,1x,4(i2,1x),i2)') &
32 ccyy_2, &
33 mo_2, &
34 dd_2, &
35 hh_2, &
36 mi_2, &
37 ss_2
38
39 if (ccyy_2 >= ccyy_1) then
40 start_year = ccyy_1
41 end_year = ccyy_2
42 else
43 start_year = ccyy_2
44 end_year = ccyy_1
45 end if
46
47 diff_days = 0
48
49 do year=start_year,end_year-1
50 diff_days = diff_days + 365
51 if (mod(year,4) == 0) then
52 diff_days = diff_days + 1
53
54 if ((mod(year,100) == 0) .and. (mod(year,400) /= 0)) then
55 diff_days = diff_days - 1
56 end if
57 end if
58 end do
59
60 if (mod(ccyy_1,4) == 0) then
61 mmday(2) = 29
62
63 if((mod(ccyy_1,100) == 0) .and. (mod(ccyy_1,400) /= 0)) then
64 mmday(2) = 28
65 end if
66 end if
67
68 jd_1 = dd_1
69
70 do i=1,mo_1-1
71 jd_1=jd_1+mmday(i)
72 end do
73
74 s_1 = real(ss_1) &
75 + 60.0*(real(mi_1) &
76 + 60.0*(real(hh_1) &
77 + 24.0* real(jd_1)))
78
79 if (mod(ccyy_2,4) == 0) then
80 mmday(2) = 29
81
82 if((mod(ccyy_2,100) == 0) .and. (mod(ccyy_2,400) /= 0)) then
83 mmday(2) = 28
84 end if
85 end if
86
87 if (ccyy_2 >= ccyy_1) then
88 jd_2 = dd_2 + diff_days
89 else
90 jd_2 = dd_2 - diff_days
91 end if
92
93 do i=1,mo_2-1
94 jd_2=jd_2+mmday(i)
95 end do
96
97 s_2 = real(ss_2) &
98 + 60.0*(real(mi_2) &
99 + 60.0*(real(hh_2) &
100 + 24.0* real(jd_2)))
101
102 da_diff_seconds = abs(s_1 - s_2)
103
104 if (trace_use_dull) call da_trace_exit("da_diff_seconds")
105
106 end function da_diff_seconds
107
108