SF_PARSE_INPUT

Description

SciFortran module for input file parsing

Quick access

Variables:

delete_input

Routines:

check_input_variable(), parse_cmd_variable(), parse_input_variable(), print_input(), save_input(), save_input_file()

Used modules

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 in i_parse_cmd_variable and iv_parse_cmd_variable.

First variable is set to default, if present. Then every command line argument of the form NAME=value, with NAME matching name (not case sensitive), is read with list-directed input into variable; if the argument is repeated the last one wins. A vector is given as a comma separated list without spaces, NAME=v1,v2,...,vn, with n=size(variable) entries, and the program stops if the number of entries differs from size(variable).

A message Variable NAME updated to value is written to standard error for each update. Unlike parse_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 in i_parse_input and iv_parse_input.

First variable is set to default, if present. Then, if file exists, it is scanned line by line for the first entry NAME=value matching name (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, with n=size(variable) entries; a single trailing comma is ignored.

Finally, the command line is parsed with parse_cmd_variable, so that an argument NAME=value overrides the value read from the file, and the variable is registered, with its comment, in the input list used by save_input and print_input.

A missing input file is not an error: the default is used and the module remembers it, so that save_input dumps a default input file and stops. The program stops if the value can not be converted to the type of variable, or if the number of entries of a vector differs from size(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=value followed by the comment of the variable. The only instance is save_input_file, whose argument file is the base name of the output file.

The output file is named used.file (see print_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 by parse_input_variable could 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 is print_input_list, whose arguments are the optional base name file of the output file and the optional list to 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. If file is present the output is written to the file used.file, replacing it if it exists; otherwise it is written to the standard output. An empty list prints input 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: True if the variable is present, False if 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=value followed by the comment of the variable. It is the public routine behind the generic name save_input.

The output file is named used.file (see print_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 by parse_input_variable could 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>