Displacement Calculator
[insert_php]$pi = 3.141592653589;
//—————————————-
//cylinder volume = pi/4 x bore^2 x stroke
if($_POST[‘a’] == “cv”)
{
$cv_bore = $_POST[‘cv_bore’];
$cv_stroke = $_POST[‘cv_stroke’];
$cv_errors = 0;
if($_POST[‘cv_bore’] == “”) {$cv_errors++;}
else { if(!is_numeric($_POST[‘cv_bore’])) {$cv_errors++;} }
if($_POST[‘cv_stroke’] == “”) {$cv_errors++;}
else { if(!is_numeric($_POST[‘cv_stroke’])) {$cv_errors++;} }
if($cv_errors != 0) {$cv_error_msg = “Please enter proper values!”;}
else
{
$total_cylinder_volume = $pi / 4 * $_POST[‘cv_bore’] * $_POST[‘cv_bore’] * $_POST[‘cv_stroke’];
$view_total_cylinder_volume = ” Cylinder Volume = “.$total_cylinder_volume;
}
}
//—————————————-
//piston displacment = pi/4 x bore^2 x stroke x number of cylinders
if($_POST[‘a’] == “pd”)
{
$pd_bore = $_POST[‘pd_bore’];
$pd_stroke = $_POST[‘pd_stroke’];
$pd_nr_cylinders = $_POST[‘pd_nr_cylinders’];
$pd_errors = 0;
if($_POST[‘pd_bore’] == “”) {$pd_errors++;}
else { if(!is_numeric($_POST[‘pd_bore’])) {$pd_errors++;} }
if($_POST[‘pd_stroke’] == “”) {$pd_errors++;}
else { if(!is_numeric($_POST[‘pd_stroke’])) {$pd_errors++;} }
if($_POST[‘pd_nr_cylinders’] == “”) {$pd_errors++;}
else { if(!is_numeric($_POST[‘pd_nr_cylinders’])) {$pd_errors++;} }
if($pd_errors != 0) {$pd_error_msg = “Please enter proper values!”;}
else
{
$total_piston_displacement = $pi / 4 * $_POST[‘pd_bore’] * $_POST[‘pd_bore’] * $_POST[‘pd_stroke’] * $_POST[‘pd_nr_cylinders’];
$view_total_piston_displacement = ” Piston Displacement = “.$total_piston_displacement;
}
}
//—————————————-
//stroke = displacement / (pi/4 x bore^2 x number of cylinders)
if($_POST[‘a’] == “s”)
{
$s_bore = $_POST[‘s_bore’];
$s_displacement = $_POST[‘s_displacement’];
$s_nr_cylinders = $_POST[‘s_nr_cylinders’];
$s_errors = 0;
if($_POST[‘s_bore’] == “”) {$s_errors++;}
else { if(!is_numeric($_POST[‘s_bore’])) {$s_errors++;} }
if($_POST[‘s_displacement’] == “”) {$s_errors++;}
else { if(!is_numeric($_POST[‘s_displacement’])) {$s_errors++;} }
if($_POST[‘s_nr_cylinders’] == “”) {$s_errors++;}
else { if(!is_numeric($_POST[‘s_nr_cylinders’])) {$s_errors++;} }
if($s_errors != 0) {$s_error_msg = “Please enter proper values!”;}
else
{
$total_stroke = $_POST[‘s_displacement’] / ($pi / 4 * $_POST[‘s_bore’] * $_POST[‘s_bore’] * $_POST[‘s_nr_cylinders’]);
$view_total_stroke = ” Stroke = “.$total_stroke;
}
}
//—————————————-
//bore = sqrt (displacement / (pi/4 x stroke x number of cylinders))
if($_POST[‘a’] == “b”)
{
$b_stroke = $_POST[‘b_stroke’];
$b_displacement = $_POST[‘b_displacement’];
$b_nr_cylinders = $_POST[‘b_nr_cylinders’];
$b_errors = 0;
if($_POST[‘b_stroke’] == “”) {$b_errors++;}
else { if(!is_numeric($_POST[‘b_stroke’])) {$b_errors++;} }
if($_POST[‘b_displacement’] == “”) {$b_errors++;}
else { if(!is_numeric($_POST[‘b_displacement’])) {$b_errors++;} }
if($_POST[‘b_nr_cylinders’] == “”) {$b_errors++;}
else { if(!is_numeric($_POST[‘b_nr_cylinders’])) {$b_errors++;} }
if($b_errors != 0) {$b_error_msg = “Please enter proper values!”;}
else
{
$total_bore = sqrt ( $_POST[‘b_displacement’] / ($pi / 4 * $_POST[‘b_stroke’] * $_POST[‘b_nr_cylinders’]));
$view_total_bore = ” Bore = “.$total_bore;
}
}
//===============================================
$content = ‘
‘;
$content = addslashes($content);
$content = “\$result=\””.$content.”\”;”;
eval($content);
print stripslashes($result);
[/insert_php]