#!/usr/bin/perl -w

use strict;

use lib "$ENV{OPSEXEC}/perl_mods";
use TT;
use Delta;

my %tt = ();
read_tt_tables("ak135", "$ENV{QETC}", \%tt);

my $file = "$ENV{QETC}/ak135/ELCOR.dat";
my ($ec, $np) = read_elcor_tbl($file);

my ($nlon, $nlat, $etopores) = (4321, 2161, 0.0833333);
$file = "$ENV{QETC}/topo/etopo5_bed_g_i2.bin";
my $topo = readtopo($file,$nlat,$nlon);

my $isxderiv = 1;
my $iszderiv = 1;

for ( my $depth = 0; $depth <= 700; $depth += 50 ) {

    my $out = sprintf "smp%03d.dat", $depth;

    open(OUT,">$out") or die;

    for ( my $delta = 1; $delta < 100; $delta++ ) {

        #($ttime_wcorr, $dtdd, $dtdh) = tt_wcorr('P', $tt{'P'}, $depth, $delta, $dbesaz, $isxderiv, $iszderiv, $selev, $lat, $lon, $topo, $nlat, $nlon, $etopores, $ec);
        #next if ( $ttime_wcorr == -999 );

        my ($ttime_p, $dtdd_p, $dtdh_p, $bpdel_p) = table_tt($tt{'P'}, $delta, $depth, 1, 1);
        my ($ttime_s, $dtdd_s, $dtdh_s, $bpdel_s) = table_tt($tt{'S'}, $delta, $depth, 1, 1);

        if ( $ttime_p != -999 and $ttime_s != -999 ) {

            printf OUT " %d %f\n", $delta, $ttime_s - $ttime_p;

        }

    }

    close OUT;

}

#
##  EOF
#
