2 ! { dg-options "-fcoarray=single" }
4 ! Run-time test for IMAGE_INDEX with cobounds only known at
5 ! the compile time, suitable for any number of NUM_IMAGES()
6 ! For compile-time cobounds, the -fcoarray=lib version still
7 ! needs to run-time evalulation if image_index returns > 1
8 ! as image_index is 0 if the index would exceed num_images().
10 ! Please set num_images() to >= 13, if possible.
15 program test_image_index
17 integer :: index1
, index2
, index3
20 integer, allocatable
:: a(:)[:,:,:], b(:)[:,:], c(:,:)[:]
21 integer, save :: d(2)[-1:3, *]
22 integer, save :: e(2)[-1:-1, 3:*]
24 one
= num_images() == 1
26 allocate(a(1)[3:3, -4:-3, 88:*])
27 allocate(b(2)[-1:0,0:*])
30 index1
= image_index(a
, [3, -4, 88] )
31 index2
= image_index(b
, [-1, 0] )
32 index3
= image_index(c
, [1] )
33 if (index1
/= 1 .or
. index2
/= 1 .or
. index3
/= 1) STOP 1
36 index1
= image_index(a
, [3, -3, 88] )
37 index2
= image_index(b
, [0, 0] )
38 index3
= image_index(c
, [2] )
40 if (one
.and
. (index1
/= 0 .or
. index2
/= 0 .or
. index3
/= 0)) &
42 if (.not
. one
.and
. (index1
/= 2 .or
. index2
/= 2 .or
. index3
/= 2)) &
46 index1
= image_index(d
, [-1, 1] )
47 index2
= image_index(d
, [0, 1] )
49 if (one
.and
. (index1
/= 1 .or
. index2
/= 0)) &
51 if (.not
. one
.and
. (index1
/= 1 .or
. index2
/= 2)) &
54 index1
= image_index(e
, [-1, 3] )
55 index2
= image_index(e
, [-1, 4] )
57 if (one
.and
. (index1
/= 1 .or
. index2
/= 0)) &
59 if (.not
. one
.and
. (index1
/= 1 .or
. index2
/= 2)) &
64 ! The following test is in honour of the F2008 standard:
66 allocate(a (10) [10, 0:9, 0:*])
68 index1
= image_index(a
, [1, 0, 0] )
69 index2
= image_index(a
, [3, 1, 2] ) ! = 213, yeah!
70 index3
= image_index(a
, [3, 1, 0] ) ! = 13
72 if (num_images() < 13 .and
. (index1
/= 1 .or
. index2
/= 0 .or
. index3
/= 0)) &
74 if (num_images() >= 213 .and
. (index1
/= 1 .or
. index2
/= 213 .or
. index3
/= 13)) &
76 if (num_images() >= 13 .and
. (index1
/= 1 .or
. index2
/= 0 .or
. index3
/= 13)) &
81 subroutine test(n
, a
, b
, c
)
83 integer :: a(1)[3*n
:3*n
, -4*n
:-3*n
, 88*n
:*], b(2)[-1*n
:0*n
,0*n
:*], c(3*n
,3*n
)[*]
85 index1
= image_index(a
, [3, -4, 88] )
86 index2
= image_index(b
, [-1, 0] )
87 index3
= image_index(c
, [1] )
88 if (index1
/= 1 .or
. index2
/= 1 .or
. index3
/= 1) STOP 11
91 index1
= image_index(a
, [3, -3, 88] )
92 index2
= image_index(b
, [0, 0] )
93 index3
= image_index(c
, [2] )
95 if (one
.and
. (index1
/= 0 .or
. index2
/= 0 .or
. index3
/= 0)) &
97 if (.not
. one
.and
. (index1
/= 2 .or
. index2
/= 2 .or
. index3
/= 2)) &
100 end program test_image_index