This repository has been archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathshared.php
259 lines (213 loc) · 7.23 KB
/
shared.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php include('weather34svgicons.php');
error_reporting(0);
// Speed
function ktsTokmh(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = number_format(1.852*$weather[$field],1);
}
function ktsTomph(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = number_format(1.150779*$weather[$field],1);
}
function ktsToms(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = number_format(0.514444*$weather[$field],2);
}
function mphTokmh(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = number_format(1.609344*$weather[$field],1);
}
function mphTokts(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = number_format(0.868976*$weather[$field],1);
}
function mphToms(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = number_format(0.44704*$weather[$field],1);
}
function kmhTokts(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = number_format(0.5399568*$weather[$field],1);
}
function kmhTomph(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = number_format(0.621371*$weather[$field],1);
}
function kmhToms(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = number_format(0.2777778*$weather[$field],1);
}
function msTokmh(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = number_format(3.6*$weather[$field],1);
}
function msTokts(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = round((float)(1.943844*$weather[$field]), 1);
}
function msTomph(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = number_format(2.236936*$weather[$field], 1);
}
// Temperature
function cToF(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = cToFDirect($weather[$field]);
}
function fToC(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = fToCDirect($weather[$field]);
}
function cToFrel(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = round((float)(1.8*$weather[$field]), 1);
}
function fToCrel(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = round((float)(0.55555556*($weather[$field])), 1);
}
function fToCDirect($field){
return round((float)(0.55555556*($field - 32)), 1);
}
function cToFDirect($field){
return number_format((float)$field*1.8 +32,1);
}
// Pressure
function mbToin(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = round((float)(0.02952999*$weather[$field]), 2);
}
function inTomb(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = round((float)(33.86388158*$weather[$field]), 2);
}
// Depth
function mmToin(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] = number_format(0.03937008*$weather[$field], 2);
}
function inTomm(&$weather, $field){
if(!isset($weather[$field])) return;
$weather[$field] =number_format(25.4*$weather[$field], 1);
}
// Calculates "real feel" heat index valid only at lower temperatures (up to 79 F)
function heatIndexLow($t, $rh) {
// Assumes Fahrenheit
return 0.5 * ($t + 61.0 + (($t - 68.0) * 1.2) + ($rh * 0.094));
}
// Calculates "real feel" heat index valid only at higher temperatures (beginning around 79-80 F), the traditional heat index formula
function heatIndexHigh($t, $rh) {
// Assumes Fahrenheit
$heatIndex = -42.379 + 2.04901523 * $t + 10.1433127*$rh - .22475441*$t*$rh - .00683783 *$t * $t - .05481717 * $rh * $rh + .00122874*$t*$t*$rh + .00085282 *$t * $rh *$rh - .00000199 *$t *$t *$rh * $rh;
// Adjustment formula, adding or subtracting as much as a couple degrees at extreme ends of temperature/humidity ranges
$a = 0;
if ($rh < 13 && ($t >= 80 && $t <= 112)) {
$a=((13 - $rh ) / 4) * sqrt((17-abs($t - 95))/17);
$a = -$a;
};
if ($rh > 85 && ($t >= 80 && $t <= 87)) {
$a=(($rh - 85)/10) * ((87 - $t) / 5);
};
$heatIndex += $a;
return $heatIndex;
}
// Ruthfusz heat index formula
// http://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
function heatIndex($temp, $rh) {
global $weather;
$t = anyToF($temp);
// First try simple formula, valid when calculated heat index <= 79 degrees F
$heatIndex = heatIndexLow($t, $rh);
// If too warm, do the complicated formula instead
if ($heatIndex >= 79)
{
$heatIndex = heatIndexHigh($t, $rh);
}
if ($weather["temp_units"] == 'C'){
$heatIndex = fToCDirect($heatIndex);
}
return round($heatIndex, 1);
}
function getUpdatedString($datetime) {
global $showDate, $dateFormat, $timeFormat;
if ($showDate) {
return '<div class="updatedtime"><span>' . date($dateFormat) . '</span><br />' . date($timeFormat) . '</div>';
}
else {
return '<div class="updatedtime"><span>Updated</span><br />' . date($timeFormat) . '</div>';
}
}
function anyToC($field){
global $weather;
if ($weather["temp_units"] == 'C'){
return $field;
} else {
return fToCDirect($field);
}
}
function anyToF($field){
global $weather;
if ($weather["temp_units"] == 'F'){
return $field;
} else {
return cToFDirect ($field);
}
}
function distance($lat, $lon, $lati, $longi) {
$lat1 = deg2rad($lati);
$lat2 = deg2rad($lat);
$long1 = deg2rad($longi);
$long2 = deg2rad($lon);
// Great circle calculation uses the radius of earth, 6371 km
return 6371 * acos(sin($lat1)*sin($lat2) + cos($lat1)*cos($lat2)*cos($long2-$long1));
}
function apparent_temperature($temp,$hum,$wind) {
global $weather;
/* from http://www.bom.gov.au/info/thermal_stress/#atapproximation
About the formula for the apparent temperature
The formula for the AT used by the Bureau of Meteorology is an approximations of the value provided by a mathematical model of heat balance in the human body. It can include the effects of temperature, humidity, wind-speed and radiation. Two forms are given, one including radiation and one without. On this site we use the non-radiation version.
Version including the effects of temperature, humidity, and wind:
AT = Ta + 0.33×e - 0.70×ws - 4.00
Version including the effects of temperature, humidity, wind, and radiation:
AT = Ta + 0.348×e - 0.70×ws + 0.70×Q/(ws + 10) - 4.25
where:
Ta = Dry bulb temperature (°C)
e = Water vapour pressure (hPa) [humidity]
ws = Wind speed (m/s) at an elevation of 10 meters
Q = Net radiation absorbed per unit area of body surface (w/m2)
The vapour pressure can be calculated from the temperature and relative humidity using the equation:
e = rh / 100 × 6.105 × exp ( 17.27 × Ta / ( 237.7 + Ta ) )
where:
rh = Relative Humidity [%]
Source: Norms of apparent temperature in Australia, Aust. Met. Mag., 1994, Vol 43, 1-16
*/
global $weather;
switch ($weather["wind_units"]) {
case 'kts':
$ws = round(0.514444*$wind,1);
break;
case 'km/h':
$ws = round(0.2777778*$wind,1);
break;
case 'mph':
$ws = round(0.44704*$wind,1);
break;
case 'm/s':
$ws = round($wind,1);
break;
default:
$ws = round($wind,1);
break;
}
if($weather['temp_units'] !=='C') {
$Ta = round((float)(0.55555556*($temp - 32)), 1);
} else {
$Ta = $temp;
}
$e = $hum/100*6.105*exp(17.27*$Ta/(237.7+$Ta));
$rfeel = round(($Ta + 0.33*$e - 0.70*$ws - 4.00),1);
if($weather['temp_units'] =='F') {
$rfeel = number_format((float)$rfeel*1.8 +32,1);
}
return($rfeel);
}