subroutine tdiff(iy2, im2, id2, it2, iy1, im1, id1, it1, idelt) ! This routine calculates the number of hours (delt) between ! two date/times. ! Note: Times are in hours ! Modifications: ! 4/29/21 (J. Dostalek) Started this Fortran 90 version !------------------------------------------------------------------------------- implicit none integer, intent(in) :: iy2 integer, intent(in) :: im2 integer, intent(in) :: id2 integer, intent(in) :: it2 integer, intent(in) :: iy1 integer, intent(in) :: im1 integer, intent(in) :: id1 integer, intent(in) :: it1 integer, intent(out) :: idelt integer :: i integer :: iry integer :: ity1 integer :: ity2 integer, dimension(12) :: nday logical :: ileap logical :: ileap1 logical :: ileap2 data nday/0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334/ ! Calculate reference year iry = iy1 - 2 if (iy2 < iry) iry = iy2 - 2 ! Calculate the number of hours from 00 Jan. 1 of the reference year ity1 = 0 do i = iry, iy1 - 1 ileap = .false. if (mod(i, 4) == 0) ileap = .true. if (mod(i, 100) == 0) ileap = .false. if (mod(i, 400) == 0) ileap = .true. if (ileap) then ity1 = ity1 + 24*366 else ity1 = ity1 + 24*365 end if end do ity2 = 0 do i = iry, iy2 - 1 ileap = .false. if (mod(i, 4) == 0) ileap = .true. if (mod(i, 100) == 0) ileap = .false. if (mod(i, 400) == 0) ileap = .true. if (ileap) then ity2 = ity2 + 24*366 else ity2 = ity2 + 24*365 end if end do ity1 = ity1 + 24*nday(im1) ileap1 = .false. if (mod(iy1, 4) == 0) ileap1 = .true. if (mod(iy1, 100) == 0) ileap1 = .false. if (mod(iy1, 400) == 0) ileap1 = .true. if (ileap1 .and. im1 > 2) ity1 = ity1 + 24 ity2 = ity2 + 24*nday(im2) ileap2 = .false. if (mod(iy2, 4) == 0) ileap2 = .true. if (mod(iy2, 100) == 0) ileap2 = .false. if (mod(iy2, 400) == 0) ileap2 = .true. if (ileap2 .and. im2 > 2) ity2 = ity2 + 24 ity1 = ity1 + 24*id1 + it1 ity2 = ity2 + 24*id2 + it2 idelt = ity2 - ity1 return end subroutine tdiff