1 ! Program to test the ASSOCIATED intrinsic.
2 program intrinsic_associated
3 call pointer_to_section ()
5 call pointer_to_derived_1 ()
9 subroutine pointer_to_section ()
10 integer, dimension(5, 5), target
:: xy
11 integer, dimension(:, :), pointer :: window
15 window
=> xy(2:4, 3:4)
22 t
= associated (window
, xy(2:4, 3:4))
23 if (.not
.t
) call abort ()
24 ! Check that none of the array got mangled
25 if ((xy(2, 3) .ne
. 0101) .or
. (xy (4, 4) .ne
. 4161) &
26 .or
. (xy(4, 3) .ne
. 4101) .or
. (xy (2, 4) .ne
. 0161)) call abort ()
27 if (any (xy(:, 1:2) .ne
. 0)) call abort ()
28 if (any (xy(:, 5) .ne
. 0)) call abort ()
29 if (any (xy (1, 3:4) .ne
. 0)) call abort ()
30 if (any (xy (5, 3:4) .ne
. 0)) call abort ()
31 if (xy(3, 3) .ne
. 10) call abort ()
32 if (xy(3, 4) .ne
. 10) call abort ()
33 if (any (xy(2:4, 3:4) .ne
. window
)) call abort ()
36 subroutine sub1 (a
, ap
)
37 integer, pointer :: ap(:, :)
38 integer, target
:: a(10, 10)
43 subroutine nullify_pp (a
)
44 integer, pointer :: a(:, :)
46 if (.not
. associated (a
)) call abort ()
50 subroutine associate_1 ()
51 integer, pointer :: a(:, :), b(:, :)
53 subroutine nullify_pp (a
)
54 integer, pointer :: a(:, :)
55 end subroutine nullify_pp
60 if (.not
. associated(a
)) call abort ()
61 if (.not
. associated(b
)) call abort ()
63 if (associated (a
)) call abort ()
64 if (.not
. associated (b
)) call abort ()
67 subroutine pointer_to_derived_1 ()
70 type(record), pointer :: rp
75 type(record2
), pointer :: r1p
80 type(record1
), pointer :: r2p
83 type(record), target
:: e1
, e2
, e3
84 type(record1
), target
:: r1
85 type(record2
), target
:: r2
87 nullify (r1
%r1p
, r2
%r2p
, e1
%rp
, e2
%rp
, e3
%rp
)
88 if (associated (r1
%r1p
)) call abort ()
89 if (associated (r2
%r2p
)) call abort ()
90 if (associated (e2
%rp
)) call abort ()
91 if (associated (e1
%rp
)) call abort ()
92 if (associated (e3
%rp
)) call abort ()
102 if (.not
. associated (r1
%r1p
)) call abort ()
103 if (.not
. associated (r2
%r2p
)) call abort ()
104 if (.not
. associated (e1
%rp
)) call abort ()
105 if (.not
. associated (e2
%rp
)) call abort ()
106 if (associated (e3
%rp
)) call abort ()
107 if (r1
%r1p
%value
.ne
. 22) call abort ()
108 if (r2
%r2p
%value
.ne
. 11) call abort ()
109 if (e1
%value
.ne
. 33) call abort ()
110 if (e2
%value
.ne
. 44) call abort ()
111 if (e3
%value
.ne
. 55) call abort ()
112 if (r1
%value
.ne
. 11) call abort ()
113 if (r2
%value
.ne
. 22) call abort ()
117 subroutine associated_2 ()
118 integer, pointer :: xp(:, :)
119 integer, target
:: x(10, 10)
120 integer, target
:: y(100, 100)
122 subroutine sub1 (a
, ap
)
123 integer, pointer :: ap(:, :)
124 integer, target
:: a(10, 1)
129 if (.not
. associated (xp
)) call abort ()
131 if (associated (xp
, y
)) call abort ()
132 if (.not
. associated (xp
, x
)) call abort ()