finer_file_ini_t
INI file class definition.
Source: src/lib/finer_file_ini_t.F90
Dependencies
Contents
- access_log
- file_ini
- free
- get_items
- get_sections_list
- get_string
- initialize
- load
- print_file_ini
- save_file_ini
- unused_options
- add_a_option
- add_option
- add_section
- free_options_all
- free_option_of_section
- free_options_of_section
- free_section
- get_a_option
- get_option
- mark_read
- parse
- assign_file_ini
- file_ini_autotest
- count_values
- has_option
- has_section
- section_file_ini
- sections_number
- index_option
- index_section
- is_global
- loop_options_section
- loop_options
Derived Types
access_log
Options read through get: one key per section/option pair, the section name, achar(0), the option name.
Components
| Name | Type | Attributes | Description |
|---|---|---|---|
keys | type(string) | allocatable | Keys of the options read. |
n | integer(kind=I4P) | Number of keys stored. |
file_ini
INI file class.
Components
| Name | Type | Attributes | Description |
|---|---|---|---|
filename | character(len=:) | allocatable | File name |
opt_sep | character(len=1) | Separator character of option name/value. | |
sections | type(section) | allocatable | Sections. |
loop_s | integer(kind=I4P) | Index of the section of the running loop over all options. | |
reads | type(access_log) | pointer | Options read through get (see unused_options): a pointer, so that get, whose self is intent(in), can record a read. |
Type-Bound Procedures
| Name | Attributes | Description |
|---|---|---|
add | Add 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_values | pass(self) | Count option value(s). |
del | Remove (freeing) an option of a section. Remove (freeing) a section. Generic: free_option_of_section, free_section | |
free | pass(self) | Free dynamic memory destroyng file data. |
free_options | Free 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 | |
get | Get option value (scalar). Get option value (array). Generic: get_option, get_a_option | |
get_items | pass(self) | Get list of pairs option name/value. |
get_sections_list | pass(self) | Get sections names list. |
get_string | pass(self) | Get option value as an allocatable string. |
initialize | pass(self) | Initialize file. |
has_option | pass(self) | Inquire the presence of an option. |
has_section | pass(self) | Inquire the presence of a section. |
index | Return the index of a section. Return the index of an option. Generic: index_section, index_option | |
load | pass(self) | Load file data. |
loop | Loop over options of a section. Loop over all options. Generic: loop_options_section, loop_options | |
print | pass(self) | Pretty printing data. |
save | pass(self) | Save data. |
section | pass(self) | Get section name once provided an index. |
sections_number | pass(self) | Return the sections number. |
unused_options | pass(self) | Get the options never read through get. |
assignment(=) | Procedure for section assignment overloading. Generic: assign_file_ini | |
add_a_option | pass(self) | Add an option to a section (array). |
add_option | pass(self) | Add an option to a section (scalar). |
add_section | pass(self) | Add a section. |
free_options_all | pass(self) | Free all options of all sections. |
free_options_of_section | pass(self) | Free all options of a section. |
free_option_of_section | pass(self) | Free an option of a section. |
free_section | pass(self) | Free a section. |
get_a_option | pass(self) | Get option value (array). |
get_option | pass(self) | Get option value (scalar). |
index_option | pass(self) | Return the index of an option. |
index_section | pass(self) | Return the index of a section. |
is_global | pass(self) | Inquire if a section is the global (unnamed) one. |
loop_options | pass(self) | Loop over all options. |
loop_options_section | pass(self) | Loop over options of a section. |
mark_read | pass(self) | Record that an option has been read. |
parse | pass(self) | Parse file data. |
assign_file_ini | pass(lhs) | Assignment overloading. |
Subroutines
free
Free dynamic memory.
Attributes: elemental
subroutine free(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. |
get_items
Get list of pairs option name/value.
Attributes: pure
subroutine get_items(self, items)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
items | character(len=:) | out | allocatable | Items, list of pairs option name/value for all options [1:No,1:2]. |
Call graph
get_sections_list
Get sections names list.
Attributes: pure
subroutine get_sections_list(self, list)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
list | character(len=:) | out | allocatable | Sections 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.
type(file_ini) :: fini
character(len=:), allocatable :: string
call fini%get_string(section_name='section-1', option_name='option-1', val=string)subroutine get_string(self, section_name, option_name, val, error, default)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
section_name | character(len=*) | in | Section name. | |
option_name | character(len=*) | in | Option name. | |
val | character(len=:) | inout | allocatable | Value. |
error | integer(kind=I4P) | out | optional | Error code. |
default | character(len=*) | in | optional | Default value, used if the option cannot be got. |
Call graph
initialize
Initialize file.
Attributes: elemental
subroutine initialize(self, filename)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. | |
filename | character(len=*) | in | optional | File name. |
load
Get file data from a file or a source string.
Usage
Loading from a file
type(file_ini):: fini
call fini%load(filename='path_to_my_file.ini')Loading from a source string
type(file_ini):: fini
call fini%load(source='[section-1] option-1=one [section-2] option-2=due')subroutine load(self, separator, filename, source, error)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. | |
separator | character(len=1) | in | optional | Separator of options name/value. |
filename | character(len=*) | in | optional | File name. |
source | character(len=*) | in | optional | File source contents. |
error | integer(kind=I4P) | out | optional | Error code. |
Call graph
print_file_ini
Print data with a pretty format.
subroutine print_file_ini(self, unit, pref, retain_comments, iostat, iomsg)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
unit | integer(kind=I4P) | in | Logic unit. | |
pref | character(len=*) | in | optional | Prefixing string. |
retain_comments | logical | in | optional | Flag for retaining eventual comments. |
iostat | integer(kind=I4P) | out | optional | IO error. |
iomsg | character(len=*) | out | optional | IO 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.
subroutine save_file_ini(self, retain_comments, iostat, iomsg, filename)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. | |
retain_comments | logical | in | optional | Flag for retaining eventual comments. |
iostat | integer(kind=I4P) | out | optional | IO error. |
iomsg | character(len=*) | out | optional | IO error message. |
filename | character(len=*) | in | optional | File 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).
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))subroutine unused_options(self, items)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
items | character(len=:) | out | allocatable | Unused 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
subroutine add_a_option(self, error, section_name, option_name, val)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. | |
error | integer(kind=I4P) | out | optional | Error code. |
section_name | character(len=*) | in | Section name. | |
option_name | character(len=*) | in | Option name. | |
val | class(*) | in | Option value. |
Call graph
add_option
Add an option (with scalar value).
If the option already exists, its value is updated.
Attributes: pure
subroutine add_option(self, error, section_name, option_name, val)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. | |
error | integer(kind=I4P) | out | optional | Error code. |
section_name | character(len=*) | in | Section name. | |
option_name | character(len=*) | in | Option name. | |
val | class(*) | in | Option 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
subroutine add_section(self, error, section_name)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. | |
error | integer(kind=I4P) | out | optional | Error code. |
section_name | character(len=*) | in | Section name. |
free_options_all
Free all options of all sections.
Attributes: elemental
subroutine free_options_all(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. |
Call graph
free_option_of_section
Free all options of a section.
Attributes: elemental
subroutine free_option_of_section(self, section_name, option_name)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. | |
section_name | character(len=*) | in | Section name. | |
option_name | character(len=*) | in | Option name. |
Call graph
free_options_of_section
Free all options of a section.
Attributes: elemental
subroutine free_options_of_section(self, section_name)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. | |
section_name | character(len=*) | in | Section name. |
Call graph
free_section
Free all options of a section.
Attributes: elemental
subroutine free_section(self, section_name)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. | |
section_name | character(len=*) | in | Section 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.
subroutine get_a_option(self, section_name, option_name, val, delimiter, error, default)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
section_name | character(len=*) | in | Section name. | |
option_name | character(len=*) | in | Option name. | |
val | class(*) | inout | Value. | |
delimiter | character(len=*) | in | optional | Delimiter used for separating values. |
error | integer(kind=I4P) | out | optional | Error code. |
default | class(*) | in | optional | Default 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.
subroutine get_option(self, section_name, option_name, val, error, default)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
section_name | character(len=*) | in | Section name. | |
option_name | character(len=*) | in | Option name. | |
val | class(*) | inout | Value. | |
error | integer(kind=I4P) | out | optional | Error code. |
default | class(*) | in | optional | Default 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.
subroutine mark_read(self, section_index, option_name)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
section_index | integer(kind=I4P) | in | Index of the section. | |
option_name | character(len=*) | in | Option name. |
Call graph
parse
Parse file either from the self source data or from a source string.
subroutine parse(self, source, error)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. | |
source | type(string) | in | String source. | |
error | integer(kind=I4P) | out | optional | Error code. |
Call graph
assign_file_ini
Assignment between two INI files.
Attributes: elemental
subroutine assign_file_ini(lhs, rhs)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
lhs | class(file_ini) | inout | Left hand side. | |
rhs | type(file_ini) | in | Rigth hand side. |
file_ini_autotest
Autotest the library functionalities.
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)
function count_values(self, delimiter, section_name, option_name) result(Nv)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
delimiter | character(len=*) | in | optional | Delimiter used for separating values. |
section_name | character(len=*) | in | Section name. | |
option_name | character(len=*) | in | Option 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
function has_option(self, option_name, section_name) result(pres)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
option_name | character(len=*) | in | Option name. | |
section_name | character(len=*) | inout | optional | Section name. |
Call graph
has_section
Inquire the presence of (at least one) section with the name passed.
Attributes: elemental
Returns: logical
function has_section(self, section_name) result(pres)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
section_name | character(len=*) | in | Section name. |
Call graph
section_file_ini
Get section name once an index (valid) is provided.
Attributes: pure
Returns: character(len=:)
function section_file_ini(self, section_index) result(sname)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
section_index | integer(kind=I4P) | in | Section index. |
Call graph
sections_number
Return the sections number.
Attributes: elemental
Returns: integer(kind=I4P)
function sections_number(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File 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)
function index_option(self, back, section_name, option_name) result(ind)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
back | logical | in | optional | If back appears with the value true, the last matching index is returned. |
section_name | character(len=*) | in | Section name. | |
option_name | character(len=*) | in | Option 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)
function index_section(self, back, section_name) result(ind)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
back | logical | in | optional | If back appears with the value true, the last matching index is returned. |
section_name | character(len=*) | in | Section 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
function is_global(self, section_index)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. | |
section_index | integer(kind=I4P) | in | Section 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
function loop_options_section(self, section_name, option_pairs) result(again)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. | |
section_name | character(len=*) | in | Section name. | |
option_pairs | character(len=:) | out | allocatable | Pairs 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
function loop_options(self, option_pairs) result(again)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | inout | File data. | |
option_pairs | character(len=:) | out | allocatable | Pairs option name/value [1:2]. |
Call graph