File: getav.pl

package info (click to toggle)
splash 3.11.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,068 kB
  • sloc: f90: 55,119; ansic: 2,435; python: 828; makefile: 601; cpp: 529; perl: 219; sh: 152
file content (37 lines) | stat: -rwxr-xr-x 832 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/perl
# adds up the L2 errors from supersphplot output; calculates average
use strict;
use warnings;

use List::Util qw(sum);
my $file = ' ';
my $avg = 0;
if ($#ARGV < 0) {
   print "script which parses supersphplot output for L2 errors \n";
   print "and calculates the average. Written by D. Price. \n\n";
   die "Usage: $0 filename(s) \n";
}

foreach $file (@ARGV) {
   open my $fh, '<', $file or die "Can't open $file: $!";
   my @errors;

   while ( <$fh> ) {
      if ( my ($error) = m/L2 error\s+=\s+(\S*)\s+/ ) {
         #print "error = $error \n";
         push @errors, $error;
      }
   }

   my $nerrors = scalar(@errors);
   if ($nerrors > 0) {
      $avg = sum(@errors) / $nerrors;
   }
   else {
      $avg = 0;   
   }

   print "$file: Average of $nerrors errors: $avg\n";
}

#print "$_\n" for @errors;