Reputation: 310
I am interested in rewriting an old Fortran code to Python. The code was for solving any general field variable, call it F
(velocity, temperature, pressure, etc). But to solve each variable we have to define EQUIVALENCE
of that variable to F
.
For example, something like this:
EQUIVALENCE (F(1,1,1),TP(1,1)),(FOLD(1,1,1),TPOLD(1,1))
Is there a Python version of the above concept?
Upvotes: 2
Views: 213
Reputation: 714
Don't rewrite working FORTRAN code. It will run much slower in Python and who knows what errors you will add with your conversion.
Instead, move the code to modern Fortran, like F90 or newer, and if you need a Python interface, call it from Python using NumPy
's F2PY Fortran support. You will have a few restrictions* with F2PY, but the code will run faster and most likely with fewer errors.
* for example, you cannot have independent FUNCTION
s. Convert them to SUBROUTINE
s and you will be fine. If they are used only in one SUBROUTINE
, include them with CONTAINS
. F90+ is your friend.
Upvotes: 0
Reputation: 104
To my knowledge, there is no way to manipulate the memory usage in python. You can perhaps simply use a list.
F=[]
and
FOLD=[]
When you do
F=FOLD
F and FOLD will point to the same data. I would suggest to use numpy and scipy to create solvers and use python concepts to make it efficient instead of trying to mimic fortran concepts. Especially very old ones.
Upvotes: 1