Porting an old fortran program to work with python + numpy

I have to do research with this huge Fortran 77 program (which I recently ported to Fortran 90 superficially). This is a very old piece of software used for modeling using finite element methods.

  • This is a monster. This is approximately 240,000 lines.
  • Since its inception in Fortran 77, it has been using some really dirty hacks to dynamically allocate memory; it mainly uses functions from the standard C library, mixed programming with C and Fortran. I have yet to fully understand how distribution works. The program is designed so that it can be easily expanded for the user, and the user usually needs to allocate some globally accessible arrays for later use. This is done using an array of memory addresses that point to the starting addresses of dynamically allocated arrays.. Of course, which element of the address array indicates which information depends on the conventions that should be studied by the user before you can really start programming. There are two address arrays: one for integers, the other for floating points.
  • Dirty hacks, I mean inconsistent. For example, an update in the GNU compiler optimization algorithm caused the program to exit with random memory leaks.
  • The program is far from elegance. The names of global variables are usually short (3-4 characters) and cryptic. Data transmission through subprograms, of course, is carried out using common blocks, including all software switches and the aforementioned arrays.
  • , . -, , , -, 4 , . , . , - (, goto bonanza), , 21 .
  • (, ), . ( , , , , ), , . ; . , python, .

:

  • python, , .
    • API python,
    • ,
    • numpy, Fortran 90 C,
    • python f2py, . , damn ? , - python ( ?).
    • python -. , . , python. . , , .

:

  • f2py - ? f2py; , numpy LAPACK .., , f2py - , .
  • - , , , .
  • Fortran 90, python, ( ) fortran. , . python, fortran.

:

  • , , - . , , , ; .
  • "", , , , . , .
+4
2

- . C ( ), . , .

, python - . , . , F77 , , , .

, F77, . , . , , ( ) . iso_c_binding Fortran 2003, C, , , .

( , ), C. , , , .

+1

, f2py fortran . .

f2py , , . , f2py, :

  • , , f2py Fortran77 Fortran90 + (, ).
  • (arround 400 x 200 x 20 x 20). , f2py python. , , . , Python .
  • , f2py COMMON Blocks .., Fortran77.
  • Fortran ( ) , . , Python . (, , ..), ( ).

Cython (. ). , .


, , - (. ). , Python Fortran (f2py, Cython,...).

, , , , . - , , , .., .

Fortran. "-" Fortran, . . , Fortran, , , . , /, . , , , , .

, python , , , - . . , Shell/GUI , . "" , , , / .., Python, , Fortran, .

, , ( + ), . , -, , , . , , , .

, C, Fortran90 +, . .

, / ( , ), Fortran. Fortran - Python / , , .

, . Cython, , .. "pass-by-reference", Python (numpy) .


- , . , Fortran77 (, goto bonanza). Fortran90/2003.

( ), python GUI (Python Qt) Fortran; Fortran.

+1

Source: https://habr.com/ru/post/1539983/


All Articles