Powered by
|
© March 5, 2007 Lorentz JÄNTSCHI |
<?
if(array_key_exists("source",$_GET)){
$definition_page["up_dir"]="";
$definition_page["auto_index"]=FALSE;
$definition_page["copyright"]=array("March 5, 2007","lori");
include($_SERVER["DOCUMENT_ROOT"]."/"."definitions.php");
include("source.php");
die();
}
if(!(count($_GET)==0)){
$form=FALSE;
$_POST=$_GET;
$_GET=array();
}elseif(!(count($_POST)==0)){
$form=FALSE;
}else{
$form=TRUE;
}
$_GET=array();
if($form){
$definition_page["auto_index"]=FALSE;
$definition_page["copyright"]=array("March 5, 2007","lori");
include($_SERVER["DOCUMENT_ROOT"]."/"."definitions.php");
include("form.php");
}else{
$definition_page["up_dir"]="";
$definition_page["auto_index"]=FALSE;
$definition_page["copyright"]=array("March 5, 2007","lori");
include($_SERVER["DOCUMENT_ROOT"]."/"."definitions.php");
include("result.php");
}
?>
<?
$list["operators"]=array("+", "-", "*", "/", "%", "(", ")", ",");
$list["coefficients"]=array("\$a", "\$b", "\$c", "\$d", "\$e");
$list["variables"]=array("\$x");
$list["functions"]=array("deg2rad", "rad2deg", "asinh", "sinh", "asin", "sin", "acosh", "cosh", "acos", "cos", "atanh", "tanh", "atan", "tan", "exp", "log10", "log", "abs", "ceil", "floor", "fmod", "max", "min", "pow", "round", "sqrt", "pi");
$list["values"]=array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "E", "e", "f", "F", ".");
$labe["coef"]=array("a", "b", "c", "d", "e");
$valu["coef"]=array(2, 2, 0, 0, 0);
$labe["vari"]=array("min", "max", "inc");
$valu["vari"]=array(0, 10, 0.1);
$labe["expr"]=array("expr");
$valu["expr"]=array("\$a*pow(\$x,2)*sin(pi()*\$x/4)+\$b");
function format_xy($xy){
if(!$xy) return $xy;
if(abs($xy-round($xy))<1e-10){
$xy=round($xy);
$fxy="%d";
}elseif(abs(log(abs($xy)+1e-20,10))>4){
$fxy="%.2e";
}else{
$fxy="%.2f";
}
$xy=trim(sprintf($fxy,$xy));
return $xy;
}
?>
<?
include("definitions.php");
echo("<br><br>");
echo("This interface allows to evaluate a mathematical expression in one variable (\$x) writen in PHP style.");
echo(" This is useful for bidimensional plots.");
echo("<form method='post' action='".$_SERVER["REQUEST_URI"]."'>");
echo("<table border='1'>");
echo("<tr><td>Expression<td>Coefficients<td>Variable<td>Compulsory");
echo("<tr><td valign='top'>");
texta_rows("expr",$labe,$valu);
echo("<td valign='top'>");
echo("<table border='1'>");
input_rows("coef",$labe,$valu);
echo("</table>");
echo("<td valign='top'>");
echo("<table border='1'>");
input_rows("vari",$labe,$valu);
echo("</table>");
echo("<td valign='top'>".valid_values($list));
echo("<tr><td>");
echo("<input type='checkbox' name='ai' CHECKED> auto plot");
echo("<td>");
echo("<input type='checkbox' name='ad' CHECKED> eval data");
echo("<td>");
echo("<A Href='".$_SERVER["REQUEST_URI"]."?source='>my source</A>");
echo("<td align='center'><input type='submit'>");
echo("</table>");
echo("</form>");
function valid_values(&$l){
$r="<table border='1'>";
foreach($l as $k => $v){
$r.="<tr><td><b>".$k."</b><td>[".implode(" ",$v)."]";
}
return $r."</table>";
}
function input_rows($n,&$l,&$v){
if(!array_key_exists($n,$l))die("</table>label error, ".$n);
if(!array_key_exists($n,$v))die("</table>value error, ".$n);
for($i=0;$i<count($l[$n]);$i++){
echo("<tr><td><b>".$l[$n][$i]."</b><td><input name='".$l[$n][$i]."' type='text' value='".format_xy($v[$n][$i])."' size='3'>");
}
}
function texta_rows($n,&$l,&$v){
if(!array_key_exists($n,$l))die("</table>label error, ".$n);
if(!array_key_exists($n,$v))die("</table>value error, ".$n);
for($i=0;$i<count($l[$n]);$i++){
echo("<textarea cols='25' rows='10' name='".$l[$n][$i]."'>".$v[$n][$i]."</textarea>");
}
}
?>
<?
define("img_prg","http://l.academicdirect.org/Fundamentals/Plots/bars/");
echo("<br><br>");
if(array_key_exists("ad",$_POST)){
$auto_data=TRUE;
unset($_POST["ad"]);
}else{
$auto_data=FALSE;
}
if(array_key_exists("ai",$_POST)){
$auto_plot=TRUE;
unset($_POST["ai"]);
}else{
$auto_plot=FALSE;
}
echo("<table border='1'>");
echo("<tr>");
foreach($_POST as $k => $v){
if($k=="expr")
echo("<td>\$y=eval(whatever)");
else
echo("<td>\$".$k);
}
echo("<tr>");
foreach($_POST as $k => $v){
echo("<td>".$v);
}
echo("</table><table>");
include("eligibility.php");
for($i=0;$i<count($labe["coef"]);$i++){
$ok=eval("\$".$labe["coef"][$i]."=".$_POST[$labe["coef"][$i]].";return TRUE;");
if(!$ok)echo($labe["coef"][$i]." eval unexpected fail.\r\n");
}
for($i=0;$i<count($labe["vari"]);$i++){
$ok=eval("\$".$labe["vari"][$i]."=".$_POST[$labe["vari"][$i]].";return TRUE;");
if(!$ok)echo($labe["vari"][$i]." eval unexpected fail.\r\n");
}
for($x=$$labe["vari"][0];$x<=$$labe["vari"][1];$x+=$$labe["vari"][2]){
$ok=eval("\$y=".$_POST[$labe["expr"][0]].";return TRUE;");
if(!$ok)echo("expr eval unexpected fail.\r\n");
$qx[]=format_xy($x);
$qy[]=format_xy($y);
}
echo("<table><tr><td valign='top'>");
if($auto_data){
echo("<table border='1'><tr><td>iter<td>\$x<td>\$y");
for($i=0;$i<count($qx);$i++){
echo("<tr><td>".$i);
echo("<td>".$qx[$i]);
echo("<td>".$qy[$i]);
}
}
echo("</table>");
echo("<td valign='top'>");
$qx=implode(";",$qx);
$qy=implode(";",$qy);
if($auto_plot){
if(strlen($qx)+strlen($qy)<1000){
echo("<img src='".img_prg."?x=".$qx."&y=".$qy."&x_m=0&y_m=0&ip=lineto'>");
}else{
$uid=$_SERVER["UNIQUE_ID"];
$cnt=file_put_contents("/var/tmp/php".$uid,"x\t".$qx."\n"."y\t".$qy."\nx_m\t0\ny_m\t0\nip\tlineto");
if(!$cnt)die("Server error.");
echo("<img src='".img_prg."?uid=".$uid."'>");
}
}else{
echo("<form method='post' action='".img_prg."'>");
echo("<table border='1'>");
echo("<tr><td><b>X's</b><br>");
echo("<textarea name='xm' cols='50' rows='10'>".$qx."</textarea>");
echo("<tr><td><b>Y's</b><br>");
echo("<textarea name='ym' cols='50' rows='10'>".$qy."</textarea>");
echo("</table><input type='hidden' name='ip' value='lineto'><input type='submit' name='method'>");
echo("</form>");
}
echo("</table>");
die();
?>
<?
echo("<br>");
echo("<b>index.php</b><br>");
highlight_file("index.php");
echo("<hr>");
echo("<b>definitions.php</b><br>");
highlight_file("definitions.php");
echo("<hr>");
echo("<b>form.php</b><br>");
highlight_file("form.php");
echo("<hr>");
echo("<b>result.php</b><br>");
highlight_file("result.php");
echo("<hr>");
echo("<b>source.php</b><br>");
highlight_file("source.php");
?>