3 ! Test functionality of pointer class arrays:
4 ! ALLOCATE with source, ASSOCIATED, DEALLOCATE, passing as arguments for
5 ! ELEMENTAL and non-ELEMENTAL procedures, SELECT TYPE and LOWER/UPPER.
10 type, extends(type1) :: type2
13 class(type1), pointer, dimension (:) :: x
15 allocate(x(2), source = type2(42,42.0))
16 call display(x, [1], [2], t2 = [type2(42,42.0),type2(42,42.0)])
17 call display(x, [1], [2], t2 = [type2(111,99.0),type2(111,99.0)])
18 if (associated (x)) deallocate (x)
20 allocate(x(1:4), source = [(type2(i,42.0 + float (i)), i = 1, 4)])
21 call display(x, [1], [4], t2 = [(type2(i,42.0 + float (i)), i = 1, 4)])
22 call display(x, [1], [4], t2 = [(type2(111,99.0), i = 1, 4)])
24 if (any (disp (x) .ne. [99.0,99.0,99.0,99.0])) call abort
26 if (associated (x)) deallocate (x)
28 allocate(x(1:4), source = type1(42))
29 call display(x, [1], [4], t1 = [(type1(42), i = 1, 4)])
30 call display(x, [1], [4], t1 = [type1(42),type1(99),type1(42),type1(42)])
31 if (any (disp (x) .ne. [0.0,0.0,0.0,0.0])) call abort
33 if (associated (x)) deallocate (x)
36 subroutine display(x, lower, upper, t1, t2)
37 class(type1), pointer, dimension (:) :: x
38 integer, dimension (:) :: lower, upper
39 type(type1), optional, dimension(:) :: t1
40 type(type2), optional, dimension(:) :: t2
43 if (present (t1)) then
44 if (any (x%i .ne. t1%i)) call abort
50 if (present (t2)) then
51 if (any (x%i .ne. t2%i)) call abort
52 if (any (x%r .ne. t2%r)) call abort
59 call bounds (x, lower, upper)
61 subroutine bounds (x, lower, upper)
62 class(type1), pointer, dimension (:) :: x
63 integer, dimension (:) :: lower, upper
64 if (any (lower .ne. lbound (x))) call abort
65 if (any (upper .ne. ubound (x))) call abort
67 elemental function disp(y) result(ans)
68 class(type1), intent(in) :: y