abstract_config Module

Define abstract type to use as a base type for derived types used to represent the input configuration of a module (actual or logical). In other words it can be used to represent a namelist state.


Contents


Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: CONFIG_MAX_NAME_LEN = 64
character(len=CONFIG_MAX_NAME_LEN), private, parameter :: default_name = "Undefined name."
integer, private, parameter :: key_align_width = 40

Controls the alignment of key/value pairs when writing config namelists. Key is left justified, align = a minimum of key_align_width characters to right of key start.


Interfaces

interface

  • private function get_default_name_interface() result(default_name)

    Arguments

    None

    Return Value character(len=CONFIG_MAX_NAME_LEN)

interface

  • private function get_default_requires_index_interface() result(default_requires_index)

    Arguments

    None

    Return Value logical

interface

  • private subroutine read_interface(self)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_config_type), intent(inout) :: self

interface

  • private subroutine write_interface(self, unit)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_config_type), intent(in) :: self
    integer, intent(in), optional :: unit

interface

  • private subroutine reset_interface(self)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_config_type), intent(inout) :: self

interface

  • private subroutine broadcast_interface(self)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_config_type), intent(inout) :: self

Derived Types

type, public ::  abstract_config_type

Define abstract type to represent the config type, allows common code to be moved here

Components

Type Visibility Attributes Name Initial
logical, private :: initialised = .false.

Have we initialised the instance?

logical, public :: exist = .false.

Does the related namelist exist in the target input file?

logical, private :: requires_index = .false.

Is this a numbered namelist with an index

integer, public :: index = 0

Used to hold the specific index of numbered namelists

character(len=CONFIG_MAX_NAME_LEN), private :: name = default_name

The name of the namelist that we represent.

logical, public :: skip_read = .false.

Do we want to skip the read step in init?

logical, public :: skip_broadcast = .false.

Do we want to skip the broadcast step in init?

Type-Bound Procedures

procedure , public , :: is_initialised => is_initialised_generic Function
procedure , public , :: init => init_generic Subroutine
procedure , public , :: setup => setup_generic Subroutine
procedure , public , :: write_namelist_header Subroutine
procedure , public , :: get_name => get_name_generic Function
procedure , public , :: get_requires_index => get_requires_index_generic Function
procedure , public , nopass :: write_namelist_footer Subroutine
procedure , private , nopass :: write_key_val_string Subroutine
procedure , private , nopass :: write_key_val_real Subroutine
procedure , private :: write_key_val_real_array Subroutine
procedure , private , nopass :: write_key_val_complex Subroutine
procedure , private :: write_key_val_complex_array Subroutine
procedure , private , nopass :: write_key_val_integer Subroutine
procedure , private :: write_key_val_integer_array Subroutine
procedure , private , nopass :: write_key_val_logical Subroutine
generic, public , :: write_key_val => write_key_val_string, write_key_val_real, write_key_val_complex, write_key_val_integer, write_key_val_logical, write_key_val_real_array, write_key_val_complex_array, write_key_val_integer_array
procedure (read_interface) , public :: read
procedure (write_interface) , public :: write
procedure (reset_interface) , public :: reset
procedure (broadcast_interface) , public :: broadcast
procedure (get_default_name_interface) , public , nopass :: get_default_name
procedure (get_default_requires_index_interface) , public , nopass :: get_default_requires_index

Functions

private function is_initialised_generic(self)

Is this instance initialised?

Arguments

Type IntentOptional Attributes Name
class(abstract_config_type), intent(in) :: self

Return Value logical

private function get_name_generic(self)

Returns the namelist name. Not very useful at the moment but may want to do more interesting things in the future

Arguments

Type IntentOptional Attributes Name
class(abstract_config_type), intent(in) :: self

Return Value character(len=CONFIG_MAX_NAME_LEN)

private function get_requires_index_generic(self)

Returns the requires_index value. Allows access whilst keeping the variable private

Arguments

Type IntentOptional Attributes Name
class(abstract_config_type), intent(in) :: self

Return Value logical

private pure function format_key(key)

Takes a given key and formats it in a consistent style. Currently that style is left justified in a character variable of minimum length key_align_width.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: key

Return Value character(len=:), allocatable


Subroutines

private subroutine init_generic(self, name, requires_index, index)

Fully initialise the config object

Arguments

Type IntentOptional Attributes Name
class(abstract_config_type), intent(inout) :: self
character(len=*), intent(in), optional :: name
logical, intent(in), optional :: requires_index
integer, intent(in), optional :: index

private subroutine setup_generic(self, name, requires_index, index)

Do some standard setup/checking

Arguments

Type IntentOptional Attributes Name
class(abstract_config_type), intent(inout) :: self
character(len=*), intent(in), optional :: name
logical, intent(in), optional :: requires_index
integer, intent(in), optional :: index

private subroutine write_namelist_header(self, unit)

Write the namelist header for this instance

Arguments

Type IntentOptional Attributes Name
class(abstract_config_type), intent(in) :: self
integer, intent(in) :: unit

private subroutine write_namelist_footer(unit)

Write the namelist footer

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit

private subroutine write_key_val_string(key, val, unit)

Writes a {key,val} pair where the value is of type character

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: key
character(len=*), intent(in) :: val
integer, intent(in) :: unit

private subroutine write_key_val_real(key, val, unit)

Writes a {key,val} pair where the value is of type real

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: key
real, intent(in) :: val
integer, intent(in) :: unit

private subroutine write_key_val_real_array(self, key, val, unit)

Writes a {key,val} pair where the value is of type real array

Arguments

Type IntentOptional Attributes Name
class(abstract_config_type), intent(in) :: self
character(len=*), intent(in) :: key
real, intent(in), dimension(:) :: val
integer, intent(in) :: unit

private subroutine write_key_val_complex(key, val, unit)

Writes a {key,val} pair where the value is of type complex

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: key
complex, intent(in) :: val
integer, intent(in) :: unit

private subroutine write_key_val_complex_array(self, key, val, unit)

Writes a {key,val} pair where the value is of type complex array

Arguments

Type IntentOptional Attributes Name
class(abstract_config_type), intent(in) :: self
character(len=*), intent(in) :: key
complex, intent(in), dimension(:) :: val
integer, intent(in) :: unit

private subroutine write_key_val_integer(key, val, unit)

Writes a {key,val} pair where the value is of type integer

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: key
integer, intent(in) :: val
integer, intent(in) :: unit

private subroutine write_key_val_integer_array(self, key, val, unit)

Writes a {key,val} pair where the value is of type integer array

Arguments

Type IntentOptional Attributes Name
class(abstract_config_type), intent(in) :: self
character(len=*), intent(in) :: key
integer, intent(in), dimension(:) :: val
integer, intent(in) :: unit

private subroutine write_key_val_logical(key, val, unit)

Writes a {key,val} pair where the value is of type logical

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: key
logical, intent(in) :: val
integer, intent(in) :: unit