先使用f2py將fortran代碼編譯為python模塊:
f2py -c -m typhoontracklib typhoon_track.f90
若出現(xiàn)以下報(bào)錯:
/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
可通過以下方法解決:
進(jìn)入到 numpy 庫的 f2py 目錄下lib/python3.10/site-packages/numpy/f2py/src,
vi fortranobject.c
找到find_first_negative_dimension
修改為:
最后再重新編譯fortran代碼即可。