Link to home
Start Free TrialLog in
Avatar of yu12koe
yu12koe

asked on

ozo,Average!

The $b variable is from the Infile,this statement: runt1!9!14(The 2nd value,it can be 3values or 5values or 9values)
Infile:
runt1!9!14
runt2!9!14
runt3!9!15
runt4!9!25
runt5!9!3


Then How do i calculate my average of the values for each parameter and print the average value to the end of each line(See output file) in the output file e.g
-9.960116E+02!+1.002406E-03!
means that -9.960116 is to the power of 2,1.002406 is to the power of -3.

ps:Your codes did not include this calculation of the power to 3?It only sum up the total is it?

Output file(Contains only 2values but it can be 3 or 5 or 9 values):

s1!NE2 40/40 Vth0!+9.939227E+02!+9.982348E+02!avg(value calculated)!
s2!NE2 40/40 Vth0!-9.960116E+02!+1.002406E-03!avg(value calculated)!    

s1!Vth Vb/2.5!+3.985872E-08!+3.948130E-08!avg(value calculated)!
s2!Vth Vb/2.5!+3.974027E-08!+3.971276E-08!avg(value calculated)!


Below is my codes:
open(FILE1,"infile") || die "Can't open infile because $!";
open(FILE2,">outfile") || die "Can't open outfile because $!";

while( <FILE1> )
{
  ($a,$b,$c) = split(/!/);
  $c = sprintf("%02d",$c);
  open (FILE3,"<$a") || die "Can't open $a because $!";
  while( <FILE3> )
  {
    next unless /SYS_WAFERID!$c\b/.../SYS_WAFERID!$c\b/;
    next unless ($para,@values) = (/([^!]+)!.*!/,/!([-+][-+\d.E]+)/g);
    push @para,$para unless $para{$para};
    if($b == 3)
    {
      for('s1'..'s3')
      {
         push @{$para{$para}{$_}},shift @values;
      }
    }
    if($b == 5)
    {
      for('s1'..'s5')
      {
         push @{$para{$para}{$_}},shift @values;
      }
    }
    if($b == 9)
    {
      for('s1'..'s9')
      {
         push @{$para{$para}{$_}},shift @values;
      }
    }
  }
  close FILE3;
}
for $p ( @para )
{
  if($b == 3)
  {
    for $s ('s1'..'s3' )
    {
       print FILE2 join"!",$s,$p,@{$para{$p}{$s}};
       $avg =0;
       for(@{$para{$p}{s}})
       {
          $avg = $avg + $_;
       }
       $avg/=@{$para{$p}{$s}};
       print FILE2 "!$avg!\n";
       #print FILE2 "\n";
    }
    print FILE2 "\n";
  }
  if($b == 5)
  {
    for $s ('s1'..'s5' )
    {
        print FILE2 join"!",$s,$p,@{$para{$p}{$s}};
        print FILE2 "\n";
    }
    print FILE2 "\n";
  }
  if($b == 9)
  {
    for $s ('s1'..'s9' )
    {
        print FILE2 join"!",$s,$p,@{$para{$p}{$s}};
        print FILE2 "\n";
    }
    print FILE2 "\n";
  }
}

How do i solve my problem of getting !avg(0)!
Pls help,thanks!!
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial