FORTRAN如何与可选参数交互?

Inq*_*Kea 1 fortran

在一个调用函数中我有这个:

call ESMF_TimeGet( date, yy=year, mm=month, dd=day, s=sec, rc=rc)
Run Code Online (Sandbox Code Playgroud)

签名ESMF_TimeSet是:

! ESMF_TimeGet - Get value in user-specified units
subroutine ESMF_TimeGet(time, YY, YRl, MM, DD, D, Dl, H, M, S, Sl, MS, &
                        US, NS, d_, h_, m_, s_, ms_, us_, ns_, Sn, Sd, &
                        dayOfYear, dayOfYear_r8, dayOfYear_intvl,      &
                        timeString, rc)


    type(ESMF_Time), intent(in) :: time
    integer, intent(out), optional :: YY
    integer(ESMF_KIND_I8), intent(out), optional :: YRl
    integer, intent(out), optional :: MM
    integer, intent(out), optional :: DD
    integer, intent(out), optional :: D
    integer(ESMF_KIND_I8), intent(out), optional :: Dl
    integer, intent(out), optional :: H
    integer, intent(out), optional :: M
    integer, intent(out), optional :: S
    integer(ESMF_KIND_I8), intent(out), optional :: Sl
    integer, intent(out), optional :: MS
    integer, intent(out), optional :: US
    integer, intent(out), optional :: NS
    double precision, intent(out), optional :: d_
    double precision, intent(out), optional :: h_
    double precision, intent(out), optional :: m_
    double precision, intent(out), optional :: s_
    double precision, intent(out), optional :: ms_
    double precision, intent(out), optional :: us_
    double precision, intent(out), optional :: ns_
    integer, intent(out), optional :: Sn
    integer, intent(out), optional :: Sd
    integer, intent(out), optional :: dayOfYear
    real(ESMF_KIND_R8), intent(out), optional :: dayOfYear_r8
    character (len=*), intent(out), optional :: timeString
    type(ESMF_TimeInterval), intent(out), optional :: dayOfYear_intvl
    integer, intent(out), optional :: rc

    type(ESMF_TimeInterval) :: day_step
    integer :: ierr
Run Code Online (Sandbox Code Playgroud)

当我调用时ESMF_TimeSet子程序如何能够将yy=yr参数转换为yy子程序内的变量(并且类似于mmdd)?此外,FORTRAN是否关心变量的区分大小写?

Wil*_*cat 6

子程序如何将"yy = yr"参数转换为子程序中的yy变量?

yy您的程序中没有变量.只有yy虚拟参数.当您调用此过程时,您使用所谓的命名参数.此功能并非特定于Fortran.但是你的可选参数有什么问题?

对于mm和dd也一样.FORTRAN是否关心变量的区分大小写?

Fortran是不区分大小写的语言.所以不,它并不关心.


好的.我会尝试解释一些基础知识,因为我在理解你的评论时遇到了一些困难.:)

在程序方面,Fortran术语在某些方面与"普通"术语不同:

  • 区分过程(通过参数执行一些返回多个结果的任务)和函数(在表达式中调用并返回表达式中使用的单个值),同时共同调用子例程是很常见的.在Fortran中,我们有子程序函数共同调用过程.
  • 在调用过程时,您通过参数传递一些信息.通常在过程定义中出现的实体称为形式参数,过程调用中出现的实体称为实际参数.在Fortran中,正式参数称为伪参数.请注意,因为伪参数通常被称为无意义的参数,仅用于符合API,即Delphi中的EmptyParam.

调用过程时(以Fortran标准引用)

实际参数列表标识实际参数与过程的伪参数之间的对应关系.

所以基本上对应是按位置的.某些语言(包括Fortran)也可以通过关键字建立对应关系.长话短说:

关键字是伪参数名称,并且在第一个关键字参数后必须没有其他位置参数.
(c)Michael Metcalf,John Reid,Malcolm Cohen.现代Fortran解释.

有关详细信息,请参阅Fortran Standard(您可以通过此处提供的链接获取Fortran 2008标准的最终草案),12.5.2实际参数,伪参数和参数关联.

因此,关键字参数是一种称为命名参数或其他语言中的命名参数的功能.

但是这个功能并不是唯一一个可以帮助程序员编写简洁易读的代码来调用程序而不会重载的功能.有些语言也有默认参数.Fortran具有类似的功能:所谓的可选参数.它看起来有点不同,但目标是一样的.

关键字参数通常与可选参数一起使用.例如,当您在参数列表的中间省略可选参数时,应该使用关键字参数.

那么你的问题是什么?