Fortran 90 added Namelist to the Fortran standard.
It seems like too few programmers know about namelist, because we see a lot of needless configuration text file parsing.
While
IBM
and
Intel
describe namelist
, the application isn't immediately obvious from their didactic explanation.
Python has the
f90nml
module for Fortran namelist I/O.
There are strong benefits from using Fortran namelists, now let us give an example of their use.
Suppose we have a program namelist_main.f90 that reads configuration parameters from a file config.nml directly into Fortran variables. Variables that are not specified in the .nml file are unmodified. Typically we set default values for all variables before reading the namelist to handle this seamlessly. If a group isn't specified in the .nml file, it's just passed over silently.
- If you don't leave an extra blank line at the end of .nml, you may get an error like
Fortran runtime error: End of file
- unused (unspecified) groups must still be specified in .nml without any variables