[GRASS5] Re: [GRASS_DE] r.mapcalc round()

Glynn Clements glynn.clements at virgin.net
Fri Jun 1 18:06:39 EDT 2001


Roger Bivand wrote:

> where the underlying C code has to take care of machine dependencies as
> well as retaining default values for the number of digits to round to, and
> the number of significant digits to retain. The resulting returned values
> are then handed off to formatting code. One reason for the difficulties is
> that different users may need very different precisions for different
> purposes, and this would in our case add to the arguments taken by
> programs outputting FCELL and DCELL as text.

Yep; so what should the syntax of these arguments be?

The simplest option (to implement) would be to allow a literal format
string to be specified, e.g. "fmt=%.6g". But that isn't necessarily
the best option for users.

One issue is that it might be desirable to allow a default format to
be set, e.g. via an environment variable. Ideally this would be able
to specify different formats depending upon whether the data was FCELL
or DCELL (assuming that the program knows; it can't know if DCELL data
is "real" DCELL data or FCELL data which has been "promoted" to
DCELL).

If the format specification is in the form of a printf() format
string, the only form of override would be complete replacement. A
more structured mechanism would allow e.g. the number of significant
figures to be changed while retaining the default style (e/f/g).

Overriding becomes important in cases where the output must conform to
certain constraints; e.g. v.out.foo where the "foo" format doesn't
support exponential form. The program would have to use some variation
on "%f", but the user could still choose the number of digits.

Thinking about this a bit, there are quite a few different ways to
specify the precision, including (but probably not limited to):

	Number of decimal places
	Number of significant figures
	Relative error
	Absolute error

Suppression or inclusion of leading and/or trailing zeroes may also be
an issue.

One parameter that cannot be controlled if you use printf() is the
number of digits used for the exponent. ANSI C dictates 2 digits
unless 3 are required, with a "+" for positive exponents
(incidentally, Microsoft's runtime always uses 3 digits).

-- 
Glynn Clements <glynn.clements at virgin.net>



More information about the grass-dev mailing list