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...
more, I have to really do this casting?
Thanks.
--
-------------
Ing. Massimiliano Cannata
Istituto di Scienze della Terra - SUPSI
C.P. 72 - CH-6952 Canobbio (Ticino, Switzerland)
Tel +41 91 /935 12 25 - Fax +41 91 /935 12 09
eMail: massimiliano.cannata@ist.supsi.ch
Internet: http://www.ist.supsi.ch
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.
--
Glynn Clements <glynn.clements@virgin.net>
Glynn Clements wrote:
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.
–
Glynn Clements glynn.clements@virgin.net
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???
Thanks a lot.
Max
—r.example----
switch (data_type)
case CELL_TYPE:
c = ((CELL *) inrast)[col];
c = c_calc(c); /* calculate /
((CELL *) outrast)[col] = c;
break;
case FCELL_TYPE:
f = ((FCELL *) inrast)[col];
f = f_calc(f); / calculate /
((FCELL *) outrast)[col] = f;
break;
case DCELL_TYPE:
d = ((DCELL *) inrast)[col];
d = d_calc(d); / calculate */
((DCELL *) outrast)[col] = d;
break;
}
–
Ing. Massimiliano Cannata
Istituto di Scienze della Terra - SUPSI
C.P. 72 - CH-6952 Canobbio (Ticino, Switzerland)
Tel +41 91 /935 12 25 - Fax +41 91 /935 12 09
eMail: massimiliano.cannata@ist.supsi.ch
Internet: http://www.ist.supsi.ch
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@virgin.net>