| 1 |
! Program to test functions returning arrays |
| 2 |
|
| 3 |
program testfnarray |
| 4 |
implicit none |
| 5 |
integer, dimension (6, 5) :: a |
| 6 |
integer n |
| 7 |
|
| 8 |
! These first two shouldn't require a temporary. |
| 9 |
a = 0 |
| 10 |
a = test(6, 5) |
| 11 |
if (a(1,1) .ne. 42) STOP 1 |
| 12 |
if (a(6,5) .ne. 43) STOP 2 |
| 13 |
|
| 14 |
a = 0 |
| 15 |
a(1:6:2, 2:5) = test2() |
| 16 |
if (a(1,2) .ne. 42) STOP 3 |
| 17 |
if (a(5,5) .ne. 43) STOP 4 |
| 18 |
|
| 19 |
a = 1 |
| 20 |
! This requires a temporary |
| 21 |
a = test(6, 5) - a |
| 22 |
if (a(1,1) .ne. 41) STOP 5 |
| 23 |
if (a(6,5) .ne. 42) STOP 6 |
| 24 |
|
| 25 |
contains |
| 26 |
|
| 27 |
function test (x, y) |
| 28 |
implicit none |
| 29 |
integer x, y |
| 30 |
integer, dimension (1:x, 1:y) :: test |
| 31 |
|
| 32 |
test(1, 1) = 42 |
| 33 |
test(x, y) = 43 |
| 34 |
end function |
| 35 |
|
| 36 |
function test2 () result (foo) |
| 37 |
implicit none |
| 38 |
integer, dimension (3, 4) :: foo |
| 39 |
|
| 40 |
foo(1, 1) = 42 |
| 41 |
foo(3, 4) = 43 |
| 42 |
end function |
| 43 |
|
| 44 |
end program |
| 45 |
|