Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several interface for one procedure #238

Merged
11 changes: 9 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ list(APPEND tests
subroutine_contains_issue101
type_bn
kind_map_default
docstring
return_array
intent_out_size
string_array_input_f2py
type_check
optional_string
long_subroutine_name
output_kind
remove_pointer_arg
)

foreach(test ${tests})
Expand All @@ -36,5 +45,3 @@ foreach(test ${tests})
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/${test}"
)
endforeach()


7 changes: 6 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ EXAMPLES = arrayderivedtypes \
docstring \
type_check \
derivedtypes_procedure \
return_array \
string_array_input_f2py \
optional_string \
long_subroutine_name \
kind_map_default
kind_map_default \
intent_out_size \
output_kind \
remove_pointer_arg

PYTHON = python

Expand Down
6 changes: 1 addition & 5 deletions examples/docstring/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ main.o: ${F90_SRC}
${F90WRAP_SRC}: ${OBJ}
${F90WRAP} -m ${PY_MOD} ${WRAPFLAGS} ${F90_SRC}

f90wrap: ${F90WRAP_SRC}

f2py: ${F90WRAP_SRC}
CFLAGS="${CFLAGS}" ${F2PY} -c -m _${PY_MOD} ${F2PYFLAGS} f90wrap_*.f90 *.o

wrapper: f2py

test: wrapper
test: f2py
python docstring_test.py
111 changes: 65 additions & 46 deletions examples/docstring/docstring_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,55 @@ def test_module_doc(self):
circle = m_circle.t_circle()
docstring = m_circle.__doc__
ref_docstring = """
Module m_circle


Defined at main.f90 lines 7-89

File: main.f90
Brief: Test program docstring
Test program docstring

Author: test_author
Copyright: test_copyright

Module m_circle
Defined at main.f90 lines 7-89
"""

assert clean_str(ref_docstring) == clean_str(docstring)

def test_docstring(self):
def test_subroutine_docstring(self):
circle = m_circle.t_circle()
docstring = m_circle.construct_circle.__doc__
ref_docstring = """
Initialize circle

construct_circle(self, radius)
Defined at main.f90 lines 17-20

Parameters
----------
circle : T_Circle
t_circle to initialize [in,out]
radius : float32
radius of the circle [in]
"""

assert clean_str(ref_docstring) == clean_str(docstring)

def test_subroutine_docstring_more_doc(self):
circle = m_circle.t_circle()
docstring = m_circle.construct_circle_more_doc.__doc__
ref_docstring = """
Initialize circle with more doc

Author: test_author
Copyright: test_copyright

construct_circle_more_doc(self, radius)
Defined at main.f90 lines 17-20

Parameters
----------
circle : T_Circle, [in,out] t_circle to initialize
radius : float, [in] radius of the circle

Brief: Initialize circle
circle : T_Circle
t_circle to initialize [in,out]
radius : float32
radius of the circle [in]
"""

assert clean_str(ref_docstring) == clean_str(docstring)
Expand All @@ -57,17 +78,17 @@ def test_no_direction(self):
circle = m_circle.t_circle()
docstring = m_circle.no_direction.__doc__
ref_docstring = """
no_direction(self, radius)

Without direction

no_direction(self, radius)
Defined at main.f90 lines 28-31

Parameters
----------
circle : T_Circle, t_circle to initialize
radius : float, radius of the circle

Brief: Without direction
circle : T_Circle
t_circle to initialize
radius : float32
radius of the circle
"""

assert clean_str(ref_docstring) == clean_str(docstring)
Expand All @@ -76,17 +97,16 @@ def test_docstring_incomplet(self):
circle = m_circle.t_circle()
docstring = m_circle.incomplete_doc_sub.__doc__
ref_docstring = """
incomplete_doc_sub(self, radius)

Incomplete doc

incomplete_doc_sub(self, radius)
Defined at main.f90 lines 38-41

Parameters
----------
circle : T_Circle
radius : float, [in] radius of the circle

Brief: Incomplete doc
radius : float32
radius of the circle [in]
"""

assert clean_str(ref_docstring) == clean_str(docstring)
Expand All @@ -95,17 +115,15 @@ def test_param_return(self):
circle = m_circle.t_circle()
docstring = m_circle.output_1.__doc__
ref_docstring = """
output = output_1()

subroutine output_1 outputs 1

output = output_1()
Defined at main.f90 lines 59-61


Returns
-------
output : float, [out] this is 1

Brief: subroutine output_1 outputs 1
output : float32
this is 1 [out]
"""

assert clean_str(ref_docstring) == clean_str(docstring)
Expand All @@ -114,20 +132,20 @@ def test_function_return(self):
circle = m_circle.t_circle()
docstring = m_circle.function_2.__doc__
ref_docstring = """
function_2 = function_2(input)

this is a function

function_2 = function_2(input)
Defined at main.f90 lines 69-71

Parameters
----------
input : str, [in] value
input : str
value [in]

Returns
-------
function_2 : int, return value

Brief: this is a function
function_2 : int32
return value
"""

assert clean_str(ref_docstring) == clean_str(docstring)
Expand All @@ -136,18 +154,19 @@ def test_details(self):
circle = m_circle.t_circle()
docstring = m_circle.details_doc.__doc__
ref_docstring = """
details_doc(self, radius)
Initialize circle

Those are very informative details

details_doc(self, radius)
Defined at main.f90 lines 80-82

Parameters
----------
circle : T_Circle, [in,out] t_circle to initialize
radius : float, [in] radius of the circle

Brief: Initialize circle
Details: Those are very informative details
circle : T_Circle
t_circle to initialize [in,out]
radius : float32
radius of the circle [in]
"""

assert clean_str(ref_docstring) == clean_str(docstring)
Expand All @@ -157,17 +176,17 @@ def test_doc_inside(self):
circle = m_circle.t_circle()
docstring = m_circle.doc_inside.__doc__
ref_docstring = """
doc_inside(self, radius)

Doc inside

doc_inside(self, radius)
Defined at main.f90 lines 43-52

Parameters
----------
circle : T_Circle, [in,out] t_circle to initialize
radius : float, [in] radius of the circle

Brief: Doc inside
circle : T_Circle
t_circle to initialize [in,out]
radius : float32
radius of the circle [in]
"""

assert clean_str(ref_docstring) == clean_str(docstring)
Expand Down
17 changes: 16 additions & 1 deletion examples/docstring/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module m_circle
real :: radius
end type t_circle

public :: construct_circle,incomplete_doc_sub
public :: construct_circle,construct_circle_more_doc
public :: incomplete_doc_sub
public :: no_direction,doc_inside
public :: output_1,function_2,details_doc

Expand All @@ -30,6 +31,20 @@ subroutine construct_circle(circle,radius)
circle%radius = radius
end subroutine construct_circle

!===========================================================================
!>
!! \brief Initialize circle with more doc
!! \author test_author
!! \copyright test_copyright
!! \param[in,out] circle t_circle to initialize
!! \param[in] radius radius of the circle
!<
subroutine construct_circle_more_doc(circle,radius)
type(t_circle) :: circle
real, intent(in) :: radius
circle%radius = radius
end subroutine construct_circle_more_doc

!===========================================================================
!>
!! \brief Without direction
Expand Down
38 changes: 38 additions & 0 deletions examples/intent_out_size/Makefile
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
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
6 changes: 6 additions & 0 deletions examples/intent_out_size/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include ../make.meson.inc

NAME := pywrapper

test: build
$(PYTHON) tests.py
26 changes: 26 additions & 0 deletions examples/intent_out_size/main.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module m_intent_out

implicit none
public

contains

subroutine interpolation(n1,n2,a1,a2,output)
!
integer, intent(in) :: n1,n2
real,dimension(n1,n2), intent(in) :: a1,a2
real,dimension(n1,n2), intent(out) :: output

integer :: i,j

do j=1,n2
do i=1,n1
output(i,j)=(a1(i,j)+a2(i,j))/2
enddo
enddo

end subroutine interpolation

end module m_intent_out


24 changes: 24 additions & 0 deletions examples/intent_out_size/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import unittest
import numpy as np

from pywrapper import m_intent_out

class TestIntentOut(unittest.TestCase):

def test_intent_out_size(self):

a1 = np.array([[1,2], [3,4]], dtype=np.float32, order='F')
a2 = np.array([[2,4], [6,8]], dtype=np.float32, order='F')
output = np.zeros((2,2), dtype=np.float32, order='F')
n1 = 2
n2 = 2

m_intent_out.interpolation(n1,n2,a1,a2,output)

ref_out = np.array([[1.5,3.], [4.5,6.]], dtype=np.float32, order='F')

np.testing.assert_array_equal(output, ref_out)

if __name__ == '__main__':

unittest.main()
Loading
Loading