Fortran Functions with optional arguments

会有一股神秘感。 提交于 2019-12-12 04:48:35

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/30080094/fortran-functions-with-optional-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!