Re: reading configuration files
- From: Joseph Huber <joseph.huber@xxxxxxxxxxxxx>
- Date: Wed, 18 Feb 2009 13:15:48 +0100
Bart Vandewoestyne wrote:
Hello all,
In an attempt to make a certain program more flexible in its use,
I would like it to read certain parameters from a textual
configuration file.
For as far as I can see now, the program parameters are all
simple scalar values, so I was wondering what could be the best
format for my configuration file, with respect to readability,
ease of reading in the values in my program and also taking into
account that the people who are entering the values in the
text-files do not know much about Fortran programming.
Some ways of doing it could be for example:
Option 1: use one space
----------------
parameter1 value1
parameter2 value2
Option 2: use :
---------------
parameter1:value1
parameter2:value2
Option 3: use tabs
------------------
parameter1 value1
parameter2 value2
Option 4: use two lines for parameter-value pairs
-------------------------------------------------
parameter1
value1
parameter2
value2
Option 5-...: any other suggestions?
------------------------------------
???
The names 'parameter1' and 'parameter2' do not necessarily have
to be the same length, and also I do not want to make many
assumptions on the input format of the numerical values (say I have
non-fortran users that need to modify the text-files and write
numerical values in it... so they don't know anything about
format descriptors etc...)
What would be a good format for my configuration files so that
i can easily read it in my fortran code and so that it is a bit
robust against different formats for the numerical values.
(e.g. a user could enter 1.0e3 or 1000 or 1000.0.
Thanks,
Bart
Since we are talking Fortran here,
consider to use NAMELIST input.
Just an example:
Input file:
&NML1
I = 0,
J = 0,
K = 0,
A = 0.0000000E+00,
B = 0.0000000E+00,
C = 0.0000000E+00,
D = 0.0000000E+00,
STRING = "a string like this"
/
&NML2
L = F,
M = 0,
N = 0,
STRING2 = "here is the end"
/
Can simply read by this program:
program nmltest
integer i,j,k,m,n
logical l
real a,b,c,d
character*16 string, string2
namelist /nml1/ i,j,k,a,b,c,d,string
namelist /nml2/ l,m,n,string2
read(*,nml1)
read(*,nml2)
end
--
--
Joseph Huber, http://www.huber-joseph.de
.
- Follow-Ups:
- Re: reading configuration files
- From: Terence
- Re: reading configuration files
- From: e p chandler
- Re: reading configuration files
- From: Arjan
- Re: reading configuration files
- References:
- reading configuration files
- From: Bart Vandewoestyne
- reading configuration files
- Prev by Date: Re: A main program error!
- Next by Date: Re: reading configuration files
- Previous by thread: Re: reading configuration files
- Next by thread: Re: reading configuration files
- Index(es):
Relevant Pages
|