[GRASS-dev] help porting GRASS-RaPlaT to GRASS7

Hi,

I have started tinkering around with porting some radio propagation tools
(http://commsys.ijs.si/en/software/grass-raplat) to GRASS 7... However, I have
run into a wall. Is there any documentation on the general approach for
porting code from GRASS6 -> GRASS7 ? I have tried following along the source
code in modules such as r.flow and r.slope.aspect... however my futile attempt
has resulted in a segfault. The tail end of which looks like:

------------------------------------------------------------------------------------------------------------------
open("/home/dylan/grass/ca630/PERMANENT/cellhd/elev30", O_RDONLY|O_LARGEFILE)
= 3
fcntl64(3, F_GETFL) = 0x8000 (flags O_RDONLY|O_LARGEFILE)
fstat64(3, {st_mode=S_IFREG|0644, st_size=200, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0xb76f5000
_llseek(3, 0, [0], SEEK_CUR) = 0
_llseek(3, 0, [0], SEEK_SET) = 0
read(3, "proj: 1\nzone: 10\nnor"..., 4096) = 200
read(3, "", 4096) = 0
_llseek(3, 0, [0], SEEK_SET) = 0
read(3, "proj: 1\nzone: 10\nnor"..., 4096) = 200
read(3, "", 4096) = 0
close(3) = 0
munmap(0xb76f5000, 4096) = 0
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
------------------------------------------------------------------------------------------------------------------

Any tips? The code in question is very clean and well documented... leading me
to believe (erroneously?) that I may be up to the task. I have contacted the
author of the code, but have not heard back yet. I suppose that I could
continue to use this code with GRASS6... However, I was just starting to get
used to all of the new features + better performance in GRASS7.

Cheers,
Dylan

--
Dylan E. Beaudette
USDA-NRCS Soil Scientist
California Soil Resource Lab
http://casoilresource.lawr.ucdavis.edu/

Dylan Beaudette wrote:

however my futile attempt has resulted in a segfault. The tail end
of which looks like:

Any tips?

Compile with debug info and without optimisation:

  make clean
  make CFLAGS=-g &> build.log

Pay attention to any warnings which are generated.

Run the program under gdb; when it segfaults, you can view the call
stack with "bt" (or "bt full" to see arguments). The top-most entry
will be the source line where the segfault occurred.

--
Glynn Clements <glynn@gclements.plus.com>

On Friday, November 04, 2011, Glynn Clements wrote:

Dylan Beaudette wrote:

> however my futile attempt has resulted in a segfault. The tail end
> of which looks like:

> Any tips?

Compile with debug info and without optimisation:

  make clean
  make CFLAGS=-g &> build.log

Pay attention to any warnings which are generated.

Run the program under gdb; when it segfaults, you can view the call
stack with "bt" (or "bt full" to see arguments). The top-most entry
will be the source line where the segfault occurred.

Thanks Gylnn,

Here is what I get:

Starting program: /usr/local/grass-7.0.svn/bin/r.fspl in=elev30 out=fspl30
coordinate=695224,4232900 ant_height=10 frequency=445
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0xb7f44be8 in G_name_is_fully_qualified (fullname=0x0, name=0xbfffdd90 "",
mapset=0xbfffdc90 "") at nme_in_mps.c:45
45 for (p = fullname; *p; p++)

#0 0xb7f44be8 in G_name_is_fully_qualified (fullname=0x0, name=0xbfffdd90 "",
mapset=0xbfffdc90 "") at nme_in_mps.c:45
#1 0xb7f44dab in G__open (element=0xb7f88330 "cellhd", name=0x0,
mapset=0x804c228 "PERMANENT", mode=0) at open.c:60
#2 0xb7f450e4 in G_fopen_old (element=0xb7f88330 "cellhd", name=0x0,
mapset=0x804c228 "PERMANENT") at open.c:230
#3 0xb7f8449e in fopen_cellhd_old (name=0x0, mapset=0x804c228 "PERMANENT") at
reclass.c:250
#4 0xb7f83e50 in Rast_is_reclass (name=0x0, mapset=0x804c228 "PERMANENT",
    rname=0xbffff048
"\342\303\376\267\364\360\377\277p\204\004\b\350\360\377\277d\372\377\267",
rmapset=0xbfffef48 "-")
    at reclass.c:49
#5 0xb7f799db in Rast_get_cellhd (name=0x0, mapset=0x804c228 "PERMANENT",
cellhd=0xbffff198) at get_cellhd.c:62
#6 0x08049203 in main (argc=6, argv=0xbffff434) at main.c:205

--
Dylan E. Beaudette
USDA-NRCS Soil Scientist
California Soil Resource Lab
http://casoilresource.lawr.ucdavis.edu/

Dylan Beaudette wrote:

Here is what I get:

#5 0xb7f799db in Rast_get_cellhd (name=0x0, mapset=0x804c228 "PERMANENT", cellhd=0xbffff198) at get_cellhd.c:62

name=0x0 means that the first argument to Rast_get_cellhd() (i.e. the
map name) is a null pointer.

I suspect that this is because the LOS_map= option wasn't specified.
Although this option is marked as "required = NO", the code assumes
that it will be set (and generates a fatal error if the specified map
cannot be found).

I would expect similar behaviour with the original, unmodified code.

[Also, note that 7.0 doesn't allow the use of upper-case letters in
option names. Specifically, it won't recognise a name=value argument
as an option if the name part contains upper-case letters.]

If an option is always required, the ->required field in the option
structure should be set to YES (this is done automatically for
G_define_standard_option(G_OPT_R_INPUT)).

If an option isn't required, either it should have a default value
(i.e. the ->answer field should be set when defining the option) or
the code should explicitly check whether ->answer is null before
attempting to use its value.

--
Glynn Clements <glynn@gclements.plus.com>