I would like to be able to use a simple configuration file to pass parameters to my program. This configuration file would consist of a list of arguments with values that can be of different types (integer, real, logical, list of words, etc.).
Here is an example of a configuration that I would like to be able to parse in a simple way:
! This is a first comment
param1 = 1234;
param2 = TRUE; ! This is a second comment
param3 = abc def ghi jkl mno
pqr stu vwx yz;
! Another type of instruction,
! i.e. to specify that var1-var3 depend on var4-var10:
var1 var2 var3 ~ var4 var5 var6
var7 var8 var9 var10;
Line breaks would be allowed, and different types of instructions could be passed to the program.
I am aware that NAMELIST could somehow allow to do that (except for the last part of the config file in this example), however it does not appear to be flexible enough for my needs. For instance, I don't think it allows to insert comments in the configuration file.
I found many libraries in C and C++ offering such a configuration file parser, but quite surprisingly, nothing in Fortran. Does anybody know of such a library?
Thanks in advance for your help!
I would always recommend using a standard format for your configuration files. This can pay dividends later if you want to say, script your program, or generate or read your config files in another programming language. There are now (in 2015) several good standard configuration file parsers available for Fortran, so there is no need to use other languages. See, for example:
Note that these are both for modern Fortran, and require one of the newer compilers (say, gfortran 4.9 or later).
we have a library called aotus, which allows the usage of Lua scripts as configuration files in Fortran applications: AOTUS Might be that this is useful for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With