3 ! Basic tests of SELECT RANK
5 ! Contributed by Paul Thomas <pault@gcc.gnu.org>
11 type, extends(mytype
) :: thytype
15 ! Torture using integers
17 integer, dimension(2,2) :: y
= reshape ([1,2,3,4],[2,2])
18 integer, dimension(4) :: z
= [1,2,3,4]
19 integer, dimension(2,2,2) :: q
= reshape ([11,12,13,14,15,16,17,18],[2,2,2])
23 if (any (y
.ne
. reshape ([10,11,12,13], [2,2]))) stop 1
27 if (any (q
.ne
. reshape ([11,12,10,11,15,16,12,13], [2,2,2]))) stop 2
34 type(mytype
), allocatable
, dimension(:,:) :: t
35 type(mytype
), allocatable
:: u
37 allocate (t
, source
= reshape ([(mytype(real(i
)), i
= 1,4)],[2,2]))
39 if (any (size (t
) .ne
. [1,1])) stop 3 ! 't' has been reallocated!
40 if (abs (t(1,1)%r
- 42.0) .ge
. 1e-6) stop 4
41 allocate (u
, source
= mytype(42.0))
48 class(mytype
), allocatable
, dimension(:,:) :: v
49 class(mytype
), allocatable
:: w
51 allocate (v
, source
= reshape ([(mytype(real(i
)), i
= 1,4)],[2,2]))
57 if (any (ubound (v
) .ne
. [3,3])) stop 6
58 if (any (abs (v
%r
- 99.0) .ge
. 1e-6)) stop 7
59 if (any (v
%i
.ne
. 42)) stop 8
61 allocate (w
, source
= thytype(42.0, 99))
65 ! Check unlimited polymorphic.
68 class(*), allocatable
, dimension(:,:,:) :: v
70 allocate (v
, source
= reshape ([(i
, i
= 1,8)],[2,2,2]))
76 if (any (ubound(v
) .ne
. [2,2,1])) stop 10
77 if (abs (sum (v
) - 10.0) .gt
. 1e-6) stop 11
83 recursive subroutine ifoo(w
, chr
)
84 integer, dimension(..) :: w
87 OUTER
: select
rank (x
=> w
)
89 if ((chr
.eq
. 'y') .and
. (any (x(1,:) .ne
. [1,3]))) stop 12
90 if ((chr
.eq
. 'r') .and
. (any (x(1,:) .ne
. [13,17]))) stop 13
91 x
= reshape ([10,11,12,13], [2,2])
93 if ((chr
.eq
. 'i') .and
. (x
.ne
. 42)) stop 14
95 if ((chr
.eq
. 'w') .and
. (any (x(1:4) .ne
. [10,11,12,13]))) stop 15
97 if ((chr
.eq
. 'z') .and
. (rank (x
) .ne
. 1)) stop 16
98 if ((chr
.eq
. 'q') .and
. (rank (x
) .ne
. 3)) stop 17
99 INNER
: select
rank (x
)
101 if ((chr
.eq
. 'z') .and
. (any (x(1:4) .ne
. [1,2,3,4]))) stop 18
103 ! Pass a rank 2 section otherwise an infinite loop ensues.
104 call ifoo(x(:,2,:), 'r')
110 integer, dimension(*) :: x
115 subroutine tfoo(w
, chr
)
116 type(mytype
), dimension(..), allocatable
:: w
119 type(mytype
), dimension(2,2) :: r
123 if (chr
.eq
. 't') then
124 r
= reshape ([(mytype(real(i
)), i
= 1,4)],[2,2])
125 if (any (abs (x
%r
- r
%r
) .gt
. 1e-6)) stop 19
126 if (allocated (x
)) deallocate (x
)
128 x(1,1) = mytype (42.0)
131 if ((chr
.eq
. 'u') .and
. (rank (x
) .ne
. 0)) stop 20
135 subroutine cfoo(w
, chr
)
136 class(mytype
), dimension(..), allocatable
:: w
139 type(mytype
), dimension(2,2) :: r
145 if (chr
.eq
. 'v') then
146 r
= reshape ([(mytype(real(i
)), i
= 1,4)],[2,2])
147 if (any (abs (c
%r
- r
%r
) .gt
. 1e-6)) stop 21
152 if (allocated (c
)) deallocate (c
)
153 allocate (c(3,3), source
= thytype (99.0, 42))
155 if ((chr
.eq
. 'w') .and
. (rank (c
) .ne
. 0)) stop 23
159 subroutine ufoo(w
, chr
)
160 class(*), dimension(..), allocatable
:: w
168 if (chr
.eq
. 'v' .and
. (sum (c
) .ne
. 36)) stop 24
172 if (allocated (c
)) deallocate(c
)
173 allocate (c
, source
= reshape ([(real(i
), i
= 1,4)],[2,2,1]))