3submodule(
fplot_core) fplot_vector_field_plot_data
6 module function vfpd_get_data_cmd(this) result(x)
8 class(vector_field_plot_data),
intent(in) :: this
9 character(len = :),
allocatable :: x
12 type(string_builder) :: str
13 integer(int32) :: i, j, m, n
14 character :: delimiter, nl
15 real(real64) :: scaling
21 scaling = this%get_arrow_size()
24 m =
size(this%m_data, 1)
25 n =
size(this%m_data, 2)
30 if (this%get_use_data_dependent_colors())
then
34 call str%append(to_string(this%m_data(i,j,1)))
35 call str%append(delimiter)
36 call str%append(to_string(this%m_data(i,j,2)))
37 call str%append(delimiter)
38 call str%append(to_string(scaling * this%m_data(i,j,3)))
39 call str%append(delimiter)
40 call str%append(to_string(scaling * this%m_data(i,j,4)))
41 call str%append(delimiter)
42 call str%append(to_string(this%m_data(i,j,5)))
50 call str%append(to_string(this%m_data(i,j,1)))
51 call str%append(delimiter)
52 call str%append(to_string(this%m_data(i,j,2)))
53 call str%append(delimiter)
54 call str%append(to_string(scaling * this%m_data(i,j,3)))
55 call str%append(delimiter)
56 call str%append(to_string(scaling * this%m_data(i,j,4)))
63 x = char(str%to_string())
67 module function vfpd_get_cmd(this) result(x)
69 class(vector_field_plot_data),
intent(in) :: this
70 character(len = :),
allocatable :: x
73 type(string_builder) :: str
81 n = len_trim(this%get_name())
83 call str%append(
' "-" title "')
84 call str%append(this%get_name())
87 call str%append(
' "-" notitle')
91 call str%append(
" with vectors")
93 if (this%get_fill_arrow())
then
94 call str%append(
" filled head")
97 if (this%get_use_data_dependent_colors())
then
98 call str%append(
" lc palette")
100 clr = this%get_line_color()
101 call str%append(
' lc rgb "#')
102 call str%append(clr%to_hex_string())
107 x = char(str%to_string())
111 module subroutine vfpd_define_data(this, x, y, dx, dy, c, err)
113 class(vector_field_plot_data),
intent(inout) :: this
114 real(real64),
intent(in),
dimension(:,:) :: x, y, dx, dy
115 real(real64),
intent(in),
dimension(:,:),
optional :: c
116 class(errors),
intent(inout),
optional,
target :: err
119 integer(int32) :: i, j, m, n, flag
120 type(errors),
target :: deferr
121 class(errors),
pointer :: errmgr
122 character(len = 256) :: errmsg
125 if (
present(err))
then
134 if (.not.check_size(y, m, n))
then
135 call write_errmsg(
"y",
size(y, 1),
size(y, 2), m, n, errmsg)
138 if (.not.check_size(dx, m, n))
then
139 call write_errmsg(
"dx",
size(y, 1),
size(y, 2), m, n, errmsg)
142 if (.not.check_size(dy, m, n))
then
143 call write_errmsg(
"dy",
size(y, 1),
size(y, 2), m, n, errmsg)
147 if (.not.check_size(c, m, n))
then
148 call write_errmsg(
"c",
size(c, 1),
size(c, 2), m, n, errmsg)
154 if (
allocated(this%m_data))
deallocate(this%m_data)
156 allocate(this%m_data(m, n, 5), stat = flag)
158 allocate(this%m_data(m, n, 4), stat = flag)
161 call errmgr%report_error(
"vfpd_define_data", &
162 "Insufficient memory available.", &
163 plot_out_of_memory_error)
169 do concurrent(j = 1:n)
171 this%m_data(i,j,1) = x(i,j)
172 this%m_data(i,j,2) = y(i,j)
173 this%m_data(i,j,3) = dx(i,j)
174 this%m_data(i,j,4) = dy(i,j)
175 this%m_data(i,j,5) = c(i,j)
179 do concurrent(j = 1:n)
181 this%m_data(i,j,1) = x(i,j)
182 this%m_data(i,j,2) = y(i,j)
183 this%m_data(i,j,3) = dx(i,j)
184 this%m_data(i,j,4) = dy(i,j)
194 call errmgr%report_error(
"vfpd_define_data", trim(errmsg), &
195 plot_array_size_mismatch_error)
203 function check_size(xc, mref, nref)
result(rst)
205 real(real64),
intent(in),
dimension(:,:) :: xc
206 integer(int32),
intent(in) :: mref, nref
210 if (
size(xc, 1) /= mref .or.
size(xc, 2) /= nref)
then
218 subroutine write_errmsg(name, mfound, nfound, mexpect, nexpect, msg)
220 character(len = *),
intent(in) :: name
221 integer(int32),
intent(in) :: mfound, nfound, mexpect, nexpect
222 character(len = *),
intent(out) :: msg
225 write(msg, 200)
"Input " // name // &
226 " is not sized correctly. Expected a ", mexpect,
"-by-", &
227 nexpect,
" matrix, but found a ", mfound,
"-by-", nfound, &
229200
format(a, i0, a, i0, a, i0, a, i0, a)
234 pure module function vfpd_get_arrow_size(this) result(rst)
235 class(vector_field_plot_data),
intent(in) :: this
237 rst = this%m_arrowSize
241 module subroutine vfpd_set_arrow_size(this, x)
242 class(vector_field_plot_data),
intent(inout) :: this
243 real(real64),
intent(in) :: x
248 pure module function vfpd_get_fill_arrow(this) result(rst)
249 class(vector_field_plot_data),
intent(in) :: this
251 rst = this%m_filledHeads
255 module subroutine vfpd_set_fill_arrow(this, x)
256 class(vector_field_plot_data),
intent(inout) :: this
257 logical,
intent(in) :: x
258 this%m_filledHeads = x
262 pure module function vfpd_get_use_data_dependent_colors(this) result(rst)
263 class(vector_field_plot_data),
intent(in) :: this
266 if (.not.
allocated(this%m_data))
return
267 rst =
size(this%m_data, 3) >= 5