Calculating Wind Dir Labels..

I noticed a post from Tom …

I took a different approach. For a 16 point compass, I’ve been using for some time (when I started the Wx-Host weather icon generation stuff) the following routine…

Its basically just an array of the various values and a calculation based upon the wind direction provided in numerical format. Ie the WindDir element in clientraw.txt file (element #3)


$winddir = array ("N","NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S",  "SSW","SW", "WSW", "W", "WNN", "NW", "NNW");
$dir = $winddir[ (int) (gv($tg,3) / 22.5) ];

gv($tg,3) = Clientraw data ellement #3 = WindDir

Basically it takes the number and divides it by 22.5 to get the whole number that then corresponds with the wind lable. IF the number is non-zero, you end up with 0 = N.

Or as a PHP function:


function windDir ($winddir)
// Given the wind direction, return the text label
// for that value.  16 point compass
{
  if (!isset($winddir)) {
    return "---";
  }
$windlabel = array ("N","NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S",
   "SSW","SW", "WSW", "W", "WNN", "NW", "NNW");
$dir = $windlabel[ (int) ($winddir / 22.5) ];
return "$dir";
}

Kevin,
I use the same method in VPLive, except I add 11 to the degrees before dividing by 22.5. Then you can either do a mod 16 on the result or add another “N” to the wind label array. That way something like 88 degrees comes out as E instead of NNE.

Steve

smart…

New function using mod 16 with the 11 added first…

function windDir ($winddir) // Given the wind direction, return the text label // for that value. 16 point compass { if (!isset($winddir)) { return "---"; } $windlabel = array ("N","NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW","SW", "WSW", "W", "WNN", "NW", "NNW"); $dir = $windlabel[ fmod((($winddir + 11) / 22.5),16) ]; return "$dir"; }

Using PHP, I have a much more simple way to display with custom tags:

%dirlabel%

Basically it’s %dirlabel%.gif for displaying the GIF image arrows. (Works without PHP too!)

Of course, that doesn’t work for the client raw but I thought I’d add my two cents.