[GRASS5] r.contour crashes if step=0.5

Markus Neteler neteler at geog.uni-hannover.de
Sat Jan 27 08:26:25 EST 2001


Roger,

On Sat, Jan 27, 2001 at 01:38:02PM +0100, Roger Bivand wrote:
> On Sat, 27 Jan 2001, Markus Neteler wrote:
> > On Sat, Jan 27, 2001 at 12:48:44PM +0100, Roger Bivand wrote:
> > > On Sat, 27 Jan 2001, Markus Neteler wrote:
> > > 
> > > > Hi developers,
> > > > 
> > > > r.contour crashes if step=0.5... Floating point exception.
> > > > I actually cannot see the problem. The offending line is a macro:
> > > > 
> > > >   dmax = (max->answer) ? atof (max->answer) : zmax - (int)zmax%(int)dstep;
> > > > 
> > > > dstep contains 0.5, zmax is determined my the program zmax=7.1231 here).
> > > 
> > > It's the (int) cast on dstep, which becomes integer 0, and which gives a
> > > NaN when used for division. For this code to work, dstep must be >= 1. It
> > > looks a bit cludgy too.
> > 
> > I see. But in my case I have a map with pH values ranging from 5.5 to
> > 7.3. So setting "step" to 1 doesn't produce exciting contours.
> > Even step is a double. Se we might need to change this line (and the next
> > in main.c of r.contours)?
> 
> Sorry to "fake" this in R, but it's the integer casts that cause the
> problem:
> 
> > dstep <- 0.5
> > max <- NULL
> > min <- NULL
> > zmax <- 7.3
> > zmin <- 5.5
> > zmax %% dstep
> [1] 0.3
> > zmin %% dstep
> [1] 0
> > dmax <- ifelse(!is.null(max), as.numeric(max),
>  zmax - (as.integer(zmax) %% as.integer(dstep)))
> > dmax
> [1] NA
> > dmax <- ifelse(!is.null(max), as.numeric(max),
>  zmax - (zmax %% dstep))
> > dmax
> [1] 7
> > dmin <- ifelse(!is.null(min), as.numeric(min),
>  ifelse(as.integer(zmin) %% as.integer(dstep),
>  zmin - (as.integer(zmin) %% as.integer(dstep)), zmin))
> > dmin
> [1] NA
> > dmin <- ifelse(!is.null(min), as.numeric(min),
>  ifelse(zmin %% dstep, zmin - (zmin %% dstep), zmin))
> > dmin
> [1] 5.5
> 
> If you set max and min for your contours, you wouldn't hit the bug, nor if
> you set the levels manually. Whether removing the casts is OK later on is
> another question, but it looks as though there are no more (int) casts,
> so I'd take out the casts in the assignments to dmax and dmin.

It seems that C behaves differently than "R".
The compiler doesn't accept modulo with doubles:

gcc -g -O2   -I/home/neteler/ggg/src/include  -c main.c -o
OBJ.i686-pc-linux-gnu/main.o
main.c: In function 'getlevels':
main.c:233: invalid operands to binary %
main.c:234: invalid operands to binary %
main.c:235: invalid operands to binary %

You are right, if I add max= and min= the problem of course disappears.
Maybe we can get rid of this macro? To be honest, I just don't get
the idea of it. Do we need it (like that)?

Thanks for looking into this,

 Markus

---------------------------------------- 
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo at geog.uni-hannover.de with
subject 'unsubscribe grass5'



More information about the grass-dev mailing list