- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
There are other restrictions on the use of optional arguments, which are detailed in the Fortran standard and in the compiler reference manual.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page