fplot 1.7.1
A Fortran library providing a convenient interface for plotting with Gnuplot.
Loading...
Searching...
No Matches
fplot_plot_data_2d.f90
1! fplot_plot_data_2d.f90
2
3submodule(fplot_core) fplot_plot_data_2d
4contains
5! ------------------------------------------------------------------------------
6 module function pd2d_get_axes_cmd(this) result(x)
7 ! Arguments
8 class(plot_data_2d), intent(in) :: this
9 character(len = :), allocatable :: x
10
11 ! Define which axes the data is to be plotted against
12 if (this%get_draw_against_y2()) then
13 x = "axes x1y2"
14 else
15 x = "axes x1y1"
16 end if
17 end function
18
19! ------------------------------------------------------------------------------
20 module function pd2d_get_data_cmd(this) result(x)
21 ! Arguments
22 class(plot_data_2d), intent(in) :: this
23 character(len = :), allocatable :: x
24
25 ! Local Variables
26 type(string_builder) :: str
27 integer(int32) :: i
28 character :: delimiter, nl
29 real(real64), allocatable, dimension(:) :: xv, yv, cv, ps
30 real(real64), allocatable, dimension(:,:) :: pts
31 real(real64) :: tol, maxy, miny, eps
32 logical :: usecolors, usevarpoints
33
34 ! Initialization
35 call str%initialize()
36 delimiter = achar(9) ! tab delimiter
37 nl = new_line(nl)
38 usecolors = this%get_use_data_dependent_colors()
39 usevarpoints = this%get_use_variable_size_points()
40
41 ! Process
42 xv = this%get_x_data()
43 yv = this%get_y_data()
44 if (usecolors .and. usevarpoints) then
45 cv = this%get_color_data()
46 ps = this%get_point_size_data()
47 do i = 1, size(xv)
48 call str%append(to_string(xv(i)))
49 call str%append(delimiter)
50 call str%append(to_string(yv(i)))
51 call str%append(delimiter)
52 call str%append(to_string(ps(i)))
53 call str%append(delimiter)
54 call str%append(to_string(cv(i)))
55 call str%append(nl)
56 end do
57 else if (usecolors .and. .not.usevarpoints) then
58 cv = this%get_color_data()
59 do i = 1, size(xv)
60 call str%append(to_string(xv(i)))
61 call str%append(delimiter)
62 call str%append(to_string(yv(i)))
63 call str%append(delimiter)
64 call str%append(to_string(cv(i)))
65 call str%append(nl)
66 end do
67 else if (.not.usecolors .and. usevarpoints) then
68 ps = this%get_point_size_data()
69 do i = 1, size(xv)
70 call str%append(to_string(xv(i)))
71 call str%append(delimiter)
72 call str%append(to_string(yv(i)))
73 call str%append(delimiter)
74 call str%append(to_string(ps(i)))
75 call str%append(nl)
76 end do
77 else
78 if (this%get_simplify_data()) then
79 maxy = maxval(yv)
80 miny = minval(yv)
81 tol = abs(this%get_simplification_factor() * (maxy - miny))
82 eps = 10.0d0 * epsilon(eps)
83 if (tol < eps) tol = eps
84 pts = simplify_polyline(xv, yv, tol)
85 do i = 1, size(pts, 1)
86 call str%append(to_string(pts(i,1)))
87 call str%append(delimiter)
88 call str%append(to_string(pts(i,2)))
89 call str%append(nl)
90 end do
91 else
92 do i = 1, size(xv)
93 call str%append(to_string(xv(i)))
94 call str%append(delimiter)
95 call str%append(to_string(yv(i)))
96 call str%append(nl)
97 end do
98 end if
99 end if
100
101 ! End
102 x = char(str%to_string())
103 end function
104
105! ------------------------------------------------------------------------------
106 pure module function pd2d_get_data_count(this) result(x)
107 class(plot_data_2d), intent(in) :: this
108 integer(int32) :: x
109 if (allocated(this%m_data)) then
110 x = size(this%m_data, 1)
111 else
112 x = 0
113 end if
114 end function
115
116! ------------------------------------------------------------------------------
117 pure module function pd2d_get_x_data(this, index) result(x)
118 class(plot_data_2d), intent(in) :: this
119 integer(int32), intent(in) :: index
120 real(real64) :: x
121 if (allocated(this%m_data)) then
122 x = this%m_data(index, 1)
123 else
124 x = 0.0d0
125 end if
126 end function
127
128! --------------------
129 module subroutine pd2d_set_x_data(this, index, x)
130 class(plot_data_2d), intent(inout) :: this
131 integer(int32), intent(in) :: index
132 real(real64), intent(in) :: x
133 if (allocated(this%m_data)) then
134 this%m_data(index, 1) = x
135 end if
136 end subroutine
137
138! ------------------------------------------------------------------------------
139 pure module function pd2d_get_y_data(this, index) result(x)
140 class(plot_data_2d), intent(in) :: this
141 integer(int32), intent(in) :: index
142 real(real64) :: x
143 if (allocated(this%m_data)) then
144 x = this%m_data(index, 2)
145 else
146 x = 0.0d0
147 end if
148 end function
149
150! --------------------
151 module subroutine pd2d_set_y_data(this, index, x)
152 class(plot_data_2d), intent(inout) :: this
153 integer(int32), intent(in) :: index
154 real(real64), intent(in) :: x
155 if (allocated(this%m_data)) then
156 this%m_data(index, 2) = x
157 end if
158 end subroutine
159
160! ------------------------------------------------------------------------------
161 module subroutine pd2d_set_data_1(this, x, y, c, ps, err)
162 ! Arguments
163 class(plot_data_2d), intent(inout) :: this
164 real(real64), intent(in), dimension(:) :: x, y
165 real(real64), intent(in), dimension(:), optional :: c, ps
166 class(errors), intent(inout), optional, target :: err
167
168 ! Local Variables
169 integer(int32) :: i, n, flag, ncols
170 class(errors), pointer :: errmgr
171 type(errors), target :: deferr
172
173 ! Initialization
174 n = size(x)
175 ncols = 2
176 if (present(c)) ncols = ncols + 1
177 if (present(ps)) ncols = ncols + 1
178 if (present(err)) then
179 errmgr => err
180 else
181 errmgr => deferr
182 end if
183
184 ! Input Check
185 if (size(y) /= n) then
186 call errmgr%report_error("pd2d_set_data_1", &
187 "The input arrays are not the same size.", &
188 plot_array_size_mismatch_error)
189 return
190 end if
191 if (present(c)) then
192 if (size(c) /= n) then
193 call errmgr%report_error("pd2d_set_data_1", &
194 "The input arrays are not the same size.", &
195 plot_array_size_mismatch_error)
196 return
197 end if
198 end if
199 if (present(ps)) then
200 if (size(ps) /= n) then
201 call errmgr%report_error("pd2d_set_data_1", &
202 "The input arrays are not the same size.", &
203 plot_array_size_mismatch_error)
204 return
205 end if
206 end if
207
208 ! Process
209 if (allocated(this%m_data)) deallocate(this%m_data)
210 allocate(this%m_data(n, ncols), stat = flag)
211 if (flag /= 0) then
212 call errmgr%report_error("pd2d_set_data_1", &
213 "Insufficient memory available.", plot_out_of_memory_error)
214 return
215 end if
216 ! if (present(c)) then
217 ! call this%set_use_data_dependent_colors(.true.)
218 ! do concurrent (i = 1:n)
219 ! this%m_data(i, 1) = x(i)
220 ! this%m_data(i, 2) = y(i)
221 ! this%m_data(i, 3) = c(i)
222 ! end do
223 ! else
224 ! call this%set_use_data_dependent_colors(.false.)
225 ! do concurrent (i = 1:n)
226 ! this%m_data(i, 1) = x(i)
227 ! this%m_data(i, 2) = y(i)
228 ! end do
229 ! end if
230 if (present(c) .and. present(ps)) then
231 call this%set_use_data_dependent_colors(.true.)
232 call this%set_use_variable_size_points(.true.)
233 do concurrent(i = 1:n)
234 this%m_data(i, 1) = x(i)
235 this%m_data(i, 2) = y(i)
236 this%m_data(i, 3) = ps(i)
237 this%m_data(i, 4) = c(i)
238 end do
239 else if (present(c) .and. .not.present(ps)) then
240 call this%set_use_data_dependent_colors(.true.)
241 call this%set_use_variable_size_points(.false.)
242 do concurrent(i = 1:n)
243 this%m_data(i, 1) = x(i)
244 this%m_data(i, 2) = y(i)
245 this%m_data(i, 3) = c(i)
246 end do
247 else if (.not.present(c) .and. present(ps)) then
248 call this%set_use_data_dependent_colors(.false.)
249 call this%set_use_variable_size_points(.true.)
250 do concurrent(i = 1:n)
251 this%m_data(i, 1) = x(i)
252 this%m_data(i, 2) = y(i)
253 this%m_data(i, 3) = ps(i)
254 end do
255 else
256 call this%set_use_data_dependent_colors(.false.)
257 call this%set_use_variable_size_points(.false.)
258 do concurrent(i = 1:n)
259 this%m_data(i, 1) = x(i)
260 this%m_data(i, 2) = y(i)
261 end do
262 end if
263 end subroutine
264
265! ------------------------------------------------------------------------------
266 pure module function pd2d_get_draw_against_y2(this) result(x)
267 class(plot_data_2d), intent(in) :: this
268 logical :: x
269 x = this%m_useY2
270 end function
271
272! --------------------
273 module subroutine pd2d_set_draw_against_y2(this, x)
274 class(plot_data_2d), intent(inout) :: this
275 logical, intent(in) :: x
276 this%m_useY2 = x
277 end subroutine
278
279! ------------------------------------------------------------------------------
280 module subroutine pd2d_set_data_2(this, y, err)
281 ! Arguments
282 class(plot_data_2d), intent(inout) :: this
283 real(real64), intent(in), dimension(:) :: y
284 class(errors), intent(inout), optional, target :: err
285
286 ! Local Variables
287 integer(int32) :: i, n, flag
288 class(errors), pointer :: errmgr
289 type(errors), target :: deferr
290
291 ! Initialization
292 n = size(y)
293 if (present(err)) then
294 errmgr => err
295 else
296 errmgr => deferr
297 end if
298
299 ! Process
300 if (allocated(this%m_data)) deallocate(this%m_data)
301 allocate(this%m_data(n, 2), stat = flag)
302 if (flag /= 0) then
303 call errmgr%report_error("pd2d_set_data_2", &
304 "Insufficient memory available.", plot_out_of_memory_error)
305 return
306 end if
307 do concurrent(i = 1:n)
308 this%m_data(i, 1) = real(i, real64)
309 this%m_data(i, 2) = y(i)
310 end do
311 end subroutine
312
313! ------------------------------------------------------------------------------
314 module function pd2d_get_x_array(this) result(x)
315 ! Arguments
316 class(plot_data_2d), intent(in) :: this
317 real(real64), allocatable, dimension(:) :: x
318
319 ! Process
320 if (allocated(this%m_data)) then
321 x = this%m_data(:,1)
322 end if
323 end function
324
325! ------------------------------------------------------------------------------
326 module function pd2d_get_y_array(this) result(x)
327 ! Arguments
328 class(plot_data_2d), intent(in) :: this
329 real(real64), allocatable, dimension(:) :: x
330
331 ! Process
332 if (allocated(this%m_data)) then
333 x = this%m_data(:,2)
334 end if
335 end function
336
337! ******************************************************************************
338! ADDED: OCT. 8, 2020 - JAC
339! ------------------------------------------------------------------------------
340 module function pd2d_get_c_array(this) result(x)
341 ! Arguments
342 class(plot_data_2d), intent(in) :: this
343 real(real64), allocatable, dimension(:) :: x
344
345 ! Process
346 if (allocated(this%m_data)) then
347 if (size(this%m_data, 2) == 3) then
348 x = this%m_data(:,3)
349 else if (size(this%m_data, 2) == 4) then
350 x = this%m_data(:,4)
351 end if
352 end if
353 end function
354
355! ******************************************************************************
356! ADDED: JAN. 12, 2024 - JAC
357! ------------------------------------------------------------------------------
358 module function pd2d_get_ps_array(this) result(x)
359 ! Arguments
360 class(plot_data_2d), intent(in) :: this
361 real(real64), allocatable, dimension(:) :: x
362
363 ! Process
364 if (allocated(this%m_data)) then
365 if (size(this%m_data, 2) > 2) then
366 x = this%m_data(:,3)
367 end if
368 end if
369 end function
370
371! ------------------------------------------------------------------------------
372end submodule
fplot_core