Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test and bug fix for chgres_cube.fd/search_util.F90 #436

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add remaining tests. Add some comments.
Fixes #279
  • Loading branch information
GeorgeGayno-NOAA committed Apr 14, 2021
commit c65150ce5afd81e0d77148d937a314fc7e494a3c
102 changes: 80 additions & 22 deletions tests/chgres_cube/ftst_search_util.F90
Original file line number Diff line number Diff line change
@@ -1,53 +1,62 @@
program test_search_util

! Test search_util using a simple 3x3 fv3 tile. Two types
! of tests are performed. First, a missing value is
! replaced with a valid neighboring value. Second, a missing
! value is replaced by a default value. This can happen
! for an isolated island located far from a valid neighbor.
edwardhartnett marked this conversation as resolved.
Show resolved Hide resolved

use mpi
use esmf
use search_util

implicit none

! Test uses a simple 3x3 fv3 tile.

integer, parameter :: idim = 3
integer, parameter :: jdim = 3
integer, parameter :: tile = 1
integer, parameter :: num_default_tests = 21

integer :: field_num, ierr, i
integer(esmf_kind_i8) :: mask(idim,jdim)
integer(esmf_kind_i8) :: mask_search1(idim,jdim)
integer(esmf_kind_i8) :: mask_search2(idim,jdim)
integer(esmf_kind_i8) :: mask_default(idim,jdim)
integer :: default_field_num(num_default_tests)

real(esmf_kind_r8) :: field(idim,jdim)
real(esmf_kind_r8) :: default_field_val(num_default_tests)
real(esmf_kind_r8) :: field_default(idim,jdim)
real(esmf_kind_r8) :: field_updated(idim,jdim)
real(esmf_kind_r8) :: field_search1(idim,jdim)
real(esmf_kind_r8) :: field_search2(idim,jdim)
real(esmf_kind_r8) :: latitude(idim,jdim)
real(esmf_kind_r8) :: terrain_land(idim,jdim)
real(esmf_kind_r8) :: soilt_climo(idim,jdim)

!--------------------------------------------------------
! These variables are used to test the 'default'
! search routine option (i.e., when the search
! fails, a default must be used)

integer, parameter :: num_default_tests = 21
integer :: default_field_num(num_default_tests)
real(esmf_kind_r8) :: default_field_val(num_default_tests)
!--------------------------------------------------------

! Definition of the mask. The '1' indicates an isolated
! island or lake depending on the field type.

data mask /0, 0, 0, 0, 1, 0, 0, 0, 0/
data mask_default /0, 0, 0, 0, 1, 0, 0, 0, 0/

data latitude /-30.0, -30.0, -30.0, 0., 0., 0., 25.0, 25.0, 25.0/

data terrain_land /0., 0., 0., 0., 75.0, 0., 0., 0., 0./

data soilt_climo /0., 0., 0., 0., 2., 0., 0., 0., 0./
data soilt_climo /0., 0., 0., 0., 2., 0., 0., 0., 0./ ! soil type

! The field values input to the search routine. The
! flag value indicates an unmapped point that must
! flag value (-9999.9) indicates an unmapped point that must
! be replaced.

data field/0., 0., 0., 0., -9999.9, 0., 0., 0., 0./
! The complete list of field numbers the search
! routine works for.
data field_default/0., 0., 0., 0., -9999.9, 0., 0., 0., 0./

! The complete list of field numbers the default search
! works for.

data default_field_num /0, 1, 7, 11, 21, &
30, 65, 66, 83, 85, &
Expand All @@ -56,36 +65,85 @@ program test_search_util

! The field value that should be returned by the
! search routine for each field value. If the returned
! value does not match, this test fails.
! value does not match this value, the test fails.

data default_field_val /0.0, 1.0, 75.0, 300.0, 265.0, &
30.0, 0.0, 0.0, 0.01, 280.0, &
0.18, 0.0, 1.0, 0.0, 2.0, &
-99999.9, 0.5, 0.5, 0.5, 1.0, 11.0/

!--------------------------------------------------------
! These variables are used for the two search option
! tests. Both tests use vegetation greenness. For this
! test, the logic is is independent of the field type.
!--------------------------------------------------------

! Test 1 - The missing value at (2,2) should be replaced
! with the valid value at (1,1).

data mask_search1 /1, 0, 0, 0, 1, 0, 0, 0, 0/
data field_search1 /.88, 0., 0., 0., -9999.9, 0., 0., 0., 0./

! Test 2 - The missing value at (3,3) should be replaced
! with the valid value at (2,2).

data mask_search2 /0, 0, 0, 0, 1, 0, 0, 0, 1/
data field_search2 /0., 0., 0., 0., .88, 0., 0., 0., -9999.9/

print*,"Starting test of search util."

call mpi_init(ierr)

print*,'RUN TESTS TO CHECK DEFAULT LOGIC'
print*,'Run test 1 to check search logic.'

field_num = 226 ! veg greenness
field_updated = field_search1

call search (field_updated, mask_search1, idim, jdim, tile, field_num)

if (field_updated(2,2) /= field_updated(1,1)) then
print*,'TEST FAILED ',field_updated(2,2), field_updated(1,1)
stop 2
endif

print*,'Run test 2 to check search logic.'

field_num = 226
field_updated = field_search2

call search (field_updated, mask_search2, idim, jdim, tile, field_num)

if (field_updated(2,2) /= field_updated(3,3)) then
print*,'TEST FAILED ',field_updated(2,2), field_updated(3,3)
stop 3
else
print*,'OK'
endif

print*,'Run tests to check default logic.'

do i = 1, num_default_tests

field_num = default_field_num(i)
field_updated = field
field_updated = field_default

print*,'CHECK DEFAULT LOGIC FOR FIELD NUMBER ',field_num

call search (field_updated, mask, idim, jdim, tile, field_num, latitude, terrain_land, &
soilt_climo)
call search (field_updated, mask_default, idim, jdim, tile, field_num, &
latitude, terrain_land, soilt_climo)

if (field_updated(2,2) /= default_field_val(i)) then
print*,'TEST FAILED ',field_updated(2,2), default_field_val(i)
stop 2
stop 4
else

print*,'OK'
endif

enddo

call mpi_finalize(ierr)

print*,'DONE'
print*,"SUCCESS!"

end program test_search_util