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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Apr 3 03:53:37 EDT 2011


Author: hamish
Date: 2011-04-03 00:53:36 -0700 (Sun, 03 Apr 2011)
New Revision: 45830

Modified:
   grass-addons/display/d.barb/description.html
   grass-addons/display/d.barb/grid.c
   grass-addons/display/d.barb/points.c
Log:
add support for u,v component raster maps

Modified: grass-addons/display/d.barb/description.html
===================================================================
--- grass-addons/display/d.barb/description.html	2011-04-03 07:41:39 UTC (rev 45829)
+++ grass-addons/display/d.barb/description.html	2011-04-03 07:53:36 UTC (rev 45830)
@@ -17,7 +17,11 @@
 by the scale parameter.
 <P>
 Wind barbs assume velocity data is given in knots. Actually it
-doesn't care, but effectively maxes out at velo=150.
+doesn't care, but effectively maxes out at velo=150. When the
+style is set to wind barbs, the <b>scale</b> parameter becomes
+a magnitude multiplier instead of changing the size of the barb.
+In this way <b>scale</b>=<tt>1.852</tt> can be used to convert
+data stored in m/s to knots without altering the data.
 <!--
   units=
   m/s    m_per_sec

Modified: grass-addons/display/d.barb/grid.c
===================================================================
--- grass-addons/display/d.barb/grid.c	2011-04-03 07:41:39 UTC (rev 45829)
+++ grass-addons/display/d.barb/grid.c	2011-04-03 07:53:36 UTC (rev 45830)
@@ -20,8 +20,8 @@
     struct Cell_head window;
     int nrows, ncols, row, col;
     int no_arrow;		/* boolean */
-    float aspect_f = -1.0;
-    float length = -1.0;
+    double aspect_f = -1.0, theta;
+    double length = -1.0, r;
     double easting, northing;
 
     G_debug(0, "Doing Eulerian field ...");
@@ -103,13 +103,12 @@
 	    else if (mag_v_raster_type == DCELL_TYPE)
 		length = *((DCELL *) mag_v_ptr);
 
-	    length *= scale;
 
 	    if (G_is_null_value(mag_v_ptr, mag_v_raster_type)) {
 		G_debug(5, "Invalid arrow length [NULL]. Skipping.");
 		no_arrow = TRUE;
 	    }
-	    else if (length <= 0.0) {	/* use fabs() or theta+=180? */
+	    else if (length < 0 && !is_component) {	/* use fabs() or theta+=180? */
 		G_debug(5, "Illegal arrow length [%.3f]. Skipping.", length);
 		no_arrow = TRUE;
 	    }
@@ -126,7 +125,29 @@
 		continue;
 	    }
 
+	    if(is_component) {
+		/* convert u,v to dir,mag */
+		r = sqrt(length*length + aspect_f*aspect_f);
+		theta = R2D(atan2(length, aspect_f));
+		length = r;
+		aspect_f = theta;
+		if(aspect_f < 0)
+		    aspect_f += 360;
+		else if (aspect_f > 360)
+		    aspect_f -= 360;
+	    }
 
+	    /* convert cartesian to compass convention */
+	    if (aspect_type == TYPE_GRASS)
+		aspect_f = 90 - aspect_f;
+
+	    if(aspect_f < 0)
+		aspect_f += 360;
+	    else if (aspect_f > 360)
+		aspect_f -= 360;
+
+	    length *= scale;
+
 	   /** Now draw the arrows **/
 	    if (G_is_null_value(dir_u_ptr, dir_u_raster_type))
 		continue;
@@ -136,20 +157,16 @@
 	    easting = G_col_to_easting(col + 0.5, &window);
 	    northing = G_row_to_northing(row + 0.5, &window);
 
-	    /* case switch for standard GRASS aspect map 
-	       measured in degrees counter-clockwise from east */
+
 	    if (aspect_f >= 0.0 && aspect_f <= 360.0) {
 		if (mag_v_map) {
-		    if (aspect_type == TYPE_GRASS)
-			draw_barb(easting, northing, length, aspect_f, 
-				  color, scale, style);
-		    else
-			draw_barb(easting, northing, length, 90 - aspect_f, 
-				  color, scale, style);
+		    draw_barb(easting, northing, length, aspect_f,
+			      color, scale, style);
 		}
 		else {
-		    if (aspect_type == TYPE_GRASS) ;	//todo   arrow_360(aspect_f);
-		    else;	//  arrow_360(90 - aspect_f);
+		    //todo   arrow_360(aspect_f);
+		    draw_barb(easting, northing, 1.0, aspect_f,
+			      color, scale, style);
 		}
 	    }
 	    else {

Modified: grass-addons/display/d.barb/points.c
===================================================================
--- grass-addons/display/d.barb/points.c	2011-04-03 07:41:39 UTC (rev 45829)
+++ grass-addons/display/d.barb/points.c	2011-04-03 07:53:36 UTC (rev 45830)
@@ -269,7 +269,7 @@
     }
 
     db_close_database_shutdown_driver(driver);
-    return;			/* shouldn't get here */
+    return;	/* shouldn't get here */
 }
 
 



More information about the grass-commit mailing list