Windscion
Joined: 27 Jul 2004 Posts: 1
|
Posted: Tue Dec 14, 2004 8:33 am Post subject: present() intrinsic does not function properly |
|
|
%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. |
|
mkcolg
Joined: 30 Jun 2004 Posts: 4996 Location: The Portland Group Inc.
|
Posted: Tue Dec 14, 2004 1:53 pm Post subject: |
|
|
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:
| Code: |
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 |
|