arg_class Derived Type

type, public :: arg_class

Public class to store and parse command-line arguments.


Inherits

type~~arg_class~~InheritsGraph type~arg_class arg_class type~arg_type arg_type type~arg_class->type~arg_type args

Type-Bound Procedures

procedure, public :: add => arg_add

  • private subroutine arg_add(this, name, short, type, max_len, min_len, required, error)

    Arguments

    Type IntentOptional Attributes Name
    class(arg_class), intent(inout) :: this
    character(len=*), intent(in), optional :: name
    character(len=1), intent(in), optional :: short
    integer, intent(in), optional :: type
    integer, intent(in), optional :: max_len
    integer, intent(in), optional :: min_len
    logical, intent(in), optional :: required
    integer, intent(out), optional :: error

procedure, public :: create => arg_create

  • private subroutine arg_create(this, max_size, default)

    Initialises arg object and adds default arguments --help and --version if default is not .false..

    Arguments

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

    Arg object.

    integer, intent(in), optional :: max_size

    Max. number of arguments to expect.

    logical, intent(in), optional :: default

    Add default arguments.

procedure, public :: destroy => arg_destroy

  • private subroutine arg_destroy(this)

    Destroys arg object.

    Arguments

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

    Arg object.

generic, public :: get => get_int32, get_logical, get_real64, get_string

  • private subroutine arg_get_int32(this, name, value, default, passed, error)

    Returns argument value as 4-byte integer.

    Arguments

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

    Arg object.

    character(len=*), intent(in) :: name

    Argument name.

    integer, intent(inout) :: value

    Argument value.

    integer, intent(in), optional :: default

    Default value.

    logical, intent(out), optional :: passed

    Passed or not.

    integer, intent(out), optional :: error

    Argument error.

  • private subroutine arg_get_logical(this, name, value, default, passed, error)

    Returns .true. if argument has been passed.

    Arguments

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

    Arg object.

    character(len=*), intent(in) :: name

    Argument name.

    logical, intent(inout) :: value

    Argument value.

    logical, intent(in), optional :: default

    Default value.

    logical, intent(out), optional :: passed

    Passed or not.

    integer, intent(out), optional :: error

    Argument error.

  • private subroutine arg_get_real64(this, name, value, default, passed, error)

    Returns argument value as 8-byte real.

    Arguments

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

    Arg object.

    character(len=*), intent(in) :: name

    Argument name.

    real(kind=r8), intent(inout) :: value

    Argument value.

    real(kind=r8), intent(in), optional :: default

    Default value.

    logical, intent(out), optional :: passed

    Passed or not.

    integer, intent(out), optional :: error

    Argument error.

  • private subroutine arg_get_string(this, name, value, default, passed, error)

    Returns argument value as character string.

    Arguments

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

    Arg object.

    character(len=*), intent(in) :: name

    Argument name.

    character(len=*), intent(inout) :: value

    Argument value.

    character(len=*), intent(in), optional :: default

    Default value.

    logical, intent(out), optional :: passed

    Passed or not.

    integer, intent(out), optional :: error

    Argument error.

procedure, public :: passed => arg_passed

  • private function arg_passed(this, name) result(passed)

    Returns .true. if argument in arguments array has been passed.

    Arguments

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

    Arg object.

    character(len=*), intent(in) :: name

    Argument name.

    Return Value logical

procedure, public :: read => arg_read

  • private function arg_read(this, callback) result(rc)

    Reads all arguments from command-line and prints error message if one is missing. Returns the error code of the first invalid argument.

    The function also parses the command-line arguments for -v/--version to display the current application and library version, and -h/--help to output all available command-line arguments. If one of these arguments is passed, dm_stop(0) is called afterwards.

    Optional argument callback is a routine that outputs the version information.

    The function returns the following error codes:

    • E_EMPTY if array of arguments is empty.
    • E_ARG_INVALID if an required argument has not been passed.
    • E_ARG_NO_VALUE if an argument has been passed without value.
    • E_ARG_TYPE if an argument has the wrong type.
    • E_ARG_LENGTH if the length of the argument is wrong.
    • E_ARG_UNKNOWN if an unknown argument has been passed.

    Arguments

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

    Arg object.

    procedure(dm_arg_version_callback), optional :: callback

    Version callback.

    Return Value integer