6 module subroutine plt_clean_up(this)
7 class(plot),
intent(inout) :: this
8 if (
associated(this%m_terminal))
then
9 deallocate(this%m_terminal)
10 nullify(this%m_terminal)
12 if (
associated(this%m_legend))
then
13 deallocate(this%m_legend)
14 nullify(this%m_legend)
16 if (
associated(this%m_colormap))
then
17 deallocate(this%m_colormap)
18 nullify(this%m_colormap)
23 module subroutine plt_init(this, term, fname, err)
25 class(plot),
intent(inout) :: this
26 integer(int32),
intent(in),
optional :: term
27 character(len = *),
intent(in),
optional :: fname
28 class(errors),
intent(inout),
optional,
target :: err
31 integer(int32) :: flag, t
32 class(errors),
pointer :: errmgr
33 type(errors),
target :: deferr
34 type(wxt_terminal),
pointer :: wxt
35 type(windows_terminal),
pointer :: win
36 type(qt_terminal),
pointer :: qt
37 type(png_terminal),
pointer :: png
38 type(latex_terminal),
pointer :: latex
41 if (
present(err))
then
46 if (
present(term))
then
49 t = gnuplot_terminal_wxt
54 if (
associated(this%m_terminal))
deallocate(this%m_terminal)
56 case (gnuplot_terminal_png)
57 allocate(png, stat = flag)
58 if (
present(fname))
call png%set_filename(fname)
59 this%m_terminal => png
60 case (gnuplot_terminal_qt)
61 allocate(qt, stat = flag)
63 case (gnuplot_terminal_win32)
64 allocate(win, stat = flag)
65 this%m_terminal => win
66 case (gnuplot_terminal_latex)
67 allocate(latex, stat = flag)
68 if (
present(fname))
call latex%set_filename(fname)
69 this%m_terminal => latex
71 allocate(wxt, stat = flag)
72 this%m_terminal => wxt
76 nullify(this%m_colormap)
78 if (flag == 0 .and. .not.
associated(this%m_legend))
then
79 allocate(this%m_legend, stat = flag)
84 call errmgr%report_error(
"plt_init", &
85 "Insufficient memory available.", plot_out_of_memory_error)
91 module function plt_get_title(this) result(txt)
92 class(plot),
intent(in) :: this
93 character(len = :),
allocatable :: txt
95 n = len_trim(this%m_title)
96 allocate(
character(len = n) :: txt)
97 txt = trim(this%m_title)
101 module subroutine plt_set_title(this, txt)
102 class(plot),
intent(inout) :: this
103 character(len = *),
intent(in) :: txt
105 n = min(len_trim(txt), plotdata_max_name_length)
108 this%m_title(1:n) = txt(1:n)
109 this%m_hasTitle = .true.
111 this%m_hasTitle = .false.
116 pure module function plt_has_title(this) result(x)
117 class(plot),
intent(in) :: this
123 module function plt_get_legend(this) result(x)
124 class(plot),
intent(in) :: this
125 type(legend),
pointer :: x
130 pure module function plt_get_count(this) result(x)
131 class(plot),
intent(in) :: this
133 x = this%m_data%count()
137 module subroutine plt_push_data(this, x, err)
139 class(plot),
intent(inout) :: this
140 class(plot_data),
intent(inout) :: x
141 class(errors),
intent(inout),
optional,
target :: err
142 class(legend),
pointer :: lgnd
146 class is (plot_data_colored)
147 call x%set_color_index(this%m_colorIndex)
148 if (this%m_colorIndex ==
size(color_list))
then
149 this%m_colorIndex = 1
151 this%m_colorIndex = this%m_colorIndex + 1
156 call this%m_data%push(x, err = err)
160 module subroutine plt_pop_data(this)
162 class(plot),
intent(inout) :: this
163 class(legend),
pointer :: lgnd
166 call this%m_data%pop()
167 if (this%m_data%count() < 2)
then
168 lgnd => this%get_legend()
169 call lgnd%set_is_visible(.false.)
174 module subroutine plt_clear_all(this)
176 class(plot),
intent(inout) :: this
179 this%m_colorIndex = 1
180 call this%m_data%clear()
184 module function plt_get(this, i) result(x)
186 class(plot),
intent(in) :: this
187 integer(int32),
intent(in) :: i
188 class(plot_data),
pointer :: x
191 class(*),
pointer :: item
194 item => this%m_data%get(i)
205 module subroutine plt_set(this, i, x)
206 class(plot),
intent(inout) :: this
207 integer(int32),
intent(in) :: i
208 class(plot_data),
intent(in) :: x
209 call this%m_data%set(i, x)
213 module function plt_get_term(this) result(x)
214 class(plot),
intent(in) :: this
215 class(terminal),
pointer :: x
220 pure module function plt_get_show_grid(this) result(x)
221 class(plot),
intent(in) :: this
227 module subroutine plt_set_show_grid(this, x)
228 class(plot),
intent(inout) :: this
229 logical,
intent(in) :: x
234 module subroutine plt_draw(this, persist, err)
236 class(plot),
intent(in) :: this
237 logical,
intent(in),
optional :: persist
238 class(errors),
intent(inout),
optional,
target :: err
241 character(len = *),
parameter :: fname =
"temp_gnuplot_file.plt"
245 integer(int32) :: fid, flag
246 class(errors),
pointer :: errmgr
247 type(errors),
target :: deferr
248 character(len = 256) :: errmsg
249 class(terminal),
pointer :: term
252 if (
present(persist))
then
257 if (
present(err))
then
262 term => this%get_terminal()
265 open(newunit = fid, file = fname, iostat = flag)
268 "The file could not be opened/created. Error code ", flag, &
270 call errmgr%report_error(
"plt_draw", trim(errmsg), &
271 plot_gnuplot_file_error)
274 write(fid,
'(A)') term%get_command_string()
275 write(fid,
'(A)') new_line(
'a')
276 write(fid,
'(A)') this%get_command_string()
281 call execute_command_line(
"gnuplot --persist " // fname)
283 call execute_command_line(
"gnuplot " // fname)
287 open(newunit = fid, file = fname)
288 close(fid, status =
"delete")
294 module subroutine plt_save(this, fname, err)
296 class(plot),
intent(in) :: this
297 character(len = *),
intent(in) :: fname
298 class(errors),
intent(inout),
optional,
target :: err
301 integer(int32) :: fid, flag
302 class(errors),
pointer :: errmgr
303 type(errors),
target :: deferr
304 character(len = 256) :: errmsg
305 class(terminal),
pointer :: term
308 if (
present(err))
then
313 term => this%get_terminal()
316 open(newunit = fid, file = fname, iostat = flag)
319 "The file could not be opened/created. Error code ", flag, &
321 call errmgr%report_error(
"plt_save", trim(errmsg), &
322 plot_gnuplot_file_error)
325 write(fid,
'(A)') term%get_command_string()
326 write(fid,
'(A)') new_line(
'a')
327 write(fid,
'(A)') this%get_command_string()
334 module function plt_get_font(this) result(x)
335 class(plot),
intent(in) :: this
336 character(len = :),
allocatable :: x
337 class(terminal),
pointer :: term
338 term => this%get_terminal()
339 x = term%get_font_name()
343 module subroutine plt_set_font(this, x)
344 class(plot),
intent(inout) :: this
345 character(len = *),
intent(in) :: x
346 class(terminal),
pointer :: term
347 term => this%get_terminal()
348 call term%set_font_name(x)
352 module function plt_get_font_size(this) result(x)
353 class(plot),
intent(in) :: this
355 class(terminal),
pointer :: term
356 term => this%get_terminal()
357 x = term%get_font_size()
361 module subroutine plt_set_font_size(this, x)
362 class(plot),
intent(inout) :: this
363 integer(int32),
intent(in) :: x
364 class(terminal),
pointer :: term
365 term => this%get_terminal()
366 call term%set_font_size(x)
370 pure module function plt_get_tics_in(this) result(x)
371 class(plot),
intent(in) :: this
377 module subroutine plt_set_tics_in(this, x)
378 class(plot),
intent(inout) :: this
379 logical,
intent(in) :: x
384 pure module function plt_get_draw_border(this) result(x)
385 class(plot),
intent(in) :: this
387 x = this%m_drawBorder
391 module subroutine plt_set_draw_border(this, x)
392 class(plot),
intent(inout) :: this
393 logical,
intent(in) :: x
394 this%m_drawBorder = x
400 module subroutine plt_push_label(this, lbl, err)
402 class(plot),
intent(inout) :: this
403 class(plot_label),
intent(in) :: lbl
404 class(errors),
intent(inout),
optional,
target :: err
407 call this%m_labels%push(lbl, err = err)
411 module subroutine plt_pop_label(this)
412 class(plot),
intent(inout) :: this
413 call this%m_labels%pop()
417 module function plt_get_label(this, i) result(x)
419 class(plot),
intent(in) :: this
420 integer(int32),
intent(in) :: i
421 class(plot_label),
pointer :: x
424 class(*),
pointer :: item
427 item => this%m_labels%get(i)
429 class is (plot_label)
437 module subroutine plt_set_label(this, i, x)
438 class(plot),
intent(inout) :: this
439 integer(int32),
intent(in) :: i
440 class(plot_label),
intent(in) :: x
441 call this%m_labels%set(i, x)
445 pure module function plt_get_label_count(this) result(x)
446 class(plot),
intent(in) :: this
448 x = this%m_labels%count()
452 module subroutine plt_clear_labels(this)
453 class(plot),
intent(inout) :: this
454 call this%m_labels%clear()
460 pure module function plt_get_axis_equal(this) result(rst)
461 class(plot),
intent(in) :: this
463 rst = this%m_axisEqual
467 module subroutine plt_set_axis_equal(this, x)
468 class(plot),
intent(inout) :: this
469 logical,
intent(in) :: x
476 module function plt_get_colormap(this) result(x)
477 class(plot),
intent(in) :: this
478 class(colormap),
pointer :: x
483 module subroutine plt_set_colormap(this, x, err)
485 class(plot),
intent(inout) :: this
486 class(colormap),
intent(in) :: x
487 class(errors),
intent(inout),
optional,
target :: err
490 integer(int32) :: flag
491 class(errors),
pointer :: errmgr
492 type(errors),
target :: deferr
495 if (
present(err))
then
502 if (
associated(this%m_colormap))
deallocate(this%m_colormap)
503 allocate(this%m_colormap, stat = flag, source = x)
505 call errmgr%report_error(
"surf_set_colormap", &
506 "Insufficient memory available.", plot_out_of_memory_error)
512 pure module function plt_get_show_colorbar(this) result(x)
513 class(plot),
intent(in) :: this
515 x = this%m_showColorbar
519 module subroutine plt_set_show_colorbar(this, x)
520 class(plot),
intent(inout) :: this
521 logical,
intent(in) :: x
522 this%m_showColorbar = x
526 module function plt_get_cmd(this) result(x)
528 class(plot),
intent(in) :: this
529 character(len = :),
allocatable :: x
533 type(string_builder) :: str
534 class(colormap),
pointer :: clr
535 class(plot_arrow),
pointer :: arrow
536 class(plot_label),
pointer :: lbl
539 call str%initialize()
542 clr => this%get_colormap()
543 if (
associated(clr))
then
544 call str%append(new_line(
'a'))
545 call str%append(clr%get_command_string())
549 if (.not.this%get_show_colorbar())
then
550 call str%append(new_line(
'a'))
551 call str%append(
"unset colorbox")
555 do i = 1, this%get_arrow_count()
556 arrow => this%get_arrow(i)
557 if (.not.
associated(arrow)) cycle
558 call str%append(new_line(
'a'))
559 call str%append(arrow%get_command_string())
563 do i = 1, this%get_label_count()
564 lbl => this%get_label(i)
565 if (.not.
associated(lbl)) cycle
566 call str%append(new_line(
'a'))
567 call str%append(lbl%get_command_string())
571 x = char(str%to_string())
577 module subroutine plt_push_arrow(this, x, err)
578 class(plot),
intent(inout) :: this
579 class(plot_arrow),
intent(in) :: x
580 class(errors),
intent(inout),
optional,
target :: err
581 call this%m_arrows%push(x, manage = .true., err = err)
585 module subroutine plt_pop_arrow(this)
586 class(plot),
intent(inout) :: this
587 call this%m_arrows%pop()
591 module function plt_get_arrow(this, i) result(rst)
592 class(plot),
intent(in) :: this
593 integer(int32),
intent(in) :: i
594 class(plot_arrow),
pointer :: rst
596 class(*),
pointer :: ptr
597 ptr => this%m_arrows%get(i)
599 class is (plot_arrow)
607 module subroutine plt_set_arrow(this, i, x)
608 class(plot),
intent(inout) :: this
609 integer(int32),
intent(in) :: i
610 class(plot_arrow),
intent(in) :: x
611 call this%m_arrows%set(i, x)
615 pure module function plt_get_arrow_count(this) result(rst)
616 class(plot),
intent(in) :: this
617 integer(int32) :: rst
618 rst = this%m_arrows%count()
622 module subroutine plt_clear_arrows(this)
623 class(plot),
intent(inout) :: this
624 call this%m_arrows%clear()