/
create_signature.py
executable file
·41 lines (35 loc) · 1.48 KB
/
create_signature.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
"""
Automatically creates python-wrapper subroutines from the interface file
SHTOOLS.f95. Unfortunately all assumed array shapes have to be changed because
their structure is only known by the Fortran compiler and can not be directly
exposed to C. It is possible that newer f2py versions can handle assumed array
shapes using a similar procedure.
"""
#==== IMPORTS ====
from numpy.f2py import crackfortran
#==== MAIN FUNCTION ====
def main():
fname_wrapper = 'PythonWrapper.f95'
fname_signature = 'pyshtools.pyf'
outfile = open(fname_signature, 'w')
print 'now cracking Fortran file SHTOOLS.f95 using f2py function...'
crackfortran.verbose = False
crackfortran.dolowercase = False
cracked_shtools = crackfortran.crackfortran(fname_wrapper)
for subroutine in cracked_shtools:
subroutine['f2pyenhancements'] = {'fortranname': subroutine['name'].lower()}
for subroutine in cracked_shtools:
subroutine['name'] = subroutine['name'][2:]
interface = {'block': 'interface', 'name': 'unknown_interface', 'from': '',
'body': cracked_shtools, 'externals': [], 'interfaced': [],
'vars': {}}
module = {'block': 'python module', 'name': '_SHTOOLS', 'from': '',
'body': interface, 'externals': [], 'interfaced': [],
'vars': {}}
out = crackfortran.crack2fortran(module)
outfile.write(out)
outfile.close()
#==== EXECUTE SCRIPT ====
if __name__ == "__main__":
main()