7 module subroutine dts_define_fcn(this, z, err)
9 class(delaunay_tri_surface),
intent(inout) :: this
10 real(real64),
intent(in),
dimension(:) :: z
11 class(errors),
intent(inout),
optional,
target :: err
14 integer(int32) :: n, flag
15 class(errors),
pointer :: errmgr
16 type(errors),
target :: deferr
17 character(len = 256) :: errmsg
20 if (
present(err))
then
25 n = this%get_point_count()
29 call errmgr%report_error(
"dts_define_fcn", &
30 "No x-y coordinates have been defined.", &
31 plot_invalid_operation_error)
34 if (
size(z) /= n)
then
35 write (errmsg, 100)
"The number of function values " // &
36 "does not match the number of x-y points. Expected to find ", &
37 n,
" function values, but found ",
size(z),
" instead."
38 call errmgr%report_error(
"dts_define_fcn", trim(errmsg), &
39 plot_array_size_mismatch_error)
44 if (
allocated(this%m_z))
deallocate(this%m_z)
45 allocate(this%m_z(n), stat = flag)
47 call errmgr%report_error(
"dts_define_fcn", &
48 "Insufficient memory available.", &
49 plot_out_of_memory_error)
54100
format(a, i0, a, i0, a)
58 pure module function dts_get_z(this) result(rst)
59 class(delaunay_tri_surface),
intent(in) :: this
60 real(real64),
allocatable,
dimension(:) :: rst
61 if (
allocated(this%m_z))
then
72 pure module function dts_interp_1(this, x, y) result(z)
74 class(delaunay_tri_surface),
intent(in) :: this
75 real(real64),
intent(in) :: x, y
79 integer(int32) :: i, n1, n2, n3
80 real(real64) :: x1, x2, x3, y1, y2, y3, z1, z2, z3
81 integer(int32),
allocatable,
dimension(:,:) :: indices
82 real(real64),
allocatable,
dimension(:) :: xc, yc, zc
85 z = ieee_value(z, ieee_quiet_nan)
86 indices = this%get_indices()
87 xc = this%get_points_x()
88 yc = this%get_points_y()
89 zc = this%get_points_z()
92 if (this%get_triangle_count() == 0 .or. &
93 this%get_point_count() == 0 .or. &
98 i = this%find_triangle(x, y)
119 z = linear_interp(x1, y1, z1, x2, y2, z2, x3, y3, z3, x, y)
123 pure module function dts_interp_2(this, x, y) result(z)
125 class(delaunay_tri_surface),
intent(in) :: this
126 real(real64),
intent(in),
dimension(:) :: x, y
127 real(real64),
allocatable,
dimension(:) :: z
130 integer(int32) :: i, j, n1, n2, n3, nxy
131 real(real64) :: x1, x2, x3, y1, y2, y3, z1, z2, z3, nan
132 integer(int32),
allocatable,
dimension(:,:) :: indices
133 real(real64),
allocatable,
dimension(:) :: xc, yc, zc
136 nxy = min(
size(x),
size(y))
137 nan = ieee_value(nan, ieee_quiet_nan)
140 indices = this%get_indices()
141 xc = this%get_points_x()
142 yc = this%get_points_y()
143 zc = this%get_points_z()
146 if (this%get_triangle_count() == 0 .or. &
147 this%get_point_count() == 0 .or. &
148 size(zc) == 0)
return
154 j = this%find_triangle(x(i), y(i))
176 z(i) = linear_interp(x1, y1, z1, x2, y2, z2, x3, y3, z3, x(i), y(i))
185 pure elemental function linear_interp(x1, y1, z1, x2, y2, z2, x3, &
186 y3, z3, x, y)
result(z)
187 real(real64),
intent(in) :: x1, y1, z1, x2, y2, z2, x3, y3, z3, x, y
188 real(real64) :: a1, a2, a3, j, z
190 j = (x2 - x1) * y3 + (x1 - x3) * y2 + (x3 - x2) * y1
191 a1 = (x2 * y3 - x3 * y2 + (y2 - y3) * x + (x3 - x2) * y)
192 a2 = (x3 * y1 - x1 * y3 + (y3 - y1) * x + (x1 - x3) * y)
193 a3 = (x1 * y2 - x2 * y1 + (y1 - y2) * x + (x2 - x1) * y)
194 z = (a1 * z1 + a2 * z2 + a3 * z3) / j