[wxqc] Text to Degrees
Steve Hatchett
steve at softwx.com
Mon Apr 9 00:08:42 CDT 2007
Yes, yours is more straightforward. I think he chose fmod so his function
would handle any positive degree value such as 450 degrees without
referencing a non-existent array element. If you know your range is limited
to 0-360 then you can simply add the extra "N" to the array as you've done.
This thread was where that function evolved:
http://www.weather-watch.com/smf/index.php/topic,18983.0.html
As for why I suggested the +11 to him instead of Round, my own code for this
is object pascal, and for performance I used all integer arithmetic wherever
possible as it was at one time much faster than floating point (although I
don't know if it makes that much difference now). I don't program in PHP so
I have no code for that. The actual code I use, which is the integer
equivalent of Round(value / 22.5) is:
Result := ((value + 11) * 2) div 45;
if (Result > 15) then Result := Result mod 16;
// where Result is the index into the label array
And converting from the label index to degrees is
Result := (value * 45) div 2;
Steve
-----Original Message-----
From: Keith Miller [mailto:kdmiller at oldsgmail.com]
Sent: Sunday, April 08, 2007 8:13 PM
To: 'Discussion of weather data quality issues'
Subject: Re: [wxqc] Text to Degrees
> -----Original Message-----
> From: wxqc-bounces at lists.gladstonefamily.net
[mailto:wxqc-bounces at lists.gladstonefamily.net]On Behalf Of Steve
Hatchett
> Sent: Sunday, April 08, 2007 9:52 PM
> To: 'Discussion of weather data quality issues'
> Subject: Re: [wxqc] Text to Degrees
>
>
> For converting degrees to text, I like the following:
> http://www.tnetweather.com/nb-0002.php
>
> which is basically a two line function
> $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) ];
>
Gee, that looks more complicated than mine:
function Deg2Card($degrees)
{
$cardinal = array('N','NNE', 'NE',
'ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW','
N');
return $cardinal[round(($degrees / 22.5), 0)];
}
Keith
--
CW5250 => http://weather.stadhaugh.com
_______________________________________________
wxqc mailing list
Post messages to wxqc at lists.gladstonefamily.net
To unsubcribe or change delivery options, please go to:
http://server.gladstonefamily.net/mailman/listinfo/wxqc
The contents of this message are the responsibility of the author.
More information about the wxqc
mailing list