Re: [GRASS-dev] remove raster map in C code
On Fri, May 11, 2018 at 11:54 AM, Luca Delucchiwrote: > > On 11 May 2018 at 10:54, Markus Metz wrote: > > Hi Luca, > > > > Hi Markus, > > > On Fri, May 11, 2018 at 10:26 AM, Luca Delucchi > > wrote: > >> > >> Hi devs, > >> > >> I would like to remove a raster map inside a C module, looking aroung > >> I found the M_do_remove function used in g.remove and r.reclass. So I > >> tried to use it but I get error in compilation > >> > >> OBJ.x86_64-pc-linux-gnu/main.o: In function `main': > >> main.c:(.text.startup+0x9eb): undefined reference to `M_get_element' > >> main.c:(.text.startup+0x9f5): undefined reference to `M_do_remove' > >> collect2: error: ld returned 1 exit status > > > > this is a problem of the linker: you need to link against the manage lib, > > see e.g. the Makefile for g.remove. Try > > > > LIBES = $(MANAGELIB) $(RASTERLIB) $(GISLIB) > > DEPENDENCIES = $(MANAGEDEP) $(RASTERDEP) $(GISDEP) > > > > in the Makefile of your module. > > > > thanks, now it compile but I get "Segmentation fault", the module is > r.tile, I attached the diff, could someone have a look to it please? I think you need to call M_read_list() first, before you loop over the tiles. Markus M > > > HTH, > > > > Markus M > > > > > > -- > ciao > Luca > > www.lucadelu.org ___ grass-dev mailing list grass-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] remove raster map in C code
On 11 May 2018 at 10:54, Markus Metzwrote: > Hi Luca, > Hi Markus, > On Fri, May 11, 2018 at 10:26 AM, Luca Delucchi > wrote: >> >> Hi devs, >> >> I would like to remove a raster map inside a C module, looking aroung >> I found the M_do_remove function used in g.remove and r.reclass. So I >> tried to use it but I get error in compilation >> >> OBJ.x86_64-pc-linux-gnu/main.o: In function `main': >> main.c:(.text.startup+0x9eb): undefined reference to `M_get_element' >> main.c:(.text.startup+0x9f5): undefined reference to `M_do_remove' >> collect2: error: ld returned 1 exit status > > this is a problem of the linker: you need to link against the manage lib, > see e.g. the Makefile for g.remove. Try > > LIBES = $(MANAGELIB) $(RASTERLIB) $(GISLIB) > DEPENDENCIES = $(MANAGEDEP) $(RASTERDEP) $(GISDEP) > > in the Makefile of your module. > thanks, now it compile but I get "Segmentation fault", the module is r.tile, I attached the diff, could someone have a look to it please? > HTH, > > Markus M > -- ciao Luca www.lucadelu.org Index: raster/r.tile/Makefile === --- raster/r.tile/Makefile (revision 72704) +++ raster/r.tile/Makefile (working copy) @@ -2,8 +2,8 @@ PGM = r.tile -LIBES = $(RASTERLIB) $(GISLIB) -DEPENDENCIES = $(RASTERDEP) $(GISDEP) +LIBES = $(MANAGELIB) $(RASTERLIB) $(GISLIB) +DEPENDENCIES = $(MANAGEDEP) $(RASTERDEP) $(GISDEP) include $(MODULE_TOPDIR)/include/Make/Module.make Index: raster/r.tile/main.c === --- raster/r.tile/main.c (revision 72704) +++ raster/r.tile/main.c (working copy) @@ -15,12 +15,15 @@ #include #include #include +#include #include +#include static struct { struct Option *rastin, *rastout, *width, *height, *overlap; } parm; + static struct Cell_head dst_w, src_w, ovl_w; static int xtiles, ytiles; static RASTER_MAP_TYPE map_type; @@ -30,6 +33,9 @@ int main(int argc, char *argv[]) { struct GModule *module; +struct Range int_range; +struct FPRange fp_range; +struct Flag *flag; int infile; const char *mapset; size_t cell_size; @@ -75,6 +81,10 @@ parm.overlap->multiple = NO; parm.overlap->description = _("Overlap of tiles"); +flag = G_define_flag(); +flag->key = 'n'; +flag->description = _("Does not create tiles having only NULL values"); + if (G_parser(argc, argv)) exit(EXIT_FAILURE); @@ -149,8 +159,31 @@ } for (xtile = 0; xtile < xtiles; xtile++) { - Rast_close(outfiles[xtile]); - write_support_files(xtile, ytile, overlap); +Rast_close(outfiles[xtile]); +write_support_files(xtile, ytile, overlap); +if (flag->answer){ +char name[GNAME_MAX]; +sprintf(name, "%s-%03d-%03d", parm.rastout->answer, ytile, xtile); +if (map_type == CELL_TYPE) { +CELL min, max; +Rast_read_range(name, G_mapset(), _range); +min = int_range.min; +max = int_range.max; +if (IS_NULL_C() && IS_NULL_C()){ +M_do_remove(M_get_element("raster"), name); +G_debug(0, "Removed empty tile %s", name); +} +} else { +DCELL min, max; +Rast_read_fp_range(name, mapset, _range); +min = fp_range.min; +max = fp_range.max; +if (IS_NULL_D() && IS_NULL_D()){ +M_do_remove(M_get_element("raster"), name); +G_debug(0, "Removed empty tile %s", name); +} +} +} } } ___ grass-dev mailing list grass-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] remove raster map in C code
Hi Luca, On Fri, May 11, 2018 at 10:26 AM, Luca Delucchiwrote: > > Hi devs, > > I would like to remove a raster map inside a C module, looking aroung > I found the M_do_remove function used in g.remove and r.reclass. So I > tried to use it but I get error in compilation > > OBJ.x86_64-pc-linux-gnu/main.o: In function `main': > main.c:(.text.startup+0x9eb): undefined reference to `M_get_element' > main.c:(.text.startup+0x9f5): undefined reference to `M_do_remove' > collect2: error: ld returned 1 exit status this is a problem of the linker: you need to link against the manage lib, see e.g. the Makefile for g.remove. Try LIBES = $(MANAGELIB) $(RASTERLIB) $(GISLIB) DEPENDENCIES = $(MANAGEDEP) $(RASTERDEP) $(GISDEP) in the Makefile of your module. HTH, Markus M > > In the source code of the module I added #include > that it seems the header containing the definition of M_do_remove. > > Any idea? > > Thanks in advance > > -- > ciao > Luca > > www.lucadelu.org > ___ > grass-dev mailing list > grass-dev@lists.osgeo.org > https://lists.osgeo.org/mailman/listinfo/grass-dev ___ grass-dev mailing list grass-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/grass-dev
[GRASS-dev] remove raster map in C code
Hi devs, I would like to remove a raster map inside a C module, looking aroung I found the M_do_remove function used in g.remove and r.reclass. So I tried to use it but I get error in compilation OBJ.x86_64-pc-linux-gnu/main.o: In function `main': main.c:(.text.startup+0x9eb): undefined reference to `M_get_element' main.c:(.text.startup+0x9f5): undefined reference to `M_do_remove' collect2: error: ld returned 1 exit status In the source code of the module I added #include that it seems the header containing the definition of M_do_remove. Any idea? Thanks in advance -- ciao Luca www.lucadelu.org ___ grass-dev mailing list grass-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/grass-dev