[LORENE] new config-file reading routines
Reinhard Prix
Reinhard.Prix at aei.mpg.de
Thu Dec 4 15:12:30 CET 2003
Hi,
this is just an announcement that there are now some new
config-file reading routines available in Lorene. These allow you to
write somewhat more flexible config-files with a "variable = value"
type syntax. Everything else is ignored as comments. The only
restriction for variable-assignments is that they have to occur at the
beginning (modulo whitespace) of a line. I think the full syntax is
best explained in an example:
--------------------------------------------------
// this is a comment
var1=10.9 // ok
var2 = hi # this is ok too, whitespace is ignored
# var3 = nix // this would be considered a comment
// you can also write:
var4 : 1 // ok
# or even just
var5 99.9 // ok
--------------------------------------------------
Note that the above lines would constitute a valid config-file as they
are, defining the variables var1,var2, var4 and var5.
Note also that the comment-syntax is basically free, so you can use
whatever comment-marker you like (including none(!), but best use some
non-alphanumeric character!)
To read this, e.g. the file "settings.par", you can either use the
general-purpose function:
read_variable ("settings.par", "var1", "%f", &some_float);
where the format-string "%f" corresponds to sscanf(),
or you can use a type-specific overloaded function, like this:
read_variable ("settings.par", "var1", some_float);
Note that the file "settings.par" is buffered in the first call and
will not be re-read from disk in subsequent calls if either the same
filename or NULL is passed as an argument.
read_variable (NULL, "var4", some_bool);
read_variable (NULL, "var5", some_double);
Return is 0 if OK, -1 on error.
These routines are not heavily tested yet, but they seem to work fine
as far as I've used them in sfstar.C.
Please let me know if there are any problems/suggestions.
Cheers,
Reinhard.
--
-----------------------------------------------------
MPI fuer Gravitationsphysik |
Albert-Einstein Institut |
Am Muehlenberg | Tel: +49(0)331 567 7128
14476 Golm b. Potsdam | Fax: +49(0)331 567 7298
Germany |
-----------------------------------------------------
More information about the Lorene.list
mailing list