libSUFR
a LIBrary of Some Useful Fortran Routines
All Classes Namespaces Files Functions Variables Pages
getopt.f90 File Reference

(libSUFR version 0.7.8, revision 407, hash 01069b8, 2025-03-02)

Procedures for a getopt and getopt_long implementation to parse command-line parameters in Fortran. More...

Go to the source code of this file.

Data Types

type  sufr_getopt::getopt_t
 Struct to define short and long options for getopt_long() More...
 

Modules

module  sufr_getopt
 Procedures for a getopt and getopt_long implementation to parse command-line parameters in Fortran.
 

Functions/Subroutines

character function sufr_getopt::getopt (optstr)
 Parse a command-line parameter and return short options and their arguments. A warning is printed to stderr if an argument is required but not present.
 
character function sufr_getopt::getopt_long (longopts)
 Parse a command-line parameter and return short and/or long options and their arguments. A warning is printed to stderr if an argument is required but not present or vice versa.
 
subroutine sufr_getopt::getopt_get_command ()
 Get the full command line in a string, split compound short options (e.g. "-abc" -> "-a -b -c") and set numberOfArguments.
 
integer function sufr_getopt::getopt_command_argument_count ()
 Return the number of arguments on the command line (excluding the command).
 
subroutine sufr_getopt::getopt_get_command_argument (argnr, arg)
 Returns the argNr-th command-line argument or option.
 
integer function sufr_getopt::getopt_optarg_to_int (minvalue, maxvalue)
 Extract and return an integer value from the argument optArg. On error, report and abort.
 
real function sufr_getopt::getopt_optarg_to_real (minvalue, maxvalue)
 Extract and return a real value from the argument optArg. On error, report and abort.
 
real(double) function sufr_getopt::getopt_optarg_to_dbl (minvalue, maxvalue)
 Extract and return a double value from the argument optArg. On error, report and abort.
 
subroutine sufr_getopt::getopt_split_short_options (cloptstr)
 Split combined short command-line options into several individual ones, e.g. "... -abc ..." -> "... -a -b -c ...".
 
subroutine sufr_getopt::getopt_help (optstr, linebef, lineaft)
 Print a help list of all short options and their required arguments.
 
subroutine sufr_getopt::getopt_long_help (longopts, linebef, lineaft)
 Print a help list of all short/long options, their required arguments and their descriptions.
 

Variables

character, dimension(9999) sufr_getopt::commandline
 The full command line as a single string.
 
integer sufr_getopt::numberofarguments = -1
 The number of arguments on the command line, excluding the command (= argc-1 in C)
 
character, dimension(999) sufr_getopt::curarg
 The current argument or option (word)
 
character, dimension(999) sufr_getopt::optarg
 The option's argument, if required and present.
 
character, dimension(longoptlen+2) sufr_getopt::longoption
 The short or long option found, including leading dash(es)
 
integer, save sufr_getopt::optcount = 0
 The current option count.
 
character, dimension(999) sufr_getopt::getopthelpheader = ''
 The header line for the message printed by getopt(_long)_help()
 
character, dimension(999) sufr_getopt::getopthelpsyntax = ''
 The syntax line for the message printed by getopt(_long)_help()
 
character, dimension(999) sufr_getopt::getopthelpfooter = ''
 The footer line for the message printed by getopt(_long)_help()
 

Detailed Description

Procedures for a getopt and getopt_long implementation to parse command-line parameters in Fortran.

Definition in file getopt.f90.