Skip to content

finer_file_ini_t ​

INI file class definition.

Source: src/lib/finer_file_ini_t.F90

Dependencies

Contents ​

Derived Types ​

access_log ​

Options read through get: one key per section/option pair, the section name, achar(0), the option name.

Components

NameTypeAttributesDescription
keystype(string)allocatableKeys of the options read.
ninteger(kind=I4P)Number of keys stored.

file_ini ​

INI file class.

Components

NameTypeAttributesDescription
filenamecharacter(len=:)allocatableFile name
opt_sepcharacter(len=1)Separator character of option name/value.
sectionstype(section)allocatableSections.
loop_sinteger(kind=I4P)Index of the section of the running loop over all options.
readstype(access_log)pointerOptions read through get (see unused_options): a pointer, so that get, whose self is intent(in), can record a read.

Type-Bound Procedures

NameAttributesDescription
addAdd a section. Add an option to a section (scalar). Add an option to a section (array). Generic: add_section, add_option, add_a_option
count_valuespass(self)Count option value(s).
delRemove (freeing) an option of a section. Remove (freeing) a section. Generic: free_option_of_section, free_section
freepass(self)Free dynamic memory destroyng file data.
free_optionsFree all options. Free all options of a section. Free an option of a section. Generic: free_options_all, free_options_of_section, free_option_of_section
getGet option value (scalar). Get option value (array). Generic: get_option, get_a_option
get_itemspass(self)Get list of pairs option name/value.
get_sections_listpass(self)Get sections names list.
get_stringpass(self)Get option value as an allocatable string.
initializepass(self)Initialize file.
has_optionpass(self)Inquire the presence of an option.
has_sectionpass(self)Inquire the presence of a section.
indexReturn the index of a section. Return the index of an option. Generic: index_section, index_option
loadpass(self)Load file data.
loopLoop over options of a section. Loop over all options. Generic: loop_options_section, loop_options
printpass(self)Pretty printing data.
savepass(self)Save data.
sectionpass(self)Get section name once provided an index.
sections_numberpass(self)Return the sections number.
unused_optionspass(self)Get the options never read through get.
assignment(=)Procedure for section assignment overloading. Generic: assign_file_ini
add_a_optionpass(self)Add an option to a section (array).
add_optionpass(self)Add an option to a section (scalar).
add_sectionpass(self)Add a section.
free_options_allpass(self)Free all options of all sections.
free_options_of_sectionpass(self)Free all options of a section.
free_option_of_sectionpass(self)Free an option of a section.
free_sectionpass(self)Free a section.
get_a_optionpass(self)Get option value (array).
get_optionpass(self)Get option value (scalar).
index_optionpass(self)Return the index of an option.
index_sectionpass(self)Return the index of a section.
is_globalpass(self)Inquire if a section is the global (unnamed) one.
loop_optionspass(self)Loop over all options.
loop_options_sectionpass(self)Loop over options of a section.
mark_readpass(self)Record that an option has been read.
parsepass(self)Parse file data.
assign_file_inipass(lhs)Assignment overloading.

Subroutines ​

free ​

Free dynamic memory.

Attributes: elemental

fortran
subroutine free(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.

get_items ​

Get list of pairs option name/value.

Attributes: pure

fortran
subroutine get_items(self, items)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
itemscharacter(len=:)outallocatableItems, list of pairs option name/value for all options [1:No,1:2].

Call graph

get_sections_list ​

Get sections names list.

Attributes: pure

fortran
subroutine get_sections_list(self, list)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
listcharacter(len=:)outallocatableSections names list.

Call graph

get_string ​

Get option value as an allocatable string.

val is (re)allocated with the length of the option value: it does not need to be allocated before the call.

If the option cannot be got (missing section, missing option or option without value) an error is returned and val is set to default, if passed, otherwise it is left unchanged.

fortran
 type(file_ini)                :: fini
 character(len=:), allocatable :: string
 call fini%get_string(section_name='section-1', option_name='option-1', val=string)
fortran
subroutine get_string(self, section_name, option_name, val, error, default)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
section_namecharacter(len=*)inSection name.
option_namecharacter(len=*)inOption name.
valcharacter(len=:)inoutallocatableValue.
errorinteger(kind=I4P)outoptionalError code.
defaultcharacter(len=*)inoptionalDefault value, used if the option cannot be got.

Call graph

initialize ​

Initialize file.

Attributes: elemental

fortran
subroutine initialize(self, filename)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.
filenamecharacter(len=*)inoptionalFile name.

load ​

Get file data from a file or a source string.

Usage ​

Loading from a file ​
bash
type(file_ini):: fini
call fini%load(filename='path_to_my_file.ini')
Loading from a source string ​
bash
type(file_ini):: fini
call fini%load(source='[section-1] option-1=one [section-2] option-2=due')
fortran
subroutine load(self, separator, filename, source, error)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.
separatorcharacter(len=1)inoptionalSeparator of options name/value.
filenamecharacter(len=*)inoptionalFile name.
sourcecharacter(len=*)inoptionalFile source contents.
errorinteger(kind=I4P)outoptionalError code.

Call graph

Print data with a pretty format.

fortran
subroutine print_file_ini(self, unit, pref, retain_comments, iostat, iomsg)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
unitinteger(kind=I4P)inLogic unit.
prefcharacter(len=*)inoptionalPrefixing string.
retain_commentslogicalinoptionalFlag for retaining eventual comments.
iostatinteger(kind=I4P)outoptionalIO error.
iomsgcharacter(len=*)outoptionalIO error message.

Call graph

save_file_ini ​

Save data.

iostat is the status of the first operation (open, write or close) that failed, 0 if none did. Without a file name (neither passed nor set before) nothing is written and iostat is ERR_SOURCE_MISSING. Without sections nothing is written (the file is neither created nor truncated) and iostat is 0.

fortran
subroutine save_file_ini(self, retain_comments, iostat, iomsg, filename)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.
retain_commentslogicalinoptionalFlag for retaining eventual comments.
iostatinteger(kind=I4P)outoptionalIO error.
iomsgcharacter(len=*)outoptionalIO error message.
filenamecharacter(len=*)inoptionalFile name.

Call graph

unused_options ​

Get the options never read through get (or get_string) since the file was loaded.

items(o, 1) is the section name (empty for the global section) and items(o, 2) the option name, in file order; no unused option gives size(items, dim=1) == 0. An option counts as read once get has been called on it, even if its value did not convert to the type asked for. Options of a duplicated section are matched by name, so they count as read when the same option of the first section with that name was read (the one get returns).

fortran
 type(file_ini)                :: fini
 character(len=:), allocatable :: items(:,:)
 integer                       :: o
 call fini%load(source='[s] used = 1'//new_line('a')//'typo = 2')
 call fini%get(section_name='s', option_name='used', val=o)
 call fini%unused_options(items=items)
 print '(A)', trim(items(1, 1))//'.'//trim(items(1, 2))
fortran
subroutine unused_options(self, items)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
itemscharacter(len=:)outallocatableUnused options, pairs section name/option name [1:No,1:2].

Call graph

add_a_option ​

Add an option (with array value).

If the option already exists, its value is updated.

Attributes: pure

fortran
subroutine add_a_option(self, error, section_name, option_name, val)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.
errorinteger(kind=I4P)outoptionalError code.
section_namecharacter(len=*)inSection name.
option_namecharacter(len=*)inOption name.
valclass(*)inOption value.

Call graph

add_option ​

Add an option (with scalar value).

If the option already exists, its value is updated.

Attributes: pure

fortran
subroutine add_option(self, error, section_name, option_name, val)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.
errorinteger(kind=I4P)outoptionalError code.
section_namecharacter(len=*)inSection name.
option_namecharacter(len=*)inOption name.
valclass(*)inOption value.

Call graph

add_section ​

Add a section.

If the section already exists, it is left unchanged.

The section with an empty name is the global one, containing the options not belonging to any named section: it is always the first section, being saved (without header) before all the others.

Attributes: pure

fortran
subroutine add_section(self, error, section_name)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.
errorinteger(kind=I4P)outoptionalError code.
section_namecharacter(len=*)inSection name.

free_options_all ​

Free all options of all sections.

Attributes: elemental

fortran
subroutine free_options_all(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.

Call graph

free_option_of_section ​

Free all options of a section.

Attributes: elemental

fortran
subroutine free_option_of_section(self, section_name, option_name)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.
section_namecharacter(len=*)inSection name.
option_namecharacter(len=*)inOption name.

Call graph

free_options_of_section ​

Free all options of a section.

Attributes: elemental

fortran
subroutine free_options_of_section(self, section_name)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.
section_namecharacter(len=*)inSection name.

Call graph

free_section ​

Free all options of a section.

Attributes: elemental

fortran
subroutine free_section(self, section_name)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.
section_namecharacter(len=*)inSection name.

get_a_option ​

Get option value (array)

If the option cannot be got (missing section, missing option, values that cannot be converted to the type of val or that val cannot hold) an error is returned and val is set to default, if passed, otherwise it is left unchanged. default must have the same size of val and a type that can be assigned to it, otherwise it is ignored.

fortran
subroutine get_a_option(self, section_name, option_name, val, delimiter, error, default)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
section_namecharacter(len=*)inSection name.
option_namecharacter(len=*)inOption name.
valclass(*)inoutValue.
delimitercharacter(len=*)inoptionalDelimiter used for separating values.
errorinteger(kind=I4P)outoptionalError code.
defaultclass(*)inoptionalDefault value, used if the option cannot be got.

Call graph

get_option ​

Get option value (scalar).

If the option cannot be got (missing section, missing option or value that cannot be converted to the type of val) an error is returned and val is set to default, if passed, otherwise it is left unchanged. default must have a type that can be assigned to val, otherwise it is ignored.

fortran
subroutine get_option(self, section_name, option_name, val, error, default)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
section_namecharacter(len=*)inSection name.
option_namecharacter(len=*)inOption name.
valclass(*)inoutValue.
errorinteger(kind=I4P)outoptionalError code.
defaultclass(*)inoptionalDefault value, used if the option cannot be got.

Call graph

mark_read ​

Record in the access log that an option of a section has been read (nothing when the option is not in the section).

self is intent(in), as in get: the log is the target of a pointer component, which get may update.

fortran
subroutine mark_read(self, section_index, option_name)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
section_indexinteger(kind=I4P)inIndex of the section.
option_namecharacter(len=*)inOption name.

Call graph

parse ​

Parse file either from the self source data or from a source string.

fortran
subroutine parse(self, source, error)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.
sourcetype(string)inString source.
errorinteger(kind=I4P)outoptionalError code.

Call graph

assign_file_ini ​

Assignment between two INI files.

Attributes: elemental

fortran
subroutine assign_file_ini(lhs, rhs)

Arguments

NameTypeIntentAttributesDescription
lhsclass(file_ini)inoutLeft hand side.
rhstype(file_ini)inRigth hand side.

file_ini_autotest ​

Autotest the library functionalities.

fortran
subroutine file_ini_autotest()

Call graph

Functions ​

count_values ​

Get the number of values of option into section data.

Attributes: elemental

Returns: integer(kind=I4P)

fortran
function count_values(self, delimiter, section_name, option_name) result(Nv)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
delimitercharacter(len=*)inoptionalDelimiter used for separating values.
section_namecharacter(len=*)inSection name.
option_namecharacter(len=*)inOption name.

Call graph

has_option ​

Inquire the presence of (at least one) option with the name passed.

Optional, the first matching section name is returned.

@note All sections are searched and the first occurence is returned.

Returns: logical

fortran
function has_option(self, option_name, section_name) result(pres)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
option_namecharacter(len=*)inOption name.
section_namecharacter(len=*)inoutoptionalSection name.

Call graph

has_section ​

Inquire the presence of (at least one) section with the name passed.

Attributes: elemental

Returns: logical

fortran
function has_section(self, section_name) result(pres)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
section_namecharacter(len=*)inSection name.

Call graph

section_file_ini ​

Get section name once an index (valid) is provided.

Attributes: pure

Returns: character(len=:)

fortran
function section_file_ini(self, section_index) result(sname)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
section_indexinteger(kind=I4P)inSection index.

Call graph

sections_number ​

Return the sections number.

Attributes: elemental

Returns: integer(kind=I4P)

fortran
function sections_number(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.

Call graph

index_option ​

Return the index of the option (inside a section) matching the name(s) passed.

@note The matching index returned is the first found if back is not passed or if back=.false.. On the contrary the last found is returned if back=.true..

Attributes: elemental

Returns: integer(kind=I4P)

fortran
function index_option(self, back, section_name, option_name) result(ind)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
backlogicalinoptionalIf back appears with the value true, the last matching index is returned.
section_namecharacter(len=*)inSection name.
option_namecharacter(len=*)inOption name.

index_section ​

Return the index of the section matching the name passed.

@note The matching index returned is the first found if back is not passed or if back=.false.. On the contrary the last found is returned if back=.true..

Attributes: elemental

Returns: integer(kind=I4P)

fortran
function index_section(self, back, section_name) result(ind)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
backlogicalinoptionalIf back appears with the value true, the last matching index is returned.
section_namecharacter(len=*)inSection name.

is_global ​

Inquire if a section is the global (unnamed) one, namely the first section if it has an empty name.

The global section contains the options defined before the first section header: it is saved without header.

Attributes: elemental

Returns: logical

fortran
function is_global(self, section_index)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inFile data.
section_indexinteger(kind=I4P)inSection index.

Call graph

loop_options_section ​

Loop returning option name/value defined into section.

The state of the loop is stored into the file data, thus loops over different sections (or different files) do not interfere. A loop must be completed (until false is returned) before starting a new one over the same section.

Returns: logical

fortran
function loop_options_section(self, section_name, option_pairs) result(again)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.
section_namecharacter(len=*)inSection name.
option_pairscharacter(len=:)outallocatablePairs option name/value [1:2].

Call graph

loop_options ​

Loop returning option name/value defined into all sections.

The state of the loop is stored into the file data. A loop must be completed (until false is returned) before starting a new one.

Returns: logical

fortran
function loop_options(self, option_pairs) result(again)

Arguments

NameTypeIntentAttributesDescription
selfclass(file_ini)inoutFile data.
option_pairscharacter(len=:)outallocatablePairs option name/value [1:2].

Call graph