Output Interval-setting in Wxsim must be set to 1 hour for script to work properly if ( ! isset($_SERVER['DOCUMENT_ROOT'] ) ) { $path_trans = str_replace( '\\\\', '/', $_SERVER['PATH_TRANSLATED']); $WEBROOT = substr($path_trans, 0, 0-strlen($_SERVER['PHP_SELF']) ); } else { $WEBROOT = $_SERVER['DOCUMENT_ROOT']; } //********************************************* //CONFIG DEFINE ("TTF_DIR",$WEBROOT."/fonts/" ); // folder for your fontfile, uses arial.ttf-fontfile. // For other font, just rename another fontfile and upload it instad $filename = "latest.csv"; // path to your latest.csv based from this script $days = "6"; // How many days do you want to show, 4, 5 and 6 days possible $lat = "38.985"; // Your latitude -> needed for figuring out nighticons $long = "1.300"; // Your longitude $offset = "+2"; // Offset from GMT (Note! Normal offset, not summertime) $icondir = "./meteogr/meteogram/"; // Iconsfolder $jp = "./jp_graph/src/"; // path to JpGraph // Texts $head = "Meteograma Sant Antoni de Portmany"; // Header $discla = "meteoibiza.com"; // copyright text, current year is added automatic $uom = "°C"; $prec = "mm"; $wsp = "km/hr"; //CONFIG END //********************************************** $fp = fopen($filename,"r"); $f_content= fread($fp, filesize($filename)); fclose($fp); $fnotes = explode("\n",$f_content); $temperature = array(); $rain = array(); $hr = array(); $hrb = array(); $barb = array(); $ws = array(); $wspd = array(); $wdir = array(); $sky = array(); $li= array(); $tr = '0'; $dl = date("I"); if ($dl == 1) { $offset = ($offset + 1); } $zenith=90+33/60; $sunri = date_sunrise(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset); $sunse = date_sunset(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset); $sunr = strtotime($sunri); $suns = strtotime($sunse); $sunrhr = date('H', $sunr); $sunshr = date('H', $suns); $howmany = count($fnotes); $dd = (($days * 24) + 4); for ($i = 4; $i < $dd; $i++) { $arrays = $fnotes[$i]; $temps = explode(' ,',$arrays); if ($i == 4) { $ruh = substr(trim($temps[3]), 0, 2); } $wdir[] = windDir(round($temps[13])); $wspd[] = rep_comma($temps[12]); $sky[] = trim($temps[4]); $li[] = rep_comma(trim($temps[25])); $hour = substr(trim($temps[3]), 0, 12); $hour = rep_comma($hour); $hrb[] = $hour; if($hour == "5") { $hrr = trim($temps[2]) . "." . trim($temps[1]) . "." . trim($temps[0]); } //else if($hour == "0") { $hrr = "|"; } else { $hrr = ""; } $hr[] = $hrr; $temp = str_replace(",",".",trim($temps[6])); $temperature[] = $temp; $rawrain = rep_comma($temps[14]); $srain[] = $rawrain; } $howmanyra = count($srain); for ($i = 2; $i < $howmanyra-1; $i++) { $calcrain = ($srain[$i+1] - $srain[$i]); $grain[] = $calcrain; } $howmanyra = count($grain); for ($i = 0; $i < $howmanyra-1; $i++) { $rarray = array(); $rarray[] = $grain[$i]; //$rarray[] = $grain[$i-2]; $rarray[] = $grain[$i-1]; $rarray[] = $grain[$i+1]; //$rarray[] = $grain[$i+2]; $rrain = max($rarray); $rain[] = $rrain; $rain[] = $rrain; $rain[] = $rrain; //$rain[] = $rrain; //$rain[] = $rrain; $i++; $i++; //$i++; //$i++; } $cond = array(); $howmanygg = count($wspd); for ($i = 3; $i < $howmanygg-3;) { $wsarray = array(); $wsarray[] = $wspd[$i]; $wsarray[] = $wspd[$i-3]; $wsarray[] = $wspd[$i-2]; $wsarray[] = $wspd[$i-1]; $wsarray[] = $wspd[$i+1]; $wsarray[] = $wspd[$i+2]; if ($days > 4) { $wsarray[] = $wspd[$i+3]; $wsarray[] = $wspd[$i-4]; } //print_r($wsarray); $wsspd = max($wsarray); $barb[] = $icondir . strtolower($wdir[$i]) . ".png"; $ws[] = $wsspd; if ($days == 4) { $i = $i+6; } else { $i = $i+8; } } $howmanygf = count($sky); for ($i = 3; $i < $howmanygf-1;) { //$cx = array(); $cx = $sky[$i] .' '; $cx .= $sky[$i-3] .' '; $cx .= $sky[$i-2] .' '; $cx .= $sky[$i-1] .' '; $cx .= $sky[$i+1] .' '; $cx .= $sky[$i+2] .' '; if ($days > 4) { $cx .= $sky[$i-4] .' '; $cx .= $sky[$i+3] .' '; } $rarray = array(); $rarray[] = $grain[$i]; $rarray[] = $grain[$i-3]; $rarray[] = $grain[$i-2]; $rarray[] = $grain[$i-1]; $rarray[] = $grain[$i+1]; $rarray[] = $grain[$i+2]; if ($days > 4) { $rarray[] .= $grain[$i-4] .' '; $rarray[] .= $grain[$i+3] .' '; } $LIarray = array(); $LIarray[] = $li[$i]; $LIarray[] = $li[$i-3]; $LIarray[] = $li[$i-2]; $LIarray[] = $li[$i-1]; $LIarray[] = $li[$i+1]; $LIarray[] = $li[$i+2]; if ($days > 4) { $LIarray[] = $li[$i+3]; $LIarray[] = $li[$i-4]; } //print_r($cxarray); $night = 0; if(($hrb[$i] > $sunrhr) && ($hrb[$i] < $sunshr)) { $day = 1; } else { $night = 1; } if($hrb[$i] <=5 || $hrb[$i] >= 23) { $night = 1; } $cond[] = $icondir . geticon($cx, $rarray, $night, $LIarray) . ".png"; if ($days == 4) { $i = $i+6; } else { $i = $i+8; } } function rep_comma($ra) { $ra = str_replace(",",".",trim($ra)); return $ra; } function rep_comma2($ra) { $ra = str_replace(",",'',trim($ra)); return $ra; } function windDir ($winddir) // Given the wind direction, return the text label // for that value. 16 point compass { if (!isset($winddir)) { return "---"; } $windlabel = array ("N","NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW","SW", "WSW", "W", "WNW", "NW", "NNW"); $dir = $windlabel[ (int) ($winddir / 22.5) ]; return "$dir"; } function geticon($sky, $precip, $night, $LI) { $icon = "dunno"; // default if (preg_match('|SUNNY|', $sky)) { $icon = "0"; } if (preg_match('|CLEAR|', $sky)) { $icon = "0"; } if (preg_match('|FAIR|', $sky)) { $icon = "9"; } if (preg_match('|CLOUDY|', $sky)) { $icon = "18"; } if (preg_match('|P.CLOUDY|', $sky)) { $icon = "2"; } if (preg_match('|M.CLDY|', $sky)) { $icon = "5"; } if (preg_match('|M.CLOUDY|', $sky)) { $icon = "5"; } if (preg_match('|DNS.OVCST|', $sky)) { $icon = "5"; } if (preg_match('|RAIN|', $sky)) { $icon = "20"; } if (preg_match('|LIGHT RAIN|', $sky)) { $icon = "22"; } if (preg_match('|SNOW|', $sky)) { $icon = "26"; } if (preg_match('|SLEET|', $sky)) { $icon = "24"; } if (preg_match('|RAIN AND SNOW|', $sky)) { $icon = "24"; } if (preg_match('|THUNDER|', $sky)) { $icon = "29"; } if (preg_match('|THUNDER POSSIBLE|', $sky)) { $icon = "36"; } if(($icon == 18) && (preg_match('|FOG|', $sky))) { $icon = "6"; } if(($icon == 2 || $icon == 5) && (max($precip) > 0)) { $icon = "37"; } if (min($LI) < 0) { $icon = "36"; } if ($night == 1) { // NIGHTICONS if (preg_match('|CLEAR|', $sky)) { $icon = "1"; } if (preg_match('|FAIR|', $sky)) { $icon = "1"; } if (preg_match('|CLOUDY|', $sky)) { $icon = "13"; } if (preg_match('|P.CLOUDY|', $sky)) { $icon = "38"; } if (preg_match('|M.CLDY|', $sky)) { $icon = "38"; } if (preg_match('|M.CLOUDY|', $sky)) { $icon = "38"; } if (preg_match('|DNS.OVCST|', $sky)) { $icon = "38"; } if (preg_match('|RAIN|', $sky)) { $icon = "12"; } if (preg_match('|LIGHT RAIN|', $sky)) { $icon = "12"; } if (preg_match('|SNOW|', $sky)) { $icon = "16"; } if (preg_match('|SLEET|', $sky)) { $icon = "16"; } if (preg_match('|RAIN AND SNOW|', $sky)) { $icon = "16"; } if (preg_match('|THUNDER|', $sky)) { $icon = "17"; } if (preg_match('|THUNDER POSSIBLE|', $sky)) { $icon = "39"; } if(($icon == 18) && (preg_match('|FOG|', $sky))) { $icon = "11"; } if(($icon == 38 || $icon == 5) && (max($precip) > 0)) { $icon = "40"; } if (min($LI) < 0) { $icon = "17"; } } return $icon; } function get_windbarb($speed) { $barb = '0'; switch (true) { case ($speed <= 2): $barb = '2'; break; case ($speed <= 5): $barb = '5'; break; case ($speed <= 10); $barb = '10'; break; case ($speed <= 12): $barb = '12'; break; case ($speed <= 15); $barb = '15'; break; case ($speed <= 17); $barb = '17'; break; case ($speed <= 20): $barb = '20'; break; case ($speed <= 22); $barb = '22'; break; case ($speed == 0): $barb = '0'; // continue for rest of cases } // end select return ($barb); }// end get_windbarb //print_r($li); // START THR GRAPH $fd = $days; include ($jp . 'jpgraph.php'); include ($jp . 'jpgraph_line.php'); include ($jp . 'jpgraph_bar.php'); include ($jp . 'jpgraph_iconplot.php'); $array = array(); $array = $temperature; $barray = array(); $barray = $rain; $carray = array(); $carray = $hr; $graph = new Graph(730,205,"auto"); $graph->img->setTransparent("#FFFFFF"); $graph->img->SetAntiAliasing(); $graph->SetScale('textlin'); $graph->title->SetColor("#383875"); $graph->SetMarginColor("#f2f2f2"); $graph->SetFrame(true,'#E1E0F0',3); $graph->SetMargin(25,25,50,45); $plot = new LinePlot($array); $plot->SetColor('red'); $plot->SetWeight(1); $bplot = new BarPlot($barray); $bplot->SetColor('#3399CC'); $bplot->SetWidth(1.0); $bplot->SetFillColor('#3399CC'); $t = '20'; $howmanyga = count($barb); $tb = (660/($howmanyga-1)); for ($i = 0; $i < $howmanyga; $i++) { $icon[$i] = new IconPlot($barb[$i]); $icon[$i]->SetAnchor('left','top'); $tt = ($i * $tb + $t); $icon[$i]->SetPos($tt, 163); } $graph->Add($icon); $t = '20'; $howmanyoa = count($ws); $tb = (660/($howmanyoa-1)); for ($i = 0; $i < $howmanyga; $i++) { $gtxt[$i]=new Text("$ws[$i]"); $gtxt[$i]->SetColor( "#424242"); $gtxt[$i]->SetFont(FF_ARIAL,FS_NORMAL,7); $tt = ($i * $tb + $t); $gtxt[$i]->Pos($tt,185); $graph->AddText($gtxt[$i]); } $t = '25'; $howmanyaa = count($cond); $tb = (660/($howmanyaa-1)); for ($i = 0; $i < $howmanyaa; $i++) { $iconc[$i] = new IconPlot($cond[$i]); $iconc[$i]->SetAnchor('left','top'); $tt = ($i * $tb + $t); $iconc[$i]->SetPos($tt, 28); } $graph->Add($iconc); if (max($grain) > 1.5) { $mx = ceil(max($grain)); } else { $mx = "1.5"; } $graph->SetY2Scale("lin", 0, $mx); $graph->title->Set("$header"); $graph->Add($plot); $graph->AddY2($bplot); $graph->ygrid->SetColor('#cccccc'); $graph->ygrid->SetLineStyle('dashed'); $graph->xaxis->title->SetColor("#383875"); $graph->xaxis->SetColor("#cccccc"); $graph->xaxis->SetTextLabelInterval(1); $graph->xaxis->SetTickLabels($carray); $graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8); $graph->xaxis->HideTicks(true,true); $graph->xaxis->SetLabelMargin(3); $graph->xaxis->SetPos('max'); $graph->yaxis->SetFont(FF_ARIAL,FS_NORMAL,8); $graph->yaxis->SetTitlemargin(0); //$graph->yaxis->SetTitle("°C", "top"); $graph->yaxis->HideTicks(true,false); $graph->yaxis->title->SetColor("red"); $graph->yaxis->SetLabelMargin(5); $graph->yaxis->SetColor("#cccccc","red"); $graph->y2axis->SetFont(FF_ARIAL,FS_NORMAL,8); $graph->y2axis->SetTitlemargin(0); //$graph->y2axis->SetTitle("mm", "middle"); $graph->y2axis->title->SetColor("#3399CC"); $graph->y2axis->SetColor("#cccccc","#3399CC"); $graph->y2axis->SetLabelMargin(3); $graph->y2axis->HideTicks(true,false); $ctxt=new Text("$head"); $ctxt->Pos(25,8); $ctxt->SetColor( "#424242"); $ctxt->SetFont(FF_ARIAL,FS_NORMAL,10); $graph->AddText( $ctxt); $txt=new Text( "$uom"); $txt->Pos( 8,29); $txt->SetColor( "red"); $txt->SetFont(FF_ARIAL,FS_NORMAL,8); $graph->AddText( $txt); $btxt=new Text( "$prec"); $btxt->Pos( 705,29); $btxt->SetColor( "#3399CC"); $btxt->SetFont(FF_ARIAL,FS_NORMAL,8); $graph->AddText( $btxt); $ttxt=new Text( "$wsp"); $ttxt->Pos( 705,183); $ttxt->SetColor( "#424242"); $ttxt->SetFont(FF_ARIAL,FS_NORMAL,7); $graph->AddText( $ttxt); $yr = date('Y'); $dtxt=new Text( "© $yr $discla"); $dtxt->Pos( 585,193); $dtxt->SetColor( "#cccccc"); $dtxt->SetFont(FF_ARIAL,FS_NORMAL,8); $graph->AddText( $dtxt); $t0 = ((24 - $ruh) * 1); $tt = count($array); $t1 = ($t0 + 24); $t2 = ($t0 + 48); $t3 = ($t0 + 72); $t4 = ($t0 + 96); $t5 = ($t0 + 120); $graph->AddLine(new PlotLine(VERTICAL,$t0,"#cccccc",1)); $graph->AddLine(new PlotLine(VERTICAL,$t1,"#cccccc",1)); $graph->AddLine(new PlotLine(VERTICAL,$t2,"#cccccc",1)); $graph->AddLine(new PlotLine(VERTICAL,$t3,"#cccccc",1)); if($t4 < $tt) { $graph->AddLine(new PlotLine(VERTICAL,$t4,"#cccccc",1)); } if($t5 < $tt) { $graph->AddLine(new PlotLine(VERTICAL,$t5,"#cccccc",1)); } $graph->Stroke(); ?>