Appearance
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:valtakes it; - present but not convertible (e.g.
frequency = abc): the run stops, as before (FiNeR's owndefault=would silently take the default here); - absent, with
default:valtakes the default; - absent, without
default(a required option): the errorfailed 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
- ini_get
- ini_get_list
- ini_load
- ini_env_override
- ini_mark_read
- record_failed
- ini_error
- ini_check
- ini_stop
- ini_get_I4P
- ini_get_R8P
- ini_get_logical
- ini_get_character
- ini_get_I4P_array
- ini_get_R8P_array
- ini_get_list_I4P
- ini_get_list_R8P
- note_read
- ini_report_defaults
- ini_warn_unused
- is_present
- replace_all
- ini_count_sections
- report_on
Variables
| Name | Type | Attributes | Description |
|---|---|---|---|
TEXT_LEN | integer(kind=I4P) | parameter | Length of the text buffer used to detect an option. |
EXTENDS_DEPTH_MAX | integer(kind=I4P) | parameter | Longest chain of files extending one another. |
pending | character(len=:) | allocatable | Errors recorded since the last ini_check, one per line. |
pending_number | integer(kind=I4P) | Number of errors recorded. | |
NOTE_LEN | integer(kind=I4P) | parameter | Length of a read note. |
NOTE_REQUIRED | integer(kind=I4P) | parameter | Read without default. |
NOTE_EQUAL | integer(kind=I4P) | parameter | Read with default, present and equal to it. |
NOTE_DIFFERS | integer(kind=I4P) | parameter | Read with default, present and different from it. |
NOTE_TAKEN | integer(kind=I4P) | parameter | Read with default, absent: the default is taken. |
report_state | integer(kind=I4P) | ADAM_REPORT_DEFAULTS: -1 not yet inquired, 0 off, 1 on. | |
notes | character(len=NOTE_LEN) | allocatable | Reads noted: section, option, default as text. |
kinds | integer(kind=I4P) | allocatable | Kind of each noted read. |
notes_number | integer(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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
filename | character(len=*) | in | Input file name. | |
ini | type(file_ini) | inout | Loaded (and merged) INI. | |
depth | integer(kind=I4P) | in | optional | Extension 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
name | character(len=*) | in | Environment variable name. | |
val | real(kind=R8P) | inout | Value, 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
ini | type(file_ini) | in | INI file. | |
section | character(len=*) | in | Section name. | |
option | character(len=*) | in | Option name. |
Call graph
record_failed
Record that the option is missing (and required) or not convertible.
fortran
subroutine record_failed(section, option)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
section | character(len=*) | in | Section name. | |
option | character(len=*) | in | Option 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
msg | character(len=*) | in | Error 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
msg | character(len=*) | in | Error message, without the leading ': '. |
Call graph
ini_get_I4P
Read an integer option.
fortran
subroutine ini_get_I4P(ini, section, option, val, default)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
ini | type(file_ini) | in | INI file. | |
section | character(len=*) | in | Section name. | |
option | character(len=*) | in | Option name. | |
val | integer(kind=I4P) | inout | Value. | |
default | integer(kind=I4P) | in | optional | Default, 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
ini | type(file_ini) | in | INI file. | |
section | character(len=*) | in | Section name. | |
option | character(len=*) | in | Option name. | |
val | real(kind=R8P) | inout | Value. | |
default | real(kind=R8P) | in | optional | Default, 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
ini | type(file_ini) | in | INI file. | |
section | character(len=*) | in | Section name. | |
option | character(len=*) | in | Option name. | |
val | logical | inout | Value. | |
default | logical | in | optional | Default, 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
ini | type(file_ini) | in | INI file. | |
section | character(len=*) | in | Section name. | |
option | character(len=*) | in | Option name. | |
val | character(len=*) | inout | Value. | |
default | character(len=*) | in | optional | Default, 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
ini | type(file_ini) | in | INI file. | |
section | character(len=*) | in | Section name. | |
option | character(len=*) | in | Option name. | |
val | integer(kind=I4P) | inout | Values. |
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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
ini | type(file_ini) | in | INI file. | |
section | character(len=*) | in | Section name. | |
option | character(len=*) | in | Option name. | |
val | real(kind=R8P) | inout | Values. |
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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
ini | type(file_ini) | in | INI file. | |
section | character(len=*) | in | Section name. | |
option | character(len=*) | in | Option name. | |
val | integer(kind=I4P) | inout | allocatable | Values. |
default | integer(kind=I4P) | in | optional | Default, 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
ini | type(file_ini) | in | INI file. | |
section | character(len=*) | in | Section name. | |
option | character(len=*) | in | Option name. | |
val | real(kind=R8P) | inout | allocatable | Values. |
default | real(kind=R8P) | in | optional | Default, 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
section | character(len=*) | in | Section name. | |
option | character(len=*) | in | Option name. | |
kind | integer(kind=I4P) | in | Kind of read. | |
default_text | character(len=*) | in | optional | Default 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
label | character(len=*) | in | optional | What 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
ini | type(file_ini) | in | INI file, after every parser has read it. | |
label | character(len=*) | in | optional | What the file is (e.g. the realm), for the message. |
as_error | logical | in | optional | Stop 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
ini | type(file_ini) | in | INI file. | |
section | character(len=*) | in | Section name. | |
option | character(len=*) | in | Option 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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
string | character(len=*) | in | Input. | |
old | character(len=*) | in | Substring to replace. | |
new | character(len=*) | in | Replacement. |
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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
ini | type(file_ini) | in | INI file. | |
prefix | character(len=*) | in | Sections 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