#!bin/perl

do "parameters.pl";

# Open the file for reading.
open DATA1, "Btoroidal_dp.csv" or die "can't open file $!";
my @data1 = <DATA1>;
close (DATA1);

# Open the file for reading.
open DATA2, "Iplasma_dp.csv" or die "can't open file $!";
my @data2 = <DATA2>;
close (DATA2);

# Open the file for reading.
open DATA3, "disR.txt" or die "can't open file $!";
my @data3 = <DATA3>;
close (DATA3);

# Open the file for reading.
open DATA4, "disZ.txt" or die "can't open file $!";
my @data4 = <DATA4>;
close (DATA4);

$PeakFactor=2;

open CIL, ">PeakFactor";
print CIL "$PeakFactor";
close (CIL);


for ($i=0;$i<$LineCount;++$i)
{
	@row1=split(';',$data1[$i+1]);
	@row2=split(';',$data2[$i]);
	@row3=split(' ',$data3[$i]);
	@row4=split(' ',$data4[$i]);
	$Time[$i]=$row1[0];
	$zkouska[$i]=(($row3[1]/1000)**2+($row4[1]/1000)**2)**0.5;
	$QedgeTimeMirnov[$i]= $row2[1]==0 ? 0 : 12500*(($LimiterPosition-(($row3[3]/1000)**2+($row4[3]/1000)**2)**0.5)**2)*abs($row1[1]/($row2[1]))*1e3;
	$Q0TimeMirnov[$i]=$QedgeTimeMirnov[$i]/($PeakFactor+1);
}

open CIL1, ">QedgeTimeMirnov.txt";
for ($i=0;$i<$LineCount;$i++)
{
	print CIL1 "$Time[$i]	$QedgeTimeMirnov[$i]	$Q0TimeMirnov[$i]\n";
}
close (CIL1);
