[GRASS-SVN] r61092 - grass/branches/develbranch_6/raster/r.in.xyz
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jun 30 22:11:04 PDT 2014
Author: hamish
Date: 2014-06-30 22:11:04 -0700 (Mon, 30 Jun 2014)
New Revision: 61092
Modified:
grass/branches/develbranch_6/raster/r.in.xyz/main.c
Log:
backport skip= option from trunk
Modified: grass/branches/develbranch_6/raster/r.in.xyz/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.in.xyz/main.c 2014-07-01 05:07:45 UTC (rev 61091)
+++ grass/branches/develbranch_6/raster/r.in.xyz/main.c 2014-07-01 05:11:04 UTC (rev 61092)
@@ -97,14 +97,14 @@
FILE *in_fp;
int out_fd;
char *infile, *outmap;
- int xcol, ycol, zcol, max_col, percent;
+ int xcol, ycol, zcol, max_col, percent, skip_lines;
int method = -1;
int bin_n, bin_min, bin_max, bin_sum, bin_sumsq, bin_index;
double zrange_min, zrange_max, d_tmp;
char *fs; /* field delim */
off_t filesize;
int linesize;
- unsigned long estimated_lines;
+ unsigned long estimated_lines, line;
int from_stdin;
int can_seek;
@@ -119,7 +119,6 @@
int row, col; /* counters */
int pass, npasses;
- unsigned long line;
char buff[BUFFSIZE];
double x, y, z;
char **tokens;
@@ -147,7 +146,7 @@
struct Option *input_opt, *output_opt, *delim_opt, *percent_opt,
*type_opt;
struct Option *method_opt, *xcol_opt, *ycol_opt, *zcol_opt, *zrange_opt,
- *zscale_opt;
+ *zscale_opt, *skip_opt;
struct Option *trim_opt, *pth_opt;
struct Flag *scan_flag, *shell_style, *skipline;
@@ -211,6 +210,16 @@
zcol_opt->description = _("Column number of data values in input file");
zcol_opt->guisection = _("Input");
+ skip_opt = G_define_option();
+ skip_opt->key = "skip";
+ skip_opt->type = TYPE_INTEGER;
+ skip_opt->required = NO;
+ skip_opt->multiple = NO;
+ skip_opt->answer = "0";
+ skip_opt->description =
+ _("Number of header lines to skip at top of input file");
+ skip_opt->guisection = _("Input");
+
zrange_opt = G_define_option();
zrange_opt->key = "zrange";
zrange_opt->type = TYPE_DOUBLE;
@@ -294,6 +303,10 @@
percent = atoi(percent_opt->answer);
zscale = atof(zscale_opt->answer);
+ skip_lines = atoi(skip_opt->answer);
+ if (skip_lines < 0)
+ G_fatal_error(_("Please specify reasonable number of lines to skip"));
+
/* parse zrange */
if (zrange_opt->answer != NULL) {
if (zrange_opt->answers[0] == NULL)
@@ -476,6 +489,12 @@
npasses = 1;
}
+ /* skip past header lines */
+ for (line = 0; line < (unsigned long)skip_lines; line++) {
+ if (0 == G_getl2(buff, BUFFSIZE - 1, in_fp))
+ break;
+ }
+
if (scan_flag->answer) {
if (zrange_opt->answer)
G_warning(_("zrange will not be taken into account during scan"));
@@ -526,9 +545,16 @@
if (npasses > 1)
G_message(_("Pass #%d (of %d) ..."), pass, npasses);
- if (can_seek)
+ if (can_seek) {
rewind(in_fp);
+ /* skip past header lines again */
+ for (line = 0; line < (unsigned long)skip_lines; line++) {
+ if (0 == G_getl2(buff, BUFFSIZE - 1, in_fp))
+ break;
+ }
+ }
+
/* figure out segmentation */
pass_north = region.north - (pass - 1) * rows * region.ns_res;
if (pass == npasses)
@@ -645,14 +671,14 @@
}
count++;
- /* G_debug(5, "x: %f, y: %f, z: %f", x, y, z); */
+ /* G_debug(5, "x: %f, y: %f, z: %f", x, y, z); */
G_free_tokens(tokens);
/* find the bin in the current array box */
arr_row = (int)((pass_north - y) / region.ns_res);
arr_col = (int)((x - region.west) / region.ew_res);
- /* G_debug(5, "arr_row: %d arr_col: %d", arr_row, arr_col); */
+ /* G_debug(5, "arr_row: %d arr_col: %d", arr_row, arr_col); */
/* The range should be [0,cols-1]. We use (int) to round down,
but if the point exactly on eastern edge arr_col will be /just/
@@ -1007,6 +1033,8 @@
G_fatal_error("?");
}
+ G_percent(row, rows, 5);
+
/* write out line of raster data */
if (1 != G_put_raster_row(out_fd, raster_row, rtype)) {
G_close_cell(out_fd);
More information about the grass-commit
mailing list