[GRASS-SVN] r67882 - grass-addons/grass7/raster/r.futures/r.futures.pga
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Feb 18 08:13:11 PST 2016
Author: annakrat
Date: 2016-02-18 08:13:11 -0800 (Thu, 18 Feb 2016)
New Revision: 67882
Modified:
grass-addons/grass7/raster/r.futures/r.futures.pga/main.c
Log:
r.futures: make reading input files more robust
Modified: grass-addons/grass7/raster/r.futures/r.futures.pga/main.c
===================================================================
--- grass-addons/grass7/raster/r.futures/r.futures.pga/main.c 2016-02-18 13:10:14 UTC (rev 67881)
+++ grass-addons/grass7/raster/r.futures/r.futures.pga/main.c 2016-02-18 16:13:11 UTC (rev 67882)
@@ -283,7 +283,15 @@
char **tokens;
while (G_getl2(buf, buflen, fp)) {
+ if (!buf || buf[0] == '\0')
+ continue;
tokens = G_tokenize2(buf, fs, td);
+ int ntokens = G_number_of_tokens(tokens);
+ if (ntokens == 0)
+ continue;
+ // id + intercept + devpressure + predictores
+ if (ntokens != pParams->numAddVariables + 3)
+ G_fatal_error(_("Wrong number of columns in line: %s"), buf);
int idx;
int id;
@@ -293,7 +301,6 @@
G_chop(tokens[0]);
id = atoi(tokens[0]);
-
if (KeyValueIntInt_find(pParams->region_map, id, &idx)) {
G_chop(tokens[1]);
di = atof(tokens[1]);
@@ -1179,11 +1186,15 @@
int years = 0;
while(G_getl2(buf, buflen, fp)) {
+ if (!buf || buf[0] == '\0')
+ continue;
tokens = G_tokenize2(buf, fs, td);
- ntokens = G_number_of_tokens(tokens);
- // skip empty lines
- if (ntokens == 0)
+ int ntokens2 = G_number_of_tokens(tokens);
+ if (ntokens2 == 0)
continue;
+ if (ntokens2 != ntokens)
+ G_fatal_error(_("Wrong number of columns in line: %s"), buf);
+
count = 0;
int i;
for (i = 1; i < ntokens; i++) {
More information about the grass-commit
mailing list