cvs: pear /Services_Weather/Weather Common.php
| From: | Alexander Wirtz | Date: | Mon, 06 Oct 2003 14:00:54 +0000 |
| Subject: | cvs: pear /Services_Weather/Weather Common.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-13420@lists.php.net to get a copy of this message | ||
eru Mon Oct 6 10:00:54 2003 EDT
Modified files:
/pear/Services_Weather/Weather Common.php
Log:
*Added humidity and dewpoint calculation
Index: pear/Services_Weather/Weather/Common.php
diff -u pear/Services_Weather/Weather/Common.php:1.13 pear/Services_Weather/Weather/Common.php:1.14
--- pear/Services_Weather/Weather/Common.php:1.13 Sun Oct 5 18:54:05 2003
+++ pear/Services_Weather/Weather/Common.php Mon Oct 6 10:00:54 2003
@@ -16,7 +16,7 @@
// | Authors: Alexander Wirtz <alex@pc4p.net> |
// +----------------------------------------------------------------------+
//
-// $Id: Common.php,v 1.13 2003/10/05 22:54:05 eru Exp $
+// $Id: Common.php,v 1.14 2003/10/06 14:00:54 eru Exp $
require_once "Services/Weather.php";
@@ -363,6 +363,73 @@
function calculateWindChill($temperature, $speed)
{
return round(35.74 + 0.6215 * $temperature - 35.75 * pow($speed, 0.16) + 0.4275 *
$temperature * pow($speed, 0.16));
+ }
+ // }}}
+
+ // {{{ calculateHumidity()
+ /**
+ * Calculate humidity from temperature and dewpoint
+ * This is only an approximation, there is no exact formula
+ *
+ * @param float $temperature
+ * @param float $dewPoint
+ * @return float
+ * @access public
+ */
+ function calculateHumidity($temperature, $dewPoint)
+ {
+ // First calculate saturation steam pressure for both temperatures
+ if ($temperature >= 0) {
+ $a = 7.5;
+ $b = 237.3;
+ } else {
+ $a = 7.6;
+ $b = 240.7;
+ }
+ $tempSSP = 6.1078 * pow(10, ($a * $temperature) / ($b + $temperature));
+
+ if ($dewPoint >= 0) {
+ $a = 7.5;
+ $b = 237.3;
+ } else {
+ $a = 7.6;
+ $b = 240.7;
+ }
+ $dewSSP = 6.1078 * pow(10, ($a * $dewPoint) / ($b + $dewPoint));
+
+ return round(100 * $dewSSP / $tempSSP, 1);
+ }
+ // }}}
+
+ // {{{ calculateDewPoint()
+ /**
+ * Calculate dewpoint from temperature and humidity
+ * This is only an approximation, there is no exact formula
+ *
+ * @param float $temperature
+ * @param float $humidity
+ * @return float
+ * @access public
+ */
+ function calculateDewPoint($temperature, $humidity)
+ {
+ if ($temperature >= 0) {
+ $a = 7.5;
+ $b = 237.3;
+ } else {
+ $a = 7.6;
+ $b = 240.7;
+ }
+
+ // First calculate saturation steam pressure for temperature
+ $SSP = 6.1078 * pow(10, ($a * $temperature) / ($b + $temperature));
+
+ // Steam pressure
+ $SP = $humidity / 100 * $SSP;
+
+ $v = log($SP / 6.1078, 10);
+
+ return round($b * $v / ($a - $v), 1);
}
// }}}