Line data Source code
1 : module time_utils 2 : 3 : use shr_kind_mod, only : r8 => shr_kind_r8 4 : use cam_abortutils, only : endrun 5 : use cam_logfile, only : iulog 6 : 7 : private 8 : public :: flt_date, moz_findplb 9 : 10 : contains 11 : 12 0 : subroutine moz_findplb( x, nx, xval, index ) 13 : !----------------------------------------------------------------------- 14 : ! ... find periodic lower bound 15 : ! search the input array for the lower bound of the interval that 16 : ! contains the input value. the returned index satifies: 17 : ! x(index) .le. xval .lt. x(index+1) 18 : ! assume the array represents values in one cycle of a periodic coordinate. 19 : ! so, if xval .lt. x(1), then index=nx. 20 : !----------------------------------------------------------------------- 21 : 22 : implicit none 23 : 24 : !----------------------------------------------------------------------- 25 : ! ... dummy args 26 : !----------------------------------------------------------------------- 27 : integer, intent(in) :: nx 28 : integer, intent(out) :: index 29 : real(r8), intent(in) :: x(nx) ! strictly increasing array 30 : real(r8), intent(in) :: xval 31 : 32 : !----------------------------------------------------------------------- 33 : ! ... local variables 34 : !----------------------------------------------------------------------- 35 : integer :: i 36 : 37 0 : if( xval < x(1) .or. xval >= x(nx) ) then 38 0 : index = nx 39 0 : return 40 : end if 41 : 42 0 : do i = 2,nx 43 0 : if( xval < x(i) ) then 44 0 : index = i - 1 45 0 : exit 46 : end if 47 : end do 48 : 49 : end subroutine moz_findplb 50 : 51 0 : real(r8) function flt_date( ncdate, ncsec ) 52 : !----------------------------------------------------------------------- 53 : ! Purpose: Convert date and seconds of day to floating point days since 54 : ! 0001/01/01 55 : !----------------------------------------------------------------------- 56 : use time_manager, only : timemgr_datediff 57 : implicit none 58 : 59 : !----------------------------------------------------------------------- 60 : ! ... dummy arguments 61 : !----------------------------------------------------------------------- 62 : integer, intent(in) :: ncdate ! Current date as yyyymmdd 63 : integer, intent(in) :: ncsec ! Seconds of day for current date 64 : 65 : integer :: refymd = 00010101 66 : integer :: reftod = 0 67 : 68 0 : call timemgr_datediff(refymd, reftod, ncdate, ncsec, flt_date) 69 0 : end function flt_date 70 : 71 : end module time_utils