@@ -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 |
@@ -87,17 +87,17 @@ discard block |
||
| 87 | 87 | $coverage_norm = 8.0/8.0; |
| 88 | 88 | } |
| 89 | 89 | $alt_m = 1000; |
| 90 | - if ($cumulus_base * 0.80 < $alt_m && $cumulus_base * 1.20 > $alt_m) { |
|
| 90 | + if ($cumulus_base*0.80 < $alt_m && $cumulus_base*1.20 > $alt_m) { |
|
| 91 | 91 | $layer_type = 'cu'; |
| 92 | - } elseif ($stratus_base * 0.80 < $alt_m && $stratus_base * 1.40 > $alt_m) { |
|
| 92 | + } elseif ($stratus_base*0.80 < $alt_m && $stratus_base*1.40 > $alt_m) { |
|
| 93 | 93 | $layer_type = 'st'; |
| 94 | 94 | } else { |
| 95 | 95 | $layer_type = 'st'; |
| 96 | 96 | } |
| 97 | 97 | $result = array(); |
| 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 | } |