Thursday, November 24, 2011

SEGY Header Dumper Version 3

Kode Perl di bawah ini berguna untuk meng-ekstrak header segy lalu meng-outputkannya ke dalam file ASCII.

Berikut adalah cara dan contoh hasil dari penggunaan kode tersebut.

 


#!/usr/bin/perl
#extract_segy_header.pl  file.sgy byte#1 byte#2 etc...
$fname=$ARGV[0];
sysopen(IN,$fname,O_RDONLY) or die "Can't Open $fname: $!";
$size= -s IN;
my $num_args = $#ARGV;
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);

open OUT," > header_$fname.txt" or die "$!\n";
my $buffer;
my $i=0;
while (sysread(IN, $buffer, 240+($noofsamples*$bytewidth),0))
{
for ($j=1; $j<=$num_args; $j++)
{
$hulu=unpack("N",substr($buffer,3600+$ARGV[$j]-1));
print OUT "$hulu\t";
}
print OUT "\n";
progress_bar( $i, $tracecount, 25, '=' );
$i++;
}
print "\e[?25h";
print "\n";
print "...process done!:   header_$fname.txt has been created\n";
sub progress_bar {
    my ( $got, $total, $width, $char ) = @_;
    $width ||= 25;
    $char  ||= '=';
    my $num_width = length $total;
    local $| = 1;
    print "\e[?25l";
    printf "|%-${width}s| read %${num_width}s traces of %s (%.2f%%)\r", 
        $char x (($width-1)*$got/$total). '>', $got, $total, 100*$got/$total;
}
exit;

No comments: