[GRASS-dev] r.flow with barrier fails

Hi, r.flow fails, when used with barrin option:

r.flow elevin=elevation.dem barin=roads flout=streams
Reading input files: elevation
Reading input files: barrier
Segmentation fault

that is, because dsout option is not defined and read_input_files()
(io.c) tryes to store something in ds structure

when dsout option is defined, you get no reasonable result:

r.flow elevin=elevation.dem barin=roads flout=streams dsout=density
d.rast density

what to do?

thanks

jachym
--
Jachym Cepicky
e-mail: jachym.cepicky gmail com
URL: http://les-ejk.cz
GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub

Je-Báchym Èepický wrote:e-A

Hi, r.flow fails, when used with barrin option:

r.flow elevin=elevation.dem barin=roads flout=streams
Reading input files: elevation
Reading input files: barrier
Segmentation fault

that is, because dsout option is not defined and read_input_files()
(io.c) tryes to store something in ds structure

when dsout option is defined, you get no reasonable result:

r.flow elevin=elevation.dem barin=roads flout=streams dsout=density
d.rast density

what to do?

Probably this:

--- raster/r.flow/io.c 7 Feb 2007 05:24:40 -0000 1.14
+++ raster/r.flow/io.c 19 Feb 2007 18:18:41 -0000
@@ -126,7 +126,7 @@
       for (col = 0; col < region.cols; col++)
       {
     BM_set(bitbar, col, row, (barc[col] != 0));
- if (barc[col] != 0)
+ if (ds.buf && barc[col] != 0)
         put(ds, row, col, -1);
       }
   }

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

hi glynn,

2007/2/19, Glynn Clements <glynn@gclements.plus.com>:

>[...]
Probably this:

--- raster/r.flow/io.c 7 Feb 2007 05:24:40 -0000 1.14
+++ raster/r.flow/io.c 19 Feb 2007 18:18:41 -0000
@@ -126,7 +126,7 @@
            for (col = 0; col < region.cols; col++)
            {
                BM_set(bitbar, col, row, (barc[col] != 0));
- if (barc[col] != 0)
+ if (ds.buf && barc[col] != 0)
                    put(ds, row, col, -1);
            }
        }

This makes it not to segfault, but it does not make r.flow work properly

thanks

jachym
--
Jachym Cepicky
e-mail: jachym.cepicky gmail com
URL: http://les-ejk.cz
GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub

On Tue, 2007-02-20 at 08:53 +0100, Jáchym Čepický wrote:

hi glynn,

2007/2/19, Glynn Clements <glynn@gclements.plus.com>:
> >[...]
> Probably this:
>
> --- raster/r.flow/io.c 7 Feb 2007 05:24:40 -0000 1.14
> +++ raster/r.flow/io.c 19 Feb 2007 18:18:41 -0000
> @@ -126,7 +126,7 @@
> for (col = 0; col < region.cols; col++)
> {
> BM_set(bitbar, col, row, (barc[col] != 0));
> - if (barc[col] != 0)
> + if (ds.buf && barc[col] != 0)
> put(ds, row, col, -1);
> }
> }

This makes it not to segfault, but it does not make r.flow work properly

The problem is that it requires that the 'dsout' option be specified in
addition to the options you already provided. The memory buffer is not
allocated without it.

I'm not sure if that's a feature or a bug. If someone can guide me to
proper operation, I'll commit fix for it.

Here's a patch that "corrects" the problem (essentially, what Glynn
already posted), but I'm not sure if this is proper behavior. Ideally,
it should either A) error out or B) allocate the memory if 'barin' is
specified:

RCS file: /grassrepository/grass6/raster/r.flow/io.c,v
retrieving revision 1.14
diff -u -r1.14 io.c
--- io.c 7 Feb 2007 05:24:40 -0000 1.14
+++ io.c 20 Feb 2007 08:30:36 -0000
@@ -114,7 +114,7 @@
        G_close_cell(fd);
     }

- if (parm.barin)
+ if (parm.barin && parm.dsout)
     {
         G_message(_("Reading input files: barrier"));
        barc = G_allocate_d_raster_buf();
@@ -132,6 +132,8 @@
        }
        G_close_cell(fd);
     }
+
+ if (barc) G_free (barc);
}

--
Brad Douglas <rez touchofmadness com> KB8UYR/6
Address: 37.493,-121.924 / WGS84 National Map Corps #TNMC-3785

Guys,

I see the main problem, that the r.flow module _does not work
properly_ with barin option. I mean, the calculation is just wrong. If
barin is specified, density output file has only one value: -1.000000

jachym

2007/2/20, Brad Douglas <rez@touchofmadness.com>:

On Tue, 2007-02-20 at 08:53 +0100, Jáchym Èepický wrote:
> hi glynn,
>
> 2007/2/19, Glynn Clements <glynn@gclements.plus.com>:
> > >[...]
> > Probably this:
> >
> > --- raster/r.flow/io.c 7 Feb 2007 05:24:40 -0000 1.14
> > +++ raster/r.flow/io.c 19 Feb 2007 18:18:41 -0000
> > @@ -126,7 +126,7 @@
> > for (col = 0; col < region.cols; col++)
> > {
> > BM_set(bitbar, col, row, (barc[col] != 0));
> > - if (barc[col] != 0)
> > + if (ds.buf && barc[col] != 0)
> > put(ds, row, col, -1);
> > }
> > }
>
> This makes it not to segfault, but it does not make r.flow work properly

The problem is that it requires that the 'dsout' option be specified in
addition to the options you already provided. The memory buffer is not
allocated without it.

I'm not sure if that's a feature or a bug. If someone can guide me to
proper operation, I'll commit fix for it.

Here's a patch that "corrects" the problem (essentially, what Glynn
already posted), but I'm not sure if this is proper behavior. Ideally,
it should either A) error out or B) allocate the memory if 'barin' is
specified:

RCS file: /grassrepository/grass6/raster/r.flow/io.c,v
retrieving revision 1.14
diff -u -r1.14 io.c
--- io.c 7 Feb 2007 05:24:40 -0000 1.14
+++ io.c 20 Feb 2007 08:30:36 -0000
@@ -114,7 +114,7 @@
        G_close_cell(fd);
     }

- if (parm.barin)
+ if (parm.barin && parm.dsout)
     {
         G_message(_("Reading input files: barrier"));
        barc = G_allocate_d_raster_buf();
@@ -132,6 +132,8 @@
        }
        G_close_cell(fd);
     }
+
+ if (barc) G_free (barc);
}

--
Brad Douglas <rez touchofmadness com> KB8UYR/6
Address: 37.493,-121.924 / WGS84 National Map Corps #TNMC-3785

--
Jachym Cepicky
e-mail: jachym.cepicky gmail com
URL: http://les-ejk.cz
GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub

On Feb 20, 2007, at 3:36 AM, Brad Douglas wrote:

On Tue, 2007-02-20 at 08:53 +0100, Jáchym Čepický wrote:

hi glynn,

2007/2/19, Glynn Clements <glynn@gclements.plus.com>:

[...]

Probably this:

--- raster/r.flow/io.c 7 Feb 2007 05:24:40 -0000 1.14
+++ raster/r.flow/io.c 19 Feb 2007 18:18:41 -0000
@@ -126,7 +126,7 @@
            for (col = 0; col < region.cols; col++)
            {
                BM_set(bitbar, col, row, (barc[col] != 0));
- if (barc[col] != 0)
+ if (ds.buf && barc[col] != 0)
                    put(ds, row, col, -1);
            }
        }

This makes it not to segfault, but it does not make r.flow work properly

The problem is that it requires that the 'dsout' option be specified in
addition to the options you already provided. The memory buffer is not
allocated without it.

I'm not sure if that's a feature or a bug.

It is a bug. I have never run it with the barrier option after it was rewritten
so I did not know that it does not work. I will try to look at it but I don't have
much time now.

Helena

If someone can guide me to
proper operation, I'll commit fix for it.

Here's a patch that "corrects" the problem (essentially, what Glynn
already posted), but I'm not sure if this is proper behavior. Ideally,
it should either A) error out or B) allocate the memory if 'barin' is
specified:

RCS file: /grassrepository/grass6/raster/r.flow/io.c,v
retrieving revision 1.14
diff -u -r1.14 io.c
--- io.c 7 Feb 2007 05:24:40 -0000 1.14
+++ io.c 20 Feb 2007 08:30:36 -0000
@@ -114,7 +114,7 @@
        G_close_cell(fd);
     }

- if (parm.barin)
+ if (parm.barin && parm.dsout)
     {
         G_message(_("Reading input files: barrier"));
        barc = G_allocate_d_raster_buf();
@@ -132,6 +132,8 @@
        }
        G_close_cell(fd);
     }
+
+ if (barc) G_free (barc);
}

--
Brad Douglas <rez touchofmadness com> KB8UYR/6
Address: 37.493,-121.924 / WGS84 National Map Corps #TNMC-3785