我对PRESENT
Fortran 95 的语句有疑问。目前我正在使用 Silverfrost 的 Plato 和他们的 FTN95 编译器(在“Release Win32”模式下)。我想做的是创建一个 subroutine SUB(a,b)
,其中b
是一个可选变量。到目前为止一切顺利,但是当我尝试为b
with赋予新值时出现问题if (.NOT. present(b)) b=0
。这是代码:
module MOD
contains
subroutine SUB(a,b)
implicit none
integer :: a
integer,optional :: b
if (.NOT. present(b)) b=0
print*, a,b
end subroutine SUB
end module MOD
program TEST
use MOD
implicit none
integer :: i=2, j=1
call SUB(i,j)
call SUB(i)
call SUB(j)
end program TEST
有没有摆脱这种情况的优雅方法,或者我真的需要创建另一个变量,b_aux
例如,然后使用以下代码?:
if (present(b)) then
b_aux=b
else
b_aux=0
endif