Debian Codegraph @

scripts/getav.pl

raw
1 #!/usr/bin/perl
2 # adds up the L2 errors from supersphplot output; calculates average
3 use strict;
4 use warnings;
5
6 use List::Util qw(sum);
7 my $file = ' ';
8 my $avg = 0;
9 if ($#ARGV < 0) {
10 print "script which parses supersphplot output for L2 errors \n";
11 print "and calculates the average. Written by D. Price. \n\n";
12 die "Usage: $0 filename(s) \n";
13 }
14
15 foreach $file (@ARGV) {
16 open my $fh, '<', $file or die "Can't open $file: $!";
17 my @errors;
18
19 while ( <$fh> ) {
20 if ( my ($error) = m/L2 error\s+=\s+(\S*)\s+/ ) {
21 #print "error = $error \n";
22 push @errors, $error;
23 }
24 }
25
26 my $nerrors = scalar(@errors);
27 if ($nerrors > 0) {
28 $avg = sum(@errors) / $nerrors;
29 }
30 else {
31 $avg = 0;
32 }
33
34 print "$file: Average of $nerrors errors: $avg\n";
35 }
36
37 #print "$_\n" for @errors;