Perl Code:
#!/usr/bin/perl
my $i=1;
while (<>) {
chomp;
@s = split ; #split data into lines
#################################
if (/VSTKT/) #grep lines contain VSTKT
{
push @inlin, @s[0]; #push into inline
push @xline, @s[1];
push @datum, @s[2];
push @cmp, @s[3];
}
####################begin push with restriction
if ($_!~/VSTKT/ && $_!~/CGG/ ) #select lines doesn't contain VSTKT and CGG
{
$numel=@s; #count no of elements in each line
for ($j=0; $j<=$numel-1; $j++)
{
push @sa,$s[$j]; #push data into array
}
}
####################end push
}
$numel2=@sa;
for ($j=0; $j<=($numel2-1)/2; $j++)
{
push @time,$sa[$j*2]; #select odd lines
push @vels,$sa[$j*2+1]; #select even lines
}
$numel3=@time;
for ($j=0; $j<=$numel3; $j++)
{
$dt[$j]=$time[$j+1]-$time[$j]; #calculate time difference
push @dtx, $dt[$j]; #push
}
my (@index) = grep $dtx[$_] < 0, 0 .. $#dtx; #locate negative time difference i.e. new cmp
$numel4=@index;
for ($j=0; $j<=$numel4-2; $j++)
{
$idx[$j]=$index[$j+1]-$index[$j]; #calculate no of analysis points
push @idx2,$idx[$j];
}
push @idx3, $index[0]+1, @idx2; #calculate no of analysis points
$numel5=@idx3;
for $m (0..$numel5-1) #no cmp
{
@time1=@time[$index[$m]-($idx3[$m]-1)..$index[$m]];
@vels1=@vels[$index[$m]-($idx3[$m]-1)..$index[$m]];
printf "%s", "SPNT";
printf "%11d",$cmp[$m];
printf "%25d",$xline[$m];
printf "%20d",$inlin[$m];
print "\n";
for $k (0..$idx3[$m]/5)
{
printf "%s", "VELF";
for $i (1..5)
{
if ($vels1[$i+$k*5-1] > 0) #exist vel
{
if ($i == 1 && $k==0) #beginning of analysis points
{
printf "%11d",$cmp[$m];
printf "%5d",$datum[$m];
printf "%5d",$time1[$i+$k*5-1];
}
elsif ($i == 1 && $k==1 ) #row no 2 in omega format of each cmp
{
printf "%21d",$time1[$i+$k*5-1];}
elsif ($i == 1 ) #rest of analysis points
{
printf "%21d",$time1[$i+$k*5-1];
}
else
{
printf "%5d",$time1[$i+$k*5-1];
}
printf "%5d",$vels1[$i+$k*5-1];
}
}
print "\n";
}
@time1=();
@vels1=();
}
No comments:
Post a Comment