[GRASS-dev] should G_raster_map_type() use G_find_cell2() ?

G_raster_map_type() calls G_find_cell(), which chops off the
@othermapset part of a map's name.

should it call G_find_cell2(), which leaves the map name alone?

("r.terraflow elev=map@othermapset" doesn't work)

thanks,
Hamish

Hamish wrote:

G_raster_map_type() calls G_find_cell(), which chops off the
@othermapset part of a map's name.

should it call G_find_cell2(), which leaves the map name alone?

Maybe, but you would need to examine everything which uses
G_raster_map_type() (71 files) in case something expects this
behaviour.

The quick solution is to pass the name/mapset returned from
G_find_file() rather than the original qualified name.

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

Hamish wrote:

> G_raster_map_type() calls G_find_cell(), which chops off the
> @othermapset part of a map's name.
>
> should it call G_find_cell2(), which leaves the map name alone?

Glynn wrote:

Maybe, but you would need to examine everything which uses
G_raster_map_type() (71 files) in case something expects this
behaviour.

That sounds dangerous. I've added a new fn called G_raster_map_type2()
which checks the map type in a non-name modifying way. (akin to
G_find_cell2(), G_find_vector2(), G_find_file2(): these already exist
for the same reason)

The quick solution is to pass the name/mapset returned from
G_find_file() rather than the original qualified name.

map existence and type are checked in two separate functions; *mapset
is never returned to main(). The "@mapset" was getting clobbered in
both. Testing a copy of the string seems highly inefficient.
[r.terraflow]

Hamish

Hamish wrote:

> > G_raster_map_type() calls G_find_cell(), which chops off the
> > @othermapset part of a map's name.
> >
> > should it call G_find_cell2(), which leaves the map name alone?

Glynn wrote:
> Maybe, but you would need to examine everything which uses
> G_raster_map_type() (71 files) in case something expects this
> behaviour.

That sounds dangerous. I've added a new fn called G_raster_map_type2()
which checks the map type in a non-name modifying way. (akin to
G_find_cell2(), G_find_vector2(), G_find_file2(): these already exist
for the same reason)

I'm in the process of adding a version which uses the descriptor:

  RASTER_MAP_TYPE G_get_raster_map_type(int fd)
  {
      struct fileinfo *fcb = &G__.fileinfo[fd];
      return fcb->map_type;
  }

In the case where the map is already open, this would be preferable to
using the name/mapset.

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

Glynn Clements wrote:

I'm in the process of adding a version which uses the descriptor:

  RASTER_MAP_TYPE G_get_raster_map_type(int fd)
  {
      struct fileinfo *fcb = &G__.fileinfo[fd];
      return fcb->map_type;
  }

In the case where the map is already open, this would be preferable to
using the name/mapset.

I've added this function, and replaced the use of G_raster_map_type()
where practical. The number of files which use G_raster_map_type() is
down from 73 to 22 (6 of which are in r.le).

The remaining cases either don't open the map (e.g. modules which only
operate upon support files), or are structured in such a way that
getting at the descriptor is problematic.

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