使用模块变量定义维度时f2py编译失败的解决问询
f2py编译Fortran代码报错:模块变量作为数组维度未被识别
编译命令
f2py -m ggchemlib -c --fcompiler=gfortran --f90flags="-fdefault-real-8 -fdefault-double-8" --opt="-O5" test.f90
报错信息
/tmp/tmpb4kqj9_4/src.linux-x86_64-3.10/ggchemlibmodule.c:292:16: error: ‘nmole’ undeclared (first use in this function) 292 | sat_Dims[0]=(nmole); | ^~~~~
问题代码(test.f90)
module CHEMISTRY integer :: NMOLE end module CHEMISTRY program main use CHEMISTRY,ONLY: NMOLE implicit none real*8 :: T NMOLE = 20 T = 1000.0 call CHECK_MELTING(T) end program main subroutine CHECK_MELTING(T) use CHEMISTRY,ONLY: NMOLE implicit none integer,parameter :: qp = selected_real_kind ( 33, 4931 ) real*8,intent(in) :: T real(kind=qp) :: Sat(NMOLE) call SUPERSAT(T,Sat) end subroutine CHECK_MELTING subroutine SUPERSAT(T,Sat) use CHEMISTRY,ONLY: NMOLE implicit none integer,parameter :: qp = selected_real_kind ( 33, 4931 ) real*8,intent(in) :: T real(kind=qp),intent(out) :: Sat(NMOLE) Sat(1:NMOLE) = 0.q0 end subroutine SUPERSAT
需求说明
报错原因是子程序SUPERSAT使用模块CHEMISTRY中的变量NMOLE定义数组Sat的维度,f2py无法识别该模块变量作为数组维度。现有修改方案因需移植的大型Fortran代码中大量使用该模式,不具备可行性,寻求简便解决方法。
内容的提问来源于stack exchange,提问作者pw31
相关产品推荐
相关产品推荐

