How do I point to a type-bound procedure? Say that I have some external subroutine that takes as an argument a pointer to a function that accepts only one argument.
call integrator(f0)
This will work if the function f0 is defined somewhere so that it looks like
function f0(x) result(val)
... do something...
end function
But now I have a type SomeClass with some type-bound procedures. One of these type-bound procedures is
function integrand(this,x) result(val)
class(SomeClass), intent(in) :: this
...do something...
end function
And I have another type-bound procedure in the same type that wants to call the subroutine above passing the first type-bound procedure to it, but I have no idea how to go about writing it! Let me first try the somewhat naive,
function CalculateIntegral(this) result(val)
class(SomeClass), intent(in) :: this
call integrator(this%integrand)
end function
This gives me
call integrator(this%integrand)
1
Error: Expected argument list at (1)
which I learnt from this discussion is because this%integrand does not return a pointer to the function but is a binding to the function.
So, now I'll try this
function CalculateIntegral(this) result(val)
class(SomeClass), intent(in) :: this
call integrator(integrand)
end function
and it compiles but gives me a Memory Reference error because it is trying to pass the value (x) to something that is meant for class(SomeClass) kind of argument (viz., this).
So if this%integrand only gives me a binding and not a pointer to a type-bound member procedure, how do I pass one of my type-bound member procedures to an external subroutine without the first "this" argument getting in the way?
NOTE: I'm used to coding in python, where self.integrand could be passed to the external function and everything would be fine.
EDIT: My bad; I remembered wrong. Python has the same problem if you try to pass self.integrand to an external function.