fplot 1.7.1
A Fortran library providing a convenient interface for plotting with Gnuplot.
Loading...
Searching...
No Matches
fplot_tri_surface_plot_data.f90
1! fplot_tri_surface_plot_data.f90
2
3submodule(fplot_core) fplot_tri_surface_plot_data
4contains
5! ------------------------------------------------------------------------------
6 module function tspd_get_data_cmd(this) result(x)
7 ! Arguments
8 class(tri_surface_plot_data), intent(in) :: this
9 character(len = :), allocatable :: x
10
11 ! Local Variables
12 ! Local Variables
13 type(string_builder) :: str
14 integer(int32) :: i, j, n
15 character :: delimiter, nl
16
17 ! Initialization
18 call str%initialize()
19 n = size(this%m_indices, 1)
20 delimiter = achar(9)
21 nl = new_line(nl)
22
23 ! Process
24 ! https://stackoverflow.com/questions/42784369/drawing-triangular-mesh-using-gnuplot
25 ! http://www.gnuplot.info/faq/faq.html#x1-530005.10
26 do i = 1, n
27 ! Line 1-2
28 ! Vertex 1
29 j = this%m_indices(i, 1)
30 call str%append(to_string(this%m_x(j)))
31 call str%append(delimiter)
32 call str%append(to_string(this%m_y(j)))
33 call str%append(delimiter)
34 call str%append(to_string(this%m_z(j)))
35 call str%append(nl)
36
37 ! Vertex 2
38 j = this%m_indices(i, 2)
39 call str%append(to_string(this%m_x(j)))
40 call str%append(delimiter)
41 call str%append(to_string(this%m_y(j)))
42 call str%append(delimiter)
43 call str%append(to_string(this%m_z(j)))
44 call str%append(nl)
45
46 ! Line 2-3
47 ! Vertex 2
48 call str%append(nl)
49 j = this%m_indices(i, 2)
50 call str%append(to_string(this%m_x(j)))
51 call str%append(delimiter)
52 call str%append(to_string(this%m_y(j)))
53 call str%append(delimiter)
54 call str%append(to_string(this%m_z(j)))
55 call str%append(nl)
56
57
58 ! Vertex 3
59 j = this%m_indices(i, 3)
60 call str%append(to_string(this%m_x(j)))
61 call str%append(delimiter)
62 call str%append(to_string(this%m_y(j)))
63 call str%append(delimiter)
64 call str%append(to_string(this%m_z(j)))
65 call str%append(nl)
66
67 ! Line 3-1
68 ! Vertex 3
69 call str%append(nl)
70 j = this%m_indices(i, 3)
71 call str%append(to_string(this%m_x(j)))
72 call str%append(delimiter)
73 call str%append(to_string(this%m_y(j)))
74 call str%append(delimiter)
75 call str%append(to_string(this%m_z(j)))
76 call str%append(nl)
77
78 ! Vertex 1
79 j = this%m_indices(i, 1)
80 call str%append(to_string(this%m_x(j)))
81 call str%append(delimiter)
82 call str%append(to_string(this%m_y(j)))
83 call str%append(delimiter)
84 call str%append(to_string(this%m_z(j)))
85 call str%append(nl)
86
87 ! Add in the two blank lines
88 if (i /= n) then
89 call str%append(nl)
90 call str%append(nl)
91 end if
92 end do
93
94 ! End
95 x = char(str%to_string())
96 end function
97
98! ------------------------------------------------------------------------------
99 module function tspd_get_cmd(this) result(x)
100 ! Arguments
101 class(tri_surface_plot_data), intent(in) :: this
102 character(len = :), allocatable :: x
103
104 ! Local Variables
105 type(string_builder) :: str
106 integer(int32) :: n
107
108 ! Initialization
109 call str%initialize()
110
111 ! Title
112 n = len_trim(this%get_name())
113 if (n > 0) then
114 call str%append(' "-" title "')
115 call str%append(this%get_name())
116 call str%append('"')
117 else
118 call str%append(' "-" notitle')
119 end if
120
121 ! PM3D or wireframe?
122 if (this%get_use_wireframe()) then
123 call str%append(" with lines")
124 else
125 call str%append(" with pm3d")
126 end if
127
128 ! End
129 x = char(str%to_string())
130 end function
131
132! ------------------------------------------------------------------------------
133 pure module function tspd_get_wireframe(this) result(rst)
134 class(tri_surface_plot_data), intent(in) :: this
135 logical :: rst
136 rst = this%m_wireframe
137 end function
138
139! ------------------------------------------------------------------------------
140 module subroutine tspd_set_wireframe(this, x)
141 class(tri_surface_plot_data), intent(inout) :: this
142 logical, intent(in) :: x
143 this%m_wireframe = x
144 end subroutine
145
146! ------------------------------------------------------------------------------
147 module subroutine tspd_define_data(this, tri)
148 ! Arguments
149 class(tri_surface_plot_data), intent(inout) :: this
150 class(delaunay_tri_surface), intent(in) :: tri
151
152 ! Process
153 if (allocated(this%m_x)) deallocate(this%m_x)
154 if (allocated(this%m_y)) deallocate(this%m_y)
155 if (allocated(this%m_z)) deallocate(this%m_z)
156 if (allocated(this%m_indices)) deallocate(this%m_indices)
157
158 this%m_x = tri%get_points_x()
159 this%m_y = tri%get_points_y()
160 this%m_z = tri%get_points_z()
161 this%m_indices = tri%get_indices()
162 end subroutine
163
164! ------------------------------------------------------------------------------
165end submodule
fplot_core