You can handle this as follows, although it is not fully equivalent to matlab's function handle (functions are not really first-class citizens in Fortran).
module roots
implicit none
contains
subroutine root_finder(f,b)
procedure(func) :: f
real, intent(in) :: b
abstract interface
real function func(a,b)
real, intent(in) :: a,b
end function
end interface
print*, g(2.)
contains
real function g(a)
real, intent(in) :: a
g = f(a,b)
end function
end subroutine
end module
As you can see, the function of two variables is passed to the subroutine, along with the parameter b
. The subroutine uses an internal function g(a)
to evaluate f(a,b)
. This function is, as it were, the "handle".
An example program, which defines an actual function f(a,b) = a**2 + b
:
program example
use roots
implicit none
call root_finder(f, 10.)
contains
real function f(a,b)
real,intent(in) :: a,b
f = a**2 + b
end function
end program
Output: 14.0000000