Fortran INI ParseR and generator

Find us on…

GitHub

FiNeR

FiNeR GitHub tag

License License License License

Status CI Status Coverage Status

FiNeR, Fortran INI ParseR and generator for FoRtraners

  • FiNeR is a pure Fortran (KISS) library for IO of INI (config) files for modern (2003+) Fortran projects;
  • FiNeR is Fortran 2003+ standard compliant;
  • FiNeR is OOP designed;
  • FiNeR is TDD designed;
  • FiNeR is a Free, Open Source Project.

Issues

GitHub issues

Compiler Support

Compiler Compiler Compiler Compiler Compiler Compiler


What is FiNeR? | Main features | Copyrights | Documentation | A Taste of FiNeR


What is FiNeR?

Modern Fortran standards (2003+) have introduced better support for strings manipulations. Exploiting such new Fortran capabilities, FiNeR provides an easy to use module library for input (parsing) and output (generating) INI (config) files.

Go to Top

Main features

  • [X] User-friendly methods for IO INI files:
    • [x] parsing files:
      • [x] automatic parsing of all sections (whose number is auto-detected);
      • [x] automatic parsing of all options of each section (whose number is auto-detected);
      • [x] unlimited polymorphic option-values extraction;
    • [x] generating files:
      • [x] user-friendly add/remove sections/options;
      • [x] unlimited polymorphic option-values setting;
    • [x] introspection:
      • [x] self-consistency checks;
      • [x] pretty-printings;
      • [x] loop over options;
      • [x] inquiring the presence of sections/options by name;
  • [ ] errors trapping mechanism.

Any feature request is welcome.

Go to Top

Copyrights

FiNeR is an open source project, it is distributed under a multi-licensing system:

Anyone is interest to use, to develop or to contribute to FiNeR is welcome, feel free to select the license that best matches your soul!

More details can be found on wiki.

Go to Top

Documentation

Besides this README file the FiNeR documentation is contained into its own wiki. Detailed documentation of the API is contained into the GitHub Pages that can also be created locally by means of ford tool.

A Taste of FiNeR

Let us assume our goal is to parse a config file. It is as simple as

use finer
...
type(file_ini)                :: fini     !< INI file handler.
character(len=:), allocatable :: source   ! Testing string.
real(R4P), allocatable        :: array(:) ! Array option.
integer(I4P)                  :: error    ! Error code.
...
source='[section-1]'//new_line('A')//    &
       'option-1 = one'//new_line('A')// &
       'option-2 = 2.'//new_line('A')//  &
       '           3.'//new_line('A')//  &
       'option-3 = bar'//new_line('A')// &
       '[section-2]'//new_line('A')//    &
       'option-1 = foo'
call fini%load(source=source)
allocate(array(1:fini%count_values(section='section-1',option='option-2')))
call fini%get(section='section-1',option='option-2',val=array,error=error)
if (error==0) then
  print*,array
else
  ! errors occur...
endif

And what about the generation of an INI file? It is simple as parsing an old one:

use finer
...
type(file_ini) :: fini !< INI file handler.
...
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')

A file named foo.ini is created. It contains something like:

[sec-foo]
bar = -0.321000000000000E+002
baz =  hello FiNeR!
array = +1 +2 +3 +4
[sec-bar]
bools = T F F

Go to Top

Developer Info

Stefano Zaghi

Derived Types