# TNET Services, Inc. # Copyright: (c) 1992-2010 Copyright TNET Services, Inc. # # License: # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, # USA. # ############################################################################ # Location of the dayfile.txt # # This needs to point to where your dayfile.txt is relative to where this # script is running. # # Normally... This will work because the daytime.txt and this script are # in the same directory (folder) $SITE['dayfile'] = './dayfile.txt'; # # Need to know where the realtime.txt file is too. We look there to get # the Unit types of the values for temp, wind, press, and rain... # # Normal would be something like $SITE['realtime'] = './realtime.txt'; # ############################################################################ ## OVERRIDE VALUES... REMOVE IF YOU ARE USING THIS SCRIPT $SITE['realtime'] = './realtime.txt'; $SITE['dayfile'] = './dayfile.txt'; ############################################################################ ############################################################################ # Really shouldn't need to change anything below here unless you want to # change the language... ############################################################################ // Fields of realtime.txt file - DON'T CHANGE!! Even for language $SITE['rfields'] = array( "date","time","temp","hum","dew","wspeed","wgust","bearing","rrate", "rfall","press","wdir","beaufort","windunit","tempunit","pressunit","rainunit", "windrun","presstrend","rmonth","ryear","rfallY","intemp","inhum","wchill", "temptrendval","tempTH","TtempTH","tempTL","TtempTL", "windTM","TwindTM","wgustTM","TwgustTM", "pressTH","TpressTH","pressTL","TpressTL", "version","build","rmaxgust","heatindex","humidex","UV","ET","SolarRad", "avgbearing","rlhour", "forecast", "daylight", "finestat"); // Values in the dayfile.txt - DON'T CHANGE!! Even for language $SITE['dfields'] = array ( 'date', 'gusthi','gusthidir','gusthitm', 'tempmin','tempmintm', 'tempmax','tempmaxtm', 'pressmin','pressmintm', 'pressmax','pressmaxtm', 'rainratemax','rainratemaxtm', 'raintot', 'tempavg', 'winrun', 'winavghi','winavghitm' ); // Values for correlating Windrun units based on windunits $windrununits = array ( 'm/s' => 'ilometres', 'mph' => 'Miles', 'km/h' => 'Kilometers', 'kts' => 'Nautical Miles' ); // Check for Options check_sourceview(); // Option to override year? if ( isset($_GET['y'] )) { $year = intval($_GET['y']); } else { $year = date('Y'); } // Option to override month? if (isset($_GET['m'] )) { $month = intval($_GET['m']); } else { $month = date('m'); } // Get Units Info from the realtime.txt file // Read data into array $DATA = get_raw($SITE['realtime'],' '); $SITE['tempunit'] = ret_rval('tempunit'); $SITE['windunit'] = ret_rval('windunit'); $SITE['pressunit'] = ret_rval('pressunit'); $SITE['rainunit'] = ret_rval('rainunit'); $SITE['windrununit'] = $windrununits[ret_rval('windunit')]; // READ the dayfile into the $raw array $raw = file($SITE['dayfile']); // Display the data echo '
Day | Hi Temp | Lo Temp | Avg Temp | Press Hi (' . $SITE['pressunit'] . ') | Press Lo (' . $SITE['pressunit'] . ') |
Highest Gust (' . $SITE['windunit'] . ') | Wind Dir | Wind run (' . $SITE['windrununit'] . ') |
Total Rain (' . $SITE['rainunit'] . ') | Max Rain Rate ' . $SITE['rainunit'] . '/hr | ';
// Set found counter to 0
$found = 0;
// Read the array now looking for data in the data set we want
foreach($raw as $key) {
if (strpos($key, ";") !==FALSE ){
$values = preg_split('/;/',$key);
} else {
$values = preg_split('/,/',$key);
}
// Check to see if this is in the date data set
if ($year == "20" . substr($values[ret_val('date')],6,2)
&& $month == substr($values[ret_val('date')],3,2) ) {
// Date
echo '
---|---|---|---|---|---|---|---|---|---|---|
' . substr($values[ret_val('date')],0,2) . ' | '; // Temps echo '' . $values[ret_val('tempmax')] . '°' . $SITE['tempunit'] . ' | ' . $values[ret_val('tempmin')] . '°' . $SITE['tempunit'] . ' | ' . $values[ret_val('tempavg')] . '°' . $SITE['tempunit'] . ' | '; // Pressure echo '' . $values[ret_val('pressmax')] . ' | ' . $values[ret_val('pressmin')] . ' | '; // Wind echo '' . $values[ret_val('gusthi')] . ' | ' . windDir($values[ret_val('gusthidir')]) . ' | ' . $values[ret_val('winrun')] . ' | '; // Rain echo '' . $values[ret_val('raintot')] . ' | ' . $values[ret_val('rainratemax')] . ' | '; echo '
Sorry, there is no data found for " . $months[$month -1 ] . ' ' . $year . "
"; } } // Return the array position of the variable function ret_val($lookup) { global $SITE; $rtn = array_search ( $lookup , $SITE['dfields'] ); if ($rtn !== FALSE) { return( $rtn ); } else { return("-"); } } // Return the array position of the variable function ret_rval($lookup) { global $SITE, $DATA; $rtn = array_search ( $lookup , $SITE['rfields'] ); if ($rtn !== FALSE) { return( $DATA[$rtn] ); } else { return("-"); } } // Standard Source view option check function check_sourceview () { global $SITE; if ( isset($_GET['view']) && $_GET['view'] == 'sce' ) { $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; } } // Calculate Word WinDir from Bearing function windDir ($winddir) { if (!isset($winddir)) { return "---"; } $windlabel = array ("N","NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW","SW", "WSW", "W", "WNW", "NW", "NNW"); $dir = $windlabel[ fmod((($winddir + 11) / 22.5),16) ]; return "$dir"; } // Function to read the data file with the // Delimiter provided function get_raw( $rawfile , $del ) { $rawdata = array(); $fd = fopen( $rawfile, "r" ); if ( $fd ) { $rawinfo = ''; while (! feof ( $fd ) ) { $rawinfo .= fread( $fd, 8192 ); } fclose($fd); $rawdata = explode ( $del, $rawinfo ); } else { $rawdata[0]= -9999; } return $rawdata; } ############################################################################ # End of Module ############################################################################