fplot 1.7.1
A Fortran library providing a convenient interface for plotting with Gnuplot.
Loading...
Searching...
No Matches
fplot_plot_data_error_bars.f90
1! fplot_plot_data_error_bars.f90
2
3submodule(fplot_core) fplot_plot_data_error_bars
4contains
5! ------------------------------------------------------------------------------
6 module function pde_get_cmd(this) result(cmd)
7 ! Arguments
8 class(plot_data_error_bars), intent(in) :: this
9 character(len = :), allocatable :: cmd
10
11 ! Local Variables
12 type(string_builder) :: str
13 integer(int32) :: n
14 type(color) :: clr
15
16 ! Initialization
17 call str%initialize()
18
19 ! Title
20 n = len_trim(this%get_name())
21 if (n > 0) then
22 call str%append(' "-" title "')
23 call str%append(this%get_name())
24 call str%append('"')
25 else
26 call str%append(' "-" notitle')
27 end if
28
29 ! Color
30 clr = this%get_line_color()
31 call str%append(' lc rgb "#')
32 call str%append(clr%to_hex_string())
33 call str%append('"')
34
35 ! Error Bars
36 if (this%get_plot_x_error_bars() .and. this%get_plot_y_error_bars()) then
37 if (this%get_use_error_box()) then
38 call str%append(" w boxxyerr")
39 else
40 call str%append(" w xyerr")
41 end if
42 else if (this%get_plot_x_error_bars() .and. .not.this%get_plot_y_error_bars()) then
43 call str%append(" w xerr")
44 else if (.not.this%get_plot_x_error_bars() .and. this%get_plot_y_error_bars()) then
45 call str%append(" w yerr")
46 end if
47
48 ! Output
49 cmd = char(str%to_string())
50 end function
51
52! ------------------------------------------------------------------------------
53 module function pde_get_data_cmd(this) result(cmd)
54 ! Arguments
55 class(plot_data_error_bars), intent(in) :: this
56 character(len = :), allocatable :: cmd
57
58 ! Local Variables
59 type(string_builder) :: str
60 integer(int32) :: i, n
61 character :: delimiter, nl
62
63 ! Initialization
64 call str%initialize()
65 delimiter = achar(9) ! tab delimiter
66 nl = new_line(nl)
67 n = this%get_count()
68
69 ! Process
70 if (this%get_plot_x_error_bars() .and. this%get_plot_y_error_bars()) then
71 if (this%get_use_range()) then
72 do i = 1, n
73 call str%append(to_string(this%m_data(i, 1)))
74 call str%append(delimiter)
75 call str%append(to_string(this%m_data(i, 2)))
76 call str%append(delimiter)
77 call str%append(to_string(this%m_data(i, 3)))
78 call str%append(delimiter)
79 call str%append(to_string(this%m_data(i, 4)))
80 call str%append(delimiter)
81 call str%append(to_string(this%m_data(i, 5)))
82 call str%append(delimiter)
83 call str%append(to_string(this%m_data(i, 6)))
84 call str%append(nl)
85 end do
86 else
87 do i = 1, n
88 call str%append(to_string(this%m_data(i, 1)))
89 call str%append(delimiter)
90 call str%append(to_string(this%m_data(i, 2)))
91 call str%append(delimiter)
92 call str%append(to_string(this%m_data(i, 3)))
93 call str%append(delimiter)
94 call str%append(to_string(this%m_data(i, 4)))
95 call str%append(nl)
96 end do
97 end if
98 else
99 if (this%get_use_range()) then
100 do i = 1, n
101 call str%append(to_string(this%m_data(i, 1)))
102 call str%append(delimiter)
103 call str%append(to_string(this%m_data(i, 2)))
104 call str%append(delimiter)
105 call str%append(to_string(this%m_data(i, 3)))
106 call str%append(delimiter)
107 call str%append(to_string(this%m_data(i, 4)))
108 call str%append(nl)
109 end do
110 else
111 do i = 1, n
112 call str%append(to_string(this%m_data(i, 1)))
113 call str%append(delimiter)
114 call str%append(to_string(this%m_data(i, 2)))
115 call str%append(delimiter)
116 call str%append(to_string(this%m_data(i, 3)))
117 call str%append(nl)
118 end do
119 end if
120 end if
121
122 ! if (this%get_plot_x_error_bars() .and. this%get_plot_y_error_bars()) then
123 ! do i = 1, n
124 ! call str%append(to_string(this%m_data(i, 1)))
125 ! call str%append(delimiter)
126 ! call str%append(to_string(this%m_data(i, 2)))
127 ! call str%append(delimiter)
128 ! call str%append(to_string(this%m_data(i, 3)))
129 ! call str%append(delimiter)
130 ! call str%append(to_string(this%m_data(i, 4)))
131 ! call str%append(nl)
132 ! end do
133 ! else
134 ! do i = 1, n
135 ! call str%append(to_string(this%m_data(i, 1)))
136 ! call str%append(delimiter)
137 ! call str%append(to_string(this%m_data(i, 2)))
138 ! call str%append(delimiter)
139 ! call str%append(to_string(this%m_data(i, 3)))
140 ! call str%append(nl)
141 ! end do
142 ! end if
143
144 ! End
145 cmd = char(str%to_string())
146 end function
147
148! ------------------------------------------------------------------------------
149 module subroutine pde_define_x_err(this, x, y, xerr, err)
150 ! Arguments
151 class(plot_data_error_bars), intent(inout) :: this
152 real(real64), intent(in), dimension(:) :: x, y, xerr
153 class(errors), intent(inout), optional, target :: err
154
155 ! Local Variables
156 integer(int32) :: i, n, flag
157 class(errors), pointer :: errmgr
158 type(errors), target :: deferr
159
160 ! Initialization
161 n = size(x)
162 if (present(err)) then
163 errmgr => err
164 else
165 errmgr => deferr
166 end if
167
168 ! Input Checking
169 if (size(y) /= n .or. size(xerr) /= n) then
170 call errmgr%report_error("pde_define_x_err", &
171 "Input arrays must be the same size.", &
172 plot_array_size_mismatch_error)
173 return
174 end if
175
176 ! Process
177 this%m_xBars = .false.
178 this%m_yBars = .false.
179 this%m_range = .false.
180 if (allocated(this%m_data)) deallocate(this%m_data)
181 allocate(this%m_data(n, 3), stat = flag)
182 if (flag /= 0) then
183 call errmgr%report_error("pde_define_x_err", &
184 "Insufficient memory available.", plot_out_of_memory_error)
185 return
186 end if
187 do i = 1, n
188 this%m_data(i, 1) = x(i)
189 this%m_data(i, 2) = y(i)
190 this%m_data(i, 3) = xerr(i)
191 end do
192 this%m_xBars = .true.
193 this%m_range = .false.
194 end subroutine
195
196! ------------------------------------------------------------------------------
197 module subroutine pde_define_y_err(this, x, y, yerr, err)
198 ! Arguments
199 class(plot_data_error_bars), intent(inout) :: this
200 real(real64), intent(in), dimension(:) :: x, y, yerr
201 class(errors), intent(inout), optional, target :: err
202
203 ! Local Variables
204 integer(int32) :: i, n, flag
205 class(errors), pointer :: errmgr
206 type(errors), target :: deferr
207
208 ! Initialization
209 n = size(x)
210 if (present(err)) then
211 errmgr => err
212 else
213 errmgr => deferr
214 end if
215
216 ! Input Checking
217 if (size(y) /= n .or. size(yerr) /= n) then
218 call errmgr%report_error("pde_define_y_err", &
219 "Input arrays must be the same size.", &
220 plot_array_size_mismatch_error)
221 return
222 end if
223
224 ! Process
225 this%m_xBars = .false.
226 this%m_yBars = .false.
227 this%m_range = .false.
228 if (allocated(this%m_data)) deallocate(this%m_data)
229 allocate(this%m_data(n, 3), stat = flag)
230 if (flag /= 0) then
231 call errmgr%report_error("pde_define_y_err", &
232 "Insufficient memory available.", plot_out_of_memory_error)
233 return
234 end if
235 do i = 1, n
236 this%m_data(i, 1) = x(i)
237 this%m_data(i, 2) = y(i)
238 this%m_data(i, 3) = yerr(i)
239 end do
240 this%m_yBars = .true.
241 this%m_range = .false.
242 end subroutine
243
244! ------------------------------------------------------------------------------
245 module subroutine pde_define_xy_err(this, x, y, xerr, yerr, err)
246 ! Arguments
247 class(plot_data_error_bars), intent(inout) :: this
248 real(real64), intent(in), dimension(:) :: x, y, xerr, yerr
249 class(errors), intent(inout), optional, target :: err
250
251 ! Local Variables
252 integer(int32) :: i, n, flag
253 class(errors), pointer :: errmgr
254 type(errors), target :: deferr
255
256 ! Initialization
257 n = size(x)
258 if (present(err)) then
259 errmgr => err
260 else
261 errmgr => deferr
262 end if
263
264 ! Input Checking
265 if (size(y) /= n .or. size(xerr) /= n .or. size(yerr) /= n) then
266 call errmgr%report_error("pde_define_xy_err", &
267 "Input arrays must be the same size.", &
268 plot_array_size_mismatch_error)
269 return
270 end if
271
272 ! Process
273 this%m_xBars = .false.
274 this%m_yBars = .false.
275 this%m_range = .false.
276 if (allocated(this%m_data)) deallocate(this%m_data)
277 allocate(this%m_data(n, 4), stat = flag)
278 if (flag /= 0) then
279 call errmgr%report_error("pde_define_xy_err", &
280 "Insufficient memory available.", plot_out_of_memory_error)
281 return
282 end if
283 do i = 1, n
284 this%m_data(i, 1) = x(i)
285 this%m_data(i, 2) = y(i)
286 this%m_data(i, 3) = xerr(i)
287 this%m_data(i, 4) = yerr(i)
288 end do
289 this%m_xBars = .true.
290 this%m_yBars = .true.
291 this%m_range = .false.
292 end subroutine
293
294! ------------------------------------------------------------------------------
295 pure module function pde_get_plot_x_err(this) result(x)
296 class(plot_data_error_bars), intent(in) :: this
297 logical :: x
298 x = this%m_xBars
299 end function
300
301! ------------------------------------------------------------------------------
302 pure module function pde_get_plot_y_err(this) result(x)
303 class(plot_data_error_bars), intent(in) :: this
304 logical :: x
305 x = this%m_yBars
306 end function
307! ------------------------------------------------------------------------------
308 pure module function pde_get_count(this) result(x)
309 class(plot_data_error_bars), intent(in) :: this
310 integer(int32) :: x
311 if (allocated(this%m_data)) then
312 x = size(this%m_data, 1)
313 else
314 x = 0
315 end if
316 end function
317
318! ------------------------------------------------------------------------------
319 pure module function pde_get_box(this) result(x)
320 class(plot_data_error_bars), intent(in) :: this
321 logical :: x
322 x = this%m_box
323 end function
324
325! --------------------
326 module subroutine pde_set_box(this, x)
327 class(plot_data_error_bars), intent(inout) :: this
328 logical, intent(in) :: x
329 this%m_box = x
330 end subroutine
331
332! ------------------------------------------------------------------------------
333 pure module function pde_get_use_range(this) result(x)
334 class(plot_data_error_bars), intent(in) :: this
335 logical :: x
336 x = this%m_range
337 end function
338
339! ------------------------------------------------------------------------------
340 module subroutine pde_define_x_err_lim(this, x, y, xmin, xmax, err)
341 ! Arguments
342 class(plot_data_error_bars), intent(inout) :: this
343 real(real64), intent(in), dimension(:) :: x, y, xmin, xmax
344 class(errors), intent(inout), optional, target :: err
345
346 ! Local Variables
347 integer(int32) :: i, n, flag
348 class(errors), pointer :: errmgr
349 type(errors), target :: deferr
350
351 ! Initialization
352 n = size(x)
353 if (present(err)) then
354 errmgr => err
355 else
356 errmgr => deferr
357 end if
358
359 ! Input Checking
360 if (size(y) /= n .or. size(xmin) /= n .or. size(xmax) /= n) then
361 call errmgr%report_error("pde_define_x_err_lim", &
362 "Input arrays must be the same size.", &
363 plot_array_size_mismatch_error)
364 return
365 end if
366
367 ! Process
368 this%m_xBars = .false.
369 this%m_yBars = .false.
370 this%m_range = .false.
371 if (allocated(this%m_data)) deallocate(this%m_data)
372 allocate(this%m_data(n, 4), stat = flag)
373 if (flag /= 0) then
374 call errmgr%report_error("pde_define_x_err_lim", &
375 "Insufficient memory available.", plot_out_of_memory_error)
376 return
377 end if
378 do i = 1, n
379 this%m_data(i, 1) = x(i)
380 this%m_data(i, 2) = y(i)
381 this%m_data(i, 3) = xmin(i)
382 this%m_data(i, 4) = xmax(i)
383 end do
384 this%m_xBars = .true.
385 this%m_range = .true.
386 end subroutine
387
388! ------------------------------------------------------------------------------
389 module subroutine pde_define_y_err_lim(this, x, y, ymin, ymax, err)
390 ! Arguments
391 class(plot_data_error_bars), intent(inout) :: this
392 real(real64), intent(in), dimension(:) :: x, y, ymin, ymax
393 class(errors), intent(inout), optional, target :: err
394
395 ! Local Variables
396 integer(int32) :: i, n, flag
397 class(errors), pointer :: errmgr
398 type(errors), target :: deferr
399
400 ! Initialization
401 n = size(x)
402 if (present(err)) then
403 errmgr => err
404 else
405 errmgr => deferr
406 end if
407
408 ! Input Checking
409 if (size(y) /= n .or. size(ymin) /= n .or. size(ymax) /= n) then
410 call errmgr%report_error("pde_define_y_err_lim", &
411 "Input arrays must be the same size.", &
412 plot_array_size_mismatch_error)
413 return
414 end if
415
416 ! Process
417 this%m_xBars = .false.
418 this%m_yBars = .false.
419 this%m_range = .false.
420 if (allocated(this%m_data)) deallocate(this%m_data)
421 allocate(this%m_data(n, 4), stat = flag)
422 if (flag /= 0) then
423 call errmgr%report_error("pde_define_y_err_lim", &
424 "Insufficient memory available.", plot_out_of_memory_error)
425 return
426 end if
427 do i = 1, n
428 this%m_data(i, 1) = x(i)
429 this%m_data(i, 2) = y(i)
430 this%m_data(i, 3) = ymin(i)
431 this%m_data(i, 4) = ymax(i)
432 end do
433 this%m_yBars = .true.
434 this%m_range = .true.
435 end subroutine
436! ------------------------------------------------------------------------------
437 module subroutine pde_define_xy_err_lim(this, x, y, xmin, xmax, ymin, ymax, err)
438 ! Arguments
439 class(plot_data_error_bars), intent(inout) :: this
440 real(real64), intent(in), dimension(:) :: x, y, xmin, xmax, &
441 ymin, ymax
442 class(errors), intent(inout), optional, target :: err
443
444 ! Local Variables
445 integer(int32) :: i, n, flag
446 class(errors), pointer :: errmgr
447 type(errors), target :: deferr
448
449 ! Initialization
450 n = size(x)
451 if (present(err)) then
452 errmgr => err
453 else
454 errmgr => deferr
455 end if
456
457 ! Input Checking
458 if (size(y) /= n .or. size(ymin) /= n .or. size(ymax) /= n) then
459 call errmgr%report_error("pde_define_xy_err_lim", &
460 "Input arrays must be the same size.", &
461 plot_array_size_mismatch_error)
462 return
463 end if
464
465 ! Process
466 this%m_xBars = .false.
467 this%m_yBars = .false.
468 this%m_range = .false.
469 if (allocated(this%m_data)) deallocate(this%m_data)
470 allocate(this%m_data(n, 6), stat = flag)
471 if (flag /= 0) then
472 call errmgr%report_error("pde_define_xy_err_lim", &
473 "Insufficient memory available.", plot_out_of_memory_error)
474 return
475 end if
476 do i = 1, n
477 this%m_data(i, 1) = x(i)
478 this%m_data(i, 2) = y(i)
479 this%m_data(i, 3) = xmin(i)
480 this%m_data(i, 4) = xmax(i)
481 this%m_data(i, 5) = ymin(i)
482 this%m_data(i, 6) = ymax(i)
483 end do
484 this%m_xBars = .true.
485 this%m_yBars = .true.
486 this%m_range = .true.
487 end subroutine
488
489! ------------------------------------------------------------------------------
490end submodule
fplot_core