Skip to content

Commit

Permalink
interpolation methods are not perfect. add tol to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mlee03 authored and mlee03 committed Jul 27, 2023
1 parent 6e9386b commit ab8d313
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions test_fms/interpolator/test_interpolator2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ program test_interpolator
use time_manager_mod, only: time_type, set_date, set_calendar_type, time_manager_init
use fms_mod, only: fms_init
use constants_mod, only: PI
use platform_mod, only: r4_kind, r8_kind

use interpolator_mod

Expand All @@ -46,6 +47,9 @@ program test_interpolator

integer, parameter :: lkind=TEST_INTP_KIND_

real(r8_kind) :: tol=1.e-5_r8_kind !< the interpolation methods are not perfect.
!! Will not get perfectly agreeing answers

integer :: nlonlat !< number of latitude and longitudinal center coordinates
integer :: nlonlatb !< number of latitude and longitudinal boundary coordinates
integer :: ntime !< number of time slices
Expand Down Expand Up @@ -168,8 +172,7 @@ subroutine test_interpolator_2D(clim_type)
do i=1, 1
do j=1, nlonlat_mod
do k=1, nlonlat_mod
write(*,*) j,k, interp_data(k,j)-ozone(k,j,i,itime)
call check_answers(interp_data(k,j), ozone(k,j,i,itime), 'test interpolator_2D')
call check_answers(interp_data(k,j), ozone(k,j,i,itime), tol, 'test interpolator_2D')
end do
end do
end do
Expand Down Expand Up @@ -200,7 +203,7 @@ subroutine test_interpolator_3D(clim_type)
do i=1, nphalf-1
do j=1, nlonlat
do k=1, nlonlat
!call check_answers(interp_data(k,j,i), ozone(k,j,i,itime), 'test interpolator_3D')
call check_answers(interp_data(k,j,i), ozone(k,j,i,itime), tol, 'test interpolator_3D')
end do
end do
end do
Expand Down Expand Up @@ -234,7 +237,7 @@ subroutine test_interpolator_4D(clim_type)
do i=1, nphalf-1
do j=1, nlonlat
do k=1, nlonlat
!call check_answers(interp_data(k,j,i,1), ozone(k,j,i,itime), 'test interpolator_3D')
call check_answers(interp_data(k,j,i,1), ozone(k,j,i,itime), tol, 'test interpolator_3D')
end do
end do
end do
Expand Down Expand Up @@ -317,13 +320,14 @@ subroutine test_query_interpolator

end subroutine test_query_interpolator
!===============================================!
subroutine check_answers(results, answers, whoami)
subroutine check_answers(results, answers, tol, whoami)

implicit none
real(TEST_INTP_KIND_) :: results, answers
real(TEST_INTP_KIND_), intent(in) :: results, answers
real(r8_kind), intent(in) :: tol
character(*) :: whoami

if (results.ne.answers) then
if (real(abs(results-answers),r8_kind).gt.tol) then
write(*,*) ' EXPECTED ', answers, ' but computed ', results
call mpp_error(FATAL, trim(whoami))
end if
Expand Down
6 changes: 3 additions & 3 deletions time_interp/include/time_interp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ character(len=*), intent(out), optional :: err_msg
else if (T<Timelist(is)) then
! time is before the beginning of the portion of the time list within the requested period
index1 = ie; index2 = is
weight = real( 1.0_kindl -((Timelist(is)-T)//(Period-(Timelist(ie)-Timelist(is)))), FMS_TI_KIND_ )
weight = real( 1.0_kindl -real(((Timelist(is)-T)//(Period-(Timelist(ie)-Timelist(is)))),kindl), FMS_TI_KIND_ )
else
call bisect(Timelist,T,index1,index2)
weight = real((T-Timelist(index1)) // (Timelist(index2)-Timelist(index1)), FMS_TI_KIND_ )
Expand Down Expand Up @@ -433,7 +433,7 @@ integer, parameter :: kindl = FMS_TI_KIND_
deallocate(terr,tserr,teerr)
endif
Td = Te-Ts
weight = real(1.0_kindl - ((Ts-T) // (Period-Td)), FMS_TI_KIND_ )
weight = real(1.0_kindl - real(((Ts-T) // (Period-Td)),kindl), FMS_TI_KIND_ )
index1 = n
index2 = 1

Expand Down Expand Up @@ -472,4 +472,4 @@ integer, parameter :: kindl = FMS_TI_KIND_
endif

end subroutine TIME_INTERP_LIST_
!> }
!> }

0 comments on commit ab8d313

Please sign in to comment.