data_frame Derived Type

type, public :: data_frame

Main data frame type for storing heterogeneous tabular data

A data frame consists of columns of potentially different types, similar to a spreadsheet or database table. Each column must have the same number of rows.

Type-bound Procedures

Constructor/Destructor

  • new([char_len]) - Initialize data frame
  • destroy() - Free memory

Basic Info

  • ncols() - Get number of columns
  • nrows() - Get number of rows
  • get_max_char_len() - Get maximum character length
  • header(index) - Get column header by index
  • dtype(index or header) - Get column data type
  • is_initialized() - Check if data frame is initialized

Components

Type Visibility Attributes Name Initial
type(column), private, dimension(:), allocatable :: data_cols
character(len=:), private, dimension(:), allocatable :: headers
logical, private :: initialized = .false.
integer, private :: max_char_len = MAX_CHAR_LEN_DEFAULT
integer, private :: num_cols = 0
logical, private :: with_headers = .false.

Type-Bound Procedures

procedure, public :: already_header

  • private function already_header(this, header) result(exists)

    Arguments

    Type IntentOptional Attributes Name
    class(data_frame), intent(in) :: this
    character(len=*), intent(in) :: header

    Return Value logical

procedure, public :: destroy => df_destructor

  • private subroutine df_destructor(this)

    Destroy a data frame and free all memory

    Read more…

    Arguments

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

procedure, private :: df_get_col_type_header

  • private pure function df_get_col_type_header(this, header) result(dtype)

    Arguments

    Type IntentOptional Attributes Name
    class(data_frame), intent(in) :: this
    character(len=*), intent(in) :: header

    Return Value integer

procedure, private :: df_get_col_type_index

  • private pure function df_get_col_type_index(this, index) result(dtype)

    Arguments

    Type IntentOptional Attributes Name
    class(data_frame), intent(in) :: this
    integer, intent(in) :: index

    Return Value integer

generic, public :: dtype => df_get_col_type_header, df_get_col_type_index

  • private pure function df_get_col_type_header(this, header) result(dtype)

    Arguments

    Type IntentOptional Attributes Name
    class(data_frame), intent(in) :: this
    character(len=*), intent(in) :: header

    Return Value integer

  • private pure function df_get_col_type_index(this, index) result(dtype)

    Arguments

    Type IntentOptional Attributes Name
    class(data_frame), intent(in) :: this
    integer, intent(in) :: index

    Return Value integer

procedure, public :: find_header_index

  • private pure function find_header_index(this, header) result(index)

    Arguments

    Type IntentOptional Attributes Name
    class(data_frame), intent(in) :: this
    character(len=*), intent(in) :: header

    Return Value integer

procedure, public :: get_data_col

  • private function get_data_col(this, index) result(col)

    Arguments

    Type IntentOptional Attributes Name
    class(data_frame), intent(in) :: this
    integer, intent(in) :: index

    Return Value type(column)

procedure, public :: get_max_char_len => df_get_max_char_len

  • private pure function df_get_max_char_len(this) result(max_len)

    Arguments

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

    Return Value integer

procedure, public :: get_with_headers

  • private pure function get_with_headers(this) result(has_headers)

    Arguments

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

    Return Value logical

procedure, public :: header => get_header

  • private function get_header(this, index) result(header)

    Arguments

    Type IntentOptional Attributes Name
    class(data_frame), intent(in) :: this
    integer, intent(in) :: index

    Return Value character(len=:), allocatable

procedure, public :: increment_num_cols

procedure, public :: is_initialized => df_is_initialized

  • private pure function df_is_initialized(this) result(is_init)

    Arguments

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

    Return Value logical

procedure, public :: ncols => df_get_num_cols

  • private pure function df_get_num_cols(this) result(num_cols)

    Arguments

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

    Return Value integer

procedure, public :: new => df_constructor

  • private subroutine df_constructor(this, char_len)

    Initialize a new data frame

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(data_frame), intent(inout) :: this
    integer, intent(in), optional :: char_len

procedure, public :: nrows => df_get_num_rows

  • private pure function df_get_num_rows(this) result(num_rows)

    Arguments

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

    Return Value integer

procedure, public :: resize_storage

  • private subroutine resize_storage(this)

    Arguments

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

procedure, public :: set_data_col

  • private subroutine set_data_col(this, index, col)

    Arguments

    Type IntentOptional Attributes Name
    class(data_frame), intent(inout) :: this
    integer, intent(in) :: index
    type(column), intent(in) :: col

procedure, public :: set_header_at_index

  • private subroutine set_header_at_index(this, index, header)

    Arguments

    Type IntentOptional Attributes Name
    class(data_frame), intent(inout) :: this
    integer, intent(in) :: index
    character(len=*), intent(in) :: header

procedure, public :: set_with_headers

  • private subroutine set_with_headers(this, has_headers)

    Arguments

    Type IntentOptional Attributes Name
    class(data_frame), intent(inout) :: this
    logical, intent(in) :: has_headers

procedure, public :: validate_column_addition

  • private subroutine validate_column_addition(this, header, col_size)

    Arguments

    Type IntentOptional Attributes Name
    class(data_frame), intent(inout) :: this
    character(len=*), intent(in), optional :: header
    integer, intent(in) :: col_size

Source Code

    type :: data_frame
        private

        integer :: num_cols = 0, max_char_len = MAX_CHAR_LEN_DEFAULT
        logical :: with_headers = .false.
        character(len=:), dimension(:), allocatable :: headers
        type(column), dimension(:), allocatable :: data_cols
        logical :: initialized = .false.

    contains
        private

        ! Constructor/Destructor
        procedure, public :: new => df_constructor
        procedure, public :: destroy => df_destructor
        procedure, public :: is_initialized => df_is_initialized

        ! Basic info
        procedure, public :: ncols => df_get_num_cols
        procedure, public :: nrows => df_get_num_rows
        procedure, public :: get_max_char_len => df_get_max_char_len
        procedure, public :: header => get_header
        procedure :: df_get_col_type_header, df_get_col_type_index
        generic, public :: dtype => df_get_col_type_header, df_get_col_type_index

        ! Internal utility procedures (public for use by other datafort modules)
        procedure, public :: already_header
        procedure, public :: resize_storage
        procedure, public :: validate_column_addition
        procedure, public :: find_header_index
        procedure, public :: get_data_col  ! Access to internal column object
        procedure, public :: set_data_col  ! Set internal column object
        procedure, public :: get_with_headers  ! Check if has headers
        procedure, public :: set_with_headers  ! Set headers flag
        procedure, public :: set_header_at_index  ! Set header at specific index
        procedure, public :: increment_num_cols  ! Increment column count
    end type data_frame