"Fossies" - the Fresh Open Source Software Archive

Member "fimex-1.4.1/share/scripts/fiMinMaxAvg.pl" (30 Oct 2019, 1278 Bytes) of package /linux/privat/fimex-1.4.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "fiMinMaxAvg.pl" see the Fossies "Dox" file reference documentation.

    1 #! /usr/bin/perl
    2 
    3 use strict;
    4 use warnings;
    5 
    6 unless (@ARGV) {
    7     print STDERR "usage: $0 file.nc\n";
    8     exit(1);
    9 }
   10 
   11 my $cmd = "fiXYcontents --input.file=$ARGV[0] --stats=mean,min,max,stddev";
   12 open my $ph, "$cmd |"
   13     or die "cannot call '$cmd': $!\n";
   14 my %stats;
   15 my $var = "";
   16 while (defined (my $line = <$ph>)) {
   17     if ($line =~ /^Var\:/) {
   18         printStats($var, \%stats) if $var;
   19         my @newVar = split ' ', $line;
   20         $var = "$newVar[1]($newVar[3])";
   21         $stats{min} = [];
   22         $stats{max} = [];
   23         $stats{mean} = [];
   24         $stats{stddev} = [];
   25     } elsif ($line =~ /mean=(\S+)\s+min=(\S+)\s+max=(\S+)\s+stddev=(\S+)/) {
   26         push @{ $stats{mean} }, $1;
   27         push @{ $stats{min} }, $2;
   28         push @{ $stats{max} }, $3;
   29         push @{ $stats{stddev} }, $4;
   30     } 
   31 }
   32 
   33 sub printStats {
   34     my ($var, $stats) = @_;
   35     print $var, " ";
   36     foreach my $stat (qw(min max mean)) {
   37         my ($min, $max) = minMax(@{ $stats->{$stat} });
   38         print "$stat=$min-$max ";
   39     }
   40     print "\n";
   41 }
   42 
   43 sub minMax {
   44     my $min = $_[0];
   45     my $max = $_[0];
   46     foreach my $el (@_) {
   47         if ($min > $el) {
   48             $min = $el;
   49         }
   50         if ($max < $el) {
   51             $max = $el;
   52         }
   53     }
   54     return ($min, $max);
   55 }
   56 
   57 sub max {
   58 }