Hello,
First time posting, though I’ve been reading for a while. I’m trying to make use of interfaces to simplify calling subroutines (e.g. call my_sub
instead of my_sub_XXX
, where XXX changes for kinds).
I have previously used them for differentiating kinds, and had no problem.
Now what I have is a subroutine with one of its arguments a function (with its relevant interface in the module). One subroutine uses a function f(x)
, the other a function f(x,y)
.
module my_mod
implicit none
interface
real function fx(x)
real, intent(in) :: x
...
end function
real function fxy(x,y)
real, intent(in) :: x
...
end function
end interface
contains
subroutine sub1(my_funx, ...)
procedure(fx) :: my_funx
...
end subroutine sub1
subroutine sub2(my_funxy, ...)
procedure(fxy) :: my_funxy
...
end subroutine sub2
end module my_mod
Those functions would be defined in the main program, for example, that use
s my_mod
Is there a way of creating a generic interface for sub1 and sub2? Naming the interface of the functions, and then using procedure(generic_f)
does not work. Neither does creating a named interface for sub1 and sub2. In the former case, the compiler complains that “the interface may not be generic”; in the latter, it says there is ambiguity in the interface. Those are errors from gfortran 10.2 (on windows, through mingw).
Alternatives to using procedure(...) :: my_fun
within the subroutines are also welcome too (I am aware of the possibility of using pointers, though I haven’t tried that route yet).
Thank you.