[GRASS-SVN] r46114 - grass-addons/display/d.barb

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 27 04:22:31 EDT 2011


Author: hamish
Date: 2011-04-27 01:22:31 -0700 (Wed, 27 Apr 2011)
New Revision: 46114

Modified:
   grass-addons/display/d.barb/
   grass-addons/display/d.barb/description.html
   grass-addons/display/d.barb/grid.c
   grass-addons/display/d.barb/legend.c
   grass-addons/display/d.barb/local_proto.h
   grass-addons/display/d.barb/main.c
   grass-addons/display/d.barb/points.c
Log:
implement reverse flag;
more examples in man page;
quieten debug messages



Property changes on: grass-addons/display/d.barb
___________________________________________________________________
Added: svn:ignore
   + OBJ.*
*.tmp.html


Modified: grass-addons/display/d.barb/description.html
===================================================================
--- grass-addons/display/d.barb/description.html	2011-04-26 19:18:42 UTC (rev 46113)
+++ grass-addons/display/d.barb/description.html	2011-04-27 08:22:31 UTC (rev 46114)
@@ -34,17 +34,6 @@
 
 <h2>EXAMPLES</h2>
 
-<h4>Eularian field from raster grid</h4>
-<div class="code"><pre>
-
-# create polar coordinate maps from cartesian components
-r.mapcalc "magnitude = sqrt($MAPu^2 + $MAPv^2)"
-r.mapcalc "direction = atan($MAPu, $MAPv)"
-
-
-d.barb
-</pre></div>
-
 <h4>Sparse staion data from vector maps</h4>
 
 First prepare some dummy data, then plot it.
@@ -56,11 +45,40 @@
 v.db.update dummy_map column=direction value='cat * 4.0'
 v.db.update dummy_map column=magnitude value='cat / 2.0'
 
+g.region n=4918590 s=4914780 w=591510 e=595650
+d.erase
+d.barb input=dummy_map direction=direction magnitude=magnitude \
+   aspect=compass style=barb
+</pre></div>
+
+<h4>Eularian field from raster grid</h4>
+<div class="code"><pre>
+# r.surf.volcano module from GRASS-addons
 g.region -d
-d.barb input=dummy_map direction=direction magnitude=magnitude aspect=compass
+r.surf.volcano output=gauss method=gaussian sigma=1
+r.colors -ne gauss color=bcyr
+r.slope.aspect elev=gauss slope=gauss.slope aspect=gauss.aspect
+d.barb dir=gauss.aspect mag=gauss.slope scale=20 color=aqua
 </pre></div>
 
+<!-- useful, but not really needed
+<h4>Create polar coordinate maps from cartesian components</h4>
 
+<div class="code"><pre>
+MAPu=velocity.u
+MAPv=velocity.v
+r.mapcalc "magnitude = sqrt($MAPu^2 + $MAPv^2)"
+r.mapcalc "direction = atan($MAPu, $MAPv)"
+</pre></div>
+
+and back again:
+
+<div class="code"><pre>
+r.mapcalc "u_component = magnitude * cos(direction)"
+r.mapcalc "v_component = magnitude * sin(direction)"
+</pre></div>
+-->
+
 <h4>Create a legend</h4>
 <div class="code"><pre>
 d.graph << EOF
@@ -85,15 +103,28 @@
 </pre></div>
 
 
+<h2>BUGS</h2>
 
+Probably ...
+<ul>
+<li>Scaling of legend does not yet match normal operation.
+</ul>
+
 <h2>SEE ALSO</h2>
-d.rast.arrow
-d.graph
-d.vect
+<i>
+<a href="d.rast.arrow.html">d.rast.arrow</a>,
+<a href="d.graph.html">d.graph</a>,
+<a href="d.vect.html">d.vect</a>
+</i>
 
 
 <h2>AUTHOR</h2>
-Hamish Bowman
-Dept Marine Science
-University of Otago
+Hamish Bowman<br> <i>
+Department of Marine Science<br>
+University of Otago<br>
+New Zealand</i><br>
 
+<br>
+<p>
+<i>Last changed: $Date$</i></p>
+

Modified: grass-addons/display/d.barb/grid.c
===================================================================
--- grass-addons/display/d.barb/grid.c	2011-04-26 19:18:42 UTC (rev 46113)
+++ grass-addons/display/d.barb/grid.c	2011-04-27 08:22:31 UTC (rev 46114)
@@ -9,7 +9,7 @@
 /* load and plot barbs from data stored in two raster maps */
 void do_barb_grid(char *dir_u_map, char *mag_v_map, int is_component,
 		  int color, int aspect_type, double scale, int skip,
-		  int style)
+		  int style, int reverse)
 {
     /* from d.rast.arrow */
     struct FPRange range;
@@ -24,8 +24,7 @@
     double length = -1.0, r;
     double easting, northing;
 
-    G_debug(0, "Doing Eulerian field ...");
-    G_warning("Not fully working yet -- use d.rast.arrow instead.");
+    G_debug(1, "Doing Eulerian field ...");
 
     /* figure out arrow scaling */
     G_init_fp_range(&range);	/* really needed? */
@@ -146,6 +145,11 @@
 	    else if (aspect_f > 360)
 		aspect_f -= 360;
 
+	    if(reverse)
+	        aspect_f += 180;
+	    if (aspect_f > 360)
+		aspect_f -= 360;
+
 	    length *= scale;
 
 	   /** Now draw the arrows **/

Modified: grass-addons/display/d.barb/legend.c
===================================================================
--- grass-addons/display/d.barb/legend.c	2011-04-26 19:18:42 UTC (rev 46113)
+++ grass-addons/display/d.barb/legend.c	2011-04-27 08:22:31 UTC (rev 46114)
@@ -18,9 +18,9 @@
     G_debug(1, "Doing legend ... (%d entries)", num_velos);
 
     if (style == TYPE_BARB)
+	angle = -90;
+    else
 	angle = 90;
-    else
-	angle = 0;
 
     D_get_screen_window(&t, &b, &l, &r);
 

Modified: grass-addons/display/d.barb/local_proto.h
===================================================================
--- grass-addons/display/d.barb/local_proto.h	2011-04-26 19:18:42 UTC (rev 46113)
+++ grass-addons/display/d.barb/local_proto.h	2011-04-27 08:22:31 UTC (rev 46114)
@@ -15,10 +15,10 @@
 #define R2D(d) (double)(d / RpD)	/* radians->degrees */
 
 /* grid.c */
-void do_barb_grid(char *, char *, int, int, int, double, int, int);
+void do_barb_grid(char *, char *, int, int, int, double, int, int, int);
 
 /* points.c */
-void do_barb_points(char *, int, char *, char *, int, int, int, double, int);
+void do_barb_points(char *, int, char *, char *, int, int, int, double, int, int);
 int count_pts_in_region(struct Map_info *);
 void fill_arrays(struct Map_info *, int, char *, char *, int, double *,
 		 double *, double *, double *);

Modified: grass-addons/display/d.barb/main.c
===================================================================
--- grass-addons/display/d.barb/main.c	2011-04-26 19:18:42 UTC (rev 46113)
+++ grass-addons/display/d.barb/main.c	2011-04-27 08:22:31 UTC (rev 46114)
@@ -154,13 +154,16 @@
     /* TODO */
     from_to = G_define_flag();
     from_to->key = 'r';
+    from_to->label =
+	_("Rotate direction 180 degrees");
     from_to->description =
-	_("Reverse direction 180 degrees");
+	_("Useful for switching between atmospheric and oceanographic conventions");
 
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
-    G_warning("This module is a work in progress. Don't expect it to work.");
+    G_warning("This module is still a work in progress.");
 
     /* check parms */
     if ((u_opt->answer && (dir_opt->answer || magn_opt->answer)) ||
@@ -249,10 +252,10 @@
     if (is_vector)
 	do_barb_points(vinput_opt->answer, vlayer,
 		       dir_u_map, mag_v_map, is_component, color,
-		       aspect_type, scale, style);
+		       aspect_type, scale, style, from_to->answer);
     else
 	do_barb_grid(dir_u_map, mag_v_map, is_component, color,
-		     aspect_type, scale, skip, style);
+		     aspect_type, scale, skip, style, from_to->answer);
 
 
     D_add_to_list(G_recreate_command());

Modified: grass-addons/display/d.barb/points.c
===================================================================
--- grass-addons/display/d.barb/points.c	2011-04-26 19:18:42 UTC (rev 46113)
+++ grass-addons/display/d.barb/points.c	2011-04-27 08:22:31 UTC (rev 46114)
@@ -9,7 +9,7 @@
 /* load and plot barbs from data stored in a vector map's attribute table */
 void do_barb_points(char *vinput_name, int vlayer, char *dir_u_col,
 		    char *mag_v_col, int is_component, int color,
-		    int aspect_type, double scale, int style)
+		    int aspect_type, double scale, int style, int reverse)
 {
 
     struct Map_info vMap;
@@ -26,7 +26,7 @@
 
     magn = NULL;		/* init in case it isn't used */
 
-    G_debug(0, "Doing sparse points ...");
+    G_debug(1, "Doing sparse points ...");
 
     if ((mapset = G_find_vector2(vinput_name, "")) == NULL)
 	G_fatal_error(_("Vector map <%s> not found"), vinput_name);
@@ -39,13 +39,13 @@
     if (1 > Vect_open_old(&vMap, vinput_name, mapset))
 	G_fatal_error(_("Unable to open vector map <%s>"), vinput_name);
 
-    G_debug(0, "<%s> is open", vinput_name);
+    G_debug(3, "<%s> is open", vinput_name);
 
     /* we need to scan through and find the greatest value in of the
        magnitude within the current region and scale from that. hence
        the following complexity ... */
     num_pts = count_pts_in_region(&vMap);
-    G_debug(0, "  %d points found in region", num_pts);
+    G_debug(2, "  %d points found in region", num_pts);
 
     coord_x = G_calloc(num_pts + 1, sizeof(double));
     coord_y = G_calloc(num_pts + 1, sizeof(double));
@@ -60,20 +60,24 @@
 
     if (aspect_type == TYPE_GRASS) {
 	for (i = 0; i < num_pts; i++) {
-	    //          G_debug(0, "in=%.1f  out=%.1f", dirn[i], 90-dirn[i] < 0 ? 360+90-dirn[i] : 90-dirn[i]);
+	    //G_debug(5, "in=%.1f  out=%.1f", dirn[i], 90-dirn[i] < 0 ? 360+90-dirn[i] : 90-dirn[i]);
 	    dirn[i] = 90 - dirn[i];
 	    if (dirn[i] < 0)
 		dirn[i] += 360;
 	}
     }
 
-    /* todone?
-    if (aspect_type == TYPE_COMPASS)
-           dir = 90 - dir;
-     */
+    if (reverse) {
+	for (i = 0; i < num_pts; i++) {
+	    //G_debug(5, "in=%.1f  out=%.1f", dirn[i], 90-dirn[i] < 0 ? 360+90-dirn[i] : 90-dirn[i]);
+	    dirn[i] = dirn[i] + 180;
+	    if (dirn[i] > 360)
+		dirn[i] -= 360;
+	}
+    }
 
     peak = max_magnitude(magn, num_pts);
-    G_debug(0, "  peak = %.2f", peak);
+    G_debug(2, "  peak = %.2f", peak);
     if (style == TYPE_BARB && peak > 150)
 	G_warning(_("Maximum wind barb displayed is 150 knots"));
 
@@ -99,9 +103,9 @@
     struct line_cats *Cats;
     struct Cell_head window;
 
-    G_debug(0, "count_pts_in_region()");
+    G_debug(3, "count_pts_in_region()");
     G_get_window(&window);
-    G_debug(0, "  n=%.2f s=%.2f e=%.2f w=%.2f", window.north, window.south,
+    G_debug(4, "  n=%.2f s=%.2f e=%.2f w=%.2f", window.north, window.south,
 	    window.east, window.west);
 
     /* Create and initialize struct's where to store points/lines and categories */
@@ -109,7 +113,7 @@
     Cats = Vect_new_cats_struct();
 
     nlines = Vect_get_num_lines(Map);
-    G_debug(0, "  %d features found in map", nlines);
+    G_debug(2, "  %d features found in map", nlines);
 
     Vect_rewind(Map);
 
@@ -152,7 +156,7 @@
     dbCatVal *cv_dir_u = NULL, *cv_mag_v = NULL;
     double theta, r;
 
-    G_debug(0, "fill_arrays()");
+    G_debug(3, "fill_arrays()");
 
     G_get_window(&window);
 
@@ -180,7 +184,7 @@
 
     nrec = db_select_CatValArray(driver, fi->table, fi->key,
 				 dir_u, NULL, &cvarr_dir_u);
-    G_debug(0, "nrec (%s) = %d", dir_u, nrec);
+    G_debug(3, "nrec (%s) = %d", dir_u, nrec);
 
     if (cvarr_dir_u.ctype != DB_C_TYPE_INT &&
 	cvarr_dir_u.ctype != DB_C_TYPE_DOUBLE)
@@ -188,12 +192,12 @@
 
     if (nrec < 0)
 	G_fatal_error(_("Cannot select data (%s) from table"), dir_u);
-    G_debug(0, "%d records selected from table", nrec);
+    G_debug(3, "%d records selected from table", nrec);
 
     if (Mags) {
 	nrec = db_select_CatValArray(driver, fi->table, fi->key,
 				     mag_v, NULL, &cvarr_mag_v);
-	G_debug(0, "nrec (%s) = %d", mag_v, nrec);
+	G_debug(4, "nrec (%s) = %d", mag_v, nrec);
 
 	if (cvarr_mag_v.ctype != DB_C_TYPE_INT &&
 	    cvarr_mag_v.ctype != DB_C_TYPE_DOUBLE)
@@ -202,7 +206,7 @@
 
 	if (nrec < 0)
 	    G_fatal_error(_("Cannot select data (%s) from table"), mag_v);
-	G_debug(0, "%d records selected from table", nrec);
+	G_debug(3, "%d records selected from table", nrec);
     }
 
     Vect_rewind(Map);
@@ -216,7 +220,7 @@
 	    G_fatal_error(_("Can't read vector map"));
 	case -2:		/* EOF */
 	    db_close_database_shutdown_driver(driver);
-	    G_debug(0, "  Array fill done.");
+	    G_debug(3, "  Array fill done.");
 	    return;
 	}
 



More information about the grass-commit mailing list