Weather-Watch.com
July 04, 2009, 02:04:11 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Members: 8,160  Posts: 313,111  Topics: 34,636
Please welcome Han, our newest member.

Latest versions: WD - 10.37O  WDL - 6.05  MML - 1.03
 News:
Check out the new FAQs (Frequently Asked Questions) board for a growing list of hints, tips and diagnostic suggestions.
  Advanced Search
   Home   Bug Tracker Photo Gallery Wiki Chat Calendar Search Login Register Help  
Pages: [1]
  Print  |  « previous  |  next »  |  Go Down  
Author Topic: Calculating Wind Dir Labels..  (Read 827 times)
0 Members and 1 Guest are viewing this topic.
TNETWeather
Kevin Reed (KrelvinAZ)
Weather Controller
*****
Offline Offline

Location: Mesa, AZ
Station Type: Davis Vantage Pro2 Plus W/FARS Wireless
Posts: 5,168
Local Time: Saturday 08:04


Gremlins are at work...


WWW
« 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:
$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.
Logged

All you need is Time, Aptitude and Desire ... and you can build just about anything...
Got a question about a script on the forum, post it IN the forum instead of PM unless asked to.
TNETWeather
Kevin Reed (KrelvinAZ)
Weather Controller
*****
Offline Offline

Location: Mesa, AZ
Station Type: Davis Vantage Pro2 Plus W/FARS Wireless
Posts: 5,168
Local Time: Saturday 08:04


Gremlins are at work...


WWW
« Reply #1 on: September 30, 2006, 04:51:51 PM »

Or as a PHP function:

Code:
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";
}
Logged

All you need is Time, Aptitude and Desire ... and you can build just about anything...
Got a question about a script on the forum, post it IN the forum instead of PM unless asked to.
SoftWx
Weather Guru
**
Offline Offline

Station Type: VP 2, daytime FARS, Solar, DIY Rain Heater
Posts: 797
Local Time: Saturday 14:04


WWW
« 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
Logged
TNETWeather
Kevin Reed (KrelvinAZ)
Weather Controller
*****
Offline Offline

Location: Mesa, AZ
Station Type: Davis Vantage Pro2 Plus W/FARS Wireless
Posts: 5,168
Local Time: Saturday 08:04


Gremlins are at work...


WWW
« 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 » Logged

All you need is Time, Aptitude and Desire ... and you can build just about anything...
Got a question about a script on the forum, post it IN the forum instead of PM unless asked to.
carterlake
Tom Chaplin
Junior Weather Controller
****
Offline Offline

Location: Carter Lake, Iowa USA
Posts: 2,274
Local Time: Saturday 09:04



WWW
« 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 » Logged


WD; Davis VP2 6153; Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; Live NOAA radio
Pages: [1]
  Print  |  « previous  |  next »  |  Go Up  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!