libSUFR
a LIBrary of Some Useful Fortran Routines
All Classes Namespaces Files Functions Variables Pages
sufr_command_line Module Reference

Procedures to handle command-line options and arguments. More...

Data Types

type  cl_options
 Struct to store command-line options. More...
 

Functions/Subroutines

subroutine get_command_argument_i (narg, arg, status)
 Get an integer from the command line.
 
subroutine get_command_argument_l (narg, arg, status)
 Get a long integer from the command line.
 
subroutine get_command_argument_d (narg, arg, status)
 Get a double-precision real from the command line.
 
subroutine get_command_argument_r (narg, arg, status)
 Get a single-precision real from the command line.
 
subroutine read_all_commandline_arguments (verbose, narg_max, nargs, arguments)
 Read all the command-line arguments and return them in a character array.
 
subroutine get_commandline_argument_types (verbose, nargs, arguments, types)
 Determine the type of each command-line argument found:
 
subroutine split_short_cl_options (verbose, narg_max, nargs, arguments, types)
 If short command-line options are found (i.e., starting with one dash), split them, e.g. "-bar" -> "-b -a -r".
 
subroutine get_commandline_options_values (verbose, narg_max, nopts, options, values, optypes, cl_option)
 Obtain command-line arguments and reduce them to options, values and types.
 
subroutine print_commandline_options_values (nopts, options, values, optypes, cl_option)
 Print all command-line options and values found to stdOut for debugging.
 
logical function cl_option_present (option, verbose)
 Check whether a command-line option is present.
 
logical function cl_option_var_string (option, string)
 Retrieve the string argument/variable of a command-line option, if it exists.
 
logical function cl_option_var_int (option, intarg)
 Retrieve the integer argument/variable of a command-line option, if it exists.
 
logical function cl_option_var_dbl (option, dblarg)
 Retrieve the floating-point argument/variable of a command-line option, if it exists.
 

Detailed Description

Procedures to handle command-line options and arguments.

Function/Subroutine Documentation

◆ cl_option_present()

logical function sufr_command_line::cl_option_present ( character, dimension(*), intent(in) option,
integer, intent(in), optional verbose )

Check whether a command-line option is present.

Parameters
optionOption to verify the presence of
verboseVerbosity: 0-print nothing, 1-print warnings, 2-print information, 3-print debugging info
Return values
cl_option_presentThe cl option is present (true/false).

Definition at line 484 of file command_line.f90.

References cl_option_present(), and get_commandline_options_values().

Referenced by cl_option_present().

Here is the call graph for this function:

◆ cl_option_var_dbl()

logical function sufr_command_line::cl_option_var_dbl ( character, dimension(*), intent(in) option,
real(double), intent(out) dblarg )

Retrieve the floating-point argument/variable of a command-line option, if it exists.

Parameters
optionOption to get the argument from
dblargArgument/variable floating-point (output)
Return values
cl_option_var_dblBool that indicates whether an option argument was present.

Definition at line 611 of file command_line.f90.

References cl_option_var_dbl(), sufr_kinds::double, and get_commandline_options_values().

Referenced by cl_option_var_dbl().

Here is the call graph for this function:

◆ cl_option_var_int()

logical function sufr_command_line::cl_option_var_int ( character, dimension(*), intent(in) option,
integer, intent(out) intarg )

Retrieve the integer argument/variable of a command-line option, if it exists.

Parameters
optionOption to get the argument from
intargArgument/variable integer (output)
Return values
cl_option_var_intBool that indicates whether an option argument was present.

Definition at line 569 of file command_line.f90.

References cl_option_var_int(), and get_commandline_options_values().

Referenced by cl_option_var_int().

Here is the call graph for this function:

◆ cl_option_var_string()

logical function sufr_command_line::cl_option_var_string ( character, dimension(*), intent(in) option,
character, dimension(*), intent(out) string )

Retrieve the string argument/variable of a command-line option, if it exists.

Parameters
optionOption to get the argument from
stringArgument/variable string (output)
Return values
cl_option_var_stringBool that indicates whether an option argument was present.

Definition at line 528 of file command_line.f90.

References cl_option_var_string(), and get_commandline_options_values().

Referenced by cl_option_var_string().

Here is the call graph for this function:

◆ get_command_argument_d()

subroutine sufr_command_line::get_command_argument_d ( integer, intent(in) narg,
real(double), intent(out) arg,
integer, intent(out), optional status )

Get a double-precision real from the command line.

Parameters
nArgNumber of command-line argument (1,2,...)
argValue of the argument (output)
statusExit status: 0: ok, !=0: not ok (output)

Definition at line 96 of file command_line.f90.

References sufr_kinds::double.

◆ get_command_argument_i()

subroutine sufr_command_line::get_command_argument_i ( integer, intent(in) narg,
integer, intent(out) arg,
integer, intent(out), optional status )

Get an integer from the command line.

Parameters
nArgNumber of command-line argument (1,2,...)
argValue of the argument (output)
statusExit status: 0: ok, !=0: not ok (output)

Definition at line 46 of file command_line.f90.

◆ get_command_argument_l()

subroutine sufr_command_line::get_command_argument_l ( integer, intent(in) narg,
integer(long), intent(out) arg,
integer, intent(out), optional status )

Get a long integer from the command line.

Parameters
nArgNumber of command-line argument (1,2,...)
argValue of the argument (output)
statusExit status: 0: ok, !=0: not ok (output)

Definition at line 70 of file command_line.f90.

References sufr_kinds::long.

◆ get_command_argument_r()

subroutine sufr_command_line::get_command_argument_r ( integer, intent(in) narg,
real, intent(out) arg,
integer, intent(out), optional status )

Get a single-precision real from the command line.

Parameters
nArgNumber of command-line argument (1,2,...)
argValue of the argument (output)
statusExit status: 0: ok, !=0: not ok (output)

Definition at line 122 of file command_line.f90.

◆ get_commandline_argument_types()

subroutine sufr_command_line::get_commandline_argument_types ( integer, intent(in) verbose,
integer, intent(in) nargs,
character, dimension(*), intent(in) arguments,
integer, dimension(nargs), intent(out) types )

Determine the type of each command-line argument found:

  • normal or short option (i.e., with two dashes or one)
  • option with or without argument
Parameters
verboseVerbosity: 0-print nothing, 1-print warnings, 2-print information, 3-print debugging info
nargsNumber of command-line arguments
argumentsArray of command-line arguments
typesArray with command-line argument types: 10: normal option (no value), 20/21: short option (one dash) (output) without/with value, 22: value for short option, 30/31: long option (two dashes) without/with value 33: value for long option

Definition at line 194 of file command_line.f90.

Referenced by get_commandline_options_values().

◆ get_commandline_options_values()

subroutine sufr_command_line::get_commandline_options_values ( integer, intent(in) verbose,
integer, intent(in) narg_max,
integer, intent(out) nopts,
character, dimension(*), intent(out) options,
character, dimension(*), intent(out) values,
integer, dimension(narg_max), intent(out) optypes,
type(cl_options), dimension(narg_max), intent(out) cl_option )

Obtain command-line arguments and reduce them to options, values and types.

Parameters
verboseVerbosity: 0-print nothing, 1-print warnings, 2-print information, 3-print debugging info
narg_maxMaximum number of command-line arguments
noptsNumber of options found (without counting their variables) (output)
optionsArray of command-line options found (output)
valuesArray of command-line values found (i.e., the parameters that belong to an option) (output)
optypesArray of option types: 10: normal option (no value), 20/21: short option (one dash) without/with value, (output) 30/31: long option (two dashes) without/with value
cl_optionStruct containing command-line option names, values, has_val, short and long (output)

Definition at line 372 of file command_line.f90.

References get_commandline_argument_types(), read_all_commandline_arguments(), and split_short_cl_options().

Referenced by cl_option_present(), cl_option_var_dbl(), cl_option_var_int(), and cl_option_var_string().

Here is the call graph for this function:

◆ print_commandline_options_values()

subroutine sufr_command_line::print_commandline_options_values ( integer, intent(in) nopts,
character, dimension(*), intent(in) options,
character, dimension(*), intent(in) values,
integer, dimension(nopts), intent(in) optypes,
type(cl_options), dimension(nopts), intent(in) cl_option )

Print all command-line options and values found to stdOut for debugging.

Parameters
noptsNumber of options found (without counting their variables) (output)
optionsArray of command-line options found (output)
valuesArray of command-line values found (i.e., the parameters that belong to an option) (output)
optypesArray of option types: 10: normal option (no value), 20/21: short option (one dash) without/with value, (output) 30/31: long option (two dashes) without/with value
cl_optionStruct containing command-line option names, values, has_val, short and long (output)

Definition at line 456 of file command_line.f90.

◆ read_all_commandline_arguments()

subroutine sufr_command_line::read_all_commandline_arguments ( integer, intent(in) verbose,
integer, intent(in) narg_max,
integer, intent(out) nargs,
character, dimension(*), intent(out) arguments )

Read all the command-line arguments and return them in a character array.

Parameters
verboseVerbosity: 0-print nothing, 1-print warnings, 2-print information, 3-print debugging info
narg_maxMaximum array size for arguments
nargsNumber of command-line arguments found (output)
argumentsArray of command-line arguments found (output)

Definition at line 148 of file command_line.f90.

Referenced by get_commandline_options_values().

◆ split_short_cl_options()

subroutine sufr_command_line::split_short_cl_options ( integer, intent(in) verbose,
integer, intent(in) narg_max,
integer, intent(out) nargs,
character, dimension(*), intent(inout) arguments,
integer, dimension(narg_max), intent(inout) types )

If short command-line options are found (i.e., starting with one dash), split them, e.g. "-bar" -> "-b -a -r".

Parameters
verboseVerbosity: 0-print nothing, 1-print warnings, 2-print information, 3-print debugging info
narg_maxMaximum number of command-line arguments
nargsActual number of command-line arguments (I/O) (output)
argumentsArray of command-line arguments (I/O) (output)
typesArray with command-line argument types: 10: normal option (no value), 20/21: short option (one dash) (output) without/with value, 22: value for short option, 30/31: long option (two dashes) without/with value 33: value for long option

Definition at line 261 of file command_line.f90.

References sufr_system::quit_program().

Referenced by get_commandline_options_values().

Here is the call graph for this function: