<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/bin/perl

do "parameters.pl";


# Open the file for reading.
open DATA, "Iplasma_dp.csv" or die "can't open file $!";
my @data = &lt;DATA&gt;;
close (DATA);
system("echo 0 &gt; Plasma;rm -f PlasmaStart PlasmaEnd PlasmaStartAdvanced PlasmaEndDelayed");



$maxI= 0;
$minI = 0;
for ($i = 1; $i &lt; $LineCount; ++$i)  
{
    @row = split(';',$data[$i]);
    $Ipl=$row[1];
    if($maxI&lt;$Ipl){$maxI=$Ipl;}
    if($minI&gt;$Ipl){$minI=$Ipl;} 
}
$polar = 1;
if(-$minI&gt;$maxI){
    $polar = -1;
    system("echo 1 &gt; ReversedCD;");
}#reverse polarity
else 
{
    system("echo 0 &gt; ReversedCD;");
}
$StartRow = 500;


for ($i = 51; $i &lt; $LineCount-500; ++$i)  
{
    @row = split(';',$data[$i-50]) ;$Ipl10=$row[1]*$polar;
    @row = split(';',$data[$i]);    $Ipl1=$row[1]*$polar;
    $TimeStart=$row[0]+120*$DeltaT;
    @row = split(';',$data[$i+150]);$Ipl2=$row[1]*$polar;
    @row = split(';',$data[$i+175]);$Ipl3=$row[1]*$polar;
    @row = split(';',$data[$i+200]);$Ipl4=$row[1]*$polar;
    if ( $Ipl2 &gt; ($Ipl1+$Ipl0)/2+$PlCurrentRise &amp;&amp; $Ipl3 &gt; $Ipl1+$PlCurrentRise &amp;&amp; $Ipl4 &gt; $Ipl1+$PlCurrentRise ){ $StartRow=$i+120;system ("echo $TimeStart &gt; PlasmaStart;echo $StartRow &gt; PlasmaStartRow");$i=$LineCount};
}

for ($i = $LineCount-50; $i &gt;  $StartRow; --$i)  
{
    @row = split(';',$data[$i+50]); $Ipl0=$row[1]*$polar;
    @row = split(';',$data[$i]);    $Ipl1=$row[1]*$polar;
    $TimeEnd=$row[0]-30*$DeltaT;
    @row = split(';',$data[$i-50]);$Ipl2=$row[1]*$polar;
    @row = split(';',$data[$i-100]);$Ipl3=$row[1]*$polar;
    @row = split(';',$data[$i-150]);$Ipl4=$row[1]*$polar;
    if ( $Ipl2 &gt; ($Ipl1+$Ipl0)/2+$PlCurrentRise &amp;&amp; $Ipl3 &gt; $Ipl1+$PlCurrentRise &amp;&amp; $Ipl4 &gt; $Ipl1+$PlCurrentRise ){$EndRow=$i-30;$dT=$TimeEnd-$TimeStart; system ("echo $TimeEnd &gt; PlasmaEnd;echo $TimeEnd*11/10 &gt; PlasmaEndDelayed;echo $dT &gt; PlasmaTimeLength;echo $EndRow &gt; PlasmaEndRow;echo 1 &gt; Plasma");$i=1};
}


$EFieldTrigger  =`cat /srv/www/svoboda/golem/operation/currentshot/Tcd_aktual`;
$EFieldTrigger = $EFieldTrigger/1000; # [ms]	

$start = ($TororoidalMagneticFieldTrigger+$EFieldTrigger)-$DeltaT*10;
system ("echo $start &gt; PlasmaStartAdvanced;")</pre></body></html>