1
|
|
|
<?php |
2
|
|
|
class Weather { |
3
|
|
|
public function buildcloudlayer($metar) { |
4
|
|
|
//print_r($metar); |
5
|
|
|
$result = array(); |
6
|
|
|
foreach($metar['cloud'] as $key => $data) { |
7
|
|
|
$alt_m = $metar['cloud'][$key]['level']; |
8
|
|
|
$alt_ft = $alt_m*3.28084; |
9
|
|
|
$pressure = $metar['QNH']; |
10
|
|
|
$cumulus_base = 122.0 * ($metar['temperature'] - $metar['dew']); |
11
|
|
|
$stratus_base = 100.0 * (100.0 * $metar['rh'])*0.3048; |
12
|
|
|
$coverage_norm = 0.0; |
13
|
|
|
if ($metar['cloud'][$key]['type'] == 'Few') { |
14
|
|
|
$coverage_norm = 2.0/8.0; |
15
|
|
|
} elseif ($metar['cloud'][$key]['type'] == 'Scattered') { |
16
|
|
|
$coverage_norm = 4.0/8.0; |
17
|
|
|
} elseif ($metar['cloud'][$key]['type'] == 'Broken') { |
18
|
|
|
$coverage_norm = 6.0/8.0; |
19
|
|
|
} elseif ($metar['cloud'][$key]['type'] == 'Overcast/Full cloud coverage') { |
20
|
|
|
$coverage_norm = 8.0/8.0; |
21
|
|
|
} |
22
|
|
|
$layer_type = 'nn'; |
|
|
|
|
23
|
|
|
if ($metar['cloud'][$key]['significant'] == 'cirrus') { |
24
|
|
|
$layer_type = 'ci'; |
25
|
|
|
} elseif ($alt_ft > 16500) { |
26
|
|
|
$layer_type = 'ci'; |
27
|
|
|
} elseif ($alt_ft > 6500) { |
28
|
|
|
$layer_type = 'ac'; |
29
|
|
|
if ($pressure < 1005.0 && $coverage_norm >= 0.5) { |
30
|
|
|
$layer_type = 'ns'; |
31
|
|
|
} |
32
|
|
|
} else { |
33
|
|
|
if ($cumulus_base * 0.80 < $alt_m && $cumulus_base * 1.20 > $alt_m) { |
34
|
|
|
$layer_type = 'cu'; |
35
|
|
|
} elseif ($stratus_base * 0.80 < $alt_m && $stratus_base * 1.40 > $alt_m) { |
36
|
|
|
$layer_type = 'st'; |
37
|
|
|
} else { |
38
|
|
|
if ($alt_ft < 2000) { |
39
|
|
|
$layer_type = 'st'; |
40
|
|
|
} elseif ($alt_ft < 4500) { |
41
|
|
|
$layer_type = 'cu'; |
42
|
|
|
} else { |
43
|
|
|
$layer_type = 'sc'; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
//echo 'coverage norm : '.$coverage_norm.' - layer_type: '.$layer_type."\n"; |
48
|
|
|
$result[] = array('cov' => $coverage_norm, 'type' => $layer_type,'alt' => $alt_m,'rh' => $metar['rh']); |
49
|
|
|
} |
50
|
|
|
if (count($result) < 2 && $metar['rh'] > 60) { |
51
|
|
|
$result[] = array('cov' => 0.75, 'type' => 'cu','alt' => 4000,'rh' => $metar['rh']); |
52
|
|
|
} |
53
|
|
|
return $result; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
/* |
57
|
|
|
require_once('class.METAR.php'); |
58
|
|
|
$METAR = new METAR(); |
59
|
|
|
*/ |
60
|
|
|
/* |
61
|
|
|
$themetar = $METAR->getMETAR('LFLL'); |
62
|
|
|
print_r($themetar); |
63
|
|
|
$result = $METAR->parse($themetar[0]['metar']); |
64
|
|
|
*/ |
65
|
|
|
/* |
66
|
|
|
$result = $METAR->parse('LFLL 081330Z 01006KT 340V050 9999 FEW020 BKN080 07/01 Q1018 NOSIG'); |
67
|
|
|
print_r($result); |
68
|
|
|
$Weather = new Weather(); |
69
|
|
|
//print_r($Weather->buildcloudlayer($result)); |
70
|
|
|
//print_r($Weather->buildcloud('46.3870','5.2941','2000','0.25')); |
71
|
|
|
print_r($Weather->generateRandomPoint('46.3870','5.2941','2000')); |
72
|
|
|
*/ |
73
|
|
|
?> |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.