Content-type: text/html
X-Powered-By: PHP/4.3.10
<?
include("config.php");
//  header("Content-type: application/xhtml+xml");
  header("content-type: image/svg+xml");
  print('<?xml version="1.0" standalone="no"?>'."\n");
  print('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"'."\n");
  print('"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'."\n");
if($_REQUEST[fnumber])
    $fnumber = (int)$_REQUEST[fnumber];
if($_REQUEST[day])
    $fnumber = (int)$_REQUEST[day];
if(strlen($_REQUEST[rulers]))
    $rulers=$_REQUEST[rulers];
if(strlen($_REQUEST[grid]))
    $grid=$_REQUEST[grid];
if(strlen($_REQUEST[size]))
  $size=$_REQUEST[size];
if($size==0)
{
  $xscreen=$uxscreen;
  $yscreen=300;
}
$viewbox="-50 -40 1560 570";
if($size==0)
  $viewbox="0 0 300 300";
?>
<svg width="100%" height="100%" version="1.1" viewBox="<?echo $viewbox?>" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<style type="text/css"><![CDATA[
.grid {
 fill: #0a0a0a;
 stroke: #222222;
 stroke-width: 2;
 opacity: 1
}
polyline {stroke-width: 1}
.snrup { stroke: <?echo $snrup?>;
 fill: none}
.snrdown { stroke: <?echo $snrdown?>;
 fill: none}
.snrtxt { fill: <?echo $snrtxt?>;}
.syncup { stroke: <?echo $syncup?>;
 fill: none}
.syncdown { stroke: <?echo $syncdown?>;
 fill: none}
.synctxt { fill: <?echo $synctxt?>;}
.tsnrup { fill: <?echo $snrup?>}
.tsnrdown { fill: <?echo $snrdown?>}
.tsyncup { fill: <?echo $syncup?>}
.tsyncdown { fill: <?echo $syncdown?>}
]]></style>
</defs>
<?
if($fnumber < 1 || $fnumber > 366)
    $fnumber=11;
$fname = sprintf("$datapath-%03d", $fnumber);
//print("<!-- fname is $fname -->\n");
function xxx($x)
{
   global $xscreen, $xsamples, $precision;
   return round($x*$xscreen/$xsamples, $precision);
}
function yyy($y)
{
   global $yscreen, $ysamples, $precision;
   return round($yscreen-($y*$yscreen/$ysamples), $precision);
}
?><?// Draw the grid?>
<rect class="grid" x="0" y="0" width="<?echo $xscreen?>" height="<?echo $yscreen?>"/>
<?if($grid==1)
{
    ?><path class="grid" d="<?
    for($x=0; $x<=24; $x++)
    {
    ?>M<?print(xxx($x*60))?> <?print(yyy(0)+7)?>V<?print(yyy($ysamples));
    }
    ?>"/><?
    ?><path class="grid" d="<?
    for($y=0; $y<=$ysamples; $y++)
    {
    ?>M<?print(xxx(0)-7)?> <?print(yyy($y))?>H<?print(xxx($xsamples)+7);
    }
    ?>"/><?
}
if($rulers==1)
{
    for($x=0; $x<=24; $x++)
    {
    ?><text x="<?print(xxx($x*60)-4)?>" y="<?print(yyy(0)+22)?>" ><?echo $x?></text><?
    }
    for($y=0; $y<=$ysamples; $y++)
    {
    ?><text class="snrtxt" x="<?print(xxx(0)-25)?>" y="<?print(yyy($y)+3)?>"><?echo $y?></text><?
    ?><text class="synctxt" x="<?print(xxx($xsamples)+8)?>" y="<?print(yyy($y)+3)?>"><?print(($y*3)*($y*3))?></text><?
    }
?><text class="snrtxt" x="<?print(xxx(0))?>" y="<?print(yyy(20)-9)?>">SNR (dB)</text>
<text class="synctxt" x="<?print(xxx(22*60))?>" y="<?print(yyy(20)-9)?>">SYNC (Kbs)</text>
<text class="tsnrdown" x="<?print(xxx(4*60))?>" y="<?print(yyy(20)-9)?>">——SNR DOWN——</text>
<text class="tsnrup" x="<?print(xxx(8*60))?>" y="<?print(yyy(20)-9)?>">——SNR UP——</text>
<text class="tsyncdown" x="<?print(xxx(12*60))?>" y="<?print(yyy(20)-9)?>">——SYNC DOWN——</text>
<text class="tsyncup" x="<?print(xxx(16*60))?>" y="<?print(yyy(20)-9)?>">——SNYC UP——</text>
<?
}
function readDataFile()
{
    global $thedata, $elements, $fname;
    $fp = fopen($fname, "r");
    $elements = 0;
    if(!$fp)
       return;
    while(!feof($fp))
    {
        $buffer = fgets($fp);
        $buffer = str_replace(", ", ",", $buffer);
        $thedata[$elements] = $buffer;
        $elements++;
    }
    fclose($fp);
//    print("<!-- read $elements elements -->");
}
readDataFile();
// open output file and print downstream SNR
function graphline($line)
{
    global $thedata, $elements;
    $c=0;
    $lastx = 0;
    $oldstuff = "-1";
    while($c < $elements)
    {
        $buffer = $thedata[$c];
        $c++;
        if(!$buffer) break;
        if($line == 1)
            $stuff = strtok($buffer, ",");
        else
            $null = strtok($buffer, ",");
        for($lp = 2; $lp < 7; $lp++)
        {
            if($lp == $line)
                $stuff = (int)strtok(",");
            else
                $null=strtok(",");
        }
        $xtime=strtok(",");
        $x=(int)strtok($xtime, ":");
        //   print("got x as $x\n");
        $x=$x*60 + (int)strtok(":");
        if($line >= 5)
            $stuff=sqrt($stuff/1000)/3;
        if($stuff == $oldstuff)
            continue;
        if($oldstuff != "-1" && ($x-1) != $lastx)
            print(xxx($x-1).','.yyy($oldstuff).' ');
        print(xxx($x).','.yyy($stuff).' ');
        $oldstuff = $stuff;
        $lastx = $x;
    }
    if($lastx != $x)
        print(xxx($x).','.yyy($stuff).' ');
}
?>
<polyline class="snrdown"
points="<?//print(xxx(0).",".yyy(0)." ");
    graphline(1);?>"/>
<polyline class="snrup"
points="<?//print(xxx(0).",".yyy(0)." ");
    graphline(2);?>"/>
<polyline class="syncup"
points="<?//print(xxx(0).",".yyy(0)." ");
    graphline(5);?>"/>
<polyline class="syncdown"
points="<?//print(xxx(0).",".yyy(0)." ");
    graphline(6);?>"/>
</svg>