Fortran INI ParseR and generator — a pure Fortran 2003+ OOP library for reading and writing INI configuration files.
- Parse INI files from disk or from an in-memory string
- Auto-detect all sections and options — no schema required
- Multi-line option values and inline comments (
;) handled automatically - Configurable option separator (default
=) - Generate INI files programmatically with
add/del/save - Unlimited polymorphic values: integer, real, logical, character, and arrays of any PENF kind
- Introspection:
has_section,has_option,index,count_values,items,loop - OOP/TDD designed — single
file_initype, all functionality as type-bound procedures
- Stefano Zaghi — @szaghi
Contributions are welcome — see the Contributing page.
This project is distributed under a multi-licensing system:
- FOSS projects: GPL v3
- Closed source / commercial: BSD 2-Clause, BSD 3-Clause, or MIT
Anyone interested in using, developing, or contributing to this project is welcome — pick the license that best fits your needs.
Parse an INI source and retrieve a multi-value option:
use finer
use penf, only: R4P, I4P
implicit none
type(file_ini) :: fini
character(len=:), allocatable :: source
real(R4P), allocatable :: array(:)
integer(I4P) :: error
source = '[section-1]'//new_line('A')// &
'option-1 = one'//new_line('A')// &
'option-2 = 2.'//new_line('A')// &
' 3.'//new_line('A')// &
'[section-2]'//new_line('A')// &
'option-1 = foo'
call fini%load(source=source)
allocate(array(1:fini%count_values(section_name='section-1', option_name='option-2')))
call fini%get(section_name='section-1', option_name='option-2', val=array, error=error)
if (error == 0) print *, array ! 2.0 3.0Generate an INI file:
use finer
use penf, only: R8P
implicit none
type(file_ini) :: fini
call fini%add(section='sec-foo')
call fini%add(section='sec-foo', option='bar', val=-32.1_R8P)
call fini%add(section='sec-foo', option='baz', val=' hello FiNeR! ')
call fini%add(section='sec-foo', option='array', val=[1, 2, 3, 4])
call fini%add(section='sec-bar')
call fini%add(section='sec-bar', option='bools', val=[.true., .false., .false.])
call fini%save(filename='foo.ini')git clone https://github.com/szaghi/FiNeR --recursive
cd FiNeR
mkdir build && cd build
cmake ..
make && ctestadd_subdirectory(FiNeR)
target_link_libraries(your_target FiNeR::FiNeR)| Tool | Command |
|---|---|
| CMake | cmake .. && make |
| FoBiS.py | FoBiS.py build -mode tests-gnu |