6 module subroutine p2d_clean_up(this)
7 type(plot_2d),
intent(inout) :: this
8 call this%free_resources()
9 if (
associated(this%m_xAxis))
then
10 deallocate(this%m_xAxis)
13 if (
associated(this%m_yAxis))
then
14 deallocate(this%m_yAxis)
17 if (
associated(this%m_y2Axis))
then
18 deallocate(this%m_y2Axis)
19 nullify(this%m_y2Axis)
24 module subroutine p2d_init(this, term, fname, err)
26 class(plot_2d),
intent(inout) :: this
27 integer(int32),
intent(in),
optional :: term
28 character(len = *),
intent(in),
optional :: fname
29 class(errors),
intent(inout),
optional,
target :: err
32 integer(int32) :: flag
33 class(errors),
pointer :: errmgr
34 type(errors),
target :: deferr
37 if (
present(err))
then
44 call plt_init(this, term, fname, errmgr)
45 if (errmgr%has_error_occurred())
return
49 if (.not.
associated(this%m_xAxis))
then
50 allocate(this%m_xAxis, stat = flag)
52 if (flag == 0 .and. .not.
associated(this%m_yAxis))
then
53 allocate(this%m_yAxis, stat = flag)
55 if (flag == 0 .and. .not.
associated(this%m_y2Axis))
then
56 allocate(this%m_y2Axis, stat = flag)
61 call errmgr%report_error(
"p2d_init", &
62 "Insufficient memory available.", plot_out_of_memory_error)
68 module function p2d_get_cmd(this) result(x)
70 class(plot_2d),
intent(in) :: this
71 character(len = :),
allocatable :: x
74 type(string_builder) :: str
75 integer(int32) :: i, n
76 class(plot_data),
pointer :: ptr
77 class(plot_axis),
pointer :: axis, xAxis, yAxis
78 type(legend),
pointer :: leg
85 call str%append(this%plot%get_command_string())
88 if (this%get_show_gridlines())
then
89 call str%append(new_line(
'a'))
90 call str%append(
"set grid")
94 n = len_trim(this%get_title())
96 call str%append(new_line(
'a'))
97 call str%append(
'set title "')
98 call str%append(this%get_title())
103 call str%append(new_line(
'a'))
104 xaxis => this%get_x_axis()
105 if (
associated(xaxis))
call str%append(xaxis%get_command_string())
107 call str%append(new_line(
'a'))
108 yaxis => this%get_y_axis()
109 if (
associated(yaxis))
call str%append(yaxis%get_command_string())
112 if (this%get_use_y2_axis())
then
113 call str%append(new_line(
'a'))
114 axis => this%get_y2_axis()
115 if (
associated(axis))
then
116 call str%append(axis%get_command_string())
117 call str%append(new_line(
'a'))
118 call str%append(
"set y2tics")
119 call str%append(new_line(
'a'))
120 call str%append(
"set ytics nomirror")
125 if (.not.this%get_tics_inward())
then
126 call str%append(new_line(
'a'))
127 call str%append(
"set tics out")
129 if (xaxis%get_zero_axis())
then
130 call str%append(new_line(
'a'))
131 call str%append(
"set xtics axis")
133 if (yaxis%get_zero_axis())
then
134 call str%append(new_line(
'a'))
135 call str%append(
"set ytics axis")
140 call str%append(new_line(
'a'))
141 call str%append(
"set border back")
143 if (this%get_draw_border())
then
147 if (.not.xaxis%get_zero_axis()) n = n + 1
148 if (.not.yaxis%get_zero_axis()) n = n + 2
150 call str%append(new_line(
'a'))
151 call str%append(
"set xtics nomirror")
152 call str%append(new_line(
'a'))
153 call str%append(
"set ytics nomirror")
155 if (this%get_use_y2_axis())
then
160 call str%append(new_line(
'a'))
162 call str%append(
"set border ")
163 call str%append(to_string(n))
165 call str%append(
"unset border")
169 if (this%get_axis_equal())
then
170 call str%append(new_line(
'a'))
171 call str%append(
"set view equal xy")
174 if (this%get_square_axes())
then
175 call str%append(new_line(
'a'))
176 call str%append(
"set size square")
180 call str%append(new_line(
'a'))
181 leg => this%get_legend()
182 if (
associated(leg))
call str%append(leg%get_command_string())
194 call str%append(new_line(
'a'))
195 call str%append(
"plot ")
198 if (.not.
associated(ptr)) cycle
199 call str%append(ptr%get_command_string())
200 if (i /= n)
call str%append(
", ")
206 if (.not.
associated(ptr)) cycle
207 call str%append(new_line(
'a'))
208 call str%append(ptr%get_data_string())
216 x = char(str%to_string())
220 module function p2d_get_x_axis(this) result(ptr)
221 class(plot_2d),
intent(in) :: this
222 class(plot_axis),
pointer :: ptr
227 module function p2d_get_y_axis(this) result(ptr)
228 class(plot_2d),
intent(in) :: this
229 class(plot_axis),
pointer :: ptr
234 module function p2d_get_y2_axis(this) result(ptr)
235 class(plot_2d),
intent(in) :: this
236 class(plot_axis),
pointer :: ptr
241 pure module function p2d_get_use_y2(this) result(x)
242 class(plot_2d),
intent(in) :: this
248 module subroutine p2d_set_use_y2(this, x)
249 class(plot_2d),
intent(inout) :: this
250 logical,
intent(in) :: x
255 pure module function p2d_get_square_axes(this) result(rst)
256 class(plot_2d),
intent(in) :: this
258 rst = this%m_set2square
262 module subroutine p2d_set_square_axes(this, x)
263 class(plot_2d),
intent(inout) :: this
264 logical,
intent(in) :: x
265 this%m_set2square = x