My workflow:
1) use a build script (bash, make, etc) to compile a set of fortran modules into shared objects.
2) ctypes python procedures can then be called in a python script to associate each of those shared fortran objects as a callable python type. Its like loading the modules and saving them as a python class.
3) The ctypes objects can then be used to call the fortran procedures, the arguments to the fortran procedures will be re-cast as special "ctypes" data types, with equivalents for doubles, ints, and ways to handle vector arguments. You can handle dynamic fortran memory too, which will be released when the python script exits.
I typically use this type of workflow to perform "scientific" unit testing. For instance, visualizing allometry, allocation, and water retention curves in FATES.
Notes:
1) I've been happily surprised that this workflow CAN actually support OOP (object oriented programming), and I've been able to use python to allocate fortran class structures, call those structures, and analyze results.
2) I've also developed some python tools that read in a CDL version of our FATES parameter files and save the parameters in a python derived type.
If anyone has a simple test case they would like to try, feel free to reach out to me with the fortran module and we could try crafting up a way to call if via python.
I've been using the "ctypes" python library to run compiled fortran code from python.
Here is documentation on ctypes: https://docs.python.org/3/library/ctypes.html
My workflow: 1) use a build script (bash, make, etc) to compile a set of fortran modules into shared objects. 2) ctypes python procedures can then be called in a python script to associate each of those shared fortran objects as a callable python type. Its like loading the modules and saving them as a python class. 3) The ctypes objects can then be used to call the fortran procedures, the arguments to the fortran procedures will be re-cast as special "ctypes" data types, with equivalents for doubles, ints, and ways to handle vector arguments. You can handle dynamic fortran memory too, which will be released when the python script exits.
I typically use this type of workflow to perform "scientific" unit testing. For instance, visualizing allometry, allocation, and water retention curves in FATES.
Notes:
1) I've been happily surprised that this workflow CAN actually support OOP (object oriented programming), and I've been able to use python to allocate fortran class structures, call those structures, and analyze results.
2) I've also developed some python tools that read in a CDL version of our FATES parameter files and save the parameters in a python derived type.
Here is a link to the current folder with all this stuff in FATES (although I have some updates coming down the pipe soon): https://github.com/NGEET/fates/tree/master/functional_unit_testing
If anyone has a simple test case they would like to try, feel free to reach out to me with the fortran module and we could try crafting up a way to call if via python.