SF_PARSE_INPUT
Description
SciFortran module for input file parsing
Quick access
- Variables:
- Routines:
check_input_variable(),parse_cmd_variable(),parse_input_variable(),print_input(),save_input(),save_input_file()
Used modules
list_inputdelete_input()⇒delete_input_list()
Variables
- sf_parse_input/delete_input
- Type:
- Attributes:
public
Subroutines and functions
- interface sf_parse_input/parse_cmd_variable(variable, name[, default])
Generic interface to update a variable from the command line. It accepts integer, real(8), logical and character scalars (
i_parse_cmd_variable,d_parse_cmd_variable,l_parse_cmd_variable,ch_parse_cmd_variable), and integer, real(8) and logical vectors (iv_parse_cmd_variable,dv_parse_cmd_variable,lv_parse_cmd_variable). The arguments are documented ini_parse_cmd_variableandiv_parse_cmd_variable.First
variableis set todefault, if present. Then every command line argument of the formNAME=value, withNAMEmatchingname(not case sensitive), is read with list-directed input intovariable; if the argument is repeated the last one wins. A vector is given as a comma separated list without spaces,NAME=v1,v2,...,vn, withn=size(variable)entries, and the program stops if the number of entries differs fromsize(variable).A message
Variable NAME updated to valueis written to standard error for each update. Unlikeparse_input_variable, the variable is not registered in the input list.- Parameters:
variable (various shapes) [integer/real/logical/character(len=*)] – variable to be set; keeps its value if not given
name [character(len=*)] – name of the variable on the command line (case insens.)
- Options:
default (various shapes) [integer/real/logical/character(len=*)] – optional: default value
- interface sf_parse_input/parse_input_variable(variable, name, file[, default, comment])
Generic interface to read a variable from an input file and from the command line, and to register it in the input list. It accepts integer, real(8), logical and character scalars (
i_parse_input,d_parse_input,l_parse_input,ch_parse_input), and integer, real(8) and logical vectors (iv_parse_input,dv_parse_input,lv_parse_input). The arguments are documented ini_parse_inputandiv_parse_input.First
variableis set todefault, if present. Then, iffileexists, it is scanned line by line for the first entryNAME=valuematchingname(not case sensitive), blanks and tabs being ignored and anything following a comment character (!,#or%) discarded. The value is read with list-directed input; if the entry is not found the variable keeps its default value. A vector is given as a comma separated list without spaces,NAME=v1,v2,...,vn, withn=size(variable)entries; a single trailing comma is ignored.Finally, the command line is parsed with
parse_cmd_variable, so that an argumentNAME=valueoverrides the value read from the file, and the variable is registered, with itscomment, in the input list used bysave_inputandprint_input.A missing input file is not an error: the default is used and the module remembers it, so that
save_inputdumps a default input file and stops. The program stops if the value can not be converted to the type ofvariable, or if the number of entries of a vector differs fromsize(variable).- Parameters:
variable (various shapes) [integer/real/logical/character(len=*)] – variable to be set; keeps its value if not found
name [character(len=*)] – name of the variable in file/command line (case insens.)
file [character(len=*)] – input file name
- Options:
default (various shapes) [integer/real/logical/character(len=*)] – optional: default value, used if not in file
comment [character(len=*)] – optional: description, printed in the saved input file
- interface sf_parse_input/save_input(file)
Generic interface to dump the input list, i.e. all the variables registered so far by
parse_input_variable, to a file with the same format as the input files,NAME=valuefollowed by the comment of the variable. The only instance issave_input_file, whose argumentfileis the base name of the output file.The output file is named
used.file(seeprint_input), and it contains the final values of the variables, i.e. after the command line has been applied. If any of the input files requested byparse_input_variablecould not be found, the file contains the default values and the program stops after writing it, which provides a way to generate a template input file.- Parameters:
file [character(len=*)] – base name of the output file, written as used.<file>
- interface sf_parse_input/print_input([file, list])
Generic interface to print the input list, i.e. all the variables registered so far by
parse_input_variable. The only instance isprint_input_list, whose arguments are the optional base namefileof the output file and the optionallistto be printed (the default list if absent).Each variable is printed, in the order it was registered, on a line
NAME=value, with vectors as comma separated lists, followed by its comment preceded by!, aligned at column 46 when possible: the format is the same as that of the input files. Iffileis present the output is written to the fileused.file, replacing it if it exists; otherwise it is written to the standard output. An empty list printsinput list: empty.- Options:
file [character(len=*)] – optional: base name of the output file, written as used.<file>
list [input_list] – optional: list to print (default list if absent)
- function sf_parse_input/check_input_variable(name, file)
This subroutine checks if the variable “name” is present in the input list. The output is a boolean:
Trueif the variable is present,Falseif it is not present.- Parameters:
name [character(len=*)] – name of the variable in file/command line (case insens.)
file [character(len=*)] – input file name
- Result:
check_input [logical]
- subroutine sf_parse_input/save_input_file(file)
This subroutine dumps the input list, i.e. all the variables registered so far by
parse_input_variable, to a file with the same format as the input files,NAME=valuefollowed by the comment of the variable. It is the public routine behind the generic namesave_input.The output file is named
used.file(seeprint_input_list), and it contains the final values of the variables, i.e. after the command line has been applied. If any of the input files requested byparse_input_variablecould not be found, the file contains the default values and the program stops after writing it, which provides a way to generate a template input file.- Parameters:
file [character(len=*)] – base name of the output file, written as used.<file>