command_argst(n) 1.0 "flibs"

Name

command_argst - Handle command-line arguments

Table Of Contents

Synopsis

Description

The command_args module can automatically handle the command-line arguments that are passed to the program. For example, if you run the test program like:

    test_command_args --real 1.2 -l

it will set the variables real_var and l_var to respectively 1.2 and .true.. It will not set the variable int_var, but it will set the other two logical variables m_var and n_var to .false., because these are turned on by the options -m and -n.

The module supports the following types of command options:

For each command argument it is possible to ask whether it was processed by the handle_command_options routine, so that special processing that is not covered by this routine, is made easier. To this end it is also possible to define options that are explicitly ignored.

ROUTINES

There are three public routines:

call handle_command_options( options )

This subroutine handles the command-line arguments as options defined in the array options. The entries of this array describe how options should be treated and - in many cases - which variables should be set. See the description below

type(cmd_options), dimension(:) options

Description of the options.

arg = optarg( var, type, short, long, description )

This function returns a value of type cmd_option, so that an array can be formed to be passed to handle_command_options. The argument var is one of the basic types: integer, single and double precision real, logical or a character string of any length.

scalar var

The variable to be assigned a value from the command-line arguments.

integer type

The type of command-line argument:

  • opt_value_next is used to indicate that the next argument is the associated value

  • opt_value_next is used to indicate that the value is concatenated (for the short version of the command-line argument) or that the next argument is the associated value (for the long version).

  • opt_true is used to indicate that the presence of this option means the associated logical variable should be set to .true.. If this option is not present, the variable is set to .false..

  • opt_false is used to indicate that the presence of this option means the associated logical variable should be set to .false.. If this option is not present, the variable is set to .true..

character(len=1) short

The one-letter short option. On the command line, such an option starts with "-", but the dash is not given.

character(len=*) long

The long option - on the command line, this should start with "--". Only the word after the two dashes should be specified.

character(len=*) decription

A descriptive string which will be printed if the help option is used.

arg = optarg( type, short, long, description )

This is a variant to be used if no variable is associated with the option.

integer type

The type of command-line argument:

  • opt_help is used to indicate that the usage information should be printed.

  • opt_ignore is used to indicate that this argument should be ignored.

  • opt_ignore_next is used to indicate that this argument and the next should be ignored.

character(len=1) short

The one-letter short option. On the command line, such an option starts with "-", but the dash is not given.

character(len=*) long

The long option - on the command line, this should start with "--". Only the word after the two dashes should be specified.

character(len=*) decription

A descriptive string which will be printed if the help option is used.

ignored = argument_ignored( indx )

Use this function to find out if the argument was ignored during processing or not.

integer type

The index of the command-line argument: