@@ -107,14 +107,15 @@ subroutine initialize(me, grid, xlabel, ylabel, title, legend, use_numpy, figsiz
107
107
integer , intent (in ), optional :: xtick_labelsize ! ! size of x axis tick lables
108
108
integer , intent (in ), optional :: ytick_labelsize ! ! size of y axis tick lables
109
109
integer , intent (in ), optional :: legend_fontsize ! ! size of legend font
110
- character (len= max_int_len) :: width_str ! ! figure width dummy string
111
- character (len= max_int_len) :: height_str ! ! figure height dummy string
112
- character (len= max_int_len) :: font_size_str ! ! font size dummy string
113
- character (len= max_int_len) :: axes_labelsize_str ! ! size of axis labels dummy string
114
- character (len= max_int_len) :: xtick_labelsize_str ! ! sise of x axis tick labels dummy string
115
- character (len= max_int_len) :: ytick_labelsize_str ! ! sise of x axis tick labels dummy string
116
- character (len= max_int_len) :: legend_fontsize_str ! ! sise of legend font dummy string
117
- character (len=* ), parameter :: default_font_size_str = ' 10' ! ! the default font size for plots
110
+
111
+ character (len= max_int_len) :: width_str ! ! figure width dummy string
112
+ character (len= max_int_len) :: height_str ! ! figure height dummy string
113
+ character (len= max_int_len) :: font_size_str ! ! font size dummy string
114
+ character (len= max_int_len) :: axes_labelsize_str ! ! size of axis labels dummy string
115
+ character (len= max_int_len) :: xtick_labelsize_str ! ! sise of x axis tick labels dummy string
116
+ character (len= max_int_len) :: ytick_labelsize_str ! ! sise of x axis tick labels dummy string
117
+ character (len= max_int_len) :: legend_fontsize_str ! ! sise of legend font dummy string
118
+ character (len=* ), parameter :: default_font_size_str = ' 10' ! ! the default font size for plots
118
119
119
120
call me% destroy()
120
121
@@ -191,12 +192,13 @@ subroutine add_plot(me, x, y, label, linestyle, markersize, linewidth)
191
192
character (len=* ), intent (in ) :: linestyle ! ! style of the plot line
192
193
integer , intent (in ), optional :: markersize ! ! size of the plot markers
193
194
integer , intent (in ), optional :: linewidth ! ! width of the plot line
194
- character (len= :), allocatable :: xstr ! ! x values strinfied
195
- character (len= :), allocatable :: ystr ! ! y values strinfied
196
- character (len= max_int_len) :: imark ! ! actual markers size
197
- character (len= max_int_len) :: iline ! ! actual line width
198
- character (len=* ), parameter :: xname = ' x' ! ! x variable name for script
199
- character (len=* ), parameter :: yname = ' y' ! ! y variable name for script
195
+
196
+ character (len= :), allocatable :: xstr ! ! x values strinfied
197
+ character (len= :), allocatable :: ystr ! ! y values strinfied
198
+ character (len= max_int_len) :: imark ! ! actual markers size
199
+ character (len= max_int_len) :: iline ! ! actual line width
200
+ character (len=* ), parameter :: xname = ' x' ! ! x variable name for script
201
+ character (len=* ), parameter :: yname = ' y' ! ! y variable name for script
200
202
201
203
if (allocated (me% str)) then
202
204
@@ -244,15 +246,16 @@ subroutine add_bar(me, left, height, label, width, bottom, color)
244
246
real (wp), dimension (:), intent (in ), optional :: width ! ! width values
245
247
real (wp), dimension (:), intent (in ), optional :: bottom ! ! bottom values
246
248
character (len=* ), intent (in ), optional :: color ! ! plot color
247
- character (len= :), allocatable :: xstr ! ! x axis values stringified
248
- character (len= :), allocatable :: ystr ! ! y axis values stringified
249
- character (len= :), allocatable :: wstr ! ! width values stringified
250
- character (len= :), allocatable :: bstr ! ! bottom values stringified
251
- character (len= :), allocatable :: plt_str ! ! plot string
252
- character (len=* ), parameter :: xname = ' x' ! ! x axis name
253
- character (len=* ), parameter :: yname = ' y' ! ! y axis name
254
- character (len=* ), parameter :: wname = ' w' ! ! width name
255
- character (len=* ), parameter :: bname = ' b' ! ! bottom name
249
+
250
+ character (len= :), allocatable :: xstr ! ! x axis values stringified
251
+ character (len= :), allocatable :: ystr ! ! y axis values stringified
252
+ character (len= :), allocatable :: wstr ! ! width values stringified
253
+ character (len= :), allocatable :: bstr ! ! bottom values stringified
254
+ character (len= :), allocatable :: plt_str ! ! plot string
255
+ character (len=* ), parameter :: xname = ' x' ! ! x axis name
256
+ character (len=* ), parameter :: yname = ' y' ! ! y axis name
257
+ character (len=* ), parameter :: wname = ' w' ! ! width name
258
+ character (len=* ), parameter :: bname = ' b' ! ! bottom name
256
259
257
260
if (allocated (me% str)) then
258
261
@@ -341,9 +344,10 @@ subroutine vec_to_string(v, str, use_numpy)
341
344
real (wp), dimension (:), intent (in ) :: v ! ! real values
342
345
character (len= :), allocatable , intent (out ) :: str ! ! real values stringified
343
346
logical , intent (in ) :: use_numpy ! ! activate numpy python module usage
344
- integer :: i ! ! counter
345
- integer :: istat ! ! IO status
346
- character (len= max_real_len) :: tmp ! ! dummy string
347
+
348
+ integer :: i ! ! counter
349
+ integer :: istat ! ! IO status
350
+ character (len= max_real_len) :: tmp ! ! dummy string
347
351
348
352
str = ' ['
349
353
do i= 1 , size (v)
@@ -362,37 +366,54 @@ end subroutine vec_to_string
362
366
363
367
! *****************************************************************************************
364
368
! > author: Jacob Williams
369
+ ! date: 8/16/2015
365
370
!
366
371
! Write the buffer to a file, and then execute it with Python.
372
+ !
373
+ ! If user specifies a Python file name, then the file is kept, otherwise
374
+ ! a temporary filename is used, and the file is deleted after it is used.
367
375
368
376
subroutine execute (me , pyfile )
369
377
370
378
class(pyplot), intent (inout ) :: me ! ! pytplot handler
371
379
character (len=* ), intent (in ), optional :: pyfile ! ! name of the python script to generate
372
- integer :: istat ! ! IO status
373
- integer :: iunit ! ! IO unit
374
- character (len= :), allocatable :: file ! ! file name
380
+
381
+ integer :: istat ! ! IO status
382
+ integer :: iunit ! ! IO unit
383
+ character (len= :), allocatable :: file ! ! file name
384
+ logical :: scratch ! ! if a scratch file is to be used
375
385
376
386
if (allocated (me% str)) then
377
-
378
- ! file name for python script:
379
- if ( present (pyfile)) then
380
- file = trim (pyfile) ! use the user-specified name
381
- else
387
+
388
+ scratch = ( .not. present (pyfile))
389
+
390
+ ! file name to use:
391
+ if (scratch) then
382
392
file = trim (tmp_file) ! use the default
393
+ else
394
+ file = trim (pyfile) ! use the user-specified name
383
395
end if
384
-
385
- ! generate the file:
396
+
397
+ ! open the file:
386
398
open (newunit= iunit, file= file, status= ' REPLACE' , iostat= istat)
387
- if (istat/= 0 ) error stop ' Error creating python script.'
399
+ if (istat/= 0 ) error stop ' Error opening file.'
400
+
401
+ ! write to the file:
388
402
write (iunit, ' (A)' ) me% str
389
- close (iunit, iostat= istat)
390
403
391
404
! run the file using python:
392
405
call execute_command_line(python_exe// ' ' // file)
393
-
406
+
407
+ ! close the file:
408
+ if (scratch) then
409
+ close (iunit, status= ' DELETE' , iostat= istat)
410
+ else
411
+ close (iunit, iostat= istat)
412
+ end if
413
+ if (istat/= 0 ) error stop ' Error closing file.'
414
+
394
415
! cleanup:
395
- deallocate (file)
416
+ if ( allocated (file)) deallocate (file)
396
417
397
418
end if
398
419
0 commit comments