Thursday, January 15, 2015

Omega Format Velocity Edit

Kode Perl di bawah ini berguna untuk mengedit velocity omega format (text):
1. set pick time and vel 1
2. set pick time and vel 2
3. set second last pick time
4. set last pick time and vel


#!/usr/bin/perl
my $file = $ARGV[0];
open(DATA, $file) || die "Can't open $file: $!\n";
while (<DATA>) {
chomp;
@s = split ;  #split data into lines
#####################################
if (/SPNT/) #grep lines contain VSTKT
{
push @inlin, @s[2];   #push into inline
push @xline, @s[1];
}

################index SPNT###########
if (/VELF/)
{  #begin VELF
#####################################
$numel=@s;  #count no of elements in each line
if ($numel==13)
{
push @cmp,$s[1];
push @datum,$s[2];
for ($j=1; $j<=10; $j++)
{
push @sa,$s[2+$j];
}
}

elsif ($numel==12)
{
for ($j=1; $j<=10; $j++)
{
push @sa,$s[1+$j];
}
}

elsif ($numel<=11)
{
for ($j=1; $j<=$numel-1; $j++)
{
push @sa,$s[$j];
}
}
} #end VELF
} #end data read


###########################################################

$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
{


@time1x=@time[$index[$m]-($idx3[$m]-1)..$index[$m]];
@vels1x=@vels[$index[$m]-($idx3[$m]-1)..$index[$m]];

$cacing=@time1x;
for ($n=0; $n<=$cacing-1; $n++)
{
if ($time1x[$n]< 3000)#set max time for second last pick ####user edit 1
{
push @time2,$time1x[$n];
push @vels2,$vels1x[$n];
}
}
###########################set last pick ############################
push @time1,@time2,6000;########################################user edit 2
push @vels1,@vels2,4850;########################################user edit 3
############# replace velocity beginning#############################
$time1[0]=0;####################################################user edit 4
$vels1[0]=1480;#################################################user edit 5
$time1[1]=300;##################################################user edit 6
$vels1[1]=1480;#################################################user edit 7
######################################################################

printf "%s", "SPNT";
printf  "%11d",$cmp[$m];
printf  "%25d",$xline[$m];
printf  "%20d",$inlin[$m];


print "\n";


$cikur=($idx3[$m]-1)/5;
my $mn = int($cikur) + ($cikur != int($cikur));

for $k (0..$mn-1)##if you see blank VELF or reduced no of row in each cmp#user edit 8
{
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=();
@time2=();
@vels2=();
}

No comments: