fplot 1.7.1
A Fortran library providing a convenient interface for plotting with Gnuplot.
Loading...
Searching...
No Matches
fplot_vector_field_plot_data.f90
1! fplot_vector_field_plot_data.f90
2
3submodule(fplot_core) fplot_vector_field_plot_data
4contains
5! ------------------------------------------------------------------------------
6 module function vfpd_get_data_cmd(this) result(x)
7 ! Arguments
8 class(vector_field_plot_data), intent(in) :: this
9 character(len = :), allocatable :: x
10
11 ! Local Variables
12 type(string_builder) :: str
13 integer(int32) :: i, j, m, n
14 character :: delimiter, nl
15 real(real64) :: scaling
16
17 ! Initialization
18 call str%initialize()
19 delimiter = achar(9) ! tab delimiter
20 nl = new_line(nl)
21 scaling = this%get_arrow_size()
22
23 ! Fix later
24 m = size(this%m_data, 1)
25 n = size(this%m_data, 2)
26
27 ! Need a quick return in the event no data exists
28
29 ! Process
30 if (this%get_use_data_dependent_colors()) then
31 do j = 1, n
32 do i = 1, m
33 ! ORDER: X, Y, DX, DY
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)))
43 call str%append(nl)
44 end do
45 end do
46 else
47 do j = 1, n
48 do i = 1, m
49 ! ORDER: X, Y, DX, DY
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)))
57 call str%append(nl)
58 end do
59 end do
60 end if
61
62 ! End
63 x = char(str%to_string())
64 end function
65
66! ------------------------------------------------------------------------------
67 module function vfpd_get_cmd(this) result(x)
68 ! Arguments
69 class(vector_field_plot_data), intent(in) :: this
70 character(len = :), allocatable :: x
71
72 ! Local Variables
73 type(string_builder) :: str
74 integer(int32) :: n
75 type(color) :: clr
76
77 ! Initialization
78 call str%initialize()
79
80 ! Title
81 n = len_trim(this%get_name())
82 if (n > 0) then
83 call str%append(' "-" title "')
84 call str%append(this%get_name())
85 call str%append('"')
86 else
87 call str%append(' "-" notitle')
88 end if
89
90 ! Property Definition
91 call str%append(" with vectors")
92
93 if (this%get_fill_arrow()) then
94 call str%append(" filled head")
95 end if
96
97 if (this%get_use_data_dependent_colors()) then
98 call str%append(" lc palette")
99 else
100 clr = this%get_line_color()
101 call str%append(' lc rgb "#')
102 call str%append(clr%to_hex_string())
103 call str%append('"')
104 end if
105
106 ! End
107 x = char(str%to_string())
108 end function
109
110! ------------------------------------------------------------------------------
111 module subroutine vfpd_define_data(this, x, y, dx, dy, c, err)
112 ! Arguments
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
117
118 ! Local Variables
119 integer(int32) :: i, j, m, n, flag
120 type(errors), target :: deferr
121 class(errors), pointer :: errmgr
122 character(len = 256) :: errmsg
123
124 ! Set up error handling
125 if (present(err)) then
126 errmgr => err
127 else
128 errmgr => deferr
129 end if
130
131 ! Input Checking
132 m = size(x, 1)
133 n = size(x, 2)
134 if (.not.check_size(y, m, n)) then
135 call write_errmsg("y", size(y, 1), size(y, 2), m, n, errmsg)
136 go to 100
137 end if
138 if (.not.check_size(dx, m, n)) then
139 call write_errmsg("dx", size(y, 1), size(y, 2), m, n, errmsg)
140 go to 100
141 end if
142 if (.not.check_size(dy, m, n)) then
143 call write_errmsg("dy", size(y, 1), size(y, 2), m, n, errmsg)
144 go to 100
145 end if
146 if (present(c)) then
147 if (.not.check_size(c, m, n)) then
148 call write_errmsg("c", size(c, 1), size(c, 2), m, n, errmsg)
149 go to 100
150 end if
151 end if
152
153 ! Allocate space for the data
154 if (allocated(this%m_data)) deallocate(this%m_data)
155 if (present(c)) then
156 allocate(this%m_data(m, n, 5), stat = flag)
157 else
158 allocate(this%m_data(m, n, 4), stat = flag)
159 end if
160 if (flag /= 0) then
161 call errmgr%report_error("vfpd_define_data", &
162 "Insufficient memory available.", &
163 plot_out_of_memory_error)
164 return
165 end if
166
167 ! Store the data
168 if (present(c)) then
169 do concurrent(j = 1:n)
170 do i = 1, m
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)
176 end do
177 end do
178 else
179 do concurrent(j = 1:n)
180 do i = 1, m
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)
185 end do
186 end do
187 end if
188
189 ! End
190 return
191
192 ! Error Handling
193 100 continue
194 call errmgr%report_error("vfpd_define_data", trim(errmsg), &
195 plot_array_size_mismatch_error)
196 return
197
198 contains
199 ! Checks the size of the supplied array (xc) vs the reference row (mref)
200 ! and column (nref) dimensions.
201 !
202 ! Returns true if the array size matches the reference; else, false.
203 function check_size(xc, mref, nref) result(rst)
204 ! Arguments
205 real(real64), intent(in), dimension(:,:) :: xc
206 integer(int32), intent(in) :: mref, nref
207 logical :: rst
208
209 ! Process
210 if (size(xc, 1) /= mref .or. size(xc, 2) /= nref) then
211 rst = .false.
212 else
213 rst = .true.
214 end if
215 end function
216
217 ! Writes an error message regarding array size.
218 subroutine write_errmsg(name, mfound, nfound, mexpect, nexpect, msg)
219 ! Arguments
220 character(len = *), intent(in) :: name
221 integer(int32), intent(in) :: mfound, nfound, mexpect, nexpect
222 character(len = *), intent(out) :: msg
223
224 ! Process
225 write(msg, 200) "Input " // name // &
226 " is not sized correctly. Expected a ", mexpect, "-by-", &
227 nexpect, " matrix, but found a ", mfound, "-by-", nfound, &
228 " matrix."
229200 format(a, i0, a, i0, a, i0, a, i0, a)
230 end subroutine
231 end subroutine
232
233! ------------------------------------------------------------------------------
234 pure module function vfpd_get_arrow_size(this) result(rst)
235 class(vector_field_plot_data), intent(in) :: this
236 real(real64) :: rst
237 rst = this%m_arrowSize
238 end function
239
240! --------------------
241 module subroutine vfpd_set_arrow_size(this, x)
242 class(vector_field_plot_data), intent(inout) :: this
243 real(real64), intent(in) :: x
244 this%m_arrowSize = x
245 end subroutine
246
247! ------------------------------------------------------------------------------
248 pure module function vfpd_get_fill_arrow(this) result(rst)
249 class(vector_field_plot_data), intent(in) :: this
250 logical :: rst
251 rst = this%m_filledHeads
252 end function
253
254! --------------------
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
259 end subroutine
260
261! ------------------------------------------------------------------------------
262 pure module function vfpd_get_use_data_dependent_colors(this) result(rst)
263 class(vector_field_plot_data), intent(in) :: this
264 logical :: rst
265 rst = .false.
266 if (.not.allocated(this%m_data)) return
267 rst = size(this%m_data, 3) >= 5
268 end function
269
270! ------------------------------------------------------------------------------
271
272! ------------------------------------------------------------------------------
273
274! ------------------------------------------------------------------------------
275end submodule
fplot_core