Revision: 5792
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5792&view=rev
Author: fer_perez
Date: 2008-07-19 07:05:43 +0000 (Sat, 19 Jul 2008)
Log Message:
-----------
Add a new f2py example that uses F90 (it's still very simple).
Added Paths:
-----------
trunk/py4science/examples/numpy_wrap/f2py/example4/
trunk/py4science/examples/numpy_wrap/f2py/example4/Makefile
trunk/py4science/examples/numpy_wrap/f2py/example4/README.txt
trunk/py4science/examples/numpy_wrap/f2py/example4/setup.cfg
trunk/py4science/examples/numpy_wrap/f2py/example4/setup.py
trunk/py4science/examples/numpy_wrap/f2py/example4/simple.f90
trunk/py4science/examples/numpy_wrap/f2py/example4/simple.pyf
trunk/py4science/examples/numpy_wrap/f2py/example4/test_simple.py
Added: trunk/py4science/examples/numpy_wrap/f2py/example4/Makefile
===================================================================
--- trunk/py4science/examples/numpy_wrap/f2py/example4/Makefile
(rev 0)
+++ trunk/py4science/examples/numpy_wrap/f2py/example4/Makefile 2008-07-19
07:05:43 UTC (rev 5792)
@@ -0,0 +1,39 @@
+# Python wrappers for a simple Fortran 90 library
+
+# Build the actual library using a standard Python setup.py script
+build: simple.so
+
+simple.so: simple.f90 simple.pyf setup.py
+ ./setup.py config_fc build_ext --inplace
+
+# Build the library in place via a direct call to f2py, using the manually
+# modified simple.pyf file.
+libpyf: simple.f90 simple.pyf
+ f2py -c --fcompiler=gnu95 simple.pyf simple.f90
+
+# Build the 'raw' library by hand, without any tweaks to the python interface
+# of any function. Note that this will NOT pass the tests, since the tests
+# expect the modified interface.
+libraw: simple.f90
+ f2py -c --fcompiler=gnu95 -m simple simple.f90
+
+# Run a very simple test.
+test: build
+ python test_simple.py
+
+# If you have nose installed, the test above can be run as a proper unittest.
+nose: build
+ nosetests test_simple.py
+
+# Build the .pyf file. Note that the supplied file simple.pyf has been
+# manually modified from the auto-generated one. It's a good idea to
+# auto-generate one with a different name if you intend to manually edit yours
+# later, to help prevent an accidental clobbering.
+pyf: simple.f90
+ f2py -h simple_auto.pyf -m simple simple.f90
+
+clean:
+ rm -rf *~ *module.c *.pyc *-f2pywrappers*.f90 build
+
+cleanall: clean
+ rm -rf *.so
Added: trunk/py4science/examples/numpy_wrap/f2py/example4/README.txt
===================================================================
--- trunk/py4science/examples/numpy_wrap/f2py/example4/README.txt
(rev 0)
+++ trunk/py4science/examples/numpy_wrap/f2py/example4/README.txt
2008-07-19 07:05:43 UTC (rev 5792)
@@ -0,0 +1,24 @@
+==================================================
+ Very simple Fortran 90 wrapping example via f2py
+==================================================
+
+This small, self-contained directory shows how to build an extension for Python
+based on Fortran 90 code. You can do it both by directly calling f2py and via
+a small setup.py file.
+
+See the accompanying makefile for the actual targets provided, but if you are
+impatient and have gfortran installed, simply type::
+
+ make test
+
+which should run the build and a simple test. If no errors are printed at the
+end, you're fine. If you have nose installed (highly recommended and needed to
+test numpy and scipy, see
+http://www.somethingaboutorange.com/mrl/projects/nose/) you can try instead::
+
+ make nose
+
+This will run the same test files but as proper tests, indicating number of
+tests, errors/failures, etc. There is currently only one test provided, but
+using this in your projects will get you going with proper testing practices
+from the start.
Added: trunk/py4science/examples/numpy_wrap/f2py/example4/setup.cfg
===================================================================
--- trunk/py4science/examples/numpy_wrap/f2py/example4/setup.cfg
(rev 0)
+++ trunk/py4science/examples/numpy_wrap/f2py/example4/setup.cfg
2008-07-19 07:05:43 UTC (rev 5792)
@@ -0,0 +1,2 @@
+[config_fc]
+fcompiler = gnu95
Added: trunk/py4science/examples/numpy_wrap/f2py/example4/setup.py
===================================================================
--- trunk/py4science/examples/numpy_wrap/f2py/example4/setup.py
(rev 0)
+++ trunk/py4science/examples/numpy_wrap/f2py/example4/setup.py 2008-07-19
07:05:43 UTC (rev 5792)
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+"""Setup script for f2py-wrapped library.
+"""
+
+# Third-party modules
+from numpy.distutils.core import setup
+from numpy.distutils.extension import Extension
+
+# Build the extension module object
+extmod = Extension( name = 'simple',
+ # List here the interface (.pyf) file, plus any sources
+ # that need to be explicitly compiled into the wrapped
+ # module (i.e., not already part of one of the fortran
+ # libraries listed below):
+ sources = ['simple.pyf',
+ 'simple.f90'
+ ],
+
+ # Additional libraries required by our extension modules
+ libraries = [],
+
+ # Add '--debug-capi' for verbose debugging of low-level
+ # calls
+ #f2py_options = ['--debug-capi'],
+ )
+
+# Make the actual distutils setup call
+setup(name = 'simple', # name of the generated extension (.so)
+ description = 'Segmentation library',
+ author = 'Felipe Arrate',
+ ext_modules = [extmod],
+ )
Property changes on: trunk/py4science/examples/numpy_wrap/f2py/example4/setup.py
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/py4science/examples/numpy_wrap/f2py/example4/simple.f90
===================================================================
--- trunk/py4science/examples/numpy_wrap/f2py/example4/simple.f90
(rev 0)
+++ trunk/py4science/examples/numpy_wrap/f2py/example4/simple.f90
2008-07-19 07:05:43 UTC (rev 5792)
@@ -0,0 +1,29 @@
+
+! Matlab-like linspace()
+Subroutine linspace(x,y,lin,n)
+Integer n,i
+Real(8) lin(n)
+Real x,y
+
+!write(6,*) "x",x,"y",y,"n",n ! dbg
+
+Do i=1,n-1
+ lin(i)=x+(i-1)*(y-x)/(n-1)
+End Do
+lin(n)=y;
+END Subroutine linspace
+
+! An identical copy of the above, simply to demo in the python wrapping a
+! different way to expose the API for instructional purposes.
+Subroutine linspace2(x,y,lin,n)
+Integer n,i
+Real(8) lin(n)
+Real x,y
+
+!write(6,*) "x",x,"y",y,"n",n ! dbg
+
+Do i=1,n-1
+ lin(i)=x+(i-1)*(y-x)/(n-1)
+End Do
+lin(n)=y;
+END Subroutine linspace2
Added: trunk/py4science/examples/numpy_wrap/f2py/example4/simple.pyf
===================================================================
--- trunk/py4science/examples/numpy_wrap/f2py/example4/simple.pyf
(rev 0)
+++ trunk/py4science/examples/numpy_wrap/f2py/example4/simple.pyf
2008-07-19 07:05:43 UTC (rev 5792)
@@ -0,0 +1,30 @@
+! -*- f90 -*-
+! Note: the context of this file is case sensitive.
+
+! NOTE: This file HAS BEEN MODIFIED! An auto-generated f2py interface was used
+! as a starting point and then modified. If you overwrite it, you'll lose all
+! changes.
+
+python module simple ! in
+ interface ! in :simple
+
+ ! Default interface produced by 'f2py -h simple.pyf simple.f90'
+ subroutine linspace(x,y,lin,n) ! in :simple:simple.f90
+ real :: x
+ real :: y
+ real(kind=8) dimension(n) :: lin
+ integer optional,check(len(lin)>=n),depend(lin) :: n=len(lin)
+ end subroutine linspace
+
+ ! Modified interface: linspace2 is identical to linspace in Fortran, but
+ ! here we change its interface to a simpler that doesn't require the
+ ! external allocation of the output array.
+ subroutine linspace2(x,y,lin,n) ! in :simple:simple.f90
+ real :: x
+ real :: y
+ integer :: n
+ real(kind=8) dimension(n),intent(out),depend(n) :: lin
+ end subroutine linspace2
+
+ end interface
+end python module simple
Added: trunk/py4science/examples/numpy_wrap/f2py/example4/test_simple.py
===================================================================
--- trunk/py4science/examples/numpy_wrap/f2py/example4/test_simple.py
(rev 0)
+++ trunk/py4science/examples/numpy_wrap/f2py/example4/test_simple.py
2008-07-19 07:05:43 UTC (rev 5792)
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+import numpy as np
+
+import simple
+
+def test_linspace():
+ """Test both versions of linspace for consistency."""
+ n,x,y = 5, 0, 2.0
+ a = np.empty(n)
+
+ simple.linspace(x,y,a)
+ print a
+
+ b = simple.linspace2(x,y,n)
+ print b
+
+ np.testing.assert_almost_equal(a,b,15)
+
+if __name__ == '__main__':
+ test_linspace()
Property changes on:
trunk/py4science/examples/numpy_wrap/f2py/example4/test_simple.py
___________________________________________________________________
Added: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins