fplot 1.7.1
A Fortran library providing a convenient interface for plotting with Gnuplot.
Loading...
Searching...
No Matches
fplot_plot_3d.f90
1! fplot_plot_3d.f90
2
3submodule(fplot_core) fplot_plot_3d
4contains
5! ------------------------------------------------------------------------------
6 module subroutine p3d_clean_up(this)
7 type(plot_3d), intent(inout) :: this
8 call this%free_resources()
9 if (associated(this%m_xAxis)) then
10 deallocate(this%m_xAxis)
11 nullify(this%m_xAxis)
12 end if
13 if (associated(this%m_yAxis)) then
14 deallocate(this%m_yAxis)
15 nullify(this%m_yAxis)
16 end if
17 if (associated(this%m_zAxis)) then
18 deallocate(this%m_zAxis)
19 nullify(this%m_zAxis)
20 end if
21 end subroutine
22
23! ------------------------------------------------------------------------------
24 module subroutine p3d_init(this, term, fname, err)
25 ! Arguments
26 class(plot_3d), intent(inout) :: this
27 integer(int32), intent(in), optional :: term
28 character(len = *), intent(in), optional :: fname
29 class(errors), intent(inout), optional, target :: err
30
31 ! Local Variables
32 integer(int32) :: flag
33 class(errors), pointer :: errmgr
34 type(errors), target :: deferr
35
36 ! Initialization
37 if (present(err)) then
38 errmgr => err
39 else
40 errmgr => deferr
41 end if
42
43 ! Initialize the base class
44 call plt_init(this, term, fname, errmgr)
45 if (errmgr%has_error_occurred()) return
46
47 ! Process
48 flag = 0
49 if (.not.associated(this%m_xAxis)) then
50 allocate(this%m_xAxis, stat = flag)
51 end if
52 if (flag == 0 .and. .not.associated(this%m_yAxis)) then
53 allocate(this%m_yAxis, stat = flag)
54 end if
55 if (flag == 0 .and. .not.associated(this%m_zAxis)) then
56 allocate(this%m_zAxis, stat = flag)
57 end if
58
59 ! Error Checking
60 if (flag /= 0) then
61 call errmgr%report_error("p3d_init", &
62 "Insufficient memory available.", plot_out_of_memory_error)
63 return
64 end if
65 end subroutine
66
67! ------------------------------------------------------------------------------
68 module function p3d_get_cmd(this) result(x)
69 ! Arguments
70 class(plot_3d), intent(in) :: this
71 character(len = :), allocatable :: x
72
73 ! Local Variables
74 type(string_builder) :: str
75 integer(int32) :: i, n
76 class(plot_data), pointer :: ptr
77 class(plot_axis), pointer :: xAxis, yAxis, zAxis
78 type(legend), pointer :: leg
79 ! class(plot_label), pointer :: lbl
80
81 ! Initialization
82 call str%initialize()
83
84 ! Call the base routine
85 call str%append(this%plot%get_command_string())
86
87 ! Grid
88 if (this%get_show_gridlines()) then
89 call str%append(new_line('a'))
90 call str%append("set grid")
91 end if
92
93 ! Title
94 n = len_trim(this%get_title())
95 if (n > 0) then
96 call str%append(new_line('a'))
97 call str%append('set title "')
98 call str%append(this%get_title())
99 call str%append('"')
100 end if
101
102 ! Axes
103 call str%append(new_line('a'))
104 xaxis => this%get_x_axis()
105 if (associated(xaxis)) call str%append(xaxis%get_command_string())
106
107 call str%append(new_line('a'))
108 yaxis => this%get_y_axis()
109 if (associated(yaxis)) call str%append(yaxis%get_command_string())
110
111 call str%append(new_line('a'))
112 zaxis => this%get_z_axis()
113 if (associated(zaxis)) call str%append(zaxis%get_command_string())
114
115 ! Tic Marks
116 if (.not.this%get_tics_inward()) then
117 call str%append(new_line('a'))
118 call str%append("set tics out")
119 end if
120 if (xaxis%get_zero_axis() .or. yaxis%get_zero_axis() .or. &
121 zaxis%get_zero_axis()) then
122 call str%append(new_line('a'))
123 call str%append("set tics axis")
124 end if
125
126 ! Border
127 if (this%get_draw_border()) then
128 n = 31
129 else
130 n = 0
131 if (.not.xaxis%get_zero_axis()) n = n + 1
132 if (.not.yaxis%get_zero_axis()) n = n + 4
133 if (.not.zaxis%get_zero_axis()) n = n + 16
134
135 call str%append(new_line('a'))
136 call str%append("set xtics nomirror")
137 call str%append(new_line('a'))
138 call str%append("set ytics nomirror")
139 call str%append(new_line('a'))
140 call str%append("set ztics nomirror")
141 end if
142 call str%append(new_line('a'))
143 if (n > 0) then
144 call str%append("set border ")
145 call str%append(to_string(n))
146 else
147 call str%append("unset border")
148 end if
149
150 ! Force the z-axis to move to the x-y plane
151 if (this%get_z_intersect_xy()) then
152 call str%append(new_line('a'))
153 call str%append("set ticslevel 0")
154 end if
155
156 ! Scaling
157 if (this%get_axis_equal()) then
158 call str%append(new_line('a'))
159 call str%append("set view equal xyz")
160 end if
161
162 ! Legend
163 call str%append(new_line('a'))
164 leg => this%get_legend()
165 if (associated(leg)) call str%append(leg%get_command_string())
166
167 ! ! Labels
168 ! do i = 1, this%get_label_count()
169 ! lbl => this%get_label(i)
170 ! if (.not.associated(lbl)) cycle
171 ! call str%append(new_line('a'))
172 ! call str%append(lbl%get_command_string())
173 ! end do
174
175 ! Orientation
176 call str%append(new_line('a'))
177 call str%append("set view ")
178 if (this%get_use_map_view()) then
179 call str%append("map")
180 else
181 call str%append(to_string(this%get_elevation()))
182 call str%append(",")
183 call str%append(to_string(this%get_azimuth()))
184 end if
185
186 ! Coordinate system
187 if (this%get_coordinate_system() == coordinates_cylindrical) then
188 call str%append(new_line('a'))
189 call str%append("set mapping cylindrical")
190 else if (this%get_coordinate_system() == coordinates_spherical) then
191 call str%append(new_line('a'))
192 call str%append("set mapping spherical")
193 end if
194
195 ! Define the plot function and data formatting commands
196 n = this%get_count()
197 call str%append(new_line('a'))
198 call str%append("splot ")
199 do i = 1, n
200 ptr => this%get(i)
201 if (.not.associated(ptr)) cycle
202 call str%append(ptr%get_command_string())
203 if (i /= n) call str%append(", ")
204 end do
205
206 ! Define the data to plot
207 do i = 1, n
208 ptr => this%get(i)
209 if (.not.associated(ptr)) cycle
210 call str%append(new_line('a'))
211 call str%append(ptr%get_data_string())
212 call str%append("e")
213 ! if (i /= n) then
214 ! call str%append("e")
215 ! end if
216 end do
217
218 ! End
219 x = char(str%to_string())
220 end function
221
222! ------------------------------------------------------------------------------
223 module function p3d_get_x_axis(this) result(ptr)
224 class(plot_3d), intent(in) :: this
225 class(plot_axis), pointer :: ptr
226 ptr => this%m_xAxis
227 end function
228
229! ------------------------------------------------------------------------------
230 module function p3d_get_y_axis(this) result(ptr)
231 class(plot_3d), intent(in) :: this
232 class(plot_axis), pointer :: ptr
233 ptr => this%m_yAxis
234 end function
235
236! ------------------------------------------------------------------------------
237 module function p3d_get_z_axis(this) result(ptr)
238 class(plot_3d), intent(in) :: this
239 class(plot_axis), pointer :: ptr
240 ptr => this%m_zAxis
241 end function
242
243! ------------------------------------------------------------------------------
244 pure module function p3d_get_elevation(this) result(x)
245 class(plot_3d), intent(in) :: this
246 real(real64) :: x
247 x = this%m_elevation
248 end function
249
250! --------------------
251 module subroutine p3d_set_elevation(this, x)
252 class(plot_3d), intent(inout) :: this
253 real(real64), intent(in) :: x
254 this%m_elevation = x
255 end subroutine
256
257! ------------------------------------------------------------------------------
258 pure module function p3d_get_azimuth(this) result(x)
259 class(plot_3d), intent(in) :: this
260 real(real64) :: x
261 x = this%m_azimuth
262 end function
263
264! --------------------
265 module subroutine p3d_set_azimuth(this, x)
266 class(plot_3d), intent(inout) :: this
267 real(real64), intent(in) :: x
268 this%m_azimuth = x
269 end subroutine
270
271! ------------------------------------------------------------------------------
272 pure module function p3d_get_z_axis_intersect(this) result(x)
273 class(plot_3d), intent(in) :: this
274 logical :: x
275 x = this%m_zIntersect
276 end function
277
278! --------------------
279 module subroutine p3d_set_z_axis_intersect(this, x)
280 class(plot_3d), intent(inout) :: this
281 logical, intent(in) :: x
282 this%m_zIntersect = x
283 end subroutine
284
285! ADDED March 29, 2023 - JAC
286! ------------------------------------------------------------------------------
287 pure module function p3d_get_use_map_view(this) result(rst)
288 class(plot_3d), intent(in) :: this
289 logical :: rst
290 rst = this%m_setMap
291 end function
292
293! --------------------
294 module subroutine p3d_set_use_map_view(this, x)
295 class(plot_3d), intent(inout) :: this
296 logical, intent(in) :: x
297 this%m_setMap = x
298 end subroutine
299
300! ADDED Sept. 15, 2023 - JAC
301! ------------------------------------------------------------------------------
302 pure module function p3d_get_csys(this) result(rst)
303 class(plot_3d), intent(in) :: this
304 integer(int32) :: rst
305 rst = this%m_csys
306 end function
307
308! --------------------
309 module subroutine p3d_set_csys(this, x)
310 class(plot_3d), intent(inout) :: this
311 integer(int32), intent(in) :: x
312 if (x /= coordinates_cartesian .and. &
313 x /= coordinates_cylindrical .and. &
314 x /= coordinates_spherical) &
315 then
316 ! Set to default as the input is nonsensical
317 this%m_csys = coordinates_cartesian
318 else
319 this%m_csys = x
320 end if
321 end subroutine
322
323! ------------------------------------------------------------------------------
324end submodule
fplot_core