[GRASS5] r.contour crashes if step=0.5
Markus Neteler
neteler at geog.uni-hannover.de
Sat Jan 27 10:09:46 EST 2001
Roger,
great!
On Sat, Jan 27, 2001 at 02:26:32PM +0100, Roger Bivand wrote:
> On Sat, 27 Jan 2001, Markus Neteler wrote:
> > 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:
> > > > > >
> > > > > > 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).
> > > > >
[...]
> 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]
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]
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.
It's in CVS now.
Thanks Roger, many users like will me enjoy this fix.
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