[GRASSLIST:4319] mode()

hi!

I encountered something strange in mapcalc

when doing:

r.mapcalc
'map_neigh=if(map==0,mode(map[-1,-1],map[-1,0],map[-1,1],map[0,1],map[1,1],m
ap[1,0],map[1,-1],map[0,-1]),map)'

100%
Segmentation fault

and no result layer or crippled

any other mode() calculation is mostly the same
but e.g. median() works ok

my grass is cvs 5.3 (grass53_exp_2004_08_21) built from source on a Mandrake
9.2

what other way can I obtain the result I intend to in my r.mapcalc equation?

cheers!
Maciek

I would like to add more info that the error occures in a precompiled 5.03
too

however I invoke the mode() function in r.mapcalc the result is always a
"Segmentation fault" and no output cell file or rubbish instead

no matter what resolution or region size, with mask or without

could it be my fault somehow?

Maciek

From: "Maciek Sieczka" <werchowyna@pf.pl>
Sent: Tuesday, September 07, 2004 7:12 PM
Subject: [GRASSLIST:4319] mode()

hi!

I encountered something strange in mapcalc

when doing:

r.mapcalc

'map_neigh=if(map==0,mode(map[-1,-1],map[-1,0],map[-1,1],map[0,1],map[1,1],m

ap[1,0],map[1,-1],map[0,-1]),map)'

100%
Segmentation fault

and no result layer or crippled

any other mode() calculation is mostly the same
but e.g. median() works ok

my grass is cvs 5.3 (grass53_exp_2004_08_21) built from source on a
Mandrake 9.2

what other way can I obtain the result I intend to in my r.mapcalc
equation?

cheers!
Maciek

Hi All!

Still no any answer so let me bug you a little more. I was thinking of
putting a bug report on this issue but first of all I don't know how to
describe it because it's weird and secondly COULD ANYBODY CHECK IF YOU CAN
REPRODUCE THE ERROR so I could make sure if I'm not a separated case? It's
hard for me to believe that such a nasty bug would survive in r.mapcalc and
I'm ready to be convinced that it's all my fault somehow.

In a given region:

projection: 0 (x,y)
zone: 0
north: 100
south: 0
west: 0
east: 100
nsres: 1
ewres: 1
rows: 100
cols: 100

I'm having adventures like this:

GRASS:~ > r.mapcalc 'map_mod=mode(2)'
100%

GRASS:~ > r.mapcalc 'map_mod=mode(2,2)'
100%
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=mode(2,2,2)'
100%

GRASS:~ > r.mapcalc 'map_mod=mode(2,2,2,2)'
100%
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=mode(2,2,2,2,2)'
100%

GRASS:~ > r.mapcalc 'map_mod=mode(2,2,2,2,2,2)'
100%
mv: nie mo¿na wykonaæ stat na
`/home/gr/home/grorient/wewn/.tmp/localhost/1197.0': No such file or
directory
ERROR: closecell: can't move
/home/gr/home/grorient/wewn/.tmp/localhost/1197.0
to cell file /home/grassdata/orient/wewn/cell/map_mod

GRASS:~ > r.mapcalc 'map_mod=mode(2,2,2,2,2,2,2)'
100%
mv: nie mo¿na wykonaæ stat na
`/home/grorient/worient/wewn/.tmp/localhost/1201.0': No such file or
directory
ERROR: closecell: can't move
/home/grorient/worient/wewn/.tmp/localhost/1201.0
to cell file /home/grassdata/orient/wewn/cell/map_mod

GRASS:~ > r.mapcalc 'map_mod=mode(2,2,2,2,2,2,2,2)'
100%

where "mv: nie mo¿na wykonaæ stat na" means "mv: cannot execute stat on"

beautifull, isn't it?

or take a look at this:

GRASS:~ > r.mapcalc 'map_mod=mode(1,2,3,4)'
100%

GRASS:~ > r.mapcalc 'map_mod=mode(1,2,3)'
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=mode(1,2)'
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=mode(1)'
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=median(1)'
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=median(1,2)'
Segmentation fault

or this one:

GRASS:~ > r.mapcalc 'map_mod=mode(5,5)'
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=mode(5,5,5)'
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=mode(5,5,5,5)'
100%

GRASS:~ > r.mapcalc 'map_mod=mode(5,5,5,5,5)'
100%

GRASS:~ > r.mapcalc 'map_mod=mode(5,5,5,5,5,5)'
100%
Segmentation fault

These listings come from a cvs Grass 5.3 (grass53_exp_2004_08_21) built from
source on a Mandrake 9.2 but I've had this fun in a precompiled 5.03 too.

Looking forward to any reply.

Maciek

Developers!

Any answer please. Was it solved? Am I the only one having this? Else?

Maciek

----- Original Message -----
From: "Maciek Sieczka" <werchowyna@pf.pl>
To: <grasslist@baylor.edu>
Sent: Friday, September 24, 2004 6:48 PM
Subject: [GRASSLIST:4413] Re: mode()

Hi All!

Still no any answer so let me bug you a little more. I was thinking of
putting a bug report on this issue but first of all I don't know how to
describe it because it's weird and secondly COULD ANYBODY CHECK IF YOU CAN
REPRODUCE THE ERROR so I could make sure if I'm not a separated case? It's
hard for me to believe that such a nasty bug would survive in r.mapcalc

and

I'm ready to be convinced that it's all my fault somehow.

In a given region:

projection: 0 (x,y)
zone: 0
north: 100
south: 0
west: 0
east: 100
nsres: 1
ewres: 1
rows: 100
cols: 100

I'm having adventures like this:

GRASS:~ > r.mapcalc 'map_mod=mode(2)'
100%

GRASS:~ > r.mapcalc 'map_mod=mode(2,2)'
100%
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=mode(2,2,2)'
100%

GRASS:~ > r.mapcalc 'map_mod=mode(2,2,2,2)'
100%
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=mode(2,2,2,2,2)'
100%

GRASS:~ > r.mapcalc 'map_mod=mode(2,2,2,2,2,2)'
100%
mv: nie mo¿na wykonaæ stat na
`/home/gr/home/grorient/wewn/.tmp/localhost/1197.0': No such file or
directory
ERROR: closecell: can't move
/home/gr/home/grorient/wewn/.tmp/localhost/1197.0
to cell file /home/grassdata/orient/wewn/cell/map_mod

GRASS:~ > r.mapcalc 'map_mod=mode(2,2,2,2,2,2,2)'
100%
mv: nie mo¿na wykonaæ stat na
`/home/grorient/worient/wewn/.tmp/localhost/1201.0': No such file or
directory
ERROR: closecell: can't move
/home/grorient/worient/wewn/.tmp/localhost/1201.0
to cell file /home/grassdata/orient/wewn/cell/map_mod

GRASS:~ > r.mapcalc 'map_mod=mode(2,2,2,2,2,2,2,2)'
100%

where "mv: nie mo¿na wykonaæ stat na" means "mv: cannot execute stat on"

beautifull, isn't it?

or take a look at this:

GRASS:~ > r.mapcalc 'map_mod=mode(1,2,3,4)'
100%

GRASS:~ > r.mapcalc 'map_mod=mode(1,2,3)'
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=mode(1,2)'
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=mode(1)'
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=median(1)'
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=median(1,2)'
Segmentation fault

or this one:

GRASS:~ > r.mapcalc 'map_mod=mode(5,5)'
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=mode(5,5,5)'
Segmentation fault

GRASS:~ > r.mapcalc 'map_mod=mode(5,5,5,5)'
100%

GRASS:~ > r.mapcalc 'map_mod=mode(5,5,5,5,5)'
100%

GRASS:~ > r.mapcalc 'map_mod=mode(5,5,5,5,5,5)'
100%
Segmentation fault

These listings come from a cvs Grass 5.3 (grass53_exp_2004_08_21) built

from

source on a Mandrake 9.2 but I've had this fun in a precompiled 5.03 too.

Looking forward to any reply.

Maciek

Maciek Sieczka wrote:

Still no any answer so let me bug you a little more. I was thinking of
putting a bug report on this issue but first of all I don't know how to
describe it because it's weird and secondly COULD ANYBODY CHECK IF YOU CAN
REPRODUCE THE ERROR so I could make sure if I'm not a separated case? It's
hard for me to believe that such a nasty bug would survive in r.mapcalc and
I'm ready to be convinced that it's all my fault somehow.

Both the mode and median functions are similarly broken.

For f_mode (in xmode.c), the expression:

  value[i] = (double) argv[j][i];

should be:

  value[j] = (double) argv[j][i];

Similarly, for f_median (in xmedian.c), the expression:

  a[i] = argv[j][i];

should be:

  a[j] = argv[j][i];

I'll commit a fix to CVS shortly.

BTW, it isn't that unlikely that such a bug would survive. There have
been more significant bugs which have existed for longer.

E.g. floating-point rasters which crossed the 180-degree meridian
didn't work (at all) from the point that floating-point rasters were
added up until a couple of weeks ago.

The size of the GRASS code base is on the same scale as XFree86 or the
Linux kernel, but we probably only have a thousandth as many users as
either of those. The end result is there is a significant amount of
code which has either never been executed, or has only been executed a
few times.

--
Glynn Clements <glynn.clements@virgin.net>