#!/usr/bin/perl                                                                                                                                                  use strict;
use warnings;
use RFC::Rig;
unless (@ARGV)
{
    print "Script for getting the maximum gas flows for a specified rig and test number.\n";
    exit;
}
my $rig = RFC::Rig->new(shift);
$rig->check_run();
my $session = $rig->session();
$session = shift if (@ARGV);
my $str = $rig->get_cv_test('main','gas_names',$session);
my $dir = $rig->webdir($session);
my $file = $dir.'jdata';
open MYIN,'<',$file or die "Could not open file $file $!\n";
my $line = <MYIN>;
close MYIN;
my @list = split(/\s+/,$line);
foreach my $gas (sort split(/\s*\,\s*/,$str))
{
    my $col = 0;
    my $x = 0;
    while (!$col && $x < @list)
    {
        $x++;
        next unless ($list[$x] eq $gas);
        $col = $x+2;
        last;
    }
    my $cmd = "awk '{if(min==\"\"){min=max=\$$col}; if(max<\$$col){max=\$$col}; if(\$$col< min) {min=\$$col};} END {print min \"\\n\" max}' $file";
    my ($min,$max) = `$cmd`;
    foreach ($min,$max)
    {
        chomp;
    }
    printf("%-16s:Max: %.2f\n",$gas,$max);
}
