[GRASS-dev] MASK_OVERRIDE

Glynn Clements glynn at gclements.plus.com
Wed Feb 20 21:55:25 EST 2008


Ivan Shmakov wrote:

>  >>> build output already. Also, NULL/non-NULL pointers are
>  >>> conventionally as much of a logic value as zero/non-zero integers.
> 
>  >> ... The thing I cannot get used in C...
> 
>  > What thing? That C doesn't have a distinct boolean type?
> 
> 	That C allows a pointer anywhere an integer is allowed.
> 
> 	I always read an `anytype *' variable as a ``reference to
> 	object'', or even simply ``object''.  It thus somewhat strange
> 	to read ``if reference, then...''

In many contexts, using a pointer where an integer is expected will
produce at least a warning (e.g. performing multiplication on a
pointer). Using a pointer as the test of an if, while or for statement
is safe as it only cares about zero or non-zero.

Technically:

       [#21]  Integer  and  floating  types are collectively called
       arithmetic types. Arithmetic types  and  pointer  types  are
       collectively  called scalar types. Array and structure types
       are collectively called aggregate types.32)

The "controlling expression" of an if, while or for statement must
have scalar type (i.e. integer, floating or pointer type), as must the
operands to the &&, || and ! operators and the first operand of the ?:
operator.

>  >> The code doesn't ever fall back to `MASK' if `MASK_OVERRIDE' is
>  >> defined.  If `MASK_OVERRIDE' doesn't point to a valid raster (e. g.,
>  >> if it's an empty string), the mask is ignored.
> 
>  > Okay; I misread the part where it was saving the mapset.
> 
>  > AFAICT, it shouldn't be necessary to handle the mapset
>  > explicitly. The lower level functions should all accept a qualified
>  > name, i.e.:
> 
>  > G__open_cell_old("mask at mapset", "")
> 
>  > So you should be able to simply test for existence with
>  > G_find_cell2(), and store the (possibly qualified) name.
> 
> 	I've tried to trace the calls made by the functions I've
> 	modified, but haven't found enough evidence that this usage
> 	pattern is allowed.  Could you please confirm that every
> 	function to be called with the `MASK_OVERRIDE's value in the
> 	modified code can be used this way?

Some time ago, I went through libgis and changed everything I could
find to accept qualified names. Most functions just pass the name and
mapset arguments down the chain until they get to G__open() or
G__file_name(), which definitely accept qualified names.

It's conceivable that I could have missed some function in the middle
which internally depends upon a name being unqualified. But if core
functions such as G_get_cellhd() or G__open_cell_old() didn't handle
it, I think that we would have noticed by now.

>  > The only code which really needs to split a qualified name is in low
>  > level functions which actually open files, plus anything which
>  > creates a derived name (i.e. foo at bar -> foo.tmp at bar not foo at bar.tmp).
> 
> 	What are the functions to:
> 
> 	* for any valid (possibly qualified) reference for an object
> 	  (raster, vector, etc.) existing in one of the mapsets
> 	  comprising the mapset search path, return a corresponding
> 	  qualified object name;

I don't think such a function exists at present. It would be easy
enough to add if there was any use for it; it's just a combination of
G_find_{cell,vector,<etc>} and G_fully_qualified_name().

> 	* like the above, but returning the name and the mapset
> 	  separately?

G_find_{cell,vector,<etc>}.

> 	Since the code of both the functions I've modified looks
> 	painfully similar, may I ask for a function to return the
> 	(qualified?) name of the (existing?) mask?  Which file should I
> 	put it in?
> 
> 	(There're some modules which could use this function as well.)

I would say find_file.c for a generic version, with type-specific
versions in find_cell.c and find_vect.c. The functions in nme_in_mps.c
are related, but they only do string operations, not I/O.

>  >> However, I doubt if it's a reasonable behaviour.  It seems to be
>  >> usual in the Unix world to ignore the environment variable's value
>  >> if it's an empty string.  Using a non-existing raster (say, `.') is
>  >> probably a better idea.
> 
>  > Good point. It's a nuisance for a shell script to distinguish between
>  > a variable being unset and being set to the empty string. We should
>  > really choose a specific "none" value rather than just silently
>  > ignoring a reference to a non-existent map. If $MASK_OVERRIDE is set
>  > but the map doesn't exist, it should at least produce a warning.
> 
> 	For now I'm considering using any name starting with `.' to
> 	specify ``none''.  The documentation should probably state that
> 	`MASK_OVERRIDE=.' is the preferred way to off the mask.
> 
> 	Unless there're other suggestions, I'd code it to check for
> 	`name[0] == '.'' and return early with a ``no mask found''
> 	condition.

Agreed.

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


More information about the grass-dev mailing list