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, dimension(12) :: mmday
16  
17    real                   :: s_1, s_2
18   
19    mmday=(/31,28,31,30,31,30,31,31,30,31,30,31/)
20   
21    read(date_char_1(1:19), fmt='(i4,1x,4(i2,1x),i2)') &
22         ccyy_1, &
23           mo_1, &
24           dd_1, &
25           hh_1, &
26           mi_1, &
27           ss_1
28   
29    read(date_char_2(1:19), fmt='(i4,1x,4(i2,1x),i2)') &
30         ccyy_2, &
31           mo_2, &
32           dd_2, &
33           hh_2, &
34           mi_2, &
35           ss_2
36 
37    if (ccyy_2 >= ccyy_1) then
38       start_year = ccyy_1
39       end_year   = ccyy_2
40    else
41       start_year = ccyy_2
42       end_year   = ccyy_1
43    end if
44 
45    diff_days = 0
46   
47    do year=start_year,end_year-1
48       diff_days = diff_days + 365
49       if (mod(year,4) == 0) then
50          diff_days = diff_days + 1
51 
52          if ((mod(year,100) == 0) .and. (mod(year,400) /= 0)) then
53             diff_days = diff_days - 1
54          end if
55       end if
56    end do
57 
58    if (mod(ccyy_1,4) == 0) then
59       mmday(2) = 29
60 
61       if((mod(ccyy_1,100) == 0) .and. (mod(ccyy_1,400) /= 0)) then
62          mmday(2) = 28
63       end if
64    end if
65 
66    jd_1 = dd_1
67 
68    do i=1,mo_1-1
69       jd_1=jd_1+mmday(i)
70    end do
71 
72    s_1 = real(ss_1) &
73        + 60.0*(real(mi_1) &
74        + 60.0*(real(hh_1) &
75        + 24.0* real(jd_1)))
76 
77    if (mod(ccyy_2,4) == 0) then
78       mmday(2) = 29
79 
80       if((mod(ccyy_2,100) == 0) .and. (mod(ccyy_2,400) /= 0)) then
81          mmday(2) = 28
82       end if
83    end if
84 
85    if (ccyy_2 >= ccyy_1) then
86       jd_2 = dd_2 + diff_days
87    else
88       jd_2 = dd_2 - diff_days
89    end if
90 
91    do i=1,mo_2-1
92       jd_2=jd_2+mmday(i)
93    end do
94 
95    s_2 = real(ss_2) &
96        + 60.0*(real(mi_2) &
97        + 60.0*(real(hh_2) &
98        + 24.0* real(jd_2)))
99 
100    da_diff_seconds = abs(s_1 - s_2)
101 
102 end function da_diff_seconds
103 
104