Hi, everyone:

I am new to the python numpy and f2py. I really need help on compiling FORTRAN module using f2py. I have been searched internet without any success. Here is my setup: I have a Ubuntu 10.04 LTS with python 2.6, numpy 1.3.0 and f2py 2 (installed from ubuntu) and gfortran compiler 4.4. I have a simple Fortran subroutine (in CSM_CH01_P1_1a_F.f95 file) as shown below:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!

subroutine sim_model_1(ts, n, a)

!

!f2py integer, intent(in) :: ts, n

!f2py real,dimension(n), intent(inout) :: a

implicit none

integer :: t, m, i

real :: ep, dm

!

m=n/2;

call init_random_seed()

do

if(t > ts) exit

call randperm(n,a)

call random_number(ep)

do i=1,n,2

dm=a(i)+a(i+1)

a(i)=ep*dm

a(i+1)=(1-ep)*dm

end do

t = t + 1

end do

return

end subroutine sim_model_1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I use f2py -m sim_model_1 -h sim_model_1.pyf CSM_CH01_P1_1a_F.f95 to generate signature file which is OK as shown below:

===================================================
!    -*- f90 -*-
! Note: the context of this file is case sensitive.

python module sim_model_1 ! in
    interface  ! in :sim_model_1
subroutine sim_model_1(ts,n,a) ! in :sim_model_1:CSM_CH01_P1_1a_F.f95
            integer intent(in) :: ts
integer optional,intent(in),check(len(a)>=n),depend(a) :: n=len(a)
            real dimension(n),intent(inout) :: a
        end subroutine sim_model_1
    end interface
end python module sim_model_1

! This file was auto-generated with f2py (version:2).
! See http://cens.ioc.ee/projects/f2py2e
===================================================

However, when I try to make the module, the compilation failed as if f2py does not pass the signature file to the compiler. The screen printout during compilation as shown below:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
f2py -c --fcompiler=gnu95 sim_model_1.pyf CSM_CH
<> f2py -c --fcompiler=gnu95 sim_model_1.pyf CSM_CH0 1_P1_1a_F.f95
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
building extension "sim_model_1" sources
creating /tmp/tmp6MXJY3
creating /tmp/tmp6MXJY3/src.linux-x86_64-2.6
f2py options: []
f2py: sim_model_1.pyf
Reading fortran codes...
    Reading file 'sim_model_1.pyf' (format:free)
Post-processing...
    Block: sim_model_1
            Block: sim_model_1
Post-processing (stage 2)...
Building modules...
    Building module "sim_model_1"...
        Constructing wrapper function "sim_model_1"...
          sim_model_1(ts,a,[n])
Wrote C/API module "sim_model_1" to file "/tmp/tmp6MXJY3/src.linux-x86_64-2.6/sim_model_1module.c"
  adding '/tmp/tmp6MXJY3/src.linux-x86_64-2.6/fortranobject.c' to sources.
  adding '/tmp/tmp6MXJY3/src.linux-x86_64-2.6' to include_dirs.
copying /usr/lib/python2.6/dist-packages/numpy/f2py/src/fortranobject.c -> /tmp/tmp6MXJY3/src.linux-x86_64-2.6 copying /usr/lib/python2.6/dist-packages/numpy/f2py/src/fortranobject.h -> /tmp/tmp6MXJY3/src.linux-x86_64-2.6
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
customize Gnu95FCompiler
Found executable /usr/bin/gfortran
customize Gnu95FCompiler using build_ext
building 'sim_model_1' extension
compiling C sources
C compiler: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC

creating /tmp/tmp6MXJY3/tmp
creating /tmp/tmp6MXJY3/tmp/tmp6MXJY3
creating /tmp/tmp6MXJY3/tmp/tmp6MXJY3/src.linux-x86_64-2.6
compile options: '-I/tmp/tmp6MXJY3/src.linux-x86_64-2.6 -I/usr/lib/python2.6/dist-packages/numpy/core/include -I/usr/include/python2.6 -c'
gcc: /tmp/tmp6MXJY3/src.linux-x86_64-2.6/fortranobject.c
gcc: /tmp/tmp6MXJY3/src.linux-x86_64-2.6/sim_model_1module.c
compiling Fortran sources
Fortran f77 compiler: /usr/bin/gfortran -Wall -ffixed-form -fno-second-underscore -fPIC -O3 -funroll-loops Fortran f90 compiler: /usr/bin/gfortran -Wall -fno-second-underscore -fPIC -O3 -funroll-loops Fortran fix compiler: /usr/bin/gfortran -Wall -ffixed-form -fno-second-underscore -Wall -fno-second-underscore -fPIC -O3 -funroll-loops compile options: '-I/tmp/tmp6MXJY3/src.linux-x86_64-2.6 -I/usr/lib/python2.6/dist-packages/numpy/core/include -I/usr/include/python2.6 -c'
gfortran:f90: CSM_CH01_P1_1a_F.f95
CSM_CH01_P1_1a_F.f95:29.7:

      a(i)=ep*dm
       1
Error: 'a' at (1) is not a variable
CSM_CH01_P1_1a_F.f95:30.7:

      a(i+1)=(1-ep)*dm
       1
Error: 'a' at (1) is not a variable
CSM_CH01_P1_1a_F.f95:9.25:

subroutine sim_model_1(ts, n, a)
                         1
Error: Symbol 'ts' at (1) has no IMPLICIT type
CSM_CH01_P1_1a_F.f95:9.28:

subroutine sim_model_1(ts, n, a)
                            1
Error: Symbol 'n' at (1) has no IMPLICIT type
CSM_CH01_P1_1a_F.f95:9.31:

subroutine sim_model_1(ts, n, a)
                               1
Error: Symbol 'a' at (1) has no IMPLICIT type
CSM_CH01_P1_1a_F.f95:28.15:

      dm=a(i)+a(i+1)
               1
Error: Function 'a' at (1) has no IMPLICIT type
CSM_CH01_P1_1a_F.f95:29.7:

      a(i)=ep*dm
       1
Error: 'a' at (1) is not a variable
CSM_CH01_P1_1a_F.f95:30.7:

      a(i+1)=(1-ep)*dm
       1
Error: 'a' at (1) is not a variable
CSM_CH01_P1_1a_F.f95:9.25:

subroutine sim_model_1(ts, n, a)
                         1
Error: Symbol 'ts' at (1) has no IMPLICIT type
CSM_CH01_P1_1a_F.f95:9.28:

subroutine sim_model_1(ts, n, a)
                            1
Error: Symbol 'n' at (1) has no IMPLICIT type
CSM_CH01_P1_1a_F.f95:9.31:

subroutine sim_model_1(ts, n, a)
                               1
Error: Symbol 'a' at (1) has no IMPLICIT type
CSM_CH01_P1_1a_F.f95:28.15:

      dm=a(i)+a(i+1)
               1
Error: Function 'a' at (1) has no IMPLICIT type
error: Command "/usr/bin/gfortran -Wall -fno-second-underscore -fPIC -O3 -funroll-loops -I/tmp/tmp6MXJY3/src.linux-x86_64-2.6 -I/usr/lib/python2.6/dist-packages/numpy/core/include -I/usr/include/python2.6 -c -c CSM_CH01_P1_1a_F.f95 -o /tmp/tmp6MXJY3/CSM_CH01_P1_1a_F.o" failed with exit status 1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

It looks like the two f2py directive declaration cause the problem. Any suggestion?
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to