Skip to content

Commit

Permalink
make tests simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
mlee03 authored and mlee03 committed Aug 29, 2023
1 parent 87b7513 commit 7d19c22
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 391 deletions.
12 changes: 6 additions & 6 deletions test_fms/mosaic/test_grid2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ subroutine test_get_cell_vertices

!---- 2d ---!
!> answers. Only testing for tile 1
answer_lon_2d(1,1)=305.0 ; answer_lon_2d(2,1)=35.0
answer_lon_2d(1,2)=305.0 ; answer_lon_2d(2,2)=35.0
answer_lon_2d(1,1)=x(1,1) ; answer_lon_2d(2,1)=x(3,1)
answer_lon_2d(1,2)=x(1,3) ; answer_lon_2d(2,2)=x(3,3)

answer_lat_2d(1,1)=-35.2643896827547 ; answer_lat_2d(2,1)=-35.2643896827547
answer_lat_2d(1,2)=35.2643896827547 ; answer_lat_2d(2,2)=35.2643896827547
answer_lat_2d(1,1)=y(1,1) ; answer_lat_2d(2,1)=y(3,1)
answer_lat_2d(1,2)=y(1,3) ; answer_lat_2d(2,2)=y(3,3)

call get_grid_cell_vertices('ATM',1,lonb_2d,latb_2d)
!> check
Expand Down Expand Up @@ -123,8 +123,8 @@ subroutine test_get_cell_centers

!--- 2d ---!
!> assign answers for 2d
answer_glon_2d(1,1)=350.0
answer_glat_2d(1,1)=0.0
answer_glon_2d(1,1)=x(2,2)
answer_glat_2d(1,1)=y(2,2)

call get_grid_cell_centers('ATM', 1, glon_2d, glat_2d)
do i=1, npt_x
Expand Down
156 changes: 24 additions & 132 deletions test_fms/mosaic/test_mosaic.F90
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,22 @@ program test_mosaic
!! In this case, the grid_version is VERSION_OCN_MOSAIC_FILE.
call fms_init()

write(*,*) 'TEST GET_MOSAIC_GRID_SIZES'
call test_get_mosaic_grid_sizes()

write(*,*) 'TEST GET_MOSAIC_CONTACT'
call test_get_mosaic_contact()

write(*,*) 'TEST GET_GRID_GREAT_CIRCLE_AREA'
call test_get_grid_great_circle_area()

write(*,*) 'TEST GET_GRID_AREA'
call test_get_grid_area()

write(*,*) 'TEST GET_MOSAIC_XGRID'
call test_get_mosaic_xgrid()

write(*,*) 'TEST IS_INSIDE_POLYGON'
call test_is_inside_polygon()

call fms_end()
Expand All @@ -62,15 +73,11 @@ subroutine test_get_mosaic_grid_sizes
integer, allocatable :: nx_out(:), ny_out(:)

type(FmsNetcdfFile_t):: fileobj
integer, allocatable :: pes(:)

!-- ocean --!
allocate(pes(mpp_npes()))
call mpp_get_current_pelist(pes)
if( .not. open_file(fileobj, 'INPUT/'//trim(ocn_mosaic_file), 'read', pelist=pes) ) &
if( .not. open_file(fileobj, 'INPUT/'//trim(ocn_mosaic_file), 'read') ) &
call mpp_error(FATAL, 'test_mosaic: error in opening file '//'INPUT/'//trim(ocn_mosaic_file))


allocate( nx_out(ocn_ntiles), ny_out(ocn_ntiles) )
!> get_mosaic_grid_sizes reads in the grid file
call get_mosaic_grid_sizes(fileobj, nx_out, ny_out )
Expand All @@ -82,7 +89,7 @@ subroutine test_get_mosaic_grid_sizes
call close_file(fileobj)

!-- atm --!
if( .not. open_file(fileobj, 'INPUT/'//trim(c1_mosaic_file), 'read', pelist=pes) ) &
if( .not. open_file(fileobj, 'INPUT/'//trim(c1_mosaic_file), 'read') ) &
call mpp_error(FATAL, 'test_mosaic: error in opening file '//'INPUT/'//trim(c1_mosaic_file))

allocate( nx_out(c1_ntiles), ny_out(c1_ntiles) )
Expand Down Expand Up @@ -112,11 +119,8 @@ subroutine test_get_mosaic_contact
integer :: answers(2, 8) !< Expected results

type(FmsNetcdfFile_t):: ocn_fileobj
integer, allocatable :: pes(:)

allocate(pes(mpp_npes()))
call mpp_get_current_pelist(pes)
if( .not. open_file(ocn_fileobj, 'INPUT/'//trim(ocn_mosaic_file), 'read', pelist=pes) ) &
if( .not. open_file(ocn_fileobj, 'INPUT/'//trim(ocn_mosaic_file), 'read') ) &
call mpp_error(FATAL, 'test_mosaic: error in opening file '//'INPUT/'//trim(ocn_mosaic_file))

answers(1,:) = (/1440, 1440, 1, 1080, 1, 1, 1, 1080 /)
Expand Down Expand Up @@ -172,76 +176,18 @@ subroutine test_get_grid_area
implicit none

type(FmsNetcdfFile_t):: c1_fileobj
integer, allocatable :: pes(:)

real :: x_rad(c1_nxp, c1_nyp), y_rad(c1_nxp, c1_nyp)
real :: area_out(c1_nx,c1_ny), area_answer(c1_nx, c1_ny), area_w_pole_answer(c1_nx, c1_ny)
real :: x_rad(c1_nx, c1_ny), y_rad(c1_nx, c1_ny)
real :: area_out(1,1)

integer :: i,j

!> get answers. Tile 1 will be the reference/benchmark data
x_rad = x1 * DEG_TO_RAD
y_rad = y1 * DEG_TO_RAD
call calc_mosaic_grid_area(x_rad, y_rad, area_answer)
write(*,*) area_answer
write(*,*)'***'

!> Tile 2 area should be the same as tile 1 area
x_rad = x2 * DEG_TO_RAD
y_rad = y2 * DEG_TO_RAD
call calc_mosaic_grid_area(x_rad, y_rad, area_out)
!> check answers
do j=1, c1_ny
do i=1, c1_nx
call check_answer_w_tol(area_answer(i,j), area_out(i,j), 'test_grid_area tile 2 ')
end do
end do
write(*,*) area_out
write(*,*)'***'

!> Tile 3 area should be the same as tile 1 area
x_rad = x3 * DEG_TO_RAD
y_rad = y3 * DEG_TO_RAD
call calc_mosaic_grid_area(x_rad, y_rad, area_w_pole_answer)
write(*,*) area_w_pole_answer
write(*,*)'***'

!> Tile 4 area should be the same as tile 1 area
x_rad = x4 * DEG_TO_RAD
y_rad = y4 * DEG_TO_RAD
call calc_mosaic_grid_area(x_rad, y_rad, area_out)
do j=1, c1_ny
do i=1, c1_nx
call check_answer_w_tol(area_answer(i,j), area_out(i,j), 'test_grid_area tile 4')
end do
end do
write(*,*) area_out
write(*,*)'***'

!> Tile 5 area should be the same as tile 1 area
x_rad = x5 * DEG_TO_RAD
y_rad = y5 * DEG_TO_RAD
call calc_mosaic_grid_area(x_rad, y_rad, area_out)
do j=1, c1_ny
do i=1, c1_nx
call check_answer_w_tol(area_answer(i,j), area_out(i,j), 'test_grid_area tile 5')
end do
end do
write(*,*) area_out
write(*,*)'***'
x_rad = x(1:2, 1:2) * DEG_TO_RAD
y_rad = y(1:2, 1:2) * DEG_TO_RAD

!> Tile 6 area should be the same as tile 3 area
x_rad = x6 * DEG_TO_RAD
y_rad = y6 * DEG_TO_RAD
call calc_mosaic_grid_area(x_rad, y_rad, area_out)
!> check answers
do j=1, c1_ny
do i=1, c1_nx
call check_answer_w_tol(area_w_pole_answer(i,j), area_out(i,j), 'test_grid_area tile 6')
end do
end do
write(*,*) area_out
write(*,*)'***'
call check_answer(area_out(1,1), area(1,1), 'TEST_GET_GRID_AREA')

end subroutine test_get_grid_area
!------------------------------------------------------!
Expand All @@ -259,70 +205,16 @@ subroutine test_get_grid_great_circle_area
type(FmsNetcdfFile_t):: c1_fileobj
integer, allocatable :: pes(:)

real :: x_rad(c1_nxp, c1_nyp), y_rad(c1_nxp, c1_nyp)
real :: area_out(c1_nx,c1_ny), area_answer(c1_nx, c1_ny)
real :: x_rad(c1_nx, c1_ny), y_rad(c1_nx, c1_ny)
real :: area_out(1,1)

integer :: i,j

!> get answers. Tile 1 will be the reference/benchmark data
x_rad = x1 * DEG_TO_RAD
y_rad = y1 * DEG_TO_RAD
call calc_mosaic_grid_great_circle_area(x_rad, y_rad, area_answer)

!> Tile 2 areas should be the same as tile 1 area
x_rad = x2 * DEG_TO_RAD
y_rad = y2 * DEG_TO_RAD
call calc_mosaic_grid_great_circle_area(x_rad, y_rad, area_out)
!> check answers
do j=1, c1_ny
do i=1, c1_nx
call check_answer_w_tol(area_answer(i,j), area_out(i,j), 'test_grid_area tile 2 ')
end do
end do

!> Tile 3 area should be the same as tile 1 area
x_rad = x3 * DEG_TO_RAD
y_rad = y3 * DEG_TO_RAD
call calc_mosaic_grid_great_circle_area(x_rad, y_rad, area_out)
!> check answers
do j=1, c1_ny
do i=1, c1_nx
call check_answer_w_tol(area_answer(i,j), area_out(i,j), 'test_grid_area tile 3')
end do
end do

!> Tile 4 area should be the same as tile 1 area
x_rad = x4 * DEG_TO_RAD
y_rad = y4 * DEG_TO_RAD
x_rad = x(1:2, 1:2) * DEG_TO_RAD
y_rad = y(1:2, 1:2) * DEG_TO_RAD
call calc_mosaic_grid_great_circle_area(x_rad, y_rad, area_out)
!> check answers
do j=1, c1_ny
do i=1, c1_nx
call check_answer_w_tol(area_answer(i,j), area_out(i,j), 'test_grid_area tile 4')
end do
end do

!> Tile 5 area should be the same as tile 1 area
x_rad = x5 * DEG_TO_RAD
y_rad = y5 * DEG_TO_RAD
call calc_mosaic_grid_great_circle_area(x_rad, y_rad, area_out)
!> check answers
do j=1, c1_ny
do i=1, c1_nx
call check_answer_w_tol(area_answer(i,j), area_out(i,j), 'test_grid_area tile 5')
end do
end do

!> Tile 6 area should be the same as tile 1 area
x_rad = x6 * DEG_TO_RAD
y_rad = y6 * DEG_TO_RAD
call calc_mosaic_grid_great_circle_area(x_rad, y_rad, area_out)
!> check answers
do j=1, c1_ny
do i=1, c1_nx
call check_answer_w_tol(area_answer(i,j), area_out(i,j), 'test_grid_area tile 6')
end do
end do
call check_answer(area_out(1,1), area(1,1), 'TEST_GET_GRID_AREA')

end subroutine test_get_grid_great_circle_area
!------------------------------------------------------!
Expand Down
8 changes: 2 additions & 6 deletions test_fms/mosaic/test_mosaic2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@
touch input.nml
rm -rf INPUT
mkdir INPUT
#test_expect_success "test mosaic" '
# mpirun -n 2 ./test_mosaic
#'
test_expect_success "test mosaic" 'mpirun -n 1 ./test_mosaic'

test_expect_success "test grid2" '
mpirun -n 1 ./test_grid2
'
test_expect_success "test grid2" 'mpirun -n 1 ./test_grid2'

#rm -rf INPUT
test_done
Loading

0 comments on commit 7d19c22

Please sign in to comment.