Bharath Ram
Bharath Ram

Reputation: 310

Python's equivalent of "EQUIVALENCE" concept in Fortran?

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

Answers (2)

Peter Kämpf
Peter Kämpf

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 FUNCTIONs. Convert them to SUBROUTINEs and you will be fine. If they are used only in one SUBROUTINE, include them with CONTAINS. F90+ is your friend.

Upvotes: 0

Michael
Michael

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

Related Questions