我试图添加转换函数以在不同衍生类型之间进行转换,我希望它们是第一个派生类型的函数,并返回另一个派生类型。只要它们在同一文件和模块中,这没有问题。但是,我真的希望它们能够分成多个文件,否则将会是一个非常大的文件。由于Fortran的依赖性和名称空间的缺乏,我无法弄清楚如何做到这一点。
是否有办法实现这一点?
以下是我想将其分成两个文件的示例(每个派生类型一个文件)。
是否有办法实现这一点?
以下是我想将其分成两个文件的示例(每个派生类型一个文件)。
Module ConversionStuff
implicit none
type A_T
real :: a, b, c
contains
procedure :: toX => a_toX
end type A_T
type X_T
real :: x, y, z
contains
procedure :: toA => x_toA
end type X_T
contains
function a_toX(this) result(x)
class(A_T), intent(inout) :: this
type(X_T) :: x
x%x = this%a * 2
x%y = this%b * 2
x%z = this%c * 2
end function a_toX
function x_toA(this) result(a)
class(X_T), intent(inout) :: this
type(A_T) :: a
a%a = this%x * 0.5
a%b = this%y * 0.5
a%c = this%z * 0.5
end function x_toA
End Module ConversionStuff
如果有打字错误,我很抱歉。在这台计算机上,我没有简单的方法来编译Fortran。