diff --git a/lib/raster/cats.c b/lib/raster/cats.c index 6eb3789daef..d299e7563d5 100644 --- a/lib/raster/cats.c +++ b/lib/raster/cats.c @@ -217,7 +217,7 @@ static CELL read_cats(const char *element, const char *name, const char *mapset, } /* Read the title for the file */ - if (G_getl(buff, sizeof buff, fd) == 0) + if (G_getl(buff, sizeof(buff), fd) == 0) goto error; G_strip(buff); /* G_ascii_check(buff) ; */ @@ -230,10 +230,10 @@ static CELL read_cats(const char *element, const char *name, const char *mapset, char fmt[256]; float m1, a1, m2, a2; - if (G_getl(fmt, sizeof fmt, fd) == 0) + if (G_getl(fmt, sizeof(fmt), fd) == 0) goto error; /* next line contains equation coefficients */ - if (G_getl(buff, sizeof buff, fd) == 0) + if (G_getl(buff, sizeof(buff), fd) == 0) goto error; if (sscanf(buff, "%f %f %f %f", &m1, &a1, &m2, &a2) != 4) goto error; @@ -244,7 +244,7 @@ static CELL read_cats(const char *element, const char *name, const char *mapset, for (cat1 = 0;; cat1++) { char label[1024]; - if (G_getl(buff, sizeof buff, fd) == 0) + if (G_getl(buff, sizeof(buff), fd) == 0) break; if (old) Rast_set_c_cat(&cat1, &cat1, buff, pcats); diff --git a/raster/r.univar/globals.h b/raster/r.univar/globals.h index f492e7edd0d..7df801e5621 100644 --- a/raster/r.univar/globals.h +++ b/raster/r.univar/globals.h @@ -69,5 +69,6 @@ int print_stats(univar_stat *stats, enum OutputFormat format); int print_stats_table(univar_stat *stats); univar_stat *create_univar_stat_struct(int map_type, int n_perc); void free_univar_stat_struct(univar_stat *stats); +univar_stat *univar_stat_with_percentiles(int map_type); #endif diff --git a/raster/r.univar/r.univar_main.c b/raster/r.univar/r.univar_main.c index be37b45c69a..4199774c97b 100644 --- a/raster/r.univar/r.univar_main.c +++ b/raster/r.univar/r.univar_main.c @@ -102,7 +102,6 @@ void set_params(void) param.shell_style->description = _( "This flag is deprecated and will be removed in a future release. Use " "format=shell instead."); - param.shell_style->guisection = _("Formatting"); param.extended = G_define_flag(); @@ -137,7 +136,6 @@ void set_params(void) } static int open_raster(const char *infile); -static univar_stat *univar_stat_with_percentiles(int map_type); static void process_raster(univar_stat *stats, thread_workspace *tw, const struct Cell_head *region, int nprocs, enum OutputFormat format); @@ -153,7 +151,7 @@ int main(int argc, char *argv[]) struct Cell_head region; struct GModule *module; univar_stat *stats; - char **p, *z; + char **infile, *zonemap; int cell_type, min, max; struct Range zone_range; const char *mapset, *name; @@ -259,20 +257,20 @@ int main(int argc, char *argv[]) thread_workspace *tw = G_malloc(nprocs * sizeof *tw); /* open zoning raster */ - if ((z = param.zonefile->answer)) { - mapset = G_find_raster2(z, ""); + if ((zonemap = param.zonefile->answer)) { + mapset = G_find_raster2(zonemap, ""); for (t = 0; t < nprocs; ++t) - tw[t].fdz = open_raster(z); + tw[t].fdz = open_raster(zonemap); cell_type = Rast_get_map_type(tw->fdz); if (cell_type != CELL_TYPE) G_fatal_error("Zoning raster must be of type CELL"); - if (Rast_read_range(z, mapset, &zone_range) == -1) + if (Rast_read_range(zonemap, mapset, &zone_range) == -1) G_fatal_error("Can not read range for zoning raster"); Rast_get_range_min_max(&zone_range, &min, &max); - if (Rast_read_cats(z, mapset, &(zone_info.cats))) + if (Rast_read_cats(zonemap, mapset, &(zone_info.cats))) G_warning("No category support for zoning raster"); zone_info.min = min; @@ -281,7 +279,8 @@ int main(int argc, char *argv[]) } /* count the input rasters given */ - for (p = (char **)param.inputfile->answers, rasters = 0; *p; p++, rasters++) + for (infile = (char **)param.inputfile->answers, rasters = 0; *infile; + infile++, rasters++) ; /* process all input rasters */ @@ -289,13 +288,13 @@ int main(int argc, char *argv[]) stats = ((map_type == -1) ? create_univar_stat_struct(-1, 0) : 0); - for (p = param.inputfile->answers; *p; p++) { + for (infile = param.inputfile->answers; *infile; infile++) { /* Check if the native extent and resolution of the input map should be used */ if (param.use_rast_region->answer) { - mapset = G_find_raster2(*p, ""); - Rast_get_cellhd(*p, mapset, ®ion); + mapset = G_find_raster2(*infile, ""); + Rast_get_cellhd(*infile, mapset, ®ion); /* Set the computational region */ Rast_set_window(®ion); } @@ -304,7 +303,7 @@ int main(int argc, char *argv[]) } for (t = 0; t < nprocs; t++) - tw[t].fd = open_raster(*p); + tw[t].fd = open_raster(*infile); if (map_type != -1) { /* NB: map_type must match when doing extended stats */ @@ -318,7 +317,7 @@ int main(int argc, char *argv[]) stats = univar_stat_with_percentiles(map_type); } else if (this_type != map_type) { - G_fatal_error(_("Raster <%s> type mismatch"), *p); + G_fatal_error(_("Raster <%s> type mismatch"), *infile); } } @@ -330,7 +329,7 @@ int main(int argc, char *argv[]) } /* close zoning raster */ - if (z) { + if (zonemap) { for (t = 0; t < nprocs; t++) Rast_close(tw[t].fdz); } @@ -363,28 +362,6 @@ static int open_raster(const char *infile) return fd; } -static univar_stat *univar_stat_with_percentiles(int map_type) -{ - univar_stat *stats; - unsigned int i, j; - unsigned int n_zones = zone_info.n_zones; - - if (n_zones == 0) - n_zones = 1; - - i = 0; - while (param.percentile->answers[i]) - i++; - stats = create_univar_stat_struct(map_type, i); - for (i = 0; i < n_zones; i++) { - for (j = 0; j < stats[i].n_perc; j++) { - sscanf(param.percentile->answers[j], "%lf", &(stats[i].perc[j])); - } - } - - return stats; -} - static void process_raster(univar_stat *stats, thread_workspace *tw, const struct Cell_head *region, int nprocs, enum OutputFormat format) diff --git a/raster/r.univar/r3.univar_main.c b/raster/r.univar/r3.univar_main.c index 4fc63b70a86..f14d50746a7 100644 --- a/raster/r.univar/r3.univar_main.c +++ b/raster/r.univar/r3.univar_main.c @@ -40,6 +40,7 @@ void set_params(void) param.output_file->required = NO; param.output_file->description = _("Name for output file (if omitted or \"-\" output to stdout)"); + param.output_file->guisection = _("Output settings"); param.percentile = G_define_option(); param.percentile->key = "percentile"; @@ -50,6 +51,7 @@ void set_params(void) param.percentile->answer = "90"; param.percentile->description = _("Percentile to calculate (requires extended statistics flag)"); + param.percentile->guisection = _("Extended"); param.separator = G_define_standard_option(G_OPT_F_SEP); param.separator->answer = NULL; @@ -62,10 +64,12 @@ void set_params(void) param.shell_style->description = _( "This flag is deprecated and will be removed in a future release. Use " "format=shell instead."); + param.shell_style->guisection = _("Formatting"); param.extended = G_define_flag(); param.extended->key = 'e'; param.extended->description = _("Calculate extended statistics"); + param.extended->guisection = _("Extended"); param.table = G_define_flag(); param.table->key = 't'; @@ -74,6 +78,7 @@ void set_params(void) param.table->description = _( "This flag is deprecated and will be removed in a future release. Use " "format=csv instead."); + param.table->guisection = _("Formatting"); param.format = G_define_standard_option(G_OPT_F_FORMAT); param.format->options = "plain,shell,csv,json"; @@ -94,20 +99,17 @@ int main(int argc, char *argv[]) FCELL val_f; /* for misc use */ DCELL val_d; /* for misc use */ int map_type, zmap_type; + RASTER3D_Region region; + struct GModule *module; univar_stat *stats; - char *infile, *zonemap; void *map, *zmap = NULL; - RASTER3D_Region region; - unsigned int i; unsigned int rows, cols, depths; unsigned int x, y, z; double dmin, dmax; - int zone, n_zones /* , use_zone = 0 */; + int zone /* , use_zone = 0 */; const char *mapset, *name; - struct GModule *module; - enum OutputFormat format; G_gisinit(argv[0]); @@ -253,24 +255,7 @@ int main(int argc, char *argv[]) Rast3d_fatal_error(_("Unable to open 3D raster map <%s>"), infile); map_type = Rast3d_tile_type_map(map); - - i = 0; - while (param.percentile->answers[i]) - i++; - - n_zones = zone_info.n_zones; - - if (n_zones == 0) - n_zones = 1; - - stats = create_univar_stat_struct(map_type, i); - for (i = 0; i < (unsigned int)n_zones; i++) { - unsigned int j; - - for (j = 0; j < stats[i].n_perc; j++) { - sscanf(param.percentile->answers[j], "%lf", &(stats[i].perc[j])); - } - } + stats = univar_stat_with_percentiles(map_type); for (z = 0; z < depths; z++) { /* From the bottom to the top */ if (format != SHELL) diff --git a/raster/r.univar/stats.c b/raster/r.univar/stats.c index c23ad21b498..f6661bf4d83 100644 --- a/raster/r.univar/stats.c +++ b/raster/r.univar/stats.c @@ -726,3 +726,25 @@ int print_stats_table(univar_stat *stats) return 1; } + +univar_stat *univar_stat_with_percentiles(int map_type) +{ + univar_stat *stats; + unsigned int i, j; + unsigned int n_zones = zone_info.n_zones; + + if (n_zones == 0) + n_zones = 1; + + i = 0; + while (param.percentile->answers[i]) + i++; + stats = create_univar_stat_struct(map_type, i); + for (i = 0; i < n_zones; i++) { + for (j = 0; j < stats[i].n_perc; j++) { + sscanf(param.percentile->answers[j], "%lf", &(stats[i].perc[j])); + } + } + + return stats; +}