Skip to content

Commit

Permalink
Actually set the fill value and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashao committed Feb 24, 2025
1 parent bc2a91f commit 8380b62
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/framework/MOM_diag_buffers.F90
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ subroutine set_fill_value(this, fill_value)
class(diag_buffer_base), intent(inout) :: this !< The diagnostic buffer
real, intent(in) :: fill_value !< The fill value to use when growing the buffer [arbitrary]

this%fill_value = fill_value
end subroutine set_fill_value

!> Mark a slot in the buffer as unused based on a diagnostic id. For example,
Expand Down Expand Up @@ -249,6 +250,7 @@ function diag_buffer_unit_tests_2d(verbose) result(fail)
write(stdout,*) '==== MOM_diag_buffers: diag_buffers_unit_tests_2d ==='
fail = fail .or. new_buffer_2d()
fail = fail .or. grow_buffer_2d()
fail = fail .or. fill_value_2d()
fail = fail .or. store_buffer_2d()
fail = fail .or. reuse_buffer_2d()

Expand Down Expand Up @@ -289,6 +291,25 @@ function grow_buffer_2d() result(local_fail)
if (verbose) write(stdout,*) "grow_buffer_2d: ", local_fail
end function grow_buffer_2d

!> Test that growing new buffer fills the array with a set fill value
function fill_value_2d() result(local_fail)
type(diag_buffer_2d) :: buffer
logical :: local_fail !< True if any of the unit tests fail
integer, parameter :: is=1, ie=2, js=3, je=6
real, parameter :: fill_value = -123.456
integer :: i


local_fail = .false.

call buffer%set_horizontal_extents(is=is, ie=ie, js=js, je=je)
call buffer%set_fill_value(fill_value)
! Grow the buffer 3 times
call buffer%grow()
if (any(buffer%buffer(1)%field(:,:) /= fill_value)) local_fail = .true.
if (verbose) write(stdout,*) "fill_value_2d: ", local_fail
end function fill_value_2d

!> Test storing a buffer based on a unique id
function store_buffer_2d() result(local_fail)
type(diag_buffer_2d) :: buffer
Expand Down Expand Up @@ -363,6 +384,7 @@ function diag_buffer_unit_tests_3d(verbose) result(fail)
write(stdout,*) '==== MOM_diag_buffers: diag_buffers_unit_tests_3d ==='
fail = fail .or. new_buffer_3d()
fail = fail .or. grow_buffer_3d()
fail = fail .or. fill_value_3d()
fail = fail .or. store_buffer_3d()
fail = fail .or. reuse_buffer_3d()

Expand Down Expand Up @@ -405,6 +427,25 @@ function grow_buffer_3d() result(local_fail)
if (verbose) write(stdout,*) "grow_buffer_3d: ", local_fail
end function grow_buffer_3d

!> Test that growing new buffer fills the array with a set fill value
function fill_value_3d() result(local_fail)
type(diag_buffer_3d) :: buffer
logical :: local_fail !< True if any of the unit tests fail
integer, parameter :: is=1, ie=2, js=3, je=6
real, parameter :: fill_value = -123.456
integer :: i


local_fail = .false.

call buffer%set_horizontal_extents(is=is, ie=ie, js=js, je=je)
call buffer%set_fill_value(fill_value)
! Grow the buffer 3 times
call buffer%grow()
if (any(buffer%buffer(1)%field(:,:,:) /= fill_value)) local_fail = .true.
if (verbose) write(stdout,*) "fill_value_3d: ", local_fail
end function fill_value_3d

!> Test storing a buffer based on a unique id
function store_buffer_3d() result(local_fail)
type(diag_buffer_3d) :: buffer
Expand Down

0 comments on commit 8380b62

Please sign in to comment.