function _weather_parse_sky_condition in Weather 7
Extract sky condition information.
Parameters
string $metar_raw: Raw METAR data to parse.
object $metar: METAR data object, may be altered.
1 call to _weather_parse_sky_condition()
- weather_parse_metar in ./
weather_parser.inc - Parses a raw METAR data string.
File
- ./
weather_parser.inc, line 261 - Retrieves and parses raw METAR data and stores result in database.
Code
function _weather_parse_sky_condition($metar_raw, &$metar) {
// The ordering of cloud covering is as follows:
// 0, CLR: clear
// 1, FEW: few
// 2, SCT: scattered
// 3, BKN: broken
// 4, OVC: overcast
if (preg_match('/^' . '(FEW|SCT|BKN|OVC)([0-9]{3})' . '(CB|TCU)?(\\/\\/\\/)?' . '$/', $metar_raw, $matches)) {
switch ($matches[1]) {
case 'CLR':
$metar->sky_condition_order[] = 0;
$metar->sky_condition_text[] = 'clear';
break;
case 'FEW':
$metar->sky_condition_order[] = 1;
$metar->sky_condition_text[] = 'few';
break;
case 'SCT':
$metar->sky_condition_order[] = 2;
$metar->sky_condition_text[] = 'scattered';
break;
case 'BKN':
$metar->sky_condition_order[] = 3;
$metar->sky_condition_text[] = 'broken';
break;
case 'OVC':
$metar->sky_condition_order[] = 4;
$metar->sky_condition_text[] = 'overcast';
break;
}
}
elseif (preg_match('/^' . '(CLR|SKC|CAVOK)' . '$/', $metar_raw, $matches)) {
$metar->sky_condition_order[] = 0;
$metar->sky_condition_text[] = 'clear';
// CAVOK implies a visibility of 10 km, there's no extra visibility section.
if ($matches[1] == 'CAVOK') {
$metar->visibility = 10000;
}
}
elseif (preg_match('/^' . '(NSC|NCD)' . '$/', $metar_raw, $matches)) {
// NSC means no significant clouds,
// NCD is from automatic stations, no cloud detected
// The ordering is equivalent to "FEW"
$metar->sky_condition_order[] = 1;
$metar->sky_condition_text[] = 'no significant clouds';
}
elseif (preg_match('/^' . 'VV[0-9\\/]{3}' . '$/', $metar_raw, $matches)) {
// VV is the vertical visibility, this should be shown as overcast.
// If no information is available, VV/// will be used.
$metar->sky_condition_order[] = 4;
$metar->sky_condition_text[] = 'overcast';
}
if (isset($metar->sky_condition_order)) {
if (isset($metar->current_sky_condition_order)) {
foreach ($metar->sky_condition_order as $index => $order) {
if ($order > $metar->current_sky_condition_order) {
$metar->current_sky_condition_order = $order;
$metar->sky_condition = $metar->sky_condition_text[$index];
}
}
}
else {
$metar->current_sky_condition_order = $metar->sky_condition_order[0];
$metar->sky_condition = $metar->sky_condition_text[0];
}
}
}