command_argst - Handle command-line arguments
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:
Short options, consisting of a single letter, for instance: -i. These options can be followed by a value as the next argument: -i 12 or the value can be concatenated: -i12.
If the option represents a logical value, then several options may be combined: -lmn would be interpreted as -l -m -n. This is only for logical options.
Long options, consisting of an entire word, for instance: --integer. These options can be followed by a value as the next argument: --integer 12. Concatenation is not supported though, as it might lead to ambiguities.
Options to print usage information. If no explicit option is defined, then -h, -? and --help will be used.
Options to stop processing further options. If no explicit option is defined, then -- is used for this purpose.
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.
There are three public routines:
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
Description of the options.
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.
The variable to be assigned a value from the command-line arguments.
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..
The one-letter short option. On the command line, such an option starts with "-", but the dash is not given.
The long option - on the command line, this should start with "--". Only the word after the two dashes should be specified.
A descriptive string which will be printed if the help option is used.
This is a variant to be used if no variable is associated with the option.
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.
The one-letter short option. On the command line, such an option starts with "-", but the dash is not given.
The long option - on the command line, this should start with "--". Only the word after the two dashes should be specified.
A descriptive string which will be printed if the help option is used.
Use this function to find out if the argument was ignored during processing or not.
The index of the command-line argument:
Copyright © 2016 Arjen Markus <arjenmarkus at sourceforge dot net>