File "graph.php"

Full path: /www/ansys/ttest/accmes/graph.php
File size: 8.36 KiB (8556 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php
$indexURL = "./index.php";
$position = isset($_POST["position"]) ? htmlspecialchars($_POST["position"]) : "";

$sepPosition = split(",", $position);
$len = count($sepPosition);

$imgFname = "./img/acc_". md5(uniqid(rand(), true)). ".png";

// 読み込むファイル名、戻る場所を決める
$dataFname = "/";
$returnPosition = "";
for($iCount = 0; $iCount < $len; $iCount++)
{
	if ($iCount > 0)
	{
		$dataFname .= "/";
		if ($iCount < $len - 1)
			$returnPosition .= ",";
	}
	$dataFname .= $sepPosition[$iCount];
	if ($iCount < $len - 1)
		$returnPosition .= $sepPosition[$iCount];
}

try
{
	$img = imagecreate(1350, 610);
	$font = "/www/ansys/config/fonts/ipagp.ttf";
	
	// color一覧
	$black = imagecolorallocate($img, 0x00, 0x00, 0x00);
	$white = imagecolorallocate($img, 0xff, 0xff, 0xff);
	//$gmain = imagecolorallocate($img, 0xff, 0xff, 0xff);
	$gmain = imagecolorallocate($img, 0x00, 0x00, 0x00);
	$gsub = imagecolorallocate($img, 0x69, 0x69, 0x69);
	//$back = imagecolorallocate($img, 0x00, 0x00, 0x00);
	$back = imagecolorallocate($img, 0xff, 0xff, 0xff);
	
	$cpx = imagecolorallocate($img, 0xff, 0x00, 0x00);
	$clx = imagecolorallocate($img, 0xff, 0x63, 0x47);
	$cpy = imagecolorallocate($img, 0x00, 0xff, 0x00);
	$cly = imagecolorallocate($img, 0x22, 0x8b, 0x57);
	$cpz = imagecolorallocate($img, 0x00, 0x00, 0xff);
	$clz = imagecolorallocate($img, 0x19, 0x19, 0x70);
	$cpv = imagecolorallocate($img, 0xff, 0xd7, 0x00);
	$clv = imagecolorallocate($img, 0xff, 0xa5, 0x00);
	
	$blx = imagecolorallocate($img, 0xff, 0xc0, 0xcb);
	$bly = imagecolorallocate($img, 0x98, 0xfb, 0x98);
	$blz = imagecolorallocate($img, 0xad, 0xd8, 0xe6);
	
	imagefilledrectangle($img, 0, 0, 1350, 610, $back);
	imagesetthickness($img, 1);
	
	// 基準軸
	imageline($img, 50, 50, 50, 550, $gmain);
	imageline($img, 50, 50, 45, 55, $gmain);
	imageline($img, 50, 50, 55, 55, $gmain);
	imageline($img, 50, 550, 1310, 550, $gmain);
	imageline($img, 1310, 550, 1305, 545, $gmain);
	imageline($img, 1310, 550, 1305, 555, $gmain);
	
	$yparse = 42;
	// 補助軸
	for($iCount = 1; $iCount < $yparse; $iCount++)
	{
		//imagettftext($img, 7, 0, 50 + (60 * $iCount) - 3, 565, $gmain, $font, mb_convert_encoding($iCount, "UTF-8", "auto"));
		imageline($img, 50 + (60 * $iCount), 50, 50 + (60 * $iCount), 550, $gsub);
		imageline($img, 50 + (60 * $iCount), 545, 50 + (60 * $iCount), 555, $gmain);
	}
	imagettftext($img, 8, 0, 650, 585, $gmain, $font, mb_convert_encoding("経過秒[sec]", "UTF-8", "auto"));
	
	imageline($img, 45, 300, 1310, 300, $gmain);
	imagettftext($img, 7, 0, 33, 300 + 4, $gmain, $font, mb_convert_encoding("0", "UTF-8", "auto"));
	for($iCount = 1; $iCount < 10; $iCount++)
	{
		imageline($img, 50, 300 + ($iCount * 25), 1310, 300 + ($iCount * 25), $gsub);
		imageline($img, 45, 300 + ($iCount * 25), 55, 300 + ($iCount * 25), $gmain);
		imagettftext($img, 7, 0, 30, 300 + ($iCount * 25) + 4, $gmain, $font, mb_convert_encoding("-". $iCount, "UTF-8", "auto"));
		
		imageline($img, 50, 300 - ($iCount * 25), 1310, 300 - ($iCount * 25), $gsub);
		imageline($img, 45, 300 - ($iCount * 25), 55, 300 - ($iCount * 25), $gmain);
		imagettftext($img, 7, 0, 28, 300 - ($iCount * 25) + 4, $gmain, $font, mb_convert_encoding("+". $iCount, "UTF-8", "auto"));
	}
	imagettftext($img, 8, 90, 15, 320, $gmain, $font, mb_convert_encoding("加速度値", "UTF-8", "auto"));
	
	// 凡例
	imageline($img, 260, 30, 285, 30, $clx);
	imagefilledellipse($img, 260, 30, 6, 6, $cpx);
	imagettftext($img, 8, 0, 240, 33, $gmain, $font, mb_convert_encoding("X :", "UTF-8", "auto"));
	
	imageline($img, 330, 30, 355, 30, $cly);
	imagefilledellipse($img, 330, 30, 6, 6, $cpy);
	imagettftext($img, 8, 0, 310, 33, $gmain, $font, mb_convert_encoding("Y :", "UTF-8", "auto"));
	
	imageline($img, 400, 30, 425, 30, $clz);
	imagefilledellipse($img, 400, 30, 6, 6, $cpz);
	imagettftext($img, 8, 0, 380, 33, $gmain, $font, mb_convert_encoding("Z :", "UTF-8", "auto"));
	
	imageline($img, 505, 30, 530, 30, $clv);
	imagefilledellipse($img, 505, 30, 6, 6, $cpv);
	imagettftext($img, 8, 0, 450, 33, $gmain, $font, mb_convert_encoding("3軸合成 :", "UTF-8", "auto"));
	
	// 各軸の最大最小
	$xmin = array("pix" => 0, "val" => 0);
	$xmax = array("pix" => 1260, "val" => 0);
	$ymin = array("pix" => 500, "val" => -10.0);
	$ymax = array("pix" => 0, "val" => 10.0);
	
	$dx = 0;
	$dy = number_format(20 / 500, 10);
	
	// データを取得
	$index = 0;
	$gacc = "";
	$fp = fopen($dataFname, "r");
	if ($fp != NULL)
	{
		while(!feof($fp))
		{
			$line = trim(fgets($fp));
			if (strcmp($line, "") != 0)
			{
				$stac = split(",", $line);
				if (strcmp(substr($stac[0], 0, 1), "#") == 0)
				{
					$gacc["x"] = $stac[1];
					$gacc["y"] = $stac[2];
					$gacc["z"] = $stac[3];
					
					imageline($img, 50, 500 - (($stac[1] - $ymin["val"]) / $dy) + 50, 1310, (500 - ($stac[1] - $ymin["val"]) / $dy) + 50, $blx);
					imageline($img, 50, 500 - (($stac[2] - $ymin["val"]) / $dy) + 50, 1310, (500 - ($stac[2] - $ymin["val"]) / $dy) + 50, $bly);
					imageline($img, 50, 500 - (($stac[3] - $ymin["val"]) / $dy) + 50, 1310, (500 - ($stac[3] - $ymin["val"]) / $dy) + 50, $blz);
					
					imagettftext($img, 8, 0, 20, 600, $gmain, $font, mb_convert_encoding("基準値(x):". $gacc["x"], "UTF-8", "auto"));
					imagettftext($img, 8, 0, 120, 600, $gmain, $font, mb_convert_encoding("基準値(y):". $gacc["y"], "UTF-8", "auto"));
					imagettftext($img, 8, 0, 220, 600, $gmain, $font, mb_convert_encoding("基準値(z):". $gacc["z"], "UTF-8", "auto"));
					
					continue;
				}
				if ($index == 0)
				{
					$xmin["val"] = floor(($stac[0] / 1000.0)) * 1000.0;
					$xmax["val"] = $xmin["val"] + ($yparse * 1000);
					$dx = number_format($yparse * 1000 / 1260, 10);
					for($iCount = 0; $iCount < 22; $iCount++)
						imagettftext($img, 7, 0, 50 - $yparse + ($iCount * 60), 570, $gmain, $font, mb_convert_encoding(date("H:i:s", $xmin["val"] / 1000.0 + ($iCount)), "UTF-8", "auto"));
				}
				$p = array();
				$p["x"] = ($stac[0] - $xmin["val"]) / $dx;
				$p["y"]["x"] = 500 - ($stac[1] - $ymin["val"]) / $dy;
				$p["y"]["y"] = 500 - ($stac[2] - $ymin["val"]) / $dy;
				$p["y"]["z"] = 500 - ($stac[3] - $ymin["val"]) / $dy;
				$p["y"]["v"] = 500 - (sqrt(
				($stac[1] * $stac[1]) + ($stac[2] * $stac[2]) + ($stac[3] * $stac[3])
				) - $ymin["val"]) / $dy;
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["x"] + 50, 3, 3, $cpx);
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["y"] + 50, 3, 3, $cpy);
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["z"] + 50, 3, 3, $cpz);
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["v"] + 50, 3, 3, $cpv);
				//print $stac["1"]. ":". $p["y"]["x"]. "<br />";
				if ($index > 0)
				{
					imageline($img, $ap["x"] + 50, $ap["y"]["x"] + 50, $p["x"] + 50, $p["y"]["x"] + 50, $clx);
					imageline($img, $ap["x"] + 50, $ap["y"]["y"] + 50, $p["x"] + 50, $p["y"]["y"] + 50, $cly);
					imageline($img, $ap["x"] + 50, $ap["y"]["z"] + 50, $p["x"] + 50, $p["y"]["z"] + 50, $clz);
					imageline($img, $ap["x"] + 50, $ap["y"]["v"] + 50, $p["x"] + 50, $p["y"]["v"] + 50, $clv);
				}
				$ap = $p;
				$index++;
			}
		}
		fclose($fp);
	}
	imagepng($img, $imgFname);
	imagedestroy($img);
}
catch(Exception $exc)
{
	print $exc->getMessage(). "<br />";
}

print "<!DOCTYPE html>";
print "<html>";

print "<head>";
print "<meta chaset=\"utf-8\">";
print "<link rel=\"stylesheet\" type=\"text/css\" href=\"./css/style.css\">";
print "<title>";
print "加速度グラフ";
print "</title>";
print "</head>";

print "<body>";

print "<img src=\"". $imgFname. "?t=$now_t\">";
print "<br />";

print "<form name=\"form_return\" method=\"post\" action=\"". $indexURL. "\" style=\"display:inline\">";
print "<a href=\"javascript:form_return.submit()\">戻る</a>";
print "<input type=\"hidden\" name=\"position\" value=\"". $returnPosition. "\">";
print "</form>";

print "&nbsp;&nbsp;&nbsp;";

print "<form name=\"move_graph\" method=\"post\" action=\"./graph2.php\" style=\"display:inline\">";
print "<a href=\"javascript:move_graph.submit()\">移動平均を見る</a>";
print "<input type=\"hidden\" name=\"position\" value=\"". $position. "\">";
print "</form>";

print "&nbsp;&nbsp;&nbsp;";

print "<form name=\"move_graph2\" method=\"post\" action=\"./graph3.php\" style=\"display:inline\">";
print "<a href=\"javascript:move_graph2.submit()\">初期値と短期移動平均の外積値を見る</a>";
print "<input type=\"hidden\" name=\"position\" value=\"". $position. "\">";
print "</form>";

print "</body>";
print "</html>";

PHP File Manager