[GRASS5] r.contour crashes if step=0.5

Roger Bivand rsb at reclus.nhh.no
Sat Jan 27 10:30:32 EST 2001


On Sat, 27 Jan 2001, Markus Neteler wrote:

> Roger,
> 
> great!
> 
> On Sat, Jan 27, 2001 at 02:26:32PM +0100, Roger Bivand wrote:
> [ .... ]
> 
> > I think we need the fmod(x,y) function (K&R2: floating point remainder of
> > x/y, same sign as x; y=0 needs to be trapped, p. 251 in my edition). So:
> > 
> > dmax = (max->answer) ? atof (max->answer) : zmax - (int)zmax%(int)dstep;
> > 
> > could be
> > 
> > dmax = (max->answer) ? atof (max->answer) : dstep == 0 ?
> >         G_error(***) : zmax - fmod(zmax, dstep);
> > 
> > though I haven't tried it. 
> 
> I have rewritten the other macro accordingly:
> Old:
> dmin = (min->answer) ? atof (min->answer) : (int)zmin%(int)dstep?
>                               zmin - (int)zmin%(int)dstep +dstep: zmin;
> 
> New:
> dmin = (min->answer) ? atof (min->answer) : dstep == 0 ?
>                    G_fatal_error("This step value is not allowed.") :
>                    fmod(zmin,dstep) ? zmin - fmod(zmin,dstep) +dstep: zmin; 
> 
> And it seems to produce reasonable results:
> 
> Old macro with fp-exception if min/max not specified:
> r.contour in=ph_upper out=ph_upper step=0.1 min=5.64 max=7.19
> Reading data.
> Percent complete:  100%
> FPRange of data:    min =  5.647517 max = 7.195973
> Minimum level will be 5.740000
> Maximum level will be 7.190000
> Continue?(y/n) [y]
> 
> New version:
> New:
> r.contour in=ph_upper out=ph_upper step=0.1
> Reading data.
> Percent complete:  100%
> FPRange of data:    min =  5.647517 max = 7.195973
> Minimum level will be 5.700000
> Maximum level will be 7.100000
> Continue?(y/n) [y] 

OK!

> 
> New:
> r.contour in=ph_upper out=ph_upper step=0.1 min=5.64 max=7.19
> Reading data.
> Percent complete:  100%
> FPRange of data:    min =  5.647517 max = 7.195973
> Minimum level will be 5.740000
> Maximum level will be 7.190000
> Continue?(y/n) [y] 

Also OK!

> 
> r.contour in=ph_upper out=ph_upper step=0.1 min=5.647 max=7.196
> Reading data.
> Percent complete:  100%
> FPRange of data:    min =  5.647517 max = 7.195973
> Minimum level will be 5.747000
> Maximum level will be 7.096000
> Continue?(y/n) [y] 
> Total levels:   15   Current level:        
> Finished.
> 

This is a bit odd, though. It's being post-processed by the subsequent
code to bring the max & min within the FPRange - ideally, the levels
should be "pretty" numbers, say for a 0.1 step breaking on 0.1, 0.2, ...,
or 0.15, 0.25, .... But that's what's in the code ...

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