-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor f2c_type to enable mixing of kind_map and default conversion…
… with test
- Loading branch information
daniel
committed
Sep 4, 2024
1 parent
a26be76
commit 5584972
Showing
8 changed files
with
113 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#======================================================================= | ||
# define the compiler names | ||
#======================================================================= | ||
|
||
CC = gcc | ||
F90 = gfortran | ||
PYTHON = python | ||
CFLAGS = -fPIC | ||
F90FLAGS = -fPIC | ||
PY_MOD = pywrapper | ||
F90_SRC = main.f90 | ||
OBJ = $(F90_SRC:.f90=.o) | ||
F90WRAP_SRC = $(addprefix f90wrap_,${F90_SRC}) | ||
WRAPFLAGS = -v --kind-map kind.map | ||
F2PYFLAGS = --build-dir build | ||
F90WRAP = f90wrap | ||
F2PY = f2py-f90wrap | ||
.PHONY: all clean | ||
|
||
all: test | ||
|
||
clean: | ||
rm -rf *.mod *.smod *.o f90wrap*.f90 ${PY_MOD}.py _${PY_MOD}*.so __pycache__/ .f2py_f2cmap build ${PY_MOD}/ | ||
|
||
main.o: ${F90_SRC} | ||
${F90} ${F90FLAGS} -c $< -o $@ | ||
|
||
%.o: %.f90 | ||
${F90} ${F90FLAGS} -c $< -o $@ | ||
|
||
${F90WRAP_SRC}: ${OBJ} | ||
${F90WRAP} -m ${PY_MOD} ${WRAPFLAGS} ${F90_SRC} | ||
|
||
f2py: ${F90WRAP_SRC} | ||
CFLAGS="${CFLAGS}" ${F2PY} -c -m _${PY_MOD} ${F2PYFLAGS} f90wrap_*.f90 *.o | ||
|
||
test: f2py | ||
${PYTHON} tests.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
include ../make.meson.inc | ||
|
||
NAME := pywrapper | ||
WRAPFLAGS += --kind_map kind.map | ||
|
||
test: build | ||
$(PYTHON) tests.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{\ | ||
'real':{'8':'double'},\ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
program main | ||
|
||
end program | ||
|
||
module m_test | ||
|
||
implicit none | ||
public | ||
|
||
contains | ||
|
||
function test_real(in_real) result(out_int) | ||
real :: in_real | ||
integer :: out_int | ||
out_int = 1 | ||
end function test_real | ||
|
||
function test_real4(in_real) result(out_int) | ||
real(kind=4) :: in_real | ||
integer :: out_int | ||
out_int = 2 | ||
end function test_real4 | ||
|
||
function test_real8(in_real) result(out_int) | ||
real(kind=8) :: in_real | ||
integer :: out_int | ||
out_int = 3 | ||
end function test_real8 | ||
|
||
end module m_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import unittest | ||
|
||
from pywrapper import m_test | ||
|
||
class TestKindMap(unittest.TestCase): | ||
|
||
def test_real(self): | ||
_ = m_test.test_real(1.) | ||
|
||
def test_real4(self): | ||
_ = m_test.test_real4(2.) | ||
|
||
def test_real8(self): | ||
_ = m_test.test_real8(3.) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters