@@ -11,12 +11,12 @@ discard block |
||
| 11 | 11 | public function buildcloudlayer($metar) { |
| 12 | 12 | //print_r($metar); |
| 13 | 13 | $result = array(); |
| 14 | - foreach($metar['cloud'] as $key => $data) { |
|
| 14 | + foreach ($metar['cloud'] as $key => $data) { |
|
| 15 | 15 | $alt_m = $metar['cloud'][$key]['level']; |
| 16 | 16 | $alt_ft = $alt_m*3.28084; |
| 17 | 17 | $pressure = $metar['QNH']; |
| 18 | - $cumulus_base = 122.0 * ($metar['temperature'] - $metar['dew']); |
|
| 19 | - $stratus_base = 100.0 * (100.0 * $metar['rh'])*0.3048; |
|
| 18 | + $cumulus_base = 122.0*($metar['temperature'] - $metar['dew']); |
|
| 19 | + $stratus_base = 100.0*(100.0*$metar['rh'])*0.3048; |
|
| 20 | 20 | $coverage_norm = 0.0; |
| 21 | 21 | if ($metar['cloud'][$key]['type'] == 'Few') { |
| 22 | 22 | $coverage_norm = 2.0/8.0; |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | $layer_type = 'ns'; |
| 39 | 39 | } |
| 40 | 40 | } else { |
| 41 | - if ($cumulus_base * 0.80 < $alt_m && $cumulus_base * 1.20 > $alt_m) { |
|
| 41 | + if ($cumulus_base*0.80 < $alt_m && $cumulus_base*1.20 > $alt_m) { |
|
| 42 | 42 | $layer_type = 'cu'; |
| 43 | - } elseif ($stratus_base * 0.80 < $alt_m && $stratus_base * 1.40 > $alt_m) { |
|
| 43 | + } elseif ($stratus_base*0.80 < $alt_m && $stratus_base*1.40 > $alt_m) { |
|
| 44 | 44 | $layer_type = 'st'; |
| 45 | 45 | } else { |
| 46 | 46 | if ($alt_ft < 2000) { |
@@ -53,25 +53,25 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | //echo 'coverage norm : '.$coverage_norm.' - layer_type: '.$layer_type."\n"; |
| 56 | - $result[] = array('cov' => $coverage_norm, 'type' => $layer_type,'alt' => $alt_m,'rh' => $metar['rh']); |
|
| 56 | + $result[] = array('cov' => $coverage_norm, 'type' => $layer_type, 'alt' => $alt_m, 'rh' => $metar['rh']); |
|
| 57 | 57 | } |
| 58 | 58 | if (count($result) < 2 && $metar['rh'] > 60) { |
| 59 | - $result[] = array('cov' => 0.75, 'type' => 'ci','alt' => 4000,'rh' => $metar['rh']); |
|
| 59 | + $result[] = array('cov' => 0.75, 'type' => 'ci', 'alt' => 4000, 'rh' => $metar['rh']); |
|
| 60 | 60 | } |
| 61 | 61 | return $result; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - public function openweathermap($latitude,$longitude) { |
|
| 64 | + public function openweathermap($latitude, $longitude) { |
|
| 65 | 65 | global $globalOpenWeatherMapKey; |
| 66 | 66 | if ($globalOpenWeatherMapKey == '') return array(); |
| 67 | 67 | $Common = new Common(); |
| 68 | 68 | $url = 'http://api.openweathermap.org/data/2.5/weather?lat='.$latitude.'&lon='.$longitude.'&units=metric&appid='.$globalOpenWeatherMapKey; |
| 69 | 69 | //echo $url."\n"; |
| 70 | - $weatherdata = json_decode($Common->getData($url),true); |
|
| 70 | + $weatherdata = json_decode($Common->getData($url), true); |
|
| 71 | 71 | if (!isset($weatherdata['main']['temp']) || !isset($weatherdata['weather'][0]['id'])) return array(); |
| 72 | - $dew = $weatherdata['main']['temp'] - ((100-$weatherdata['main']['humidity'])/5); |
|
| 73 | - $cumulus_base = 122.0 * ($weatherdata['main']['temp'] - $dew); |
|
| 74 | - $stratus_base = 100.0 * (100.0 * $weatherdata['main']['humidity'])*0.3048; |
|
| 72 | + $dew = $weatherdata['main']['temp'] - ((100 - $weatherdata['main']['humidity'])/5); |
|
| 73 | + $cumulus_base = 122.0*($weatherdata['main']['temp'] - $dew); |
|
| 74 | + $stratus_base = 100.0*(100.0*$weatherdata['main']['humidity'])*0.3048; |
|
| 75 | 75 | $coverage_norm = 0.0; |
| 76 | 76 | if ($weatherdata['weather'][0]['id'] == 801) { |
| 77 | 77 | // few clouds |
@@ -88,16 +88,16 @@ discard block |
||
| 88 | 88 | } |
| 89 | 89 | $layer_type = 'nn'; |
| 90 | 90 | $alt_m = 1000; |
| 91 | - if ($cumulus_base * 0.80 < $alt_m && $cumulus_base * 1.20 > $alt_m) { |
|
| 91 | + if ($cumulus_base*0.80 < $alt_m && $cumulus_base*1.20 > $alt_m) { |
|
| 92 | 92 | $layer_type = 'cu'; |
| 93 | - } elseif ($stratus_base * 0.80 < $alt_m && $stratus_base * 1.40 > $alt_m) { |
|
| 93 | + } elseif ($stratus_base*0.80 < $alt_m && $stratus_base*1.40 > $alt_m) { |
|
| 94 | 94 | $layer_type = 'st'; |
| 95 | 95 | } else { |
| 96 | 96 | $layer_type = 'st'; |
| 97 | 97 | } |
| 98 | - $result[] = array('cov' => $coverage_norm, 'type' => $layer_type,'alt' => $alt_m,'rh' => $weatherdata['main']['humidity']); |
|
| 98 | + $result[] = array('cov' => $coverage_norm, 'type' => $layer_type, 'alt' => $alt_m, 'rh' => $weatherdata['main']['humidity']); |
|
| 99 | 99 | if ($weatherdata['main']['humidity'] > 60) { |
| 100 | - $result[] = array('cov' => 0.75, 'type' => 'ci','alt' => 4000,'rh' => $weatherdata['main']['humidity']); |
|
| 100 | + $result[] = array('cov' => 0.75, 'type' => 'ci', 'alt' => 4000, 'rh' => $weatherdata['main']['humidity']); |
|
| 101 | 101 | } |
| 102 | 102 | return $result; |
| 103 | 103 | } |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | // http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p50.pl?file=gfs.t05z.pgrb2full.0p50.f000&lev_10_m_above_ground=on&lev_surface=on&var_TMP=on&var_UGRD=on&var_VGRD=on&leftlon=0&rightlon=360&toplat=90&bottomlat=-90&dir=/gfs.2017111717 |
| 119 | 119 | $resolution = '0.5'; |
| 120 | - $baseurl = 'http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_'.($resolution === '1' ? '1p00':'0p50').'.pl'; |
|
| 121 | - $get = array('file' => 'gfs.t'.sprintf('%02d',(6*floor($hour/6))).($resolution === '1' ? 'z.pgrb2.1p00.f000' : 'z.pgrb2full.0p50.f000'), |
|
| 120 | + $baseurl = 'http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_'.($resolution === '1' ? '1p00' : '0p50').'.pl'; |
|
| 121 | + $get = array('file' => 'gfs.t'.sprintf('%02d', (6*floor($hour/6))).($resolution === '1' ? 'z.pgrb2.1p00.f000' : 'z.pgrb2full.0p50.f000'), |
|
| 122 | 122 | 'lev_10_m_above_ground' => 'on', |
| 123 | 123 | 'lev_surface' => 'on', |
| 124 | 124 | 'var_TMP' => 'on', |
@@ -128,21 +128,21 @@ discard block |
||
| 128 | 128 | 'rightlon' => 360, |
| 129 | 129 | 'toplat' => 90, |
| 130 | 130 | 'bottomlat' => -90, |
| 131 | - 'dir' => '/gfs.'.date('Ymd').sprintf('%02d',(6*floor($hour/6))) |
|
| 131 | + 'dir' => '/gfs.'.date('Ymd').sprintf('%02d', (6*floor($hour/6))) |
|
| 132 | 132 | ); |
| 133 | 133 | $url = $baseurl.'?'.http_build_query($get); |
| 134 | 134 | //echo $url; |
| 135 | 135 | $Common = new Common(); |
| 136 | - $Common->download($url,$windpathsrc); |
|
| 136 | + $Common->download($url, $windpathsrc); |
|
| 137 | 137 | // Check if the downloaded file is in GRIB format |
| 138 | - $file = fopen($windpathsrc,"r"); |
|
| 138 | + $file = fopen($windpathsrc, "r"); |
|
| 139 | 139 | $firc = fgetc($file); |
| 140 | 140 | fclose($file); |
| 141 | 141 | if ($firc == 'G') { |
| 142 | 142 | system($grib2json.' --data --output '.$windpathdest.' --names --compact '.$windpathsrc); |
| 143 | 143 | } else { |
| 144 | 144 | // if not try previous run |
| 145 | - if ($hour == date('G')) $this->nomad_wind(date('G')-6); |
|
| 145 | + if ($hour == date('G')) $this->nomad_wind(date('G') - 6); |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -161,10 +161,10 @@ discard block |
||
| 161 | 161 | $url = 'https://podaac.jpl.nasa.gov/ws/search/granule/?datasetId=PODAAC-OSCAR-03D01&itemsPerPage=1&sortBy=timeDesc&format=atom&pretty=false'; |
| 162 | 162 | $Common = new Common(); |
| 163 | 163 | $oscarlst = $Common->getData($url); |
| 164 | - $oscarlst_xml = json_decode(json_encode(simplexml_load_string($oscarlst)),true); |
|
| 164 | + $oscarlst_xml = json_decode(json_encode(simplexml_load_string($oscarlst)), true); |
|
| 165 | 165 | foreach ($oscarlst_xml['entry']['link'] as $oscarlnk) { |
| 166 | 166 | if ($oscarlnk['@attributes']['type'] == 'application/x-netcdf') { |
| 167 | - $Common->download($oscarlnk['@attributes']['href'],$wavepathsrc.'.gz'); |
|
| 167 | + $Common->download($oscarlnk['@attributes']['href'], $wavepathsrc.'.gz'); |
|
| 168 | 168 | break; |
| 169 | 169 | } |
| 170 | 170 | } |
@@ -63,12 +63,16 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | public function openweathermap($latitude,$longitude) { |
| 65 | 65 | global $globalOpenWeatherMapKey; |
| 66 | - if ($globalOpenWeatherMapKey == '') return array(); |
|
| 66 | + if ($globalOpenWeatherMapKey == '') { |
|
| 67 | + return array(); |
|
| 68 | + } |
|
| 67 | 69 | $Common = new Common(); |
| 68 | 70 | $url = 'http://api.openweathermap.org/data/2.5/weather?lat='.$latitude.'&lon='.$longitude.'&units=metric&appid='.$globalOpenWeatherMapKey; |
| 69 | 71 | //echo $url."\n"; |
| 70 | 72 | $weatherdata = json_decode($Common->getData($url),true); |
| 71 | - if (!isset($weatherdata['main']['temp']) || !isset($weatherdata['weather'][0]['id'])) return array(); |
|
| 73 | + if (!isset($weatherdata['main']['temp']) || !isset($weatherdata['weather'][0]['id'])) { |
|
| 74 | + return array(); |
|
| 75 | + } |
|
| 72 | 76 | $dew = $weatherdata['main']['temp'] - ((100-$weatherdata['main']['humidity'])/5); |
| 73 | 77 | $cumulus_base = 122.0 * ($weatherdata['main']['temp'] - $dew); |
| 74 | 78 | $stratus_base = 100.0 * (100.0 * $weatherdata['main']['humidity'])*0.3048; |
@@ -104,7 +108,9 @@ discard block |
||
| 104 | 108 | |
| 105 | 109 | public function nomad_wind($hour = '') { |
| 106 | 110 | global $globalWindsPath; |
| 107 | - if ($hour == '') $hour = date('G'); |
|
| 111 | + if ($hour == '') { |
|
| 112 | + $hour = date('G'); |
|
| 113 | + } |
|
| 108 | 114 | if (isset($globalWindsPath) && $globalWindsPath != '') { |
| 109 | 115 | $grib2json = $globalWindsPath['grib2json']; |
| 110 | 116 | $windpathsrc = $globalWindsPath['source']; |
@@ -142,7 +148,9 @@ discard block |
||
| 142 | 148 | system($grib2json.' --data --output '.$windpathdest.' --names --compact '.$windpathsrc); |
| 143 | 149 | } else { |
| 144 | 150 | // if not try previous run |
| 145 | - if ($hour == date('G')) $this->nomad_wind(date('G')-6); |
|
| 151 | + if ($hour == date('G')) { |
|
| 152 | + $this->nomad_wind(date('G')-6); |
|
| 153 | + } |
|
| 146 | 154 | } |
| 147 | 155 | } |
| 148 | 156 | |
@@ -9,11 +9,11 @@ discard block |
||
| 9 | 9 | header('Content-disposition: attachment; filename="weather.json"'); |
| 10 | 10 | } |
| 11 | 11 | header('Content-Type: text/javascript'); |
| 12 | -$latitude = filter_input(INPUT_GET,'latitude',FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 13 | -$longitude = filter_input(INPUT_GET,'longitude',FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 12 | +$latitude = filter_input(INPUT_GET, 'latitude', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
| 13 | +$longitude = filter_input(INPUT_GET, 'longitude', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
| 14 | 14 | if ($latitude == '' || $longitude == '') return ''; |
| 15 | 15 | //echo 'latitude : '.$latitude.' - longitude : '.$longitude."\n"; |
| 16 | -$airports = $Spotter->closestAirports($latitude,$longitude,300); |
|
| 16 | +$airports = $Spotter->closestAirports($latitude, $longitude, 300); |
|
| 17 | 17 | //print_r($airports); |
| 18 | 18 | $METAR = new METAR(); |
| 19 | 19 | $Weather = new Weather(); |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | $ew = true; |
| 22 | 22 | $dtf = false; |
| 23 | 23 | if (empty($airports)) $ew = false; |
| 24 | -while($ew) { |
|
| 24 | +while ($ew) { |
|
| 25 | 25 | $met = $METAR->getMETAR($airports[$i]['icao']); |
| 26 | 26 | //print_r($met); |
| 27 | 27 | if (!empty($met)) { |
@@ -45,6 +45,6 @@ discard block |
||
| 45 | 45 | $i++; |
| 46 | 46 | if ($i >= count($airports)) $ew = false; |
| 47 | 47 | } |
| 48 | -if ($dtf === false) echo json_encode($Weather->openweathermap($latitude,$longitude)); |
|
| 48 | +if ($dtf === false) echo json_encode($Weather->openweathermap($latitude, $longitude)); |
|
| 49 | 49 | |
| 50 | 50 | ?> |
| 51 | 51 | \ No newline at end of file |
@@ -11,7 +11,9 @@ discard block |
||
| 11 | 11 | header('Content-Type: text/javascript'); |
| 12 | 12 | $latitude = filter_input(INPUT_GET,'latitude',FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 13 | 13 | $longitude = filter_input(INPUT_GET,'longitude',FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 14 | -if ($latitude == '' || $longitude == '') return ''; |
|
| 14 | +if ($latitude == '' || $longitude == '') { |
|
| 15 | + return ''; |
|
| 16 | +} |
|
| 15 | 17 | //echo 'latitude : '.$latitude.' - longitude : '.$longitude."\n"; |
| 16 | 18 | $airports = $Spotter->closestAirports($latitude,$longitude,300); |
| 17 | 19 | //print_r($airports); |
@@ -20,7 +22,9 @@ discard block |
||
| 20 | 22 | $i = 0; |
| 21 | 23 | $ew = true; |
| 22 | 24 | $dtf = false; |
| 23 | -if (empty($airports)) $ew = false; |
|
| 25 | +if (empty($airports)) { |
|
| 26 | + $ew = false; |
|
| 27 | +} |
|
| 24 | 28 | while($ew) { |
| 25 | 29 | $met = $METAR->getMETAR($airports[$i]['icao']); |
| 26 | 30 | //print_r($met); |
@@ -43,8 +47,12 @@ discard block |
||
| 43 | 47 | } |
| 44 | 48 | } |
| 45 | 49 | $i++; |
| 46 | - if ($i >= count($airports)) $ew = false; |
|
| 50 | + if ($i >= count($airports)) { |
|
| 51 | + $ew = false; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | +if ($dtf === false) { |
|
| 55 | + echo json_encode($Weather->openweathermap($latitude,$longitude)); |
|
| 47 | 56 | } |
| 48 | -if ($dtf === false) echo json_encode($Weather->openweathermap($latitude,$longitude)); |
|
| 49 | 57 | |
| 50 | 58 | ?> |
| 51 | 59 | \ No newline at end of file |