9 module function simplify_polyline_2d1(x, y, tol, err) result(ln)
11 real(real64),
intent(in),
dimension(:) :: x, y
12 real(real64),
intent(in) :: tol
13 class(errors),
intent(inout),
optional,
target :: err
14 real(real64),
allocatable,
dimension(:,:) :: ln
17 class(errors),
pointer :: errmgr
18 type(errors),
target :: deferr
19 character(len = 256) :: errmsg
26 if (
present(err))
then
33 if (
size(y) /= n)
then
34 write(errmsg, 100)
"The array sizes did not match. " // &
35 "The x array contained ",
size(x), &
36 " items, but the y array contained ",
size(y),
"."
37 call errmgr%report_error(
"simplify_polyline_2d1", trim(errmsg), &
38 plot_array_size_mismatch_error)
43 call errmgr%report_error(
"simplify_polyline_2d1", &
44 "The tolerance value is either negative or less " // &
45 "than machine precision.", plot_invalid_input_error)
50 ln = radial_distance_2d(x, y, tol, err)
52100
format(a, i0, a, i0, a)
56 module function simplify_polyline_3d1(x, y, z, tol, err) result(ln)
58 real(real64),
intent(in),
dimension(:) :: x, y, z
59 real(real64),
intent(in) :: tol
60 class(errors),
intent(inout),
optional,
target :: err
61 real(real64),
allocatable,
dimension(:,:) :: ln
64 class(errors),
pointer :: errmgr
65 type(errors),
target :: deferr
66 character(len = 256) :: errmsg
73 if (
present(err))
then
80 if (
size(y) /= n .or.
size(z) /= n)
then
81 write(errmsg, 100)
"The array sizes did not match. " // &
82 "The x array contained ",
size(x), &
83 " items, the y array contained ",
size(y), &
84 ", and the z array contained ",
size(z),
"."
85 call errmgr%report_error(
"simplify_polyline_3d1", trim(errmsg), &
86 plot_array_size_mismatch_error)
91 call errmgr%report_error(
"simplify_polyline_3d1", &
92 "The tolerance value is either negative or less " // &
93 "than machine precision.", plot_invalid_input_error)
98 ln = radial_distance_3d(x, y, z, tol, errmgr)
100100
format(a, i0, a, i0, a, i0, a)
105 module function simplify_polyline_mtx(xy, tol, err) result(ln)
107 real(real64),
intent(in),
dimension(:,:) :: xy
108 real(real64),
intent(in) :: tol
109 class(errors),
intent(inout),
optional,
target :: err
110 real(real64),
allocatable,
dimension(:,:) :: ln
113 class(errors),
pointer :: errmgr
114 type(errors),
target :: deferr
115 character(len = 256) :: errmsg
118 if (
present(err))
then
125 if (
size(xy, 2) < 2)
then
126 write(errmsg, 100)
"The input matrix must have at " // &
127 "least 2 columns; however, only ",
size(xy, 2),
" was found."
128 call errmgr%report_error(
"simplify_polyline_mtx", trim(errmsg), &
129 plot_array_size_mismatch_error)
134 if (
size(xy, 2) == 2)
then
135 ln = simplify_polyline_2d1(xy(:,1), xy(:,2), tol, errmgr)
137 ln = simplify_polyline_3d1(xy(:,1), xy(:,2), xy(:,3), tol, errmgr)
145 function radial_distance_2d(x, y, tol, err)
result(pts)
147 real(real64),
intent(in),
dimension(:) :: x, y
148 real(real64),
intent(in) :: tol
149 class(errors),
intent(inout) :: err
150 real(real64),
allocatable,
dimension(:,:) :: pts
153 integer(int32) :: i, j, n, nvalid, flag
154 logical,
allocatable,
dimension(:) :: valid
155 real(real64) :: r, xref, yref
166 allocate(valid(n), stat = flag)
168 call err%report_error(
"radial_distance_2d", &
169 "Insufficient memory available.", &
170 plot_out_of_memory_error)
178 r = pythag2(x(i), y(i), xref, yref)
195 allocate(pts(nvalid, 2), stat = flag)
197 call err%report_error(
"radial_distance_2d", &
198 "Insufficient memory available.", &
199 plot_out_of_memory_error)
213 function radial_distance_3d(x, y, z, tol, err)
result(pts)
215 real(real64),
intent(in),
dimension(:) :: x, y, z
216 real(real64),
intent(in) :: tol
217 class(errors),
intent(inout) :: err
218 real(real64),
allocatable,
dimension(:,:) :: pts
221 integer(int32) :: i, j, n, nvalid, flag
222 logical,
allocatable,
dimension(:) :: valid
223 real(real64) :: r, xref, yref, zref
235 allocate(valid(n), stat = flag)
237 call err%report_error(
"radial_distance_3d", &
238 "Insufficient memory available.", &
239 plot_out_of_memory_error)
247 r = pythag3(x(i), y(i), z(i), xref, yref, zref)
265 allocate(pts(nvalid, 3), stat = flag)
267 call err%report_error(
"radial_distance_3d", &
268 "Insufficient memory available.", &
269 plot_out_of_memory_error)
283 pure function pythag2(x, y, xo, yo)
result(r)
285 real(real64),
intent(in) :: x, y, xo, yo
289 real(real64) :: w, xabs, yabs
295 if (w < epsilon(w))
then
298 r = w * sqrt((xabs / w)**2 + (yabs / w)**2)
302 pure function pythag3(x, y, z, xo, yo, zo)
result(r)
304 real(real64),
intent(in) :: x, y, z, xo, yo, zo
308 real(real64) :: w, xabs, yabs, zabs
314 w = max(xabs, yabs, zabs)
315 if (w < epsilon(w))
then
316 r = xabs + yabs + zabs
318 r = w * sqrt((xabs / w)**2 + (yabs / w)**2 + (zabs / w)**2)