fplot 1.7.1
A Fortran library providing a convenient interface for plotting with Gnuplot.
Loading...
Searching...
No Matches
fplot_plot_axis.f90
1! fplot_plot_axis.f90
2
3submodule(fplot_core) fplot_plot_axis
4contains
5! ------------------------------------------------------------------------------
6 module function pa_get_title(this) result(txt)
7 class(plot_axis), intent(in) :: this
8 character(len = :), allocatable :: txt
9 integer(int32) :: n
10 n = len_trim(this%m_title)
11 allocate(character(len = n) :: txt)
12 txt = trim(this%m_title)
13 end function
14
15! --------------------
16 module subroutine pa_set_title(this, txt)
17 ! Arguments
18 class(plot_axis), intent(inout) :: this
19 character(len = *), intent(in) :: txt
20
21 ! Local Variables
22 integer(int32) :: n
23
24 ! Process
25 n = min(len_trim(txt), plotdata_max_name_length)
26 this%m_title = ""
27 if (n /= 0) then
28 this%m_title(1:n) = txt(1:n)
29 this%m_hasTitle = .true.
30 else
31 this%m_hasTitle = .false.
32 end if
33 end subroutine
34
35! ------------------------------------------------------------------------------
36 pure module function pa_has_title(this) result(x)
37 class(plot_axis), intent(in) :: this
38 logical :: x
39 x = this%m_hasTitle
40 end function
41
42! ------------------------------------------------------------------------------
43 pure module function pa_get_autoscale(this) result(x)
44 class(plot_axis), intent(in) :: this
45 logical :: x
46 x = this%m_autoscale
47 end function
48
49! --------------------
50 module subroutine pa_set_autoscale(this, x)
51 class(plot_axis), intent(inout) :: this
52 logical, intent(in) :: x
53 this%m_autoscale = x
54 end subroutine
55
56! ------------------------------------------------------------------------------
57 pure module function pa_get_axis_limits(this) result(x)
58 class(plot_axis), intent(in) :: this
59 real(real64), dimension(2) :: x
60 x(1) = minval(this%m_limits)
61 x(2) = maxval(this%m_limits)
62 end function
63
64! --------------------
65 module subroutine pa_set_axis_limits(this, lower, upper)
66 class(plot_axis), intent(inout) :: this
67 real(real64), intent(in) :: lower, upper
68 this%m_limits(1) = lower
69 this%m_limits(2) = upper
70 end subroutine
71
72! ------------------------------------------------------------------------------
73 pure module function pa_get_log_scale(this) result(x)
74 class(plot_axis), intent(in) :: this
75 logical :: x
76 x = this%m_logScale
77 end function
78
79! --------------------
80 module subroutine pa_set_log_scale(this, x)
81 class(plot_axis), intent(inout) :: this
82 logical, intent(in) :: x
83 this%m_logScale = x
84 end subroutine
85
86! ------------------------------------------------------------------------------
87 module function pa_get_cmd_string(this) result(txt)
88 ! Arguments
89 class(plot_axis), intent(in) :: this
90 character(len = :), allocatable :: txt
91
92 ! Local Variables
93 type(string_builder) :: str
94 character(len = :), allocatable :: axis, fmt
95 real(real64) :: lim(2)
96
97 ! Process
98 axis = this%get_id_string()
99 fmt = this%get_tic_label_format()
100 lim = this%get_limits()
101 call str%initialize()
102
103 ! Formatting
104 if (.not.this%get_use_default_tic_label_format()) then
105 call str%append("set format ")
106 call str%append(axis)
107 call str%append('"')
108 call str%append(fmt)
109 call str%append('"')
110 call str%append(new_line('a'))
111 end if
112
113 ! Axis Limits
114 if (this%get_autoscale()) then
115 call str%append("set ")
116 call str%append(axis)
117 call str%append("range [*:*]")
118 else
119 call str%append("set ")
120 call str%append(axis)
121 call str%append("range [")
122 call str%append(to_string(lim(1)))
123 call str%append(":")
124 call str%append(to_string(lim(2)))
125 call str%append("]")
126 end if
127
128 ! Titles
129 call str%append(new_line('a'))
130 if (this%is_title_defined()) then
131 call str%append("set ")
132 call str%append(axis)
133 call str%append("label ")
134 call str%append('"')
135 call str%append(this%get_title())
136 call str%append('"')
137 else
138 call str%append("set ")
139 call str%append(axis)
140 call str%append("label ")
141 call str%append('""')
142 end if
143
144 ! Scaling
145 call str%append(new_line('a'))
146 if (this%get_is_log_scaled()) then
147 call str%append("set log ")
148 call str%append(axis)
149 else
150 call str%append("unset log ")
151 call str%append(axis)
152 end if
153
154 ! Zero Axis
155 if (this%get_zero_axis()) then
156 call str%append(new_line('a'))
157 call str%append("set ")
158 call str%append(this%get_id_string())
159 call str%append("zeroaxis linestyle -1 linewidth ")
160 call str%append(to_string(this%get_zero_axis_line_width()))
161 end if
162
163 ! Output
164 txt = char(str%to_string())
165 end function
166
167! ------------------------------------------------------------------------------
168 pure module function pa_get_zero_axis(this) result(x)
169 class(plot_axis), intent(in) :: this
170 logical :: x
171 x = this%m_zeroAxis
172 end function
173
174! --------------------
175 module subroutine pa_set_zero_axis(this, x)
176 class(plot_axis), intent(inout) :: this
177 logical, intent(in) :: x
178 this%m_zeroAxis = x
179 end subroutine
180
181! ------------------------------------------------------------------------------
182 pure module function pa_get_zero_axis_width(this) result(x)
183 class(plot_axis), intent(in) :: this
184 real(real32) :: x
185 x = this%m_axisWidth
186 end function
187
188! --------------------
189 module subroutine pa_set_zero_axis_width(this, x)
190 class(plot_axis), intent(inout) :: this
191 real(real32), intent(in) :: x
192 this%m_axisWidth = x
193 end subroutine
194
195! ADDED March 29, 2023 - JAC
196! ------------------------------------------------------------------------------
197 pure module function pa_get_use_dft_tic_lbl_fmt(this) result(rst)
198 class(plot_axis), intent(in) :: this
199 logical :: rst
200 rst = this%m_defaultTicLabels
201 end function
202
203! --------------------
204 module subroutine pa_set_use_dft_tic_lbl_fmt(this, x)
205 class(plot_axis), intent(inout) :: this
206 logical, intent(in) :: x
207 this%m_defaultTicLabels = x
208 end subroutine
209
210! ------------------------------------------------------------------------------
211 pure module function pa_get_tic_label_fmt(this) result(rst)
212 class(plot_axis), intent(in) :: this
213 character(len = :), allocatable :: rst
214 rst = trim(this%m_ticLabelFmt)
215 end function
216
217! --------------------
218 module subroutine pa_set_tic_label_fmt(this, x)
219 class(plot_axis), intent(inout) :: this
220 character(len = *), intent(in) :: x
221 this%m_ticLabelFmt = x
222 end subroutine
223
224! ------------------------------------------------------------------------------
225end submodule
fplot_core