subroutine test_accumulate_with_undef_some_steps(this)
class(ESMF_TestMethod), intent(inout) :: this
type(MeanAction) :: acc
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer :: status
type(ESMF_Field) :: update_field
integer :: n
real(kind=ESMF_KIND_R4), parameter :: UPDATE_VALUE = 3.0_R4
real(kind=ESMF_KIND_R4), pointer :: upPtr(:), accPtr(:)
integer(kind=ESMF_KIND_I4), pointer :: countPtr(:)
logical, allocatable :: mask(:)
call initialize_objects(importState, exportState, clock, ESMF_TYPEKIND_R4, _RC)
call acc%initialize(importState, exportState, clock, _RC)
call initialize_field(update_field, acc%accumulation_field, _RC)
call assign_fptr(update_field, upPtr, _RC)
upPtr = UPDATE_VALUE
allocate(mask(size(upPtr)))
mask = .TRUE.
call acc%accumulate(update_field, _RC)
call acc%accumulate(update_field, _RC)
call assign_fptr(update_field, upPtr, _RC)
n = size(upPtr) - 1
call set_undef(upPtr(n))
call acc%accumulate(update_field, _RC)
mask(n) = .FALSE.
call assign_fptr(update_field, upPtr, _RC)
upPtr = UPDATE_VALUE
call acc%accumulate(update_field, _RC)
call acc%accumulate(update_field, _RC)
call assign_fptr(acc%counter_field, countPtr, _RC)
@assertEqual(4, countPtr(n), 'Missing point counter does not match.')
@assertTrue(all(pack(countPtr, mask) == 5), 'Other point counters do not match.')
call assign_fptr(acc%accumulation_field, accPtr, _RC)
@assertEqual(4*UPDATE_VALUE, accPtr(n), 'Missing point does not match.')
@assertTrue(all(pack(accPtr, mask) == 5*UPDATE_VALUE), 'Other points do not match.')
call destroy_objects(importState, exportState, clock, _RC)
call ESMF_FieldDestroy(update_field)
end subroutine test_accumulate_with_undef_some_steps