[GRASS5] r.contour crashes if step=0.5

Roger Bivand rsb at reclus.nhh.no
Sat Jan 27 07:38:02 EST 2001


On Sat, 27 Jan 2001, Markus Neteler wrote:

> Roger,
> 
> [cc to grass5]
> 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.

Roger

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no
and: Department of Geography and Regional Development, University of
Gdansk, al. Mar. J. Pilsudskiego 46, PL-81 378 Gdynia, Poland.


---------------------------------------- 
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