Originally posted by: hemangh
Is there a way to "painlessly" copy those elements of an extended type that are shared with its base type into a new base type array?
For example I want to copy a everything in the type (truck) :: A into a type(vehicle)::B, except for anual_milage. I don't want to go over each element of type A and pick and choose.
module types
implicit none
type :: vehicle
integer :: wheels
character(len=6),allocatable,dimension(:) :: service_date
end type vehicle
type,extends(vehicle) :: truck
real, allocatable, dimension(:,:) :: anual_miles
end type truck
type track
class(vehicle), pointer :: object => null()
end type track
end module
program test_alloc
use types
implicit none
type(truck)::A
type(vehicle) :: B
A%wheels = 8
allocate(A%service_date(2))
A%service_date(1)='May16'
A%service_date(2)='Sep16'
allocate(A%anual_miles(10,10:17))
A%anual_miles = 0.0
A%anual_miles(1,10) = 3067.1
call fill_x(B,A)
end program test_alloc
subroutine fill_x(B,A)
use types
class(vehicle), target :: A
class(vehicle), allocatable :: B
! allocate(B, mold=A)
! what should go here?
end subroutine
#C/C++andFortran#Fortran-Cafe-for-AIX