Skip to content

adam_ini_library ​

ADAM, strict reads of INI options with optional defaults (issue #80, P1).

ini_get(ini, section, option, val[, default]) reads one option of one section:

  • present and convertible to the type of val: val takes it;
  • present but not convertible (e.g. frequency = abc): the run stops, as before (FiNeR's own default= would silently take the default here);
  • absent, with default: val takes the default;
  • absent, without default (a required option): the error failed to load [<section>].(<option>) is recorded.

Recorded errors do not stop the run at once (issue #80, P2, F1): a parser reads all its options, then calls ini_check, which stops with every error recorded so far, one line each, so that one run reports every missing or malformed option instead of one per run. A single error stops with the message every parser used before, : failed to load [<section>].(<option>). ini_stop(msg) records a validation error (a value outside its accepted set) and stops at once with the whole list; ini_error(msg) records one and lets the parser go on. A parser must call ini_check before it uses a value it has just read to size, loop or branch, when a failed read would leave that value meaningless (a count key without default, for instance).

The recorded errors are module state of this library, kept only between a parser's reads and its ini_check. Absence is told apart from a bad value by reading the option first as text, which fails only when the option is not in the section (FiNeR's has_option searches every section, not one).

ini_load(filename, ini) loads an input file that may extend another (issue #80, P4): a global option (before the first section) extends = <file> names a base file, read first (recursively, its path relative to the including file's directory); the including file's options are then added onto it, replacing the values of the options both define and adding the others, sections included. extends itself is consumed: it is not an option of the result.

ini_get_list(ini, section, option, val[, default]) reads a list whose length is the number of values given (issue #80, F4): val is allocatable and takes that length, so no input states how many values follow. Absent, val takes default (a zero-size default makes the list optional); absent without default is a recorded error.

ini_count_sections(ini, prefix) counts the enumerated sections <prefix>1, <prefix>2, ... (issue #80, F5): a parser uses it as the default of its count key ([amr] markers_number, [slices] slices_number, ...), so an input lists its sections and need not count them. The sections must be numbered 1..N without gaps.

ADAM_REPORT_DEFAULTS=1 in the environment (issue #80, F6) makes every read through ini_get/ini_get_list noted, and ini_report_defaults (called by the forest once a realm is initialized, before the unread-key check) prints, on rank 0, one line per option:

  • [ini-defaults] equal [<section>].(<option>): the input sets the option to its default, at every read of it, so the line can be deleted with no effect;
  • [ini-defaults] taken [<section>].(<option>) = <value>: the input omits the option and the run takes its default.

An option read without a default anywhere (required), or set to a value other than a default, is not listed; options read by parsers that bypass this library are not listed either.

Source: src/lib/common/adam_ini_library.F90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
TEXT_LENinteger(kind=I4P)parameterLength of the text buffer used to detect an option.
EXTENDS_DEPTH_MAXinteger(kind=I4P)parameterLongest chain of files extending one another.
pendingcharacter(len=:)allocatableErrors recorded since the last ini_check, one per line.
pending_numberinteger(kind=I4P)Number of errors recorded.
NOTE_LENinteger(kind=I4P)parameterLength of a read note.
NOTE_REQUIREDinteger(kind=I4P)parameterRead without default.
NOTE_EQUALinteger(kind=I4P)parameterRead with default, present and equal to it.
NOTE_DIFFERSinteger(kind=I4P)parameterRead with default, present and different from it.
NOTE_TAKENinteger(kind=I4P)parameterRead with default, absent: the default is taken.
report_stateinteger(kind=I4P)ADAM_REPORT_DEFAULTS: -1 not yet inquired, 0 off, 1 on.
notescharacter(len=NOTE_LEN)allocatableReads noted: section, option, default as text.
kindsinteger(kind=I4P)allocatableKind of each noted read.
notes_numberinteger(kind=I4P)Number of reads noted.

Interfaces ​

ini_get ​

Read an INI option strictly, with an optional default when absent.

Module procedures: ini_get_I4P, ini_get_R8P, ini_get_logical, ini_get_character, ini_get_I4P_array, ini_get_R8P_array

ini_get_list ​

Read an INI list into an allocatable array sized by the number of values given.

Module procedures: ini_get_list_I4P, ini_get_list_R8P

Subroutines ​

ini_load ​

Load an input file into ini, resolving extends = <file> (a global option) recursively: the base file first, then the including file's options added onto it (an option both define takes the including file's value).

A missing file loads empty, as FiNeR does (the required options then fail to load); a missing base file, a chain longer than EXTENDS_DEPTH_MAX (a cycle) and an empty extends stop the run.

Attributes: recursive

fortran
subroutine ini_load(filename, ini, depth)

Arguments

NameTypeIntentAttributesDescription
filenamecharacter(len=*)inInput file name.
initype(file_ini)inoutLoaded (and merged) INI.
depthinteger(kind=I4P)inoptionalExtension depth of this file (0 for the input itself).

Call graph

ini_env_override ​

Override a real option by the environment variable name, when it is set (issue #80 P5). The regression harnesses set ADAM_MEMORY_FRACTION so that a tiny case does not allocate and initialize a block pool that fills the node (the init of a PRISM FNL case took ~74 s of its ~2 min); a value that is not a number stops the run.

fortran
subroutine ini_env_override(name, val)

Arguments

NameTypeIntentAttributesDescription
namecharacter(len=*)inEnvironment variable name.
valreal(kind=R8P)inoutValue, replaced when the variable is set.

Call graph

ini_mark_read ​

Count an option as read (issue #80 P5). FiNeR counts only the options read through get, so a parser that walks a section with loop (to refuse the options it does not know) marks each one it accepts, or ini_warn_unused would report it never read.

fortran
subroutine ini_mark_read(ini, section, option)

Arguments

NameTypeIntentAttributesDescription
initype(file_ini)inINI file.
sectioncharacter(len=*)inSection name.
optioncharacter(len=*)inOption name.

Call graph

record_failed ​

Record that the option is missing (and required) or not convertible.

fortran
subroutine record_failed(section, option)

Arguments

NameTypeIntentAttributesDescription
sectioncharacter(len=*)inSection name.
optioncharacter(len=*)inOption name.

Call graph

ini_error ​

Record an input error; the run goes on until the next ini_check (or ini_stop).

fortran
subroutine ini_error(msg)

Arguments

NameTypeIntentAttributesDescription
msgcharacter(len=*)inError message, without the leading ': '.

Call graph

ini_check ​

Stop the run if any input error has been recorded, reporting all of them.

One error: : <message>, as every parser reported it before. More: a count, then one indented message per line.

fortran
subroutine ini_check()

Call graph

ini_stop ​

Record an input error and stop at once with every error recorded (a value the parser cannot go on with).

fortran
subroutine ini_stop(msg)

Arguments

NameTypeIntentAttributesDescription
msgcharacter(len=*)inError message, without the leading ': '.

Call graph

ini_get_I4P ​

Read an integer option.

fortran
subroutine ini_get_I4P(ini, section, option, val, default)

Arguments

NameTypeIntentAttributesDescription
initype(file_ini)inINI file.
sectioncharacter(len=*)inSection name.
optioncharacter(len=*)inOption name.
valinteger(kind=I4P)inoutValue.
defaultinteger(kind=I4P)inoptionalDefault, when the option is absent.

Call graph

ini_get_R8P ​

Read a real option.

fortran
subroutine ini_get_R8P(ini, section, option, val, default)

Arguments

NameTypeIntentAttributesDescription
initype(file_ini)inINI file.
sectioncharacter(len=*)inSection name.
optioncharacter(len=*)inOption name.
valreal(kind=R8P)inoutValue.
defaultreal(kind=R8P)inoptionalDefault, when the option is absent.

Call graph

ini_get_logical ​

Read a logical option.

fortran
subroutine ini_get_logical(ini, section, option, val, default)

Arguments

NameTypeIntentAttributesDescription
initype(file_ini)inINI file.
sectioncharacter(len=*)inSection name.
optioncharacter(len=*)inOption name.
vallogicalinoutValue.
defaultlogicalinoptionalDefault, when the option is absent.

Call graph

ini_get_character ​

Read a text option into a fixed-length buffer (the caller trims it).

fortran
subroutine ini_get_character(ini, section, option, val, default)

Arguments

NameTypeIntentAttributesDescription
initype(file_ini)inINI file.
sectioncharacter(len=*)inSection name.
optioncharacter(len=*)inOption name.
valcharacter(len=*)inoutValue.
defaultcharacter(len=*)inoptionalDefault, when the option is absent.

Call graph

ini_get_I4P_array ​

Read a integer list (values separated by blanks) into val, whose size is the number of values expected.

fortran
subroutine ini_get_I4P_array(ini, section, option, val)

Arguments

NameTypeIntentAttributesDescription
initype(file_ini)inINI file.
sectioncharacter(len=*)inSection name.
optioncharacter(len=*)inOption name.
valinteger(kind=I4P)inoutValues.

Call graph

ini_get_R8P_array ​

Read a real list (values separated by blanks) into val, whose size is the number of values expected.

fortran
subroutine ini_get_R8P_array(ini, section, option, val)

Arguments

NameTypeIntentAttributesDescription
initype(file_ini)inINI file.
sectioncharacter(len=*)inSection name.
optioncharacter(len=*)inOption name.
valreal(kind=R8P)inoutValues.

Call graph

ini_get_list_I4P ​

Read a integer list (values separated by blanks); val takes the number of values given.

fortran
subroutine ini_get_list_I4P(ini, section, option, val, default)

Arguments

NameTypeIntentAttributesDescription
initype(file_ini)inINI file.
sectioncharacter(len=*)inSection name.
optioncharacter(len=*)inOption name.
valinteger(kind=I4P)inoutallocatableValues.
defaultinteger(kind=I4P)inoptionalDefault, when the option is absent.

Call graph

ini_get_list_R8P ​

Read a real list (values separated by blanks); val takes the number of values given.

fortran
subroutine ini_get_list_R8P(ini, section, option, val, default)

Arguments

NameTypeIntentAttributesDescription
initype(file_ini)inINI file.
sectioncharacter(len=*)inSection name.
optioncharacter(len=*)inOption name.
valreal(kind=R8P)inoutallocatableValues.
defaultreal(kind=R8P)inoptionalDefault, when the option is absent.

Call graph

note_read ​

Note one read for the defaults report.

fortran
subroutine note_read(section, option, kind, default_text)

Arguments

NameTypeIntentAttributesDescription
sectioncharacter(len=*)inSection name.
optioncharacter(len=*)inOption name.
kindinteger(kind=I4P)inKind of read.
default_textcharacter(len=*)inoptionalDefault as text.

Call graph

ini_report_defaults ​

Print (rank 0) the options set to their default and the defaults taken since the last report, then forget them.

fortran
subroutine ini_report_defaults(label)

Arguments

NameTypeIntentAttributesDescription
labelcharacter(len=*)inoptionalWhat the file is (e.g. the realm), for the message.

Call graph

ini_warn_unused ​

Report (rank 0) every option of the file that no parser has read since it was loaded (issue #80, P2, F2): a misspelled key or a key no longer used is otherwise silently ignored. As warnings, the run goes on; as_error ([IO].(unused_keys) = error, P5) prints the same list as errors and stops the run.

fortran
subroutine ini_warn_unused(ini, label, as_error)

Arguments

NameTypeIntentAttributesDescription
initype(file_ini)inINI file, after every parser has read it.
labelcharacter(len=*)inoptionalWhat the file is (e.g. the realm), for the message.
as_errorlogicalinoptionalStop the run when an option was never read.

Call graph

Functions ​

is_present ​

True if the option is in the section.

Returns: logical

fortran
function is_present(ini, section, option)

Arguments

NameTypeIntentAttributesDescription
initype(file_ini)inINI file.
sectioncharacter(len=*)inSection name.
optioncharacter(len=*)inOption name.

Call graph

replace_all ​

Return string with every occurrence of old replaced by new.

Attributes: pure

Returns: character(len=:)

fortran
function replace_all(string, old, new) result(replaced)

Arguments

NameTypeIntentAttributesDescription
stringcharacter(len=*)inInput.
oldcharacter(len=*)inSubstring to replace.
newcharacter(len=*)inReplacement.

Call graph

ini_count_sections ​

Number of the enumerated sections <prefix>1 .. <prefix>N; stops the run when their numbers have a gap.

Returns: integer(kind=I4P)

fortran
function ini_count_sections(ini, prefix) result(n)

Arguments

NameTypeIntentAttributesDescription
initype(file_ini)inINI file.
prefixcharacter(len=*)inSections name before the number (e.g. slice_).

Call graph

report_on ​

True if the environment asks for the defaults report (ADAM_REPORT_DEFAULTS set, not 0).

Returns: logical

fortran
function report_on()

Call graph