说我有一个Fortran派生类型Fortran派生类型分配
type :: atype
integer :: n
integer :: a(10)
integer, allocatable :: b(:)
end type
,我有这种类型的
type(atype) :: t1, t2
当我做如下分配到底发生了什么的两个实例?
t2 = t1
我感兴趣的,是因为我想正确地作出派生类型变量的含义,标量分量应该是平等的副本,阵列组件中的每个元素应该是平等和分配数组应具有相同的分配的大小和元素应该是平等的。此刻,我只想写一个子程序,其副本和正确分配的组件。
subroutine copy_atype(from, to)
type(atype) :: from, to
to%n = from%n
to%a = from%a
if (allocated(to%b)) deallocate(to%b)
if (allocated(from%b) then
allocate(to%b(size(from%b)))
to%b = from%b
end if
end subroutine
我将不胜感激指示适当的部分在标准。
我使用gfortran 4.7。
好知道,但不正是我一直在寻找。 – stiaan