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
24 changes: 17 additions & 7 deletions src/pyplot_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1336,16 +1336,18 @@ end subroutine matrix_to_string
! If user specifies a Python file name, then the file is kept, otherwise
! a temporary filename is used, and the file is deleted after it is used.

subroutine execute(me, pyfile, istat)
subroutine execute(me, pyfile, istat, python)

class(pyplot), intent(inout) :: me !! pytplot handler
character(len=*), intent(in), optional :: pyfile !! name of the python script to generate
integer, intent (out),optional :: istat !! status output (0 means no problems)
character(len=*), intent(in),optional :: python !! python executable to use. (by default, this is 'python')

integer :: iunit !! IO unit
character(len=:), allocatable :: file !! file name
logical :: scratch !! if a scratch file is to be used
integer :: iostat !! open/close status code
character(len=:), allocatable :: python_ !! python executable to use

if (allocated(me%str)) then

Expand Down Expand Up @@ -1379,12 +1381,18 @@ subroutine execute(me, pyfile, istat)
write(error_unit,'(A)') 'Error closing file: '//trim(file)
else

if (present(python)) then
python_ = trim(python)
else
python_ = python_exe
end if

!run the file using python:
if (index(file,' ')>0) then
! space in path, probably should enclose in quotes
call execute_command_line(python_exe//' "'//file//'"')
call execute_command_line(python_//' "'//file//'"')
else
call execute_command_line(python_exe//' '//file)
call execute_command_line(python_//' '//file)
end if

if (scratch) then
Expand Down Expand Up @@ -1466,7 +1474,7 @@ end subroutine finish_ops
! * modified: Johannes Rieke 6/16/2017
! * modified: Jacob Williams 6/16/2017

subroutine savefig(me, figfile, pyfile, dpi, transparent, facecolor, edgecolor, orientation, istat)
subroutine savefig(me, figfile, pyfile, dpi, transparent, facecolor, edgecolor, orientation, istat, python)

class(pyplot), intent(inout) :: me !! pyplot handler
character(len=*), intent(in) :: figfile !! file name for the figure
Expand All @@ -1478,6 +1486,7 @@ subroutine savefig(me, figfile, pyfile, dpi, transparent, facecolor, edgecolor,
character(len=*), intent(in), optional :: edgecolor !! the colors of the figure rectangle
character(len=*), intent(in), optional :: orientation !! 'landscape' or 'portrait'
integer, intent (out), optional :: istat !! status output (0 means no problems)
character(len=*), intent(in),optional :: python !! python executable to use. (by default, this is 'python')

character(len=:),allocatable :: tmp !! for building the `savefig` arguments.

Expand Down Expand Up @@ -1510,7 +1519,7 @@ subroutine savefig(me, figfile, pyfile, dpi, transparent, facecolor, edgecolor,
deallocate(tmp)

!run it:
call me%execute(pyfile, istat=istat)
call me%execute(pyfile, istat=istat, python=python)

else
if (present(istat)) istat = -1
Expand All @@ -1526,11 +1535,12 @@ end subroutine savefig
!
! Shows the figure.

subroutine showfig(me, pyfile, istat)
subroutine showfig(me, pyfile, istat, python)

class(pyplot), intent(inout) :: me !! pyplot handler
character(len=*), intent(in), optional :: pyfile !! name of the Python script to generate
integer, intent (out), optional :: istat !! status output (0 means no problems)
character(len=*), intent(in),optional :: python !! python executable to use. (by default, this is 'python')

if (.not. allocated(me%str)) then

Expand All @@ -1553,7 +1563,7 @@ subroutine showfig(me, pyfile, istat)
call me%add_str('plt.show()')

!run it:
call me%execute(pyfile, istat=istat)
call me%execute(pyfile, istat=istat, python=python)

end if

Expand Down
2 changes: 1 addition & 1 deletion test/test.f90
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ program test
call plt%savefig('errorbar.png', &
pyfile='errorbar.py', &
dpi='200', &
transparent=.true.,istat=istat)
transparent=.true.,istat=istat, python='python')

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