module Test_LonAxis use funit use mapl3g_CoordinateAxis use mapl3g_LonAxis use esmf, only: ESMF_KIND_R8 use esmf, only: ESMF_HConfig use esmf, only: ESMF_HConfigCreate use esmf, only: ESMF_HConfigDestroy implicit none integer, parameter :: R8 = ESMF_KIND_R8 contains @test subroutine test_is_periodic() type(LonAxis) :: axis integer, parameter :: N = 6 real(kind=R8) :: centers(N) real(kind=R8) :: corners(N+1) integer :: i do i = 1, n centers(i) = (360./n) * i corners(i) = (360./n) * i - (360./(2*n)) end do corners(n+1) = 360 + (360./(2*n)) axis = LonAxis(centers = centers, corners=corners) @assert_that(axis%is_periodic(), is(true())) end subroutine test_is_periodic @test subroutine test_is_not_periodic() type(LonAxis) :: axis integer, parameter :: N = 6 real(kind=R8) :: centers(N) real(kind=R8) :: corners(N+1) integer :: i do i = 1, n centers(i) = (360./n) * i corners(i) = (360./n) * i - (360./(2*n)) end do corners(n+1) = 360 + (360./(2*n)) + 1 axis = LonAxis(centers = centers, corners=corners) @assert_that(axis%is_periodic(), is(false())) corners(n+1) = 360 + (360./(2*n)) - 1 axis = LonAxis(centers = centers, corners=corners) @assert_that(axis%is_periodic(), is(false())) end subroutine test_is_not_periodic @test subroutine test_get_lon_range_DC() type(AxisRanges) :: ranges type(ESMF_HConfig) :: hconfig integer :: status hconfig = ESMF_HConfigCreate(content="{dateline: DC}", rc=status) @assert_that(status, is(0)) ranges = get_lon_range(hconfig, 4, rc=status) @assert_that(status, is(0)) @assert_that(ranges%center_min, is(-180._R8)) @assert_that(ranges%center_max, is(90._R8)) @assert_that(ranges%corner_min, is(-225._R8)) @assert_that(ranges%corner_max, is(135._R8)) call ESMF_HConfigDestroy(hconfig) end subroutine test_get_lon_range_DC @test subroutine test_get_lon_range_DE() type(AxisRanges) :: ranges type(ESMF_HConfig) :: hconfig integer :: status hconfig = ESMF_HConfigCreate(content="{dateline: DE}", rc=status) @assert_that(status, is(0)) ranges = get_lon_range(hconfig, 4, rc=status) @assert_that(status, is(0)) @assert_that(ranges%center_min, is(-135._R8)) @assert_that(ranges%center_max, is(+135._R8)) @assert_that(ranges%corner_min, is(-180._R8)) @assert_that(ranges%corner_max, is(+180._R8)) call ESMF_HConfigDestroy(hconfig) end subroutine test_get_lon_range_DE @test subroutine test_get_lon_range_GC() type(AxisRanges) :: ranges type(ESMF_HConfig) :: hconfig integer :: status hconfig = ESMF_HConfigCreate(content="{dateline: GC}", rc=status) @assert_that(status, is(0)) ranges = get_lon_range(hconfig, 4, rc=status) @assert_that(status, is(0)) @assert_that(ranges%center_min, is(0._R8)) @assert_that(ranges%center_max, is(270._R8)) @assert_that(ranges%corner_min, is(-45._R8)) @assert_that(ranges%corner_max, is(+315._R8)) call ESMF_HConfigDestroy(hconfig) end subroutine test_get_lon_range_GC @test subroutine test_get_lon_range_GE() type(AxisRanges) :: ranges type(ESMF_HConfig) :: hconfig integer :: status hconfig = ESMF_HConfigCreate(content="{dateline: GE}", rc=status) @assert_that(status, is(0)) ranges = get_lon_range(hconfig, 4, rc=status) @assert_that(status, is(0)) @assert_that(ranges%center_min, is(+45._R8)) @assert_that(ranges%center_max, is(+315._R8)) @assert_that(ranges%corner_min, is(0._R8)) @assert_that(ranges%corner_max, is(270._R8)) call ESMF_HConfigDestroy(hconfig) call ESMF_HConfigDestroy(hconfig) end subroutine test_get_lon_range_GE @test subroutine test_get_lon_range_regional() type(AxisRanges) :: ranges type(ESMF_HConfig) :: hconfig integer :: status hconfig = ESMF_HConfigCreate(content="{lon_range: [0., 30.]}", rc=status) @assert_that(status, is(0)) ranges = get_lon_range(hconfig, 3, rc=status) @assert_that(status, is(0)) @assert_that(ranges%center_min, is(+5._R8)) @assert_that(ranges%center_max, is(+25._R8)) @assert_that(ranges%corner_min, is(0._R8)) @assert_that(ranges%corner_max, is(30._R8)) call ESMF_HConfigDestroy(hconfig) end subroutine test_get_lon_range_regional @test subroutine test_make_lon_axis_from_hconfig() type(ESMF_HConfig) :: hconfig type(LonAxis) :: axis integer :: status real(kind=R8), allocatable :: expected_centers(:) hconfig = ESMF_HConfigCreate( & content="{im_world: 4, jm_world: 5, nx: 1, ny: 1, dateline: DC}", & rc=status) @assert_that(status, is(0)) axis = make_LonAxis(hconfig, rc=status) @assert_that(status, is(0)) expected_centers = [-180, -90, 0, 90] @assert_that(axis%get_centers(), is(equal_to(expected_centers))) call ESMF_HConfigDestroy(hconfig) end subroutine test_make_lon_axis_from_hconfig end module Test_LonAxis