function get_temperature($part, &$metarPtr, &$group, &$wxInfo) { // Decodes temperature and dew point information. Relative humidity is calculated. Also, // depending on the temperature, Heat Index or Wind Chill Temperature is calculated. // Format is tt/dd where tt = temperature and dd = dew point temperature. All units are // in Celsius. A 'M' preceeding the tt or dd indicates a negative temperature. Some // stations do not report dew point, so the format is tt/ or tt/XX. 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) { $hiF = -42.379 + 2.04901523 * $tempF + 10.14333127 * $rh - 0.22475541 * $tempF * $rh; $hiF += -0.00683783 * pow($tempF, 2) - 0.05481717 * pow($rh, 2); $hiF += 0.00122874 * pow($tempF, 2) * $rh + 0.00085282 * $tempF * pow($rh, 2); $hiF += -0.00000199 * pow($tempF, 2) * pow($rh, 2); $hiF = round($hiF); $hiC = round(($hiF - 32) / 1.8); $wxInfo['HEAT INDEX'] = "$hiF°F ($hiC°C)"; } } function get_wind_chill($tempF, &$wxInfo) { // Calculate Wind Chill Temperature based on temperature in F and // wind speed in miles per hour if ($tempF < 51 && $wxInfo['WIND'] != 'calm') { $pieces = explode(' ', $wxInfo['WIND']); $windspeed = (integer) $pieces[2]; // wind speed must be in miles per hour if ($windspeed > 3) { $chillF = 35.74 + 0.6215 * $tempF - 35.75 * pow($windspeed, 0.16) + 0.4275 * $tempF * pow($windspeed, 0.16); $chillF = round($chillF); $chillC = round(($chillF - 32) / 1.8); $wxInfo['WIND CHILL'] = "$chillF°F ($chillC°C)"; } } } if (ereg('^(M?[0-9]{2})/(M?[0-9]{2}|[X]{2})?$',$part,$pieces)) { $tempC = (integer) strtr($pieces[1], 'M', '-'); $tempF = round(1.8 * $tempC + 32); $wxInfo['TEMP'] = "$tempF°F ($tempC°C)"; get_wind_chill($tempF, $wxInfo); if (strlen($pieces[2]) != 0 && $pieces[2] != 'XX') { $dewC = (integer) strtr($pieces[2], 'M', '-'); $dewF = round(1.8 * $dewC + 32); $wxInfo['DEWPT'] = "$dewF°F ($dewC°C)"; $rh = round(100 * pow((112 - (0.1 * $tempC) + $dewC) / (112 + (0.9 * $tempC)), 8)); $wxInfo['HUMIDITY'] = $rh . '%'; get_heat_index($tempF, $rh, $wxInfo); } $metarPtr++; $group++; } else { $group++; } }