[GRASS-SVN] r31778 - grass/branches/develbranch_6/misc/m.cogo

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 21 07:51:29 EDT 2008


Author: hamish
Date: 2008-06-21 07:51:28 -0400 (Sat, 21 Jun 2008)
New Revision: 31778

Modified:
   grass/branches/develbranch_6/misc/m.cogo/TODO
   grass/branches/develbranch_6/misc/m.cogo/description.html
   grass/branches/develbranch_6/misc/m.cogo/main.c
Log:
remove buggy self defined hypot():
 - returned nan if x,y are negative.
 - #ifdef test did not detect math.h's hypot correctly.
skip comment and blank lines.
update examples in man page.
qualify TODO.


Modified: grass/branches/develbranch_6/misc/m.cogo/TODO
===================================================================
--- grass/branches/develbranch_6/misc/m.cogo/TODO	2008-06-21 09:52:05 UTC (rev 31777)
+++ grass/branches/develbranch_6/misc/m.cogo/TODO	2008-06-21 11:51:28 UTC (rev 31778)
@@ -1,3 +1,6 @@
-Add interactive code from r.profile to easily
-draw line.
+Add interactive code from r.profile to easily draw line.
+ (GRASS 6 only; interactive xmon code in modules is replaced by
+  wxGUI wrappers and non-interactive backend modules in GRASS 7)
 
+see also d.where with <middle click> between coords, which could 
+then be piped into m.cogo.

Modified: grass/branches/develbranch_6/misc/m.cogo/description.html
===================================================================
--- grass/branches/develbranch_6/misc/m.cogo/description.html	2008-06-21 09:52:05 UTC (rev 31777)
+++ grass/branches/develbranch_6/misc/m.cogo/description.html	2008-06-21 11:51:28 UTC (rev 31778)
@@ -15,16 +15,19 @@
 
 <P>
 <B>Example COGO input:</B>
+<div class="code"><pre>
+   P23 N 23:14:12 W 340
+   P24 S 04:18:56 E 230
+   ...
+</pre></div>
+
 <P>
-P23 N 23:14:12 W 340<BR>
-P24 S 04:18:56 E 230<BR>
-...<BR>
-<P>
 The first column may contain a label and you must use the <B>-l</B>
 flag so the program knows.  This is followed by a space, and then
 either the character 'N' or 'S' to indicate whether the bearing is
 relative to the north or south directions.  After another space,
-the angle begins.  Generally, the angle can be of the form
+the angle begins in degrees, minutes, and seconds in
+"DDD:MM:SS.SSSS" format. Generally, the angle can be of the form
 <EM>digits + separator + digits + separator + digits [+ '.' + digits]</EM>.
 A space follows the angle, and is then followed by either the 'E' or 'W'
 characters. A space separates the bearing from the distance (which should
@@ -32,11 +35,12 @@
 
 <P>
 <B>Output of the above input:</B>
+<div class="code"><pre>
+   -134.140211 312.420236 P23
+   -116.832837 83.072345 P24
+   ...
+</pre></div>
 <P>
--134.140211 312.420236 P23<BR>
--116.832837 83.072345 P24<BR>
-...<BR>
-<P>
 Unless specified with the <B>coord</B> option, calculations begin from (0,0).
 
 <P>
@@ -57,7 +61,6 @@
 
 <P>
 
-
 <H2>NOTES</H2>
 
 This program is very simplistic, and will not handle deviations
@@ -67,8 +70,44 @@
 will be extended to provide the capability to generate
 vector and/or sites layers.
 
+
+<H2>EXAMPLE</H2>
+
+<div class="code"><pre>
+   m.cogo -l in=cogo.dat
+</pre></div>
+
+Where the <tt>cogo.dat</tt> input file looks like:
+<div class="code"><pre>
+# Sample COGO input file -- This defines an area.
+# &lt;label&gt; &lt;bearing&gt; &lt;distance&gt;
+P001 S 88:44:56 W 6.7195
+P002 N 33:34:15 W 2.25
+P003 N 23:23:50 W 31.4024
+P004 N 05:04:45 W 25.6981
+P005 N 18:07:25 E 22.2439
+P006 N 27:49:50 E 75.7317
+P007 N 22:56:50 E 87.4482
+P008 N 37:45:15 E 37.7835
+P009 N 46:04:30 E 11.5854
+P010 N 90:00:00 E 8.8201
+P011 N 90:00:00 E 164.1128
+P012 S 48:41:12 E 10.1311
+P013 S 00:25:50 W 255.7652
+P014 N 88:03:13 W 98.8567
+P015 S 88:44:56 W 146.2713
+P016 S 88:44:56 W 18.7164
+</pre></div>
+
+Round trip:
+<div class="code"><pre>
+   m.cogo -l in=cogo.dat | m.cogo -rl in="-"
+</pre></div>
+
+
 <H2>AUTHOR</H2>
 
 Eric G. Miller
 
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>

Modified: grass/branches/develbranch_6/misc/m.cogo/main.c
===================================================================
--- grass/branches/develbranch_6/misc/m.cogo/main.c	2008-06-21 09:52:05 UTC (rev 31777)
+++ grass/branches/develbranch_6/misc/m.cogo/main.c	2008-06-21 11:51:28 UTC (rev 31778)
@@ -31,9 +31,6 @@
 #define FORMAT_2 " %1[NS] %d%c%d%c%lf %1[EW] %lf "
 #define FORMAT_3 " %lf %lf %s "
 
-#ifndef hypot
-#define hypot(x,y) (sqrt(x*x+y*y))
-#endif
 
 struct survey_record {
       char   label[20];
@@ -82,6 +79,7 @@
    const char *cptr;
    
    memset (line, 0, sizeof(line));
+/* TODO: update to G_getl2(), but this fn needs to return pointer to string not ok/EOF int */
    cptr = fgets (line, 512, infile);
    return cptr;
 }
@@ -165,12 +163,16 @@
    else
       out->haslabel = YES;
 
+   G_debug(5, "IN:  x=%f  y=%f  out->x=%f  out->y=%f", x, y, out->x, out->y);
+
    out->rads = atan2(y - out->y, x - out->x);
    out->dist = hypot(x - out->x, y - out->y);
    out->x = x;
    out->y = y;
    out->dd = RAD2DEG(out->rads);
-   
+
+   G_debug(5, "OUT: out->dd=%f  out->dist=%f", out->dd, out->dist);
+
    if (out->rads >= 0.0)
    {
       out->n_s[0] = 'N';
@@ -342,10 +344,16 @@
    {  
       record.x = record.y = 0.0;
    }
-   
+
    while ((cptr = next_line(infile)))
    {
       linenum++;
+
+      if( (cptr[0] == '#') || (cptr[0] == '\0') || (cptr[0] == '\n') ) {
+	/* remove \n check once module is updated to use G_getl2() */
+	 continue; /* line is a comment or blank */
+      }
+
       if (!parse_line(cptr, &record))
       {
          if (verbose)



More information about the grass-commit mailing list