fplot 1.7.1
A Fortran library providing a convenient interface for plotting with Gnuplot.
Loading...
Searching...
No Matches
fplot_plot_data_bar.f90
1! fplot_plot_data_bar.f90
2
3submodule(fplot_core) fplot_plot_data_bar
4contains
5! ------------------------------------------------------------------------------
6pure module function pdb_get_count(this) result(x)
7 class(plot_data_bar), intent(in) :: this
8 integer(int32) :: x
9 if (allocated(this%m_barData)) then
10 x = size(this%m_barData, 1)
11 else
12 x = 0
13 end if
14end function
15
16! ------------------------------------------------------------------------------
17pure module function pdb_get_data(this, index, col) result(x)
18 class(plot_data_bar), intent(in) :: this
19 integer(int32), intent(in) :: index, col
20 real(real64) :: x
21 if (allocated(this%m_barData)) then
22 x = this%m_barData(index, col)
23 else
24 x = 0.0d0
25 end if
26end function
27
28! ------------------------------------------------------------------------------
29module subroutine pdb_set_data(this, index, col, x)
30 class(plot_data_bar), intent(inout) :: this
31 integer(int32), intent(in) :: index, col
32 real(real64), intent(in) :: x
33 if (allocated(this%m_barData)) then
34 this%m_barData(index, col) = x
35 end if
36end subroutine
37
38! ------------------------------------------------------------------------------
39pure module function pdb_get_data_set(this, col) result(x)
40 class(plot_data_bar), intent(in) :: this
41 integer(int32), intent(in) :: col
42 real(real64), allocatable, dimension(:) :: x
43 if (allocated(this%m_barData)) then
44 x = this%m_barData(:,col)
45 else
46 allocate(x(0))
47 end if
48end function
49
50! ------------------------------------------------------------------------------
51pure module function pdb_get_label(this, index) result(x)
52 class(plot_data_bar), intent(in) :: this
53 integer(int32), intent(in) :: index
54 character(len = :), allocatable :: x
55 if (allocated(this%m_axisLabels)) then
56 x = char(this%m_axisLabels(index))
57 else
58 x = ""
59 end if
60end function
61
62! ------------------------------------------------------------------------------
63module subroutine pdb_set_label(this, index, txt)
64 class(plot_data_bar), intent(inout) :: this
65 integer(int32) :: index
66 character(len = *), intent(in) :: txt
67 if (allocated(this%m_axisLabels)) then
68 this%m_axisLabels(index) = txt
69 end if
70end subroutine
71
72! ------------------------------------------------------------------------------
73pure module function pdb_get_use_labels(this) result(x)
74 class(plot_data_bar), intent(in) :: this
75 logical :: x
76 x = this%m_useAxisLabels
77end function
78
79! ------------------------------------------------------------------------------
80module subroutine pdb_set_use_labels(this, x)
81 class(plot_data_bar), intent(inout) :: this
82 logical, intent(in) :: x
83 this%m_useAxisLabels = x
84end subroutine
85
86! ------------------------------------------------------------------------------
87module function pdb_get_cmd(this) result(x)
88 ! Arguments
89 class(plot_data_bar), intent(in) :: this
90 character(len = :), allocatable :: x
91
92 ! Local Variables
93 type(string_builder) :: str
94 integer(int32) :: n, ncols
95 type(color) :: clr
96
97 ! Initialization
98 call str%initialize()
99
100 ! Starting off...
101 call str%append(' "-" ')
102
103 ! Tic Labels
104 if (this%get_use_labels() .and. allocated(this%m_barData) .and. &
105 allocated(this%m_axisLabels)) then
106 ncols = size(this%m_barData, 2)
107 if (ncols == 1) then
108 call str%append(" using 2:xtic(1) ")
109 else
110 call str%append(" using 2:")
111 call str%append(to_string(ncols))
112 call str%append(":xtic(1) ")
113 end if
114 end if
115
116 ! Enforce a box plot
117 call str%append(" with boxes ")
118
119 ! Filled?
120 if (this%get_is_filled()) then
121 call str%append(" fill solid ")
122 else
123 call str%append(" fill empty ")
124 end if
125
126 ! Transparency
127 call str%append(to_string(this%get_transparency()))
128
129 ! Title
130 n = len_trim(this%get_name())
131 if (n > 0) then
132 call str%append(' title "')
133 call str%append(this%get_name())
134 call str%append('"')
135 else
136 call str%append(' notitle')
137 end if
138
139 ! Color
140 clr = this%get_line_color()
141 call str%append(' lc rgb "#')
142 call str%append(clr%to_hex_string())
143 call str%append('"')
144
145 ! Define the axes structure
146 call str%append(" ")
147 call str%append(this%get_axes_string())
148
149 ! End
150 x = char(str%to_string())
151end function
152
153! ------------------------------------------------------------------------------
154module function pdb_get_data_cmd(this) result(x)
155 ! Arguments
156 class(plot_data_bar), intent(in) :: this
157 character(len = :), allocatable :: x
158
159 ! Local Variables
160 type(string_builder) :: str
161 integer(int32) :: i, j, nbars, ncols
162 character :: delimiter, nl
163
164 ! Initialization
165 call str%initialize()
166 delimiter = achar(9)
167 nl = new_line(nl)
168 nbars = this%get_count()
169 ncols = this%get_bar_per_label_count()
170
171 ! Process
172 if (this%get_use_labels() .and. allocated(this%m_axisLabels) .and. &
173 allocated(this%m_barData)) then
174 do i = 1, nbars
175 call str%append(char(this%m_axisLabels(i)))
176 call str%append(delimiter)
177 do j = 1, ncols
178 call str%append(to_string(this%get(i, j)))
179 if (j /= nbars) call str%append(delimiter)
180 end do
181 call str%append(nl)
182 end do
183 else
184 do i = 1, nbars
185 do j = 1, ncols
186 call str%append(to_string(this%get(i, j)))
187 if (j /= nbars) call str%append(delimiter)
188 end do
189 call str%append(nl)
190 end do
191 end if
192
193 ! End
194 x = char(str%to_string())
195end function
196
197! ------------------------------------------------------------------------------
198module function pdb_get_axes_cmd(this) result(x)
199 ! Arguments
200 class(plot_data_bar), intent(in) :: this
201 character(len = :), allocatable :: x
202
203 ! Define which axes the data is to be plotted against
204 if (this%get_draw_against_y2()) then
205 x = "axes x1y2"
206 else
207 x = "axes x1y1"
208 end if
209end function
210
211! ------------------------------------------------------------------------------
212pure module function pdb_get_col_count(this) result(x)
213 class(plot_data_bar), intent(in) :: this
214 integer(int32) :: x
215 if (allocated(this%m_barData)) then
216 x = size(this%m_barData, 2)
217 else
218 x = 0
219 end if
220end function
221
222! ------------------------------------------------------------------------------
223pure module function pdb_get_use_y2(this) result(x)
224 class(plot_data_bar), intent(in) :: this
225 logical :: x
226 x = this%m_useY2
227end function
228
229! ------------------------------------------------------------------------------
230module subroutine pdb_set_use_y2(this, x)
231 class(plot_data_bar), intent(inout) :: this
232 logical, intent(in) :: x
233 this%m_useY2 = x
234end subroutine
235
236! ------------------------------------------------------------------------------
237module subroutine pdb_set_data_1(this, x, err)
238 ! Arguments
239 class(plot_data_bar), intent(inout) :: this
240 real(real64), intent(in), dimension(:) :: x
241 class(errors), intent(inout), optional, target :: err
242
243 ! Process
244 call this%set_data_1(x, err)
245end subroutine
246
247! ------------------------------------------------------------------------------
248module subroutine pdb_set_data_2(this, labels, x, err)
249 ! Arguments
250 class(plot_data_bar), intent(inout) :: this
251 class(string), intent(in), dimension(:) :: labels
252 real(real64), intent(in), dimension(:) :: x
253 class(errors), intent(inout), optional, target :: err
254
255 ! Process
256 call this%set_data_2(labels, x, err)
257end subroutine
258
259! ------------------------------------------------------------------------------
260module subroutine pdb_set_data_3(this, labels, x, fmt, err)
261 ! Arguments
262 class(plot_data_bar), intent(inout) :: this
263 real(real64), intent(in), dimension(:) :: labels
264 real(real64), intent(in), dimension(:) :: x
265 character(len = *), intent(in), optional :: fmt
266 class(errors), intent(inout), optional, target :: err
267
268 ! Process
269 call this%set_data_3(labels, x, fmt, err)
270end subroutine
271
272! ------------------------------------------------------------------------------
273pure module function pdb_get_is_filled(this) result(x)
274 class(plot_data_bar), intent(in) :: this
275 logical :: x
276 x = this%m_filled
277end function
278
279! ------------------------------------------------------------------------------
280module subroutine pdb_set_is_filled(this, x)
281 class(plot_data_bar), intent(inout) :: this
282 logical, intent(in) :: x
283 this%m_filled = x
284end subroutine
285
286! ------------------------------------------------------------------------------
287pure module function pdb_get_alpha(this) result(x)
288 class(plot_data_bar), intent(in) :: this
289 real(real32) :: x
290 x = this%m_alpha
291end function
292
293! ------------------------------------------------------------------------------
294module subroutine pdb_set_alpha(this, x)
295 class(plot_data_bar), intent(inout) :: this
296 real(real32), intent(in) :: x
297 if (x > 1.0) then
298 this%m_alpha = 1.0
299 else if (x < 0.0) then
300 this%m_alpha = 0.0
301 else
302 this%m_alpha = x
303 end if
304end subroutine
305
306! ------------------------------------------------------------------------------
307module subroutine pdb_set_data_1_core(this, x, err)
308 ! Arguments
309 class(plot_data_bar), intent(inout) :: this
310 real(real64), intent(in), dimension(:) :: x
311 class(errors), intent(inout), optional, target :: err
312
313 ! Local Variables
314 class(errors), pointer :: errmgr
315 type(errors), target :: deferr
316 integer(int32) :: n, flag
317
318 ! Initialization
319 if (present(err)) then
320 errmgr => err
321 else
322 errmgr => deferr
323 end if
324 n = size(x)
325
326 ! Process
327 if (allocated(this%m_axisLabels)) deallocate(this%m_axisLabels)
328 if (allocated(this%m_barData)) deallocate(this%m_barData)
329 allocate(this%m_barData(n, 1), stat = flag)
330 if (flag /= 0) then
331 call errmgr%report_error("pdb_set_data_1_core", &
332 "Insufficient memory available.", plot_out_of_memory_error)
333 return
334 end if
335 this%m_barData(:,1) = x
336end subroutine
337
338! ------------------------------------------------------------------------------
339module subroutine pdb_set_data_2_core(this, labels, x, err)
340 ! Arguments
341 class(plot_data_bar), intent(inout) :: this
342 class(string), intent(in), dimension(:) :: labels
343 real(real64), intent(in), dimension(:) :: x
344 class(errors), intent(inout), optional, target :: err
345
346 ! Local Variables
347 class(errors), pointer :: errmgr
348 type(errors), target :: deferr
349 integer(int32) :: n, flag
350
351 ! Initialization
352 if (present(err)) then
353 errmgr => err
354 else
355 errmgr => deferr
356 end if
357 n = size(x)
358
359 ! Input Check
360 if (size(labels) /= n) then
361 call errmgr%report_error("pdb_set_data_2_core", &
362 "The input arrays are not the same size.", &
363 plot_array_size_mismatch_error)
364 return
365 end if
366
367 ! Process
368 if (allocated(this%m_axisLabels)) deallocate(this%m_axisLabels)
369 if (allocated(this%m_barData)) deallocate(this%m_barData)
370 allocate(this%m_barData(n, 1), stat = flag)
371 if (flag == 0) allocate(this%m_axisLabels(n), stat = flag)
372 if (flag /= 0) then
373 call errmgr%report_error("pdb_set_data_2_core", &
374 "Insufficient memory available.", plot_out_of_memory_error)
375 return
376 end if
377 this%m_barData(:,1) = x
378 this%m_axisLabels = labels
379end subroutine
380
381! ------------------------------------------------------------------------------
382module subroutine pdb_set_data_3_core(this, labels, x, fmt, err)
383 ! Arguments
384 class(plot_data_bar), intent(inout) :: this
385 real(real64), intent(in), dimension(:) :: labels
386 real(real64), intent(in), dimension(:) :: x
387 character(len = *), intent(in), optional :: fmt
388 class(errors), intent(inout), optional, target :: err
389
390 ! Local Variables
391 class(errors), pointer :: errmgr
392 type(errors), target :: deferr
393 integer(int32) :: i, n, flag
394 type(string), allocatable, dimension(:) :: lbls
395
396 ! Initialization
397 if (present(err)) then
398 errmgr => err
399 else
400 errmgr => deferr
401 end if
402 n = size(x)
403
404 ! Input Check
405 if (size(labels) /= n) then
406 call errmgr%report_error("pdb_set_data_3_core", &
407 "The input arrays are not the same size.", &
408 plot_array_size_mismatch_error)
409 return
410 end if
411
412 ! Convert the numeric labels to strings
413 allocate(lbls(n), stat = flag)
414 if (flag /= 0) then
415 call errmgr%report_error("pdb_set_data_3_core", &
416 "Insufficient memory available.", plot_out_of_memory_error)
417 return
418 end if
419 do i = 1, n
420 lbls(i) = to_string(labels(i), fmt)
421 end do
422
423 ! Store the data
424 if (allocated(this%m_axisLabels)) deallocate(this%m_axisLabels)
425 if (allocated(this%m_barData)) deallocate(this%m_barData)
426 allocate(this%m_barData(n, 1), stat = flag)
427 if (flag == 0) allocate(this%m_axisLabels(n), stat = flag)
428 if (flag /= 0) then
429 call errmgr%report_error("pdb_set_data_3_core", &
430 "Insufficient memory available.", plot_out_of_memory_error)
431 return
432 end if
433 this%m_barData(:,1) = x
434 this%m_axisLabels = lbls
435end subroutine
436
437! ------------------------------------------------------------------------------
438end submodule
fplot_core