\r"; /*------------------------------------------------ //WU-History.php //PHP script by Jim McMurry - jmcmurry@mwt.net - jcweather.us //Current version maintained at http://jcweather.us/scripts.php //Version 1.0 February 18, 2008 // 1.1 February 19, 2008 - Fixed a broken link to WU & added optional selection of other stations. // 1.2 February 20, 2008 - Fixed an obscure link bug dealing with the new "other station" option. // 1.3 February 22, 2008 - Added option to omit cloud conditions from tabular listing. Fixed solar & rain issue in the summary section. // 1.4 February 22, 2008 - Supressed Solar & UV graphs in monthly & longer modes. Supressed current conditions in the summary except when viewing current day. // 1.5 February 23, 2008 - Fixed precip error when viewing previous days. Added optional top link in header to return to "today" when off somewhere else. // 1.6 February 27, 2008 - Fixed some missing tags that were missing in the English mode that were preventing validation. // 1.7 March 25, 2008 - Removed a superfluous tag that caused a failed validation when using the option for multiple stations. // 1.8 April, 05, 2008 - added Settings.php awareness to script (K True/saratoga-weather.org) for Carterlake/WD/AJAX/PHP templates. // 1.9 April 07, 2008 - Made the tabular data listing optional. // 2.0 December 23, 2008 - Fixes bugs in code to determine units output. (Thanks to Jozef (Pinto) for finding those. // 2.1 December 23, 2008 - Fixes the modes other than Daily that were affected. (Jozef is now officially a co-author) // 2.2 January 31, 2009 - Fixes errors in average wind and some metric rain conversions. (Thanks to Paul Gogan for finding these) // 2.3 February 10, 2009 - A better fix to the average wind issue and a variable we can turn off when they fix the problem. // 2.4 April 18, 2009 - Changed cm to mm in tabular section when showing units "both" in daily mode. Added Solar to daily tabular data // 2.5 April 15, 2010 - Fixed a bug found by Pelle where metric rain wasn't being converted to mm in the summary section // 2.6 August 8, 2011 - Chenged the above back to get the rain right again due to problem reported by Oebel // 2.7 February 3, 2012 - Put in a check to preclude selecting a future date which was causing problems for Wunderground // 2.8 October 10, 2013 - Fixed the spacing on some of the units. Found by Han // 2.9 December 1, 2013 - Fixed first of the week/month or other times that there's no data in the csv file. Found by Han // 3.0 December 29, 2014 - WU doesn't remove deleted lines, but makes temps -999 so this removes those. Found by Jerry Callahan // 3.1 April 28, 2015 - Jachym found - If data is missing WU will usually report -999.9 or -573.3 (that is -999.9 F converted to C....) // 3.2 January 28, 2016 - ereg_replace changed to str_replace for PHP 7.0. Thanks Wim // 3.3 March 4, 2016 - Changed code for getting WU data. Thanks once again Wim // //Portions of the code was borrowed from: //Weather Underground - wunderground.com //Ken True - saratoga-weather.org //Tom Chaplin - carterlake.org //Kevin Reed - tnetweather.com //and probably several others. //This script retrieves a weather station's raw data from Weather Underground //and displays it in a similar way to how they do it on their site. //Weather Underground is very willing to share the graphics and data //on their site with those who provide weather data to them. //In a correspondence with Ken True, John Celenza, Director of Weather //Technology at Wunderground stated: //"Please feel free to use Wunderground images and data on personal sites, //as long as you link those images to Wunderground or give direct credit. //Something like 'This image courtesy of Weather Underground' is appropriate." //This script does NOT generate a complete HTML page and is intended for use //ONLY by being included in an existing webpage on your site by: // include("./WU-History.php"); //You'll also have to place the following in the section of your calling //page: // //See the enclosed test file TestHistory.php to see how this is done. //If your WU-history files are to be kept in a folder other than where your //calling page is, you'll have to adjust the above. As an example, //if your calling page is in the root folder of your web site and the WU files //have been placed in a folder named /abc/, the paths above would need to be // ./abc/WU-History.xxx //If using the optional files below to place information to the right of the //summary area, the same path will have to be used with those files as well. //Just remember that the paths are always relative to the calling page. //The supporting graphics are in the enclosed wuicons folder, and that folder //must be placed in the same folder with this script. If you wish the icons //elsewhere, just make the appropriate changes in WU-History.css. //Optional parameters are normally not necessary, but there are a few available: //ID=xxxxxxx should you wish to call it with a different station ID for some reason //day=xx for a day other than today //month=xx for a month other than this month //year=xxxx for a different year //There must be a "?" to signal the beginning of the parameters and "&" between items //So, if you wished to call it for my station and show last Christmas, you'd use //WU-History.php?ID=KWIMAUST1&day=25&month=12&year=2007 //Folks with graphic talent may want to modify the css and create graphics in other //colors in order to come up with different color schemes. If you put something //together that you'd like to share, please send me copies of the .css and the //graphics and I'd be happy to add them to this package for others to use. //This script Is Valid XHTML 1.0 Strict! $WunderWrong //settings ----------------------------- */ // Special Temporary Setting. In week, month or year modes, Wundergrund is sending Average Wind in mph instead of km/h. Only affects metric users. // I'll get the word out if they fix it and you can turn it off. $WunderWrong = true; // $timezone = "America/Chicago"; // Change to your TZ. Ken True has a list available at http://saratoga-weather.org/timezone.txt $WUID = "KWIMAUST1"; // Your stations Wunderground ID $units = "B"; // Default units which are changeable at runtime. "M" for Metric, "E" for English or "B" for Both $birthday = "02-06-2005"; // Stations first day of operation format dd-mm-yyyy. This will determine years on the date selector. $gwidth = "500"; // Width of the graph - normally 500 $gtemp = true; // =true if you want the temperature graph =false if no $gpress = true; // =true if baro graph =false if no $gwind = true; // =true if wind velocity graph =false if no $gwindir = true; // =true if wind direction graph =false if no $grain = true; // =true if rain graph =false if no $gsolar = true; // =true if solar graph =false if no $guv = true; // =true if UV graph =false if no $pwidth = "100%"; // The width of the summary and graph portion of the page (% or px). Normally 100% // Optional header info $header = true; // true if you wish to use it $Langtitle = "Station Historical Data"; // The Bold text at the top $LcurDay = "Return to Current Day"; // The link back to the current day if off in one of the other modes. "" to disable it. // Optional footer bar $footer = true; // true if you wish to have the colored footer bar at the bottom $LangFtext = "Juneau County Weather"; // Anything you wish or "" for a plain bar // Optional content to be placed to the right of the Summary/Graph portion of the page $inboxfile = "./top.htm"; // A file of html to be placed in the right outlined box. Make it "" if not using, or just don't have a file available. $outboxfile = "./bottom.htm"; // Same but for the area below the right blue box. Paths to the files must be relative to the calling page. // Optional "Return to Top" link on the right side $toTop = false; // Most will want this, but some folks have alternative methods. $LtopPg = "Return to Top"; // Optional selector for other PWS data $selOthers = false; // true if you wish to show other stations, false if not $otherIds = array('KWIMAUST1', 'ISILKEBO2', 'IVLAAMSG7', 'IBOUCHES4'); // Only works for PWS - Not Airports! $otherLocat = array('Mauston, WI', 'Silkeborg, DK', 'Kampenhout, BE', 'Cassis, FR'); // Option to not show sky conditions in the daily tabular listing $skipSolar = false; // true to skip solar data, false to include them $skipSky = false; // true to skip sky conditions, false to include them // Option to not show the tabular data $skipTab = false; // true if you wish to suppress the tabular data // // Language changes follow. If unsure about any of them, try it and see what happens. $mnthname = array('Nil', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); // Next are for the Summary Table $Langtabs = array('Daily', 'Weekly', 'Monthly', 'Yearly', 'Custom'); // Tabs above the Summary Table $LangSumHeads = array("Temperature", "Dew Point", "Humidity", "Wind Speed", "Wind Gust", "Wind", "Pressure", "Precipitation", "Solar"); // Headings for the Summary Table $LangSumCols = array("Current", "High", "Low", "Average"); $LSumfor = "Summary for"; $Lunits = "Units"; $Lboth = "Both"; $Lenglish = "English"; $Lmetric = "Metric"; $Lnext = "Next"; $Lprev = "Previous"; $Ltarget = array("Day", "Week", "Month", "Year"); $Lview = "View"; $LNoData = "No Data Available for This Period"; // added 12/1/13 $Ltab1 = "Tabular Data for"; // Next 5 for Blue bar above the Tabular listing $Ltab2 = "Weeks Tabular Data"; $Ltab3 = "Months Tabular Data"; $Ltab4 = "Years Tabular Data"; $Ltab5 = "Custom Date Range Tabular Data"; // Next are for the Tabular Table $Lheadings = array('Time', 'Temperature', 'Dew Point', 'Pressure', 'Wind', 'Wind Speed', 'Wind Gust', 'Humidity', 'Rainfall Rate (Hourly)', 'solar', 'Conditions'); // Headings when in weekly, monthly etc modes $Lhdngs2 = array("Temp", "Dew Point", "Humidity", "Sea Level Pressure", "Wind", "Gust Speed", "Precip"); $Lcols2 = array("high", "ave", "low", "sum"); $Lcommafile= "Comma Delimited File"; $Lthanks = "Compliments of"; // // end of settings //------------------------------------------------ // overrides from Settings.php if available global $SITE; if (isset($SITE['tz'])) {$timezone = $SITE['tz'];} if (isset($SITE['WUID'])) {$WUID = $SITE['WUID'];} if (isset($SITE['uomTemp'])) { $units = preg_match('|C|i',$SITE['uomTemp']) ? 'M':'E'; } if (isset($SITE['WUunits'])) {$units = $SITE['WUunits'];} if (isset($SITE['WUstationname'])) {$LangFtext = $SITE['WUstationname'];} if (isset($SITE['WUbirthday'])) {$birthday = $SITE['WUbirthday'];} if (isset($SITE['UV'])) {$guv = $SITE['UV'];} if (isset($SITE['SOLAR'])) {$gsolar = $SITE['SOLAR'];} if (isset($SITE['timeFormat'])) {$timeFormat = $SITE['timeFormat'];} // end of overrides from Settings.php if available if (!function_exists('date_default_timezone_set')) { putenv("TZ=" . $timezone); } else { date_default_timezone_set($timezone); } if (isset($_REQUEST['sce']) && strtolower($_REQUEST['sce']) == 'view' ) { //--self downloader -- $filenameReal = __FILE__; $download_size = filesize($filenameReal); header('Pragma: public'); header('Cache-Control: private'); header('Cache-Control: no-cache, must-revalidate'); header("Content-type: text/plain"); header("Accept-Ranges: bytes"); header("Content-Length: $download_size"); header('Connection: close'); readfile($filenameReal); exit; } echo $Version; if(isset($_REQUEST['debug'])) {$debug = true; } // Set some dates $mo = date("m"); $da = date("d"); $yr = date("Y"); $FIRST_YEAR = substr($birthday,6,4); $LAST_YEAR = $yr; if ($debug) { print "\n"; print "\n"; } // Defaults if called without parameters $PHP_SELF = $_SERVER['PHP_SELF']; if ( empty($_REQUEST['ID']) ) $_REQUEST['ID']=$WUID; if ( empty($_REQUEST['day']) ) $_REQUEST['day']=$da; if ( empty($_REQUEST['dayend']) ) $_REQUEST['dayend']=$da; if ( empty($_REQUEST['month']) ) $_REQUEST['month']=$mo; if ( empty($_REQUEST['monthend']) ) $_REQUEST['monthend']=$mo; if ( empty($_REQUEST['year']) ) $_REQUEST['year']=$yr; if ( empty($_REQUEST['yearend']) ) $_REQUEST['yearend']=$yr; if ( empty($_REQUEST['units']) ) $_REQUEST['units']=$units; if ( empty($_REQUEST['mode']) ) $_REQUEST['mode']=1; if ($debug) {print "\n";} //Pass into PHP variables //------------------------------------------------ $WUID = $_REQUEST['ID']; $da = $_REQUEST['day']; $mo = $_REQUEST['month']; $yr = $_REQUEST['year']; $da2 = $_REQUEST['dayend']; $mo2 = $_REQUEST['monthend']; $yr2 = $_REQUEST['yearend']; $units = $_REQUEST['units']; $mode = $_REQUEST['mode']; print "\n"; // Find out if it's today or in the past $reqdate = $da . "-" . $mo . "-" . $yr; $isToday = strtotime($reqdate) == strtotime(date("d-m-Y")); if (time() < strtotime($mo . "/" . $da . "/" . $yr)) { // preclude any dates in the future that were causing problems for Wunderground $mo = date("n"); $da = date("j"); $yr = date("Y"); } // Gather the csv data $WUgraphstr = "http://www.wunderground.com/cgi-bin/wxStationGraphAll"; $WUdatastr = "http://www.wunderground.com/weatherstation/WXDailyHistory.asp"; if ($mode == 1) { $wunderstring = $WUdatastr . "?ID=" . $WUID . "&month=" . $mo . "&day=" . $da . "&year=" . $yr . "&format=1&graphspan=day"; // Day } elseif ($mode == 2) { $wunderstring = $WUdatastr . "?ID=" . $WUID . "&month=" . $mo . "&day=" . $da . "&year=" . $yr . "&format=1&graphspan=week"; // Week } elseif ($mode == 3) { $wunderstring = $WUdatastr . "?ID=" . $WUID . "&month=" . $mo . "&day=" . $da . "&year=" . $yr . "&format=1&graphspan=month"; // Month } elseif ($mode == 4) { $wunderstring = $WUdatastr . "?ID=" . $WUID . "&month=" . $mo . "&day=" . $da . "&year=" . $yr . "&format=1&graphspan=year"; // Year } elseif ($mode == 5) { $wunderstring = $WUdatastr . "?ID=" . $WUID . "&month=" . $mo . "&day=" . $da . "&year=" . $yr . "&monthend=" . $mo2 . "&dayend=" . $da2 . "&yearend=" . $yr2 . "&format=1&graphspan=custom"; // Custom } $csvraw=getcsvWithoutHanging($wunderstring); //echo $wunderstring; //print_r($csvraw); //exit; $csvdata = array_pure($csvraw); //$csvdata has headings in row 0. Saving a copy for no good reason echo "\r"; // Thanks to Jerry Callahan for finding this issue foreach($csvdata as $key => &$line) { // See if there are any deleted entries and remove them if ($line[1] < -100 || $line[1] > 150) { // If data is missing WU will usually report -999.9 or -573.3 (that is -999.9 F converted to C....) // if ($line[1] == -999.0) { // Temp is this when the line's been deleted by the user echo "\r"; unset($csvdata[$key]); } } unset($line); // break the reference with the last element echo "\r"; $csvarray = $csvdata; if ($mode == 1){ array_shift($csvarray); // Now $csvarray has nothing but 2D data. The other modes don't need this treatment if ($csvarray[0][3] > 50) { // Use Baro to determine whether raw data is metric or not $rawunits = "metric"; // Depends on how the user's wunderground cookie is set } else { $rawunits = "english"; } if ($debug) { echo "\n"; } } else { if ($csvarray[0][10] > 50) { // Baro is in a different position in the other modes $rawunits = "metric"; } else { $rawunits = "english"; } if ($debug) {echo "\n";} } sizeof($csvarray) > 0 ? $DataGood = true : $DataGood = false; // changed 12/1/13 $wunderCSVstring = str_replace("&","&",$wunderstring); // So the link to the csv output will validate ?>
' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; $needheading = false; echo '' . "\n"; } echo '' . "\n"; for ($col=0; $col<$columns; $col++) { $data = $csvarray[$row][$col]; if ($col == 0) { $pmo = substr($data, 5, 2); $pda = substr($data, strrpos($data,"-")+1, 2); $pyr = substr($data, 0, 4); $tdate = AddDate($pmo, $pda, $pyr, 0); // just to get the name of the day if ($row !== count($csvarray) - 1) { // ie not the last row if (substr($data, 0, 7) !== substr($csvarray[$row+1][0], 0, 7)) $needheading = true; } $data = ''; //Date/Time } if ($col == 1) { $convarray = convertTemps($data); $data = merge_data($convarray); // Figures out which measurement is desired & returns it $data = ''; // Temp } if ($col == 2) { $convarray = convertTemps($data); $data = merge_data($convarray); $data = ''; } if ($col == 3) { $convarray = convertTemps($data); $data = merge_data($convarray); $data = ''; } if ($col == 4 || $col == 5 || $col == 6) { // DP $convarray = convertTemps($data); $data = merge_data($convarray); $data = ''; } if ($col == 7) $data = ''; // Humidity if ($col == 8) $data = ''; if ($col == 9) $data = ''; if ($col == 10 || $col == 11) { // Baro $convarray = convertBaro($data); $data = merge_data($convarray); $data = ''; } if ($col == 12) { // Wind if ($debug) echo $data . " "; $convarray = convertWind($data); $data = merge_data($convarray); $data = ''; } if ($col == 13) { if ($debug) echo $data . " "; $convarray = convertWind($data); // Returns an array with km in [0] and mi in [1] if ($WunderWrong) { if ($rawunits == "metric") $convarray[0] = miTokm($convarray[0],1); // Wunderground is sending in mph vs km/h } $data = merge_data($convarray); /* if ($rawunits == "metric") $data = miTokm($data,1); // PG 28/01/2009 (WU send mi/h instead of km/h for average wind speed) */ $data = ''; } if ($col == 14) { // Gust if ($debug) echo $data . " / "; $convarray = convertWind($data); $data = merge_data($convarray); $data = ''; } if ($col == 15) { // Rain // $convarray = convertRainCM($data); // changed 8/2010 $convarray = convertRainMM($data); $data = merge_data($convarray); $data = ''; } echo $data; } // Columns echo ''; if ($needheading) { echo ''; echo '
' . $Langtitle . '
' . "\r"; // Display link back to current day if not currently showing "today" if (($mode > 1 or ! $isToday) && $LcurDay <> "") { $callstr = $PHP_SELF . '?ID=' . $WUID . '&month=' . date("m") . '&day=' . date("d") . '&year=' . date("Y") . '&mode=1&units=' . $units; echo '' . "\r"; } else { echo '
 
' . "\r"; } } if ($mode == 1) { $bannerphrase = $Langtabs[0] . ' ' . $LSumfor . ' ' . $mnthname[intval($mo)] . ' ' . $da . ', ' . $yr; } elseif ($mode == 2) { $bannerphrase = $Langtabs[1] . ' ' . $LSumfor . ' ' . $mnthname[intval($mo)] . ' ' . $da . ', ' . $yr; } elseif ($mode == 3) { $bannerphrase = $Langtabs[2] . ' ' . $LSumfor . ' ' . $mnthname[intval($mo)] . ' ' . $yr; } elseif ($mode == 4) { $bannerphrase = $Langtabs[3] . ' ' . $LSumfor . ' ' . $yr; } else { $bannerphrase = $LSumfor . ' ' . $mnthname[intval($mo)] . ' ' . $da . ', ' . $yr . ' - ' . $mnthname[intval($mo2)] . ' ' . $da2 . ', ' . $yr2; } ?> '; echo '
'; echo '
'; echo '
'; include ($inboxfile); echo '
'; echo '
'; if (file_exists($outboxfile)) { include ($outboxfile); } echo '
'; echo ''; } ?>
' . $Lmetric . '    ' . $Lenglish . '   ' . $Lboth . ''; } elseif ($units == "E") { echo $Lunits . ':  ' . $Lenglish . '    ' . $Lmetric . '   ' . $Lboth . ''; } else { echo $Lunits . ':  ' . $Lboth . '    ' . $Lenglish . '   ' . $Lmetric . ''; } ?>
« ' . $Lprev . ' ' . $Ltarget[0] . ''; } elseif ($mode == 2) { $ndate = AddDate($mo, $da, $yr, -7); echo ''; } elseif ($mode == 3) { $ndate = AddDate($mo, $da, $yr, -30); echo ''; } elseif ($mode == 4) { $ndate = AddDate($mo, $da, $yr, -365); echo ''; } ?> ' . $Lnext . ' ' . $Ltarget[0] . ' »'; } elseif ($mode == 2) { $ndate = AddDate($mo, $da, $yr, +7); echo ''; } elseif ($mode == 3) { $ndate = AddDate($mo, $da, $yr, +30); echo ''; } elseif ($mode == 4) { $ndate = AddDate($mo, $da, $yr, +365); echo ''; } ?>
« ' . $Lprev . ' ' . $Ltarget[1] . '« ' . $Lprev . ' ' . $Ltarget[2] . '« ' . $Lprev . ' ' . $Ltarget[3] . ' '; echo ''; if ($selOthers) { echo ''; } echo ''; if ($mode == 5) { //Add second set here echo ''; } echo '
- TO -
' . "\n"; ?>
' . $Lnext . ' ' . $Ltarget[1] . ' »' . $Lnext . ' ' . $Ltarget[2] . ' »' . $Lnext . ' ' . $Ltarget[3] . ' »
' . $Langtabs[0] . '' . "\n"; } else { echo '' . "\n"; } if ($mode == 2) { echo '' . "\n"; } else { echo '' . "\n"; } if ($mode == 3) { echo '' . "\n"; } else { echo '' . "\n"; } if ($mode == 4) { echo '' . "\n"; } else { echo '' . "\n"; } if ($mode == 5) { echo '' . "\n"; } else { echo '' . "\n"; } ?>
' . $Langtabs[0] . '' . $Langtabs[1] . '' . $Langtabs[1] . '' . $Langtabs[2] . '' . $Langtabs[2] . '' . $Langtabs[3] . '' . $Langtabs[3] . '' . $Langtabs[4] . '' . $Langtabs[4] . '
' . $LangSumCols[0] . ':'; ?> \n"; if ($mode == 1) { $result=temp_stats($csvarray, 1); // Temp $current=convertTemps($csvarray[count($csvarray)-1][1]); } else { $t = temp_stats($csvarray, 1); // Process column 1 of the raw data $result[0] = $t[0]; // Store just the Hi (of the Hi's) $t = temp_stats($csvarray, 3); // Then column 2 which are the Lo's $result[1] = $t[1]; // Store the Lo (of the Lo's) $t = temp_stats($csvarray, 2); // Lastly proces column 3 which are the ave's $result[2] = $t[2]; // Store the Ave (of the Ave's) } if ($units == "M") { if ($mode == 1 && $isToday) echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } elseif ($units == "E"){ if ($mode == 1 && $isToday) echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } else { if ($mode == 1 && $isToday) echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } ?> ' . $current[0] . ' °C' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } elseif ($units == "E"){ if ($mode == 1 && $isToday) echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } else { if ($mode == 1 && $isToday) echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } ?> ' . $csvarray[count($csvarray)-1][8] . '%' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; ?> ' . $current[0] . 'km/h' . "\n"; echo '' . "\n"; if ($result[1] == 0){ echo '' . "\n";} else{ echo '' . "\n";} echo '' . "\n"; } elseif ($units == "E"){ if ($mode == 1 && $isToday) echo '' . "\n"; echo '' . "\n"; if ($result[1] == 0){ echo '' . "\n";} else{ echo '' . "\n";} echo '' . "\n"; } else { if ($mode == 1 && $isToday) echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } ?> ' . $current[0] . 'km/h' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } elseif ($units == "E"){ if ($mode == 1 && $isToday) echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } else { if ($mode == 1 && $isToday) echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } ?> '; echo ''; $result=wDirAvg($csvarray); // Wind Direction if ($csvarray[count($csvarray)-1][6]==0) { $current = "Calm"; } else { $current = $csvarray[count($csvarray)-1][4]; } if ($mode == 1 && $isToday) echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } ?> ' . $current[0] . ' hPa' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } elseif ($units == "E"){ if ($mode == 1 && $isToday) echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } else { if ($mode == 1 && $isToday) echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo ''; } ?> ' . $current[0] * 10 . ' mm'; // To fix the cm to mm conversion problem found by Pelle echo ''; // Changed back 8/2011 } elseif ($units == "E"){ echo ''; } else { // echo ''; // Same echo ''; } ?>  '; } ?>
  : : :
' . $current[0] . ' °C' . $result[0][0] . ' °C' . $result[1][0] . ' °C' . $result[2][0] . ' °C' . $current[1] . ' °F' . $result[0][1] . ' °F' . $result[1][1] . ' °F' . $result[2][1] . ' °F' . $current[1] . ' °F /  ' . $current[0] . ' °C' . $result[0][1] . ' °F /  ' . $result[0][0] . ' °C' . $result[1][1] . ' °F /  ' . $result[1][0] . ' °C' . $result[2][1] . ' °F /  ' . $result[2][0] . ' °C
' . $result[0][0] . ' °C' . $result[1][0] . ' °C' . $result[2][0] . ' °C' . $current[1] . ' °F' . $result[0][1] . ' °F' . $result[1][1] . ' °F' . $result[2][1] . ' °F' . $current[1] . ' °F /  ' . $current[0] . ' °C' . $result[0][1] . ' °F /  ' . $result[0][0] . ' °C' . $result[1][1] . ' °F /  ' . $result[1][0] . ' °C' . $result[2][1] . ' °F /  ' . $result[2][0] . ' °C
' . $result[0] . '%' . $result[1] . '%' . round($result[2],0) . '%
' . $result[0][0] . 'km/h-' . $result[1][0] . 'km/h' . $result[2][0] . 'km/h' . $current[1] . 'mph' . $result[0][1] . 'mph-' . $result[1][1] . 'mph' . $result[2][1] . 'mph' . $current[1] . 'mph /  ' . $current[0] . 'km/h' . $result[0][1] . 'mph /  ' . $result[0][0] . 'km/h-' . $result[2][1] . 'mph /  ' . $result[2][0] . 'km/h
' . $result[0][0] . 'km/h--' . $current[1] . 'mph' . $result[0][1] . 'mph--' . $current[1] . 'mph /  ' . $current[0] . 'km/h' . $result[0][1] . 'mph /  ' . $result[0][0] . 'km/h--
' . $LangSumHeads[5] . '' . $current . '--' . degTotxt($result) . '
' . $result[0][0] . ' hPa' . $result[1][0] . ' hPa-' . $current[1] . ' in' . $result[0][1] . ' in' . $result[1][1] . ' in-' . $current[1] . ' in /  ' . $current[0] . ' hPa' . $result[0][1] . ' in /  ' . $result[0][0] . ' hPa' . $result[1][1] . ' in /  ' . $result[1][0] . ' hPa-
' . $current[0] . ' mm' . $current[1] . ' in' . $current[1] . ' in /  ' . $current[0] * 10 . ' mm' . $current[1] . ' in /  ' . $current[0] . ' mm   
 

' . $LNoData . '

 

'; } ?>
Historical Graphs
 
 
' . $LtopPg . ''; } if (! $skipTab) { // Begin tabular section with option to suppress if ($mode == 1) { $bannerphrase = $Ltab1 . ' ' . $mnthname[intval($mo)] . ' ' . $da . ', ' . $yr; } elseif ($mode == 2) { $bannerphrase = $Ltab2; } elseif ($mode == 3) { $bannerphrase = $Ltab3; } elseif ($mode == 4) { $bannerphrase = $Ltab4; } else { $bannerphrase = $Ltab5; } echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '
' . $bannerphrase . '
' . "\n"; echo '
' . "\n"; // This is the lower data table when in Daily mode if ($mode == 1) { echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; $columns = 10; if (! $skipSolar) { echo '' . "\n"; $columns++; } if (! $skipSky) { echo '' . "\n"; $columns++; } echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; for ($row=0; $row" . "\n"; for ($col=0; $col<$columns; $col++) { $data = $csvarray[$row][$col]; if ($col == 0) $data = substr($data,11,5); //Date/Time if ($col == 1 || $col == 2){ // Temp or DP $convarray = convertTemps($data); if ($units == "M") { $data = "" . $convarray[0] . " °C"; } elseif ($units == "E"){ $data = "" . $convarray[1] . " °F"; } else { $data = "" . $convarray[1] . " °F /  " . "" . $convarray[0] . " °C"; } } if ($col == 3) { // Baro $convarray = convertBaro($data); if ($units == "M") { $data = "" . $convarray[0] . " hPa"; } elseif ($units == "E"){ $data = "" . $convarray[1] . " in"; } else { $data = "" . $convarray[1] . "in /  " . "" . $convarray[0] . "hPa"; } } if ($col == 4) { // Wind direction if ($csvarray[$row][$col+2]==0) $data = "Calm"; $col++; // Skip the wind "degrees" column } if ($col == 6 || $col == 7){ // Wind or Gust $convarray = convertWind($data); if ($data == 0) { $data = " "; } elseif ($units == "M") { $data = "" . $convarray[0] . " km/h"; } elseif ($units == "E"){ $data = "" . $convarray[1] . " mph"; } else { $data = "" . $convarray[1] . "mph /  " . "" . $convarray[0] . "km/h"; } } if ($col == 8) $data = $data . "%"; //Humidity if ($col == 9) { // Rain $convarray = convertRainMM($data); if ($units == "M") { $data = "" . $convarray[0] . " mm"; } elseif ($units == "E"){ $data = "" . $convarray[1] . " in"; } else { $data = "" . $convarray[1] . "in /  " . "" . $convarray[0] . "mm"; } /* if ($skipSolar) { $col = $col + 1; // Skip the solar column } if ($skipSky) { $col = $col + 1; // Skip the condition column } */ } if ($col == 10 && ! $skipSolar) { // Solar $data = $csvarray[$row][$col+3]; $data = "" . $data . " W/m2"; } if ($col == 11 && ! $skipSky) { // Conditions $data = $csvarray[$row][$col-1]; } echo '" . "\n"; } // for $col echo ""; } // for $row echo ''; echo '
' . $Lheadings[0] . '' . $Lheadings[1] . '' . $Lheadings[2] . '' . $Lheadings[3] . '' . $Lheadings[4] . '' . $Lheadings[5] . '' . $Lheadings[6] . '' . $Lheadings[7] . '' . $Lheadings[8] . '' . $Lheadings[9] . '' . $Lheadings[10] . '
' . $data . "
'; } else { // Its weekly, monthly, yearly or custom if ($units == "M") { $tsym = "°C"; $bsym = "hPa"; $dsym = "km/h"; $vsym = "km"; $rsym = "cm"; // $rsym = "mm"; // Change to mm for Pelle } elseif ($units == "E") { $tsym = "°F"; $bsym = "in"; $dsym = "mph"; $vsym = "mi"; $rsym = "in"; } else { $tsym = "°F / °C"; $bsym = "in / hPa"; $dsym = "mph / km/h"; $vsym = "mi / km"; $rsym = "in / cm"; // $rsym = "in / mm"; // Change to mm for Pelle } $pmo = substr($csvarray[0][0], 5, 2); $pda = substr($csvarray[0][0], strrpos($csvarray[0][0],"-")+1, 2); $pyr = substr($csvarray[0][0], 0, 4); $columns = 16; $needheading = true; for ($row=0; $row' . "\n"; echo '
' . $pyr . '' . $Lhdngs2[0] . ' (' . $tsym . ')' . $Lhdngs2[1] . ' (' . $tsym . ')' . $Lhdngs2[2] . ' (%)' . $Lhdngs2[3] . ' (' . $bsym . ')' . $Lhdngs2[4] . ' (' . $dsym . ')' . $Lhdngs2[5] . ' (' . $dsym . ')' . $Lhdngs2[6] . ' (' . $rsym . ')
' . $col1title . '' . $Lcols2[0] . '' . $Lcols2[1] . '' . $Lcols2[2] . '' . $Lcols2[0] . '' . $Lcols2[1] . '' . $Lcols2[2] . '' . $Lcols2[0] . '' . $Lcols2[1] . '' . $Lcols2[2] . '' . $Lcols2[0] . '' . $Lcols2[2] . '' . $Lcols2[0] . '' . $Lcols2[1] . '' . $Lcols2[0] . '' . $Lcols2[3] . '
' . substr($tdate[weekday], 0, 3) . '' . $pda . '' . $data . '' . $data . '' . $data . '' . $data . '' . $data . '' . $data . '' . $data . '' . $data . '' . $data . '' . $data . '' . $data . '' . $data . '
'; } } // Rows echo ''; echo ''; } echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '
' . "\n"; echo '
' . "\n"; // echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '
' . "\n"; } // End of skipping tabular data echo '' . "\n"; // // if ($toTop == 1) { // Optional link to top of the page echo '
' . $LtopPg . '
'; } if ($footer and $LangFtext <> '') { echo '
' . $LangFtext . '
'; } ?>
Weather Underground -
$hi) $hi=$arr[$row][$col]; if ($arr[$row][$col] < $lo) $lo=$arr[$row][$col]; } $return[0] = $hi; $return[1] = $lo; $return[2] = round($tot / count($arr),1); return $return; } function temp_stats($arr, $col) { //Returns array $return with Hi Lo & Ave in [0],[1]&[2] //Each of those is an array with C in 0 and F in 1 $hi=$arr[0][$col]; $lo=$arr[0][$col]; $tot=0; for ($row=0; $row $hi) $hi=$arr[$row][$col]; if ($arr[$row][$col] < $lo) $lo=$arr[$row][$col]; } $return[0] = convertTemps($hi); $return[1] = convertTemps($lo); $return[2] = convertTemps(round($tot / count($arr),1)); return $return; } function convertTemps($raw) { // Returns an array with C in [0] and F in [1] global $rawunits; if ($rawunits == "english") { $return[0] = FtoC($raw,1); $return[1] = $raw; } else { $return[0] = $raw; $return[1] = CtoF($raw,1); } return $return; } function CtoF ($cTemp, $prec=0) { $prec = (integer)$prec; $fTemp = (float)(1.8 * $cTemp) + 32; return round($fTemp, $prec); } function FtoC ($fTemp, $prec=0) { $prec = (integer)$prec; $cTemp = (float)(($fTemp - 32) / 1.8 ); return round($cTemp, $prec); } function baro_stats($arr, $col) { //Returns array $return with Hi Lo & Ave in [0],[1]&[2] //Each of those is an array with mb in 0 and inches in 1 $hi=$arr[0][$col]; $lo=$arr[0][$col]; $tot=0; for ($row=0; $row $hi) $hi=$arr[$row][$col]; if ($arr[$row][$col] < $lo) $lo=$arr[$row][$col]; } $return[0] = convertBaro($hi); $return[1] = convertBaro($lo); $return[2] = convertBaro(round($tot / count($arr),1)); return $return; } function convertBaro($raw) { // Returns an array with mb in [0] and inches in [1] global $rawunits; if ($rawunits == "english") { $return[0] = inTomb($raw,1); $return[1] = $raw; } else { $return[0] = $raw; $return[1] = mbToin($raw,1); } return $return; } function inTomb ($inch, $prec=0) { $prec = (integer)$prec; $mb = (float)$inch * 33.86; return round($mb, $prec); } function mbToin ($mb, $prec=0) { $prec = (integer)$prec; $in = (float)$mb / 33.86; return round($in, $prec); } function wind_stats ($arr, $col) { //Returns array $return with Hi Lo & Ave in [0],[1]&[2] //Disregards 0 or "calm" entries $hi=$arr[0][$col]; $lo=$arr[0][$col]; $tot=0; $num=0; for ($row=0; $row $hi) $hi=$arr[$row][$col]; if ($arr[$row][$col] < $lo) $lo=$arr[$row][$col]; //} } $return[0] = convertWind($hi); $return[1] = convertWind($lo); $return[2] = convertWind(round($tot / $num,1)); return $return; } function convertWind($raw) { // Returns an array with km in [0] and mi in [1] global $rawunits; if ($rawunits == "english") { $return[0] = miTokm($raw,1); $return[1] = $raw; } else { $return[0] = $raw; $return[1] = kmTomi($raw,1); } return $return; } function wDirAvg($arr) { //Returns average wind direction //Disregards 0 or "calm" entries $tot=0; $num=0; for ($row=0; $row= 0 ) $return = "North"; if ($wind > 10 ) $return = "NNE"; if ($wind > 33 ) $return = "NE"; if ($wind > 55 ) $return = "ENE"; if ($wind > 78 ) $return = "East"; if ($wind > 100 ) $return = "ESE"; if ($wind > 123 ) $return = "SE"; if ($wind > 145 ) $return = "SSE"; if ($wind > 168 ) $return = "South"; if ($wind > 190 ) $return = "SSW"; if ($wind > 213 ) $return = "SW"; if ($wind > 235 ) $return = "WSW"; if ($wind > 258 ) $return = "West"; if ($wind > 280 ) $return = "WNW"; if ($wind > 303 ) $return = "NW"; if ($wind > 325 ) $return = "NNW"; if ($wind > 348 ) $return = "North"; return $return; } function miTokm ($mile, $prec=0) { $prec = (integer)$prec; $km = (float)$mile * 1.6093; return round($km, $prec); } function kmTomi ($km, $prec=0) { $prec = (integer)$prec; $mi = (float)$km * .6213; return round($mi, $prec); } function total_rain($arr, $col) { //Returns the total rain in a column in an array //When in metric mode, wunderground gives us rain in cm global $rawunits; $tot=0; for ($row=0; $row 40 [minutes] => 58 [hours] => 21 [mday] => 17 [wday] => 2 [mon] => 6 [year] => 2003 [yday] => 167 [weekday] => Tuesday [month] => June [0] => 1055901520*/ function array_pure ($input) { // Bad hack to pick out the lines w/o "\r\n" by picking known content $i = 0; while($i < count($input)) { if( $input[$i][0][0] == "2" || $input[$i][0][0] == "T") { $return[] = $input[$i]; } $i++; } return $return; } function getcsvWithoutHanging($url) { $numberOfSeconds=4; error_reporting(0); $url = str_replace("http://","",$url); $urlComponents = explode("/",$url); $domain = $urlComponents[0]; $resourcePath = str_replace($domain,"",$url); // $socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds); $socketConnection = fsockopen('ssl://'.$domain, 443, $errno, $errstr, $numberOfSeconds); $cols = ''; fputs($socketConnection, "GET $resourcePath HTTP/1.0\r\nHost: $domain\r\nUser-agent: $UA\r\nConnection: close\r\n\r\n"); $rows = 0; while (!feof($socketConnection)) { // $line = ereg_replace("
", "", fgets($socketConnection, 4096)); //One of these gets left in there somehow $line = str_replace("
", "", fgets($socketConnection, 4096)); //One of these gets left in there somehow $cols[] = explode(",", $line); } fclose ($socketConnection); /* $cols = file($url); print_r($cols); exit; */ for ($i = 0; $i<=11;$i++) { // Remove the header info that came with download array_shift($cols); } return($cols); } ?>