use strict;
use warnings;

my $nodata = 0;               
my $nodata_max = -1;          
my $nodata_maxline = "!";     

my $infiles = join ", ", @ARGV;

my $tot_file = 0;
my $num_file = 0;

while (<>) {
  chomp;
  my $tot_line = 0;             
  my $num_line = 0;             
  my $rejects  = 0;

  
  my ($date, @fields) = split;
  while (@fields and my ($datum, $flag) = splice @fields, 0, 2) {
    if ($flag+1 < 2) {
      $nodata++;
      $rejects++;
      next;
    }

    
    if($nodata_max == $nodata and $nodata > 0){
      $nodata_maxline = "$nodata_maxline, $date";
    }
    if($nodata_max < $nodata and $nodata > 0){
      $nodata_max = $nodata;
      $nodata_maxline = $date;
    }
    
    $nodata = 0; 
    
    $tot_line += $datum;
    $num_line++;
  }

  
  $tot_file += $tot_line;
  $num_file += $num_line;

  printf "Line:%11s  Reject:%2i  Accept:%2i  Line_tot:%10.3f  Line_avg:%10.3f\n",
         $date, $rejects, $num_line, $tot_line, ($num_line>0)? $tot_line/$num_line: 0;

}

printf "\n";
printf "File(s)  =%s\n", $infiles;
printf "Total    =%10.3f\n", $tot_file;
printf "Readings =%6i\n", $num_file;
printf "Average  =%10.3f\n", $tot_file / $num_file;

printf "\nMaximum run(s) of%i consecutive false readings ends at line starting with date(s):%s\n", 
       $nodata_max, $nodata_maxline;