#!/usr/bin/perl

#perl script to calc ERI and ERI*
#ERI - EVN reliability indicator/index (goodvis:expvis)
#ERI* - doesnt account 'acts of god' (bad weather/RFI etc)

print "How many antennas are scheduled to be in the experiment?\n";
$ant=<STDIN>; chomp $ant;

print "How long is the experiment? (mins)\n";
$timetot=<STDIN>; chomp $timetot;

print "How many time chunks?\n";
$time=<STDIN>; chomp $time;

print "Please enter the times of the chunks (in mins space sepd, must add to total time) BETTER WORDING REQ\n";
$tweight=<STDIN>; chomp $tweight;

@tw=split(" ",$tweight);

for ($i=0;$i<=$#tw; $i++){
    $tw[$i]=$tw[$i]/$timetot;
#    print "$tw[$i]\n";
}

print "How many subbands (inc pols) is the experiment? (e.g. 8 IFs 2 pols = 16)\n";
#print "How many frequency chunks?\n";
$freqtot=<STDIN>; chomp $freqtot;

print "How many frequency chunks?\n";
$freq=<STDIN>; chomp $freq;

print "How many SBs per freq chunk (space sepd, must add to total SBs)?\n";
$fweight=<STDIN>; chomp $fweight;

@fw=split(" ",$fweight);

for ($i=0;$i<=$#fw; $i++){
    $fw[$i]=$fw[$i]/$freqtot;
#    print "freqweight $fw[$i]\n";
}

$vis=$timetot*$freqtot*($ant*($ant-1)/2);

print "total pseudo vis = $vis\n";

$AV=0;
for ($i=0; $i<=$time-1;$i++){
    $ii=$i+1;
    for ($j=0; $j<=$freq-1;$j++){
	$jj=$j+1;
	print "How many antennas are lost for time chunk $ii and freq chunk $jj?\n";
	$antx=<STDIN>;
	chomp $antx;
	$anttot=$ant-$antx;
	$basetot=$anttot*($anttot-1)/2;
	#actual vis AV
#	print "$AV $basetot $tw[$i] $timetot $fw[$j] $freqtot\n";
	$AV=$AV+($basetot*$tw[$i]*$timetot*$fw[$j]*$freqtot);
    }
}

print "AV= $AV\n";

$ERI=$AV/$vis;

print "ERI = $ERI\n";

#$vis1=$...

#print "How long is the experiment? (mins)\n";
#$timetot=<STDIN>; chomp $timetot;

#print "How many subbands (inc pols) is the experiment? (e.g. 8 IFs 2 pols = 16)\n";
#$sb=<STDIN>; chomp $sb;
