Skip to content

Commit

Permalink
add comments to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mlee03 authored and mlee03 committed Aug 11, 2023
1 parent 86e17f0 commit a361575
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
47 changes: 30 additions & 17 deletions test_fms/interpolator/test_interpolator2.F90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!***********************************************************************
!***********************************************************************
!* GNU Lesser General Public License
!*
!* This file is part of the GFDL Flexible Modeling System (FMS).
Expand Down Expand Up @@ -47,7 +47,7 @@ program test_interpolator2
real(r8_kind), parameter :: tol=1.e-5_r8_kind !< the interpolation methods are not perfect.
!! Will not get perfectly agreeing answers

!> climatology related variables and arrays (holding made up data)
!> climatology related variables and arrays (made up data)
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 @@ -81,27 +81,22 @@ program test_interpolator2
!> test interpolator_init
write(*,*) '===== test_interpolator_init ====='
call test_interpolator_init(o3)
write(*,'(A,/)') 'test interpolator_init success'

!> test interpolator 2D-4D
write(*,*) '===== test_intepolator ======='
call test_interpolator(o3)
write(*,'(A,/)') 'test_interpolator success'

!> test interpolate_type_eq
write(*,*) '===== test_interpolate_type_eq ====='
call test_interpolate_type_eq()
write(*,'(A,/)') 'test_interpolate_type_eq success'

!> test query_interpolator
write(*,*) '===== test_query_interpolator ====='
call test_query_interpolator()
write(*,'(A,/)') 'test_query_interpolator success'

!> test interpolator end
write(*,*) '===== test_interpolator_end ====='
call test_interpolator_end(o3)
write(*,'(A,/)') 'test_interpolator_end success'

!> deallocate all arrays used to write the .nc file and used for model coordinates
call deallocate_arrays()
Expand All @@ -113,12 +108,11 @@ program test_interpolator2
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
!===============================================!
!> test interpolator init
subroutine test_interpolator_init(clim_type)

!> interopolator_init initializes the interpolate_type after reading in the
!! climatology data. The required arguments are clim_type, file_name, lonb_mod, latb_mod
!! where lonb_mod and latb_mod contain the model longitude and latitude values on the grid.
Expand All @@ -134,6 +128,10 @@ end subroutine test_interpolator_init
!===============================================!
subroutine test_interpolator(clim_type)

!> call the variants of interpolator (4D-2d) that interpolates data at a given time-point
!! The tests here do not test the "no_axis" interpolator routines
!! This subroutine also tests obtain_interpolator_time_slices for the 2D case.

implicit none

type(interpolate_type), intent(inout) :: clim_type
Expand All @@ -151,7 +149,7 @@ subroutine test_interpolator(clim_type)

model_time=set_date(1849,1,1+int(clim_time(itime)))

!> 4D
!> test interpolator_4D_r4/8
call interpolator(clim_type, model_time, phalf, interp_data, 'ozone')
do i=1, npfull
do j=1, nlonlat
Expand All @@ -161,7 +159,7 @@ subroutine test_interpolator(clim_type)
end do
end do

!> 3D
!> test interpolator_3_r4/8
call interpolator(clim_type, model_time, phalf, interp_data(:,:,:,1), 'ozone')
do i=1, npfull
do j=1, nlonlat
Expand All @@ -171,11 +169,18 @@ subroutine test_interpolator(clim_type)
end do
end do

!> 2D. Also test obtain_interpolator_time_slices
!> test interpolator_2D_r4/8
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

!> 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')
Expand All @@ -188,6 +193,8 @@ end subroutine test_interpolator
!===============================================!
subroutine test_interpolator_end(clim_type)

!> This subroutine tests interpolator_end

implicit none

type(interpolate_type) :: clim_type
Expand All @@ -198,12 +205,13 @@ end subroutine test_interpolator_end
!===============================================!
subroutine test_interpolator_no_time_axis(clim_type)

!> This subroutine tests the variants (42-2D) of interpolator_no_time_axis

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
integer :: i, j, k

Expand All @@ -212,7 +220,7 @@ subroutine test_interpolator_no_time_axis(clim_type)
phalf(:,:,3)=0.0004_lkind
phalf(:,:,4)=0.0005_lkind

!> 4D
!> test interpolator_4D_no_time_axis_r4/8
call interpolator(clim_type, phalf, interp_data, 'ozone')
do i=1, nphalf-1
do j=1, nlonlat
Expand All @@ -222,7 +230,7 @@ subroutine test_interpolator_no_time_axis(clim_type)
end do
end do

!> 3D
!> test interpolator_3D_no_time_axis_r4/8
call interpolator(clim_type, phalf, interp_data(:,:,:,1), 'ozone')
do i=1, nphalf-1
do j=1, nlonlat
Expand All @@ -232,7 +240,7 @@ subroutine test_interpolator_no_time_axis(clim_type)
end do
end do

!> 2D
!> test interpolator_2D_no_time_axis_r4/8
call interpolator(clim_type, interp_data(:,:,1,1), 'ozone')
do j=1, nlonlat
do k=1, nlonlat
Expand All @@ -244,6 +252,9 @@ end subroutine test_interpolator_no_time_axis
!===============================================!
subroutine test_interpolate_type_eq

!> This subroutine tests interpolaote_type_eq (assignment = operator)
!! The success of "=" is insured by checking to see if interpolation with o3_copy succeds.

implicit none

type(interpolate_type) :: o3_copy
Expand All @@ -255,6 +266,8 @@ end subroutine test_interpolate_type_eq
!===============================================!
subroutine test_query_interpolator

!> This subroutne tests query_interpolator

implicit none

character(100), parameter :: answer_field_name='ozone'
Expand Down
21 changes: 21 additions & 0 deletions test_fms/interpolator/test_interpolator_write_climatology.inc
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
!***********************************************************************
!* GNU Lesser General Public License
!*
!* This file is part of the GFDL Flexible Modeling System (FMS).
!*
!* FMS is free software: you can redistribute it and/or modify it under
!* the terms of the GNU Lesser General Public License as published by
!* the Free Software Foundation, either version 3 of the License, or (at
!* your option) any later version.
!*
!* FMS is distributed in the hope that it will be useful, but WITHOUT
!* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
!* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
!* for more details.
!*
!* You should have received a copy of the GNU Lesser General Public
!* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
!***********************************************************************

!> This file contains subroutines that initialize data and write out the climatology file.

subroutine write_climatology_file

implicit none
Expand Down

0 comments on commit a361575

Please sign in to comment.