Re: calling C function from Python via f2py

From: Matt Fearon <matt.fearon_at_nyahnyahspammersnyahnyah>
Date: Fri May 21 2010 - 12:34:59 MDT

Hi Nikolaos,

Thanks for your help. However, I receive the same results and trouble
swapping float for double. See below.

f2py -c -lm FFMCcalc.pyf FFMCcalc.c
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 "FFMCcalc" sources
creating /tmp/tmp53aYou
creating /tmp/tmp53aYou/src.linux-i686-2.6
f2py options: []
f2py: FFMCcalc.pyf
Reading fortran codes...
        Reading file 'FFMCcalc.pyf' (format:free)
Line #7 in FFMCcalc.pyf:" intent(c) "
        All arguments will have attribute intent(c)
Post-processing...
        Block: FFMCcalc
                        Block: FFMCcalc
Post-processing (stage 2)...
Building modules...
        Building module "FFMCcalc"...
                Constructing wrapper function "FFMCcalc"...
                  FFMCcalc(T,H,W,ro,Fo,F)
        Wrote C/API module "FFMCcalc" to file
"/tmp/tmp53aYou/src.linux-i686-2.6/FFMCcalcmodule.c"
  adding '/tmp/tmp53aYou/src.linux-i686-2.6/fortranobject.c' to sources.
  adding '/tmp/tmp53aYou/src.linux-i686-2.6' to include_dirs.
copying /usr/lib/python2.6/dist-packages/numpy/f2py/src/fortranobject.c
-> /tmp/tmp53aYou/src.linux-i686-2.6
copying /usr/lib/python2.6/dist-packages/numpy/f2py/src/fortranobject.h
-> /tmp/tmp53aYou/src.linux-i686-2.6
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
building 'FFMCcalc' extension
compiling C sources
C compiler: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2
-Wall -Wstrict-prototypes -fPIC

creating /tmp/tmp53aYou/tmp
creating /tmp/tmp53aYou/tmp/tmp53aYou
creating /tmp/tmp53aYou/tmp/tmp53aYou/src.linux-i686-2.6
compile options: '-I/tmp/tmp53aYou/src.linux-i686-2.6
-I/usr/lib/python2.6/dist-packages/numpy/core/include
-I/usr/include/python2.6 -c'
gcc: FFMCcalc.c
FFMCcalc.c: In function ‘FFMCcalc’:
FFMCcalc.c:20: warning: implicit declaration of function ‘exp’
FFMCcalc.c:20: warning: incompatible implicit declaration of built-in
function ‘exp’
FFMCcalc.c:28: warning: implicit declaration of function ‘pow’
FFMCcalc.c:28: warning: incompatible implicit declaration of built-in
function ‘pow’
FFMCcalc.c:38: warning: incompatible implicit declaration of built-in
function ‘pow’
FFMCcalc.c:40: warning: incompatible implicit declaration of built-in
function ‘exp’
gcc: /tmp/tmp53aYou/src.linux-i686-2.6/FFMCcalcmodule.c
gcc: /tmp/tmp53aYou/src.linux-i686-2.6/fortranobject.c
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions
/tmp/tmp53aYou/tmp/tmp53aYou/src.linux-i686-2.6/FFMCcalcmodule.o
/tmp/tmp53aYou/FFMCcalc.o
/tmp/tmp53aYou/tmp/tmp53aYou/src.linux-i686-2.6/fortranobject.o -lm -o
./FFMCcalc.so
running scons
Removing build directory /tmp/tmp53aYou
matt@oyster:~/fwi/f2py_test$ ./test.py
FFMCcalc - Function signature:
  FFMCcalc(T,H,W,ro,Fo,F)
Required arguments:
  T : input float
  H : input float
  W : input float
  ro : input float
  Fo : input float
  F : input float

Traceback (most recent call last):
  File "./test.py", line 13, in <module>
    print FFMCcalc.FFMCcalc([T,H,W,ro,Fo,F])
TypeError: Required argument 'H' (pos 2) not found

On Fri, May 21, 2010 at 2:08 PM, Hatzopoulos, Nikolaos
<hatzopou@chapman.edu> wrote:
>
> What's the results if you replace the double variables to floats
>
> --
> Nikolaos Hatzopoulos - Research Associate
> Chapman University
> Center of Excellence in Applied,
> Computational and Fundamental Science
> web: http://forecast.chapman.edu
>
>
>
> -----Original Message-----
> From: pyngl-talk-bounces@ucar.edu on behalf of Matt Fearon
> Sent: Fri 5/21/2010 10:58 AM
> To: pyngl-talk@ucar.edu
> Subject: calling C function from Python via f2py
>
> Hello,
>
> New to PyNGL. I am trying to use f2py to generate a wrapped C function
> that I can call from Python (passing arguments to and from). I have
> this almost working, but I receive trouble with "exp and pow" related
> to C and some "pos (2) error" with one of my passed variables. My f2py
> syntax is:
>
> f2py -c -lm FFMCcalc.pyf FFMCcalc.c
>
> Also, my 3 scripts are short and attached.
>
> 1. FFMCcalc.c, C function
> 2. FFMCcalc.pyf, wrapper file
> 3. test.py, short python code that calls C function
>
> Any advice would greatly appreciated to get this working.
> thanks,
> Matt
>
>
_______________________________________________
pyngl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Fri May 21 12:35:02 2010

This archive was generated by hypermail 2.1.8 : Fri Jul 02 2010 - 10:10:53 MDT