[Phphtmllib-devel] SF.net SVN: phphtmllib:[3526] trunk/open2300/lib/modules/api/ AviationWeather.in
Status: Beta
Brought to you by:
hemna
From: <he...@us...> - 2010-06-30 22:51:01
|
Revision: 3526 http://phphtmllib.svn.sourceforge.net/phphtmllib/?rev=3526&view=rev Author: hemna Date: 2010-06-30 22:50:55 +0000 (Wed, 30 Jun 2010) Log Message: ----------- VFR conditions Modified Paths: -------------- trunk/open2300/lib/modules/api/AviationWeather.inc Modified: trunk/open2300/lib/modules/api/AviationWeather.inc =================================================================== --- trunk/open2300/lib/modules/api/AviationWeather.inc 2010-06-28 23:27:13 UTC (rev 3525) +++ trunk/open2300/lib/modules/api/AviationWeather.inc 2010-06-30 22:50:55 UTC (rev 3526) @@ -57,7 +57,7 @@ $cache_key = "METAR_".$icao; $info = $this->cache->get($cache_key); - if ($info) { + if ($info && false) { $wxInfo = $info; return $wxInfo; } @@ -70,6 +70,7 @@ $this->process_metar($metar, $wxInfo); $wxInfo["metar"] = $metar; + $this->decide_vfr($wxInfo); if ($airport != null) { $wxInfo["runways"] = $this->get_runways($airport, $wxInfo); @@ -392,6 +393,7 @@ if (strlen($part) == 1) { // visibility is limited to a whole mile plus a fraction part $integerMile = $part . ' '; $metarPtr++; + $wxInfo["vis_distance"] = $integerMile; } else if (substr($part,-2) == 'SM') { // visibility is in miles $part = substr($part,0,strlen($part)-2); if (substr($part,0,1) == 'M') { @@ -408,6 +410,8 @@ $wxInfo['Visibility'] = $prefix . $integerMile . $part . $unit; $metarPtr++; $group++; + + $wxInfo["vis_distance"] = $integerMile.$part; } else if (substr($part,-2) == 'KM') { // unknown (Reported by NFFN in Fiji) $metarPtr++; @@ -421,6 +425,8 @@ $wxInfo['Visibility'] = $distance . $unit; $metarPtr++; $group++; + + $wxInfo["vis_distance"] = $distance; } else if ($part == 'CAVOK') { // good weather $wxInfo['Visibility'] = 'greater than 7 miles'; // or 10 km @@ -428,6 +434,9 @@ $wxInfo['Clouds'] = 'clear skies'; $metarPtr++; $group += 4; // can skip the next 3 groups + + //just need to mark this as > 5 + $wxInfo["vis_distance"] = 10; } else { $group++; @@ -525,6 +534,7 @@ 'VV' => 'vertical visibility'); if ($part == 'SKC' || $part == 'CLR') { $wxInfo['Clouds'] = $cloudCode[$part]; + $this->add_cloud_entry($part, $cloudCode[$part], "", $wxInfo); $metarPtr++; $group++; } @@ -535,6 +545,11 @@ $altitude = (integer) 100 * $pieces[2]; // units are feet $wxInfo['Clouds'] .= " at $altitude ft"; // } + $code = substr($part,0,2); + if ($code != "VV") { + $code = substr($part,0,3); + } + $this->add_cloud_entry($code, $clodeCode[$part], $altitude, $wxInfo); $metarPtr++; } else { @@ -542,6 +557,20 @@ } } } + + private function add_cloud_entry($code, $human, $altitude, &$wxInfo) { + $newEntry = array("code" => $code, "human" => $human, "altitude" => $altitude); + $wxInfo['CloudArr'][] = $newEntry; + if (!empty($altitude) && !isset($wxInfo['lowestClouds'])) { + $wxInfo['lowestClouds'] = $newEntry; + } else if (!empty($altitude)) { + if ($wxInfo['lowestClouds']['altitude'] > $altitude) { + $wxInfo['lowestClouds'] = $newEntry; + } + } + } + + protected function get_heat_index($tempF, $rh, &$wxInfo) { // Calculate Heat Index based on temperature in F and relative humidity (65 = 65%) if ($tempF > 79 && $rh > 39) { @@ -835,9 +864,8 @@ $densalt = $densaltzm*$ft_per_m; if ( $densalt > 36090 || $densalt < -15000 ) { - - var_dump ("Out of range for Troposhere Algorithm: Altitude =" . round($densalt,0) . " feet" ); - return; + Log::singleton()->err("AviationWeather::density_altitude($altitude, $Pmb, $PinHg, $tempC, $dewC) -- Out of range for Troposhere Algorithm: Altitude =" . round($densalt,0) . " feet" ); + return null; } return round($densalt,0); @@ -950,6 +978,64 @@ } return false; } + + + + /** + * decide what meteorological conditions + * the airport is in. + * + * @see http://aviationweather.gov/adds/metars/description_ifr.php + */ + function decide_vfr($wxInfo) { + //first lets try the easy approach. + //if we have > 5 miles visibility + if ($wxInfo["vis_distance"] >= 5) { + //clouds need to be > 3000 AGL + if ($wxInfo["lowestClouds"]["altitude"] >= 3000 || + ( $wxInfo["lowestClouds"]["altitude"] < 3000 && + ($wxInfo["lowestClouds"]["code"] == "CLR" || + $wxInfo["lowestClouds"]["code"] == "SKC" || + $wxInfo["lowestClouds"]["code"] == "FEW" || + $wxInfo["lowestClouds"]["code"] == "SCT")) + ) { + $wxInfo["SkyConditions"] = "VFR"; + } else { + $wxInfo["SkyConditions"] = "MVFR"; + } + + } else if ($wxInfo["vis_distance"] >=3) { + //clounds between 1000' and 3000' + if ($wxInfo["lowestClouds"]["altitude"] >= 1000 || + ( $wxInfo["lowestClouds"]["altitude"] < 1000 && + ( $wxInfo["lowestClouds"]["code"] == "CLR" || + $wxInfo["lowestClouds"]["code"] == "SKC" || + $wxInfo["lowestClouds"]["code"] == "FEW" || + $wxInfo["lowestClouds"]["code"] == "SCT")) + ) { + $wxInfo["SkyConditions"] = "MVFR"; + } else { + $wxInfo["SkyConditions"] = "IFR"; + } + + } else if ($wxInfo["vis_distance"] >=1) { + //clouds between 500' and 1000' + if ($wxInfo["lowestCloudes"]["altitude"] >= 500) { + $wxInfo["SkyConditions"] = "IFR"; + } else { + $wxInfo["SkyConditions"] = "LIFR"; + } + + + } else if ($wxInfo["vis_distance"] <1) { + //clouds < 500' + if ($wxInfo["lowestCloudes"]["altitude"] < 500) { + $wxInfo["SkyConditions"] = "LIFR"; + } else { + $wxInfo["SkyConditions"] = "IFR"; + } + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |