Fortran 90存在可选参数 [英] Fortran 90 Presence Of Optional Arguments

查看:918
本文介绍了Fortran 90存在可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白使用pgf90 7.2的present()内在函数的行为。我写了一个20行的示例程序来测试这个,但结果对我来说仍然没有意义。注意:

I do not understand the behavior of the present() intrinsic function with pgf90 7.2. I wrote a 20 line sample program to test this, but the results still make no sense to me. Observe:


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

如果我:call testopt(1,2, (任何变量))从我的主程序,它打印:现在检查:TF。但是,如果我从子程序中调用testopt(1,2,(任何变量)),它将打印:当前检查:T T。我希望在任何一种情况下都能看到现在的检查:F F,因为我只用3个非可选参数调用子程序,而没有任何可选参数。我无法理解为什么它会以这种方式行事,这导致了我正在开发的程序中的一个重大错误。我感谢任何见解。感谢。

if I: call testopt(1,2,(any variable)) from my main program, it prints: "present check: T F". However if I: call testopt(1,2,(any variable)) from a subprogram it prints: "present check: T T". I expected to see "present check: F F" in either case, because I am only calling the subroutine with the 3 non-optional arguments, and neither of the optional ones. I cannot fathom why it would behave this way, and this is causing a major bug in a program I am working on. I appreciate any insight. Thanks.

推荐答案

这篇关于Fortran 90存在可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆