Skip to content

Commit abdf021

Browse files
Add clean data functionality
1 parent 81211c0 commit abdf021

12 files changed

Lines changed: 148 additions & 5 deletions

src/fplot_filled_plot_data.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module fplot_filled_plot_data
2424
procedure, public :: get_command_string => fpd_get_cmd
2525
procedure, public :: get_data_string => fpd_get_data_cmd
2626
procedure, public :: define_data => fpd_define_data
27+
procedure, public :: clean_data => fpd_clean_data
2728
end type
2829

2930
contains
@@ -209,5 +210,13 @@ subroutine fpd_define_data(this, x, y, yc, err)
209210
end do
210211
end subroutine
211212

213+
! ------------------------------------------------------------------------------
214+
subroutine fpd_clean_data(this)
215+
!! Cleans the data from this data set.
216+
class(filled_plot_data), intent(inout) :: this
217+
!! The filled_plot_data object.
218+
if (allocated(this%m_data)) deallocate(this%m_data)
219+
end subroutine
220+
212221
! ------------------------------------------------------------------------------
213222
end module

src/fplot_plot_data.f90

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ module fplot_plot_data
3434
procedure, public :: set_datablock_name => pd_set_datablock_name
3535
procedure, public :: create_unique_datablock_name => &
3636
pd_create_unique_datablock_name
37+
procedure, public :: clean => pd_clean
3738
procedure(pd_get_string_result), deferred, public :: get_data_string
39+
procedure(pd_clean_action), deferred, public :: clean_data
3840
end type
3941

4042
interface
@@ -46,6 +48,13 @@ function pd_get_string_result(this) result(x)
4648
character(len = :), allocatable :: x
4749
!! The string.
4850
end function
51+
52+
subroutine pd_clean_action(this)
53+
!! Performs a cleaning operation.
54+
import plot_data
55+
class(plot_data), intent(inout) :: this
56+
!! The plot_data object.
57+
end subroutine
4958
end interface
5059

5160
type, abstract, extends(plot_data) :: plot_data_colored
@@ -241,13 +250,27 @@ subroutine pd_create_unique_datablock_name(this)
241250
real(real64) :: r, rng
242251
integer(int32) :: count
243252

253+
call random_seed()
244254
call random_number(r)
245255
r = r * huge(count)
246256
count = floor(r)
247257
str = "PlotData" // to_string(count)
248258
call this%set_datablock_name(char(str))
249259
end subroutine
250260

261+
! ------------------------------------------------------------------------------
262+
subroutine pd_clean(this)
263+
!! Cleans the data set by removing stored data and clearing the
264+
!! GNUPLOT datablock name. This routine also calls clean_data to
265+
!! ensure the data is cleared from the data set as well as the datablock
266+
!! name.
267+
class(plot_data), intent(inout) :: this
268+
!! The plot_data object.
269+
270+
call this%set_datablock_name("")
271+
call this%clean_data()
272+
end subroutine
273+
251274
! ******************************************************************************
252275
! PLOT_DATA_COLORED
253276
! ------------------------------------------------------------------------------

src/fplot_plot_data_2d.f90

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module fplot_plot_data_2d
3333
procedure, public :: get_y_data => pd2d_get_y_array
3434
procedure, public :: get_color_data => pd2d_get_c_array
3535
procedure, public :: get_point_size_data => pd2d_get_ps_array
36+
procedure, public :: clean_data => pd2d_clean_data
3637
end type
3738

3839
contains
@@ -443,8 +444,6 @@ function pd2d_get_c_array(this) result(x)
443444
end if
444445
end function
445446

446-
! ******************************************************************************
447-
! ADDED: JAN. 12, 2024 - JAC
448447
! ------------------------------------------------------------------------------
449448
function pd2d_get_ps_array(this) result(x)
450449
!! Gets the stored point size data array.
@@ -461,5 +460,13 @@ function pd2d_get_ps_array(this) result(x)
461460
end if
462461
end function
463462

463+
! ------------------------------------------------------------------------------
464+
subroutine pd2d_clean_data(this)
465+
!! Cleans the data from this data set.
466+
class(plot_data_2d), intent(inout) :: this
467+
!! The plot_data_2d object.
468+
if (allocated(this%m_data)) deallocate(this%m_data)
469+
end subroutine
470+
464471
! ------------------------------------------------------------------------------
465472
end module

src/fplot_plot_data_3d.f90

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module fplot_plot_data_3d
2929
procedure, public :: get_z_data => pd3d_get_z_array
3030
procedure, public :: get_color_data => pd3d_get_c_array
3131
procedure, public :: get_point_size_data => pd3d_get_c_array
32+
procedure, public :: clean_data => pd3d_clean_data
3233
end type
3334

3435
contains
@@ -420,8 +421,6 @@ function pd3d_get_c_array(this) result(x)
420421
end if
421422
end function
422423

423-
! ******************************************************************************
424-
! ADDED: JAN. 12, 2020 - JAC
425424
! ------------------------------------------------------------------------------
426425
function pd3d_get_ps_array(this) result(x)
427426
!! Gets the stored point scaling data array.
@@ -438,5 +437,13 @@ function pd3d_get_ps_array(this) result(x)
438437
end if
439438
end function
440439

440+
! ------------------------------------------------------------------------------
441+
subroutine pd3d_clean_data(this)
442+
!! Cleans the data from this data set.
443+
class(plot_data_3d), intent(inout) :: this
444+
!! The plot_data_3d object.
445+
if (allocated(this%m_data)) deallocate(this%m_data)
446+
end subroutine
447+
441448
! ------------------------------------------------------------------------------
442449
end module

src/fplot_plot_data_bar.f90

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module fplot_plot_data_bar
5555
procedure, public :: set_data_1 => pdb_set_data_1_core
5656
procedure, public :: set_data_2 => pdb_set_data_2_core
5757
procedure, public :: set_data_3 => pdb_set_data_3_core
58+
procedure, public :: clean_data => pdb_clean_data
5859
end type
5960

6061
contains
@@ -583,5 +584,14 @@ subroutine pdb_set_data_3_core(this, labels, x, fmt, err)
583584
this%m_axisLabels = lbls
584585
end subroutine
585586

587+
! ------------------------------------------------------------------------------
588+
subroutine pdb_clean_data(this)
589+
!! Cleans the data from this data set.
590+
class(plot_data_bar), intent(inout) :: this
591+
!! The plot_data_bar object.
592+
if (allocated(this%m_axisLabels)) deallocate(this%m_axisLabels)
593+
if (allocated(this%m_barData)) deallocate(this%m_barData)
594+
end subroutine
595+
586596
! ------------------------------------------------------------------------------
587597
end module

src/fplot_plot_data_box_whisker.f90

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module fplot_plot_data_box_whisker
5555
procedure, public :: set_fill_boxes => pdbw_set_fill_boxes
5656
procedure, public :: get_box_fill_opacity => pdbw_get_opacity
5757
procedure, public :: set_box_fill_opacity => pdbw_set_opacity
58+
procedure, public :: clean_data => pdbw_clean_data
5859
end type
5960

6061
contains
@@ -379,5 +380,17 @@ subroutine pdbw_set_opacity(this, x)
379380
this%m_boxOpacity = x
380381
end subroutine
381382

383+
! ------------------------------------------------------------------------------
384+
subroutine pdbw_clean_data(this)
385+
!! Cleans the data from this data set.
386+
class(plot_data_box_whisker), intent(inout) :: this
387+
!! The plot_data_box_whisker object.
388+
if (allocated(this%m_x)) deallocate(this%m_x)
389+
if (allocated(this%m_boxMin)) deallocate(this%m_boxMin)
390+
if (allocated(this%m_boxMax)) deallocate(this%m_boxMax)
391+
if (allocated(this%m_whiskerMin)) deallocate(this%m_whiskerMin)
392+
if (allocated(this%m_whiskerMin)) deallocate(this%m_whiskerMin)
393+
end subroutine
394+
382395
! ------------------------------------------------------------------------------
383396
end module

src/fplot_plot_data_error_bars.f90

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module fplot_plot_data_error_bars
4141
procedure, public :: get_use_error_box => pde_get_box
4242
procedure, public :: set_use_error_box => pde_set_box
4343
procedure, public :: get_use_range => pde_get_use_range
44-
44+
procedure, public :: clean_data => pde_clean_data
4545
procedure :: pde_define_x_err
4646
procedure :: pde_define_y_err
4747
procedure :: pde_define_xy_err
@@ -715,5 +715,13 @@ subroutine pde_define_xy_err_lim(this, x, y, xmin, xmax, ymin, &
715715
this%m_range = .true.
716716
end subroutine
717717

718+
! ------------------------------------------------------------------------------
719+
subroutine pde_clean_data(this)
720+
!! Cleans the data from this data set.
721+
class(plot_data_error_bars), intent(inout) :: this
722+
!! The plot_data_error_bars object.
723+
if (allocated(this%m_data)) deallocate(this%m_data)
724+
end subroutine
725+
718726
! ------------------------------------------------------------------------------
719727
end module

src/fplot_plot_data_histogram.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module fplot_plot_data_histogram
4040
procedure, public :: get_draw_against_y2 => pdh_get_use_y2
4141
procedure, public :: set_draw_against_y2 => pdh_set_use_y2
4242
procedure, public :: get => pdh_get_bin_data
43+
procedure, public :: clean_data => pdh_clean_data
4344
end type
4445

4546
contains
@@ -307,5 +308,13 @@ subroutine pdh_get_bin_data(this, i, x, cnt)
307308
cnt = floor(this%m_data(i,1))
308309
end subroutine
309310

311+
! ------------------------------------------------------------------------------
312+
subroutine pdh_clean_data(this)
313+
!! Cleans the data from this data set.
314+
class(plot_data_histogram), intent(inout) :: this
315+
!! The plot_data_histogram object.
316+
if (allocated(this%m_data)) deallocate(this%m_data)
317+
end subroutine
318+
310319
! ------------------------------------------------------------------------------
311320
end module

src/fplot_plot_data_tri_2d.f90

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module fplot_plot_data_tri_2d
3232
procedure, public :: set_line_width => pdt2d_set_line_width
3333
procedure, public :: get_line_style => pdt2d_get_line_style
3434
procedure, public :: set_line_style => pdt2d_set_line_style
35+
procedure, public :: clean_data => pdt2d_clean_data
3536
end type
3637

3738
contains
@@ -279,5 +280,15 @@ subroutine pdt2d_set_line_style(this, x)
279280
end if
280281
end subroutine
281282

283+
! ------------------------------------------------------------------------------
284+
subroutine pdt2d_clean_data(this)
285+
!! Cleans the data from this data set.
286+
class(plot_data_tri_2d), intent(inout) :: this
287+
!! The plot_data_tri_2d object.
288+
if (allocated(this%m_indices)) deallocate(this%m_indices)
289+
if (allocated(this%m_x)) deallocate(this%m_x)
290+
if (allocated(this%m_y)) deallocate(this%m_y)
291+
end subroutine
292+
282293
! ------------------------------------------------------------------------------
283294
end module

src/fplot_surface_plot_data.f90

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module fplot_surface_plot_data
3232
procedure, public :: get_command_string => surfd_get_cmd
3333
procedure, public :: get_data_string => surfd_get_data_cmd
3434
procedure, public :: define_data => surfd_set_data_1
35+
procedure, public :: clean_data => surfd_clean_data
3536
end type
3637

3738
contains
@@ -319,5 +320,15 @@ subroutine surfd_set_data_1(this, x, y, z, err)
319320
end do
320321
end subroutine
321322

323+
! ------------------------------------------------------------------------------
324+
subroutine surfd_clean_data(this)
325+
!! Cleans the data from this data set.
326+
class(surface_plot_data), intent(inout) :: this
327+
!! The surface_plot_data object.
328+
if (allocated(this%m_x)) deallocate(this%m_x)
329+
if (allocated(this%m_y)) deallocate(this%m_y)
330+
if (allocated(this%m_z)) deallocate(this%m_z)
331+
end subroutine
332+
322333
! ------------------------------------------------------------------------------
323334
end module

0 commit comments

Comments
 (0)