Thread: CVS: phpweather phpweather.php,1.25,1.26
Brought to you by:
iridium
From: Martin G. <gim...@us...> - 2002-05-18 08:39:12
|
Update of /cvsroot/phpweather/phpweather In directory usw-pr-cvs1:/tmp/cvs-serv18817 Modified Files: phpweather.php Log Message: When the windchill and heatindex was calculated, the temperature and windspeed was compared to strings and not integers. I also re-indented some of the code. Index: phpweather.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/phpweather.php,v retrieving revision 1.25 retrieving revision 1.26 diff -u -3 -r1.25 -r1.26 --- phpweather.php 15 May 2002 22:23:26 -0000 1.25 +++ phpweather.php 18 May 2002 08:39:08 -0000 1.26 @@ -23,7 +23,8 @@ /** * PHP Weather is a class that understands how to parse a raw METAR. * - * The decoded METAR is saved in $decoded_metar, in a language-neutral format. + * The decoded METAR is saved in $decoded_metar, in a language-neutral + * format. * * @author Martin Geisler <gim...@gi...> * @version $Id$ @@ -143,22 +144,27 @@ if ($windunit == 'KT') { /* The windspeed measured in knots: */ $knots = number_format($value); - /* The windspeed measured in meters per second, rounded to one decimal place */ + /* The windspeed measured in meters per second, rounded to one + decimal place */ $meterspersec = number_format($value * 0.5144, 1); - /* The windspeed measured in miles per hour, rounded to one decimal place */ + /* The windspeed measured in miles per hour, rounded to one + decimal place */ $milesperhour = number_format($value * 1.1508, 1); } elseif ($windunit == 'MPS') { /* The windspeed measured in meters per second */ $meterspersec = number_format($value); - /* The windspeed measured in knots, rounded to one decimal place */ + /* The windspeed measured in knots, rounded to one decimal + place */ $knots = number_format($value / 0.5144, 1); - /* The windspeed measured in miles per hour, rounded to one decimal place */ + /* The windspeed measured in miles per hour, rounded to one + decimal place */ $milesperhour = number_format($value / 0.5144 * 1.1508, 1); } elseif ($windunit == 'KMH') { /* The windspeed measured in kilometers per hour */ $meterspersec = number_format($value * 1000 / 3600, 1); $knots = number_format($value * 1000 / 3600 / 0.5144, 1); - /* The windspeed measured in miles per hour, rounded to one decimal place */ + /* The windspeed measured in miles per hour, rounded to one + decimal place */ $milesperhour = number_format($knots * 1.1508, 1); } } @@ -274,7 +280,7 @@ */ $decoded_metar['wind']['var_beg'] = $regs[1]; $decoded_metar['wind']['var_end'] = $regs[2]; - } elseif(ereg('^([0-9]{4})([NS]?[EW]?)$', $part, $regs)) { + } elseif (ereg('^([0-9]{4})([NS]?[EW]?)$', $part, $regs)) { /* * Visibility in meters (4 digits only) */ @@ -466,24 +472,32 @@ /* * Temperature/Dew Point Group. */ - $decoded_metar['temperature']['temp_c'] = round(strtr($regs[1], 'M', '-')); - $decoded_metar['temperature']['temp_f'] = round(strtr($regs[1], 'M', '-') * (9/5) + 32); + $decoded_metar['temperature']['temp_c'] = + round(strtr($regs[1], 'M', '-')); + $decoded_metar['temperature']['temp_f'] = + round(strtr($regs[1], 'M', '-') * (9/5) + 32); if (!empty($regs[2])) { - $decoded_metar['temperature']['dew_c'] = round(strtr($regs[2], 'M', '-')); - $decoded_metar['temperature']['dew_f'] = round(strtr($regs[2], 'M', '-') * (9/5) + 32); + $decoded_metar['temperature']['dew_c'] = + round(strtr($regs[2], 'M', '-')); + $decoded_metar['temperature']['dew_f'] = + round(strtr($regs[2], 'M', '-') * (9/5) + 32); } - } elseif(ereg('A([0-9]{4})', $part, $regs)) { + } elseif (ereg('A([0-9]{4})', $part, $regs)) { /* * Altimeter. * The pressure measured in inHg. */ - $decoded_metar['altimeter']['inhg'] = number_format($regs[1]/100, 2); + $decoded_metar['altimeter']['inhg'] = + number_format($regs[1]/100, 2); /* The pressure measured in mmHg, hPa and atm */ - $decoded_metar['altimeter']['mmhg'] = number_format($regs[1] * 0.254, 1, '.', ''); - $decoded_metar['altimeter']['hpa'] = round($regs[1] * 0.33864); - $decoded_metar['altimeter']['atm'] = number_format($regs[1] * 3.3421e-4, 3, '.', ''); - } elseif(ereg('Q([0-9]{4})', $part, $regs)) { + $decoded_metar['altimeter']['mmhg'] = + number_format($regs[1] * 0.254, 1, '.', ''); + $decoded_metar['altimeter']['hpa'] = + round($regs[1] * 0.33864); + $decoded_metar['altimeter']['atm'] = + number_format($regs[1] * 3.3421e-4, 3, '.', ''); + } elseif (ereg('Q([0-9]{4})', $part, $regs)) { /* * Altimeter. * The specification doesn't say anything about @@ -494,9 +508,12 @@ $decoded_metar['altimeter']['hpa'] = round($regs[1]); /* The pressure measured in mmHg, inHg and atm */ - $decoded_metar['altimeter']['mmhg'] = number_format($regs[1] * 0.75006, 1, '.', ''); - $decoded_metar['altimeter']['inhg'] = number_format($regs[1] * 0.02953, 2); - $decoded_metar['altimeter']['atm'] = number_format($regs[1] * 9.8692e-4, 3, '.', ''); + $decoded_metar['altimeter']['mmhg'] = + number_format($regs[1] * 0.75006, 1, '.', ''); + $decoded_metar['altimeter']['inhg'] = + number_format($regs[1] * 0.02953, 2); + $decoded_metar['altimeter']['atm'] = + number_format($regs[1] * 9.8692e-4, 3, '.', ''); } elseif (ereg('^T([0-9]{4})([0-9]{4})', $part, $regs)) { /* @@ -540,7 +557,7 @@ $this->store_temp($regs[2] / 10, $decoded_metar['temp_min_max']['min24h_c'], $decoded_metar['temp_min_max']['min24h_f']); - } elseif(ereg('^P([0-9]{4})', $part, $regs)) { + } elseif (ereg('^P([0-9]{4})', $part, $regs)) { /* * Precipitation during last hour in hundredths of an inch @@ -549,10 +566,12 @@ $decoded_metar['precipitation']['in'] = -1; $decoded_metar['precipitation']['mm'] = -1; } else { - $decoded_metar['precipitation']['in'] = number_format($regs[1]/100, 2); - $decoded_metar['precipitation']['mm'] = number_format($regs[1]*0.254, 2); + $decoded_metar['precipitation']['in'] = + number_format($regs[1]/100, 2); + $decoded_metar['precipitation']['mm'] = + number_format($regs[1]*0.254, 2); } - } elseif(ereg('^6([0-9]{4})', $part, $regs)) { + } elseif (ereg('^6([0-9]{4})', $part, $regs)) { /* * Precipitation during last 3 or 6 hours in hundredths of an @@ -562,10 +581,12 @@ $decoded_metar['precipitation']['in_6h'] = -1; $decoded_metar['precipitation']['mm_6h'] = -1; } else { - $decoded_metar['precipitation']['in_6h'] = number_format($regs[1]/100, 2); - $decoded_metar['precipitation']['mm_6h'] = number_format($regs[1]*0.254, 2); + $decoded_metar['precipitation']['in_6h'] = + number_format($regs[1]/100, 2); + $decoded_metar['precipitation']['mm_6h'] = + number_format($regs[1]*0.254, 2); } - } elseif(ereg('^7([0-9]{4})', $part, $regs)) { + } elseif (ereg('^7([0-9]{4})', $part, $regs)) { /* * Precipitation during last 24 hours in hundredths of an inch. @@ -574,10 +595,12 @@ $decoded_metar['precipitation']['in_24h'] = -1; $decoded_metar['precipitation']['mm_24h'] = -1; } else { - $decoded_metar['precipitation']['in_24h'] = number_format($regs[1]/100, 2, '.', ''); - $decoded_metar['precipitation']['mm_24h'] = number_format($regs[1]*0.254, 2, '.', ''); + $decoded_metar['precipitation']['in_24h'] = + number_format($regs[1]/100, 2, '.', ''); + $decoded_metar['precipitation']['mm_24h'] = + number_format($regs[1]*0.254, 2, '.', ''); } - } elseif(ereg('^4/([0-9]{3})', $part, $regs)) { + } elseif (ereg('^4/([0-9]{3})', $part, $regs)) { /* * Snow depth in inches @@ -615,12 +638,12 @@ /* - * Compute windchill if temp < 40f and windspeed > 3 mph - */ + * Compute windchill if temp < 40f and windspeed > 3 mph + */ if (!empty($decoded_metar['temperature']['temp_f']) && - $decoded_metar['temperature']['temp_f'] <= '40' && + $decoded_metar['temperature']['temp_f'] <= 40 && !empty($decoded_metar['wind']['miles_per_hour']) && - $decoded_metar['wind']['miles_per_hour'] > '3'){ + $decoded_metar['wind']['miles_per_hour'] > 3) { $decoded_metar['windchill']['windchill_f'] = number_format(35.74 + 0.6215*$decoded_metar['temperature']['temp_f'] - 35.75*pow($decoded_metar['wind']['miles_per_hour'], 0.16) @@ -633,12 +656,13 @@ pow(($decoded_metar['wind']['miles_per_hour']/1.609), 0.16)); } - /* - * Compute heat index if temp > 70F - */ - if (!empty($decoded_metar['temperature']['temp_f']) && $decoded_metar['temperature']['temp_f'] > '70' && - !empty($decoded_metar['rel_humidity'])){ - $decoded_metar['heatindex']['heatindex_f']= + /* + * Compute heat index if temp > 70F + */ + if (!empty($decoded_metar['temperature']['temp_f']) && + $decoded_metar['temperature']['temp_f'] > 70 && + !empty($decoded_metar['rel_humidity'])) { + $decoded_metar['heatindex']['heatindex_f']= number_format(-42.379 + 2.04901523*$decoded_metar['temperature']['temp_f'] + 10.14333127*$decoded_metar['rel_humidity'] - 0.22475541*$decoded_metar['temperature']['temp_f'] @@ -660,12 +684,10 @@ $decoded_metar['heatindex']['heatindex_c']= number_format(($decoded_metar['heatindex']['heatindex_f'] - 32) / 1.8); } - /* Finally we store our decoded METAR in $this->decoded_metar so * that other methods can use it. */ - $this->decoded_metar = $decoded_metar; return $decoded_metar; } |