Skip to content

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 heat
  • load(source=) parses a string: lines are separated by new_line('a'). A header [name] starts a section and each name = value line is an option of the section above it.
  • get(section_name=, option_name=, val=) converts the value into val. val is unlimited polymorphic: the same call reads an integer, a real or a string, and the type of val decides 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 = copper

What you learned

load a source, get typed values, print the result. Reference: Loading, saving, printing, Reading values.

Next: 2. Reading the case file.