fplot 1.7.1
A Fortran library providing a convenient interface for plotting with Gnuplot.
Loading...
Searching...
No Matches
fplot_filled_plot_data.f90
1! fplot_filled_plot_data.f90
2
3submodule(fplot_core) fplot_filled_plot_data
4contains
5! ------------------------------------------------------------------------------
6 module function fpd_get_axes_cmd(this) result(x)
7 ! Arguments
8 class(filled_plot_data), intent(in) :: this
9 character(len = :), allocatable :: x
10
11 ! Define which axes the data is to be plotted against
12 if (this%get_draw_against_y2()) then
13 x = "axes x1y2"
14 else
15 x = "axes x1y1"
16 end if
17 end function
18
19! ------------------------------------------------------------------------------
20 pure module function fpd_get_draw_against_y2(this) result(x)
21 class(filled_plot_data), intent(in) :: this
22 logical :: x
23 x = this%m_useY2
24 end function
25
26! --------------------
27 module subroutine fpd_set_draw_against_y2(this, x)
28 class(filled_plot_data), intent(inout) :: this
29 logical, intent(in) :: x
30 this%m_useY2 = x
31 end subroutine
32
33! ------------------------------------------------------------------------------
34 module function fpd_get_cmd(this) result(x)
35 ! Arguments
36 class(filled_plot_data), intent(in) :: this
37 character(len = :), allocatable :: x
38
39 ! Local Variables
40 type(string_builder) :: str
41 integer(int32) :: n
42 type(color) :: clr
43
44 ! Initialization
45 call str%initialize()
46
47 ! Title
48 n = len_trim(this%get_name())
49 if (n > 0) then
50 call str%append(' "-" title "')
51 call str%append(this%get_name())
52 call str%append('"')
53 else
54 call str%append(' "-" notitle')
55 end if
56
57 ! Establish filled data
58 call str%append(" with filledcurves")
59
60 ! Line Color
61 clr = this%get_line_color()
62 call str%append(' lc rgb "#')
63 call str%append(clr%to_hex_string())
64 call str%append('"')
65
66 ! Define the axes structure
67 call str%append(" ")
68 call str%append(this%get_axes_string())
69
70 ! End
71 x = char(str%to_string())
72 end function
73
74! ------------------------------------------------------------------------------
75 module function fpd_get_data_cmd(this) result(x)
76 ! Arguments
77 class(filled_plot_data), intent(in) :: this
78 character(len = :), allocatable :: x
79
80 ! Local Variables
81 type(string_builder) :: str
82 integer(int32) :: i
83 character(len = :), allocatable :: nl, delimiter
84
85 ! Initialization
86 call str%initialize()
87 delimiter = achar(9) ! tab delimiter
88 nl = new_line(nl)
89
90 ! Process
91 do i = 1, size(this%m_data, 1)
92 call str%append(to_string(this%m_data(i,1)))
93 call str%append(delimiter)
94 call str%append(to_string(this%m_data(i,2)))
95 call str%append(delimiter)
96 call str%append(to_string(this%m_data(i,3)))
97 call str%append(nl)
98 end do
99
100 ! End
101 x = char(str%to_string())
102 end function
103
104! ------------------------------------------------------------------------------
105 module subroutine fpd_define_data(this, x, y, yc, err)
106 ! Arguments
107 class(filled_plot_data), intent(inout) :: this
108 real(real64), intent(in), dimension(:) :: x, y, yc
109 class(errors), intent(inout), optional, target :: err
110
111 ! Local Variables
112 type(errors), target :: deferr
113 class(errors), pointer :: errmgr
114 character(len = 256) :: errmsg
115 integer(int32) :: i, n, flag
116
117 ! Set up error handling
118 if (present(err)) then
119 errmgr => err
120 else
121 errmgr => deferr
122 end if
123
124 ! Input Checking
125 n = size(x)
126 if (size(y) /= n) then
127 write(errmsg, 100) "Expected the y array to have ", n, &
128 " elements, but found an array with ", size(y), " elements."
129 call errmgr%report_error("fpd_define_data", trim(errmsg), &
130 plot_array_size_mismatch_error)
131 return
132 end if
133 if (size(yc) /= n) then
134 write(errmsg, 100) "Expected the yc array to have ", n, &
135 " elements, but found an array with ", size(yc), " elements."
136 call errmgr%report_error("fpd_define_data", trim(errmsg), &
137 plot_array_size_mismatch_error)
138 return
139 end if
140
141 ! Allocate space for the data
142 if (allocated(this%m_data)) deallocate(this%m_data)
143 allocate(this%m_data(n, 3), stat = flag)
144 if (flag /= 0) then
145 call errmgr%report_error("fpd_define_data", &
146 "Insufficient memory available.", &
147 plot_out_of_memory_error)
148 return
149 end if
150
151 ! Store the data
152 do concurrent(i = 1:n)
153 this%m_data(i,1) = x(i)
154 this%m_data(i,2) = y(i)
155 this%m_data(i,3) = yc(i)
156 end do
157
158100 format(a, i0, a, i0, a)
159 end subroutine
160
161! ------------------------------------------------------------------------------
162end submodule
fplot_core