Skip to content

Commit 60c5690

Browse files
Merge pull request #51 from jacobwilliams/50-quotes
always enclose filename in quotes in execute function if it isn't already
2 parents d9ded3f + da34d27 commit 60c5690

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/pyplot_module.F90

+8-2
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,12 @@ subroutine execute(me, pyfile, istat, python)
13971397
file = trim(pyfile) !use the user-specified name
13981398
end if
13991399

1400+
if (file == '') then
1401+
if (present(istat)) istat = -1
1402+
write(error_unit,'(A)') 'Error: filename is blank.'
1403+
return
1404+
end if
1405+
14001406
!open the file:
14011407
open(newunit=iunit, file=file, status='REPLACE', iostat=iostat)
14021408
if (iostat/=0) then
@@ -1423,8 +1429,8 @@ subroutine execute(me, pyfile, istat, python)
14231429
end if
14241430

14251431
!run the file using python:
1426-
if (index(file,' ')>0) then
1427-
! space in path, probably should enclose in quotes
1432+
if (file(1:1)/='"') then
1433+
! if not already in quotes, should enclose in quotes
14281434
call execute_command_line(python_//' "'//file//'"')
14291435
else
14301436
call execute_command_line(python_//' '//file)

test/test.f90

+6
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,11 @@ program test
201201
dpi='200', &
202202
transparent=.true.,istat=istat, python='python')
203203

204+
! also test one with spaces and () in the filename
205+
call plt%savefig(testdir//'error bar (1).png', &
206+
pyfile=testdir//'error bar (1).py', &
207+
dpi='200', &
208+
transparent=.true.,istat=istat, python='python')
209+
204210
end program test
205211
!*****************************************************************************************

0 commit comments

Comments
 (0)