Tuesday, November 22, 2011

SEGY Header Dumper Version 1

Pada artikel SEGY, saya telah membahas penggunaan Kode PERL untuk mengekstrak informasi yang dimiliki oleh binary header dan trace header yang pertama dari sebuah data SEGY.

Pada bagian ini anda dapat menggunakan kode PERL yang telah saya kembangkan untuk melakukan ekstrak trace header untuk setiap trace.

Berikut adalah contoh hasil dump sebuah file SEGY.
./headerdumper.pl gathertest.segy
-----Agus Abdullah 2011   ----------------
 -----Press ENTER for the Next Trace-------
Trace no: 3 out of 1236
byte#001-004:        3                    byte#005-008:        3         
byte#009-012:        290084729      byte#013-016:        1235      
byte#017-020:        0                    byte#021-024:        0         
byte#025-028:        3                    byte#029-032:        589825    
byte#033-036:        65537             byte#037-040:        0         
byte#041-044:        0                    byte#045-048:        0         
byte#049-052:        0                    byte#053-056:        0         
byte#057-060:        0                    byte#061-064:        0         
byte#065-068:        0                    byte#069-072:        65537     
byte#073-076:        0                    byte#077-080:        0         
byte#081-084:        0                    byte#085-088:        0         
byte#089-092:        65536             byte#093-096:        0         
byte#097-100:        0                    byte#101-104:        0         
byte#105-108:        0                    byte#109-112:        0         
byte#113-116:        263645            byte#117-120:        262144000 
byte#121-124:        0                    byte#125-128:        0         
byte#129-132:        0                    byte#133-136:        0         
byte#137-140:        0                    byte#141-144:        0         
byte#145-148:        0                    byte#149-152:        0         
byte#153-156:        0                    byte#157-160:        0         
byte#161-164:        0                    byte#165-168:        0         
byte#169-172:        0                    byte#173-176:        0         
byte#177-180:        0                    byte#181-184:        0         
byte#185-188:        0                    byte#189-192:        0         
byte#193-196:        0                    byte#197-200:        0         
byte#201-204:        0                    byte#205-208:        0         
byte#209-212:        0                    byte#213-216:        0         
byte#217-220:        0                    byte#221-224:        0         
byte#225-228:        0                    byte#229-232:        0         
byte#233-236:        0                    byte#237-240:        0         
 -----Press 9 then ENTER to EXIT----------


Copy kode PERL di bawah ini lalu simpan dalam directory tempat data seismik anda berada.

#!/usr/bin/perl
$fname=$ARGV[0];
sysopen(IN,$fname,O_RDONLY) or die "Can't Open $fname: $!";
$size= -s IN;
open my $fh, '<', $fname or die "Cannot open ";
$bytewidth=4;
my $cacing;
read($fh,$cacing,3600,0);
$noofsamples = unpack("n",substr($cacing,3220));
$tracecount=($size-3600)/(240+$bytewidth*$noofsamples);

$tracecount = sprintf("%.0f", $tracecount);
my $i=1;
my $buffer;
$,="";  
while (sysread(IN, $buffer, 240+($noofsamples*$bytewidth),0))
{
print" -----Agus Abdullah 2011   ----------------\n";
print" -----Press ENTER for the Next Trace-------\n";
print"Trace no: $i out of $tracecount\n";
$i++;
for ($j=0; $j<=60; $j++)
{
$head[$j]=unpack("N",substr($buffer,3600+$j*4));
}
printf "%-20s %-20d %-20s %-10d \n","byte#001-004:", $head[0],"byte#005-008:", $head[1];
printf "%-20s %-20d %-20s %-10d \n","byte#009-012:", $head[2],"byte#013-016:", $head[3];
printf "%-20s %-20d %-20s %-10d \n","byte#017-020:", $head[4],"byte#021-024:", $head[5];
printf "%-20s %-20d %-20s %-10d \n","byte#025-028:", $head[6],"byte#029-032:", $head[7];
printf "%-20s %-20d %-20s %-10d \n","byte#033-036:", $head[8],"byte#037-040:", $head[9];
printf "%-20s %-20d %-20s %-10d \n","byte#041-044:", $head[10],"byte#045-048:", $head[11];
printf "%-20s %-20d %-20s %-10d \n","byte#049-052:", $head[12],"byte#053-056:", $head[13];
printf "%-20s %-20d %-20s %-10d \n","byte#057-060:", $head[14],"byte#061-064:", $head[15];
printf "%-20s %-20d %-20s %-10d \n","byte#065-068:", $head[16],"byte#069-072:", $head[17];
printf "%-20s %-20d %-20s %-10d \n","byte#073-076:", $head[18],"byte#077-080:", $head[19];
printf "%-20s %-20d %-20s %-10d \n","byte#081-084:", $head[20],"byte#085-088:", $head[21];
printf "%-20s %-20d %-20s %-10d \n","byte#089-092:", $head[22],"byte#093-096:", $head[23];
printf "%-20s %-20d %-20s %-10d \n","byte#097-100:", $head[24],"byte#101-104:", $head[25];
printf "%-20s %-20d %-20s %-10d \n","byte#105-108:", $head[26],"byte#109-112:", $head[27];
printf "%-20s %-20d %-20s %-10d \n","byte#113-116:", $head[28],"byte#117-120:", $head[29];
printf "%-20s %-20d %-20s %-10d \n","byte#121-124:", $head[30],"byte#125-128:", $head[31];
printf "%-20s %-20d %-20s %-10d \n","byte#129-132:", $head[32],"byte#133-136:", $head[33];
printf "%-20s %-20d %-20s %-10d \n","byte#137-140:", $head[34],"byte#141-144:", $head[35];
printf "%-20s %-20d %-20s %-10d \n","byte#145-148:", $head[36],"byte#149-152:", $head[37];
printf "%-20s %-20d %-20s %-10d \n","byte#153-156:", $head[38],"byte#157-160:", $head[39];
printf "%-20s %-20d %-20s %-10d \n","byte#161-164:", $head[40],"byte#165-168:", $head[41];
printf "%-20s %-20d %-20s %-10d \n","byte#169-172:", $head[42],"byte#173-176:", $head[43];
printf "%-20s %-20d %-20s %-10d \n","byte#177-180:", $head[44],"byte#181-184:", $head[45];
printf "%-20s %-20d %-20s %-10d \n","byte#185-188:", $head[46],"byte#189-192:", $head[47];
printf "%-20s %-20d %-20s %-10d \n","byte#193-196:", $head[48],"byte#197-200:", $head[49];
printf "%-20s %-20d %-20s %-10d \n","byte#201-204:", $head[50],"byte#205-208:", $head[51];
printf "%-20s %-20d %-20s %-10d \n","byte#209-212:", $head[52],"byte#213-216:", $head[53];
printf "%-20s %-20d %-20s %-10d \n","byte#217-220:", $head[54],"byte#221-224:", $head[55];
printf "%-20s %-20d %-20s %-10d \n","byte#225-228:", $head[56],"byte#229-232:", $head[57];
printf "%-20s %-20d %-20s %-10d \n","byte#233-236:", $head[58],"byte#237-240:", $head[59];
print" -----Press 9 then ENTER to EXIT----------\n";
$quit = <STDIN>;
if($quit==9)
{
exit;
}
print "\e[2J\e[1;1H";
}
print "\n";
exit;


Coba jalankan dengan perintah:
./headerdumper.pl file.segy atau headerdumper.pl file.segy

Anda dapat meng-compile kode perl dengan perintah pp. Jika anda belum memilikinya install (UBUNTU 10.10) dengan perintah:
sudo apt-get install libpar-packer-perl

Setelah itu compile dengan perintah:
pp -o segyheaderdumper headerdumper.pl

Lalu run:
./segyheaderdumper file.sgy

No comments: