fplot 1.7.1
A Fortran library providing a convenient interface for plotting with Gnuplot.
Loading...
Searching...
No Matches
fplot_colormap.f90
1! fplot_colormap.f90
2
3submodule(fplot_core) fplot_colormap
4contains
5! ******************************************************************************
6! COLORMAP MEMBERS
7! ------------------------------------------------------------------------------
8 module function cm_get_cmd(this) result(x)
9 ! Arguments
10 class(colormap), intent(in) :: this
11 character(len = :), allocatable :: x
12
13 ! Local Variables
14 type(string_builder) :: str
15
16 ! Initialization
17 call str%initialize()
18
19 ! Palette Definition
20 call str%append("set palette defined (")
21 call str%append(this%get_color_string())
22 call str%append(")")
23
24 if (len(this%get_label()) > 0) then
25 call str%append(new_line('a'))
26 call str%append('set cblabel "')
27 call str%append(this%get_label())
28 call str%append('"')
29 end if
30
31 ! Orientation
32 if (this%get_horizontal()) then
33 call str%append(new_line('a'))
34 call str%append("set colorbox horizontal")
35 call str%append(new_line('a'))
36 call str%append("set size 0.8,0.8; set origin 0.1,0.2")
37 call str%append(new_line('a'))
38 call str%append("set colorbox user origin 0.1,0.175 size 0.8,0.055")
39
40 if (len(this%get_label()) > 0) then
41 call str%append(new_line('a'))
42 call str%append("set cblabel offset 0,0.8")
43 end if
44 end if
45
46 ! Border & Tic Marks
47 if (.not.this%get_draw_border()) then
48 ! Eliminate the border
49 call str%append(new_line('a'))
50 call str%append("set colorbox noborder")
51
52 ! Hide the tic marks
53 call str%append(new_line('a'))
54 call str%append("set cbtic scale 0")
55 else
56 ! Respect the tic mark visibility setting if the border is shown
57 if (.not.this%get_show_tics()) then
58 call str%append(new_line('a'))
59 call str%append("set cbtic scale 0")
60 end if
61 end if
62
63 ! End
64 x = char(str%to_string())
65 end function
66
67! ------------------------------------------------------------------------------
68 pure module function cm_get_label(this) result(rst)
69 class(colormap), intent(in) :: this
70 character(len = :), allocatable :: rst
71 if (allocated(this%m_label)) then
72 rst = this%m_label
73 else
74 rst = ""
75 end if
76 end function
77
78! --------------------
79 module subroutine cm_set_label(this, x)
80 class(colormap), intent(inout) :: this
81 character(len = *), intent(in) :: x
82 this%m_label = x
83 end subroutine
84
85! ------------------------------------------------------------------------------
86 pure module function cm_get_horizontal(this) result(rst)
87 class(colormap), intent(in) :: this
88 logical :: rst
89 rst = this%m_horizontal
90 end function
91
92! --------------------
93 module subroutine cm_set_horizontal(this, x)
94 class(colormap), intent(inout) :: this
95 logical, intent(in) :: x
96 this%m_horizontal = x
97 end subroutine
98
99! ------------------------------------------------------------------------------
100 pure module function cm_get_draw_border(this) result(rst)
101 class(colormap), intent(in) :: this
102 logical :: rst
103 rst = this%m_drawBorder
104 end function
105
106! --------------------
107 module subroutine cm_set_draw_border(this, x)
108 class(colormap), intent(inout) :: this
109 logical, intent(in) :: x
110 this%m_drawBorder = x
111 end subroutine
112
113! ------------------------------------------------------------------------------
114 pure module function cm_get_show_tics(this) result(rst)
115 class(colormap), intent(in) :: this
116 logical :: rst
117 rst = this%m_showTics
118 end function
119
120! --------------------
121 module subroutine cm_set_show_tics(this, x)
122 class(colormap), intent(inout) :: this
123 logical, intent(in) :: x
124 this%m_showTics = x
125 end subroutine
126
127! ------------------------------------------------------------------------------
128! TO DO:
129! - Set user-defined tic labels & limits (ref: http://gnuplot.sourceforge.net/demo_5.4/cerf.html)
130
131! ******************************************************************************
132! RAINBOW_COLORMAP MEMBERS
133! ------------------------------------------------------------------------------
134 module function rcm_get_clr(this) result(x)
135 class(rainbow_colormap), intent(in) :: this
136 character(len = :), allocatable :: x
137 x = '0 "dark-blue", 1 "blue", 2 "cyan", 3 "green", 4 "yellow", ' // &
138 '5 "orange", 6 "red", 7 "dark-red"'
139 end function
140
141! ******************************************************************************
142! HOT_COLORMAP MEMBERS
143! ------------------------------------------------------------------------------
144 module function hcm_get_clr(this) result(x)
145 class(hot_colormap), intent(in) :: this
146 character(len = :), allocatable :: x
147 x = '0 "black", 1 "red", 2 "orange", 3 "yellow", 4 "white"'
148 end function
149
150! ******************************************************************************
151! COOL_COLORMAP MEMBERS
152! ------------------------------------------------------------------------------
153 module function ccm_get_clr(this) result(x)
154 class(cool_colormap), intent(in) :: this
155 character(len = :), allocatable :: x
156
157 type(string_builder) :: str
158
159 call str%append("0 '#08589E',")
160 call str%append("1 '#2B8CBE',")
161 call str%append("2 '#4EB3D3',")
162 call str%append("3 '#7BCCC4',")
163 call str%append("4 '#A8DDB5',")
164 call str%append("5 '#CCEBC5',")
165 call str%append("6 '#E0F3DB',")
166 call str%append("7 '#F7FCF0'")
167
168 x = char(str%to_string())
169 ! x = '0 "blue", 1 "turquoise", 2 "light-green"'
170 end function
171
172! ******************************************************************************
173! PARULA_COLORMAP MEMBERS
174! ------------------------------------------------------------------------------
175 module function pcm_get_clr(this) result(x)
176 class(parula_colormap), intent(in) :: this
177 character(len = :), allocatable :: x
178
179 type(string_builder) :: str
180
181 call str%append("0 '#352a87',")
182 call str%append("1 '#0363e1',")
183 call str%append("2 '#1485d4',")
184 call str%append("3 '#06a7c6',")
185 call str%append("4 '#38b99e',")
186 call str%append("5 '#92bf73',")
187 call str%append("6 '#d9ba56',")
188 call str%append("7 '#fcce2e',")
189 call str%append("8 '#f9fb0e'")
190
191 x = char(str%to_string())
192 end function
193
194! ******************************************************************************
195! GREY_COLORMAP MEMBERS
196! ------------------------------------------------------------------------------
197 module function gcm_get_clr(this) result(x)
198 class(grey_colormap), intent(in) :: this
199 character(len = :), allocatable :: x
200
201 type(string_builder) :: str
202
203 call str%append("0 '#FFFFFF',")
204 call str%append("1 '#F0F0F0',")
205 call str%append("2 '#D9D9D9',")
206 call str%append("3 '#BDBDBD',")
207 call str%append("4 '#969696',")
208 call str%append("5 '#737373',")
209 call str%append("6 '#525252',")
210 call str%append("7 '#252525'")
211
212 x = char(str%to_string())
213 end function
214
215! ******************************************************************************
216! EARTH_COLORMAP
217! ------------------------------------------------------------------------------
218 module function ecm_get_clr(this) result(x)
219 class(earth_colormap), intent(in) :: this
220 character(len = :), allocatable :: x
221
222 type(string_builder) :: str
223
224 call str%append("0 '#8C510A',")
225 call str%append("1 '#BF812D',")
226 call str%append("2 '#DFC27D',")
227 call str%append("3 '#F6E8C3',")
228 call str%append("4 '#D9F0D3',")
229 call str%append("5 '#A6DBA0',")
230 call str%append("6 '#5AAE61',")
231 call str%append("7 '#1B7837'")
232
233 x = char(str%to_string())
234 end function
235
236! ------------------------------------------------------------------------------
237! Additional Color Maps:
238! https://github.com/Gnuplotting/gnuplot-palettes
239
240! ******************************************************************************
241! ADDED: Jan. 08, 2024 - JAC
242! ------------------------------------------------------------------------------
243 module function custom_get_clr(this) result(x)
244 class(custom_colormap), intent(in) :: this
245 character(len = :), allocatable :: x
246
247 type(string_builder) :: str
248 integer(int32) :: i, n, r, g, b
249 type(color) :: clr
250
251 if (.not.associated(this%m_map)) then
252 allocate(character(len = 0) :: x)
253 return
254 end if
255
256 n = this%m_map%get_levels()
257 do i = 0, n - 1
258 ! Get the RGB triple
259 call this%m_map%get_RGB(i, clr%red, clr%green, clr%blue)
260
261 ! Append the color information
262 call str%append(to_string(i))
263 call str%append(" '#")
264 call str%append(clr%to_hex_string())
265 call str%append("'")
266 if (i /= n - 1) then
267 call str%append(",")
268 end if
269 end do
270
271 x = char(str%to_string())
272 end function
273
274! ------------------------------------------------------------------------------
275 module subroutine custom_set(this, map, err)
276 ! Arguments
277 class(custom_colormap), intent(inout) :: this
278 class(cmap), intent(in) :: map
279 class(errors), intent(inout), optional, target :: err
280
281 ! Local Variables
282 integer(int32) :: flag
283 class(errors), pointer :: errmgr
284 type(errors), target :: deferr
285
286 ! Initialization
287 if (present(err)) then
288 errmgr => err
289 else
290 errmgr => deferr
291 end if
292
293 ! Process
294 if (associated(this%m_map)) deallocate(this%m_map)
295 allocate(this%m_map, source = map, stat = flag)
296 if (flag /= 0) then
297 call errmgr%report_error("custom_init", &
298 "Memory allocation error code " // char(to_string(flag)) // ".", &
299 plot_out_of_memory_error)
300 return
301 end if
302 end subroutine
303
304! ------------------------------------------------------------------------------
305 module function custom_get(this) result(rst)
306 class(custom_colormap), intent(in) :: this
307 class(cmap), pointer :: rst
308 rst => this%m_map
309 end function
310
311! ------------------------------------------------------------------------------
312 module subroutine custom_final(this)
313 type(custom_colormap), intent(inout) :: this
314 if (associated(this%m_map)) then
315 deallocate(this%m_map)
316 nullify(this%m_map)
317 end if
318 end subroutine
319
320! ------------------------------------------------------------------------------
321end submodule
fplot_core