function _weather_parse_wind in Weather 7
Same name and namespace in other branches
- 5.6 weather_parser.inc \_weather_parse_wind()
- 5 weather_parser.inc \_weather_parse_wind()
- 6.5 weather_parser.inc \_weather_parse_wind()
Extract wind information.
Parameters
string $metar_raw: Raw METAR data to parse.
object $metar: METAR data object, may be altered.
1 call to _weather_parse_wind()
- weather_parse_metar in ./
weather_parser.inc - Parses a raw METAR data string.
File
- ./
weather_parser.inc, line 512 - Retrieves and parses raw METAR data and stores result in database.
Code
function _weather_parse_wind($metar_raw, &$metar) {
if (preg_match('/^' . '([0-9]{3}|VRB)' . '([0-9]{2,3})' . '(G([0-9]{2,3}))?' . '(KT|MPS|KMH)' . '$/', $metar_raw, $matches)) {
if ($matches[1] == 'VRB') {
$metar->wind_direction = 'variable';
}
else {
$metar->wind_direction = (int) $matches[1];
}
$wind_speed = (int) $matches[2];
$wind_gusts = (int) $matches[4];
$wind_unit = $matches[5];
// Ensure that windspeed is in km/h.
switch ($wind_unit) {
case 'KT':
// Convert from knots (1 knot = 1.852 km/h)
$metar->wind_speed = round($wind_speed * 1.852, 1);
if ($wind_gusts > 0) {
$metar->wind_gusts = round($wind_gusts * 1.852, 1);
}
break;
case 'MPS':
// Convert from meter/s (1 m/s = 3.6 km/h)
$metar->wind_speed = round($wind_speed * 3.6, 1);
if ($wind_gusts > 0) {
$metar->wind_gusts = round($wind_gusts * 3.6, 1);
}
break;
case 'KMH':
$metar->wind_speed = $wind_speed;
if ($wind_gusts > 0) {
$metar->wind_gusts = $wind_gusts;
}
break;
}
}
elseif (preg_match('/^' . '([0-9]{3})' . 'V' . '([0-9]{3})' . '$/', $metar_raw, $matches)) {
$metar->wind_direction = $matches[1] . '-' . $matches[2];
}
}