cloudy

Author Topic: Calculating Wind Dir Labels..  (Read 1552 times)

0 Members and 1 Guest are viewing this topic.

Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,859
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Calculating Wind Dir Labels..
« on: September 30, 2006, 04:41:08 PM »
I noticed a post from Tom ...


  // figure out a text value for compass direction
   switch (TRUE) {
     case (($winddir >= 349) and ($winddir <= 360)):
       $winddir = 'N';
     break;
     case (($winddir >= 0) and ($winddir <= 11)):
       $winddir = 'N';
snip....

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)

Code: [Select]
$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.

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,859
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: Calculating Wind Dir Labels..
« Reply #1 on: September 30, 2006, 04:51:51 PM »
Or as a PHP function:

Code: [Select]
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";
}

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline SoftWx

  • Posts: 832
    • SoftWx
Re: Calculating Wind Dir Labels..
« Reply #2 on: September 30, 2006, 05:05:42 PM »
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

Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,859
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: Calculating Wind Dir Labels..
« Reply #3 on: September 30, 2006, 05:14:02 PM »
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";
}

« Last Edit: September 30, 2006, 05:23:58 PM by krelvinaz »

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline carterlake

  • Tom Chaplin
  • Posts: 2,273
  • Carter Lake, Iowa USA
    • Carter Lake, Iowa Weather
Re: Calculating Wind Dir Labels..
« Reply #4 on: September 30, 2006, 06:06:33 PM »
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.
« Last Edit: September 30, 2006, 06:08:17 PM by carterlake »

WD; Davis VP2 6153; Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; Live NOAA radio