$pageName) { $scriptString = $pageFile.' loaded instead of '.$pageName.' - '.$pageVersion; } echo ''.PHP_EOL; # ---------------------------------------------------------------------------------------- $wuData = $wsreportsDir.'wuData/'; $wuLang = $wsreportsDir.'wuLang/'; # # if (isset ($_POST["report_go"]) && $wsDebug ) {echo ''.PHP_EOL;} # if (!isset ($lower)) {$lower = false;} if (!isset ($insideTemplate) ) {$insideTemplate = false;} if (!isset ($lang) ) {$lang = 'en';} if (!isset ($p) ) {$p = '10';} # include $wsreportsDir.'wsReportsFunctions.php'; # $numFormat = '%01.0f'; // most values from WU are whole numbers $trans = 'wsreport_'; $seasonal = false; // normal year 1-1 / 31-12 season year 1-12/30-11 or 1-6/31-05 # $fieldLookup= array(); $fieldLookup['Date'] = array ('kind' => 'date', 'level' => ''); $fieldLookup['TemperatureHigh'] = array ('kind' => 'temp', 'level' => 'high'); $fieldLookup['TemperatureAvg'] = array ('kind' => 'temp', 'level' => 'avg'); $fieldLookup['TemperatureLow'] = array ('kind' => 'temp', 'level' => 'low'); $fieldLookup['DewpointHigh'] = array ('kind' => 'dewp', 'level' => 'high'); $fieldLookup['DewpointAvg'] = array ('kind' => 'dewp', 'level' => 'avg'); $fieldLookup['DewpointLow'] = array ('kind' => 'dewp', 'level' => 'low'); $fieldLookup['HumidityHigh'] = array ('kind' => 'hum', 'level' => 'high'); $fieldLookup['HumidityAvg'] = array ('kind' => 'hum', 'level' => 'avg'); $fieldLookup['HumidityLow'] = array ('kind' => 'hum', 'level' => 'low'); $fieldLookup['PressureMax'] = array ('kind' => 'baro', 'level' => 'high'); $fieldLookup['PressureMin'] = array ('kind' => 'baro', 'level' => 'low'); $fieldLookup['WindSpeedMax'] = array ('kind' => 'wind', 'level' => 'high'); $fieldLookup['WindSpeedAvg'] = array ('kind' => 'wind', 'level' => 'avg'); $fieldLookup['GustSpeedMax'] = array ('kind' => 'gust', 'level' => 'high'); $fieldLookup['PrecipitationSum']= array ('kind' => 'rain', 'level' => 'sum'); $fieldLookup['Windrum'] = array ('kind' => 'wind', 'level' => 'sum'); // 24* $fieldLookup['WindSpeedAvgKMH'] # $kindArr = array(); $kindArr['temp'] = array('kind' => 'temp', 'desc' => 'Temperature', 'uom' => trim($uomTemp) ); $kindArr['baro'] = array('kind' => 'baro', 'desc' => 'Barometric pressure', 'uom' => trim($uomBaro) ); $kindArr['rain'] = array('kind' => 'rain', 'desc' => 'Rain', 'uom' => trim($uomRain) ); $kindArr['wind'] = array('kind' => 'wind', 'desc' => 'Wind', 'uom' => trim($uomWind) ); $kindArr['gust'] = array('kind' => 'gust', 'desc' => 'Gust', 'uom' => trim($uomWind) ); $kindArr['wrun'] = array('kind' => 'windrun', 'desc' => 'Wind run', 'uom' => trim($uomWrun) ); $kindArr['dewp'] = array('kind' => 'dewp', 'desc' => 'Dewpoint', 'uom' => trim($uomTemp) ); $kindArr['hum'] = array('kind' => 'hum', 'desc' => 'Humidity', 'uom' => '%'); # $typeArr = array(); $typeArr['daily'] = array('type' => 'daily', 'desc' => 'Daily detail'); $typeArr['summonthly'] = array('type' => 'summonthly', 'desc' => 'Monthly summary'); $typeArr['seasonal'] = array('type' => 'seasonal', 'desc' => 'Season detail'); $typeArr['sumseasonal'] = array('type' => 'sumseasonal','desc' => 'Seasonal summary'); # print_r ($typeArr); /* # $now = time(); $yearArr = array (); $startYear = (int) substr($wustart,6,4); // ? add validity check ? $endYear = date( 'Y', $now); $end = $endYear - $startYear + 1; if ($end > 20) {$end = 20;} // if someone has 20 or more years of wu data? for ($c = 0; $c < $end; $c++) { $yearArr[] = $endYear - $c;} // year arr goes down # print_r ($yearArr); /* # if (!isset ($_POST["report_kind"]) ) { $kind = $kindArr['temp']['kind']; } else {$kind = $_POST["report_kind"];} if (!isset ($_POST["report_type"]) ) { $type = $typeArr['daily']['type']; } else {$type = $_POST["report_type"];} if (!isset ($_POST["report_year"]) ) { $reqYear = $yearArr[0]; } else {$reqYear = $_POST["report_year"];} # if ( ($type == 'seasonal') || ($type == 'sumseasonal') ) {$seasonal = true;} # # ---- calculate period for valid data example # year 2013: 20130100 - 20131232 # Northern Hemisphere 2013/14: 20131200 - 20141132 # $validFrom = $firstYear = $validUntil = $lastYear = $reqYear; // most of the time one year # if ($seasonal) { $thisMonth = (int) date('n',$now); if ($latitude < 0) { $monthsArr = array ('', '07','08','09','10','11','00','01','02','03','04','05','06'); $monthNamesShort = array ('', "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec","Jan", "Feb", "Mar", "Apr", "May" ); $monthNames = array ('', "June", "July", "August", "September", "October", "November", "December","January", "February", "March", "April", "May"); $thisMonth = date('n',$now); if ($thisMonth > 5 ){ $validUntil = $lastYear = $reqYear + 1; // seasonal always two years } else { $validFrom = $firstYear = $reqYear - 1; } $mmddFrom = '0600'; $mmddUntil = '0532'; $validFrom .= '0600'; $validUntil .= '0532'; } else { $monthsArr = array ('','01','02','03','04','05','06','07','08','09','10','11','00'); $monthNamesShort = array ('', "Dec","Jan","Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov" ); $monthNames = array ('', "December","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November"); if ($thisMonth > 11) { $validUntil = $lastYear = $reqYear + 1; // seasonal always two years } else { $validFrom = $firstYear = $reqYear - 1; } $mmddFrom = '1200'; $mmddUntil = '1132'; $validFrom .= '1200'; $validUntil .= '1132'; } } else { $monthsArr = array ('','00','01','02','03','04','05','06','07','08','09','10','11'); $monthNamesShort = array ('',"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ); $monthNames = array ('',"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); $mmddFrom = '0000'; $mmddUntil = '1232'; $validFrom .= '0000'; $validUntil .= '1232'; } if ($firstYear < $startYear) {$firstYear = $startYear;} if ($type == 'summonthly' || $type == 'sumseasonal'){ $validFrom = $firstYear = $startYear; $validUntil = $lastYear = $endYear; // summary alwaus all years $validFrom .= '0000'; $validUntil .= '1232'; } # $fileNames = array(); $wuURLs = array(); for ($i = $firstYear; $i <= $lastYear; $i++) { $fileNames[] = $wuData.$wuid.'-year-'.$i.'.txt'; // IVLAAMSG47-year-2014.txt $wuURLs[] = 'https://www.weerstationafferden.nl/WXDailyHistory.php?ID='.$wuid.'&month=01&day=01&year='.$i.'&format=1&graphspan=year'; } #$fileName = $fileNames['0']; #$wuURL = $wuURLs['0']; #print_r($fileNames); exit; # $headText = wsReporttransstr($trans.$kindArr[$kind]['desc']).' ('.$kindArr[$kind]['uom'].') '. wsReporttransstr($trans.$typeArr[$type]['desc']).' '. wsReporttransstr($trans.'report').' - '. # wsReporttransstr($trans.'over'). wsReporttransstr($trans.'period').': '; if ($type == 'daily') { $headText .= $firstYear;} else { $headText .= $firstYear.'-'.$lastYear;} if ($insideTemplate) {$langString = '';} else {$langString = '?lang='.$lang;} $firstpartHtml = '

'.$headText.'


1: '.wsReporttransstr($trans.'period').' 2: '.wsReporttransstr($trans.'report type').' 3: '.wsReporttransstr($trans.'weather value').' 4:
'; $button = ''; # $firstpartHtml .= $button.'

'.PHP_EOL; echo $firstpartHtml; $from = array ('°',' ','/'); # if ($kind == 'temp' || $kind == 'dewp') { $uomMetric = 'c'; $uomEnglish = 'f'; $round = 0; $request[] = 1; // field in col 1 $request[] = 3; // field in col 3 $tempLabels = array ('High','High Avg','Mean','Low Avg','Low' ); $uomOut = trim(strtolower(str_replace ($from,'', $uomTemp) ) ); if ($uomOut == 'c') { $tempLow = -15; $tempInc = 5; } else { $tempLow = 0; $tempInc = 10; } $increments = 15; // max 15, adapt css if more is needed $tempLevels = array ($tempLow); for ( $i = 0; $i < $increments ; $i ++ ) { $tempLevels[$i+1] = $tempLevels[$i] + $tempInc; } } if ($kind == 'dewp') { $request[0] = 4; // field in col 4 $request[1] = 6; // field in col 6 $dewpLabels = $tempLabels; $dewpLevels = $tempLevels; } if ($kind == 'baro') { $uomMetric = 'hpa'; $uomEnglish = 'inhg'; $request[] = 10; // field in col 10 $request[] = 11; // field in col 11 $baroLabels = array ('High','Mean','Low' ); $uomOut = trim(strtolower(str_replace ($from,'', $uomBaro) ) ); if ($uomOut == 'hpa' || $uomOut == 'mb') { $baroLow = 980; $baroInc = 5; $round = 0; } else { $baroLow = 29.4; $baroInc = 0.1; $round = 2; $numFormat = '%01.2f'; } $increments = 12; // max 15, adapt css if more is needed $baroLevels = array ($baroLow); for ( $i = 0; $i < $increments ; $i ++ ) { $baroLevels[$i+1] = $baroLevels[$i] + $baroInc; } } if ($kind == 'rain') { $uomMetric = 'cm'; $uomEnglish = 'in'; $request[] = 15; // field in col 15 $rainLabels = array ('Raindays','Month total','YTD total' ); $uomOut = trim(strtolower(str_replace ($from,'', $uomRain) ) ); if ($uomOut == 'mm') { $rainLow = 2; $rainInc = 2; $round = 1; $numFormat = '%01.1f'; } else { $rainLow = 0.1; $rainInc = 0.1; $round = 2; $numFormat = '%01.2f'; } $increments = 12; // max 15, adapt css if more is needed $rainLevels = array ($rainLow); for ( $i = 0; $i < $increments ; $i ++ ) { $rainLevels[$i+1] = $rainLevels[$i] + $rainInc; } } if ($kind == 'wind') { $uomMetric = 'kmh'; $uomEnglish = 'mph'; $request[] = 12; // field in col 12 $request[] = 13; // field in col 13 $windLabels = array ('High','High Avg ','Avg High','Avg' ); $windLow = 1; $windInc = 10; $round = 1; $numFormat = '%01.0f'; $uomOut = trim(strtolower(str_replace ($from,'', $uomWind) ) ); if ($uomOut == 'ms') { $windLow = 1; $windInc = 20; } $increments = 12; // max 15, adapt css if more is needed $windLevels = array ($windLow); for ( $i = 0; $i < $increments ; $i ++ ) { $windLevels[$i+1] = $windLevels[$i] + $windInc; } } if ($kind == 'gust') { $uomMetric = 'kmh'; $uomEnglish = 'mph'; $request[] = 14; // field in col 14 = gust $request[] = 12; // field in col 12 = normal wind $gustLabels = array ('High','Avg High'); #,'High Avg ','Avg High','Avg' ); $gustLow = 1; $gustInc = 10; $round = 1; $numFormat = '%01.0f'; $uomOut = trim(strtolower(str_replace ($from,'', $uomWind) ) ); if ($uomOut == 'ms') { $gustLow = 1; $gustInc = 20; } $increments = 12; // max 15, adapt css if more is needed $gustLevels = array ($gustLow); for ( $i = 0; $i < $increments ; $i ++ ) { $gustLevels[$i+1] = $gustLevels[$i] + $gustInc; } $fieldLookup['WindSpeedMax'] = array ('kind' => 'wind', 'level' => 'avg'); } if ($kind == 'windrun' || $kind == 'wrun') { $uomMetric = 'km'; $uomEnglish = 'mi'; $request[] = 16; // field in col 16 $wrunLabels = array ('High','High Avg','Low' ); $wrunLow = 20; $wrunInc = 40; $round = 1; $numFormat = '%01.0f'; $uomOut = trim(strtolower(str_replace ($from,'', $uomWrun) ) ); $increments = 12; // max 15, adapt css if more is needed $wrunLevels = array ($wrunLow); for ( $i = 0; $i < $increments ; $i ++ ) { $wrunLevels[$i+1] = $wrunLevels[$i] + $wrunInc; } } if ($kind == 'hum') { $uomMetric = '%'; $uomEnglish = '%'; $round = 0; $request[] = 7; // field in col 7 $request[] = 9; // field in col 9 $humLabels = array ('High','High Avg','Mean','Low Avg','Low' ); $humLow = 10; $humInc = 10; $uomOut = '%'; $increments = 9; // max 15, adapt css if more is needed $humLevels = array ($humLow); for ( $i = 0; $i < $increments ; $i ++ ) { $humLevels[$i+1] = $humLevels[$i] + $humInc; } } # $levelArr = $kind.'Levels'; #var_dump($$levelArr); exit; $row = 0; $noValue = '---'; $empty = ' '; $yearArray = array(); $fields = array(); $valuesMonth = count($request); $months = 12; $cols = $valuesMonth * $months; # # gather all data starting at $validFrom end at $validUntil # the files for those years are at array $fileNames[] # $endYear = count($fileNames); $checkYear = $firstYear -1; $thisYear = date ('Y', $now ); $today = date ('Ymd', $now ); $nowHour = date ('G', $now ); $firstYearOnly = true; for ($cntYear = 0; $cntYear < $endYear; $cntYear++) { $checkYear++; $fileName = $fileNames[$cntYear]; $wuURL = $wuURLs[$cntYear]; # $readFile = 'no'; $status = ''.PHP_EOL; # echo $status; # if ( $readFile == 'yes' ){ // file (not yet) read from WU echo ''; $wsData = wsReportCurl ($wuURL); if ($wsData == false) {echo '

ERROR: no data for '.$wuURL.'

'; exit;} $wsData = trim($wsData); $wsData = str_replace (PHP_EOL.'
','',$wsData); // clean data $wsData = str_replace ('
','',$wsData); // if ( !file_put_contents($fileName, $wsData) ) { echo ''; } } $handle = fopen($fileName, "r"); $firstLine = true; $currentYear= false; while (($data = fgetcsv($handle, 1000, ",")) !== false) { $num = count($data); if ($num < 2) {continue;} if ($firstLine) { // first line has fieldnames $firstLine = false; $nrFields = $num; if ($wsDebug) { echo "'.PHP_EOL;} } # check which unit-type is used for this file either metric or english $fieldname = trim($data[1]); // should be either TemperatureHighF or TemperatureHighC $string = strtolower(substr($fieldname,-1) ); if ($string == 'c') {$uomInput = $uomMetric;} elseif ($string == 'f') {$uomInput = $uomEnglish;} else { echo '

Error file for '.$checkYear.' has unknown uom\'s'; exit; } continue; } // eo if row 1 if ($num <> $nrFields) {echo "ERROR in line $row: Number of fields = $num, expected $nrFields".PHP_EOL; continue;} # clean date field $string = $data[0]; if (strpos ($string,'-') == false) {echo 'invalid data - stop'; print_r ($data); exit; } list ($year,$month,$Day) = explode ('-',$string); if (strlen($month) == 1) {$month = '0'.$month;} if (strlen($Day) == 1) {$Day = '0'.$Day;} # process only records in range $validFrom - $validUntil $dataDate = $year.$month.$Day; if ($currentYear === false) { $currentYear = $year;} if ($year > $currentYear) {break;} if ( ($dataDate > $validFrom) && ($dataDate < $validUntil) ) { $yearArray[0][$row] = $year.$month.$Day; for ($k = 0; $k < count($request); $k++) { $fieldNr = $request[$k]; if ($kind == 'windrun' || $kind == 'wrun') { # add calculated values $value = convertUom (24 * $data[13]); } else { $value = convertUom ($data[$fieldNr]); } $yearArray[$k+1][$row]= $value; } // eo for requests $row++; } // eo if in range # end process in range } // end of data fclose($handle); } // end of processing all files # $fields[] = 'Windrum'; // add label for calculated field # if ($wsDebug) {echo ''.PHP_EOL;} # echo '
'; print_r($yearArray);  exit;
#
if ($type == 'summonthly' || $type == 'sumseasonal'){ 
	include $wsreportsDir.'wsReportsSum.php'; 
} else {
	include $wsreportsDir.'wsReportsDaily.php';
}
#
echo '

'.PHP_EOL; # credits $link_leuven = 'http://leuven-template.eu/'; $link_wildwoodweather = 'http://weather.wildwoodnaturist.com/'; $link_wundergroundsite = 'http://www.wunderground.com/personal-weather-station/dashboard?ID='.$wuid; $stringCredit = '

'; $stringCredit .= wsReporttransstr($trans.'Script developed by Wim van der Kuil of').' Weerstation Leuven.  '; $stringCredit .= wsReporttransstr($trans.'The script uses the data from this station which is uploaded to').' Weather Underground.  '; $stringCredit .= wsReporttransstr($trans.'The idea for this script came from a similar kind of script using NOAA data, written by Murry Conarroe of').' Wildwood Weather. '; $stringCredit .= '

'.PHP_EOL; echo $stringCredit; # missing language translations if (isset ($ownTranslate) && count ($missingTrans) <> 0) { $string = ''; echo ''.PHP_EOL; } ?>