You are here

function _weather_format_wind in Weather 5.6

Same name and namespace in other branches
  1. 5 weather.module \_weather_format_wind()
  2. 6.5 weather.module \_weather_format_wind()

Convert wind

Parameters

int Wind:

string The unit to be returned (km/h, knots, meter/s, mph):

array Settings, used for abbreviated wind directions:

Return value

string Formatted representation

1 call to _weather_format_wind()
theme_weather in ./weather.module
Custom theme function for the weather block output

File

./weather.module, line 1102
Display <acronym title="METeorological Aerodrome Report">METAR</acronym> weather data from anywhere in the world

Code

function _weather_format_wind($wind, $unit, $settings) {

  // shortcut for a special case
  if ($wind['direction'] == 0 and $wind['speed_kmh'] == 0) {
    return t('Calm');
  }
  $wind['direction_text'] = weather_bearing_to_text($wind['direction']);
  $wind['direction_text_short'] = weather_bearing_to_text($wind['direction'], TRUE);
  if (isset($wind['variable_start'])) {
    $wind['variable_start_text'] = weather_bearing_to_text($wind['variable_start']);
    $wind['variable_start_text_short'] = weather_bearing_to_text($wind['variable_start'], TRUE);
  }
  if (isset($wind['variable_end'])) {
    $wind['variable_end_text'] = weather_bearing_to_text($wind['variable_end']);
    $wind['variable_end_text_short'] = weather_bearing_to_text($wind['variable_end'], TRUE);
  }

  // handle variable wind directions
  if ($wind['direction'] == 'VRB' or isset($wind['variable_start'])) {
    if (isset($wind['variable_start'])) {
      if ($settings['show_abbreviated_directions']) {
        if ($settings['show_directions_degree']) {
          $result[] = t('Variable from !direction_a (!degree_a°) to !direction_b (!degree_b°)', array(
            '!direction_a' => $wind['variable_start_text_short'],
            '!degree_a' => $wind['variable_start'],
            '!direction_b' => $wind['variable_end_text_short'],
            '!degree_b' => $wind['variable_end'],
          ));
        }
        else {
          $result[] = t('Variable from !direction_a to !direction_b', array(
            '!direction_a' => $wind['variable_start_text_short'],
            '!direction_b' => $wind['variable_end_text_short'],
          ));
        }
      }
      else {
        if ($settings['show_directions_degree']) {
          $result[] = t('Variable from !direction_a (!degree_a°) to !direction_b (!degree_b°)', array(
            '!direction_a' => $wind['variable_start_text'],
            '!degree_a' => $wind['variable_start'],
            '!direction_b' => $wind['variable_end_text'],
            '!degree_b' => $wind['variable_end'],
          ));
        }
        else {
          $result[] = t('Variable from !direction_a to !direction_b', array(
            '!direction_a' => $wind['variable_start_text'],
            '!direction_b' => $wind['variable_end_text'],
          ));
        }
      }
    }
    else {
      $result[] = t('Variable');
    }
  }
  else {

    // no variable wind direction, but an exact one
    if ($settings['show_abbreviated_directions']) {
      if ($settings['show_directions_degree']) {
        $result[] = t('!direction (!degree°)', array(
          '!direction' => $wind['direction_text_short'],
          '!degree' => $wind['direction'],
        ));
      }
      else {
        $result[] = $wind['direction_text_short'];
      }
    }
    else {
      if ($settings['show_directions_degree']) {
        $result[] = t('!direction (!degree°)', array(
          '!direction' => $wind['direction_text'],
          '!degree' => $wind['direction'],
        ));
      }
      else {
        $result[] = $wind['direction_text'];
      }
    }
  }

  // set up the wind speed
  if ($unit['windspeed'] == 'mph') {
    $result[] = t('!speed mph', array(
      '!speed' => $wind['speed_mph'],
    ));
  }
  else {
    if ($unit['windspeed'] == 'knots') {
      $result[] = t('!speed knots', array(
        '!speed' => $wind['speed_knots'],
      ));
    }
    else {
      if ($unit['windspeed'] == 'mps') {
        $result[] = t('!speed meter/s', array(
          '!speed' => $wind['speed_mps'],
        ));
      }
      else {
        if ($unit['windspeed'] == 'beaufort') {
          $result[] = t('Beaufort !number', array(
            '!number' => $wind['speed_beaufort'],
          ));
        }
        else {

          // default to metric units
          $result[] = t('!speed km/h', array(
            '!speed' => $wind['speed_kmh'],
          ));
        }
      }
    }
  }

  // set up gusts, if applicable
  if ($wind['gusts_kmh'] > 0) {
    if ($unit['windspeed'] == 'mph') {
      $result[] = t('gusts up to !speed mph', array(
        '!speed' => $wind['gusts_mph'],
      ));
    }
    else {
      if ($unit['windspeed'] == 'knots') {
        $result[] = t('gusts up to !speed knots', array(
          '!speed' => $wind['gusts_knots'],
        ));
      }
      else {
        if ($unit['windspeed'] == 'mps') {
          $result[] = t('gusts up to !speed meter/s', array(
            '!speed' => $wind['gusts_mps'],
          ));
        }
        else {
          if ($unit['windspeed'] == 'beaufort') {
            $result[] = t('gusts up to Beaufort !number', array(
              '!number' => $wind['gusts_beaufort'],
            ));
          }
          else {

            // default to metric units
            $result[] = t('gusts up to !speed km/h', array(
              '!speed' => $wind['gusts_kmh'],
            ));
          }
        }
      }
    }
  }
  return join(', ', $result);
}