@@ -24,9 +24,16 @@ module fplot_plot_data
2424 private
2525 character (len = PLOTDATA_MAX_NAME_LENGTH) :: m_name = " "
2626 ! ! The name to associate with the data set.
27+ character (len = PLOTDATA_MAX_NAME_LENGTH) :: m_datablockName = " "
28+ ! ! The name to associate with the datablock used to store the data
29+ ! ! in the actual plot file.
2730 contains
2831 procedure , public :: get_name = > pd_get_name
2932 procedure , public :: set_name = > pd_set_name
33+ procedure , public :: get_datablock_name = > pd_get_datablock_name
34+ procedure , public :: set_datablock_name = > pd_set_datablock_name
35+ procedure , public :: create_unique_datablock_name = > &
36+ pd_create_unique_datablock_name
3037 procedure (pd_get_string_result), deferred, public :: get_data_string
3138 end type
3239
@@ -194,6 +201,53 @@ subroutine pd_set_name(this, txt)
194201 end if
195202 end subroutine
196203
204+ ! ------------------------------------------------------------------------------
205+ pure function pd_get_datablock_name (this ) result(rst)
206+ ! ! Gets the name to associate with the datablock in the actual GNUPLOT
207+ ! ! plot file.
208+ class(plot_data), intent (in ) :: this
209+ ! ! The plot_data object.
210+ character (len = :), allocatable :: rst
211+ ! ! The name.
212+
213+ rst = trim (this% m_datablockName)
214+ end function
215+
216+ ! --------------------
217+ subroutine pd_set_datablock_name (this , x )
218+ ! ! Sets the name to associate with the datablock in the actual GNUPLOT
219+ ! ! plot file.
220+ class(plot_data), intent (inout ) :: this
221+ ! ! The plot_data object.
222+ character (len = * ), intent (in ) :: x
223+ ! ! The name.
224+
225+ integer (int32) :: n
226+ n = min (len (x), PLOTDATA_MAX_NAME_LENGTH)
227+ this% m_datablockName = " "
228+ if (n /= 0 ) then
229+ this% m_datablockName(1 :n) = x(1 :n)
230+ end if
231+ end subroutine
232+
233+ ! ------------------------------------------------------------------------------
234+ subroutine pd_create_unique_datablock_name (this )
235+ ! ! Creates a unique name for the GNUPLOT datablock representing this
236+ ! ! data set.
237+ class(plot_data), intent (inout ) :: this
238+ ! ! The plot_data object.
239+
240+ type (string) :: str
241+ real (real64) :: r, rng
242+ integer (int32) :: count
243+
244+ call random_number (r)
245+ r = r * huge (count)
246+ count = floor (r)
247+ str = " PlotData" // to_string(count)
248+ call this% set_datablock_name(char (str))
249+ end subroutine
250+
197251! ******************************************************************************
198252! PLOT_DATA_COLORED
199253! ------------------------------------------------------------------------------
@@ -260,14 +314,18 @@ function spd_get_cmd(this) result(x)
260314 ! Initialization
261315 call str% initialize()
262316
317+ ! Data Block
318+ call str% append (" $" )
319+ call str% append (this% get_datablock_name())
320+
263321 ! Title
264322 n = len_trim (this% get_name())
265323 if (n > 0 ) then
266- call str% append (' "-" title "' )
324+ call str% append (' title "' )
267325 call str% append (this% get_name())
268326 call str% append (' "' )
269327 else
270- call str% append (' "-" notitle' )
328+ call str% append (' notitle' )
271329 end if
272330
273331 ! Lines, points, or filled
0 commit comments