current version 1.6 - 31st January 2020
version | date | comment |
---|---|---|
1.0 | 01/Feb/2007 | Original code |
1.1 | 09/Mar/2007 | support for sections and subsections |
1.2 | 25/Oct/2008 | support for multiple ini files using type IniList |
1.3 | 11/Aug/2009 | Added SectionIsPresent |
1.4 | 19/Oct/2017 | Added SubSectionIsPresent |
1.5 | 24/Nov/2017 | Added IniOpenFileUnit |
1.6 | 31/Jan/2020 | Functions GetNofSections, GetNofSubSections |
license: GNU GPL http://www.gnu.org/licenses/
This file is part of
MOSAICO -- MOdular library for raSter bAsed hydrologIcal appliCatiOn.
Copyright (C) 2011 Giovanni Ravazzani
routines for reading configuration files
with each line of the form line 'name = value'
with support for sections []
and subsections [[ ]]
.
Comments are denoted by '#' and can occupy a an entire line
or terminating one
example file:
# ini file example
key1 = value1
key2 = value2
[section1] # first section
key1 = value3
key2 = value4
[section2] # second section
key1 = value5
key2 = value6
[[subsection]] # subsection in section1
key1 = value7
key2 = value8
Adapted from Antony Lewis (http://cosmologist.info/)
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
logical, | private | :: | inSection | ||||
logical, | private | :: | inSubSection |
define a dynamic list to store elements in memory |
|||
integer(kind=long), | private | :: | ios | ||||
integer(kind=long), | private | :: | numKeys | = | 0 | ||
integer(kind=long), | private, | parameter | :: | stringLen | = | 500 |
open and read a ini file
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | fileName | |||
type(IniList), | intent(out) | :: | iniDB |
read a ini file already open
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=short), | intent(in) | :: | fileUnit | |||
type(IniList), | intent(out) | :: | iniDB |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=stringLen), | public, | POINTER | :: | keys(:) | |||
integer(kind=long), | public | :: | nOfSections | ||||
integer(kind=long), | public | :: | nOfSubSections | ||||
integer(kind=long), | public | :: | numKeys | ||||
integer(kind=long), | public, | POINTER | :: | sectionBegin(:) | |||
integer(kind=long), | public, | POINTER | :: | sectionEnd(:) | |||
character(len=stringLen), | public, | POINTER | :: | sectionName(:) | |||
integer(kind=long), | public, | POINTER | :: | subSectionBegin(:) | |||
integer(kind=long), | public, | POINTER | :: | subSectionEnd(:) | |||
character(len=stringLen), | public, | POINTER | :: | subSectionName(:) | |||
character(len=stringLen), | public, | POINTER | :: | vals(:) |
count sections in a ini db
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(IniList), | intent(in) | :: | ini |
return number of subsections within a section of a ini db
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(IniList), | intent(in) | :: | ini | |||
character(len=*), | intent(in) | :: | sectionname |
read an double precision number corresponding to Key
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | key | |||
type(IniList), | intent(in) | :: | iniDB | |||
character(len=*), | intent(in), | optional | :: | section | ||
character(len=*), | intent(in), | optional | :: | subSection | ||
real(kind=double), | intent(in), | optional | :: | default |
read an integer corresponding to Key
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | key | |||
type(IniList), | intent(in) | :: | iniDB | |||
character(len=*), | intent(in), | optional | :: | section | ||
character(len=*), | intent(in), | optional | :: | subSection | ||
integer(kind=long), | intent(in), | optional | :: | default |
read a logical value corresponding to Key
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | key | |||
type(IniList), | intent(in) | :: | iniDB | |||
character(len=*), | intent(in), | optional | :: | section | ||
character(len=*), | intent(in), | optional | :: | subSection | ||
logical, | intent(in), | optional | :: | default |
read a string corresponding to Key
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | key | |||
type(IniList), | intent(in) | :: | iniDB | |||
character(len=*), | intent(in), | optional | :: | section | ||
character(len=*), | intent(in), | optional | :: | subSection |
return true if key is present, false otherwise
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | key | |||
type(IniList), | intent(in) | :: | iniDB | |||
character(len=*), | intent(in), | optional | :: | section | ||
character(len=*), | intent(in), | optional | :: | subSection |
return true if section is present, false otherwise
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | section | |||
type(IniList), | intent(in) | :: | iniDB |
return true if subsection is present in section, false otherwise
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | subsection | |||
character(len=*), | intent(in) | :: | section | |||
type(IniList), | intent(in) | :: | iniDB |
read a real number corresponding to Key
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | key | |||
type(IniList), | intent(in) | :: | iniDB | |||
character(len=*), | intent(in), | optional | :: | section | ||
character(len=*), | intent(in), | optional | :: | subSection | ||
real(kind=float), | intent(in), | optional | :: | default |
count Key-Val pair in a file
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=short), | intent(in) | :: | unit |
synchronize the window in which searching for the key
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=long), | intent(out) | :: | first | |||
integer(kind=long), | intent(out) | :: | last | |||
type(IniList), | intent(in) | :: | iniDB | |||
character(len=*), | intent(in), | optional | :: | sec | ||
character(len=*), | intent(in), | optional | :: | subSec |
check if section and subsection still opened
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(IniList), | intent(inout) | :: | iniDB |
add a new Key-Val pair
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | aInLine | |||
type(IniList), | intent(out) | :: | iniDB |
open and read a ini file
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | fileName | |||
type(IniList), | intent(out) | :: | iniDB |
read a ini file already open
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=short), | intent(in) | :: | fileUnit | |||
type(IniList), | intent(out) | :: | iniDB |