我有两个例程,一个例程调用另一个例程,另一个例程根据类型进行选择。
matc_a
调用 takano
。当我从 matc_a
调用 takano
时,我需要
因此,将对 takano
的调用包装在 Select Type
中,或者我可以直接调用 is
如下
Case ("takano")
Call takano (a)
有两个例程
Subroutine takano &
( &
a &
)
Class (*), Intent (out) :: a
Select Type (a)
Type Is (Real (Real32))
a = atan ( Real(1,Real32) / Real(49,Real32) )
Type Is (Real (Real64))
a = atan ( Real(1,Real64) / Real(49,Real64) )
Type Is (Real (Real128))
a = atan ( Real(1,Real128) / Real(49,Real128) )
End Select
End Subroutine takano
Subroutine matc_a &
( &
a, strategy &
)
Class (*), Intent (out) :: a
Character (len=*) :: strategy
Select Case (Trim (strategy))
Case ("takano")
Select Type (a)
Type Is (Real (Real32))
Call takano (a)
Type Is (Real (Real64))
Call takano (a)
Type Is (Real (Real128))
Call takano (a)
End Select
End Select
End Subroutine matc_a
最佳答案
是的,您可以只使用较短的版本并避免第一种类型选择。
无论您是否在 takano
内使用它都没有关系。重要的是它接受多态虚拟参数。
顺便说一句,在我看来,您正在用 Fortran 模拟动态类型语言。我不确定这是否明智。
关于Fortran 级联多态性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27526665/