main_ex Program

program~~main_ex~~UsesGraph program~main_ex main_ex module~external_ex external_ex module~external_ex->program~main_ex module~square square module~square->program~main_ex module~square->module~external_ex iso_fortran_env iso_fortran_env iso_fortran_env->program~main_ex iso_fortran_env->module~external_ex iso_fortran_env->module~square
Help


Calls

program~~main_ex~~CallsGraph program~main_ex main_ex squarefun squarefun program~main_ex->squarefun proc~funwrapper~2 funWrapper program~main_ex->proc~funwrapper~2 proc~squarewrapperinternal~2 squareWrapperInternal program~main_ex->proc~squarewrapperinternal~2 proc~square_local square_local program~main_ex->proc~square_local squarewrapperexternal squarewrapperexternal program~main_ex->squarewrapperexternal proc~executefun~2 executeFun proc~funwrapper~2->proc~executefun~2 proc~squarewrapperinternal~2->squarefun proc~squarefun squareFun proc~square_local->proc~squarefun
Help

Source Code


Variables

Type AttributesNameInitial
real(kind=wp) :: x(5) =[1., 2., 3., 4., 5.]
real(kind=wp) :: y(5)

Functions

function executeFun(myfun, x) result(y)

Arguments

Type IntentOptional AttributesName
procedure(fun_interf) :: myfun
real(kind=wp), intent(in), dimension(:):: x

Return Value real(kind=wp), dimension(size(x))


Subroutines

subroutine funWrapper(myfun, x, y)

Arguments

Type IntentOptional AttributesName
procedure(fun_interf) :: myfun
real(kind=wp), intent(in), dimension(:):: x
real(kind=wp), intent(out), dimension(:):: y

subroutine squareWrapperInternal(x, y)

Arguments

Type IntentOptional AttributesName
real(kind=wp), intent(in), dimension(:):: x
real(kind=wp), intent(out), dimension(:):: y

Source Code

program main_ex
  use iso_fortran_env, only: wp=>real64
  use square, only: fun_interf, &
                  & squareFun, &
                  & square_local
  use external_ex, only: squareWrapperExternal
  implicit none

  real(wp) :: x(5) = [1., 2., 3., 4., 5.]
  real(wp) :: y(5)

  ! Call squareFun directly
  y = squareFun(x)
  print '(1x,5(1x,f6.2))', y

  ! Call squareFun using a 'local' wrapper, which exists in same module
  y = square_local(x)
  print '(1x,5(1x,f6.2))', y

  ! Call squareFun using an internal wrapper that calls squareFun directly
  call squareWrapperInternal(x, y)
  print '(1x,5(1x,f6.2))', y

  ! Call squareFun using an external wrapper that calls squareFun directly
  call squareWrapperExternal(x, y)
  print '(1x,5(1x,f6.2))', y

  ! Send squareFun to a 'general' function wrapper - uses a procedure interface
  call funWrapper(squareFun, x, y)
  print '(1x,5(1x,f6.2))', y

contains

  subroutine funWrapper(myfun, x, y)
    real(wp), intent(in),   dimension(:)  :: x
    real(wp), intent(out),  dimension(:)  :: y
    procedure(fun_interf)                 :: myfun

    y = executeFun(myfun, x)

    return
  end subroutine funWrapper

  function executeFun(myfun, x) result(y)
    real(wp), intent(in),   dimension(:)  :: x
    real(wp),             dimension(size(x))  :: y
    procedure(fun_interf)                 :: myfun

    y = myfun(x)

    return
  end function executeFun

  subroutine squareWrapperInternal(x, y)
    real(wp), intent(in),   dimension(:)  :: x
    real(wp), intent(out),  dimension(:)  :: y

    y = squareFun(x)

    return
  end subroutine squareWrapperInternal

end program main_ex