I am trying to compile a Fortran f90 file with f2py, to use in Python. The file is a subroutine that calls a module from another file. The module is basically for allocation. I can compile the module, using 'gfortran my_dec.f90' in the command window, but I get errors when trying to compile the subroutine file. It's especially difficult because I've barely used Fortran and this is someone else's code.
Here are the module and a section of the subroutine, because it's quite long, including its start and end:
module my_dec
integer ndir, nfreq
integer ihmax,ier
integer nk,nth,nspec
real hspmin
real wsmult
real wscut
logical flcomb, flc
parameter(ndir=24)
parameter(nfreq=23)
parameter(nk=nfreq)
parameter(nth=ndir)
parameter(nspec=nk*nth)
REAL DTH, SIG(0:nk+1), DSII(0:nk+1), DSIP(0:nk+1)
REAL ECOS(nspec+nth), ESIN(nspec+nth), XFR
REAL FACHFE, TH(nth), FTE
REAL ES2(nspec+NTH),EC2(nspec+NTH),ESC(nspec+NTH)
REAL DDEN(NK),DDEN2(nspec)
REAL SIG2(nspec)
INTEGER IAPROC, NAPERR, NDSE, NDST
INTEGER year, TIME
real pcg ! percentage either side of peakfor gamma estimate
data pcg/0.3/
end module my_dec
subroutine:
subroutine my_init
use my_dec
use constants
iaproc=1
naperr=1
ndset=1
ndst=1
IHM = 100
HSPM = 0.05
WSM = 1.7
WSC = 0.333
FLC = .true.
IHMAX = MAX ( 50, IHM )
HSPMIN = MAX ( 0.0001 , HSPM )
WSMULT = MAX ( 1. , WSM )
WSCUT = MIN ( 1.0001 , MAX ( 0. , WSC ) )
FLCOMB = FLC
...
return
end
When I try to compile the subroutine file, 'my_init.f90', using 'f2py -c my_init.f90 -m my_init_m' I get a whole bunch of messages, about references to variables from the module, in the subroutine:
c:\users\lwl\appdata\local\temp\tmptlve6z\Release\my_init.o:my_init.f90:(.text+0
xb): undefined reference to `__my_dec_MOD_iaproc'
c:\users\lwl\appdata\local\temp\tmptlve6z\Release\my_init.o:my_init.f90:(.text+0
x15): undefined reference to `__my_dec_MOD_naperr'
c:\users\lwl\appdata\local\temp\tmptlve6z\Release\my_init.o:my_init.f90:(.text+0
x26): undefined reference to `__my_dec_MOD_ndst'
c:\users\lwl\appdata\local\temp\tmptlve6z\Release\my_init.o:my_init.f90:(.text+0
x4f): undefined reference to `__my_dec_MOD_flc'
and then the error, which doesn't reveal much to me:
collect2: ld returned 1 exit status
error: Command "C:\Python27\Scripts\gfortran.exe -Wall -Wall -shared c:\users\lw
l\appdata\local\temp\tmptlve6z\Release\users\lwl\appdata\local\temp\tmptlve6z\sr
c.win-amd64-2.7\my_init_mmodule.o c:\users\lwl\appdata\local\temp\tmptlve6z\Rele
ase\users\lwl\appdata\local\temp\tmptlve6z\src.win-amd64-2.7\fortranobject.o c:\
users\lwl\appdata\local\temp\tmptlve6z\Release\my_init.o -Lc:\python27\egg-info\
mingw\usr\lib\gcc\x86_64-w64-mingw32\4.5.2 -LC:\Python27\libs -LC:\Python27\PCbu
ild\amd64 -lpython27 -lgfortran -o .\my_init_m.pyd" failed with exit status 1
I've been trying to work this out for a couple of days, including searching the internet, but to no avail. Anyone have any ideas? it could be quite a simple problem. Thanks for any help.
Edit: I've got it to work if I copy and paste the module into the same file as the subroutine, but it would be nice to have it work with them as seperate files.