#define _VERIFY(status) \ if(status /= 0) then; \ call assert_that(status, is(0), location=SourceLocation(__FILE__,__LINE__)); \ if (anyExceptions()) return; \ endif #define _RC rc=status); _VERIFY(status ! Helper procedures #define _SUCCESS 0 #define _RC2 rc=status); _VERIFY2(status #define _VERIFY2(status) if (status /= 0) then; if (present(rc)) rc=status; return; endif #define _RETURN(status) if (present(rc)) rc=status; return module Test_RouteHandleManager use pfunit use mapl3g_regridder_mgr use mapl3g_geom_mgr use esmf_TestMethod_mod ! mapl use esmf implicit none contains ! Helper procedures ! TODO add error handling to helper procedures function make_geom(geom_mgr, hconfig, rc) result(geom) type(ESMF_Geom) :: geom type(GeomManager), intent(inout) :: geom_mgr type(ESMF_HConfig), optional, intent(in) :: hconfig integer, optional, intent(out) :: rc type(MaplGeom), pointer :: mapl_geom class(GeomSpec), allocatable :: spec integer :: status type(ESMF_HConfig) :: hconfig_ hconfig_ = ESMF_HConfigCreate(content="{class: latlon, im_world: 12, jm_world: 13, pole: PC, dateline: DC, nx: 1, ny: 1}", _RC2) if (present(hconfig)) hconfig_ = hconfig mapl_geom => geom_mgr%get_mapl_geom(hconfig_, _RC2) geom = mapl_geom%get_geom() _RETURN(_SUCCESS) end function make_geom function make_field(geom, name, value, rc) result(field) type(ESMF_Field) :: field type(ESMF_Geom), intent(in) :: geom character(*), intent(in) :: name real(kind=ESMF_KIND_R4), intent(in) :: value integer, optional, intent(out) :: rc real(kind=ESMF_KIND_R4), pointer :: x(:,:) integer :: status field = ESMF_FieldEmptyCreate(name=name, _RC2) call ESMF_FieldEmptySet(field, geom, _RC2) call ESMF_FieldEmptyComplete(field, typekind=ESMF_TypeKind_R4, _RC2) call ESMF_FieldGet(field, farrayptr=x, _RC2) x = value end function make_field @test(type=ESMF_TestMethod, npes=[1]) ! Just execute a series of plausible commands and ensure that no ! failures are indicated Regrid a constant field onto identical ! geometry should not change any values. subroutine test_basic(this) class(ESMF_TestMethod), intent(inout) :: this type(GeomManager), target :: geom_mgr type(RegridderManager) :: regridder_mgr type(RegridderSpec) :: regridder_spec integer :: status class(Regridder), pointer :: my_regridder type(ESMF_Geom) :: geom type(ESMF_Field) :: f1, f2 real(kind=ESMF_KIND_R4), pointer :: x(:,:) geom_mgr = GeomManager() regridder_mgr = RegridderManager() geom = make_geom(geom_mgr, _RC) ! use default esmf regrid parameters: method, zero region, etc regridder_spec = RegridderSpec(EsmfRegridderParam(), geom, geom) my_regridder => regridder_mgr%get_regridder(regridder_spec, _RC) f1 = make_field(geom, 'f1', value=3._ESMF_KIND_R4, _RC) f2 = make_field(geom, 'f2', value=0._ESMF_KIND_R4, _RC) call my_regridder%regrid(f1, f2, _RC) call ESMF_FieldGet(f1, farrayptr=x, _RC) @assert_that(x, every_item(is(equal_to(3._ESMF_KIND_R4)))) end subroutine test_basic end module Test_RouteHandleManager