| Gordon Sande 2004-03-27, 12:17 am |
| In article <405ACF83.7E98437D@wldelft.nl>,
Arjen Markus <arjen.markus@wldelft.nl> wrote:
>Subject: Re: Needed: Library or function that can read program settings from aplain text file.
>From: Arjen Markus <arjen.markus@wldelft.nl>
>Organization: WL | Delft Hydraulics (http://www.wldelft.nl)
>Date: Fri, 19 Mar 2004 11:46:27 +0100
>Newsgroups: comp.lang.fortran
>
>Claus Pedersen wrote:
>
>You are certainly not the first person with this problem.
>Depending on the kind of data you have:
>- Write a few routines that simply read the data you need (Fortran has
> excellent facilities for doing so). The advantage is that you can
>control
> exactly what the format of the data is. The di vantage is that it
>may
> be a lot of work to get it foolproof. Still, if you have data like
> a matrix of values, that may be the best chance.
>- You can use a small library that reads a specific format. I guess many
> people have such libraries and I myself have a small library for
>reading
> files like Windows INI files or Java properties files. I also have a
> library (in Fortran) to read XML files. You can have either, if this
> is all you need.
>- You can also resort to embedding a scripting language. My personal
> favourite is Tcl and I have written a small library to embed Tcl in
> Fortran programs. The advantage there is that with a bit of care
> data can be executed as Tcl code - making the effort of getting
> data from a file almost null. Again: this is available, just say
> the word.
>
>The real problem is: what kind of data are you dealing with?
For close to zero extra work but with some number of restrictions
you can use Fortran's NAMELIST.
So
&parms eps=1.0e-5, population=867 /
will set eps and population and leave any number of othe parameters
at their defaults. The restriction is that you need the NAMELIST name
and format (the &parms above) and must use their convetions on arrys etc.
To get you going until you write your own data parser it is the best
deal in town. It is so good that you might even not bother with doing
your own data parser. For very heavy duty you probably will do your
own but such things look less attractive once you figure out how to use
NAMELIST effectively. I tend to use NAMELIST for testbeds and small
one offs but have a collection of template matching parsers for bigger
problems. Each has its use where the other is not cost effective.
>Regards,
>
>Arjen
|