带有可选参数的Fortran函数 [英] Fortran Functions with optional arguments

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

问题描述

我想使用一个运算符 .ef。,但运算符不接受可选参数。是否有可能保留我的功能,并且能够让操作员也工作?

 模块核心
隐含无

接口操作符(.ef。)
模块过程fes
结束接口操作符(.ef。)

包含

功能fes&
(&
nm,wn&
)&
结果(位于)

逻辑位置
字符(Len = *),意图(In):: nm
字符(Len = *),意图(In),Optional :: wn

End Function

Gfortran正在返回以下问题:

  lib / scriptus / core.f:62:0:

函数fes& amp ;
1
错误:在(1)操作员界面的第二个参数不能是可选的


解决方案

您不允许为定义的操作提供可选参数。 Fortran 2008,Cl。 12.4.3.4.2。说:


<1> ...虚拟参数应该是非可选的虚拟数据对象...

blockquote>

这是编译器在发出错误时引用的内容:


错误: (1)处的操作员界面的第二个参数不能是可选的


注意:您可以拥有可选参数的过程,并且它们可以显示在模块中,但它们不能在带有操作符关键字的接口块中引用。你的函数 fes 看起来不错,这不是问题。你的问题是将操作符映射到函数的接口块。


I want to use an operator .ef. however the operator does not accept optional arguments. Is it possible to keep the my function and be able to have the operator working too?

Module Core
Implicit None

Interface Operator (.ef.)
  Module Procedure fes
End Interface Operator (.ef.)

Contains

Function fes    &
  (             &
    nm, wn      &
  )             &
    Result (located)

Logical :: located
Character (Len=*), Intent (In) :: nm
Character (Len=*), Intent (In), Optional :: wn 

End Function 

Gfortran is returning the following problem

lib/scriptus/core.f:62:0:

Function fes    &
1
Error: Second argument of operator interface at (1) cannot be optional

解决方案

You are not allowed to have optional arguments to defined operations. Fortran 2008, Cl. 12.4.3.4.2. says:

1 ... The dummy arguments shall be nonoptional dummy data objects ...

This is what your compiler is referencing when it emitted the error:

Error: Second argument of operator interface at (1) cannot be optional

Note: you can have procedures with optional arguments and they can appear in modules, but they cannot be referenced in interface blocks with the operator keyword. Your function fes looks fine and it is not the problem. Your problem is the the interface block mapping an operator to the function.

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

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