[f2py] Derived Types and 'kind=' statements

mbennun at spawn.scs.uiuc.edu mbennun at spawn.scs.uiuc.edu
Fri Oct 7 20:58:09 EEST 2005


Hello: 

We are new to f2py and therefore you may find our questions trivial..
We are trying to compile a F90 module which consists basically of some 
definitions and so far we have failed. 

The program is called Module.f90 and it is attached below.
We run the command:
%f2py -c -m --fcompiler=pg fmslib Module.f90 

the output is attached in a file called log.  Two things are not clear to 
me:
1. Can the compiler read my .f2py_f2cmap file correctly (the file is 
enclosed below)?  I ask because the log file had the statement: 

"Failed to apply user defined changes from .f2py_f2cmap. Skipping.
Reading .f2py_f2cmap ..."
But later on it seems as if it does try to access the mapping file. 

2. Our module has a lot of derived types (see the Module below and in the 
attached FMSTypes.h file).  Can f2py handle this? 

Many thanks for your help and please let me know if you need more 
information. 

 -Dr. Michal Ben-Nun 


Here is Module.f90 

Module FMSLib
include 'FMSTypes.h'
end Module 

Here is .f2py_f2cmap 

{'real' : {'DefReal':'double'}}
{'integer' : {'DefInt':'int'}}
{'integer' : {'DefShort':'short'}}
{'complex' : {'DefComplex':'complex_double'}}
{'real' : {'ShReal':'float'}} 


FMSTypes.h is long so I attached it along with
log which is the output from the f2py compiler. 


-------------- next part --------------
!
! FMS derived types and parameters 
! It is assumed that mqmtypes.h will also be included, so we do not
! define the most basic types or those associated with MQM for 
! ab initio MD.
!
!---------------------------------------------------------------------------
!                           GLOBAL PARAMETERS
!---------------------------------------------------------------------------
! Parameters that are hard-coded in many places, and define dimensions
! of arrays that take too little memory to bother with dynamic allocation.
      integer,parameter::DefReal=8
      integer,parameter::DefShort=2
      integer,parameter::DefInt=4
      integer,parameter::DefComp=8
      integer,parameter::ShReal=4
! Physical Constants and Unit Conversion Factors
      real (kind=DefReal),parameter::BohrToAng=0.529177249D0
      real (kind=DefReal),parameter::eVToH=1.0/27.2113962D0
      real (kind=DefReal),parameter::Pi=3.141592653589793
      real (kind=DefReal),parameter::d2=2.0
      real (kind=DefReal),parameter::dp5=0.5
      real (kind=DefReal),parameter::d1=1.0
      real (kind=DefReal),parameter::d0=0.0
      real (kind=DefReal),parameter::FPZero=1.0d-10
      real (kind=DefReal),parameter::FPInfinity=1.0d+100
      real (kind=DefReal),parameter::DegToAu=0.000003167
      real (kind=DefReal),parameter::CMToAu=0.000004556
      real (kind=DefReal),parameter::MassToAu=1822.887
      integer (kind=DefInt),parameter::i0=0
      complex (kind=DefComp),parameter::c1i=(0.0,1.0)
!---------------------------------------------------------------------------
!                           DERIVED TYPES
!---------------------------------------------------------------------------
! This data structure holds an individual particle
      type T_Particle
      integer ParticleID        ! ID for potentials, etc.
      integer NumDimensions     ! Number of spatial dimensions
                                ! known to this particle
      real (kind=DefReal),pointer::Position(:) ! Position,size=NumDimensions
      real (kind=DefReal),pointer::Momentum(:) ! Momentum,size=NumDimensions
      real (kind=DefReal),pointer::PosDot(:) ! Time Deriv of Position
      real (kind=DefReal),pointer::MomDot(:) ! Time Deriv of Momentum
      real (kind=DefReal)::Width ! Position Uncertainty 
      real (kind=DefReal)::Freq  ! Particle Frequency Spin-Boson Model
      real (kind=DefReal)::CLinear !Particle Linear coupling Spin-Boson Model
      real (kind=DefReal),pointer::Pos0(:) ! Initial value of position
      real (kind=defReal),pointer::Mom0(:) ! Initial value of momentum
      end Type T_Particle
!---------------------------------------------------------------------------
! This data structure holds an individual trajectory time step
      type T_Trajectory
      integer IDNum             ! Trajectory ID Number
      integer Model             ! ID for Potential Used
      logical Diabatic          ! True if diabatic basis is used
      integer NumDimensions     ! Total Dimensionality
      integer NumParticles      ! Number of Particles
      integer NumStates         ! Number of Electronic States
      integer StateID           ! Electronic State Index
      real (kind=DefReal)::EShift !Global energy shift
      integer IMethod           ! Method used for dynamics: FMS, 
	                        ! Surface-Hopping or Ehrenfest
                                ! (0,1,2 respectively)
      logical NoOldEvecs        ! True if no reference phasing info exists
      logical NoOldTheta        ! True if Theta has never been determined 
                                ! (For Model=4 only at present)
      real (kind=DefReal)::OldTheta ! Last Value of Theta computed
                                ! (For Model=4 only at present)
      logical DCDOpen           ! True if a DCD file already exists &
                                ! should only be appended      
      real (kind=DefReal)::CurrentTime ! Time 
      real (kind=DefReal)::Time0 !Zero of time for Trajectory
      type (T_Particle),pointer::Particle(:) ! Particle Data
      complex (kind=DefComp)::Amplitude ! Trajectory Amplitude
      complex (kind=DefComp)::AmpDot ! Time Deriv of Amplitude
      real (kind=DefReal)::Phase ! Semiclassical Phase
      real (kind=DefReal)::PhaseDot ! Time Deriv of Phase
      real (kind=DefReal),pointer::PotEn(:) ! Potential Energy for
                                ! given nuclear configuration.  We cannot
                                ! guarantee it is consistent with 
                                ! the current configuration, so be cautious.
      integer,pointer::SpawnMode(:) 
                                ! Spawning mode with respect
                                ! to a given electronic state
      real (kind=DefReal),pointer::LastSpawn(:) 
                                ! Point in time at which we exited the
                                ! Last nonadiabatic coupling region
      real (kind=DefReal),pointer::OldEvecs(:,:)
                                ! The eigenvectors obtained at the last time
                                ! step.  We will use these to ensure 
                                ! continuity of the phase
      real (kind=DefReal),pointer::SpawnTime(:)
                                ! Can only spawn to ith state if the current
                                ! time is greater than SpawnTime(i)
      complex (kind=DefComp),pointer::EhrenAmp(:)
                                ! Ehrenfest amplitudes for each trajectory
                                ! Currently not used in spawning, but could 
                                ! be a good idea.  Also, these are needed for
                                ! Tully-1990 TSH and for Eherenfest Dynamics
      complex (kind=DefComp),pointer::EhrenAmpDot(:)
      complex (kind=DefComp),pointer::EhrenH(:,:)
      end Type T_Trajectory
!---------------------------------------------------------------------------
! This data structure holds a bundle of trajectories -- all living
! trajectories for the current time step.
      type T_TrajectoryBundle
      integer NumStates         ! Number of Electronic States
      integer NumTraj           ! Number of trajectories in this bundle
      real (kind=DefReal)::EShift ! Global energy shift
      integer IMethod           ! Method used for dynamics: FMS, 
	                        ! Surface-Hopping or Ehrenfest
                                ! (0,1,2 respectively)
      type (T_Trajectory),pointer::Trajectory(:) ! NumTraj Trajectories
      real (kind=DefReal)::CurrentTime ! Time
      real (kind=DefReal)::RegThresh   ! Regularization Threshold
      real (kind=DefReal) :: InvThresh ! If  the condition number of the
                                       ! S matrix is less than this number
				       ! then a regular inversion is performed.
      logical :: AssumeHermitian       ! if TRUE the code does not check for
                                       ! Hermiticity of H or S.
      logical :: Adaptive              ! If false, overrides adaptive 
                                       ! integrators
      character*2 ::IntegType ! Selects the type of integrator.				       
      complex (kind=DefComp),pointer::H(:,:) ! Hamiltonian Matrix
      complex (kind=DefComp),pointer::S(:,:) ! Overlap Matrix
      complex (kind=DefComp),pointer::SDot(:,:) ! Time Derivative Matrix
      complex (kind=DefComp),pointer::SInv(:,:) ! Overlap Inverse
      complex (kind=DefComp),pointer::Sp5(:,:)  ! S^1/2
      complex (kind=DefComp),pointer::HEff(:,:) ! Effective Hamiltonian
      complex (kind=DefComp),pointer::HEff1(:,:) ! Effective Hamiltonian 
                                                 ! w/o S^-1
      end Type T_TrajectoryBundle
!---------------------------------------------------------------------------
!   Defines a structure to hold open unit files
      Type File_Units
         Integer :: Unit_E
	 Integer :: Unit_N
	 Integer :: Unit_Spawn
	 Integer :: Unit_Traj
	 Integer :: Unit_ReStart
      End Type File_Units
!----------------------------------------------------------------------------






-------------- next part --------------
Failed to apply user defined changes from .f2py_f2cmap. Skipping.
Reading .f2py_f2cmap ...
numpy_info:
  FOUND:
    define_macros = [('NUMERIC_VERSION', '"\\"24.0b2\\""')]
    include_dirs = ['/usr/include/python2.3']

running build
running config_fc
running build_src
building extension "fmsmod" sources
f2py:> /tmp/tmp7fVPVq/src/fmsmodmodule.c
creating /tmp/tmp7fVPVq
creating /tmp/tmp7fVPVq/src
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "integer(kind=defint)" not supported (use .f2py_f2cmap).
getctype: "integer(kind=defint)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "complex(kind=defcomp)" not supported (use .f2py_f2cmap).
getctype: "complex(kind=defcomp)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
getctype: "real(kind=defreal)" not supported (use .f2py_f2cmap).
Reading fortran codes...
	Reading file 'Module.f90'
	Reading file 'FMSTypes.h'
Post-processing...
	Block: fmsmod
			Block: fmslib
{'i0': 0, 'dp5': 0.5, 'fpzero': '1.0d-10', 'masstoau': 1822.8869999999999, 'degtoau': 3.1669999999999999e-06}
In: :fmsmod:Module.f90:fmslib
get_parameters: got "invalid syntax (line 1)" on '1.0d-10'
{'dp5': 0.5, 'masstoau': 1822.8869999999999, 'defreal': 8, 'i0': 0, 'fpzero': '1.0d-10', 'defcomp': 8, 'defshort': 2, 'defint': 4, 'cmtoau': 4.5560000000000001e-06, 'shreal': 4, 'c1i': (0.0, 1.0), 'degtoau': 3.1669999999999999e-06, 'fpinfinity': '1.0d+100', 'pi': 3.1415926535897931}
In: :fmsmod:Module.f90:fmslib
get_parameters: got "invalid syntax (line 1)" on '1.0d+100'
{'dp5': 0.5, 'masstoau': 1822.8869999999999, 'defreal': 8, 'i0': 0, 'fpzero': '1.0d-10', 'defcomp': 8, 'defshort': 2, 'defint': 4, 'cmtoau': 4.5560000000000001e-06, 'shreal': 4, 'c1i': (0.0, 1.0), 'degtoau': 3.1669999999999999e-06, 'fpinfinity': '1.0d+100', 'bohrtoang': '0.529177249d0', 'pi': 3.1415926535897931}
In: :fmsmod:Module.f90:fmslib
get_parameters: got "unexpected EOF while parsing (line 1)" on '0.529177249d0'
{'dp5': 0.5, 'evtoh': '1.0/27.2113962d0', 'masstoau': 1822.8869999999999, 'defreal': 8, 'i0': 0, 'fpzero': '1.0d-10', 'defcomp': 8, 'defshort': 2, 'defint': 4, 'cmtoau': 4.5560000000000001e-06, 'shreal': 4, 'c1i': (0.0, 1.0), 'degtoau': 3.1669999999999999e-06, 'fpinfinity': '1.0d+100', 'bohrtoang': '0.529177249d0', 'pi': 3.1415926535897931}
In: :fmsmod:Module.f90:fmslib
get_parameters: got "unexpected EOF while parsing (line 1)" on '1.0/27.2113962d0'
				Block: t_particle
				Block: t_trajectory
				Block: t_trajectorybundle
				Block: file_units
Post-processing (stage 2)...
	Block: fmsmod
		Block: unknown_interface
			Block: fmslib
				Block: t_particle
				Block: t_trajectory
				Block: t_trajectorybundle
				Block: file_units
Building modules...
	Building module "fmsmod"...
		Constructing F90 module support for "fmslib"...
		  Variables: masstoau defreal i0 defcomp defshort bohrtoang evtoh d2 d0 d1 dp5 fpzero defint cmtoau shreal c1i degtoau fpinfinity pi
Skipping type t_particle
Skipping type t_trajectory
Skipping type t_trajectorybundle
Skipping type file_units
	Wrote C/API module "fmsmod" to file "/tmp/tmp7fVPVq/src/fmsmodmodule.c"
	Fortran 90 wrappers are saved to "/tmp/tmp7fVPVq/src/fmsmod-f2pywrappers2.f90"
  adding '/tmp/tmp7fVPVq/src/fortranobject.c' to sources.
  adding '/tmp/tmp7fVPVq/src' to include_dirs.
copying /usr/lib/python2.3/site-packages/f2py2e/src/fortranobject.c -> /tmp/tmp7fVPVq/src
copying /usr/lib/python2.3/site-packages/f2py2e/src/fortranobject.h -> /tmp/tmp7fVPVq/src
  adding '/tmp/tmp7fVPVq/src/fmsmod-f2pywrappers2.f90' to sources.
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
customize PGroupFCompiler
customize PGroupFCompiler using build_ext
building 'fmsmod' extension
compiling C sources
gcc options: '-pthread -fno-strict-aliasing -DNDEBUG -O2 -pipe -m32 -march=i386 -mtune=pentium4 -D_GNU_SOURCE -fPIC -fPIC'
creating /tmp/tmp7fVPVq/tmp
creating /tmp/tmp7fVPVq/tmp/tmp7fVPVq
creating /tmp/tmp7fVPVq/tmp/tmp7fVPVq/src
compile options: '-I/usr/include/python2.3 -I/tmp/tmp7fVPVq/src -I/usr/include/python2.3 -c'
gcc: /tmp/tmp7fVPVq/src/fmsmodmodule.c
gcc: /tmp/tmp7fVPVq/src/fortranobject.c
compiling Fortran 90 module sources
pgf77(f77) options: '-fpic -Minform=inform -Mnosecond_underscore -fast'
pgf90(f90) options: '-fpic -Minform=inform -Mnosecond_underscore -fast'
pgf90(fix) options: '-Mfixed -fpic -Minform=inform -Mnosecond_underscore -fast'
compile options: '-I/usr/include/python2.3 -I/tmp/tmp7fVPVq/src -I/usr/include/python2.3 -c'
extra options: '-module /tmp/tmp7fVPVq/ -I/tmp/tmp7fVPVq/'
pgf90:fix: Module.f90
compiling Fortran sources
pgf77(f77) options: '-fpic -Minform=inform -Mnosecond_underscore -fast'
pgf90(f90) options: '-fpic -Minform=inform -Mnosecond_underscore -fast'
pgf90(fix) options: '-Mfixed -fpic -Minform=inform -Mnosecond_underscore -fast'
compile options: '-I/usr/include/python2.3 -I/tmp/tmp7fVPVq/src -I/usr/include/python2.3 -c'
extra options: '-module /tmp/tmp7fVPVq/ -I/tmp/tmp7fVPVq/'
pgf90:f90: /tmp/tmp7fVPVq/src/fmsmod-f2pywrappers2.f90
pgf90 -shared /tmp/tmp7fVPVq/tmp/tmp7fVPVq/src/fmsmodmodule.o /tmp/tmp7fVPVq/tmp/tmp7fVPVq/src/fortranobject.o /tmp/tmp7fVPVq/Module.o /tmp/tmp7fVPVq/tmp/tmp7fVPVq/src/fmsmod-f2pywrappers2.o -o ./fmsmod.so
Removing build directory /tmp/tmp7fVPVq


More information about the f2py-users mailing list