Skip to content

Commit

Permalink
Finish unit test for function get_xnsum.
Browse files Browse the repository at this point in the history
  • Loading branch information
George Gayno committed Dec 13, 2024
1 parent d39963a commit 4f4de62
Showing 1 changed file with 55 additions and 61 deletions.
116 changes: 55 additions & 61 deletions tests/orog/ftst_get_xnsum.F90
Original file line number Diff line number Diff line change
@@ -1,121 +1,115 @@
program check_get_xnsum

! Unit test for function get_xnsum, which computes the
! the number of high-resolution orography data points
! within a model grid box that are above the average
! terrain height.

use orog_utils, only : get_xnsum

implicit none

integer, parameter :: imn=360
integer, parameter :: jmn=181
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)
integer :: zslm(imn,jmn)
integer :: zavg(imn,jmn) ! High-res grid terrain
integer :: zslm(imn,jmn) ! High-res grid land mask

real :: delxn=360.0/float(imn)
real :: glat(jmn)
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
real :: xnsum

print*,"Begin test."
print*,"Begin test of function get_xnsum"

! Set up a 'high-res' 1-degree grid.
! 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
print*,'j lat ',j,glat(j)
enddo

! Bounds of model grid box - straddles equator/greenwich.
! There are approximately 16 high-res points located within
! the model box.

lon1 = -2.5
lon2 = 2.5
lat1 = -1.5
lat2 = 1.5

! First test point. The high-res grid is all ocean. Since all points in
! the model grid box will be sea level, there will be no points
! higher than the average of 0 meters.

print*,"Test point 1."

zslm = 0 ! all water
zavg = -999 ! all sea level

! Bounds of model grid box - straddles greenwich.

lon1 = -2.5
lon2 = 2.5
lat1 = -1.5
lat2 = 1.5
zslm = 0 ! high-res grid all water
zavg = -999 ! high-res grid all sea level

xnsum = get_xnsum(lon1,lat1,lon2,lat2,imn,jmn, &
glat, zavg, zslm, delxn)

if (nint(xnsum) /= 0) stop 2

! Second test point. All high-res points are land with an elevation
! of 50 meters. There will be no points higher than the average.

print*,"Test point 2."

zslm = 1 ! all land
zslm = 1 ! high-res grid all land
zavg = 50 ! constant elevation of 50 meters.

! Bounds of model grid box - straddles greenwich.

lon1 = -2.5
lon2 = 2.5
lat1 = -1.5
lat2 = 1.5

xnsum = get_xnsum(lon1,lat1,lon2,lat2,imn,jmn, &
glat, zavg, zslm, delxn)

if (nint(xnsum) /= 0) stop 4

print*,"Test point 3."
! Third test point. All high-res points are land. One point is
! 100 meters, the rest are 50 meters. Therefore, there should
! be one point higher than the average.

zslm = 1 ! all land
zavg = 50 ! constant elevation of 50 meters.
zavg(359,91) = 100

! Bounds of model grid box - straddles greenwich.
print*,"Test point 3."

lon1 = -2.5
lon2 = 2.5
lat1 = -1.5
lat2 = 1.5
zslm = 1 ! all land
zavg = 50 ! initialize elevation to 50 meters.
zavg(359,91) = 100 ! one point within the model box is 100 meters.

xnsum = get_xnsum(lon1,lat1,lon2,lat2,imn,jmn, &
glat, zavg, zslm, delxn)

if (nint(xnsum) /= 1) stop 6

print*,"Test point 4."

zslm = 0 ! all water
zavg = -999 ! set to sea level.
zavg(2,93) = 20 ! this represents an inland lake above sea level.
! Fourth test point. All high-res points are water. One point is
! 20 meters, which represents an inland lake. The other points
! are ocean. Therefore, there should be one point higher than the average.

! Bounds of model grid box - straddles greenwich.
print*,"Test point 4."

lon1 = -2.5
lon2 = 2.5
lat1 = -1.5
lat2 = 1.5
zslm = 0 ! all water
zavg = -999 ! initialize to sea level.
zavg(2,93) = 20 ! this represents an inland lake above sea level.

xnsum = get_xnsum(lon1,lat1,lon2,lat2,imn,jmn, &
glat, zavg, zslm, delxn)

if (nint(xnsum) /= 1) stop 8

print*,"Test point 5."

zslm = 0 ! all water
zavg = -999 ! set to sea level.
zslm(1:2,90:93) = 1 ! half points in grid box land
zavg(1,90:93) = 25 ! land points above sea level
zavg(2,90) = 100 ! land points above sea level
zavg(2,91) = 110 ! land points above sea level
zavg(2,92) = 107 ! land points above sea level
zavg(2,93) = 207 ! land points above sea level
! Fifth test point. Half of the high-res points within the grid
! box are land and half are water. Four high-res points are
! above the average.

! Bounds of model grid box - straddles greenwich.
print*,"Test point 5."

lon1 = -2.5
lon2 = 2.5
lat1 = -1.5
lat2 = 1.5
zslm = 0 ! Initialize to all water
zavg = -999 ! Initialize to sea level.
zslm(1:2,90:93) = 1 ! Half the points in the grid box are land.
zavg(1,90:93) = 25 ! Set the elevation at the
zavg(2,90) = 100 ! land points so that
zavg(2,91) = 110 ! four points are above the average.
zavg(2,92) = 107
zavg(2,93) = 207

xnsum = get_xnsum(lon1,lat1,lon2,lat2,imn,jmn, &
glat, zavg, zslm, delxn)
Expand Down

0 comments on commit 4f4de62

Please sign in to comment.