Skip to content

Commit 9c98195

Browse files
committed
added wait option to execute_command_line
fixed for invalid escape sequence in the tests Fixes #53
1 parent 8eceb6f commit 9c98195

4 files changed

Lines changed: 20 additions & 11 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ The following example generates a plot of the sine function:
9494
9595
!plot it:
9696
call plt%initialize(grid=.true.,xlabel='angle (rad)',&
97-
title='Plot of $\sin(x)$',legend=.true.)
98-
call plt%add_plot(x,sx,label='$\sin(x)$',linestyle='b-o',markersize=5,linewidth=2)
97+
title='Plot of $\\sin(x)$',legend=.true.)
98+
call plt%add_plot(x,sx,label='$\\sin(x)$',linestyle='b-o',markersize=5,linewidth=2)
9999
call plt%savefig('sinx.png', pyfile='sinx.py')
100100
101101
end program test

src/pyplot_module.F90

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,25 +1371,34 @@ end subroutine matrix_to_string
13711371
! If user specifies a Python file name, then the file is kept, otherwise
13721372
! a temporary filename is used, and the file is deleted after it is used.
13731373

1374-
subroutine execute(me, pyfile, istat, python)
1374+
subroutine execute(me, pyfile, istat, python, wait)
13751375

13761376
class(pyplot), intent(inout) :: me !! pytplot handler
13771377
character(len=*), intent(in), optional :: pyfile !! name of the python script to generate
13781378
integer, intent (out),optional :: istat !! status output (0 means no problems)
13791379
character(len=*), intent(in),optional :: python !! python executable to use. (by default, this is 'python')
1380+
logical, intent(in),optional :: wait !! if true, will wait for the python process to
1381+
!! finish before continuing. (default is true).
13801382

13811383
integer :: iunit !! IO unit
13821384
character(len=:), allocatable :: file !! file name
13831385
logical :: scratch !! if a scratch file is to be used
13841386
integer :: iostat !! open/close status code
13851387
character(len=:), allocatable :: python_ !! python executable to use
1388+
logical :: wait_ !! whether to wait for the python process to finish
13861389

13871390
if (allocated(me%str)) then
13881391

13891392
if (present(istat)) istat = 0
13901393

13911394
scratch = (.not. present(pyfile))
13921395

1396+
if (present(wait)) then
1397+
wait_ = wait
1398+
else
1399+
wait_ = .true.
1400+
end if
1401+
13931402
!file name to use:
13941403
if (scratch) then
13951404
file = trim(tmp_file) !use the default
@@ -1431,9 +1440,9 @@ subroutine execute(me, pyfile, istat, python)
14311440
!run the file using python:
14321441
if (file(1:1)/='"') then
14331442
! if not already in quotes, should enclose in quotes
1434-
call execute_command_line(python_//' "'//file//'"')
1443+
call execute_command_line(python_//' "'//file//'"', wait=wait_)
14351444
else
1436-
call execute_command_line(python_//' '//file)
1445+
call execute_command_line(python_//' '//file, wait=wait_)
14371446
end if
14381447

14391448
if (scratch) then

test/date_test.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ program date_test
4040
title='date test',legend=.true.,axis_equal=.true.,&
4141
tight_layout=.true., &
4242
xaxis_date_fmt=xaxis_date_fmt, yaxis_date_fmt=yaxis_date_fmt)
43-
call plt%add_plot(x,sx,label='$\sin (x)$',linestyle='b-o',markersize=5,linewidth=2,istat=istat)
44-
call plt%add_plot(x,cx,label='$\cos (x)$',linestyle='r-o',markersize=5,linewidth=2,istat=istat)
45-
call plt%add_plot(x,tx,label='$\sin (x) \cos (x)$',linestyle='g-o',markersize=2,linewidth=1,istat=istat)
43+
call plt%add_plot(x,sx,label='$\\sin (x)$',linestyle='b-o',markersize=5,linewidth=2,istat=istat)
44+
call plt%add_plot(x,cx,label='$\\cos (x)$',linestyle='r-o',markersize=5,linewidth=2,istat=istat)
45+
call plt%add_plot(x,tx,label='$\\sin (x) \\cos (x)$',linestyle='g-o',markersize=2,linewidth=1,istat=istat)
4646
call plt%savefig(testdir//'datetest.png', pyfile=testdir//'datetest.py',&
4747
istat=istat)
4848

test/test.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ program test
6363
call plt%initialize(grid=.true.,xlabel='angle (rad)',figsize=[20,10],&
6464
title='plot test',legend=.true.,axis_equal=.true.,&
6565
tight_layout=.true.)
66-
call plt%add_plot(x,sx,label='$\sin (x)$',linestyle='b-o',markersize=5,linewidth=2,istat=istat)
67-
call plt%add_plot(x,cx,label='$\cos (x)$',linestyle='r-o',markersize=5,linewidth=2,istat=istat)
68-
call plt%add_plot(x,tx,label='$\sin (x) \cos (x)$',linestyle='g-o',markersize=2,linewidth=1,istat=istat)
66+
call plt%add_plot(x,sx,label='$\\sin (x)$',linestyle='b-o',markersize=5,linewidth=2,istat=istat)
67+
call plt%add_plot(x,cx,label='$\\cos (x)$',linestyle='r-o',markersize=5,linewidth=2,istat=istat)
68+
call plt%add_plot(x,tx,label='$\\sin (x) \\cos (x)$',linestyle='g-o',markersize=2,linewidth=1,istat=istat)
6969
call plt%savefig(testdir//'plottest.png', pyfile=testdir//'plottest.py',&
7070
istat=istat)
7171

0 commit comments

Comments
 (0)