Skip to content

Commit 329a032

Browse files
Implement datablocks
1 parent 83fa381 commit 329a032

15 files changed

Lines changed: 223 additions & 52 deletions

src/fplot_filled_plot_data.f90

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,18 @@ function fpd_get_cmd(this) result(x)
8585
! Initialization
8686
call str%initialize()
8787

88+
! Data Block
89+
call str%append(" $")
90+
call str%append(this%get_datablock_name())
91+
8892
! Title
8993
n = len_trim(this%get_name())
9094
if (n > 0) then
91-
call str%append(' "-" title "')
95+
call str%append(' title "')
9296
call str%append(this%get_name())
9397
call str%append('"')
9498
else
95-
call str%append(' "-" notitle')
99+
call str%append(' notitle')
96100
end if
97101

98102
! Establish filled data
@@ -192,6 +196,11 @@ subroutine fpd_define_data(this, x, y, yc, err)
192196
return
193197
end if
194198

199+
! Create a name
200+
if (len(this%get_datablock_name()) == 0) then
201+
call this%create_unique_datablock_name()
202+
end if
203+
195204
! Store the data
196205
do concurrent (i = 1:n)
197206
this%m_data(i,1) = x(i)

src/fplot_plot_2d.f90

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -296,27 +296,28 @@ function p2d_get_cmd(this) result(x)
296296
call str%append("unset jitter")
297297
end if
298298

299-
! Define the plot function and data formatting commands
299+
! Define the datablock
300300
n = this%get_count()
301-
call str%append(new_line('a'))
302-
call str%append("plot ")
303301
do i = 1, n
304302
ptr => this%get(i)
305303
if (.not.associated(ptr)) cycle
306-
call str%append(ptr%get_command_string())
307-
if (i /= n) call str%append(", ")
304+
call str%append(new_line('a'))
305+
call str%append("$")
306+
call str%append(ptr%get_datablock_name())
307+
call str%append(" << EOD")
308+
call str%append(new_line('a'))
309+
call str%append(ptr%get_data_string())
310+
call str%append("EOD")
308311
end do
309312

310-
! Define the data to plot
313+
! Define the plot function and data formatting commands
314+
call str%append(new_line('a'))
315+
call str%append("plot ")
311316
do i = 1, n
312317
ptr => this%get(i)
313318
if (.not.associated(ptr)) cycle
314-
call str%append(new_line('a'))
315-
call str%append(ptr%get_data_string())
316-
call str%append("e")
317-
! if (i /= n) then
318-
! call str%append("e")
319-
! end if
319+
call str%append(ptr%get_command_string())
320+
if (i /= n) call str%append(", ")
320321
end do
321322

322323
! End

src/fplot_plot_3d.f90

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,27 +290,28 @@ function p3d_get_cmd(this) result(x)
290290
call str%append("set mapping spherical")
291291
end if
292292

293-
! Define the plot function and data formatting commands
293+
! Define the datablock
294294
n = this%get_count()
295-
call str%append(new_line('a'))
296-
call str%append("splot ")
297295
do i = 1, n
298296
ptr => this%get(i)
299297
if (.not.associated(ptr)) cycle
300-
call str%append(ptr%get_command_string())
301-
if (i /= n) call str%append(", ")
298+
call str%append(new_line('a'))
299+
call str%append("$")
300+
call str%append(ptr%get_datablock_name())
301+
call str%append(" << EOD")
302+
call str%append(new_line('a'))
303+
call str%append(ptr%get_data_string())
304+
call str%append("EOD")
302305
end do
303306

304-
! Define the data to plot
307+
! Define the plot function and data formatting commands
308+
call str%append(new_line('a'))
309+
call str%append("splot ")
305310
do i = 1, n
306311
ptr => this%get(i)
307312
if (.not.associated(ptr)) cycle
308-
call str%append(new_line('a'))
309-
call str%append(ptr%get_data_string())
310-
call str%append("e")
311-
! if (i /= n) then
312-
! call str%append("e")
313-
! end if
313+
call str%append(ptr%get_command_string())
314+
if (i /= n) call str%append(", ")
314315
end do
315316

316317
! End

src/fplot_plot_data.f90

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/fplot_plot_data_2d.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ subroutine pd2d_set_data_1(this, x, y, c, ps, err)
249249
errmgr => deferr
250250
end if
251251

252+
if (len(this%get_datablock_name()) == 0) then
253+
call this%create_unique_datablock_name()
254+
end if
255+
252256
! Input Check
253257
if (size(y) /= n) then
254258
call report_array_size_mismatch_error(errmgr, "pd2d_set_data_1", &
@@ -374,6 +378,10 @@ subroutine pd2d_set_data_2(this, y, err)
374378
errmgr => deferr
375379
end if
376380

381+
if (len(this%get_datablock_name()) == 0) then
382+
call this%create_unique_datablock_name()
383+
end if
384+
377385
! Process
378386
if (allocated(this%m_data)) deallocate(this%m_data)
379387
allocate(this%m_data(n, 2), stat = flag)

src/fplot_plot_data_3d.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ subroutine pd3d_set_data_1(this, x, y, z, c, ps, err)
283283
errmgr => deferr
284284
end if
285285

286+
if (len(this%get_datablock_name()) == 0) then
287+
call this%create_unique_datablock_name()
288+
end if
289+
286290
! Input Check
287291
if (size(y) /= n) then
288292
call report_array_size_mismatch_error(errmgr, "pd3d_set_data_1", &

src/fplot_plot_data_bar.f90

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ function pdb_get_cmd(this) result(x)
188188
! Initialization
189189
call str%initialize()
190190

191-
! Starting off...
192-
call str%append(' "-" ')
191+
! Data Block
192+
call str%append(" $")
193+
call str%append(this%get_datablock_name())
193194

194195
! Tic Labels
195196
if (this%get_use_labels() .and. allocated(this%m_barData) .and. &
@@ -456,6 +457,10 @@ subroutine pdb_set_data_1_core(this, x, err)
456457
end if
457458
n = size(x)
458459

460+
if (len(this%get_datablock_name()) == 0) then
461+
call this%create_unique_datablock_name()
462+
end if
463+
459464
! Process
460465
if (allocated(this%m_axisLabels)) deallocate(this%m_axisLabels)
461466
if (allocated(this%m_barData)) deallocate(this%m_barData)
@@ -492,6 +497,10 @@ subroutine pdb_set_data_2_core(this, labels, x, err)
492497
end if
493498
n = size(x)
494499

500+
if (len(this%get_datablock_name()) == 0) then
501+
call this%create_unique_datablock_name()
502+
end if
503+
495504
! Input Check
496505
if (size(labels) /= n) then
497506
call report_array_size_mismatch_error(errmgr, "pdb_set_data_2_core", &
@@ -540,6 +549,10 @@ subroutine pdb_set_data_3_core(this, labels, x, fmt, err)
540549
end if
541550
n = size(x)
542551

552+
if (len(this%get_datablock_name()) == 0) then
553+
call this%create_unique_datablock_name()
554+
end if
555+
543556
! Input Check
544557
if (size(labels) /= n) then
545558
call report_array_size_mismatch_error(errmgr, "pdb_set_data_3_core", &

src/fplot_plot_data_box_whisker.f90

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ subroutine pdbw_define_data_xstring(this, x, boxmin, boxmax, whiskermin, &
9090
end if
9191
n = size(x)
9292

93+
if (len(this%get_datablock_name()) == 0) then
94+
call this%create_unique_datablock_name()
95+
end if
96+
9397
! Allocations
9498
if (allocated(this%m_x)) deallocate(this%m_x)
9599
if (allocated(this%m_boxMin)) deallocate(this%m_boxMin)
@@ -121,9 +125,12 @@ function pdbw_get_cmd(this) result(rst)
121125
integer(int32) :: n, nname
122126
type(color) :: clr
123127

128+
! Data Block
129+
call str%append(" $")
130+
call str%append(this%get_datablock_name())
131+
124132
! Style
125-
! call str%append(' "-" using ($0+1):2:3:4:5:xtic(1) with candlesticks')
126-
call str%append(' "-" using ($0+1):2:3:4:5:(')
133+
call str%append(' using ($0+1):2:3:4:5:(')
127134
call str%append(to_string(this%get_box_width()))
128135
call str%append("):xtic(1) with candlesticks")
129136

src/fplot_plot_data_error_bars.f90

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,18 @@ function pde_get_cmd(this) result(cmd)
6767
! Initialization
6868
call str%initialize()
6969

70+
! Data Block
71+
call str%append(" $")
72+
call str%append(this%get_datablock_name())
73+
7074
! Title
7175
n = len_trim(this%get_name())
7276
if (n > 0) then
73-
call str%append(' "-" title "')
77+
call str%append(' title "')
7478
call str%append(this%get_name())
7579
call str%append('"')
7680
else
77-
call str%append(' "-" notitle')
81+
call str%append(' notitle')
7882
end if
7983

8084
! Color
@@ -225,6 +229,10 @@ subroutine pde_define_x_err(this, x, y, xerr, err)
225229
errmgr => deferr
226230
end if
227231

232+
if (len(this%get_datablock_name()) == 0) then
233+
call this%create_unique_datablock_name()
234+
end if
235+
228236
! Input Checking
229237
if (size(y) /= n) then
230238
call report_array_size_mismatch_error(errmgr, "pde_define_x_err", &
@@ -284,6 +292,10 @@ subroutine pde_define_y_err(this, x, y, yerr, err)
284292
errmgr => deferr
285293
end if
286294

295+
if (len(this%get_datablock_name()) == 0) then
296+
call this%create_unique_datablock_name()
297+
end if
298+
287299
! Input Checking
288300
if (size(y) /= n) then
289301
call report_array_size_mismatch_error(errmgr, "pde_define_y_err", &
@@ -344,6 +356,10 @@ subroutine pde_define_xy_err(this, x, y, xerr, yerr, err)
344356
errmgr => deferr
345357
end if
346358

359+
if (len(this%get_datablock_name()) == 0) then
360+
call this%create_unique_datablock_name()
361+
end if
362+
347363
! Input Checking
348364
if (size(y) /= n) then
349365
call report_array_size_mismatch_error(errmgr, "pde_define_xy_err", &
@@ -487,6 +503,10 @@ subroutine pde_define_x_err_lim(this, x, y, xmin, xmax, err)
487503
errmgr => deferr
488504
end if
489505

506+
if (len(this%get_datablock_name()) == 0) then
507+
call this%create_unique_datablock_name()
508+
end if
509+
490510
! Input Checking
491511
if (size(y) /= n) then
492512
call report_array_size_mismatch_error(errmgr, &
@@ -557,6 +577,10 @@ subroutine pde_define_y_err_lim(this, x, y, ymin, ymax, err)
557577
errmgr => deferr
558578
end if
559579

580+
if (len(this%get_datablock_name()) == 0) then
581+
call this%create_unique_datablock_name()
582+
end if
583+
560584
! Input Checking
561585
if (size(y) /= n) then
562586
call report_array_size_mismatch_error(errmgr, &
@@ -633,6 +657,10 @@ subroutine pde_define_xy_err_lim(this, x, y, xmin, xmax, ymin, &
633657
errmgr => deferr
634658
end if
635659

660+
if (len(this%get_datablock_name()) == 0) then
661+
call this%create_unique_datablock_name()
662+
end if
663+
636664
! Input Checking
637665
if (size(y) /= n) then
638666
call report_array_size_mismatch_error(errmgr, &

0 commit comments

Comments
 (0)