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.

Keyword arguments.

sb2601
Beginner
468 Views
I am writinga two stage Runge Kutta code, at present my code calls two subroutines, these are identical except that the the Runge Kutta coefficients are 0.50 and 1.0 for steps 1 and 2 respectively.
To shorten my code I'd like to be able to call the same basic Runge Kutta subroutine twice from my main program,using a RK coefficient of 0.5 for the first call and 1.0 for the second call.
I believe that I may be able to do thisusing keyword arguments when I call my subroutines, but so far haven't got this to work. I'd be grateful if anyone can offer advice or refer me to example coding showing this.
Thank you,
Simon.
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
468 Views
You don't need keyword arguments -- you just have to pass your calculating function as an EXTERNAL, and pass the parameter as an additional argument, like:
PROGRAM Foo
EXTERNAL Value
...
CALL RungeKutta(Value, 0.5, ...)
CALL RungeKutta(Value, 1.0, ...)
...
SUBROUTINE RungeKutta(Eval, Param, ...)
EXTERNAL:: Eval
REAL:: Param
...
DO i=0,whatever
x = i * step
CALL Eval(x, Param, y)

END DO
...
END SUBROUTINE RungeKutta

SUBROUTINE Value(x, Param, y)
REAL, INTENT(IN):: x, Param
REAL, INTENT(OUT):: y

y = x**2 + exp(x/Param) - whatever
END SUBROUTINE Value


Instead of EXTERNAL, you could use INTERFACE statements (which is required at least in RungeKutta routine) which would provide more thorough argument-checking than EXTERNAL, but that's the principle.

Jugoslav
0 Kudos
Reply