Skip to content

Commit

Permalink
test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mlee03 authored and mlee03 committed Sep 29, 2023
1 parent 79a2058 commit 5b78de6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 44 deletions.
38 changes: 22 additions & 16 deletions test_fms/interpolator/test_interpolator2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ program test_interpolator2
use mpp_mod, only: mpp_error, FATAL, WARNING
use time_manager_mod, only: time_type, set_calendar_type, time_manager_init, &
get_date_no_leap, get_date_julian, set_date, set_time, &
set_date_no_leap, set_date_julian, &
set_date_no_leap, set_date_julian, operator(/), &
operator(+), operator(-), time_type_to_real, increment_time, &
leap_year, days_in_month, print_date
leap_year, days_in_month, print_date, print_time
use fms_mod, only: fms_init
use constants_mod, only: PI
use platform_mod, only: r4_kind, r8_kind
Expand All @@ -47,7 +47,7 @@ program test_interpolator2

character(100), parameter :: ncfile='immadeup.o3.climatology.nc' !< fake climatology file.
integer, parameter :: lkind=TEST_INTP_KIND_
real(r8_kind), parameter :: tol=1.e-5_r8_kind !< the interpolation methods are not perfect.
real(r8_kind), parameter :: tol=1.e-1_r8_kind !< the interpolation methods are not perfect.
!! Will not get perfectly agreeing answers
integer :: calendar_type

Expand Down Expand Up @@ -97,16 +97,16 @@ program test_interpolator2
call time_manager_init
!> set data
if(test_daily_noleap) then
call set_parameters(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=20, npfull_in=3, &
call set_parameters(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=140, npfull_in=3, &
daily_in=.true., yearly_in=.false., noleap_in=.true.)
else if(test_daily_julian) then
call set_parameters(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=20, npfull_in=3, &
call set_parameters(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=140, npfull_in=3, &
daily_in=.true., yearly_in=.false., noleap_in=.false.)
else if(test_yearly_noleap) then
call set_parameters(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=20, npfull_in=3, &
call set_parameters(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=140, npfull_in=3, &
daily_in=.false., yearly_in=.true., noleap_in=.true.)
else if(test_yearly_julian) then
call set_parameters(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=20, npfull_in=3, &
call set_parameters(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=140, npfull_in=3, &
daily_in=.false., yearly_in=.true., noleap_in=.false.)
end if
call set_and_write_data
Expand Down Expand Up @@ -159,52 +159,58 @@ subroutine test_interpolator(clim_type, model_time)

type(interpolate_type), intent(inout) :: clim_type
type(time_type), dimension(ntime), intent(in) :: model_time
type(time_type) :: tmp_time
real(TEST_INTP_KIND_), dimension(nlonlat_mod,nlonlat_mod,npfull,1) :: interp_data !< last column, there is only one field
real(TEST_INTP_KIND_), dimension(nlonlat_mod,nlonlat_mod,nphalf) :: phalf
integer :: itime, i, j, k, l

real(TEST_INTP_KIND_) :: answer

phalf(:,:,1)=0.0000_lkind
phalf(:,:,2)=0.0002_lkind
phalf(:,:,3)=0.0004_lkind
phalf(:,:,4)=0.0005_lkind

do itime=2, ntime-1

answer=real(itime,TEST_INTP_KIND_)-0.5_lkind

!> test interpolator_4D_r4/8
call interpolator(clim_type, model_time(itime), phalf, interp_data, 'ozone')
tmp_time=model_time(itime-1)+ (model_time(itime)-model_time(itime-1))/2
call interpolator(clim_type, tmp_time, phalf, interp_data, 'ozone')
do i=1, npfull
do j=1, nlonlat_mod
do k=1, nlonlat_mod
call check_answers(interp_data(k,j,i,1), ozone(k,j,i,itime), tol, 'test interpolator_4D')
call check_answers(interp_data(k,j,i,1), answer, tol, 'test interpolator_4D')
end do
end do
end do

!> test interpolator_3_r4/8
call interpolator(clim_type, model_time(itime), phalf, interp_data(:,:,:,1), 'ozone')
call interpolator(clim_type, tmp_time, phalf, interp_data(:,:,:,1), 'ozone')
do i=1, npfull
do j=1, nlonlat_mod
do k=1, nlonlat_mod
call check_answers(interp_data(k,j,i,1), ozone(k,j,i,itime), tol, 'test interpolator_3D')
call check_answers(interp_data(k,j,i,1), answer, tol, 'test interpolator_3D')
end do
end do
end do

!> test interpolator_2D_r4/8
call interpolator(clim_type, model_time(itime), interp_data(:,:,1,1), 'ozone')
call interpolator(clim_type, tmp_time, interp_data(:,:,1,1), 'ozone')
do j=1, nlonlat_mod
do k=1, nlonlat_mod
call check_answers(interp_data(k,j,1,1), ozone(k,j,1,itime), tol, 'test interpolator_2D')
call check_answers(interp_data(k,j,1,1), answer, tol, 'test interpolator_2D')
end do
end do

!> Test obtain_interpolator_time_slices
call obtain_interpolator_time_slices(clim_type,model_time(itime))
call interpolator(clim_type, model_time(itime), interp_data(:,:,1,1), 'ozone')
call obtain_interpolator_time_slices(clim_type,tmp_time)
call interpolator(clim_type, tmp_time, interp_data(:,:,1,1), 'ozone')
call unset_interpolator_time_flag(clim_type)
do j=1, nlonlat_mod
do k=1, nlonlat_mod
call check_answers(interp_data(k,j,1,1), ozone(k,j,1,itime), tol, 'test interpolator_2D')
call check_answers(interp_data(k,j,1,1), answer, tol, 'test interpolator_2D')
end do
end do

Expand Down
2 changes: 0 additions & 2 deletions test_fms/interpolator/test_interpolator2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ test_expect_success "test_interpolator2 daily r4 noleap unit tests" 'mpirun -n 1
test_expect_success "test_interpolator2 daily r8 noleap unit tests" 'mpirun -n 1 ./test_interpolator2_r8'
#rm -rf INPUT *.nc test_interpolator.nml

exit

#Run the yearly interpolator tests when the file calendar is in units of years and calendar type is NOLEAP
cat <<EOF > test_interpolator.nml
&test_interpolator_nml
Expand Down
55 changes: 29 additions & 26 deletions test_fms/interpolator/test_interpolator_write_climatology.inc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ subroutine set_clim_time()
implicit none
integer :: i
type(time_type) :: base_time, tmp_time, tmp_time2
type(time_type) :: base_time
integer :: l, ii, yr, mo, dy, hr, mn, sc
integer :: ntime2
Expand All @@ -187,35 +187,37 @@ subroutine set_clim_time()
!write(*,*) ' -- SETTING TIME -- '

hr = 1 ; mn = 1 ; sc = 1

if(test_daily_noleap) then
base_time=set_date_no_leap(1849,1,1,0,0,0)
base_time=set_date_no_leap(1849,1,1,1,1,1)
yr = 1849 ; mo = 1 ; dy = 15
do i=1, ntime
tmp_time=increment_time(base_time,0,(365+5)*i)
call get_date_no_leap(tmp_time, yr, mo, dy, hr, mn, sc)
yr = yr + 1
mo = mo + 1 ; if( mo > 12 ) mo=1
dy = 15
model_time_julian(i)=set_date_julian(yr, mo, dy, hr, mn, sc)
model_time_noleap(i)=set_date_no_leap(yr, mo, dy, hr, mn, sc)
clim_time(i)=time_type_to_real(tmp_time-base_time)/86400._lkind
call set_calendar_type(4)
call print_date(tmp_time)
call set_calendar_type(0)
clim_time(i)=time_type_to_real(model_time_noleap(i)-base_time)/86400._lkind
end do
else if(test_daily_julian) then
base_time=set_date_julian(1849,1,1,0,0,0)
base_time=set_date_julian(1849,1,1,1,1,1)
yr = 1849 ; mo = 1 ; dy = 15
do i=1, ntime
tmp_time=increment_time(base_time,0, (365+5)*i)
call get_date_julian(tmp_time, yr, mo, dy, hr, mn, sc)
yr = yr + 1
mo = mo + 1 ; if( mo > 12 ) mo=1
dy = 15
model_time_julian(i)=set_date_julian(yr, mo, dy, hr, mn, sc)
model_time_noleap(i)=set_date_no_leap(yr, mo, dy, hr, mn, sc)
clim_time(i)=time_type_to_real(tmp_time-base_time)/86400._lkind
call set_calendar_type(2)
call print_date(tmp_time)
call set_calendar_type(0)
clim_time(i)=time_type_to_real(model_time_julian(i)-base_time)/86400._lkind
end do
else if(test_yearly_noleap) then
base_time=set_date_no_leap(1849,1,1,0,0,0)
base_time=set_date_no_leap(1849,1,1,1,1,1)
yr = 1849 ; mo = 1 ; dy = 15
do i=1, ntime
tmp_time=increment_time(base_time,0,(365+3)*i)
call get_date_no_leap(tmp_time, yr, mo, dy, hr, mn, sc)
yr = yr + 1
mo = mo + 1 ; if( mo > 12 ) mo=1
dy = 15
model_time_julian(i)=set_date_julian(yr, mo, dy, hr, mn, sc)
model_time_noleap(i)=set_date_no_leap(yr, mo, dy, hr, mn, sc)
clim_time(i)=real(yr-1849,lkind)
Expand All @@ -226,27 +228,28 @@ subroutine set_clim_time()
case(4,6,9,11) ; clim_time(i) = clim_time(i) + 30.0_lkind/365._lkind
end select
end do
clim_time(i) = clim_time(i) + (dy-1)/real(365,lkind)
clim_time(i) = clim_time(i) + real(dy-1)/real(365,lkind)
end do
else if(test_yearly_julian) then
base_time=set_date_julian(1849,1,1,0,0,0)
base_time=set_date_julian(1849,1,1,1,1,1)
yr = 1849 ; mo = 1 ; dy = 15
call set_calendar_type(2)
do i=1, ntime
tmp_time=increment_time(base_time,0,(365+4)*i)
call get_date_julian(tmp_time, yr, mo, dy, hr, mn, sc)
yr = yr + 1
mo = mo + 1 ; if( mo > 12 ) mo=1
dy = 15
model_time_julian(i)=set_date_julian(yr,mo,dy,hr,mn,sc)
model_time_noleap(i)=set_date_no_leap(yr,mo,dy,hr,mn,sc)
clim_time(i)=real(yr-1849,lkind)
l=0 ; if(leap_year(tmp_time)) l=l+1
l=0 ; if(leap_year(model_time_julian(i))) l=l+1
do ii=1, mo-1
select case(ii)
case(1,3,5,7,8,10,12) ; clim_time(i) = clim_time(i) + 31.0_lkind/real(365+l,lkind)
case(2) ; clim_time(i) = clim_time(i) + real(28+l,lkind)/real(365+l,lkind)
case(4,6,9,11) ; clim_time(i) = clim_time(i) + 30.0_lkind/real(365+l,lkind)
end select
end do
clim_time(i) = clim_time(i) + (dy-1)/real(365+l,lkind)
!call print_date(tmp_time)
clim_time(i) = clim_time(i) + real(dy-1)/real(365+l,lkind)
end do
call set_calendar_type(0)
end if
Expand Down Expand Up @@ -354,7 +357,7 @@ subroutine set_ozone()
do j=1, npfull
do k=1, nlonlat
do l=1, nlonlat
ozone(l,k,j,i)=real(i,TEST_INTP_KIND_)
ozone(l,k,j,i)= real(i,TEST_INTP_KIND_)
end do
end do
end do
Expand Down

0 comments on commit 5b78de6

Please sign in to comment.