| 1 |
! Program to test the upper and lower bound intrinsics |
| 2 |
program testbounds |
| 3 |
implicit none |
| 4 |
real, dimension(:, :), allocatable :: a |
| 5 |
integer, dimension(5) :: j |
| 6 |
integer i |
| 7 |
|
| 8 |
! Check compile time simplification |
| 9 |
if (lbound(j,1).ne.1 .or. ubound(j,1).ne.5) STOP 1 |
| 10 |
|
| 11 |
allocate (a(3:8, 6:7)) |
| 12 |
|
| 13 |
! With one parameter |
| 14 |
j = 0; |
| 15 |
j(3:4) = ubound(a) |
| 16 |
if (j(3) .ne. 8) STOP 1 |
| 17 |
if (j(4) .ne. 7) STOP 2 |
| 18 |
|
| 19 |
! With two parameters, assigning to an array |
| 20 |
j = lbound(a, 1) |
| 21 |
if ((j(1) .ne. 3) .or. (j(5) .ne. 3)) STOP 3 |
| 22 |
|
| 23 |
! With a variable second parameter |
| 24 |
i = 2 |
| 25 |
i = lbound(a, i) |
| 26 |
if (i .ne. 6) STOP 4 |
| 27 |
|
| 28 |
call test(a) |
| 29 |
contains |
| 30 |
subroutine test (a) |
| 31 |
real, dimension (1:, 1:) :: a |
| 32 |
integer i |
| 33 |
|
| 34 |
i = 2 |
| 35 |
if ((ubound(a, 1) .ne. 6) .or. (ubound(a, i) .ne. 2)) STOP 5 |
| 36 |
end subroutine |
| 37 |
end program |
| 38 |
|