Skip to content

Commit 5f3609b

Browse files
committed
Fix assumed shape character arrays
1 parent 5d4823a commit 5f3609b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

gfort2py/module_parse.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ def dtype(self):
196196
elif k == 8:
197197
return np.cdouble
198198
elif t == "CHARACTER":
199-
return f"S{self.strlen.value}"
199+
try:
200+
return f"S{self.strlen.value}"
201+
except AttributeError:
202+
return "S"
200203

201204
raise NotImplementedError(f"Object of type {t} and kind {k} not supported yet")
202205

tests/strings.f90

+12
Original file line numberDiff line numberDiff line change
@@ -357,4 +357,16 @@ subroutine set_chr_star_star(x)
357357
end subroutine set_chr_star_star
358358

359359

360+
subroutine check_assumed_shape_str(x)
361+
character(len=*), dimension(:), intent(in) :: x
362+
integer :: i
363+
364+
365+
do i=1,ubound(x,dim=1)
366+
write(*,*) trim(x(i))
367+
end do
368+
369+
370+
end subroutine check_assumed_shape_str
371+
360372
end module strings

tests/strings_test.py

+7
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,10 @@ def test_set_str_array_dt_out(self):
289289
def test_set_chr_star_star(self):
290290
res = x.set_chr_star_star(" ")
291291
assert res.args["x"] == "abcdefghijkl"
292+
293+
def test_check_assumed_shape_str(self, capfd):
294+
y = np.array(["a/b/c/d/e/f/g"], dtype="S")
295+
296+
res = x.check_assumed_shape_str(y)
297+
out, err = capfd.readouterr()
298+
assert out.strip() == "a/b/c/d/e/f/g"

0 commit comments

Comments
 (0)