subroutine tadd(iyr, imon, iday, itime, ihra, iyra, imona, idaya, itimea) ! This subroutine calculates the year,month,day,time (iyra,imona,idaya,itimea) ! that are ihra hours after the input year,month,day,time (iyr,imon,iday,itime). ! ihra can not exceed the number of hours in 9 months. ! If ihra is negative, the year,month,day,time that are abs(ihra) before the ! input year,month,day,time are calculated. ! The Julian day utilities jday and jdayi are called by this routine. ! Modifications: ! 4/30/21 (J. Dostalek) Started this Fortran 90 version !------------------------------------------------------------------------------- implicit none integer, intent(in) :: iyr integer, intent(in) :: imon integer, intent(in) :: iday integer, intent(in) :: itime integer, intent(in) :: ihra integer, intent(out) :: iyra integer, intent(out) :: imona integer, intent(out) :: idaya integer, intent(out) :: itimea integer :: idayex integer :: jdate integer :: jmax logical :: ileap iyra = iyr imona = imon idaya = iday select case (ihra) case default ! ** Start calculation for nonnegative ihra (default)** ! Add the hours to the input time itimea = itime + ihra if (itimea < 24) return ! Calculate the number of extra days in the itimea variable and subtract ! them from itimea idayex = itimea/24 itimea = itimea - idayex*24 ! Calculate Julian day of input date and add extra days to it call jday(imon, iday, iyr, jdate) jdate = jdate + idayex ! Check to see if year has changed call jday(12, 31, iyr, jmax) ! if (jdate > jmax) then iyra = iyr + 1 jdate = jdate - jmax else iyra = iyr end if ! Calculate month and day corresponding to the increased jdate call jdayi(jdate, iyra, imona, idaya) case (:-1) ! ** Start calculation for negative ihra ** ! Add the hours to the input time itimea = itime + ihra if (itimea >= 0) return ! Calculate adjusted time idayex = -1 + itimea/24 itimea = itimea - idayex*24 if (itimea == 24) then itimea = 0 idayex = idayex + 1 end if ! Calculate Julian day of input date and subtract extra days from it call jday(imon, iday, iyr, jdate) jdate = jdate + idayex ! Check to see if year has changed if (jdate < 1) then iyra = iyra - 1 jdate = jdate + 365 ileap = .false. if (mod(iyr - 1, 4) == 0) ileap = .true. if (mod(iyr - 1, 100) == 0) ileap = .false. if (mod(iyr - 1, 400) == 0) ileap = .true. if (ileap) jdate = jdate + 1 end if ! Calculate month and day corresponding to the decreased jdate call jdayi(jdate, iyra, imona, idaya) end select return end subroutine tadd