| 1 |
! Program to test the PRESENT intrinsic |
| 2 |
program intrinsic_present |
| 3 |
implicit none |
| 4 |
integer a |
| 5 |
integer, pointer :: b |
| 6 |
integer, dimension(10) :: c |
| 7 |
integer, pointer, dimension(:) :: d |
| 8 |
|
| 9 |
if (testvar()) STOP 1 |
| 10 |
if (.not. testvar(a)) STOP 2 |
| 11 |
if (testptr()) STOP 3 |
| 12 |
if (.not. testptr(b)) STOP 4 |
| 13 |
if (testarray()) STOP 5 |
| 14 |
if (.not. testarray(c)) STOP 6 |
| 15 |
if (testparray()) STOP 7 |
| 16 |
if (.not. testparray(d)) STOP 8 |
| 17 |
|
| 18 |
contains |
| 19 |
logical function testvar (p) |
| 20 |
integer, optional :: p |
| 21 |
testvar = present(p) |
| 22 |
end function |
| 23 |
|
| 24 |
logical function testptr (p) |
| 25 |
integer, pointer, optional :: p |
| 26 |
testptr = present(p) |
| 27 |
end function |
| 28 |
|
| 29 |
logical function testarray (p) |
| 30 |
integer, dimension (10), optional :: p |
| 31 |
testarray = present(p) |
| 32 |
end function |
| 33 |
|
| 34 |
logical function testparray (p) |
| 35 |
integer, pointer, dimension(:), optional :: p |
| 36 |
testparray = present(p) |
| 37 |
end function |
| 38 |
|
| 39 |
end program |
| 40 |
|