Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Share:
Notifications
Clear all

[Solved] Pascal - How to convert Degrees to Wind Direction

1 Posts
1 Users
0 Reactions
1,272 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

I had to write a quick procedure to convert degrees (0 to 360 degrees) to text wind direction, and thought I'd share it here as I could not find any examples online ...

The function takes a floating point number and returns a string.

function DegreesToWindDirection(Degrees:Double):string;
var WindDirection:string;
const North = 'N'; // Translate/change if needed
      South = 'S';
      East = 'E';
      West = 'W';
      Error = 'Error';
begin
  if (Degrees<0) or (Degrees>360) then
    WindDirection:=Error
  else if Degrees<= 11.25 then
    WindDirection:=North
  else if Degrees<= 33.75 then
    WindDirection:=North+North+East
  else if Degrees<= 56.25 then
    WindDirection:=North+East
  else if Degrees<= 78.75 then
    WindDirection:=East+North+East
  else if Degrees<= 101.25 then
    WindDirection:=East
  else if Degrees<= 123.75 then
    WindDirection:=East+South+East
  else if Degrees<= 146.25 then
    WindDirection:=South+East
  else if Degrees<= 168.75 then
    WindDirection:=South+South+East
  else if Degrees<= 191.25 then
    WindDirection:=South
  else if Degrees<= 213.75 then
    WindDirection:=South+South+West
  else if Degrees<= 236.25 then
    WindDirection:=South+West
  else if Degrees<= 258.75 then
    WindDirection:=West+South+West
  else if Degrees<= 281.25 then
    WindDirection:=West
  else if Degrees<= 303.75 then
    WindDirection:=West+North+West
  else if Degrees<= 326.25 then
    WindDirection:=North+West
  else if Degrees<= 348.75 then
    WindDirection:=North+North+West
  else if Degrees<= 360 then
    WindDirection:=North;
  DegreesToWindDirection:=WindDirection;
end;           

   
ReplyQuote
Share: