subroutine execute(me, pyfile)
class(pyplot), intent(inout) :: me !! pytplot handler
character(len=*), intent(in), optional :: pyfile !! name of the python script to generate
integer :: istat !! IO status
integer :: iunit !! IO unit
character(len=:), allocatable :: file !! file name
logical :: scratch !! if a scratch file is to be used
if (allocated(me%str)) then
scratch = (.not. present(pyfile))
!file name to use:
if (scratch) then
file = trim(tmp_file) !use the default
else
file = trim(pyfile) !use the user-specified name
end if
!open the file:
open(newunit=iunit, file=file, status='REPLACE', iostat=istat)
if (istat/=0) error stop 'Error opening file.'
!write to the file:
write(iunit, '(A)') me%str
!to ensure that the file is there for the next command line call:
flush(iunit)
!run the file using python:
call execute_command_line(python_exe//' '//file)
!close the file:
if (scratch) then
close(iunit, status='DELETE', iostat=istat)
else
close(iunit, iostat=istat)
end if
if (istat/=0) error stop 'Error closing file.'
!cleanup:
if (allocated(file)) deallocate(file)
end if
end subroutine execute