Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mlee03 authored and mlee03 committed Jul 31, 2023
1 parent ab8d313 commit e858037
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 137 deletions.
3 changes: 3 additions & 0 deletions interpolator/include/interpolator.inc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ if (use_mpp_io) then
'MPP_IO is no longer supported. Please remove from use_mpp_io from interpolator_nml')
endif

if(kind(lonb_mod).eq.r4_kind) clim_type%is_r4=.true.
if(kind(lonb_mod).eq.r8_kind) clim_type%is_r8=.true.

call fms2io_interpolator_init(clim_type, file_name, lonb_mod, latb_mod, &
data_names, data_out_of_bounds, &
vert_interp, clim_units, single_year_file)
Expand Down
16 changes: 13 additions & 3 deletions interpolator/interpolator.F90
Original file line number Diff line number Diff line change
Expand Up @@ -675,15 +675,22 @@ subroutine interpolator_end(clim_type)
if (allocated (clim_type%r8_type%lonb )) deallocate(clim_type%r8_type%lonb)
if (allocated (clim_type%r8_type%levs )) deallocate(clim_type%r8_type%levs)
if (allocated (clim_type%r8_type%halflevs)) deallocate(clim_type%r8_type%halflevs)
if (allocated (clim_type%r8_type%data)) deallocate(clim_type%r4_type%data)
if (allocated (clim_type%r8_type%data)) deallocate(clim_type%r8_type%data)
end if

call horiz_interp_del(clim_type%interph)
if (allocated (clim_type%time_slice)) deallocate(clim_type%time_slice)
if (allocated (clim_type%has_level)) deallocate(clim_type%has_level)
if (allocated (clim_type%field_name)) deallocate(clim_type%field_name)
if (allocated (clim_type%time_init )) deallocate(clim_type%time_init)
if (allocated (clim_type%has_level)) deallocate(clim_type%has_level)
if (allocated (clim_type%mr )) deallocate(clim_type%mr)
if (allocated (clim_type%out_of_bounds )) deallocate(clim_type%out_of_bounds)
if (allocated (clim_type%vert_interp )) deallocate(clim_type%vert_interp)
if (allocated(clim_type%indexm)) deallocate(clim_type%indexm)
if (allocated(clim_type%indexp)) deallocate(clim_type%indexp)
if (allocated(clim_type%clim_times)) deallocate(clim_type%clim_times)
if (allocated(clim_type%climatology)) deallocate(clim_type%climatology)

call horiz_interp_del(clim_type%interph)

if(clim_type%is_r4) then
if (allocated (clim_type%r4_type%pmon_pyear)) then
Expand All @@ -701,6 +708,9 @@ subroutine interpolator_end(clim_type)
end if
endif

clim_type%is_r4=.false.
clim_type%is_r8=.false.

!! RSH mod
if( .not. (clim_type%TIME_FLAG .eq. LINEAR .and. &
! read_all_on_init)) .or. clim_type%TIME_FLAG .eq. BILINEAR ) then
Expand Down
194 changes: 72 additions & 122 deletions test_fms/interpolator/test_interpolator2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
!! an interpolator_type which cannot be queried.
!! This subroutine should be called by the interpolators.

program test_interpolator
program test_interpolator_mod

use fms2_io_mod, only: FmsNetcdfFile_t, UNLIMITED, &
register_field, register_variable_attribute, &
Expand Down Expand Up @@ -80,61 +80,36 @@ program test_interpolator
call set_calendar_type(calendar_type)

!> set data
nlonlat = 10 !< number of latitude and longitudinal center coordinates
nlonlatb = nlonlat+1 !< number of latitude and longitudinal boundary coordinates
nlonlat_mod = nlonlat
nlonlatb_mod = nlonlatb
ntime = 5 !< number of time slices
npfull = 3 !< number of p levels
nphalf = npfull+1 !< number of half p levels
call allocate_arrays()
call set_clim_time()
call set_latlon_b()
call set_pfullhalf()
call set_ozone()
call write_climatology_file()

call set_latlon_b_mod()
call set_write_data(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=5, npfull_in=3)

write(*,*) '===== test_intepolator_init ====='
call test_interpolator_init(o3)
write(*,*) ' test interpolator_init success'
write(*,*) ''
write(*,'(A,/)') ' test interpolator_init success'

write(*,*) '===== test_intepolator_2D ======='
write(*,*) ' ALSO TESTING obtain_interpolator_time_slices'
call test_interpolator_2D(o3)
write(*,*) ' test_interpolator_2D success'
write(*,*) ''

write(*,*) '===== test_intepolator_3D ======='
call test_interpolator_3D(o3)
write(*,*) ' test_interpolator_3D success'
write(*,*) ''

write(*,*) '===== test_intepolator_4D ======='
call test_interpolator_4D(o3)
write(*,*) ' test_interpolator_4D success'
write(*,*) ''
write(*,*) '===== test_intepolator ======='
call test_interpolator(o3)
write(*,'(A,/)') ' test_interpolator success'

write(*,*) '===== test_interpolate_type_eq ====='
call test_interpolate_type_eq()
write(*,*) ' test_interpolate_type_eq success'
write(*,*) ''
write(*,'(A,/)') ' test_interpolate_type_eq success'

write(*,*) '===== test_query_interpolator ====='
call test_query_interpolator()
write(*,*) ' test_query_interpolator success'
write(*,*) ''
write(*,'(A,/)') ' test_query_interpolator success'

write(*,*) '===== test_interpolator_end ====='
call test_interpolator_end(o3)
write(*,*) ' test_interpolator_end success'
write(*,*) ''
write(*,'(A,/)') ' test_interpolator_end success'

call deallocate_arrays()

write(*,*) "*************************************"
!> set data
call set_write_data(nlonlat_in=10, nlonlat_mod_in=10, ntime_in=0, npfull_in=3)
call test_interpolator_init(o3)
write(*,*) '===== test_intepolator_no_time_axis ======='
call test_interpolator_no_time_axis(o3)
write(*,*) ' test_interpolator_no_time_axis success'

contains
!===============================================!
Expand All @@ -153,87 +128,37 @@ subroutine test_interpolator_init(clim_type)

end subroutine test_interpolator_init
!===============================================!
subroutine test_interpolator_2D(clim_type)
subroutine test_interpolator(clim_type)

implicit none
type(interpolate_type), intent(inout) :: clim_type

real(TEST_INTP_KIND_), dimension(nlonlat_mod,nlonlat_mod) :: interp_data !< returns interpolation for first plevel
type(time_type) :: model_time
integer :: itime, i, j, k

do itime=1, ntime
model_time=set_date(1849,1,1+int(clim_time(itime)))
call obtain_interpolator_time_slices(clim_type,model_time)
call interpolator(clim_type, model_time, interp_data, 'ozone')
call unset_interpolator_time_flag(clim_type)
call interpolator(clim_type, model_time, interp_data, 'ozone')

do i=1, 1
do j=1, nlonlat_mod
do k=1, nlonlat_mod
call check_answers(interp_data(k,j), ozone(k,j,i,itime), tol, 'test interpolator_2D')
end do
end do
end do

end do

end subroutine test_interpolator_2D
!===============================================!
subroutine test_interpolator_3D(clim_type)

implicit none
type(interpolate_type), intent(inout) :: clim_type
real(TEST_INTP_KIND_), dimension(nlonlat,nlonlat,nphalf-1) :: interp_data
real(TEST_INTP_KIND_), dimension(nlonlat,nlonlat,nphalf-1,1) :: interp_data !< last column, there is only one field
real(TEST_INTP_KIND_), dimension(nlonlat,nlonlat,nphalf) :: phalf
type(time_type) :: model_time
integer :: itime, i, j, k, l

integer :: itime, i, j, k
phalf(:,:,1)=0.0000_lkind
phalf(:,:,2)=0.0002_lkind
phalf(:,:,3)=0.0004_lkind
phalf(:,:,4)=0.0005_lkind

do itime=1, ntime

model_time=set_date(1849,1,1+int(clim_time(itime)))
phalf(:,:,1)=0.0000_lkind
phalf(:,:,2)=0.0002_lkind
phalf(:,:,3)=0.0004_lkind
phalf(:,:,4)=0.0005_lkind
call interpolator(clim_type, model_time, phalf, interp_data, 'ozone')

!> 4D
call interpolator(clim_type, model_time, phalf, interp_data, 'ozone')
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), tol, 'test interpolator_3D')
call check_answers(interp_data(k,j,i,1), ozone(k,j,i,itime), tol, 'test interpolator_4D')
end do
end do
end do

end do

end subroutine test_interpolator_3D
!===============================================!
subroutine test_interpolator_4D(clim_type)

implicit none

type(interpolate_type) :: clim_type

real(TEST_INTP_KIND_), dimension(nlonlat,nlonlat,nphalf-1,1) :: interp_data !< last column, there is only one field

real(TEST_INTP_KIND_), dimension(nlonlat,nlonlat,nphalf) :: phalf
type(time_type) :: model_time

integer :: itime, i, j, k, l

do itime=1, ntime

model_time=set_date(1849,1,1+int(clim_time(itime)))
phalf(:,:,1)=0.0000_lkind
phalf(:,:,2)=0.0002_lkind
phalf(:,:,3)=0.0004_lkind
phalf(:,:,4)=0.0005_lkind
call interpolator(clim_type, model_time, phalf, interp_data, 'ozone')

!> 3D
call interpolator(clim_type, model_time, phalf, interp_data(:,:,:,1), 'ozone')
do i=1, nphalf-1
do j=1, nlonlat
do k=1, nlonlat
Expand All @@ -242,9 +167,20 @@ subroutine test_interpolator_4D(clim_type)
end do
end do

!> 2D. Also test obtain_interpolator_time_slices
call obtain_interpolator_time_slices(clim_type,model_time)
call interpolator(clim_type, model_time, interp_data(:,:,1,1), 'ozone')
call unset_interpolator_time_flag(clim_type)
call interpolator(clim_type, model_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')
end do
end do

end do

end subroutine test_interpolator_4D
end subroutine test_interpolator
!===============================================!
subroutine test_interpolator_end(clim_type)

Expand All @@ -256,37 +192,51 @@ subroutine test_interpolator_end(clim_type)

end subroutine test_interpolator_end
!===============================================!
subroutine test_interpolator_4D_no_time_axis(clim_type)
subroutine test_interpolator_no_time_axis(clim_type)

implicit none

type(interpolate_type) :: clim_type

real(TEST_INTP_KIND_), dimension(nlonlat,nlonlat,nphalf-1) :: interp_data !< last column, there is only one field
real(TEST_INTP_KIND_), dimension(nlonlat,nlonlat,nphalf-1,1) :: interp_data !< last column, there is only one field

real(TEST_INTP_KIND_), dimension(nlonlat,nlonlat,nphalf) :: phalf
type(time_type) :: model_time
integer :: i, j, k

phalf(:,:,1)=0.0000_lkind
phalf(:,:,2)=0.0002_lkind
phalf(:,:,3)=0.0004_lkind
phalf(:,:,4)=0.0005_lkind
model_time=set_date(1849,1,1+int(clim_time(1)))
call read_data(clim_type, 'ozone', interp_data, 1, 1, Time=model_time)

!> 4D
call interpolator(clim_type, phalf, interp_data, 'ozone')
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,1), tol, 'test interpolator_4D_no_time_axis')
end do
end do
end do

!> 3D
call interpolator(clim_type, phalf, interp_data(:,:,:,1), 'ozone')
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,1), tol, 'test interpolator_3D_no_time_axis')
end do
end do
end do

!> 2D
call interpolator(clim_type, interp_data(:,:,1,1), 'ozone')
do j=1, nlonlat
do k=1, nlonlat
call check_answers(interp_data(k,j,1,1), ozone(k,j,1,1), tol, 'test interpolator_2D_no_time_axis')
end do
end do

!do i=1, 1!nphalf-1
! do j=1, nlonlat
! do k=1, nlonlat
! if( interp_data(k,j,i).ne.ozone(k,j,i,1) ) then
! write(*,*) k,j,interp_data(k,j,i), ozone(k,j,i,1)
! !call mpp_error(FATAL, 'wrong')
! end if
! end do
! end do
!end do

end subroutine test_interpolator_4D_no_time_axis
end subroutine test_interpolator_no_time_axis
!===============================================!
subroutine test_interpolate_type_eq

Expand All @@ -295,7 +245,7 @@ subroutine test_interpolate_type_eq
type(interpolate_type) :: o3_copy

o3_copy = o3
call test_interpolator_3D(o3_copy)
call test_interpolator(o3_copy)

end subroutine test_interpolate_type_eq
!===============================================!
Expand Down Expand Up @@ -336,4 +286,4 @@ end subroutine check_answers
!===============================================!
#include "test_interpolator_write_climatology.inc"

end program test_interpolator
end program test_interpolator_mod
2 changes: 1 addition & 1 deletion test_fms/interpolator/test_interpolator2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ mkdir -p INPUT
test_expect_success "test_interpolator2 r4 unit tests" 'mpirun -n 1 ./test_interpolator2_r4'
test_expect_success "test_interpolator2 r8 unit tests" 'mpirun -n 1 ./test_interpolator2_r8'

rm -rf INPUT *.nc # remove any leftover io files to save space
#rm -rf INPUT *.nc # remove any leftover io files to save space

test_done
Loading

0 comments on commit e858037

Please sign in to comment.