summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2019-12-09 15:48:39 -0600
committerGitHub <noreply@github.com>2019-12-09 15:48:39 -0600
commitc01014507c6f128394ba1a66f91ef32fc94bbeba (patch)
treeabbe4a6642e8ca635d105a7accce3ae34422270c
parentbf9614b3253e9ef4dbbcef1f48751955b8f2a598 (diff)
parentf6ab00eb61d3db15522f373462d8984e792edeb8 (diff)
downloadnumpy-c01014507c6f128394ba1a66f91ef32fc94bbeba.tar.gz
Merge pull request #15035 from mattip/issue-14625
Test, fix for missing end words in fortran subroutines and functions. Fixes gh-14625
-rw-r--r--numpy/f2py/cfuncs.py2
-rwxr-xr-xnumpy/f2py/crackfortran.py3
-rw-r--r--numpy/f2py/tests/test_crackfortran.py40
3 files changed, 43 insertions, 2 deletions
diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py
index ccb7b3a32..cede06119 100644
--- a/numpy/f2py/cfuncs.py
+++ b/numpy/f2py/cfuncs.py
@@ -542,7 +542,7 @@ cppmacros[
'ARRSIZE'] = '#define ARRSIZE(dims,rank) (_PyArray_multiply_list(dims,rank))'
cppmacros['OLDPYNUM'] = """\
#ifdef OLDPYNUM
-#error You need to install NumPy version 13 or higher. See https://scipy.org/install.html
+#error You need to install NumPy version 0.13 or higher. See https://scipy.org/install.html
#endif
"""
################# C functions ###############
diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py
index 2aaf5d7c6..2db4a47e8 100755
--- a/numpy/f2py/crackfortran.py
+++ b/numpy/f2py/crackfortran.py
@@ -558,7 +558,8 @@ groupbegins90 = groupbegins77 + \
r'|module(?!\s*procedure)|python\s*module|interface|type(?!\s*\()'
beginpattern90 = re.compile(
beforethisafter % ('', groupbegins90, groupbegins90, '.*'), re.I), 'begin'
-groupends = r'end|endprogram|endblockdata|endmodule|endpythonmodule|endinterface'
+groupends = (r'end|endprogram|endblockdata|endmodule|endpythonmodule|'
+ r'endinterface|endsubroutine|endfunction')
endpattern = re.compile(
beforethisafter % ('', groupends, groupends, r'[\w\s]*'), re.I), 'end'
# endifs='end\s*(if|do|where|select|while|forall)'
diff --git a/numpy/f2py/tests/test_crackfortran.py b/numpy/f2py/tests/test_crackfortran.py
new file mode 100644
index 000000000..941696be3
--- /dev/null
+++ b/numpy/f2py/tests/test_crackfortran.py
@@ -0,0 +1,40 @@
+from __future__ import division, absolute_import, print_function
+
+import pytest
+
+import numpy as np
+from numpy.testing import assert_array_equal
+from . import util
+
+
+class TestNoSpace(util.F2PyTest):
+ # issue gh-15035: add handling for endsubroutine, endfunction with no space
+ # between "end" and the block name
+ code = """
+ subroutine subb(k)
+ real(8), intent(inout) :: k(:)
+ k=k+1
+ endsubroutine
+
+ subroutine subc(w,k)
+ real(8), intent(in) :: w(:)
+ real(8), intent(out) :: k(size(w))
+ k=w+1
+ endsubroutine
+
+ function t0(value)
+ character value
+ character t0
+ t0 = value
+ endfunction
+ """
+
+ def test_module(self):
+ k = np.array([1, 2, 3], dtype=np.float64)
+ w = np.array([1, 2, 3], dtype=np.float64)
+ self.module.subb(k)
+ assert_array_equal(k, w + 1)
+ self.module.subc([w, k])
+ assert_array_equal(k, w + 1)
+ assert self.module.t0(23) == b'2'
+