fplot 1.7.1
A Fortran library providing a convenient interface for plotting with Gnuplot.
Loading...
Searching...
No Matches
fplot_plot_polar.f90
1! fplot_polar.f90
2
3submodule(fplot_core) fplot_plot_polar
4contains
5! ------------------------------------------------------------------------------
6 module subroutine plr_clean_up(this)
7 type(plot_polar), intent(inout) :: this
8 call this%free_resources()
9 end subroutine
10
11! ------------------------------------------------------------------------------
12 module subroutine plr_init(this, term, fname, err)
13 ! Arguments
14 class(plot_polar), intent(inout) :: this
15 integer(int32), intent(in), optional :: term
16 character(len = *), intent(in), optional :: fname
17 class(errors), intent(inout), optional, target :: err
18
19 ! Local Variables
20 class(errors), pointer :: errmgr
21 type(errors), target :: deferr
22
23 ! Initialization
24 if (present(err)) then
25 errmgr => err
26 else
27 errmgr => deferr
28 end if
29
30 ! Initialize the base class
31 call plt_init(this, term, fname, errmgr)
32 if (errmgr%has_error_occurred()) return
33
34 ! Initialize the rest of the object
35 this%m_thetaStart = polar_theta_right
36 this%m_thetaDirection = polar_theta_ccw
37 end subroutine
38
39! ------------------------------------------------------------------------------
40 module function plr_get_cmd(this) result(x)
41 ! Arguments
42 class(plot_polar), intent(in) :: this
43 character(len = :), allocatable :: x
44
45 ! Local Variables
46 integer(int32) :: i, n
47 type(string_builder) :: str
48 type(legend), pointer :: leg
49 real(real64) :: lim(2)
50 ! class(plot_label), pointer :: lbl
51 class(plot_data), pointer :: ptr
52
53 ! Initialization
54 call str%initialize()
55
56 ! Call the base routine
57 call str%append(this%plot%get_command_string())
58
59 ! Polar-Specific Settings
60 call str%append(new_line('a'))
61 call str%append("unset border")
62
63 call str%append(new_line('a'))
64 call str%append("set polar")
65
66 call str%append(new_line('a'))
67 call str%append("set size square")
68
69 call str%append(new_line('a'))
70 call str%append("unset xtics")
71 call str%append(new_line('a'))
72 call str%append("unset ytics")
73
74 call str%append(new_line('a'))
75 call str%append('set ttics 0, 30 format "%g".GPVAL_DEGREE_SIGN')
76
77 call str%append(new_line('a'))
78 call str%append("set mttics 3")
79
80 call str%append(new_line('a'))
81 call str%append("set theta ")
82 call str%append(this%get_theta_start_position())
83 call str%append(" ")
84 call str%append(this%get_theta_direction())
85
86 ! Radial Limits
87 if (.not.this%get_autoscale()) then
88 lim = this%get_radial_limits()
89 call str%append(new_line('a'))
90 call str%append("set rrange [")
91 call str%append(to_string(lim(1)))
92 call str%append(":")
93 call str%append(to_string(lim(2)))
94 call str%append("]")
95 end if
96
97 ! Grid
98 if (this%get_show_gridlines()) then
99 call str%append(new_line('a'))
100 call str%append("set grid r polar")
101 end if
102
103 ! Title
104 n = len_trim(this%get_title())
105 if (n > 0) then
106 call str%append(new_line('a'))
107 call str%append('set title "')
108 call str%append(this%get_title())
109 call str%append('"')
110 end if
111
112 ! Border
113 call str%append(new_line('a'))
114 if (this%get_draw_border()) then
115 call str%append("set border polar")
116 else
117 call str%append("set border 0")
118 end if
119
120 ! Legend
121 call str%append(new_line('a'))
122 leg => this%get_legend()
123 if (associated(leg)) call str%append(leg%get_command_string())
124
125 ! ! Labels
126 ! do i = 1, this%get_label_count()
127 ! lbl => this%get_label(i)
128 ! if (.not.associated(lbl)) cycle
129 ! call str%append(new_line('a'))
130 ! call str%append(lbl%get_command_string())
131 ! end do
132
133 ! Define the plot function and data formatting commands
134 n = this%get_count()
135 call str%append(new_line('a'))
136 call str%append("plot ")
137 do i = 1, n
138 ptr => this%get(i)
139 if (.not.associated(ptr)) cycle
140 call str%append(ptr%get_command_string())
141 if (i /= n) call str%append(", ")
142 end do
143
144 ! Define the data to plot
145 do i = 1, n
146 ptr => this%get(i)
147 if (.not.associated(ptr)) cycle
148 call str%append(new_line('a'))
149 call str%append(ptr%get_data_string())
150 call str%append("e")
151 end do
152
153 ! End
154 x = char(str%to_string())
155 end function
156
157! ------------------------------------------------------------------------------
158 pure module function plr_get_autoscale(this) result(rst)
159 class(plot_polar), intent(in) :: this
160 logical :: rst
161 rst = this%m_autoscale
162 end function
163
164! --------------------
165 module subroutine plr_set_autoscale(this, x)
166 class(plot_polar), intent(inout) :: this
167 logical, intent(in) :: x
168 this%m_autoscale = x
169 end subroutine
170
171! ------------------------------------------------------------------------------
172 pure module function plr_get_limits(this) result(rst)
173 class(plot_polar), intent(in) :: this
174 real(real64) :: rst(2)
175 rst = [this%m_minrad, this%m_maxrad]
176 end function
177
178! --------------------
179 module subroutine plr_set_limits(this, x)
180 class(plot_polar), intent(inout) :: this
181 real(real64), intent(in) :: x(2)
182 this%m_minrad = minval(x)
183 this%m_maxrad = maxval(x)
184 end subroutine
185
186! ------------------------------------------------------------------------------
187 pure module function plr_get_theta_start(this) result(rst)
188 class(plot_polar), intent(in) :: this
189 character(len = :), allocatable :: rst
190 rst = this%m_thetaStart
191 end function
192
193! --------------------
194 module subroutine plr_set_theta_start(this, x)
195 class(plot_polar), intent(inout) :: this
196 character(len = *), intent(in) :: x
197 if (x /= polar_theta_bottom .and. &
198 x /= polar_theta_top .and. &
199 x /= polar_theta_left .and. &
200 x /= polar_theta_right) &
201 then
202 ! Reset to default
203 this%m_thetaStart = polar_theta_right
204 else
205 this%m_thetaStart = x
206 end if
207 end subroutine
208
209! ------------------------------------------------------------------------------
210 pure module function plr_get_theta_direction(this) result(rst)
211 class(plot_polar), intent(in) :: this
212 character(len = :), allocatable :: rst
213 rst = this%m_thetaDirection
214 end function
215
216! --------------------
217 module subroutine plr_set_theta_direction(this, x)
218 class(plot_polar), intent(inout) :: this
219 character(len = *), intent(in) :: x
220 if (x /= polar_theta_ccw .and. x /= polar_theta_cw) then
221 ! Reset to default
222 this%m_thetaDirection = polar_theta_ccw
223 else
224 this%m_thetaDirection = x
225 end if
226 end subroutine
227
228! ------------------------------------------------------------------------------
229
230! --------------------
231
232! ------------------------------------------------------------------------------
233end submodule
fplot_core