Debian Codegraph @

gcc/testsuite/gfortran.dg/c-interop/note-5-3.f90

raw
1 ! { dg-do run }
2 !
3 ! TS 29113
4 ! NOTE 5.3
5 ! The intrinsic inquiry function RANK can be used to inquire about the
6 ! rank of a data object. The rank of an assumed-rank object is zero if
7 ! the rank of the corresponding actual argument is zero.
8
9 program test
10
11 integer :: scalar, array_1d(10), array_2d(3, 3)
12
13 call testit (scalar, array_1d, array_2d)
14
15 contains
16
17 function test_rank (a)
18 integer :: test_rank
19 integer :: a(..)
20
21 test_rank = rank (a)
22 end function
23
24 subroutine testit (a0, a1, a2)
25 integer :: a0(..), a1(..), a2(..)
26
27 integer, target :: b0, b1(10), b2(3, 3)
28 integer, allocatable :: c0, c1(:), c2(:,:)
29 integer, pointer :: d0, d1(:), d2(:,:)
30
31 ! array descriptor passed from caller through testit to test_rank
32 if (test_rank (a0) .ne. 0) stop 100
33 if (test_rank (a1) .ne. 1) stop 101
34 if (test_rank (a2) .ne. 2) stop 102
35
36 ! array descriptor created locally here, fixed size
37 if (test_rank (b0) .ne. 0) stop 200
38 if (test_rank (b1) .ne. 1) stop 201
39 if (test_rank (b2) .ne. 2) stop 202
40
41 ! allocatable arrays don't actually have to be allocated.
42 if (test_rank (c0) .ne. 0) stop 300
43 if (test_rank (c1) .ne. 1) stop 301
44 if (test_rank (c2) .ne. 2) stop 302
45
46 ! pointer arrays do need to point at something.
47 d0 => b0
48 d1 => b1
49 d2 => b2
50 if (test_rank (d0) .ne. 0) stop 400
51 if (test_rank (d1) .ne. 1) stop 401
52 if (test_rank (d2) .ne. 2) stop 402
53
54 end subroutine
55 end program