BraWl
Loading...
Searching...
No Matches
command_line.f90 File Reference

Functions to parse command line arguments. More...

Go to the source code of this file.

Data Types

type  command_line::cmd_arg
 type containing a key-value pair More...
 
type  command_line::str_wrapper
 wrapper to allow array of allocatable strings More...
 
interface  command_line::get_arg
 read arguments by name or number More...
 

Modules

module  command_line
 

Functions/Subroutines

subroutine command_line::parse_args ()
 Parse out command line args.
 
subroutine command_line::initial_parse
 helper function - do a parse if it hasn't been done yet
 
integer function, public command_line::arg_count ()
 get the number of arguments note: total count may not match command_argument_count due to parsing key=value syntax!
 
logical function command_line::get_arg_num_logical (num, val, exists)
 read by number for logical values
 
logical function command_line::get_arg_name_logical (name, val, exists)
 Read by name for logical values.
 
logical function command_line::get_arg_num_dbl (num, val, exists)
 read by number for double precision values
 
logical function command_line::get_arg_name_dbl (name, val, exists)
 read by name for double precision values
 
logical function command_line::get_arg_num_float (num, val, exists)
 Read by number for single precision (float) values.
 
logical function command_line::get_arg_name_float (name, val, exists)
 read by name for single precision (float) values
 
logical function command_line::get_arg_num_int (num, val, exists)
 read by number for integer values
 
logical function command_line::get_arg_name_int (name, val, exists)
 read by name for integer values
 
logical function command_line::get_arg_num_long (num, val, exists)
 read by number for long integer values
 
logical function command_line::get_arg_name_long (name, val, exists)
 read by name for long integer values
 
logical function command_line::get_arg_num_str (num, val, exists)
 read by number for string/character values
 
logical function command_line::get_arg_name_str (name, val, exists)
 read by name for string values
 
logical function, public command_line::arg_present (name, has_value)
 check presence of an argument by name
 
type(str_wrapper) function, dimension(:), allocatable, public command_line::dump_names ()
 get all the argument names (by copy) order will probably match input order, but this is not guaranteed
 
character(len=:) function, allocatable, public command_line::get_arg_value (name, exists)
 lookup an argument by name and return the value as an (allocatable) string if the name is not present, an empty string is returned
 

Variables

logical command_line::initial_parse_done = .false.
 
type(cmd_arg), dimension(:), allocatable, private command_line::all_args
 the argument list
 
integer, private command_line::num_args = 0
 the number of arguments
 
integer, parameter command_line::max_string_len = 200
 

Detailed Description

Functions to parse command line arguments.

Module to read command line arguments to a program. We assume they are of the form name=value (spaces around '=' are ignored) or are a flag.

Note: 'val=""' differs from 'val' - the latter is a flag, the former an empty string. Value can be extracted as a string, integer, a long-integer or a single or double-precision real, according to the type passed in. Argument names are limited to 20 chars, and values to 30 chars as read.

Note: The only functions you should call from outside are:

  1. get_arg and get_arg_value for 'key=value' arguments
  2. arg_present to check presence and state (flag or valued)
  3. arg_count and dump_names for general inquiries

Note: Flags can also be read by name as a logical: TRUE if present, FALSE if not.

Note: Total count may not match command_argument_count due to parsing spaces out of key( )=()value syntax!

Author
H. Ratcliffe, Senior Research Software Engineer, University of Warwick
Date
2024

Definition in file command_line.f90.