fplot 1.7.1
A Fortran library providing a convenient interface for plotting with Gnuplot.
Loading...
Searching...
No Matches
fplot_plot_data_tri_2d.f90
1! fplot_plot_data_tri_2d.f90
2
3submodule(fplot_core) fplot_plot_data_tri_2d
4contains
5! ------------------------------------------------------------------------------
6 module function pdt2d_get_data_cmd(this) result(x)
7 ! Arguments
8 class(plot_data_tri_2d), intent(in) :: this
9 character(len = :), allocatable :: x
10
11 ! Local Variables
12 type(string_builder) :: str
13 integer(int32) :: i, j, n
14 character :: delimiter, nl
15
16 ! Initialization
17 call str%initialize()
18 n = size(this%m_indices, 1)
19 delimiter = achar(9)
20 nl = new_line(nl)
21
22 ! Process
23 ! https://stackoverflow.com/questions/42784369/drawing-triangular-mesh-using-gnuplot
24 ! http://www.gnuplot.info/faq/faq.html#x1-530005.10
25 ! https://codeyarns.com/2011/01/25/gnuplot-plotting-a-3d-triangulation/
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("0.0")
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("0.0")
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("0.0")
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("0.0")
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("0.0")
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("0.0")
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 pdt2d_get_cmd(this) result(x)
100 ! Arguments
101 class(plot_data_tri_2d), intent(in) :: this
102 character(len = :), allocatable :: x
103
104 ! Local Variables
105 type(string_builder) :: str
106 integer(int32) :: n
107 type(color) :: clr
108
109 ! Initialization
110 call str%initialize()
111
112 ! Title
113 n = len_trim(this%get_name())
114 if (n > 0) then
115 call str%append(' "-" title "')
116 call str%append(this%get_name())
117 call str%append('"')
118 else
119 call str%append(' "-" notitle')
120 end if
121
122 ! Lines
123 call str%append(" with lines")
124
125 ! Line Width
126 call str%append(" lw ")
127 call str%append(to_string(this%get_line_width()))
128
129 ! Line Color
130 clr = this%get_line_color()
131 call str%append(' lc rgb "#')
132 call str%append(clr%to_hex_string())
133 call str%append('"')
134
135 ! Line Style
136 call str%append(" lt ")
137 call str%append(to_string(this%get_line_style()))
138 if (this%get_line_style() /= line_solid) then
139 call str%append(" dashtype ")
140 call str%append(to_string(this%get_line_style()))
141 end if
142
143 ! End
144 x = char(str%to_string())
145 end function
146
147! ------------------------------------------------------------------------------
148 module subroutine pdt2d_define_data(this, tri)
149 ! Arguments
150 class(plot_data_tri_2d), intent(inout) :: this
151 class(delaunay_tri_2d), intent(in) :: tri
152
153 ! Process
154 if (allocated(this%m_x)) deallocate(this%m_x)
155 if (allocated(this%m_y)) deallocate(this%m_y)
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_indices = tri%get_indices()
161 end subroutine
162
163! ------------------------------------------------------------------------------
164 pure module function pdt2d_get_line_width(this) result(rst)
165 class(plot_data_tri_2d), intent(in) :: this
166 real(real32) :: rst
167 rst = this%m_lineWidth
168 end function
169
170! --------------------
171 module subroutine pdt2d_set_line_width(this, x)
172 class(plot_data_tri_2d), intent(inout) :: this
173 real(real32), intent(in) :: x
174 if (x <= 0.0d0) then
175 this%m_lineWidth = 1.0d0
176 else
177 this%m_lineWidth = x
178 end if
179 end subroutine
180! ------------------------------------------------------------------------------
181 pure module function pdt2d_get_line_style(this) result(rst)
182 class(plot_data_tri_2d), intent(in) :: this
183 integer(int32) :: rst
184 rst = this%m_lineStyle
185 end function
186
187! --------------------
188 module subroutine pdt2d_set_line_style(this, x)
189 class(plot_data_tri_2d), intent(inout) :: this
190 integer(int32), intent(in) :: x
191 if (x == line_dashed .or. &
192 x == line_dash_dotted .or. &
193 x == line_dash_dot_dot .or. &
194 x == line_dotted .or. &
195 x == line_solid) then
196 ! Only reset the line style if it is a valid type.
197 this%m_lineStyle = x
198 end if
199 end subroutine
200
201! ------------------------------------------------------------------------------
202end submodule
fplot_core