test_calculate_mean_R4 Subroutine

public subroutine test_calculate_mean_R4()

Arguments

None

Calls

proc~~test_calculate_mean_r4~~CallsGraph proc~test_calculate_mean_r4 test_calculate_mean_R4 anyexceptions anyexceptions proc~test_calculate_mean_r4->anyexceptions assert_that assert_that proc~test_calculate_mean_r4->assert_that asserttrue asserttrue proc~test_calculate_mean_r4->asserttrue interface~assign_fptr assign_fptr proc~test_calculate_mean_r4->interface~assign_fptr interface~fieldisconstant FieldIsConstant proc~test_calculate_mean_r4->interface~fieldisconstant interface~fieldset FieldSet proc~test_calculate_mean_r4->interface~fieldset none~calculate_mean_r4 MeanAction%calculate_mean_R4 proc~test_calculate_mean_r4->none~calculate_mean_r4 none~initialize~38 AccumulatorAction%initialize proc~test_calculate_mean_r4->none~initialize~38 proc~initialize_objects initialize_objects proc~test_calculate_mean_r4->proc~initialize_objects proc~undef undef proc~test_calculate_mean_r4->proc~undef sourcelocation sourcelocation proc~test_calculate_mean_r4->sourcelocation none~calculate_mean_r4->interface~assign_fptr proc~mapl_return MAPL_Return none~calculate_mean_r4->proc~mapl_return proc~mapl_verify MAPL_Verify none~calculate_mean_r4->proc~mapl_verify esmf_fieldget esmf_fieldget none~initialize~38->esmf_fieldget esmf_stateget esmf_stateget none~initialize~38->esmf_stateget interface~fieldsareconformable FieldsAreConformable none~initialize~38->interface~fieldsareconformable interface~fieldsaresametypekind FieldsAreSameTypeKind none~initialize~38->interface~fieldsaresametypekind interface~mapl_assert MAPL_Assert none~initialize~38->interface~mapl_assert none~clear~154 AccumulatorAction%clear none~initialize~38->none~clear~154 none~create_fields~2 AccumulatorAction%create_fields none~initialize~38->none~create_fields~2 none~initialize~38->proc~mapl_return none~initialize~38->proc~mapl_verify proc~initialize_objects->anyexceptions proc~initialize_objects->assert_that proc~initialize_objects->sourcelocation ESMF_ClockCreate ESMF_ClockCreate proc~initialize_objects->ESMF_ClockCreate ESMF_GridCreateNoPeriDimUfrm ESMF_GridCreateNoPeriDimUfrm proc~initialize_objects->ESMF_GridCreateNoPeriDimUfrm ESMF_TimeIntervalSet ESMF_TimeIntervalSet proc~initialize_objects->ESMF_TimeIntervalSet ESMF_TimeSet ESMF_TimeSet proc~initialize_objects->ESMF_TimeSet esmf_fieldcreate esmf_fieldcreate proc~initialize_objects->esmf_fieldcreate esmf_statecreate esmf_statecreate proc~initialize_objects->esmf_statecreate none~clear~154->interface~fieldset none~clear~154->interface~mapl_assert none~clear~154->proc~mapl_return none~clear~154->proc~mapl_verify none~create_fields~2->esmf_fieldcreate none~create_fields~2->proc~mapl_return none~create_fields~2->proc~mapl_verify esmf_fielddestroy esmf_fielddestroy none~create_fields~2->esmf_fielddestroy none~initialized~11 AccumulatorAction%initialized none~create_fields~2->none~initialized~11 at at proc~mapl_return->at insert insert proc~mapl_return->insert proc~mapl_throw_exception MAPL_throw_exception proc~mapl_return->proc~mapl_throw_exception proc~mapl_verify->proc~mapl_throw_exception

Source Code

   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