Skip to content

Commit

Permalink
Baseline unit test for routine 'read_mask'. Fix doxygen in
Browse files Browse the repository at this point in the history
that routine.

Fixes ufs-community#1000.
  • Loading branch information
George Gayno committed Jan 9, 2025
1 parent f272d8c commit 1bade53
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sorc/orog_mask_tools.fd/orog.fd/io_utils.F90
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ end subroutine write_mask_netcdf
!> Read the land mask file
!!
!! @param[in] merge_file path
!! @param[in] slm Land-sea mask.
!! @param[in] land_frac Land fraction.
!! @param[in] lake_frac Lake fraction
!! @param[out] slm Land-sea mask.
!! @param[out] land_frac Land fraction.
!! @param[out] lake_frac Lake fraction
!! @param[in] im 'i' dimension of a model grid tile.
!! @param[in] jm 'j' dimension of a model grid tile.
!! @author George Gayno NOAA/EMC
Expand Down
8 changes: 8 additions & 0 deletions tests/orog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ execute_process( COMMAND ${CMAKE_COMMAND} -E copy
execute_process( COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/data/C12_grid.tile1.nc ${CMAKE_CURRENT_BINARY_DIR}/C12_grid.tile1.nc)

# Note, the "read_mask" test expects this file.
execute_process( COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/data/C48.mx500.tile1.nc ${CMAKE_CURRENT_BINARY_DIR}/C48.mx500.tile1.nc)

add_executable(ftst_ll2xyz ftst_ll2xyz.F90)
add_test(NAME orog-ftst_ll2xyz COMMAND ftst_ll2xyz)
target_link_libraries(ftst_ll2xyz orog_lib)
Expand Down Expand Up @@ -86,3 +90,7 @@ target_link_libraries(ftst_read_mdl_dims orog_lib)
add_executable(ftst_read_mdl_grid_file ftst_read_mdl_grid_file.F90)
add_test(NAME orog-ftst_read_mdl_grid_file COMMAND ftst_read_mdl_grid_file)
target_link_libraries(ftst_read_mdl_grid_file orog_lib)

add_executable(ftst_read_mask ftst_read_mask.F90)
add_test(NAME orog-ftst_read_mask COMMAND ftst_read_mask)
target_link_libraries(ftst_read_mask orog_lib)
Binary file added tests/orog/data/C48.mx500.tile1.nc
Binary file not shown.
82 changes: 82 additions & 0 deletions tests/orog/ftst_read_mask.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
program read_mask_test

! Test routine 'read_mask' by reading a sample C48 global
! uniform tile file.
!
! Author George Gayno NCEP/EMC

use io_utils, only : read_mask

implicit none

character(len=20) :: merge_file

integer, parameter :: im=48
integer, parameter :: jm=48
integer, parameter :: chk_pts = 4
integer :: i, j, ij

real, parameter :: EPSILON = 0.001
real :: land_frac(im,jm)
real :: lake_frac(im,jm)
real :: slm(im,jm)
real :: land_frac_chk(chk_pts)
real :: lake_frac_chk(chk_pts)
real :: slm_chk(chk_pts)

type :: indices
integer :: i
integer :: j
end type indices

type(indices) :: idx(chk_pts)

! The i/j indicies of the check points.

data idx%i /1,29,47,48/
data idx%j /1,25,23,48/

! The expected values of the check points.

data land_frac_chk /0.58463, 0.8377, 0.0, 0.415374/
data lake_frac_chk /0.0, 0.0, 1.0, 0.0/
data slm_chk /1.0, 1.0, 0.0, 0.0/

print*,"- Starting test of routine read_mask."

merge_file = "./C48.mx500.tile1.nc"

! Initialize output fields to flag value.

land_frac = -999.9
lake_frac = -999.9
slm = -999.9

call read_mask(merge_file,slm,land_frac,lake_frac,im,jm)

! All flag values should have been replaced. All fields
! should have values greater than zero.

do j = 1, jm
do i = 1, im
if (land_frac(i,j) < 0.0) stop 3
if (lake_frac(i,j) < 0.0) stop 5
if (slm(i,j) < 0.0) stop 7
enddo
enddo

! Check some points against expected values.

do ij = 1, chk_pts
i = idx(ij)%i
j = idx(ij)%j
if (abs(land_frac(i,j)-land_frac_chk(ij)) > EPSILON) stop 12
if (abs(lake_frac(i,j)-lake_frac_chk(ij)) > EPSILON) stop 15
if (abs(slm(i,j)-slm_chk(ij)) > EPSILON) stop 18
enddo

print*,"OK"

print*,"SUCCESS"

end program read_mask_test

0 comments on commit 1bade53

Please sign in to comment.