Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Rémy Mozul
FortHon
Commits
b471d4cd
Commit
b471d4cd
authored
Feb 10, 2016
by
frozar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DEV] Documentation and examples of binding between python and fortran using f2py.
parent
5650b219
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
287 additions
and
0 deletions
+287
-0
python_binding_fortran/f2py_way/README
python_binding_fortran/f2py_way/README
+3
-0
python_binding_fortran/f2py_way/doc/f2py.pdf
python_binding_fortran/f2py_way/doc/f2py.pdf
+0
-0
python_binding_fortran/f2py_way/example_1/main.py
python_binding_fortran/f2py_way/example_1/main.py
+31
-0
python_binding_fortran/f2py_way/example_2/main.py
python_binding_fortran/f2py_way/example_2/main.py
+31
-0
python_binding_fortran/f2py_way/example_3/main.py
python_binding_fortran/f2py_way/example_3/main.py
+31
-0
python_binding_fortran/f2py_way/example_3/main_2.py
python_binding_fortran/f2py_way/example_3/main_2.py
+31
-0
python_binding_fortran/f2py_way/example_4/main.py
python_binding_fortran/f2py_way/example_4/main.py
+31
-0
python_binding_fortran/f2py_way/src_1/add.f90
python_binding_fortran/f2py_way/src_1/add.f90
+14
-0
python_binding_fortran/f2py_way/src_1/makefile
python_binding_fortran/f2py_way/src_1/makefile
+10
-0
python_binding_fortran/f2py_way/src_2/add.f90
python_binding_fortran/f2py_way/src_2/add.f90
+22
-0
python_binding_fortran/f2py_way/src_2/makefile
python_binding_fortran/f2py_way/src_2/makefile
+10
-0
python_binding_fortran/f2py_way/src_3/filter.f90
python_binding_fortran/f2py_way/src_3/filter.f90
+27
-0
python_binding_fortran/f2py_way/src_3/makefile
python_binding_fortran/f2py_way/src_3/makefile
+10
-0
python_binding_fortran/f2py_way/src_4/add_n_sub.f90
python_binding_fortran/f2py_way/src_4/add_n_sub.f90
+26
-0
python_binding_fortran/f2py_way/src_4/makefile
python_binding_fortran/f2py_way/src_4/makefile
+10
-0
No files found.
python_binding_fortran/f2py_way/README
0 → 100644
View file @
b471d4cd
Documentation:
http://docs.scipy.org/doc/numpy-1.10.1/user/c-info.python-as-glue.html
python_binding_fortran/f2py_way/doc/f2py.pdf
0 → 100644
View file @
b471d4cd
File added
python_binding_fortran/f2py_way/example_1/main.py
0 → 100755
View file @
b471d4cd
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def
usage
(
prog_name
):
print
" Usage:"
,
prog_name
print
" Example:"
,
prog_name
if
__name__
==
"__main__"
:
import
sys
# Add the local installation directory of the demonstration spam module
lib_dir
=
sys
.
path
[
0
]
+
'/../src_1'
sys
.
path
=
[
lib_dir
]
+
sys
.
path
try
:
import
add
except
ImportError
:
print
" FAIL: Cannot load the demonstration module spam."
print
" hint: cd ../src_1 ; make ; cd -"
exit
(
-
1
)
print
add
.
zadd
.
__doc__
print
add
.
zadd
(
[
1
,
2
,
3
],
[
1
,
2
],
[
3
,
4
],
1000
)
# spam.system('echo " SUCCESS: Loading spam module done."')
# if ( len( sys.argv[ 1: ] ) != 2 ):
# usage( sys.argv[ 0 ] )
# exit( 0 )
python_binding_fortran/f2py_way/example_2/main.py
0 → 100755
View file @
b471d4cd
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def
usage
(
prog_name
):
print
" Usage:"
,
prog_name
print
" Example:"
,
prog_name
if
__name__
==
"__main__"
:
import
sys
# Add the local installation directory of the demonstration spam module
lib_dir
=
sys
.
path
[
0
]
+
'/../src_2'
sys
.
path
=
[
lib_dir
]
+
sys
.
path
try
:
import
add
except
ImportError
:
print
" FAIL: Cannot load the demonstration module spam."
print
" hint: cd ../src_2 ; make ; cd -"
exit
(
-
1
)
print
add
.
zadd
.
__doc__
print
add
.
zadd
(
[
1
,
2
],
[
1
,
2
]
)
# spam.system('echo " SUCCESS: Loading spam module done."')
# if ( len( sys.argv[ 1: ] ) != 2 ):
# usage( sys.argv[ 0 ] )
# exit( 0 )
python_binding_fortran/f2py_way/example_3/main.py
0 → 100755
View file @
b471d4cd
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def
usage
(
prog_name
):
print
" Usage:"
,
prog_name
print
" Example:"
,
prog_name
if
__name__
==
"__main__"
:
import
sys
# Add the local installation directory of the demonstration spam module
lib_dir
=
sys
.
path
[
0
]
+
'/../src_3'
sys
.
path
=
[
lib_dir
]
+
sys
.
path
try
:
import
filter
except
ImportError
:
print
" FAIL: Cannot load the demonstration module spam."
print
" hint: cd ../src_1 ; make ; cd -"
exit
(
-
1
)
print
filter
.
dfilter2d
.
__doc__
# print add.zadd( [1,2], [1,2] )
# spam.system('echo " SUCCESS: Loading spam module done."')
# if ( len( sys.argv[ 1: ] ) != 2 ):
# usage( sys.argv[ 0 ] )
# exit( 0 )
python_binding_fortran/f2py_way/example_3/main_2.py
0 → 100755
View file @
b471d4cd
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def
usage
(
prog_name
):
print
" Usage:"
,
prog_name
print
" Example:"
,
prog_name
if
__name__
==
"__main__"
:
from
numpy
import
f2py
with
open
(
"../src_3/filter.f90"
)
as
sourcefile
:
sourcecode
=
sourcefile
.
read
()
f2py
.
compile
(
sourcecode
,
modulename
=
'filter'
,
verbose
=
1
)
try
:
import
filter
except
ImportError
:
print
" FAIL: Cannot load the demonstration module spam."
print
" hint: cd ../src_3 ; make ; cd -"
exit
(
-
1
)
print
filter
.
dfilter2d
.
__doc__
# print add.zadd( [1,2], [1,2] )
# spam.system('echo " SUCCESS: Loading spam module done."')
# if ( len( sys.argv[ 1: ] ) != 2 ):
# usage( sys.argv[ 0 ] )
# exit( 0 )
python_binding_fortran/f2py_way/example_4/main.py
0 → 100755
View file @
b471d4cd
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def
usage
(
prog_name
):
print
" Usage:"
,
prog_name
print
" Example:"
,
prog_name
if
__name__
==
"__main__"
:
import
sys
# Add the local installation directory of the demonstration spam module
lib_dir
=
sys
.
path
[
0
]
+
'/../src_4'
sys
.
path
=
[
lib_dir
]
+
sys
.
path
try
:
import
add_n_sub
except
ImportError
:
print
" FAIL: Cannot load the demonstration module spam."
print
" hint: cd ../src_4 ; make ; cd -"
exit
(
-
1
)
print
add_n_sub
.
zadd_n_sub
.
__doc__
print
add_n_sub
.
zadd_n_sub
(
[
1
,
2
],
[
1
,
2
]
)
# spam.system('echo " SUCCESS: Loading spam module done."')
# if ( len( sys.argv[ 1: ] ) != 2 ):
# usage( sys.argv[ 0 ] )
# exit( 0 )
python_binding_fortran/f2py_way/src_1/add.f90
0 → 100644
View file @
b471d4cd
subroutine
zadd
(
a
,
b
,
c
,
n
)
double
complex
a
(
*
)
double
complex
b
(
*
)
double
complex
c
(
*
)
integer
n
do
j
=
1
,
n
c
(
j
)
=
a
(
j
)
+
b
(
j
)
end
do
end
subroutine
zadd
! f2py -c -m add add.f90
python_binding_fortran/f2py_way/src_1/makefile
0 → 100644
View file @
b471d4cd
all
:
build_addmodule
build_addmodule
:
add.f90
f2py
-c
-m
add add.f90
clean
:
@
rm
-f
*
.so
*
.c
*
.mod
*
~
python_binding_fortran/f2py_way/src_2/add.f90
0 → 100644
View file @
b471d4cd
subroutine
zadd
(
a
,
b
,
c
,
n
)
implicit
none
!F2PY INTENT(OUT) :: C
!F2PY INTENT(HIDE) :: N
!F2PY DOUBLE COMPLEX :: A(N)
!F2PY DOUBLE COMPLEX :: B(N)
!F2PY DOUBLE COMPLEX :: C(N)
double
complex
a
(
*
)
double
complex
b
(
*
)
double
complex
c
(
*
)
integer
n
,
j
do
j
=
1
,
n
c
(
j
)
=
a
(
j
)
+
b
(
j
)
end
do
end
subroutine
zadd
! f2py -c -m add add.f90
python_binding_fortran/f2py_way/src_2/makefile
0 → 100644
View file @
b471d4cd
all
:
build_addmodule
build_addmodule
:
add.f90
f2py
-c
-m
add add.f90
clean
:
@
rm
-f
*
.so
*
.c
*
.mod
*
~
python_binding_fortran/f2py_way/src_3/filter.f90
0 → 100644
View file @
b471d4cd
subroutine
dfilter2d
(
a
,
b
,
m
,
n
)
implicit
none
double precision
a
(
m
,
n
)
double precision
b
(
m
,
n
)
integer
m
,
n
!F2PY INTENT(OUT) :: b
!F2PY INTENT(HIDE) :: M
!F2PY INTENT(HIDE) :: N
integer
i
,
j
do
i
=
2
,
m
-1
do
j
=
2
,
n
-1
b
(
i
,
j
)
=
a
(
i
,
j
)
+
&
(
a
(
i
-1
,
j
)
+
a
(
i
+1
,
j
)
+
&
a
(
i
,
j
-1
)
+
a
(
i
,
j
+1
)
)
*
0.5D0
+
&
(
a
(
i
-1
,
j
-1
)
+
a
(
i
-1
,
j
+1
)
+
&
a
(
i
+1
,
j
-1
)
+
a
(
i
+1
,
j
+1
)
)
*
0.25D0
end
do
end
do
end
subroutine
dfilter2d
! f2py -c -m filter filter.f90
python_binding_fortran/f2py_way/src_3/makefile
0 → 100644
View file @
b471d4cd
all
:
build_filtermodule
build_filtermodule
:
filter.f90
f2py
-c
-m
filter filter.f90
clean
:
@
rm
-f
*
.so
*
.c
*
.mod
*
~
python_binding_fortran/f2py_way/src_4/add_n_sub.f90
0 → 100644
View file @
b471d4cd
subroutine
zadd_n_sub
(
a
,
b
,
c
,
d
,
n
)
implicit
none
!F2PY INTENT(OUT) :: c
!F2PY INTENT(OUT) :: d
!F2PY INTENT(HIDE) :: N
!F2PY DOUBLE COMPLEX :: a(N)
!F2PY DOUBLE COMPLEX :: b(N)
!F2PY DOUBLE COMPLEX :: c(N)
!F2PY DOUBLE COMPLEX :: d(N)
double
complex
a
(
*
)
double
complex
b
(
*
)
double
complex
c
(
*
)
double
complex
d
(
*
)
integer
n
,
j
do
j
=
1
,
n
c
(
j
)
=
a
(
j
)
+
b
(
j
)
d
(
j
)
=
a
(
j
)
-
b
(
j
)
end
do
end
subroutine
zadd_n_sub
! f2py -c -m add_n_sub add_n_sub.f90
python_binding_fortran/f2py_way/src_4/makefile
0 → 100644
View file @
b471d4cd
all
:
build_addmodule
build_addmodule
:
add_n_sub.f90
f2py
-c
-m
add_n_sub add_n_sub.f90
clean
:
@
rm
-f
*
.so
*
.c
*
.mod
*
~
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment