Tuesday, November 22, 2011

SEGY Header Dumper Version 2

Versi ini memiliki kapabilitas untuk melakukan scanning seluruh trace header yang dimiliki oleh data SEGY, lalu menampilkan nilai minimum dan maksimum untuk setiap lokasi byte.

Copy kode berikut lalu beri nama headerminmax.pl

#!/usr/bin/perl
my $num_args = $#ARGV;
die "usage: headerminmax.pl file.sgy  \n" if ($num_args+1 eq 0);
$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);
print"Agus Abdullah, PhD 2011 agusabdullah at gmail.com\n";
my $buffer;
my $i=0;
while (sysread(IN, $buffer, 240+($noofsamples*$bytewidth),0))
{
for ($j=0; $j<=59; $j++)
{
$head[$j]=unpack("N",substr($buffer,3600+$j*4));
push @{$hulu[$j]},$head[$j];
}
progress_bar( $i, $tracecount, 25, '=' );
$i++;
}
print "\n";
print"Statistics MIN-MAX Trace Header $fname (Assume: 32 bits Integer)\n";
print"               min              -        max\n";
for ($j=0; $j<=59; $j++)
{
@{$hulu[$j]}=sort {  $a  <=>  $b  } @{$hulu[$j]};
$k1=$j*4+1;
$k2=$j*4+4;
printf "%-15s %-15d %-8s %-31d \n","byte #$k1-$k2:", $hulu[$j][1],"-",$hulu[$j][$tracecount];
@{$hulu[$j]}=();
}
print "\e[?25h";
sub progress_bar {
    my ( $got, $total, $width, $char ) = @_;
    $width ||= 25;
    $char  ||= '=';
    my $num_width = length $total;
    local $| = 1;
    print "\e[?25l";
    printf "|%-${width}s| scanning %${num_width}s traces of %s (%.2f%%)\r",
        $char x (($width-1)*$got/$total). '>', $got, $total, 100*$got/$total;}
exit;

No comments: