Skip to content

Commit

Permalink
Move new routine 'ftst_fill_regional_halo' to utils.F90
Browse files Browse the repository at this point in the history
to allow for using it in unit tests. Create simple unit
test for that routine.

Fixes #105
  • Loading branch information
GeorgeGayno-NOAA committed Aug 26, 2021
1 parent 1ec6689 commit f87f1f5
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 36 deletions.
36 changes: 0 additions & 36 deletions sorc/grid_tools.fd/filter_topo.fd/filter_topo.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1153,42 +1153,6 @@ subroutine fill_cubic_grid_halo(data, data2, halo, ioff, joff, sign1, sign2)

end subroutine fill_cubic_grid_halo

!> This routine extrapolate geolat_c and geolon_c halo points for the
!! regional standalone grid. Halo points are needed for dxc and dyc
!! calculation.
!!
!! @param[in,out] data - field to be extrapolated
!! @param[in] halo - number of halo rows/columns
!! @author Ratko Vasic (NCEP/EMC)
subroutine fill_regional_halo(data, halo)
integer, intent(in) :: halo
real, dimension(1-halo:,1-halo:,:), intent(inout) :: data
integer :: h, i_st, i_ed, j_st, j_ed

i_st=lbound(data,1)+halo
i_ed=ubound(data,1)-halo
j_st=lbound(data,2)+halo
j_ed=ubound(data,2)-halo

do h = 1, halo
data(i_st:i_ed, j_st-1 , :) = 2* data(i_st:i_ed, j_st , :) - data(i_st:i_ed, j_st+1 , :)! north
data(i_st:i_ed, j_ed+1 , :) = 2* data(i_st:i_ed, j_ed , :) - data(i_st:i_ed, j_ed-1 , :)! south
data(i_st-1 , j_st:j_ed, :) = 2* data(i_st , j_st:j_ed, :) - data(i_st+1 , j_st:j_ed, :)! east
data(i_ed+1 , j_st:j_ed, :) = 2* data(i_ed , j_st:j_ed, :) - data(i_ed-1 , j_st:j_ed, :)! west

data(i_st-1, j_st-1, :) = (data(i_st-1, j_st, :) + data(i_st, j_st-1, :))*0.5 !NW Corner
data(i_ed+1, j_st-1, :) = (data(i_ed+1, j_st, :) + data(i_ed, j_st-1, :))*0.5 !NE Corner
data(i_st-1, j_ed+1, :) = (data(i_st-1, j_ed, :) + data(i_st, j_ed+1, :))*0.5 !SW Corner
data(i_ed+1, j_ed+1, :) = (data(i_ed+1, j_ed, :) + data(i_ed, j_ed+1, :))*0.5 !SE Corner

i_st=i_st-1
i_ed=i_ed+1
j_st=j_st-1
j_ed=j_ed+1
enddo

end subroutine fill_regional_halo

!> ???
!!
!! @param[in] is ???
Expand Down
36 changes: 36 additions & 0 deletions sorc/grid_tools.fd/filter_topo.fd/utils.F90
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,42 @@ subroutine read_namelist

end subroutine read_namelist

!> This routine extrapolate geolat_c and geolon_c halo points for the
!! regional standalone grid. Halo points are needed for dxc and dyc
!! calculation.
!!
!! @param[in,out] data - field to be extrapolated
!! @param[in] halo - number of halo rows/columns
!! @author Ratko Vasic (NCEP/EMC)
subroutine fill_regional_halo(data, halo)
integer, intent(in) :: halo
real, dimension(1-halo:,1-halo:,:), intent(inout) :: data
integer :: h, i_st, i_ed, j_st, j_ed

i_st=lbound(data,1)+halo
i_ed=ubound(data,1)-halo
j_st=lbound(data,2)+halo
j_ed=ubound(data,2)-halo

do h = 1, halo
data(i_st:i_ed, j_st-1 , :) = 2* data(i_st:i_ed, j_st , :) - data(i_st:i_ed, j_st+1 , :)! north
data(i_st:i_ed, j_ed+1 , :) = 2* data(i_st:i_ed, j_ed , :) - data(i_st:i_ed, j_ed-1 , :)! south
data(i_st-1 , j_st:j_ed, :) = 2* data(i_st , j_st:j_ed, :) - data(i_st+1 , j_st:j_ed, :)! east
data(i_ed+1 , j_st:j_ed, :) = 2* data(i_ed , j_st:j_ed, :) - data(i_ed-1 , j_st:j_ed, :)! west

data(i_st-1, j_st-1, :) = (data(i_st-1, j_st, :) + data(i_st, j_st-1, :))*0.5 !NW Corner
data(i_ed+1, j_st-1, :) = (data(i_ed+1, j_st, :) + data(i_ed, j_st-1, :))*0.5 !NE Corner
data(i_st-1, j_ed+1, :) = (data(i_st-1, j_ed, :) + data(i_st, j_ed+1, :))*0.5 !SW Corner
data(i_ed+1, j_ed+1, :) = (data(i_ed+1, j_ed, :) + data(i_ed, j_ed+1, :))*0.5 !SE Corner

i_st=i_st-1
i_ed=i_ed+1
j_st=j_st-1
j_ed=j_ed+1
enddo

end subroutine fill_regional_halo

!> Prints an error message to standard output,
!! then halts program execution with a
!! bad status.
Expand Down
4 changes: 4 additions & 0 deletions tests/filter_topo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ execute_process( COMMAND ${CMAKE_COMMAND} -E copy
add_executable(ftst_read_filter_topo_nml ftst_readnml.F90)
add_test(NAME filter_topo-ftst_read_namelist COMMAND ftst_read_filter_topo_nml)
target_link_libraries(ftst_read_filter_topo_nml filter_topo_lib)

add_executable(ftst_fill_regional_halo ftst_fill_regional_halo.F90)
add_test(NAME filter_topo-ftst_fill_regional_halo COMMAND ftst_fill_regional_halo)
target_link_libraries(ftst_fill_regional_halo filter_topo_lib)
23 changes: 23 additions & 0 deletions tests/filter_topo/ftst_fill_regional_halo.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
! Unit test for filter_topo routine "fill_regional_halo".
!
! Author Ratko Vasic

program fill_halo

use utils

implicit none

integer :: halo

real, allocatable :: testdata(:,:,:)

print*, "Starting test of filter_topo routine fill_regional_halo"

call fill_regional_halo(testdata, halo)


print*, "OK"
print*, "SUCCESS!"

end program fill_halo

0 comments on commit f87f1f5

Please sign in to comment.