pgf90 7.2でのpresent()組み込み関数の動作を理解していません。これをテストするために20行のサンプルプログラムを作成しましたが、結果はまだ意味がありません。観察:
subroutine testopt(one,two,three,four,five)
implicit none
integer, intent(in) :: one,two
integer, intent(out) :: three
integer, intent(in), optional :: four
integer, intent(out), optional :: five
three = one + two
print *,"present check: ",present(four),present(five)
if (present(four) .and. present(five)) then
five = four*four
end if
end subroutine testopt
メインプログラムからtestopt(1,2、(any variable))を呼び出すと、「present check:TF」と出力されます。ただし、I:サブプログラムからtestopt(1,2、(any variable))を呼び出すと、「present check:TT」と出力されます。どちらの場合も「presentcheck:F F」が表示されると予想しました。これは、オプションではない3つの引数のみを使用してサブルーチンを呼び出しており、オプションの引数はどちらも呼び出していないためです。なぜこのように動作するのか理解できず、これが私が取り組んでいるプログラムに大きなバグを引き起こしています。洞察に感謝します。ありがとう。