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(100, 100), target :: xy
11 integer, dimension(:, :), pointer :: window
16 window => xy(10:50, 30:60)
19 window (41, 31) = 4161
23 t = associated (window, xy(10:50, 30:60))
24 if (.not.t) call abort ()
25 if (window(1, 1) .ne. xy(10, 30)) call abort ()
26 if (window(41, 31) .ne. xy(50, 60)) call abort ()
27 if (window(1, 31) .ne. xy(10, 60)) call abort ()
28 if (window(41, 1) .ne. xy(50, 30)) call abort ()
29 if (xy(9, 29) .ne. 0) call abort ()
30 if (xy(51,29 ) .ne. 0) call abort ()
31 if (xy(9, 60) .ne. 0) call abort ()
32 if (xy(51, 60) .ne. 0) call abort ()
33 if (xy(11, 31) .ne. 10) call abort ()
34 if (xy(49, 59) .ne. 10) call abort ()
35 if (xy(11, 59) .ne. 10) call abort ()
36 if (xy(49, 31) .ne. 10) call abort ()
39 subroutine sub1 (a, ap)
40 integer, pointer :: ap(:, :)
41 integer, target :: a(10, 10)
46 subroutine nullify_pp (a)
47 integer, pointer :: a(:, :)
49 if (.not. associated (a)) call abort ()
53 subroutine associate_1 ()
54 integer, pointer :: a(:, :), b(:, :)
56 subroutine nullify_pp (a)
57 integer, pointer :: a(:, :)
58 end subroutine nullify_pp
63 if (.not. associated(a)) call abort ()
64 if (.not. associated(b)) call abort ()
66 if (associated (a)) call abort ()
67 if (.not. associated (b)) call abort ()
70 subroutine pointer_to_derived_1 ()
73 type(record), pointer :: rp
78 type(record2), pointer :: r1p
83 type(record1), pointer :: r2p
86 type(record), target :: e1, e2, e3
87 type(record1), target :: r1
88 type(record2), target :: r2
90 nullify (r1%r1p, r2%r2p, e1%rp, e2%rp, e3%rp)
91 if (associated (r1%r1p)) call abort ()
92 if (associated (r2%r2p)) call abort ()
93 if (associated (e2%rp)) call abort ()
94 if (associated (e1%rp)) call abort ()
95 if (associated (e3%rp)) call abort ()
105 if (.not. associated (r1%r1p)) call abort ()
106 if (.not. associated (r2%r2p)) call abort ()
107 if (.not. associated (e1%rp)) call abort ()
108 if (.not. associated (e2%rp)) call abort ()
109 if (associated (e3%rp)) call abort ()
110 if (r1%r1p%value .ne. 22) call abort ()
111 if (r2%r2p%value .ne. 11) call abort ()
112 if (e1%value .ne. 33) call abort ()
113 if (e2%value .ne. 44) call abort ()
114 if (e3%value .ne. 55) call abort ()
115 if (r1%value .ne. 11) call abort ()
116 if (r2%value .ne. 22) call abort ()
120 subroutine associated_2 ()
121 integer, pointer :: xp(:, :)
122 integer, target :: x(10, 10)
123 integer, target :: y(100, 100)
125 subroutine sub1 (a, ap)
126 integer, pointer :: ap(:, :)
127 integer, target :: a(10, 1)
132 if (.not. associated (xp)) call abort ()
134 if (associated (xp, y)) call abort ()
135 if (.not. associated (xp, x)) call abort ()