- #1
JellyKing
- 2
- 0
Hi all,
I'm new to Physics Forums, but not to physics, since I'm now doing my MSc. I've had a persistent problem in a segment of my Fortran code that I've worked around, but would like to fix.
The long and short is that I'm integrating a six-dimensional ODE with a fourth-order Runge-Kutta method.* I've tried to do it with function calls as follows. In the main program body, there will be a line to iterate the solution one step, using some function I call rk. I'd like the line of code to be something like
Sure enough, after the END program, I have the function, initiated by
In the opening lines, I'll declare that rk is a six-dimensional real (REAL(6)). That's fine. However, when I try to call it as above, I get an error like
Error: FUNCTION 'rk' is of rank (1) at {function declaration} and rank (0) and {function call}.
Okay, so I figure I need to tell the program that rk is going to be a REAL(6). But now the compiler tries to parse the arguments as array indices, so I'll get an error like
v = rk(w,E,L,Q,a,dtau)
...1
Error: Array index at (1) must be of INTEGER type
I haven't had this problem with functions that return scalars. For now, I've worked around the function calls by using routines, so that instead of a line like
I use
Sorry this is a long post, and if there are any other details that will help find a solution just ask. Thanks in advance for any help you can provide. This has been bugging me for a while.
JK
*I can't for the life of me work out how one is supposed to import other people's modules, but that's another story.
I'm new to Physics Forums, but not to physics, since I'm now doing my MSc. I've had a persistent problem in a segment of my Fortran code that I've worked around, but would like to fix.
The long and short is that I'm integrating a six-dimensional ODE with a fourth-order Runge-Kutta method.* I've tried to do it with function calls as follows. In the main program body, there will be a line to iterate the solution one step, using some function I call rk. I'd like the line of code to be something like
Code:
output = rk(input, parameters)
Code:
FUNCTION rk(inputx,parametersx)
REAL(6) :: rk,...
...
rk = ...
END FUNCTION
Error: FUNCTION 'rk' is of rank (1) at {function declaration} and rank (0) and {function call}.
Okay, so I figure I need to tell the program that rk is going to be a REAL(6). But now the compiler tries to parse the arguments as array indices, so I'll get an error like
v = rk(w,E,L,Q,a,dtau)
...1
Error: Array index at (1) must be of INTEGER type
I haven't had this problem with functions that return scalars. For now, I've worked around the function calls by using routines, so that instead of a line like
Code:
output = rk(input,parameters)
I use
Code:
CALL rk(input,parameters,output)
Sorry this is a long post, and if there are any other details that will help find a solution just ask. Thanks in advance for any help you can provide. This has been bugging me for a while.
JK
*I can't for the life of me work out how one is supposed to import other people's modules, but that's another story.