Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions numpy/f2py/crackfortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,28 @@ def updatevars(typespec, selector, attrspec, entitydecl):
d1[k] = unmarkouterparen(d1[k])
else:
del d1[k]

if 'len' in d1:
if typespec in ['complex', 'integer', 'logical', 'real']:
if ('kindselector' not in edecl) or (not edecl['kindselector']):
edecl['kindselector'] = {}
edecl['kindselector']['*'] = d1['len']
del d1['len']
elif typespec == 'character':
if ('charselector' not in edecl) or (not edecl['charselector']):
edecl['charselector'] = {}
if 'len' in edecl['charselector']:
del edecl['charselector']['len']
edecl['charselector']['*'] = d1['len']
del d1['len']

if 'init' in d1:
if '=' in edecl and (not edecl['='] == d1['init']):
outmess('updatevars: attempt to change the init expression of "%s" ("%s") to "%s". Ignoring.\n' % (
ename, edecl['='], d1['init']))
else:
edecl['='] = d1['init']

if 'len' in d1 and 'array' in d1:
if d1['len'] == '':
d1['len'] = d1['array']
Expand All @@ -1753,6 +1775,7 @@ def updatevars(typespec, selector, attrspec, entitydecl):
del d1['len']
errmess('updatevars: "%s %s" is mapped to "%s %s(%s)"\n' % (
typespec, e, typespec, ename, d1['array']))

if 'array' in d1:
dm = 'dimension(%s)' % d1['array']
if 'attrspec' not in edecl or (not edecl['attrspec']):
Expand All @@ -1766,23 +1789,6 @@ def updatevars(typespec, selector, attrspec, entitydecl):
% (ename, dm1, dm))
break

if 'len' in d1:
if typespec in ['complex', 'integer', 'logical', 'real']:
if ('kindselector' not in edecl) or (not edecl['kindselector']):
edecl['kindselector'] = {}
edecl['kindselector']['*'] = d1['len']
elif typespec == 'character':
if ('charselector' not in edecl) or (not edecl['charselector']):
edecl['charselector'] = {}
if 'len' in edecl['charselector']:
del edecl['charselector']['len']
edecl['charselector']['*'] = d1['len']
if 'init' in d1:
if '=' in edecl and (not edecl['='] == d1['init']):
outmess('updatevars: attempt to change the init expression of "%s" ("%s") to "%s". Ignoring.\n' % (
ename, edecl['='], d1['init']))
else:
edecl['='] = d1['init']
else:
outmess('updatevars: could not crack entity declaration "%s". Ignoring.\n' % (
ename + m.group('after')))
Expand Down
2 changes: 2 additions & 0 deletions numpy/f2py/tests/src/string/scalar_string.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
MODULE string_test

character(len=8) :: string
character string77 * 8

character(len=12), dimension(5,7) :: strarr
character strarr77(5,7) * 12

END MODULE string_test
22 changes: 12 additions & 10 deletions numpy/f2py/tests/test_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,16 +575,18 @@ class TestStringScalarArr(util.F2PyTest):

@pytest.mark.slow
def test_char(self):
out = self.module.string_test.string
expected = ()
assert out.shape == expected
expected = '|S8'
assert out.dtype == expected
for out in (self.module.string_test.string,
self.module.string_test.string77):
expected = ()
assert out.shape == expected
expected = '|S8'
assert out.dtype == expected

@pytest.mark.slow
def test_char_arr(self):
out = self.module.string_test.strarr
expected = (5,7)
assert out.shape == expected
expected = '|S12'
assert out.dtype == expected
for out in (self.module.string_test.strarr,
self.module.string_test.strarr77):
expected = (5,7)
assert out.shape == expected
expected = '|S12'
assert out.dtype == expected