[GRASS-dev] more interesting failure for reading fp_range of a NULL map

Glynn Clements glynn at gclements.plus.com
Thu Mar 7 13:11:13 PST 2013


Yann Chemin wrote:

> That is a module level way, i was wondering about a C function like the one
> below:
> 
> /*A fatal error when NULL map*/
> if(Rast_is_null_map(mapname, mapset)<0){
>    G_fatal("Input file has only null values");
> } else {
>   /* do some useful thing */
> }

1. In general, there's nothing erroneous about an all-null input map. 
Most modules should treat such a map the same as any other map.

2. Whether or not a map contains any non-null cells is usually
irrelevant. What matters is whether there are any non-null cells
within the current region (and after any mask has been applied). And
this can't be determined without actually reading the map.

So given that the map has to be read anyhow, the module should simply
operate normally, keeping track of whether any non-null values have
been read so that any final calculation doesn't make assumptions about
e.g. the count of non-null cells being non-zero, having a valid
minimum and maximum, etc.

If, for a specific module, all-null inputs are common, it might be
worth checking whether the range has null minimum and/or maximum
(they'll be either both null or both non-null) as an optimisation. But
I would expect this to be the exception rather than the rule.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list