先使用f2py将fortran代码编译为python模块:
f2py -c -m typhoontracklib typhoon_track.f90
若出现以下报错:
/tmp/tmp30s5acvp/src.linux-x86_64-3.10/fortranobject.c: In function ‘find_first_negative_dimension’:
/tmp/tmp30s5acvp/src.linux-x86_64-3.10/fortranobject.c:729:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
for (int i = 0; i < rank; ++i) {
^
/tmp/tmp30s5acvp/src.linux-x86_64-3.10/fortranobject.c:729:5: note: use option -std=c99 or -std=gnu99 to compile your code
可通过以下方法解决:
进入到 numpy 库的 f2py 目录下lib/python3.10/site-packages/numpy/f2py/src,
vi fortranobject.c
找到find_first_negative_dimension
修改为:
最后再重新编译fortran代码即可。