This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: CLASS array patch latest
- From: Arjen Markus <arjen dot markus895 at gmail dot com>
- To: Paul Richard Thomas <paul dot richard dot thomas at gmail dot com>
- Cc: Tobias Burnus <burnus at net-b dot de>, Janus Weil <janus at gcc dot gnu dot org>, fortran at gcc dot gnu dot org
- Date: Sun, 13 Nov 2011 21:08:50 +0100
- Subject: Re: CLASS array patch latest
- References: <CAGkQGiKFViksqU-tjt=-hND-OQrystj33T+hAc2f0tmRocic6g@mail.gmail.com>
Hello,
2011/11/13 Paul Richard Thomas <paul.richard.thomas@gmail.com>:
> ?subroutine reallocate (a)
> ? ?class(base_type), dimension(:), allocatable, intent(inout) :: a
> ? ?class(base_type), dimension(:), allocatable :: tmp
>
> ? ?allocate (tmp (2 * size (a))) ! how to alloc b with same type as a ?
>
> ! This is one way how!
> ! ? ?select type (a)
> ! ? ? ?type is (base_type); ? ? ?allocate (base_type :: tmp (2 * size (a)))
> ! ? ? ?type is (extended_type); ?allocate (extended_type :: tmp (2 * size (a)))
> ! ? ?end select
>
You can use the source= keyword, can't you?
allocate( tmp(2*size(a), source = a(1) )
(I think the a(1) is required, as the contents of a are copied)
Regards,
Arjen