Skip to content

Loading, saving, printing ​

load ​

fortran
call fini%load([filename=] [, source=] [, separator=] [, error=])
ArgumentType
filenamecharacter(*), inthe file to read; it is stored in fini%filename
sourcecharacter(*), ina string holding the whole file, lines separated by new_line('a')
separatorcharacter(1), inthe separator of names and values, = by default
errorinteger(I4P), out0, the I/O status of a failed read, or ERR_SOURCE_MISSING
  • filename takes precedence over source. With neither, load reads fini%filename if it is set (by an earlier load, save or initialize, or by hand).
  • The new sections replace all the sections of fini. If the file cannot be read, fini keeps its sections and error holds the I/O status (not zero).
  • error is ERR_SOURCE_MISSING when there is nothing to read: no source, or a source with no option and no section.
  • The separator is remembered by fini for the following load calls that do not pass one.
sourcea file or a stringlinesCR dropped, split on LFcomments! ; # lines skippedsectionssplit at [headers]continuationsjoined to their optionoptionsname = value ; commentthe result replaces the sections of the file_ini; values stay text until get converts them

save ​

fortran
call fini%save([filename=] [, retain_comments=] [, iostat=] [, iomsg=])
ArgumentType
filenamecharacter(*), inthe file to write (created or replaced); it is stored in fini%filename
retain_commentslogical, inwrite the inline comments back, .false. by default
iostatinteger(I4P), out0, or the status of the first operation that failed
iomsgcharacter(*), outthe message of that failure
  • Without filename, save writes fini%filename. With neither, nothing is written and iostat is ERR_SOURCE_MISSING.
  • A fini without sections writes nothing: the file is neither created nor truncated, and iostat is 0.
  • iostat is the status of the first open, write or close that failed: a file that cannot be opened (a missing directory, no permission) is reported, and nothing is written after it.
  • What save writes: options as name = value, comment lines dropped, continuations joined.

print ​

fortran
call fini%print(unit= [, pref=] [, retain_comments=] [, iostat=] [, iomsg=])
ArgumentType
unitinteger(I4P), inan open unit, 6 (or output_unit) for the standard output
prefcharacter(*), ina prefix written at the start of every line
retain_commentslogical, inprint the inline comments, .false. by default
iostat, iomsgoutas for save: 0 when nothing failed (also when there is nothing to print)

print writes what save writes, each option indented by two blanks, each line after pref.

The file name, initialize and free ​

  • fini%filename is a public character(len=:), allocatable member: load(filename=) and save(filename=) set it, and you can set it by hand.
  • initialize([filename=]) empties fini (as free) and sets filename.
  • free() deletes every section and option, the file name, and the separator (back to =).

Copying ​

b = a makes b an independent copy of a: its file name, separator, sections and options. Changing one does not change the other.

Examples ​