Is it possible to link different subroutines with procedures in derived types with the same structure?
I'm using derived types and my idea is to link different subroutines with the same structure so it can be passed as arguments.
I thought of subroutine overloading. However, it needs arguments with different types, which won't help.
The following code doesn't compile but it has the main idea.
module mod1
implicit none
type foo_data
integer :: a, b
contains
procedure :: oper !I know that this isn't allowed because some coding is missing
end type foo_data
type(foo_data) :: foo1
type(foo_data) :: foo2
contains
subroutine add(a,b,c)
integer, intent(in) :: a, b
integer, intent(out) :: c
c=a+b
end subroutine add
subroutine sub(a,b,c)
integer, intent(in) :: a, b
integer, intent(out) :: c
c=a-b
end subroutine sub
end module mod1
program main
use mod1
implicit none
Integer :: c, d
!link add with foo1 using oper or another idea
!link sub with foo2 using oper or another idea
foo1%a=1
foo1%b=2
foo2%a=2
foo2%b=1
call compute(foo1,c)
write(*,*) c
call compute(foo2,d)
write(*,*) d
contains
subroutine compute(foo,r)
type(foo_data) :: foo
integer, intent(out) :: r
call foo%oper(foo%a,foo%b,r)
end subroutine compute
end program main