#!bin/perl

do "parameters.pl";

# Open the file for reading.
open DATA1, "Iplasma_dp.csv" or die "can't open file $!";
my @data1 = <DATA1>;
close (DATA1);

open DATA2, "PlasmaStartRow" or die "can't open file $!";
my $PlasmaStartRow = <DATA2>;
close (DATA2);

open DATA3, "PlasmaEndRow" or die "can't open file $!";
my $PlasmaEndRow = <DATA3>;
close (DATA3);

for ($i=0;$i<$LineCount;++$i)
{
	@row1=split(';',$data1[$i]);
	$Time[$i]=$row1[0];
	$GreenwaldDensityTime[$i]= abs(($row1[1]/100000)/(3.14159265*($LimiterPosition)**2));
}
$maxGreenwaldDensity=0;
for ($i=$PlasmaStartRow;$i<$PlasmaEndRow;++$i)
{
	$maxGreenwaldDensity= $maxGreenwaldDensity < $GreenwaldDensityTime[$i] ? $GreenwaldDensityTime[$i] : $maxGreenwaldDensity;
}
open CIL1, ">GreenwaldDensityTime.txt";
for ($i=0;$i<$LineCount;$i++)
{
	print CIL1 "$Time[$i]	$GreenwaldDensityTime[$i]\n";
}
close (CIL1);

open CIL2, ">maxGreenwaldDensity";
print CIL2 "$maxGreenwaldDensity";
close (CIL2);
