The FORTRAN code below cannot be compiled with f2py using command
f2py -m ggchemlib -c --fcompiler=gfortran --f90flags="-fdefault-real-8 -fdefault-double-8" --opt="-O5" test.f90
The error message is
/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);
| ^~~~~
The problem seems to be the way that the variable Sat is declared in subroutine SUPERSAT,
where the dimension of Sat is taken from a data module. Here is 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
Is there a simple way to fix this?
Thanks, Peter
The following modification would work, but this is not a feasible solution for me, because I want to port
a large FORTRAN code to python, where taking the dimensions of variables from modules is used
all the time.
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(NMOLE,T,Sat)
end subroutine CHECK_MELTING
subroutine SUPERSAT(NMOLE,T,Sat)
implicit none
integer,parameter :: qp = selected_real_kind ( 33, 4931 )
integer,intent(in) :: NMOLE
real*8,intent(in) :: T
real(kind=qp),intent(out) :: Sat(NMOLE)
Sat(1:NMOLE) = 0.q0
end subroutine SUPERSAT
pw31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.