f2py compiling fails when dimensions are taken from a module

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>/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);
| ^~~~~
</code>
<code>/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); | ^~~~~ </code>
/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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>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
</code>
<code>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 </code>
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.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>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
</code>
<code>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 </code>
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

New contributor

pw31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật