[GRASS-SVN] r70108 - grass/trunk/raster/r.quantile
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Dec 20 14:32:58 PST 2016
Author: mmetz
Date: 2016-12-20 14:32:58 -0800 (Tue, 20 Dec 2016)
New Revision: 70108
Modified:
grass/trunk/raster/r.quantile/main.c
Log:
r.quantile: add option to print output to file instead of stdout
Modified: grass/trunk/raster/r.quantile/main.c
===================================================================
--- grass/trunk/raster/r.quantile/main.c 2016-12-20 22:04:52 UTC (rev 70107)
+++ grass/trunk/raster/r.quantile/main.c 2016-12-20 22:32:58 UTC (rev 70108)
@@ -11,6 +11,7 @@
*
*****************************************************************************/
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <math.h>
#include <grass/gis.h>
@@ -230,9 +231,9 @@
v = max;
if (recode)
- printf("%f:%f:%i\n", prev_v, v, quant + 1);
+ fprintf(stdout, "%f:%f:%i\n", prev_v, v, quant + 1);
else
- printf("%d:%f:%f\n", quant, 100 * quants[quant], v);
+ fprintf(stdout, "%d:%f:%f\n", quant, 100 * quants[quant], v);
prev_v = v;
}
@@ -246,7 +247,7 @@
struct GModule *module;
struct
{
- struct Option *input, *quant, *perc, *slots;
+ struct Option *input, *quant, *perc, *slots, *file;
} opt;
struct {
struct Flag *r;
@@ -286,6 +287,12 @@
opt.slots->description = _("Number of bins to use");
opt.slots->answer = "1000000";
+ opt.file = G_define_standard_option(G_OPT_F_OUTPUT);
+ opt.file->key = "file";
+ opt.file->required = NO;
+ opt.file->description =
+ _("Name for output file (if omitted or \"-\" output to stdout)");
+
flag.r = G_define_flag();
flag.r->key = 'r';
flag.r->description = _("Generate recode rules based on quantile-defined intervals");
@@ -296,6 +303,12 @@
num_slots = atoi(opt.slots->answer);
recode = flag.r->answer;
+ if (opt.file->answer != NULL && strcmp(opt.file->answer, "-") != 0) {
+ if (NULL == freopen(opt.file->answer, "w", stdout)) {
+ G_fatal_error(_("Unable to open file <%s> for writing"), opt.file->answer);
+ }
+ }
+
if (opt.perc->answer) {
int i;
More information about the grass-commit
mailing list