function _weather_parse_phenomena in Weather 7
Same name and namespace in other branches
- 5.6 weather_parser.inc \_weather_parse_phenomena()
- 5 weather_parser.inc \_weather_parse_phenomena()
- 6.5 weather_parser.inc \_weather_parse_phenomena()
Extract phenomena information.
Parameters
string $metar_raw: Raw METAR data to parse.
object $metar: METAR data object, may be altered.
1 call to _weather_parse_phenomena()
- weather_parse_metar in ./
weather_parser.inc - Parses a raw METAR data string.
File
- ./
weather_parser.inc, line 346 - Retrieves and parses raw METAR data and stores result in database.
Code
function _weather_parse_phenomena($metar_raw, &$metar) {
// Handle rain
if (preg_match('/^' . '(-|\\+|VC)?' . '(SH|TS|FZ)?' . 'RA' . '$/', $metar_raw, $matches)) {
// Construct a result array of the following form:
// [light/heavy] [freezing] [rain] [showers]
$result[2] = 'rain';
$intensity = 'moderate';
if (isset($matches[1])) {
switch ($matches[1]) {
case '-':
$result[0] = 'light';
$intensity = 'light';
break;
case '+':
$result[0] = 'heavy';
$intensity = 'heavy';
break;
}
}
if (isset($matches[2])) {
switch ($matches[2]) {
case 'SH':
$result[3] = 'showers';
break;
case 'FZ':
$result[1] = 'freezing';
break;
}
}
ksort($result);
$metar->phenomena[] = implode(' ', $result);
// Store parts of the weather phenomena for image name construction.
$metar->image_part['precipitation'] = "{$intensity}-rain";
}
elseif (preg_match('/^' . '(-|\\+|VC)?' . '(FZ)?' . 'DZ' . '$/', $metar_raw, $matches)) {
// Construct a result array of the following form:
// [light/heavy] [freezing] [drizzle]
$result[2] = 'drizzle';
$intensity = 'moderate';
if (isset($matches[1])) {
switch ($matches[1]) {
case '-':
$result[0] = 'light';
$intensity = 'light';
break;
case '+':
$result[0] = 'heavy';
$intensity = 'heavy';
break;
}
}
if (isset($matches[2])) {
switch ($matches[2]) {
case 'FZ':
$result[1] = 'freezing';
break;
}
}
ksort($result);
$metar->phenomena[] = implode(' ', $result);
// Store parts of the weather phenomena for image name construction.
$metar->image_part['precipitation'] = "{$intensity}-rain";
}
elseif (preg_match('/^' . '(-|\\+|VC)?' . '(BL|DR|SH)?' . 'SN' . '$/', $metar_raw, $matches)) {
// Construct a result array of the following form:
// [light/heavy] [blowing/low driftig] [snow] [showers]
$result[2] = 'snow';
$intensity = 'moderate';
if (isset($matches[1])) {
switch ($matches[1]) {
case '-':
$result[0] = 'light';
$intensity = 'light';
break;
case '+':
$result[0] = 'heavy';
$intensity = 'heavy';
break;
}
}
if (isset($matches[2])) {
switch ($matches[2]) {
case 'BL':
$result[1] = 'blowing';
break;
case 'DR':
$result[1] = 'low drifting';
break;
case 'SH':
$result[3] = 'showers';
break;
}
}
ksort($result);
$metar->phenomena[] = implode(' ', $result);
// Store parts of the weather phenomena for image name construction.
$metar->image_part['precipitation'] = "{$intensity}-snow";
}
elseif (preg_match('/^' . 'BR' . '$/', $metar_raw, $matches)) {
$metar->phenomena[] = 'mist';
// Store parts of the weather phenomena for image name construction.
$metar->image_part['fog'] = 'fog';
}
elseif (preg_match('/^' . '(VC|MI|PR|BC|FZ)?' . 'FG' . '$/', $metar_raw, $matches)) {
// Construct a result array of the following form:
// [shallow/partial/patches of/freezing] [fog]
$result[1] = 'fog';
if (isset($matches[1])) {
switch ($matches[1]) {
case 'MI':
$result[0] = 'shallow';
break;
case 'PR':
$result[0] = 'partial';
break;
case 'BC':
$result[0] = 'patches of';
break;
case 'FZ':
$result[0] = 'freezing';
break;
}
}
ksort($result);
$metar->phenomena[] = implode(' ', $result);
// Store parts of the weather phenomena for image name construction.
$metar->image_part['fog'] = 'fog';
}
elseif (preg_match('/^' . 'FU' . '$/', $metar_raw, $matches)) {
$metar->phenomena[] = 'smoke';
// Store parts of the weather phenomena for image name construction.
$metar->image_part['fog'] = 'fog';
}
}