Still having problems with f2py and python 2.6.2.
My Steps:
1. Installed f2py with # aptitude install f2py
1.5 tested f2py
abalter@scibox:~/Fortran$ f2py
Usage:
f2py -h <filename.pyf> ...< same options as in (1) >
Description: This program generates a Python C/API file (<modulename>module.c)
that contains wrappers for given fortran functions so that they
can be called from Python. With the -c option the corresponding extension modules are built.
Options:
--2d-numpy Use numpy.f2py tool with NumPy support. [DEFAULT]
--2d-numeric Use f2py2e tool with Numeric support.
--2d-numarray Use f2py2e tool with Numarray support.
--g3-numpy Use 3rd generation f2py from the separate f2py package. [NOT AVAILABLE YET]
-h <filename> Write signatures of the fortran routines to file <filename> and exit. You can then edit <filename> and use it instead of <fortran files>. If <filename>==stdout then the signatures are printed to stdout.
<fortran functions> Names of fortran routines for which Python C/API functions will be generated. Default is all that are found in <fortran files>.
<fortran files> Paths to fortran/signature files that will be scanned for <fortran functions> in order to determine their signatures.
skip: Ignore fortran functions that follow until `:'.
only: Use only fortran functions that follow until `:'.
: Get back to <fortran files> mode.
-m <modulename> Name of the module; f2py generates a Python/C API file <modulename>module.c or extension module <modulename>. Default is 'untitled'.
--[no-]lower Do [not] lower the cases in <fortran files>. By default, --lower is assumed with -h key, and --no-lower without -h key.
--build-dir <dirname> All f2py generated files are created in <dirname>. Default is tempfile.mktemp().
--[no-]latex-doc Create (or not) <modulename>module.tex. Default is --no-latex-doc.
--short-latex Create 'incomplete' LaTeX document (without commands \documentclass, \tableofcontents, and \begin{document}, \end{document}).
--[no-]rest-doc Create (or not) <modulename>module.rst. Default is --no-rest-doc.
--debug-capi Create C/API code that reports the state of the wrappers during runtime. Useful for debugging.
--[no-]wrap-functions Create Fortran subroutine wrappers to Fortran 77 functions. --wrap-functions is default because it ensures maximum portability/compiler independence.
--include_paths <path1>:<path2>:... Search include files from the given directories.
--help-link [..] List system resources found by system_info.py. See also --link-<resource> switch below. [..] is optional list of resources names. E.g. try 'f2py --help-link lapack_opt'.
--quiet Run quietly.
--verbose Run with extra verbosity.
-v Print f2py version ID and exit.
numpy.distutils options (only effective with -c):
--fcompiler= Specify Fortran compiler type by vendor
--compiler= Specify C compiler type (as defined by distutils)
--help-fcompiler List available Fortran compilers and exit
--f77exec= Specify the path to F77 compiler
--f90exec= Specify the path to F90 compiler
--f77flags= Specify F77 compiler flags
--f90flags= Specify F90 compiler flags
--opt= Specify optimization flags
--arch= Specify architecture specific optimization flags
--noopt Compile without optimization
--noarch Compile without arch-dependent optimization
--debug Compile with debugging information
Extra options (only effective with -c):
--link-<resource> Link extension module with <resource> as defined by numpy.distutils/system_info.py. E.g. to link with optimized LAPACK libraries (vecLib on MacOSX, ATLAS elsewhere), use --link-lapack_opt. See also --help-link switch.
Using the following macros may be required with non-gcc Fortran
compilers:
-DPREPEND_FORTRAN -DNO_APPEND_FORTRAN -DUPPERCASE_FORTRAN
-DUNDERSCORE_G77
When using -DF2PY_REPORT_ATEXIT, a performance report of F2PY
interface is printed out at exit (platforms: Linux).
When using -DF2PY_REPORT_ON_ARRAY_COPY=<int>, a message is
sent to stderr whenever F2PY interface makes a copy of an
array. Integer <int> sets the threshold for array sizes when
a message should be shown.
Version: 2_5972
numpy Version: 1.2.1
Requires: Python 2.3 or higher.
License: NumPy license (see LICENSE.txt in the NumPy source code)
Copyright 1999 - 2005 Pearu Peterson all rights reserved. http://cens.ioc.ee/projects/f2py2e/
abalter@scibox:~/Fortran$
2. Created hello.f
___
program hello
print *,"Hello World!"
end program hello
___
3. $ python hello.f -m hello
4. >> import hello
>>> hello
<module 'hello' from 'hello.so'>
>>> dir(hello)
['__doc__', '__file__', '__name__', '__package__', '__version__']
>>>
KeyboardInterrupt
>>>
5. So I can't run hello.hello()
6. Created zadd.f
___
C
SUBROUTINE ZADD(A,B,C,N)
C
DOUBLE COMPLEX A(*)
DOUBLE COMPLEX B(*)
DOUBLE COMPLEX C(*)
INTEGER N
DO 20 J = 1, N
C(J) = A(J)+B(J)
20 CONTINUE
END
___
7. abalter@scibox:~/Fortran$ f2py zadd.f -m zadd
Reading fortran codes...
Reading file 'zadd.f' (format:fix,strict)
Traceback (most recent call last):
File "/usr/bin/f2py", line 24, in <module>
main()
File "/usr/lib/python2.6/dist-packages/numpy/f2py/f2py2e.py", line 562, in main
run_main(sys.argv[1:])
File "/usr/lib/python2.6/dist-packages/numpy/f2py/f2py2e.py", line 342, in run_main
postlist=callcrackfortran(files,options)
File "/usr/lib/python2.6/dist-packages/numpy/f2py/f2py2e.py", line 280, in callcrackfortran
postlist=crackfortran.crackfortran(files)
File "/usr/lib/python2.6/dist-packages/numpy/f2py/crackfortran.py", line 2675, in crackfortran
readfortrancode(files,crackline)
File "/usr/lib/python2.6/dist-packages/numpy/f2py/crackfortran.py", line 345, in readfortrancode
raise 'readfortrancode: Found non-(space,digit) char in the first column.\n\tAre you sure that this code is in fix form?\n\tline=%s'%`l`
TypeError: exceptions must be classes or instances, not str
abalter@scibox:~/Fortran$
Still having problems with f2py and python 2.6.2. scibox: ~/Fortran$ f2py
My Steps:
1. Installed f2py with # aptitude install f2py
1.5 tested f2py
abalter@
Usage:
1) To construct extension module sources:
f2py [<options>] <fortran files> [[[only:]||[skip:]] \
<fortran functions> ] \
[: <fortran files> ...]
2) To compile fortran files and build extension modules:
f2py -c [<options>, <build_flib options>, <extra options>] <fortran files>
3) To generate signature files:
f2py -h <filename.pyf> ...< same options as in (1) >
Description: This program generates a Python C/API file (<modulename> module. c)
extension modules are built.
that contains wrappers for given fortran functions so that they
can be called from Python. With the -c option the corresponding
Options:
--2d-numpy Use numpy.f2py tool with NumPy support. [DEFAULT]
[NOT AVAILABLE YET]
--2d-numeric Use f2py2e tool with Numeric support.
--2d-numarray Use f2py2e tool with Numarray support.
--g3-numpy Use 3rd generation f2py from the separate f2py package.
-h <filename> Write signatures of the fortran routines to file <filename>
and exit. You can then edit <filename> and use it instead
of <fortran files>. If <filename>==stdout then the
signatures are printed to stdout.
functions will be generated. Default is all that are found
in <fortran files>.
<fortran functions> in order to determine their signatures.
<fortran functions> Names of fortran routines for which Python C/API
<fortran files> Paths to fortran/signature files that will be scanned for
skip: Ignore fortran functions that follow until `:'.
only: Use only fortran functions that follow until `:'.
: Get back to <fortran files> mode.
-m <modulename> Name of the module; f2py generates a Python/C API
file <modulename> module. c or extension module <modulename>.
Default is 'untitled'.
--[no-]lower Do [not] lower the cases in <fortran files>. By default,
-- lower is assumed with -h key, and --no-lower without -h key.
--build-dir <dirname> All f2py generated files are created in <dirname>.
Default is tempfile.mktemp().
--overwrite- signature Overwrite existing signature file.
--[no-]latex-doc Create (or not) <modulename> module. tex.
Default is --no-latex-doc.
\documentc lass, \tableofcontents, and \begin{document},
\end{ document} ).
--short-latex Create 'incomplete' LaTeX document (without commands
--[no-]rest-doc Create (or not) <modulename> module. rst.
Default is --no-rest-doc.
--debug-capi Create C/API code that reports the state of the wrappers
during runtime. Useful for debugging.
--[no- ]wrap-functions Create Fortran subroutine wrappers to Fortran 77
functions. --wrap-functions is default because it ensures
maximum portability/ compiler independence.
--include_paths <path1>:<path2>:... Search include files from the given
directorie s.
--help-link [..] List system resources found by system_info.py. See also
-- link-<resource> switch below. [..] is optional list
of resources names. E.g. try 'f2py --help-link lapack_opt'.
--quiet Run quietly.
--verbose Run with extra verbosity.
-v Print f2py version ID and exit.
numpy.distutils options (only effective with -c):
--fcompiler= Specify Fortran compiler type by vendor
--compiler= Specify C compiler type (as defined by distutils)
--help-fcompiler List available Fortran compilers and exit
--f77exec= Specify the path to F77 compiler
--f90exec= Specify the path to F90 compiler
--f77flags= Specify F77 compiler flags
--f90flags= Specify F90 compiler flags
--opt= Specify optimization flags
--arch= Specify architecture specific optimization flags
--noopt Compile without optimization
--noarch Compile without arch-dependent optimization
--debug Compile with debugging information
Extra options (only effective with -c):
--link-<resource> Link extension module with <resource> as defined
by numpy.distutils /system_ info.py. E.g. to link
with optimized LAPACK libraries (vecLib on MacOSX,
ATLAS elsewhere), use --link-lapack_opt.
See also --help-link switch.
-L/path/to/lib/ -l<libname> to/include/
-D<define> -U<name>
-I/path/
<filename>.o <filename>.so <filename>.a
Using the following macros may be required with non-gcc Fortran FORTRAN -DNO_APPEND_FORTRAN -DUPPERCASE_FORTRAN E_G77
compilers:
-DPREPEND_
-DUNDERSCOR
When using -DF2PY_ REPORT_ ATEXIT, a performance report of F2PY
interface is printed out at exit (platforms: Linux).
When using -DF2PY_ REPORT_ ON_ARRAY_ COPY=<int> , a message is
sent to stderr whenever F2PY interface makes a copy of an
array. Integer <int> sets the threshold for array sizes when
a message should be shown.
Version: 2_5972 cens.ioc. ee/projects/ f2py2e/ scibox: ~/Fortran$
numpy Version: 1.2.1
Requires: Python 2.3 or higher.
License: NumPy license (see LICENSE.txt in the NumPy source code)
Copyright 1999 - 2005 Pearu Peterson all rights reserved.
http://
abalter@
2. Created hello.f
___
program hello
print *,"Hello World!"
end program hello
___
3. $ python hello.f -m hello
4. >> import hello
>>> hello
<module 'hello' from 'hello.so'>
>>> dir(hello)
['__doc__', '__file__', '__name__', '__package__', '__version__']
>>>
KeyboardInterrupt
>>>
5. So I can't run hello.hello()
6. Created zadd.f
___
C
SUBROUTINE ZADD(A,B,C,N)
C
DOUBLE COMPLEX A(*)
DOUBLE COMPLEX B(*)
DOUBLE COMPLEX C(*)
INTEGER N
DO 20 J = 1, N
C(J) = A(J)+B(J)
20 CONTINUE
END
___
7. abalter@ scibox: ~/Fortran$ f2py zadd.f -m zadd python2. 6/dist- packages/ numpy/f2py/ f2py2e. py", line 562, in main main(sys. argv[1: ]) python2. 6/dist- packages/ numpy/f2py/ f2py2e. py", line 342, in run_main callcrackfortra n(files, options) python2. 6/dist- packages/ numpy/f2py/ f2py2e. py", line 280, in callcrackfortran crackfortran. crackfortran( files) python2. 6/dist- packages/ numpy/f2py/ crackfortran. py", line 2675, in crackfortran code(files, crackline) python2. 6/dist- packages/ numpy/f2py/ crackfortran. py", line 345, in readfortrancode tline=% s'%`l` scibox: ~/Fortran$
Reading fortran codes...
Reading file 'zadd.f' (format:fix,strict)
Traceback (most recent call last):
File "/usr/bin/f2py", line 24, in <module>
main()
File "/usr/lib/
run_
File "/usr/lib/
postlist=
File "/usr/lib/
postlist=
File "/usr/lib/
readfortran
File "/usr/lib/
raise 'readfortrancode: Found non-(space,digit) char in the first column.\n\tAre you sure that this code is in fix form?\n\
TypeError: exceptions must be classes or instances, not str
abalter@