fplot 1.7.1
A Fortran library providing a convenient interface for plotting with Gnuplot.
Loading...
Searching...
No Matches
fplot_surface_plot_data.f90
1! fplot_surface_plot_data.f90
2
3submodule(fplot_core) fplot_surface_plot_data
4contains
5! ------------------------------------------------------------------------------
6 pure module function surfd_get_size(this, dim) result(x)
7 class(surface_plot_data), intent(in) :: this
8 integer(int32), intent(in) :: dim
9 integer(int32) :: x
10 if (allocated(this%m_x)) then
11 x = size(this%m_x, dim)
12 else
13 x = 0
14 end if
15 end function
16
17! ------------------------------------------------------------------------------
18 pure module function surfd_get_x(this, i, j) result(x)
19 class(surface_plot_data), intent(in) :: this
20 integer(int32), intent(in) :: i, j
21 real(real64) :: x
22 if (allocated(this%m_x)) then
23 x = this%m_x(i,j)
24 else
25 x = 0.0d0
26 end if
27 end function
28
29! --------------------
30 module subroutine surfd_set_x(this, i, j, x)
31 class(surface_plot_data), intent(inout) :: this
32 integer(int32), intent(in) :: i, j
33 real(real64), intent(in) :: x
34 if (allocated(this%m_x)) then
35 this%m_x(i,j) = x
36 end if
37 end subroutine
38
39! ------------------------------------------------------------------------------
40 pure module function surfd_get_y(this, i, j) result(x)
41 class(surface_plot_data), intent(in) :: this
42 integer(int32), intent(in) :: i, j
43 real(real64) :: x
44 if (allocated(this%m_y)) then
45 x = this%m_y(i,j)
46 else
47 x = 0.0d0
48 end if
49 end function
50
51! --------------------
52 module subroutine surfd_set_y(this, i, j, x)
53 class(surface_plot_data), intent(inout) :: this
54 integer(int32), intent(in) :: i, j
55 real(real64), intent(in) :: x
56 if (allocated(this%m_y)) then
57 this%m_y(i,j) = x
58 end if
59 end subroutine
60
61! ------------------------------------------------------------------------------
62 pure module function surfd_get_z(this, i, j) result(x)
63 class(surface_plot_data), intent(in) :: this
64 integer(int32), intent(in) :: i, j
65 real(real64) :: x
66 if (allocated(this%m_z)) then
67 x = this%m_z(i,j)
68 else
69 x = 0.0d0
70 end if
71 end function
72
73! --------------------
74 module subroutine surfd_set_z(this, i, j, x)
75 class(surface_plot_data), intent(inout) :: this
76 integer(int32), intent(in) :: i, j
77 real(real64), intent(in) :: x
78 if (allocated(this%m_z)) then
79 this%m_z(i,j) = x
80 end if
81 end subroutine
82
83! ------------------------------------------------------------------------------
84 pure module function surfd_get_wireframe(this) result(x)
85 class(surface_plot_data), intent(in) :: this
86 logical :: x
87 x = this%m_wireframe
88 end function
89
90! --------------------
91 module subroutine surfd_set_wireframe(this, x)
92 class(surface_plot_data), intent(inout) :: this
93 logical, intent(in) :: x
94 this%m_wireframe = x
95 end subroutine
96
97! ------------------------------------------------------------------------------
98 module function surfd_get_cmd(this) result(x)
99 ! Arguments
100 class(surface_plot_data), intent(in) :: this
101 character(len = :), allocatable :: x
102
103 ! Local Variables
104 type(string_builder) :: str
105 integer(int32) :: n
106
107 ! Initialization
108 call str%initialize()
109
110 ! Title
111 n = len_trim(this%get_name())
112 if (n > 0) then
113 call str%append(' "-" title "')
114 call str%append(this%get_name())
115 call str%append('"')
116 else
117 call str%append(' "-" notitle')
118 end if
119
120 ! PM3D or wireframe?
121 if (this%get_use_wireframe()) then
122 call str%append(" with lines")
123 else
124 call str%append(" with pm3d")
125 end if
126
127 ! End
128 x = char(str%to_string())
129 end function
130
131! ------------------------------------------------------------------------------
132 module function surfd_get_data_cmd(this) result(x)
133 ! Arguments
134 class(surface_plot_data), intent(in) :: this
135 character(len = :), allocatable :: x
136
137 ! Local Variables
138 type(string_builder) :: str
139 integer(int32) :: i, j, m, n
140 character :: delimiter, nl
141
142 ! Initialization
143 call str%initialize()
144 m = this%get_size(1)
145 n = this%get_size(2)
146 delimiter = achar(9) ! tab delimiter
147 nl = new_line(nl)
148
149 ! Process
150 do j = 1, n
151 do i = 1, m
152 call str%append(to_string(this%get_x(i,j)))
153 call str%append(delimiter)
154 call str%append(to_string(this%get_y(i,j)))
155 call str%append(delimiter)
156 call str%append(to_string(this%get_z(i,j)))
157 call str%append(nl)
158 end do
159 if (j /= n) call str%append(nl)
160 end do
161
162 ! End
163 x = char(str%to_string())
164 end function
165
166! ------------------------------------------------------------------------------
167 module subroutine surfd_set_data_1(this, x, y, z, err)
168 ! Arguments
169 class(surface_plot_data), intent(inout) :: this
170 real(real64), intent(in), dimension(:,:) :: x, y, z
171 class(errors), intent(inout), optional, target :: err
172
173 ! Local Variables
174 integer(int32) :: i, j, m, n, flag
175 class(errors), pointer :: errmgr
176 type(errors), target :: deferr
177
178 ! Initialization
179 m = size(x, 1)
180 n = size(x, 2)
181 if (present(err)) then
182 errmgr => err
183 else
184 errmgr => deferr
185 end if
186
187 ! Input Check
188 if (size(y, 1) /= m .or. size(y, 2) /= n .or. size(z, 1) /= m .or. size(z, 2) /= n) then
189 call errmgr%report_error("surfd_set_data_1", &
190 "The input arrays are not the same size.", &
191 plot_array_size_mismatch_error)
192 return
193 end if
194
195 ! Process
196 if (allocated(this%m_x)) deallocate(this%m_x)
197 if (allocated(this%m_y)) deallocate(this%m_y)
198 if (allocated(this%m_z)) deallocate(this%m_z)
199 allocate(this%m_x(m, n), stat = flag)
200 if (flag == 0) allocate(this%m_y(m, n), stat = flag)
201 if (flag == 0) allocate(this%m_z(m, n), stat = flag)
202 if (flag /= 0) then
203 call errmgr%report_error("surfd_set_data_1", &
204 "Insufficient memory available.", plot_out_of_memory_error)
205 return
206 end if
207 do concurrent(j = 1:n)
208 do i = 1, m
209 this%m_x(i, j) = x(i, j)
210 this%m_y(i, j) = y(i, j)
211 this%m_z(i, j) = z(i, j)
212 end do
213 end do
214 end subroutine
215
216end submodule
fplot_core