Skip to content

Commit

Permalink
Fix potential array OOB error when computing the ol1 and ol2 GWDO fields
Browse files Browse the repository at this point in the history
For MPAS grid cells that are small enough that the dimensions of their bounding
boxes (nx and ny) in the 30" terrain dataset are less than four, loop bounds of
0 may be used in the computation of the ol1 and ol2 GWDO fields. A lower bound
of zero would result in an access below the allocated lower bound for the 'box'
array in the mpas_init_atm_gwd module, while an upper bound of zero (with a
positive lower bound) would result in a division by zero (as 'nt' would never be
incremented).

The correction applied in this commit is to enforce a lower bound of 1 to both
upper and lower loop bounds in the computation of ol1 and ol2. The resulting ol1
and ol2 fields may not contain correct values, but it's likely the YSU GWDO
scheme will not be very active for such small grid cells anyway.
  • Loading branch information
mgduda committed Oct 21, 2021
1 parent 51d5624 commit f15fb64
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core_init_atmosphere/mpas_init_atm_gwd.F
Expand Up @@ -892,7 +892,7 @@ real (kind=RKIND) function get_ol1()
nw = 0
nt = 0

do j=ny/4,3*ny/4
do j=max(ny/4,1),max((3*ny)/4,1)
do i=1,nx
if (box(i,j) > hc) nw = nw + 1
nt = nt + 1
Expand Down Expand Up @@ -926,7 +926,7 @@ real (kind=RKIND) function get_ol2()
nt = 0

do j=1,ny
do i=nx/4,3*nx/4
do i=max(nx/4,1),max((3*nx)/4,1)
if (box(i,j) > hc) nw = nw + 1
nt = nt + 1
end do
Expand Down

0 comments on commit f15fb64

Please sign in to comment.