[GRASS-SVN] r59033 - grass/trunk/raster/r.profile
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Feb 14 00:53:41 PST 2014
Author: hamish
Date: 2014-02-14 00:53:41 -0800 (Fri, 14 Feb 2014)
New Revision: 59033
Modified:
grass/trunk/raster/r.profile/input.c
grass/trunk/raster/r.profile/local_proto.h
grass/trunk/raster/r.profile/main.c
grass/trunk/raster/r.profile/r.profile.html
Log:
add option to read from a file, stdin usage moved to coord file called '-'
Modified: grass/trunk/raster/r.profile/input.c
===================================================================
--- grass/trunk/raster/r.profile/input.c 2014-02-14 04:51:02 UTC (rev 59032)
+++ grass/trunk/raster/r.profile/input.c 2014-02-14 08:53:41 UTC (rev 59033)
@@ -6,7 +6,8 @@
#include "local_proto.h"
-int input(char *blank1, char *word1, char *blank2, char *word2, char *rest)
+int input(char *blank1, char *word1, char *blank2, char *word2, char *rest,
+ FILE *infile)
{
char buf[1024];
char *b, *w1, *w2;
@@ -18,7 +19,7 @@
*blank1 = *blank2 = 0;
*word1 = *word2 = *rest = 0;
- if (!fgets(buf, 1024, stdin)) {
+ if (!fgets(buf, 1024, infile)) {
*buf = 0;
return 0;
}
Modified: grass/trunk/raster/r.profile/local_proto.h
===================================================================
--- grass/trunk/raster/r.profile/local_proto.h 2014-02-14 04:51:02 UTC (rev 59032)
+++ grass/trunk/raster/r.profile/local_proto.h 2014-02-14 08:53:41 UTC (rev 59033)
@@ -14,7 +14,7 @@
char *);
/* input.c */
-int input(char *, char *, char *, char *, char *);
+int input(char *, char *, char *, char *, char *, FILE *);
extern int clr;
extern struct Colors colors;
Modified: grass/trunk/raster/r.profile/main.c
===================================================================
--- grass/trunk/raster/r.profile/main.c 2014-02-14 04:51:02 UTC (rev 59032)
+++ grass/trunk/raster/r.profile/main.c 2014-02-14 08:53:41 UTC (rev 59033)
@@ -24,7 +24,7 @@
{
char *name, *outfile;
int fd, projection;
- FILE *fp;
+ FILE *fp, *coor_fp;
double res;
char *null_string;
char ebuf[256], nbuf[256], label[512], formatbuff[256];
@@ -37,7 +37,7 @@
struct Cell_head window;
struct
{
- struct Option *opt1, *profile, *res, *output, *null_str;
+ struct Option *opt1, *profile, *res, *output, *null_str, *coord_file;
struct Flag *g, *c;
}
parm;
@@ -66,11 +66,16 @@
parm.profile->required = NO;
parm.profile->multiple = YES;
parm.profile->key_desc = "east,north";
- parm.profile->label = _("Profile coordinate pairs");
- parm.profile->description =
- _("If no coordinate pairs are specified, "
- "coordinates at standard input are expected.");
+ parm.profile->description = _("Profile coordinate pairs");
+ parm.coord_file = G_define_standard_option(G_OPT_F_INPUT);
+ parm.coord_file->key = "coordinate_file";
+ parm.coord_file->label =
+ _("Name of input file containing coordinate pairs");
+ parm.coord_file->description =
+ _("Use instead of the 'profile' option. \"-\" reads from stdin.");
+ parm.coord_file->required = NO;
+
parm.res = G_define_option();
parm.res->key = "res";
parm.res->type = TYPE_DOUBLE;
@@ -106,6 +111,11 @@
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"));
+
G_get_window(&window);
projection = G_projection();
if (parm.res->answer) {
@@ -161,9 +171,17 @@
G_message(formatbuff);
/* Get Profile Start Coords */
- if (!parm.profile->answer) {
- /* Assume input from stdin */
- for (n = 1; input(b1, ebuf, b2, nbuf, label); n++) {
+ 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 (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()))
@@ -176,9 +194,12 @@
n1 = n2;
havefirst = TRUE;
}
+
+ if (coor_fp != stdin)
+ fclose(coor_fp);
}
else {
- /* Coords from Command Line */
+ /* 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;
Modified: grass/trunk/raster/r.profile/r.profile.html
===================================================================
--- grass/trunk/raster/r.profile/r.profile.html 2014-02-14 04:51:02 UTC (rev 59032)
+++ grass/trunk/raster/r.profile/r.profile.html 2014-02-14 08:53:41 UTC (rev 59033)
@@ -11,8 +11,10 @@
<p>The <b>profile</b> parameter can be set to comma separated geographic
coordinates for profile line endpoints.
-Alternatively the coordinate pairs can be piped
-from stdin, one comma separated pair per line.
+Alternatively the coordinate pairs can be piped from the text file specified
+by <b>coordinate_file</b> option, or if set to "-", from <tt>stdin</tt>.
+In these cases the coordinate pairs should be given one comma separated pair
+per line.
<p>The <b>res</b> parameter sets the distance between each profile point
(resolution). The resolution must be provided in GRASS database units (i.e.
@@ -39,6 +41,7 @@
<p>The optional RGB output provides the associated GRASS colour value for
each profile point.
+
<h2>EXAMPLES</h2>
<b>Example 1</b><br>
@@ -52,6 +55,7 @@
<p><br>
+<!-- d.where no longer there
<b>Example 2</b><br>
Extract a profile with coordinates provided from standard input or an external file:
<p>First create a points file with <em><a href="d.where.html">d.where</a></em>
@@ -75,14 +79,13 @@
<div class="code"><pre>
d.where | r.profile elevation.dem
</pre></div>
-
<p><br>
+-->
-
-<b>Example 3</b><br>
+<b>Example 2</b><br>
Pipe coordinates into r.profile
<div class="code"><pre>
-r.profile elevation.dem res=1000 << EOF
+r.profile elevation.dem res=1000 coordinate_file=- << EOF
591243,4926344
592509,4922156
594100,4920793
@@ -109,6 +112,7 @@
This filters out the everything except the numbers.
+
<h2>SEE ALSO</h2>
<em>
@@ -120,7 +124,9 @@
<a href="wxGUI.html">wxGUI profile tool</a>
</em>
+
<h2>AUTHOR</h2>
<a href="mailto:bcovill at tekmap.ns.ca">Bob Covill</a>
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>
More information about the grass-commit
mailing list