Skip to content

Commit

Permalink
Baseline unit test for routine get_xnsum3.
Browse files Browse the repository at this point in the history
  • Loading branch information
George Gayno committed Dec 17, 2024
1 parent 79c5d00 commit d4ba274
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/orog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# George Gayno, Ed Hartnett

if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|IntelLLVM)$")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -r8")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -r8 -warn unused")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-0 -fdefault-real-8")
endif()
Expand Down Expand Up @@ -49,3 +49,7 @@ target_link_libraries(ftst_get_xnsum orog_lib)
add_executable(ftst_get_xnsum2 ftst_get_xnsum2.F90)
add_test(NAME orog-ftst_get_xnsum2 COMMAND ftst_get_xnsum2)
target_link_libraries(ftst_get_xnsum2 orog_lib)

add_executable(ftst_get_xnsum3 ftst_get_xnsum3.F90)
add_test(NAME orog-ftst_get_xnsum3 COMMAND ftst_get_xnsum3)
target_link_libraries(ftst_get_xnsum3 orog_lib)
74 changes: 74 additions & 0 deletions tests/orog/ftst_get_xnsum3.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
program check_get_xnsum3

! Unit test for routine get_xnsum3, which counts the
! number of high-resolution orography points within a
! model grid box, and counts the number of high-resolution
! points higher than a critical height. The critical
! height is passed into routine get_xnsum3, whereas in
! get_xnsum2 it is computed.

use orog_utils, only : get_xnsum3

implicit none

integer, parameter :: imn=360 ! i-dimension of high-res grid
integer, parameter :: jmn=181 ! j-dimension of high-res grid

integer :: j
integer :: zavg(imn,jmn) ! High-res grid terrain

real :: delxn=360.0/float(imn) ! Resolution of high-res grid in degrees.
real :: glat(jmn) ! Latitude of each high-res grid row in degrees.
real :: lon1,lat1,lon2,lat2,hc
real :: xnsum1,xnsum2

! Variables holding the expected test results.

integer :: expected_xnsum1, expected_xnsum2

data expected_xnsum1 /4/ ! Expected number of high-res pts in model
! grid box that are above the critical height.
data expected_xnsum2 /16/ ! Expected total number of high-res pts in model grid box.

print*,"Begin test of routine get_xnsum2."

! The high-res grid is a global one-degree lat/lon grid. Point (1,1)
! is the south pole/greenwich.

do j = 1, jmn
glat(j) = -90.0 + float(j-1) * delxn
enddo

! Bounds of model grid box - straddles equator/greenwich.
! There are 16 high-res points located within the model
! box. The i/j range of these 16 points is i=359,360,1,2
! and j=0,91,92,93.

lon1 = -2.5 ! in degrees.
lon2 = 2.5
lat1 = -1.5
lat2 = 1.5

! Initialize high-res orography. Half of the points
! within the model grid box are at sea level, one quarter
! are at 500 meters and one quarter are at 1000 meters.
! The critical height was chosen as 700 meters. So,
! four points should be above the critical value.

zavg = -999 ! Flag value for sea level.
zavg(359,90:93) = 1000
zavg(360,90:93) = 500

hc = 700.0 ! Critical height in meters.

call get_xnsum3(lon1,lat1,lon2,lat2,imn,jmn, &
glat,zavg,delxn,xnsum1,xnsum2,hc)

if (nint(xnsum1) /= expected_xnsum1) stop 2
if (nint(xnsum2) /= expected_xnsum2) stop 4

print*,"OK"

print*,"SUCCESS"

end program check_get_xnsum3

0 comments on commit d4ba274

Please sign in to comment.