$replacement) { $dtline = str_replace($key,$replacement,$dtline); } } } if($sunpart == "summer" && $sunri == "--"){$sunstr = get_lang("Midnight Sun");$spos = 0;} else if($sunpart == "winter" && $sunri == "--"){$sunstr = get_lang("Polar Night");$spos = 0;} else { $sunstr = ' '.$sunri.'     '.$sunse.'   '.get_lang("Daylength").': '.$daylength; $spos = -2; } if(is_numeric($revdata[2]) && $tstr > time()) { if($startt == '') { $startt = $tstr;$res = $tstr+345600;} $rawdata[$a][time] = $tstr; $rawdata[$a][dateline] = $dtline; $rawdata[$a][dayline] = $daline; $rawdata[$a][sunstr] = $sunstr; $rawdata[$a][spos] = $spos; $rawdata[$a][dn] = $dn; $rawdata[$a][wgst]= $revdata[$windgstwp]; $rawdata[$a][wdir]= $revdata[$dirwp]; $rawdata[$a][wspd]= $revdata[$windwp]; $rawdata[$a][temp]= $revdata[$tempwp]; $rawdata[$a][chill]= $revdata[$chillwp]; $rawdata[$a][heat]= $revdata[$heatwp]; //$wvp = ($revdata[$humwp] / 100) * 6.105 * exp(17.27 * $revdata[$tempwp] / (237.7 + $revdata[$tempwp])); //$rawdata[$a][appar] = sprintf("%01.1f",$revdata[$tempwp] + (0.33 * $wvp) - (0.70 * $revdata[$windwp]) - 4.00); if($revdata[$tempwp]<15){ $rawdata[$a][appar] = $revdata[$chillwp]; }else{ $rawdata[$a][appar] = $revdata[$heatwp]; } $rawdata[$a][visib]= $revdata[$visibwp]; $rawdata[$a][pres]= $revdata[$barowp]; $rawdata[$a][dewp]= $revdata[$dewwp]; $rawdata[$a][solar]= $revdata[$solarwp]; $rawdata[$a][uv]= $revdata[$uviwp]; $rawdata[$a][prec]= $revdata[$precwp] - $pre; $pre = $revdata[$precwp]; $precs[] = $revdata[$precwp]; if($snowava <> true){$revdata[$snowwp] = 0;} if($useussnow){$rawdata[$a][snow]= $revdata[$snowwp];} else{$rawdata[$a][snow]= round($revdata[$snowwp]);} $snows[]= $revdata[$snowwp]; $rawdata[$a][tmax]= $revdata[$tmaxwp]; $rawdata[$a][tmin]= $revdata[$tminwp]; if($sgactive == true) { $rawdata[$a][grass]= $revdata[$grasstwp]; $rawdata[$a][surface]= $revdata[$surftwp]; $rawdata[$a][soil1t]= $revdata[$soil1twp]; $rawdata[$a][soil2t]= $revdata[$soil2twp]; $rawdata[$a][soil1m]= $revdata[$soil1mwp]; $rawdata[$a][soil2m]= $revdata[$soil2mwp]; } $rawdata[$a][cover]= $revdata[$covvwp]; $rawdata[$a][conv]= $revdata[$convwp]; $rawdata[$a][ki]= $revdata[$kiwp]; if($revdata[$kiwp]<0){$rawdata[$a][ki]=0;} $rawdata[$a][lev]= $revdata[$levelwp]; $rawdata[$a][rawcond]= $revdata[$condwp3].$revdata[$condwp2].$revdata[$condwp1]; $a++; } } unset($csv); unset($revdata); // Puuuh, ~200 lines and we have only parsed the raw data to an array yet LOL //############################################################################# $hr1=0; $hr3=0; $howm = count($rawdata); for($i=0;$i<$howm;$i++) { $line = $rawdata[$i]; // Collect for getting max/mins for some values $tbl1[temps][]= $line[temp]; $tbl3[temps][]= $line[temp]; $tbl1[chills][]= $line[chill]; $tbl3[chills][]= $line[chill]; $tbl1[appars][]= $line[appar]; $tbl3[appars][]= $line[appar]; $tbl1[heats][]= $line[heat]; $tbl3[heats][]= $line[heat]; $tbl1[wgsts][]= $line[wgst]; $tbl3[wgsts][]= $line[wgst]; $tbl1[wdirs][]= $line[wdir]; $tbl3[wdirs][]= $line[wdir]; $tbl6[wdirs][]= $line[wdir]; $tbl6[wspds][]= $line[wspd]; $tbl1[precs][]= $line[prec]; $tbl3[precs][]= $line[prec]; $tbl1[visibs][]= $line[visib]; $tbl3[visibs][]= $line[visib]; $tbl1[kiws][]= $line[ki]; $tbl3[kiws][]= $line[ki]; $tbl1[convs][]= $line[conv]; $tbl3[convs][]= $line[conv]; $tbl1[covers][]= $line[cover]; $tbl3[covers][]= $line[cover]; $tbl1[levs][]= $line[lev]; $tbl3[levs][]= $line[lev]; $tbl1[uvs][]= $line[uv]; $tbl3[uvs][]= $line[uv]; $tbl1[cond].= $line[rawcond]; $tbl3[cond].= $line[rawcond]; // Average pressure a bit $ba[]=$line[pres]; if(isset($rawdata[$i-2][pres])){$ba[]=$rawdata[$i-2][pres];} if(isset($rawdata[$i-1][pres])){$ba[]=$rawdata[$i-1][pres];} if(isset($rawdata[$i+1][pres])){$ba[]=$rawdata[$i+1][pres];} if(isset($rawdata[$i+2][pres])){$ba[]=$rawdata[$i+2][pres];} $line[avpres]= array_avg($ba); $ba=array(); // 1h table if(date("i",$line[time])=="00"){ //wind $w = round($line[wspd]); $wdir = $line[wdir]; $mxgst = max($tbl1[wgsts]); $wcolor=wiconcolor($w); $wline='
'; if($w>0){ $wline.=''; } $wline.=''.$w.'
Max: '.round($mxgst).' '.$uoms[2].'
'; $line[wline] = $wline; //Temp if($tempuom=="C"){ if($line[temp]<-11||$line[temp]>25){$tcolor="#fff";}else{$tcolor="#000";} }else{ if($line[temp]<12||$line[temp]>77){$tcolor="#fff";}else{$tcolor="#000";} } $line[tempbox]='
'.round($line[temp]).'°
'; //windchill & heat $line[chline] = '
'.get_lang("Feels").': '.$line[appar].'°
'; // rain & co $line[maxcover] = max($tbl1[covers]); $line[maxkiw] = max($tbl1[kiws]); $line[maxconv] = 0; if(count($tbl1[convs])>0){$line[maxconv] = max($tbl1[convs]);} $line[prectot]= array_sum($tbl1[precs]); $line[prectot1h]= array_sum($tbl1[precs]); if($line[maxcover]<$precclcover || $line[prectot]<$traceam1){$line[prectot] = 0;} if($useusprec==1){$line[prectot]= sprintf("%01.2f", $line[prectot]);} else{$line[prectot]= sprintf("%01.1f", $line[prectot]);} $line[fog] = fogcond($line[cond]); $line[raintyp] = raintyp($line[temp],$line[dewp],$line[lev],$tempuom); $line[preccond] = preccond($line[maxcover],$line[prectot],$line[raintyp]); // icon $icons = explode('|',wanewicon($line[preccond],$line[fog],$line[maxconv],$line[maxcover],$line[prectot])); if($line[dn]<> "day") {$line[icon] = $icons[1];} else {$line[icon] = $icons[0];} $line[icons]='
'.geticon($line[icon]).'
'; $line[maxuv] = max($tbl1[uvs]); $line[minvis] = min($tbl1[visibs]); $hr1++; if($hr1<48){ get_onehourrow(); } $tbl1=array(); } // 3h table if(in_array(date('Hi',$line[time]),$hour3)) { //wind $w = round($line[wspd]); $wdir = $line[wdir]; $mxgst = max($tbl3[wgsts]); $wcolor=wiconcolor($w); $wline='
'; if($w>0){ $wline.=''; } $wline.=''.$w.'
Max: '.round($mxgst).' '.$uoms[2].'
'; $line[wline] = $wline; //Temp if($tempuom=="C"){ if($line[temp]<-11||$line[temp]>25){$tcolor="#fff";}else{$tcolor="#000";} }else{ if($line[temp]<12||$line[temp]>77){$tcolor="#fff";}else{$tcolor="#000";} } $line[tempbox]='
'.round($line[temp]).'°
'; //windchill & heat $line[chline] = '
'.get_lang("Feels").': '.$line[appar].'°
'; # Frost $frostline3 = ''; if($month >=$froststart && $month <=$frostend) { if(preg_match('|SCTD.FRO|Ui',$stuff) || preg_match('|LT. FROST|Ui',$stuff)) {$sctfrost = true;} else if(preg_match('|FRO|Ui',$stuff)) { $hwyfrost = true;} } // rain & co $line[maxcover] = max($tbl3[covers]); $line[maxkiw] = max($tbl3[kiws]); $line[maxconv] = 0; if(count($tbl3[convs])>0){$line[maxconv] = max($tbl3[convs]);} $line[prectot]= array_sum($tbl3[precs]); if($line[maxcover]<$precclcover || $line[prectot]<$traceam3){$line[prectot] = 0;} if($useusprec==1){$line[prectot]= sprintf("%01.2f", $line[prectot]);} else{$line[prectot]= sprintf("%01.1f", $line[prectot]);} $line[fog] = fogcond($line[cond]); $line[raintyp] = raintyp($line[temp],$line[dewp],$line[lev],$tempuom); $line[preccond] = preccond($line[maxcover],$line[prectot],$line[raintyp]); if(date("i",$line[time])=="00"&&$hr1<72){ $jst = (($line[time]+$utcdiff)*1000); $precjson[]= array($jst,round($line[prectot],1)); $prectip[(string)$jst-7200000]= round($line[prectot],1); $prectip[(string)$jst-3600000]= round($line[prectot],1); $prectip[(string)$jst]= round($line[prectot],1); } // icon $icons = explode('|',wanewicon($line[preccond],$line[fog],$line[maxconv],$line[maxcover],$line[prectot])); if($line[dn]<> "day") {$line[icon] = $icons[1];} else {$line[icon] = $icons[0];} $line[icons]='
'.geticon($line[icon]).'
'; // Text $txtcond = $txtcloud.'. '; if($line[dn] <> "day") { $txtcond = str_replace('Mostly sunny','Mostly clear',$txtcond); $txtcond = str_replace('Sunny','Clear',$txtcond); } if(strlen($line[preccond]) > 4) {$prcond = '
'.ucfirst($line[preccond]).'.';}else{$prcond='';} if($line[fog] <> '') {$fog = '
'.ucfirst($line[fog]).'.';}else{$fog='';} $frostline=''; if($sctfrost) {$frostline = '
Scattered frost.'; } if($hwyfrost) {$frostline = '
Moderate or heavy frost.';} $sctfrost = false; $hwyfrost = false; $tsactive = false; $prcond = fixstring($prcond,$line[maxconv],$line[maxkiw],$line[maxcover],$line[prectot],$traceam3); $line[condtxt] = $txtcond.$prcond.$fog.' '.$frostline.$visibline.$tmcond; reset ($Language); foreach ($Language as $key => $replacement) { $line[condtxt] = str_replace($key,$replacement,$line[condtxt]); } $line[maxuv] = max($tbl3[uvs]); $line[minvis] = min($tbl3[visibs]); get_threehourrow(); if($sgactive == true){ get_grassrow(); } $tbl3=array(); // icons for graph $condic = "-"; $condictime = "-"; $condic = $line[icon]; $condictime = ($line[time]+$utcdiff)*1000; $svgjson.= '{time:'.$condictime.', dir: '.$wdir.', spd: '.$w.', bft: '.getbft($w).', cond: "'.$condic.'"},'; } // 6h, icons for graph if(in_array(date('Hi',$line[time]),$hour6) && $line[time]<$res) { /*$condic = $line[icon]; $condictime = ($line[time]+$utcdiff)*1000; if($condic<>"-"&&$condic<>""){ $icjson.= '{x:'.$condictime.',y:16,marker:{}},'; } $mxw = max($tbl6[wspds]); $wicjson.= '{x:'.$condictime.',y:13,marker:{}},'; $svgjson.= '{time:'.$condictime.', dir: '.array_avg($tbl6[wdirs]).', spd: '.$mxw.', cond: "'.$condic.'"},'; */ $tbl6=array(); } // CREATE JSONSTRINGS FOR GRAPH if(date("i",$line[time])=="00"&&$hr1<74){ $jst = ($line[time]+$utcdiff)*1000; if($jstart == '') {$jstart = $jst;} $jsstop = $jst; if($revdata[$kiwp]<0){$line[kiw]=0;} $tempjson[]= floatval($line[temp]); $tmaxjson[]= floatval($line[tmax]); $tminjson[]= floatval($line[tmin]); $dewjson[]= floatval($line[dewp]); $chilljson[]= floatval($line[appar]); $heatjson[]= floatval($line[heat]); $barojson[]= floatval(sprintf("%01.1f",$line[avpres])); $uvjson[]= floatval($line[uv]); $solarjson[]= floatval($line[solar]); $kijson[]= floatval(thunderproc3($line[ki])); $snowjson[]= floatval($line[snow]); $wspdjson[]= array(floatval($line[wspd]),floatval($line[wgst])); $wspdtip[(string)$jst]= array(round($line[wspd],1),round($line[wgst],1)); } } $hrtable1.=''; $hrtable3.=''; $grsstable.=''; ################################################################# function getbft($w){ global $uoms; if($uoms[2]=="km/h"||$uoms[2]=="kmh"){$w=$w*0.277777778;} if($uoms[2]=="mph"){$w=$w*0.44704;} if($w<0.3){$b=0;} if($w>=0.3&&$w<1.5){$b=1;} if($w>=1.5&&$w<3.3){$b=2;} if($w>=3.3&&$w<5.5){$b=3;} if($w>=5.5&&$w<8){$b=4;} if($w>=8&&$w<10.8){$b=5;} if($w>=10.8&&$w<13.9){$b=6;} if($w>=13.9&&$w<17.2){$b=7;} if($w>=17.2&&$w<20.7){$b=8;} if($w>=20.7&&$w<24.5){$b=9;} if($w>=24.5&&$w<28.4){$b=10;} if($w>=28.4&&$w<32.6){$b=11;} if($w>=32.6){$b=12;} return $b; } function get_onehourrow() { global $tbl1,$line,$hr1,$hrtable1,$daychanges; global $snows,$washowzeroprecip,$minuvtoshow,$uoms; // Header if($hr1==1){ $hrtable1 = ''; if(max($snows) > 0) { $hrtable1.= ''; } else {$hrtable1.= '';} $hrtable1.= ' '; } // Dateline if($hr1==1 || in_array($line[time],$daychanges)) { $hrtable1.=''; } // Create row if($hr1%2==0) {$row = 'wxsimdata'; }else{$row = 'wxsimdataodd';} $hrtable1.=''; return; } function get_threehourrow() { global $tbl3,$line,$hr3,$hrtable3,$daychanges; global $snows,$washowzeroprecip,$minuvtoshow,$uoms; $hr3++; // Header if($hr3==1){ $hrtable3 = '
  '.get_lang("Conditions").' '.get_lang("Temperature").' '.get_lang("Dewpoint").' '.get_lang("Precipitation").''.get_lang("Snowdepth").''.get_lang("Thunderstorm probability").''.get_lang("Wind").' '.get_lang("Pressure").' '.get_lang("UV Index").' '.get_lang("Cloud cover").' '.get_lang("Visibility").'
'.$line[sunstr].' '.$line[dateline].'
'.date('H:i',$line[time]).' '.$line[icons].' '.$line[tempbox].$line[chline].' '.$line[dewp].'° '.showprecipt($line[prectot],$uoms[1],$washowzeroprecip,get_lang("No precip")).' '.fixSnowTS(max($snows),$line[snow],$uoms[4],thunderproc2($line[maxkiw])).' '.$line[wline].' '.sprintf("%01.1f", $line[avpres]).' '.$uoms[3].' '.fixuvimg($line[maxuv],$line[dn],$minuvtoshow).' '.$line[maxcover].'% '.$line[minvis].' '.$uoms[5].'
'; if(max($snows) > 0) { $hrtable3.= ''; } $hrtable3.= ' '; } if(max($snows) > 0) {$colspan=9;}else{$colspan=8;} // Dateline if($hr3==1 || in_array($line[time],$daychanges)) { $hrtable3.=''; } // Create row if($hr3%2==0) {$row = 'wxsimdata'; }else{$row = 'wxsimdataodd';} $hrtable3.=''; if(max($snows) > 0) {$hrtable3.='';} $hrtable3.=''; return; } function get_grassrow() { global $tbl3,$line,$hr3,$grsstable,$daychanges,$tempuom; global $sgdepth1,$sgdepth2,$washowzeroprecip,$minuvtoshow,$uoms; // Header if($hr3==1){ $grsstable = '
  '.get_lang("Conditions").' '.get_lang("Temperature").' '.get_lang("Precipitation").''.get_lang("Snowdepth").''.get_lang("Wind").' '.get_lang("Pressure").' '.get_lang("UV Index").' '.get_lang("Description and notes").'
'.$line[sunstr].' '.$line[dateline].'
'.date('H:i',$line[time]).' '.$line[icons].' '.$line[tempbox].$line[chline].' '.showprecipt($line[prectot],$uoms[1],$washowzeroprecip,get_lang("No precip")).''.fixsnow(max($snows),round($line[snow]),$uoms[4]).''.$line[wline].' '.sprintf("%01.1f", $line[avpres]).' '.$uoms[3].' '.fixuvimg($line[maxuv],$line[dn],$minuvtoshow).' '.$line[condtxt].'
'; } // Dateline if($hr3==1 || in_array($line[time],$daychanges)) { $grsstable.=''; } // row if($hr3%2==0) {$row = 'wxsimdata'; }else{$row = 'wxsimdataodd';} if($tempuom=="C"){ if($line[temp]<-11||$line[temp]>25){$tcolor="#fff";}else{$tcolor="#000";} if($line[grass]<-11||$line[grass]>25){$gcolor="#fff";}else{$gcolor="#000";} if($line[surface]<-11||$line[surface]>25){$scolor="#fff";}else{$scolor="#000";} if($line[soil1t]<-11||$line[soil1t]>25){$s1color="#fff";}else{$s1color="#000";} if($line[soil2t]<-11||$line[soil2t]>25){$s2color="#fff";}else{$s2color="#000";} }else{ if($line[temp]<12||$line[temp]>77){$tcolor="#fff";}else{$tcolor="#000";} if($line[grass]<12||$line[grass]>77){$gcolor="#fff";}else{$gcolor="#000";} if($line[surface]<12||$line[surface]>77){$scolor="#fff";}else{$scolor="#000";} if($line[soil1t]<12||$line[soil1t]>77){$s1color="#fff";}else{$s1color="#000";} if($line[soil2t]<12||$line[soil2t]>77){$s2color="#fff";}else{$s2color="#000";} } $grsstable.=''; } ######################################################## # Put together the graph $icstart = $jstart-(round(($jstop-$jstart)/($mainwidth-20)*15)); $jsdata=' '; $graph='
'; if($baroonmain){$graph.=''.get_lang("Temp./Prec./Baro.").'';} else{$graph.=''.get_lang("Temp./Prec.").'';} if(max($snows)>0) {$graph.=''.get_lang("Snowdepth").'';} $graph.=''.get_lang("Thunder/Dewp.").' '.get_lang("Solar/UV").' '.get_lang("Max/min temp.").' '.get_lang("Compare").'
'; ############################################################## # Put together the output-variables $wxallmain='
'.get_lang("Overview").' '.get_lang("Hour-by-hour").' '.get_lang("Detailed").' 48 '.get_lang("hrs").''; if($showgraph == true){ $wxallmain.=' '.get_lang("Meteogram").''; } if($sgactive == true) { $wxallmain.=' '.get_lang("Grass & Soil").''; } $wxallmain.='
'.$shorttable.'
'; if($showgraph == true){$wxallmain.='';} $wxallmain.='

'; if($usemc){$wxallmain.='Meteoconsult comparedata provided by Hetweeractueel and Meteoconsult. ';} $wxallmain.='YR.NO-comparedata provided by YR.NO and NRK.'.$discl; $wxallgraph=$graph; $cssage = filemtime($wxallmainfolder.'css/wxall.css'); $wxallhead = ' '; $wxallfooter = $jsdata.' '; function roundUpToAny($n) { return ceil($n/5)*5; } function array_avg($array) { return array_sum($array) / count($array); } function get_nationaldata(){ global $utcdiff,$usefmi,$fmiplace,$fmiapikey,$usemc,$mcid,$mckey,$cachedir; $fetchSeconds = 3600; if($usefmi){ $URL = 'http://data.fmi.fi/fmi-apikey/'.$fmiapikey.'/wfs?request=getFeature&storedquery_id=fmi::forecast::hirlam::ground::point::timevaluepair×tep=60&crs=EPSG::4326&place='.fixurl($fmiplace); $cacheName = $cachedir.'fmifrcst_'.md5($fmiplace).'.txt'; // prototype for path/filename for cache file if (file_exists($cacheName) and filemtime($cacheName) + $fetchSeconds > time()) { $html = file_get_contents($cacheName); } else { $html = file_get_contents($URL); file_put_contents($cacheName,$html);; chmod($cacheName, 0666); } $xml=xml2array($html); $xml = $xml["wfs:FeatureCollection"]["wfs:member"]; for($i=0;$i time()) { $html = file_get_contents($cacheName); } else { $html = file_get_contents($URLS); file_put_contents($cacheName,$html);; chmod($cacheName, 0666); } $xml=xml2ary($html); $xml = $xml['Verwachting'][_c]['Plaatsen'][_c]['Plaats'][_c]['Verwachtingen'][_c]['Verwachting']; $howmany = count($xml); for ($i = 0; $i < $howmany; $i++) { $day = $xml[$i][_a]['datum']; $hour = $xml[$i][_a]['uur']; $time = strtotime($day.' '.$hour.':00:00 CET'); $jstime = (($time+$utcdiff)*1000); $tempjson[] = array($jstime,round($xml[$i][_c]['temperatuur'][_v],1)); } }else{return array();} return $tempjson; } function get_yrdata() { global $lat,$long,$utcdiff,$jsstop,$fmiplace,$cachedir; $URLS = "http://api.yr.no/weatherapi/locationforecast/1.8/?lat=$lat&lon=$long"; // URL to the ENGLISH page on yr.no where location is $cacheName = $cachedir.'yrfrcst_'.md5($lat.$long).'.txt'; // prototype for path/filename for cache file $fetchSeconds = 3600; // refresh every hour if (file_exists($cacheName) and filemtime($cacheName) + $fetchSeconds > time()) { $html = file_get_contents($cacheName); } else { $html = file_get_contents($URLS); file_put_contents($cacheName,$html);; chmod($cacheName, 0666); } $xml=xml2ary($html); $xml = $xml['weatherdata'][_c]; $forecasts = $xml[product][_c][time]; $howmany = count($forecasts); for ($i = 0; $i < $howmany; $i++) { if(isset($forecasts[$i][_c][location][_c][temperature][_a][value])){ $validfr = $forecasts[$i][_a][from]; $jstime = ((strtotime($validfr)+$utcdiff)*1000); if($jstime<$jsstop){ $tempjson[] = array($jstime,round($forecasts[$i][_c][location][_c][temperature][_a][value],1)); } } } return $tempjson; } function microtime_float(){ list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } ?>
  '.get_lang("Temperature").' '.get_lang("Precipitation").' '.get_lang("Grass temperature").' '.get_lang("Surface temperature").' '.get_lang("Soil").' '.$sgdepth1.' '.get_lang("Soil").' '.$sgdepth2.'
'.$line[sunstr].' '.$line[dateline].'
'.date('H:i',$line[time]).'
'.round($line[temp]).'°
'.showprecipt($line[prectot],$uoms[1],$washowzeroprecip,get_lang("No precip")).'
'.round($line[grass]).'°
'.round($line[surface]).'°
'.round($line[soil1t]).'°
'.get_lang("Moisture").':'.round($line[soil1m]).'%
'.round($line[soil2t]).'°
'.get_lang("Moisture").':'.round($line[soil2m]).'%