pyguymer3.f90¶
A Python sub-module containing a bunch of random functions that I have written over the years in FORTRAN to be called from Python using f2py.
Notes
To compile the FORTRAN source code and create the sub-module just run the Makefile.
f2py isn’t good at creating interfaces to FORTRAN functions, so all the FORTRAN here will be subroutines (see these Stack Overflow questions [1] and [2]).
f2py doesn’t release the GIL, so I have to do that with a macro (see this StackOverflow question [3]).
Documentation of the FORTRAN subroutine can be obtained by running:
>>> import pyguymer3
>>> import pyguymer3.f90
>>> print(pyguymer3.f90.funcs.${FUNC}.__doc__)
According to the definition of c2py_map.keys() in the source of
“capi_maps.py”
(in the source of “f2py”) only the following
short-hands for C data types are recognised by f2py:
doublefloatlong_doublecharsigned_charunsigned_charshortunsigned_shortintlonglong_longunsignedcomplex_floatcomplex_doublecomplex_long_doublestring
According to the gfortran “ISO_C_BINDING” documentation only the following FORTRAN-C mappings are possible (where mappings have been removed if the corresponding C data type does not have a corresponding short-hand in f2py above):
integer
FORTRAN
C_INTgoes to Cint(which isintin f2py)FORTRAN
C_SHORTgoes to Cshort int(which isshortin f2py)FORTRAN
C_LONGgoes to Clong int(which islongin f2py)FORTRAN
C_LONG_LONGgoes to Clong long int(which islong_longin f2py)FORTRAN
C_SIGNED_CHARgoes to Csigned char(which issigned_charin f2py)
real
complex
character
FORTRAN
C_CHARgoes to Cchar(which ischarin f2py)
The above study has led me to create .f2py_f2cmap to allow me to use FORTRAN data types from
“ISO_C_BINDING” and have them magically mapped over to the correct
corresponding C data type in f2py.
Copyright 2017 Thomas Guymer [4]
References
Modules
c = add(a,b) |