config_file Derived Type

type, public :: config_file

a class for handling JSON config files.


Inherits

type~~config_file~~InheritsGraph type~config_file config_file json_file json_file type~config_file->json_file json

Components

Type Visibility Attributes Name Initial
character(len=:), private, allocatable :: name

the file name

type(json_file), public :: json

made it public so we can use the methods


Type-Bound Procedures

procedure, public :: open => open_config_file

  • private subroutine open_config_file(me, filename)

    Open the file.

    Arguments

    Type IntentOptional Attributes Name
    class(config_file), intent(inout) :: me
    character(len=*), intent(in) :: filename

    the name of the JSON file

procedure, public :: close => close_config_file

  • private subroutine close_config_file(me)

    Open the file.

    Arguments

    Type IntentOptional Attributes Name
    class(config_file), intent(inout) :: me

generic, public :: get => get_int, get_real, get_logical, get_char, get_real_vec

  • private subroutine get_int(me, name, variable, found)

    Get an integer variable from the config file.

    Arguments

    Type IntentOptional Attributes Name
    class(config_file), intent(inout) :: me
    character(len=*), intent(in) :: name

    name of the variable

    integer, intent(inout) :: variable

    the variable to populate with the value

    logical, intent(out), optional :: found

    if the variable was in the file

  • private subroutine get_real(me, name, variable, found)

    Get a real variable from the config file.

    Arguments

    Type IntentOptional Attributes Name
    class(config_file), intent(inout) :: me
    character(len=*), intent(in) :: name

    name of the variable

    real(kind=wp), intent(inout) :: variable

    the variable to populate with the value

    logical, intent(out), optional :: found

    if the variable was in the file

  • private subroutine get_logical(me, name, variable, found)

    Get a logical variable from the config file.

    Arguments

    Type IntentOptional Attributes Name
    class(config_file), intent(inout) :: me
    character(len=*), intent(in) :: name

    name of the variable

    logical, intent(inout) :: variable

    the variable to populate with the value

    logical, intent(out), optional :: found

    if the variable was in the file

  • private subroutine get_char(me, name, variable, found)

    Get a character variable from the config file.

    Arguments

    Type IntentOptional Attributes Name
    class(config_file), intent(inout) :: me
    character(len=*), intent(in) :: name

    name of the variable

    character(len=:), intent(inout), allocatable :: variable

    the variable to populate with the value

    logical, intent(out), optional :: found

    if the variable was in the file

  • private subroutine get_real_vec(me, name, variable, found)

    Get a real vector from the config file.

    Arguments

    Type IntentOptional Attributes Name
    class(config_file), intent(inout) :: me
    character(len=*), intent(in) :: name

    name of the variable

    real(kind=wp), intent(inout), dimension(:), allocatable :: variable

    the variable to populate with the value

    logical, intent(out), optional :: found

    if the variable was in the file

procedure, private :: get_real_vec

  • private subroutine get_real_vec(me, name, variable, found)

    Get a real vector from the config file.

    Arguments

    Type IntentOptional Attributes Name
    class(config_file), intent(inout) :: me
    character(len=*), intent(in) :: name

    name of the variable

    real(kind=wp), intent(inout), dimension(:), allocatable :: variable

    the variable to populate with the value

    logical, intent(out), optional :: found

    if the variable was in the file

procedure, private :: get_char

  • private subroutine get_char(me, name, variable, found)

    Get a character variable from the config file.

    Arguments

    Type IntentOptional Attributes Name
    class(config_file), intent(inout) :: me
    character(len=*), intent(in) :: name

    name of the variable

    character(len=:), intent(inout), allocatable :: variable

    the variable to populate with the value

    logical, intent(out), optional :: found

    if the variable was in the file

procedure, private :: get_logical

  • private subroutine get_logical(me, name, variable, found)

    Get a logical variable from the config file.

    Arguments

    Type IntentOptional Attributes Name
    class(config_file), intent(inout) :: me
    character(len=*), intent(in) :: name

    name of the variable

    logical, intent(inout) :: variable

    the variable to populate with the value

    logical, intent(out), optional :: found

    if the variable was in the file

procedure, private :: get_real

  • private subroutine get_real(me, name, variable, found)

    Get a real variable from the config file.

    Arguments

    Type IntentOptional Attributes Name
    class(config_file), intent(inout) :: me
    character(len=*), intent(in) :: name

    name of the variable

    real(kind=wp), intent(inout) :: variable

    the variable to populate with the value

    logical, intent(out), optional :: found

    if the variable was in the file

procedure, private :: get_int

  • private subroutine get_int(me, name, variable, found)

    Get an integer variable from the config file.

    Arguments

    Type IntentOptional Attributes Name
    class(config_file), intent(inout) :: me
    character(len=*), intent(in) :: name

    name of the variable

    integer, intent(inout) :: variable

    the variable to populate with the value

    logical, intent(out), optional :: found

    if the variable was in the file

Source Code

    type,public :: config_file
        !! a class for handling JSON config files.
        private
        character(len=:),allocatable :: name !! the file name
        type(json_file),public :: json !! made it public so we can use the methods
        contains
        private
        procedure,public :: open  => open_config_file
        procedure,public :: close => close_config_file
        generic,public :: get => get_int, get_real, get_logical, get_char,&
                                 get_real_vec
        procedure,private :: get_int, get_real, get_logical, get_char, get_real_vec
    end type config_file