[GRASSLIST:899] Re: CELL, FCELL, DCELL type...

Glynn Clements glynn.clements at virgin.net
Mon Aug 4 06:51:01 EDT 2003


Massimiliano Cannata wrote:

> > > I'm trying write a code that use a raster to make
> > > calulation....
> > > so I get the raster cell value (CELL, FCELL, DCELL
> > > depending on the original map) and then i have to
> > > use the math.h function
> > >
> > > double pow(double,double)
> > >
> > > so, how do I have to cast CELL, FCELL or DCELL to
> > > double?
> > > It seems that
> > >
> > > double x;
> > > x = (double) CELL
> > >
> > > doesn't work...
> >
> > It should work.
> >
> > > more, I have to really do this casting?
> >
> > ANSI C will automatically cast numeric function arguments to the
> > appropriate type, so you can just pass CELL values to pow() directly.
> 
> So if it is able an automatic cast...
> i don't really need to develop 3 version of my calculus module as in the
> "r.example" for the switch type....
> i can just make one, doing someting like:
> 
> double mycalculus(double x)
> 
> and than pass CELL, DCELL or FCELL as argument?????

If the operations are going to cast the cell values to a double, you
should just read the maps as DCELL (i.e. use G_get_d_raster_row());
GRASS will convert CELL and FCELL maps automatically.

The main reason for reading maps using their "native" format (i.e. 
reading CELL as CELL etc) is when you need to preserve the format of
the data, e.g. so that operations on integer maps are exact (i.e. no
rounding error due to use of floating-point).

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




More information about the grass-user mailing list