My minimum, reproducible example looks like this: in my program mymain
I call a subroutine which has as arguments an external function f1
and a variable result
. Within the subroutine something is done with the function (for this example it is just being evaluated at a specific point) and the result is given back via the argument result
.
PROGRAM mymain
IMPLICIT NONE
REAL(KIND=8) f1
REAL(KIND=8) result
EXTERNAL f1
CALL sub1(f1,result)
PRINT *,result
END PROGRAM mymain
SUBROUTINE sub1(f1,result)
IMPLICIT NONE
REAL(KIND=8) ::f1
REAL(KIND=8), INTENT(OUT) ::result
REAL(KIND=8) ::input
EXTERNAL f1
input=0.5
result=f1(input)
END SUBROUTINE sub1
REAL(KIND=8) FUNCTION f1(x)
REAL(KIND=8), INTENT(IN) ::x
REAL(KIND=8) ::const
const=1.
f1=x**2+const
END FUNCTION f1
My problem is that I want to change the variable const
in the function f1
from within mymain
.
In my real world problem the subroutine is one of a Fortran library that takes the integral of an external function and I need to call this subroutine many times but always with a different parameter in the external function.
I have no idea how to do this because I cannot call the subroutine from mymain
like this
CALL sub1(f1(x,const),result)