Appendix: wrapping Fortran 90 Code¶
This section describes the machinery involved in connecting between Python and Fortran. You should only read it if you want to extend or modify quippy, or if you’re interested in how it works.
There are four steps in the process of wrapping a QUIP Fortran routine to allow it to be called from quippy. The first two take place at compile-time (and so these modules do not form part of the installed quippy package), and the last two at run-time.
f90docis used to scan the Fortran source file, building up a data struture which describes all the types, subroutines and functions found in the file.
f2py_wrapper_genis used to write a simplified Fortran 90 prototype for each routine, with derived type arguments replaced by integer arrays containing a representation of a pointer to the derived type, in the manner described in [Pletzer2008] This allows us to pass opaque references to the true Fortran derived type data structures back and forth between Python and Fortran. The
patch_f2pymodule is used to patch the
numpy.f2pysystem at runtime, to slightly modify the way it generates C code.
quippy.oo_fortranacts as a thin object-oriented layer on top of the f2py generated wrapper functions which handles conversion between Python object instances and Fortran derived-type variables, converting arguments back and forth automatically.
|[Pletzer2008]||Pletzer, A et al., Exposing Fortran Derived Types to C and Other Languages, Computing in Science and Engineering, 10, 86 (2008). http://link.aip.org/link/?CSENFA/10/86/1|