[f2py] wrapping c with f2py (Ariel Balter)

Shang-Jun Ye yeshangjun at gmail.com
Tue Nov 24 17:04:03 EET 2009


I think the problem is caused by the format output.
I do get the same problem when wrapping a fortran code with f2py.

2009/11/24 <f2py-users-request at cens.ioc.ee>

> Send f2py-users mailing list submissions to
>        f2py-users at cens.ioc.ee
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://cens.ioc.ee/mailman/listinfo/f2py-users
> or, via email, send a message with subject or body 'help' to
>        f2py-users-request at cens.ioc.ee
>
> You can reach the person managing the list at
>        f2py-users-owner at cens.ioc.ee
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of f2py-users digest..."
>
>
> Today's Topics:
>
>   1. Re: wrapping c with f2py (Pearu Peterson)
>   2. Re: wrapping c with f2py (Pearu Peterson)
>   3.  wrapping c with f2py (Ariel Balter)
>   4. Re: wrapping c with f2py (Ariel Balter)
>   5. Re: wrapping c with f2py (Pearu Peterson)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 24 Nov 2009 09:36:14 +0200
> From: Pearu Peterson <pearu.peterson at gmail.com>
> Subject: Re: [f2py] wrapping c with f2py
> To: For users of the f2py program <f2py-users at cens.ioc.ee>
> Message-ID: <4B0B8CEE.4030607 at cens.ioc.ee>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi,
>
> The example works fine here with:
> $ f2py -v
> 2_6882
>
> What f2py version are you using?
>
> Pearu
>
> Ariel Balter wrote:
> > Hi,
> > I am trying to wrap c code with f2py.  I have found a couple of
> > resources such as
> > http://www.scipy.org/Cookbook/f2py_and_NumPy
> > and this post
> > http://cens.ioc.ee/pipermail/f2py-users/2005-February/001059.html
> >
> > Since I am writing, you might guess I'm having some trouble.  I'm
> > running ubuntu 9.10 and compiling with gfortran and gcc.  My python
> > version is 2.6.4.
> >
> > Here are my files:
> >
> > // ---------- f2ctest.c ----------- //
> > #include<stdio.h>
> >
> > int f2ctest(int num)
> > {
> >  printf( "Test:%i",num);
> >  return -1;
> > }
> >
> > // --------------------------------- //
> >
> > #-------- f2c.pyf ----------- #
> > python module f2c
> >  interface
> >    function f2ctest(num)
> >      intent(c) f2ctest
> >      integer f2ctest, num
> >      intent(c) num
> >    end function f2ctest
> >  end interface
> > end python module f2c
> > #------------------------------- #
> >
> > These are just the 2 example files in the post.  However, when I run
> > "f2py -c f2c.pyf f2ctest.c", I get a lot of very bad looking output,
> > full of the ominous word "error".  Since you probably have nothing
> > better to do than to read it, I have attached it.
> >
> > I would have posted this to the f2py forum, but I sincerely can't figure
> > out how.  I got this by clicking on your email link on the above post.
> >
> > Cheer, Ariel
> >
> > --
> > /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
> >
> > Ariel I Balter, Ph.D.
> > Postdoc
> > Biological Monitoring/Modeling
> > Fundamental and Computational Sciences Directorate
> >
> > Pacific Northwest National Laboratory Mail:
> > PO Box 999, MS P7-58,Richland, WA 99352
> > Shipping:
> > 790 6th Street, MS P7-58, Richland, WA 99354
> >
> > Tel:  509-376-7605 Cell:  509-713-0087
> > ariel.balter at pnl.gov <mailto:ariel.balter at pnl.gov>
> > www.arielbalter.com <http://www.arielbalter.com>
> > www.pnl.gov <http://www.pnl.gov>
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > f2py-users mailing list
> > f2py-users at cens.ioc.ee
> > http://cens.ioc.ee/mailman/listinfo/f2py-users
>
>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 24 Nov 2009 09:44:32 +0200
> From: Pearu Peterson <pearu.peterson at gmail.com>
> Subject: Re: [f2py] wrapping c with f2py
> To: For users of the f2py program <f2py-users at cens.ioc.ee>
> Message-ID: <4B0B8EE0.9020204 at cens.ioc.ee>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi again,
>
> Look at the first error message:
>
> ...
> In file included from /tmp/tmp6MoTqW/src.linux-i686-2.6/fortranobject.c:2:
> /tmp/tmp6MoTqW/src.linux-i686-2.6/fortranobject.h:7:20: error: Python.h:
> No such file or directory
> ...
>
> It means that you must install python developer package. Try, for example,
>
>  sudo apt-get install python-dev
>
> HTH,
> Pearu
>
>
> Ariel Balter wrote:
> > Hi,
> > I am trying to wrap c code with f2py.  I have found a couple of
> > resources such as
> > http://www.scipy.org/Cookbook/f2py_and_NumPy
> > and this post
> > http://cens.ioc.ee/pipermail/f2py-users/2005-February/001059.html
> >
> > Since I am writing, you might guess I'm having some trouble.  I'm
> > running ubuntu 9.10 and compiling with gfortran and gcc.  My python
> > version is 2.6.4.
> >
> > Here are my files:
> >
> > // ---------- f2ctest.c ----------- //
> > #include<stdio.h>
> >
> > int f2ctest(int num)
> > {
> >  printf( "Test:%i",num);
> >  return -1;
> > }
> >
> > // --------------------------------- //
> >
> > #-------- f2c.pyf ----------- #
> > python module f2c
> >  interface
> >    function f2ctest(num)
> >      intent(c) f2ctest
> >      integer f2ctest, num
> >      intent(c) num
> >    end function f2ctest
> >  end interface
> > end python module f2c
> > #------------------------------- #
> >
> > These are just the 2 example files in the post.  However, when I run
> > "f2py -c f2c.pyf f2ctest.c", I get a lot of very bad looking output,
> > full of the ominous word "error".  Since you probably have nothing
> > better to do than to read it, I have attached it.
> >
> > I would have posted this to the f2py forum, but I sincerely can't figure
> > out how.  I got this by clicking on your email link on the above post.
> >
> > Cheer, Ariel
> >
> > --
> > /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
> >
> > Ariel I Balter, Ph.D.
> > Postdoc
> > Biological Monitoring/Modeling
> > Fundamental and Computational Sciences Directorate
> >
> > Pacific Northwest National Laboratory Mail:
> > PO Box 999, MS P7-58,Richland, WA 99352
> > Shipping:
> > 790 6th Street, MS P7-58, Richland, WA 99354
> >
> > Tel:  509-376-7605 Cell:  509-713-0087
> > ariel.balter at pnl.gov <mailto:ariel.balter at pnl.gov>
> > www.arielbalter.com <http://www.arielbalter.com>
> > www.pnl.gov <http://www.pnl.gov>
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > f2py-users mailing list
> > f2py-users at cens.ioc.ee
> > http://cens.ioc.ee/mailman/listinfo/f2py-users
>
>
>
> ------------------------------
>
> Message: 3
> Date: Tue, 24 Nov 2009 00:15:41 -0800
> From: Ariel Balter <ariel at arielbalter.com>
> Subject: [f2py]  wrapping c with f2py
> To: f2py-users at cens.ioc.ee
> Message-ID: <4B0B962D.3020601 at arielbalter.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Stunned by the almost instantaneous response!
>
> Yes, installing python-dev did make that example work.  So, my system
> appears to be able to handle the necessities now.  Thanks!
>
> Now, perhaps you can please help me with this slightly more elaborate
> example:
>
> // ------------  cadd.c ------------------- //
>
> #include <stdio.h>
> #include <stdlib.h>
>
>
> int cadd(int a, int b){
>   int c = a + b;
>   printf("sum of %i and %i is %i\n", a, b, c );
>   return c;
> }
>
> // -------------------------------------------- //
>
> # -------------- padd.pyf -------------- #
>
> python module padd
>  interface
>    function cadd(a, b, c) result c
>      integer intent(c) cadd
>      integer intent(c) a
>      integer intent(c) b
>      integer intent(c) c
>    end function cadd
>  end interface
> end python module padd
>
> # ----------------------------------------- #
>
>
> I can compile with "f2py -c pyadd.pyf cadd.c" just fine.  BUT, when I
> try to import into python, I get:
>
> > >>> import padd
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> > ImportError: ./padd.so: undefined symbol: unknown_function_
>
> I've tried a couple of different formats for the PYF file, but I don't
> seem to have found the right approach.
>
> Thanks much, Ariel
>
> --
> /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
>
> Ariel I Balter, Ph.D.
> Postdoc
> Biological Monitoring/Modeling
> Fundamental and Computational Sciences Directorate
>
> Pacific Northwest National Laboratory Mail:
> PO Box 999, MS P7-58,Richland, WA 99352
> Shipping:
> 790 6th Street, MS P7-58, Richland, WA 99354
>
> Tel:  509-376-7605 Cell:  509-713-0087
> ariel.balter at pnl.gov
> www.arielbalter.com
> www.pnl.gov
>
>
>
>
> ------------------------------
>
> Message: 4
> Date: Tue, 24 Nov 2009 00:20:36 -0800
> From: Ariel Balter <ariel at arielbalter.com>
> Subject: Re: [f2py] wrapping c with f2py
> To: f2py-users at cens.ioc.ee
> Message-ID: <4B0B9754.20707 at arielbalter.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Darn!! I wrote too soon!  I just got it to work with:
>
>
> # -------------- padd.pyf -------------- #
>
> python module padd
>  interface
>    function cadd(a, b) result(c)
>      integer intent(c) :: cadd
>      integer intent(c) :: a
>      integer intent(c) :: b
>      integer intent(c) :: c
>    end function cadd
>  end interface
> end python module padd
>
> # ----------------------------------------- #
>
>
> I don't really understand how this all works yet, but I'm trying to
> follow various examples.  I'm a confirmed high-level programmer (or
> scripter as some like to call us).
>
> I'm working up to be able to wrap some sophisticated c code, so I'll
> probably be back...
>
> Thanks, Ariel
>
> Ariel Balter wrote:
> > Stunned by the almost instantaneous response!
> >
> > Yes, installing python-dev did make that example work.  So, my system
> > appears to be able to handle the necessities now.  Thanks!
> >
> > Now, perhaps you can please help me with this slightly more elaborate
> > example:
> >
> > // ------------  cadd.c ------------------- //
> >
> > #include <stdio.h>
> > #include <stdlib.h>
> >
> >
> > int cadd(int a, int b){
> >   int c = a + b;
> >   printf("sum of %i and %i is %i\n", a, b, c );
> >   return c;
> > }
> >
> > // -------------------------------------------- //
> >
> > # -------------- padd.pyf -------------- #
> >
> > python module padd
> >  interface
> >    function cadd(a, b, c) result c
> >      integer intent(c) cadd
> >      integer intent(c) a
> >      integer intent(c) b
> >      integer intent(c) c
> >    end function cadd
> >  end interface
> > end python module padd
> >
> > # ----------------------------------------- #
> >
> >
> > I can compile with "f2py -c pyadd.pyf cadd.c" just fine.  BUT, when I
> > try to import into python, I get:
> >
> >> >>> import padd
> >> Traceback (most recent call last):
> >>   File "<stdin>", line 1, in <module>
> >> ImportError: ./padd.so: undefined symbol: unknown_function_
> >
> > I've tried a couple of different formats for the PYF file, but I don't
> > seem to have found the right approach.
> >
> > Thanks much, Ariel
> >
>
> --
> /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
>
> Ariel I Balter, Ph.D.
> Postdoc
> Biological Monitoring/Modeling
> Fundamental and Computational Sciences Directorate
>
> Pacific Northwest National Laboratory Mail:
> PO Box 999, MS P7-58,Richland, WA 99352
> Shipping:
> 790 6th Street, MS P7-58, Richland, WA 99354
>
> Tel:  509-376-7605 Cell:  509-713-0087
> ariel.balter at pnl.gov
> www.arielbalter.com
> www.pnl.gov
>
>
>
>
> ------------------------------
>
> Message: 5
> Date: Tue, 24 Nov 2009 10:55:31 +0200
> From: Pearu Peterson <pearu.peterson at gmail.com>
> Subject: Re: [f2py] wrapping c with f2py
> To: For users of the f2py program <f2py-users at cens.ioc.ee>
> Message-ID: <4B0B9F83.6060503 at cens.ioc.ee>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Try the following signature file:
>
> python module padd
>  interface
>    function cadd(a, b) result (c)
>      integer, intent(c) :: cadd
>      integer, intent(c) :: a
>      integer, intent(c) :: b
>      integer, intent(c) :: c
>    end function cadd
>  end interface
> end python module padd
>
> or a shorter one:
>
> python module padd
>  interface
>    integer function cadd(a, b) result (c)
>      intent(c)  ! all arguments will have intent(c)
>      intent(c) cadd  ! function must be specified separately for intent(c)
>      integer a, b, c
>    end function cadd
>  end interface
> end python module padd
>
> Also check the syntax rules of the signature files in
>
>  http://cens.ioc.ee/projects/f2py2e/usersguide/index.html#signature-file
>
> Pearu
>
> Ariel Balter wrote:
> > Stunned by the almost instantaneous response!
> >
> > Yes, installing python-dev did make that example work.  So, my system
> > appears to be able to handle the necessities now.  Thanks!
> >
> > Now, perhaps you can please help me with this slightly more elaborate
> > example:
> >
> > // ------------  cadd.c ------------------- //
> >
> > #include <stdio.h>
> > #include <stdlib.h>
> >
> >
> > int cadd(int a, int b){
> >    int c = a + b;
> >    printf("sum of %i and %i is %i\n", a, b, c );
> >    return c;
> > }
> >
> > // -------------------------------------------- //
> >
> > # -------------- padd.pyf -------------- #
> >
> > python module padd
> >   interface
> >     function cadd(a, b, c) result c
> >       integer intent(c) cadd
> >       integer intent(c) a
> >       integer intent(c) b
> >       integer intent(c) c
> >     end function cadd
> >   end interface
> > end python module padd
> >
> > # ----------------------------------------- #
> >
> >
> > I can compile with "f2py -c pyadd.pyf cadd.c" just fine.  BUT, when I
> > try to import into python, I get:
> >
> >>>>> import padd
> >> Traceback (most recent call last):
> >>   File "<stdin>", line 1, in <module>
> >> ImportError: ./padd.so: undefined symbol: unknown_function_
> >
> > I've tried a couple of different formats for the PYF file, but I don't
> > seem to have found the right approach.
> >
> > Thanks much, Ariel
> >
>
>
>
> ------------------------------
>
> _______________________________________________
> f2py-users mailing list
> f2py-users at cens.ioc.ee
> http://cens.ioc.ee/mailman/listinfo/f2py-users
>
>
> End of f2py-users Digest, Vol 57, Issue 7
> *****************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cens.ioc.ee/pipermail/f2py-users/attachments/20091124/4df644f5/attachment-0001.htm 


More information about the f2py-users mailing list