subroutine test_calculate_mean_R4() type(MeanAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock integer :: status integer(kind=ESMF_KIND_I4), parameter :: COUNTER = 4 real(kind=ESMF_KIND_R4), parameter :: MEAN = 4.0_R4 logical :: matches_expected real(kind=ESMF_KIND_R4), pointer :: fptr(:) integer(kind=ESMF_KIND_I4), pointer :: ifptr(:) integer :: n logical, allocatable :: mask(:) call initialize_objects(importState, exportState, clock, ESMF_TYPEKIND_R4, _RC) call acc%initialize(importState, exportState, clock, _RC) call FieldSet(acc%accumulation_field, COUNTER*MEAN, _RC) call assign_fptr(acc%accumulation_field, fptr, _RC) call assign_fptr(acc%counter_field, ifptr, _RC) ifptr = COUNTER n = size(fptr)-1 ! All points are not UNDEF and counter > 0 call acc%calculate_mean_R4(_RC) matches_expected = FieldIsConstant(acc%accumulation_field, MEAN, _RC) @assertTrue(matches_expected, 'accumulation_field not equal to MEAN') ! counter 0 at one point call FieldSet(acc%accumulation_field, COUNTER*MEAN, _RC) call assign_fptr(acc%counter_field, fptr, _RC) fptr(n) = 0 mask = fptr /= 0 call assign_fptr(acc%accumulation_field, fptr, _RC) call acc%calculate_mean_R4(_RC) @assertTrue(all(pack(fptr, mask) == MEAN), 'Some valid points not equal to MEAN') @assertTrue(undef(fptr(n)), 'mean at point was not UNDEF') end subroutine test_calculate_mean_R4