1. A first file
A file_ini holds a whole INI file: its sections, and the options of each section. Everything comes from one module, finer; the kinds (I4P, R8P, ...) come from PENF, a dependency of FiNeR.
f90
program heat
!< Tutorial, chapter 1: a first file.
use finer
use penf, only : I4P, R8P
implicit none
type(file_ini) :: case_file
integer(I4P) :: cells
real(R8P) :: length
character(len=32) :: material
call case_file%load(source='[grid]'//new_line('a')// &
'cells = 64'//new_line('a')// &
'length = 0.5'//new_line('a')// &
'[material]'//new_line('a')// &
'name = copper')
call case_file%get(section_name='grid', option_name='cells', val=cells)
call case_file%get(section_name='grid', option_name='length', val=length)
call case_file%get(section_name='material', option_name='name', val=material)
print '(A,I0,A,F5.2,A)', 'a rod of ', cells, ' cells, ', length, ' m long, made of '//trim(material)
call case_file%print(unit=6)
endprogram heatload(source=)parses a string: lines are separated bynew_line('a'). A header[name]starts a section and eachname = valueline is an option of the section above it.get(section_name=, option_name=, val=)converts the value intoval.valis unlimited polymorphic: the same call reads an integer, a real or a string, and the type ofvaldecides the conversion.print(unit=)writes the file as FiNeR holds it, with the options indented.
Running it
$ heat
a rod of 64 cells, 0.50 m long, made of copper
[grid]
cells = 64
length = 0.5
[material]
name = copperWhat you learned
load a source, get typed values, print the result. Reference: Loading, saving, printing, Reading values.
Next: 2. Reading the case file.