Appearance
finer_file_ini_t
INI file class definition.
Source: src/lib/finer_file_ini_t.F90
Dependencies
Contents
- file_ini
- free
- get_items
- get_sections_list
- get_string
- initialize
- load
- print_file_ini
- save_file_ini
- 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
- 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
file_ini
INI file class.
Components
| Name | Type | Attributes | Description |
|---|---|---|---|
filename | character(len=:) | allocatable | File name |
Ns | integer(kind=I4P) | Number of sections. | |
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. |
Type-Bound Procedures
| Name | Attributes | Description |
|---|---|---|
add | Add a section. | |
count_values | pass(self) | Count option value(s). |
del | Remove (freeing) an option of a section. | |
free | pass(self) | Free dynamic memory destroyng file data. |
free_options | Free all options. | |
get | Get option value (scalar). | |
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. | |
load | pass(self) | Load file data. |
loop | Loop over options of a section. | |
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. |
assignment(=) | Procedure for section assignment overloading. | |
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. |
parse | pass(self) | Parse file data. |
assign_file_ini | pass(lhs) | Assignment overloading. |
Subroutines
free
Free dynamic memory.
Attributes: elemental
fortran
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
fortran
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
fortran
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.
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
| 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
fortran
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
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
| 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.
fortran
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.
fortran
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
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
| 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
fortran
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
fortran
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
fortran
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
fortran
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
fortran
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
fortran
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.
fortran
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.
fortran
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
parse
Parse file either from the self source data or from a source string.
fortran
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
fortran
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.
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
| 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
fortran
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
fortran
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=:)
fortran
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)
fortran
function sections_number(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(file_ini) | in | File data. |
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
| 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)
fortran
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
fortran
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
fortran
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
fortran
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