[f2py] Help with wrapping multiple fortran modules
Amit Aides <amitibo-v2yAWYI3+kL7r6psnUbsSmZHpeb/A1Y/@public.gmane.org> Mon, 18 Feb 2013 20:53:48 +0200
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--------------010301030609040507080000
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Hello,
I am trying to wrap the attached Fortran code using the f2py tool
(included in the epd 7.3-2 distribution that comes with numpy 1.6.1). I
am using the following commands:
1) f2py hparx_base.f90 -m hparx -h hparx.pyf
2) f2py -c --fcompiler=gnu95 hparx.pyf hparx_base.f90 globals.f90
The first command generates the signature file but with several errors:
In: :hparx:../src/hparx/hparx_base.f90:hparx_base
get_useparameters: no module globals info used by hparx_base
appenddecl: "dimension" not implemented.
vars2fortran: No typespec for argument "abstract_1r".
The second command fails with the following error:
../src/hparx/hparx_base.f90:35.70:
use globals, only : R_, RD_, R4_, R8_, I4_, I8_, IMIN_, IMAX_, RLRG_
1
Fatal Error: Can't open module file 'globals.mod' for reading at
(1): No such file or directory
gfortran.exe: Internal error: Aborted (program f951)
Attached are the files.
In the f2py user guide it says:
"Currently F2PY uses use statement only for linking call-back modules
and external arguments (call-back functions)"
But the following thread claims that it is possible:
http://cens.ioc.ee/pipermail/f2py-users/2008-March/001570.html
I appreciate any help.
Thanks,
Amit
--------------010301030609040507080000
Content-Type: text/plain; charset=windows-1255;
name="globals.f90"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="globals.f90"
!-*-f90-*-
! @LICENSE_HEADER_START@
!
! This file is part of MCARaTS.
!
! --
! MCARaTS: Monte Carlo Atmospheric Radiative Transfer Simulator
!
! Copyright (C) 2006-2012 Hironobu Iwabuchi.
!
! MCARaTS is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! MCARaTS is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with MCARaTS. If not, see <http://www.gnu.org/licenses/>.
!
! @LICENSE_HEADER_END@
!+
! Global constants
!-
module globals
implicit none
public ! all in this module are public!
! Kinds of real or complex variables
!integer, parameter :: R_ = selected_real_kind(6) ! default precision (programmer's choice)
integer, parameter :: R_ = selected_real_kind(13) ! default precision (programmer's choice)
integer, parameter :: RD_ = selected_real_kind(13) ! higher precision (programmer's choice)
integer, parameter :: R4_ = selected_real_kind(6) ! 4-byte real (no freedom)
integer, parameter :: R8_ = selected_real_kind(13) ! 8-byte real (no freedom)
!// Note: The R_ is default and RD_ should be used only when needed.
! One's choice may depend on required accuracy and used memory size.
! Kinds of integer variables
integer, parameter :: I4_ = selected_int_kind(9) ! 4-byte integer (no freedom)
integer, parameter :: I8_ = selected_int_kind(18) ! 8-byte integer (no freedom)
! Numerical parameters for real variables
real(R_), parameter :: REPS_ = epsilon(1.0_R_) ! 1.0e-7, typically
real(R_), parameter :: RTINY_ = tiny(1.0_R_) ! 1.0e-37
real(R_), parameter :: RHUGE_ = huge(1.0_R_) ! 1.0e+37
real(R_), parameter :: RSML_ = RTINY_ * 3.0_R_ ! 1.0e-37
real(R_), parameter :: RLRG_ = RHUGE_ / 3.0_R_ ! 1.0e+37
real(RD_), parameter :: RDEPS_ = epsilon(1.0_RD_) ! 1.0e-15, typically
real(RD_), parameter :: RDTINY_ = tiny(1.0_RD_) ! 1.0e-307
real(RD_), parameter :: RDHUGE_ = huge(1.0_RD_) ! 1.0e+307
real(RD_), parameter :: RDSML_ = RDTINY_ * 3.0_RD_ ! 1.0e-307
real(RD_), parameter :: RDLRG_ = RDHUGE_ / 3.0_RD_ ! 1.0e+307
! Numerical parameters for integer variables
integer, parameter :: IMAX_ = 2147483647 ! max integer of default kind
integer, parameter :: IMIN_ = -2147483647 - 1 ! min integer of default kind
! Mathematical constants
real(R_), parameter :: PI_ = 3.141592653589793238462643383279502884197_R_ ! pi
real(R_), parameter :: PIH_ = 1.570796326794896619231321691639751442098_R_ ! pi/2
real(R_), parameter :: PI2_ = 6.283185307179586476925286766559005768394_R_ ! pi*2
real(RD_), parameter :: DPI_ = 3.141592653589793238462643383279502884197_RD_ ! pi
real(RD_), parameter :: DPIH_ = 1.570796326794896619231321691639751442098_RD_ ! pi/2
real(RD_), parameter :: DPI2_ = 6.283185307179586476925286766559005768394_RD_ ! pi*2
real(R_), parameter :: SQRT2_ = 1.414213562373095048801688724209698078569_R_ ! sqrt(2)
real(R_), parameter :: SQRT3_ = 1.732050807568877293527446341505872366942_R_ ! sqrt(3)
real(R_), parameter :: SQRT2A_ = 0.7071067811865475244008443621048490392848_R_ ! 1/sqrt(2)
real(R_), parameter :: SQRT3A_ = 0.5773502691896257645091487805019574556476_R_ ! 1/sqrt(3)
real(R_), parameter :: DTOR_ = PI_ / 180.0_R_ ! degree-to-radian factor
real(R_), parameter :: FRAC13_ = 1.0_R_ / 3.0_R_ ! 1/3
real(R_), parameter :: FRAC23_ = 2.0_R_ / 3.0_R_ ! 2/3
real(R_), parameter :: FRAC43_ = 4.0_R_ / 3.0_R_ ! 4/3
real(R_), parameter :: FRAC53_ = 5.0_R_ / 3.0_R_ ! 5/3
real(R_), parameter :: FRAC16_ = 1.0_R_ / 6.0_R_ ! 1/6
! Physical constants (SI unit)
real(R_), parameter :: CSPEED_ = 2.99792458e+8_R_ ! speed of light (m/s)
real(R_), parameter :: PLANCK_ = 6.6260689633e-34_R_ ! Planck's constant (J*s)
real(R_), parameter :: BOLTZ_ = 1.380650424e-23_R_ ! Boltzmann's constant (J/K)
real(R_), parameter :: STEBOL_ = 5.67040040e-8_R_ ! Stefan-Boltzmann's constant (W/m^2/K^4)
real(R_), parameter :: AVOGAD_ = 6.0221417930e+23_R_ ! Avogadro number (/mol)
real(R_), parameter :: GASCON_ = 8.31447215_R_ ! universal gas constant (J/mol/K)
real(R_), parameter :: VOLMOL_ = 2.241399639e-2_R_ ! Molar volume (m^3/mol) of ideal gas (0 deg.C, 1 atm)
real(R_), parameter :: EGRAVE_ = 9.7803267715_R_ ! earth equatorial gravity (m/s^2)
real(R_), parameter :: EGRAV0_ = 9.80665_R_ ! earth standard gravity (m/s^2)
!real(R_), parameter :: WGTVAP_ = 18.02e-3 ! water vapor molecular weight (kg/mol)
!real(R_), parameter :: WGTDRY_ = 28.9964e-3 ! dry air molecular weight (kg/mol)
!real(R_), parameter :: GASCONDRY_ = GASCON_ / WGTDRY_ ! gas constant of dry air (J/K/mol)
real(R_), parameter :: RHOICE0_ = 0.917e+3_R_ ! density (kg/m^3) of water ice (0 deg.C)
contains
!+
! Print values of some global constants
!-
subroutine globals__print()
write (*,*) R_, RD_, R4_, R8_
write (*,*) I4_, I8_
write (*,*) REPS_, RTINY_, RHUGE_
write (*,*) IMIN_, IMAX_
end subroutine globals__print
end module globals
--------------010301030609040507080000
Content-Type: text/plain; charset=windows-1255;
name="hparx_base.f90"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="hparx_base.f90"
!-*-f90-*-
! @LICENSE_HEADER_START@
!
! This file is part of MCARaTS.
!
! --
! MCARaTS: Monte Carlo Atmospheric Radiative Transfer Simulator
!
! Copyright (C) 2006-2012 Hironobu Iwabuchi.
!
! MCARaTS is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! MCARaTS is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with MCARaTS. If not, see <http://www.gnu.org/licenses/>.
!
! @LICENSE_HEADER_END@
!+
! Library of basic utilities
!-
module hparx_base
use globals, only : R_, RD_, R4_, R8_, I4_, I8_, IMIN_, IMAX_, RLRG_
implicit none
private
! Public
public :: abstract_1R
contains
!+
! Abstract (extract) 1-D real array
! ex) If (is, iw, n) = (3, 2, 4), then retrieved points will be (3, 5, 7, 9)
!-
function abstract_1R(dat, n1, is, iw) result(dat1)
real(R_), intent(in) :: dat(:) ! original data
integer, intent(in) :: n1 ! # of points retrieved
integer, intent(in), optional :: is ! start point
integer, intent(in), optional :: iw ! spacing width in points
real(R_) :: dat1(n1) ! result
integer :: is1, ie1, iw1, n2
is1 = 1
iw1 = 1
if (present(is)) is1 = is ! start
if (present(iw)) iw1 = iw ! step width
ie1 = is1 + iw1 * (n1 - 1)
n2 = n1
if (ie1 > size(dat)) then ! exceed the upper bound
n2 = (size(dat) - is1) / iw1 + 1
ie1 = is1 + iw1 * (n2 - 1)
end if
dat1(1:n2) = dat(is1:ie1:iw1) ! conversion
end function abstract_1R
end module hparx_base
--------------010301030609040507080000
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
f2py-users mailing list
f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
http://cens.ioc.ee/mailman/listinfo/f2py-users
--------------010301030609040507080000--