Case Study: Transitioning from F90 to Python
- Start with stand alone F90 application -- legacy system
- Python becomes your main function
- Can remove the file interpreters and text processing from Fortran code base. Let Python do it.
- Can just import FFT and signal processing stuff from scipy or numpy.
- General Issue with FORTRAN
- use large number of globals
- causes "states" with wrapped modules
- makes threading difficult
- Not very modular
- One or two very long functions -- not easy to break up
- doesn't handle memory allocation well
- good for us since we can then manage the memory from python
- FORTRAN 90 does memory management but doesn't easily map to C (base for Python).
- Problems with global variables
- If wrapped functions can be called in different order. Result can differ depending on the state of the global variables
- You are keeping info the user doesn't know about
- Fixes
- Remove the ability of calling functions out of order by wrapping functions at the highest level.
- This can be a problem because perhaps calling the lower level functions separately is useful.
- Can still have threading problems.
- Get rid of global variables and include them in the argument list for functions
- This is best option but may be a lot of work.
- Problems with non-modularity
- There is no easy solution
- Generally want to only wrap FORTRAN simulation code. Leave the pre and post processing exercises to Python.
- Problems with long argument lists
- long lists encouraged by FORTRAN
- need to determine what each argument refers to
- Switching to Python gets rid of need for many arguments used for return arguments or array indicies
- Use classes to group arguments
- class to define environment
- class to define sources
- class to define algorithm
- Look for the nouns in the problem definitions to identify potential classes
- When designing your OO interface is the API understandable by someone who is only interested in the science