| 1 | c Fortran 77 Standard Sec. 5, Arrays and Substrings
|
|---|
| 2 | c This uses subscript triplets (a.k.a. array slices) that were only introduced
|
|---|
| 3 | c in Fortran 90.
|
|---|
| 4 | program p
|
|---|
| 5 | implicit none
|
|---|
| 6 | integer a(6), b(0:5), c(-3:2), d(10:10,6)
|
|---|
| 7 | logical h(6)
|
|---|
| 8 | complex f(2,3,4,5,6,7)
|
|---|
| 9 | h = (/.true., .true., .true., .false., .false., .false./)
|
|---|
| 10 | c$ civl assert(all(h(1:3)))
|
|---|
| 11 | c$ civl assert(any(h(3:6)))
|
|---|
| 12 | c$ civl assert(.not. all(h(1:4)))
|
|---|
| 13 | c$ civl assert(.not. any(h(4:6)))
|
|---|
| 14 |
|
|---|
| 15 | a = (/ 1, 2, 3, 4, 5, 6 /)
|
|---|
| 16 | b = a
|
|---|
| 17 | c$ civl assert(all(a .eq. b))
|
|---|
| 18 | c = 0
|
|---|
| 19 | c(-3:-1) = a(1:3)
|
|---|
| 20 | c$ civl assert(all(c .eq. a .eqv. h))
|
|---|
| 21 | c(0:) = b(3:5)
|
|---|
| 22 | c$ civl assert(c(1) .eq. a(5))
|
|---|
| 23 | d(10,:) = a
|
|---|
| 24 | c$ civl assert(sum(d(10,1:2)) .eq. sum(a(1:2)))
|
|---|
| 25 | f(2,3,4,5,6,7) = (1,-2)
|
|---|
| 26 | c$ civl assert(imag(f(2,3,4,5,6,7)) .eq. -2.0)
|
|---|
| 27 |
|
|---|
| 28 | c$ civl assert(all(a(::2) .eq. (/1,3,5/)))
|
|---|
| 29 | c$ civl assert(all(a(2:6:2) .eq. (/2,4,6/)))
|
|---|
| 30 |
|
|---|
| 31 | a = a + 6
|
|---|
| 32 | c$ civl assert(all(a .eq. (/6,7,8,9,10,11,12/)))
|
|---|
| 33 | a = 2 * b + a
|
|---|
| 34 | c$ civl assert(all(a .eq. (/8,11,14,17,20,23,26/)))
|
|---|
| 35 |
|
|---|
| 36 | c N692 Sec. 6.2.2.4.1 "a subscript in a subscript triplet need not be within
|
|---|
| 37 | c the declared bounds for that dimension if all values used in selecting the
|
|---|
| 38 | c array elements are within the declared bounds."
|
|---|
| 39 | c$ civl assert(all(a(2:7:2) .eq. (/2,4,6/)))
|
|---|
| 40 |
|
|---|
| 41 | c "When the stride is negative, the sequence begins with the first subscript
|
|---|
| 42 | c and proceeds in increments of the stride down to the smallest such integer
|
|---|
| 43 | c equal to or greater than the second subscript"
|
|---|
| 44 | c$ civl assert(all(a(6:1:-2) .eq. (/6,4,2/)))
|
|---|
| 45 | end program
|
|---|