- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
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
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

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