%begin code snippet
subroutine inter3z(fig)
…
logical, optional, intent(in) :: fig
…
if(present(fig)) then
…
%end code snippet
This code takes the branch for present(fig) = .true. even when no arguments were supplied!
I have verified this using pfg90 v5.2-4 with flags
-g -Mbounds -Mdclchk -Mchkfpstk
on RHEL3.0, Intel Pentium 4/Xeon.
Hello,
The problem is that the optional argument is getting assigned a value. To fix, you need to add an interface so that the caller recognizes that fig is optional.
Example:
program present_tester
! Comment out the interface to recreate the problem
interface
subroutine present_test(fig)
character, optional, intent(in) :: fig
end subroutine present_test
end interface
call present_test()
call present_test('a')
end program present_tester
subroutine present_test(fig)
character, optional, intent(in) :: fig
if (present(fig)) then
write(*,*) 'Is Present ', fig
else
write(*,*) 'Not Present'
end if
end subroutine present_test
Hope this helps,
Mat