- #1
sghan
- 10
- 1
Hi all,
When I use Present(x) to check for the presence of an optional variable, I am getting TRUE even when the subroutine call clearly does NOT contain the optional variable. See here the call to test_present(a,b):
program options
implicit none
real*8 a,b
real*8 c
a = 10.d0
b = 5.d0
c = 3.d0
call test_present(a,b)
end program options
! In a separate file:
subroutine test_present(a,b,c)
implicit none
real*8 a,b
real*8, optional :: c
logical value
value = present(c)
write(*,*)"is c present?", value !THIS RETURNS TRUE!
end subroutine test_present
Why does present(c) return TRUE even though c is not given in the call? Strangely, if variables a,b are of type integer, present(c) returns false as it should.
Thanks!
When I use Present(x) to check for the presence of an optional variable, I am getting TRUE even when the subroutine call clearly does NOT contain the optional variable. See here the call to test_present(a,b):
program options
implicit none
real*8 a,b
real*8 c
a = 10.d0
b = 5.d0
c = 3.d0
call test_present(a,b)
end program options
! In a separate file:
subroutine test_present(a,b,c)
implicit none
real*8 a,b
real*8, optional :: c
logical value
value = present(c)
write(*,*)"is c present?", value !THIS RETURNS TRUE!
end subroutine test_present
Why does present(c) return TRUE even though c is not given in the call? Strangely, if variables a,b are of type integer, present(c) returns false as it should.
Thanks!