CLASS array patch latest

Arjen Markus arjen.markus895@gmail.com
Sun Nov 13 20:10:00 GMT 2011


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



More information about the Fortran mailing list