6 module function mp_get_command(this) result(x)
8 class(multiplot),
intent(in) :: this
9 character(len = :),
allocatable :: x
12 type(string_builder) :: str
13 integer(int32) :: i, j, m, n
14 class(plot),
pointer :: ptr
18 m = this%get_row_count()
19 n = this%get_column_count()
22 call str%append(
"set multiplot layout ")
23 call str%append(to_string(m))
25 call str%append(to_string(n))
26 call str%append(
" columnsfirst")
27 if (this%is_title_defined())
then
28 call str%append(
" title ")
30 call str%append(this%get_title())
33 call str%append(new_line(
'a'))
39 call str%append(new_line(
'a'))
40 call str%append(ptr%get_command_string())
45 call str%append(new_line(
'a'))
46 call str%append(
"unset multiplot")
49 x = char(str%to_string())
53 module subroutine mp_init(this, m, n, term, err)
55 class(multiplot),
intent(inout) :: this
56 integer(int32),
intent(in) :: m, n
57 integer(int32),
intent(in),
optional :: term
58 class(errors),
intent(inout),
optional,
target :: err
61 integer(int32) :: flag, t, i
62 class(errors),
pointer :: errmgr
63 type(errors),
target :: deferr
64 type(wxt_terminal),
pointer :: wxt
65 type(windows_terminal),
pointer :: win
66 type(qt_terminal),
pointer :: qt
67 type(png_terminal),
pointer :: png
68 type(latex_terminal),
pointer :: latex
71 if (
present(err))
then
76 if (
present(term))
then
79 t = gnuplot_terminal_wxt
83 call this%m_plots%clear()
92 call this%m_plots%push(i)
96 if (
associated(this%m_terminal))
deallocate(this%m_terminal)
98 case (gnuplot_terminal_png)
99 allocate(png, stat = flag)
100 this%m_terminal => png
101 case (gnuplot_terminal_qt)
102 allocate(qt, stat = flag)
103 this%m_terminal => qt
104 case (gnuplot_terminal_win32)
105 allocate(win, stat = flag)
106 this%m_terminal => win
107 case (gnuplot_terminal_latex)
108 allocate(latex, stat = flag)
109 this%m_terminal => latex
111 allocate(wxt, stat = flag)
112 this%m_terminal => wxt
117 call errmgr%report_error(
"mp_init", &
118 "Insufficient memory available.", plot_out_of_memory_error)
124 module subroutine mp_clean(this)
125 type(multiplot),
intent(inout) :: this
126 if (
associated(this%m_terminal))
deallocate(this%m_terminal)
127 nullify(this%m_terminal)
131 pure module function mp_get_rows(this) result(x)
132 class(multiplot),
intent(in) :: this
138 pure module function mp_get_cols(this) result(x)
139 class(multiplot),
intent(in) :: this
145 pure module function mp_get_count(this) result(x)
146 class(multiplot),
intent(in) :: this
148 x = this%m_plots%count()
152 module function mp_get_title(this) result(x)
153 class(multiplot),
intent(in) :: this
154 character(len = :),
allocatable :: x
159 module subroutine mp_set_title(this, x)
161 class(multiplot),
intent(inout) :: this
162 character(len = *),
intent(in) :: x
168 n = min(len(x), plotdata_max_name_length)
171 this%m_title(1:n) = x(1:n)
172 this%m_hasTitle = .true.
174 this%m_hasTitle = .false.
179 module subroutine mp_draw(this, persist, err)
181 class(multiplot),
intent(in) :: this
182 logical,
intent(in),
optional :: persist
183 class(errors),
intent(inout),
optional,
target :: err
186 character(len = *),
parameter :: fname =
"temp_gnuplot_file.plt"
190 integer(int32) :: fid, flag
191 class(errors),
pointer :: errmgr
192 type(errors),
target :: deferr
193 character(len = 256) :: errmsg
194 class(terminal),
pointer :: term
197 if (
present(persist))
then
202 if (
present(err))
then
207 term => this%get_terminal()
210 open(newunit = fid, file = fname, iostat = flag)
213 "The file could not be opened/created. Error code ", flag, &
215 call errmgr%report_error(
"mp_draw", trim(errmsg), &
216 plot_gnuplot_file_error)
219 write(fid,
'(A)') term%get_command_string()
220 write(fid,
'(A)') new_line(
'a')
221 write(fid,
'(A)') this%get_command_string()
226 call execute_command_line(
"gnuplot --persist " // fname)
228 call execute_command_line(
"gnuplot " // fname)
232 open(newunit = fid, file = fname)
233 close(fid, status =
"delete")
239 module function mp_get(this, i, j) result(x)
241 class(multiplot),
intent(in) :: this
242 integer(int32),
intent(in) :: i, j
243 class(plot),
pointer :: x
246 class(*),
pointer :: item
247 integer(int32) :: ind
250 ind = this%m_rows * (j - 1) + i
251 item => this%m_plots%get(ind)
261 module subroutine mp_set(this, i, j, x)
263 class(multiplot),
intent(inout) :: this
264 integer(int32),
intent(in) :: i, j
265 class(plot),
intent(in) :: x
268 integer(int32) :: ind
271 ind = this%m_rows * (j - 1) + i
272 call this%m_plots%set(ind, x)
276 pure module function mp_has_title(this) result(x)
277 class(multiplot),
intent(in) :: this
283 module function mp_get_term(this) result(x)
284 class(multiplot),
intent(in) :: this
285 class(terminal),
pointer :: x
290 module subroutine mp_save(this, fname, err)
292 class(multiplot),
intent(in) :: this
293 character(len = *),
intent(in) :: fname
294 class(errors),
intent(inout),
optional,
target :: err
297 integer(int32) :: fid, flag
298 class(errors),
pointer :: errmgr
299 type(errors),
target :: deferr
300 character(len = 256) :: errmsg
301 class(terminal),
pointer :: term
304 if (
present(err))
then
309 term => this%get_terminal()
312 open(newunit = fid, file = fname, iostat = flag)
315 "The file could not be opened/created. Error code ", flag, &
317 call errmgr%report_error(
"mp_save", trim(errmsg), &
318 plot_gnuplot_file_error)
321 write(fid,
'(A)') term%get_command_string()
322 write(fid,
'(A)') new_line(
'a')
323 write(fid,
'(A)') this%get_command_string()
330 module function mp_get_font(this) result(x)
331 class(multiplot),
intent(in) :: this
332 character(len = :),
allocatable :: x
333 class(terminal),
pointer :: term
334 term => this%get_terminal()
335 x = term%get_font_name()
339 module subroutine mp_set_font(this, x)
340 class(multiplot),
intent(inout) :: this
341 character(len = *),
intent(in) :: x
342 class(terminal),
pointer :: term
343 term => this%get_terminal()
344 call term%set_font_name(x)
348 module function mp_get_font_size(this) result(x)
349 class(multiplot),
intent(in) :: this
351 class(terminal),
pointer :: term
352 term => this%get_terminal()
353 x = term%get_font_size()
357 module subroutine mp_set_font_size(this, x)
358 class(multiplot),
intent(inout) :: this
359 integer(int32),
intent(in) :: x
360 class(terminal),
pointer :: term
361 term => this%get_terminal()
362 call term%set_font_size(x)