說我有一個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