enz Function

public function enz(n, z, show_warning)

Exponential integral .

If show_warning = .true., a warning message is displayed when cexint returns IERR = 2 or IERR = 4.

Arguments

Type IntentOptional Attributes Name
integer(kind=i4), intent(in) :: n
complex(kind=wp), intent(in) :: z
logical, intent(in), optional :: show_warning

Default=.true.

Return Value complex(kind=wp)


Calls

proc~~enz~~CallsGraph proc~enz enz proc~cexint cexint proc~enz->proc~cexint

Source Code

  complex(wp) function enz(n, z, show_warning)
    !* Exponential integral \(\mathrm{E}_n(z)\).
    ! 
    ! \(n \geq 1,\thinspace z \in \mathbb{C},\thinspace -\pi \lt \arg(z) \leq \pi \)
    !
    ! If `show_warning = .true.`, a warning message is displayed when `cexint` returns
    !* `IERR = 2` or `IERR = 4`.

    integer(i4), intent(in) :: n
    complex(wp), intent(in) :: z
    logical, intent(in), optional :: show_warning  !! Default=`.true.`
    real(wp), parameter :: tol = eps_wp
    integer(i4), parameter :: m = 1
    complex(wp) :: cy(m)
    integer(i4) :: ierr
    logical :: show_warning_

    show_warning_ = .true.
    
    if (present(show_warning)) then
      show_warning_ = show_warning
    end if

    ! Computing En(z) with no scaling (KODE = 1).
    call cexint(z, n, 1, tol, m, cy, ierr)
    enz = cy(1)

    select case (ierr)
      case (1)
        error stop 'CALGO 683 IERR = 1: An input error. No computation.'
      case (2)
        ! Computing E1(z) with scaling (KODE = 2).
        call cexint(z, n, 1, tol, m, cy, ierr)
        enz = exp(-z) * cy(1)

        if (show_warning_) then
          write(stderr, '(a)') 'CALGO 683 IERR = 2: Underflow. ' // &
                               'En(z) = (0.0, 0.0). Real(z) > 0.0 ' // &
                               'too large on KODE = 1. Recomputed with KODE = 2.'
        end if
      case (3)
        error stop 'CALGO 683 IERR = 3: Overflow. No computation. ' // &
                   'Real(z) < 0.0 too small on KODE = 1.'
      case (4)
        if (show_warning_) then
          write(stderr, '(a)') 'CALGO 683 IERR = 4: |z| or n large. '  // &
                               'Computation done but losses of significance by ' // &
                               'argument reduction may exceed half precision.'
        end if
      case (5)
        error stop 'CALGO 683 IERR = 5: |z| or n large. No computation. ' // &
                   'All loss of significance by argument reduction has occurred.'
      case (6)
        error stop 'CALGO 683 IERR = 6: Convergence error. No computation. ' // &
                   'Algorithm termination condition not met.'
      case (7)
        error stop 'CALGO 683 IERR = 7: Discrimination error. No computation. ' // &
                   'This condition should never occur.'
    end select
  end function enz