I'm trying to port fortran code to python (call me crazy), and am wondering whether I'm handling the input of a variable to a function in a correct way.
note that I've read:
Fortran77: what does the asterisk (*) means in subroutine argument?
How can a scalar be passed to a vector (1D array) to a Fortran subroutine?
, but my question stands.
Focusing on the variable wrk(ia)
used in curfit.f
to input to subroutine fpcurf.f
. wrk
is a 1-d array.
curfit.f source
c ..array arguments..
real*8 ... wrk(lwrk) ...
c ... no values assigned to wrk here, it is still empty initialized ...
call fpcurf(...,
* wrk(ia),...)
...
(from the links I understand the *
is just a line continuation.
curfit.py
...
n, c, fp, ier = call_fpcurf(..., wrk[ia], ...)
...
fpcurf.f
takes the variable wrk(ia)
as variable a
, which is defined as an array. Now I understand that this somehow becomes a "dummy" array (whatever that means).
fpcurf.f source
recursive subroutine fpcurf(...,
* ...,a,...)
implicit none
c ..
c ..scalar arguments..
...
c ..array arguments..
real*8 ...,
* ...,a(nest,k1),...
Since
wrk
is empty initialized in curfit.f
, and the element wrk(ia)
is inputted to fpcurf.f
as a
, which has array dimensions (nest, k1)
, I basically ignore the inputted value of a
in fpcurf.py
and simply initialize a new empty / zeros array.
fpcurf.py
def fpcurfpy(... a, ...):
...
a = np.zeros(shape=(nest, k1), dtype=np.float64)
# alt.
# a = np.empty(shape=(nest, k1), dtype=np.float64)
...
Is this python code a correct representation of the fortran code?
Assume a
is not returned from fpcurf.f
, i.e. not used in curfit.f
More specifically: is a = np.zeros(shape=(nest, k1), dtype=np.float64)
in my python file the best representation of what's going on in the fortran code, especially how a
is treated in fpcurf.f