checked_accumulate_charge Subroutine

public subroutine checked_accumulate_charge(accumulator, increment, context)

有限なcharge incrementをoverflowさせずscalar accumulatorへ加える。

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(inout) :: accumulator
real(kind=dp), intent(in) :: increment
character(len=*), intent(in) :: context

Called by

proc~~checked_accumulate_charge~~CalledByGraph proc~checked_accumulate_charge checked_accumulate_charge proc~accumulate_charge_ledger accumulate_charge_ledger proc~accumulate_charge_ledger->proc~checked_accumulate_charge

Source Code

  subroutine checked_accumulate_charge(accumulator, increment, context)
    real(dp), intent(inout) :: accumulator
    real(dp), intent(in) :: increment
    character(len=*), intent(in) :: context

    if (.not. ieee_is_finite(accumulator) .or. .not. ieee_is_finite(increment)) then
      error stop trim(context)//' contains a non-finite charge.'
    end if
    if (increment > 0.0_dp .and. accumulator > huge(accumulator) - increment) then
      error stop trim(context)//' charge accumulation overflowed.'
    end if
    if (increment < 0.0_dp .and. accumulator < -huge(accumulator) - increment) then
      error stop trim(context)//' charge accumulation overflowed.'
    end if
    accumulator = accumulator + increment
    if (.not. ieee_is_finite(accumulator)) error stop trim(context)//' charge accumulation is not finite.'
  end subroutine checked_accumulate_charge