-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfplot_plot_data_2d.f90
More file actions
457 lines (424 loc) · 15.4 KB
/
fplot_plot_data_2d.f90
File metadata and controls
457 lines (424 loc) · 15.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
module fplot_plot_data_2d
use iso_fortran_env
use fplot_plot_data
use fplot_simplify
use fplot_errors
use ferror
use strings
implicit none
private
public :: plot_data_2d
type, extends(scatter_plot_data) :: plot_data_2d
!! Defines a two-dimensional plot data set.
real(real64), private, allocatable, dimension(:,:) :: m_data
!! An N-by-2 matrix containing the x and y data points.
!> Draw against the secondary y axis?
logical, private :: m_useY2 = .false.
!! Draw against the secondary y axis?
contains
procedure, public :: get_axes_string => pd2d_get_axes_cmd
procedure, public :: get_data_string => pd2d_get_data_cmd
procedure, public :: get_count => pd2d_get_data_count
procedure, public :: get_x => pd2d_get_x_data
procedure, public :: set_x => pd2d_set_x_data
procedure, public :: get_y => pd2d_get_y_data
procedure, public :: set_y => pd2d_set_y_data
procedure, public :: get_draw_against_y2 => pd2d_get_draw_against_y2
procedure, public :: set_draw_against_y2 => pd2d_set_draw_against_y2
generic, public :: define_data => pd2d_set_data_1, pd2d_set_data_2
procedure :: pd2d_set_data_1
procedure :: pd2d_set_data_2
procedure, public :: get_x_data => pd2d_get_x_array
procedure, public :: get_y_data => pd2d_get_y_array
procedure, public :: get_color_data => pd2d_get_c_array
procedure, public :: get_point_size_data => pd2d_get_ps_array
end type
contains
! ------------------------------------------------------------------------------
function pd2d_get_axes_cmd(this) result(x)
!! Gets the GNUPLOT command string defining which axes the data
!! is to be plotted against.
class(plot_data_2d), intent(in) :: this
!! The plot_data_2d object.
character(len = :), allocatable :: x
!! The command string.
! Define which axes the data is to be plotted against
if (this%get_draw_against_y2()) then
x = "axes x1y2"
else
x = "axes x1y1"
end if
end function
! ------------------------------------------------------------------------------
function pd2d_get_data_cmd(this) result(x)
!! Gets the GNUPLOT command string containing the actual data
!! to plot.
class(plot_data_2d), intent(in) :: this
!! The plot_data_2d object.
character(len = :), allocatable :: x
!! The command string.
! Local Variables
type(string_builder) :: str
integer(int32) :: i
character :: delimiter, nl
real(real64), allocatable, dimension(:) :: xv, yv, cv, ps
real(real64), allocatable, dimension(:,:) :: pts
real(real64) :: tol, maxy, miny, eps
logical :: usecolors, usevarpoints
! Initialization
call str%initialize()
delimiter = achar(9) ! tab delimiter
nl = new_line(nl)
usecolors = this%get_use_data_dependent_colors()
usevarpoints = this%get_use_variable_size_points()
! Process
xv = this%get_x_data()
yv = this%get_y_data()
if (usecolors .and. usevarpoints) then
cv = this%get_color_data()
ps = this%get_point_size_data()
do i = 1, size(xv)
call str%append(to_string(xv(i)))
call str%append(delimiter)
call str%append(to_string(yv(i)))
call str%append(delimiter)
call str%append(to_string(ps(i)))
call str%append(delimiter)
call str%append(to_string(cv(i)))
call str%append(nl)
end do
else if (usecolors .and. .not.usevarpoints) then
cv = this%get_color_data()
do i = 1, size(xv)
call str%append(to_string(xv(i)))
call str%append(delimiter)
call str%append(to_string(yv(i)))
call str%append(delimiter)
call str%append(to_string(cv(i)))
call str%append(nl)
end do
else if (.not.usecolors .and. usevarpoints) then
ps = this%get_point_size_data()
do i = 1, size(xv)
call str%append(to_string(xv(i)))
call str%append(delimiter)
call str%append(to_string(yv(i)))
call str%append(delimiter)
call str%append(to_string(ps(i)))
call str%append(nl)
end do
else
if (this%get_simplify_data()) then
maxy = maxval(yv)
miny = minval(yv)
tol = abs(this%get_simplification_factor() * (maxy - miny))
eps = 10.0d0 * epsilon(eps)
if (tol < eps) tol = eps
pts = simplify_polyline(xv, yv, tol)
do i = 1, size(pts, 1)
call str%append(to_string(pts(i,1)))
call str%append(delimiter)
call str%append(to_string(pts(i,2)))
call str%append(nl)
end do
else
do i = 1, size(xv)
call str%append(to_string(xv(i)))
call str%append(delimiter)
call str%append(to_string(yv(i)))
call str%append(nl)
end do
end if
end if
! End
x = char(str%to_string())
end function
! ------------------------------------------------------------------------------
pure function pd2d_get_data_count(this) result(x)
!! Gets the number of data points.
class(plot_data_2d), intent(in) :: this
!! The plot_data_2d object.
integer(int32) :: x
!! The number of data points.
if (allocated(this%m_data)) then
x = size(this%m_data, 1)
else
x = 0
end if
end function
! ------------------------------------------------------------------------------
pure function pd2d_get_x_data(this, index) result(x)
!! Gets the requested X data point.
class(plot_data_2d), intent(in) :: this
!! The plot_data_2d object.
integer(int32), intent(in) :: index
!! The index of the data point to retrieve.
real(real64) :: x
!! The requested data point.
if (allocated(this%m_data)) then
x = this%m_data(index, 1)
else
x = 0.0d0
end if
end function
! --------------------
subroutine pd2d_set_x_data(this, index, x)
!! Sets the requested X data point.
class(plot_data_2d), intent(inout) :: this
!! The plot_data_2d object.
integer(int32), intent(in) :: index
!! The index of the data point to replace.
real(real64), intent(in) :: x
!! The data point.
if (allocated(this%m_data)) then
this%m_data(index, 1) = x
end if
end subroutine
! ------------------------------------------------------------------------------
pure function pd2d_get_y_data(this, index) result(x)
!! Gets the requested Y data point.
class(plot_data_2d), intent(in) :: this
!! The plot_data_2d object.
integer(int32), intent(in) :: index
!! The index of the data point to retrieve.
real(real64) :: x
!! The requested data point.
if (allocated(this%m_data)) then
x = this%m_data(index, 2)
else
x = 0.0d0
end if
end function
! --------------------
subroutine pd2d_set_y_data(this, index, x)
!! Sets the requested Y data point.
class(plot_data_2d), intent(inout) :: this
!! The plot_data_2d object.
integer(int32), intent(in) :: index
!! The index of the data point to replace.
real(real64), intent(in) :: x
!! The data point.
if (allocated(this%m_data)) then
this%m_data(index, 2) = x
end if
end subroutine
! ------------------------------------------------------------------------------
subroutine pd2d_set_data_1(this, x, y, c, ps, err)
!! Defines the data set to plot.
class(plot_data_2d), intent(inout) :: this
!! The plot_data_2d object.
real(real64), intent(in), dimension(:) :: x
!! An N-element array containing the x coordinate data.
real(real64), intent(in), dimension(:) :: y
!! An N-element array containing the y coordinate data.
real(real64), intent(in), dimension(:), optional :: c
!! An N-element array defining how color should vary with the
!! current colormap for each value.
real(real64), intent(in), dimension(:), optional :: ps
!! An N-element array defining the size of each data point.
class(errors), intent(inout), optional, target :: err
!! An error-handling object.
! Local Variables
integer(int32) :: i, n, flag, ncols
class(errors), pointer :: errmgr
type(errors), target :: deferr
! Initialization
n = size(x)
ncols = 2
if (present(c)) ncols = ncols + 1
if (present(ps)) ncols = ncols + 1
if (present(err)) then
errmgr => err
else
errmgr => deferr
end if
! Input Check
if (size(y) /= n) then
call report_array_size_mismatch_error(errmgr, "pd2d_set_data_1", &
"y", n, size(y))
return
end if
if (present(c)) then
if (size(c) /= n) then
call report_array_size_mismatch_error(errmgr, &
"pd2d_set_data_1", "c", n, size(c))
return
end if
end if
if (present(ps)) then
if (size(ps) /= n) then
call report_array_size_mismatch_error(errmgr, &
"pd2d_set_data_1", "ps", n, size(ps))
return
end if
end if
! Process
if (allocated(this%m_data)) deallocate(this%m_data)
allocate(this%m_data(n, ncols), stat = flag)
if (flag /= 0) then
call report_memory_error(errmgr, "pd2d_set_data_1", flag)
return
end if
! if (present(c)) then
! call this%set_use_data_dependent_colors(.true.)
! do concurrent (i = 1:n)
! this%m_data(i, 1) = x(i)
! this%m_data(i, 2) = y(i)
! this%m_data(i, 3) = c(i)
! end do
! else
! call this%set_use_data_dependent_colors(.false.)
! do concurrent (i = 1:n)
! this%m_data(i, 1) = x(i)
! this%m_data(i, 2) = y(i)
! end do
! end if
if (present(c) .and. present(ps)) then
call this%set_use_data_dependent_colors(.true.)
call this%set_use_variable_size_points(.true.)
do concurrent (i = 1:n)
this%m_data(i, 1) = x(i)
this%m_data(i, 2) = y(i)
this%m_data(i, 3) = ps(i)
this%m_data(i, 4) = c(i)
end do
else if (present(c) .and. .not.present(ps)) then
call this%set_use_data_dependent_colors(.true.)
call this%set_use_variable_size_points(.false.)
do concurrent (i = 1:n)
this%m_data(i, 1) = x(i)
this%m_data(i, 2) = y(i
C2D0
)
this%m_data(i, 3) = c(i)
end do
else if (.not.present(c) .and. present(ps)) then
call this%set_use_data_dependent_colors(.false.)
call this%set_use_variable_size_points(.true.)
do concurrent (i = 1:n)
this%m_data(i, 1) = x(i)
this%m_data(i, 2) = y(i)
this%m_data(i, 3) = ps(i)
end do
else
call this%set_use_data_dependent_colors(.false.)
call this%set_use_variable_size_points(.false.)
do concurrent (i = 1:n)
this%m_data(i, 1) = x(i)
this%m_data(i, 2) = y(i)
end do
end if
end subroutine
! ------------------------------------------------------------------------------
pure function pd2d_get_draw_against_y2(this) result(x)
!! Gets a value determining if the data should be plotted against
!! the secondary y-axis.
class(plot_data_2d), intent(in) :: this
!! The plot_data_2d object.
logical :: x
!! Returns true if the data should be plotted against the secondary
!! y-axis; else, false to plot against the primary y-axis.
x = this%m_useY2
end function
! --------------------
subroutine pd2d_set_draw_against_y2(this, x)
!! Sets a value determining if the data should be plotted against
!! the secondary y-axis.
class(plot_data_2d), intent(inout) :: this
!! The plot_data_2d object.
logical, intent(in) :: x
!! Set to true if the data should be plotted against the
!! secondary y-axis; else, false to plot against the primary y-axis.
this%m_useY2 = x
end subroutine
! ------------------------------------------------------------------------------
subroutine pd2d_set_data_2(this, y, err)
!! Defines the data set to plot.
class(plot_data_2d), intent(inout) :: this
!! The plot_data_2d object.
real(real64), intent(in), dimension(:) :: y
!! An N-element array containing the y-coordinate data. This
!! data will be plotted against its own index.
class(errors), intent(inout), optional, target :: err
!! An error-handling object.
! Local Variables
integer(int32) :: i, n, flag
class(errors), pointer :: errmgr
type(errors), target :: deferr
! Initialization
n = size(y)
if (present(err)) then
errmgr => err
else
errmgr => deferr
end if
! Process
if (allocated(this%m_data)) deallocate(this%m_data)
allocate(this%m_data(n, 2), stat = flag)
if (flag /= 0) then
call report_memory_error(errmgr, "pd2d_set_data_2", flag)
return
end if
do concurrent (i = 1:n)
this%m_data(i, 1) = real(i, real64)
this%m_data(i, 2) = y(i)
end do
end subroutine
! ------------------------------------------------------------------------------
function pd2d_get_x_array(this) result(x)
!! Gets the stored X data array.
class(plot_data_2d), intent(in) :: this
!! The plot_data_2d object.
real(real64), allocatable, dimension(:) :: x
!! A copy of the stored data array.
! Process
if (allocated(this%m_data)) then
x = this%m_data(:,1)
end if
end function
! ------------------------------------------------------------------------------
function pd2d_get_y_array(this) result(x)
!! Gets the stored Y data array.
class(plot_data_2d), intent(in) :: this
!! The plot_data_2d object.
real(real64), allocatable, dimension(:) :: x
!! A copy of the stored data array.
! Process
if (allocated(this%m_data)) then
x = this%m_data(:,2)
end if
end function
! ******************************************************************************
! ADDED: OCT. 8, 2020 - JAC
! ------------------------------------------------------------------------------
function pd2d_get_c_array(this) result(x)
!! Gets the stored color scaling data array.
class(plot_data_2d), intent(in) :: this
!! The plot_data_2d object.
real(real64), allocatable, dimension(:) :: x
!! A copy of the stored data array.
! Process
if (allocated(this%m_data)) then
if (size(this%m_data, 2) == 3) then
x = this%m_data(:,3)
else if (size(this%m_data, 2) == 4) then
x = this%m_data(:,4)
end if
end if
end function
! ******************************************************************************
! ADDED: JAN. 12, 2024 - JAC
! ------------------------------------------------------------------------------
function pd2d_get_ps_array(this) result(x)
!! Gets the stored point size data array.
class(plot_data_2d), intent(in) :: this
!! The plot_data_2d object.
real(real64), allocatable, dimension(:) :: x
!! A copy of the stored data array.
! Process
if (allocated(this%m_data)) then
if (size(this%m_data, 2) > 2) then
x = this%m_data(:,3)
end if
end if
end function
! ------------------------------------------------------------------------------
end module