Kuukauden sää

# 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. # ############################################################################ $SITE['dayfile'] = './dayfile.txt'; $SITE['realtime'] = './realtime.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' => 'km', 'mph' => 'Miles', 'km/h' => 'km/h', '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 display_month($year,$month) ; echo '
Sää nyt
Päivittyy kerran vuorokaudessa keskiyön jälkeen'; // Function to parse the month needed. // Allows multiple display_month calls above. function display_month($year,$month) { global $raw, $SITE; $months = array ("Tammikuu","Helmikuu","Maaliskuu","Huhtikuu","Toukokuu","Kesäkuu", "Heinäkuu","Elokuu","Syyskuu","Lokakuu","Marraskuu","Joulukuu"); echo '

' . $months[$month -1 ] . ' ' . $year . '


'; echo ''; // 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 ''; // Temps echo ''; // Pressure echo ''; // Wind echo ''; // Rain echo ''; echo '' . $LF; $found++; } } echo '
Päivä Max lämpöMin lämpöKeskiarvo Max paine
(' . $SITE['pressunit'] . ')
Min paine
(' . $SITE['pressunit'] . ')
Tuulenpuuska
(' . $SITE['windunit'] . ')
Tuulen suuntaTuulen matka
(' . $SITE['windrununit'] . ')
Sademäärä
(' . $SITE['rainunit'] . ')
Max sade
' . $SITE['rainunit'] . '/h
' . substr($values[ret_val('date')],0,2) . '' . $values[ret_val('tempmax')] . '°' . $SITE['tempunit'] . '' . $values[ret_val('tempmin')] . '°' . $SITE['tempunit'] . '' . $values[ret_val('tempavg')] . '°' . $SITE['tempunit'] . '' . $values[ret_val('pressmax')] . '' . $values[ret_val('pressmin')] . '' . $values[ret_val('gusthi')] . '' . windDir($values[ret_val('gusthidir')]) . '' . $values[ret_val('winrun')] . '' . $values[ret_val('raintot')] . '' . $values[ret_val('rainratemax')] . '
'; // If we found no records, output an error: if (!$found) { 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 ("Pohjoinen","NNE", "Koillinen", "ENE", "Itä", "ESE", "Kaakko", "SSE", "Etelä", "SSW","Lounas", "WSW", "Länsi", "WNW", "Luode", "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 ############################################################################