buffer_token_1D_t Derived Type

type, public :: buffer_token_1D_t

@brief Re-sizeable array type that can be filled elementwise to build up a contiguous data chunk that can then be dumped to an allocatable

@details For multidimensional buffers only the last dimension can grow. (i.e. it is only possible to add columns.)

The buffer has to be initiliazed before first use. After dumping (dump_reset) it is automatically resetted.


Components

Type Visibility Attributes Name Initial
type(Token_t), public, dimension(:), allocatable :: buf
integer(kind=int64), private :: pos
real(kind=dp), private :: grow_factor = 1.5_dp
integer(kind=int64), private :: start_size = 100_int64

Type-Bound Procedures

procedure, public :: init => init_token_1D

  • private pure subroutine init_token_1D(this, grow_factor, start_size)

    @brief Set up the re-sizeable array (buffer) with a given start size and grow_factor.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(buffer_token_1D_t), intent(inout) :: this
    real(kind=dp), intent(in), optional :: grow_factor

    Factor about which to grow the buffer, if the capacity is not sufficient.

    integer(kind=int64), intent(in), optional :: start_size

    Initial size of the buffer.

procedure, public :: finalize => finalize_token_1D

  • private pure subroutine finalize_token_1D(this)

    @brief Deallocate the resource.

    Arguments

    Type IntentOptional Attributes Name
    class(buffer_token_1D_t), intent(inout) :: this

procedure, private :: reset => reset_token_1D

  • private pure subroutine reset_token_1D(this)

    @brief Reset an already initiliazed buffer.

    Arguments

    Type IntentOptional Attributes Name
    class(buffer_token_1D_t), intent(inout) :: this

procedure, public :: size => get_size_token_1D

  • private pure function get_size_token_1D(this) result(n_els)

    @brief Returns the number of already stored elements in the buffer along the last dimension.

    Arguments

    Type IntentOptional Attributes Name
    class(buffer_token_1D_t), intent(in) :: this

    Return Value integer(kind=int64)

procedure, public :: capacity => get_capacity_token_1D

  • private pure function get_capacity_token_1D(this) result(capacity)

    @brief Returns the capacity of the buffer along the last dimension.

    Arguments

    Type IntentOptional Attributes Name
    class(buffer_token_1D_t), intent(in) :: this

    Return Value integer(kind=int64)

procedure, public :: push_back => add_val_token_1D

  • private pure subroutine add_val_token_1D(this, val)

    @brief Append a value to the buffer, expanding the capacity if necessary.

    Arguments

    Type IntentOptional Attributes Name
    class(buffer_token_1D_t), intent(inout) :: this
    type(Token_t), intent(in) :: val

    Value to be added

procedure, private :: dump => dump_token_1D

  • private pure subroutine dump_token_1D(this, tgt)

    @brief Dump the buffer to an allocatable array.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(buffer_token_1D_t), intent(inout) :: this
    type(Token_t), intent(out), dimension(:), allocatable :: tgt

    Allocatable array (reset upon entry), contains the stored elements of

procedure, public :: dump_reset => dump_reset_token_1D

  • private pure subroutine dump_reset_token_1D(this, tgt)

    Dump the buffer to an allocatable array and reset the buffer.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(buffer_token_1D_t), intent(inout) :: this
    type(Token_t), intent(out), dimension(:), allocatable :: tgt

    Allocatable array (reset upon entry), contains the stored elements of

Source Code

    type :: buffer_token_1D_t
        private

        type(Token_t), dimension(:), allocatable, public :: buf
        ! Internal position of the buffer
        integer(int64) :: pos
        real(dp) :: grow_factor = 1.5_dp
        integer(int64) :: start_size = 100_int64

    contains

        procedure :: init => init_token_1D
        procedure :: finalize => finalize_token_1D
        procedure, private :: reset => reset_token_1D

        procedure :: size => get_size_token_1D
        procedure :: capacity => get_capacity_token_1D

        procedure :: push_back => add_val_token_1D

        procedure, private :: dump => dump_token_1D
        procedure :: dump_reset => dump_reset_token_1D
    end type buffer_token_1D_t