[GRASS-SVN] r69521 - grass-addons/grass7/raster3d/r3.profile
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Sep 18 18:32:09 PDT 2016
Author: wenzeslaus
Date: 2016-09-18 18:32:08 -0700 (Sun, 18 Sep 2016)
New Revision: 69521
Removed:
grass-addons/grass7/raster3d/r3.profile/testsuite/
Modified:
grass-addons/grass7/raster3d/r3.profile/input.c
grass-addons/grass7/raster3d/r3.profile/local_proto.h
grass-addons/grass7/raster3d/r3.profile/main.c
grass-addons/grass7/raster3d/r3.profile/read_rast.c
Log:
r3.profile: whitespace and testsuite clean up
Modified: grass-addons/grass7/raster3d/r3.profile/input.c
===================================================================
--- grass-addons/grass7/raster3d/r3.profile/input.c 2016-09-19 01:27:53 UTC (rev 69520)
+++ grass-addons/grass7/raster3d/r3.profile/input.c 2016-09-19 01:32:08 UTC (rev 69521)
@@ -7,57 +7,57 @@
#include "local_proto.h"
int input(char *blank1, char *word1, char *blank2, char *word2, char *rest,
- FILE *infile)
+ FILE * infile)
{
char buf[1024];
char *b, *w1, *w2;
int string_size;
if (isatty(0))
- fprintf(stderr, "> ");
+ fprintf(stderr, "> ");
*blank1 = *blank2 = 0;
*word1 = *word2 = *rest = 0;
if (!fgets(buf, 1024, infile)) {
- *buf = 0;
- return 0;
+ *buf = 0;
+ return 0;
}
/* note ebuf and nbuf in main.c (w1 and w2 here) are only 256 chars, we
check here to make sure we don't move the pointer past sizeof(buf) */
if (strlen(buf) >= 1023)
- G_fatal_error(_("One coordinate pair per line, please"));
+ G_fatal_error(_("One coordinate pair per line, please"));
b = buf;
w1 = word1;
w2 = word2;
while (*b == ' ' || *b == '\t' || *b == ',')
- *blank1++ = *b++;
+ *blank1++ = *b++;
*blank1 = 0;
while (*b != '\n' && *b != ' ' && *b != '\t' && *b != ',')
- *word1++ = *b++;
+ *word1++ = *b++;
*word1 = 0;
string_size = strlen(w1);
G_debug(5, "strlen w1=%d [%s]", string_size, w1);
if (string_size > 255)
- G_fatal_error(_("One coordinate pair per line, please"));
+ G_fatal_error(_("One coordinate pair per line, please"));
while (*b == ' ' || *b == '\t' || *b == ',')
- *blank2++ = *b++;
+ *blank2++ = *b++;
*blank2 = 0;
while (*b != '\n' && *b != ' ' && *b != '\t' && *b != ',')
- *word2++ = *b++;
+ *word2++ = *b++;
*word2 = 0;
string_size = strlen(w2);
G_debug(5, "strlen w2=%d [%s]", string_size, w2);
if (string_size > 255)
- G_fatal_error(_("One coordinate pair per line, please"));
+ G_fatal_error(_("One coordinate pair per line, please"));
/* bug? really = and not ==? */
/* not a bug: we are filling "rest" with the remaining fgets buffer.
@@ -65,7 +65,7 @@
while ((*rest++ = *b++)) ;
if (isatty(0) && strcmp("end", w1) == 0 && *w2 == 0)
- return 0;
+ return 0;
return 1;
}
Modified: grass-addons/grass7/raster3d/r3.profile/local_proto.h
===================================================================
--- grass-addons/grass7/raster3d/r3.profile/local_proto.h 2016-09-19 01:27:53 UTC (rev 69520)
+++ grass-addons/grass7/raster3d/r3.profile/local_proto.h 2016-09-19 01:32:08 UTC (rev 69521)
@@ -7,11 +7,11 @@
/* main.c */
int do_profile(double, double, double, double, int, double, int, int,
- FILE *, char *, const char *, double);
+ FILE *, char *, const char *, double);
/* read_rast.c */
int read_rast(double, double, double, int, int, RASTER_MAP_TYPE, FILE *,
- char *);
+ char *);
/* input.c */
int input(char *, char *, char *, char *, char *, FILE *);
Modified: grass-addons/grass7/raster3d/r3.profile/main.c
===================================================================
--- grass-addons/grass7/raster3d/r3.profile/main.c 2016-09-19 01:27:53 UTC (rev 69520)
+++ grass-addons/grass7/raster3d/r3.profile/main.c 2016-09-19 01:32:08 UTC (rev 69521)
@@ -40,8 +40,9 @@
struct Cell_head window;
struct
{
- struct Option *opt1, *profile, *res, *output, *null_str, *coord_file, *units;
- struct Flag *g, *c, *m;
+ struct Option *opt1, *profile, *res, *output, *null_str, *coord_file,
+ *units;
+ struct Flag *g, *c, *m;
}
parm;
struct GModule *module;
@@ -53,7 +54,7 @@
G_add_keyword(_("raster"));
G_add_keyword(_("profile"));
module->description =
- _("Outputs the raster map layer values lying on user-defined line(s).");
+ _("Outputs the raster map layer values lying on user-defined line(s).");
parm.opt1 = G_define_standard_option(G_OPT_R_INPUT);
@@ -61,7 +62,7 @@
parm.output->required = NO;
parm.output->answer = "-";
parm.output->description =
- _("Name of file for output (use output=- for stdout)");
+ _("Name of file for output (use output=- for stdout)");
parm.profile = G_define_standard_option(G_OPT_M_COORDS);
parm.profile->required = NO;
@@ -72,17 +73,17 @@
parm.coord_file->key = "file";
parm.coord_file->required = NO;
parm.coord_file->label =
- _("Name of input file containing coordinate pairs");
+ _("Name of input file containing coordinate pairs");
parm.coord_file->description =
- _("Use instead of the 'coordinates' option. "
- "\"-\" reads from stdin.");
+ _("Use instead of the 'coordinates' option. "
+ "\"-\" reads from stdin.");
parm.res = G_define_option();
parm.res->key = "resolution";
parm.res->type = TYPE_DOUBLE;
parm.res->required = NO;
parm.res->description =
- _("Resolution along profile (default = current region resolution)");
+ _("Resolution along profile (default = current region resolution)");
parm.null_str = G_define_standard_option(G_OPT_M_NULL_VALUE);
parm.null_str->answer = "*";
@@ -90,32 +91,33 @@
parm.g = G_define_flag();
parm.g->key = 'g';
parm.g->description =
- _("Output easting and northing in first two columns of four column output");
+ _("Output easting and northing in first two columns of four column output");
parm.c = G_define_flag();
parm.c->key = 'c';
parm.c->description =
- _("Output RRR:GGG:BBB color values for each profile point");
+ _("Output RRR:GGG:BBB color values for each profile point");
parm.units = G_define_standard_option(G_OPT_M_UNITS);
parm.units->options = "meters,kilometers,feet,miles";
parm.units->label = parm.units->description;
- parm.units->description = _("If units are not specified, current location units are used. "
- "Meters are used by default in geographic (latlon) locations.");
+ parm.units->description =
+ _("If units are not specified, current location units are used. "
+ "Meters are used by default in geographic (latlon) locations.");
if (G_parser(argc, argv))
- exit(EXIT_FAILURE);
+ exit(EXIT_FAILURE);
clr = 0;
if (parm.c->answer)
- clr = 1; /* color output */
+ clr = 1; /* color output */
null_string = parm.null_str->answer;
if ((parm.profile->answer && parm.coord_file->answer) ||
- (!parm.profile->answer && !parm.coord_file->answer))
- G_fatal_error(_("Either use profile option or coordinate_file "
- " option, but not both"));
+ (!parm.profile->answer && !parm.coord_file->answer))
+ G_fatal_error(_("Either use profile option or coordinate_file "
+ " option, but not both"));
G_get_window(&window);
projection = G_projection();
@@ -130,7 +132,7 @@
else if (projection == PROJECTION_LL) {
factor = 1;
unit = "meters";
- }
+ }
else {
/* get conversion factor to current units */
unit = G_database_unit_name(1);
@@ -138,14 +140,15 @@
}
if (parm.res->answer) {
- res = atof(parm.res->answer);
- /* Catch bad resolution ? */
- if (res <= 0)
- G_fatal_error(_("Illegal resolution %g [%s]"), res / factor, unit);
+ res = atof(parm.res->answer);
+ /* Catch bad resolution ? */
+ if (res <= 0)
+ G_fatal_error(_("Illegal resolution %g [%s]"), res / factor,
+ unit);
}
else {
- /* Do average of EW and NS res */
- res = (window.ew_res + window.ns_res) / 2;
+ /* Do average of EW and NS res */
+ res = (window.ew_res + window.ns_res) / 2;
}
G_message(_("Using resolution: %g [%s]"), res / factor, unit);
@@ -156,23 +159,23 @@
/* Get Input Name */
name = parm.opt1->answer;
if (parm.g->answer)
- coords = 1;
+ coords = 1;
/* Open Raster File */
fd = Rast_open_old(name, "");
/* initialize color structure */
if (clr)
- Rast_read_colors(name, "", &colors);
+ Rast_read_colors(name, "", &colors);
/* Open ASCII file for output or stdout */
outfile = parm.output->answer;
if ((strcmp("-", outfile)) == 0) {
- fp = stdout;
+ fp = stdout;
}
else if (NULL == (fp = fopen(outfile, "w")))
- G_fatal_error(_("Unable to open file <%s>"), outfile);
+ G_fatal_error(_("Unable to open file <%s>"), outfile);
/* Get Raster Type */
data_type = Rast_get_map_type(fd);
@@ -181,92 +184,93 @@
/* Show message giving output format */
G_message(_("Output columns:"));
if (coords == 1)
- sprintf(formatbuff,
- _("Easting, Northing, Along track dist. [%s], Elevation"), unit);
+ sprintf(formatbuff,
+ _("Easting, Northing, Along track dist. [%s], Elevation"),
+ unit);
else
- sprintf(formatbuff, _("Along track dist. [%s], Elevation"), unit);
+ sprintf(formatbuff, _("Along track dist. [%s], Elevation"), unit);
if (clr)
- strcat(formatbuff, _(" RGB color"));
+ strcat(formatbuff, _(" RGB color"));
G_message("%s", formatbuff);
/* Get Profile Start Coords */
if (parm.coord_file->answer) {
- if (strcmp("-", parm.coord_file->answer) == 0)
- coor_fp = stdin;
- else
- coor_fp = fopen(parm.coord_file->answer, "r");
+ if (strcmp("-", parm.coord_file->answer) == 0)
+ coor_fp = stdin;
+ else
+ coor_fp = fopen(parm.coord_file->answer, "r");
- if (coor_fp == NULL)
- G_fatal_error(_("Could not open <%s>"), parm.coord_file->answer);
+ if (coor_fp == NULL)
+ G_fatal_error(_("Could not open <%s>"), parm.coord_file->answer);
- for (n = 1; input(b1, ebuf, b2, nbuf, label, coor_fp); n++) {
- G_debug(4, "stdin line %d: ebuf=[%s] nbuf=[%s]", n, ebuf, nbuf);
- if (!G_scan_easting(ebuf, &e2, G_projection()) ||
- !G_scan_northing(nbuf, &n2, G_projection()))
- G_fatal_error(_("Invalid coordinates %s %s"), ebuf, nbuf);
+ for (n = 1; input(b1, ebuf, b2, nbuf, label, coor_fp); n++) {
+ G_debug(4, "stdin line %d: ebuf=[%s] nbuf=[%s]", n, ebuf, nbuf);
+ if (!G_scan_easting(ebuf, &e2, G_projection()) ||
+ !G_scan_northing(nbuf, &n2, G_projection()))
+ G_fatal_error(_("Invalid coordinates %s %s"), ebuf, nbuf);
- if (havefirst)
- do_profile(e1, e2, n1, n2, coords, res, fd, data_type,
- fp, null_string, unit, factor);
- e1 = e2;
- n1 = n2;
- havefirst = TRUE;
- }
+ if (havefirst)
+ do_profile(e1, e2, n1, n2, coords, res, fd, data_type,
+ fp, null_string, unit, factor);
+ e1 = e2;
+ n1 = n2;
+ havefirst = TRUE;
+ }
- if (coor_fp != stdin)
- fclose(coor_fp);
+ if (coor_fp != stdin)
+ fclose(coor_fp);
}
else {
- /* Coords given on the Command Line using the profile= option */
- for (i = 0; parm.profile->answers[i]; i += 2) {
- /* Test for number coordinate pairs */
- k = i;
- }
+ /* Coords given on the Command Line using the profile= option */
+ for (i = 0; parm.profile->answers[i]; i += 2) {
+ /* Test for number coordinate pairs */
+ k = i;
+ }
- if (k == 0) {
- /* Only one coordinate pair supplied */
- G_scan_easting(parm.profile->answers[0], &e1, G_projection());
- G_scan_northing(parm.profile->answers[1], &n1, G_projection());
- e2 = e1;
- n2 = n1;
+ if (k == 0) {
+ /* Only one coordinate pair supplied */
+ G_scan_easting(parm.profile->answers[0], &e1, G_projection());
+ G_scan_northing(parm.profile->answers[1], &n1, G_projection());
+ e2 = e1;
+ n2 = n1;
- /* Get profile info */
- do_profile(e1, e2, n1, n2, coords, res, fd, data_type, fp,
- null_string, unit, factor);
- }
- else {
- for (i = 0; i <= k - 2; i += 2) {
- G_scan_easting(parm.profile->answers[i], &e1, G_projection());
- G_scan_northing(parm.profile->answers[i + 1], &n1,
- G_projection());
- G_scan_easting(parm.profile->answers[i + 2], &e2,
- G_projection());
- G_scan_northing(parm.profile->answers[i + 3], &n2,
- G_projection());
+ /* Get profile info */
+ do_profile(e1, e2, n1, n2, coords, res, fd, data_type, fp,
+ null_string, unit, factor);
+ }
+ else {
+ for (i = 0; i <= k - 2; i += 2) {
+ G_scan_easting(parm.profile->answers[i], &e1, G_projection());
+ G_scan_northing(parm.profile->answers[i + 1], &n1,
+ G_projection());
+ G_scan_easting(parm.profile->answers[i + 2], &e2,
+ G_projection());
+ G_scan_northing(parm.profile->answers[i + 3], &n2,
+ G_projection());
- /* Get profile info */
- do_profile(e1, e2, n1, n2, coords, res, fd, data_type,
- fp, null_string, unit, factor);
+ /* Get profile info */
+ do_profile(e1, e2, n1, n2, coords, res, fd, data_type,
+ fp, null_string, unit, factor);
- }
- }
+ }
+ }
}
Rast_close(fd);
fclose(fp);
if (clr)
- Rast_free_colors(&colors);
+ Rast_free_colors(&colors);
exit(EXIT_SUCCESS);
-} /* Done with main */
+} /* Done with main */
/* Calculate the Profile Now */
/* Establish parameters */
int do_profile(double e1, double e2, double n1, double n2,
- int coords, double res, int fd, int data_type, FILE * fp,
- char *null_string, const char *unit, double factor)
+ int coords, double res, int fd, int data_type, FILE * fp,
+ char *null_string, const char *unit, double factor)
{
double rows, cols, LEN;
double Y, X, k;
@@ -278,14 +282,15 @@
G_message(_("Approx. transect length: %f [%s]"), LEN / factor, unit);
if (!G_point_in_region(e2, n2))
- G_warning(_("Endpoint coordinates are outside of current region settings"));
+ G_warning(_("Endpoint coordinates are outside of current region settings"));
/* Calculate Azimuth of Line */
if (rows == 0 && cols == 0) {
- /* Special case for no movement */
- e = e1;
- n = n1;
- read_rast(e, n, dist / factor, fd, coords, data_type, fp, null_string);
+ /* Special case for no movement */
+ e = e1;
+ n = n1;
+ read_rast(e, n, dist / factor, fd, coords, data_type, fp,
+ null_string);
}
k = res / hypot(rows, cols);
@@ -301,43 +306,46 @@
}
if (rows >= 0 && cols < 0) {
- /* SE Quad or due east */
- for (e = e1, n = n1; e < e2 || n > n2; e += X, n -= Y) {
- read_rast(e, n, dist / factor, fd, coords, data_type, fp, null_string);
- /* d+=res; */
- dist += G_distance(e - X, n + Y, e, n);
- }
+ /* SE Quad or due east */
+ for (e = e1, n = n1; e < e2 || n > n2; e += X, n -= Y) {
+ read_rast(e, n, dist / factor, fd, coords, data_type, fp,
+ null_string);
+ /* d+=res; */
+ dist += G_distance(e - X, n + Y, e, n);
+ }
}
if (rows < 0 && cols <= 0) {
- /* NE Quad or due north */
- for (e = e1, n = n1; e < e2 || n < n2; e += X, n += Y) {
- read_rast(e, n, dist / factor, fd, coords, data_type, fp, null_string);
- /* d+=res; */
- dist += G_distance(e - X, n - Y, e, n);
- }
+ /* NE Quad or due north */
+ for (e = e1, n = n1; e < e2 || n < n2; e += X, n += Y) {
+ read_rast(e, n, dist / factor, fd, coords, data_type, fp,
+ null_string);
+ /* d+=res; */
+ dist += G_distance(e - X, n - Y, e, n);
+ }
}
if (rows > 0 && cols >= 0) {
- /* SW Quad or due south */
- for (e = e1, n = n1; e > e2 || n > n2; e -= X, n -= Y) {
- read_rast(e, n, dist / factor, fd, coords, data_type, fp, null_string);
- /* d+=res; */
- dist += G_distance(e + X, n + Y, e, n);
- }
+ /* SW Quad or due south */
+ for (e = e1, n = n1; e > e2 || n > n2; e -= X, n -= Y) {
+ read_rast(e, n, dist / factor, fd, coords, data_type, fp,
+ null_string);
+ /* d+=res; */
+ dist += G_distance(e + X, n + Y, e, n);
+ }
}
if (rows <= 0 && cols > 0) {
- /* NW Quad or due west */
- for (e = e1, n = n1; e > e2 || n < n2; e -= X, n += Y) {
- read_rast(e, n, dist / factor, fd, coords, data_type, fp, null_string);
- /* d+=res; */
- dist += G_distance(e + X, n - Y, e, n);
- }
+ /* NW Quad or due west */
+ for (e = e1, n = n1; e > e2 || n < n2; e -= X, n += Y) {
+ read_rast(e, n, dist / factor, fd, coords, data_type, fp,
+ null_string);
+ /* d+=res; */
+ dist += G_distance(e + X, n - Y, e, n);
+ }
}
/*
* return dist;
*/
return 0;
-} /* done with do_profile */
-
+} /* done with do_profile */
Modified: grass-addons/grass7/raster3d/r3.profile/read_rast.c
===================================================================
--- grass-addons/grass7/raster3d/r3.profile/read_rast.c 2016-09-19 01:27:53 UTC (rev 69520)
+++ grass-addons/grass7/raster3d/r3.profile/read_rast.c 2016-09-19 01:32:08 UTC (rev 69521)
@@ -13,7 +13,7 @@
#include "local_proto.h"
int read_rast(double east, double north, double dist, int fd, int coords,
- RASTER_MAP_TYPE data_type, FILE * fp, char *null_string)
+ RASTER_MAP_TYPE data_type, FILE * fp, char *null_string)
{
static DCELL *dcell;
static int cur_row = -1;
@@ -24,11 +24,11 @@
int outofbounds = FALSE;
if (!dcell) {
- Rast_set_c_null_value(&nullcell, 1);
- dcell = Rast_allocate_d_buf();
- G_get_window(&window);
- nrows = window.rows;
- ncols = window.cols;
+ Rast_set_c_null_value(&nullcell, 1);
+ dcell = Rast_allocate_d_buf();
+ G_get_window(&window);
+ nrows = window.rows;
+ ncols = window.cols;
}
row = (window.north - north) / window.ns_res;
@@ -36,38 +36,37 @@
G_debug(4, "row=%d:%d col=%d:%d", row, nrows, col, ncols);
if ((row < 0) || (row >= nrows) || (col < 0) || (col >= ncols))
- outofbounds = TRUE;
+ outofbounds = TRUE;
if (!outofbounds) {
- if (row != cur_row)
- Rast_get_d_row(fd, dcell, row);
- cur_row = row;
+ if (row != cur_row)
+ Rast_get_d_row(fd, dcell, row);
+ cur_row = row;
}
if (coords)
- fprintf(fp, "%f %f", east, north);
+ fprintf(fp, "%f %f", east, north);
fprintf(fp, " %f", dist);
if (outofbounds || Rast_is_d_null_value(&dcell[col]))
- fprintf(fp, " %s", null_string);
+ fprintf(fp, " %s", null_string);
else {
- if (data_type == CELL_TYPE)
- fprintf(fp, " %d", (int) dcell[col]);
- else
- fprintf(fp, " %f", dcell[col]);
+ if (data_type == CELL_TYPE)
+ fprintf(fp, " %d", (int)dcell[col]);
+ else
+ fprintf(fp, " %f", dcell[col]);
}
if (clr) {
- int red, green, blue;
+ int red, green, blue;
- if (outofbounds)
- Rast_get_c_color(&nullcell, &red, &green, &blue, &colors);
- else
- Rast_get_d_color(&dcell[col], &red, &green, &blue,
- &colors);
+ if (outofbounds)
+ Rast_get_c_color(&nullcell, &red, &green, &blue, &colors);
+ else
+ Rast_get_d_color(&dcell[col], &red, &green, &blue, &colors);
- fprintf(fp, " %03d:%03d:%03d", red, green, blue);
+ fprintf(fp, " %03d:%03d:%03d", red, green, blue);
}
fprintf(fp, "\n");
More information about the grass-commit
mailing list