Weather data (direction) should always be reported in degrees true.
Some of you have a desire / need to report wind direction degrees MAGNETIC - this shouldn't really be 'published' or on a 'weather' page.
So, for those with a need to create some sort of MAGNETIC direction 'advisory', and have their wind vane aligned 'true North', and are using <#webtags> in their 'advisory' template .....
In the <head> section of your <#webtags> Template page:
Code: Select all
<script type="text/javascript">
var mag_deviation = 24; // difference between 'local' 360 TRUE North and MAGNETIC North
// +ve for True is East of Mag N, -ve for True is West of Mag N
// function to convert degrees True to degrees MAGNETIC
function toMAG(deg, subvert){
newDeg = deg - mag_deviation;
if(newDeg < 1){ newDeg = newDeg +360;} // will happen with +ve mag_deviation
if(newDeg > 360){newDeg = newDeg -360;} // will happen with -ve mag_deviation
// cosmetic 'default' - ANY (logical true) value for 'subvert' will return a number for further processing
if(!subvert) {newDeg += "°M";} // may be commented out if not required
return newDeg;
} // END function toMAG
</script>Code: Select all
Current wind direction is <script>document.write(toMAG(<#bearing));</script><noscript><#bearing>° true</noscript>
Current wind direction is 21°M (JavaScript enabled browser)
Current wind direction is 45° true (JavaScript DISabled browser)
An advanced codester may wish to use the above simple function together with some sort of ajax routine using realtime.txt or whatever - you're on your own
Some interesting reading on MAGNETIC North:
http://en.wikipedia.org/wiki/North_Magnetic_Pole
http://en.wikipedia.org/wiki/Magnetic_declination