[Printable]
Share

Windspeed to Beaufort Converter

Posted: Wed 19th January 2005 in Blog

Description

 

Bf_Convert ( float windspeed, int format)


  This is a PHP function to convert a wind speed in knots to a Beaufort scale. Takes a speed in knots and returns either the description (e.g. "Strong Breeze"), the Beaufort number, or both.

Parameter List

 

speed



the wind speed you want converted to Beaufort in Knots (nautical Miles per Hour)

format



an integer which tells the function what sort of out put you want:

  • 1 return the Beaufort Scale Force Number for the Wind Speed.
  • 2 return the Beaufort Scale Name for the Wind Speed (e.g. "Strong Breeze")
  • 3 return both, separated by a comma, (eg "5, Strong breeze")
    Return Values

      Returns either a number or a string of the Beaufort Scale equivalent of the current wind speed.

    Example 1. Bf_convert() example

     

    echo Bf_convert(23.1,2);

    ?>

  • The above will output:


    Strong Breeze


    CODE:

    function Bf_Convert ($speed, $return) {
    switch ($speed) {
    case ($speed < 1):
    $bf=0; $desc = 'Calm';
    break;
    case ($speed < 4):
    $bf=1; $desc = 'Light Air';
    break;
    case ($speed < 7):
    $bf=2; $desc = 'Light Breeze';
    break;
    case ($speed < 11):
    $bf=3; $desc = 'Gentle Breeze';
    break;
    case ($speed < 17):
    $bf=4; $desc = 'Moderate Breeze';
    break;
    case ($speed < 22):
    $bf=5; $desc = 'Fresh Breeze';
    break;
    case ($speed < 28):
    $bf=6; $desc = 'Strong Breeze';
    break;
    case ($speed < 34):
    $bf=7; $desc = 'Near Gale';
    break;
    case ($speed < 41):
    $bf=8; $desc = 'Gale';
    break;
    case ($speed < 48):
    $bf=9; $desc = 'Strong Gale';
    break;
    case ($speed < 56):
    $bf=10; $desc = 'Storm';
    break;
    case ($speed < 64):
    $bf=11; $desc = 'Severe Storm';
    break;
    case ($speed > 64):
    $bf=12; $desc = 'Huricane';
    break;
    };
    //right decide what to output
    switch ($return) {
    case 1: $out = $bf;
    break;
    case 2: $out = $desc;
    break;
    case 3: $out = ("$bf, $desc");
    break;
    };
    return("$out");
    };
    [Printable]
    Share

    Windspeed to Beaufort Converter

    Posted: Wed 19th January 2005 in Blog

    Windspeed to Beaufort Converter

    Description

     

    Bf_Convert ( float windspeed, int format)


      This is a PHP function to convert a wind speed in knots to a Beaufort scale. Takes a speed in knots and returns either the description (e.g. "Strong Breeze"), the Beaufort number, or both.

    Parameter List

     

    speed



    the wind speed you want converted to Beaufort in Knots (nautical Miles per Hour)

    format



    an integer which tells the function what sort of out put you want:

  • 1 return the Beaufort Scale Force Number for the Wind Speed.
  • 2 return the Beaufort Scale Name for the Wind Speed (e.g. "Strong Breeze")
  • 3 return both, separated by a comma, (eg "5, Strong breeze")
    Return Values

      Returns either a number or a string of the Beaufort Scale equivalent of the current wind speed.

    Example 1. Bf_convert() example

     

    echo Bf_convert(23.1,2);

    ?>

  • The above will output:


    Strong Breeze


    CODE:

    function Bf_Convert ($speed, $return) {
    switch ($speed) {
    case ($speed < 1):
    $bf=0; $desc = 'Calm';
    break;
    case ($speed < 4):
    $bf=1; $desc = 'Light Air';
    break;
    case ($speed < 7):
    $bf=2; $desc = 'Light Breeze';
    break;
    case ($speed < 11):
    $bf=3; $desc = 'Gentle Breeze';
    break;
    case ($speed < 17):
    $bf=4; $desc = 'Moderate Breeze';
    break;
    case ($speed < 22):
    $bf=5; $desc = 'Fresh Breeze';
    break;
    case ($speed < 28):
    $bf=6; $desc = 'Strong Breeze';
    break;
    case ($speed < 34):
    $bf=7; $desc = 'Near Gale';
    break;
    case ($speed < 41):
    $bf=8; $desc = 'Gale';
    break;
    case ($speed < 48):
    $bf=9; $desc = 'Strong Gale';
    break;
    case ($speed < 56):
    $bf=10; $desc = 'Storm';
    break;
    case ($speed < 64):
    $bf=11; $desc = 'Severe Storm';
    break;
    case ($speed > 64):
    $bf=12; $desc = 'Huricane';
    break;
    };
    //right decide what to output
    switch ($return) {
    case 1: $out = $bf;
    break;
    case 2: $out = $desc;
    break;
    case 3: $out = ("$bf, $desc");
    break;
    };
    return("$out");
    };