#!/usr/bin/perl

open REPORT, ">opticalpower.tex";
open LOG, "<opticalpower.txt";




while (<LOG>) {
    /(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)/ 
	or die "Unrecognized format of log file";

    $pwr[$1]{'ori'} = $2;
    $pwr[$1]{'ppi'} = $3;
    $pwr[$1]{'ppo'} = $4;
    $pwr[$1]{'gtu'} = $5;
$lay_var=$1;
}

  



print REPORT "\\begin{center}\n";
print REPORT "\\begin{tabular}{|l|cc|cc|cc|cc|cc|}\n";
print REPORT "\\hline\n";

for ($i=0; $i<10; $i++) {
    printf REPORT "& S%d%s ", ($i/2) % 10, ($i%2 == 0) ? 'A' : 'B';
}
print REPORT "\\\\\n";

for ($i=0; $i<10; $i++) {
    print REPORT "& $i ";
}
print REPORT "\\\\\n";

print REPORT "\\hline\n";

print REPORT "\$P_{ORI}\$ (\$\\mu\$W)";
for ($i=$lay_var-9; $i<=$lay_var; $i++) {
    printf REPORT "& %d ", $pwr[$i]{'ori'};
}
print REPORT "\\\\\n";

print REPORT "\$P_{PP in}\$ (\$\\mu\$W)";
for ($i=$lay_var-9; $i<=$lay_var; $i++) {
    printf REPORT "& %d ", $pwr[$i]{'ppi'};
}
print REPORT "\\\\\n";

print REPORT "\$P_{PP out}\$ (\$\\mu\$W)";
for ($i=$lay_var-9; $i<=$lay_var; $i++) {
    printf REPORT "& %d ", $pwr[$i]{'ppo'};
}
print REPORT "\\\\\n";

print REPORT "\$P_{GTU}\$ (\$\\mu\$W)";
for ($i=$lay_var-9; $i<=$lay_var; $i++) {
    printf REPORT "& %d ", $pwr[$i]{'gtu'};
}
print REPORT "\\\\\n";


print REPORT "\\hline\n";

print REPORT "\\end{tabular}\n";
print REPORT "\\end{center}\n";


print REPORT "\n";
print REPORT "\\begin{center}\n";
print REPORT "\\includegraphics[width=\\textwidth]{opticalpower.pdf}\n";
print REPORT "\\end{center}\n";

