function _weather_format_temperature in Weather 6.5
Same name and namespace in other branches
- 5.6 weather.module \_weather_format_temperature()
- 5 weather.module \_weather_format_temperature()
Convert temperatures and calculate wind chill
Windchill temperature is only defined for temperatures at or below 50 °F and wind speeds above 3 mph. Bright sunshine may increase the wind chill temperature by 10 to 18 degrees F. @link http://www.weather.gov/os/windchill/windchillglossary.shtml
Parameters
array Temperature data:
array Wind data:
array The unit to be returned (celsius, fahrenheit):
array The display setting, whether to show windchill:
Return value
array Formatted representation, either in celsius or fahrenheit with the wind chill calculated
1 call to _weather_format_temperature()
- theme_weather_theming in ./
weather.module - Custom theme function for preprocessing the weather block output
File
- ./
weather.module, line 1527 - Display <acronym title="METeorological Aerodrome Report">METAR</acronym> weather data from anywhere in the world
Code
function _weather_format_temperature($temperature, $wind, $unit, $settings) {
if (isset($settings['show_windchill']) and $settings['show_windchill'] == TRUE and $temperature['fahrenheit'] <= 50 and $wind['speed_mph'] >= 3) {
// Calculate windchill (in degree Fahrenheit)
$windchill['fahrenheit'] = round(35.74 + 0.6215000000000001 * $temperature['fahrenheit'] - 35.75 * pow($wind['speed_mph'], 0.16) + 0.4275 * $temperature['fahrenheit'] * pow($wind['speed_mph'], 0.16), 1);
$windchill['celsius'] = round(($windchill['fahrenheit'] - 32) * 5 / 9, 1);
if ($unit['temperature'] == 'fahrenheit') {
$result['temperature_windchill'] = t('!temperature °F', array(
'!temperature' => $windchill['fahrenheit'],
));
}
elseif ($unit['temperature'] == 'celsiusfahrenheit') {
$result['temperature_windchill'] = t('!temperature_c °C / !temperature_f °F', array(
'!temperature_c' => $windchill['celsius'],
'!temperature_f' => $windchill['fahrenheit'],
));
}
elseif ($unit['temperature'] == 'fahrenheitcelsius') {
$result['temperature_windchill'] = t('!temperature_f °F / !temperature_c °C', array(
'!temperature_f' => $windchill['fahrenheit'],
'!temperature_c' => $windchill['celsius'],
));
}
else {
// default to metric units
$result['temperature_windchill'] = t('!temperature °C', array(
'!temperature' => $windchill['celsius'],
));
}
}
// Format the temperature
if ($unit['temperature'] == 'fahrenheit') {
$result['temperature'] = t('!temperature °F', array(
'!temperature' => $temperature['fahrenheit'],
));
}
elseif ($unit['temperature'] == 'celsiusfahrenheit') {
$result['temperature'] = t('!temperature_c °C / !temperature_f °F', array(
'!temperature_c' => $temperature['celsius'],
'!temperature_f' => $temperature['fahrenheit'],
));
}
elseif ($unit['temperature'] == 'fahrenheitcelsius') {
$result['temperature'] = t('!temperature_f °F / !temperature_c °C', array(
'!temperature_f' => $temperature['fahrenheit'],
'!temperature_c' => $temperature['celsius'],
));
}
else {
// default to metric units
$result['temperature'] = t('!temperature °C', array(
'!temperature' => $temperature['celsius'],
));
}
return preg_replace("/([^ ]*) ([^ ]*)/", '<span style="white-space:nowrap;">\\1 \\2</span>', $result);
}