Skip to content

Commit

Permalink
Merge pull request #51 from jacobwilliams/50-quotes
Browse files Browse the repository at this point in the history
always enclose filename in quotes in execute function if it isn't already
  • Loading branch information
jacobwilliams authored Aug 17, 2024
2 parents d9ded3f + da34d27 commit 60c5690
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pyplot_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,12 @@ subroutine execute(me, pyfile, istat, python)
file = trim(pyfile) !use the user-specified name
end if

if (file == '') then
if (present(istat)) istat = -1
write(error_unit,'(A)') 'Error: filename is blank.'
return
end if

!open the file:
open(newunit=iunit, file=file, status='REPLACE', iostat=iostat)
if (iostat/=0) then
Expand All @@ -1423,8 +1429,8 @@ subroutine execute(me, pyfile, istat, python)
end if

!run the file using python:
if (index(file,' ')>0) then
! space in path, probably should enclose in quotes
if (file(1:1)/='"') then
! if not already in quotes, should enclose in quotes
call execute_command_line(python_//' "'//file//'"')
else
call execute_command_line(python_//' '//file)
Expand Down
6 changes: 6 additions & 0 deletions test/test.f90
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,11 @@ program test
dpi='200', &
transparent=.true.,istat=istat, python='python')

! also test one with spaces and () in the filename
call plt%savefig(testdir//'error bar (1).png', &
pyfile=testdir//'error bar (1).py', &
dpi='200', &
transparent=.true.,istat=istat, python='python')

end program test
!*****************************************************************************************

0 comments on commit 60c5690

Please sign in to comment.