$name = $_SERVER['SCRIPT_NAME'];
$chars = preg_split('/\//', $name, -1, PREG_SPLIT_NO_EMPTY);
$me = sizeof($chars);
$file_name_execute = $chars[$me-1];
set_time_limit(0);
$array_full =array();
$min_step = 5; //As a percentage.
$min_step_size = $min_step/100;
$working_counter=0;
$f_num = 2;
$r_num = $_REQUEST['r_num'];
$order_max = $_REQUEST['order_max'];
$submit = $_REQUEST['submit'];
$view_all=$_REQUEST['view_all'];
print "
";
print " ";
if (preg_match("/calculate/i",$submit)){
print "";
for($a=1;$a<=$f_num;$a++){
$value_bw = "bw_$a"; $$value_bw = $_REQUEST[$value_bw];
$value_per = "per_$a"; $$value_per = $_REQUEST[$value_per];
$value_tb = "true_bw_$a";$$value_tb = $$value_per/100*$$value_bw;
$value_f = "f_$a"; $$value_f = $_REQUEST[$value_f];
$value_s = "step_$a"; $$value_s = $_REQUEST[$value_s];
if (($$value_tb*$min_step_size) > $$value_s) $$value_s =$$value_tb*$min_step_size;
$value_min = "f_min_$a"; $$value_min = $$value_f-$$value_tb/2;
$value_max = "f_max_$a"; $$value_max = $$value_f+$$value_tb/2;
$value_val = "f_val_$a"; $$value_val = $$value_min;
$g1=$$value_bw; $g2= $$value_per; $g3=$$value_tb; $g4= $$value_f; $g5=$$value_s;
# print "bandwidth:$g1 percentage:$g2 bandwidth Used:$g3 Cf:$g4 step size used:$g5 ";
print "Bandwidth Used:$g3 MHz ";
print "Cf:$g4 MHz ";
print "Step Size Used:$g5 MHz ";
}
print "
";
for($a=1;$a<=$r_num;$a++){
$value = "f_low_$a"; $$value = $_REQUEST[$value];
$value = "f_high_$a"; $$value = $_REQUEST[$value];
}
$power = pow(2,($f_num));
$num_max =15;
print "Working:";
flush ();
$start_time = explode(' ', microtime());
$start_time = $start_time[1] + $start_time[0];
/* print "
Carrier 1
n
Carrier 2
m
Pim Frequency
Order
Low Limit
High Limit
";
#*/
$f_val_1 = $f_min_1 - $step_1;
# print "$f_num,$r_num ";
while ($f_val_1 <= ($f_max_1-$step_1)){
$f_val_1 = $f_val_1 + $step_1;
$f_val_2 = $f_min_2 - $step_2;
while ($f_val_2 <= ($f_max_2-$step_2)){
$f_val_2 = $f_val_2+ $step_2;
for($n=1;$n<=$num_max;$n++){
for($m=1;$m<=$num_max;$m++){
$order = $n + $m;
if (($order_max <1 ) || strlen ($order_max)<1 ) $order_max = 1000;
# print "ORDRE = $order, $order_max ";
if ($order > $order_max) {break;}
for($count=0;$count<=($power-1);$count++){
$binary = strrev(decbin($count));
# $binary = strrev($binary);
if ($binary[0]==0) $a=""; else $a ="-";
if ($binary[1]==0) $b=""; else $b ="-";
$equation = "$a$f_val_1*$n + $b$f_val_2*$m ";
# print "EQN: $equation , $power ,$count,ORDER:$order,$f_val_1, $f_val_2, $f_max_1, $f_max_2 ";
EVAL("\$equation = $equation;");
# print "EQN: $equation ";
for($loc=1;$loc<=$r_num;$loc++){
$valuel= "f_low_$loc";
$valueh = "f_high_$loc";
$val1=$$valuel;
$val2=$$valueh;
#print "$loc, $count, BIN:$binary,$n, $m, $o,$p,$q,$r,$s,Calc:$equation,Order: $order, $val1, $val2 ";
if (($equation >= $$valuel) && ($equation < $$valueh) ){
/* print "
$f_val_1
$a$n
$f_val_2
$b$m
$equation
$order
$val1
$val2
";
#*/
$a="$a$n"; EVAL("\$a = $a;");
$b="$b$m"; EVAL("\$b = $b;");
$array_full[] = array($f_val_1,$a,$f_val_2,$b,$equation,$order,$val1,$val2);
#print "$loc, BIN:$binary,$n, $m, $o,$p,$q,$r,$s,Calc:$equation,Order: $order, $val1 ,$val2, ";
break;
} //Close IF check for within rec. band
}
# if ( ($n==0 ) || ($m==0) ) break;
} //close count loop
} // close m loop
// if (preg_match("/IE/i",$HTTP_USER_AGENT)){}else{
$working_counter = $working_counter + 1;
if ( ($working_counter % 10) == 0) {flush(); echo str_pad('.',1)."";}
if ( ($working_counter % 600) == 0) echo str_pad('Still working',1)."";
if ( ($working_counter % 1200) == 0) print " ";
// }
} //close n loop
} //close f2 while loop
} //close f1 while loop
$end_time = explode(' ', microtime());
$total_time = $end_time[0] + $end_time[1] - $start_time;
printf(' Calculations completed in %.3f seconds.', $total_time);
flush();
#*/
// print "
";
foreach ($array_full as $key => $row) {
$array_val1[$key] = $row['6'];
$array_order[$key] = $row['5'];
}
array_multisort($array_val1, SORT_ASC, $array_order, SORT_ASC, $array_full);
foreach ($array_full as $key => $row) {
$starting_val = $row['6'];
$starting_order = $row['5'];
break;
}
$distance = 9999;
$key_counter=0;
$order_number = 0;
foreach ($array_full as $key => $row) {
$new_val = $row['6'];
$new_order = $row['5'];
if ( ( $starting_val == $new_val) && ($starting_order == $new_order)){
}else{
$distance = 9999;
$order_number = 0;
$key_counter= $key_counter+1;
$starting_val = $new_val;
$starting_order = $new_order;
}
$order_total[$key_counter] = ++$order_number;
$distance_new = sqrt(pow(($f_1-$row['0']),2) + pow(($f_2-$row['2']),2));
if ($distance_new < $distance){
$distance = $distance_new;
$keys[$key_counter] = $key;
}
}
print " ";
print "Following results shows the closest frequencies to CF for each order and receive band checked ";
print "
Carrier 1
Index F1
Carrier 2
Index F2
Pim Frequency
Order
Low Limit
High Limit
Number that also failed the same order and limit range
";
#*/
foreach ($keys as $key => $row) {
$line = $array_full [$row];
print "";
foreach ($line as $key_line => $row_line) {
print "$row_line ";
}
echo "".$order_total[$key]." ";
print " ";
}
print "
";
print " ";
if (preg_match ("/yes/i",$view_all)){
print "
Carrier 1
Index F1
Carrier 2
Index F2
Pim Frequency
Order
Low Limit
High Limit
";
foreach ($array_full as $key => $row) {
print "";
foreach ($row as $key_line => $row_line) {
print "$row_line ";
}
print " ";
}
print "
";
}
}
}else{
print "This calculator handles 2 carriers, where you define the bandwidth. ";
print "Select the number of receive frequencies ranges to check:";
print "";
for($num=1;$num<=10;$num++){
if($num==$r_num) $selected="selected";
else $selected="";
print " $num ";
}
print " ";
print "
";
}
?>