I'm trying to use routines in QUADPACK
to perform numerical integration. The routines expect functions to be passed as REAL,EXTERNAL
, so I don't have the liberty of using pointers or whatever else.
Is it possible to alias a function f(x,a,b,...)
as being a function f(x)
for the routine that expects a function of x only? Much like what one would accomplish in MATLAB
with @(x)f(x,a,b,...)
.
You cannot make similar tricks with functions in Fortran directly. You also cannot return a closure in Fortran. Just write a wrapper.
It can be an internal or module function and get
a
andb
by the host association or it can use the module containinga
andb
.If you want to pass the function as an actual argument, it cannot be an internal procedure in up to Fortran 2003, but only in Fortran 2008. But it works in recent versions of gfortran and ifort. For better portability use a module.
I can show a nice solution for this problem. I am also a former MATLAB user and when switching to FORTRAN you miss function handles haha. I solved your problem in this way: