Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

optional arguments

wgriggdraper_com
Beginner
637 Views
All,

I have the following:

CALL ECBC(XLATLP, XLATN0, XLONLP, XLONN0, DTNED0, QN0C,
+ TNO2UC, TNT2NO, TECBC, EC, BC, XLOS, WE, DTR, RTD)


....

SUBROUTINE ECBC(XLL,XL0,XLONL,XLON0,DELTIM,TUC2NO,TNO2UC,TNT2NO,
+ T,EC,BC,XLOS,WE,DTR,RTD)

....

END

This is legacy code that builds and executes just fine. I modify the subroutine declaration and subroutine like this:

CALL ECBC(XLATLP, XLATN0, XLONLP, XLONN0, DTNED0, QN0C,
+ TNO2UC, TNT2NO, TECBC, EC, BC, XLOS, WE, DTR, RTD,switch)

...
OPTIONAL :: switch

....

END

The subroutine compiles and the static library in which it resides compiles and builds. However, the module that calls ECBC, which has not been modified, produces a link failure that indicates that ECBC cannot be found due to the wrong number of calling parameters.

What am I missing? There must be some way to add an optional parameter to an existing subroutine without modifying ALL of the places that call that subroutine. Otherwise, the parameter is not very "optional".

TIA,

Bill
0 Kudos
2 Replies
TimP
Honored Contributor III
637 Views
The definition with optional argument has to be visible whereever the subroutine is called, according to module procedure or interface block. You may have to create interface block and USE it where it is required.
0 Kudos
mecej4
Honored Contributor III
637 Views
What is optional is the inclusion of OPTIONAL arguments in a subroutine/function invocation. What is not optional is the requirement that the programmer provide an explicit interface to subprograms with OPTIONAL arguments -- a fact the necessity for which becomes obvious if one asks how the compiler is to process OPTIONAL arguments in the invocation, in particular those that were left out from the call.

There are other restrictions on the use of optional arguments, which are detailed in the Fortran standard and in the compiler reference manual.
0 Kudos
Reply