23) {$t[0] = 12; } if (preg_match('/^12.*a/i',$tfixed)) { $t[0] = 0; } if ($t[0] < '10') {$t[0] = sprintf("%02d",$t[0]); } // leading zero on hour. $t2 = join(':',$t); // put time back to gether; $t2 = preg_replace('/[^\d\:]/is','',$t2); // strip out the am/pm if any $Debug .= "\n"; return($t2); } // end WXSfixupTime #------------------------------------------------------------------------------------- # WXS support function - WXS_setDateTimes #------------------------------------------------------------------------------------- function WXS_setDateTimes ($indate,$intime,$MDYformat=true) { // returns: $date_year,$date_month,$date_day,$time_hour,$time_minute,$date_month,$monthname,$dayname global $Debug; $Debug .= "\n"; $d = explode('/',$indate); if($d[2]<2000) {$d[2]+=2000;} if($MDYformat) { // mm/dd/yyyy $YMD = "$d[2]-$d[0]-$d[1]"; } else { // dd/mm/yyyy $YMD = "$d[2]-$d[1]-$d[0]"; } $t = WXSfixupTime($intime); $WXStime = strtotime("$YMD $t:00"); $Debug .= "\n"; $WXStime = date('Y m d H i F l',$WXStime); $Debug .= "\n"; if(isset($_REQUEST['debug'])) {echo $Debug; } return(explode(' ',$WXStime)); // results returned in array for list() assignment } // end WXS_setDateTimes #------------------------------------------------------------------------------------- # WXS support function - WXS_beaufortNumber #------------------------------------------------------------------------------------- function WXS_beaufortNumber ($rawwind,$usedunit) { global $Debug; // first convert all winds to knots $WINDkts = 0.0; if (preg_match('/kts|knot/i',$usedunit)) { $WINDkts = $rawwind * 1.0; } elseif (preg_match('/mph/i',$usedunit)) { $WINDkts = $rawwind * 0.8689762; } elseif (preg_match('/mps|m\/s/i',$usedunit)) { $WINDkts = $rawwind * 1.94384449; } elseif (preg_match('/kmh|km\/h/i',$usedunit)) { $WINDkts = $rawwind * 0.539956803; } else { $Debug .= "\n"; $WINDkts = $rawwind * 1.0; } // return a number for the beaufort scale based on wind in knots if ($WINDkts < 1 ) {return(0); } if ($WINDkts < 4 ) {return(1); } if ($WINDkts < 7 ) {return(2); } if ($WINDkts < 11 ) {return(3); } if ($WINDkts < 17 ) {return(4); } if ($WINDkts < 22 ) {return(5); } if ($WINDkts < 28 ) {return(6); } if ($WINDkts < 34 ) {return(7); } if ($WINDkts < 41 ) {return(8); } if ($WINDkts < 48 ) {return(9); } if ($WINDkts < 56 ) {return(10); } if ($WINDkts < 64 ) {return(11); } if ($WINDkts >= 64 ) {return(12); } return("0"); } // end WXS_beaufortNumber #------------------------------------------------------------------------------------- # WXS support function - WXS_beaufortText #------------------------------------------------------------------------------------- function WXS_beaufortText ($beaufortnumber) { $B = array( /* Beaufort 0 to 12 in English */ "Calm", "Light air", "Light breeze", "Gentle breeze", "Moderate breeze", "Fresh breeze", "Strong breeze", "Near gale", "Gale", "Strong gale", "Storm", "Violent storm", "Hurricane" ); if(isset($B[$beaufortnumber])) { return $B[$beaufortnumber]; } else { return "Unknown $beaufortnumber Bft"; } } // end WXS_beaufortText #------------------------------------------------------------------------------------- # WXS support function - WXS_setFeelslike #------------------------------------------------------------------------------------- function WXS_setFeelslike ($temp,$windchill,$heatindex,$tempUOM) { global $Debug; // establish the feelslike temperature and return a word describing how it feels $HeatWords = array( 'Unknown', 'Extreme Heat Danger', 'Heat Danger', 'Extreme Heat Caution', 'Extremely Hot', 'Uncomfortably Hot', 'Hot', 'Warm', 'Comfortable', 'Cool', 'Cold', 'Uncomfortably Cold', 'Very Cold', 'Extreme Cold' ); // first convert all temperatures to Centigrade if need be $TC = $temp; $WC = $windchill; $HC = $heatindex; if (preg_match('|F|i',$tempUOM)) { // convert F to C if need be $TC = sprintf("%01.1f",round(($TC-32.0) / 1.8,1)); $WC = sprintf("%01.1f",round(($WC-32.0) / 1.8,1)); $HC = sprintf("%01.1f",round(($HC-32.0) / 1.8,1)); } // Feelslike if ($TC <= 16.0 ) { $feelslike = $WC; //use WindChill } elseif ($TC >=27.0) { $feelslike = $HC; //use HeatIndex } else { $feelslike = $TC; // use temperature } if (preg_match('|F|i',$tempUOM)) { // convert C back to F if need be $feelslike = (1.8 * $feelslike) + 32.0; } $feelslike = round($feelslike,0); // determine the 'heat color word' to use $hcWord = $HeatWords[0]; $hcFound = false; if ($TC > 32 and $HC > 29) { if ($HC > 54 and ! $hcFound) { $hcWord = $HeatWords[1]; $hcFound = true;} if ($HC > 45 and ! $hcFound) { $hcWord = $HeatWords[2]; $hcFound = true; } if ($HC > 39 and ! $hcFound) { $hcWord = $HeatWords[4]; $hcFound = true; } if ($HC > 29 and ! $hcFound) { $hcWord = $HeatWords[6]; $hcFound = true; } } elseif ($WC < 16 ) { if ($WC < -18 and ! $hcFound) { $hcWord = $HeatWords[13]; $hcFound = true; } if ($WC < -9 and ! $hcFound) { $hcWord = $HeatWords[12]; $hcFound = true; } if ($WC < -1 and ! $hcFound) { $hcWord = $HeatWords[11]; $hcFound = true; } if ($WC < 8 and ! $hcFound) { $hcWord = $HeatWords[10]; $hcFound = true; } if ($WC < 16 and ! $hcFound) { $hcWord = $HeatWords[9]; $hcFound = true; } } elseif ($WC >= 16 and $TC <= 32) { if ($TC <= 26 and ! $hcFound) { $hcWord = $HeatWords[8]; $hcFound = true; } if ($TC <= 32 and ! $hcFound) { $hcWord = $HeatWords[7]; $hcFound = true; } } if(isset($_REQUEST['debug'])) { echo "\n"; } return(array($feelslike,$hcWord)); } // end of WXS_setFeelslike #------------------------------------------------------------------------------------- # WXS support function - WXS_CBI - Chandler Burning Index #------------------------------------------------------------------------------------- function WXS_CBI($inTemp,$inTempUOM,$inHumidity) { // thanks to Chris from sloweather.com for the CBI calculation script // modified by Ken True for template usage preg_match('/([\d\.\+\-]+)/',$inTemp,$t); // strip non-numeric from inTemp if any $ctemp = $t[1]; if(!preg_match('|C|i',$inTempUOM)) { $ctemp = ($ctemp-32.0) / 1.8; // convert from Fahrenheit } preg_match('/([\d\.\+\-]+)/',$inHumidity,$t); // strip non-numeric from inHumidity if any $rh = $t[1]; // Start Index Calcs // Chandler Index $cbi = (((110 - 1.373 * $rh) - 0.54 * (10.20 - $ctemp)) * (124 * pow(10,-0.0142 * $rh) ))/60; // CBI = (((110 - 1.373*RH) - 0.54 * (10.20 - T)) * (124 * 10**(-0.0142*RH)))/60 //Sort out the Chandler Index $cbi = round($cbi,1); if ($cbi > "97.5") { $cbitxt = "EXTREME"; $cbiimg= "fdl_extreme.gif"; } elseif ($cbi >="90") { $cbitxt = "VERY HIGH"; $cbiimg= "fdl_vhigh.gif"; } elseif ($cbi >= "75") { $cbitxt = "HIGH"; $cbiimg= "fdl_high.gif"; } elseif ($cbi >= "50") { $cbitxt = "MODERATE"; $cbiimg= "fdl_moderate.gif"; } else { $cbitxt="LOW"; $cbiimg= "fdl_low.gif"; } $data = array($cbi,$cbitxt,$cbiimg); return $data; } // end WXS_CBI #------------------------------------------------------------------------------------- # end of WXS support functions #------------------------------------------------------------------------------------- ?>