I would like to pass an elemental procedure to another elemental procedure. A minimum working example might be something like this:
elemental real function func(x, f_dummy)
implicit none
real, intent(in) :: x
interface
elemental real function f_dummy(x)
real, intent(in) :: x
end function f_dummy
end interface
func = 2.0 * f_dummy(x)
return
end function func
The compiler says:
Error: Dummy procedure ‘f_dummy’ not allowed in elemental procedure ‘func’ at (1)
If I delete all instances of elemental, then it compiles.
Is there a legal way to pass an elemental procedure to another elemental procedure?
No, the arguments of an elemantal procedure must be scalars, not arrays, not procedures. As a workaround you can write a procedure that deals with an array and the procedure and is just pure, not elemental.
Elemental procedures can be dummy arguments. But an argument of an elemental procedure cannot be a procedure. Perhaps it could be a procedure pointer, but then you would have to pass an array of pointers when calling it elementally on an array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With