You are here

function weather_format_windchill_temperature in Weather 7.3

Same name and namespace in other branches
  1. 7.2 weather_theme.inc \weather_format_windchill_temperature()

Calculates windchill temperature.

Windchill temperature is only defined for temperatures at or below 10 °C (50 °F) and wind speeds above 1.34 m/s (3 mph). Bright sunshine may increase the wind chill temperature. @link http://en.wikipedia.org/wiki/Wind_chill.

Parameters

int $temperature: Temperature in degree celsius.

int $wind_speed: Wind speed in m/s.

string $unit: Unit to be returned (celsius, fahrenheit, ...).

Return value

string Formatted representation in the desired unit. If the windchill is not defined for the current conditions, returns NULL.

1 call to weather_format_windchill_temperature()
theme_weather_forecast_preprocess in ./weather_theme.inc
Custom theme function for preprocessing the weather display.

File

./weather_theme.inc, line 261
Prepare themed weather output.

Code

function weather_format_windchill_temperature($temperature, $wind_speed, $unit) {

  // Set up the empty result, if windchill temperature is not defined
  // for current conditions.
  $result = NULL;

  // First, check conditions for windchill temperature.
  if ($temperature <= 10 and $wind_speed >= 1.34) {

    // Convert wind speed to km/h for formula.
    $wind_speed = $wind_speed * 3.6;

    // Calculate windchill (in degree Celsius).
    // The integer cast is necessary to avoid a result of '-0°C'.
    $windchill = (int) round(13.12 + 0.6215000000000001 * $temperature - 11.37 * pow($wind_speed, 0.16) + 0.3965 * $temperature * pow($wind_speed, 0.16));
    $result = weather_format_temperature($windchill, $unit);
  }
  return $result;
}