[GRASS5] raster category confusion

Markus Neteler neteler at itc.it
Thu Sep 1 10:06:33 EDT 2005


On Thu, Sep 01, 2005 at 01:21:24PM +0100, Glynn Clements wrote:
> 
> Markus Neteler wrote:
> 
> > > Forget about r.cats (and categories in general). This:
> > > 
> > > > r.stats -1 one
> > > > 120
> > > > 156
> > > > 99
> > > > 100
> > > > 120
> > > > 156
> > > > 99
> > > > 100
> > > 
> > > is a lot more interesting (and relevant).
> > 
> > OK:
> > 
> > in r.stats:
> > 
> > main.c 
> >  G_get_range_min_max (&range, &min, &max);
> >  min =1
> >  max =1
> > 
> > ok so far.
> > raw_stats (fd, verbose, with_coordinates, with_xy, with_labels);
> >            fd     0           0               0          0
> > 
> > Entering raw_stats():
> > raw_stats.c:49
> >  rastp[i] = rast[i];
> >  i=0
> >  rastp[0]= void
> > 
> >  raw_stats.c:98, when i is 0, then
> > *((CELL *) rastp[i]) is 120.
> > 
> > Then it prints 120 and so forth.
> > 
> > Should I add some G_debug() in raw_stats?
> 
> I'd start by examining the pointers rastp[0] and rast[0], and the
> contents of the buffer to which they point, before entering the
> "for (col = ..." loop. I.e.:
> 
> 	print rast[0]
> 	print rastp[0]
> 	print *(CELL*)(rast[0])@50

The @ is dislike (not sure what it does). This is what I get:

GRASS 6.1.cvs (spearfish60):~/grass61/raster/r.stats > cvs diff raw_stats.c
Index: raw_stats.c
===================================================================
RCS file: /grassrepository/grass6/raster/r.stats/raw_stats.c,v
retrieving revision 2.1
diff -u -r2.1 raw_stats.c
--- raw_stats.c 13 Jul 2005 15:55:40 -0000      2.1
+++ raw_stats.c 1 Sep 2005 13:10:08 -0000
@@ -52,6 +52,11 @@
        if (with_coordinates)
            G_format_northing (G_row_to_northing(row+.5, &window), nbuf, -1);

+
+       G_debug(0, "rast[%d]: %d", rast[i], i);
+       G_debug(0, "rastp[%d]: %d", rastp[i], i);
+       G_debug(0, "*(CELL*)(rast[0]): %d", *(CELL*)(rast[0]));
+       G_debug(0, "*(CELL*)(rast[%d]): %d", *(CELL*)(rast[i]));
        for (col = 0; col < ncols; col++)
        {
            if (no_nulls || no_nulls_all)
GRASS 6.1.cvs (spearfish60):~/grass61/raster/r.stats > r.stats -1 one
D0/0: rast[0]: 1
D0/0: rastp[0]: 1
D0/0: *(CELL*)(rast[0]): 120
Segmentation fault

Apparently the last G_debug does not make sense, but the mysterious (?) 120
is there.

BTW:
 gcc version 3.4.3 20050227 (Red Hat 3.4.3-22.1)

I just see that the damn optimization creeped in again.

When I do

CFLAGS="-g -Wall" ./configure ...
checking host system type... i686-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler (gcc -g -Wall ) works... yes
checking whether the C compiler (gcc -g -Wall ) is a cross-compiler... no
...
 C compiler:                  gcc -g -Wall
 C++ compiler:                c++ -g -O2
...

But:
grep CFLAGS_OPTIMIZE ~/grass61/include/Make/Platform.make
CFLAGS_OPTIMIZE     = -O2

I have to manually fix that. Seems to be evil in aclocal.m4
around line 756:

        Linux*)
            SHLIB_CFLAGS="-fPIC"
            SHLIB_LD_LIBS='${LIBS}'
            SHLIB_SUFFIX=".so"

            CFLAGS_OPTIMIZE=-O2
            # egcs-2.91.66 on Redhat Linux 6.0 generates lots of warnings
            # when you inline the string and math operations.  Turn this off to
            # get rid of the warnings.
            #CFLAGS_OPTIMIZE="${CFLAGS_OPTIMIZE} -D__NO_STRING_INLINES -D__NO_MATH_INLINES"
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


The r.stats debug result remains however the same.

Markus




More information about the grass-dev mailing list