Skip to content

Commit c9983ce

Browse files
committed
restored some of my spacing conventions.
1 parent e52ca51 commit c9983ce

File tree

1 file changed

+122
-68
lines changed

1 file changed

+122
-68
lines changed

src/pyplot_module.f90

Lines changed: 122 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,99 @@
1+
!*****************************************************************************************
12
!> author: Jacob Williams
23
! date: 4/14/2015
34
! license: BSD
45
!
5-
!# DESCRIPTION
66
! For making simple x-y plots from Fortran.
77
! It works by generating a Python script and executing it.
88
!
9-
!# SEE ALSO
9+
!# See also
1010
! * Inspired by: [EasyPlot](https://pypi.python.org/pypi/EasyPlot)
11-
module pyplot_module
1211

13-
use, intrinsic :: iso_fortran_env, only : real64
12+
module pyplot_module
1413

15-
implicit none
14+
use, intrinsic :: iso_fortran_env, only : real64
1615

17-
private
16+
implicit none
1817

19-
integer, parameter, private :: wp = real64 !! Default real kind [8 bytes].
20-
21-
character(len=*), parameter :: tmp_file = 'pyplot_module_temp_1234567890.py' !! Default name of the temporary file
22-
!! (this can also be user-specified).
23-
24-
character(len=*), parameter :: python_exe ='python' !! The python executable name.
25-
character(len=*), parameter :: int_fmt = '(I10)' !! integer format string
26-
integer, parameter :: max_int_len = 10 !! max string length for integers
27-
character(len=*), parameter :: real_fmt = '(E30.16)' !! real number format string
28-
integer, parameter :: max_real_len = 30 !! max string length for reals
18+
private
2919

20+
integer, parameter, private :: wp = real64 !! Default real kind [8 bytes].
21+
22+
character(len=*), parameter :: tmp_file = 'pyplot_module_temp_1234567890.py' !! Default name of the temporary file
23+
!! (this can also be user-specified).
24+
25+
character(len=*), parameter :: python_exe ='python' !! The python executable name.
26+
character(len=*), parameter :: int_fmt = '(I10)' !! integer format string
27+
integer, parameter :: max_int_len = 10 !! max string length for integers
28+
character(len=*), parameter :: real_fmt = '(E30.16)' !! real number format string
29+
integer, parameter :: max_real_len = 30 !! max string length for reals
30+
31+
type, public :: pyplot
32+
33+
!! The main pyplot class.
34+
35+
private
36+
37+
character(len=:), allocatable :: str !! string buffer
38+
39+
logical :: show_legend = .false. !! show legend into plot
40+
logical :: use_numpy = .true. !! use numpy python module
41+
42+
contains
43+
44+
! public methods
45+
procedure, public :: initialize !! initialize pyplot instance
46+
procedure, public :: add_plot !! add a plot to pyplot instance
47+
procedure, public :: add_bar !! add a barplot to pyplot instance
48+
procedure, public :: savefig !! save plots of pyplot instance
49+
procedure, public :: destroy !! destroy pyplot instance
50+
51+
! private methods
52+
procedure :: execute !! execute pyplot commands
53+
procedure :: add_str !! add string to pytplot instance buffer
54+
55+
end type pyplot
56+
57+
contains
58+
!*****************************************************************************************
59+
60+
!*****************************************************************************************
3061
!> author: Jacob Williams
3162
!
32-
! The main pyplot class.
33-
type, public :: pyplot
34-
private
63+
! Destructor.
3564

36-
character(len=:), allocatable :: str !! string buffer
37-
38-
logical :: show_legend = .false. !! show legend into plot
39-
logical :: use_numpy = .true. !! use numpy python module
40-
contains
41-
! public methods
42-
procedure, public :: initialize !! initialize pyplot instance
43-
procedure, public :: add_plot !! add a plot to pyplot instance
44-
procedure, public :: add_bar !! add a barplot to pyplot instance
45-
procedure, public :: savefig !! save plots of pyplot instance
46-
procedure, public :: destroy !! destroy pyplot instance
47-
! private methods
48-
procedure :: execute !! execute pyplot commands
49-
procedure :: add_str !! add string to pytplot instance buffer
50-
end type pyplot
51-
contains
52-
53-
!> author: Jacob Williams
54-
!
55-
! Destructor
5665
subroutine destroy(me)
66+
5767
class(pyplot),intent(inout) :: me !! pyplot handler
5868

5969
if (allocated(me%str)) deallocate(me%str)
70+
6071
end subroutine destroy
72+
!*****************************************************************************************
73+
74+
!*****************************************************************************************
75+
!> author: Jacob Williams
76+
!
77+
! Add a string to the buffer.
6178

62-
!> author: Jacob Williams
63-
!
64-
! Add a string to the buffer.
6579
subroutine add_str(me,str)
80+
6681
class(pyplot), intent(inout) :: me !! pyplot handler
6782
character(len=*), intent(in) :: str !! str to be added to pyplot handler buffer
6883

6984
me%str = me%str//str//new_line(' ')
85+
7086
end subroutine add_str
87+
!*****************************************************************************************
88+
89+
!*****************************************************************************************
90+
!> author: Jacob Williams
91+
!
92+
! Initialize a plot
7193

72-
!> author: Jacob Williams
73-
!
74-
! Initialize a plot
7594
subroutine initialize(me, grid, xlabel, ylabel, title, legend, use_numpy, figsize, &
7695
font_size, axes_labelsize, xtick_labelsize, ytick_labelsize, legend_fontsize)
96+
7797
class(pyplot), intent(inout) :: me !! pyplot handler
7898
logical, intent(in), optional :: grid !! activate grid drawing
7999
character(len=*), intent(in), optional :: xlabel !! label of x axis
@@ -153,12 +173,17 @@ subroutine initialize(me, grid, xlabel, ylabel, title, legend, use_numpy, figsiz
153173
if (present(title)) call me%add_str('ax.set_title("' //trim(title) //'")')
154174

155175
call me%add_str('')
176+
156177
end subroutine initialize
178+
!*****************************************************************************************
179+
180+
!*****************************************************************************************
181+
!> author: Jacob Williams
182+
!
183+
! Add an x,y plot.
157184

158-
!> author: Jacob Williams
159-
!
160-
! Add an x,y plot.
161185
subroutine add_plot(me, x, y, label, linestyle, markersize, linewidth)
186+
162187
class(pyplot), intent (inout) :: me !! pyplot handler
163188
real(wp), dimension(:), intent (in) :: x !! x values
164189
real(wp), dimension(:), intent (in) :: y !! y values
@@ -201,12 +226,17 @@ subroutine add_plot(me, x, y, label, linestyle, markersize, linewidth)
201226
else
202227
error stop 'Error in add_plot: pyplot class not properly initialized.'
203228
end if
229+
204230
end subroutine add_plot
231+
!*****************************************************************************************
205232

206-
!> author: Jacob Williams
207-
!
208-
! Add a bar plot.
233+
!*****************************************************************************************
234+
!> author: Jacob Williams
235+
!
236+
! Add a bar plot.
237+
209238
subroutine add_bar(me, left, height, label, width, bottom, color)
239+
210240
class(pyplot), intent(inout) :: me !! pyplot handler
211241
real(wp), dimension(:), intent(in) :: left !! left bar values
212242
real(wp), dimension(:), intent(in) :: height !! height bar values
@@ -257,12 +287,16 @@ subroutine add_bar(me, left, height, label, width, bottom, color)
257287
end if
258288

259289
end subroutine add_bar
290+
!*****************************************************************************************
291+
292+
!*****************************************************************************************
293+
!> author: Jacob Williams
294+
!
295+
! Integer to string, specifying the default value if
296+
! the optional argument is not present.
260297

261-
!> author: Jacob Williams
262-
!
263-
! Integer to string, specifying the default value if
264-
! the optional argument is not present.
265298
subroutine optional_int_to_string(int_value, string_value, default_value)
299+
266300
integer, intent(in), optional :: int_value !! integer value
267301
character(len=*), intent(out) :: string_value !! integer value stringified
268302
character(len=*), intent(in) :: default_value !! default integer value
@@ -274,10 +308,13 @@ subroutine optional_int_to_string(int_value, string_value, default_value)
274308
end if
275309

276310
end subroutine optional_int_to_string
311+
!*****************************************************************************************
312+
313+
!*****************************************************************************************
314+
!> author: Jacob Williams
315+
!
316+
! Integer to string conversion.
277317

278-
!> author: Jacob Williams
279-
!
280-
! Integer to string conversion.
281318
subroutine integer_to_string(i, s)
282319
integer, intent(in), optional :: i !! integer value
283320
character(len=*), intent(out) :: s !! integer value stringified
@@ -292,11 +329,15 @@ subroutine integer_to_string(i, s)
292329
end if
293330

294331
end subroutine integer_to_string
332+
!*****************************************************************************************
333+
334+
!*****************************************************************************************
335+
!> author: Jacob Williams
336+
!
337+
! Real vector to string.
295338

296-
!> author: Jacob Williams
297-
!
298-
! Real vector to string.
299339
subroutine vec_to_string(v, str, use_numpy)
340+
300341
real(wp), dimension(:), intent(in) :: v !! real values
301342
character(len=:), allocatable, intent(out) :: str !! real values stringified
302343
logical, intent(in) :: use_numpy !! activate numpy python module usage
@@ -317,11 +358,15 @@ subroutine vec_to_string(v, str, use_numpy)
317358
if (use_numpy) str = 'np.array('//str//')'
318359

319360
end subroutine vec_to_string
361+
!*****************************************************************************************
362+
363+
!*****************************************************************************************
364+
!> author: Jacob Williams
365+
!
366+
! Write the buffer to a file, and then execute it with Python.
320367

321-
!> author: Jacob Williams
322-
!
323-
! Write the buffer to a file, and then execute it with Python.
324368
subroutine execute(me, pyfile)
369+
325370
class(pyplot), intent(inout) :: me !! pytplot handler
326371
character(len=*), intent(in), optional :: pyfile !! name of the python script to generate
327372
integer :: istat !! IO status
@@ -350,12 +395,17 @@ subroutine execute(me, pyfile)
350395
deallocate(file)
351396

352397
end if
398+
353399
end subroutine execute
400+
!*****************************************************************************************
401+
402+
!*****************************************************************************************
403+
!> author: Jacob Williams
404+
!
405+
! Save the figure.
354406

355-
!> author: Jacob Williams
356-
!
357-
! Save the figure.
358407
subroutine savefig(me, figfile, pyfile)
408+
359409
class(pyplot), intent(inout) :: me !! pyplot handler
360410
character(len=*), intent(in) :: figfile !! file name for the figure
361411
character(len=*), intent(in), optional :: pyfile !! name of the Python script to generate
@@ -377,4 +427,8 @@ subroutine savefig(me, figfile, pyfile)
377427
end if
378428

379429
end subroutine savefig
380-
end module pyplot_module
430+
!*****************************************************************************************
431+
432+
!*****************************************************************************************
433+
end module pyplot_module
434+
!*****************************************************************************************

0 commit comments

Comments
 (0)